mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
util: storage: Turn virStorageSource into a virObject
To allow tracking a single virStorageSource in multiple structures without extra hassle allow refcounting by turining it into an object. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
@@ -47,6 +47,8 @@
|
|||||||
|
|
||||||
VIR_LOG_INIT("util.storagefile");
|
VIR_LOG_INIT("util.storagefile");
|
||||||
|
|
||||||
|
static virClassPtr virStorageSourceClass;
|
||||||
|
|
||||||
VIR_ENUM_IMPL(virStorage, VIR_STORAGE_TYPE_LAST,
|
VIR_ENUM_IMPL(virStorage, VIR_STORAGE_TYPE_LAST,
|
||||||
"none",
|
"none",
|
||||||
"file",
|
"file",
|
||||||
@@ -2558,30 +2560,49 @@ virStorageSourceClear(virStorageSourcePtr def)
|
|||||||
|
|
||||||
virStorageSourceInitiatorClear(&def->initiator);
|
virStorageSourceInitiatorClear(&def->initiator);
|
||||||
|
|
||||||
memset(def, 0, sizeof(*def));
|
/* clear everything except the class header as the object APIs
|
||||||
|
* will break otherwise */
|
||||||
|
memset((char *) def + sizeof(def->parent), 0,
|
||||||
|
sizeof(*def) - sizeof(def->parent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
virStorageSourceDispose(void *obj)
|
||||||
|
{
|
||||||
|
virStorageSourcePtr src = obj;
|
||||||
|
|
||||||
|
virStorageSourceClear(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
virStorageSourceOnceInit(void)
|
||||||
|
{
|
||||||
|
if (!VIR_CLASS_NEW(virStorageSource, virClassForObject()))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
VIR_ONCE_GLOBAL_INIT(virStorageSource);
|
||||||
|
|
||||||
|
|
||||||
virStorageSourcePtr
|
virStorageSourcePtr
|
||||||
virStorageSourceNew(void)
|
virStorageSourceNew(void)
|
||||||
{
|
{
|
||||||
virStorageSourcePtr ret = NULL;
|
if (virStorageSourceInitialize() < 0)
|
||||||
|
|
||||||
if (VIR_ALLOC(ret) < 0)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return ret;
|
return virObjectNew(virStorageSourceClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
virStorageSourceFree(virStorageSourcePtr def)
|
virStorageSourceFree(virStorageSourcePtr def)
|
||||||
{
|
{
|
||||||
if (!def)
|
virObjectUnref(def);
|
||||||
return;
|
|
||||||
|
|
||||||
virStorageSourceClear(def);
|
|
||||||
VIR_FREE(def);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -242,6 +242,8 @@ typedef virStorageSource *virStorageSourcePtr;
|
|||||||
* IMPORTANT: When adding fields to this struct it's also necessary to add
|
* IMPORTANT: When adding fields to this struct it's also necessary to add
|
||||||
* appropriate code to the virStorageSourceCopy deep copy function */
|
* appropriate code to the virStorageSourceCopy deep copy function */
|
||||||
struct _virStorageSource {
|
struct _virStorageSource {
|
||||||
|
virObject parent;
|
||||||
|
|
||||||
unsigned int id; /* backing chain identifier, 0 is unset */
|
unsigned int id; /* backing chain identifier, 0 is unset */
|
||||||
int type; /* virStorageType */
|
int type; /* virStorageType */
|
||||||
char *path;
|
char *path;
|
||||||
|
|||||||
Reference in New Issue
Block a user