Go to file
Faruk Kasumovic 039b070d1a - Prevent double-free failure when the same dataset is closed multiple times
In some cases, copying dataset object, either by passing by value or in
some other pattern can lead to code that will close the same dataset
multiple times (e.g. defer). Or otherwise, code with complicated
handling of dataset cleanup.
Fixes: #30, Closes: #31
2020-09-09 10:22:37 +02: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 README update 2018-11-09 19:41:37 +01:00
a_test.go - Prevent double-free failure when the same dataset is closed multiple times 2020-09-09 10:22:37 +02:00
common.c Change how properties single linked list is released from memory 2019-03-07 18:55:59 +01:00
common.go Error constants: fix typo, add as per libzfs.h 0.8.2 (#27) 2020-08-18 16:06:32 +02:00
common.h Changes to build on musl/alpine 2018-11-15 21:58:33 +01:00
destroy_test.go - Prevent double-free failure when the same dataset is closed multiple times 2020-09-09 10:22:37 +02:00
go.mod - Make SendOne compatible with libzfs 0.8 2019-12-20 10:09:00 +01:00
sendrecv.go - Unpack resume information from resume token to go structure ResumeToken 2020-07-16 13:34:14 +02:00
sort.go DestroyPromote - recursive destroy dataset, but don’t destroy any dependent clones, promote them first 2018-12-17 14:01:59 +01:00
zfs.c - Fixed memory leak in dataset_list_callb 2020-01-30 16:27:53 +01:00
zfs.go - Prevent double-free failure when the same dataset is closed multiple times 2020-09-09 10:22:37 +02:00
zfs.h - Small fixes 2017-12-07 09:54:07 +01:00
zfs_test.go - Prevent double-free failure when the same dataset is closed multiple times 2020-09-09 10:22:37 +02:00
zpool.c Add fetching of GUID in VDevTree 2020-08-31 10:56:49 +02:00
zpool.go Add fetching of GUID in VDevTree 2020-08-31 10:56:49 +02:00
zpool.h Add fetching of GUID in VDevTree 2020-08-31 10:56:49 +02:00
zpool_test.go - Prevent double-free failure when the same dataset is closed multiple times 2020-09-09 10:22:37 +02:00
zpool_vdev.c Changes to build on musl/alpine 2018-11-15 21:58:33 +01:00
zpool_vdev.go - Fixed memory leak in zpool_vded.Clear 2020-02-03 10:56:20 +00: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. 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.

Note

This golang package is only used and tested on Linux.

  • Version tagged as v0.1 is latest used and compatible with ZFS On Linux version 0.6.5.x
  • Version tagged as v0.2 is latest used and compatible with ZFS On Linux version 0.7.x

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.
  • Send and receive snapshot streams

Requirements:

  • OpenZFS on Linux and libzfs with development headers installed.
  • Developed using go1.9

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.