unpriv_sgio setting is tight with the shared device helpers, let's put them together in qemu_conf.c --- src/qemu/qemu_conf.c | 36 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_conf.h | 2 ++ src/qemu/qemu_process.c | 38 -------------------------------------- src/qemu/qemu_process.h | 1 - 4 files changed, 38 insertions(+), 39 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 67b6d82..b7dea57 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1308,6 +1308,42 @@ cleanup: return ret; } +int +qemuSetUnprivSGIO(virDomainDiskDefPtr disk) +{ + char *sysfs_path = NULL; + int val = -1; + int ret = 0; + + /* "sgio" is only valid for block disk; cdrom + * and floopy disk can have empty source. + */ + if (!disk->src || + disk->device != VIR_DOMAIN_DISK_DEVICE_LUN || + (disk->type != VIR_DOMAIN_DISK_TYPE_BLOCK && + !(disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME && + disk->srcpool && + disk->srcpool->voltype == VIR_STORAGE_VOL_BLOCK))) + return 0; + + sysfs_path = virGetUnprivSGIOSysfsPath(disk->src, NULL); + if (sysfs_path == NULL) + return -1; + + /* By default, filter the SG_IO commands, i.e. set unpriv_sgio to 0. */ + val = (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED); + + /* Do not do anything if unpriv_sgio is not supported by the kernel and the + * whitelist is enabled. But if requesting unfiltered access, always call + * virSetDeviceUnprivSGIO, to report an error for unsupported unpriv_sgio. + */ + if ((virFileExists(sysfs_path) || val == 1) && + virSetDeviceUnprivSGIO(disk->src, NULL, val) < 0) + ret = -1; + + VIR_FREE(sysfs_path); + return ret; +} int qemuDriverAllocateID(virQEMUDriverPtr driver) { diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index c004f7f..5e76739 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -299,6 +299,8 @@ int qemuRemoveSharedDevice(virQEMUDriverPtr driver, const char *name) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); +int qemuSetUnprivSGIO(virDomainDiskDefPtr disk); + int qemuDriverAllocateID(virQEMUDriverPtr driver); virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 28427af..eb42df1 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3203,44 +3203,6 @@ qemuProcessReconnectAll(virConnectPtr conn, virQEMUDriverPtr driver) virDomainObjListForEach(driver->domains, qemuProcessReconnectHelper, &data); } -int -qemuSetUnprivSGIO(virDomainDiskDefPtr disk) -{ - char *sysfs_path = NULL; - int val = -1; - int ret = 0; - - /* "sgio" is only valid for block disk; cdrom - * and floopy disk can have empty source. - */ - if (!disk->src || - disk->device != VIR_DOMAIN_DISK_DEVICE_LUN || - (disk->type != VIR_DOMAIN_DISK_TYPE_BLOCK && - !(disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME && - disk->srcpool && - disk->srcpool->voltype == VIR_STORAGE_VOL_BLOCK))) - return 0; - - sysfs_path = virGetUnprivSGIOSysfsPath(disk->src, NULL); - if (sysfs_path == NULL) - return -1; - - /* By default, filter the SG_IO commands, i.e. set unpriv_sgio to 0. */ - val = (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED); - - /* Do not do anything if unpriv_sgio is not supported by the kernel and the - * whitelist is enabled. But if requesting unfiltered access, always call - * virSetDeviceUnprivSGIO, to report an error for unsupported unpriv_sgio. - */ - if ((virFileExists(sysfs_path) || val == 1) && - virSetDeviceUnprivSGIO(disk->src, NULL, val) < 0) - ret = -1; - - VIR_FREE(sysfs_path); - return ret; -} - - static int qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver, virQEMUDriverConfigPtr cfg, diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index cb1a8bf..d4768fc 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -97,6 +97,5 @@ bool qemuProcessAutoDestroyActive(virQEMUDriverPtr driver, virDomainObjPtr vm); virBitmapPtr qemuPrepareCpumap(virQEMUDriverPtr driver, virBitmapPtr nodemask); -int qemuSetUnprivSGIO(virDomainDiskDefPtr disk); #endif /* __QEMU_PROCESS_H__ */ -- 1.8.1.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list