[libvirt PATCH 0/7] remove support for unpriv_sgio

This feature was never merged in upstream kernel and only made it to upstream libvirt by mistakes. Remove it as well as the 'sharedDevices' hash table that was only used for this purpose. The 'sgio' attribute is preserved for compatibility reasons and its 'filtered' value is left intact. An error is added to the XML validator for the 'unfiltered' value, which means 'unpriv_sgio' Ján Tomko (7): util: remove virGetUnprivSGIOSysfsPath conf: reject unfiltered sgio on validation qemu: remove all use of SGIO qemu: remove sharedDevices hash table util: remove virGetDeviceID util: remove {Get,Set}UnprivSGIO qemu: simplify qemuProcessSetupRawIO src/conf/domain_validate.c | 11 + src/libvirt_private.syms | 4 - src/qemu/qemu_conf.c | 448 ------------------ src/qemu/qemu_conf.h | 37 -- src/qemu/qemu_driver.c | 3 - src/qemu/qemu_hostdev.c | 31 -- src/qemu/qemu_hotplug.c | 23 - src/qemu/qemu_process.c | 36 +- src/util/virutil.c | 122 ----- src/util/virutil.h | 12 - tests/qemuhotplugmock.c | 17 - .../disk-scsi-lun-passthrough-sgio.xml | 35 -- tests/qemuxml2argvdata/hostdev-scsi-rawio.xml | 37 -- tests/qemuxml2argvdata/hostdev-scsi-sgio.xml | 37 -- .../disk-scsi-lun-passthrough-sgio.xml | 46 -- .../qemuxml2xmloutdata/hostdev-scsi-rawio.xml | 47 -- .../qemuxml2xmloutdata/hostdev-scsi-sgio.xml | 47 -- tests/qemuxml2xmltest.c | 11 - 18 files changed, 14 insertions(+), 990 deletions(-) delete mode 100644 tests/qemuxml2argvdata/disk-scsi-lun-passthrough-sgio.xml delete mode 100644 tests/qemuxml2argvdata/hostdev-scsi-rawio.xml delete mode 100644 tests/qemuxml2argvdata/hostdev-scsi-sgio.xml delete mode 100644 tests/qemuxml2xmloutdata/disk-scsi-lun-passthrough-sgio.xml delete mode 100644 tests/qemuxml2xmloutdata/hostdev-scsi-rawio.xml delete mode 100644 tests/qemuxml2xmloutdata/hostdev-scsi-sgio.xml -- 2.31.1

unpriv_sgio was a downstream-only feature in certain RHEL versions. The libvirt support was merged upstream by mistake. Remove the function that constructs the sysfs path and assume it does not exist in all the callers. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/libvirt_private.syms | 1 - src/qemu/qemu_conf.c | 43 ++---------------- src/util/virutil.c | 96 +++++----------------------------------- src/util/virutil.h | 2 - 4 files changed, 16 insertions(+), 126 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 5b76e66e61..932dbf4f72 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3521,7 +3521,6 @@ virGetPassword; virGetSelfLastChanged; virGetSystemPageSize; virGetSystemPageSizeKB; -virGetUnprivSGIOSysfsPath; virGetUserCacheDirectory; virGetUserConfigDirectory; virGetUserDirectory; diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 6077457ff4..73497ad848 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1484,42 +1484,11 @@ qemuGetSharedDeviceKey(const char *device_path) * 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; } @@ -1840,7 +1809,6 @@ qemuSetUnprivSGIO(virDomainDeviceDef *dev) { virDomainDiskDef *disk = NULL; virDomainHostdevDef *hostdev = NULL; - g_autofree char *sysfs_path = NULL; const char *path = NULL; int val = -1; @@ -1873,9 +1841,6 @@ qemuSetUnprivSGIO(virDomainDeviceDef *dev) 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); @@ -1883,7 +1848,7 @@ qemuSetUnprivSGIO(virDomainDeviceDef *dev) * 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) diff --git a/src/util/virutil.c b/src/util/virutil.c index e04f1343d8..0acdc052c3 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1354,96 +1354,24 @@ virGetDeviceID(const char *path G_GNUC_UNUSED, } #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; } diff --git a/src/util/virutil.h b/src/util/virutil.h index 854b494890..bd2c69bfaa 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -125,8 +125,6 @@ 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); int virParseOwnershipIds(const char *label, uid_t *uidPtr, gid_t *gidPtr); -- 2.31.1

On Thu, Jan 13, 2022 at 06:47:36PM +0100, Ján Tomko wrote:
unpriv_sgio was a downstream-only feature in certain RHEL versions.
Which ones? No need to be vague :) -- Andrea Bolognani / Red Hat / Virtualization

