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

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/beadm/beadm.c
          +++ new/usr/src/cmd/beadm/beadm.c
↓ open down ↓ 115 lines elided ↑ open up ↑
 116  116  };
 117  117  
 118  118  static void
 119  119  usage(void)
 120  120  {
 121  121          (void) fprintf(stderr, _("usage:\n"
 122  122              "\tbeadm subcommand cmd_options\n"
 123  123              "\n"
 124  124              "\tsubcommands:\n"
 125  125              "\n"
 126      -            "\tbeadm activate beName\n"
 127      -            "\tbeadm create [-d BE_desc]\n"
      126 +            "\tbeadm activate [-v] beName\n"
      127 +            "\tbeadm create [-a] [-d BE_desc]\n"
 128  128              "\t\t[-o property=value] ... [-p zpool] \n"
 129      -            "\t\t[-e nonActiveBe | beName@snapshot] beName\n"
      129 +            "\t\t[-e nonActiveBe | beName@snapshot] [-v] beName\n"
 130  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"));
      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  141  }
 142  142  
 143  143  static int
 144  144  run_be_cmd(const char *cmdname, int argc, char **argv)
 145  145  {
 146  146          const be_command_t *command;
 147  147  
 148  148          for (command = &be_command_tbl[0]; command->name != NULL; command++)
 149  149                  if (strcmp(command->name, cmdname) == 0)
 150  150                          return (command->func(argc, argv));
↓ open down ↓ 506 lines elided ↑ open up ↑
 657  657          }
 658  658  
 659  659          return (0);
 660  660  }
 661  661  
 662  662  static int
 663  663  be_do_activate(int argc, char **argv)
 664  664  {
 665  665          nvlist_t        *be_attrs;
 666  666          int             err = 1;
      667 +        int             c;
 667  668          char            *obe_name;
 668  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 +
 669  681          argc -= optind;
 670  682          argv += optind;
 671  683  
 672  684          if (argc != 1) {
 673  685                  usage();
 674  686                  return (1);
 675  687          }
 676  688  
 677  689          obe_name = argv[0];
 678  690  
↓ open down ↓ 42 lines elided ↑ open up ↑
 721  733          int             err = 1;
 722  734          char            *obe_name = NULL;
 723  735          char            *snap_name = NULL;
 724  736          char            *nbe_zpool = NULL;
 725  737          char            *nbe_name = NULL;
 726  738          char            *nbe_desc = NULL;
 727  739          char            *propname = NULL;
 728  740          char            *propval = NULL;
 729  741          char            *strval = NULL;
 730  742  
 731      -        while ((c = getopt(argc, argv, "ad:e:io:p:")) != -1) {
      743 +        while ((c = getopt(argc, argv, "ad:e:io:p:v")) != -1) {
 732  744                  switch (c) {
 733  745                  case 'a':
 734  746                          activate = B_TRUE;
 735  747                          break;
 736  748                  case 'd':
 737  749                          nbe_desc = optarg;
 738  750                          break;
 739  751                  case 'e':
 740  752                          obe_name = optarg;
 741  753                          break;
↓ open down ↓ 17 lines elided ↑ open up ↑
 759  771  
 760  772                          }
 761  773                          if (be_nvl_add_string(zfs_props, propname, propval)
 762  774                              != 0)
 763  775                                  goto out2;
 764  776  
 765  777                          break;
 766  778                  case 'p':
 767  779                          nbe_zpool = optarg;
 768  780                          break;
      781 +                case 'v':
      782 +                        libbe_print_errors(B_TRUE);
      783 +                        break;
 769  784                  default:
 770  785                          usage();
 771  786                          goto out2;
 772  787                  }
 773  788          }
 774  789  
 775  790          argc -= optind;
 776  791          argv += optind;
 777  792  
 778  793          if (argc != 1) {
↓ open down ↓ 153 lines elided ↑ open up ↑
 932  947  {
 933  948          nvlist_t        *be_attrs;
 934  949          boolean_t       is_snap = B_FALSE;
 935  950          boolean_t       suppress_prompt = B_FALSE;
 936  951          int             err = 1;
 937  952          int             c;
 938  953          int             destroy_flags = 0;
 939  954          char            *snap_name;
 940  955          char            *be_name;
 941  956  
 942      -        while ((c = getopt(argc, argv, "fFs")) != -1) {
      957 +        while ((c = getopt(argc, argv, "fFsv")) != -1) {
 943  958                  switch (c) {
 944  959                  case 'f':
 945  960                          destroy_flags |= BE_DESTROY_FLAG_FORCE_UNMOUNT;
 946  961                          break;
 947  962                  case 's':
 948  963                          destroy_flags |= BE_DESTROY_FLAG_SNAPSHOTS;
 949  964                          break;
      965 +                case 'v':
      966 +                        libbe_print_errors(B_TRUE);
      967 +                        break;
 950  968                  case 'F':
 951  969                          suppress_prompt = B_TRUE;
 952  970                          break;
 953  971                  default:
 954  972                          usage();
 955  973                          return (1);
 956  974                  }
 957  975          }
 958  976  
 959  977          argc -= optind;
↓ open down ↓ 94 lines elided ↑ open up ↑
1054 1072  {
1055 1073          be_node_list_t  *be_nodes = NULL;
1056 1074          boolean_t       all = B_FALSE;
1057 1075          boolean_t       dsets = B_FALSE;
1058 1076          boolean_t       snaps = B_FALSE;
1059 1077          boolean_t       parsable = B_FALSE;
1060 1078          int             err = 1;
1061 1079          int             c = 0;
1062 1080          char            *be_name = NULL;
1063 1081  
1064      -        while ((c = getopt(argc, argv, "nadsH")) != -1) {
     1082 +        while ((c = getopt(argc, argv, "adsvH")) != -1) {
1065 1083                  switch (c) {
1066 1084                  case 'a':
1067 1085                          all = B_TRUE;
1068 1086                          break;
1069 1087                  case 'd':
1070 1088                          dsets = B_TRUE;
1071 1089                          break;
1072 1090                  case 's':
1073 1091                          snaps = B_TRUE;
1074 1092                          break;
     1093 +                case 'v':
     1094 +                        libbe_print_errors(B_TRUE);
     1095 +                        break;
1075 1096                  case 'H':
1076 1097                          parsable = B_TRUE;
1077 1098                          break;
1078 1099                  default:
1079 1100                          usage();
1080 1101                          return (1);
1081 1102                  }
1082 1103          }
1083 1104  
1084 1105          if (all) {
↓ open down ↓ 53 lines elided ↑ open up ↑
1138 1159  {
1139 1160          nvlist_t        *be_attrs;
1140 1161          boolean_t       shared_fs = B_FALSE;
1141 1162          int             err = 1;
1142 1163          int             c;
1143 1164          int             mount_flags = 0;
1144 1165          char            *obe_name;
1145 1166          char            *mountpoint;
1146 1167          char            *tmp_mp = NULL;
1147 1168  
1148      -        while ((c = getopt(argc, argv, "s:")) != -1) {
     1169 +        while ((c = getopt(argc, argv, "s:v")) != -1) {
1149 1170                  switch (c) {
1150 1171                  case 's':
1151 1172                          shared_fs = B_TRUE;
1152 1173  
1153 1174                          mount_flags |= BE_MOUNT_FLAG_SHARED_FS;
1154 1175  
1155 1176                          if (strcmp(optarg, "rw") == 0) {
1156 1177                                  mount_flags |= BE_MOUNT_FLAG_SHARED_RW;
1157 1178                          } else if (strcmp(optarg, "ro") != 0) {
1158 1179                                  (void) fprintf(stderr, _("The -s flag "
1159 1180                                      "requires an argument [ rw | ro ]\n"));
1160 1181                                  usage();
1161 1182                                  return (1);
1162 1183                          }
1163 1184  
1164 1185                          break;
     1186 +                case 'v':
     1187 +                        libbe_print_errors(B_TRUE);
     1188 +                        break;
1165 1189                  default:
1166 1190                          usage();
1167 1191                          return (1);
1168 1192                  }
1169 1193          }
1170 1194  
1171 1195          argc -= optind;
1172 1196          argv += optind;
1173 1197  
1174 1198          if (argc < 1 || argc > 2) {
↓ open down ↓ 41 lines elided ↑ open up ↑
1216 1240              mount_flags) != 0)
1217 1241                  goto out;
1218 1242  
1219 1243          err = be_mount(be_attrs);
1220 1244  
1221 1245          switch (err) {
1222 1246          case BE_SUCCESS:
1223 1247                  (void) printf(_("Mounted successfully on: '%s'\n"), mountpoint);
1224 1248                  break;
1225 1249          case BE_ERR_BE_NOENT:
1226      -                err = 1;
1227 1250                  (void) fprintf(stderr, _("%s does not exist or appear "
1228 1251                      "to be a valid BE.\nPlease check that the name of "
1229 1252                      "the BE provided is correct.\n"), obe_name);
1230 1253                  break;
1231 1254          case BE_ERR_MOUNTED:
1232 1255                  (void) fprintf(stderr, _("%s is already mounted.\n"
1233 1256                      "Please unmount the BE before mounting it again.\n"),
1234 1257                      obe_name);
1235 1258                  break;
1236 1259          case BE_ERR_PERM:
1237 1260          case BE_ERR_ACCESS:
1238      -                err = 1;
1239 1261                  (void) fprintf(stderr, _("Unable to mount %s.\n"), obe_name);
1240 1262                  (void) fprintf(stderr, _("You have insufficient privileges to "
1241 1263                      "execute this command.\n"));
1242 1264                  break;
1243 1265          default:
1244      -                err = 1;
1245 1266                  (void) fprintf(stderr, _("Unable to mount %s.\n"), obe_name);
1246 1267                  (void) fprintf(stderr, "%s\n", be_err_to_str(err));
1247 1268          }
1248 1269  
1249 1270  out:
1250 1271          if (tmp_mp != NULL)
1251 1272                  free(tmp_mp);
1252 1273          nvlist_free(be_attrs);
1253 1274          return (err);
1254 1275  }
1255 1276  
1256 1277  static int
1257 1278  be_do_unmount(int argc, char **argv)
1258 1279  {
1259 1280          nvlist_t        *be_attrs;
1260 1281          char            *obe_name;
1261 1282          int             err = 1;
1262 1283          int             c;
1263 1284          int             unmount_flags = 0;
1264 1285  
1265      -        while ((c = getopt(argc, argv, "f")) != -1) {
     1286 +        while ((c = getopt(argc, argv, "fv")) != -1) {
1266 1287                  switch (c) {
1267 1288                  case 'f':
1268 1289                          unmount_flags |= BE_UNMOUNT_FLAG_FORCE;
1269 1290                          break;
     1291 +                case 'v':
     1292 +                        libbe_print_errors(B_TRUE);
     1293 +                        break;
1270 1294                  default:
1271 1295                          usage();
1272 1296                          return (1);
1273 1297                  }
1274 1298          }
1275 1299  
1276 1300          argc -= optind;
1277 1301          argv += optind;
1278 1302  
1279 1303          if (argc != 1) {
↓ open down ↓ 50 lines elided ↑ open up ↑
1330 1354          return (err);
1331 1355  }
1332 1356  
1333 1357  static int
1334 1358  be_do_rename(int argc, char **argv)
1335 1359  {
1336 1360          nvlist_t        *be_attrs;
1337 1361          char            *obe_name;
1338 1362          char            *nbe_name;
1339 1363          int err = 1;
     1364 +        int c;
1340 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 +
1341 1377          argc -= optind;
1342 1378          argv += optind;
1343 1379  
1344 1380          if (argc != 2) {
1345 1381                  usage();
1346 1382                  return (1);
1347 1383          }
1348 1384  
1349 1385          obe_name = argv[0];
1350 1386          nbe_name = argv[1];
↓ open down ↓ 36 lines elided ↑ open up ↑
1387 1423          return (err);
1388 1424  }
1389 1425  
1390 1426  static int
1391 1427  be_do_rollback(int argc, char **argv)
1392 1428  {
1393 1429          nvlist_t        *be_attrs;
1394 1430          char            *obe_name;
1395 1431          char            *snap_name;
1396 1432          int             err = 1;
     1433 +        int             c;
1397 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 +
1398 1446          argc -= optind;
1399 1447          argv += optind;
1400 1448  
1401 1449          if (argc < 1 || argc > 2) {
1402 1450                  usage();
1403 1451                  return (1);
1404 1452          }
1405 1453  
1406 1454          obe_name = argv[0];
1407 1455          if (argc == 2)
↓ open down ↓ 58 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX