Changeset View
Changeset View
Standalone View
Standalone View
cddl/contrib/opensolaris/cmd/zfs/zfs_main.c
Show First 20 Lines • Show All 1,323 Lines • ▼ Show 20 Lines | if (nvlist_empty(cb.cb_nvl)) { | ||||
rv = 1; | rv = 1; | ||||
goto out; | goto out; | ||||
} | } | ||||
if (cb.cb_verbose) { | if (cb.cb_verbose) { | ||||
char buf[16]; | char buf[16]; | ||||
zfs_nicenum(cb.cb_snapused, buf, sizeof (buf)); | zfs_nicenum(cb.cb_snapused, buf, sizeof (buf)); | ||||
if (cb.cb_parsable) { | if (cb.cb_parsable) { | ||||
(void) printf("reclaim\t%llu\n", | (void) printf("reclaim\t%"PRId64"\n", | ||||
cb.cb_snapused); | cb.cb_snapused); | ||||
} else if (cb.cb_dryrun) { | } else if (cb.cb_dryrun) { | ||||
(void) printf(gettext("would reclaim %s\n"), | (void) printf(gettext("would reclaim %s\n"), | ||||
buf); | buf); | ||||
} else { | } else { | ||||
(void) printf(gettext("will reclaim %s\n"), | (void) printf(gettext("will reclaim %s\n"), | ||||
buf); | buf); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 726 Lines • ▼ Show 20 Lines | if (spa_version < needed_spa_version) { | ||||
cb->cb_numfailed++; | cb->cb_numfailed++; | ||||
return (0); | return (0); | ||||
} | } | ||||
/* upgrade */ | /* upgrade */ | ||||
if (version < cb->cb_version) { | if (version < cb->cb_version) { | ||||
char verstr[16]; | char verstr[16]; | ||||
(void) snprintf(verstr, sizeof (verstr), | (void) snprintf(verstr, sizeof (verstr), | ||||
"%llu", cb->cb_version); | "%"PRIu64, cb->cb_version); | ||||
if (cb->cb_lastfs[0] && !same_pool(zhp, cb->cb_lastfs)) { | if (cb->cb_lastfs[0] && !same_pool(zhp, cb->cb_lastfs)) { | ||||
/* | /* | ||||
* If they did "zfs upgrade -a", then we could | * If they did "zfs upgrade -a", then we could | ||||
* be doing ioctls to different pools. We need | * be doing ioctls to different pools. We need | ||||
* to log this history once to each pool, and bypass | * to log this history once to each pool, and bypass | ||||
* the normal history logging that happens in main(). | * the normal history logging that happens in main(). | ||||
*/ | */ | ||||
(void) zpool_log_history(g_zfs, history_str); | (void) zpool_log_history(g_zfs, history_str); | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | if (showversions) { | ||||
(void) printf("see the ZFS Administration Guide.\n\n"); | (void) printf("see the ZFS Administration Guide.\n\n"); | ||||
ret = 0; | ret = 0; | ||||
} else if (argc || all) { | } else if (argc || all) { | ||||
/* Upgrade filesystems */ | /* Upgrade filesystems */ | ||||
if (cb.cb_version == 0) | if (cb.cb_version == 0) | ||||
cb.cb_version = ZPL_VERSION; | cb.cb_version = ZPL_VERSION; | ||||
ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_FILESYSTEM, | ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_FILESYSTEM, | ||||
NULL, NULL, 0, upgrade_set_callback, &cb); | NULL, NULL, 0, upgrade_set_callback, &cb); | ||||
(void) printf(gettext("%llu filesystems upgraded\n"), | (void) printf(gettext("%"PRIu64" filesystems upgraded\n"), | ||||
cb.cb_numupgraded); | cb.cb_numupgraded); | ||||
if (cb.cb_numsamegraded) { | if (cb.cb_numsamegraded) { | ||||
(void) printf(gettext("%llu filesystems already at " | (void) printf(gettext("%"PRIu64" filesystems already at " | ||||
"this version\n"), | "this version\n"), | ||||
cb.cb_numsamegraded); | cb.cb_numsamegraded); | ||||
} | } | ||||
if (cb.cb_numfailed != 0) | if (cb.cb_numfailed != 0) | ||||
ret = 1; | ret = 1; | ||||
} else { | } else { | ||||
/* List old-version filesytems */ | /* List old-version filesytems */ | ||||
boolean_t found; | boolean_t found; | ||||
▲ Show 20 Lines • Show All 348 Lines • ▼ Show 20 Lines | if ((n = uu_avl_find(avl, node, &sortinfo, &idx)) == NULL) { | ||||
node = n; | node = n; | ||||
props = node->usn_nvl; | props = node->usn_nvl; | ||||
} | } | ||||
/* Calculate/update width of USED/QUOTA fields */ | /* Calculate/update width of USED/QUOTA fields */ | ||||
if (cb->cb_nicenum) | if (cb->cb_nicenum) | ||||
zfs_nicenum(space, sizebuf, sizeof (sizebuf)); | zfs_nicenum(space, sizebuf, sizeof (sizebuf)); | ||||
else | else | ||||
(void) snprintf(sizebuf, sizeof (sizebuf), "%llu", space); | (void) snprintf(sizebuf, sizeof (sizebuf), "%"PRIu64, space); | ||||
sizelen = strlen(sizebuf); | sizelen = strlen(sizebuf); | ||||
if (prop == ZFS_PROP_USERUSED || prop == ZFS_PROP_GROUPUSED) { | if (prop == ZFS_PROP_USERUSED || prop == ZFS_PROP_GROUPUSED) { | ||||
propname = "used"; | propname = "used"; | ||||
if (!nvlist_exists(props, "quota")) | if (!nvlist_exists(props, "quota")) | ||||
(void) nvlist_add_uint64(props, "quota", 0); | (void) nvlist_add_uint64(props, "quota", 0); | ||||
} else { | } else { | ||||
propname = "quota"; | propname = "quota"; | ||||
if (!nvlist_exists(props, "used")) | if (!nvlist_exists(props, "used")) | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | while ((field = fields[cfield]) != USFIELD_LAST) { | ||||
} | } | ||||
switch (field) { | switch (field) { | ||||
case USFIELD_TYPE: | case USFIELD_TYPE: | ||||
strval = (char *)us_type2str(val32); | strval = (char *)us_type2str(val32); | ||||
break; | break; | ||||
case USFIELD_NAME: | case USFIELD_NAME: | ||||
if (type == DATA_TYPE_UINT64) { | if (type == DATA_TYPE_UINT64) { | ||||
(void) sprintf(valstr, "%llu", val64); | (void) sprintf(valstr, "%"PRIu64, val64); | ||||
strval = valstr; | strval = valstr; | ||||
} | } | ||||
break; | break; | ||||
case USFIELD_USED: | case USFIELD_USED: | ||||
case USFIELD_QUOTA: | case USFIELD_QUOTA: | ||||
if (type == DATA_TYPE_UINT64) { | if (type == DATA_TYPE_UINT64) { | ||||
if (parsable) { | if (parsable) { | ||||
(void) sprintf(valstr, "%llu", val64); | (void) sprintf(valstr, "%"PRIu64, val64); | ||||
} else { | } else { | ||||
zfs_nicenum(val64, valstr, | zfs_nicenum(val64, valstr, | ||||
sizeof (valstr)); | sizeof (valstr)); | ||||
} | } | ||||
if (field == USFIELD_QUOTA && | if (field == USFIELD_QUOTA && | ||||
strcmp(valstr, "0") == 0) | strcmp(valstr, "0") == 0) | ||||
strval = "none"; | strval = "none"; | ||||
else | else | ||||
strval = valstr; | strval = valstr; | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
if (!first) { | if (!first) { | ||||
if (scripted) | if (scripted) | ||||
(void) printf("\t"); | (void) printf("\t"); | ||||
else | else | ||||
(void) printf(" "); | (void) printf(" "); | ||||
} | } | ||||
if (scripted) | if (scripted) | ||||
(void) printf("%s", strval); | (void) printf("%s", strval); | ||||
else if (field == USFIELD_TYPE || field == USFIELD_NAME) | else if (field == USFIELD_TYPE || field == USFIELD_NAME) | ||||
(void) printf("%-*s", width[field], strval); | (void) printf("%-*s", (int)width[field], strval); | ||||
else | else | ||||
(void) printf("%*s", width[field], strval); | (void) printf("%*s", (int)width[field], strval); | ||||
first = B_FALSE; | first = B_FALSE; | ||||
cfield++; | cfield++; | ||||
} | } | ||||
(void) printf("\n"); | (void) printf("\n"); | ||||
} | } | ||||
static void | static void | ||||
print_us(boolean_t scripted, boolean_t parsable, int *fields, int types, | print_us(boolean_t scripted, boolean_t parsable, int *fields, int types, | ||||
size_t *width, boolean_t rmnode, uu_avl_t *avl) | size_t *width, boolean_t rmnode, uu_avl_t *avl) | ||||
{ | { | ||||
us_node_t *node; | us_node_t *node; | ||||
const char *col; | const char *col; | ||||
int cfield = 0; | int cfield = 0; | ||||
int field; | int field; | ||||
if (!scripted) { | if (!scripted) { | ||||
boolean_t first = B_TRUE; | boolean_t first = B_TRUE; | ||||
while ((field = fields[cfield]) != USFIELD_LAST) { | while ((field = fields[cfield]) != USFIELD_LAST) { | ||||
col = gettext(us_field_hdr[field]); | col = gettext(us_field_hdr[field]); | ||||
if (field == USFIELD_TYPE || field == USFIELD_NAME) { | if (field == USFIELD_TYPE || field == USFIELD_NAME) { | ||||
(void) printf(first ? "%-*s" : " %-*s", | (void) printf(first ? "%-*s" : " %-*s", | ||||
width[field], col); | (int)width[field], col); | ||||
} else { | } else { | ||||
(void) printf(first ? "%*s" : " %*s", | (void) printf(first ? "%*s" : " %*s", | ||||
width[field], col); | (int)width[field], col); | ||||
} | } | ||||
first = B_FALSE; | first = B_FALSE; | ||||
cfield++; | cfield++; | ||||
} | } | ||||
(void) printf("\n"); | (void) printf("\n"); | ||||
} | } | ||||
for (node = uu_avl_first(avl); node; node = uu_avl_next(avl, node)) { | for (node = uu_avl_first(avl); node; node = uu_avl_next(avl, node)) { | ||||
▲ Show 20 Lines • Show All 277 Lines • ▼ Show 20 Lines | if (pl->pl_prop != ZPROP_INVAL) { | ||||
headerbuf[i] = toupper(pl->pl_user_prop[i]); | headerbuf[i] = toupper(pl->pl_user_prop[i]); | ||||
headerbuf[i] = '\0'; | headerbuf[i] = '\0'; | ||||
header = headerbuf; | header = headerbuf; | ||||
} | } | ||||
if (pl->pl_next == NULL && !right_justify) | if (pl->pl_next == NULL && !right_justify) | ||||
(void) printf("%s", header); | (void) printf("%s", header); | ||||
else if (right_justify) | else if (right_justify) | ||||
(void) printf("%*s", pl->pl_width, header); | (void) printf("%*s", (int)pl->pl_width, header); | ||||
else | else | ||||
(void) printf("%-*s", pl->pl_width, header); | (void) printf("%-*s", (int)pl->pl_width, header); | ||||
} | } | ||||
(void) printf("\n"); | (void) printf("\n"); | ||||
} | } | ||||
/* | /* | ||||
* Given a dataset and a list of fields, print out all the properties according | * Given a dataset and a list of fields, print out all the properties according | ||||
* to the described layout. | * to the described layout. | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | for (; pl != NULL; pl = pl->pl_next) { | ||||
/* | /* | ||||
* If this is being called in scripted mode, or if this is the | * If this is being called in scripted mode, or if this is the | ||||
* last column and it is left-justified, don't include a width | * last column and it is left-justified, don't include a width | ||||
* format specifier. | * format specifier. | ||||
*/ | */ | ||||
if (cb->cb_scripted || (pl->pl_next == NULL && !right_justify)) | if (cb->cb_scripted || (pl->pl_next == NULL && !right_justify)) | ||||
(void) printf("%s", propstr); | (void) printf("%s", propstr); | ||||
else if (right_justify) | else if (right_justify) | ||||
(void) printf("%*s", pl->pl_width, propstr); | (void) printf("%*s", (int)pl->pl_width, propstr); | ||||
else | else | ||||
(void) printf("%-*s", pl->pl_width, propstr); | (void) printf("%-*s", (int)pl->pl_width, propstr); | ||||
} | } | ||||
(void) printf("\n"); | (void) printf("\n"); | ||||
} | } | ||||
/* | /* | ||||
* Generic callback function to list a dataset or snapshot. | * Generic callback function to list a dataset or snapshot. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 545 Lines • ▼ Show 20 Lines | zfs_do_set(int argc, char **argv) | ||||
} | } | ||||
/* validate argument order: prop=val args followed by dataset args */ | /* validate argument order: prop=val args followed by dataset args */ | ||||
for (int i = 1; i < argc; i++) { | for (int i = 1; i < argc; i++) { | ||||
if (strchr(argv[i], '=') != NULL) { | if (strchr(argv[i], '=') != NULL) { | ||||
if (ds_start > 0) { | if (ds_start > 0) { | ||||
/* out-of-order prop=val argument */ | /* out-of-order prop=val argument */ | ||||
(void) fprintf(stderr, gettext("invalid " | (void) fprintf(stderr, gettext("invalid " | ||||
"argument order\n"), i); | "argument order\n")); | ||||
usage(B_FALSE); | usage(B_FALSE); | ||||
} | } | ||||
} else if (ds_start < 0) { | } else if (ds_start < 0) { | ||||
ds_start = i; | ds_start = i; | ||||
} | } | ||||
} | } | ||||
if (ds_start < 0) { | if (ds_start < 0) { | ||||
(void) fprintf(stderr, gettext("missing dataset name(s)\n")); | (void) fprintf(stderr, gettext("missing dataset name(s)\n")); | ||||
▲ Show 20 Lines • Show All 1,570 Lines • ▼ Show 20 Lines | for (who_node = uu_avl_first(who_avl); who_node != NULL; | ||||
uu_avl_t *avl = who_node->who_perm.who_deleg_perm_avl; | uu_avl_t *avl = who_node->who_perm.who_deleg_perm_avl; | ||||
zfs_deleg_who_type_t who_type = who_node->who_perm.who_type; | zfs_deleg_who_type_t who_type = who_node->who_perm.who_type; | ||||
const char *who_name = who_node->who_perm.who_name; | const char *who_name = who_node->who_perm.who_name; | ||||
int weight = who_type2weight(who_type); | int weight = who_type2weight(who_type); | ||||
boolean_t first = B_TRUE; | boolean_t first = B_TRUE; | ||||
deleg_perm_node_t *deleg_node; | deleg_perm_node_t *deleg_node; | ||||
if (prev_weight != weight) { | if (prev_weight != weight) { | ||||
(void) printf(*title_ptr++); | (void) printf("%s", *title_ptr++); | ||||
prev_weight = weight; | prev_weight = weight; | ||||
} | } | ||||
if (who_name == NULL || strnlen(who_name, 1) == 0) | if (who_name == NULL || strnlen(who_name, 1) == 0) | ||||
(void) printf("\t"); | (void) printf("\t"); | ||||
else | else | ||||
(void) printf("\t%s ", who_name); | (void) printf("\t%s ", who_name); | ||||
Show All 38 Lines | for (deleg_node = uu_avl_first(avl); | ||||
if (local != deleg_node->dpn_perm.dp_local || | if (local != deleg_node->dpn_perm.dp_local || | ||||
descend != deleg_node->dpn_perm.dp_descend) | descend != deleg_node->dpn_perm.dp_descend) | ||||
continue; | continue; | ||||
if (prt_who) { | if (prt_who) { | ||||
const char *who = NULL; | const char *who = NULL; | ||||
if (prt_title) { | if (prt_title) { | ||||
prt_title = B_FALSE; | prt_title = B_FALSE; | ||||
(void) printf(title); | (void) printf("%s", title); | ||||
} | } | ||||
switch (who_type) { | switch (who_type) { | ||||
case ZFS_DELEG_USER_SETS: | case ZFS_DELEG_USER_SETS: | ||||
case ZFS_DELEG_USER: | case ZFS_DELEG_USER: | ||||
who = gettext("user"); | who = gettext("user"); | ||||
if (nice_who_name) | if (nice_who_name) | ||||
who_name = nice_who_name; | who_name = nice_who_name; | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | for (node = uu_list_first(fspset->fsps_list); node != NULL; | ||||
node = uu_list_next(fspset->fsps_list, node)) { | node = uu_list_next(fspset->fsps_list, node)) { | ||||
uu_avl_t *sc_avl = node->fspn_fsperm.fsp_sc_avl; | uu_avl_t *sc_avl = node->fspn_fsperm.fsp_sc_avl; | ||||
uu_avl_t *uge_avl = node->fspn_fsperm.fsp_uge_avl; | uu_avl_t *uge_avl = node->fspn_fsperm.fsp_uge_avl; | ||||
int left = 0; | int left = 0; | ||||
(void) snprintf(buf, sizeof (buf), | (void) snprintf(buf, sizeof (buf), | ||||
gettext("---- Permissions on %s "), | gettext("---- Permissions on %s "), | ||||
node->fspn_fsperm.fsp_name); | node->fspn_fsperm.fsp_name); | ||||
(void) printf(dsname); | (void) printf("%s", dsname); | ||||
left = 70 - strlen(buf); | left = 70 - strlen(buf); | ||||
while (left-- > 0) | while (left-- > 0) | ||||
(void) printf("-"); | (void) printf("-"); | ||||
(void) printf("\n"); | (void) printf("\n"); | ||||
print_set_creat_perms(sc_avl); | print_set_creat_perms(sc_avl); | ||||
print_uge_deleg_perms(uge_avl, B_TRUE, B_FALSE, | print_uge_deleg_perms(uge_avl, B_TRUE, B_FALSE, | ||||
gettext("Local permissions:\n")); | gettext("Local permissions:\n")); | ||||
▲ Show 20 Lines • Show All 262 Lines • ▼ Show 20 Lines | print_holds(boolean_t scripted, boolean_t literal, size_t nwidth, | ||||
nvpair_t *nvp = NULL; | nvpair_t *nvp = NULL; | ||||
char *hdr_cols[] = { "NAME", "TAG", "TIMESTAMP" }; | char *hdr_cols[] = { "NAME", "TAG", "TIMESTAMP" }; | ||||
const char *col; | const char *col; | ||||
if (!scripted) { | if (!scripted) { | ||||
for (i = 0; i < 3; i++) { | for (i = 0; i < 3; i++) { | ||||
col = gettext(hdr_cols[i]); | col = gettext(hdr_cols[i]); | ||||
if (i < 2) | if (i < 2) | ||||
(void) printf("%-*s ", i ? tagwidth : nwidth, | (void) printf("%-*s ", i ? (int)tagwidth : (int)nwidth, | ||||
col); | col); | ||||
else | else | ||||
(void) printf("%s\n", col); | (void) printf("%s\n", col); | ||||
} | } | ||||
} | } | ||||
while ((nvp = nvlist_next_nvpair(nvl, nvp)) != NULL) { | while ((nvp = nvlist_next_nvpair(nvl, nvp)) != NULL) { | ||||
char *zname = nvpair_name(nvp); | char *zname = nvpair_name(nvp); | ||||
nvlist_t *nvl2; | nvlist_t *nvl2; | ||||
nvpair_t *nvp2 = NULL; | nvpair_t *nvp2 = NULL; | ||||
(void) nvpair_value_nvlist(nvp, &nvl2); | (void) nvpair_value_nvlist(nvp, &nvl2); | ||||
while ((nvp2 = nvlist_next_nvpair(nvl2, nvp2)) != NULL) { | while ((nvp2 = nvlist_next_nvpair(nvl2, nvp2)) != NULL) { | ||||
char tsbuf[DATETIME_BUF_LEN]; | char tsbuf[DATETIME_BUF_LEN]; | ||||
char *tagname = nvpair_name(nvp2); | char *tagname = nvpair_name(nvp2); | ||||
uint64_t val = 0; | uint64_t val = 0; | ||||
time_t time; | time_t time; | ||||
struct tm t; | struct tm t; | ||||
char sep = scripted ? '\t' : ' '; | char sep = scripted ? '\t' : ' '; | ||||
size_t sepnum = scripted ? 1 : 2; | size_t sepnum = scripted ? 1 : 2; | ||||
(void) nvpair_value_uint64(nvp2, &val); | (void) nvpair_value_uint64(nvp2, &val); | ||||
if (literal) | if (literal) | ||||
snprintf(tsbuf, DATETIME_BUF_LEN, "%llu", val); | snprintf(tsbuf, DATETIME_BUF_LEN, "%"PRIu64, val); | ||||
else { | else { | ||||
time = (time_t)val; | time = (time_t)val; | ||||
(void) localtime_r(&time, &t); | (void) localtime_r(&time, &t); | ||||
(void) strftime(tsbuf, DATETIME_BUF_LEN, | (void) strftime(tsbuf, DATETIME_BUF_LEN, | ||||
gettext(STRFTIME_FMT_STR), &t); | gettext(STRFTIME_FMT_STR), &t); | ||||
} | } | ||||
(void) printf("%-*s%*c%-*s%*c%s\n", nwidth, zname, | (void) printf("%-*s%*c%-*s%*c%s\n", (int)nwidth, zname, (int)sepnum, (int)sep, (int)tagwidth, tagname, (int)sepnum, (int)sep, tsbuf); | ||||
allanjude: This line should be wrapped | |||||
sepnum, sep, tagwidth, tagname, sepnum, sep, tsbuf); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* Generic callback function to list a dataset or snapshot. | * Generic callback function to list a dataset or snapshot. | ||||
*/ | */ | ||||
static int | static int | ||||
▲ Show 20 Lines • Show All 452 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
append_options(char *mntopts, char *newopts) | append_options(char *mntopts, char *newopts) | ||||
{ | { | ||||
int len = strlen(mntopts); | int len = strlen(mntopts); | ||||
/* original length plus new string to append plus 1 for the comma */ | /* original length plus new string to append plus 1 for the comma */ | ||||
if (len + 1 + strlen(newopts) >= MNT_LINE_MAX) { | if (len + 1 + strlen(newopts) >= MNT_LINE_MAX) { | ||||
(void) fprintf(stderr, gettext("the opts argument for " | (void) fprintf(stderr, gettext("the opts argument for " | ||||
"'%c' option is too long (more than %d chars)\n"), | "'%s' option is too long (more than %d chars)\n"), | ||||
"-o", MNT_LINE_MAX); | "-o", MNT_LINE_MAX); | ||||
allanjudeUnsubmitted Not Done Inline Actionsgood catch here, this is a legit bug you found here. allanjude: good catch here, this is a legit bug you found here. | |||||
usage(B_FALSE); | usage(B_FALSE); | ||||
} | } | ||||
if (*mntopts) | if (*mntopts) | ||||
mntopts[len++] = ','; | mntopts[len++] = ','; | ||||
(void) strcpy(&mntopts[len], newopts); | (void) strcpy(&mntopts[len], newopts); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,102 Lines • Show Last 20 Lines |
This line should be wrapped