1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-23 21:34:54 +03: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:
Peter Krempa 2019-02-14 16:20:25 +01:00
parent 84966103be
commit dcda2bf4c1
14 changed files with 37 additions and 23 deletions

View File

@ -1881,7 +1881,7 @@ virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt)
if (VIR_ALLOC(ret) < 0)
return NULL;
if (VIR_ALLOC(ret->src) < 0)
if (!(ret->src = virStorageSourceNew()))
goto error;
if (xmlopt &&
@ -2099,7 +2099,7 @@ virDomainFSDefNew(void)
if (VIR_ALLOC(ret) < 0)
return NULL;
if (VIR_ALLOC(ret->src) < 0)
if (!(ret->src = virStorageSourceNew()))
goto cleanup;
return ret;
@ -7674,7 +7674,7 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr sourcenode,
/* For the purposes of command line creation, this needs to look
* like a disk storage source */
if (VIR_ALLOC(iscsisrc->src) < 0)
if (!(iscsisrc->src = virStorageSourceNew()))
return -1;
iscsisrc->src->type = VIR_STORAGE_TYPE_NETWORK;
iscsisrc->src->protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI;
@ -9167,7 +9167,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
goto cleanup;
}
if (VIR_ALLOC(backingStore) < 0)
if (!(backingStore = virStorageSourceNew()))
goto cleanup;
/* backing store is always read-only */
@ -9325,7 +9325,7 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def,
char *blockJob = NULL;
int ret = -1;
if (VIR_ALLOC(def->mirror) < 0)
if (!(def->mirror = virStorageSourceNew()))
goto cleanup;
if ((blockJob = virXMLPropString(cur, "job"))) {

View File

@ -122,7 +122,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
ctxt->node = node;
if (VIR_ALLOC(def->src) < 0)
if (!(def->src = virStorageSourceNew()))
goto cleanup;
def->name = virXMLPropString(node, "name");
@ -621,7 +621,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def,
if (virBitmapIsBitSet(map, i))
continue;
disk = &def->disks[ndisks++];
if (VIR_ALLOC(disk->src) < 0)
if (!(disk->src = virStorageSourceNew()))
goto cleanup;
if (VIR_STRDUP(disk->name, def->dom->disks[i]->dst) < 0)
goto cleanup;

View File

@ -1200,7 +1200,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
}
if ((backingStore = virXPathString("string(./backingStore/path)", ctxt))) {
if (VIR_ALLOC(def->target.backingStore) < 0)
if (!(def->target.backingStore = virStorageSourceNew()))
return NULL;
def->target.backingStore->type = VIR_STORAGE_TYPE_FILE;

View File

@ -2925,6 +2925,7 @@ virStorageSourceIsLocalStorage;
virStorageSourceIsRelative;
virStorageSourceIsSameLocation;
virStorageSourceNetworkAssignDefaultPorts;
virStorageSourceNew;
virStorageSourceNewFromBacking;
virStorageSourceNewFromBackingAbsolute;
virStorageSourceParseRBDColonString;

View File

@ -2742,7 +2742,7 @@ qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr node,
goto cleanup;
}
if (VIR_ALLOC(migrSource) < 0)
if (!(migrSource = virStorageSourceNew()))
goto cleanup;
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 */
if (!disksrc->backingStore &&
VIR_ALLOC(disksrc->backingStore) < 0)
!(disksrc->backingStore = virStorageSourceNew()))
goto cleanup;
/* host cdrom requires special treatment in qemu, so we need to check

View File

@ -17984,7 +17984,7 @@ qemuDomainBlockRebase(virDomainPtr dom, const char *path, const char *base,
return qemuDomainBlockPullCommon(driver, vm, path, base, bandwidth, flags);
/* If we got here, we are doing a block copy rebase. */
if (VIR_ALLOC(dest) < 0)
if (!(dest = virStorageSourceNew()))
goto cleanup;
dest->type = (flags & VIR_DOMAIN_BLOCK_REBASE_COPY_DEV) ?
VIR_STORAGE_TYPE_BLOCK : VIR_STORAGE_TYPE_FILE;

View File

