Print this page
8115 parallel zfs mount
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libzpool/common/util.c
+++ new/usr/src/lib/libzpool/common/util.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2016 by Delphix. All rights reserved.
24 + * Copyright 2017 RackTop Systems.
24 25 */
25 26
26 27 #include <assert.h>
27 28 #include <sys/zfs_context.h>
28 29 #include <sys/avl.h>
29 30 #include <string.h>
30 31 #include <stdio.h>
31 32 #include <stdlib.h>
32 33 #include <sys/spa.h>
33 34 #include <sys/fs/zfs.h>
34 35 #include <sys/refcount.h>
35 36 #include <dlfcn.h>
36 37
38 +extern void nicenum(uint64_t num, char *buf, size_t);
39 +
37 40 /*
38 41 * Routines needed by more than one client of libzpool.
39 42 */
40 43
41 44 static void
42 45 show_vdev_stats(const char *desc, const char *ctype, nvlist_t *nv, int indent)
43 46 {
44 47 vdev_stat_t *vs;
45 48 vdev_stat_t v0 = { 0 };
46 49 uint64_t sec;
47 50 uint64_t is_log = 0;
48 51 nvlist_t **child;
49 52 uint_t c, children;
50 53 char used[6], avail[6];
51 54 char rops[6], wops[6], rbytes[6], wbytes[6], rerr[6], werr[6], cerr[6];
52 55 char *prefix = "";
53 56
54 57 if (indent == 0 && desc != NULL) {
55 58 (void) printf(" "
56 59 " capacity operations bandwidth ---- errors ----\n");
57 60 (void) printf("description "
58 61 "used avail read write read write read write cksum\n");
59 62 }
60 63
61 64 if (desc != NULL) {
62 65 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_LOG, &is_log);
63 66
64 67 if (is_log)
65 68 prefix = "log ";
66 69
67 70 if (nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
68 71 (uint64_t **)&vs, &c) != 0)
69 72 vs = &v0;
70 73
71 74 sec = MAX(1, vs->vs_timestamp / NANOSEC);
72 75
73 76 nicenum(vs->vs_alloc, used, sizeof (used));
74 77 nicenum(vs->vs_space - vs->vs_alloc, avail, sizeof (avail));
75 78 nicenum(vs->vs_ops[ZIO_TYPE_READ] / sec, rops, sizeof (rops));
76 79 nicenum(vs->vs_ops[ZIO_TYPE_WRITE] / sec, wops, sizeof (wops));
77 80 nicenum(vs->vs_bytes[ZIO_TYPE_READ] / sec, rbytes,
78 81 sizeof (rbytes));
79 82 nicenum(vs->vs_bytes[ZIO_TYPE_WRITE] / sec, wbytes,
80 83 sizeof (wbytes));
81 84 nicenum(vs->vs_read_errors, rerr, sizeof (rerr));
82 85 nicenum(vs->vs_write_errors, werr, sizeof (werr));
83 86 nicenum(vs->vs_checksum_errors, cerr, sizeof (cerr));
84 87
85 88 (void) printf("%*s%s%*s%*s%*s %5s %5s %5s %5s %5s %5s %5s\n",
86 89 indent, "",
87 90 prefix,
88 91 indent + strlen(prefix) - 25 - (vs->vs_space ? 0 : 12),
89 92 desc,
90 93 vs->vs_space ? 6 : 0, vs->vs_space ? used : "",
91 94 vs->vs_space ? 6 : 0, vs->vs_space ? avail : "",
92 95 rops, wops, rbytes, wbytes, rerr, werr, cerr);
93 96 }
94 97
95 98 if (nvlist_lookup_nvlist_array(nv, ctype, &child, &children) != 0)
96 99 return;
97 100
98 101 for (c = 0; c < children; c++) {
99 102 nvlist_t *cnv = child[c];
100 103 char *cname, *tname;
101 104 uint64_t np;
102 105 if (nvlist_lookup_string(cnv, ZPOOL_CONFIG_PATH, &cname) &&
103 106 nvlist_lookup_string(cnv, ZPOOL_CONFIG_TYPE, &cname))
104 107 cname = "<unknown>";
105 108 tname = calloc(1, strlen(cname) + 2);
106 109 (void) strcpy(tname, cname);
107 110 if (nvlist_lookup_uint64(cnv, ZPOOL_CONFIG_NPARITY, &np) == 0)
108 111 tname[strlen(tname)] = '0' + np;
109 112 show_vdev_stats(tname, ctype, cnv, indent + 2);
110 113 free(tname);
111 114 }
112 115 }
113 116
114 117 void
115 118 show_pool_stats(spa_t *spa)
116 119 {
117 120 nvlist_t *config, *nvroot;
118 121 char *name;
119 122
120 123 VERIFY(spa_get_stats(spa_name(spa), &config, NULL, 0) == 0);
121 124
122 125 VERIFY(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
123 126 &nvroot) == 0);
124 127 VERIFY(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
125 128 &name) == 0);
126 129
127 130 show_vdev_stats(name, ZPOOL_CONFIG_CHILDREN, nvroot, 0);
128 131 show_vdev_stats(NULL, ZPOOL_CONFIG_L2CACHE, nvroot, 0);
129 132 show_vdev_stats(NULL, ZPOOL_CONFIG_SPARES, nvroot, 0);
130 133
131 134 nvlist_free(config);
132 135 }
133 136
134 137 /*
135 138 * Sets given global variable in libzpool to given unsigned 32-bit value.
136 139 * arg: "<variable>=<value>"
137 140 */
138 141 int
139 142 set_global_var(char *arg)
140 143 {
141 144 void *zpoolhdl;
142 145 char *varname = arg, *varval;
143 146 u_longlong_t val;
144 147
145 148 #ifndef _LITTLE_ENDIAN
146 149 /*
147 150 * On big endian systems changing a 64-bit variable would set the high
148 151 * 32 bits instead of the low 32 bits, which could cause unexpected
149 152 * results.
150 153 */
151 154 fprintf(stderr, "Setting global variables is only supported on "
152 155 "little-endian systems\n", varname);
153 156 return (ENOTSUP);
154 157 #endif
155 158 if ((varval = strchr(arg, '=')) != NULL) {
156 159 *varval = '\0';
157 160 varval++;
158 161 val = strtoull(varval, NULL, 0);
159 162 if (val > UINT32_MAX) {
160 163 fprintf(stderr, "Value for global variable '%s' must "
161 164 "be a 32-bit unsigned integer\n", varname);
162 165 return (EOVERFLOW);
163 166 }
164 167 } else {
165 168 return (EINVAL);
166 169 }
167 170
168 171 zpoolhdl = dlopen("libzpool.so", RTLD_LAZY);
169 172 if (zpoolhdl != NULL) {
170 173 uint32_t *var;
171 174 var = dlsym(zpoolhdl, varname);
172 175 if (var == NULL) {
173 176 fprintf(stderr, "Global variable '%s' does not exist "
174 177 "in libzpool.so\n", varname);
175 178 return (EINVAL);
176 179 }
177 180 *var = (uint32_t)val;
178 181
179 182 dlclose(zpoolhdl);
180 183 } else {
181 184 fprintf(stderr, "Failed to open libzpool.so to set global "
182 185 "variable\n");
183 186 return (EIO);
184 187 }
185 188
186 189 return (0);
187 190 }
↓ open down ↓ |
141 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX