nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0095-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch

d9d99f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d9d99f
From: Andrei Borzenkov <arvidjaar@gmail.com>
d9d99f
Date: Tue, 21 Jun 2016 16:44:17 +0000
d9d99f
Subject: [PATCH] Fallback to old subvol name scheme to support old snapshot
d9d99f
 config
d9d99f
d9d99f
Ref: bsc#953538
d9d99f
---
d9d99f
 grub-core/fs/btrfs.c | 32 +++++++++++++++++++++++++++++++-
d9d99f
 1 file changed, 31 insertions(+), 1 deletion(-)
d9d99f
d9d99f
diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
b71686
index 2e36ac47e..4a31d39ee 100644
d9d99f
--- a/grub-core/fs/btrfs.c
d9d99f
+++ b/grub-core/fs/btrfs.c
d9d99f
@@ -924,11 +924,41 @@ lookup_root_by_name(struct grub_btrfs_data *data, const char *path)
d9d99f
   return GRUB_ERR_NONE;
d9d99f
 }
d9d99f
 
d9d99f
+static grub_err_t
d9d99f
+lookup_root_by_name_fallback(struct grub_btrfs_data *data, const char *path)
d9d99f
+{
d9d99f
+  grub_err_t err;
d9d99f
+  grub_uint64_t tree = 0;
d9d99f
+  grub_uint8_t type;
d9d99f
+  struct grub_btrfs_key key;
d9d99f
+
d9d99f
+  err = find_path (data, path, &key, &tree, &type);
d9d99f
+  if (err)
d9d99f
+      return grub_error(GRUB_ERR_FILE_NOT_FOUND, "couldn't locate %s\n", path);
d9d99f
+
d9d99f
+  if (key.object_id != grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK) || tree == 0)
d9d99f
+    return grub_error(GRUB_ERR_BAD_FILE_TYPE, "%s: not a subvolume\n", path);
d9d99f
+
d9d99f
+  data->fs_tree = tree;
d9d99f
+  return GRUB_ERR_NONE;
d9d99f
+}
d9d99f
+
d9d99f
 static grub_err_t
d9d99f
 btrfs_handle_subvol(struct grub_btrfs_data *data __attribute__ ((unused)))
d9d99f
 {
d9d99f
   if (btrfs_default_subvol)
d9d99f
-    return lookup_root_by_name(data, btrfs_default_subvol);
d9d99f
+    {
d9d99f
+      grub_err_t err;
d9d99f
+      err = lookup_root_by_name(data, btrfs_default_subvol);
d9d99f
+
d9d99f
+      /* Fallback to old schemes */
d9d99f
+      if (err == GRUB_ERR_FILE_NOT_FOUND)
d9d99f
+	{
d9d99f
+	  err = GRUB_ERR_NONE;
d9d99f
+	  return lookup_root_by_name_fallback(data, btrfs_default_subvol);
d9d99f
+	}
d9d99f
+      return err;
d9d99f
+    }
d9d99f
 
d9d99f
   if (btrfs_default_subvolid)
d9d99f
     return lookup_root_by_id(data, btrfs_default_subvolid);