- Improvements on properties, state and status handling of pool and dataset
This commit is contained in:
parent
1d6e6a86cb
commit
c1288a9a2e
|
@ -13,6 +13,8 @@ func Test(t *testing.T) {
|
||||||
zpoolTestImport(t)
|
zpoolTestImport(t)
|
||||||
zpoolTestExportForce(t)
|
zpoolTestExportForce(t)
|
||||||
zpoolTestImport(t)
|
zpoolTestImport(t)
|
||||||
|
zpoolTestPoolProp(t)
|
||||||
|
zpoolTestPoolStatusAndState(t)
|
||||||
zpoolTestPoolOpenAll(t)
|
zpoolTestPoolOpenAll(t)
|
||||||
zpoolTestFailPoolOpen(t)
|
zpoolTestFailPoolOpen(t)
|
||||||
|
|
||||||
|
|
6
zfs.go
6
zfs.go
|
@ -266,6 +266,10 @@ func (d *Dataset) SetProperty(p ZFSProp, value string) (err error) {
|
||||||
if errcode != 0 {
|
if errcode != 0 {
|
||||||
err = LastError()
|
err = LastError()
|
||||||
}
|
}
|
||||||
|
// Update Properties member with change made
|
||||||
|
if _, err = d.GetProperty(p); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,7 +402,7 @@ func (d *Dataset) UnmountAll(flags int) (err error) {
|
||||||
// ( returns built in string representation of property name).
|
// ( returns built in string representation of property name).
|
||||||
// This is optional, you can represent each property with string
|
// This is optional, you can represent each property with string
|
||||||
// name of choice.
|
// name of choice.
|
||||||
func (d *Dataset) PropertyToName(p ZFSProp) (name string) {
|
func DatasetPropertyToName(p ZFSProp) (name string) {
|
||||||
if p == ZFSNumProps {
|
if p == ZFSNumProps {
|
||||||
return "numofprops"
|
return "numofprops"
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,7 +164,7 @@ func ExampleDatasetOpen() {
|
||||||
if p, err = d.GetProperty(zfs.ZFSPropAvailable); err != nil {
|
if p, err = d.GetProperty(zfs.ZFSPropAvailable); err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
println(d.PropertyToName(zfs.ZFSPropAvailable), " = ", p.Value)
|
println(zfs.DatasetPropertyToName(zfs.ZFSPropAvailable), " = ", p.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleDatasetOpenAll() {
|
func ExampleDatasetOpenAll() {
|
||||||
|
|
12
zpool.go
12
zpool.go
|
@ -127,7 +127,7 @@ func PoolCloseAll(pools []Pool) {
|
||||||
// ( returns built in string representation of property name).
|
// ( returns built in string representation of property name).
|
||||||
// This is optional, you can represent each property with string
|
// This is optional, you can represent each property with string
|
||||||
// name of choice.
|
// name of choice.
|
||||||
func (pool *Pool) PropertyToName(p PoolProp) (name string) {
|
func PoolPropertyToName(p PoolProp) (name string) {
|
||||||
if p == PoolNumProps {
|
if p == PoolNumProps {
|
||||||
return "numofprops"
|
return "numofprops"
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ func (pool *Pool) GetProperty(p PoolProp) (prop Property, err error) {
|
||||||
// First check if property exist at all
|
// First check if property exist at all
|
||||||
if p < PoolPropName || p > PoolNumProps {
|
if p < PoolPropName || p > PoolNumProps {
|
||||||
err = errors.New(fmt.Sprint("Unknown zpool property: ",
|
err = errors.New(fmt.Sprint("Unknown zpool property: ",
|
||||||
pool.PropertyToName(p)))
|
PoolPropertyToName(p)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var list C.property_list_t
|
var list C.property_list_t
|
||||||
|
@ -210,15 +210,17 @@ func (pool *Pool) SetProperty(p PoolProp, value string) (err error) {
|
||||||
// First check if property exist at all
|
// First check if property exist at all
|
||||||
if p < PoolPropName || p > PoolNumProps {
|
if p < PoolPropName || p > PoolNumProps {
|
||||||
err = errors.New(fmt.Sprint("Unknown zpool property: ",
|
err = errors.New(fmt.Sprint("Unknown zpool property: ",
|
||||||
pool.PropertyToName(p)))
|
PoolPropertyToName(p)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r := C.zpool_set_prop(pool.list.zph, C.CString(pool.PropertyToName(p)), C.CString(value))
|
r := C.zpool_set_prop(pool.list.zph, C.CString(PoolPropertyToName(p)), C.CString(value))
|
||||||
if r != 0 {
|
if r != 0 {
|
||||||
err = LastError()
|
err = LastError()
|
||||||
} else {
|
} else {
|
||||||
// Update Properties member with change made
|
// Update Properties member with change made
|
||||||
_, err = pool.GetProperty(p)
|
if _, err = pool.GetProperty(p); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,6 +208,59 @@ func zpoolTestImport(t *testing.T) {
|
||||||
println("PASS\n")
|
println("PASS\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func zpoolTestPoolProp(t *testing.T) {
|
||||||
|
println("TEST PoolProp on ", TST_POOL_NAME, " ... ")
|
||||||
|
if pool, err := zfs.PoolOpen(TST_POOL_NAME); err == nil {
|
||||||
|
defer pool.Close()
|
||||||
|
// Turn on snapshot listing for pool
|
||||||
|
pool.SetProperty(zfs.PoolPropListsnaps, "on")
|
||||||
|
// Verify change is succesfull
|
||||||
|
if pool.Properties[zfs.PoolPropListsnaps].Value != "on" {
|
||||||
|
t.Error(fmt.Errorf("Update of pool property failed"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test fetching property
|
||||||
|
_, err := pool.GetProperty(zfs.PoolPropHealth)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetch all properties
|
||||||
|
if err = pool.ReloadProperties(); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
println("PASS\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func zpoolTestPoolStatusAndState(t *testing.T) {
|
||||||
|
println("TEST pool Status/State ( ", TST_POOL_NAME, " ) ... ")
|
||||||
|
pool, err := zfs.PoolOpen(TST_POOL_NAME)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer pool.Close()
|
||||||
|
|
||||||
|
if _, err = pool.Status(); err != nil {
|
||||||
|
t.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = pool.State(); err != nil {
|
||||||
|
t.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
println("PASS\n")
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
// EXAMPLES:
|
// EXAMPLES:
|
||||||
|
|
||||||
|
@ -216,6 +269,15 @@ func ExamplePoolProp() {
|
||||||
print("Pool size is: ", pool.Properties[zfs.PoolPropSize].Value)
|
print("Pool size is: ", pool.Properties[zfs.PoolPropSize].Value)
|
||||||
// Turn on snapshot listing for pool
|
// Turn on snapshot listing for pool
|
||||||
pool.SetProperty(zfs.PoolPropListsnaps, "on")
|
pool.SetProperty(zfs.PoolPropListsnaps, "on")
|
||||||
|
println("Changed property",
|
||||||
|
zfs.PoolPropertyToName(zfs.PoolPropListsnaps), "to value:",
|
||||||
|
pool.Properties[zfs.PoolPropListsnaps].Value)
|
||||||
|
|
||||||
|
prop, err := pool.GetProperty(zfs.PoolPropHealth)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
println("Update and print out pool health:", prop.Value)
|
||||||
} else {
|
} else {
|
||||||
print("Error: ", err)
|
print("Error: ", err)
|
||||||
}
|
}
|
||||||
|
@ -244,7 +306,8 @@ func ExamplePoolOpenAll() {
|
||||||
if pkey == zfs.PoolPropName {
|
if pkey == zfs.PoolPropName {
|
||||||
continue // Skip name its already printed above
|
continue // Skip name its already printed above
|
||||||
}
|
}
|
||||||
fmt.Printf("|%14s | %20s | %15s |\n", p.PropertyToName(pkey),
|
fmt.Printf("|%14s | %20s | %15s |\n",
|
||||||
|
zfs.PoolPropertyToName(pkey),
|
||||||
prop.Value, prop.Source)
|
prop.Value, prop.Source)
|
||||||
println("")
|
println("")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue