From 5512e10b5778f41800eed7fc0f1779e375e71f19 Mon Sep 17 00:00:00 2001 From: Ben McClelland Date: Mon, 28 Feb 2022 21:29:00 -0800 Subject: [PATCH] add release blocks --- scoutfs.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scoutfs.go b/scoutfs.go index ea02cbb..6dfa9b7 100644 --- a/scoutfs.go +++ b/scoutfs.go @@ -313,6 +313,31 @@ func roundUp(size, bs uint64) uint64 { return ((size / bs) * bs) + bs } +// ReleaseBlocks marks blocks offline and frees associated extents +// offset/length must be 4k aligned +func ReleaseBlocks(path string, offset, length, version uint64) error { + f, err := os.OpenFile(path, os.O_WRONLY, 0) + if err != nil { + return err + } + defer f.Close() + + return FReleaseBlocks(f, offset, length, version) +} + +// FReleaseBlocks marks blocks offline and frees associated extents +// offset/length must be 4k aligned +func FReleaseBlocks(f *os.File, offset, length, version uint64) error { + r := iocRelease{ + Offset: offset, + Length: length, + Version: version, + } + + _, err := scoutfsctl(f, IOCRELEASE, unsafe.Pointer(&r)) + return err +} + // StageFile rehydrates offline file func StageFile(path string, version, offset uint64, b []byte) (int, error) { f, err := os.OpenFile(path, os.O_WRONLY, 0)