From 99fdd434bcb2f939af565a14abafc34274f83edb Mon Sep 17 00:00:00 2001 From: Osier Yang Date: Sat, 4 May 2013 02:07:41 +0800 Subject: [PATCH] qemu: Move qemuSetUnprivSGIO into qemu_conf.c 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 | 37 ------------------------------------- src/qemu/qemu_process.h | 1 - 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 44901384bc..21685e1ca0 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1340,6 +1340,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 4568e6cc9f..25350ddec5 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -305,6 +305,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 f9229b6a3d..c25769da59 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3203,43 +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 qemuProcessVNCAllocatePorts(virQEMUDriverPtr driver, virDomainGraphicsDefPtr graphics) diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index cb1a8bf8ce..d4768fcdf4 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__ */ -- GitLab