Skip to content

Commit 14f7f62

Browse files
committed
bootenv: reorganise and document
In 99d7453 I split out the "OS-specific" zfs_bootenv_os.h for userspace, added a placeholder "posix" vendor and set BOOTENV_OS to use it by default. This turned out to be the wrong thing to do. BOOTENV_OS is not actually OS-specific but rather, part of a protocol coordinating behaviour between libzfsbootenv and the bootloader. So, all bootenv keys now get prefixed with posix:, and their respective loaders can no longer find them[1]. Reverting would have been straightforward, however, I am more interested in trying to reorganise libzfsbootenv and surrounds to provide all the pieces a loader, its support tools and the kernel module need in order to have agreement on how to communicate with each other. This commit is attempting that rework. The two goals here are: - it should be possible to set and get the loader prefix in libzfsbootenv at run time, allowing the possibility for the library to work on loader prefixes other than the one it was compiled with. - a loader is a constrained environment, and so should be able to get all the config it needs from a single header that libzfsbootenv and the kernel at least default to using. FreeBSD (and illumos, which borrows heavily from it) is the only system out there that currently has this tight integration between loader, kernel and tools, so it is the obvious target to focus on here, but I'm also trying to clearly draw the lines for future systems. First, we remove sys/zfs_bootenv.h and the various sys/zfs_bootenv_os.h. This is not really a public API, and as discussed, is not the proper way to target a loader anyway. The important macros for a consumer have been moved to fs/zfs.h as public and supported names. These are the minimum necessary to use libzfsbootenv (actually lzc_get_bootenv/lzc_set_bootenv) effectively anyway, and since they live in headers, a standalone loader can make use of them. Here we have macros nvlist keys for "known" loaders, and for common/known bootenv vars. Worth noting that only "bootonce" is currently used in libzfsbootenv proper, but listing them out at least makes sure they're documented and we can encourage future systems to do it the same way. libzfsbootenv gains an internal notion of the current loader, just the string prefix. Two new functions are added, lzbe_set_loader() and lzbe_get_loader(), allowing runtime changes. By compiler define, we set the default on FreeBSD and illumos to the matching macro from fs/zfs.h, and "unknown" otherwise. This should keep existing consumers working without change. The rest is simple cleanup. Sponsored-by: https://despairlabs.com/sponsor/ Signed-off-by: Rob Norris <[email protected]> 1. https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=291211
1 parent 7f7d493 commit 14f7f62

File tree

18 files changed

+165
-222
lines changed

18 files changed

+165
-222
lines changed

include/Makefile.am

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ COMMON_H = \
123123
sys/zcp_set.h \
124124
sys/zfeature.h \
125125
sys/zfs_acl.h \
126-
sys/zfs_bootenv.h \
127126
sys/zfs_chksum.h \
128127
sys/zfs_context.h \
129128
sys/zfs_debug.h \

include/libzfsbootenv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
/*
1414
* Copyright 2020 Toomas Soome <[email protected]>
15+
* Copyright (c) 2025, Rob Norris <[email protected]>
1516
*/
1617

1718
#ifndef _LIBZFSBOOTENV_H
@@ -36,6 +37,8 @@ _LIBZFSBOOTENV_H int lzbe_set_boot_device(const char *, lzbe_flags_t,
3637
const char *);
3738
_LIBZFSBOOTENV_H int lzbe_get_boot_device(const char *, char **);
3839
_LIBZFSBOOTENV_H int lzbe_bootenv_print(const char *, const char *, FILE *);
40+
_LIBZFSBOOTENV_H const char *lzbe_loader_get(void);
41+
_LIBZFSBOOTENV_H int lzbe_loader_set(const char *, size_t);
3942

4043
#ifdef __cplusplus
4144
}

include/os/freebsd/Makefile.am

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ noinst_HEADERS = \
8282
%D%/zfs/sys/freebsd_event.h \
8383
%D%/zfs/sys/trace_zfs.h \
8484
%D%/zfs/sys/vdev_os.h \
85-
%D%/zfs/sys/zfs_bootenv_os.h \
8685
%D%/zfs/sys/zfs_context_os.h \
8786
%D%/zfs/sys/zfs_ctldir.h \
8887
%D%/zfs/sys/zfs_debug_os.h \

include/os/freebsd/zfs/sys/zfs_bootenv_os.h

Lines changed: 0 additions & 30 deletions
This file was deleted.

include/os/linux/Makefile.am

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ kernel_sys_HEADERS = \
3838
%D%/zfs/sys/trace_zil.h \
3939
%D%/zfs/sys/trace_zio.h \
4040
%D%/zfs/sys/trace_zrlock.h \
41-
%D%/zfs/sys/zfs_bootenv_os.h \
4241
%D%/zfs/sys/zfs_context_os.h \
4342
%D%/zfs/sys/zfs_ctldir.h \
4443
%D%/zfs/sys/zfs_debug_os.h \

include/os/linux/zfs/sys/zfs_bootenv_os.h

