From 768fbf7f229dca1034bc8334bc92b8d646811d5a Mon Sep 17 00:00:00 2001 From: Faruk Kasumovic Date: Mon, 31 Aug 2020 10:56:49 +0200 Subject: [PATCH] Add fetching of GUID in VDevTree --- zpool.c | 6 ++++++ zpool.go | 3 +++ zpool.h | 1 + 3 files changed, 10 insertions(+) diff --git a/zpool.c b/zpool.c index df64295..9a0a48a 100644 --- a/zpool.c +++ b/zpool.c @@ -378,6 +378,12 @@ const char *get_vdev_type(nvlist_ptr nv) { return value; } +uint64_t get_vdev_guid(nvlist_ptr nv) { + uint64_t value = 0; + nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &value); + return value; +} + const vdev_stat_ptr get_vdev_stats(nvlist_ptr nv) { vdev_stat_ptr vs = NULL; uint_t count; diff --git a/zpool.go b/zpool.go index 5b3c784..54672d3 100644 --- a/zpool.go +++ b/zpool.go @@ -115,6 +115,7 @@ type VDevTree struct { Spares []VDevTree L2Cache []VDevTree Logs *VDevTree + GUID uint64 Parity uint Path string Name string @@ -178,6 +179,8 @@ func poolGetConfig(name string, nv C.nvlist_ptr) (vdevs VDevTree, err error) { return } + vdevs.GUID = uint64(C.get_vdev_guid(nv)) + // Fetch vdev state if vs = C.get_vdev_stats(nv); vs == nil { err = fmt.Errorf("Failed to fetch %s", C.ZPOOL_CONFIG_VDEV_STATS) diff --git a/zpool.h b/zpool.h index f37db38..3758e72 100644 --- a/zpool.h +++ b/zpool.h @@ -62,6 +62,7 @@ nvlist_t *nvlist_array_at(nvlist_t **a, uint_t i); int refresh_stats(zpool_list_t *pool); const char *get_vdev_type(nvlist_ptr nv); +uint64_t get_vdev_guid(nvlist_ptr nv); const vdev_stat_ptr get_vdev_stats(nvlist_ptr nv); pool_scan_stat_ptr get_vdev_scan_stats(nvlist_t *nv); vdev_children_ptr get_vdev_children(nvlist_t *nv);