提交 99fdd434 编写于 作者: O Osier Yang

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
上级 67653160
...@@ -1340,6 +1340,42 @@ cleanup: ...@@ -1340,6 +1340,42 @@ cleanup:
return ret; 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) int qemuDriverAllocateID(virQEMUDriverPtr driver)
{ {
......
...@@ -305,6 +305,8 @@ int qemuRemoveSharedDevice(virQEMUDriverPtr driver, ...@@ -305,6 +305,8 @@ int qemuRemoveSharedDevice(virQEMUDriverPtr driver,
const char *name) const char *name)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
int qemuSetUnprivSGIO(virDomainDiskDefPtr disk);
int qemuDriverAllocateID(virQEMUDriverPtr driver); int qemuDriverAllocateID(virQEMUDriverPtr driver);
virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver); virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver);
......
...@@ -3203,43 +3203,6 @@ qemuProcessReconnectAll(virConnectPtr conn, virQEMUDriverPtr driver) ...@@ -3203,43 +3203,6 @@ qemuProcessReconnectAll(virConnectPtr conn, virQEMUDriverPtr driver)
virDomainObjListForEach(driver->domains, qemuProcessReconnectHelper, &data); 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 static int
qemuProcessVNCAllocatePorts(virQEMUDriverPtr driver, qemuProcessVNCAllocatePorts(virQEMUDriverPtr driver,
virDomainGraphicsDefPtr graphics) virDomainGraphicsDefPtr graphics)
......
...@@ -97,6 +97,5 @@ bool qemuProcessAutoDestroyActive(virQEMUDriverPtr driver, ...@@ -97,6 +97,5 @@ bool qemuProcessAutoDestroyActive(virQEMUDriverPtr driver,
virDomainObjPtr vm); virDomainObjPtr vm);
virBitmapPtr qemuPrepareCpumap(virQEMUDriverPtr driver, virBitmapPtr qemuPrepareCpumap(virQEMUDriverPtr driver,
virBitmapPtr nodemask); virBitmapPtr nodemask);
int qemuSetUnprivSGIO(virDomainDiskDefPtr disk);
#endif /* __QEMU_PROCESS_H__ */ #endif /* __QEMU_PROCESS_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册