mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
conf: Allow error reporting in virDomainDiskSourceIsBlockType
Rather than provide a somewhat generic error message when the API returns false, allow the caller to supply a "report = true" option in order to cause virReportError's to describe which of the 3 paths that can cause failure. Some callers don't care about what caused the failure, they just want to have a true/false - for those, calling with report = false should be sufficient.
This commit is contained in:
parent
4ae72f131b
commit
36025c552c
@ -23995,10 +23995,16 @@ virDomainDefFindDevice(virDomainDefPtr def,
|
|||||||
* Return true if its source is block type, or false otherwise.
|
* Return true if its source is block type, or false otherwise.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
virDomainDiskSourceIsBlockType(virStorageSourcePtr src)
|
virDomainDiskSourceIsBlockType(virStorageSourcePtr src,
|
||||||
|
bool report)
|
||||||
{
|
{
|
||||||
if (!src->path)
|
if (!src->path) {
|
||||||
|
if (report)
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
|
_("source path not found for device='lun' "
|
||||||
|
"using type='%d'"), src->type);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (src->type == VIR_STORAGE_TYPE_BLOCK)
|
if (src->type == VIR_STORAGE_TYPE_BLOCK)
|
||||||
return true;
|
return true;
|
||||||
@ -24014,11 +24020,20 @@ virDomainDiskSourceIsBlockType(virStorageSourcePtr src)
|
|||||||
* (e.g. set sgio=filtered|unfiltered for it) in libvirt.
|
* (e.g. set sgio=filtered|unfiltered for it) in libvirt.
|
||||||
*/
|
*/
|
||||||
if (src->srcpool->pooltype == VIR_STORAGE_POOL_ISCSI &&
|
if (src->srcpool->pooltype == VIR_STORAGE_POOL_ISCSI &&
|
||||||
src->srcpool->mode == VIR_STORAGE_SOURCE_POOL_MODE_DIRECT)
|
src->srcpool->mode == VIR_STORAGE_SOURCE_POOL_MODE_DIRECT) {
|
||||||
|
if (report)
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
_("disk device='lun' for iSCSI is not "
|
||||||
|
"supported with mode='direct'."));
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (report)
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
_("disk device='lun' is only valid for block "
|
||||||
|
"type disk source"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3128,7 +3128,7 @@ int virDomainDefFindDevice(virDomainDefPtr def,
|
|||||||
virDomainDeviceDefPtr dev,
|
virDomainDeviceDefPtr dev,
|
||||||
bool reportError);
|
bool reportError);
|
||||||
|
|
||||||
bool virDomainDiskSourceIsBlockType(virStorageSourcePtr src)
|
bool virDomainDiskSourceIsBlockType(virStorageSourcePtr src, bool report)
|
||||||
ATTRIBUTE_NONNULL(1);
|
ATTRIBUTE_NONNULL(1);
|
||||||
|
|
||||||
void virDomainChrSourceDefClear(virDomainChrSourceDefPtr def);
|
void virDomainChrSourceDefClear(virDomainChrSourceDefPtr def);
|
||||||
|
@ -382,7 +382,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
|
|||||||
|
|
||||||
VIR_DEBUG("Allowing any disk block devs");
|
VIR_DEBUG("Allowing any disk block devs");
|
||||||
for (i = 0; i < def->ndisks; i++) {
|
for (i = 0; i < def->ndisks; i++) {
|
||||||
if (!virDomainDiskSourceIsBlockType(def->disks[i]->src))
|
if (!virDomainDiskSourceIsBlockType(def->disks[i]->src, false))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (virCgroupAllowDevicePath(cgroup,
|
if (virCgroupAllowDevicePath(cgroup,
|
||||||
|
@ -4069,11 +4069,9 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virDomainDiskSourceIsBlockType(def->src)) {
|
if (!virDomainDiskSourceIsBlockType(def->src, true))
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
||||||
_("Can't setup disk for non-block device"));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
src = virDomainDiskGetSource(def);
|
src = virDomainDiskGetSource(def);
|
||||||
if (src == NULL) {
|
if (src == NULL) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
@ -3476,10 +3476,7 @@ qemuCheckDiskConfig(virDomainDiskDefPtr disk)
|
|||||||
virStorageNetProtocolTypeToString(disk->src->protocol));
|
virStorageNetProtocolTypeToString(disk->src->protocol));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else if (!virDomainDiskSourceIsBlockType(disk->src)) {
|
} else if (!virDomainDiskSourceIsBlockType(disk->src, true)) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
||||||
_("disk device='lun' is only valid for block "
|
|
||||||
"type disk source"));
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (disk->wwn) {
|
if (disk->wwn) {
|
||||||
|
@ -1210,7 +1210,7 @@ qemuAddSharedDisk(virQEMUDriverPtr driver,
|
|||||||
char *key = NULL;
|
char *key = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!disk->src->shared || !virDomainDiskSourceIsBlockType(disk->src))
|
if (!disk->src->shared || !virDomainDiskSourceIsBlockType(disk->src, false))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
qemuDriverLock(driver);
|
qemuDriverLock(driver);
|
||||||
@ -1355,7 +1355,7 @@ qemuRemoveSharedDisk(virQEMUDriverPtr driver,
|
|||||||
char *key = NULL;
|
char *key = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!disk->src->shared || !virDomainDiskSourceIsBlockType(disk->src))
|
if (!disk->src->shared || !virDomainDiskSourceIsBlockType(disk->src, false))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
qemuDriverLock(driver);
|
qemuDriverLock(driver);
|
||||||
@ -1443,7 +1443,7 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
|
|||||||
disk = dev->data.disk;
|
disk = dev->data.disk;
|
||||||
|
|
||||||
if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN ||
|
if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN ||
|
||||||
!virDomainDiskSourceIsBlockType(disk->src))
|
!virDomainDiskSourceIsBlockType(disk->src, false))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
path = virDomainDiskGetSource(disk);
|
path = virDomainDiskGetSource(disk);
|
||||||
|
Loading…
Reference in New Issue
Block a user