storage: Track backing store of a volume in the target struct

As we have a nested pointer for storing the backing store of a volume
there's no need to store it in a separate struct.
This commit is contained in:
Peter Krempa 2014-07-14 15:19:49 +02:00
parent c861750ee9
commit 15213d1e5d
6 changed files with 73 additions and 50 deletions

View File

@ -331,7 +331,6 @@ virStorageVolDefFree(virStorageVolDefPtr def)
VIR_FREE(def->source.extents);
virStorageSourceClear(&def->target);
virStorageSourceClear(&def->backingStore);
VIR_FREE(def);
}
@ -1168,6 +1167,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
char *allocation = NULL;
char *capacity = NULL;
char *unit = NULL;
char *backingStore = NULL;
xmlNodePtr node;
xmlNodePtr *nodes = NULL;
size_t i;
@ -1252,21 +1252,35 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
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 (ret->backingStore.format < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown volume format type %s"), format);
VIR_FREE(format);
if ((backingStore = virXPathString("string(./backingStore/path)", ctxt))) {
if (VIR_ALLOC(ret->target.backingStore) < 0)
goto error;
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);
}
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);
@ -1308,19 +1322,13 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
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:
@ -1544,9 +1552,10 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
&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);

View File

@ -68,7 +68,6 @@ struct _virStorageVolDef {
virStorageVolSource source;
virStorageSource target;
virStorageSource backingStore;
};
typedef struct _virStorageVolDefList virStorageVolDefList;

View File

@ -844,11 +844,11 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
}
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",
@ -862,7 +862,8 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
* 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;
@ -871,24 +872,24 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
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;
}
}
@ -929,7 +930,7 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
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);
@ -937,7 +938,7 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
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 &&
@ -1055,7 +1056,7 @@ virStorageBackendCreateQcowCreate(virConnectPtr conn ATTRIBUTE_UNUSED,
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"));
@ -1460,8 +1461,8 @@ virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
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)

View File

@ -890,10 +890,13 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
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;
ignore_value(virStorageBackendUpdateVolTargetInfo(&vol->backingStore,
vol->target.backingStore->path = backingStore;
vol->target.backingStore->format = backingStoreFormat;
ignore_value(virStorageBackendUpdateVolTargetInfo(vol->target.backingStore,
true, false,
VIR_STORAGE_VOL_OPEN_DEFAULT));
/* If this failed, the backing file is currently unavailable,

View File

@ -246,6 +246,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
virStorageSourcePtr meta = NULL;
char *header = NULL;
ssize_t len = VIR_STORAGE_MAX_HEADER;
int backingFormat;
*volptr = NULL;
@ -295,16 +296,23 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
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) {

View File

@ -139,11 +139,14 @@ virStorageBackendLogicalMakeVol(char **const groups,
* 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)
@ -752,8 +755,8 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
}
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);