Print this page
3745 zpool create should treat -O mountpoint and -m the same
Submitted by:   Will Andrews <willa@spectralogic.com>
Submitted by:   Alan Somers <alans@spectralogic.com>
Reviewed by:    Matthew Ahrens <mahrens@delphix.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/zpool/zpool_main.c
          +++ new/usr/src/cmd/zpool/zpool_main.c
↓ open down ↓ 669 lines elided ↑ open up ↑
 670  670                                  goto errout;
 671  671                          if (nvlist_lookup_string(props,
 672  672                              zpool_prop_to_name(ZPOOL_PROP_CACHEFILE),
 673  673                              &propval) == 0)
 674  674                                  break;
 675  675                          if (add_prop_list(zpool_prop_to_name(
 676  676                              ZPOOL_PROP_CACHEFILE), "none", &props, B_TRUE))
 677  677                                  goto errout;
 678  678                          break;
 679  679                  case 'm':
      680 +                        /* Equivalent to -O mountpoint=optarg */
 680  681                          mountpoint = optarg;
 681  682                          break;
 682  683                  case 'o':
 683  684                          if ((propval = strchr(optarg, '=')) == NULL) {
 684  685                                  (void) fprintf(stderr, gettext("missing "
 685  686                                      "'=' for -o option\n"));
 686  687                                  goto errout;
 687  688                          }
 688  689                          *propval = '\0';
 689  690                          propval++;
↓ open down ↓ 18 lines elided ↑ open up ↑
 708  709                          break;
 709  710                  case 'O':
 710  711                          if ((propval = strchr(optarg, '=')) == NULL) {
 711  712                                  (void) fprintf(stderr, gettext("missing "
 712  713                                      "'=' for -O option\n"));
 713  714                                  goto errout;
 714  715                          }
 715  716                          *propval = '\0';
 716  717                          propval++;
 717  718  
      719 +                        /*
      720 +                         * Mountpoints are checked and then added later.
      721 +                         * Uniquely among properties, they can be specified
      722 +                         * more than once, to avoid conflict with -m.
      723 +                         */
      724 +                        if (!strcmp(optarg,
      725 +                            zfs_prop_to_name(ZFS_PROP_MOUNTPOINT)))
      726 +                                mountpoint = propval;
 718  727                          if (add_prop_list(optarg, propval, &fsprops, B_FALSE))
 719  728                                  goto errout;
 720  729                          break;
 721  730                  case ':':
 722  731                          (void) fprintf(stderr, gettext("missing argument for "
 723  732                              "'%c' option\n"), optopt);
 724  733                          goto badusage;
 725  734                  case '?':
 726  735                          (void) fprintf(stderr, gettext("invalid option '%c'\n"),
 727  736                              optopt);
↓ open down ↓ 98 lines elided ↑ open up ↑
 826  835                                  (void) fprintf(stderr, gettext("mountpoint "
 827  836                                      "'%s' exists and is not empty\n"), buf);
 828  837                                  (void) fprintf(stderr, gettext("use '-m' "
 829  838                                      "option to provide a "
 830  839                                      "different default\n"));
 831  840                                  goto errout;
 832  841                          }
 833  842                  }
 834  843          }
 835  844  
      845 +        /*
      846 +         * Now that the mountpoint's validity has been checked, ensure that
      847 +         * the property is set appropriately prior to creating the pool.
      848 +         */
      849 +        if (mountpoint != NULL)
      850 +                if (add_prop_list(zfs_prop_to_name(ZFS_PROP_MOUNTPOINT),
      851 +                    mountpoint, &fsprops, B_FALSE))
      852 +                        goto errout;
      853 +
 836  854          if (dryrun) {
 837  855                  /*
 838  856                   * For a dry run invocation, print out a basic message and run
 839  857                   * through all the vdevs in the list and print out in an
 840  858                   * appropriate hierarchy.
 841  859                   */
 842  860                  (void) printf(gettext("would create '%s' with the "
 843  861                      "following layout:\n\n"), poolname);
 844  862  
 845  863                  print_vdev_tree(NULL, poolname, nvroot, 0, B_FALSE);
↓ open down ↓ 24 lines elided ↑ open up ↑
 870  888                                  if (add_prop_list(propname, ZFS_FEATURE_ENABLED,
 871  889                                      &props, B_TRUE) != 0)
 872  890                                          goto errout;
 873  891                          }
 874  892                  }
 875  893                  if (zpool_create(g_zfs, poolname,
 876  894                      nvroot, props, fsprops) == 0) {
 877  895                          zfs_handle_t *pool = zfs_open(g_zfs, poolname,
 878  896                              ZFS_TYPE_FILESYSTEM);
 879  897                          if (pool != NULL) {
 880      -                                if (mountpoint != NULL)
 881      -                                        verify(zfs_prop_set(pool,
 882      -                                            zfs_prop_to_name(
 883      -                                            ZFS_PROP_MOUNTPOINT),
 884      -                                            mountpoint) == 0);
 885  898                                  if (zfs_mount(pool, NULL, 0) == 0)
 886  899                                          ret = zfs_shareall(pool);
 887  900                                  zfs_close(pool);
 888  901                          }
 889  902                  } else if (libzfs_errno(g_zfs) == EZFS_INVALIDNAME) {
 890  903                          (void) fprintf(stderr, gettext("pool name may have "
 891  904                              "been omitted\n"));
 892  905                  }
 893  906          }
 894  907  
↓ open down ↓ 4276 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX