render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c401cc
From d673797628091c365d603b306db81c63bda22e96 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <d673797628091c365d603b306db81c63bda22e96@dist-git>
c401cc
From: Osier Yang <jyang@redhat.com>
c401cc
Date: Sun, 2 Feb 2014 23:09:40 +0800
c401cc
Subject: [PATCH] util: Add one argument for several scsi utils
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=957292
c401cc
c401cc
To support passing the path of the test data to the utils, one
c401cc
more argument is added to virSCSIDeviceGetSgName,
c401cc
virSCSIDeviceGetDevName, and virSCSIDeviceNew, and the related
c401cc
code is changed accordingly.
c401cc
c401cc
Later tests for the scsi utils will be based on this patch.
c401cc
c401cc
Signed-off-by: Osier Yang <jyang@redhat.com>
c401cc
(cherry picked from commit 10c9ceff6d07f65773ef638bd36fe1d6a5f3a5ac)
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/qemu/qemu_cgroup.c           |  3 ++-
c401cc
 src/qemu/qemu_command.c          |  3 ++-
c401cc
 src/qemu/qemu_command.h          |  3 ++-
c401cc
 src/qemu/qemu_conf.c             | 12 ++++++++----
c401cc
 src/qemu/qemu_hostdev.c          |  9 ++++++---
c401cc
 src/security/security_apparmor.c |  3 ++-
c401cc
 src/security/security_dac.c      |  6 ++++--
c401cc
 src/security/security_selinux.c  |  6 ++++--
c401cc
 src/util/virscsi.c               | 26 ++++++++++++++++----------
c401cc
 src/util/virscsi.h               |  9 ++++++---
c401cc
 tests/testutilsqemu.c            |  3 ++-
c401cc
 11 files changed, 54 insertions(+), 29 deletions(-)
