mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
storage: Add param to check whether we can write a disk label
Modify virStorageBackendDiskValidLabel to add a 'writelabel' parameter. While initially for the purpose of determining whether the label should be written during DiskBuild, a future use during DiskStart could determine whether the pool should be started using the label found. Augment the error messages also to give a hint as to what someone may need to do or why the command failed.
This commit is contained in:
parent
2f177c5a41
commit
05c46f5c22
@ -435,24 +435,40 @@ virStorageBackendDiskFindLabel(const char* device)
|
|||||||
* Determine whether the label on the disk is valid or in a known format
|
* Determine whether the label on the disk is valid or in a known format
|
||||||
* for the purpose of rewriting the label during build
|
* for the purpose of rewriting the label during build
|
||||||
*
|
*
|
||||||
|
* When 'writelabel' is true, if we find a valid disk label on the device,
|
||||||
|
* then we shouldn't be attempting to write as the volume may contain
|
||||||
|
* data. Force the usage of the overwrite flag to the build command in
|
||||||
|
* order to be certain. When the disk label is unrecognized, then it
|
||||||
|
* should be safe to write.
|
||||||
|
*
|
||||||
* Return: True if it's OK
|
* Return: True if it's OK
|
||||||
* False if something's wrong
|
* False if something's wrong
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
virStorageBackendDiskValidLabel(const char *device)
|
virStorageBackendDiskValidLabel(const char *device,
|
||||||
|
bool writelabel)
|
||||||
{
|
{
|
||||||
bool valid = false;
|
bool valid = false;
|
||||||
int check;
|
int check;
|
||||||
|
|
||||||
check = virStorageBackendDiskFindLabel(device);
|
check = virStorageBackendDiskFindLabel(device);
|
||||||
if (check > 0) {
|
if (check > 0) {
|
||||||
|
if (writelabel)
|
||||||
valid = true;
|
valid = true;
|
||||||
|
else
|
||||||
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||||
|
_("Unrecognized disk label found, requires build"));
|
||||||
} else if (check < 0) {
|
} else if (check < 0) {
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||||
_("Error checking for disk label"));
|
_("Error checking for disk label, failed to get "
|
||||||
|
"disk partition information"));
|
||||||
} else {
|
} else {
|
||||||
|
if (writelabel)
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
_("Disk label already present"));
|
_("Valid disk label already present, "
|
||||||
|
"requires --overwrite"));
|
||||||
|
else
|
||||||
|
valid = true;
|
||||||
}
|
}
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
@ -481,7 +497,8 @@ virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
ok_to_mklabel = true;
|
ok_to_mklabel = true;
|
||||||
else
|
else
|
||||||
ok_to_mklabel = virStorageBackendDiskValidLabel(
|
ok_to_mklabel = virStorageBackendDiskValidLabel(
|
||||||
pool->def->source.devices[0].path);
|
pool->def->source.devices[0].path,
|
||||||
|
true);
|
||||||
|
|
||||||
if (ok_to_mklabel) {
|
if (ok_to_mklabel) {
|
||||||
/* eg parted /dev/sda mklabel --script msdos */
|
/* eg parted /dev/sda mklabel --script msdos */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user