Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Successfully build go-zfs and added a sample #1

Open
wants to merge 2 commits into
base: qct-master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions examples/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"fmt"
"os"
"github.com/RealImage/go-libzfs"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

give blank line above to separate builtin and external packages.

)

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))
}
3 changes: 2 additions & 1 deletion zfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down