equal
deleted
inserted
replaced
171 break; |
171 break; |
172 } |
172 } |
173 } |
173 } |
174 |
174 |
175 if (nvlist_unpack((void *)(uintptr_t)zc.zc_config_dst, |
175 if (nvlist_unpack((void *)(uintptr_t)zc.zc_config_dst, |
176 zc.zc_config_dst_size, &config, 0) != 0) |
176 zc.zc_config_dst_size, &config, 0) != 0) { |
|
177 free((void *)(uintptr_t)zc.zc_config_dst); |
177 return (no_memory(hdl)); |
178 return (no_memory(hdl)); |
|
179 } |
178 |
180 |
179 free((void *)(uintptr_t)zc.zc_config_dst); |
181 free((void *)(uintptr_t)zc.zc_config_dst); |
180 |
182 |
181 /* |
183 /* |
182 * Clear out any existing configuration information. |
184 * Clear out any existing configuration information. |
244 * iostat to show configuration changes and determine the delta from the last |
246 * iostat to show configuration changes and determine the delta from the last |
245 * time the function was called. This function can fail, in case the pool has |
247 * time the function was called. This function can fail, in case the pool has |
246 * been destroyed. |
248 * been destroyed. |
247 */ |
249 */ |
248 int |
250 int |
249 zpool_refresh_stats(zpool_handle_t *zhp) |
251 zpool_refresh_stats(zpool_handle_t *zhp, boolean_t *missing) |
250 { |
252 { |
251 zfs_cmd_t zc = { 0 }; |
253 zfs_cmd_t zc = { 0 }; |
252 int error; |
254 int error; |
253 nvlist_t *config; |
255 nvlist_t *config; |
254 |
256 |
|
257 *missing = B_FALSE; |
255 (void) strcpy(zc.zc_name, zhp->zpool_name); |
258 (void) strcpy(zc.zc_name, zhp->zpool_name); |
256 |
259 |
257 if (zhp->zpool_config_size == 0) |
260 if (zhp->zpool_config_size == 0) |
258 zhp->zpool_config_size = 1 << 16; |
261 zhp->zpool_config_size = 1 << 16; |
259 |
262 |
266 if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_POOL_STATS, |
269 if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_POOL_STATS, |
267 &zc) == 0) { |
270 &zc) == 0) { |
268 /* |
271 /* |
269 * The real error is returned in the zc_cookie field. |
272 * The real error is returned in the zc_cookie field. |
270 */ |
273 */ |
271 error = errno = zc.zc_cookie; |
274 error = zc.zc_cookie; |
272 break; |
275 break; |
273 } |
276 } |
274 |
277 |
275 if (errno == ENOMEM) { |
278 if (errno == ENOMEM) { |
276 free((void *)(uintptr_t)zc.zc_config_dst); |
279 free((void *)(uintptr_t)zc.zc_config_dst); |
278 zfs_alloc(zhp->zpool_hdl, |
281 zfs_alloc(zhp->zpool_hdl, |
279 zc.zc_config_dst_size)) == NULL) |
282 zc.zc_config_dst_size)) == NULL) |
280 return (-1); |
283 return (-1); |
281 } else { |
284 } else { |
282 free((void *)(uintptr_t)zc.zc_config_dst); |
285 free((void *)(uintptr_t)zc.zc_config_dst); |
283 return (-1); |
286 if (errno == ENOENT || errno == EINVAL) |
|
287 *missing = B_TRUE; |
|
288 zhp->zpool_state = POOL_STATE_UNAVAIL; |
|
289 return (0); |
284 } |
290 } |
285 } |
291 } |
286 |
292 |
287 if (nvlist_unpack((void *)(uintptr_t)zc.zc_config_dst, |
293 if (nvlist_unpack((void *)(uintptr_t)zc.zc_config_dst, |
288 zc.zc_config_dst_size, &config, 0) != 0) { |
294 zc.zc_config_dst_size, &config, 0) != 0) { |
291 } |
297 } |
292 |
298 |
293 zhp->zpool_config_size = zc.zc_config_dst_size; |
299 zhp->zpool_config_size = zc.zc_config_dst_size; |
294 free((void *)(uintptr_t)zc.zc_config_dst); |
300 free((void *)(uintptr_t)zc.zc_config_dst); |
295 |
301 |
296 if (set_pool_health(config) != 0) |
302 if (set_pool_health(config) != 0) { |
|
303 nvlist_free(config); |
297 return (no_memory(zhp->zpool_hdl)); |
304 return (no_memory(zhp->zpool_hdl)); |
|
305 } |
298 |
306 |
299 if (zhp->zpool_config != NULL) { |
307 if (zhp->zpool_config != NULL) { |
300 uint64_t oldtxg, newtxg; |
308 uint64_t oldtxg, newtxg; |
301 |
309 |
302 verify(nvlist_lookup_uint64(zhp->zpool_config, |
310 verify(nvlist_lookup_uint64(zhp->zpool_config, |
314 zhp->zpool_old_config = zhp->zpool_config; |
322 zhp->zpool_old_config = zhp->zpool_config; |
315 } |
323 } |
316 } |
324 } |
317 |
325 |
318 zhp->zpool_config = config; |
326 zhp->zpool_config = config; |
319 |
327 if (error) |
320 return (error ? -1 : 0); |
328 zhp->zpool_state = POOL_STATE_UNAVAIL; |
|
329 else |
|
330 zhp->zpool_state = POOL_STATE_ACTIVE; |
|
331 |
|
332 return (0); |
321 } |
333 } |
322 |
334 |
323 /* |
335 /* |
324 * Iterate over all pools in the system. |
336 * Iterate over all pools in the system. |
325 */ |
337 */ |
334 return (-1); |
346 return (-1); |
335 |
347 |
336 for (cn = uu_avl_first(hdl->libzfs_ns_avl); cn != NULL; |
348 for (cn = uu_avl_first(hdl->libzfs_ns_avl); cn != NULL; |
337 cn = uu_avl_next(hdl->libzfs_ns_avl, cn)) { |
349 cn = uu_avl_next(hdl->libzfs_ns_avl, cn)) { |
338 |
350 |
339 if ((zhp = zpool_open_silent(hdl, cn->cn_name)) == NULL) |
351 if (zpool_open_silent(hdl, cn->cn_name, &zhp) != 0) |
|
352 return (-1); |
|
353 |
|
354 if (zhp == NULL) |
340 continue; |
355 continue; |
341 |
356 |
342 if ((ret = func(zhp, data)) != 0) |
357 if ((ret = func(zhp, data)) != 0) |
343 return (ret); |
358 return (ret); |
344 } |
359 } |