9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright (c) 2012 by Delphix. All rights reserved.
29 */
30
31 /*
32 * The pool configuration repository is stored in /etc/zfs/zpool.cache as a
33 * single packed nvlist. While it would be nice to just read in this
34 * file from userland, this wouldn't work from a local zone. So we have to have
35 * a zpool ioctl to return the complete configuration for all pools. In the
36 * global zone, this will be identical to reading the file and unpacking it in
37 * userland.
38 */
39
40 #include <errno.h>
41 #include <sys/stat.h>
42 #include <fcntl.h>
43 #include <stddef.h>
44 #include <string.h>
45 #include <unistd.h>
46 #include <libintl.h>
47 #include <libuutil.h>
48
150 default:
151 zcmd_free_nvlists(&zc);
152 return (zfs_standard_error(hdl, errno,
153 dgettext(TEXT_DOMAIN, "failed to read "
154 "pool configuration")));
155 }
156 } else {
157 hdl->libzfs_ns_gen = zc.zc_cookie;
158 break;
159 }
160 }
161
162 if (zcmd_read_dst_nvlist(hdl, &zc, &config) != 0) {
163 zcmd_free_nvlists(&zc);
164 return (-1);
165 }
166
167 zcmd_free_nvlists(&zc);
168
169 /*
170 * Clear out any existing configuration information.
171 */
172 cookie = NULL;
173 while ((cn = uu_avl_teardown(hdl->libzfs_ns_avl, &cookie)) != NULL) {
174 nvlist_free(cn->cn_config);
175 free(cn->cn_name);
176 free(cn);
177 }
178
179 elem = NULL;
180 while ((elem = nvlist_next_nvpair(config, elem)) != NULL) {
181 nvlist_t *child;
182 uu_avl_index_t where;
183
184 if ((cn = zfs_alloc(hdl, sizeof (config_node_t))) == NULL) {
185 nvlist_free(config);
186 return (-1);
187 }
188
189 if ((cn->cn_name = zfs_strdup(hdl,
190 nvpair_name(elem))) == NULL) {
191 free(cn);
192 nvlist_free(config);
193 return (-1);
194 }
195
196 verify(nvpair_value_nvlist(elem, &child) == 0);
197 if (nvlist_dup(child, &cn->cn_config, 0) != 0) {
|
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright (c) 2012 by Delphix. All rights reserved.
29 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
30 */
31
32 /*
33 * The pool configuration repository is stored in /etc/zfs/zpool.cache as a
34 * single packed nvlist. While it would be nice to just read in this
35 * file from userland, this wouldn't work from a local zone. So we have to have
36 * a zpool ioctl to return the complete configuration for all pools. In the
37 * global zone, this will be identical to reading the file and unpacking it in
38 * userland.
39 */
40
41 #include <errno.h>
42 #include <sys/stat.h>
43 #include <fcntl.h>
44 #include <stddef.h>
45 #include <string.h>
46 #include <unistd.h>
47 #include <libintl.h>
48 #include <libuutil.h>
49
151 default:
152 zcmd_free_nvlists(&zc);
153 return (zfs_standard_error(hdl, errno,
154 dgettext(TEXT_DOMAIN, "failed to read "
155 "pool configuration")));
156 }
157 } else {
158 hdl->libzfs_ns_gen = zc.zc_cookie;
159 break;
160 }
161 }
162
163 if (zcmd_read_dst_nvlist(hdl, &zc, &config) != 0) {
164 zcmd_free_nvlists(&zc);
165 return (-1);
166 }
167
168 zcmd_free_nvlists(&zc);
169
170 /*
171 * Clear out any existing configuration information, and recreate
172 * the AVL tree.
173 */
174 cookie = NULL;
175 while ((cn = uu_avl_teardown(hdl->libzfs_ns_avl, &cookie)) != NULL) {
176 nvlist_free(cn->cn_config);
177 free(cn->cn_name);
178 free(cn);
179 }
180
181 uu_avl_recreate(hdl->libzfs_ns_avl);
182
183 elem = NULL;
184 while ((elem = nvlist_next_nvpair(config, elem)) != NULL) {
185 nvlist_t *child;
186 uu_avl_index_t where;
187
188 if ((cn = zfs_alloc(hdl, sizeof (config_node_t))) == NULL) {
189 nvlist_free(config);
190 return (-1);
191 }
192
193 if ((cn->cn_name = zfs_strdup(hdl,
194 nvpair_name(elem))) == NULL) {
195 free(cn);
196 nvlist_free(config);
197 return (-1);
198 }
199
200 verify(nvpair_value_nvlist(elem, &child) == 0);
201 if (nvlist_dup(child, &cn->cn_config, 0) != 0) {
|