From 165a6b361f8fa09c5b06742fb78b8e607f376c704e631be80245891e4be7e8a3 Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Thu, 21 Aug 2014 03:39:11 +0000 Subject: [PATCH] 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 --- ...ine-add-envvar-loader_cmdline_append.patch | 66 ------- ...-add-ability-to-boot-from-subvolumes.patch | 0 ...b2-btrfs-02-export-subvolume-envvars.patch | 0 grub2-btrfs-03-follow_default.patch | 187 ++++++++++++++++++ grub2-btrfs-04-grub2-install.patch | 160 +++++++++++++++ grub2-btrfs-05-grub2-mkconfig.patch | 134 +++++++++++++ grub2.changes | 16 ++ grub2.spec | 14 +- 8 files changed, 506 insertions(+), 71 deletions(-) delete mode 100644 0003-cmdline-add-envvar-loader_cmdline_append.patch rename 0002-btrfs-add-ability-to-boot-from-subvolumes.patch => grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch (100%) rename 0004-btrfs-export-subvolume-envvars.patch => grub2-btrfs-02-export-subvolume-envvars.patch (100%) create mode 100644 grub2-btrfs-03-follow_default.patch create mode 100644 grub2-btrfs-04-grub2-install.patch create mode 100644 grub2-btrfs-05-grub2-mkconfig.patch diff --git a/0003-cmdline-add-envvar-loader_cmdline_append.patch b/0003-cmdline-add-envvar-loader_cmdline_append.patch deleted file mode 100644 index f32f6bf..0000000 --- a/0003-cmdline-add-envvar-loader_cmdline_append.patch +++ /dev/null @@ -1,66 +0,0 @@ -From: Michael Chang -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 ---- - 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 - #include -+#include -+#include - - 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 - diff --git a/0002-btrfs-add-ability-to-boot-from-subvolumes.patch b/grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch similarity index 100% rename from 0002-btrfs-add-ability-to-boot-from-subvolumes.patch rename to grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch diff --git a/0004-btrfs-export-subvolume-envvars.patch b/grub2-btrfs-02-export-subvolume-envvars.patch similarity index 100% rename from 0004-btrfs-export-subvolume-envvars.patch rename to grub2-btrfs-02-export-subvolume-envvars.patch diff --git a/grub2-btrfs-03-follow_default.patch b/grub2-btrfs-03-follow_default.patch new file mode 100644 index 0000000..9c797b8 --- /dev/null +++ b/grub2-btrfs-03-follow_default.patch @@ -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) diff --git a/grub2-btrfs-04-grub2-install.patch b/grub2-btrfs-04-grub2-install.patch new file mode 100644 index 0000000..e0f7889 --- /dev/null +++ b/grub2-btrfs-04-grub2-install.patch @@ -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); diff --git a/grub2-btrfs-05-grub2-mkconfig.patch b/grub2-btrfs-05-grub2-mkconfig.patch new file mode 100644 index 0000000..f46496f --- /dev/null +++ b/grub2-btrfs-05-grub2-mkconfig.patch @@ -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 </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` diff --git a/grub2.changes b/grub2.changes index beb7f59..b7c7818 100644 --- a/grub2.changes +++ b/grub2.changes @@ -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 diff --git a/grub2.spec b/grub2.spec index 2f7fd27..8fe5ffe 100644 --- a/grub2.spec +++ b/grub2.spec @@ -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