zfs_main.c (200516) | zfs_main.c (205199) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 176 unchanged lines hidden (view full) --- 185 return (gettext("\tcreate [-p] [-o property=value] ... " 186 "<filesystem>\n" 187 "\tcreate [-ps] [-b blocksize] [-o property=value] ... " 188 "-V <size> <volume>\n")); 189 case HELP_DESTROY: 190 return (gettext("\tdestroy [-rRf] " 191 "<filesystem|volume|snapshot>\n")); 192 case HELP_GET: | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 176 unchanged lines hidden (view full) --- 185 return (gettext("\tcreate [-p] [-o property=value] ... " 186 "<filesystem>\n" 187 "\tcreate [-ps] [-b blocksize] [-o property=value] ... " 188 "-V <size> <volume>\n")); 189 case HELP_DESTROY: 190 return (gettext("\tdestroy [-rRf] " 191 "<filesystem|volume|snapshot>\n")); 192 case HELP_GET: |
193 return (gettext("\tget [-rHp] [-o field[,...]] " 194 "[-s source[,...]]\n" | 193 return (gettext("\tget [-rHp] [-d max] " 194 "[-o field[,...]] [-s source[,...]]\n" |
195 "\t <\"all\" | property[,...]> " 196 "[filesystem|volume|snapshot] ...\n")); 197 case HELP_INHERIT: 198 return (gettext("\tinherit [-r] <property> " 199 "<filesystem|volume|snapshot> ...\n")); 200 case HELP_UPGRADE: 201 return (gettext("\tupgrade [-v]\n" 202 "\tupgrade [-r] [-V version] <-a | filesystem ...>\n")); 203 case HELP_JAIL: 204 return (gettext("\tjail <jailid> <filesystem>\n")); 205 case HELP_UNJAIL: 206 return (gettext("\tunjail <jailid> <filesystem>\n")); 207 case HELP_LIST: | 195 "\t <\"all\" | property[,...]> " 196 "[filesystem|volume|snapshot] ...\n")); 197 case HELP_INHERIT: 198 return (gettext("\tinherit [-r] <property> " 199 "<filesystem|volume|snapshot> ...\n")); 200 case HELP_UPGRADE: 201 return (gettext("\tupgrade [-v]\n" 202 "\tupgrade [-r] [-V version] <-a | filesystem ...>\n")); 203 case HELP_JAIL: 204 return (gettext("\tjail <jailid> <filesystem>\n")); 205 case HELP_UNJAIL: 206 return (gettext("\tunjail <jailid> <filesystem>\n")); 207 case HELP_LIST: |
208 return (gettext("\tlist [-rH] [-o property[,...]] " 209 "[-t type[,...]] [-s property] ...\n" | 208 return (gettext("\tlist [-rH][-d max] " 209 "[-o property[,...]] [-t type[,...]] [-s property] ...\n" |
210 "\t [-S property] ... " 211 "[filesystem|volume|snapshot] ...\n")); 212 case HELP_MOUNT: 213 return (gettext("\tmount\n" 214 "\tmount [-vO] [-o opts] <-a | filesystem>\n")); 215 case HELP_PROMOTE: 216 return (gettext("\tpromote <clone-filesystem>\n")); 217 case HELP_RECEIVE: --- 209 unchanged lines hidden (view full) --- 427 (void) fprintf(stderr, gettext("internal " 428 "error: out of memory\n")); 429 return (-1); 430 } 431 return (0); 432 433} 434 | 210 "\t [-S property] ... " 211 "[filesystem|volume|snapshot] ...\n")); 212 case HELP_MOUNT: 213 return (gettext("\tmount\n" 214 "\tmount [-vO] [-o opts] <-a | filesystem>\n")); 215 case HELP_PROMOTE: 216 return (gettext("\tpromote <clone-filesystem>\n")); 217 case HELP_RECEIVE: --- 209 unchanged lines hidden (view full) --- 427 (void) fprintf(stderr, gettext("internal " 428 "error: out of memory\n")); 429 return (-1); 430 } 431 return (0); 432 433} 434 |
435static int 436parse_depth(char *opt, int *flags) 437{ 438 char *tmp; 439 int depth; 440 441 depth = (int)strtol(opt, &tmp, 0); 442 if (*tmp) { 443 (void) fprintf(stderr, 444 gettext("%s is not an integer\n"), optarg); 445 usage(B_FALSE); 446 } 447 if (depth < 0) { 448 (void) fprintf(stderr, 449 gettext("Depth can not be negative.\n")); 450 usage(B_FALSE); 451 } 452 *flags |= (ZFS_ITER_DEPTH_LIMIT|ZFS_ITER_RECURSE); 453 return (depth); 454} 455 |
|
435/* 436 * zfs clone [-p] [-o prop=value] ... <snap> <fs | vol> 437 * 438 * Given an existing dataset, create a writable copy whose initial contents 439 * are the same as the source. The newly created dataset maintains a 440 * dependency on the original; the original cannot be destroyed so long as 441 * the clone exists. 442 * --- 671 unchanged lines hidden (view full) --- 1114 1115static int 1116zfs_do_get(int argc, char **argv) 1117{ 1118 zprop_get_cbdata_t cb = { 0 }; 1119 int i, c, flags = 0; 1120 char *value, *fields; 1121 int ret; | 456/* 457 * zfs clone [-p] [-o prop=value] ... <snap> <fs | vol> 458 * 459 * Given an existing dataset, create a writable copy whose initial contents 460 * are the same as the source. The newly created dataset maintains a 461 * dependency on the original; the original cannot be destroyed so long as 462 * the clone exists. 463 * --- 671 unchanged lines hidden (view full) --- 1135 1136static int 1137zfs_do_get(int argc, char **argv) 1138{ 1139 zprop_get_cbdata_t cb = { 0 }; 1140 int i, c, flags = 0; 1141 char *value, *fields; 1142 int ret; |
1143 int limit = 0; |
|
1122 zprop_list_t fake_name = { 0 }; 1123 1124 /* 1125 * Set up default columns and sources. 1126 */ 1127 cb.cb_sources = ZPROP_SRC_ALL; 1128 cb.cb_columns[0] = GET_COL_NAME; 1129 cb.cb_columns[1] = GET_COL_PROPERTY; 1130 cb.cb_columns[2] = GET_COL_VALUE; 1131 cb.cb_columns[3] = GET_COL_SOURCE; 1132 cb.cb_type = ZFS_TYPE_DATASET; 1133 1134 /* check options */ | 1144 zprop_list_t fake_name = { 0 }; 1145 1146 /* 1147 * Set up default columns and sources. 1148 */ 1149 cb.cb_sources = ZPROP_SRC_ALL; 1150 cb.cb_columns[0] = GET_COL_NAME; 1151 cb.cb_columns[1] = GET_COL_PROPERTY; 1152 cb.cb_columns[2] = GET_COL_VALUE; 1153 cb.cb_columns[3] = GET_COL_SOURCE; 1154 cb.cb_type = ZFS_TYPE_DATASET; 1155 1156 /* check options */ |
1135 while ((c = getopt(argc, argv, ":o:s:rHp")) != -1) { | 1157 while ((c = getopt(argc, argv, ":d:o:s:rHp")) != -1) { |
1136 switch (c) { 1137 case 'p': 1138 cb.cb_literal = B_TRUE; 1139 break; | 1158 switch (c) { 1159 case 'p': 1160 cb.cb_literal = B_TRUE; 1161 break; |
1162 case 'd': 1163 limit = parse_depth(optarg, &flags); 1164 break; |
|
1140 case 'r': 1141 flags |= ZFS_ITER_RECURSE; 1142 break; 1143 case 'H': 1144 cb.cb_scripted = B_TRUE; 1145 break; 1146 case ':': 1147 (void) fprintf(stderr, gettext("missing argument for " --- 114 unchanged lines hidden (view full) --- 1262 fake_name.pl_next = cb.cb_proplist; 1263 cb.cb_proplist = &fake_name; 1264 } 1265 1266 cb.cb_first = B_TRUE; 1267 1268 /* run for each object */ 1269 ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_DATASET, NULL, | 1165 case 'r': 1166 flags |= ZFS_ITER_RECURSE; 1167 break; 1168 case 'H': 1169 cb.cb_scripted = B_TRUE; 1170 break; 1171 case ':': 1172 (void) fprintf(stderr, gettext("missing argument for " --- 114 unchanged lines hidden (view full) --- 1287 fake_name.pl_next = cb.cb_proplist; 1288 cb.cb_proplist = &fake_name; 1289 } 1290 1291 cb.cb_first = B_TRUE; 1292 1293 /* run for each object */ 1294 ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_DATASET, NULL, |
1270 &cb.cb_proplist, get_callback, &cb); | 1295 &cb.cb_proplist, limit, get_callback, &cb); |
1271 1272 if (cb.cb_proplist == &fake_name) 1273 zprop_free_list(fake_name.pl_next); 1274 else 1275 zprop_free_list(cb.cb_proplist); 1276 1277 return (ret); 1278} --- 96 unchanged lines hidden (view full) --- 1375 } else if (!zfs_prop_user(propname)) { 1376 (void) fprintf(stderr, gettext("invalid property '%s'\n"), 1377 propname); 1378 usage(B_FALSE); 1379 } 1380 1381 if (flags & ZFS_ITER_RECURSE) { 1382 ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_DATASET, | 1296 1297 if (cb.cb_proplist == &fake_name) 1298 zprop_free_list(fake_name.pl_next); 1299 else 1300 zprop_free_list(cb.cb_proplist); 1301 1302 return (ret); 1303} --- 96 unchanged lines hidden (view full) --- 1400 } else if (!zfs_prop_user(propname)) { 1401 (void) fprintf(stderr, gettext("invalid property '%s'\n"), 1402 propname); 1403 usage(B_FALSE); 1404 } 1405 1406 if (flags & ZFS_ITER_RECURSE) { 1407 ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_DATASET, |
1383 NULL, NULL, inherit_recurse_cb, propname); | 1408 NULL, NULL, 0, inherit_recurse_cb, propname); |
1384 } else { 1385 ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_DATASET, | 1409 } else { 1410 ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_DATASET, |
1386 NULL, NULL, inherit_cb, propname); | 1411 NULL, NULL, 0, inherit_cb, propname); |
1387 } 1388 1389 return (ret); 1390} 1391 1392typedef struct upgrade_cbdata { 1393 uint64_t cb_numupgraded; 1394 uint64_t cb_numsamegraded; --- 178 unchanged lines hidden (view full) --- 1573 "version/zpl/N\n\n"); 1574 (void) printf(gettext("Where 'N' is the version number.\n")); 1575 ret = 0; 1576 } else if (argc || all) { 1577 /* Upgrade filesystems */ 1578 if (cb.cb_version == 0) 1579 cb.cb_version = ZPL_VERSION; 1580 ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_FILESYSTEM, | 1412 } 1413 1414 return (ret); 1415} 1416 1417typedef struct upgrade_cbdata { 1418 uint64_t cb_numupgraded; 1419 uint64_t cb_numsamegraded; --- 178 unchanged lines hidden (view full) --- 1598 "version/zpl/N\n\n"); 1599 (void) printf(gettext("Where 'N' is the version number.\n")); 1600 ret = 0; 1601 } else if (argc || all) { 1602 /* Upgrade filesystems */ 1603 if (cb.cb_version == 0) 1604 cb.cb_version = ZPL_VERSION; 1605 ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_FILESYSTEM, |
1581 NULL, NULL, upgrade_set_callback, &cb); | 1606 NULL, NULL, 0, upgrade_set_callback, &cb); |
1582 (void) printf(gettext("%llu filesystems upgraded\n"), 1583 cb.cb_numupgraded); 1584 if (cb.cb_numsamegraded) { 1585 (void) printf(gettext("%llu filesystems already at " 1586 "this version\n"), 1587 cb.cb_numsamegraded); 1588 } 1589 if (cb.cb_numfailed != 0) 1590 ret = 1; 1591 } else { 1592 /* List old-version filesytems */ 1593 boolean_t found; 1594 (void) printf(gettext("This system is currently running " 1595 "ZFS filesystem version %llu.\n\n"), ZPL_VERSION); 1596 1597 flags |= ZFS_ITER_RECURSE; 1598 ret = zfs_for_each(0, NULL, flags, ZFS_TYPE_FILESYSTEM, | 1607 (void) printf(gettext("%llu filesystems upgraded\n"), 1608 cb.cb_numupgraded); 1609 if (cb.cb_numsamegraded) { 1610 (void) printf(gettext("%llu filesystems already at " 1611 "this version\n"), 1612 cb.cb_numsamegraded); 1613 } 1614 if (cb.cb_numfailed != 0) 1615 ret = 1; 1616 } else { 1617 /* List old-version filesytems */ 1618 boolean_t found; 1619 (void) printf(gettext("This system is currently running " 1620 "ZFS filesystem version %llu.\n\n"), ZPL_VERSION); 1621 1622 flags |= ZFS_ITER_RECURSE; 1623 ret = zfs_for_each(0, NULL, flags, ZFS_TYPE_FILESYSTEM, |
1599 NULL, NULL, upgrade_list_callback, &cb); | 1624 NULL, NULL, 0, upgrade_list_callback, &cb); |
1600 1601 found = cb.cb_foundone; 1602 cb.cb_foundone = B_FALSE; 1603 cb.cb_newer = B_TRUE; 1604 1605 ret = zfs_for_each(0, NULL, flags, ZFS_TYPE_FILESYSTEM, | 1625 1626 found = cb.cb_foundone; 1627 cb.cb_foundone = B_FALSE; 1628 cb.cb_newer = B_TRUE; 1629 1630 ret = zfs_for_each(0, NULL, flags, ZFS_TYPE_FILESYSTEM, |
1606 NULL, NULL, upgrade_list_callback, &cb); | 1631 NULL, NULL, 0, upgrade_list_callback, &cb); |
1607 1608 if (!cb.cb_foundone && !found) { 1609 (void) printf(gettext("All filesystems are " 1610 "formatted with the current version.\n")); 1611 } 1612 } 1613 1614 return (ret); 1615} 1616 1617/* | 1632 1633 if (!cb.cb_foundone && !found) { 1634 (void) printf(gettext("All filesystems are " 1635 "formatted with the current version.\n")); 1636 } 1637 } 1638 1639 return (ret); 1640} 1641 1642/* |
1618 * list [-rH] [-o property[,property]...] [-t type[,type]...] | 1643 * list [-r][-d max] [-H] [-o property[,property]...] [-t type[,type]...] |
1619 * [-s property [-s property]...] [-S property [-S property]...] 1620 * <dataset> ... 1621 * 1622 * -r Recurse over all children | 1644 * [-s property [-s property]...] [-S property [-S property]...] 1645 * <dataset> ... 1646 * 1647 * -r Recurse over all children |
1648 * -d Limit recursion by depth. |
|
1623 * -H Scripted mode; elide headers and separate columns by tabs 1624 * -o Control which fields to display. 1625 * -t Control which object types to display. 1626 * -s Specify sort columns, descending order. 1627 * -S Specify sort columns, ascending order. 1628 * 1629 * When given no arguments, lists all filesystems in the system. 1630 * Otherwise, list the specified datasets, optionally recursing down them if --- 133 unchanged lines hidden (view full) --- 1764 boolean_t scripted = B_FALSE; 1765 static char default_fields[] = 1766 "name,used,available,referenced,mountpoint"; 1767 int types = ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME; 1768 boolean_t types_specified = B_FALSE; 1769 char *fields = NULL; 1770 list_cbdata_t cb = { 0 }; 1771 char *value; | 1649 * -H Scripted mode; elide headers and separate columns by tabs 1650 * -o Control which fields to display. 1651 * -t Control which object types to display. 1652 * -s Specify sort columns, descending order. 1653 * -S Specify sort columns, ascending order. 1654 * 1655 * When given no arguments, lists all filesystems in the system. 1656 * Otherwise, list the specified datasets, optionally recursing down them if --- 133 unchanged lines hidden (view full) --- 1790 boolean_t scripted = B_FALSE; 1791 static char default_fields[] = 1792 "name,used,available,referenced,mountpoint"; 1793 int types = ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME; 1794 boolean_t types_specified = B_FALSE; 1795 char *fields = NULL; 1796 list_cbdata_t cb = { 0 }; 1797 char *value; |
1798 int limit = 0; |
|
1772 int ret; 1773 zfs_sort_column_t *sortcol = NULL; 1774 int flags = ZFS_ITER_PROP_LISTSNAPS | ZFS_ITER_ARGS_CAN_BE_PATHS; 1775 1776 /* check options */ | 1799 int ret; 1800 zfs_sort_column_t *sortcol = NULL; 1801 int flags = ZFS_ITER_PROP_LISTSNAPS | ZFS_ITER_ARGS_CAN_BE_PATHS; 1802 1803 /* check options */ |
1777 while ((c = getopt(argc, argv, ":o:rt:Hs:S:")) != -1) { | 1804 while ((c = getopt(argc, argv, ":d:o:rt:Hs:S:")) != -1) { |
1778 switch (c) { 1779 case 'o': 1780 fields = optarg; 1781 break; | 1805 switch (c) { 1806 case 'o': 1807 fields = optarg; 1808 break; |
1809 case 'd': 1810 limit = parse_depth(optarg, &flags); 1811 break; |
|
1782 case 'r': 1783 flags |= ZFS_ITER_RECURSE; 1784 break; 1785 case 'H': 1786 scripted = B_TRUE; 1787 break; 1788 case 's': 1789 if (zfs_add_sort_column(&sortcol, optarg, --- 74 unchanged lines hidden (view full) --- 1864 if (zprop_get_list(g_zfs, fields, &cb.cb_proplist, ZFS_TYPE_DATASET) 1865 != 0) 1866 usage(B_FALSE); 1867 1868 cb.cb_scripted = scripted; 1869 cb.cb_first = B_TRUE; 1870 1871 ret = zfs_for_each(argc, argv, flags, types, sortcol, &cb.cb_proplist, | 1812 case 'r': 1813 flags |= ZFS_ITER_RECURSE; 1814 break; 1815 case 'H': 1816 scripted = B_TRUE; 1817 break; 1818 case 's': 1819 if (zfs_add_sort_column(&sortcol, optarg, --- 74 unchanged lines hidden (view full) --- 1894 if (zprop_get_list(g_zfs, fields, &cb.cb_proplist, ZFS_TYPE_DATASET) 1895 != 0) 1896 usage(B_FALSE); 1897 1898 cb.cb_scripted = scripted; 1899 cb.cb_first = B_TRUE; 1900 1901 ret = zfs_for_each(argc, argv, flags, types, sortcol, &cb.cb_proplist, |
1872 list_callback, &cb); | 1902 limit, list_callback, &cb); |
1873 1874 zprop_free_list(cb.cb_proplist); 1875 zfs_free_sort_columns(sortcol); 1876 1877 if (ret == 0 && cb.cb_first && !cb.cb_scripted) 1878 (void) printf(gettext("no datasets available\n")); 1879 1880 return (ret); --- 366 unchanged lines hidden (view full) --- 2247 2248 if (*cb.cb_propname == '\0') { 2249 (void) fprintf(stderr, 2250 gettext("missing property in property=value argument\n")); 2251 usage(B_FALSE); 2252 } 2253 2254 ret = zfs_for_each(argc - 2, argv + 2, NULL, | 1903 1904 zprop_free_list(cb.cb_proplist); 1905 zfs_free_sort_columns(sortcol); 1906 1907 if (ret == 0 && cb.cb_first && !cb.cb_scripted) 1908 (void) printf(gettext("no datasets available\n")); 1909 1910 return (ret); --- 366 unchanged lines hidden (view full) --- 2277 2278 if (*cb.cb_propname == '\0') { 2279 (void) fprintf(stderr, 2280 gettext("missing property in property=value argument\n")); 2281 usage(B_FALSE); 2282 } 2283 2284 ret = zfs_for_each(argc - 2, argv + 2, NULL, |
2255 ZFS_TYPE_DATASET, NULL, NULL, set_callback, &cb); | 2285 ZFS_TYPE_DATASET, NULL, NULL, 0, set_callback, &cb); |
2256 2257 return (ret); 2258} 2259 2260/* 2261 * zfs snapshot [-r] [-o prop=value] ... <fs@snap> 2262 * 2263 * Creates a snapshot with the given name. While functionally equivalent to --- 617 unchanged lines hidden (view full) --- 2881 if (parse_allow_args(&argc, &argv, B_TRUE, 2882 &ds, &recurse, &zperms) == -1) 2883 return (1); 2884 2885 if (recurse) 2886 flags |= ZFS_ITER_RECURSE; 2887 error = zfs_for_each(argc, argv, flags, 2888 ZFS_TYPE_FILESYSTEM|ZFS_TYPE_VOLUME, NULL, | 2286 2287 return (ret); 2288} 2289 2290/* 2291 * zfs snapshot [-r] [-o prop=value] ... <fs@snap> 2292 * 2293 * Creates a snapshot with the given name. While functionally equivalent to --- 617 unchanged lines hidden (view full) --- 2911 if (parse_allow_args(&argc, &argv, B_TRUE, 2912 &ds, &recurse, &zperms) == -1) 2913 return (1); 2914 2915 if (recurse) 2916 flags |= ZFS_ITER_RECURSE; 2917 error = zfs_for_each(argc, argv, flags, 2918 ZFS_TYPE_FILESYSTEM|ZFS_TYPE_VOLUME, NULL, |
2889 NULL, unallow_callback, (void *)zperms); | 2919 NULL, 0, unallow_callback, (void *)zperms); |
2890 2891 if (zperms) 2892 nvlist_free(zperms); 2893 2894 return (error); 2895} 2896 2897typedef struct get_all_cbdata { --- 1416 unchanged lines hidden --- | 2920 2921 if (zperms) 2922 nvlist_free(zperms); 2923 2924 return (error); 2925} 2926 2927typedef struct get_all_cbdata { --- 1416 unchanged lines hidden --- |