Expose zpool guids through kstats
There are times when end-users may wish to have a fast and convenient method to get zpool guid without having to use libzfs. This commit exposes the zpool guid via kstats in similar manner to the zpool state. Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Andrew Walker <awalker@ixsystems.com> Closes #13466
This commit is contained in:
parent
c0cf6ed679
commit
00ac77464e
|
@ -898,6 +898,7 @@ typedef struct spa_stats {
|
|||
spa_history_kstat_t tx_assign_histogram;
|
||||
spa_history_list_t mmp_history;
|
||||
spa_history_kstat_t state; /* pool state */
|
||||
spa_history_kstat_t guid; /* pool guid */
|
||||
spa_history_kstat_t iostats;
|
||||
} spa_stats_t;
|
||||
|
||||
|
|
|
@ -819,6 +819,41 @@ spa_state_init(spa_t *spa)
|
|||
kmem_strfree(name);
|
||||
}
|
||||
|
||||
static int
|
||||
spa_guid_data(char *buf, size_t size, void *data)
|
||||
{
|
||||
spa_t *spa = (spa_t *)data;
|
||||
(void) snprintf(buf, size, "%llu\n", (u_longlong_t)spa_guid(spa));
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
spa_guid_init(spa_t *spa)
|
||||
{
|
||||
spa_history_kstat_t *shk = &spa->spa_stats.guid;
|
||||
char *name;
|
||||
kstat_t *ksp;
|
||||
|
||||
mutex_init(&shk->lock, NULL, MUTEX_DEFAULT, NULL);
|
||||
|
||||
name = kmem_asprintf("zfs/%s", spa_name(spa));
|
||||
|
||||
ksp = kstat_create(name, 0, "guid", "misc",
|
||||
KSTAT_TYPE_RAW, 0, KSTAT_FLAG_VIRTUAL);
|
||||
|
||||
shk->kstat = ksp;
|
||||
if (ksp) {
|
||||
ksp->ks_lock = &shk->lock;
|
||||
ksp->ks_data = NULL;
|
||||
ksp->ks_private = spa;
|
||||
ksp->ks_flags |= KSTAT_FLAG_NO_HEADERS;
|
||||
kstat_set_raw_ops(ksp, NULL, spa_guid_data, spa_state_addr);
|
||||
kstat_install(ksp);
|
||||
}
|
||||
|
||||
kmem_strfree(name);
|
||||
}
|
||||
|
||||
static void
|
||||
spa_health_destroy(spa_t *spa)
|
||||
{
|
||||
|
@ -830,6 +865,17 @@ spa_health_destroy(spa_t *spa)
|
|||
mutex_destroy(&shk->lock);
|
||||
}
|
||||
|
||||
static void
|
||||
spa_guid_destroy(spa_t *spa)
|
||||
{
|
||||
spa_history_kstat_t *shk = &spa->spa_stats.guid;
|
||||
kstat_t *ksp = shk->kstat;
|
||||
if (ksp)
|
||||
kstat_delete(ksp);
|
||||
|
||||
mutex_destroy(&shk->lock);
|
||||
}
|
||||
|
||||
static const spa_iostats_t spa_iostats_template = {
|
||||
{ "trim_extents_written", KSTAT_DATA_UINT64 },
|
||||
{ "trim_bytes_written", KSTAT_DATA_UINT64 },
|
||||
|
@ -950,6 +996,7 @@ spa_stats_init(spa_t *spa)
|
|||
spa_tx_assign_init(spa);
|
||||
spa_mmp_history_init(spa);
|
||||
spa_state_init(spa);
|
||||
spa_guid_init(spa);
|
||||
spa_iostats_init(spa);
|
||||
}
|
||||
|
||||
|
@ -962,6 +1009,7 @@ spa_stats_destroy(spa_t *spa)
|
|||
spa_txg_history_destroy(spa);
|
||||
spa_read_history_destroy(spa);
|
||||
spa_mmp_history_destroy(spa);
|
||||
spa_guid_destroy(spa);
|
||||
}
|
||||
|
||||
ZFS_MODULE_PARAM(zfs, zfs_, read_history, INT, ZMOD_RW,
|
||||
|
|
Loading…
Reference in New Issue