refactor and remove unused created variable Signed-off-by: Yi Li <yili@xxxxxxxxxxx> --- src/storage/storage_util.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index c6d0f7a97c..c02ece8253 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -384,11 +384,10 @@ storageBackendCreateRaw(virStoragePoolObjPtr pool, unsigned int flags) { virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); - int ret = -1; + int ret = 0; int operation_flags; bool reflink_copy = false; mode_t open_mode = VIR_STORAGE_DEFAULT_VOL_PERM_MODE; - bool created = false; VIR_AUTOCLOSE fd = -1; virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA | @@ -399,13 +398,13 @@ storageBackendCreateRaw(virStoragePoolObjPtr pool, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("metadata preallocation is not supported for raw " "volumes")); - goto cleanup; + return -1; } if (virStorageSourceHasBacking(&vol->target)) { virReportError(VIR_ERR_NO_SUPPORT, "%s", _("backing storage not supported for raw volumes")); - goto cleanup; + return -1; } if (flags & VIR_STORAGE_VOL_CREATE_REFLINK) @@ -415,7 +414,7 @@ storageBackendCreateRaw(virStoragePoolObjPtr pool, if (vol->target.encryption) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("storage pool does not support encrypted volumes")); - goto cleanup; + return -1; } operation_flags = VIR_FILE_OPEN_FORCE_MODE | VIR_FILE_OPEN_FORCE_OWNER; @@ -434,22 +433,23 @@ storageBackendCreateRaw(virStoragePoolObjPtr pool, virReportSystemError(-fd, _("Failed to create file '%s'"), vol->target.path); - goto cleanup; + return -1; } - created = true; /* NB, COW flag can only be toggled when the file is zero-size, * so must go before the createRawFile call allocates payload */ if (vol->target.nocow && - virFileSetCOW(vol->target.path, VIR_TRISTATE_BOOL_NO) < 0) + virFileSetCOW(vol->target.path, VIR_TRISTATE_BOOL_NO) < 0) { + ret = -1; goto cleanup; + } - if ((ret = createRawFile(fd, vol, inputvol, reflink_copy)) < 0) + if (createRawFile(fd, vol, inputvol, reflink_copy) < 0) /* createRawFile already reported the exact error. */ ret = -1; cleanup: - if (ret < 0 && created) + if (ret < 0) ignore_value(virFileRemove(vol->target.path, vol->target.perms->uid, vol->target.perms->gid)); -- 2.25.3