dd65c9
From 104d13b765fac0308dbd01a1f3a0221504bd0412 Mon Sep 17 00:00:00 2001
dd65c9
From: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
dd65c9
Date: Wed, 1 Mar 2017 21:30:17 +0100
dd65c9
Subject: [PATCH] udev: Use parent bus id for virtio disk builtin path-id
dd65c9
 (#5500)
dd65c9
dd65c9
The builtin path id for virtio block devices has been changed
dd65c9
to use the bus id without a prefix "virtio-pci" to be
dd65c9
compatible with all virtio transport types.
dd65c9
dd65c9
In order to not break existing setups, the by-path symlinks for
dd65c9
virtio block devices on the PCI bus are reintroduced by udev rules.
dd65c9
The virtio-pci symlinks are considered to be deprecated and
dd65c9
should be replaced by the native PCI symlinks.
dd65c9
dd65c9
Example output for a virtio disk in PCI slot 7:
dd65c9
 $ ls  /dev/disk/by-path
dd65c9
 pci-0000:00:07.0
dd65c9
 pci-0000:00:07.0-part1
dd65c9
 virtio-pci-0000:00:07.0
dd65c9
 virtio-pci-0000:00:07.0-part1
dd65c9
dd65c9
See also
dd65c9
[1] https://lists.freedesktop.org/archives/systemd-devel/2017-February/038326.html
dd65c9
[2] https://lists.freedesktop.org/archives/systemd-devel/2017-March/038397.html
dd65c9
dd65c9
This reverts f073b1b but keeps the same symlinks for compatibility.
dd65c9
dd65c9
(cherry picked from commit fb92fbb1b171ef94207a1ebc111ef0e414d49b4c)
dd65c9
dd65c9
Resolves: #1496697
dd65c9
---
dd65c9
 rules/60-persistent-storage.rules | 4 ++++
dd65c9
 src/udev/udev-builtin-path_id.c   | 5 +----
dd65c9
 2 files changed, 5 insertions(+), 4 deletions(-)
dd65c9
dd65c9
diff --git a/rules/60-persistent-storage.rules b/rules/60-persistent-storage.rules
dd65c9
index 06e3329cc..10642a1fd 100644
dd65c9
--- a/rules/60-persistent-storage.rules
dd65c9
+++ b/rules/60-persistent-storage.rules
dd65c9
@@ -71,6 +71,10 @@ ENV{DEVTYPE}=="partition", ENV{ID_SAS_PATH}=="?*", SYMLINK+="disk/by-path/$env{I
dd65c9
 # skip unpartitioned removable media devices from drivers which do not send "change" events
dd65c9
 ENV{DEVTYPE}=="disk", KERNEL!="sd*|sr*", ATTR{removable}=="1", GOTO="persistent_storage_end"
dd65c9
 
dd65c9
+# legacy virtio-pci by-path links (deprecated)
dd65c9
+KERNEL=="vd*[!0-9]", ENV{ID_PATH}=="pci-*", SYMLINK+="disk/by-path/virtio-$env{ID_PATH}"
dd65c9
+KERNEL=="vd*[0-9]", ENV{ID_PATH}=="pci-*", SYMLINK+="disk/by-path/virtio-$env{ID_PATH}-part%n"
dd65c9
+
dd65c9
 # probe filesystem metadata of optical drives which have a media inserted
dd65c9
 KERNEL=="sr*", ENV{DISK_EJECT_REQUEST}!="?*", ENV{ID_CDROM_MEDIA_TRACK_COUNT_DATA}=="?*", ENV{ID_CDROM_MEDIA_SESSION_LAST_OFFSET}=="?*", \
dd65c9
   IMPORT{builtin}="blkid --offset=$env{ID_CDROM_MEDIA_SESSION_LAST_OFFSET}"
dd65c9
diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c
dd65c9
index 19447201b..d113ff21b 100644
dd65c9
--- a/src/udev/udev-builtin-path_id.c
dd65c9
+++ b/src/udev/udev-builtin-path_id.c
dd65c9
@@ -688,11 +688,8 @@ restart:
dd65c9
                         parent = skip_subsystem(parent, "xen");
dd65c9
                         supported_parent = true;
dd65c9
                 } else if (streq(subsys, "virtio")) {
dd65c9
-                        while (parent && streq_ptr("virtio", udev_device_get_subsystem(parent)))
dd65c9
-                                parent = udev_device_get_parent(parent);
dd65c9
-                        path_prepend(&path, "virtio-pci-%s", udev_device_get_sysname(parent));
dd65c9
+                        parent = skip_subsystem(parent, "virtio");
dd65c9
                         supported_transport = true;
dd65c9
-                        supported_parent = true;
dd65c9
                 } else if (streq(subsys, "scm")) {
dd65c9
                         path_prepend(&path, "scm-%s", udev_device_get_sysname(parent));
dd65c9
                         parent = skip_subsystem(parent, "scm");