This ignores the default "filtered" if unpriv_sgio is not supported
by kernel, but for explicit request "filtered", it error out for
domain starting.
---
src/libvirt_private.syms | 1 +
src/qemu/qemu_driver.c | 15 +++++++++------
src/qemu/qemu_process.c | 31 +++++++++++++++++++++++++++++++
src/qemu/qemu_process.h | 1 +
src/util/util.c | 2 +-
src/util/util.h | 2 ++
6 files changed, 45 insertions(+), 7 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index e500ea9..3276f72 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1288,6 +1288,7 @@ virGetDeviceUnprivSGIO;
virGetGroupID;
virGetGroupName;
virGetHostname;
+virGetUnprivSGIOSysfsPath;
virGetUserCacheDirectory;
virGetUserConfigDirectory;
virGetUserDirectory;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a313f5e..98b6b59 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6046,12 +6046,15 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
NULLSTR(disk->src));
}
- if (ret == 0 &&
- disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK &&
- disk->shared) {
- if (qemuAddSharedDisk(driver->sharedDisks, disk->src) < 0)
- VIR_WARN("Failed to add disk '%s' to shared disk table",
- disk->src);
+ if (ret == 0) {
+ if (disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK && disk->shared) {
+ if (qemuAddSharedDisk(driver->sharedDisks, disk->src) < 0)
+ VIR_WARN("Failed to add disk '%s' to shared disk
table",
+ disk->src);
+ }
+
+ if (qemuSetUnprivSGIO(disk) < 0)
+ VIR_WARN("Failed to set unpriv_sgio of disk '%s'",
disk->src);
}
end:
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index a84df07..66637d1 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3385,6 +3385,34 @@ qemuProcessReconnectAll(virConnectPtr conn, virQEMUDriverPtr
driver)
virHashForEach(driver->domains.objs, qemuProcessReconnectHelper, &data);
}
+int
+qemuSetUnprivSGIO(virDomainDiskDefPtr disk)
+{
+ int val = -1;
+
+ if (disk->sgio)
+ val = (disk->sgio == VIR_DOMAIN_DISK_SGIO_UNFILTERED);
+
+ /* Ignore the setting if unpriv_sgio is not supported by the
+ * kernel, otherwise defaults to filter the SG_IO commands,
+ * I.E. Set unpriv_sgio to 0.
+ */
+ if (disk->sgio == VIR_DOMAIN_DISK_SGIO_DEFAULT &&
+ disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
+ char *sysfs_path = NULL;
+
+ if ((sysfs_path = virGetUnprivSGIOSysfsPath(disk->src, NULL)) &&
+ virFileExists(sysfs_path))
+ val = 0;
+ VIR_FREE(sysfs_path);
+ }
+
+ if (val >= 0 && virSetDeviceUnprivSGIO(disk->src, NULL, val) < 0)
+ return -1;
+
+ return 0;
+}
+
int qemuProcessStart(virConnectPtr conn,
virQEMUDriverPtr driver,
virDomainObjPtr vm,
@@ -3734,6 +3762,9 @@ int qemuProcessStart(virConnectPtr conn,
if (qemuAddSharedDisk(driver->sharedDisks, disk->src) < 0)
goto cleanup;
}
+
+ if (qemuSetUnprivSGIO(disk) < 0)
+ goto cleanup;
}
virCommandSetPreExecHook(cmd, qemuProcessHook, &hookData);
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index c12df32..52a298d 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -98,5 +98,6 @@ bool qemuProcessAutoDestroyActive(virQEMUDriverPtr driver,
virDomainObjPtr vm);
virBitmapPtr qemuPrepareCpumap(virQEMUDriverPtr driver,
virBitmapPtr nodemask);
+int qemuSetUnprivSGIO(virDomainDiskDefPtr disk);
#endif /* __QEMU_PROCESS_H__ */
diff --git a/src/util/util.c b/src/util/util.c
index 06c7e33..bc6d17f 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -3171,7 +3171,7 @@ virGetDeviceID(const char *path ATRRIBUTE_UNUSED,
#define SYSFS_DEV_BLOCK_PATH "/sys/dev/block"
-static char *
+char *
virGetUnprivSGIOSysfsPath(const char *path,
const char *sysfs_dir)
{
diff --git a/src/util/util.h b/src/util/util.h
index 71003f7..7f873d6 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -291,5 +291,7 @@ int virSetDeviceUnprivSGIO(const char *path,
int virGetDeviceUnprivSGIO(const char *path,
const char *sysfs_dir,
int *unpriv_sgio);
+char * virGetUnprivSGIOSysfsPath(const char *path,
+ const char *sysfs_dir);
#endif /* __VIR_UTIL_H__ */
--
1.7.7.6