Accepting request 245527 from home:michael-chang:test

- snapper rollback support patches.
- rename patch
  * 0002-btrfs-add-ability-to-boot-from-subvolumes.patch to
    grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch
  * 0004-btrfs-export-subvolume-envvars.patch to
    grub2-btrfs-02-export-subvolume-envvars.patch
- added patches
  * grub2-btrfs-03-follow_default.patch
  * grub2-btrfs-04-grub2-install.patch
  * grub2-btrfs-05-grub2-mkconfig.patch 
- remove patch
  * 0003-cmdline-add-envvar-loader_cmdline_append.patch

OBS-URL: https://build.opensuse.org/request/show/245527
OBS-URL: https://build.opensuse.org/package/show/Base:System/grub2?expand=0&rev=106
This commit is contained in:
Michael Chang 2014-08-21 03:39:11 +00:00 committed by Git OBS Bridge
parent 9b3ed0ba28
commit 165a6b361f
8 changed files with 506 additions and 71 deletions

View File

@ -1,66 +0,0 @@
From: Michael Chang <mchang@suse.com>
Subject: add loader_cmdline_append environment variable
Add loader_cmdline_append environment variable that appends it's
value to the loader's command line. We can use this variable to
assign values determined at run time. It will take effect on any
subsidiary configs loaded using configfile as well.
By means of this variable, we can, for example, set rootflags=
according to the selected btrfs snapshots and tell linux kernel's
btrfs module to mount the snapshot by the subvolume name or id.
Signed-off-by: Michael Chang <mchang@suse.com>
---
grub-core/lib/cmdline.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c
index a702e64..c5be945 100644
--- a/grub-core/lib/cmdline.c
+++ b/grub-core/lib/cmdline.c
@@ -19,6 +19,8 @@
#include <grub/lib/cmdline.h>
#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/env.h>
static unsigned int check_arg (char *c, int *has_space)
{
@@ -65,6 +67,8 @@ int grub_create_loader_cmdline (int argc, char *argv[], char *buf,
int i, space;
unsigned int arg_size;
char *c;
+ const char *append = NULL;
+ grub_size_t append_size = 0;
for (i = 0; i < argc; i++)
{
@@ -95,6 +99,23 @@ int grub_create_loader_cmdline (int argc, char *argv[], char *buf,
*buf++ = ' ';
}
+ append = grub_env_get ("loader_cmdline_append");
+
+ if (append)
+ append_size = grub_strlen (append);
+
+ if (append_size)
+ {
+ append_size++;
+ if (size >= append_size)
+ {
+ grub_strcpy (buf, append);
+ buf += append_size;
+ size -= append_size;
+ i++;
+ }
+ }
+
/* Replace last space with null. */
if (i)
buf--;
--
1.8.1.4

View File

@ -0,0 +1,187 @@
Index: grub-2.02~beta2/grub-core/fs/btrfs.c
===================================================================
--- grub-2.02~beta2.orig/grub-core/fs/btrfs.c
+++ grub-2.02~beta2/grub-core/fs/btrfs.c
@@ -913,6 +913,7 @@ grub_btrfs_mount (grub_device_t dev)
{
struct grub_btrfs_data *data;
grub_err_t err;
+ const char *relpath = grub_env_get ("btrfs_relative_path");
if (!dev->disk)
{
@@ -943,11 +944,14 @@ grub_btrfs_mount (grub_device_t dev)
data->devices_attached[0].dev = dev;
data->devices_attached[0].id = data->sblock.this_device.device_id;
- err = btrfs_handle_subvol (data);
- if (err)
+ if (relpath && (relpath[0] == '1' || relpath[0] == 'y'))
{
- grub_free (data);
- return NULL;
+ err = btrfs_handle_subvol (data);
+ if (err)
+ {
+ grub_free (data);
+ return NULL;
+ }
}
return data;
@@ -1407,24 +1411,39 @@ find_path (struct grub_btrfs_data *data,
grub_size_t allocated = 0;
struct grub_btrfs_dir_item *direl = NULL;
struct grub_btrfs_key key_out;
+ int follow_default;
const char *ctoken;
grub_size_t ctokenlen;
char *path_alloc = NULL;
char *origpath = NULL;
unsigned symlinks_max = 32;
+ const char *relpath = grub_env_get ("btrfs_relative_path");
+ follow_default = 0;
origpath = grub_strdup (path);
if (!origpath)
return grub_errno;
- if (data->fs_tree)
+ if (relpath && (relpath[0] == '1' || relpath[0] == 'y'))
{
- *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
- *tree = data->fs_tree;
- /* This is a tree root, so everything starts at objectid 256 */
- key->object_id = grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK);
- key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
- key->offset = 0;
+ if (data->fs_tree)
+ {
+ *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
+ *tree = data->fs_tree;
+ /* This is a tree root, so everything starts at objectid 256 */
+ key->object_id = grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK);
+ key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
+ key->offset = 0;
+ }
+ else
+ {
+ *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
+ *tree = data->sblock.root_tree;
+ key->object_id = data->sblock.root_dir_objectid;
+ key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
+ key->offset = 0;
+ follow_default = 1;
+ }
}
else
{
@@ -1435,15 +1454,23 @@ find_path (struct grub_btrfs_data *data,
while (1)
{
- while (path[0] == '/')
- path++;
- if (!path[0])
- break;
- slash = grub_strchr (path, '/');
- if (!slash)
- slash = path + grub_strlen (path);
- ctoken = path;
- ctokenlen = slash - path;
+ if (!follow_default)
+ {
+ while (path[0] == '/')
+ path++;
+ if (!path[0])
+ break;
+ slash = grub_strchr (path, '/');
+ if (!slash)
+ slash = path + grub_strlen (path);
+ ctoken = path;
+ ctokenlen = slash - path;
+ }
+ else
+ {
+ ctoken = "default";
+ ctokenlen = sizeof ("default") - 1;
+ }
if (*type != GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY)
{
@@ -1454,7 +1481,9 @@ find_path (struct grub_btrfs_data *data,
if (ctokenlen == 1 && ctoken[0] == '.')
{
- path = slash;
+ if (!follow_default)
+ path = slash;
+ follow_default = 0;
continue;
}
if (ctokenlen == 2 && ctoken[0] == '.' && ctoken[1] == '.')
@@ -1485,8 +1514,9 @@ find_path (struct grub_btrfs_data *data,
*type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
key->object_id = key_out.offset;
- path = slash;
-
+ if (!follow_default)
+ path = slash;
+ follow_default = 0;
continue;
}
@@ -1555,7 +1585,9 @@ find_path (struct grub_btrfs_data *data,
return err;
}
- path = slash;
+ if (!follow_default)
+ path = slash;
+ follow_default = 0;
if (cdirel->type == GRUB_BTRFS_DIR_ITEM_TYPE_SYMLINK)
{
struct grub_btrfs_inode inode;
@@ -1605,14 +1637,26 @@ find_path (struct grub_btrfs_data *data,
path = path_alloc = tmp;
if (path[0] == '/')
{
- if (data->fs_tree)
+ if (relpath && (relpath[0] == '1' || relpath[0] == 'y'))
{
- *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
- *tree = data->fs_tree;
- /* This is a tree root, so everything starts at objectid 256 */
- key->object_id = grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK);
- key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
- key->offset = 0;
+ if (data->fs_tree)
+ {
+ *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
+ *tree = data->fs_tree;
+ /* This is a tree root, so everything starts at objectid 256 */
+ key->object_id = grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK);
+ key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
+ key->offset = 0;
+ }
+ else
+ {
+ *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
+ *tree = data->sblock.root_tree;
+ key->object_id = data->sblock.root_dir_objectid;
+ key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
+ key->offset = 0;
+ follow_default = 1;
+ }
}
else
{
@@ -2268,6 +2312,7 @@ GRUB_MOD_INIT (btrfs)
subvolid_set_env);
grub_env_export ("btrfs_subvol");
grub_env_export ("btrfs_subvolid");
+ grub_env_export ("btrfs_relative_path");
}
GRUB_MOD_FINI (btrfs)

View File

@ -0,0 +1,160 @@
Index: grub-2.02~beta2/grub-core/osdep/unix/config.c
===================================================================
--- grub-2.02~beta2.orig/grub-core/osdep/unix/config.c
+++ grub-2.02~beta2/grub-core/osdep/unix/config.c
@@ -82,6 +82,19 @@ grub_util_load_config (struct grub_util_
if (v)
cfg->grub_distributor = xstrdup (v);
+ v = getenv ("SUSE_BTRFS_SNAPSHOT_BOOTING");
+ if (v)
+ {
+ if (grub_strncmp(v, "true", sizeof ("true") - 1) == 0)
+ {
+ cfg->is_suse_btrfs_snapshot_enabled = 1;
+ }
+ else
+ {
+ cfg->is_suse_btrfs_snapshot_enabled = 0;
+ }
+ }
+
cfgfile = grub_util_get_config_filename ();
if (!grub_util_is_regular (cfgfile))
return;
@@ -105,8 +118,8 @@ grub_util_load_config (struct grub_util_
*ptr++ = *iptr;
}
- strcpy (ptr, "'; printf \"GRUB_ENABLE_CRYPTODISK=%s\\nGRUB_DISTRIBUTOR=%s\\n\", "
- "\"$GRUB_ENABLE_CRYPTODISK\", \"$GRUB_DISTRIBUTOR\"");
+ strcpy (ptr, "'; printf \"GRUB_ENABLE_CRYPTODISK=%s\\nGRUB_DISTRIBUTOR=%s\\nSUSE_BTRFS_SNAPSHOT_BOOTING=%s\\n\", "
+ "\"$GRUB_ENABLE_CRYPTODISK\", \"$GRUB_DISTRIBUTOR\", \"$SUSE_BTRFS_SNAPSHOT_BOOTING\"");
argv[2] = script;
argv[3] = '\0';
Index: grub-2.02~beta2/include/grub/emu/config.h
===================================================================
--- grub-2.02~beta2.orig/include/grub/emu/config.h
+++ grub-2.02~beta2/include/grub/emu/config.h
@@ -37,6 +37,7 @@ struct grub_util_config
{
int is_cryptodisk_enabled;
char *grub_distributor;
+ int is_suse_btrfs_snapshot_enabled;
};
void
Index: grub-2.02~beta2/util/config.c
===================================================================
--- grub-2.02~beta2.orig/util/config.c
+++ grub-2.02~beta2/util/config.c
@@ -42,6 +42,16 @@ grub_util_parse_config (FILE *f, struct
cfg->is_cryptodisk_enabled = 1;
continue;
}
+ if (grub_strncmp (ptr, "SUSE_BTRFS_SNAPSHOT_BOOTING=",
+ sizeof ("SUSE_BTRFS_SNAPSHOT_BOOTING=") - 1) == 0)
+ {
+ ptr += sizeof ("SUSE_BTRFS_SNAPSHOT_BOOTING=") - 1;
+ if (*ptr == '"' || *ptr == '\'')
+ ptr++;
+ if (grub_strncmp(ptr, "true", sizeof ("true") - 1) == 0)
+ cfg->is_suse_btrfs_snapshot_enabled = 1;
+ continue;
+ }
if (grub_strncmp (ptr, "GRUB_DISTRIBUTOR=",
sizeof ("GRUB_DISTRIBUTOR=") - 1) == 0)
{
Index: grub-2.02~beta2/util/grub-install.c
===================================================================
--- grub-2.02~beta2.orig/util/grub-install.c
+++ grub-2.02~beta2/util/grub-install.c
@@ -816,6 +816,8 @@ fill_core_services (const char *core_ser
free (sysv_plist);
}
+extern int use_relative_path_on_btrfs;
+
int
main (int argc, char *argv[])
{
@@ -849,6 +851,9 @@ main (int argc, char *argv[])
grub_util_load_config (&config);
+ if (config.is_suse_btrfs_snapshot_enabled)
+ use_relative_path_on_btrfs = 1;
+
if (!bootloader_id && config.grub_distributor)
{
char *ptr;
@@ -1334,6 +1339,16 @@ main (int argc, char *argv[])
fprintf (load_cfg_f, "set debug='%s'\n",
debug_image);
}
+
+ if (config.is_suse_btrfs_snapshot_enabled
+ && grub_strncmp(grub_fs->name, "btrfs", sizeof ("btrfs") - 1) == 0)
+ {
+ if (!load_cfg_f)
+ load_cfg_f = grub_util_fopen (load_cfg, "wb");
+ have_load_cfg = 1;
+ fprintf (load_cfg_f, "set btrfs_relative_path='y'\n");
+ }
+
char *prefix_drive = NULL;
char *install_drive = NULL;
Index: grub-2.02~beta2/grub-core/osdep/linux/getroot.c
===================================================================
--- grub-2.02~beta2.orig/grub-core/osdep/linux/getroot.c
+++ grub-2.02~beta2/grub-core/osdep/linux/getroot.c
@@ -364,6 +364,7 @@ get_btrfs_fs_prefix (const char *mount_p
return ret;
}
+int use_relative_path_on_btrfs = 0;
char **
grub_find_root_devices_from_mountinfo (const char *dir, char **relroot)
@@ -502,6 +503,12 @@ grub_find_root_devices_from_mountinfo (c
{
ret = grub_find_root_devices_from_btrfs (dir);
fs_prefix = get_btrfs_fs_prefix (entries[i].enc_path);
+ if (use_relative_path_on_btrfs)
+ {
+ if (fs_prefix)
+ free (fs_prefix);
+ fs_prefix = xstrdup ("/");
+ }
}
if (!ret)
{
Index: grub-2.02~beta2/util/grub-mkrelpath.c
===================================================================
--- grub-2.02~beta2.orig/util/grub-mkrelpath.c
+++ grub-2.02~beta2/util/grub-mkrelpath.c
@@ -40,9 +40,12 @@ struct arguments
};
static struct argp_option options[] = {
+ {"relative", 'r', 0, 0, "use relative path on btrfs", 0},
{ 0, 0, 0, 0, 0, 0 }
};
+extern int use_relative_path_on_btrfs;
+
static error_t
argp_parser (int key, char *arg, struct argp_state *state)
{
@@ -52,6 +55,9 @@ argp_parser (int key, char *arg, struct
switch (key)
{
+ case 'r':
+ use_relative_path_on_btrfs = 1;
+ break;
case ARGP_KEY_ARG:
if (state->arg_num == 0)
arguments->pathname = xstrdup (arg);

View File

@ -0,0 +1,134 @@
---
util/grub-mkconfig.in | 3 ++-
util/grub-mkconfig_lib.in | 4 ++++
util/grub.d/00_header.in | 23 ++++++++++++++++++++++-
util/grub.d/10_linux.in | 11 ++++++++++-
util/grub.d/20_linux_xen.in | 4 ++++
5 files changed, 42 insertions(+), 3 deletions(-)
Index: grub-2.02~beta2/util/grub-mkconfig_lib.in
===================================================================
--- grub-2.02~beta2.orig/util/grub-mkconfig_lib.in
+++ grub-2.02~beta2/util/grub-mkconfig_lib.in
@@ -49,7 +49,11 @@ grub_warn ()
make_system_path_relative_to_its_root ()
{
+ if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] ; then
+ "${grub_mkrelpath}" -r "$1"
+ else
"${grub_mkrelpath}" "$1"
+ fi
}
is_path_readable_by_grub ()
Index: grub-2.02~beta2/util/grub.d/00_header.in
===================================================================
--- grub-2.02~beta2.orig/util/grub.d/00_header.in
+++ grub-2.02~beta2/util/grub.d/00_header.in
@@ -27,6 +27,14 @@ export TEXTDOMAINDIR="@localedir@"
. "@datadir@/@PACKAGE@/grub-mkconfig_lib"
+if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] &&
+ [ "x${GRUB_FS}" = "xbtrfs" ] ; then
+ cat <<EOF
+set btrfs_relative_path="y"
+export btrfs_relative_path
+EOF
+fi
+
# Do this as early as possible, since other commands might depend on it.
# (e.g. the `loadfont' command might need lvm or raid modules)
for i in ${GRUB_PRELOAD_MODULES} ; do
@@ -43,7 +51,9 @@ if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved
if [ "x${GRUB_TIMEOUT_BUTTON}" = "x" ] ; then GRUB_TIMEOUT_BUTTON="$GRUB_TIMEOUT" ; fi
cat << EOF
-if [ -s \$prefix/grubenv ]; then
+if [ -f \${config_directory}/grubenv ]; then
+ load_env -f \${config_directory}/grubenv
+elif [ -s \$prefix/grubenv ]; then
load_env
fi
EOF
@@ -356,3 +366,14 @@ fi
if [ "x${GRUB_BADRAM}" != "x" ] ; then
echo "badram ${GRUB_BADRAM}"
fi
+
+if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] &&
+ [ "x${GRUB_FS}" = "xbtrfs" ] ; then
+ cat <<EOF
+if [ -n "\$extra_cmdline" ]; then
+ submenu "Bootable snapshot #\$snapshot_num" {
+ menuentry "If OK, run 'snapper rollback \$snapshot_num' and reboot." { true; }
+ }
+fi
+EOF
+fi
Index: grub-2.02~beta2/util/grub-mkconfig.in
===================================================================
--- grub-2.02~beta2.orig/util/grub-mkconfig.in
+++ grub-2.02~beta2/util/grub-mkconfig.in
@@ -250,7 +250,8 @@ export GRUB_DEFAULT \
GRUB_OS_PROBER_SKIP_LIST \
GRUB_DISABLE_SUBMENU \
GRUB_CMDLINE_LINUX_RECOVERY \
- GRUB_USE_LINUXEFI
+ GRUB_USE_LINUXEFI \
+ SUSE_BTRFS_SNAPSHOT_BOOTING
if test "x${grub_cfg}" != "x"; then
rm -f "${grub_cfg}.new"
Index: grub-2.02~beta2/util/grub.d/10_linux.in
===================================================================
--- grub-2.02~beta2.orig/util/grub.d/10_linux.in
+++ grub-2.02~beta2/util/grub.d/10_linux.in
@@ -53,10 +53,14 @@ fi
case x"$GRUB_FS" in
xbtrfs)
+ if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then
+ GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}"
+ else
rootsubvol="`make_system_path_relative_to_its_root /`"
rootsubvol="${rootsubvol#/}"
if [ "x${rootsubvol}" != x ]; then
GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
+ fi
fi;;
xzfs)
rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
@@ -194,6 +198,12 @@ while [ "x$list" != "x" ] ; do
basename=`basename $linux`
dirname=`dirname $linux`
rel_dirname=`make_system_path_relative_to_its_root $dirname`
+ if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] &&
+ [ "x${GRUB_FS}" = "xbtrfs" ] ; then
+ rel_dirname="\${btrfs_subvol}$dirname"
+ else
+ rel_dirname="$dirname"
+ fi
version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
alt_version=`echo $version | sed -e "s,\.old$,,g"`
linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
Index: grub-2.02~beta2/util/grub.d/20_linux_xen.in
===================================================================
--- grub-2.02~beta2.orig/util/grub.d/20_linux_xen.in
+++ grub-2.02~beta2/util/grub.d/20_linux_xen.in
@@ -67,10 +67,14 @@ fi
case x"$GRUB_FS" in
xbtrfs)
+ if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then
+ GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}"
+ else
rootsubvol="`make_system_path_relative_to_its_root /`"
rootsubvol="${rootsubvol#/}"
if [ "x${rootsubvol}" != x ]; then
GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
+ fi
fi;;
xzfs)
rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`

View File

@ -1,3 +1,19 @@
-------------------------------------------------------------------
Fri Aug 15 07:55:54 UTC 2014 - mchang@suse.com
- snapper rollback support patches.
- rename patch
* 0002-btrfs-add-ability-to-boot-from-subvolumes.patch to
grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch
* 0004-btrfs-export-subvolume-envvars.patch to
grub2-btrfs-02-export-subvolume-envvars.patch
- added patches
* grub2-btrfs-03-follow_default.patch
* grub2-btrfs-04-grub2-install.patch
* grub2-btrfs-05-grub2-mkconfig.patch
- remove patch
* 0003-cmdline-add-envvar-loader_cmdline_append.patch
-------------------------------------------------------------------
Thu Aug 14 06:35:58 UTC 2014 - mchang@suse.com

View File

@ -151,9 +151,11 @@ Patch40: aarch64-reloc.patch
Patch41: grub2-vbe-blacklist-preferred-1440x900x32.patch
Patch42: grub2-btrfs-fix-incorrect-address-reference.patch
# Btrfs snapshot booting related patches
Patch101: 0002-btrfs-add-ability-to-boot-from-subvolumes.patch
Patch102: 0003-cmdline-add-envvar-loader_cmdline_append.patch
Patch103: 0004-btrfs-export-subvolume-envvars.patch
Patch101: grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch
Patch102: grub2-btrfs-02-export-subvolume-envvars.patch
Patch103: grub2-btrfs-03-follow_default.patch
Patch104: grub2-btrfs-04-grub2-install.patch
Patch105: grub2-btrfs-05-grub2-mkconfig.patch
Patch110: 0001-script-provide-overridable-root-by-subvol.patch
Patch111: 0002-script-create-menus-for-btrfs-snapshot.patch
# PowerPC LE support
@ -354,8 +356,10 @@ mv po/grub.pot po/%{name}.pot
%patch101 -p1
%patch102 -p1
%patch103 -p1
%patch110 -p1
%patch111 -p1
%patch104 -p1
%patch105 -p1
#%patch110 -p1
#%patch111 -p1
%patch201 -p1
%patch202 -p1
%patch203 -p1