Go to file
Faruk Kasumovic 6d3c5e3bd4 Prevent race condition on zfs-linux internal implementation of access to mnttab 2018-11-09 16:08:20 +01:00
.gitignore Return logs (ZIL) vdev as well in VDevTree 2018-03-28 10:24:47 +02:00
LICENSE.md Update LICENSE.md 2015-06-04 00:05:13 +02:00
README.md - Changes to make library interface more clear and to better suit go package standards 2015-12-04 23:05:19 +01:00
a_test.go Functions to set hold, release and list user references on snapshots 2018-11-02 11:15:55 +01:00
common.c - Fix issue not building on go 1.8 , and some more improvements 2017-06-02 08:42:14 +02:00
common.go Additional compatibility changes to work with libzfs 0.7.x 2018-08-06 10:35:39 +02:00
common.h - Fix issue not building on go 1.8 , and some more improvements 2017-06-02 08:42:14 +02:00
sendrecv.go Fix problem with from snapshot name interpretation on incremental syncs 2018-08-15 20:23:12 +02:00
zfs.c Estimate snapshot send size 2018-08-06 10:35:39 +02:00
zfs.go Prevent race condition on zfs-linux internal implementation of access to mnttab 2018-11-09 16:08:20 +01:00
zfs.h - Small fixes 2017-12-07 09:54:07 +01:00
zfs_test.go Functions to set hold, release and list user references on snapshots 2018-11-02 11:15:55 +01:00
zpool.c Port to zfs-0.7.x 2018-08-06 10:35:39 +02:00
zpool.go Merge branch 'dev-zfs-0.6.5.x' into dev-zfs-0.7.x 2018-08-06 14:54:47 +02:00
zpool.h zpool online, offline and clear devices 2018-06-26 14:01:39 +02:00
zpool_test.go Functions to set hold, release and list user references on snapshots 2018-11-02 11:15:55 +01:00
zpool_vdev.c zpool online, offline and clear devices 2018-06-26 14:01:39 +02:00
zpool_vdev.go zpool online, offline and clear devices 2018-06-26 14:01:39 +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[DatasetPropVolsize] = Property{Value: strSize}
// In addition I explicitly choose some more properties to be set.
props[DatasetPropVolblocksize] = Property{Value: "4096"}
props[DatasetPropReservation] = 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.