mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
util: Add one argument for several scsi utils
To support passing the path of the test data to the utils, one more argument is added to virSCSIDeviceGetSgName, virSCSIDeviceGetDevName, and virSCSIDeviceNew, and the related code is changed accordingly. Later tests for the scsi utils will be based on this patch. Signed-off-by: Osier Yang <jyang@redhat.com>
This commit is contained in:
parent
fd243fc4ad
commit
10c9ceff6d
@ -291,7 +291,8 @@ qemuSetupHostdevCGroup(virDomainObjPtr vm,
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
|
||||
if ((scsi = virSCSIDeviceNew(dev->source.subsys.u.scsi.adapter,
|
||||
if ((scsi = virSCSIDeviceNew(NULL,
|
||||
dev->source.subsys.u.scsi.adapter,
|
||||
dev->source.subsys.u.scsi.bus,
|
||||
dev->source.subsys.u.scsi.target,
|
||||
dev->source.subsys.u.scsi.unit,
|
||||
|
@ -5785,7 +5785,8 @@ qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
char *sg = NULL;
|
||||
|
||||
sg = (callbacks->qemuGetSCSIDeviceSgName)(dev->source.subsys.u.scsi.adapter,
|
||||
sg = (callbacks->qemuGetSCSIDeviceSgName)(NULL,
|
||||
dev->source.subsys.u.scsi.adapter,
|
||||
dev->source.subsys.u.scsi.bus,
|
||||
dev->source.subsys.u.scsi.target,
|
||||
dev->source.subsys.u.scsi.unit);
|
||||
|
@ -57,7 +57,8 @@
|
||||
typedef struct _qemuBuildCommandLineCallbacks qemuBuildCommandLineCallbacks;
|
||||
typedef qemuBuildCommandLineCallbacks *qemuBuildCommandLineCallbacksPtr;
|
||||
struct _qemuBuildCommandLineCallbacks {
|
||||
char * (*qemuGetSCSIDeviceSgName) (const char *adapter,
|
||||
char * (*qemuGetSCSIDeviceSgName) (const char *sysfs_prefix,
|
||||
const char *adapter,
|
||||
unsigned int bus,
|
||||
unsigned int target,
|
||||
unsigned int unit);
|
||||
|
@ -761,7 +761,8 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
|
||||
} else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
|
||||
hostdev = dev->data.hostdev;
|
||||
|
||||
if (!(hostdev_name = virSCSIDeviceGetDevName(hostdev->source.subsys.u.scsi.adapter,
|
||||
if (!(hostdev_name = virSCSIDeviceGetDevName(NULL,
|
||||
hostdev->source.subsys.u.scsi.adapter,
|
||||
hostdev->source.subsys.u.scsi.bus,
|
||||
hostdev->source.subsys.u.scsi.target,
|
||||
hostdev->source.subsys.u.scsi.unit)))
|
||||
@ -949,7 +950,8 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
|
||||
if (!(key = qemuGetSharedDeviceKey(disk->src)))
|
||||
goto cleanup;
|
||||
} else {
|
||||
if (!(dev_name = virSCSIDeviceGetDevName(hostdev->source.subsys.u.scsi.adapter,
|
||||
if (!(dev_name = virSCSIDeviceGetDevName(NULL,
|
||||
hostdev->source.subsys.u.scsi.adapter,
|
||||
hostdev->source.subsys.u.scsi.bus,
|
||||
hostdev->source.subsys.u.scsi.target,
|
||||
hostdev->source.subsys.u.scsi.unit)))
|
||||
@ -1053,7 +1055,8 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver,
|
||||
if (!(key = qemuGetSharedDeviceKey(disk->src)))
|
||||
goto cleanup;
|
||||
} else {
|
||||
if (!(dev_name = virSCSIDeviceGetDevName(hostdev->source.subsys.u.scsi.adapter,
|
||||
if (!(dev_name = virSCSIDeviceGetDevName(NULL,
|
||||
hostdev->source.subsys.u.scsi.adapter,
|
||||
hostdev->source.subsys.u.scsi.bus,
|
||||
hostdev->source.subsys.u.scsi.target,
|
||||
hostdev->source.subsys.u.scsi.unit)))
|
||||
@ -1137,7 +1140,8 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
|
||||
hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI))
|
||||
return 0;
|
||||
|
||||
if (!(hostdev_name = virSCSIDeviceGetDevName(hostdev->source.subsys.u.scsi.adapter,
|
||||
if (!(hostdev_name = virSCSIDeviceGetDevName(NULL,
|
||||
hostdev->source.subsys.u.scsi.adapter,
|
||||
hostdev->source.subsys.u.scsi.bus,
|
||||
hostdev->source.subsys.u.scsi.target,
|
||||
hostdev->source.subsys.u.scsi.unit)))
|
||||
|
@ -264,7 +264,8 @@ qemuUpdateActiveScsiHostdevs(virQEMUDriverPtr driver,
|
||||
hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)
|
||||
continue;
|
||||
|
||||
if (!(scsi = virSCSIDeviceNew(hostdev->source.subsys.u.scsi.adapter,
|
||||
if (!(scsi = virSCSIDeviceNew(NULL,
|
||||
hostdev->source.subsys.u.scsi.adapter,
|
||||
hostdev->source.subsys.u.scsi.bus,
|
||||
hostdev->source.subsys.u.scsi.target,
|
||||
hostdev->source.subsys.u.scsi.unit,
|
||||
@ -1102,7 +1103,8 @@ qemuPrepareHostdevSCSIDevices(virQEMUDriverPtr driver,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(scsi = virSCSIDeviceNew(hostdev->source.subsys.u.scsi.adapter,
|
||||
if (!(scsi = virSCSIDeviceNew(NULL,
|
||||
hostdev->source.subsys.u.scsi.adapter,
|
||||
hostdev->source.subsys.u.scsi.bus,
|
||||
hostdev->source.subsys.u.scsi.target,
|
||||
hostdev->source.subsys.u.scsi.unit,
|
||||
@ -1406,7 +1408,8 @@ qemuDomainReAttachHostScsiDevices(virQEMUDriverPtr driver,
|
||||
hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)
|
||||
continue;
|
||||
|
||||
if (!(scsi = virSCSIDeviceNew(hostdev->source.subsys.u.scsi.adapter,
|
||||
if (!(scsi = virSCSIDeviceNew(NULL,
|
||||
hostdev->source.subsys.u.scsi.adapter,
|
||||
hostdev->source.subsys.u.scsi.bus,
|
||||
hostdev->source.subsys.u.scsi.target,
|
||||
hostdev->source.subsys.u.scsi.unit,
|
||||
|
@ -829,7 +829,8 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
|
||||
|
||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
|
||||
virSCSIDevicePtr scsi =
|
||||
virSCSIDeviceNew(dev->source.subsys.u.scsi.adapter,
|
||||
virSCSIDeviceNew(NULL,
|
||||
dev->source.subsys.u.scsi.adapter,
|
||||
dev->source.subsys.u.scsi.bus,
|
||||
dev->source.subsys.u.scsi.target,
|
||||
dev->source.subsys.u.scsi.unit,
|
||||
|
@ -532,7 +532,8 @@ virSecurityDACSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
|
||||
|
||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
|
||||
virSCSIDevicePtr scsi =
|
||||
virSCSIDeviceNew(dev->source.subsys.u.scsi.adapter,
|
||||
virSCSIDeviceNew(NULL,
|
||||
dev->source.subsys.u.scsi.adapter,
|
||||
dev->source.subsys.u.scsi.bus,
|
||||
dev->source.subsys.u.scsi.target,
|
||||
dev->source.subsys.u.scsi.unit,
|
||||
@ -650,7 +651,8 @@ virSecurityDACRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr,
|
||||
|
||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
|
||||
virSCSIDevicePtr scsi =
|
||||
virSCSIDeviceNew(dev->source.subsys.u.scsi.adapter,
|
||||
virSCSIDeviceNew(NULL,
|
||||
dev->source.subsys.u.scsi.adapter,
|
||||
dev->source.subsys.u.scsi.bus,
|
||||
dev->source.subsys.u.scsi.target,
|
||||
dev->source.subsys.u.scsi.unit,
|
||||
|
@ -1350,7 +1350,8 @@ virSecuritySELinuxSetSecurityHostdevSubsysLabel(virDomainDefPtr def,
|
||||
|
||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
|
||||
virSCSIDevicePtr scsi =
|
||||
virSCSIDeviceNew(dev->source.subsys.u.scsi.adapter,
|
||||
virSCSIDeviceNew(NULL,
|
||||
dev->source.subsys.u.scsi.adapter,
|
||||
dev->source.subsys.u.scsi.bus,
|
||||
dev->source.subsys.u.scsi.target,
|
||||
dev->source.subsys.u.scsi.unit,
|
||||
@ -1542,7 +1543,8 @@ virSecuritySELinuxRestoreSecurityHostdevSubsysLabel(virSecurityManagerPtr mgr,
|
||||
|
||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
|
||||
virSCSIDevicePtr scsi =
|
||||
virSCSIDeviceNew(dev->source.subsys.u.scsi.adapter,
|
||||
virSCSIDeviceNew(NULL,
|
||||
dev->source.subsys.u.scsi.adapter,
|
||||
dev->source.subsys.u.scsi.bus,
|
||||
dev->source.subsys.u.scsi.target,
|
||||
dev->source.subsys.u.scsi.unit,
|
||||
|
@ -102,7 +102,8 @@ virSCSIDeviceGetAdapterId(const char *adapter,
|
||||
}
|
||||
|
||||
char *
|
||||
virSCSIDeviceGetSgName(const char *adapter,
|
||||
virSCSIDeviceGetSgName(const char *sysfs_prefix,
|
||||
const char *adapter,
|
||||
unsigned int bus,
|
||||
unsigned int target,
|
||||
unsigned int unit)
|
||||
@ -112,13 +113,14 @@ virSCSIDeviceGetSgName(const char *adapter,
|
||||
char *path = NULL;
|
||||
char *sg = NULL;
|
||||
unsigned int adapter_id;
|
||||
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
|
||||
|
||||
if (virSCSIDeviceGetAdapterId(adapter, &adapter_id) < 0)
|
||||
return NULL;
|
||||
|
||||
if (virAsprintf(&path,
|
||||
SYSFS_SCSI_DEVICES "/%d:%d:%d:%d/scsi_generic",
|
||||
adapter_id, bus, target, unit) < 0)
|
||||
"%s/%d:%d:%d:%d/scsi_generic",
|
||||
prefix, adapter_id, bus, target, unit) < 0)
|
||||
return NULL;
|
||||
|
||||
if (!(dir = opendir(path))) {
|
||||
@ -145,7 +147,8 @@ cleanup:
|
||||
* on failure.
|
||||
*/
|
||||
char *
|
||||
virSCSIDeviceGetDevName(const char *adapter,
|
||||
virSCSIDeviceGetDevName(const char *sysfs_prefix,
|
||||
const char *adapter,
|
||||
unsigned int bus,
|
||||
unsigned int target,
|
||||
unsigned int unit)
|
||||
@ -155,13 +158,14 @@ virSCSIDeviceGetDevName(const char *adapter,
|
||||
char *path = NULL;
|
||||
char *name = NULL;
|
||||
unsigned int adapter_id;
|
||||
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
|
||||
|
||||
if (virSCSIDeviceGetAdapterId(adapter, &adapter_id) < 0)
|
||||
return NULL;
|
||||
|
||||
if (virAsprintf(&path,
|
||||
SYSFS_SCSI_DEVICES "/%d:%d:%d:%d/block",
|
||||
adapter_id, bus, target, unit) < 0)
|
||||
"%s/%d:%d:%d:%d/block",
|
||||
prefix, adapter_id, bus, target, unit) < 0)
|
||||
return NULL;
|
||||
|
||||
if (!(dir = opendir(path))) {
|
||||
@ -185,7 +189,8 @@ cleanup:
|
||||
}
|
||||
|
||||
virSCSIDevicePtr
|
||||
virSCSIDeviceNew(const char *adapter,
|
||||
virSCSIDeviceNew(const char *sysfs_prefix,
|
||||
const char *adapter,
|
||||
unsigned int bus,
|
||||
unsigned int target,
|
||||
unsigned int unit,
|
||||
@ -198,6 +203,7 @@ virSCSIDeviceNew(const char *adapter,
|
||||
char *model_path = NULL;
|
||||
char *vendor = NULL;
|
||||
char *model = NULL;
|
||||
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
|
||||
|
||||
if (VIR_ALLOC(dev) < 0)
|
||||
return NULL;
|
||||
@ -208,7 +214,7 @@ virSCSIDeviceNew(const char *adapter,
|
||||
dev->readonly = readonly;
|
||||
dev->shareable = shareable;
|
||||
|
||||
if (!(sg = virSCSIDeviceGetSgName(adapter, bus, target, unit)))
|
||||
if (!(sg = virSCSIDeviceGetSgName(prefix, adapter, bus, target, unit)))
|
||||
goto cleanup;
|
||||
|
||||
if (virSCSIDeviceGetAdapterId(adapter, &dev->adapter) < 0)
|
||||
@ -227,9 +233,9 @@ virSCSIDeviceNew(const char *adapter,
|
||||
}
|
||||
|
||||
if (virAsprintf(&vendor_path,
|
||||
SYSFS_SCSI_DEVICES "/%s/vendor", dev->name) < 0 ||
|
||||
"%s/%s/vendor", prefix, dev->name) < 0 ||
|
||||
virAsprintf(&model_path,
|
||||
SYSFS_SCSI_DEVICES "/%s/model", dev->name) < 0)
|
||||
"%s/%s/model", prefix, dev->name) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virFileReadAll(vendor_path, 1024, &vendor) < 0)
|
||||
|
@ -33,16 +33,19 @@ typedef virSCSIDevice *virSCSIDevicePtr;
|
||||
typedef struct _virSCSIDeviceList virSCSIDeviceList;
|
||||
typedef virSCSIDeviceList *virSCSIDeviceListPtr;
|
||||
|
||||
char *virSCSIDeviceGetSgName(const char *adapter,
|
||||
char *virSCSIDeviceGetSgName(const char *sysfs_prefix,
|
||||
const char *adapter,
|
||||
unsigned int bus,
|
||||
unsigned int target,
|
||||
unsigned int unit);
|
||||
char *virSCSIDeviceGetDevName(const char *adapter,
|
||||
char *virSCSIDeviceGetDevName(const char *sysfs_prefix,
|
||||
const char *adapter,
|
||||
unsigned int bus,
|
||||
unsigned int target,
|
||||
unsigned int unit);
|
||||
|
||||
virSCSIDevicePtr virSCSIDeviceNew(const char *adapter,
|
||||
virSCSIDevicePtr virSCSIDeviceNew(const char *sysfs_prefix,
|
||||
const char *adapter,
|
||||
unsigned int bus,
|
||||
unsigned int target,
|
||||
unsigned int unit,
|
||||
|
@ -355,7 +355,8 @@ cleanup:
|
||||
|
||||
|
||||
static char *
|
||||
testSCSIDeviceGetSgName(const char *adapter ATTRIBUTE_UNUSED,
|
||||
testSCSIDeviceGetSgName(const char *sysfs_prefix ATTRIBUTE_UNUSED,
|
||||
const char *adapter ATTRIBUTE_UNUSED,
|
||||
unsigned int bus ATTRIBUTE_UNUSED,
|
||||
unsigned int target ATTRIBUTE_UNUSED,
|
||||
unsigned int unit ATTRIBUTE_UNUSED)
|
||||
|
Loading…
Reference in New Issue
Block a user