Skip to content

Commit

Permalink
Introduce zpool_get_prop_literal interface
Browse files Browse the repository at this point in the history
This change introduces zpool_get_prop_literal. It's an expanded version
of zpool_get_prop taking one additional boolean parameter. With this
parameter set to B_FALSE it will behave identically to zpool_get_prop.
Setting it to B_TRUE will return full precision numbers for the
following properties:

ZPOOL_PROP_SIZE
ZPOOL_PROP_ALLOCATED
ZPOOL_PROP_FREE
ZPOOL_PROP_FREEING
ZPOOL_PROP_EXPANDSZ
ZPOOL_PROP_ASHIFT

Also introduced is a wrapper function for zpool_get_prop making it
use zpool_get_prop_literal in the background.

Signed-off-by: Brian Behlendorf <[email protected]>
Issue #1813
  • Loading branch information
Lalufu authored and behlendorf committed Oct 28, 2013
1 parent 157c9b6 commit 8b921f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, char *);
extern int zpool_set_prop(zpool_handle_t *, const char *, const char *);
extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *,
size_t proplen, zprop_source_t *);
extern int zpool_get_prop_literal(zpool_handle_t *, zpool_prop_t, char *,
size_t proplen, zprop_source_t *, boolean_t literal);
extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t,
zprop_source_t *);

Expand Down
20 changes: 17 additions & 3 deletions lib/libzfs/libzfs_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,22 @@ zpool_pool_state_to_name(pool_state_t state)
}

/*
* Get a zpool property value for 'prop' and return the value in
* a pre-allocated buffer.
* API compatibility wrapper around zpool_get_prop_literal
*/
int
zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf, size_t len,
zprop_source_t *srctype)
{
return zpool_get_prop_literal(zhp, prop, buf, len, srctype, B_FALSE);
}

/*
* Get a zpool property value for 'prop' and return the value in
* a pre-allocated buffer.
*/
int
zpool_get_prop_literal(zpool_handle_t *zhp, zpool_prop_t prop, char *buf, size_t len,
zprop_source_t *srctype, boolean_t literal)
{
uint64_t intval;
const char *strval;
Expand Down Expand Up @@ -308,7 +318,11 @@ zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf, size_t len,
case ZPOOL_PROP_FREEING:
case ZPOOL_PROP_EXPANDSZ:
case ZPOOL_PROP_ASHIFT:
(void) zfs_nicenum(intval, buf, len);
if (literal)
(void) snprintf(buf, len, "%llu",
(u_longlong_t)intval);
else
(void) zfs_nicenum(intval, buf, len);
break;

case ZPOOL_PROP_CAPACITY:
Expand Down

0 comments on commit 8b921f6

Please sign in to comment.