mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
util: Introduce function for allocating virStorageSource
Add virStorageSourceNew and refactor places allocating that structure to use the helper. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
84966103be
commit
dcda2bf4c1
@ -1881,7 +1881,7 @@ virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt)
|
|||||||
if (VIR_ALLOC(ret) < 0)
|
if (VIR_ALLOC(ret) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(ret->src) < 0)
|
if (!(ret->src = virStorageSourceNew()))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (xmlopt &&
|
if (xmlopt &&
|
||||||
@ -2099,7 +2099,7 @@ virDomainFSDefNew(void)
|
|||||||
if (VIR_ALLOC(ret) < 0)
|
if (VIR_ALLOC(ret) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(ret->src) < 0)
|
if (!(ret->src = virStorageSourceNew()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -7674,7 +7674,7 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
|
|||||||
|
|
||||||
/* For the purposes of command line creation, this needs to look
|
/* For the purposes of command line creation, this needs to look
|
||||||
* like a disk storage source */
|
* like a disk storage source */
|
||||||
if (VIR_ALLOC(iscsisrc->src) < 0)
|
if (!(iscsisrc->src = virStorageSourceNew()))
|
||||||
return -1;
|
return -1;
|
||||||
iscsisrc->src->type = VIR_STORAGE_TYPE_NETWORK;
|
iscsisrc->src->type = VIR_STORAGE_TYPE_NETWORK;
|
||||||
iscsisrc->src->protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI;
|
iscsisrc->src->protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI;
|
||||||
@ -9167,7 +9167,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(backingStore) < 0)
|
if (!(backingStore = virStorageSourceNew()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* backing store is always read-only */
|
/* backing store is always read-only */
|
||||||
@ -9325,7 +9325,7 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def,
|
|||||||
char *blockJob = NULL;
|
char *blockJob = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (VIR_ALLOC(def->mirror) < 0)
|
if (!(def->mirror = virStorageSourceNew()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((blockJob = virXMLPropString(cur, "job"))) {
|
if ((blockJob = virXMLPropString(cur, "job"))) {
|
||||||
|
@ -122,7 +122,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
|
|||||||
|
|
||||||
ctxt->node = node;
|
ctxt->node = node;
|
||||||
|
|
||||||
if (VIR_ALLOC(def->src) < 0)
|
if (!(def->src = virStorageSourceNew()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
def->name = virXMLPropString(node, "name");
|
def->name = virXMLPropString(node, "name");
|
||||||
@ -621,7 +621,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def,
|
|||||||
if (virBitmapIsBitSet(map, i))
|
if (virBitmapIsBitSet(map, i))
|
||||||
continue;
|
continue;
|
||||||
disk = &def->disks[ndisks++];
|
disk = &def->disks[ndisks++];
|
||||||
if (VIR_ALLOC(disk->src) < 0)
|
if (!(disk->src = virStorageSourceNew()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (VIR_STRDUP(disk->name, def->dom->disks[i]->dst) < 0)
|
if (VIR_STRDUP(disk->name, def->dom->disks[i]->dst) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -1200,7 +1200,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((backingStore = virXPathString("string(./backingStore/path)", ctxt))) {
|
if ((backingStore = virXPathString("string(./backingStore/path)", ctxt))) {
|
||||||
if (VIR_ALLOC(def->target.backingStore) < 0)
|
if (!(def->target.backingStore = virStorageSourceNew()))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
def->target.backingStore->type = VIR_STORAGE_TYPE_FILE;
|
def->target.backingStore->type = VIR_STORAGE_TYPE_FILE;
|
||||||
|
@ -2925,6 +2925,7 @@ virStorageSourceIsLocalStorage;
|
|||||||
virStorageSourceIsRelative;
|
virStorageSourceIsRelative;
|
||||||
virStorageSourceIsSameLocation;
|
virStorageSourceIsSameLocation;
|
||||||
virStorageSourceNetworkAssignDefaultPorts;
|
virStorageSourceNetworkAssignDefaultPorts;
|
||||||
|
virStorageSourceNew;
|
||||||
virStorageSourceNewFromBacking;
|
virStorageSourceNewFromBacking;
|
||||||
virStorageSourceNewFromBackingAbsolute;
|
virStorageSourceNewFromBackingAbsolute;
|
||||||
virStorageSourceParseRBDColonString;
|
virStorageSourceParseRBDColonString;
|
||||||
|
@ -2742,7 +2742,7 @@ qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr node,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(migrSource) < 0)
|
if (!(migrSource = virStorageSourceNew()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(type = virXMLPropString(ctxt->node, "type"))) {
|
if (!(type = virXMLPropString(ctxt->node, "type"))) {
|
||||||
@ -9050,7 +9050,7 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
/* terminate the chain for such images as the code below would do */
|
/* terminate the chain for such images as the code below would do */
|
||||||
if (!disksrc->backingStore &&
|
if (!disksrc->backingStore &&
|
||||||
VIR_ALLOC(disksrc->backingStore) < 0)
|
!(disksrc->backingStore = virStorageSourceNew()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* host cdrom requires special treatment in qemu, so we need to check
|
/* host cdrom requires special treatment in qemu, so we need to check
|
||||||
|
@ -17984,7 +17984,7 @@ qemuDomainBlockRebase(virDomainPtr dom, const char *path, const char *base,
|
|||||||
return qemuDomainBlockPullCommon(driver, vm, path, base, bandwidth, flags);
|
return qemuDomainBlockPullCommon(driver, vm, path, base, bandwidth, flags);
|
||||||
|
|
||||||
/* If we got here, we are doing a block copy rebase. */
|
/* If we got here, we are doing a block copy rebase. */
|
||||||
if (VIR_ALLOC(dest) < 0)
|
if (!(dest = virStorageSourceNew()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
dest->type = (flags & VIR_DOMAIN_BLOCK_REBASE_COPY_DEV) ?
|
dest->type = (flags & VIR_DOMAIN_BLOCK_REBASE_COPY_DEV) ?
|
||||||
VIR_STORAGE_TYPE_BLOCK : VIR_STORAGE_TYPE_FILE;
|
VIR_STORAGE_TYPE_BLOCK : VIR_STORAGE_TYPE_FILE;
|
||||||
|
@ -794,14 +794,14 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
VIR_DEBUG("starting blockdev mirror for disk=%s to host=%s", diskAlias, host);
|
VIR_DEBUG("starting blockdev mirror for disk=%s to host=%s", diskAlias, host);
|
||||||
|
|
||||||
if (VIR_ALLOC(copysrc) < 0)
|
if (!(copysrc = virStorageSourceNew()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
copysrc->type = VIR_STORAGE_TYPE_NETWORK;
|
copysrc->type = VIR_STORAGE_TYPE_NETWORK;
|
||||||
copysrc->protocol = VIR_STORAGE_NET_PROTOCOL_NBD;
|
copysrc->protocol = VIR_STORAGE_NET_PROTOCOL_NBD;
|
||||||
copysrc->format = VIR_STORAGE_FILE_RAW;
|
copysrc->format = VIR_STORAGE_FILE_RAW;
|
||||||
|
|
||||||
if (VIR_ALLOC(copysrc->backingStore) < 0)
|
if (!(copysrc->backingStore = virStorageSourceNew()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_STRDUP(copysrc->path, diskAlias) < 0)
|
if (VIR_STRDUP(copysrc->path, diskAlias) < 0)
|
||||||
|
@ -294,7 +294,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (meta->backingStoreRaw) {
|
if (meta->backingStoreRaw) {
|
||||||
if (VIR_ALLOC(vol->target.backingStore) < 0)
|
if (!(vol->target.backingStore = virStorageSourceNew()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
vol->target.backingStore->type = VIR_STORAGE_TYPE_NETWORK;
|
vol->target.backingStore->type = VIR_STORAGE_TYPE_NETWORK;
|
||||||
|
@ -308,7 +308,7 @@ virStorageBackendLogicalMakeVol(char **const groups,
|
|||||||
* lv is created with "--virtualsize").
|
* lv is created with "--virtualsize").
|
||||||
*/
|
*/
|
||||||
if (groups[1] && STRNEQ(groups[1], "") && (groups[1][0] != '[')) {
|
if (groups[1] && STRNEQ(groups[1], "") && (groups[1][0] != '[')) {
|
||||||
if (VIR_ALLOC(vol->target.backingStore) < 0)
|
if (!(vol->target.backingStore = virStorageSourceNew()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virAsprintf(&vol->target.backingStore->path, "%s/%s",
|
if (virAsprintf(&vol->target.backingStore->path, "%s/%s",
|
||||||
|
@ -3402,7 +3402,7 @@ storageBackendProbeTarget(virStorageSourcePtr target,
|
|||||||
if (!virStorageSourceIsLocalStorage(target->backingStore)) {
|
if (!virStorageSourceIsLocalStorage(target->backingStore)) {
|
||||||
virStorageSourceFree(target->backingStore);
|
virStorageSourceFree(target->backingStore);
|
||||||
|
|
||||||
if (VIR_ALLOC(target->backingStore) < 0)
|
if (!(target->backingStore = virStorageSourceNew()))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
target->backingStore->type = VIR_STORAGE_TYPE_NETWORK;
|
target->backingStore->type = VIR_STORAGE_TYPE_NETWORK;
|
||||||
@ -3576,7 +3576,7 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
VIR_DIR_CLOSE(dir);
|
VIR_DIR_CLOSE(dir);
|
||||||
|
|
||||||
if (VIR_ALLOC(target))
|
if (!(target = virStorageSourceNew()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((fd = open(def->target.path, O_RDONLY)) < 0) {
|
if ((fd = open(def->target.path, O_RDONLY)) < 0) {
|
||||||
|
@ -2245,7 +2245,7 @@ virStorageSourceCopy(const virStorageSource *src,
|
|||||||
{
|
{
|
||||||
virStorageSourcePtr def = NULL;
|
virStorageSourcePtr def = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(def) < 0)
|
if (!(def = virStorageSourceNew()))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
def->id = src->id;
|
def->id = src->id;
|
||||||
@ -2562,6 +2562,18 @@ virStorageSourceClear(virStorageSourcePtr def)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virStorageSourcePtr
|
||||||
|
virStorageSourceNew(void)
|
||||||
|
{
|
||||||
|
virStorageSourcePtr ret = NULL;
|
||||||
|
|
||||||
|
if (VIR_ALLOC(ret) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
virStorageSourceFree(virStorageSourcePtr def)
|
virStorageSourceFree(virStorageSourcePtr def)
|
||||||
{
|
{
|
||||||
@ -2580,7 +2592,7 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent,
|
|||||||
virStorageSourcePtr def;
|
virStorageSourcePtr def;
|
||||||
VIR_AUTOFREE(char *) dirname = NULL;
|
VIR_AUTOFREE(char *) dirname = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(def) < 0)
|
if (!(def = virStorageSourceNew()))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* store relative name */
|
/* store relative name */
|
||||||
@ -3627,7 +3639,7 @@ virStorageSourceNewFromBackingAbsolute(const char *path)
|
|||||||
virStorageSourcePtr def;
|
virStorageSourcePtr def;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (VIR_ALLOC(def) < 0)
|
if (!(def = virStorageSourceNew()))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (virStorageIsFile(path)) {
|
if (virStorageIsFile(path)) {
|
||||||
@ -4900,7 +4912,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* add terminator */
|
/* add terminator */
|
||||||
if (VIR_ALLOC(backingStore) < 0)
|
if (!(backingStore = virStorageSourceNew()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,6 +431,7 @@ int virStorageSourceGetActualType(const virStorageSource *def);
|
|||||||
bool virStorageSourceIsLocalStorage(const virStorageSource *src);
|
bool virStorageSourceIsLocalStorage(const virStorageSource *src);
|
||||||
bool virStorageSourceIsEmpty(virStorageSourcePtr src);
|
bool virStorageSourceIsEmpty(virStorageSourcePtr src);
|
||||||
bool virStorageSourceIsBlockLocal(const virStorageSource *src);
|
bool virStorageSourceIsBlockLocal(const virStorageSource *src);
|
||||||
|
virStorageSourcePtr virStorageSourceNew(void);
|
||||||
void virStorageSourceFree(virStorageSourcePtr def);
|
void virStorageSourceFree(virStorageSourcePtr def);
|
||||||
void virStorageSourceBackingStoreClear(virStorageSourcePtr def);
|
void virStorageSourceBackingStoreClear(virStorageSourcePtr def);
|
||||||
int virStorageSourceUpdatePhysicalSize(virStorageSourcePtr src,
|
int virStorageSourceUpdatePhysicalSize(virStorageSourcePtr src,
|
||||||
|
@ -55,7 +55,7 @@ testBackingXMLjsonXML(const void *args)
|
|||||||
VIR_AUTOPTR(virStorageSource) xmlsrc = NULL;
|
VIR_AUTOPTR(virStorageSource) xmlsrc = NULL;
|
||||||
VIR_AUTOPTR(virStorageSource) jsonsrc = NULL;
|
VIR_AUTOPTR(virStorageSource) jsonsrc = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(xmlsrc) < 0)
|
if (!(xmlsrc = virStorageSourceNew()))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
xmlsrc->type = data->type;
|
xmlsrc->type = data->type;
|
||||||
|
@ -98,7 +98,7 @@ testStorageFileGetMetadata(const char *path,
|
|||||||
virStorageSourcePtr ret = NULL;
|
virStorageSourcePtr ret = NULL;
|
||||||
VIR_AUTOPTR(virStorageSource) def = NULL;
|
VIR_AUTOPTR(virStorageSource) def = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(def) < 0)
|
if (!(def = virStorageSourceNew()))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
def->type = VIR_STORAGE_TYPE_FILE;
|
def->type = VIR_STORAGE_TYPE_FILE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user