mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-24 19:28:53 +03:00
Add support for boot environment data to be stored in the label
Modern bootloaders leverage data stored in the root filesystem to enable some of their powerful features. GRUB specifically has a grubenv file which can store large amounts of configuration data that can be read and written at boot time and during normal operation. This allows sysadmins to configure useful features like automated failover after failed boot attempts. Unfortunately, due to the Copy-on-Write nature of ZFS, the standard behavior of these tools cannot handle writing to ZFS files safely at boot time. We need an alternative way to store data that allows the bootloader to make changes to the data. This work is very similar to work that was done on Illumos to enable similar functionality in the FreeBSD bootloader. This patch is different in that the data being stored is a raw grubenv file; this file can store arbitrary variables and values, and the scripting provided by grub is powerful enough that special structures are not required to implement advanced behavior. We repurpose the second padding area in each label to store the grubenv file, protected by an embedded checksum. We add two ioctls to get and set this data, and libzfs_core and libzfs functions to access them more easily. There are no direct command line interfaces to these functions; these will be added directly to the bootloader utilities. Reviewed-by: Pavel Zakharov <pavel.zakharov@delphix.com> Reviewed-by: Matthew Ahrens <mahrens@delphix.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Paul Dagnelie <pcd@delphix.com> Closes #10009
This commit is contained in:
@@ -3512,6 +3512,58 @@ zfs_ioc_log_history(const char *unused, nvlist_t *innvl, nvlist_t *outnvl)
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* This ioctl is used to set the bootenv configuration on the current
|
||||
* pool. This configuration is stored in the second padding area of the label,
|
||||
* and 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.
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
static const zfs_ioc_key_t zfs_keys_set_bootenv[] = {
|
||||
{"envmap", DATA_TYPE_STRING, 0},
|
||||
};
|
||||
|
||||
static int
|
||||
zfs_ioc_set_bootenv(const char *name, nvlist_t *innvl, nvlist_t *outnvl)
|
||||
{
|
||||
char *envmap;
|
||||
int error;
|
||||
spa_t *spa;
|
||||
|
||||
envmap = fnvlist_lookup_string(innvl, "envmap");
|
||||
if ((error = spa_open(name, &spa, FTAG)) != 0)
|
||||
return (error);
|
||||
spa_vdev_state_enter(spa, SCL_ALL);
|
||||
error = vdev_label_write_bootenv(spa->spa_root_vdev, envmap);
|
||||
(void) spa_vdev_state_exit(spa, NULL, 0);
|
||||
spa_close(spa, FTAG);
|
||||
return (error);
|
||||
}
|
||||
|
||||
static const zfs_ioc_key_t zfs_keys_get_bootenv[] = {
|
||||
/* no nvl keys */
|
||||
};
|
||||
|
||||
/* ARGSUSED */
|
||||
static int
|
||||
zfs_ioc_get_bootenv(const char *name, nvlist_t *innvl, nvlist_t *outnvl)
|
||||
{
|
||||
spa_t *spa;
|
||||
int error;
|
||||
|
||||
if ((error = spa_open(name, &spa, FTAG)) != 0)
|
||||
return (error);
|
||||
spa_vdev_state_enter(spa, SCL_ALL);
|
||||
error = vdev_label_read_bootenv(spa->spa_root_vdev, outnvl);
|
||||
(void) spa_vdev_state_exit(spa, NULL, 0);
|
||||
spa_close(spa, FTAG);
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* The dp_config_rwlock must not be held when calling this, because the
|
||||
* unmount may need to write out data.
|
||||
@@ -6981,6 +7033,16 @@ zfs_ioctl_init(void)
|
||||
POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_FALSE,
|
||||
zfs_keys_fs_wait, ARRAY_SIZE(zfs_keys_fs_wait));
|
||||
|
||||
zfs_ioctl_register("set_bootenv", ZFS_IOC_SET_BOOTENV,
|
||||
zfs_ioc_set_bootenv, zfs_secpolicy_config, POOL_NAME,
|
||||
POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_TRUE,
|
||||
zfs_keys_set_bootenv, ARRAY_SIZE(zfs_keys_set_bootenv));
|
||||
|
||||
zfs_ioctl_register("get_bootenv", ZFS_IOC_GET_BOOTENV,
|
||||
zfs_ioc_get_bootenv, zfs_secpolicy_none, POOL_NAME,
|
||||
POOL_CHECK_SUSPENDED, B_FALSE, B_TRUE,
|
||||
zfs_keys_get_bootenv, ARRAY_SIZE(zfs_keys_get_bootenv));
|
||||
|
||||
/* IOCTLS that use the legacy function signature */
|
||||
|
||||
zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE, zfs_ioc_pool_freeze,
|
||||
|
||||
Reference in New Issue
Block a user