提交 a4cb4a74 编写于 作者: J John Ferlan

storage: Adjust disk label found to match labels

Currently as long as the disk is formatted using a known parted format
type, the algorithm is happy to continue. However, that leaves a scenario
whereby a disk formatted using "pc98" could be used by a pool that's defined
using "dvh" (or vice versa). Alter the check to be match and different
and adjust the caller.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 a48c674f
...@@ -2853,7 +2853,8 @@ virStorageBackendBLKIDFindEmpty(const char *device ATTRIBUTE_UNUSED, ...@@ -2853,7 +2853,8 @@ virStorageBackendBLKIDFindEmpty(const char *device ATTRIBUTE_UNUSED,
typedef enum { typedef enum {
VIR_STORAGE_PARTED_ERROR = -1, VIR_STORAGE_PARTED_ERROR = -1,
VIR_STORAGE_PARTED_FOUND, /* Valid label found */ VIR_STORAGE_PARTED_MATCH, /* Valid label found and matches format */
VIR_STORAGE_PARTED_DIFFERENT, /* Valid label found but not match format */
VIR_STORAGE_PARTED_UNKNOWN, /* No or unrecognized label */ VIR_STORAGE_PARTED_UNKNOWN, /* No or unrecognized label */
VIR_STORAGE_PARTED_NOPTTYPE, /* Did not find the Partition Table type */ VIR_STORAGE_PARTED_NOPTTYPE, /* Did not find the Partition Table type */
VIR_STORAGE_PARTED_PTTYPE_UNK, /* Partition Table type unknown*/ VIR_STORAGE_PARTED_PTTYPE_UNK, /* Partition Table type unknown*/
...@@ -2866,7 +2867,8 @@ typedef enum { ...@@ -2866,7 +2867,8 @@ typedef enum {
* returns virStorageBackendPARTEDResult * returns virStorageBackendPARTEDResult
*/ */
static virStorageBackendPARTEDResult static virStorageBackendPARTEDResult
virStorageBackendPARTEDFindLabel(const char *device) virStorageBackendPARTEDFindLabel(const char *device,
const char *format)
{ {
const char *const args[] = { const char *const args[] = {
device, "print", "--script", NULL, device, "print", "--script", NULL,
...@@ -2914,7 +2916,11 @@ virStorageBackendPARTEDFindLabel(const char *device) ...@@ -2914,7 +2916,11 @@ virStorageBackendPARTEDFindLabel(const char *device)
goto cleanup; goto cleanup;
} }
ret = VIR_STORAGE_PARTED_FOUND; /* Does the on disk match what the pool desired? */
if (STREQ(start, format))
ret = VIR_STORAGE_PARTED_MATCH;
ret = VIR_STORAGE_PARTED_DIFFERENT;
cleanup: cleanup:
virCommandFree(cmd); virCommandFree(cmd);
...@@ -2944,12 +2950,13 @@ virStorageBackendPARTEDFindLabel(const char *device) ...@@ -2944,12 +2950,13 @@ virStorageBackendPARTEDFindLabel(const char *device)
*/ */
static int static int
virStorageBackendPARTEDValidLabel(const char *device, virStorageBackendPARTEDValidLabel(const char *device,
const char *format,
bool writelabel) bool writelabel)
{ {
int ret = -1; int ret = -1;
virStorageBackendPARTEDResult check; virStorageBackendPARTEDResult check;
check = virStorageBackendPARTEDFindLabel(device); check = virStorageBackendPARTEDFindLabel(device, format);
switch (check) { switch (check) {
case VIR_STORAGE_PARTED_ERROR: case VIR_STORAGE_PARTED_ERROR:
virReportError(VIR_ERR_OPERATION_FAILED, "%s", virReportError(VIR_ERR_OPERATION_FAILED, "%s",
...@@ -2957,15 +2964,21 @@ virStorageBackendPARTEDValidLabel(const char *device, ...@@ -2957,15 +2964,21 @@ virStorageBackendPARTEDValidLabel(const char *device,
"disk partition information")); "disk partition information"));
break; break;
case VIR_STORAGE_PARTED_FOUND: case VIR_STORAGE_PARTED_MATCH:
if (writelabel) if (writelabel)
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID,
_("Valid disk label already present, " _("Disk label already formatted using '%s'"),
"requires --overwrite")); format);
else else
ret = 0; ret = 0;
break; break;
case VIR_STORAGE_PARTED_DIFFERENT:
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("Known, but different label format present, "
"requires build --overwrite"));
break;
case VIR_STORAGE_PARTED_UNKNOWN: case VIR_STORAGE_PARTED_UNKNOWN:
if (writelabel) if (writelabel)
ret = 0; ret = 0;
...@@ -3010,7 +3023,7 @@ virStorageBackendDeviceIsEmpty(const char *devpath, ...@@ -3010,7 +3023,7 @@ virStorageBackendDeviceIsEmpty(const char *devpath,
if ((ret = virStorageBackendBLKIDFindEmpty(devpath, format, if ((ret = virStorageBackendBLKIDFindEmpty(devpath, format,
writelabel)) == -2) writelabel)) == -2)
ret = virStorageBackendPARTEDValidLabel(devpath, writelabel); ret = virStorageBackendPARTEDValidLabel(devpath, format, writelabel);
return ret == 0; return ret == 0;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册