nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0060-grub2-btrfs-04-grub2-install.patch

5593c8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
5593c8
From: Michael Chang <mchang@suse.com>
5593c8
Date: Thu, 21 Aug 2014 03:39:11 +0000
5593c8
Subject: [PATCH] grub2-btrfs-04-grub2-install
5593c8
5593c8
---
5593c8
 grub-core/osdep/linux/getroot.c |  7 +++++++
5593c8
 grub-core/osdep/unix/config.c   | 17 +++++++++++++++--
5593c8
 util/config.c                   | 10 ++++++++++
5593c8
 util/grub-install.c             | 15 +++++++++++++++
5593c8
 util/grub-mkrelpath.c           |  6 ++++++
5593c8
 include/grub/emu/config.h       |  1 +
5593c8
 6 files changed, 54 insertions(+), 2 deletions(-)
5593c8
5593c8
diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c
d3c3ab
index 001b818fe58..caf9b1ccd3f 100644
5593c8
--- a/grub-core/osdep/linux/getroot.c
5593c8
+++ b/grub-core/osdep/linux/getroot.c
5593c8
@@ -376,6 +376,7 @@ get_btrfs_fs_prefix (const char *mount_path)
5593c8
   return NULL;
5593c8
 }
5593c8
 
5593c8
+int use_relative_path_on_btrfs = 0;
5593c8
 
5593c8
 char **
5593c8
 grub_find_root_devices_from_mountinfo (const char *dir, char **relroot)
5593c8
@@ -519,6 +520,12 @@ again:
5593c8
 	{
5593c8
 	  ret = grub_find_root_devices_from_btrfs (dir);
5593c8
 	  fs_prefix = get_btrfs_fs_prefix (entries[i].enc_path);
5593c8
+	  if (use_relative_path_on_btrfs)
5593c8
+	    {
5593c8
+	      if (fs_prefix)
5593c8
+	        free (fs_prefix);
5593c8
+	      fs_prefix = xstrdup ("/");
5593c8
+	    }
5593c8
 	}
5593c8
       else if (!retry && grub_strcmp (entries[i].fstype, "autofs") == 0)
5593c8
 	{
5593c8
diff --git a/grub-core/osdep/unix/config.c b/grub-core/osdep/unix/config.c
d3c3ab
index 7d6325138ce..46a881530c0 100644
5593c8
--- a/grub-core/osdep/unix/config.c
5593c8
+++ b/grub-core/osdep/unix/config.c
5593c8
@@ -82,6 +82,19 @@ grub_util_load_config (struct grub_util_config *cfg)
5593c8
   if (v)
5593c8
     cfg->grub_distributor = xstrdup (v);
5593c8
 
5593c8
+  v = getenv ("SUSE_BTRFS_SNAPSHOT_BOOTING");
5593c8
+  if (v)
5593c8
+    {
5593c8
+      if (grub_strncmp(v, "true", sizeof ("true") - 1) == 0)
5593c8
+        {
5593c8
+          cfg->is_suse_btrfs_snapshot_enabled = 1;
5593c8
+        }
5593c8
+      else
5593c8
+        {
5593c8
+          cfg->is_suse_btrfs_snapshot_enabled = 0;
5593c8
+        }
5593c8
+    }
5593c8
+
5593c8
   cfgfile = grub_util_get_config_filename ();
5593c8
   if (!grub_util_is_regular (cfgfile))
5593c8
     return;
5593c8
@@ -105,8 +118,8 @@ grub_util_load_config (struct grub_util_config *cfg)
5593c8
       *ptr++ = *iptr;
5593c8
     }
5593c8
 
5593c8
-  strcpy (ptr, "'; printf \"GRUB_ENABLE_CRYPTODISK=%s\\nGRUB_DISTRIBUTOR=%s\\n\" "
5593c8
-	  "\"$GRUB_ENABLE_CRYPTODISK\" \"$GRUB_DISTRIBUTOR\"");
5593c8
+  strcpy (ptr, "'; printf \"GRUB_ENABLE_CRYPTODISK=%s\\nGRUB_DISTRIBUTOR=%s\\nSUSE_BTRFS_SNAPSHOT_BOOTING=%s\\n\" "
5593c8
+	  "\"$GRUB_ENABLE_CRYPTODISK\" \"$GRUB_DISTRIBUTOR\" \"$SUSE_BTRFS_SNAPSHOT_BOOTING\"");
5593c8
 
5593c8
   argv[2] = script;
5593c8
   argv[3] = '\0';
5593c8
diff --git a/util/config.c b/util/config.c
d3c3ab
index ebcdd8f5e22..f044a880a76 100644
5593c8
--- a/util/config.c
5593c8
+++ b/util/config.c
5593c8
@@ -42,6 +42,16 @@ grub_util_parse_config (FILE *f, struct grub_util_config *cfg, int simple)
5593c8
 	    cfg->is_cryptodisk_enabled = 1;
