[libvirt] [PATCH 0/2] Partially revert separation of volume creating and building

The storage driver expects 'createVol' to fill out the volume key. For disk and logical backends, we generate the key only after the volume has been built. Revert the separation commits for these backends. Ján Tomko (2): Revert "storage: lvm: Separate creating of the volume from building" Revert "storage: disk: Separate creating of the volume from building" src/storage/storage_backend_disk.c | 44 ++++++++----------------- src/storage/storage_backend_logical.c | 60 ++++++++++++++--------------------- 2 files changed, 37 insertions(+), 67 deletions(-) -- 1.8.3.2

This reverts commit af1fb38f55d4fb87e0fcaee1e973fa9c6713b1e6. With it, creating new logical volumes fails: https://www.redhat.com/archives/libvir-list/2014-February/msg00658.html In the storage driver, we expect CreateVol to fill out the volume key, but the LVM backend fills the key with the uuid reported by lvs after the logical volume is created. --- src/storage/storage_backend_logical.c | 60 ++++++++++++++--------------------- 1 file changed, 23 insertions(+), 37 deletions(-) diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index 039d962..15b86dc 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -702,16 +702,32 @@ cleanup: static int -virStorageBackendLogicalBuildVol(virConnectPtr conn, - virStoragePoolObjPtr pool, - virStorageVolDefPtr vol, - unsigned int flags) +virStorageBackendLogicalCreateVol(virConnectPtr conn, + virStoragePoolObjPtr pool, + virStorageVolDefPtr vol) { int fd = -1; virCommandPtr cmd = NULL; virErrorPtr err; - virCheckFlags(0, -1); + if (vol->target.encryption != NULL) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", _("storage pool does not support encrypted " + "volumes")); + return -1; + } + + vol->type = VIR_STORAGE_VOL_BLOCK; + + if (vol->target.path != NULL) { + /* A target path passed to CreateVol has no meaning */ + VIR_FREE(vol->target.path); + } + + if (virAsprintf(&vol->target.path, "%s/%s", + pool->def->target.path, + vol->name) == -1) + return -1; cmd = virCommandNewArgList(LVCREATE, "--name", vol->name, @@ -770,7 +786,7 @@ virStorageBackendLogicalBuildVol(virConnectPtr conn, return 0; -error: + error: err = virSaveLastError(); VIR_FORCE_CLOSE(fd); virStorageBackendLogicalDeleteVol(conn, pool, vol, 0); @@ -780,36 +796,6 @@ error: return -1; } - -static int -virStorageBackendLogicalCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool, - virStorageVolDefPtr vol) -{ - if (vol->target.encryption != NULL) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("storage pool does not support encrypted volumes")); - return -1; - } - - vol->type = VIR_STORAGE_VOL_BLOCK; - - VIR_FREE(vol->target.path); - if (virAsprintf(&vol->target.path, "%s/%s", - pool->def->target.path, - vol->name) == -1) - return -1; - - if (virFileExists(vol->target.path)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("volume target path '%s' already exists"), - vol->target.path); - return -1; - } - - return 0; -} - static int virStorageBackendLogicalBuildVolFrom(virConnectPtr conn, virStoragePoolObjPtr pool, @@ -837,7 +823,7 @@ virStorageBackend virStorageBackendLogical = { .refreshPool = virStorageBackendLogicalRefreshPool, .stopPool = virStorageBackendLogicalStopPool, .deletePool = virStorageBackendLogicalDeletePool, - .buildVol = virStorageBackendLogicalBuildVol, + .buildVol = NULL, .buildVolFrom = virStorageBackendLogicalBuildVolFrom, .createVol = virStorageBackendLogicalCreateVol, .deleteVol = virStorageBackendLogicalDeleteVol, -- 1.8.3.2

This reverts commit 67ccf91bf29488783bd1fda46b362450f71a2078. We only generate the volume key after we've built it, but the storage driver expects it to be filled after createVol finishes. Squash the volume building back with creating to fulfill this expectation. --- src/storage/storage_backend_disk.c | 44 ++++++++++++-------------------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c index aa3b72f..a7a7d0e 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -617,43 +617,28 @@ virStorageBackendDiskPartBoundries(virStoragePoolObjPtr pool, static int virStorageBackendDiskCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool ATTRIBUTE_UNUSED, + virStoragePoolObjPtr pool, virStorageVolDefPtr vol) { - if (vol->target.encryption != NULL) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("storage pool does not support encrypted volumes")); - return -1; - } - - vol->type = VIR_STORAGE_VOL_BLOCK; - - return 0; -} - - -static int -virStorageBackendDiskBuildVol(virConnectPtr conn ATTRIBUTE_UNUSED, - virStoragePoolObjPtr pool, - virStorageVolDefPtr vol, - unsigned int flags) -{ int res = -1; char *partFormat = NULL; unsigned long long startOffset = 0, endOffset = 0; - virCommandPtr cmd = NULL; - - virCheckFlags(0, -1); - - cmd = virCommandNewArgList(PARTED, - pool->def->source.devices[0].path, - "mkpart", - "--script", - NULL); + virCommandPtr cmd = virCommandNewArgList(PARTED, + pool->def->source.devices[0].path, + "mkpart", + "--script", + NULL); - if (virStorageBackendDiskPartFormat(pool, vol, &partFormat) != 0) + if (vol->target.encryption != NULL) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", _("storage pool does not support encrypted " + "volumes")); goto cleanup; + } + if (virStorageBackendDiskPartFormat(pool, vol, &partFormat) != 0) { + goto cleanup; + } virCommandAddArg(cmd, partFormat); if (virStorageBackendDiskPartBoundries(pool, &startOffset, @@ -783,6 +768,5 @@ virStorageBackend virStorageBackendDisk = { .createVol = virStorageBackendDiskCreateVol, .deleteVol = virStorageBackendDiskDeleteVol, - .buildVol = virStorageBackendDiskBuildVol, .buildVolFrom = virStorageBackendDiskBuildVolFrom, }; -- 1.8.3.2

On 02/12/14 15:03, Ján Tomko wrote:
The storage driver expects 'createVol' to fill out the volume key. For disk and logical backends, we generate the key only after the volume has been built. Revert the separation commits for these backends.
Ján Tomko (2): Revert "storage: lvm: Separate creating of the volume from building" Revert "storage: disk: Separate creating of the volume from building"
src/storage/storage_backend_disk.c | 44 ++++++++----------------- src/storage/storage_backend_logical.c | 60 ++++++++++++++--------------------- 2 files changed, 37 insertions(+), 67 deletions(-)
ACK series, these changes are not needed in the end for my gluster series. Sorry for breaking that :/ Peter

On 02/12/2014 03:15 PM, Peter Krempa wrote:
On 02/12/14 15:03, Ján Tomko wrote:
The storage driver expects 'createVol' to fill out the volume key. For disk and logical backends, we generate the key only after the volume has been built. Revert the separation commits for these backends.
Ján Tomko (2): Revert "storage: lvm: Separate creating of the volume from building" Revert "storage: disk: Separate creating of the volume from building"
src/storage/storage_backend_disk.c | 44 ++++++++----------------- src/storage/storage_backend_logical.c | 60 ++++++++++++++--------------------- 2 files changed, 37 insertions(+), 67 deletions(-)
ACK series, these changes are not needed in the end for my gluster series.
Now pushed. Jan
participants (2)
-
Ján Tomko
-
Peter Krempa