VIR_FREE(def->source.extents);
virStorageSourceClear(&def->target);
- virStorageSourceClear(&def->backingStore);
VIR_FREE(def);
}
char *allocation = NULL;
char *capacity = NULL;
char *unit = NULL;
+ char *backingStore = NULL;
xmlNodePtr node;
xmlNodePtr *nodes = NULL;
size_t i;
goto error;
}
- ret->backingStore.path = virXPathString("string(./backingStore/path)", ctxt);
- if (options->formatFromString) {
- char *format = virXPathString("string(./backingStore/format/@type)", ctxt);
- if (format == NULL)
- ret->backingStore.format = options->defaultFormat;
- else
- ret->backingStore.format = (options->formatFromString)(format);
+ if ((backingStore = virXPathString("string(./backingStore/path)", ctxt))) {
+ if (VIR_ALLOC(ret->target.backingStore) < 0)
+ goto error;
- if (ret->backingStore.format < 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unknown volume format type %s"), format);
+ ret->target.backingStore->path = backingStore;
+ backingStore = NULL;
+
+ if (options->formatFromString) {
+ char *format = virXPathString("string(./backingStore/format/@type)", ctxt);
+ if (format == NULL)
+ ret->target.backingStore->format = options->defaultFormat;
+ else
+ ret->target.backingStore->format = (options->formatFromString)(format);
+
+ if (ret->target.backingStore->format < 0) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("unknown volume format type %s"), format);
+ VIR_FREE(format);
+ goto error;
+ }
VIR_FREE(format);
- goto error;
}
- VIR_FREE(format);
+
+ if (VIR_ALLOC(ret->target.backingStore->perms) < 0)
+ goto error;
+ if (virStorageDefParsePerms(ctxt, ret->target.backingStore->perms,
+ "./backingStore/permissions",
+ DEFAULT_VOL_PERM_MODE) < 0)
+ goto error;
}
ret->target.compat = virXPathString("string(./target/compat)", ctxt);
VIR_FREE(nodes);
}
- if (VIR_ALLOC(ret->backingStore.perms) < 0)
- goto error;
- if (virStorageDefParsePerms(ctxt, ret->backingStore.perms,
- "./backingStore/permissions",
- DEFAULT_VOL_PERM_MODE) < 0)
- goto error;
-
cleanup:
VIR_FREE(nodes);
VIR_FREE(allocation);
VIR_FREE(capacity);
VIR_FREE(unit);
VIR_FREE(type);
+ VIR_FREE(backingStore);
return ret;
error:
&def->target, "target") < 0)
goto cleanup;
- if (def->backingStore.path &&
+ if (def->target.backingStore &&
virStorageVolTargetDefFormat(options, &buf,
- &def->backingStore, "backingStore") < 0)
+ def->target.backingStore,
+ "backingStore") < 0)
goto cleanup;
virBufferAdjustIndent(&buf, -2);
virStorageVolSource source;
virStorageSource target;
- virStorageSource backingStore;
};
typedef struct _virStorageVolDefList virStorageVolDefList;
}
- if (vol->backingStore.path) {
+ if (vol->target.backingStore) {
int accessRetCode = -1;
char *absolutePath = NULL;
- backingType = virStorageFileFormatTypeToString(vol->backingStore.format);
+ backingType = virStorageFileFormatTypeToString(vol->target.backingStore->format);
if (preallocate) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
* may cause issues with lvm. Untested essentially.
*/
if (inputvol &&
- STRNEQ_NULLABLE(inputvol->backingStore.path, vol->backingStore.path)) {
+ STRNEQ_NULLABLE(inputvol->target.backingStore->path,
+ vol->target.backingStore->path)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("a different backing store cannot be specified."));
return NULL;
if (backingType == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown storage vol backing store type %d"),
- vol->backingStore.format);
+ vol->target.backingStore->format);
return NULL;
}
/* Convert relative backing store paths to absolute paths for access
* validation.
*/
- if ('/' != *(vol->backingStore.path) &&
+ if ('/' != *(vol->target.backingStore->path) &&
virAsprintf(&absolutePath, "%s/%s", pool->def->target.path,
- vol->backingStore.path) < 0)
+ vol->target.backingStore->path) < 0)
return NULL;
accessRetCode = access(absolutePath ? absolutePath
- : vol->backingStore.path, R_OK);
+ : vol->target.backingStore->path, R_OK);
VIR_FREE(absolutePath);
if (accessRetCode != 0) {
virReportSystemError(errno,
_("inaccessible backing store volume %s"),
- vol->backingStore.path);
+ vol->target.backingStore->path);
return NULL;
}
}
cmd = virCommandNew(create_tool);
convert = !!inputvol;
- backing = !inputvol && vol->backingStore.path;
+ backing = !inputvol && vol->target.backingStore;
if (convert)
virCommandAddArgList(cmd, "convert", "-f", inputType, "-O", type, NULL);
virCommandAddArgList(cmd, "create", "-f", type, NULL);
if (backing)
- virCommandAddArgList(cmd, "-b", vol->backingStore.path, NULL);
+ virCommandAddArgList(cmd, "-b", vol->target.backingStore->path, NULL);
if (imgformat >= QEMU_IMG_BACKING_FORMAT_OPTIONS) {
if (vol->target.format == VIR_STORAGE_FILE_QCOW2 && !compat &&
vol->target.format);
return -1;
}
- if (vol->backingStore.path != NULL) {
+ if (vol->target.backingStore != NULL) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("copy-on-write image not supported with "
"qcow-create"));
openflags)) < 0)
return ret;
- if (vol->backingStore.path &&
- (ret = virStorageBackendUpdateVolTargetInfo(&vol->backingStore,
+ if (vol->target.backingStore &&
+ (ret = virStorageBackendUpdateVolTargetInfo(vol->target.backingStore,
updateCapacity,
withBlockVolFormat,
VIR_STORAGE_VOL_OPEN_DEFAULT)) < 0)
vol->type = VIR_STORAGE_VOL_DIR;
if (backingStore != NULL) {
- vol->backingStore.path = backingStore;
- vol->backingStore.format = backingStoreFormat;
+ if (VIR_ALLOC(vol->target.backingStore) < 0)
+ goto cleanup;
+
+ vol->target.backingStore->path = backingStore;
+ vol->target.backingStore->format = backingStoreFormat;
- ignore_value(virStorageBackendUpdateVolTargetInfo(&vol->backingStore,
+ ignore_value(virStorageBackendUpdateVolTargetInfo(vol->target.backingStore,
true, false,
VIR_STORAGE_VOL_OPEN_DEFAULT));
/* If this failed, the backing file is currently unavailable,
virStorageSourcePtr meta = NULL;
char *header = NULL;
ssize_t len = VIR_STORAGE_MAX_HEADER;
+ int backingFormat;
*volptr = NULL;
if (!(meta = virStorageFileGetMetadataFromBuf(name, header, len,
VIR_STORAGE_FILE_AUTO,
- &vol->backingStore.format)))
+ &backingFormat)))
goto cleanup;
- vol->backingStore.path = meta->backingStoreRaw;
- meta->backingStoreRaw = NULL;
+ if (meta->backingStoreRaw) {
+ if (VIR_ALLOC(vol->target.backingStore) < 0)
+ goto cleanup;
+
+ vol->target.backingStore->path = meta->backingStoreRaw;
+
+ if (backingFormat < 0)
+ vol->target.backingStore->format = VIR_STORAGE_FILE_RAW;
+ else
+ vol->target.backingStore->format = backingFormat;
+ meta->backingStoreRaw = NULL;
+ }
vol->target.format = meta->format;
- if (vol->backingStore.path &&
- vol->backingStore.format < 0)
- vol->backingStore.format = VIR_STORAGE_FILE_RAW;
if (meta->capacity)
vol->target.capacity = meta->capacity;
if (meta->encryption) {
* lv is created with "--virtualsize").
*/
if (groups[1] && !STREQ(groups[1], "") && (groups[1][0] != '[')) {
- if (virAsprintf(&vol->backingStore.path, "%s/%s",
+ if (VIR_ALLOC(vol->target.backingStore) < 0)
+ goto cleanup;
+
+ if (virAsprintf(&vol->target.backingStore->path, "%s/%s",
pool->def->target.path, groups[1]) < 0)
goto cleanup;
- vol->backingStore.format = VIR_STORAGE_POOL_LOGICAL_LVM2;
+ vol->target.backingStore->format = VIR_STORAGE_POOL_LOGICAL_LVM2;
}
if (!vol->key && VIR_STRDUP(vol->key, groups[2]) < 0)
}
virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->target.capacity,
1024));
- if (vol->backingStore.path)
- virCommandAddArgList(cmd, "-s", vol->backingStore.path, NULL);
+ if (vol->target.backingStore)
+ virCommandAddArgList(cmd, "-s", vol->target.backingStore->path, NULL);
else
virCommandAddArg(cmd, pool->def->source.name);