diff options
author | Toomas Soome <[email protected]> | 2020-09-16 01:42:27 +0300 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2020-09-15 18:36:12 -0700 |
commit | 84d9492e527be42f81af743afd0231bc38fff954 (patch) | |
tree | e2992dc44edc22b731c36e7cf7b2efde698a0ad2 /include | |
parent | c8bbb0c93d3d91fe73c8635c655ddae031ecd474 (diff) |
zfs label bootenv should store data as nvlist
nvlist does allow us to support different data types and systems.
To encapsulate user data to/from nvlist, the libzfsbootenv library is
provided.
Reviewed-by: Arvind Sankar <[email protected]>
Reviewed-by: Allan Jude <[email protected]>
Reviewed-by: Paul Dagnelie <[email protected]>
Reviewed-by: Igor Kozhukhov <[email protected]>
Signed-off-by: Toomas Soome <[email protected]>
Closes #10774
Diffstat (limited to 'include')
-rw-r--r-- | include/Makefile.am | 1 | ||||
-rw-r--r-- | include/libzfs.h | 4 | ||||
-rw-r--r-- | include/libzfs_core.h | 2 | ||||
-rw-r--r-- | include/libzfsbootenv.h | 41 | ||||
-rw-r--r-- | include/os/freebsd/zfs/sys/Makefile.am | 1 | ||||
-rw-r--r-- | include/os/freebsd/zfs/sys/zfs_bootenv_os.h | 29 | ||||
-rw-r--r-- | include/os/linux/zfs/sys/Makefile.am | 1 | ||||
-rw-r--r-- | include/os/linux/zfs/sys/zfs_bootenv_os.h | 29 | ||||
-rw-r--r-- | include/sys/Makefile.am | 1 | ||||
-rw-r--r-- | include/sys/fs/zfs.h | 4 | ||||
-rw-r--r-- | include/sys/vdev.h | 2 | ||||
-rw-r--r-- | include/sys/vdev_impl.h | 11 | ||||
-rw-r--r-- | include/sys/zfs_bootenv.h | 53 |
13 files changed, 172 insertions, 7 deletions
diff --git a/include/Makefile.am b/include/Makefile.am index 0e997deaf..17286ecbb 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -15,6 +15,7 @@ USER_H = \ libuutil.h \ libuutil_impl.h \ libzfs.h \ + libzfsbootenv.h \ libzfs_core.h \ libzfs_impl.h \ libzutil.h \ diff --git a/include/libzfs.h b/include/libzfs.h index 6b4f518a4..e0b2676a4 100644 --- a/include/libzfs.h +++ b/include/libzfs.h @@ -892,8 +892,8 @@ extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **, * Label manipulation. */ extern int zpool_clear_label(int); -extern int zpool_set_bootenv(zpool_handle_t *, const char *); -extern int zpool_get_bootenv(zpool_handle_t *, char *, size_t, off_t); +extern int zpool_set_bootenv(zpool_handle_t *, const nvlist_t *); +extern int zpool_get_bootenv(zpool_handle_t *, nvlist_t **); /* * Management interfaces for SMB ACL files diff --git a/include/libzfs_core.h b/include/libzfs_core.h index e69fe32cd..34161a06f 100644 --- a/include/libzfs_core.h +++ b/include/libzfs_core.h @@ -135,7 +135,7 @@ int lzc_wait(const char *, zpool_wait_activity_t, boolean_t *); int lzc_wait_tag(const char *, zpool_wait_activity_t, uint64_t, boolean_t *); int lzc_wait_fs(const char *, zfs_wait_activity_t, boolean_t *); -int lzc_set_bootenv(const char *, const char *); +int lzc_set_bootenv(const char *, const nvlist_t *); int lzc_get_bootenv(const char *, nvlist_t **); #ifdef __cplusplus } diff --git a/include/libzfsbootenv.h b/include/libzfsbootenv.h new file mode 100644 index 000000000..b078b605d --- /dev/null +++ b/include/libzfsbootenv.h @@ -0,0 +1,41 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2020 Toomas Soome <[email protected]> + */ + +#ifndef _LIBZFSBOOTENV_H +#define _LIBZFSBOOTENV_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum lzbe_flags { + lzbe_add, /* add data to existing nvlist */ + lzbe_replace /* replace current nvlist */ +} lzbe_flags_t; + +extern int lzbe_nvlist_get(const char *, const char *, void **); +extern int lzbe_nvlist_set(const char *, const char *, void *); +extern void lzbe_nvlist_free(void *); +extern int lzbe_add_pair(void *, const char *, const char *, void *, size_t); +extern int lzbe_remove_pair(void *, const char *); +extern int lzbe_set_boot_device(const char *, lzbe_flags_t, const char *); +extern int lzbe_get_boot_device(const char *, char **); +extern int lzbe_bootenv_print(const char *, const char *, FILE *); + +#ifdef __cplusplus +} +#endif + +#endif /* _LIBZFSBOOTENV_H */ diff --git a/include/os/freebsd/zfs/sys/Makefile.am b/include/os/freebsd/zfs/sys/Makefile.am index 6a65a7326..bf5cc39eb 100644 --- a/include/os/freebsd/zfs/sys/Makefile.am +++ b/include/os/freebsd/zfs/sys/Makefile.am @@ -2,6 +2,7 @@ KERNEL_H = \ freebsd_crypto.h \ sha2.h \ vdev_os.h \ + zfs_bootenv_os.h \ zfs_context_os.h \ zfs_ctldir.h \ zfs_dir.h \ diff --git a/include/os/freebsd/zfs/sys/zfs_bootenv_os.h b/include/os/freebsd/zfs/sys/zfs_bootenv_os.h new file mode 100644 index 000000000..80c71a6c5 --- /dev/null +++ b/include/os/freebsd/zfs/sys/zfs_bootenv_os.h @@ -0,0 +1,29 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2020 Toomas Soome <[email protected]> + */ + +#ifndef _ZFS_BOOTENV_OS_H +#define _ZFS_BOOTENV_OS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define BOOTENV_OS BE_FREEBSD_VENDOR + +#ifdef __cplusplus +} +#endif + +#endif /* _ZFS_BOOTENV_OS_H */ diff --git a/include/os/linux/zfs/sys/Makefile.am b/include/os/linux/zfs/sys/Makefile.am index b56e6771d..a5f2502d2 100644 --- a/include/os/linux/zfs/sys/Makefile.am +++ b/include/os/linux/zfs/sys/Makefile.am @@ -16,6 +16,7 @@ KERNEL_H = \ trace_zil.h \ trace_zio.h \ trace_zrlock.h \ + zfs_bootenv_os.h \ zfs_context_os.h \ zfs_ctldir.h \ zfs_dir.h \ diff --git a/include/os/linux/zfs/sys/zfs_bootenv_os.h b/include/os/linux/zfs/sys/zfs_bootenv_os.h new file mode 100644 index 000000000..7b2f083ad --- /dev/null +++ b/include/os/linux/zfs/sys/zfs_bootenv_os.h @@ -0,0 +1,29 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2020 Toomas Soome <[email protected]> + */ + +#ifndef _ZFS_BOOTENV_OS_H +#define _ZFS_BOOTENV_OS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define BOOTENV_OS BE_LINUX_VENDOR + +#ifdef __cplusplus +} +#endif + +#endif /* _ZFS_BOOTENV_OS_H */ diff --git a/include/sys/Makefile.am b/include/sys/Makefile.am index 75727b93a..a944c5ea8 100644 --- a/include/sys/Makefile.am +++ b/include/sys/Makefile.am @@ -102,6 +102,7 @@ COMMON_H = \ zcp_set.h \ zfeature.h \ zfs_acl.h \ + zfs_bootenv.h \ zfs_context.h \ zfs_debug.h \ zfs_delay.h \ diff --git a/include/sys/fs/zfs.h b/include/sys/fs/zfs.h index f6f633a95..fe63d735b 100644 --- a/include/sys/fs/zfs.h +++ b/include/sys/fs/zfs.h @@ -1336,8 +1336,8 @@ typedef enum zfs_ioc { ZFS_IOC_NEXTBOOT, /* 0x84 (FreeBSD) */ ZFS_IOC_JAIL, /* 0x85 (FreeBSD) */ ZFS_IOC_UNJAIL, /* 0x86 (FreeBSD) */ - ZFS_IOC_SET_BOOTENV, /* 0x87 (Linux) */ - ZFS_IOC_GET_BOOTENV, /* 0x88 (Linux) */ + ZFS_IOC_SET_BOOTENV, /* 0x87 */ + ZFS_IOC_GET_BOOTENV, /* 0x88 */ ZFS_IOC_LAST } zfs_ioc_t; diff --git a/include/sys/vdev.h b/include/sys/vdev.h index 797065fdd..6dcd20969 100644 --- a/include/sys/vdev.h +++ b/include/sys/vdev.h @@ -181,7 +181,7 @@ extern void vdev_config_generate_stats(vdev_t *vd, nvlist_t *nv); extern void vdev_label_write(zio_t *zio, vdev_t *vd, int l, abd_t *buf, uint64_t offset, uint64_t size, zio_done_func_t *done, void *priv, int flags); extern int vdev_label_read_bootenv(vdev_t *, nvlist_t *); -extern int vdev_label_write_bootenv(vdev_t *, char *); +extern int vdev_label_write_bootenv(vdev_t *, nvlist_t *); typedef enum { VDEV_LABEL_CREATE, /* create/add a new device */ diff --git a/include/sys/vdev_impl.h b/include/sys/vdev_impl.h index 90d607746..3c4c3fb5a 100644 --- a/include/sys/vdev_impl.h +++ b/include/sys/vdev_impl.h @@ -476,7 +476,16 @@ typedef struct vdev_phys { } vdev_phys_t; typedef enum vbe_vers { - /* The bootenv file is stored as ascii text in the envblock */ + /* + * The bootenv file is stored as ascii text in the envblock. + * It is used by the GRUB bootloader used on Linux to store the + * contents of the grubenv file. The file is stored as raw ASCII, + * and is protected by an embedded checksum. By default, GRUB will + * check if the boot filesystem supports storing the environment data + * in a special location, and if so, will invoke filesystem specific + * logic to retrieve it. This can be overriden by a variable, should + * the user so desire. + */ VB_RAW = 0, /* diff --git a/include/sys/zfs_bootenv.h b/include/sys/zfs_bootenv.h new file mode 100644 index 000000000..7af0a57dd --- /dev/null +++ b/include/sys/zfs_bootenv.h @@ -0,0 +1,53 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2020 Toomas Soome <[email protected]> + */ + +#ifndef _ZFS_BOOTENV_H +#define _ZFS_BOOTENV_H + +/* + * Define macros for label bootenv nvlist pair keys. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#define BOOTENV_VERSION "version" + +#define BE_ILLUMOS_VENDOR "illumos" +#define BE_FREEBSD_VENDOR "freebsd" +#define BE_GRUB_VENDOR "grub" +#define BE_LINUX_VENDOR "linux" + +#include <sys/zfs_bootenv_os.h> + +#define GRUB_ENVMAP BE_GRUB_VENDOR ":" "envmap" + +#define FREEBSD_BOOTONCE BE_FREEBSD_VENDOR ":" "bootonce" +#define FREEBSD_BOOTONCE_USED BE_FREEBSD_VENDOR ":" "bootonce-used" +#define FREEBSD_NVSTORE BE_FREEBSD_VENDOR ":" "nvstore" +#define ILLUMOS_BOOTONCE BE_ILLUMOS_VENDOR ":" "bootonce" +#define ILLUMOS_BOOTONCE_USED BE_ILLUMOS_VENDOR ":" "bootonce-used" +#define ILLUMOS_NVSTORE BE_ILLUMOS_VENDOR ":" "nvstore" + +#define OS_BOOTONCE BOOTENV_OS ":" "bootonce" +#define OS_BOOTONCE_USED BOOTENV_OS ":" "bootonce-used" +#define OS_NVSTORE BOOTENV_OS ":" "nvstore" + +#ifdef __cplusplus +} +#endif + +#endif /* _ZFS_BOOTENV_H */ |