So I decided to use "zfs list -H -o name,used" instead, but it has the
bad habit of making the output user-friendly by showing KB, MB or GB
depending on the size of a filesystem. E.g.:
data/user1 24.5K
data/user2 316M
data/user3 1.45G
It's not that I don't know how to convert GB into KB, but the problem is
that I get different granularity depending on the size of the
filesystem. When comparing zfs output from yesterday with the one from
today, for user3 to actually see a diff his filesystem must grow by at
least 10MB. For user2, a change of 1MB is visible, while for user1 512b
make a diff.
Is there a way to make "zfs list" show sizes in KB (or at least MB) for
*all* filesystems, independent of the size? I think an implementation
like used in du (default block, -k KB, -h user-friendly) would be better
for scripts.
mp.
--
SysAdmin | Institute of Scientific Computing, University of Vienna
PCA | Analyze, download and install patches for Solaris
| http://www.par.univie.ac.at/solaris/pca/
The used diskspace is one of the properties. These may be retrieved
using the "zfs get" sub-command. In combination with "-H" (without
headers, tab-separated columns) and "-p" (parsable numbers), you will
get what you want:
theseus# zfs get -Hp used black-eye/users/borchert
black-eye/users/borchert used 15235882314 -
theseus#
It is also possible to retrieve such values through the libzfs library
which happens to be undocumented (with the excuse that interfaces
are likely to change):
#include <libzfs.h>
#include <stdio.h>
int main(int argc, char** argv) {
char* cmdname = argv[0];
if (argc != 2) {
fprintf(stderr, "Usage: %s zfs-filesystem\n", cmdname);
exit(1);
}
char* zfsfs = argv[1];
libzfs_handle_t *libzfs = libzfs_init();
if (libzfs == 0) {
perror("libzfs"); exit(1);
}
zfs_handle_t *zhp;
if ((zhp = zfs_open(libzfs, zfsfs,
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME)) == 0) {
perror(zfsfs); exit(1);
}
uint64_t size = zfs_prop_get_int(zhp, ZFS_PROP_USED);
printf("%llu\n", size);
}
Andreas.
Indeed. Instead of:
$ zfs list -H -o name,used
... I can now use:
$ zfs get -H -p used | cut -d' ' -f1,3
as a direct replacement. A possible RFE would be to add "-p" to the "zfs
list" sub-command as well.
Thanks a lot for the pointer!
Martin.
zfs get -o name,value -Hp used
makes the cut unnecessary.
--
Daniel