Re: [PATCH] efinet: Skip virtual VLAN devices during card enumeration
On Fri, Oct 18, 2024 at 08:08:28AM GMT, zhangqiumiao wrote: > > On Thu, Oct 03, 2024 at 03:23:15PM +0800, Michael Chang via Grub-devel > > wrote: > >> Similar to the fix in commit "c52ae4057 efinet: skip virtual IPv4 and > >> IPv6 devices during card enumeration", the UEFI PXE driver creates > >> additional VLAN child devices when a VLAN ID is configured on a network > >> interface associated with a physical NIC. These virtual VLAN devices > >> must be skipped during card enumeration to ensure that the subsequent > >> SNP exclusive open operation targets the correct physical card > >> instances, otherwise packet transfer would fail. > >> > >> Example device path with VLAN nodes: > >> > >> /MAC(123456789ABC,0x1)/Vlan(20)/IPv4(0.0.0.0,0x0,DHCP,0.0.0.0,0.0.0.0,0.0.0.0) > >> > >> Signed-Off-by: Michael Chang > > > > Reviewed-by: Daniel Kiper > > > > Daniel > > I submitted almost the same patch in August this year, more than a month > earlier than Michael Chang's patch. Why did the community ignore my patch and > accept his patch instead? Hi zhangqiumiao, I don't think it was intentional. There were times my patch was overlooked as well. With the mailing list constantly flooded with new patches every day, it's possible that it simply got buried and went unnoticed. In such cases, resending the patch might help remind the maintainer. > > The patch I submitted in August: > https://www.mail-archive.com/grub-devel@gnu.org/msg38860.html Unfortunately I overlooked yours fix in the mailing list as well when trying to solved the reported issue (and coincidently that was reported on a huawei system too). Anyway, Let's ping Daniel if he can help to drop mine and commit yours. Hi Daniel, Could you please help on that ? Thanks, Michael ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v3 22/29] btrfs: Add ability to boot from subvolumes
On Mon, Oct 14, 2024 at 1:11 PM Leo Sandoval wrote: > > From: Jeff Mahoney > > This patch adds the ability to specify a different root on a btrfs > filesystem too boot from other than the default one. > > btrfs-list-snapshots will list the subvolumes available on the > filesystem. > > set btrfs_subvol= and set btrfs_subvolid= will specify > which subvolume to use and any pathnames provided with either of those > variables set will start using that root. If the subvolume or subvolume id > doesn't exist, then an error case will result. > > It is possible to boot into a separate GRUB instance by exporting the > variable and loading the config file from the subvolume. > > Signed-off-by: Jeff Mahoney > --- > grub-core/fs/btrfs.c | 554 +-- > include/grub/btrfs.h | 1 + > 2 files changed, 534 insertions(+), 21 deletions(-) > > diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c > index ba0c58352..f14fe9c1b 100644 > --- a/grub-core/fs/btrfs.c > +++ b/grub-core/fs/btrfs.c > @@ -38,6 +38,9 @@ > #include > #include > #include > +#include > +#include > +#include > #include > #include > #include > @@ -79,9 +82,11 @@ struct grub_btrfs_superblock >grub_uint64_t generation; >grub_uint64_t root_tree; >grub_uint64_t chunk_tree; > - grub_uint8_t dummy2[0x20]; > + grub_uint8_t dummy2[0x18]; > + grub_uint64_t bytes_used; >grub_uint64_t root_dir_objectid; > - grub_uint8_t dummy3[0x41]; > + grub_uint64_t num_devices; > + grub_uint8_t dummy3[0x39]; >struct grub_btrfs_device this_device; >char label[0x100]; >grub_uint8_t dummy4[0x100]; > @@ -121,6 +126,7 @@ struct grub_btrfs_data >grub_uint64_t exttree; >grub_size_t extsize; >struct grub_btrfs_extent_data *extent; > + grub_uint64_t fs_tree; > }; > > struct grub_btrfs_chunk_item > @@ -191,6 +197,14 @@ struct grub_btrfs_leaf_descriptor >} *data; > }; > > +struct grub_btrfs_root_ref > +{ > + grub_uint64_t dirid; > + grub_uint64_t sequence; > + grub_uint16_t name_len; > + const char name[0]; > +} __attribute__ ((packed)); > + > struct grub_btrfs_time > { >grub_int64_t sec; > @@ -236,6 +250,14 @@ struct grub_btrfs_extent_data > > #define GRUB_BTRFS_OBJECT_ID_CHUNK 0x100 > > +#define GRUB_BTRFS_ROOT_TREE_OBJECTID 1ULL > +#define GRUB_BTRFS_FS_TREE_OBJECTID 5ULL > +#define GRUB_BTRFS_ROOT_REF_KEY 156 > +#define GRUB_BTRFS_ROOT_ITEM_KEY 132 > + > +static grub_uint64_t btrfs_default_subvolid = 0; > +static char *btrfs_default_subvol = NULL; > + > static grub_disk_addr_t superblock_sectors[] = { 64 * 2, 64 * 1024 * 2, >256 * 1048576 * 2, 1048576ULL * 1048576ULL * 2 > }; > @@ -1252,6 +1274,62 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, > grub_disk_addr_t addr, >return GRUB_ERR_NONE; > } > > +static grub_err_t > +get_fs_root(struct grub_btrfs_data *data, grub_uint64_t tree, > +grub_uint64_t objectid, grub_uint64_t offset, > +grub_uint64_t *fs_root); > + > +static grub_err_t > +lookup_root_by_id(struct grub_btrfs_data *data, grub_uint64_t id) > +{ > + grub_err_t err; > + grub_uint64_t tree; > + > + err = get_fs_root(data, data->sblock.root_tree, id, -1, &tree); > + if (!err) > +data->fs_tree = tree; > + return err; > +} > + > +static grub_err_t > +find_path (struct grub_btrfs_data *data, > + const char *path, struct grub_btrfs_key *key, > + grub_uint64_t *tree, grub_uint8_t *type); > + > +static grub_err_t > +lookup_root_by_name(struct grub_btrfs_data *data, const char *path) > +{ > + grub_err_t err; > + grub_uint64_t tree = 0; > + grub_uint8_t type; > + struct grub_btrfs_key key; > + > + err = find_path (data, path, &key, &tree, &type); > + if (err) > + return grub_error(GRUB_ERR_FILE_NOT_FOUND, "couldn't locate %s\n", > path); > + > + if (key.object_id != grub_cpu_to_le64_compile_time > (GRUB_BTRFS_OBJECT_ID_CHUNK) || tree == 0) > +return grub_error(GRUB_ERR_BAD_FILE_TYPE, "%s: not a subvolume\n", path); > + > + data->fs_tree = tree; > + return GRUB_ERR_NONE; > +} > + > +static grub_err_t > +btrfs_handle_subvol(struct grub_btrfs_data *data __attribute__ ((unused))) > +{ > + if (btrfs_default_subvol) > +return lookup_root_by_name(data, btrfs_default_subvol); > + > + if (btrfs_default_subvolid) > +return lookup_root_by_id(data, btrfs_default_subvolid); > + > + data->fs_tree = 0; > + > + return GRUB_ERR_NONE; > +} > + > + > static struct grub_btrfs_data * > grub_btrfs_mount (grub_device_t dev) > { > @@ -1287,6 +1365,13 @@ 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) > +{ > + grub_free (data); > + return NULL; > +} > + >return data; > } > > @@ -1784,6 +1869,91 @@ get_root (struct grub_btrfs_data *data, struct > grub_btrfs_key *key, >return GRUB_ERR_NONE; > } >
Re: [PATCH v3 23/29] btrfs: fix a bad null check
On Mon, Oct 14, 2024 at 1:10 PM Leo Sandoval wrote: > > From: Peter Jones > > current gcc complains: > > grub-core/fs/btrfs.c: In function ‘grub_cmd_btrfs_info’: > grub-core/fs/btrfs.c:2745:7: error: the comparison will always evaluate as > ‘true’ for the address of ‘label’ will never be NULL [-Werror=address] >2745 | if (data->sblock.label) > | ^~~~ > grub-core/fs/btrfs.c:92:8: note: ‘label’ declared here > 92 | char label[0x100]; > |^ > cc1: all warnings being treated as errors > > Obviously this check should be on the first data byte instead of the > symbol itself. > > Signed-off-by: Peter Jones > --- > grub-core/fs/btrfs.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c > index f14fe9c1b..8e2b1e9f7 100644 > --- a/grub-core/fs/btrfs.c > +++ b/grub-core/fs/btrfs.c > @@ -2625,7 +2625,7 @@ grub_cmd_btrfs_info (grub_command_t cmd __attribute__ > ((unused)), int argc, >return grub_error (GRUB_ERR_BAD_ARGUMENT, "failed to open fs"); > } > > - if (data->sblock.label) > + if (data->sblock.label[0]) > grub_printf("Label: '%s' ", data->sblock.label); >else > grub_printf("Label: none "); > -- > 2.46.2 > Straightforward and reasonable. Reviewed-by: Neal Gompa -- 真実はいつも一つ!/ Always, there's only one truth! ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v3 24/29] btrfs: export btrfs_subvol and btrfs_subvolid
On Mon, Oct 14, 2024 at 1:10 PM Leo Sandoval wrote: > > From: Michael Chang > > We should export btrfs_subvol and btrfs_subvolid to have both visible > to subsidiary configuration files loaded using configfile. > > Signed-off-by: Michael Chang > --- > grub-core/fs/btrfs.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c > index 8e2b1e9f7..14e38a4df 100644 > --- a/grub-core/fs/btrfs.c > +++ b/grub-core/fs/btrfs.c > @@ -2920,6 +2920,8 @@ GRUB_MOD_INIT (btrfs) > subvol_set_env); >grub_register_variable_hook ("btrfs_subvolid", subvolid_get_env, > subvolid_set_env); > + grub_env_export ("btrfs_subvol"); > + grub_env_export ("btrfs_subvolid"); > } > > GRUB_MOD_FINI (btrfs) > -- > 2.46.2 > LGTM. :) Reviewed-by: Neal Gompa -- 真実はいつも一つ!/ Always, there's only one truth! ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v3 22/29] btrfs: Add ability to boot from subvolumes
Le lun. 14 oct. 2024, 20:10, Leo Sandoval a écrit : > From: Jeff Mahoney > > This patch adds the ability to specify a different root on a btrfs > filesystem too boot from other than the default one. > Does it make available some files that are currentl y unavailable? Do you have an example? > > btrfs-list-snapshots will list the subvolumes available on the > filesystem. > > set btrfs_subvol= and set btrfs_subvolid= will specify > which subvolume to use and any pathnames provided with either of those > variables set will start using that root. If the subvolume or subvolume id > doesn't exist, then an error case will result. > > It is possible to boot into a separate GRUB instance by exporting the > variable and loading the config file from the subvolume. > > Signed-off-by: Jeff Mahoney > --- > grub-core/fs/btrfs.c | 554 +-- > include/grub/btrfs.h | 1 + > 2 files changed, 534 insertions(+), 21 deletions(-) > > diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c > index ba0c58352..f14fe9c1b 100644 > --- a/grub-core/fs/btrfs.c > +++ b/grub-core/fs/btrfs.c > @@ -38,6 +38,9 @@ > #include > #include > #include > +#include > +#include > +#include > #include > #include > #include > @@ -79,9 +82,11 @@ struct grub_btrfs_superblock >grub_uint64_t generation; >grub_uint64_t root_tree; >grub_uint64_t chunk_tree; > - grub_uint8_t dummy2[0x20]; > + grub_uint8_t dummy2[0x18]; > + grub_uint64_t bytes_used; >grub_uint64_t root_dir_objectid; > - grub_uint8_t dummy3[0x41]; > + grub_uint64_t num_devices; > + grub_uint8_t dummy3[0x39]; >struct grub_btrfs_device this_device; >char label[0x100]; >grub_uint8_t dummy4[0x100]; > @@ -121,6 +126,7 @@ struct grub_btrfs_data >grub_uint64_t exttree; >grub_size_t extsize; >struct grub_btrfs_extent_data *extent; > + grub_uint64_t fs_tree; > }; > > struct grub_btrfs_chunk_item > @@ -191,6 +197,14 @@ struct grub_btrfs_leaf_descriptor >} *data; > }; > > +struct grub_btrfs_root_ref > +{ > + grub_uint64_t dirid; > + grub_uint64_t sequence; > + grub_uint16_t name_len; > + const char name[0]; > +} __attribute__ ((packed)); > + > struct grub_btrfs_time > { >grub_int64_t sec; > @@ -236,6 +250,14 @@ struct grub_btrfs_extent_data > > #define GRUB_BTRFS_OBJECT_ID_CHUNK 0x100 > > +#define GRUB_BTRFS_ROOT_TREE_OBJECTID 1ULL > +#define GRUB_BTRFS_FS_TREE_OBJECTID 5ULL > +#define GRUB_BTRFS_ROOT_REF_KEY 156 > +#define GRUB_BTRFS_ROOT_ITEM_KEY 132 > + > +static grub_uint64_t btrfs_default_subvolid = 0; > +static char *btrfs_default_subvol = NULL; > + > static grub_disk_addr_t superblock_sectors[] = { 64 * 2, 64 * 1024 * 2, >256 * 1048576 * 2, 1048576ULL * 1048576ULL * 2 > }; > @@ -1252,6 +1274,62 @@ grub_btrfs_read_logical (struct grub_btrfs_data > *data, grub_disk_addr_t addr, >return GRUB_ERR_NONE; > } > > +static grub_err_t > +get_fs_root(struct grub_btrfs_data *data, grub_uint64_t tree, > +grub_uint64_t objectid, grub_uint64_t offset, > +grub_uint64_t *fs_root); > + > +static grub_err_t > +lookup_root_by_id(struct grub_btrfs_data *data, grub_uint64_t id) > +{ > + grub_err_t err; > + grub_uint64_t tree; > + > + err = get_fs_root(data, data->sblock.root_tree, id, -1, &tree); > + if (!err) > +data->fs_tree = tree; > + return err; > +} > + > +static grub_err_t > +find_path (struct grub_btrfs_data *data, > + const char *path, struct grub_btrfs_key *key, > + grub_uint64_t *tree, grub_uint8_t *type); > + > +static grub_err_t > +lookup_root_by_name(struct grub_btrfs_data *data, const char *path) > +{ > + grub_err_t err; > + grub_uint64_t tree = 0; > + grub_uint8_t type; > + struct grub_btrfs_key key; > + > + err = find_path (data, path, &key, &tree, &type); > + if (err) > + return grub_error(GRUB_ERR_FILE_NOT_FOUND, "couldn't locate %s\n", > path); > + > + if (key.object_id != grub_cpu_to_le64_compile_time > (GRUB_BTRFS_OBJECT_ID_CHUNK) || tree == 0) > +return grub_error(GRUB_ERR_BAD_FILE_TYPE, "%s: not a subvolume\n", > path); > + > + data->fs_tree = tree; > + return GRUB_ERR_NONE; > +} > + > +static grub_err_t > +btrfs_handle_subvol(struct grub_btrfs_data *data __attribute__ ((unused))) > +{ > + if (btrfs_default_subvol) > +return lookup_root_by_name(data, btrfs_default_subvol); > + > + if (btrfs_default_subvolid) > +return lookup_root_by_id(data, btrfs_default_subvolid); > + > + data->fs_tree = 0; > + > + return GRUB_ERR_NONE; > +} > + > + > static struct grub_btrfs_data * > grub_btrfs_mount (grub_device_t dev) > { > @@ -1287,6 +1365,13 @@ 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) > +{ > + grub_free (data); > + return NULL; > +} > + >return data; > } > > @@ -1784,6 +1869,91 @@ get_root (str
Re: [PATCH v3 26/29] grub-mkconfig: Add GRUB_BTRFS_SNAPSHOT_BOOTING simple configuration
On Mon, Oct 14, 2024 at 1:10 PM Leo Sandoval wrote: > > From: Michael Chang > > To support btrfs rollback and snapshot booting, a simple configuration setting > GRUB_BTRFS_SNAPSHOT_BOOTING is introduced to enable this at the configuration > level. When set to "yes," grub-mkconfig will set btrfs_relative_path=y, and > all > paths produced by grub-mkrelpath will be relative to the default subvolume. > > Signed-off-by: Michael Chang > --- > util/grub-mkconfig.in | 4 +++- > util/grub-mkconfig_lib.in | 4 > util/grub.d/00_header.in| 25 - > util/grub.d/10_linux.in | 4 > util/grub.d/20_linux_xen.in | 4 > 5 files changed, 39 insertions(+), 2 deletions(-) > > diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in > index 91f761331..b9932147d 100644 > --- a/util/grub-mkconfig.in > +++ b/util/grub-mkconfig.in > @@ -259,7 +259,9 @@ export GRUB_DEFAULT \ >GRUB_BADRAM \ >GRUB_OS_PROBER_SKIP_LIST \ >GRUB_DISABLE_SUBMENU \ > - GRUB_DEFAULT_DTB > + GRUB_DEFAULT_DTB \ > + GRUB_BTRFS_SNAPSHOT_BOOTING > + > > if test "x${grub_cfg}" != "x"; then >rm -f "${grub_cfg}.new" > diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in > index 33e1750ae..71e75f0bc 100644 > --- a/util/grub-mkconfig_lib.in > +++ b/util/grub-mkconfig_lib.in > @@ -49,7 +49,11 @@ grub_warn () > > make_system_path_relative_to_its_root () > { > + if [ "x${GRUB_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] ; then > + "${grub_mkrelpath}" -r "$1" > + else >"${grub_mkrelpath}" "$1" > + fi > } > > is_path_readable_by_grub () > diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in > index 6a316a5ba..2e94a4c95 100644 > --- a/util/grub.d/00_header.in > +++ b/util/grub.d/00_header.in > @@ -27,6 +27,14 @@ export TEXTDOMAINDIR="@localedir@" > > . "$pkgdatadir/grub-mkconfig_lib" > > +if [ "x${GRUB_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] && > + [ "x${GRUB_FS}" = "xbtrfs" ] ; then > +cat < +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" ] ; then > GRUB_DEFAULT_BUTTON='${saved_ > 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 > @@ -354,3 +364,16 @@ fi > if [ "x${GRUB_BADRAM}" != "x" ] ; then >echo "badram ${GRUB_BADRAM}" > fi > + > +if [ "x${GRUB_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] && > + [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ] && > + [ "x${GRUB_FS}" = "xbtrfs" ] ; then > +# Note: No $snapshot_num on *read-only* rollback! (bsc#901487) > +cat < +if [ -n "\$extra_cmdline" ]; then > + submenu "Bootable snapshot #\$snapshot_num" { > +menuentry "If OK, run 'snapper rollback' and reboot." { true; } > + } > +fi > +EOF > +fi > diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in > index b94af4a8d..c7a691051 100644 > --- a/util/grub.d/10_linux.in > +++ b/util/grub.d/10_linux.in > @@ -68,10 +68,14 @@ fi > > case x"$GRUB_FS" in > xbtrfs) > + if [ "x${GRUB_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/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in > index 94dd8be13..d6573bd8f 100644 > --- a/util/grub.d/20_linux_xen.in > +++ b/util/grub.d/20_linux_xen.in > @@ -75,10 +75,14 @@ fi > > case x"$GRUB_FS" in > xbtrfs) > + if [ "x${GRUB_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` > -- > 2.46.2 > LGTM. :) Reviewed-by: Neal Gompa -- 真実はいつも一つ!/ Always, there's only one truth! ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v3 25/29] btrfs: Allow specifying btrfs_relative_path to follow the default subvolume
On Mon, Oct 14, 2024 at 1:10 PM Leo Sandoval wrote: > > From: Michael Chang > > This patch enables the use of a relative path to the btrfs default subvolume > by > setting the environment variable btrfs_relative_path=[y1]. In contrast to > using > an absolute path from the toplevel root, which always reads files consistently > from a fixed location, the relative path allows grub to follow changes in the > default subvolume, which might occur as a consequence of a rollback operation. > > The btrfs_relative_path environment variable is available but not enabled by > default, so the default path remains aligned with the upstream definition. For > systems that do not require btrfs rollback or booting from snapshots, an > absolute path is preferred, as it makes path handling consistent with other > non-btrfs filesystems and allows file access throughout the filesystem > regardless of subvolumes, etc. > > Signed-off-by: Michael Chang > Signed-off-by: Robbie Harwood > --- > grub-core/fs/btrfs.c | 107 ++- > 1 file changed, 76 insertions(+), 31 deletions(-) > > diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c > index 14e38a4df..d47f9ab03 100644 > --- a/grub-core/fs/btrfs.c > +++ b/grub-core/fs/btrfs.c > @@ -1335,6 +1335,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) > { > @@ -1365,11 +1366,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; > @@ -1966,24 +1970,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 > { > @@ -1994,15 +2013,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) > { > @@ -2013,7 +2040,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] == '.') > @@ -2044,8 +2073,9 @@ find_path (struct grub_btrfs_data *data
Re: [PATCH v3 27/29] btrfs: add btrfs-get-default-subvol command
On Mon, Oct 14, 2024 at 1:10 PM Leo Sandoval wrote: > > From: Michael Chang > > Introduce the "btrfs-get-default-subvol" command to output the default > subvolume's name or id to the console, or to a variable specified via "-o". > > Some example usage: > > 1. Output the default subvolume's name or path: >btrfs-get-default-subvol -p ($root) > 2. Output the default subvolume's ID or number: >btrfs-get-default-subvol -n ($root) > 3. Output the default subvolume's path to a variable "btrfs_prefix": >btrfs-get-default-subvol -p -o btrfs_prefix ($root) > > This is useful in a prebuilt image like `grub.xen`, which is built at a time > when the guest configuration cannot be determined. In such a setup, trying to > enable "btrfs_relative_path" in the load configuration may lead to problems if > the guest image did not enable btrfs snapshots in its configuration. > > As a result, when attempting to locate grub.cfg in a guest, it may be > necessary > to specify the default subvolume in advance where the grub.cfg resides. The > script would look like this: > > btrfs-get-default-subvol -p -o btrfs_prefix ($root) > if [ -n "${btrfs_prefix}" ]; then > configfile "${btrfs_prefix}/boot/grub/grub.cfg" > else > configfile "/boot/grub/grub.cfg" > fi > > Signed-off-by: Michael Chang > Signed-off-by: Robbie Harwood > --- > grub-core/fs/btrfs.c | 238 +++ > 1 file changed, 238 insertions(+) > > diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c > index d47f9ab03..d93e9615a 100644 > --- a/grub-core/fs/btrfs.c > +++ b/grub-core/fs/btrfs.c > @@ -2876,6 +2876,238 @@ out: >return 0; > } > > +static grub_err_t > +grub_btrfs_get_parent_subvol_path (struct grub_btrfs_data *data, > + grub_uint64_t child_id, > + const char *child_path, > + grub_uint64_t *parent_id, > + char **path_out) > +{ > + grub_uint64_t fs_root = 0; > + struct grub_btrfs_key key_in = { > +.object_id = child_id, > +.type = GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF, > +.offset = 0, > + }, key_out; > + struct grub_btrfs_root_ref *ref; > + char *buf; > + struct grub_btrfs_leaf_descriptor desc; > + grub_size_t elemsize; > + grub_disk_addr_t elemaddr; > + grub_err_t err; > + char *parent_path; > + > + *parent_id = 0; > + *path_out = 0; > + > + err = lower_bound(data, &key_in, &key_out, data->sblock.root_tree, > +&elemaddr, &elemsize, &desc, 0); > + if (err) > +return err; > + > + if (key_out.type != GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF || elemaddr == 0) > +next(data, &desc, &elemaddr, &elemsize, &key_out); > + > + if (key_out.type != GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF) > +{ > + free_iterator(&desc); > + return grub_error(GRUB_ERR_FILE_NOT_FOUND, N_("can't find root > backrefs")); > +} > + > + buf = grub_malloc(elemsize + 1); > + if (!buf) > +{ > + free_iterator(&desc); > + return grub_errno; > +} > + > + err = grub_btrfs_read_logical(data, elemaddr, buf, elemsize, 0); > + if (err) > +{ > + grub_free(buf); > + free_iterator(&desc); > + return err; > +} > + > + buf[elemsize] = 0; > + ref = (struct grub_btrfs_root_ref *)buf; > + > + err = get_fs_root(data, data->sblock.root_tree, grub_le_to_cpu64 > (key_out.offset), > +0, &fs_root); > + if (err) > +{ > + grub_free(buf); > + free_iterator(&desc); > + return err; > +} > + > + find_pathname(data, grub_le_to_cpu64 (ref->dirid), fs_root, ref->name, > &parent_path); > + > + if (child_path) > +{ > + *path_out = grub_xasprintf ("%s/%s", parent_path, child_path); > + grub_free (parent_path); > +} > + else > +*path_out = parent_path; > + > + *parent_id = grub_le_to_cpu64 (key_out.offset); > + > + grub_free(buf); > + free_iterator(&desc); > + return GRUB_ERR_NONE; > +} > + > +static grub_err_t > +grub_btrfs_get_default_subvolume_id (struct grub_btrfs_data *data, > grub_uint64_t *id) > +{ > + grub_err_t err; > + grub_disk_addr_t elemaddr; > + grub_size_t elemsize; > + struct grub_btrfs_key key, key_out; > + struct grub_btrfs_dir_item *direl = NULL; > + const char *ctoken = "default"; > + grub_size_t ctokenlen = sizeof ("default") - 1; > + > + *id = 0; > + key.object_id = data->sblock.root_dir_objectid; > + key.type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM; > + key.offset = grub_cpu_to_le64 (~grub_getcrc32c (1, ctoken, ctokenlen)); > + err = lower_bound (data, &key, &key_out, data->sblock.root_tree, > &elemaddr, &elemsize, > +NULL, 0); > + if (err) > +return err; > + > + if (key_cmp (&key, &key_out) != 0) > +return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file not found")); > + > + struct grub_btrfs_dir_item *cdirel; > + direl = grub_malloc (elemsize + 1); > + err = grub_btrfs_read_logical (data, elemaddr, direl, elemsize, 0); > + if (err) > +{ > + grub_free (direl);
Re: [PATCH v3 22/29] btrfs: Add ability to boot from subvolumes
On Fri, Oct 18, 2024 at 1:39 PM Vladimir 'phcoder' Serbinenko wrote: > > > > Le lun. 14 oct. 2024, 20:10, Leo Sandoval a écrit : >> >> From: Jeff Mahoney >> >> This patch adds the ability to specify a different root on a btrfs >> filesystem too boot from other than the default one. > > Does it make available some files that are currentl y unavailable? Do you > have an example? This is currently in use by openSUSE's boot to snapshot method, and people also do this on Fedora manually as we provide all the tools to do it. -- 真実はいつも一つ!/ Always, there's only one truth! ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v19 30/33] tpm2_key_protector: Add grub-emu support
On Thu, Oct 17, 2024 at 07:57:11PM +0200, Daniel Kiper wrote: > On Fri, Sep 06, 2024 at 05:11:22PM +0800, Gary Lin via Grub-devel wrote: > > As a preparation to test tpm2_key_protector with grub-emu, the new > > option, --tpm-device, is introduced to specify the TPM device for > > grub-emu so that grub-emu can share the emulated TPM device with > > the host. > > s/can share the emulated TPM device with/can access an emulated TPM device > from/? > > > Since grub-emu can directly access the device node on host, it's easy to > > s/device node/device/ > Will fix them in the next version. > > implement the essential TCG2 command submission function with the > > read/write functions and enable tpm2_key_protector module for grub-emu, > > so that we can further test TPM2 key unsealing with grub-emu. > > > > Signed-off-by: Gary Lin > > Reviewed-by: Stefan Berger > > Otherwise Reviewed-by: Daniel Kiper ... > > ... and three nits below... > > > --- > > grub-core/Makefile.core.def | 3 ++ > > grub-core/kern/emu/main.c | 11 ++- > > grub-core/kern/emu/misc.c | 51 + > > grub-core/lib/tss2/tcg2_emu.c | 54 +++ > > include/grub/emu/misc.h | 5 > > 5 files changed, 123 insertions(+), 1 deletion(-) > > create mode 100644 grub-core/lib/tss2/tcg2_emu.c > > > > diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def > > index 97ae4e49b..40427165e 100644 > > --- a/grub-core/Makefile.core.def > > +++ b/grub-core/Makefile.core.def > > @@ -2574,7 +2574,9 @@ module = { > >common = lib/tss2/tpm2_cmd.c; > >common = lib/tss2/tss2.c; > >efi = lib/efi/tcg2.c; > > + emu = lib/tss2/tcg2_emu.c; > >enable = efi; > > + enable = emu; > >cppflags = '-I$(srcdir)/lib/tss2'; > > }; > > > > @@ -2586,6 +2588,7 @@ module = { > >common = commands/tpm2_key_protector/tpm2key_asn1_tab.c; > >/* The plaform support of tpm2_key_protector depends on the tcg2 > > implementation in tss2. */ > >enable = efi; > > + enable = emu; > >cppflags = '-I$(srcdir)/lib/tss2 -I$(srcdir)/lib/libtasn1-grub'; > > }; > > > > diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c > > index 855b11c3d..c10838613 100644 > > --- a/grub-core/kern/emu/main.c > > +++ b/grub-core/kern/emu/main.c > > @@ -55,7 +55,7 @@ > > static jmp_buf main_env; > > > > /* Store the prefix specified by an argument. */ > > -static char *root_dev = NULL, *dir = NULL; > > +static char *root_dev = NULL, *dir = NULL, *tpm_dev = NULL; > > > > grub_addr_t grub_modbase = 0; > > > > @@ -108,6 +108,7 @@ static struct argp_option options[] = { > >{"verbose", 'v', 0, 0, N_("print verbose messages."), 0}, > >{"hold", 'H', N_("SECS"), OPTION_ARG_OPTIONAL, N_("wait until a > > debugger will attach"), 0}, > >{"kexec", 'X', 0, 0, N_("use kexec to boot Linux kernels via > > systemctl (pass twice to enable dangerous fallback to non-systemctl)."), 0}, > > + {"tpm-device", 't', N_("DEV"), 0, N_("Set TPM device."), 0}, > > s/Set/set/? It looks all messages start with lowercase... > Oh, yes, it should start with lowercase. > >{ 0, 0, 0, 0, 0, 0 } > > }; > > > > @@ -168,6 +169,10 @@ argp_parser (int key, char *arg, struct argp_state > > *state) > > case 'X': > >grub_util_set_kexecute (); > >break; > > +case 't': > > + free (tpm_dev); > > + tpm_dev = xstrdup (arg); > > + break; > > > > case ARGP_KEY_ARG: > >{ > > @@ -276,6 +281,9 @@ main (int argc, char *argv[]) > > > >dir = xstrdup (dir); > > > > + if (tpm_dev) > > +grub_util_tpm_open (tpm_dev); > > + > >/* Start GRUB! */ > >if (setjmp (main_env) == 0) > > grub_main (); > > @@ -283,6 +291,7 @@ main (int argc, char *argv[]) > >grub_fini_all (); > >grub_hostfs_fini (); > >grub_host_fini (); > > + grub_util_tpm_close (); > > > >grub_machine_fini (GRUB_LOADER_FLAG_NORETURN); > > > > diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c > > index 521220b49..1db24fde7 100644 > > --- a/grub-core/kern/emu/misc.c > > +++ b/grub-core/kern/emu/misc.c > > @@ -28,6 +28,8 @@ > > #include > > #include > > #include > > +#include > > +#include > > > > #include > > #include > > @@ -41,6 +43,8 @@ > > int verbosity; > > int kexecute; > > > > +static int grub_util_tpm_fd = -1; > > + > > void > > grub_util_warn (const char *fmt, ...) > > { > > @@ -230,3 +234,50 @@ grub_util_get_kexecute (void) > > { > >return kexecute; > > } > > + > > +grub_err_t > > +grub_util_tpm_open (const char *tpm_dev) > > +{ > > + if (grub_util_tpm_fd != -1) > > +return GRUB_ERR_NONE; > > + > > + grub_util_tpm_fd = open (tpm_dev, O_RDWR); > > + if (grub_util_tpm_fd == -1) > > +grub_util_error (_("cannot open TPM device '%s': %s"), tpm_dev, > > strerror (errno)); > > + > > + return GRUB_ERR_NONE; > > +} > > + > > +grub_err_t > > +grub_util_tpm_close (void)
Re: Re: [PATCH] efinet: Skip virtual VLAN devices during card enumeration
> On Thu, Oct 03, 2024 at 03:23:15PM +0800, Michael Chang via Grub-devel wrote: >> Similar to the fix in commit "c52ae4057 efinet: skip virtual IPv4 and >> IPv6 devices during card enumeration", the UEFI PXE driver creates >> additional VLAN child devices when a VLAN ID is configured on a network >> interface associated with a physical NIC. These virtual VLAN devices >> must be skipped during card enumeration to ensure that the subsequent >> SNP exclusive open operation targets the correct physical card >> instances, otherwise packet transfer would fail. >> >> Example device path with VLAN nodes: >> >> /MAC(123456789ABC,0x1)/Vlan(20)/IPv4(0.0.0.0,0x0,DHCP,0.0.0.0,0.0.0.0,0.0.0.0) >> >> Signed-Off-by: Michael Chang > > Reviewed-by: Daniel Kiper > > Daniel I submitted almost the same patch in August this year, more than a month earlier than Michael Chang's patch. Why did the community ignore my patch and accept his patch instead? The patch I submitted in August: https://www.mail-archive.com/grub-devel@gnu.org/msg38860.html ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel