c401cc
From c65be9f02e4c778fef97b390c0802545f2897e8a Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <c65be9f02e4c778fef97b390c0802545f2897e8a@dist-git>
c401cc
From: Osier Yang <jyang@redhat.com>
c401cc
Date: Sun, 2 Feb 2014 23:09:37 +0800
c401cc
Subject: [PATCH] util: Add "shareable" field for virSCSIDevice struct
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=957292
c401cc
c401cc
Unlike the host devices of other types, SCSI host device XML supports
c401cc
"shareable" tag. This patch introduces it for the virSCSIDevice struct
c401cc
for a later patch use (to detect if the SCSI device is shareable when
c401cc
preparing the SCSI host device in QEMU driver).
c401cc
(cherry picked from commit 2b66504ded244a249aa4a877b41c1ef9101ba28f)
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/libvirt_private.syms         |  1 +
c401cc
 src/qemu/qemu_cgroup.c           |  3 ++-
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               | 11 ++++++++++-
c401cc
 src/util/virscsi.h               |  4 +++-
c401cc
 8 files changed, 32 insertions(+), 11 deletions(-)
c401cc
c401cc
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
c401cc
index 5e65c35..f5ee380 100644
c401cc
--- a/src/libvirt_private.syms
c401cc
+++ b/src/libvirt_private.syms
c401cc
@@ -1852,6 +1852,7 @@ virSCSIDeviceGetDevName;
c401cc
 virSCSIDeviceGetName;
c401cc
 virSCSIDeviceGetReadonly;
c401cc
 virSCSIDeviceGetSgName;
c401cc
+virSCSIDeviceGetShareable;
c401cc
 virSCSIDeviceGetTarget;
c401cc
 virSCSIDeviceGetUnit;
c401cc
 virSCSIDeviceGetUsedBy;
c401cc
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
c401cc
index 3ebbeb7..4d7ade1 100644
c401cc
--- a/src/qemu/qemu_cgroup.c
c401cc
+++ b/src/qemu/qemu_cgroup.c
c401cc
@@ -294,7 +294,8 @@ qemuSetupHostdevCGroup(virDomainObjPtr vm,
c401cc
                                          dev->source.subsys.u.scsi.bus,
c401cc
                                          dev->source.subsys.u.scsi.target,
c401cc
                                          dev->source.subsys.u.scsi.unit,
c401cc
-                                         dev->readonly)) == NULL)
c401cc
+                                         dev->readonly,
c401cc
+                                         dev->shareable)) == NULL)
c401cc
                 goto cleanup;
c401cc
 
c401cc
             if (virSCSIDeviceFileIterate(scsi,
c401cc
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
c401cc
index b78f080..4d613b8 100644
c401cc
--- a/src/qemu/qemu_hostdev.c
c401cc
+++ b/src/qemu/qemu_hostdev.c
c401cc
@@ -267,7 +267,8 @@ qemuUpdateActiveScsiHostdevs(virQEMUDriverPtr driver,
c401cc
                                       hostdev->source.subsys.u.scsi.bus,
c401cc
                                       hostdev->source.subsys.u.scsi.target,
c401cc
                                       hostdev->source.subsys.u.scsi.unit,
c401cc
-                                      hostdev->readonly)))
c401cc
+                                      hostdev->readonly,
c401cc
+                                      hostdev->shareable)))
c401cc
             goto cleanup;
c401cc
 
c401cc
         virSCSIDeviceSetUsedBy(scsi, def->name);
c401cc
@@ -1096,7 +1097,8 @@ qemuPrepareHostdevSCSIDevices(virQEMUDriverPtr driver,
c401cc
                                       hostdev->source.subsys.u.scsi.bus,
c401cc
                                       hostdev->source.subsys.u.scsi.target,
c401cc
                                       hostdev->source.subsys.u.scsi.unit,
c401cc
-                                      hostdev->readonly)))
c401cc
+                                      hostdev->readonly,
c401cc
+                                      hostdev->shareable)))
c401cc
             goto cleanup;
c401cc
 
c401cc
         if (scsi && virSCSIDeviceListAdd(list, scsi) < 0) {
c401cc
@@ -1394,7 +1396,8 @@ qemuDomainReAttachHostScsiDevices(virQEMUDriverPtr driver,
c401cc
                                       hostdev->source.subsys.u.scsi.bus,
c401cc
                                       hostdev->source.subsys.u.scsi.target,
c401cc
                                       hostdev->source.subsys.u.scsi.unit,
c401cc
-                                      hostdev->readonly))) {
c401cc
+                                      hostdev->readonly,
c401cc
+                                      hostdev->shareable))) {
c401cc
             VIR_WARN("Unable to reattach SCSI device %s:%d:%d:%d on domain %s",
c401cc
                      hostdev->source.subsys.u.scsi.adapter,
c401cc
                      hostdev->source.subsys.u.scsi.bus,
c401cc
diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
c401cc
index eb80d23..9c97e3b 100644
c401cc
--- a/src/security/security_apparmor.c
c401cc
+++ b/src/security/security_apparmor.c
c401cc
@@ -833,7 +833,8 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
c401cc
                              dev->source.subsys.u.scsi.bus,
c401cc
                              dev->source.subsys.u.scsi.target,
c401cc
                              dev->source.subsys.u.scsi.unit,
c401cc
-                             dev->readonly);
c401cc
+                             dev->readonly,
c401cc
+                             dev->shareable);
c401cc
 
c401cc
          if (!scsi)
c401cc
              goto done;
c401cc
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
c401cc
index 6876bd5..26fa124 100644
c401cc
--- a/src/security/security_dac.c
c401cc
+++ b/src/security/security_dac.c
c401cc
@@ -532,7 +532,8 @@ virSecurityDACSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
c401cc
                              dev->source.subsys.u.scsi.bus,
c401cc
                              dev->source.subsys.u.scsi.target,
c401cc
                              dev->source.subsys.u.scsi.unit,
c401cc
-                             dev->readonly);
c401cc
+                             dev->readonly,
c401cc
+                             dev->shareable);
c401cc
 
c401cc
         if (!scsi)
c401cc
             goto done;
c401cc
@@ -649,7 +650,8 @@ virSecurityDACRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr,
c401cc
                              dev->source.subsys.u.scsi.bus,
c401cc
                              dev->source.subsys.u.scsi.target,
c401cc
                              dev->source.subsys.u.scsi.unit,
c401cc
-                             dev->readonly);
c401cc
+                             dev->readonly,
c401cc
+                             dev->shareable);
c401cc
 
c401cc
         if (!scsi)
c401cc
             goto done;
c401cc
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
c401cc
index ba008ca..dd25ba8 100644
c401cc
--- a/src/security/security_selinux.c
c401cc
+++ b/src/security/security_selinux.c
c401cc
@@ -1363,7 +1363,8 @@ virSecuritySELinuxSetSecurityHostdevSubsysLabel(virDomainDefPtr def,
c401cc
                              dev->source.subsys.u.scsi.bus,
c401cc
                              dev->source.subsys.u.scsi.target,
c401cc
                              dev->source.subsys.u.scsi.unit,
c401cc
-                             dev->readonly);
c401cc
+                             dev->readonly,
c401cc
+                             dev->shareable);
c401cc
 
c401cc
         if (!scsi)
c401cc
             goto done;
c401cc
@@ -1554,7 +1555,8 @@ virSecuritySELinuxRestoreSecurityHostdevSubsysLabel(virSecurityManagerPtr mgr,
c401cc
                              dev->source.subsys.u.scsi.bus,
c401cc
                              dev->source.subsys.u.scsi.target,
c401cc
                              dev->source.subsys.u.scsi.unit,
c401cc
-                             dev->readonly);
c401cc
+                             dev->readonly,
c401cc
+                             dev->shareable);
c401cc
 
c401cc
             if (!scsi)
c401cc
                 goto done;
c401cc
diff --git a/src/util/virscsi.c b/src/util/virscsi.c
c401cc
index 3950c62..4036db8 100644
c401cc
--- a/src/util/virscsi.c
c401cc
+++ b/src/util/virscsi.c
c401cc
@@ -58,6 +58,7 @@ struct _virSCSIDevice {
c401cc
     const char *used_by; /* name of the domain using this dev */
c401cc
 
c401cc
     bool readonly;
c401cc
+    bool shareable;
c401cc
 };
c401cc
 
c401cc
 struct _virSCSIDeviceList {
c401cc
@@ -185,7 +186,8 @@ virSCSIDeviceNew(const char *adapter,
c401cc
                  unsigned int bus,
c401cc
                  unsigned int target,
c401cc
                  unsigned int unit,
c401cc
-                 bool readonly)
c401cc
+                 bool readonly,
c401cc
+                 bool shareable)
c401cc
 {
c401cc
     virSCSIDevicePtr dev, ret = NULL;
c401cc
     char *sg = NULL;
c401cc
@@ -201,6 +203,7 @@ virSCSIDeviceNew(const char *adapter,
c401cc
     dev->target = target;
c401cc
     dev->unit = unit;
c401cc
     dev->readonly = readonly;
c401cc
+    dev->shareable= shareable;
c401cc
 
c401cc
     if (!(sg = virSCSIDeviceGetSgName(adapter, bus, target, unit)))
c401cc
         goto cleanup;
c401cc
@@ -311,6 +314,12 @@ virSCSIDeviceGetReadonly(virSCSIDevicePtr dev)
c401cc
     return dev->readonly;
c401cc
 }
c401cc
 
c401cc
+bool
c401cc
+virSCSIDeviceGetShareable(virSCSIDevicePtr dev)
c401cc
+{
c401cc
+    return dev->shareable;
c401cc
+}
c401cc
+
c401cc
 int
c401cc
 virSCSIDeviceFileIterate(virSCSIDevicePtr dev,
c401cc
                          virSCSIDeviceFileActor actor,
c401cc
diff --git a/src/util/virscsi.h b/src/util/virscsi.h
c401cc
index cce5df4..84890be 100644
c401cc
--- a/src/util/virscsi.h
c401cc
+++ b/src/util/virscsi.h
c401cc
@@ -46,7 +46,8 @@ virSCSIDevicePtr virSCSIDeviceNew(const char *adapter,
c401cc
                                   unsigned int bus,
c401cc
                                   unsigned int target,
c401cc
                                   unsigned int unit,
c401cc
-                                  bool readonly);
c401cc
+                                  bool readonly,
c401cc
+                                  bool shareable);
c401cc
 
c401cc
 void virSCSIDeviceFree(virSCSIDevicePtr dev);
c401cc
 void virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev, const char *name);
c401cc
@@ -57,6 +58,7 @@ unsigned int virSCSIDeviceGetBus(virSCSIDevicePtr dev);
c401cc
 unsigned int virSCSIDeviceGetTarget(virSCSIDevicePtr dev);
c401cc
 unsigned int virSCSIDeviceGetUnit(virSCSIDevicePtr dev);
c401cc
 bool virSCSIDeviceGetReadonly(virSCSIDevicePtr dev);
c401cc
+bool virSCSIDeviceGetShareable(virSCSIDevicePtr dev);
c401cc
 
c401cc
 /*
c401cc
  * Callback that will be invoked once for each file
c401cc
-- 
c401cc
1.8.5.4
c401cc