c401cc
c401cc
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
c401cc
index 4d7ade1..e0e1041 100644
c401cc
--- a/src/qemu/qemu_cgroup.c
c401cc
+++ b/src/qemu/qemu_cgroup.c
c401cc
@@ -290,7 +290,8 @@ qemuSetupHostdevCGroup(virDomainObjPtr vm,
c401cc
             break;
c401cc
 
c401cc
         case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
c401cc
-            if ((scsi = virSCSIDeviceNew(dev->source.subsys.u.scsi.adapter,
c401cc
+            if ((scsi = virSCSIDeviceNew(NULL,
c401cc
+                                         dev->source.subsys.u.scsi.adapter,
c401cc
                                          dev->source.subsys.u.scsi.bus,
c401cc
                                          dev->source.subsys.u.scsi.target,
c401cc
                                          dev->source.subsys.u.scsi.unit,
c401cc
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
c401cc
index debafa2..b5729a4 100644
c401cc
--- a/src/qemu/qemu_command.c
c401cc
+++ b/src/qemu/qemu_command.c
c401cc
@@ -5608,7 +5608,8 @@ qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
c401cc
     virBuffer buf = VIR_BUFFER_INITIALIZER;
c401cc
     char *sg = NULL;
c401cc
 
c401cc
-    sg = (callbacks->qemuGetSCSIDeviceSgName)(dev->source.subsys.u.scsi.adapter,
c401cc
+    sg = (callbacks->qemuGetSCSIDeviceSgName)(NULL,
c401cc
+                                              dev->source.subsys.u.scsi.adapter,
c401cc
                                               dev->source.subsys.u.scsi.bus,
c401cc
                                               dev->source.subsys.u.scsi.target,
c401cc
                                               dev->source.subsys.u.scsi.unit);
c401cc
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
c401cc
index decc940..39da555 100644
c401cc
--- a/src/qemu/qemu_command.h
c401cc
+++ b/src/qemu/qemu_command.h
c401cc
@@ -57,7 +57,8 @@
c401cc
 typedef struct _qemuBuildCommandLineCallbacks qemuBuildCommandLineCallbacks;
c401cc
 typedef qemuBuildCommandLineCallbacks *qemuBuildCommandLineCallbacksPtr;
c401cc
 struct _qemuBuildCommandLineCallbacks {
c401cc
-    char * (*qemuGetSCSIDeviceSgName) (const char *adapter,
c401cc
+    char * (*qemuGetSCSIDeviceSgName) (const char *sysfs_prefix,
c401cc
+                                       const char *adapter,
c401cc
                                        unsigned int bus,
c401cc
                                        unsigned int target,
c401cc
                                        unsigned int unit);
c401cc
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
c401cc
index e45180a..ba32959 100644
c401cc
--- a/src/qemu/qemu_conf.c
c401cc
+++ b/src/qemu/qemu_conf.c
c401cc
@@ -726,7 +726,8 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
c401cc
     } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
c401cc
         hostdev = dev->data.hostdev;
c401cc
 
c401cc
-        if (!(hostdev_name = virSCSIDeviceGetDevName(hostdev->source.subsys.u.scsi.adapter,
c401cc
+        if (!(hostdev_name = virSCSIDeviceGetDevName(NULL,
c401cc
+                                                     hostdev->source.subsys.u.scsi.adapter,
c401cc
                                                      hostdev->source.subsys.u.scsi.bus,
c401cc
                                                      hostdev->source.subsys.u.scsi.target,
c401cc
                                                      hostdev->source.subsys.u.scsi.unit)))
c401cc
@@ -914,7 +915,8 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
c401cc
         if (!(key = qemuGetSharedDeviceKey(disk->src)))
c401cc
             goto cleanup;
c401cc
     } else {
c401cc
-        if (!(dev_name = virSCSIDeviceGetDevName(hostdev->source.subsys.u.scsi.adapter,
c401cc
+        if (!(dev_name = virSCSIDeviceGetDevName(NULL,
c401cc
+                                                 hostdev->source.subsys.u.scsi.adapter,
c401cc
                                                  hostdev->source.subsys.u.scsi.bus,
c401cc
                                                  hostdev->source.subsys.u.scsi.target,
c401cc
                                                  hostdev->source.subsys.u.scsi.unit)))
c401cc
@@ -1018,7 +1020,8 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver,
c401cc
         if (!(key = qemuGetSharedDeviceKey(disk->src)))
c401cc
             goto cleanup;
c401cc
     } else {
c401cc
-        if (!(dev_name = virSCSIDeviceGetDevName(hostdev->source.subsys.u.scsi.adapter,
c401cc
+        if (!(dev_name = virSCSIDeviceGetDevName(NULL,
c401cc
+                                                 hostdev->source.subsys.u.scsi.adapter,
c401cc
                                                  hostdev->source.subsys.u.scsi.bus,
c401cc
                                                  hostdev->source.subsys.u.scsi.target,
c401cc
                                                  hostdev->source.subsys.u.scsi.unit)))
c401cc
@@ -1102,7 +1105,8 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
c401cc
               hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI))
c401cc
             return 0;
c401cc
 
c401cc
-        if (!(hostdev_name = virSCSIDeviceGetDevName(hostdev->source.subsys.u.scsi.adapter,
c401cc
+        if (!(hostdev_name = virSCSIDeviceGetDevName(NULL,
c401cc
+                                                     hostdev->source.subsys.u.scsi.adapter,
c401cc
                                                      hostdev->source.subsys.u.scsi.bus,
c401cc
                                                      hostdev->source.subsys.u.scsi.target,
c401cc
                                                      hostdev->source.subsys.u.scsi.unit)))
c401cc
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
c401cc
index 7282b15..49e17e1 100644
c401cc
--- a/src/qemu/qemu_hostdev.c
c401cc
+++ b/src/qemu/qemu_hostdev.c
c401cc
@@ -264,7 +264,8 @@ qemuUpdateActiveScsiHostdevs(virQEMUDriverPtr driver,
c401cc
             hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)
c401cc
             continue;
c401cc
 
c401cc
-        if (!(scsi = virSCSIDeviceNew(hostdev->source.subsys.u.scsi.adapter,
c401cc
+        if (!(scsi = virSCSIDeviceNew(NULL,
c401cc
+                                      hostdev->source.subsys.u.scsi.adapter,
c401cc
                                       hostdev->source.subsys.u.scsi.bus,
c401cc
                                       hostdev->source.subsys.u.scsi.target,
c401cc
                                       hostdev->source.subsys.u.scsi.unit,
c401cc
@@ -1101,7 +1102,8 @@ qemuPrepareHostdevSCSIDevices(virQEMUDriverPtr driver,
c401cc
             goto cleanup;
c401cc
         }
c401cc
 
c401cc
-        if (!(scsi = virSCSIDeviceNew(hostdev->source.subsys.u.scsi.adapter,
c401cc
+        if (!(scsi = virSCSIDeviceNew(NULL,
c401cc
+                                      hostdev->source.subsys.u.scsi.adapter,
c401cc
                                       hostdev->source.subsys.u.scsi.bus,
c401cc
                                       hostdev->source.subsys.u.scsi.target,
c401cc
                                       hostdev->source.subsys.u.scsi.unit,
c401cc
@@ -1405,7 +1407,8 @@ qemuDomainReAttachHostScsiDevices(virQEMUDriverPtr driver,
c401cc
             hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)
c401cc
             continue;
c401cc
 
c401cc
-        if (!(scsi = virSCSIDeviceNew(hostdev->source.subsys.u.scsi.adapter,
c401cc
+        if (!(scsi = virSCSIDeviceNew(NULL,
c401cc
+                                      hostdev->source.subsys.u.scsi.adapter,
c401cc
                                       hostdev->source.subsys.u.scsi.bus,
c401cc
                                       hostdev->source.subsys.u.scsi.target,
c401cc
                                       hostdev->source.subsys.u.scsi.unit,
c401cc
diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
c401cc
index 9c97e3b..fdf0acc 100644
c401cc
--- a/src/security/security_apparmor.c
c401cc
+++ b/src/security/security_apparmor.c
c401cc
@@ -829,7 +829,8 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
c401cc
 
c401cc
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
c401cc
         virSCSIDevicePtr scsi =
c401cc
-            virSCSIDeviceNew(dev->source.subsys.u.scsi.adapter,
c401cc
+            virSCSIDeviceNew(NULL,
c401cc
+                             dev->source.subsys.u.scsi.adapter,
c401cc
                              dev->source.subsys.u.scsi.bus,
c401cc
                              dev->source.subsys.u.scsi.target,
c401cc
                              dev->source.subsys.u.scsi.unit,
c401cc
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
c401cc
index 26fa124..2a44ceb 100644
c401cc
--- a/src/security/security_dac.c
c401cc
+++ b/src/security/security_dac.c
c401cc
@@ -528,7 +528,8 @@ virSecurityDACSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
c401cc
 
c401cc
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
c401cc
         virSCSIDevicePtr scsi =
c401cc
-            virSCSIDeviceNew(dev->source.subsys.u.scsi.adapter,
c401cc
+            virSCSIDeviceNew(NULL,
c401cc
+                             dev->source.subsys.u.scsi.adapter,
c401cc
                              dev->source.subsys.u.scsi.bus,
c401cc
                              dev->source.subsys.u.scsi.target,
c401cc
                              dev->source.subsys.u.scsi.unit,
c401cc
@@ -646,7 +647,8 @@ virSecurityDACRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr,
c401cc
 
c401cc
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
c401cc
         virSCSIDevicePtr scsi =
c401cc
-            virSCSIDeviceNew(dev->source.subsys.u.scsi.adapter,
c401cc
+            virSCSIDeviceNew(NULL,
c401cc
+                             dev->source.subsys.u.scsi.adapter,
c401cc
                              dev->source.subsys.u.scsi.bus,
c401cc
                              dev->source.subsys.u.scsi.target,
c401cc
                              dev->source.subsys.u.scsi.unit,
c401cc
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
c401cc
index dd25ba8..91c5ffb 100644
c401cc
--- a/src/security/security_selinux.c
c401cc
+++ b/src/security/security_selinux.c
c401cc
@@ -1359,7 +1359,8 @@ virSecuritySELinuxSetSecurityHostdevSubsysLabel(virDomainDefPtr def,
c401cc
 
c401cc
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
c401cc
         virSCSIDevicePtr scsi =
c401cc
-            virSCSIDeviceNew(dev->source.subsys.u.scsi.adapter,
c401cc
+            virSCSIDeviceNew(NULL,
c401cc
+                             dev->source.subsys.u.scsi.adapter,
c401cc
                              dev->source.subsys.u.scsi.bus,
c401cc
                              dev->source.subsys.u.scsi.target,
c401cc
                              dev->source.subsys.u.scsi.unit,
c401cc
@@ -1551,7 +1552,8 @@ virSecuritySELinuxRestoreSecurityHostdevSubsysLabel(virSecurityManagerPtr mgr,
c401cc
 
c401cc
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
c401cc
         virSCSIDevicePtr scsi =
c401cc
-            virSCSIDeviceNew(dev->source.subsys.u.scsi.adapter,
c401cc
+            virSCSIDeviceNew(NULL,
c401cc
+                             dev->source.subsys.u.scsi.adapter,
c401cc
                              dev->source.subsys.u.scsi.bus,
c401cc
                              dev->source.subsys.u.scsi.target,
c401cc
                              dev->source.subsys.u.scsi.unit,
c401cc
diff --git a/src/util/virscsi.c b/src/util/virscsi.c
c401cc
index 0d496ae..f4a28e0 100644
c401cc
--- a/src/util/virscsi.c
c401cc
+++ b/src/util/virscsi.c
c401cc
@@ -102,7 +102,8 @@ virSCSIDeviceGetAdapterId(const char *adapter,
c401cc
 }
c401cc
 
c401cc
 char *
c401cc
-virSCSIDeviceGetSgName(const char *adapter,
c401cc
+virSCSIDeviceGetSgName(const char *sysfs_prefix,
c401cc
+                       const char *adapter,
c401cc
                        unsigned int bus,
c401cc
                        unsigned int target,
c401cc
                        unsigned int unit)
c401cc
@@ -112,13 +113,14 @@ virSCSIDeviceGetSgName(const char *adapter,
c401cc
     char *path = NULL;
c401cc
     char *sg = NULL;
c401cc
     unsigned int adapter_id;
c401cc
+    const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
c401cc
 
c401cc
     if (virSCSIDeviceGetAdapterId(adapter, &adapter_id) < 0)
c401cc
         return NULL;
c401cc
 
c401cc
     if (virAsprintf(&path,
c401cc
-                    SYSFS_SCSI_DEVICES "/%d:%d:%d:%d/scsi_generic",
c401cc
-                    adapter_id, bus, target, unit) < 0)
c401cc
+                    "%s/%d:%d:%d:%d/scsi_generic",
c401cc
+                    prefix, adapter_id, bus, target, unit) < 0)
c401cc
         return NULL;
c401cc
 
c401cc
     if (!(dir = opendir(path))) {
c401cc
@@ -145,7 +147,8 @@ cleanup:
c401cc
  * on failure.
c401cc
  */
c401cc
 char *
c401cc
-virSCSIDeviceGetDevName(const char *adapter,
c401cc
+virSCSIDeviceGetDevName(const char *sysfs_prefix,
c401cc
+                        const char *adapter,
c401cc
                         unsigned int bus,
c401cc
                         unsigned int target,
c401cc
                         unsigned int unit)
c401cc
@@ -155,13 +158,14 @@ virSCSIDeviceGetDevName(const char *adapter,
c401cc
     char *path = NULL;
c401cc
     char *name = NULL;
c401cc
     unsigned int adapter_id;
c401cc
+    const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
c401cc
 
c401cc
     if (virSCSIDeviceGetAdapterId(adapter, &adapter_id) < 0)
c401cc
         return NULL;
c401cc
 
c401cc
     if (virAsprintf(&path,
c401cc
-                    SYSFS_SCSI_DEVICES "/%d:%d:%d:%d/block",
c401cc
-                    adapter_id, bus, target, unit) < 0)
c401cc
+                    "%s/%d:%d:%d:%d/block",
c401cc
+                    prefix, adapter_id, bus, target, unit) < 0)
c401cc
         return NULL;
c401cc
 
c401cc
     if (!(dir = opendir(path))) {
c401cc
@@ -185,7 +189,8 @@ cleanup:
c401cc
 }
c401cc
 
c401cc
 virSCSIDevicePtr
c401cc
-virSCSIDeviceNew(const char *adapter,
c401cc
+virSCSIDeviceNew(const char *sysfs_prefix,
c401cc
+                 const char *adapter,
c401cc
                  unsigned int bus,
c401cc
                  unsigned int target,
c401cc
                  unsigned int unit,
c401cc
@@ -198,6 +203,7 @@ virSCSIDeviceNew(const char *adapter,
c401cc
     char *model_path = NULL;
c401cc
     char *vendor = NULL;
c401cc
     char *model = NULL;
c401cc
+    const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
c401cc
 
c401cc
     if (VIR_ALLOC(dev) < 0)
c401cc
         return NULL;
c401cc
@@ -208,7 +214,7 @@ virSCSIDeviceNew(const char *adapter,
c401cc
     dev->readonly = readonly;
c401cc
     dev->shareable = shareable;
c401cc
 
c401cc
-    if (!(sg = virSCSIDeviceGetSgName(adapter, bus, target, unit)))
c401cc
+    if (!(sg = virSCSIDeviceGetSgName(prefix, adapter, bus, target, unit)))
c401cc
         goto cleanup;
c401cc
 
c401cc
     if (virSCSIDeviceGetAdapterId(adapter, &dev->adapter) < 0)
c401cc
@@ -227,9 +233,9 @@ virSCSIDeviceNew(const char *adapter,
c401cc
     }
c401cc
 
c401cc
     if (virAsprintf(&vendor_path,
c401cc
-                    SYSFS_SCSI_DEVICES "/%s/vendor", dev->name) < 0 ||
c401cc
+                    "%s/%s/vendor", prefix, dev->name) < 0 ||
c401cc
         virAsprintf(&model_path,
c401cc
-                    SYSFS_SCSI_DEVICES "/%s/model", dev->name) < 0)
c401cc
+                    "%s/%s/model", prefix, dev->name) < 0)
c401cc
         goto cleanup;
c401cc
 
c401cc
     if (virFileReadAll(vendor_path, 1024, &vendor) < 0)
c401cc
diff --git a/src/util/virscsi.h b/src/util/virscsi.h
c401cc
index 5bb91ed..ce9d3b4 100644
c401cc
--- a/src/util/virscsi.h
c401cc
+++ b/src/util/virscsi.h
c401cc
@@ -33,16 +33,19 @@ typedef virSCSIDevice *virSCSIDevicePtr;
c401cc
 typedef struct _virSCSIDeviceList virSCSIDeviceList;
c401cc
 typedef virSCSIDeviceList *virSCSIDeviceListPtr;
c401cc
 
c401cc
-char *virSCSIDeviceGetSgName(const char *adapter,
c401cc
+char *virSCSIDeviceGetSgName(const char *sysfs_prefix,
c401cc
+                             const char *adapter,
c401cc
                              unsigned int bus,
c401cc
                              unsigned int target,
c401cc
                              unsigned int unit);
c401cc
-char *virSCSIDeviceGetDevName(const char *adapter,
c401cc
+char *virSCSIDeviceGetDevName(const char *sysfs_prefix,
c401cc
+                              const char *adapter,
c401cc
                               unsigned int bus,
c401cc
                               unsigned int target,
c401cc
                               unsigned int unit);
c401cc
 
c401cc
-virSCSIDevicePtr virSCSIDeviceNew(const char *adapter,
c401cc
+virSCSIDevicePtr virSCSIDeviceNew(const char *sysfs_prefix,
c401cc
+                                  const char *adapter,
c401cc
                                   unsigned int bus,
c401cc
                                   unsigned int target,
c401cc
                                   unsigned int unit,
c401cc
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
c401cc
index fac83b2..86e7ee7 100644
c401cc
--- a/tests/testutilsqemu.c
c401cc
+++ b/tests/testutilsqemu.c
c401cc
@@ -292,7 +292,8 @@ cleanup:
c401cc
 
c401cc
 
c401cc
 static char *
c401cc
-testSCSIDeviceGetSgName(const char *adapter ATTRIBUTE_UNUSED,
c401cc
+testSCSIDeviceGetSgName(const char *sysfs_prefix ATTRIBUTE_UNUSED,
c401cc
+                        const char *adapter ATTRIBUTE_UNUSED,
c401cc
                         unsigned int bus ATTRIBUTE_UNUSED,
c401cc
                         unsigned int target ATTRIBUTE_UNUSED,
c401cc
                         unsigned int unit ATTRIBUTE_UNUSED)
c401cc
-- 
c401cc
1.8.5.4
c401cc