Go to file
Faruk Kasumovic db4703b708 - Add properties from libzfs in 0.6.5 version 2015-10-28 11:00:08 +01:00
.gitignore - Make dataset destroy returns meaningful error if dataset contains children 2015-06-03 23:39:46 +02:00
LICENSE.md Update LICENSE.md 2015-06-04 00:05:13 +02:00
README.md - More updates to README to reflect change of project location 2015-04-20 10:55:04 +02:00
a_test.go - Improvements on properties, state and status handling of pool and dataset 2015-06-09 14:26:35 +02:00
common.go - Add properties from libzfs in 0.6.5 version 2015-10-28 11:00:08 +01:00
zfs.c - Starting from here, already useful initial implementation :-) 2015-04-19 23:26:54 +02:00
zfs.go - Improvements on properties, state and status handling of pool and dataset 2015-06-09 14:26:35 +02:00
zfs.h - Starting from here, already useful initial implementation :-) 2015-04-19 23:26:54 +02:00
zfs_test.go - Improvements on properties, state and status handling of pool and dataset 2015-06-09 14:26:35 +02:00
zpool.c - Starting from here, already useful initial implementation :-) 2015-04-19 23:26:54 +02:00
zpool.go - Pretty much completed set of examples and tests on 'pool' APIs implemented so far 2015-06-11 00:51:46 +02:00
zpool.h - Starting from here, already useful initial implementation :-) 2015-04-19 23:26:54 +02:00
zpool_test.go - Pretty much completed set of examples and tests on 'pool' APIs implemented so far 2015-06-11 00:51:46 +02:00

README.md

Introduction

go-libzfs currently implements basic manipulation of ZFS pools and data sets. Plan is to add more in further development, improve documentation with more examples, and add more tests. go-libzfs use libzfs C library and does not wrap OpenZFS CLI tools. That way it ensure best performance. Per my personal opinion its more reliable way to do it, and that libzfs is less subject of possible changes then CLI tools. Goal is to let easy using and manipulating OpenZFS form with in go, and tries to map libzfs C library in to go style package respecting golang common practice.

GoDoc

Main features

  • Creating, destroying, importing and exporting pools.
  • Reading and modifying pool properties.
  • Creating, destroying and renaming of filesystem datasets and volumes.
  • Creating, destroying and rollback of snapshots.
  • Cloning datasets and volumes.
  • Reading and modifying dataset and volume properties.

Requirements:

  • OpenZFS and libzfs with development headers installed.
  • Developed using go1.4.2

Installing

go get github.com/bicomsystems/go-libzfs

Testing

# On command line shell run
cd $GOPATH/src/github.com/bicomsystems/go-libzfs
go test

Usage example

// Create map to represent ZFS dataset properties. This is equivalent to
// list of properties you can get from ZFS CLI tool, and some more
// internally used by libzfs.
props := make(map[ZFSProp]Property)

// I choose to create (block) volume 1GiB in size. Size is just ZFS dataset
// property and this is done as map of strings. So, You have to either
// specify size as base 10 number in string, or use strconv package or
// similar to convert in to string (base 10) from numeric type.
strSize := "1073741824"

props[ZFSPropVolsize] = Property{Value: strSize}
// In addition I explicitly choose some more properties to be set.
props[ZFSPropVolblocksize] = Property{Value: "4096"}
props[ZFSPropReservation] = Property{Value: strSize}

// Lets create desired volume
d, err := DatasetCreate("TESTPOOL/VOLUME1", DatasetTypeVolume, props)
if err != nil {
	println(err.Error())
	return
}
// Dataset have to be closed for memory cleanup
defer d.Close()

println("Created zfs volume TESTPOOL/VOLUME1")

Special thanks to

  • Bicom Systems for supporting this little project and that way making it possible.
  • OpenZFS as the main ZFS software collective.