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 +                ret = add_prop_list(zfs_prop_to_name(ZFS_PROP_MOUNTPOINT),
      851 +                    mountpoint, &fsprops, B_FALSE);
      852 +                if (ret != 0)
      853 +                        goto errout;
      854 +        }
      855 +
      856 +        ret = 1;
 836  857          if (dryrun) {
 837  858                  /*
 838  859                   * For a dry run invocation, print out a basic message and run
 839  860                   * through all the vdevs in the list and print out in an
 840  861                   * appropriate hierarchy.
 841  862                   */
 842  863                  (void) printf(gettext("would create '%s' with the "
 843  864                      "following layout:\n\n"), poolname);
 844  865  
 845  866                  print_vdev_tree(NULL, poolname, nvroot, 0, B_FALSE);
↓ open down ↓ 14 lines elided ↑ open up ↑
 860  881                                  (void) snprintf(propname, sizeof (propname),
 861  882                                      "feature@%s", feat->fi_uname);
 862  883  
 863  884                                  /*
 864  885                                   * Skip feature if user specified it manually
 865  886                                   * on the command line.
 866  887                                   */
 867  888                                  if (nvlist_exists(props, propname))
 868  889                                          continue;
 869  890  
 870      -                                if (add_prop_list(propname, ZFS_FEATURE_ENABLED,
 871      -                                    &props, B_TRUE) != 0)
      891 +                                ret = add_prop_list(propname,
      892 +                                    ZFS_FEATURE_ENABLED, &props, B_TRUE);
      893 +                                if (ret != 0)
 872  894                                          goto errout;
 873  895                          }
 874  896                  }
 875  897                  if (zpool_create(g_zfs, poolname,
 876  898                      nvroot, props, fsprops) == 0) {
 877  899                          zfs_handle_t *pool = zfs_open(g_zfs, poolname,
 878  900                              ZFS_TYPE_FILESYSTEM);
 879  901                          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  902                                  if (zfs_mount(pool, NULL, 0) == 0)
 886  903                                          ret = zfs_shareall(pool);
 887  904                                  zfs_close(pool);
 888  905                          }
 889  906                  } else if (libzfs_errno(g_zfs) == EZFS_INVALIDNAME) {
 890  907                          (void) fprintf(stderr, gettext("pool name may have "
 891  908                              "been omitted\n"));
 892  909                  }
 893  910          }
 894  911  
↓ open down ↓ 4276 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX