From 19ced38f1c198a603fd4ca7385736829505c0e32 Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Wed, 14 Dec 2016 18:03:20 -0500 Subject: [PATCH] storage: Add writelabel bool for virStorageBackendDeviceProbe It's possible that the API could be called from a startup path in order to check whether the label on the device matches what our format is. In order to handle that condition, add a 'writelabel' boolean to the API in order to indicate whether a write or just read is about to happen. This alters two "error" conditions that would care about knowing. Signed-off-by: John Ferlan --- src/storage/storage_backend.c | 29 +++++++++++++++++++++-------- src/storage/storage_backend.h | 3 ++- src/storage/storage_backend_fs.c | 2 +- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 6be928e992..fb7b744f60 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -2730,6 +2730,7 @@ virStorageBackendBLKIDFindPart(blkid_probe probe, /* * @device: Path to device * @format: Desired format + * @writelabel: True if desire to write the label * * Use the blkid_ APIs in order to get details regarding whether a file * system or partition exists on the disk already. @@ -2740,7 +2741,8 @@ virStorageBackendBLKIDFindPart(blkid_probe probe, */ static int virStorageBackendBLKIDFindEmpty(const char *device, - const char *format) + const char *format, + bool writelabel) { int ret = -1; @@ -2768,7 +2770,12 @@ virStorageBackendBLKIDFindEmpty(const char *device, switch (rc) { case VIR_STORAGE_BLKID_PROBE_UNDEFINED: - ret = 0; + if (writelabel) + ret = 0; + else + virReportError(VIR_ERR_STORAGE_PROBE_FAILED, + _("Device '%s' is unrecognized, requires build"), + device); break; case VIR_STORAGE_BLKID_PROBE_ERROR: @@ -2784,9 +2791,12 @@ virStorageBackendBLKIDFindEmpty(const char *device, break; case VIR_STORAGE_BLKID_PROBE_MATCH: - virReportError(VIR_ERR_STORAGE_POOL_BUILT, - _("Device '%s' already formatted using '%s'"), - device, format); + if (writelabel) + virReportError(VIR_ERR_STORAGE_POOL_BUILT, + _("Device '%s' already formatted using '%s'"), + device, format); + else + ret = 0; break; case VIR_STORAGE_BLKID_PROBE_DIFFERENT: @@ -2813,7 +2823,8 @@ virStorageBackendBLKIDFindEmpty(const char *device, static int virStorageBackendBLKIDFindEmpty(const char *device ATTRIBUTE_UNUSED, - const char *format ATTRIBUTE_UNUSED) + const char *format ATTRIBUTE_UNUSED, + bool writelabel ATTRIBUTE_UNUSED) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("probing for filesystems is unsupported " @@ -2827,6 +2838,7 @@ virStorageBackendBLKIDFindEmpty(const char *device ATTRIBUTE_UNUSED, /* virStorageBackendDeviceIsEmpty: * @devpath: Path to the device to check * @format: Desired format string + * @writelabel: True if the caller expects to write the label * * Check if the @devpath has some sort of known file system using the * BLKID API if available. @@ -2836,7 +2848,8 @@ virStorageBackendBLKIDFindEmpty(const char *device ATTRIBUTE_UNUSED, */ bool virStorageBackendDeviceIsEmpty(const char *devpath, - const char *format) + const char *format, + bool writelabel) { - return virStorageBackendBLKIDFindEmpty(devpath, format) == 0; + return virStorageBackendBLKIDFindEmpty(devpath, format, writelabel) == 0; } diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h index c7b2e32d18..7ae8d58dbc 100644 --- a/src/storage/storage_backend.h +++ b/src/storage/storage_backend.h @@ -159,7 +159,8 @@ int virStorageBackendVolWipeLocal(virConnectPtr conn, unsigned int flags); bool virStorageBackendDeviceIsEmpty(const char *devpath, - const char *format); + const char *format, + bool writelabel); typedef struct _virStorageBackend virStorageBackend; typedef virStorageBackend *virStorageBackendPtr; diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index ba4f598975..f0ef07b2fa 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -693,7 +693,7 @@ virStorageBackendMakeFileSystem(virStoragePoolObjPtr pool, if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) { ok_to_mkfs = true; } else if (flags & VIR_STORAGE_POOL_BUILD_NO_OVERWRITE && - virStorageBackendDeviceIsEmpty(device, format)) { + virStorageBackendDeviceIsEmpty(device, format, true)) { ok_to_mkfs = true; } -- GitLab