/*
* @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.
*/
static int
virStorageBackendBLKIDFindEmpty(const char *device,
- const char *format)
+ const char *format,
+ bool writelabel)
{
int ret = -1;
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:
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:
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 "
/* 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.
*/
bool
virStorageBackendDeviceIsEmpty(const char *devpath,
- const char *format)
+ const char *format,
+ bool writelabel)
{
- return virStorageBackendBLKIDFindEmpty(devpath, format) == 0;
+ return virStorageBackendBLKIDFindEmpty(devpath, format, writelabel) == 0;
}