storage.builtin and storage.removable do not overlap, but bootsource
can overlap with one of them leading to confusing output, when the
bootsource has nothing bootable as the boot will be attempted twice.

Add a new .nonbootsource specialization and use that in the default.

While at it, also drop the unused bootcdev.

Signed-off-by: Ahmad Fatoum <[email protected]>
---
 common/boot.c       |  4 ++--
 common/cdev-alias.c | 23 +++++++++++++++--------
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/common/boot.c b/common/boot.c
index 7b2ce4740759..e400a4fcb8b3 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -138,8 +138,8 @@ static int init_boot(void)
                global_boot_default = xstrdup(
                        IF_ENABLED(CONFIG_EFI_LOADER_BOOTMGR,  "efibootmgr ")
                        IF_ENABLED(CONFIG_BOOT_DEFAULTS,       "bootsource ")
-                       IF_ENABLED(CONFIG_BOOT_DEFAULTS,       "storage.builtin 
")
-                       IF_ENABLED(CONFIG_BOOT_DEFAULTS,       
"storage.removable ")
+                       IF_ENABLED(CONFIG_BOOT_DEFAULTS,       
"storage.builtin.nonbootsource ")
+                       IF_ENABLED(CONFIG_BOOT_DEFAULTS,       
"storage.removable.nonbootsource ")
                        "net"
                );
 
diff --git a/common/cdev-alias.c b/common/cdev-alias.c
index 82b91108c1fc..ca5048f35a26 100644
--- a/common/cdev-alias.c
+++ b/common/cdev-alias.c
@@ -82,6 +82,8 @@ static int cdev_alias_resolve_diskuuid(struct cdev_alias_res 
*cdev_alias_res,
 #define STORAGE_REMOVABLE      BIT(0)
 #define STORAGE_BUILTIN                BIT(1)
 
+#define STORAGE_NONBOOTSOURCE  BIT(31)
+
 /**
  * call_for_each_storage() - invoke callback for each storage medium
  *
@@ -136,24 +138,29 @@ static int cdev_alias_resolve_storage(struct 
cdev_alias_res *cdev_alias_res,
                                      cdev_alias_processor_t fn,
                                      void *data)
 {
-       struct cdev *bootcdev;
        unsigned filter = 0;
-       int bootsource, nmatches;
+       int bootsource = 0, nmatches;
 
        if (!class)
-               filter = ~0;
+               filter = STORAGE_REMOVABLE | STORAGE_BUILTIN;
+       else if (streq_ptr(class, "nonbootsource"))
+               filter = STORAGE_REMOVABLE | STORAGE_BUILTIN | 
STORAGE_NONBOOTSOURCE;
        else if (streq_ptr(class, "removable"))
                filter |= STORAGE_REMOVABLE;
        else if (streq_ptr(class, "builtin"))
                filter |= STORAGE_BUILTIN;
+       else if (streq_ptr(class, "removable.nonbootsource"))
+               filter |= STORAGE_REMOVABLE | STORAGE_NONBOOTSOURCE;
+       else if (streq_ptr(class, "builtin.nonbootsource"))
+               filter |= STORAGE_BUILTIN | STORAGE_NONBOOTSOURCE;
        else
                return -EINVAL;
 
-       bootcdev = bootsource_of_cdev_find();
-
-       bootsource = call_for_each_storage(fn, data, filter, true);
-       if (bootsource < 0)
-               return bootsource;
+       if (!(filter & STORAGE_NONBOOTSOURCE)) {
+               bootsource = call_for_each_storage(fn, data, filter, true);
+               if (bootsource < 0)
+                       return bootsource;
+       }
 
        nmatches = call_for_each_storage(fn, data, filter, false);
        if (nmatches < 0)
-- 
2.47.3


Reply via email to