mistifyio / go-zfs

Go wrappers for ZFS commands
Apache License 2.0
128 stars 66 forks source link

Ability to create sparse voumes #77

Open mateuszkwiatkowski opened 3 years ago

mateuszkwiatkowski commented 3 years ago

Hello, I'd like to be able to create sparse volumes using this library. To do that with zfs command one need to specify -s flag so a function like this would work (it's just a copy of CreateVolume with additional flag in args[2]):

// CreateVolume creates a new ZFS volume with the specified name, size, and
// properties.
// A full list of available ZFS properties may be found here:
// https://www.freebsd.org/cgi/man.cgi?zfs(8).
func CreateSparseVolume(name string, size uint64, properties map[string]string) (*Dataset, error) {
    args := make([]string, 4, 5)
    args[0] = "create"
    args[1] = "-p"
    args[2] = "-sV"
    args[3] = strconv.FormatUint(size, 10)
    if properties != nil {
        args = append(args, propsSlice(properties)...)
    }
    args = append(args, name)
    _, err := zfs(args...)
    if err != nil {
        return nil, err
    }
    return GetDataset(name)
}