Print this page
2447 beadm should be more descriptive about some errors


 106         { "activate",           be_do_activate },
 107         { "create",             be_do_create },
 108         { "destroy",            be_do_destroy },
 109         { "list",               be_do_list },
 110         { "mount",              be_do_mount },
 111         { "unmount",            be_do_unmount },
 112         { "umount",             be_do_unmount }, /* unmount alias */
 113         { "rename",             be_do_rename },
 114         { "rollback",           be_do_rollback },
 115         { NULL,                 NULL },
 116 };
 117 
 118 static void
 119 usage(void)
 120 {
 121         (void) fprintf(stderr, _("usage:\n"
 122             "\tbeadm subcommand cmd_options\n"
 123             "\n"
 124             "\tsubcommands:\n"
 125             "\n"
 126             "\tbeadm activate beName\n"
 127             "\tbeadm create [-d BE_desc]\n"
 128             "\t\t[-o property=value] ... [-p zpool] \n"
 129             "\t\t[-e nonActiveBe | beName@snapshot] beName\n"
 130             "\tbeadm create [-d BE_desc]\n"
 131             "\t\t[-o property=value] ... [-p zpool] beName@snapshot\n"
 132             "\tbeadm destroy [-Ffs] beName \n"
 133             "\tbeadm destroy [-F] beName@snapshot \n"
 134             "\tbeadm list [[-a] | [-d] [-s]] [-H] [beName]\n"
 135             "\tbeadm mount [-s ro|rw] beName [mountpoint]\n"
 136             "\tbeadm unmount [-f] beName | mountpoint\n"
 137             "\tbeadm umount [-f] beName | mountpoint\n"
 138             "\tbeadm rename origBeName newBeName\n"
 139             "\tbeadm rollback beName snapshot\n"
 140             "\tbeadm rollback beName@snapshot\n"));
 141 }
 142 
 143 static int
 144 run_be_cmd(const char *cmdname, int argc, char **argv)
 145 {
 146         const be_command_t *command;
 147 
 148         for (command = &be_command_tbl[0]; command->name != NULL; command++)
 149                 if (strcmp(command->name, cmdname) == 0)
 150                         return (command->func(argc, argv));
 151 
 152         (void) fprintf(stderr, _("Invalid command: %s\n"), cmdname);
 153         usage();
 154         return (1);
 155 }
 156 
 157 int
 158 main(int argc, char **argv)
 159 {
 160         const char *cmdname;


 647 
 648 static int
 649 be_nvl_add_uint16(nvlist_t *nvl, const char *name, uint16_t val)
 650 {
 651         assert(nvl != NULL);
 652 
 653         if (nvlist_add_uint16(nvl, name, val) != 0) {
 654                 (void) fprintf(stderr, _("nvlist_add_uint16 failed for "
 655                     "%s (%hu).\n"), name, val);
 656                 return (1);
 657         }
 658 
 659         return (0);
 660 }
 661 
 662 static int
 663 be_do_activate(int argc, char **argv)
 664 {
 665         nvlist_t        *be_attrs;
 666         int             err = 1;

 667         char            *obe_name;
 668 











 669         argc -= optind;
 670         argv += optind;
 671 
 672         if (argc != 1) {
 673                 usage();
 674                 return (1);
 675         }
 676 
 677         obe_name = argv[0];
 678 
 679         if (be_nvl_alloc(&be_attrs) != 0)
 680                 return (1);
 681 
 682         if (be_nvl_add_string(be_attrs, BE_ATTR_ORIG_BE_NAME, obe_name) != 0)
 683                 goto out;
 684 
 685         err = be_activate(be_attrs);
 686 
 687         switch (err) {
 688         case BE_SUCCESS:


 711 }
 712 
 713 static int
 714 be_do_create(int argc, char **argv)
 715 {
 716         nvlist_t        *be_attrs;
 717         nvlist_t        *zfs_props = NULL;
 718         boolean_t       activate = B_FALSE;
 719         boolean_t       is_snap = B_FALSE;
 720         int             c;
 721         int             err = 1;
 722         char            *obe_name = NULL;
 723         char            *snap_name = NULL;
 724         char            *nbe_zpool = NULL;
 725         char            *nbe_name = NULL;
 726         char            *nbe_desc = NULL;
 727         char            *propname = NULL;
 728         char            *propval = NULL;
 729         char            *strval = NULL;
 730 
 731         while ((c = getopt(argc, argv, "ad:e:io:p:")) != -1) {
 732                 switch (c) {
 733                 case 'a':
 734                         activate = B_TRUE;
 735                         break;
 736                 case 'd':
 737                         nbe_desc = optarg;
 738                         break;
 739                 case 'e':
 740                         obe_name = optarg;
 741                         break;
 742                 case 'o':
 743                         if (zfs_props == NULL && be_nvl_alloc(&zfs_props) != 0)
 744                                 return (1);
 745 
 746                         propname = optarg;
 747                         if ((propval = strchr(propname, '=')) == NULL) {
 748                                 (void) fprintf(stderr, _("missing "
 749                                     "'=' for -o option\n"));
 750                                 goto out2;
 751                         }
 752                         *propval = '\0';
 753                         propval++;
 754                         if (nvlist_lookup_string(zfs_props, propname,
 755                             &strval) == 0) {
 756                                 (void) fprintf(stderr, _("property '%s' "
 757                                     "specified multiple times\n"), propname);
 758                                 goto out2;
 759 
 760                         }
 761                         if (be_nvl_add_string(zfs_props, propname, propval)
 762                             != 0)
 763                                 goto out2;
 764 
 765                         break;
 766                 case 'p':
 767                         nbe_zpool = optarg;
 768                         break;



 769                 default:
 770                         usage();
 771                         goto out2;
 772                 }
 773         }
 774 
 775         argc -= optind;
 776         argv += optind;
 777 
 778         if (argc != 1) {
 779                 usage();
 780                 goto out2;
 781         }
 782 
 783         nbe_name = argv[0];
 784 
 785         if ((snap_name = strrchr(nbe_name, '@')) != NULL) {
 786                 if (snap_name[1] == '\0') {
 787                         usage();
 788                         goto out2;


 922         nvlist_free(be_attrs);
 923 out2:
 924         if (zfs_props != NULL)
 925                 nvlist_free(zfs_props);
 926 
 927         return (err);
 928 }
 929 
 930 static int
 931 be_do_destroy(int argc, char **argv)
 932 {
 933         nvlist_t        *be_attrs;
 934         boolean_t       is_snap = B_FALSE;
 935         boolean_t       suppress_prompt = B_FALSE;
 936         int             err = 1;
 937         int             c;
 938         int             destroy_flags = 0;
 939         char            *snap_name;
 940         char            *be_name;
 941 
 942         while ((c = getopt(argc, argv, "fFs")) != -1) {
 943                 switch (c) {
 944                 case 'f':
 945                         destroy_flags |= BE_DESTROY_FLAG_FORCE_UNMOUNT;
 946                         break;
 947                 case 's':
 948                         destroy_flags |= BE_DESTROY_FLAG_SNAPSHOTS;
 949                         break;



 950                 case 'F':
 951                         suppress_prompt = B_TRUE;
 952                         break;
 953                 default:
 954                         usage();
 955                         return (1);
 956                 }
 957         }
 958 
 959         argc -= optind;
 960         argv += optind;
 961 
 962         if (argc != 1) {
 963                 usage();
 964                 return (1);
 965         }
 966 
 967         be_name = argv[0];
 968         if (!suppress_prompt && !confirm_destroy(be_name)) {
 969                 (void) printf(_("%s has not been destroyed.\n"), be_name);


1044                 (void) fprintf(stderr, "%s\n", be_err_to_str(err));
1045         }
1046 
1047 out:
1048         nvlist_free(be_attrs);
1049         return (err);
1050 }
1051 
1052 static int
1053 be_do_list(int argc, char **argv)
1054 {
1055         be_node_list_t  *be_nodes = NULL;
1056         boolean_t       all = B_FALSE;
1057         boolean_t       dsets = B_FALSE;
1058         boolean_t       snaps = B_FALSE;
1059         boolean_t       parsable = B_FALSE;
1060         int             err = 1;
1061         int             c = 0;
1062         char            *be_name = NULL;
1063 
1064         while ((c = getopt(argc, argv, "nadsH")) != -1) {
1065                 switch (c) {
1066                 case 'a':
1067                         all = B_TRUE;
1068                         break;
1069                 case 'd':
1070                         dsets = B_TRUE;
1071                         break;
1072                 case 's':
1073                         snaps = B_TRUE;
1074                         break;



1075                 case 'H':
1076                         parsable = B_TRUE;
1077                         break;
1078                 default:
1079                         usage();
1080                         return (1);
1081                 }
1082         }
1083 
1084         if (all) {
1085                 if (dsets) {
1086                         (void) fprintf(stderr, _("Invalid options: -a and %s "
1087                             "are mutually exclusive.\n"), "-d");
1088                         usage();
1089                         return (1);
1090                 }
1091                 if (snaps) {
1092                         (void) fprintf(stderr, _("Invalid options: -a and %s "
1093                             "are mutually exclusive.\n"), "-s");
1094                         usage();


1128                 (void) fprintf(stderr, "%s\n", be_err_to_str(err));
1129         }
1130 
1131         if (be_nodes != NULL)
1132                 be_free_list(be_nodes);
1133         return (err);
1134 }
1135 
1136 static int
1137 be_do_mount(int argc, char **argv)
1138 {
1139         nvlist_t        *be_attrs;
1140         boolean_t       shared_fs = B_FALSE;
1141         int             err = 1;
1142         int             c;
1143         int             mount_flags = 0;
1144         char            *obe_name;
1145         char            *mountpoint;
1146         char            *tmp_mp = NULL;
1147 
1148         while ((c = getopt(argc, argv, "s:")) != -1) {
1149                 switch (c) {
1150                 case 's':
1151                         shared_fs = B_TRUE;
1152 
1153                         mount_flags |= BE_MOUNT_FLAG_SHARED_FS;
1154 
1155                         if (strcmp(optarg, "rw") == 0) {
1156                                 mount_flags |= BE_MOUNT_FLAG_SHARED_RW;
1157                         } else if (strcmp(optarg, "ro") != 0) {
1158                                 (void) fprintf(stderr, _("The -s flag "
1159                                     "requires an argument [ rw | ro ]\n"));
1160                                 usage();
1161                                 return (1);
1162                         }
1163 
1164                         break;



1165                 default:
1166                         usage();
1167                         return (1);
1168                 }
1169         }
1170 
1171         argc -= optind;
1172         argv += optind;
1173 
1174         if (argc < 1 || argc > 2) {
1175                 usage();
1176                 return (1);
1177         }
1178 
1179         obe_name = argv[0];
1180 
1181         if (argc == 2) {
1182                 mountpoint = argv[1];
1183                 if (mountpoint[0] != '/') {
1184                         (void) fprintf(stderr, _("Invalid mount point %s. "


1206         if (be_nvl_alloc(&be_attrs) != 0)
1207                 return (1);
1208 
1209         if (be_nvl_add_string(be_attrs, BE_ATTR_ORIG_BE_NAME, obe_name) != 0)
1210                 goto out;
1211 
1212         if (be_nvl_add_string(be_attrs, BE_ATTR_MOUNTPOINT, mountpoint) != 0)
1213                 goto out;
1214 
1215         if (shared_fs && be_nvl_add_uint16(be_attrs, BE_ATTR_MOUNT_FLAGS,
1216             mount_flags) != 0)
1217                 goto out;
1218 
1219         err = be_mount(be_attrs);
1220 
1221         switch (err) {
1222         case BE_SUCCESS:
1223                 (void) printf(_("Mounted successfully on: '%s'\n"), mountpoint);
1224                 break;
1225         case BE_ERR_BE_NOENT:
1226                 err = 1;
1227                 (void) fprintf(stderr, _("%s does not exist or appear "
1228                     "to be a valid BE.\nPlease check that the name of "
1229                     "the BE provided is correct.\n"), obe_name);
1230                 break;
1231         case BE_ERR_MOUNTED:
1232                 (void) fprintf(stderr, _("%s is already mounted.\n"
1233                     "Please unmount the BE before mounting it again.\n"),
1234                     obe_name);
1235                 break;
1236         case BE_ERR_PERM:
1237         case BE_ERR_ACCESS:
1238                 err = 1;
1239                 (void) fprintf(stderr, _("Unable to mount %s.\n"), obe_name);
1240                 (void) fprintf(stderr, _("You have insufficient privileges to "
1241                     "execute this command.\n"));
1242                 break;
1243         default:
1244                 err = 1;
1245                 (void) fprintf(stderr, _("Unable to mount %s.\n"), obe_name);
1246                 (void) fprintf(stderr, "%s\n", be_err_to_str(err));
1247         }
1248 
1249 out:
1250         if (tmp_mp != NULL)
1251                 free(tmp_mp);
1252         nvlist_free(be_attrs);
1253         return (err);
1254 }
1255 
1256 static int
1257 be_do_unmount(int argc, char **argv)
1258 {
1259         nvlist_t        *be_attrs;
1260         char            *obe_name;
1261         int             err = 1;
1262         int             c;
1263         int             unmount_flags = 0;
1264 
1265         while ((c = getopt(argc, argv, "f")) != -1) {
1266                 switch (c) {
1267                 case 'f':
1268                         unmount_flags |= BE_UNMOUNT_FLAG_FORCE;
1269                         break;



1270                 default:
1271                         usage();
1272                         return (1);
1273                 }
1274         }
1275 
1276         argc -= optind;
1277         argv += optind;
1278 
1279         if (argc != 1) {
1280                 usage();
1281                 return (1);
1282         }
1283 
1284         obe_name = argv[0];
1285 
1286         if (be_nvl_alloc(&be_attrs) != 0)
1287                 return (1);
1288 
1289 


1320                 (void) fprintf(stderr, _("You have insufficient privileges to "
1321                     "execute this command.\n"));
1322                 break;
1323         default:
1324                 (void) fprintf(stderr, _("Unable to unmount %s.\n"), obe_name);
1325                 (void) fprintf(stderr, "%s\n", be_err_to_str(err));
1326         }
1327 
1328 out:
1329         nvlist_free(be_attrs);
1330         return (err);
1331 }
1332 
1333 static int
1334 be_do_rename(int argc, char **argv)
1335 {
1336         nvlist_t        *be_attrs;
1337         char            *obe_name;
1338         char            *nbe_name;
1339         int err = 1;

1340 











1341         argc -= optind;
1342         argv += optind;
1343 
1344         if (argc != 2) {
1345                 usage();
1346                 return (1);
1347         }
1348 
1349         obe_name = argv[0];
1350         nbe_name = argv[1];
1351 
1352         if (be_nvl_alloc(&be_attrs) != 0)
1353                 return (1);
1354 
1355         if (be_nvl_add_string(be_attrs, BE_ATTR_ORIG_BE_NAME, obe_name) != 0)
1356                 goto out;
1357 
1358         if (be_nvl_add_string(be_attrs, BE_ATTR_NEW_BE_NAME, nbe_name) != 0)
1359                 goto out;
1360 


1377                     "execute this command.\n"));
1378                 break;
1379         default:
1380                 (void) fprintf(stderr, _("Rename of BE %s failed.\n"),
1381                     obe_name);
1382                 (void) fprintf(stderr, "%s\n", be_err_to_str(err));
1383         }
1384 
1385 out:
1386         nvlist_free(be_attrs);
1387         return (err);
1388 }
1389 
1390 static int
1391 be_do_rollback(int argc, char **argv)
1392 {
1393         nvlist_t        *be_attrs;
1394         char            *obe_name;
1395         char            *snap_name;
1396         int             err = 1;

1397 











1398         argc -= optind;
1399         argv += optind;
1400 
1401         if (argc < 1 || argc > 2) {
1402                 usage();
1403                 return (1);
1404         }
1405 
1406         obe_name = argv[0];
1407         if (argc == 2)
1408                 snap_name = argv[1];
1409         else { /* argc == 1 */
1410                 if ((snap_name = strrchr(obe_name, '@')) != NULL) {
1411                         if (snap_name[1] == '\0') {
1412                                 usage();
1413                                 return (1);
1414                         }
1415 
1416                         snap_name[0] = '\0';
1417                         snap_name++;




 106         { "activate",           be_do_activate },
 107         { "create",             be_do_create },
 108         { "destroy",            be_do_destroy },
 109         { "list",               be_do_list },
 110         { "mount",              be_do_mount },
 111         { "unmount",            be_do_unmount },
 112         { "umount",             be_do_unmount }, /* unmount alias */
 113         { "rename",             be_do_rename },
 114         { "rollback",           be_do_rollback },
 115         { NULL,                 NULL },
 116 };
 117 
 118 static void
 119 usage(void)
 120 {
 121         (void) fprintf(stderr, _("usage:\n"
 122             "\tbeadm subcommand cmd_options\n"
 123             "\n"
 124             "\tsubcommands:\n"
 125             "\n"
 126             "\tbeadm activate [-v] beName\n"
 127             "\tbeadm create [-a] [-d BE_desc]\n"
 128             "\t\t[-o property=value] ... [-p zpool] \n"
 129             "\t\t[-e nonActiveBe | beName@snapshot] [-v] beName\n"
 130             "\tbeadm create [-d BE_desc]\n"
 131             "\t\t[-o property=value] ... [-p zpool] [-v] beName@snapshot\n"
 132             "\tbeadm destroy [-Ffsv] beName \n"
 133             "\tbeadm destroy [-Fv] beName@snapshot \n"
 134             "\tbeadm list [[-a] | [-d] [-s]] [-H] [-v] [beName]\n"
 135             "\tbeadm mount [-s ro|rw] [-v] beName [mountpoint]\n"
 136             "\tbeadm unmount [-fv] beName | mountpoint\n"
 137             "\tbeadm umount [-fv] beName | mountpoint\n"
 138             "\tbeadm rename [-v] origBeName newBeName\n"
 139             "\tbeadm rollback [-v] beName snapshot\n"
 140             "\tbeadm rollback [-v] beName@snapshot\n"));
 141 }
 142 
 143 static int
 144 run_be_cmd(const char *cmdname, int argc, char **argv)
 145 {
 146         const be_command_t *command;
 147 
 148         for (command = &be_command_tbl[0]; command->name != NULL; command++)
 149                 if (strcmp(command->name, cmdname) == 0)
 150                         return (command->func(argc, argv));
 151 
 152         (void) fprintf(stderr, _("Invalid command: %s\n"), cmdname);
 153         usage();
 154         return (1);
 155 }
 156 
 157 int
 158 main(int argc, char **argv)
 159 {
 160         const char *cmdname;


 647 
 648 static int
 649 be_nvl_add_uint16(nvlist_t *nvl, const char *name, uint16_t val)
 650 {
 651         assert(nvl != NULL);
 652 
 653         if (nvlist_add_uint16(nvl, name, val) != 0) {
 654                 (void) fprintf(stderr, _("nvlist_add_uint16 failed for "
 655                     "%s (%hu).\n"), name, val);
 656                 return (1);
 657         }
 658 
 659         return (0);
 660 }
 661 
 662 static int
 663 be_do_activate(int argc, char **argv)
 664 {
 665         nvlist_t        *be_attrs;
 666         int             err = 1;
 667         int             c;
 668         char            *obe_name;
 669 
 670         while ((c = getopt(argc, argv, "v")) != -1) {
 671                 switch (c) {
 672                 case 'v':
 673                         libbe_print_errors(B_TRUE);
 674                         break;
 675                 default:
 676                         usage();
 677                         return (1);
 678                 }
 679         }
 680 
 681         argc -= optind;
 682         argv += optind;
 683 
 684         if (argc != 1) {
 685                 usage();
 686                 return (1);
 687         }
 688 
 689         obe_name = argv[0];
 690 
 691         if (be_nvl_alloc(&be_attrs) != 0)
 692                 return (1);
 693 
 694         if (be_nvl_add_string(be_attrs, BE_ATTR_ORIG_BE_NAME, obe_name) != 0)
 695                 goto out;
 696 
 697         err = be_activate(be_attrs);
 698 
 699         switch (err) {
 700         case BE_SUCCESS:


 723 }
 724 
 725 static int
 726 be_do_create(int argc, char **argv)
 727 {
 728         nvlist_t        *be_attrs;
 729         nvlist_t        *zfs_props = NULL;
 730         boolean_t       activate = B_FALSE;
 731         boolean_t       is_snap = B_FALSE;
 732         int             c;
 733         int             err = 1;
 734         char            *obe_name = NULL;
 735         char            *snap_name = NULL;
 736         char            *nbe_zpool = NULL;
 737         char            *nbe_name = NULL;
 738         char            *nbe_desc = NULL;
 739         char            *propname = NULL;
 740         char            *propval = NULL;
 741         char            *strval = NULL;
 742 
 743         while ((c = getopt(argc, argv, "ad:e:io:p:v")) != -1) {
 744                 switch (c) {
 745                 case 'a':
 746                         activate = B_TRUE;
 747                         break;
 748                 case 'd':
 749                         nbe_desc = optarg;
 750                         break;
 751                 case 'e':
 752                         obe_name = optarg;
 753                         break;
 754                 case 'o':
 755                         if (zfs_props == NULL && be_nvl_alloc(&zfs_props) != 0)
 756                                 return (1);
 757 
 758                         propname = optarg;
 759                         if ((propval = strchr(propname, '=')) == NULL) {
 760                                 (void) fprintf(stderr, _("missing "
 761                                     "'=' for -o option\n"));
 762                                 goto out2;
 763                         }
 764                         *propval = '\0';
 765                         propval++;
 766                         if (nvlist_lookup_string(zfs_props, propname,
 767                             &strval) == 0) {
 768                                 (void) fprintf(stderr, _("property '%s' "
 769                                     "specified multiple times\n"), propname);
 770                                 goto out2;
 771 
 772                         }
 773                         if (be_nvl_add_string(zfs_props, propname, propval)
 774                             != 0)
 775                                 goto out2;
 776 
 777                         break;
 778                 case 'p':
 779                         nbe_zpool = optarg;
 780                         break;
 781                 case 'v':
 782                         libbe_print_errors(B_TRUE);
 783                         break;
 784                 default:
 785                         usage();
 786                         goto out2;
 787                 }
 788         }
 789 
 790         argc -= optind;
 791         argv += optind;
 792 
 793         if (argc != 1) {
 794                 usage();
 795                 goto out2;
 796         }
 797 
 798         nbe_name = argv[0];
 799 
 800         if ((snap_name = strrchr(nbe_name, '@')) != NULL) {
 801                 if (snap_name[1] == '\0') {
 802                         usage();
 803                         goto out2;


 937         nvlist_free(be_attrs);
 938 out2:
 939         if (zfs_props != NULL)
 940                 nvlist_free(zfs_props);
 941 
 942         return (err);
 943 }
 944 
 945 static int
 946 be_do_destroy(int argc, char **argv)
 947 {
 948         nvlist_t        *be_attrs;
 949         boolean_t       is_snap = B_FALSE;
 950         boolean_t       suppress_prompt = B_FALSE;
 951         int             err = 1;
 952         int             c;
 953         int             destroy_flags = 0;
 954         char            *snap_name;
 955         char            *be_name;
 956 
 957         while ((c = getopt(argc, argv, "fFsv")) != -1) {
 958                 switch (c) {
 959                 case 'f':
 960                         destroy_flags |= BE_DESTROY_FLAG_FORCE_UNMOUNT;
 961                         break;
 962                 case 's':
 963                         destroy_flags |= BE_DESTROY_FLAG_SNAPSHOTS;
 964                         break;
 965                 case 'v':
 966                         libbe_print_errors(B_TRUE);
 967                         break;
 968                 case 'F':
 969                         suppress_prompt = B_TRUE;
 970                         break;
 971                 default:
 972                         usage();
 973                         return (1);
 974                 }
 975         }
 976 
 977         argc -= optind;
 978         argv += optind;
 979 
 980         if (argc != 1) {
 981                 usage();
 982                 return (1);
 983         }
 984 
 985         be_name = argv[0];
 986         if (!suppress_prompt && !confirm_destroy(be_name)) {
 987                 (void) printf(_("%s has not been destroyed.\n"), be_name);


1062                 (void) fprintf(stderr, "%s\n", be_err_to_str(err));
1063         }
1064 
1065 out:
1066         nvlist_free(be_attrs);
1067         return (err);
1068 }
1069 
1070 static int
1071 be_do_list(int argc, char **argv)
1072 {
1073         be_node_list_t  *be_nodes = NULL;
1074         boolean_t       all = B_FALSE;
1075         boolean_t       dsets = B_FALSE;
1076         boolean_t       snaps = B_FALSE;
1077         boolean_t       parsable = B_FALSE;
1078         int             err = 1;
1079         int             c = 0;
1080         char            *be_name = NULL;
1081 
1082         while ((c = getopt(argc, argv, "adsvH")) != -1) {
1083                 switch (c) {
1084                 case 'a':
1085                         all = B_TRUE;
1086                         break;
1087                 case 'd':
1088                         dsets = B_TRUE;
1089                         break;
1090                 case 's':
1091                         snaps = B_TRUE;
1092                         break;
1093                 case 'v':
1094                         libbe_print_errors(B_TRUE);
1095                         break;
1096                 case 'H':
1097                         parsable = B_TRUE;
1098                         break;
1099                 default:
1100                         usage();
1101                         return (1);
1102                 }
1103         }
1104 
1105         if (all) {
1106                 if (dsets) {
1107                         (void) fprintf(stderr, _("Invalid options: -a and %s "
1108                             "are mutually exclusive.\n"), "-d");
1109                         usage();
1110                         return (1);
1111                 }
1112                 if (snaps) {
1113                         (void) fprintf(stderr, _("Invalid options: -a and %s "
1114                             "are mutually exclusive.\n"), "-s");
1115                         usage();


1149                 (void) fprintf(stderr, "%s\n", be_err_to_str(err));
1150         }
1151 
1152         if (be_nodes != NULL)
1153                 be_free_list(be_nodes);
1154         return (err);
1155 }
1156 
1157 static int
1158 be_do_mount(int argc, char **argv)
1159 {
1160         nvlist_t        *be_attrs;
1161         boolean_t       shared_fs = B_FALSE;
1162         int             err = 1;
1163         int             c;
1164         int             mount_flags = 0;
1165         char            *obe_name;
1166         char            *mountpoint;
1167         char            *tmp_mp = NULL;
1168 
1169         while ((c = getopt(argc, argv, "s:v")) != -1) {
1170                 switch (c) {
1171                 case 's':
1172                         shared_fs = B_TRUE;
1173 
1174                         mount_flags |= BE_MOUNT_FLAG_SHARED_FS;
1175 
1176                         if (strcmp(optarg, "rw") == 0) {
1177                                 mount_flags |= BE_MOUNT_FLAG_SHARED_RW;
1178                         } else if (strcmp(optarg, "ro") != 0) {
1179                                 (void) fprintf(stderr, _("The -s flag "
1180                                     "requires an argument [ rw | ro ]\n"));
1181                                 usage();
1182                                 return (1);
1183                         }
1184 
1185                         break;
1186                 case 'v':
1187                         libbe_print_errors(B_TRUE);
1188                         break;
1189                 default:
1190                         usage();
1191                         return (1);
1192                 }
1193         }
1194 
1195         argc -= optind;
1196         argv += optind;
1197 
1198         if (argc < 1 || argc > 2) {
1199                 usage();
1200                 return (1);
1201         }
1202 
1203         obe_name = argv[0];
1204 
1205         if (argc == 2) {
1206                 mountpoint = argv[1];
1207                 if (mountpoint[0] != '/') {
1208                         (void) fprintf(stderr, _("Invalid mount point %s. "


1230         if (be_nvl_alloc(&be_attrs) != 0)
1231                 return (1);
1232 
1233         if (be_nvl_add_string(be_attrs, BE_ATTR_ORIG_BE_NAME, obe_name) != 0)
1234                 goto out;
1235 
1236         if (be_nvl_add_string(be_attrs, BE_ATTR_MOUNTPOINT, mountpoint) != 0)
1237                 goto out;
1238 
1239         if (shared_fs && be_nvl_add_uint16(be_attrs, BE_ATTR_MOUNT_FLAGS,
1240             mount_flags) != 0)
1241                 goto out;
1242 
1243         err = be_mount(be_attrs);
1244 
1245         switch (err) {
1246         case BE_SUCCESS:
1247                 (void) printf(_("Mounted successfully on: '%s'\n"), mountpoint);
1248                 break;
1249         case BE_ERR_BE_NOENT:

1250                 (void) fprintf(stderr, _("%s does not exist or appear "
1251                     "to be a valid BE.\nPlease check that the name of "
1252                     "the BE provided is correct.\n"), obe_name);
1253                 break;
1254         case BE_ERR_MOUNTED:
1255                 (void) fprintf(stderr, _("%s is already mounted.\n"
1256                     "Please unmount the BE before mounting it again.\n"),
1257                     obe_name);
1258                 break;
1259         case BE_ERR_PERM:
1260         case BE_ERR_ACCESS:

1261                 (void) fprintf(stderr, _("Unable to mount %s.\n"), obe_name);
1262                 (void) fprintf(stderr, _("You have insufficient privileges to "
1263                     "execute this command.\n"));
1264                 break;
1265         default:

1266                 (void) fprintf(stderr, _("Unable to mount %s.\n"), obe_name);
1267                 (void) fprintf(stderr, "%s\n", be_err_to_str(err));
1268         }
1269 
1270 out:
1271         if (tmp_mp != NULL)
1272                 free(tmp_mp);
1273         nvlist_free(be_attrs);
1274         return (err);
1275 }
1276 
1277 static int
1278 be_do_unmount(int argc, char **argv)
1279 {
1280         nvlist_t        *be_attrs;
1281         char            *obe_name;
1282         int             err = 1;
1283         int             c;
1284         int             unmount_flags = 0;
1285 
1286         while ((c = getopt(argc, argv, "fv")) != -1) {
1287                 switch (c) {
1288                 case 'f':
1289                         unmount_flags |= BE_UNMOUNT_FLAG_FORCE;
1290                         break;
1291                 case 'v':
1292                         libbe_print_errors(B_TRUE);
1293                         break;
1294                 default:
1295                         usage();
1296                         return (1);
1297                 }
1298         }
1299 
1300         argc -= optind;
1301         argv += optind;
1302 
1303         if (argc != 1) {
1304                 usage();
1305                 return (1);
1306         }
1307 
1308         obe_name = argv[0];
1309 
1310         if (be_nvl_alloc(&be_attrs) != 0)
1311                 return (1);
1312 
1313 


1344                 (void) fprintf(stderr, _("You have insufficient privileges to "
1345                     "execute this command.\n"));
1346                 break;
1347         default:
1348                 (void) fprintf(stderr, _("Unable to unmount %s.\n"), obe_name);
1349                 (void) fprintf(stderr, "%s\n", be_err_to_str(err));
1350         }
1351 
1352 out:
1353         nvlist_free(be_attrs);
1354         return (err);
1355 }
1356 
1357 static int
1358 be_do_rename(int argc, char **argv)
1359 {
1360         nvlist_t        *be_attrs;
1361         char            *obe_name;
1362         char            *nbe_name;
1363         int err = 1;
1364         int c;
1365 
1366         while ((c = getopt(argc, argv, "v")) != -1) {
1367                 switch (c) {
1368                 case 'v':
1369                         libbe_print_errors(B_TRUE);
1370                         break;
1371                 default:
1372                         usage();
1373                         return (1);
1374                 }
1375         }
1376 
1377         argc -= optind;
1378         argv += optind;
1379 
1380         if (argc != 2) {
1381                 usage();
1382                 return (1);
1383         }
1384 
1385         obe_name = argv[0];
1386         nbe_name = argv[1];
1387 
1388         if (be_nvl_alloc(&be_attrs) != 0)
1389                 return (1);
1390 
1391         if (be_nvl_add_string(be_attrs, BE_ATTR_ORIG_BE_NAME, obe_name) != 0)
1392                 goto out;
1393 
1394         if (be_nvl_add_string(be_attrs, BE_ATTR_NEW_BE_NAME, nbe_name) != 0)
1395                 goto out;
1396 


1413                     "execute this command.\n"));
1414                 break;
1415         default:
1416                 (void) fprintf(stderr, _("Rename of BE %s failed.\n"),
1417                     obe_name);
1418                 (void) fprintf(stderr, "%s\n", be_err_to_str(err));
1419         }
1420 
1421 out:
1422         nvlist_free(be_attrs);
1423         return (err);
1424 }
1425 
1426 static int
1427 be_do_rollback(int argc, char **argv)
1428 {
1429         nvlist_t        *be_attrs;
1430         char            *obe_name;
1431         char            *snap_name;
1432         int             err = 1;
1433         int             c;
1434 
1435         while ((c = getopt(argc, argv, "v")) != -1) {
1436                 switch (c) {
1437                 case 'v':
1438                         libbe_print_errors(B_TRUE);
1439                         break;
1440                 default:
1441                         usage();
1442                         return (1);
1443                 }
1444         }
1445 
1446         argc -= optind;
1447         argv += optind;
1448 
1449         if (argc < 1 || argc > 2) {
1450                 usage();
1451                 return (1);
1452         }
1453 
1454         obe_name = argv[0];
1455         if (argc == 2)
1456                 snap_name = argv[1];
1457         else { /* argc == 1 */
1458                 if ((snap_name = strrchr(obe_name, '@')) != NULL) {
1459                         if (snap_name[1] == '\0') {
1460                                 usage();
1461                                 return (1);
1462                         }
1463 
1464                         snap_name[0] = '\0';
1465                         snap_name++;