mirror of https://gitee.com/openkylin/libvirt.git
storage: Refactor disk label checking
Create a new function virStorageBackendDiskValidLabel to handle checking whether there is a label on the device and whether it's valid or not. While initially for the purpose of determining whether the label can be overwritten during DiskBuild, a future use during DiskStart could determine whether the pool should be started using the label found.
This commit is contained in:
parent
fdda37608a
commit
2f177c5a41
|
@ -431,6 +431,33 @@ virStorageBackendDiskFindLabel(const char* device)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the label on the disk is valid or in a known format
|
||||||
|
* for the purpose of rewriting the label during build
|
||||||
|
*
|
||||||
|
* Return: True if it's OK
|
||||||
|
* False if something's wrong
|
||||||
|
*/
|
||||||
|
static bool
|
||||||
|
virStorageBackendDiskValidLabel(const char *device)
|
||||||
|
{
|
||||||
|
bool valid = false;
|
||||||
|
int check;
|
||||||
|
|
||||||
|
check = virStorageBackendDiskFindLabel(device);
|
||||||
|
if (check > 0) {
|
||||||
|
valid = true;
|
||||||
|
} else if (check < 0) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||||
|
_("Error checking for disk label"));
|
||||||
|
} else {
|
||||||
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
|
_("Disk label already present"));
|
||||||
|
}
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a new partition table header
|
* Write a new partition table header
|
||||||
*/
|
*/
|
||||||
|
@ -450,23 +477,11 @@ virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
VIR_STORAGE_POOL_BUILD_NO_OVERWRITE,
|
VIR_STORAGE_POOL_BUILD_NO_OVERWRITE,
|
||||||
error);
|
error);
|
||||||
|
|
||||||
if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) {
|
if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE)
|
||||||
ok_to_mklabel = true;
|
ok_to_mklabel = true;
|
||||||
} else {
|
else
|
||||||
int check;
|
ok_to_mklabel = virStorageBackendDiskValidLabel(
|
||||||
|
|
||||||
check = virStorageBackendDiskFindLabel(
|
|
||||||
pool->def->source.devices[0].path);
|
pool->def->source.devices[0].path);
|
||||||
if (check > 0) {
|
|
||||||
ok_to_mklabel = true;
|
|
||||||
} else if (check < 0) {
|
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
|
||||||
_("Error checking for disk label"));
|
|
||||||
} else {
|
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("Disk label already present"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ok_to_mklabel) {
|
if (ok_to_mklabel) {
|
||||||
/* eg parted /dev/sda mklabel --script msdos */
|
/* eg parted /dev/sda mklabel --script msdos */
|
||||||
|
|
Loading…
Reference in New Issue