SHA256
1
0
forked from pool/grub2

Accepting request 625372 from Base:System

OBS-URL: https://build.opensuse.org/request/show/625372
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/grub2?expand=0&rev=190
This commit is contained in:
Dominique Leuenberger 2018-08-02 12:49:00 +00:00 committed by Git OBS Bridge
parent 13a1c53724
commit f1e201a0aa
5 changed files with 300 additions and 26 deletions

View File

@ -1,7 +1,12 @@
Index: grub-2.02~rc2/grub-core/fs/btrfs.c
V2:
* Fix grub2-install --root-directory does not work for /boot/grub2/<arch> on
separate btrfs subvolume (boo#1098420)
Index: grub-2.02/grub-core/fs/btrfs.c
===================================================================
--- grub-2.02~rc2.orig/grub-core/fs/btrfs.c
+++ grub-2.02~rc2/grub-core/fs/btrfs.c
--- grub-2.02.orig/grub-core/fs/btrfs.c
+++ grub-2.02/grub-core/fs/btrfs.c
@@ -32,6 +32,7 @@
#include <grub/command.h>
#include <grub/env.h>
@ -264,10 +269,10 @@ Index: grub-2.02~rc2/grub-core/fs/btrfs.c
cmd_list_subvols = grub_register_extcmd("btrfs-list-subvols",
grub_cmd_btrfs_list_subvols, 0,
"[-p|-n] [-o var] DEVICE",
Index: grub-2.02~rc2/grub-core/osdep/linux/getroot.c
Index: grub-2.02/grub-core/osdep/linux/getroot.c
===================================================================
--- grub-2.02~rc2.orig/grub-core/osdep/linux/getroot.c
+++ grub-2.02~rc2/grub-core/osdep/linux/getroot.c
--- grub-2.02.orig/grub-core/osdep/linux/getroot.c
+++ grub-2.02/grub-core/osdep/linux/getroot.c
@@ -107,6 +107,14 @@ struct btrfs_ioctl_search_key
grub_uint32_t unused[9];
};
@ -447,11 +452,11 @@ Index: grub-2.02~rc2/grub-core/osdep/linux/getroot.c
char *
grub_make_system_path_relative_to_its_root_os (const char *path)
{
Index: grub-2.02~rc2/util/grub-install.c
Index: grub-2.02/util/grub-install.c
===================================================================
--- grub-2.02~rc2.orig/util/grub-install.c
+++ grub-2.02~rc2/util/grub-install.c
@@ -1560,6 +1560,55 @@ main (int argc, char *argv[])
--- grub-2.02.orig/util/grub-install.c
+++ grub-2.02/util/grub-install.c
@@ -1560,6 +1560,58 @@ main (int argc, char *argv[])
prefix_drive = xasprintf ("(%s)", grub_drives[0]);
}
@ -463,13 +468,12 @@ Index: grub-2.02~rc2/util/grub-install.c
+ char *subvol = NULL;
+ char *mount_path = NULL;
+ char **rootdir_devices = NULL;
+ char *rootdir_path = grub_util_path_concat (2, "/", rootdir);
+ char *t = grub_util_path_concat (2, "/", rootdir);
+ char *rootdir_path = grub_canonicalize_file_name (t);
+
+ if (grub_util_is_directory (rootdir_path))
+ if (rootdir_path && grub_util_is_directory (rootdir_path))
+ rootdir_devices = grub_guess_root_devices (rootdir_path);
+
+ free (rootdir_path);
+
+ if (rootdir_devices && rootdir_devices[0])
+ if (grub_strcmp (rootdir_devices[0], grub_devices[0]) == 0)
+ subvol = grub_util_get_btrfs_subvol (platdir, &mount_path);
@ -478,28 +482,32 @@ Index: grub-2.02~rc2/util/grub-install.c
+ {
+ char *def_subvol;
+
+ def_subvol = grub_util_get_btrfs_subvol ("/", NULL);
+ def_subvol = grub_util_get_btrfs_subvol (rootdir_path, NULL);
+
+ if (def_subvol)
+ {
+ char *rootdir_mount_path = NULL;
+ if (!load_cfg_f)
+ load_cfg_f = grub_util_fopen (load_cfg, "wb");
+ have_load_cfg = 1;
+
+ if (grub_strcmp (subvol, def_subvol) != 0)
+ fprintf (load_cfg_f, "btrfs-mount-subvol ($root) %s %s\n", mount_path, subvol);
+ if (grub_strncmp (rootdir_path, mount_path, grub_strlen (rootdir_path)) == 0)
+ rootdir_mount_path = grub_util_path_concat (2, "/", mount_path + grub_strlen (rootdir_path));
+
+ if (grub_strcmp (subvol, def_subvol) != 0 && rootdir_mount_path)
+ fprintf (load_cfg_f, "btrfs-mount-subvol ($root) %s %s\n", rootdir_mount_path, subvol);
+ free (rootdir_mount_path);
+ free (def_subvol);
+ }
+ }
+
+ free (t);
+ free (rootdir_path);
+ for (curdev = rootdir_devices; *curdev; curdev++)
+ free (*curdev);
+ if (rootdir_devices)
+ free (rootdir_devices);
+ if (subvol)
+ free (subvol);
+ if (mount_path)
+ free (mount_path);
+ free (rootdir_devices);
+ free (subvol);
+ free (mount_path);
+ }
+
+#endif
@ -507,10 +515,10 @@ Index: grub-2.02~rc2/util/grub-install.c
char mkimage_target[200];
const char *core_name = NULL;
Index: grub-2.02~rc2/include/grub/emu/getroot.h
Index: grub-2.02/include/grub/emu/getroot.h
===================================================================
--- grub-2.02~rc2.orig/include/grub/emu/getroot.h
+++ grub-2.02~rc2/include/grub/emu/getroot.h
--- grub-2.02.orig/include/grub/emu/getroot.h
+++ grub-2.02/include/grub/emu/getroot.h
@@ -53,6 +53,11 @@ char **
grub_find_root_devices_from_mountinfo (const char *dir, char **relroot);
#endif

