Blame SOURCES/0017-If-we-can-t-parse-part-of-the-device-link-skip-it-an.patch

529d1b
From bc215d06720b346ba0d888a6149cf90f544a90ad Mon Sep 17 00:00:00 2001
529d1b
From: Peter Jones <pjones@redhat.com>
529d1b
Date: Wed, 20 Jun 2018 17:00:24 -0400
529d1b
Subject: [PATCH 17/17] If we can't parse part of the device link, skip it and
529d1b
 set DEV_ABBREV_ONLY
529d1b
529d1b
If we can't parse some part of the device symlink, we can't write a full
529d1b
device path, but we can write an abbreviated HD() or File() path.  So if
529d1b
we've exausted all possibilities, skip to the next node, set
529d1b
DEV_ABBREV_ONLY in the device's flags, and try parsing again.  Then when
529d1b
creator.c checks if that flag conflicts, it'll throw an error if it
529d1b
does.
529d1b
529d1b
Signed-off-by: Peter Jones <pjones@redhat.com>
529d1b
---
529d1b
 src/linux.c | 62 ++++++++++++++++++++++++++++++++++++++++-------------
529d1b
 1 file changed, 47 insertions(+), 15 deletions(-)
529d1b
529d1b
diff --git a/src/linux.c b/src/linux.c
529d1b
index 1e7db4e3f61..8fe21f19f78 100644
529d1b
--- a/src/linux.c
529d1b
+++ b/src/linux.c
529d1b
@@ -429,14 +429,17 @@ struct device HIDDEN
529d1b
 
529d1b
         const char *current = dev->link;
529d1b
         bool needs_root = true;
529d1b
+        int last_successful_probe = -1;
529d1b
 
529d1b
         debug(DEBUG, "searching for device nodes in %s", dev->link);
529d1b
         for (i = 0; dev_probes[i] && dev_probes[i]->parse; i++) {
529d1b
                 struct dev_probe *probe = dev_probes[i];
529d1b
                 ssize_t pos;
529d1b
 
529d1b
-                if (!needs_root && (probe->flags & DEV_PROVIDES_ROOT)) {
529d1b
-                        debug(DEBUG, "not testing %s because flags is 0x%x", probe->name, probe->flags);
529d1b
+                if (!needs_root &&
529d1b
+                    (probe->flags & DEV_PROVIDES_ROOT)) {
529d1b
+                        debug(DEBUG, "not testing %s because flags is 0x%x",
529d1b
+                              probe->name, probe->flags);
529d1b
                         continue;
529d1b
                 }
529d1b
 
529d1b
@@ -445,22 +448,51 @@ struct device HIDDEN
529d1b
                 if (pos < 0) {
529d1b
                         efi_error("parsing %s failed", probe->name);
529d1b
                         goto err;
529d1b
-                } else if (pos == 0) {
529d1b
+                } else if (pos > 0) {
529d1b
+                        debug(DEBUG, "%s matched %s", probe->name, current);
529d1b
+                        dev->flags |= probe->flags;
529d1b
+
529d1b
+                        if (probe->flags & DEV_PROVIDES_HD ||
529d1b
+                            probe->flags & DEV_PROVIDES_ROOT ||
529d1b
+                            probe->flags & DEV_ABBREV_ONLY)
529d1b
+                                needs_root = false;
529d1b
+
529d1b
+                        dev->probes[n++] = dev_probes[i];
529d1b
+                        current += pos;
529d1b
+                        debug(DEBUG, "current:%s", current);
529d1b
+                        last_successful_probe = i;
529d1b
+
529d1b
+                        if (!*current || !strncmp(current, "block/", 6))
529d1b
+                                break;
529d1b
+
529d1b
                         continue;
529d1b
                 }
529d1b
-                debug(DEBUG, "%s matched %s", probe->name, current);
529d1b
-                dev->flags |= probe->flags;
529d1b
 
529d1b
-                if (probe->flags & DEV_PROVIDES_HD ||
529d1b
-                    probe->flags & DEV_PROVIDES_ROOT ||
529d1b
-                    probe->flags & DEV_ABBREV_ONLY)
529d1b
-                        needs_root = false;
529d1b
-                dev->probes[n++] = dev_probes[i];
529d1b
-                current += pos;
529d1b
-                debug(DEBUG, "current:%s", current);
529d1b
-
529d1b
-                if (!*current || !strncmp(current, "block/", 6))
529d1b
-                        break;
529d1b
+                debug(DEBUG, "dev_probes[i+1]: %p dev->interface_type: %d\n",
529d1b
+                      dev_probes[i+1], dev->interface_type);
529d1b
+                if (dev_probes[i+1] == NULL && dev->interface_type == unknown) {
529d1b
+                        int new_pos = 0;
529d1b
+                        rc = sscanf(current, "%*[^/]/%n", &new_pos);
529d1b
+                        if (rc < 0) {
529d1b
+                                efi_error(
529d1b
+                                     "Cannot parse device link segment \"%s\"",
529d1b
+                                     current);
529d1b
+                                goto err;
529d1b
+                        }
529d1b
+                        debug(DEBUG,
529d1b
+                              "Cannot parse device link segment \"%s\"",
529d1b
+                              current);
529d1b
+                        debug(DEBUG, "Skipping to \"%s\"", current + new_pos);
529d1b
+                        debug(DEBUG,
529d1b
+                              "This means we can only write abbreviated paths");
529d1b
+                        if (rc < 0)
529d1b
+                                goto err;
529d1b
+                        if (new_pos == 0)
529d1b
+                                goto err;
529d1b
+                        dev->flags |= DEV_ABBREV_ONLY;
529d1b
+                        i = last_successful_probe;
529d1b
+                        current += new_pos;
529d1b
+                }
529d1b
         }
529d1b
 
529d1b
         if (dev->interface_type == unknown) {
529d1b
-- 
529d1b
2.17.1
529d1b