Return logs (ZIL) vdev as well in VDevTree
This commit is contained in:
		
							parent
							
								
									08a4903509
								
							
						
					
					
						commit
						f5a73ad14f
					
				| 
						 | 
				
			
			@ -1,2 +1,3 @@
 | 
			
		|||
.gitconfig
 | 
			
		||||
*.sublime-*
 | 
			
		||||
go-libzfs.test
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										14
									
								
								zpool.go
								
								
								
								
							
							
						
						
									
										14
									
								
								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
 | 
			
		||||
		}
 | 
			
		||||
		if islog != C.B_FALSE {
 | 
			
		||||
			vdevs.Logs = &vdev
 | 
			
		||||
		} else {
 | 
			
		||||
			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
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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))
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue