Print this page
grub patch

Split Close
Expand all
Collapse all
          --- old/grub/grub-core/fs/zfs/zfsinfo.c
          +++ new/grub/grub-core/fs/zfs/zfsinfo.c
↓ open down ↓ 176 lines elided ↑ open up ↑
 177  177        return GRUB_ERR_NONE;
 178  178      }
 179  179  
 180  180    print_tabs (tab);
 181  181    grub_printf_ (N_("Unknown virtual device type: %s\n"), type);
 182  182  
 183  183    return GRUB_ERR_NONE;
 184  184  }
 185  185  
 186  186  static grub_err_t
 187      -get_bootpath (char *nvlist, char **bootpath, char **devid)
      187 +get_bootpath (char *nvlist, char **bootpath, char **devid, grub_uint64_t inguid)
 188  188  {
 189  189    char *type = 0;
      190 +  grub_uint64_t diskguid = 0;
 190  191  
 191  192    type = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_TYPE);
 192  193  
 193  194    if (!type)
 194  195      return grub_errno;
 195  196  
 196  197    if (grub_strcmp (type, VDEV_TYPE_DISK) == 0)
 197  198      {
      199 +      grub_zfs_nvlist_lookup_uint64 (nvlist, "guid", &diskguid);
 198  200        *bootpath = grub_zfs_nvlist_lookup_string (nvlist,
 199  201                                                   ZPOOL_CONFIG_PHYS_PATH);
 200  202        *devid = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_DEVID);
 201      -      if (!*bootpath || !*devid)
      203 +      if (!*bootpath || !*devid || (diskguid != inguid))
 202  204          {
 203  205            grub_free (*bootpath);
 204  206            grub_free (*devid);
 205  207            *bootpath = 0;
 206  208            *devid = 0;
 207  209          }
 208  210        return GRUB_ERR_NONE;
 209  211      }
 210  212  
 211  213    if (grub_strcmp (type, VDEV_TYPE_MIRROR) == 0)
↓ open down ↓ 4 lines elided ↑ open up ↑
 216  218          (nvlist, ZPOOL_CONFIG_CHILDREN);
 217  219  
 218  220        for (i = 0; i < nelm; i++)
 219  221          {
 220  222            char *child;
 221  223  
 222  224            child = grub_zfs_nvlist_lookup_nvlist_array (nvlist,
 223  225                                                         ZPOOL_CONFIG_CHILDREN,
 224  226                                                         i);
 225  227  
 226      -          get_bootpath (child, bootpath, devid);
      228 +          get_bootpath (child, bootpath, devid, inguid);
 227  229  
 228  230            grub_free (child);
 229  231  
 230  232            if (*bootpath && *devid)
 231  233              return GRUB_ERR_NONE;
 232  234          }
 233  235      }
 234  236  
 235  237    return GRUB_ERR_NONE;
 236  238  }
↓ open down ↓ 96 lines elided ↑ open up ↑
 333  335  {
 334  336    grub_device_t dev;
 335  337    char *devname;
 336  338    grub_err_t err;
 337  339    char *nvlist = 0;
 338  340    char *nv = 0;
 339  341    char *bootpath = 0, *devid = 0;
 340  342    char *fsname;
 341  343    char *bootfs;
 342  344    char *poolname;
 343      -  grub_uint64_t mdnobj;
      345 +  char def_path[512];
      346 +  struct grub_zfs_data * data;
      347 +  grub_uint64_t mdnobj, guid;
      348 +  int def = 0;
 344  349  
 345      -  if (argc < 1)
      350 +  if (argc <  1) 
 346  351      return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
 347  352  
 348  353    devname = grub_file_get_device_name (args[0]);
      354 +
 349  355    if (grub_errno)
 350  356      return grub_errno;
 351  357  
 352  358    dev = grub_device_open (devname);
 353  359    grub_free (devname);
 354  360    if (!dev)
 355  361      return grub_errno;
 356  362  
 357  363    err = grub_zfs_fetch_nvlist (dev, &nvlist);
 358  364  
 359  365    fsname = grub_strchr (args[0], ')');
 360  366    if (fsname)
 361  367      fsname++;
 362  368    else
 363  369      fsname = args[0];
 364  370  
 365      -  if (!err)
      371 +  if (grub_strcmp(fsname, "default") == 0)
      372 +    ++def;
      373 +
      374 +  if (! def) {
 366  375      err = grub_zfs_getmdnobj (dev, fsname, &mdnobj);
      376 +  } else {
      377 +    err = get_default_bootfs_obj(dev, def_path, &mdnobj);
      378 +  }
 367  379  
 368  380    grub_device_close (dev);
 369  381  
 370  382    if (err)
 371  383      return err;
 372  384  
 373  385    poolname = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_POOL_NAME);
 374  386    if (!poolname)
 375  387      {
 376  388        if (!grub_errno)
 377  389          grub_error (GRUB_ERR_BAD_FS, "No poolname found");
 378  390        return grub_errno;
 379  391      }
 380  392  
 381  393    nv = grub_zfs_nvlist_lookup_nvlist (nvlist, ZPOOL_CONFIG_VDEV_TREE);
      394 +  grub_zfs_nvlist_lookup_uint64 (nvlist, "guid", &guid);
 382  395  
 383      -  if (nv)
 384      -    get_bootpath (nv, &bootpath, &devid);
      396 +  if (nv && guid)
      397 +    get_bootpath (nv, &bootpath, &devid, guid);
 385  398  
 386  399    grub_free (nv);
 387  400    grub_free (nvlist);
 388  401  
 389  402    bootfs = grub_xasprintf ("zfs-bootfs=%s/%llu%s%s%s%s%s%s",
 390  403                             poolname, (unsigned long long) mdnobj,
 391  404                             bootpath ? ",bootpath=\"" : "",
 392  405                             bootpath ? : "",
 393  406                             bootpath ? "\"" : "",
 394  407                             devid ? ",diskdevid=\"" : "",
 395  408                             devid ? : "",
 396  409                             devid ? "\"" : "");
 397  410    if (!bootfs)
 398  411      return grub_errno;
 399  412    if (argc >= 2)
 400  413      grub_env_set (args[1], bootfs);
 401  414    else
 402  415      grub_printf ("%s\n", bootfs);
 403  416  
      417 +  if ((def) && (argc >= 3))
      418 +    grub_env_set(args[2], def_path);
      419 +  else if (def)
      420 +    grub_printf("%s\n", def_path);
      421 +
 404  422    grub_free (bootfs);
 405  423    grub_free (poolname);
 406  424    grub_free (bootpath);
 407  425    grub_free (devid);
 408  426  
 409  427    return GRUB_ERR_NONE;
 410  428  }
 411  429  
 412  430  
 413  431  static grub_command_t cmd_info, cmd_bootfs;
↓ open down ↓ 16 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX