1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

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 <jferlan@redhat.com>
This commit is contained in:
John Ferlan 2016-12-14 18:03:20 -05:00
parent a22e1a0032
commit 19ced38f1c
3 changed files with 24 additions and 10 deletions

View File

@ -2730,6 +2730,7 @@ virStorageBackendBLKIDFindPart(blkid_probe probe,
/* /*
* @device: Path to device * @device: Path to device
* @format: Desired format * @format: Desired format
* @writelabel: True if desire to write the label
* *
* Use the blkid_ APIs in order to get details regarding whether a file * Use the blkid_ APIs in order to get details regarding whether a file
* system or partition exists on the disk already. * system or partition exists on the disk already.
@ -2740,7 +2741,8 @@ virStorageBackendBLKIDFindPart(blkid_probe probe,
*/ */
static int static int
virStorageBackendBLKIDFindEmpty(const char *device, virStorageBackendBLKIDFindEmpty(const char *device,
const char *format) const char *format,
bool writelabel)
{ {
int ret = -1; int ret = -1;
@ -2768,7 +2770,12 @@ virStorageBackendBLKIDFindEmpty(const char *device,
switch (rc) { switch (rc) {
case VIR_STORAGE_BLKID_PROBE_UNDEFINED: case VIR_STORAGE_BLKID_PROBE_UNDEFINED:
if (writelabel)
ret = 0; ret = 0;
else
virReportError(VIR_ERR_STORAGE_PROBE_FAILED,
_("Device '%s' is unrecognized, requires build"),
device);
break; break;
case VIR_STORAGE_BLKID_PROBE_ERROR: case VIR_STORAGE_BLKID_PROBE_ERROR:
@ -2784,9 +2791,12 @@ virStorageBackendBLKIDFindEmpty(const char *device,
break; break;
case VIR_STORAGE_BLKID_PROBE_MATCH: case VIR_STORAGE_BLKID_PROBE_MATCH:
if (writelabel)
virReportError(VIR_ERR_STORAGE_POOL_BUILT, virReportError(VIR_ERR_STORAGE_POOL_BUILT,
_("Device '%s' already formatted using '%s'"), _("Device '%s' already formatted using '%s'"),
device, format); device, format);
else
ret = 0;
break; break;
case VIR_STORAGE_BLKID_PROBE_DIFFERENT: case VIR_STORAGE_BLKID_PROBE_DIFFERENT:
@ -2813,7 +2823,8 @@ virStorageBackendBLKIDFindEmpty(const char *device,
static int static int
virStorageBackendBLKIDFindEmpty(const char *device ATTRIBUTE_UNUSED, 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", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("probing for filesystems is unsupported " _("probing for filesystems is unsupported "
@ -2827,6 +2838,7 @@ virStorageBackendBLKIDFindEmpty(const char *device ATTRIBUTE_UNUSED,
/* virStorageBackendDeviceIsEmpty: /* virStorageBackendDeviceIsEmpty:
* @devpath: Path to the device to check * @devpath: Path to the device to check
* @format: Desired format string * @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 * Check if the @devpath has some sort of known file system using the
* BLKID API if available. * BLKID API if available.
@ -2836,7 +2848,8 @@ virStorageBackendBLKIDFindEmpty(const char *device ATTRIBUTE_UNUSED,
*/ */
bool bool
virStorageBackendDeviceIsEmpty(const char *devpath, virStorageBackendDeviceIsEmpty(const char *devpath,
const char *format) const char *format,
bool writelabel)
{ {
return virStorageBackendBLKIDFindEmpty(devpath, format) == 0; return virStorageBackendBLKIDFindEmpty(devpath, format, writelabel) == 0;
} }

View File

@ -159,7 +159,8 @@ int virStorageBackendVolWipeLocal(virConnectPtr conn,
unsigned int flags); unsigned int flags);
bool virStorageBackendDeviceIsEmpty(const char *devpath, bool virStorageBackendDeviceIsEmpty(const char *devpath,
const char *format); const char *format,
bool writelabel);
typedef struct _virStorageBackend virStorageBackend; typedef struct _virStorageBackend virStorageBackend;
typedef virStorageBackend *virStorageBackendPtr; typedef virStorageBackend *virStorageBackendPtr;

View File

@ -693,7 +693,7 @@ virStorageBackendMakeFileSystem(virStoragePoolObjPtr pool,
if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) { if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) {
ok_to_mkfs = true; ok_to_mkfs = true;
} else if (flags & VIR_STORAGE_POOL_BUILD_NO_OVERWRITE && } else if (flags & VIR_STORAGE_POOL_BUILD_NO_OVERWRITE &&
virStorageBackendDeviceIsEmpty(device, format)) { virStorageBackendDeviceIsEmpty(device, format, true)) {
ok_to_mkfs = true; ok_to_mkfs = true;
} }