From 1807b8f1fc0afdf01e366dfa694295063e2eb982 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Wed, 10 May 2023 15:47:44 +0900
Subject: [PATCH] udev: do not set ID_PATH and by-path symlink for nvmf disks

Prompted by #27391.

(cherry picked from commit 39a39f18f2bd2b1ef7b4fa4823472d129c514030)
(cherry picked from commit dbf50f19112cf39c6f281c6dd2a0a9177774f932)
(cherry picked from commit 5ec7ad9588172bae561ce77ffadfa8f9eb44aa45)

Conflict:NA
Reference:https://github.com/systemd/systemd-stable/commit/1807b8f1fc0afdf01e366dfa694295063e2eb982
---
 src/udev/udev-builtin-path_id.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c
index 1084eb2d81..483350d98d 100644
--- a/src/udev/udev-builtin-path_id.c
+++ b/src/udev/udev-builtin-path_id.c
@@ -545,7 +545,7 @@ static sd_device *handle_ap(sd_device *parent, char **path) {
 
 static int find_real_nvme_parent(sd_device *dev, sd_device **ret) {
         _cleanup_(sd_device_unrefp) sd_device *nvme = NULL;
-        const char *sysname, *end;
+        const char *sysname, *end, *devpath;
         int r;
 
         /* If the device belongs to "nvme-subsystem" (not to be confused with "nvme"), which happens when
@@ -576,6 +576,14 @@ static int find_real_nvme_parent(sd_device *dev, sd_device **ret) {
         if (r < 0)
                 return r;
 
+        r = sd_device_get_devpath(nvme, &devpath);
+        if (r < 0)
+                return r;
+
+        /* If the 'real parent' is (still) virtual, e.g. for nvmf disks, refuse to set ID_PATH. */
+        if (path_startswith(devpath, "/devices/virtual/"))
+                return -ENXIO;
+
         *ret = TAKE_PTR(nvme);
         return 0;
 }
-- 
2.33.0

