From 5af530e9d8c1536dc6173471cb957a19b3f0cc6a Mon Sep 17 00:00:00 2001 From: Raja Bose C Leo M Date: Mon, 10 Jul 2017 17:34:55 +0530 Subject: [PATCH 1/2] Successfully build go-zfs and added a sample --- examples/status.go | 39 +++++++++++++++++++++++++++++++++++++++ zfs.c | 3 ++- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 examples/status.go diff --git a/examples/status.go b/examples/status.go new file mode 100644 index 0000000..05498af --- /dev/null +++ b/examples/status.go @@ -0,0 +1,39 @@ +package main + +import ( + "fmt" + "os" + "github.com/RealImage/go-libzfs" +) + +func main () { + poolName := os.Args[1] + fmt.Println("Trying to open pool having name " + poolName) + + pool, err := zfs.PoolOpen(poolName) + if err != nil { + fmt.Println("Failed to open pool: " + err.Error()) + return + } + + defer pool.Close() + + status, err := pool.Status() + if err != nil { + fmt.Println("Failed to get status: " + err.Error()) + return + } + + if status != zfs.PoolStatusOk { + fmt.Println("Zpool status failed with code: " + string(status)) + return + } + + state, err := pool.State() + if err != nil { + fmt.Println("Failed to get Zpool state: " + err.Error()) + return + } + + fmt.Println("Zpool state: " + zfs.PoolStateToName(state)) +} diff --git a/zfs.c b/zfs.c index 9089392..43e0afe 100644 --- a/zfs.c +++ b/zfs.c @@ -10,6 +10,7 @@ #include "zpool.h" #include "zfs.h" +#define verify(EX) ((void)(EX)) dataset_list_t *create_dataset_list_item() { dataset_list_t *zlist = malloc(sizeof(dataset_list_t)); @@ -99,7 +100,7 @@ int read_user_property(zfs_handle_t *zh, property_list_t *list, const char *prop char *strval; char *sourceval; // char source[ZFS_MAX_DATASET_NAME_LEN]; - + if (nvlist_lookup_nvlist(user_props, prop, &propval) != 0) { sourcetype = ZPROP_SRC_NONE; From e3d40a6040c521ddd396a835c7660d142e6370ef Mon Sep 17 00:00:00 2001 From: Raja Bose C Leo M Date: Tue, 11 Jul 2017 09:57:11 +0530 Subject: [PATCH 2/2] Updated code as per review comments --- examples/status.go | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/status.go b/examples/status.go index 05498af..c413db8 100644 --- a/examples/status.go +++ b/examples/status.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "github.com/RealImage/go-libzfs" )