No kernels supported by upstream libvirt have the feature. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/conf/domain_validate.c | 11 +++++ .../disk-scsi-lun-passthrough-sgio.xml | 35 -------------- tests/qemuxml2argvdata/hostdev-scsi-rawio.xml | 37 --------------- tests/qemuxml2argvdata/hostdev-scsi-sgio.xml | 37 --------------- .../disk-scsi-lun-passthrough-sgio.xml | 46 ------------------ .../qemuxml2xmloutdata/hostdev-scsi-rawio.xml | 47 ------------------- .../qemuxml2xmloutdata/hostdev-scsi-sgio.xml | 47 ------------------- tests/qemuxml2xmltest.c | 11 ----- 8 files changed, 11 insertions(+), 260 deletions(-) delete mode 100644 tests/qemuxml2argvdata/disk-scsi-lun-passthrough-sgio.xml delete mode 100644 tests/qemuxml2argvdata/hostdev-scsi-rawio.xml delete mode 100644 tests/qemuxml2argvdata/hostdev-scsi-sgio.xml delete mode 100644 tests/qemuxml2xmloutdata/disk-scsi-lun-passthrough-sgio.xml delete mode 100644 tests/qemuxml2xmloutdata/hostdev-scsi-rawio.xml delete mode 100644 tests/qemuxml2xmloutdata/hostdev-scsi-sgio.xml diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index a4271f1247..e9baf1d41a 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -621,6 +621,12 @@ virDomainDiskDefValidate(const virDomainDef *def, if (virDomainDiskDefValidateSource(disk->src) < 0) return -1; + if (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("unfiltered sgio is no longer supported")); + return -1; + } + /* Validate LUN configuration */ if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) { if (virDomainDiskDefSourceLUNValidate(disk->src) < 0) @@ -1917,6 +1923,11 @@ virDomainHostdevDefValidate(const virDomainHostdevDef *hostdev) "address type")); return -1; } + if (hostdev->source.subsys.u.scsi.sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("unfiltered sgio is no longer supported")); + return -1; + } break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: if (hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && diff --git a/tests/qemuxml2argvdata/disk-scsi-lun-passthrough-sgio.xml b/tests/qemuxml2argvdata/disk-scsi-lun-passthrough-sgio.xml deleted file mode 100644 index 3e561642a3..0000000000 --- a/tests/qemuxml2argvdata/disk-scsi-lun-passthrough-sgio.xml +++ /dev/null @@ -1,35 +0,0 @@ -<domain type='qemu'> - <name>QEMUGuest1</name> - <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> - <memory unit='KiB'>219136</memory> - <currentMemory unit='KiB'>219136</currentMemory> - <vcpu placement='static'>1</vcpu> - <os> - <type arch='i686' machine='pc'>hvm</type> - <boot dev='hd'/> - </os> - <clock offset='utc'/> - <on_poweroff>destroy</on_poweroff> - <on_reboot>restart</on_reboot> - <on_crash>destroy</on_crash> - <devices> - <emulator>/usr/bin/qemu-system-i386</emulator> - <disk type='block' device='lun' rawio='no' sgio='unfiltered'> - <source dev='/dev/HostVG/QEMUGuest1'/> - <target dev='hda' bus='scsi'/> - <address type='drive' controller='0' bus='0' target='0' unit='0'/> - </disk> - <disk type='block' device='lun' sgio='filtered'> - <source dev='/dev/HostVG/QEMUGuest2'/> - <target dev='hdb' bus='scsi'/> - <address type='drive' controller='0' bus='0' target='1' unit='1'/> - </disk> - <controller type='scsi' index='0' model='virtio-scsi'/> - <controller type='scsi' index='1' model='lsilogic'/> - <controller type='usb' index='0'/> - <controller type='pci' index='0' model='pci-root'/> - <input type='mouse' bus='ps2'/> - <input type='keyboard' bus='ps2'/> - <memballoon model='virtio'/> - </devices> -</domain> diff --git a/tests/qemuxml2argvdata/hostdev-scsi-rawio.xml b/tests/qemuxml2argvdata/hostdev-scsi-rawio.xml deleted file mode 100644 index eb60e550f0..0000000000 --- a/tests/qemuxml2argvdata/hostdev-scsi-rawio.xml +++ /dev/null @@ -1,37 +0,0 @@ -<domain type='qemu'> - <name>QEMUGuest2</name> - <uuid>c7a5fdbd-edaf-9466-926a-d65c16db1809</uuid> - <memory unit='KiB'>219100</memory> - <currentMemory unit='KiB'>219100</currentMemory> - <vcpu placement='static'>1</vcpu> - <os> - <type arch='i686' machine='pc'>hvm</type> - <boot dev='hd'/> - </os> - <clock offset='utc'/> - <on_poweroff>destroy</on_poweroff> - <on_reboot>restart</on_reboot> - <on_crash>destroy</on_crash> - <devices> - <emulator>/usr/bin/qemu-system-i386</emulator> - <disk type='block' device='disk'> - <source dev='/dev/HostVG/QEMUGuest2'/> - <target dev='hda' bus='ide'/> - <address type='drive' controller='0' bus='0' target='0' unit='0'/> - </disk> - <controller type='scsi' index='0' model='virtio-scsi'/> - <controller type='usb' index='0'/> - <controller type='ide' index='0'/> - <controller type='pci' index='0' model='pci-root'/> - <input type='mouse' bus='ps2'/> - <input type='keyboard' bus='ps2'/> - <hostdev mode='subsystem' type='scsi' managed='yes' sgio='unfiltered' rawio='yes'> - <source> - <adapter name='scsi_host0'/> - <address bus='0' target='0' unit='0'/> - </source> - <address type='drive' controller='0' bus='0' target='4' unit='8'/> - </hostdev> - <memballoon model='virtio'/> - </devices> -</domain> diff --git a/tests/qemuxml2argvdata/hostdev-scsi-sgio.xml b/tests/qemuxml2argvdata/hostdev-scsi-sgio.xml deleted file mode 100644 index bfc5346807..0000000000 --- a/tests/qemuxml2argvdata/hostdev-scsi-sgio.xml +++ /dev/null @@ -1,37 +0,0 @@ -<domain type='qemu'> - <name>QEMUGuest2</name> - <uuid>c7a5fdbd-edaf-9466-926a-d65c16db1809</uuid> - <memory unit='KiB'>219100</memory> - <currentMemory unit='KiB'>219100</currentMemory> - <vcpu placement='static'>1</vcpu> - <os> - <type arch='i686' machine='pc'>hvm</type> - <boot dev='hd'/> - </os> - <clock offset='utc'/> - <on_poweroff>destroy</on_poweroff> - <on_reboot>restart</on_reboot> - <on_crash>destroy</on_crash> - <devices> - <emulator>/usr/bin/qemu-system-i386</emulator> - <disk type='block' device='disk'> - <source dev='/dev/HostVG/QEMUGuest2'/> - <target dev='hda' bus='ide'/> - <address type='drive' controller='0' bus='0' target='0' unit='0'/> - </disk> - <controller type='scsi' index='0' model='virtio-scsi'/> - <controller type='usb' index='0'/> - <controller type='ide' index='0'/> - <controller type='pci' index='0' model='pci-root'/> - <input type='mouse' bus='ps2'/> - <input type='keyboard' bus='ps2'/> - <hostdev mode='subsystem' type='scsi' managed='yes' sgio='unfiltered'> - <source> - <adapter name='scsi_host0'/> - <address bus='0' target='0' unit='0'/> - </source> - <address type='drive' controller='0' bus='0' target='4' unit='8'/> - </hostdev> - <memballoon model='virtio'/> - </devices> -</domain> diff --git a/tests/qemuxml2xmloutdata/disk-scsi-lun-passthrough-sgio.xml b/tests/qemuxml2xmloutdata/disk-scsi-lun-passthrough-sgio.xml deleted file mode 100644 index 2b62595805..0000000000 --- a/tests/qemuxml2xmloutdata/disk-scsi-lun-passthrough-sgio.xml +++ /dev/null @@ -1,46 +0,0 @@ -<domain type='qemu'> - <name>QEMUGuest1</name> - <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> - <memory unit='KiB'>219136</memory> - <currentMemory unit='KiB'>219136</currentMemory> - <vcpu placement='static'>1</vcpu> - <os> - <type arch='i686' machine='pc'>hvm</type> - <boot dev='hd'/> - </os> - <clock offset='utc'/> - <on_poweroff>destroy</on_poweroff> - <on_reboot>restart</on_reboot> - <on_crash>destroy</on_crash> - <devices> - <emulator>/usr/bin/qemu-system-i386</emulator> - <disk type='block' device='lun' rawio='no' sgio='unfiltered'> - <driver name='qemu' type='raw'/> - <source dev='/dev/HostVG/QEMUGuest1'/> - <target dev='hda' bus='scsi'/> - <address type='drive' controller='0' bus='0' target='0' unit='0'/> - </disk> - <disk type='block' device='lun' sgio='filtered'> - <driver name='qemu' type='raw'/> - <source dev='/dev/HostVG/QEMUGuest2'/> - <target dev='hdb' bus='scsi'/> - <address type='drive' controller='0' bus='0' target='1' unit='1'/> - </disk> - <controller type='scsi' index='0' model='virtio-scsi'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> - </controller> - <controller type='scsi' index='1' model='lsilogic'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> - </controller> - <controller type='usb' index='0'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> - </controller> - <controller type='pci' index='0' model='pci-root'/> - <input type='mouse' bus='ps2'/> - <input type='keyboard' bus='ps2'/> - <audio id='1' type='none'/> - <memballoon model='virtio'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> - </memballoon> - </devices> -</domain> diff --git a/tests/qemuxml2xmloutdata/hostdev-scsi-rawio.xml b/tests/qemuxml2xmloutdata/hostdev-scsi-rawio.xml deleted file mode 100644 index b9f3fc1446..0000000000 --- a/tests/qemuxml2xmloutdata/hostdev-scsi-rawio.xml +++ /dev/null @@ -1,47 +0,0 @@ -<domain type='qemu'> - <name>QEMUGuest2</name> - <uuid>c7a5fdbd-edaf-9466-926a-d65c16db1809</uuid> - <memory unit='KiB'>219100</memory> - <currentMemory unit='KiB'>219100</currentMemory> - <vcpu placement='static'>1</vcpu> - <os> - <type arch='i686' machine='pc'>hvm</type> - <boot dev='hd'/> - </os> - <clock offset='utc'/> - <on_poweroff>destroy</on_poweroff> - <on_reboot>restart</on_reboot> - <on_crash>destroy</on_crash> - <devices> - <emulator>/usr/bin/qemu-system-i386</emulator> - <disk type='block' device='disk'> - <driver name='qemu' type='raw'/> - <source dev='/dev/HostVG/QEMUGuest2'/> - <target dev='hda' bus='ide'/> - <address type='drive' controller='0' bus='0' target='0' unit='0'/> - </disk> - <controller type='scsi' index='0' model='virtio-scsi'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> - </controller> - <controller type='usb' index='0'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> - </controller> - <controller type='ide' index='0'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> - </controller> - <controller type='pci' index='0' model='pci-root'/> - <input type='mouse' bus='ps2'/> - <input type='keyboard' bus='ps2'/> - <audio id='1' type='none'/> - <hostdev mode='subsystem' type='scsi' managed='yes' sgio='unfiltered' rawio='yes'> - <source> - <adapter name='scsi_host0'/> - <address bus='0' target='0' unit='0'/> - </source> - <address type='drive' controller='0' bus='0' target='4' unit='8'/> - </hostdev> - <memballoon model='virtio'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> - </memballoon> - </devices> -</domain> diff --git a/tests/qemuxml2xmloutdata/hostdev-scsi-sgio.xml b/tests/qemuxml2xmloutdata/hostdev-scsi-sgio.xml deleted file mode 100644 index 748d5ac543..0000000000 --- a/tests/qemuxml2xmloutdata/hostdev-scsi-sgio.xml +++ /dev/null @@ -1,47 +0,0 @@ -<domain type='qemu'> - <name>QEMUGuest2</name> - <uuid>c7a5fdbd-edaf-9466-926a-d65c16db1809</uuid> - <memory unit='KiB'>219100</memory> - <currentMemory unit='KiB'>219100</currentMemory> - <vcpu placement='static'>1</vcpu> - <os> - <type arch='i686' machine='pc'>hvm</type> - <boot dev='hd'/> - </os> - <clock offset='utc'/> - <on_poweroff>destroy</on_poweroff> - <on_reboot>restart</on_reboot> - <on_crash>destroy</on_crash> - <devices> - <emulator>/usr/bin/qemu-system-i386</emulator> - <disk type='block' device='disk'> - <driver name='qemu' type='raw'/> - <source dev='/dev/HostVG/QEMUGuest2'/> - <target dev='hda' bus='ide'/> - <address type='drive' controller='0' bus='0' target='0' unit='0'/> - </disk> - <controller type='scsi' index='0' model='virtio-scsi'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> - </controller> - <controller type='usb' index='0'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> - </controller> - <controller type='ide' index='0'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> - </controller> - <controller type='pci' index='0' model='pci-root'/> - <input type='mouse' bus='ps2'/> - <input type='keyboard' bus='ps2'/> - <audio id='1' type='none'/> - <hostdev mode='subsystem' type='scsi' managed='yes' sgio='unfiltered'> - <source> - <adapter name='scsi_host0'/> - <address bus='0' target='0' unit='0'/> - </source> - <address type='drive' controller='0' bus='0' target='4' unit='8'/> - </hostdev> - <memballoon model='virtio'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> - </memballoon> - </devices> -</domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index fb438269b9..68d74fa4f1 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -617,11 +617,6 @@ mymain(void) ARG_END); DO_TEST_NOCAPS("numad-static-vcpu-no-numatune"); - DO_TEST("disk-scsi-lun-passthrough-sgio", - QEMU_CAPS_SCSI_LSI, - QEMU_CAPS_VIRTIO_SCSI, - QEMU_CAPS_SCSI_DISK_WWN, - QEMU_CAPS_SCSI_BLOCK); DO_TEST("disk-scsi-disk-vpd", QEMU_CAPS_SCSI_LSI, QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_SCSI_DISK_WWN); DO_TEST_NOCAPS("disk-source-pool"); @@ -1002,12 +997,6 @@ mymain(void) DO_TEST("hostdev-scsi-shareable", QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_SCSI_LSI); - DO_TEST("hostdev-scsi-sgio", - QEMU_CAPS_VIRTIO_SCSI, - QEMU_CAPS_SCSI_LSI); - DO_TEST("hostdev-scsi-rawio", - QEMU_CAPS_VIRTIO_SCSI, - QEMU_CAPS_SCSI_LSI); DO_TEST("hostdev-scsi-autogen-address", QEMU_CAPS_VIRTIO_SCSI, -- 2.31.1

Now that the 'unfiltered' attribute is rejected by the validator, remove all the code that deals with the feature. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/libvirt_private.syms | 2 - src/qemu/qemu_conf.c | 121 --------------------------------------- src/qemu/qemu_conf.h | 2 - src/qemu/qemu_hostdev.c | 3 - src/qemu/qemu_hotplug.c | 3 - src/qemu/qemu_process.c | 3 - 6 files changed, 134 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 932dbf4f72..48e8ef6c72 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3511,7 +3511,6 @@ virDoubleToStr; virFormatIntDecimal; virFormatIntPretty; virGetDeviceID; -virGetDeviceUnprivSGIO; virGetGroupID; virGetGroupList; virGetGroupName; @@ -3545,7 +3544,6 @@ virPipeQuiet; virScaleInteger; virSetBlocking; virSetCloseExec; -virSetDeviceUnprivSGIO; virSetInherit; virSetNonBlock; virSetSockReuseAddr; diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 73497ad848..28cbdd6e61 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1472,65 +1472,6 @@ qemuGetSharedDeviceKey(const char *device_path) return g_strdup_printf("%d:%d", maj, min); } -/* - * Make necessary checks for the need to check and for the current setting - * of the 'unpriv_sgio' value for the device_path passed. - * - * Returns: - * 0 - Success - * -1 - Some failure which would already have been messaged - * -2 - Mismatch with the "shared" sgio setting - needs to be messaged - * by caller since it has context of which type of disk resource is - * being used and in the future the hostdev information. - */ -static int -qemuCheckUnprivSGIO(GHashTable *sharedDevices G_GNUC_UNUSED, - const char *device_path G_GNUC_UNUSED, - int sgio G_GNUC_UNUSED) -{ - /* It can't be conflict if unpriv_sgio is not supported by kernel. */ - return 0; -} - - -/* Check if a shared device's setting conflicts with the conf - * used by other domain(s). Currently only checks the sgio - * setting. Note that this should only be called for disk with - * block source if the device type is disk. - * - * Returns 0 if no conflicts, otherwise returns -1. - */ -static int -qemuCheckSharedDisk(GHashTable *sharedDevices, - virDomainDiskDef *disk) -{ - int ret; - - if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN) - return 0; - - if ((ret = qemuCheckUnprivSGIO(sharedDevices, disk->src->path, - disk->sgio)) < 0) { - if (ret == -2) { - if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_VOLUME) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("sgio of shared disk 'pool=%s' 'volume=%s' " - "conflicts with other active domains"), - disk->src->srcpool->pool, - disk->src->srcpool->volume); - } else { - virReportError(VIR_ERR_OPERATION_INVALID, - _("sgio of shared disk '%s' conflicts with " - "other active domains"), - disk->src->path); - } - } - return -1; - } - - return 0; -} - bool qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntry *entry, @@ -1647,9 +1588,6 @@ qemuSharedDiskAddRemoveInternal(virQEMUDriver *driver, goto cleanup; if (addDisk) { - if (qemuCheckSharedDisk(driver->sharedDevices, disk) < 0) - goto cleanup; - if (qemuSharedDeviceEntryInsert(driver, key, name) < 0) goto cleanup; } else { @@ -1804,65 +1742,6 @@ qemuRemoveSharedDevice(virQEMUDriver *driver, } -int -qemuSetUnprivSGIO(virDomainDeviceDef *dev) -{ - virDomainDiskDef *disk = NULL; - virDomainHostdevDef *hostdev = NULL; - const char *path = NULL; - int val = -1; - - /* "sgio" is only valid for block disk; cdrom - * and floopy disk can have empty source. - */ - if (dev->type == VIR_DOMAIN_DEVICE_DISK) { - disk = dev->data.disk; - - if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN || - !virStorageSourceIsBlockLocal(disk->src)) - return 0; - - path = virDomainDiskGetSource(disk); - } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) { - hostdev = dev->data.hostdev; - - if (!qemuIsSharedHostdev(hostdev)) - return 0; - - if (hostdev->source.subsys.u.scsi.sgio) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("'sgio' is not supported for SCSI " - "generic device yet ")); - return -1; - } - - return 0; - } else { - return 0; - } - - /* 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 (val == 1) { - int curr_val; - - if (virGetDeviceUnprivSGIO(path, NULL, &curr_val) < 0) - return -1; - - if (curr_val != val && - virSetDeviceUnprivSGIO(path, NULL, val) < 0) { - return -1; - } - } - - return 0; -} - int qemuDriverAllocateID(virQEMUDriver *driver) { return g_atomic_int_add(&driver->lastvmid, 1) + 1; diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 2f64e39a18..5961b0b205 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -376,8 +376,6 @@ int qemuRemoveSharedDisk(virQEMUDriver *driver, const char *name) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); -int qemuSetUnprivSGIO(virDomainDeviceDef *dev); - int qemuDriverAllocateID(virQEMUDriver *driver); virDomainXMLOption *virQEMUDriverCreateXMLConf(virQEMUDriver *driver, const char *defsecmodel); diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index 00f301f941..5461de459a 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -289,9 +289,6 @@ qemuHostdevPrepareSCSIDevices(virQEMUDriver *driver, if (qemuAddSharedDevice(driver, &dev, name) < 0) return -1; - - if (qemuSetUnprivSGIO(&dev) < 0) - return -1; } return virHostdevPrepareSCSIDevices(hostdev_mgr, QEMU_DRIVER_NAME, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 04c6600f26..0dd3121221 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -980,9 +980,6 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriver *driver, if (qemuAddSharedDevice(driver, dev, vm->def->name) < 0) goto cleanup; - if (qemuSetUnprivSGIO(dev) < 0) - goto cleanup; - if (qemuDomainDetermineDiskChain(driver, vm, disk, NULL, true) < 0) goto cleanup; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 5c9ca0fe4f..b425acfec1 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5046,9 +5046,6 @@ qemuProcessSetupRawIO(virQEMUDriver *driver, dev.data.disk = disk; if (qemuAddSharedDevice(driver, &dev, vm->def->name) < 0) goto cleanup; - - if (qemuSetUnprivSGIO(&dev) < 0) - goto cleanup; } /* If rawio not already set, check hostdevs as well */ -- 2.31.1

