Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

zfs list - size in KB/MB/GB

8,570 views
Skip to first unread message

Martin Paul

unread,
Apr 24, 2008, 5:34:46 AM4/24/08
to
For a local script which generates disk usage statistics, I need to
collect data about e.g. the size of users' home directories. For UFS,
quot was very usable, but unfortunately this doesn't work on ZFS.

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/

Andreas F. Borchert

unread,
Apr 24, 2008, 7:33:17 PM4/24/08
to
On 2008-04-24, Martin Paul <m...@par.univie.ac.at> wrote:
> 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.

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.

Martin Paul

unread,
Apr 25, 2008, 4:09:48 AM4/25/08
to
Andreas F. Borchert wrote:
> 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:

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.

Daniel Rock

unread,
Apr 25, 2008, 3:08:55 PM4/25/08
to
Martin Paul <m...@par.univie.ac.at> wrote:
> $ zfs get -H -p used | cut -d' ' -f1,3

zfs get -o name,value -Hp used

makes the cut unnecessary.

--
Daniel

0 new messages