@ -794,14 +794,14 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr driver,
VIR_DEBUG("starting blockdev mirror for disk=%s to host=%s", diskAlias, host);
if (VIR_ALLOC(copysrc) < 0)
if (!(copysrc = virStorageSourceNew()))
goto cleanup;
copysrc->type = VIR_STORAGE_TYPE_NETWORK;
copysrc->protocol = VIR_STORAGE_NET_PROTOCOL_NBD;
copysrc->format = VIR_STORAGE_FILE_RAW;
if (VIR_ALLOC(copysrc->backingStore) < 0)
if (!(copysrc->backingStore = virStorageSourceNew()))
goto cleanup;
if (VIR_STRDUP(copysrc->path, diskAlias) < 0)

View File

@ -294,7 +294,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
goto cleanup;
if (meta->backingStoreRaw) {
if (VIR_ALLOC(vol->target.backingStore) < 0)
if (!(vol->target.backingStore = virStorageSourceNew()))
goto cleanup;
vol->target.backingStore->type = VIR_STORAGE_TYPE_NETWORK;

View File

@ -308,7 +308,7 @@ virStorageBackendLogicalMakeVol(char **const groups,
* lv is created with "--virtualsize").
*/
if (groups[1] && STRNEQ(groups[1], "") && (groups[1][0] != '[')) {
if (VIR_ALLOC(vol->target.backingStore) < 0)
if (!(vol->target.backingStore = virStorageSourceNew()))
goto cleanup;
if (virAsprintf(&vol->target.backingStore->path, "%s/%s",

View File

@ -3402,7 +3402,7 @@ storageBackendProbeTarget(virStorageSourcePtr target,
if (!virStorageSourceIsLocalStorage(target->backingStore)) {
virStorageSourceFree(target->backingStore);
if (VIR_ALLOC(target->backingStore) < 0)
if (!(target->backingStore = virStorageSourceNew()))
return -1;
target->backingStore->type = VIR_STORAGE_TYPE_NETWORK;
@ -3576,7 +3576,7 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
goto cleanup;
VIR_DIR_CLOSE(dir);
if (VIR_ALLOC(target))
if (!(target = virStorageSourceNew()))
goto cleanup;
if ((fd = open(def->target.path, O_RDONLY)) < 0) {

View File

@ -2245,7 +2245,7 @@ virStorageSourceCopy(const virStorageSource *src,
{
virStorageSourcePtr def = NULL;
if (VIR_ALLOC(def) < 0)
if (!(def = virStorageSourceNew()))
return NULL;
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
virStorageSourceFree(virStorageSourcePtr def)
{
@ -2580,7 +2592,7 @@ virStorageSourceNewFromBackingRelative(virStorageSourcePtr parent,
virStorageSourcePtr def;
VIR_AUTOFREE(char *) dirname = NULL;
if (VIR_ALLOC(def) < 0)
if (!(def = virStorageSourceNew()))
return NULL;
/* store relative name */
@ -3627,7 +3639,7 @@ virStorageSourceNewFromBackingAbsolute(const char *path)
virStorageSourcePtr def;
int rc;
if (VIR_ALLOC(def) < 0)
if (!(def = virStorageSourceNew()))
return NULL;
if (virStorageIsFile(path)) {
@ -4900,7 +4912,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
}
} else {
/* add terminator */
if (VIR_ALLOC(backingStore) < 0)
if (!(backingStore = virStorageSourceNew()))
goto cleanup;
}

View File

@ -431,6 +431,7 @@ int virStorageSourceGetActualType(const virStorageSource *def);
bool virStorageSourceIsLocalStorage(const virStorageSource *src);
bool virStorageSourceIsEmpty(virStorageSourcePtr src);
bool virStorageSourceIsBlockLocal(const virStorageSource *src);
virStorageSourcePtr virStorageSourceNew(void);
void virStorageSourceFree(virStorageSourcePtr def);
void virStorageSourceBackingStoreClear(virStorageSourcePtr def);
int virStorageSourceUpdatePhysicalSize(virStorageSourcePtr src,

View File

@ -55,7 +55,7 @@ testBackingXMLjsonXML(const void *args)
VIR_AUTOPTR(virStorageSource) xmlsrc = NULL;
VIR_AUTOPTR(virStorageSource) jsonsrc = NULL;
if (VIR_ALLOC(xmlsrc) < 0)
if (!(xmlsrc = virStorageSourceNew()))
return -1;
xmlsrc->type = data->type;

View File

@ -98,7 +98,7 @@ testStorageFileGetMetadata(const char *path,
virStorageSourcePtr ret = NULL;
VIR_AUTOPTR(virStorageSource) def = NULL;
if (VIR_ALLOC(def) < 0)
if (!(def = virStorageSourceNew()))
return NULL;
def->type = VIR_STORAGE_TYPE_FILE;