nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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