Print this page
grub patch
@@ -182,25 +182,27 @@
return GRUB_ERR_NONE;
}
static grub_err_t
-get_bootpath (char *nvlist, char **bootpath, char **devid)
+get_bootpath (char *nvlist, char **bootpath, char **devid, grub_uint64_t inguid)
{
char *type = 0;
+ grub_uint64_t diskguid = 0;
type = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_TYPE);
if (!type)
return grub_errno;
if (grub_strcmp (type, VDEV_TYPE_DISK) == 0)
{
+ grub_zfs_nvlist_lookup_uint64 (nvlist, "guid", &diskguid);
*bootpath = grub_zfs_nvlist_lookup_string (nvlist,
ZPOOL_CONFIG_PHYS_PATH);
*devid = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_DEVID);
- if (!*bootpath || !*devid)
+ if (!*bootpath || !*devid || (diskguid != inguid))
{
grub_free (*bootpath);
grub_free (*devid);
*bootpath = 0;
*devid = 0;
@@ -221,11 +223,11 @@
child = grub_zfs_nvlist_lookup_nvlist_array (nvlist,
ZPOOL_CONFIG_CHILDREN,
i);
- get_bootpath (child, bootpath, devid);
+ get_bootpath (child, bootpath, devid, inguid);
grub_free (child);
if (*bootpath && *devid)
return GRUB_ERR_NONE;
@@ -338,16 +340,20 @@
char *nv = 0;
char *bootpath = 0, *devid = 0;
char *fsname;
char *bootfs;
char *poolname;
- grub_uint64_t mdnobj;
+ char def_path[512];
+ struct grub_zfs_data * data;
+ grub_uint64_t mdnobj, guid;
+ int def = 0;
if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
devname = grub_file_get_device_name (args[0]);
+
if (grub_errno)
return grub_errno;
dev = grub_device_open (devname);
grub_free (devname);
@@ -360,12 +366,18 @@
if (fsname)
fsname++;
else
fsname = args[0];
- if (!err)
+ if (grub_strcmp(fsname, "default") == 0)
+ ++def;
+
+ if (! def) {
err = grub_zfs_getmdnobj (dev, fsname, &mdnobj);
+ } else {
+ err = get_default_bootfs_obj(dev, def_path, &mdnobj);
+ }
grub_device_close (dev);
if (err)
return err;
@@ -377,13 +389,14 @@
grub_error (GRUB_ERR_BAD_FS, "No poolname found");
return grub_errno;
}
nv = grub_zfs_nvlist_lookup_nvlist (nvlist, ZPOOL_CONFIG_VDEV_TREE);
+ grub_zfs_nvlist_lookup_uint64 (nvlist, "guid", &guid);
- if (nv)
- get_bootpath (nv, &bootpath, &devid);
+ if (nv && guid)
+ get_bootpath (nv, &bootpath, &devid, guid);
grub_free (nv);
grub_free (nvlist);
bootfs = grub_xasprintf ("zfs-bootfs=%s/%llu%s%s%s%s%s%s",
@@ -399,10 +412,15 @@
if (argc >= 2)
grub_env_set (args[1], bootfs);
else
grub_printf ("%s\n", bootfs);
+ if ((def) && (argc >= 3))
+ grub_env_set(args[2], def_path);
+ else if (def)
+ grub_printf("%s\n", def_path);
+
grub_free (bootfs);
grub_free (poolname);
grub_free (bootpath);
grub_free (devid);