From f5a73ad14f12b221060b69662dc25eede342dcca Mon Sep 17 00:00:00 2001 From: Faruk Kasumovic Date: Wed, 28 Mar 2018 10:24:47 +0200 Subject: [PATCH] Return logs (ZIL) vdev as well in VDevTree --- .gitignore | 1 + zpool.go | 18 +++++++----------- zpool_test.go | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index cf468c9..1fcc717 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .gitconfig *.sublime-* +go-libzfs.test diff --git a/zpool.go b/zpool.go index 9a6fba1..7a3f547 100644 --- a/zpool.go +++ b/zpool.go @@ -103,7 +103,7 @@ type VDevTree struct { Devices []VDevTree // groups other devices (e.g. mirror) Spares []VDevTree L2Cache []VDevTree - Logs []VDevTree + Logs *VDevTree Parity uint Path string Name string @@ -222,9 +222,7 @@ func poolGetConfig(name string, nv C.nvlist_ptr) (vdevs VDevTree, err error) { var islog = C.uint64_t(C.B_FALSE) islog = C.get_vdev_is_log(C.nvlist_array_at(children.first, c)) - if islog != C.B_FALSE { - continue - } + vname := C.zpool_vdev_name(C.libzfsHandle, nil, C.nvlist_array_at(children.first, c), C.B_TRUE) var vdev VDevTree @@ -234,13 +232,11 @@ func poolGetConfig(name string, nv C.nvlist_ptr) (vdevs VDevTree, err error) { if err != nil { return } - vdevs.Devices = append(vdevs.Devices, vdev) - } - if vdevs.Spares, err = poolGetSpares(name, nv); err != nil { - return - } - if vdevs.L2Cache, err = poolGetL2Cache(name, nv); err != nil { - return + if islog != C.B_FALSE { + vdevs.Logs = &vdev + } else { + vdevs.Devices = append(vdevs.Devices, vdev) + } } return } diff --git a/zpool_test.go b/zpool_test.go index 8740d7b..3ea75eb 100644 --- a/zpool_test.go +++ b/zpool_test.go @@ -1,6 +1,7 @@ package zfs_test import ( + "encoding/json" "fmt" "io/ioutil" "os" @@ -529,3 +530,34 @@ func ExamplePool_State() { } println("POOL TESTPOOL state:", zfs.PoolStateToName(pstate)) } + +func TestPool_VDevTree(t *testing.T) { + type fields struct { + poolName string + } + tests := []struct { + name string + fields fields + wantErr bool + }{ + // TODO: Add test cases. + { + name: "test1", + fields: fields{"NETSTOR"}, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + pool, _ := zfs.PoolOpen(tt.fields.poolName) + defer pool.Close() + gotVdevs, err := pool.VDevTree() + if (err != nil) != tt.wantErr { + t.Errorf("Pool.VDevTree() error = %v, wantErr %v", err, tt.wantErr) + return + } + jsonData, _ := json.MarshalIndent(gotVdevs, "", "\t") + t.Logf("gotVdevs: %s", string(jsonData)) + }) + } +}