Skip to content

ZFS/other CoW FS save_env support

Paul Dagnelie grub-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest7 patches 2 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7Factor out file filter function for reusegrub-core/kern/file.c+27 -190 replies
2/7Add support for special envblk functions in GRUBgrub-core/kern/file.c include/grub/file.h include/grub/fs.h+50 -20 replies
3/7Factor out envblk buffer creation for reuseinclude/grub/util/install.h util/editenv.c+20 -90 replies
4/7Use envblk file and fs functions to implement reading the grubenv file from special FS regionsgrub-core/commands/loadenv.c include/grub/lib/envblk.h+109 -150 replies
5/7Add ZFS envblock functionsgrub-core/fs/zfs/zfs.c include/grub/zfs/vdev_impl.h+139 -280 replies
6/7Refactor default envblk size out for reuseinclude/grub/lib/envblk.h util/editenv.c+5 -50 replies
7/7Update editenv to support editing zfs envblock, fix whitespace, and autodetect bootenv support in libzfsconfigure.ac include/grub/util/libzfs.h util/grub-editenv.c+284 -90 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/7] ZFS/other CoW FS save_env support

Hey all, I previously discussed my concept for this patch in my email
https://lists.gnu.org/archive/html/grub-devel/2020-01/msg00004.html . I'm pleased to announce that I've gotten it into a working state and it is ready to review. There are a number of changes here, which I will break down below.

First, the concept of "special files" is introduced into grub. These are files that are manipulated using different functions from the remainder of the filesystem. A filesystem advertises its support for these files by filling in new entries in the grub_fs struct.

Second, the loadenv command was modified to use the special file functions of the root filesystem if they are detected. If that happens, these functions are used to open, read, and write to the loadenv file instead of the normal grub file functions. A variable was also added that allows the user to force a file to be used instead of the special files, or vice versa.

Third, the grub-editenv command was modified to teach it to probe the root filesystem and then check in an array of structures that contain functions that will read and modify the filesystem's special file in userland. These functions are very similar to normal read and write functions, and so don't result in a very different code flow.

Finally, the GRUB ZFS logic was modified to have new special_file functions. These functions manipulate the pad2 area of the ZFS label, which was previously unused. It now stores a version number, the raw contents of the grubenv file, and an embedded checksum for integrity purposes. GRUB was taught to read and verify these areas, and also to modify them, computing the embeddded checksum appropriately. In addition, if GRUB is build with libzfs support, an entry is added to the grub-editenv table that points GRUB to the appropriate libzfs functions, and init and fini functions are built into grub-editenv itself.

Future work:
* In the ZFS code could store a packed nvlist instead of a raw file, but this would involve further changes to the grub environment file code and was deferred for when it would be more useful and important.
* For the special files code, there is only one special file allowed per filesystem, but a specification interface (using either an enum or a set of names) could be added in the future.
* Other filesystem support was not built into this change, but extensibility was a primary goal, so adding support for btrfs or other filesystems should be relatively straightforward.
* I did not implement the proposed UEFI variable support, but I did develop this with that future in mind, so adding it should be a relatively simple extension of these changes.

This patchset has been tested on systems with and without ZFS as the boot filesystem, and built with and without ZFS libraries installed. It worked in each case I tried, including with manual corruption applied to the ZFS labels to force GRUB to read from the other label. This was tested in conjunction with
https://github.com/zfsonlinux/zfs/pull/10009 , the ZoL patch that enables ZFS to read from and write to the padding areas we reserved for the data.

Paul Dagnelie (7):
Factor out file filter function for reuse
Add support for special envblk functions in GRUB
Factor out envblk buffer creation for reuse
Use envblk file and fs functions to implement reading the grubenv file
from special FS regions
Add ZFS envblock functions
Refactor default envblk size out for reuse
Update editenv to support editing zfs envblock, fix whitespace, and
autodetect bootenv support in libzfs

 configure.ac                 |   8 +
 grub-core/commands/loadenv.c | 122 +++++++++++++--
 grub-core/fs/zfs/zfs.c       | 134 +++++++++++++++--
 grub-core/kern/file.c        |  76 +++++++---
 include/grub/file.h          |  10 ++
 include/grub/fs.h            |  12 ++
 include/grub/lib/envblk.h    |   3 +
 include/grub/util/install.h  |   3 +
 include/grub/util/libzfs.h   |   7 +
 include/grub/zfs/vdev_impl.h |  33 ++---
 util/editenv.c               |  31 ++--
 util/grub-editenv.c          | 278 +++++++++++++++++++++++++++++++++--
 12 files changed, 632 insertions(+), 85 deletions(-)
Signature · 1 line
2.19.0