}
}
- for (tmp = disk->src; tmp; tmp = tmp->backingStore) {
+ for (tmp = disk->src; virStorageSourceIsBacking(tmp); tmp = tmp->backingStore) {
/* execute the callback only for local storage */
if (virStorageSourceIsLocalStorage(tmp) &&
tmp->path) {
if (virStorageSize(unit, capacity, &ret->target.capacity) < 0)
goto error;
} else if (!(flags & VIR_VOL_XML_PARSE_NO_CAPACITY) &&
- !((flags & VIR_VOL_XML_PARSE_OPT_CAPACITY) && ret->target.backingStore)) {
+ !((flags & VIR_VOL_XML_PARSE_OPT_CAPACITY) &&
+ virStorageSourceHasBacking(&ret->target))) {
virReportError(VIR_ERR_XML_ERROR, "%s", _("missing capacity element"));
goto error;
}
&def->target, "target") < 0)
goto cleanup;
- if (def->target.backingStore &&
+ if (virStorageSourceHasBacking(&def->target) &&
virStorageVolTargetDefFormat(options, &buf,
def->target.backingStore,
"backingStore") < 0)
virStorageSourceFree;
virStorageSourceGetActualType;
virStorageSourceGetSecurityLabelDef;
+virStorageSourceHasBacking;
virStorageSourceInitChainElement;
+virStorageSourceIsBacking;
virStorageSourceIsBlockLocal;
virStorageSourceIsEmpty;
virStorageSourceIsLocalStorage;
{
virStorageSourcePtr next = disk->src;
- while (next) {
+ while (virStorageSourceIsBacking(next)) {
VIR_FREE(next->nodeformat);
VIR_FREE(next->nodestorage);
goto cleanup;
}
- while (src && entry) {
+ while (virStorageSourceIsBacking(src) && entry) {
if (src->nodeformat || src->nodestorage) {
if (STRNEQ_NULLABLE(src->nodeformat, entry->nodeformat) ||
STRNEQ_NULLABLE(src->nodestorage, entry->nodestorage))
virStorageSourcePtr next;
bool forceReadonly = false;
- for (next = disk->src; next; next = next->backingStore) {
+ for (next = disk->src; virStorageSourceIsBacking(next); next = next->backingStore) {
if (qemuSetupImageCgroupInternal(vm, next, forceReadonly) < 0)
return -1;
{
virStorageSourcePtr next;
- for (next = disk->src; next; next = next->backingStore) {
+ for (next = disk->src; virStorageSourceIsBacking(next); next = next->backingStore) {
if (qemuTeardownImageCgroup(vm, next) < 0)
return -1;
}
if (virStorageSourceIsEmpty(disk->src))
goto cleanup;
- if (disk->src->backingStore) {
+ if (virStorageSourceHasBacking(disk->src)) {
if (force_probe)
virStorageSourceBackingStoreClear(disk->src);
else
char *dst = NULL;
int ret = -1;
- for (next = disk->src; next; next = next->backingStore) {
+ for (next = disk->src; virStorageSourceIsBacking(next); next = next->backingStore) {
if (!next->path || !virStorageSourceIsLocalStorage(next)) {
/* Not creating device. Just continue. */
continue;
&ndevMountsPath) < 0)
goto cleanup;
- for (next = src; next; next = next->backingStore) {
+ for (next = src; virStorageSourceIsBacking(next); next = next->backingStore) {
if (virStorageSourceIsEmpty(next) ||
!virStorageSourceIsLocalStorage(next)) {
/* Not creating device. Just continue. */
virStorageSourcePtr next;
unsigned int idx = 1;
- for (next = src->backingStore; next; next = next->backingStore)
+ for (next = src->backingStore; virStorageSourceIsBacking(next); next = next->backingStore)
next->id = idx++;
}
}
/* clear the _SHALLOW flag if there is only one layer */
- if (!disk->src->backingStore)
+ if (!virStorageSourceHasBacking(disk->src))
flags &= ~VIR_DOMAIN_BLOCK_COPY_SHALLOW;
/* unless the user provides a pre-created file, shallow copy into a raw
goto endjob;
}
- if (!topSource->backingStore) {
+ if (!virStorageSourceHasBacking(topSource)) {
virReportError(VIR_ERR_INVALID_ARG,
_("top '%s' in chain for '%s' has no backing file"),
topSource->path, path);
virStorageSourcePtr src = disk->src;
unsigned int backing_idx = 0;
- while (src && (backing_idx == 0 || visitBacking)) {
+ while (virStorageSourceIsBacking(src) &&
+ (backing_idx == 0 || visitBacking)) {
if (qemuDomainGetStatsOneBlock(driver, cfg, dom, record, maxparams,
disk, src, visited, backing_idx,
stats, nodestats) < 0)
{
virStorageSourcePtr next;
- for (next = disk->src; next; next = next->backingStore) {
+ for (next = disk->src; virStorageSourceIsBacking(next); next = next->backingStore) {
if (virSecurityDACSetImageLabel(mgr, def, next) < 0)
return -1;
}
* be tracked in domain XML, at which point labelskip should be a
* per-file attribute instead of a disk attribute. */
if (disk_seclabel && disk_seclabel->labelskip &&
- !src->backingStore)
+ !virStorageSourceHasBacking(src))
return 0;
/* Don't restore labels on readonly/shared disks, because other VMs may
bool first = true;
virStorageSourcePtr next;
- for (next = disk->src; next; next = next->backingStore) {
+ for (next = disk->src; virStorageSourceIsBacking(next); next = next->backingStore) {
if (virSecuritySELinuxSetImageLabelInternal(mgr, def, next, first) < 0)
return -1;
/* XXX - if we knew the qemu user:group here we could send it in
* so that the open could be re-tried as that user:group.
*/
- if (!disk->src->backingStore) {
+ if (!virStorageSourceHasBacking(disk->src)) {
bool probe = ctl->allowDiskFormatProbing;
virStorageFileGetMetadata(disk->src, -1, -1, probe, false);
}
}
virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->target.capacity,
1024));
- if (vol->target.backingStore)
+ if (virStorageSourceHasBacking(&vol->target))
virCommandAddArgList(cmd, "-s", vol->target.backingStore->path, NULL);
else
virCommandAddArg(cmd, def->source.name);
ret = 0;
cleanup:
- if (src->backingStore)
+ if (virStorageSourceHasBacking(src))
src->backingStore->id = depth;
VIR_FREE(buf);
virStorageFileDeinit(src);
goto cleanup;
}
- if (vol->target.backingStore) {
+ if (virStorageSourceHasBacking(&vol->target)) {
virReportError(VIR_ERR_NO_SUPPORT, "%s",
_("backing storage not supported for raw volumes"));
goto cleanup;
return -1;
}
- if (vol->target.backingStore != NULL) {
+ if (virStorageSourceHasBacking(&vol->target)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("copy-on-write ploop volumes are not yet supported"));
return -1;
* backing store, not really sure what use it serves though, and it
* may cause issues with lvm. Untested essentially.
*/
- if (inputvol && inputvol->target.backingStore &&
+ if (inputvol && virStorageSourceHasBacking(&inputvol->target) &&
STRNEQ_NULLABLE(inputvol->target.backingStore->path,
info->backingPath)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
storageBackendCreateQemuImgSetInput(inputvol, &info) < 0)
return NULL;
- if (vol->target.backingStore &&
+ if (virStorageSourceHasBacking(&vol->target) &&
storageBackendCreateQemuImgSetBacking(pool, vol, inputvol, &info) < 0)
return NULL;
openflags, readflags)) < 0)
return ret;
- if (vol->target.backingStore &&
+ if (virStorageSourceHasBacking(&vol->target) &&
(ret = storageBackendUpdateVolTargetInfo(VIR_STORAGE_VOL_FILE,
vol->target.backingStore,
withBlockVolFormat,
return -1;
}
- if (vol->target.backingStore) {
+ if (virStorageSourceHasBacking(&vol->target)) {
virReportError(VIR_ERR_NO_SUPPORT, "%s",
_("backing storage not supported for directories volumes"));
return -1;
if (vol->target.format == VIR_STORAGE_FILE_PLOOP)
vol->type = VIR_STORAGE_VOL_PLOOP;
- if (vol->target.backingStore) {
+ if (virStorageSourceHasBacking(&vol->target)) {
ignore_value(storageBackendUpdateVolTargetInfo(VIR_STORAGE_VOL_FILE,
vol->target.backingStore,
false,
if (!chain)
return 0;
- for (tmp = chain; tmp; tmp = tmp->backingStore) {
+ for (tmp = chain; virStorageSourceIsBacking(tmp); tmp = tmp->backingStore) {
/* Break when we hit end of chain; report error if we detected
* a missing backing file, infinite loop, or other error */
if (!tmp->backingStore && tmp->backingStoreRaw) {
return ret;
}
+
+/**
+ * virStorageSourceIsBacking:
+ * @src: storage source
+ *
+ * Returns true if @src is a eligible backing store structure. Useful
+ * for iterators.
+ */
+bool
+virStorageSourceIsBacking(const virStorageSource *src)
+{
+ return !!src;
+}
+
+/**
+ * virStorageSourceHasBacking:
+ * @src: storage source
+ *
+ * Returns true if @src has backing store/chain.
+ */
+bool
+virStorageSourceHasBacking(const virStorageSource *src)
+{
+ return virStorageSourceIsBacking(src) && src->backingStore;
+}
+
+
/* Given a @chain, look for the backing store @name that is a backing file
* of @startFrom (or any member of @chain if @startFrom is NULL) and return
* that location within the chain. @chain must always point to the top of
*parent = NULL;
if (startFrom) {
- while (chain && chain != startFrom->backingStore)
+ while (virStorageSourceIsBacking(chain) &&
+ chain != startFrom->backingStore)
chain = chain->backingStore;
*parent = startFrom;
}
- while (chain) {
+ while (virStorageSourceIsBacking(chain)) {
if (!name && !idx) {
- if (!chain->backingStore)
+ if (!virStorageSourceHasBacking(chain))
break;
} else if (idx) {
VIR_DEBUG("%u: %s", chain->id, chain->path);
chain = chain->backingStore;
}
- if (!chain)
+ if (!virStorageSourceIsBacking(chain))
goto error;
return chain;
*relpath = NULL;
- for (next = top; next; next = next->backingStore) {
+ for (next = top; virStorageSourceIsBacking(next); next = next->backingStore) {
if (!next->relPath) {
ret = 1;
goto cleanup;
if (idx)
*idx = 0;
- for (tmp = top; tmp; tmp = tmp->backingStore) {
+ for (tmp = top; virStorageSourceIsBacking(tmp); tmp = tmp->backingStore) {
if ((tmp->nodeformat && STREQ(tmp->nodeformat, nodeName)) ||
(tmp->nodestorage && STREQ(tmp->nodestorage, nodeName)))
return tmp;
virStorageSourceNetworkAssignDefaultPorts(virStorageSourcePtr src)
ATTRIBUTE_NONNULL(1);
+bool
+virStorageSourceIsBacking(const virStorageSource *src);
+bool
+virStorageSourceHasBacking(const virStorageSource *src);
+
+
#endif /* __VIR_STORAGE_FILE_H__ */
}
elt = meta;
- while (elt) {
+ while (virStorageSourceIsBacking(elt)) {
char *expect = NULL;
char *actual = NULL;