View File

@ -0,0 +1,233 @@
Index: grub-2.02/grub-core/fs/btrfs.c
===================================================================
--- grub-2.02.orig/grub-core/fs/btrfs.c
+++ grub-2.02/grub-core/fs/btrfs.c
@@ -2590,8 +2590,7 @@ grub_btrfs_get_default_subvolume_id (str
}
static grub_err_t
-grub_cmd_btrfs_get_default_subvol (struct grub_extcmd_context *ctxt,
- int argc, char **argv)
+grub_btrfs_get_default_subvol (const char *name, grub_uint64_t *ret_subvolid, char **ret_subvol)
{
char *devname;
grub_device_t dev;
@@ -2600,21 +2599,8 @@ grub_cmd_btrfs_get_default_subvol (struc
grub_uint64_t id;
char *subvol = NULL;
grub_uint64_t subvolid = 0;
- char *varname = NULL;
- char *output = NULL;
- int path_only = ctxt->state[1].set;
- int num_only = ctxt->state[2].set;
-
- if (ctxt->state[0].set)
- varname = ctxt->state[0].arg;
-
- if (argc < 1)
- return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
-
- devname = grub_file_get_device_name(argv[0]);
- if (!devname)
- return grub_errno;
+ devname = grub_file_get_device_name(name);
dev = grub_device_open (devname);
grub_free (devname);
if (!dev)
@@ -2655,12 +2641,43 @@ grub_cmd_btrfs_get_default_subvol (struc
return err;
}
- if (subvol)
- grub_free (subvol);
+ grub_free (subvol);
subvol = path_out;
id = parent_id;
}
+ if (ret_subvolid)
+ *ret_subvolid = subvolid;
+ if (ret_subvol)
+ *ret_subvol = subvol;
+
+ grub_btrfs_unmount (data);
+ grub_device_close (dev);
+
+ return GRUB_ERR_NONE;
+}
+
+static grub_err_t
+grub_cmd_btrfs_get_default_subvol (struct grub_extcmd_context *ctxt,
+ int argc, char **argv)
+{
+ grub_err_t err;
+ char *subvol = NULL;
+ grub_uint64_t subvolid = 0;
+ char *varname = NULL;
+ char *output = NULL;
+ int path_only = ctxt->state[1].set;
+ int num_only = ctxt->state[2].set;
+
+ if (ctxt->state[0].set)
+ varname = ctxt->state[0].arg;
+
+ if (argc < 1)
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
+
+ if ((err = grub_btrfs_get_default_subvol (argv[0], &subvolid, &subvol)) != GRUB_ERR_NONE)
+ return err;
+
if (num_only && path_only)
output = grub_xasprintf ("%"PRIuGRUB_UINT64_T" /%s", subvolid, subvol);
else if (num_only)
@@ -2676,9 +2693,6 @@ grub_cmd_btrfs_get_default_subvol (struc
grub_free (output);
grub_free (subvol);
- grub_btrfs_unmount (data);
- grub_device_close (dev);
-
return GRUB_ERR_NONE;
}
@@ -2757,6 +2771,122 @@ subvol_get_env (struct grub_env_var *var
return "";
}
+
+static char *
+grub_btrfs_path_to_abs (const char *path)
+{
+ grub_err_t err;
+ char *device_name = NULL;
+ char *subvol = NULL;
+ const char *file_name;
+ char *ret;
+
+ if (!path)
+ return NULL;
+
+ if ((err = grub_btrfs_get_default_subvol (path, 0, &subvol)) != GRUB_ERR_NONE)
+ {
+ grub_errno = GRUB_ERR_NONE;
+ return NULL;
+ }
+
+ if (!subvol || *subvol == '\0')
+ return NULL;
+
+ file_name = (path[0] == '(') ? grub_strchr (path, ')') : NULL;
+ if (file_name)
+ file_name++;
+ else
+ file_name = path;
+ device_name = grub_file_get_device_name (path);
+ if (device_name)
+ ret = grub_xasprintf ("(%s)/%s%s", device_name, subvol, file_name);
+ else
+ ret = grub_xasprintf ("/%s%s", subvol, file_name);
+
+ grub_free (device_name);
+ grub_free (subvol);
+
+ return ret;
+}
+
+static char *
+grub_btrfs_path_to_rel (const char *path)
+{
+ grub_err_t err;
+ char *subvol = NULL;
+ const char *file_name;
+
+ if (!path)
+ return NULL;
+
+ if ((err = grub_btrfs_get_default_subvol (path, 0, &subvol)) != GRUB_ERR_NONE)
+ {
+ grub_errno = GRUB_ERR_NONE;
+ return NULL;
+ }
+
+ if (!subvol || *subvol == '\0')
+ return NULL;
+
+ file_name = (path[0] == '(') ? grub_strchr (path, ')') : NULL;
+ if (file_name)
+ file_name++;
+ else
+ file_name = path;
+
+ if (*file_name == '/')
+ file_name++;
+
+ if (grub_strncmp (file_name, subvol, grub_strlen (subvol)) == 0)
+ {
+ char *device_name;
+ char *ret;
+
+ device_name = grub_file_get_device_name (path);
+ file_name += grub_strlen (subvol);
+ if (device_name)
+ ret = grub_xasprintf ("(%s)%s", device_name, file_name);
+ else
+ ret = grub_strdup (file_name);
+ grub_free (device_name);
+ grub_free (subvol);
+ return ret;
+ }
+
+ grub_free (subvol);
+ return NULL;
+}
+
+static char *
+relpath_set_env (struct grub_env_var *var,
+ const char *val)
+{
+ int new_val, old_val;
+ new_val = (val[0] == '1' || val[0] == 'y') ? 1 : 0;
+ old_val = (var->value[0] == '1' || var->value[0] == 'y') ? 1 : 0;
+
+ if (new_val != old_val)
+ {
+ const char **n;
+ char * (*path_to_xxx) (const char *);
+ const char *envname[] = {"config_file", "config_directory", NULL};
+
+ path_to_xxx = (new_val == 1) ? grub_btrfs_path_to_rel : grub_btrfs_path_to_abs;
+ for (n = envname; *n; n++)
+ {
+ char *ctmp = path_to_xxx (grub_env_get (*n));
+ if (ctmp)
+ {
+ grub_env_set (*n, ctmp);
+ grub_free (ctmp);
+ }
+ }
+ }
+
+ return grub_strdup (val);
+}
+
GRUB_MOD_INIT (btrfs)
{
grub_fs_register (&grub_btrfs_fs);
@@ -2780,6 +2910,8 @@ GRUB_MOD_INIT (btrfs)
subvol_set_env);
grub_register_variable_hook ("btrfs_subvolid", subvolid_get_env,
subvolid_set_env);
+ grub_register_variable_hook ("btrfs_relative_path", NULL,
+ relpath_set_env);
grub_env_export ("btrfs_subvol");
grub_env_export ("btrfs_subvolid");
grub_env_export ("btrfs_relative_path");
@@ -2789,6 +2921,7 @@ GRUB_MOD_FINI (btrfs)
{
grub_register_variable_hook ("btrfs_subvol", NULL, NULL);
grub_register_variable_hook ("btrfs_subvolid", NULL, NULL);
+ grub_register_variable_hook ("btrfs_relative_path", NULL, NULL);
grub_unregister_command (cmd_info);
grub_unregister_extcmd (cmd_list_subvols);
grub_fs_unregister (&grub_btrfs_fs);

View File

@ -0,0 +1,17 @@
Index: grub-2.02/grub-core/normal/main.c
===================================================================
--- grub-2.02.orig/grub-core/normal/main.c
+++ grub-2.02/grub-core/normal/main.c
@@ -282,10 +282,11 @@ grub_normal_execute (const char *config,
int boot;
boot = 0;
char *script;
+ char *dummy[1] = { NULL };
script = grub_malloc (1024);
if (! grub_ieee1275_cas_reboot (script))
{
- if (! grub_script_execute_sourcecode (script))
+ if (! grub_script_execute_new_scope (script, 0, dummy))
boot = 1;
}
grub_free (script);

View File

@ -1,3 +1,15 @@
-------------------------------------------------------------------
Tue Jul 24 07:56:02 UTC 2018 - mchang@suse.com
- Fix config_directory on btrfs to follow path scheme (bsc#1063443)
* grub2-btrfs-10-config-directory.patch
- Fix grub2-install --root-directory does not work for /boot/grub2/<arch> on
separate btrfs subvolume (boo#1098420)
* grub2-btrfs-06-subvol-mount.patch
- Fix setparams doesn't work as expected from boot-last-label NVRAM var, after
inital CAS reboot on ieee1275 (bsc#1088830)
* grub2-ppc64-cas-new-scope.patch
-------------------------------------------------------------------
Mon Jul 16 07:53:19 UTC 2018 - mchang@suse.com

View File

@ -228,6 +228,7 @@ Patch106: grub2-btrfs-06-subvol-mount.patch
Patch107: grub2-btrfs-07-subvol-fallback.patch
Patch108: grub2-btrfs-08-workaround-snapshot-menu-default-entry.patch
Patch109: grub2-btrfs-09-get-default-subvolume.patch
Patch110: grub2-btrfs-10-config-directory.patch
# Support EFI xen loader
Patch120: grub2-efi-xen-chainload.patch
Patch121: grub2-efi-chainloader-root.patch
@ -252,6 +253,7 @@ Patch211: grub2-ppc64-cas-reboot-support.patch
Patch212: grub2-install-remove-useless-check-PReP-partition-is-empty.patch
Patch213: grub2-Fix-incorrect-netmask-on-ppc64.patch
Patch214: grub2-ieee1275-open-raw-mode.patch
Patch215: grub2-ppc64-cas-new-scope.patch
Patch233: grub2-use-stat-instead-of-udevadm-for-partition-lookup.patch
Patch234: fix-grub2-use-stat-instead-of-udevadm-for-partition-lookup-with-new-glibc.patch
Patch236: grub2-efi_gop-avoid-low-resolution.patch
@ -517,6 +519,7 @@ swap partition while in resuming
%patch107 -p1
%patch108 -p1
%patch109 -p1
%patch110 -p1
%patch120 -p1
%patch121 -p1
%patch122 -p1
@ -535,6 +538,7 @@ swap partition while in resuming
%patch212 -p1
%patch213 -p1
%patch214 -p1
%patch215 -p1
%patch233 -p1
%patch234 -p1
%patch236 -p1