Lines changed: 0 additions & 30 deletions
This file was deleted.

include/sys/fs/zfs.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* Copyright (c) 2021, Colm Buckley <[email protected]>
3333
* Copyright (c) 2022 Hewlett Packard Enterprise Development LP.
3434
* Copyright (c) 2024, Klara, Inc.
35+
* Copyright (c) 2025, Rob Norris <[email protected]>
3536
*/
3637

3738
#ifndef _SYS_FS_ZFS_H
@@ -2003,6 +2004,41 @@ enum zio_encrypt {
20032004
ZFS_XA_NS_PREFIX_MATCH(LINUX_TRUSTED, name) || \
20042005
ZFS_XA_NS_PREFIX_MATCH(LINUX_USER, name))
20052006

2007+
2008+
/*
2009+
* Boot environment support. The vdev environment block is accessed with the
2010+
* ZFS_IOC_GET_BOOTENV and ZFS_IOC_SET_BOOTENV calls. libzfsbootenv uses these
2011+
* internally, and is the preferred way to work with boot environments, but
2012+
* these defines are provided here to assist bootloaders and tools that want to
2013+
* do their own thing.
2014+
*/
2015+
2016+
#define ZFS_BE_VERSION "version"
2017+
enum zfs_bootenv_version {
2018+
ZFS_BE_VERSION_GRUBENV = 0, /* GRUB "grubenv" file */
2019+
ZFS_BE_VERSION_NVLIST = 1, /* arbitrary packed nvlist */
2020+
};
2021+
2022+
/* nvlist key for GRUB "grubenv" string */
2023+
#define ZFS_BE_GRUB_ENVMAP "grub:envmap"
2024+
2025+
/*
2026+
* Keys in NVLIST bootenvs should be prefixed with a loader-specific string,
2027+
* allowing the envblock to support multiple loaders.
2028+
*
2029+
* This is the list of known loader prefixes.
2030+
*/
2031+
#define ZFS_BE_LOADER_FREEBSD "freebsd"
2032+
#define ZFS_BE_LOADER_ILLUMOS "illumos"
2033+
2034+
/*
2035+
* Common bootenv keys, to be combined with the loader prefix. New loaders are
2036+
* encouraged to use these where appropriate to assist cross-platform interop.
2037+
*/
2038+
#define ZFS_BE_BOOTONCE "bootonce"
2039+
#define ZFS_BE_BOOTONCE_USED "bootonce-used"
2040+
#define ZFS_BE_NVSTORE "nvstore"
2041+
20062042
#ifdef __cplusplus
20072043
}
20082044
#endif

include/sys/vdev_impl.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -503,26 +503,6 @@ typedef struct vdev_phys {
503503
zio_eck_t vp_zbt;
504504
} vdev_phys_t;
505505

506-
typedef enum vbe_vers {
507-
/*
508-
* The bootenv file is stored as ascii text in the envblock.
509-
* It is used by the GRUB bootloader used on Linux to store the
510-
* contents of the grubenv file. The file is stored as raw ASCII,
511-
* and is protected by an embedded checksum. By default, GRUB will
512-
* check if the boot filesystem supports storing the environment data
513-
* in a special location, and if so, will invoke filesystem specific
514-
* logic to retrieve it. This can be overridden by a variable, should
515-
* the user so desire.
516-
*/
517-
VB_RAW = 0,
518-
519-
/*
520-
* The bootenv file is converted to an nvlist and then packed into the
521-
* envblock.
522-
*/
523-
VB_NVLIST = 1
524-
} vbe_vers_t;
525-
526506
typedef struct vdev_boot_envblock {
527507
uint64_t vbe_version;
528508
char vbe_bootenv[VDEV_PAD_SIZE - sizeof (uint64_t) -

include/sys/zfs_bootenv.h

Lines changed: 0 additions & 55 deletions
This file was deleted.

lib/libzfsbootenv/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ lib_LTLIBRARIES += libzfsbootenv.la
55
CPPCHECKTARGETS += libzfsbootenv.la
66

77
libzfsbootenv_la_CPPFLAGS = $(AM_CPPFLAGS)
8-
libzfsbootenv_la_CPPFLAGS += -I$(srcdir)/include/os/@ac_system_l@/zfs
98

109
dist_libzfsbootenv_la_SOURCES = \
1110
%D%/lzbe_device.c \
11+
%D%/lzbe_loader.c \
1212
%D%/lzbe_pair.c \
1313
%D%/lzbe_util.c
1414

@@ -22,7 +22,7 @@ if !ASAN_ENABLED
2222
libzfsbootenv_la_LDFLAGS += -Wl,-z,defs
2323
endif
2424

25-
libzfsbootenv_la_LDFLAGS += -version-info 1:0:0
25+
libzfsbootenv_la_LDFLAGS += -version-info 2:0:1
2626

2727
pkgconfig_DATA += %D%/libzfsbootenv.pc
2828

0 commit comments

Comments
 (0)