]>
git.proxmox.com Git - mirror_zfs.git/blob - zfs/lib/libzpool/util.c
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
29 #include <sys/zfs_context.h>
35 #include <sys/fs/zfs.h>
36 #include <sys/refcount.h>
39 * Routines needed by more than one client of libzpool.
43 nicenum(uint64_t num
, char *buf
)
50 n
= (n
+ (1024 / 2)) / 1024; /* Round up or down */
57 (void) sprintf(buf
, "%llu", (u_longlong_t
)n
);
58 } else if (n
< 10 && (num
& (num
- 1)) != 0) {
59 (void) sprintf(buf
, "%.2f%c",
60 (double)num
/ (1ULL << 10 * index
), u
);
61 } else if (n
< 100 && (num
& (num
- 1)) != 0) {
62 (void) sprintf(buf
, "%.1f%c",
63 (double)num
/ (1ULL << 10 * index
), u
);
65 (void) sprintf(buf
, "%llu%c", (u_longlong_t
)n
, u
);
70 show_vdev_stats(const char *desc
, nvlist_t
*nv
, int indent
)
77 char used
[6], avail
[6];
78 char rops
[6], wops
[6], rbytes
[6], wbytes
[6], rerr
[6], werr
[6], cerr
[6];
83 " capacity operations bandwidth ---- errors ----\n");
84 (void) printf("description "
85 "used avail read write read write read write cksum\n");
88 VERIFY(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_STATS
,
89 (uint64_t **)&vs
, &c
) == 0);
90 (void) nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_IS_LOG
, &is_log
);
95 sec
= MAX(1, vs
->vs_timestamp
/ NANOSEC
);
97 nicenum(vs
->vs_alloc
, used
);
98 nicenum(vs
->vs_space
- vs
->vs_alloc
, avail
);
99 nicenum(vs
->vs_ops
[ZIO_TYPE_READ
] / sec
, rops
);
100 nicenum(vs
->vs_ops
[ZIO_TYPE_WRITE
] / sec
, wops
);
101 nicenum(vs
->vs_bytes
[ZIO_TYPE_READ
] / sec
, rbytes
);
102 nicenum(vs
->vs_bytes
[ZIO_TYPE_WRITE
] / sec
, wbytes
);
103 nicenum(vs
->vs_read_errors
, rerr
);
104 nicenum(vs
->vs_write_errors
, werr
);
105 nicenum(vs
->vs_checksum_errors
, cerr
);
107 (void) printf("%*s%s%*s%*s%*s %5s %5s %5s %5s %5s %5s %5s\n",
110 indent
+ strlen(prefix
) - 19 - (vs
->vs_space
? 0 : 12), desc
,
111 vs
->vs_space
? 6 : 0, vs
->vs_space
? used
: "",
112 vs
->vs_space
? 6 : 0, vs
->vs_space
? avail
: "",
113 rops
, wops
, rbytes
, wbytes
, rerr
, werr
, cerr
);
115 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
116 &child
, &children
) != 0)
119 for (c
= 0; c
< children
; c
++) {
120 nvlist_t
*cnv
= child
[c
];
123 if (nvlist_lookup_string(cnv
, ZPOOL_CONFIG_PATH
, &cname
) &&
124 nvlist_lookup_string(cnv
, ZPOOL_CONFIG_TYPE
, &cname
))
126 tname
= calloc(1, strlen(cname
) + 2);
127 (void) strcpy(tname
, cname
);
128 if (nvlist_lookup_uint64(cnv
, ZPOOL_CONFIG_NPARITY
, &np
) == 0)
129 tname
[strlen(tname
)] = '0' + np
;
130 show_vdev_stats(tname
, cnv
, indent
+ 2);
136 show_pool_stats(spa_t
*spa
)
138 nvlist_t
*config
, *nvroot
;
141 spa_config_enter(spa
, RW_READER
, FTAG
);
142 config
= spa_config_generate(spa
, NULL
, -1ULL, B_TRUE
);
143 spa_config_exit(spa
, FTAG
);
145 VERIFY(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
147 VERIFY(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
150 show_vdev_stats(name
, nvroot
, 0);