nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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