mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-05 04:25:19 +00:00
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:
parent
c861750ee9
commit
15213d1e5d
@ -331,7 +331,6 @@ virStorageVolDefFree(virStorageVolDefPtr def)
|
|||||||
VIR_FREE(def->source.extents);
|
VIR_FREE(def->source.extents);
|
||||||
|
|
||||||
virStorageSourceClear(&def->target);
|
virStorageSourceClear(&def->target);
|
||||||
virStorageSourceClear(&def->backingStore);
|
|
||||||
VIR_FREE(def);
|
VIR_FREE(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1168,6 +1167,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
|
|||||||
char *allocation = NULL;
|
char *allocation = NULL;
|
||||||
char *capacity = NULL;
|
char *capacity = NULL;
|
||||||
char *unit = NULL;
|
char *unit = NULL;
|
||||||
|
char *backingStore = NULL;
|
||||||
xmlNodePtr node;
|
xmlNodePtr node;
|
||||||
xmlNodePtr *nodes = NULL;
|
xmlNodePtr *nodes = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -1252,15 +1252,21 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret->backingStore.path = virXPathString("string(./backingStore/path)", ctxt);
|
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) {
|
if (options->formatFromString) {
|
||||||
char *format = virXPathString("string(./backingStore/format/@type)", ctxt);
|
char *format = virXPathString("string(./backingStore/format/@type)", ctxt);
|
||||||
if (format == NULL)
|
if (format == NULL)
|
||||||
ret->backingStore.format = options->defaultFormat;
|
ret->target.backingStore->format = options->defaultFormat;
|
||||||
else
|
else
|
||||||
ret->backingStore.format = (options->formatFromString)(format);
|
ret->target.backingStore->format = (options->formatFromString)(format);
|
||||||
|
|
||||||
if (ret->backingStore.format < 0) {
|
if (ret->target.backingStore->format < 0) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("unknown volume format type %s"), format);
|
_("unknown volume format type %s"), format);
|
||||||
VIR_FREE(format);
|
VIR_FREE(format);
|
||||||
@ -1269,6 +1275,14 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
|
|||||||
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);
|
ret->target.compat = virXPathString("string(./target/compat)", ctxt);
|
||||||
if (ret->target.compat) {
|
if (ret->target.compat) {
|
||||||
char **version = virStringSplit(ret->target.compat, ".", 2);
|
char **version = virStringSplit(ret->target.compat, ".", 2);
|
||||||
@ -1308,19 +1322,13 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
|
|||||||
VIR_FREE(nodes);
|
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:
|
cleanup:
|
||||||
VIR_FREE(nodes);
|
VIR_FREE(nodes);
|
||||||
VIR_FREE(allocation);
|
VIR_FREE(allocation);
|
||||||
VIR_FREE(capacity);
|
VIR_FREE(capacity);
|
||||||
VIR_FREE(unit);
|
VIR_FREE(unit);
|
||||||
VIR_FREE(type);
|
VIR_FREE(type);
|
||||||
|
VIR_FREE(backingStore);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
@ -1544,9 +1552,10 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
|
|||||||
&def->target, "target") < 0)
|
&def->target, "target") < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (def->backingStore.path &&
|
if (def->target.backingStore &&
|
||||||
virStorageVolTargetDefFormat(options, &buf,
|
virStorageVolTargetDefFormat(options, &buf,
|
||||||
&def->backingStore, "backingStore") < 0)
|
def->target.backingStore,
|
||||||
|
"backingStore") < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
virBufferAdjustIndent(&buf, -2);
|
virBufferAdjustIndent(&buf, -2);
|
||||||
|
@ -68,7 +68,6 @@ struct _virStorageVolDef {
|
|||||||
|
|
||||||
virStorageVolSource source;
|
virStorageVolSource source;
|
||||||
virStorageSource target;
|
virStorageSource target;
|
||||||
virStorageSource backingStore;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _virStorageVolDefList virStorageVolDefList;
|
typedef struct _virStorageVolDefList virStorageVolDefList;
|
||||||
|
@ -844,11 +844,11 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vol->backingStore.path) {
|
if (vol->target.backingStore) {
|
||||||
int accessRetCode = -1;
|
int accessRetCode = -1;
|
||||||
char *absolutePath = NULL;
|
char *absolutePath = NULL;
|
||||||
|
|
||||||
backingType = virStorageFileFormatTypeToString(vol->backingStore.format);
|
backingType = virStorageFileFormatTypeToString(vol->target.backingStore->format);
|
||||||
|
|
||||||
if (preallocate) {
|
if (preallocate) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
@ -862,7 +862,8 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
|
|||||||
* may cause issues with lvm. Untested essentially.
|
* may cause issues with lvm. Untested essentially.
|
||||||
*/
|
*/
|
||||||
if (inputvol &&
|
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",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("a different backing store cannot be specified."));
|
_("a different backing store cannot be specified."));
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -871,24 +872,24 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
|
|||||||
if (backingType == NULL) {
|
if (backingType == NULL) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unknown storage vol backing store type %d"),
|
_("unknown storage vol backing store type %d"),
|
||||||
vol->backingStore.format);
|
vol->target.backingStore->format);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert relative backing store paths to absolute paths for access
|
/* Convert relative backing store paths to absolute paths for access
|
||||||
* validation.
|
* validation.
|
||||||
*/
|
*/
|
||||||
if ('/' != *(vol->backingStore.path) &&
|
if ('/' != *(vol->target.backingStore->path) &&
|
||||||
virAsprintf(&absolutePath, "%s/%s", pool->def->target.path,
|
virAsprintf(&absolutePath, "%s/%s", pool->def->target.path,
|
||||||
vol->backingStore.path) < 0)
|
vol->target.backingStore->path) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
accessRetCode = access(absolutePath ? absolutePath
|
accessRetCode = access(absolutePath ? absolutePath
|
||||||
: vol->backingStore.path, R_OK);
|
: vol->target.backingStore->path, R_OK);
|
||||||
VIR_FREE(absolutePath);
|
VIR_FREE(absolutePath);
|
||||||
if (accessRetCode != 0) {
|
if (accessRetCode != 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("inaccessible backing store volume %s"),
|
_("inaccessible backing store volume %s"),
|
||||||
vol->backingStore.path);
|
vol->target.backingStore->path);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -929,7 +930,7 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
|
|||||||
cmd = virCommandNew(create_tool);
|
cmd = virCommandNew(create_tool);
|
||||||
|
|
||||||
convert = !!inputvol;
|
convert = !!inputvol;
|
||||||
backing = !inputvol && vol->backingStore.path;
|
backing = !inputvol && vol->target.backingStore;
|
||||||
|
|
||||||
if (convert)
|
if (convert)
|
||||||
virCommandAddArgList(cmd, "convert", "-f", inputType, "-O", type, NULL);
|
virCommandAddArgList(cmd, "convert", "-f", inputType, "-O", type, NULL);
|
||||||
@ -937,7 +938,7 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
|
|||||||
virCommandAddArgList(cmd, "create", "-f", type, NULL);
|
virCommandAddArgList(cmd, "create", "-f", type, NULL);
|
||||||
|
|
||||||
if (backing)
|
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 (imgformat >= QEMU_IMG_BACKING_FORMAT_OPTIONS) {
|
||||||
if (vol->target.format == VIR_STORAGE_FILE_QCOW2 && !compat &&
|
if (vol->target.format == VIR_STORAGE_FILE_QCOW2 && !compat &&
|
||||||
@ -1055,7 +1056,7 @@ virStorageBackendCreateQcowCreate(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
vol->target.format);
|
vol->target.format);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (vol->backingStore.path != NULL) {
|
if (vol->target.backingStore != NULL) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("copy-on-write image not supported with "
|
_("copy-on-write image not supported with "
|
||||||
"qcow-create"));
|
"qcow-create"));
|
||||||
@ -1460,8 +1461,8 @@ virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
|
|||||||
openflags)) < 0)
|
openflags)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (vol->backingStore.path &&
|
if (vol->target.backingStore &&
|
||||||
(ret = virStorageBackendUpdateVolTargetInfo(&vol->backingStore,
|
(ret = virStorageBackendUpdateVolTargetInfo(vol->target.backingStore,
|
||||||
updateCapacity,
|
updateCapacity,
|
||||||
withBlockVolFormat,
|
withBlockVolFormat,
|
||||||
VIR_STORAGE_VOL_OPEN_DEFAULT)) < 0)
|
VIR_STORAGE_VOL_OPEN_DEFAULT)) < 0)
|
||||||
|
@ -890,10 +890,13 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
vol->type = VIR_STORAGE_VOL_DIR;
|
vol->type = VIR_STORAGE_VOL_DIR;
|
||||||
|
|
||||||
if (backingStore != NULL) {
|
if (backingStore != NULL) {
|
||||||
vol->backingStore.path = backingStore;
|
if (VIR_ALLOC(vol->target.backingStore) < 0)
|
||||||
vol->backingStore.format = backingStoreFormat;
|
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,
|
true, false,
|
||||||
VIR_STORAGE_VOL_OPEN_DEFAULT));
|
VIR_STORAGE_VOL_OPEN_DEFAULT));
|
||||||
/* If this failed, the backing file is currently unavailable,
|
/* If this failed, the backing file is currently unavailable,
|
||||||
|
@ -246,6 +246,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
|
|||||||
virStorageSourcePtr meta = NULL;
|
virStorageSourcePtr meta = NULL;
|
||||||
char *header = NULL;
|
char *header = NULL;
|
||||||
ssize_t len = VIR_STORAGE_MAX_HEADER;
|
ssize_t len = VIR_STORAGE_MAX_HEADER;
|
||||||
|
int backingFormat;
|
||||||
|
|
||||||
*volptr = NULL;
|
*volptr = NULL;
|
||||||
|
|
||||||
@ -295,16 +296,23 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
|
|||||||
|
|
||||||
if (!(meta = virStorageFileGetMetadataFromBuf(name, header, len,
|
if (!(meta = virStorageFileGetMetadataFromBuf(name, header, len,
|
||||||
VIR_STORAGE_FILE_AUTO,
|
VIR_STORAGE_FILE_AUTO,
|
||||||
&vol->backingStore.format)))
|
&backingFormat)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
vol->backingStore.path = meta->backingStoreRaw;
|
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;
|
meta->backingStoreRaw = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
vol->target.format = meta->format;
|
vol->target.format = meta->format;
|
||||||
if (vol->backingStore.path &&
|
|
||||||
vol->backingStore.format < 0)
|
|
||||||
vol->backingStore.format = VIR_STORAGE_FILE_RAW;
|
|
||||||
if (meta->capacity)
|
if (meta->capacity)
|
||||||
vol->target.capacity = meta->capacity;
|
vol->target.capacity = meta->capacity;
|
||||||
if (meta->encryption) {
|
if (meta->encryption) {
|
||||||
|
@ -139,11 +139,14 @@ virStorageBackendLogicalMakeVol(char **const groups,
|
|||||||
* lv is created with "--virtualsize").
|
* lv is created with "--virtualsize").
|
||||||
*/
|
*/
|
||||||
if (groups[1] && !STREQ(groups[1], "") && (groups[1][0] != '[')) {
|
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)
|
pool->def->target.path, groups[1]) < 0)
|
||||||
goto cleanup;
|
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)
|
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,
|
virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->target.capacity,
|
||||||
1024));
|
1024));
|
||||||
if (vol->backingStore.path)
|
if (vol->target.backingStore)
|
||||||
virCommandAddArgList(cmd, "-s", vol->backingStore.path, NULL);
|
virCommandAddArgList(cmd, "-s", vol->target.backingStore->path, NULL);
|
||||||
else
|
else
|
||||||
virCommandAddArg(cmd, pool->def->source.name);
|
virCommandAddArg(cmd, pool->def->source.name);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user