getroot for ZFS without libzfs?
Greetings all,
I've been working for the last few weeks with Grub on a Linux system using ZFS drivers from zfsonlinux.org. One change required to Grub has been in adapting the way the the build process detects and links to libzfs for the code in util/getroot.c. I'd like to see the changes required included in Grub of course, but I have some concerns about the licensing issues and also accessing the private libzfs.
It appears that existing Grub code already links against libzfs for the benefit of find_root_device_from_libzfs and other functions in getroot.c. It also appears that libzfs is not used outside this file. That linkage surprises me a bit as I would have expected GPL Grub linked against CDDL libzfs to create a problem. Also libzfs is considered a private API and not intended to be linked against, though admittedly what I propose (reading on-disk structures directly) is arguably worse than accessing a private library.
As best I can tell, all of the ZFS-related functionality that getroot.c requires was included in the GPL release that Sun made in Grub 0.97. I think it should be relatively straight forward to modify getroot.c to use the GPL'd ZFS code to directly access the disk and read the necessary bits out of ZFS that it needs to configure itself. Assuming that change is made, it should be possible to expunge Grub of all references to libzfs and have its ZFS support operate purely on the GPL'd dump from Sun.
I'd like to dive in and make these changes, but I wanted to solicit thoughts from other Grub devs before starting. Am I incorrect in my belief that linking libzfs is a GPL problem for Grub? Is the CDDL/GPL problem not reciprocal and this only a problem for CDDL ZFS using GPL kernel and not the other way around?
Does anyone see an issue with getroot.c reading the on-disk ZFS structures directly? grub-probe already does this in its search for uberblocks and labels, so I don't think changing getroot.c is making the situation worse.
Any other thoughts would be appreciated.
Best regards,
Zac Bedell
Hi Zachary,
2011/8/8 Zachary Bedell <[email protected]>:
Quoted 1 line
It appears that existing Grub code already links against libzfs for the benefit of
find_root_device_from_libzfsand other functions ingetroot.c. It also appears that libzfs is not used outside this file. That linkage surprises me a bit as I would have expected GPL Grub linked against CDDL libzfs to create a problem.
Not really. This kind of use falls under the system library exception, see section 1 of the GPL.
Quoted 1 line
Also libzfs is considered a private API and not intended to be linked against, though admittedly what I propose (reading on-disk structures directly) is arguably worse than accessing a private library.
I don't think you can figure out the disks corresponding to a zpool just by reading disk structures. You can guess, but only the kernel knows for sure.
The other API that is available to us is /dev/zfs. But is that device meant to be used directly? How stable is this interface?
Signature · 1 line
Robert Millan
Quoted 6 lines · Robert Millan
2011/8/8 Zachary Bedell <[email protected]>:
Quoted 1 line
Also libzfs is considered a private API and not intended to be linked against, though admittedly what I propose (reading on-disk structures directly) is arguably worse than accessing a private library.
I don't think you can figure out the disks corresponding to a zpool just by reading disk structures. You can guess, but only the kernel knows for sure.
It's all in there, and the structures are pretty well defined & stable. You'd need to look at all the raw devices to begin with and see which if any has a ZFS label (always in a well known location). Assuming any does, you get the vdev_tree out of the label's nvlist, and from there you can discover child and parent devices to rebuild the full tree. It looks like the code in getroot.c is doing pretty much that by calling the various nvlist_lookup_* functions from libzfs. Doing the same from the pool isn't much more difficult, and the necessary nvlist-related functions are already in zfs.c in Grub at this point.
Quoted 2 lines
The other API that is available to us is
/dev/zfs. But is that device meant to be used directly? How stable is this interface?
/dev/zfs is probably less stable than libzfs, both of which are less stable than the on-disk format. That said, libzfs is going to be stable for the foreseeable future until/unless Oracle dumps more code. I do know that the cryptography related work in Solaris 11 changed the on-disk structures slightly, though in theory in a backwards compatible way. Likewise, the particular functions of libzfs that Grub needs are core enough to ZFS that I doubt they'd be broken in a future release.
My reasons for looking at other options were primarily GPL driven, but given that's not an issue, it's probably moot for now. It might be slightly more elegant to use pure Grub code given that all of the underlying functionality is there already, but the real benefits are probably minimal.
SO that said… It probably makes the most sense to withdraw my thoughts of removing libzfs. In lieu of that, I have a patch which allows ZFS detection to function on Linux. I'll post that under separate subject momentarily as it's unrelated to libzfs in getroot.c.
Best regards,
Zac
2011/8/9 Zachary Bedell <[email protected]>:
Quoted 1 line
You'd need to look at all the raw devices to begin with and see which if any has a ZFS label
Yes, but how do you know this is the label you wanted? Consider the case where there's more than one pool with this name.
Quoted 4 lines
Quoted 2 lines
The other API that is available to us is
/dev/zfs. But is that device meant to be used directly? How stable is this interface?
/dev/zfsis probably less stable than libzfs
Then I wouldn't use /dev/zfs. The less stable and standard is the ZFS API GRUB uses, the more likely is that one can argue it doesn't fall under the "system library" exception.
Directly accessing on-disk structures is entirely different, since a data structure itself can't be copyrighted.
Quoted 1 line
My reasons for looking at other options were primarily GPL driven, but given that's not an issue, it's probably moot for now. It might be slightly more elegant to use pure Grub code given that all of the underlying functionality is there already,
I agree. But I'm still concerned about the technical problems.
Signature · 1 line
Robert Millan
Quoted 5 lines · Robert Millan
2011/8/9 Zachary Bedell <[email protected]>:
Quoted 1 line
You'd need to look at all the raw devices to begin with and see which if any has a ZFS label
Yes, but how do you know this is the label you wanted? Consider the case where there's more than one pool with this name.
The pool can be identified positively via the guid which is in the labels and available via zpool list -H -o guid <pool name>. It's not possible to have two pools imported at once with the same name, so getting the root dataset via parsing /proc/mounts, /etc/mtab, or /etc/mnttab then going to zpool list will give you the guid of the root pool definitively. Then just parse all the device labels until you find a label with a matching guid. (And probably keep scanning for all of the devices with that guid to install Grub to all of them similar to the MD support, but I'm getting ahead of myself…)
It would also be possible to check the imported status of the pool since a conflicted name couldn't be imported normally (though multiple pools available via SAN fabric would probably invalidate that). It may also be possible to compare the hostid of the host that has it imported, though I'm not sure it's possible to get the hostid reliably without going to libzfs. There's logic in the Linux ZFS driver that diverges from both Solaris and FreeBSD a bit as far as how the hostid is calculated from the live system, so that's probably a tough option.
Is calling out to zpool as a helper kosher? The -H flag to zpool pool is basically Sun's idea of a public API in that it's intended to output only the requested fields with no header information for automated parsing.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
The other API that is available to us is
/dev/zfs. But is that device meant to be used directly? How stable is this interface?
/dev/zfsis probably less stable than libzfsThen I wouldn't use
/dev/zfs. The less stable and standard is the ZFS API GRUB uses, the more likely is that one can argue it doesn't fall under the "system library" exception.
Definitely agree. The fact that libzfs is specifically listed as private API not intended for linking against also makes me wonder if the syslib exception is a concern for that.
Quoted 2 lines
Directly accessing on-disk structures is entirely different, since a data structure itself can't be copyrighted.
Right. And a bonus that the on-disk is well documented by Sun with the explicitly stated purpose of interoperability.
Assuming calling out to zpool would be acceptable, I think I'm going to dive in this week and see if I can get it running. The libzfs related autoconf stuff is the biggest area that Linux is "special" in, and it would be nice to yank that all out.
-Zac
2011/8/11 Zachary Bedell <[email protected]>:
Quoted 1 line
The pool can be identified positively via the guid which is in the labels and available via
zpool list -H -o guid <pool name>.
I see. Thanks for the explanation.
Quoted 1 line
Is calling out to zpool as a helper kosher? The -H flag to zpool pool is basically Sun's idea of a public API in that it's intended to output only the requested fields with no header information for automated parsing.
I think -H output looks sane enough (and more stable, so all the better).
Quoted 1 line
Definitely agree. The fact that libzfs is specifically listed as private API not intended for linking against also makes me wonder if the syslib exception is a concern for that.
But SUN/Oracle has linked GRUB with libzfs. This is a good indication that they trust this method to be safe (it's our copyright which would be infringed by them, not theirs by us).
Signature · 1 line
Robert Millan
Quoted 6 lines · Zachary Bedell
Quoted 4 lines · Robert Millan
2011/8/9 Zachary Bedell <[email protected]>:
Quoted 1 line
You'd need to look at all the raw devices to begin with and see which if any has a ZFS label
Yes, but how do you know this is the label you wanted? Consider the case where there's more than one pool with this name.
The pool can be identified positively via the guid which is in the labels and available via
zpool list -H -o guid <pool name>. It's not possible to have two pools imported at once with the same name,
If you can't import 2 pools with same name in the same time then it's a bug. It's like not being able to mount 2 disks with same label. And so as such I expect it to be fixed in future and so I don't rely on this.
Quoted 2 lines
(And probably keep scanning for all of the devices with that guid to install Grub to all of them similar to the MD support, but I'm getting ahead of myself…)
This would be inappropriate. Install is done to the disk, not to FS. So if user tells to install to one disk, you have to obey, not guess what user might have wanted.
Quoted 1 line
It would also be possible to check the imported status of the pool since a conflicted name couldn't be imported normally (though multiple pools available via SAN fabric would probably invalidate that).
The status of the pool in on-disk structures may be "IMPORTED" even if the pool currently isn't. For instance FreeBSD keeps the state to "IMPORTED" on shutdown and so it would appear as imported if booted into another OS.
Quoted 2 lines
It may also be possible to compare the hostid of the host that has it imported, though I'm not sure it's possible to get the hostid reliably without going to libzfs. There's logic in the Linux ZFS driver that diverges from both Solaris and FreeBSD a bit as far as how the hostid is calculated from the live system, so that's probably a tough option.
and unreliable as well.
Quoted 1 line
Is calling out to zpool as a helper kosher?
English translation of "kosher" ("כשר") is "appropriate". Why not stick to English?
Quoted 1 line
The -H flag to zpool pool is basically Sun's idea of a public API in that it's intended to output only the requested fields with no header information for automated parsing.
But probably using unusual symbols in zpool names will make the parsing go haywire anyway.
@Seth: any comment on what Sun considers a public API?
Quoted 4 lines
Quoted 4 lines
Then I wouldn't use
/dev/zfs. The less stable and standard is the ZFS API GRUB uses, the more likely is that one can argue it doesn't fall under the "system library" exception.
We don't need system library exception to read /dev/zfs. It's not a library but a way to speak with kernel which is definitely interprocess communication.
Quoted 15 lines
Quoted 2 lines
Directly accessing on-disk structures is entirely different, since a data structure itself can't be copyrighted.
Right. And a bonus that the on-disk is well documented by Sun with the explicitly stated purpose of interoperability.
Assuming calling out to zpool would be acceptable, I think I'm going to dive in this week and see if I can get it running. The libzfs related autoconf stuff is the biggest area that Linux is "special" in, and it would be nice to yank that all out.
-Zac
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
Hi,
Quoted 2 lines
@Seth: any comment on what Sun considers a public API?
Quoted 1 line
Quoted 1 line
As far as I know, libzfs is not a publicly documented API. I don't think I can give any assurances about its stability.
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Then I wouldn't use
/dev/zfs. The less stable and standard is the ZFS API GRUB uses, the more likely is that one can argue it doesn't fall under the "system library" exception.We don't need system library exception to read
/dev/zfs. It's not a library but a way to speak with kernel which is definitely interprocess communication.
My gut reaction to that would be that it would probably be easier for the ioctl interface to change than the libzfs interface, but that's my personal opinion :).
If you do decide to make changes for other systems, it would be nice to leave in the libzfs code that exists for platforms that have it, if that's allowable/possible.
--S
Hi,
Please test / comment on proof-of-concept attached patch, it gets rid of libzfs dependency in GRUB.
The approach is to implement a disk abstraction, like LVM does, but in this case a very simple one (passthrough). Then grub-probe et al can obtain their information from this abstraction layer like they currently do with LVM or mdRAID, but they don't need the device node list anymore (since it's filled with a full scan, as with LVM).
Signature · 1 line
Robert Millan
=== modified file 'configure.ac'
configure.ac +0 -12
@@ -916,18 +916,6 @@ AC_CHECK_LIB([lzma], [lzma_code], [Define to 1 if you have the LZMA library.])],) AC_SUBST([LIBLZMA]) -AC_CHECK_LIB([zfs], [libzfs_init], - [LIBZFS="-lzfs" - AC_DEFINE([HAVE_LIBZFS], [1], - [Define to 1 if you have the ZFS library.])],) -AC_SUBST([LIBZFS]) - -AC_CHECK_LIB([nvpair], [nvlist_print], - [LIBNVPAIR="-lnvpair" - AC_DEFINE([HAVE_LIBNVPAIR], [1], - [Define to 1 if you have the NVPAIR library.])],) -AC_SUBST([LIBNVPAIR]) - LIBS="" pkglibrootdir='$(libdir)'/`echo $PACKAGE | sed "$program_transform_name"`
=== modified file 'grub-core/fs/zfs/zfs.c'
fs/zfs/zfs.c +135 -0
158 lines not on this page · raw message
=== modified file 'grub-core/kern/disk.c'
kern/disk.c +1 -2
@@ -267,6 +267,7 @@ grub_disk_open (const char *name)for (dev = grub_disk_dev_list; dev; dev = dev->next) { + disk->dev = dev;if ((dev->open) (raw, disk) ==GRUB_ERR_NONE )break ;else if (grub_errno ==GRUB_ERR_UNKNOWN_DEVICE )
@@ -289,8 +290,6 @@ grub_disk_open (const char *name) goto fail; } - disk->dev = dev; -if (p) { disk->partition =grub_partition_probe (disk, p +1 );
=== modified file 'include/grub/disk.h'
grub/disk.h +1 -0
@@ -44,6 +44,7 @@ enum grub_disk_dev_idGRUB_DISK_DEVICE_FILE_ID ,GRUB_DISK_DEVICE_CRYPTODISK_ID ,GRUB_DISK_DEVICE_ARCDISK_ID , + GRUB_DISK_DEVICE_ZFS_ID, };struct grub_disk ;
=== modified file 'include/grub/emu/getroot.h'
grub/emu/getroot.h +1 -0
@@ -27,6 +27,7 @@ enum grub_dev_abstraction_types {GRUB_DEV_ABSTRACTION_RAID ,GRUB_DEV_ABSTRACTION_LUKS ,GRUB_DEV_ABSTRACTION_GELI , + GRUB_DEV_ABSTRACTION_ZFS, };char *grub_find_device (const char *dir,dev_t dev);
=== modified file 'util/getroot.c'
getroot.c +41 -103
230 lines not on this page · raw message
=== modified file 'util/grub-probe.c'
grub-probe.c +10 -4
@@ -144,6 +144,9 @@ probe_abstraction (grub_disk_t disk)if (disk->dev->id ==GRUB_DISK_DEVICE_LVM_ID )printf ("lvm " ); +if (disk->dev->id ==GRUB_DISK_DEVICE_ZFS_ID ) +printf ("zfs " ); +if (disk->dev->id ==GRUB_DISK_DEVICE_CRYPTODISK_ID )grub_util_cryptodisk_print_abstraction (disk);
@@ -171,13 +174,16 @@ probe (const char *path, char *device_naif (path ==NULL ) { +if (!grub_util_check_nodeless_device (device_name)) + {#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) -if (!grub_util_check_char_device (device_name)) -grub_util_error ("%s is not a character device" , device_name); +if (!grub_util_check_char_device (device_name)) +grub_util_error ("%s is not a character device" , device_name);#else -if (!grub_util_check_block_device (device_name)) -grub_util_error ("%s is not a block device" , device_name); +if (!grub_util_check_block_device (device_name)) +grub_util_error ("%s is not a block device" , device_name);#endif + } }else {
Hi,
Have you tested this with phcoder's experimental zfs branch that has mirroring support? What is the device node list used for? To list devices that each need grub installed, or for something else?
--S
Quoted 18 lines · Robert Millan
Hi,
Please test / comment on proof-of-concept attached patch, it gets rid of libzfs dependency in GRUB.
The approach is to implement a disk abstraction, like LVM does, but in this case a very simple one (passthrough). Then grub-probe et al can obtain their information from this abstraction layer like they currently do with LVM or mdRAID, but they don't need the device node list anymore (since it's filled with a full scan, as with LVM).
Signature · 6 lines
Robert Millan <zfs.diff> _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
2011/10/15 Seth Goldberg <[email protected]>:
Quoted 3 lines
Hi,
Have you tested this with phcoder's experimental zfs branch that has mirroring support?
No. I guess I might have duplicated some work; where's that branch? I'll try to rebase my patch.
Quoted 1 line
What is the device node list used for? To list devices that each need grub installed, or for something else?
grub-probe internally needs access to the raw devices because it wants to use GRUB codepaths to obtain fs_uuid and such.
Signature · 1 line
Robert Millan
2011/10/16 Robert Millan <[email protected]>:
Quoted 4 lines
Quoted 1 line
What is the device node list used for? To list devices that each need grub installed, or for something else?
grub-probe internally needs access to the raw devices because it wants to use GRUB codepaths to obtain
fs_uuidand such.
In other words: to use same ZFS codepaths directly on raw device as they will be used when real GRUB boots.
Signature · 1 line
Robert Millan
Hi again,
Also: can we please retain the liners usage for those platforms that actually have it and that would rather use it? I can certainly understand the desire to eliminate it for platforms that don't have or don't want to port it, but eliminating it from all platforms is overkill.
Thanks,
--S
Quoted 18 lines · Robert Millan
Hi,
Please test / comment on proof-of-concept attached patch, it gets rid of libzfs dependency in GRUB.
The approach is to implement a disk abstraction, like LVM does, but in this case a very simple one (passthrough). Then grub-probe et al can obtain their information from this abstraction layer like they currently do with LVM or mdRAID, but they don't need the device node list anymore (since it's filled with a full scan, as with LVM).
Signature · 6 lines
Robert Millan <zfs.diff> _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 3 lines · Seth Goldberg
Hi again,
Also: can we please retain the liners usage
Sorry -- that should have read libzfs, not liners.
--S
Quoted 30 lines
for those platforms that actually have it and that would rather use it? I can certainly understand the desire to eliminate it for platforms that don't have or don't want to port it, but eliminating it from all platforms is overkill.
Thanks,
--SQuoted 18 lines · Robert Millan
Hi,
Please test / comment on proof-of-concept attached patch, it gets rid of libzfs dependency in GRUB.
The approach is to implement a disk abstraction, like LVM does, but in this case a very simple one (passthrough). Then grub-probe et al can obtain their information from this abstraction layer like they currently do with LVM or mdRAID, but they don't need the device node list anymore (since it's filled with a full scan, as with LVM).
Signature · 6 lines
Robert Millan <zfs.diff> _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
2011/10/15 Seth Goldberg <[email protected]>:
Quoted 3 lines
Hi again,
Also: can we please retain the libzfs usage for those platforms that actually have it and that would rather use it?
What for? libzfs is only needed for a single operation (determining physical device list). With my patch that operation is no longer required.
Quoted 1 line
I can certainly understand the desire to eliminate it for platforms that don't have or don't want to port it, but eliminating it from all platforms is overkill.
It's not a portability problem. It seems libzfs isn't really meant to be used externally. ABI changes without notice, there's no soname update and no versioning information. See:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=645305
Signature · 1 line
Robert Millan
Quoting Robert Millan, who wrote the following on Sun, 16 Oct 2011:
Quoted 8 lines
2011/10/15 Seth Goldberg <[email protected]>:
Quoted 3 lines
Hi again,
Also: can we please retain the libzfs usage for those platforms that actually have it and that would rather use it?
What for? libzfs is only needed for a single operation (determining physical device list). With my patch that operation is no longer required.
Ah, ok -- I missed that :).
Quoted 7 lines
Quoted 2 lines
I can certainly understand the desire to eliminate it for platforms that don't have or don't want to port it, but eliminating it from all platforms is overkill.
It's not a portability problem. It seems libzfs isn't really meant to be used externally. ABI changes without notice, there's no soname update and no versioning information. See:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=645305
That's true, though in practice there hasn't been much churn. I like the
idea of using the code that will be running at boot time anyway to do all operations required. And I really like the abstraction -- I think that's what's been missing as a precursor to mirroring support (or raidzX support), so thanks for doing the work!
--S
Quoted 8 lines
Signature · 7 lines
-- Robert Millan _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 5 lines · Robert Millan
Hi,
Please test / comment on proof-of-concept attached patch, it gets rid of libzfs dependency in GRUB.
It looks like this patch would map all zpools with the same name to the same device. That's a problem since system may have several identically-named pools or misdetect a pool somewhere where there is none.
Quoted 12 lines
The approach is to implement a disk abstraction, like LVM does, but in this case a very simple one (passthrough). Then grub-probe et al can obtain their information from this abstraction layer like they currently do with LVM or mdRAID, but they don't need the device node list anymore (since it's filled with a full scan, as with LVM).
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko