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