dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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