/* * Like the above, but silent on error. Used when iterating over pools (because * the configuration cache may be out of date). */ int zpool_open_silent(libzfs_handle_t *hdl, const char *pool, zpool_handle_t **ret) { zpool_handle_t *zhp; boolean_t missing; if ((zhp = zfs_alloc(hdl, sizeof (zpool_handle_t))) == NULL) return (-1); zhp->zpool_hdl = hdl; (void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name)); if (zpool_refresh_stats(zhp, &missing) != 0) { zpool_close(zhp); return (-1); } if (missing) { zpool_close(zhp); *ret = NULL; return (0); } *ret = zhp; return (0); }
/* * Retrieves a list of enabled features and their refcounts and caches it in * the pool handle. */ nvlist_t * zpool_get_features(zpool_handle_t *zhp) { nvlist_t *config, *features; config = zpool_get_config(zhp, NULL); if (config == NULL || !nvlist_exists(config, ZPOOL_CONFIG_FEATURE_STATS)) { int error; boolean_t missing = B_FALSE; error = zpool_refresh_stats(zhp, &missing); if (error != 0 || missing) return (NULL); config = zpool_get_config(zhp, NULL); } verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_FEATURE_STATS, &features) == 0); return (features); }
int zpool_get_stats(zpool_handle_t * zhp, void * data) { config_t * cnf = (config_t *)data; uint_t c; boolean_t missing; nvlist_t * nv, * config; vdev_stat_t * vs; if (zpool_refresh_stats(zhp, &missing) != 0) return 1; config = zpool_get_config(zhp, NULL); if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, &nv) != 0) { return 1; } if (nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS, (uint64_t **)&vs, &c) != 0) { return 1; } if (!strcmp(zpool_get_name(zhp), cnf->zname)) { cnf->zpool.read_ops = vs->vs_ops[ZIO_TYPE_READ]; cnf->zpool.write_ops = vs->vs_ops[ZIO_TYPE_WRITE]; cnf->zpool.read_bts = vs->vs_bytes[ZIO_TYPE_READ]; cnf->zpool.write_bts = vs->vs_bytes[ZIO_TYPE_WRITE]; cnf->zpool.alloc = vs->vs_alloc; cnf->zpool.free = vs->vs_space - vs->vs_alloc; cnf->zpool.health = zpool_get_health(zhp); cnf->zpool.dedupratio = zpool_get_dedupratio(zhp); cnf->zpool.name = zpool_get_poolname(zhp); cnf->zpool.ddt_memory = get_dedup_stats(config); } zpool_close(zhp); return 0; }
/* * Open a handle to the given pool, even if the pool is currently in the FAULTED * state. */ zpool_handle_t * zpool_open_canfail(libzfs_handle_t *hdl, const char *pool) { zpool_handle_t *zhp; boolean_t missing; /* * Make sure the pool name is valid. */ if (!zpool_name_valid(hdl, B_TRUE, pool)) { (void) zfs_error(hdl, EZFS_INVALIDNAME, dgettext(TEXT_DOMAIN, "cannot open '%s'"), pool); return (NULL); } if ((zhp = zfs_alloc(hdl, sizeof (zpool_handle_t))) == NULL) return (NULL); zhp->zpool_hdl = hdl; (void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name)); if (zpool_refresh_stats(zhp, &missing) != 0) { zpool_close(zhp); return (NULL); } if (missing) { zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "no such pool")); (void) zfs_error(hdl, EZFS_NOENT, dgettext(TEXT_DOMAIN, "cannot open '%s'"), pool); zpool_close(zhp); return (NULL); } return (zhp); }