* being used and in the future the hostdev information.
*/
static int
-qemuCheckUnprivSGIO(GHashTable *sharedDevices,
- const char *device_path,
- int sgio)
+qemuCheckUnprivSGIO(GHashTable *sharedDevices G_GNUC_UNUSED,
+ const char *device_path G_GNUC_UNUSED,
+ int sgio G_GNUC_UNUSED)
{
- g_autofree char *sysfs_path = NULL;
- g_autofree char *key = NULL;
- int val;
-
- if (!(sysfs_path = virGetUnprivSGIOSysfsPath(device_path, NULL)))
- return -1;
-
/* It can't be conflict if unpriv_sgio is not supported by kernel. */
- if (!virFileExists(sysfs_path))
- return 0;
-
- if (!(key = qemuGetSharedDeviceKey(device_path)))
- return -1;
-
- /* It can't be conflict if no other domain is sharing it. */
- if (!(virHashLookup(sharedDevices, key)))
- return 0;
-
- if (virGetDeviceUnprivSGIO(device_path, NULL, &val) < 0)
- return -1;
-
- /* Error message on failure needs to be handled in caller
- * since there is more specific knowledge of device
- */
- if (!((val == 0 &&
- (sgio == VIR_DOMAIN_DEVICE_SGIO_FILTERED ||
- sgio == VIR_DOMAIN_DEVICE_SGIO_DEFAULT)) ||
- (val == 1 &&
- sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))) {
- return -2;
- }
-
return 0;
}
{
virDomainDiskDef *disk = NULL;
virDomainHostdevDef *hostdev = NULL;
- g_autofree char *sysfs_path = NULL;
const char *path = NULL;
int val = -1;
return 0;
}
- if (!(sysfs_path = virGetUnprivSGIOSysfsPath(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);
* 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) {
+ if (val == 1) {
int curr_val;
if (virGetDeviceUnprivSGIO(path, NULL, &curr_val) < 0)
}
#endif
-#define SYSFS_DEV_BLOCK_PATH "/sys/dev/block"
-
-char *
-virGetUnprivSGIOSysfsPath(const char *path,
- const char *sysfs_dir)
-{
- int maj, min;
- int rc;
-
- if ((rc = virGetDeviceID(path, &maj, &min)) < 0) {
- virReportSystemError(-rc,
- _("Unable to get device ID '%s'"),
- path);
- return NULL;
- }
-
- return g_strdup_printf("%s/%d:%d/queue/unpriv_sgio",
- sysfs_dir ? sysfs_dir : SYSFS_DEV_BLOCK_PATH, maj,
- min);
-}
-
int
-virSetDeviceUnprivSGIO(const char *path,
- const char *sysfs_dir,
- int unpriv_sgio)
+virSetDeviceUnprivSGIO(const char *path G_GNUC_UNUSED,
+ const char *sysfs_dir G_GNUC_UNUSED,
+ int unpriv_sgio G_GNUC_UNUSED)
{
- char *sysfs_path = NULL;
- char *val = NULL;
- int ret = -1;
- int rc;
-
- if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, sysfs_dir)))
- return -1;
-
- if (!virFileExists(sysfs_path)) {
- virReportError(VIR_ERR_OPERATION_INVALID, "%s",
- _("unpriv_sgio is not supported by this kernel"));
- goto cleanup;
- }
-
- val = g_strdup_printf("%d", unpriv_sgio);
-
- if ((rc = virFileWriteStr(sysfs_path, val, 0)) < 0) {
- virReportSystemError(-rc, _("failed to set %s"), sysfs_path);
- goto cleanup;
- }
-
- ret = 0;
- cleanup:
- VIR_FREE(sysfs_path);
- VIR_FREE(val);
- return ret;
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("unpriv_sgio is not supported by this kernel"));
+ return -1;
}
int
-virGetDeviceUnprivSGIO(const char *path,
- const char *sysfs_dir,
- int *unpriv_sgio)
+virGetDeviceUnprivSGIO(const char *path G_GNUC_UNUSED,
+ const char *sysfs_dir G_GNUC_UNUSED,
+ int *unpriv_sgio G_GNUC_UNUSED)
{
- char *sysfs_path = NULL;
- char *buf = NULL;
- char *tmp = NULL;
- int ret = -1;
-
- if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, sysfs_dir)))
- return -1;
-
- if (!virFileExists(sysfs_path)) {
- virReportError(VIR_ERR_OPERATION_INVALID, "%s",
- _("unpriv_sgio is not supported by this kernel"));
- goto cleanup;
- }
-
- if (virFileReadAll(sysfs_path, 1024, &buf) < 0)
- goto cleanup;
-
- if ((tmp = strchr(buf, '\n')))
- *tmp = '\0';
-
- if (virStrToLong_i(buf, NULL, 10, unpriv_sgio) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to parse value of %s"), sysfs_path);
- goto cleanup;
- }
-
- ret = 0;
- cleanup:
- VIR_FREE(sysfs_path);
- VIR_FREE(buf);
- return ret;
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("unpriv_sgio is not supported by this kernel"));
+ return -1;
}