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

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