Its only use was to check conflicts of the sgio attributes between devices shared with other domains. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/qemu/qemu_conf.c | 292 ---------------------------------------- src/qemu/qemu_conf.h | 35 ----- src/qemu/qemu_driver.c | 3 - src/qemu/qemu_hostdev.c | 28 ---- src/qemu/qemu_hotplug.c | 20 --- src/qemu/qemu_process.c | 27 +--- 6 files changed, 1 insertion(+), 404 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 28cbdd6e61..81449b8b77 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1450,298 +1450,6 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriver *driver, } -struct _qemuSharedDeviceEntry { - size_t ref; - char **domains; /* array of domain names */ -}; - -/* Construct the hash key for sharedDevices as "major:minor" */ -char * -qemuGetSharedDeviceKey(const char *device_path) -{ - int maj, min; - int rc; - - if ((rc = virGetDeviceID(device_path, &maj, &min)) < 0) { - virReportSystemError(-rc, - _("Unable to get minor number of device '%s'"), - device_path); - return NULL; - } - - return g_strdup_printf("%d:%d", maj, min); -} - - -bool -qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntry *entry, - const char *name, - int *idx) -{ - size_t i; - - for (i = 0; i < entry->ref; i++) { - if (STREQ(entry->domains[i], name)) { - if (idx) - *idx = i; - return true; - } - } - - return false; -} - -void -qemuSharedDeviceEntryFree(void *payload) -{ - qemuSharedDeviceEntry *entry = payload; - size_t i; - - if (!entry) - return; - - for (i = 0; i < entry->ref; i++) - g_free(entry->domains[i]); - g_free(entry->domains); - g_free(entry); -} - - -static int -qemuSharedDeviceEntryInsert(virQEMUDriver *driver, - const char *key, - const char *name) -{ - qemuSharedDeviceEntry *entry = NULL; - - if ((entry = virHashLookup(driver->sharedDevices, key))) { - /* Nothing to do if the shared scsi host device is already - * recorded in the table. - */ - if (!qemuSharedDeviceEntryDomainExists(entry, name, NULL)) { - VIR_EXPAND_N(entry->domains, entry->ref, 1); - entry->domains[entry->ref - 1] = g_strdup(name); - } - } else { - entry = g_new0(qemuSharedDeviceEntry, 1); - entry->domains = g_new0(char *, 1); - - entry->domains[0] = g_strdup(name); - - entry->ref = 1; - - if (virHashAddEntry(driver->sharedDevices, key, entry) < 0) - goto error; - } - - return 0; - - error: - qemuSharedDeviceEntryFree(entry); - return -1; -} - - -static int -qemuSharedDeviceEntryRemove(virQEMUDriver *driver, - const char *key, - const char *name) -{ - qemuSharedDeviceEntry *entry = NULL; - int idx; - - if (!(entry = virHashLookup(driver->sharedDevices, key))) - return -1; - - /* Nothing to do if the shared disk is not recorded in the table. */ - if (!qemuSharedDeviceEntryDomainExists(entry, name, &idx)) - return 0; - - if (entry->ref != 1) { - VIR_FREE(entry->domains[idx]); - VIR_DELETE_ELEMENT(entry->domains, idx, entry->ref); - } else { - ignore_value(virHashRemoveEntry(driver->sharedDevices, key)); - } - - return 0; -} - - -static int -qemuSharedDiskAddRemoveInternal(virQEMUDriver *driver, - virDomainDiskDef *disk, - const char *name, - bool addDisk) -{ - g_autofree char *key = NULL; - int ret = -1; - - if (virStorageSourceIsEmpty(disk->src) || - !disk->src->shared || - !virStorageSourceIsBlockLocal(disk->src)) - return 0; - - qemuDriverLock(driver); - - if (!(key = qemuGetSharedDeviceKey(virDomainDiskGetSource(disk)))) - goto cleanup; - - if (addDisk) { - if (qemuSharedDeviceEntryInsert(driver, key, name) < 0) - goto cleanup; - } else { - if (qemuSharedDeviceEntryRemove(driver, key, name) < 0) - goto cleanup; - } - - ret = 0; - cleanup: - qemuDriverUnlock(driver); - return ret; -} - - -/* qemuAddSharedDisk: - * @driver: Pointer to qemu driver struct - * @src: disk source - * @name: The domain name - * - * Increase ref count and add the domain name into the list which - * records all the domains that use the shared device if the entry - * already exists, otherwise add a new entry. - */ -int -qemuAddSharedDisk(virQEMUDriver *driver, - virDomainDiskDef *disk, - const char *name) -{ - return qemuSharedDiskAddRemoveInternal(driver, disk, name, true); -} - - -static bool -qemuIsSharedHostdev(virDomainHostdevDef *hostdev) -{ - return (hostdev->shareable && - (virHostdevIsSCSIDevice(hostdev) && - hostdev->source.subsys.u.scsi.protocol != - VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI)); -} - - -static char * -qemuGetHostdevPath(virDomainHostdevDef *hostdev) -{ - virDomainHostdevSubsysSCSI *scsisrc = &hostdev->source.subsys.u.scsi; - virDomainHostdevSubsysSCSIHost *scsihostsrc = &scsisrc->u.host; - g_autofree char *dev_name = NULL; - - if (!(dev_name = virSCSIDeviceGetDevName(NULL, - scsihostsrc->adapter, - scsihostsrc->bus, - scsihostsrc->target, - scsihostsrc->unit))) - return NULL; - - return g_strdup_printf("/dev/%s", dev_name); -} - - -static int -qemuSharedHostdevAddRemoveInternal(virQEMUDriver *driver, - virDomainHostdevDef *hostdev, - const char *name, - bool addDevice) -{ - g_autofree char *dev_path = NULL; - g_autofree char *key = NULL; - int ret = -1; - - if (!qemuIsSharedHostdev(hostdev)) - return 0; - - if (!(dev_path = qemuGetHostdevPath(hostdev)) || - !(key = qemuGetSharedDeviceKey(dev_path))) - return -1; - - qemuDriverLock(driver); - - if (addDevice) - ret = qemuSharedDeviceEntryInsert(driver, key, name); - else - ret = qemuSharedDeviceEntryRemove(driver, key, name); - - qemuDriverUnlock(driver); - - return ret; -} - -static int -qemuSharedDeviceAddRemoveInternal(virQEMUDriver *driver, - virDomainDeviceDef *dev, - const char *name, - bool addDevice) -{ - /* Currently the only conflicts we have to care about for - * the shared disk and shared host device is "sgio" setting, - * which is only valid for block disk and scsi host device. - */ - if (dev->type == VIR_DOMAIN_DEVICE_DISK) - return qemuSharedDiskAddRemoveInternal(driver, dev->data.disk, - name, addDevice); - if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) - return qemuSharedHostdevAddRemoveInternal(driver, dev->data.hostdev, - name, addDevice); - return 0; -} - - -/* qemuAddSharedDevice: - * @driver: Pointer to qemu driver struct - * @dev: The device def - * @name: The domain name - * - * Increase ref count and add the domain name into the list which - * records all the domains that use the shared device if the entry - * already exists, otherwise add a new entry. - */ -int -qemuAddSharedDevice(virQEMUDriver *driver, - virDomainDeviceDef *dev, - const char *name) -{ - return qemuSharedDeviceAddRemoveInternal(driver, dev, name, true); -} - - -int -qemuRemoveSharedDisk(virQEMUDriver *driver, - virDomainDiskDef *disk, - const char *name) -{ - return qemuSharedDiskAddRemoveInternal(driver, disk, name, false); -} - - -/* qemuRemoveSharedDevice: - * @driver: Pointer to qemu driver struct - * @device: The device def - * @name: The domain name - * - * Decrease ref count and remove the domain name from the list which - * records all the domains that use the shared device if ref is not - * 1, otherwise remove the entry. - */ -int -qemuRemoveSharedDevice(virQEMUDriver *driver, - virDomainDeviceDef *dev, - const char *name) -{ - return qemuSharedDeviceAddRemoveInternal(driver, dev, name, false); -} - - int qemuDriverAllocateID(virQEMUDriver *driver) { return g_atomic_int_add(&driver->lastvmid, 1) + 1; diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 5961b0b205..c71a666aea 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -292,9 +292,6 @@ struct _virQEMUDriver { virHostdevManager *hostdevMgr; - /* Immutable pointer. Unsafe APIs. XXX */ - GHashTable *sharedDevices; - /* Immutable pointer, immutable object */ virPortAllocatorRange *remotePorts; @@ -344,38 +341,6 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriver *driver, virArch arch, virDomainVirtType virttype); -typedef struct _qemuSharedDeviceEntry qemuSharedDeviceEntry; - -bool qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntry *entry, - const char *name, - int *idx) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); - -char *qemuGetSharedDeviceKey(const char *disk_path) - ATTRIBUTE_NONNULL(1); - -void qemuSharedDeviceEntryFree(void *payload); - -int qemuAddSharedDisk(virQEMUDriver *driver, - virDomainDiskDef *disk, - const char *name) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); - -int qemuAddSharedDevice(virQEMUDriver *driver, - virDomainDeviceDef *dev, - const char *name) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); - -int qemuRemoveSharedDevice(virQEMUDriver *driver, - virDomainDeviceDef *dev, - const char *name) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); - -int qemuRemoveSharedDisk(virQEMUDriver *driver, - virDomainDiskDef *disk, - const char *name) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); - int qemuDriverAllocateID(virQEMUDriver *driver); virDomainXMLOption *virQEMUDriverCreateXMLConf(virQEMUDriver *driver, const char *defsecmodel); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 65ac5ef367..028b53b4ad 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -735,8 +735,6 @@ qemuStateInitialize(bool privileged, if (!(qemu_driver->hostdevMgr = virHostdevManagerGetDefault())) goto error; - qemu_driver->sharedDevices = virHashNew(qemuSharedDeviceEntryFree); - if (qemuMigrationDstErrorInit(qemu_driver) < 0) goto error; @@ -1078,7 +1076,6 @@ qemuStateCleanup(void) virPortAllocatorRangeFree(qemu_driver->migrationPorts); virPortAllocatorRangeFree(qemu_driver->webSocketPorts); virPortAllocatorRangeFree(qemu_driver->remotePorts); - g_clear_pointer(&qemu_driver->sharedDevices, g_hash_table_unref); virObjectUnref(qemu_driver->hostdevMgr); virObjectUnref(qemu_driver->securityManager); virObjectUnref(qemu_driver->domainEventState); diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index 5461de459a..dfe657c51e 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -272,25 +272,8 @@ qemuHostdevPrepareSCSIDevices(virQEMUDriver *driver, virDomainHostdevDef **hostdevs, int nhostdevs) { - size_t i; virHostdevManager *hostdev_mgr = driver->hostdevMgr; - /* Loop 1: Add the shared scsi host device to shared device - * table. - */ - for (i = 0; i < nhostdevs; i++) { - virDomainDeviceDef dev; - - if (!virHostdevIsSCSIDevice(hostdevs[i])) - continue; - - dev.type = VIR_DOMAIN_DEVICE_HOSTDEV; - dev.data.hostdev = hostdevs[i]; - - if (qemuAddSharedDevice(driver, &dev, name) < 0) - return -1; - } - return virHostdevPrepareSCSIDevices(hostdev_mgr, QEMU_DRIVER_NAME, name, hostdevs, nhostdevs); } @@ -426,19 +409,8 @@ qemuHostdevReAttachSCSIDevices(virQEMUDriver *driver, virDomainHostdevDef **hostdevs, int nhostdevs) { - size_t i; virHostdevManager *hostdev_mgr = driver->hostdevMgr; - for (i = 0; i < nhostdevs; i++) { - virDomainHostdevDef *hostdev = hostdevs[i]; - virDomainDeviceDef dev; - - dev.type = VIR_DOMAIN_DEVICE_HOSTDEV; - dev.data.hostdev = hostdev; - - ignore_value(qemuRemoveSharedDevice(driver, &dev, name)); - } - virHostdevReAttachSCSIDevices(hostdev_mgr, QEMU_DRIVER_NAME, name, hostdevs, nhostdevs); } diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 0dd3121221..9dc74d89d2 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -603,7 +603,6 @@ qemuDomainChangeEjectableMedia(virQEMUDriver *driver, qemuDomainObjPrivate *priv = vm->privateData; virStorageSource *oldsrc = disk->src; qemuDomainDiskPrivate *diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); - bool sharedAdded = false; bool managedpr = virStorageSourceChainHasManagedPR(oldsrc) || virStorageSourceChainHasManagedPR(newsrc); int ret = -1; @@ -620,11 +619,6 @@ qemuDomainChangeEjectableMedia(virQEMUDriver *driver, if (virDomainDiskTranslateSourcePool(disk) < 0) goto cleanup; - if (qemuAddSharedDisk(driver, disk, vm->def->name) < 0) - goto cleanup; - - sharedAdded = true; - if (qemuDomainDetermineDiskChain(driver, vm, disk, NULL, true) < 0) goto cleanup; @@ -649,7 +643,6 @@ qemuDomainChangeEjectableMedia(virQEMUDriver *driver, /* remove the old source from shared device list */ disk->src = oldsrc; - ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name)); ignore_value(qemuDomainStorageSourceChainAccessRevoke(driver, vm, oldsrc)); /* media was changed, so we can remove the old media definition now */ @@ -662,9 +655,6 @@ qemuDomainChangeEjectableMedia(virQEMUDriver *driver, cleanup: /* undo changes to the new disk */ if (ret < 0) { - if (sharedAdded) - ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name)); - ignore_value(qemuDomainStorageSourceChainAccessRevoke(driver, vm, newsrc)); } @@ -977,9 +967,6 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriver *driver, if (virDomainDiskTranslateSourcePool(disk) < 0) goto cleanup; - if (qemuAddSharedDevice(driver, dev, vm->def->name) < 0) - goto cleanup; - if (qemuDomainDetermineDiskChain(driver, vm, disk, NULL, true) < 0) goto cleanup; @@ -1076,8 +1063,6 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriver *driver, cleanup: if (ret < 0) { - ignore_value(qemuRemoveSharedDevice(driver, dev, vm->def->name)); - if (releaseUSB) virDomainUSBAddressRelease(priv->usbaddrs, &disk->info); @@ -4418,7 +4403,6 @@ qemuDomainRemoveDiskDevice(virQEMUDriver *driver, { qemuDomainDiskPrivate *diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); g_autoptr(qemuBlockStorageSourceChainData) diskBackend = NULL; - virDomainDeviceDef dev; size_t i; qemuDomainObjPrivate *priv = vm->privateData; bool blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV); @@ -4482,10 +4466,6 @@ qemuDomainRemoveDiskDevice(virQEMUDriver *driver, if (diskBackend) qemuDomainStorageSourceChainAccessRevoke(driver, vm, disk->src); - dev.type = VIR_DOMAIN_DEVICE_DISK; - dev.data.disk = disk; - ignore_value(qemuRemoveSharedDevice(driver, &dev, vm->def->name)); - if (virStorageSourceChainHasManagedPR(disk->src) && qemuHotplugRemoveManagedPR(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) goto cleanup; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index b425acfec1..6203efef3a 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5022,7 +5022,7 @@ qemuProcessSetupGraphics(virQEMUDriver *driver, static int -qemuProcessSetupRawIO(virQEMUDriver *driver, +qemuProcessSetupRawIO(virQEMUDriver *driver G_GNUC_UNUSED, virDomainObj *vm, virCommand *cmd G_GNUC_UNUSED) { @@ -5032,7 +5032,6 @@ qemuProcessSetupRawIO(virQEMUDriver *driver, /* in case a certain disk is desirous of CAP_SYS_RAWIO, add this */ for (i = 0; i < vm->def->ndisks; i++) { - virDomainDeviceDef dev; virDomainDiskDef *disk = vm->def->disks[i]; if (disk->rawio == VIR_TRISTATE_BOOL_YES) { @@ -5041,11 +5040,6 @@ qemuProcessSetupRawIO(virQEMUDriver *driver, break; #endif } - - dev.type = VIR_DOMAIN_DEVICE_DISK; - dev.data.disk = disk; - if (qemuAddSharedDevice(driver, &dev, vm->def->name) < 0) - goto cleanup; } /* If rawio not already set, check hostdevs as well */ @@ -5066,7 +5060,6 @@ qemuProcessSetupRawIO(virQEMUDriver *driver, ret = 0; - cleanup: if (rawio) { #ifdef CAP_SYS_RAWIO if (ret == 0) @@ -8134,15 +8127,6 @@ void qemuProcessStop(virQEMUDriver *driver, qemuSecurityRestoreAllLabel(driver, vm, !!(flags & VIR_QEMU_PROCESS_STOP_MIGRATED)); - for (i = 0; i < vm->def->ndisks; i++) { - virDomainDeviceDef dev; - virDomainDiskDef *disk = vm->def->disks[i]; - - dev.type = VIR_DOMAIN_DEVICE_DISK; - dev.data.disk = disk; - ignore_value(qemuRemoveSharedDevice(driver, &dev, vm->def->name)); - } - /* Clear out dynamically assigned labels */ for (i = 0; i < vm->def->nseclabels; i++) { if (vm->def->seclabels[i]->type == VIR_DOMAIN_SECLABEL_DYNAMIC) @@ -8789,12 +8773,8 @@ qemuProcessReconnect(void *opaque) if (qemuDomainInitializePflashStorageSource(obj) < 0) goto error; - /* XXX: Need to change as long as lock is introduced for - * qemu_driver->sharedDevices. - */ for (i = 0; i < obj->def->ndisks; i++) { virDomainDiskDef *disk = obj->def->disks[i]; - virDomainDeviceDef dev; if (virDomainDiskTranslateSourcePool(disk) < 0) goto error; @@ -8811,11 +8791,6 @@ qemuProcessReconnect(void *opaque) } else { VIR_DEBUG("skipping backing chain detection for '%s'", disk->dst); } - - dev.type = VIR_DOMAIN_DEVICE_DISK; - dev.data.disk = disk; - if (qemuAddSharedDevice(driver, &dev, obj->def->name) < 0) - goto error; } for (i = 0; i < obj->def->ngraphics; i++) { -- 2.31.1

On Thu, Jan 13, 2022 at 06:47:39PM +0100, Ján Tomko wrote:
@@ -649,7 +643,6 @@ qemuDomainChangeEjectableMedia(virQEMUDriver *driver,
/* remove the old source from shared device list */ disk->src = oldsrc; - ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name)); ignore_value(qemuDomainStorageSourceChainAccessRevoke(driver, vm, oldsrc));
I believe you should also drop the comment, the line where disk->src is set to oldsrc as well as the one a little bit below where it's set back to newsrc. -- Andrea Bolognani / Red Hat / Virtualization

It was only used to construct the hash key for the (now removed) shared devices in the qemu driver. Remove it and its mocking. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/libvirt_private.syms | 1 - src/util/virutil.c | 29 ----------------------------- src/util/virutil.h | 3 --- tests/qemuhotplugmock.c | 17 ----------------- 4 files changed, 50 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 48e8ef6c72..ae132f9b11 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3510,7 +3510,6 @@ virDoesUserExist; virDoubleToStr; virFormatIntDecimal; virFormatIntPretty; -virGetDeviceID; virGetGroupID; virGetGroupList; virGetGroupName; diff --git a/src/util/virutil.c b/src/util/virutil.c index 0acdc052c3..4dc421a85f 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1324,35 +1324,6 @@ virValidateWWN(const char *wwn) return true; } -#if defined(major) && defined(minor) -int -virGetDeviceID(const char *path, int *maj, int *min) -{ - struct stat sb; - - if (stat(path, &sb) < 0) - return -errno; - - if (!S_ISBLK(sb.st_mode)) - return -EINVAL; - - if (maj) - *maj = major(sb.st_rdev); - if (min) - *min = minor(sb.st_rdev); - - return 0; -} -#else -int -virGetDeviceID(const char *path G_GNUC_UNUSED, - int *maj, - int *min) -{ - *maj = *min = 0; - return -ENOSYS; -} -#endif int virSetDeviceUnprivSGIO(const char *path G_GNUC_UNUSED, diff --git a/src/util/virutil.h b/src/util/virutil.h index bd2c69bfaa..c8b8445bbc 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -116,9 +116,6 @@ bool virDoesGroupExist(const char *name); bool virValidateWWN(const char *wwn); -int virGetDeviceID(const char *path, - int *maj, - int *min) G_GNUC_NO_INLINE; int virSetDeviceUnprivSGIO(const char *path, const char *sysfs_dir, int unpriv_sgio); diff --git a/tests/qemuhotplugmock.c b/tests/qemuhotplugmock.c index 3b5f858044..051f2b20dc 100644 --- a/tests/qemuhotplugmock.c +++ b/tests/qemuhotplugmock.c @@ -27,7 +27,6 @@ #include "virmock.h" #include <fcntl.h> -static int (*real_virGetDeviceID)(const char *path, int *maj, int *min); static bool (*real_virFileExists)(const char *path); static void @@ -36,7 +35,6 @@ init_syms(void) if (real_virFileExists) return; - VIR_MOCK_REAL_INIT(virGetDeviceID); VIR_MOCK_REAL_INIT(virFileExists); } @@ -68,21 +66,6 @@ virDevMapperGetTargets(const char *path, } -int -virGetDeviceID(const char *path, int *maj, int *min) -{ - init_syms(); - - if (STREQ(path, "/dev/mapper/virt")) { - *maj = 254; - *min = 0; - return 0; - } - - return real_virGetDeviceID(path, maj, min); -} - - bool virFileExists(const char *path) { -- 2.31.1

These are no longer used. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/virutil.c | 21 --------------------- src/util/virutil.h | 7 ------- 2 files changed, 28 deletions(-) diff --git a/src/util/virutil.c b/src/util/virutil.c index 4dc421a85f..8a6efd4d5c 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1325,27 +1325,6 @@ virValidateWWN(const char *wwn) } -int -virSetDeviceUnprivSGIO(const char *path G_GNUC_UNUSED, - const char *sysfs_dir G_GNUC_UNUSED, - int unpriv_sgio G_GNUC_UNUSED) -{ - virReportError(VIR_ERR_OPERATION_INVALID, "%s", - _("unpriv_sgio is not supported by this kernel")); - return -1; -} - -int -virGetDeviceUnprivSGIO(const char *path G_GNUC_UNUSED, - const char *sysfs_dir G_GNUC_UNUSED, - int *unpriv_sgio G_GNUC_UNUSED) -{ - virReportError(VIR_ERR_OPERATION_INVALID, "%s", - _("unpriv_sgio is not supported by this kernel")); - return -1; -} - - /** * virParseOwnershipIds: * diff --git a/src/util/virutil.h b/src/util/virutil.h index c8b8445bbc..6bb55918ad 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -116,13 +116,6 @@ bool virDoesGroupExist(const char *name); bool virValidateWWN(const char *wwn); -int virSetDeviceUnprivSGIO(const char *path, - const char *sysfs_dir, - int unpriv_sgio); -int virGetDeviceUnprivSGIO(const char *path, - const char *sysfs_dir, - int *unpriv_sgio); - int virParseOwnershipIds(const char *label, uid_t *uidPtr, gid_t *gidPtr); -- 2.31.1

Remove the now unused 'driver' parameter, as well as the pointless if (ret == 0) comparison which is always true after removing the cleanup label. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/qemu/qemu_process.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 6203efef3a..7ff4dc1835 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5022,8 +5022,7 @@ qemuProcessSetupGraphics(virQEMUDriver *driver, static int -qemuProcessSetupRawIO(virQEMUDriver *driver G_GNUC_UNUSED, - virDomainObj *vm, +qemuProcessSetupRawIO(virDomainObj *vm, virCommand *cmd G_GNUC_UNUSED) { bool rawio = false; @@ -5062,8 +5061,7 @@ qemuProcessSetupRawIO(virQEMUDriver *driver G_GNUC_UNUSED, if (rawio) { #ifdef CAP_SYS_RAWIO - if (ret == 0) - virCommandAllowCap(cmd, CAP_SYS_RAWIO); + virCommandAllowCap(cmd, CAP_SYS_RAWIO); #else virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Raw I/O is not supported on this platform")); @@ -7423,7 +7421,7 @@ qemuProcessLaunch(virConnectPtr conn, goto cleanup; VIR_DEBUG("Setting up raw IO"); - if (qemuProcessSetupRawIO(driver, vm, cmd) < 0) + if (qemuProcessSetupRawIO(vm, cmd) < 0) goto cleanup; virCommandSetPreExecHook(cmd, qemuProcessHook, &hookData); -- 2.31.1

On Thu, Jan 13, 2022 at 06:47:35PM +0100, Ján Tomko wrote:
This feature was never merged in upstream kernel and only made it to upstream libvirt by mistakes.
Remove it as well as the 'sharedDevices' hash table that was only used for this purpose.
The 'sgio' attribute is preserved for compatibility reasons and its 'filtered' value is left intact.
An error is added to the XML validator for the 'unfiltered' value, which means 'unpriv_sgio'
Ján Tomko (7): util: remove virGetUnprivSGIOSysfsPath conf: reject unfiltered sgio on validation qemu: remove all use of SGIO qemu: remove sharedDevices hash table util: remove virGetDeviceID util: remove {Get,Set}UnprivSGIO qemu: simplify qemuProcessSetupRawIO
src/conf/domain_validate.c | 11 + src/libvirt_private.syms | 4 - src/qemu/qemu_conf.c | 448 ------------------ src/qemu/qemu_conf.h | 37 -- src/qemu/qemu_driver.c | 3 - src/qemu/qemu_hostdev.c | 31 -- src/qemu/qemu_hotplug.c | 23 - src/qemu/qemu_process.c | 36 +- src/util/virutil.c | 122 ----- src/util/virutil.h | 12 - tests/qemuhotplugmock.c | 17 - .../disk-scsi-lun-passthrough-sgio.xml | 35 -- tests/qemuxml2argvdata/hostdev-scsi-rawio.xml | 37 -- tests/qemuxml2argvdata/hostdev-scsi-sgio.xml | 37 -- .../disk-scsi-lun-passthrough-sgio.xml | 46 -- .../qemuxml2xmloutdata/hostdev-scsi-rawio.xml | 47 -- .../qemuxml2xmloutdata/hostdev-scsi-sgio.xml | 47 -- tests/qemuxml2xmltest.c | 11 - 18 files changed, 14 insertions(+), 990 deletions(-)
Stunning diffstat. I feel like I might cry. I left a couple of small comments, but either way Reviewed-by: Andrea Bolognani <abologna@redhat.com> -- Andrea Bolognani / Red Hat / Virtualization
participants (2)
-
Andrea Bolognani
-
Ján Tomko