5593c8
 	  continue;
5593c8
 	}
5593c8
+      if (grub_strncmp (ptr, "SUSE_BTRFS_SNAPSHOT_BOOTING=",
5593c8
+			sizeof ("SUSE_BTRFS_SNAPSHOT_BOOTING=") - 1) == 0)
5593c8
+	{
5593c8
+	  ptr += sizeof ("SUSE_BTRFS_SNAPSHOT_BOOTING=") - 1;
5593c8
+	  if (*ptr == '"' || *ptr == '\'')
5593c8
+	    ptr++;
5593c8
+	  if (grub_strncmp(ptr, "true", sizeof ("true") - 1) == 0)
5593c8
+	    cfg->is_suse_btrfs_snapshot_enabled = 1;
5593c8
+	  continue;
5593c8
+	}
5593c8
       if (grub_strncmp (ptr, "GRUB_DISTRIBUTOR=",
5593c8
 			sizeof ("GRUB_DISTRIBUTOR=") - 1) == 0)
5593c8
 	{
5593c8
diff --git a/util/grub-install.c b/util/grub-install.c
d3c3ab
index 0fbe7f78c6d..0f66f36d23a 100644
5593c8
--- a/util/grub-install.c
5593c8
+++ b/util/grub-install.c
5593c8
@@ -827,6 +827,8 @@ fill_core_services (const char *core_services)
5593c8
   free (sysv_plist);
5593c8
 }
5593c8
 
5593c8
+extern int use_relative_path_on_btrfs;
5593c8
+
5593c8
 int
5593c8
 main (int argc, char *argv[])
5593c8
 {
5593c8
@@ -860,6 +862,9 @@ main (int argc, char *argv[])
5593c8
 
5593c8
   grub_util_load_config (&config);
5593c8
 
5593c8
+  if (config.is_suse_btrfs_snapshot_enabled)
5593c8
+    use_relative_path_on_btrfs = 1;
5593c8
+
5593c8
   if (!bootloader_id && config.grub_distributor)
5593c8
     {
5593c8
       char *ptr;
5593c8
@@ -1352,6 +1357,16 @@ main (int argc, char *argv[])
5593c8
       fprintf (load_cfg_f, "set debug='%s'\n",
5593c8
 	      debug_image);
5593c8
     }
5593c8
+
5593c8
+  if (config.is_suse_btrfs_snapshot_enabled
5593c8
+      && grub_strncmp(grub_fs->name, "btrfs", sizeof ("btrfs") - 1) == 0)
5593c8
+    {
5593c8
+      if (!load_cfg_f)
5593c8
+        load_cfg_f = grub_util_fopen (load_cfg, "wb");
5593c8
+      have_load_cfg = 1;
5593c8
+      fprintf (load_cfg_f, "set btrfs_relative_path='y'\n");
5593c8
+    }
5593c8
+
5593c8
   char *prefix_drive = NULL;
5593c8
   char *install_drive = NULL;
5593c8
 
5593c8
diff --git a/util/grub-mkrelpath.c b/util/grub-mkrelpath.c
d3c3ab
index 47a241a391b..5db7a9a7d97 100644
5593c8
--- a/util/grub-mkrelpath.c
5593c8
+++ b/util/grub-mkrelpath.c
5593c8
@@ -40,9 +40,12 @@ struct arguments
5593c8
 };
5593c8
 
5593c8
 static struct argp_option options[] = {
5593c8
+  {"relative",  'r', 0, 0, "use relative path on btrfs", 0},
5593c8
   { 0, 0, 0, 0, 0, 0 }
5593c8
 };
5593c8
 
5593c8
+extern int use_relative_path_on_btrfs;
5593c8
+
5593c8
 static error_t
5593c8
 argp_parser (int key, char *arg, struct argp_state *state)
5593c8
 {
5593c8
@@ -52,6 +55,9 @@ argp_parser (int key, char *arg, struct argp_state *state)
5593c8
 
5593c8
   switch (key)
5593c8
     {
5593c8
+    case 'r':
5593c8
+      use_relative_path_on_btrfs = 1;
5593c8
+      break;
5593c8
     case ARGP_KEY_ARG:
5593c8
       if (state->arg_num == 0)
5593c8
 	arguments->pathname = xstrdup (arg);
5593c8
diff --git a/include/grub/emu/config.h b/include/grub/emu/config.h
d3c3ab
index 875d5896ce1..c9a7e5f4ade 100644
5593c8
--- a/include/grub/emu/config.h
5593c8
+++ b/include/grub/emu/config.h
5593c8
@@ -37,6 +37,7 @@ struct grub_util_config
5593c8
 {
5593c8
   int is_cryptodisk_enabled;
5593c8
   char *grub_distributor;
5593c8
+  int is_suse_btrfs_snapshot_enabled;
5593c8
 };
5593c8
 
5593c8
 void