jhixson74 / go-libzfs

go language link to libzfs C library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

build workflow PkgGoDev Chat

ZFS On Linux compatibility

  • Version tagged as v2.22. is compatible with ZOL version 2.2.

Installing

go get github.com/kraudcloud/go-libzfs/v2

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")

Testing

docker buildx build --progress=plain -f ci.Dockerfile . -t zz
docker run --privileged --shm-size=4G zz

Special thanks to

this was forked from the original work by bicomsystems

About

go language link to libzfs C library

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Go 76.4%Language:C 22.5%Language:Dockerfile 0.6%Language:Shell 0.5%