int sec_remaining =
(zcb->zcb_totalasize - bytes) / 1024 / kb_per_sec;
- zfs_nicenum(bytes, buf, sizeof (buf));
+ zfs_nicebytes(bytes, buf, sizeof (buf));
(void) fprintf(stderr,
"\r%5s completed (%4dMB/s) "
"estimated time remaining: %uhr %02umin %02usec ",
if (cb.cb_verbose) {
char buf[16];
- zfs_nicenum(cb.cb_snapused, buf, sizeof (buf));
+ zfs_nicebytes(cb.cb_snapused, buf, sizeof (buf));
if (cb.cb_parsable) {
(void) printf("reclaim\t%llu\n",
(u_longlong_t)cb.cb_snapused);
}
/* Calculate/update width of USED/QUOTA fields */
- if (cb->cb_nicenum)
- zfs_nicenum(space, sizebuf, sizeof (sizebuf));
- else
+ if (cb->cb_nicenum) {
+ if (prop == ZFS_PROP_USERUSED || prop == ZFS_PROP_GROUPUSED ||
+ prop == ZFS_PROP_USERQUOTA || prop == ZFS_PROP_GROUPQUOTA) {
+ zfs_nicebytes(space, sizebuf, sizeof (sizebuf));
+ } else {
+ zfs_nicenum(space, sizebuf, sizeof (sizebuf));
+ }
+ } else {
(void) snprintf(sizebuf, sizeof (sizebuf), "%llu",
(u_longlong_t)space);
+ }
sizelen = strlen(sizebuf);
if (prop == ZFS_PROP_USERUSED || prop == ZFS_PROP_GROUPUSED) {
propname = "used";
break;
case USFIELD_USED:
case USFIELD_QUOTA:
+ if (type == DATA_TYPE_UINT64) {
+ if (parsable) {
+ (void) sprintf(valstr, "%llu",
+ (u_longlong_t)val64);
+ strval = valstr;
+ } else if (field == USFIELD_QUOTA &&
+ val64 == 0) {
+ strval = "none";
+ } else {
+ zfs_nicebytes(val64, valstr,
+ sizeof (valstr));
+ strval = valstr;
+ }
+ }
+ break;
case USFIELD_OBJUSED:
case USFIELD_OBJQUOTA:
if (type == DATA_TYPE_UINT64) {
if (parsable) {
(void) sprintf(valstr, "%llu",
(u_longlong_t)val64);
+ strval = valstr;
+ } else if (field == USFIELD_OBJQUOTA &&
+ val64 == 0) {
+ strval = "none";
} else {
zfs_nicenum(val64, valstr,
sizeof (valstr));
- }
- if ((field == USFIELD_QUOTA ||
- field == USFIELD_OBJQUOTA) &&
- strcmp(valstr, "0") == 0)
- strval = "none";
- else
strval = valstr;
+ }
}
break;
}
start = ps->pss_start_time;
end = ps->pss_end_time;
- zfs_nicenum(ps->pss_processed, processed_buf, sizeof (processed_buf));
+ zfs_nicebytes(ps->pss_processed, processed_buf, sizeof (processed_buf));
assert(ps->pss_func == POOL_SCAN_SCRUB ||
ps->pss_func == POOL_SCAN_RESILVER);
mins_left = ((total - examined) / rate) / 60;
hours_left = mins_left / 60;
- zfs_nicenum(examined, examined_buf, sizeof (examined_buf));
- zfs_nicenum(total, total_buf, sizeof (total_buf));
- zfs_nicenum(rate, rate_buf, sizeof (rate_buf));
+ zfs_nicebytes(examined, examined_buf, sizeof (examined_buf));
+ zfs_nicebytes(total, total_buf, sizeof (total_buf));
+ zfs_nicebytes(rate, rate_buf, sizeof (rate_buf));
/*
* do not print estimated time if hours_left is more than 30 days
ddt_stat_t *dds;
ddt_object_t *ddo;
uint_t c;
+ char dspace[6], mspace[6];
/*
* If the pool was faulted then we may not have been able to
return;
}
- (void) printf("DDT entries %llu, size %llu on disk, %llu in core\n",
+ zfs_nicebytes(ddo->ddo_dspace, dspace, sizeof (dspace));
+ zfs_nicebytes(ddo->ddo_mspace, mspace, sizeof (mspace));
+ (void) printf("DDT entries %llu, size %s on disk, %s in core\n",
(u_longlong_t)ddo->ddo_count,
- (u_longlong_t)ddo->ddo_dspace,
- (u_longlong_t)ddo->ddo_mspace);
+ dspace,
+ mspace);
verify(nvlist_lookup_uint64_array(config, ZPOOL_CONFIG_DDT_STATS,
(uint64_t **)&dds, &c) == 0);
enum zfs_nicenum_format {
ZFS_NICENUM_1024 = 0,
- ZFS_NICENUM_TIME = 1,
- ZFS_NICENUM_RAW = 2
+ ZFS_NICENUM_BYTES = 1,
+ ZFS_NICENUM_TIME = 2,
+ ZFS_NICENUM_RAW = 3
};
/*
extern void zfs_nicetime(uint64_t, char *, size_t);
+extern void zfs_nicebytes(uint64_t, char *, size_t);
extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *);
/*
*/
if (intval < SPA_MINBLOCKSIZE ||
intval > maxbs || !ISP2(intval)) {
- zfs_nicenum(maxbs, buf, sizeof (buf));
+ zfs_nicebytes(maxbs, buf, sizeof (buf));
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"'%s' must be power of 2 from 512B "
"to %s"), propname, buf);
case ZFS_PROP_VOLSIZE:
if (intval % blocksize != 0) {
- zfs_nicenum(blocksize, buf,
+ zfs_nicebytes(blocksize, buf,
sizeof (buf));
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"'%s' must be a multiple of "
(void) snprintf(propbuf, proplen, "%llu",
(u_longlong_t)val);
else
- zfs_nicenum(val, propbuf, proplen);
+ zfs_nicebytes(val, propbuf, proplen);
}
break;
(void) snprintf(propbuf, proplen, "%llu", (u_longlong_t)val);
break;
+ case ZFS_PROP_REFERENCED:
+ case ZFS_PROP_AVAILABLE:
+ case ZFS_PROP_USED:
+ case ZFS_PROP_USEDSNAP:
+ case ZFS_PROP_USEDDS:
+ case ZFS_PROP_USEDREFRESERV:
+ case ZFS_PROP_USEDCHILD:
+ if (get_numeric_property(zhp, prop, src, &source, &val) != 0)
+ return (-1);
+ if (literal)
+ (void) snprintf(propbuf, proplen, "%llu",
+ (u_longlong_t)val);
+ else
+ zfs_nicebytes(val, propbuf, proplen);
+ break;
+
default:
switch (zfs_prop_get_type(prop)) {
case PROP_TYPE_NUMBER:
(type == ZFS_PROP_USERQUOTA || type == ZFS_PROP_GROUPQUOTA ||
type == ZFS_PROP_USEROBJQUOTA || type == ZFS_PROP_GROUPOBJQUOTA)) {
(void) strlcpy(propbuf, "none", proplen);
+ } else if (type == ZFS_PROP_USERQUOTA || type == ZFS_PROP_GROUPQUOTA ||
+ type == ZFS_PROP_USERUSED || type == ZFS_PROP_GROUPUSED) {
+ zfs_nicebytes(propvalue, propbuf, proplen);
} else {
zfs_nicenum(propvalue, propbuf, proplen);
}
(void) snprintf(propbuf, proplen, "%llu",
(u_longlong_t)propvalue);
} else {
- zfs_nicenum(propvalue, propbuf, proplen);
+ zfs_nicebytes(propvalue, propbuf, proplen);
}
return (0);
(void) snprintf(buf, len, "%llu",
(u_longlong_t)intval);
} else {
- (void) zfs_nicenum(intval, buf, len);
+ (void) zfs_nicebytes(intval, buf, len);
}
break;
{
char buf[64];
- zfs_nicenum(SPA_MINDEVSIZE, buf, sizeof (buf));
+ zfs_nicebytes(SPA_MINDEVSIZE, buf,
+ sizeof (buf));
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"one or more devices is less than the "
{
char buf[64];
- zfs_nicenum(SPA_MINDEVSIZE, buf, sizeof (buf));
+ zfs_nicebytes(SPA_MINDEVSIZE, buf,
+ sizeof (buf));
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"device is less than the minimum "
tm->tm_hour, tm->tm_min, tm->tm_sec,
bytes, zhp->zfs_name);
} else {
- zfs_nicenum(bytes, buf, sizeof (buf));
+ zfs_nicebytes(bytes, buf, sizeof (buf));
(void) fprintf(stderr, "%02d:%02d:%02d %5s %s\n",
tm->tm_hour, tm->tm_min, tm->tm_sec,
buf, zhp->zfs_name);
(longlong_t)size);
} else {
char buf[16];
- zfs_nicenum(size, buf, sizeof (buf));
+ zfs_nicebytes(size, buf, sizeof (buf));
(void) fprintf(fout, dgettext(TEXT_DOMAIN,
" estimated size is %s"), buf);
}
(longlong_t)sdd.size);
} else {
char buf[16];
- zfs_nicenum(sdd.size, buf, sizeof (buf));
+ zfs_nicebytes(sdd.size, buf, sizeof (buf));
(void) fprintf(fout, dgettext(TEXT_DOMAIN,
"total estimated size is %s\n"), buf);
}
time_t delta = time(NULL) - begin_time;
if (delta == 0)
delta = 1;
- zfs_nicenum(bytes, buf1, sizeof (buf1));
- zfs_nicenum(bytes/delta, buf2, sizeof (buf1));
+ zfs_nicebytes(bytes, buf1, sizeof (buf1));
+ zfs_nicebytes(bytes/delta, buf2, sizeof (buf1));
- (void) printf("received %sB stream in %lu seconds (%sB/sec)\n",
+ (void) printf("received %s stream in %lu seconds (%s/sec)\n",
buf1, delta, buf2);
}
zfs_nicenum(1ULL << h, refcnt, sizeof (refcnt));
zfs_nicenum(dds->dds_blocks, blocks, sizeof (blocks));
- zfs_nicenum(dds->dds_lsize, lsize, sizeof (lsize));
- zfs_nicenum(dds->dds_psize, psize, sizeof (psize));
- zfs_nicenum(dds->dds_dsize, dsize, sizeof (dsize));
+ zfs_nicebytes(dds->dds_lsize, lsize, sizeof (lsize));
+ zfs_nicebytes(dds->dds_psize, psize, sizeof (psize));
+ zfs_nicebytes(dds->dds_dsize, dsize, sizeof (dsize));
zfs_nicenum(dds->dds_ref_blocks, ref_blocks, sizeof (ref_blocks));
- zfs_nicenum(dds->dds_ref_lsize, ref_lsize, sizeof (ref_lsize));
- zfs_nicenum(dds->dds_ref_psize, ref_psize, sizeof (ref_psize));
- zfs_nicenum(dds->dds_ref_dsize, ref_dsize, sizeof (ref_dsize));
+ zfs_nicebytes(dds->dds_ref_lsize, ref_lsize, sizeof (ref_lsize));
+ zfs_nicebytes(dds->dds_ref_psize, ref_psize, sizeof (ref_psize));
+ zfs_nicebytes(dds->dds_ref_dsize, ref_dsize, sizeof (ref_dsize));
(void) printf("%6s %6s %5s %5s %5s %6s %5s %5s %5s\n",
refcnt,
const char *u;
const char *units[3][7] = {
[ZFS_NICENUM_1024] = {"", "K", "M", "G", "T", "P", "E"},
+ [ZFS_NICENUM_BYTES] = {"B", "K", "M", "G", "T", "P", "E"},
[ZFS_NICENUM_TIME] = {"ns", "us", "ms", "s", "?", "?", "?"}
};
const int units_len[] = {[ZFS_NICENUM_1024] = 6,
+ [ZFS_NICENUM_BYTES] = 6,
[ZFS_NICENUM_TIME] = 4};
const int k_unit[] = { [ZFS_NICENUM_1024] = 1024,
+ [ZFS_NICENUM_BYTES] = 1024,
[ZFS_NICENUM_TIME] = 1000};
double val;
zfs_nicenum_format(num, buf, buflen, ZFS_NICENUM_RAW);
}
-
+/*
+ * Convert a number of bytes to an appropriately human-readable output.
+ */
+void
+zfs_nicebytes(uint64_t num, char *buf, size_t buflen)
+{
+ zfs_nicenum_format(num, buf, buflen, ZFS_NICENUM_BYTES);
+}
void
libzfs_print_on_error(libzfs_handle_t *hdl, boolean_t printerr)
typeset ds=$1
typeset used
- used=`zfs list -H -o used $ds`
- used=${used%[m|M]}
- if [[ $used == *K ]]; then
- used=0
- fi
+ used=`zfs list -H -p -o used $ds`
echo $used
}
typeset -i cfactor
typeset -i fsize=${FILESIZE%[m|M]}
- ((used = ${charged_spc%[m|M]}))
+ ((used = $charged_spc / 1024 / 1024))
((cfactor = used / fsize))
if ((cfactor != expected_cfactor)); then
log_fail "The space is not charged correctly while setting" \
fi
for val in 1 2 3; do
blks=`ls -ls /$TESTPOOL/fs_$val/$FILE | awk '{print $1}'`
- (( used = blks * $blksize / (1024 * 1024) ))
+ (( used = blks * $blksize )) # bytes
check_used $used $val
done
log_note "Verify df(1M) can corectly display the space charged."
for val in 1 2 3; do
- used=`df -F zfs -h /$TESTPOOL/fs_$val/$FILE | grep $TESTPOOL/fs_$val \
+ used=`df -F zfs -k /$TESTPOOL/fs_$val/$FILE | grep $TESTPOOL/fs_$val \
| awk '{print $3}'`
+ (( used = used * 1024 )) # kb -> bytes
check_used $used $val
done
log_note "Verify du(1) can correctly display the space charged."
for val in 1 2 3; do
- used=`du -h /$TESTPOOL/fs_$val/$FILE | awk '{print $1}'`
+ used=`du -k /$TESTPOOL/fs_$val/$FILE | awk '{print $1}'`
+ (( used = used * 1024 )) # kb -> bytes
check_used $used $val
done
# Copyright (c) 2012, 2015 by Delphix. All rights reserved.
#
-set -A RW_FS_PROP "quota=512M" \
- "reservation=512M" \
- "recordsize=256K" \
+set -A RW_FS_PROP "quota=536870912" \
+ "reservation=536870912" \
+ "recordsize=262144" \
"mountpoint=/tmp/mnt$$" \
"checksum=fletcher2" \
"compression=lzjb" \
"canmount=off" \
"local:department=123"
-set -A RW_VOL_PROP "volblocksize=16K" \
+set -A RW_VOL_PROP "volblocksize=16384" \
"checksum=fletcher2" \
"compression=lzjb" \
"readonly=on" \
"readonly=on" \
"local:department=123"
-set -A FS_ONLY_PROP "quota=512M" \
- "recordsize=64K" \
+set -A FS_ONLY_PROP "quota=536870912" \
+ "recordsize=65536" \
"mountpoint=/tmp/mnt$$" \
"atime=off" \
"devices=off" \
"canmount=off" \
"version=1"
-set -A VOL_ONLY_PROP "volblocksize=16K" "volsize=512M"
+set -A VOL_ONLY_PROP "volblocksize=16384" "volsize=536870912"
typeset prop=$(echo $propstr | awk -F= '{print $1}')
typeset expect_value=$(echo $propstr | awk -F= '{print $2}')
- typeset value=$(zfs get -H -o value $prop $dtst)
+ typeset value=$(zfs get -H -p -o value $prop $dtst)
if [[ "$expect_value" == "$value" ]]; then
log_assert "'zpool create -O property=value pool' can successfully create a pool \
with correct filesystem property set."
-set -A RW_FS_PROP "quota=512M" \
- "reservation=512M" \
- "recordsize=64K" \
+set -A RW_FS_PROP "quota=536870912" \
+ "reservation=536870912" \
+ "recordsize=262144" \
"mountpoint=/tmp/mnt$$" \
"checksum=fletcher2" \
"compression=lzjb" \
log_assert "'zpool create -O property=value pool' can successfully create a pool \
with multiple filesystem properties set."
-set -A RW_FS_PROP "quota=512M" \
- "reservation=512M" \
- "recordsize=64K" \
+set -A RW_FS_PROP "quota=536870912" \
+ "reservation=536870912" \
+ "recordsize=262144" \
"mountpoint=/tmp/mnt$$" \
"checksum=fletcher2" \
"compression=lzjb" \
sync_pool
typeset user_used=$(get_value "userused@$QUSER1" $QFS)
typeset group_used=$(get_value "groupused@$QGROUP" $QFS)
+typeset file_size='100m'
if [[ $user_used != 0 ]]; then
log_fail "FAIL: userused is $user_used, should be 0"
fi
mkmount_writable $QFS
-log_must user_run $QUSER1 mkfile 100m $QFILE
+log_must user_run $QUSER1 mkfile $file_size $QFILE
sync_pool
user_used=$(get_value "userused@$QUSER1" $QFS)
group_used=$(get_value "groupused@$QGROUP" $QFS)
-if [[ $user_used != "100M" ]]; then
+# get_value() reads the exact byte value which is slightly more than 100m
+if [[ "$(($user_used/1024/1024))m" != "$file_size" ]]; then
log_note "user $QUSER1 used is $user_used"
- log_fail "userused for user $QUSER1 expected to be 50.0M, not $user_used"
+ log_fail "userused for user $QUSER1 expected to be $file_size, " \
+ "not $user_used"
fi
if [[ $user_used != $group_used ]]; then
typeset prop=$1
typeset dataset=$2
- prop_val=$(zfs get -H -o value $prop $dataset 2>/dev/null)
+ prop_val=$(zfs get -H -p -o value $prop $dataset 2>/dev/null)
if [[ $? -ne 0 ]]; then
log_note "Unable to get $prop property for dataset " \
"$dataset"