From 0ecbe891b5147c6be1e3e432f26c02970358c2f7 Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Tue, 12 Aug 2014 17:48:07 -0700 Subject: [PATCH] remove pkg/btrfs --- pkg/btrfs/btrfs_linux.go | 74 ---------------------------------------- pkg/btrfs/btrfs_stubs.go | 17 --------- pkg/btrfs/btrfs_test.go | 31 ----------------- 3 files changed, 122 deletions(-) delete mode 100644 pkg/btrfs/btrfs_linux.go delete mode 100644 pkg/btrfs/btrfs_stubs.go delete mode 100644 pkg/btrfs/btrfs_test.go diff --git a/pkg/btrfs/btrfs_linux.go b/pkg/btrfs/btrfs_linux.go deleted file mode 100644 index f48dd6386..000000000 --- a/pkg/btrfs/btrfs_linux.go +++ /dev/null @@ -1,74 +0,0 @@ -// +build linux,amd64 - -package btrfs - -import ( - "fmt" - "os" - "runtime" - "syscall" - "unsafe" - - "github.com/coreos/etcd/log" -) - -const ( - // from Linux/include/uapi/linux/magic.h - BTRFS_SUPER_MAGIC = 0x9123683E - - // from Linux/include/uapi/linux/fs.h - FS_NOCOW_FL = 0x00800000 - FS_IOC_GETFLAGS = 0x80086601 - FS_IOC_SETFLAGS = 0x40086602 -) - -// IsBtrfs checks whether the file is in btrfs -func IsBtrfs(path string) bool { - // btrfs is linux-only filesystem - // exit on other platforms - if runtime.GOOS != "linux" { - return false - } - var buf syscall.Statfs_t - if err := syscall.Statfs(path, &buf); err != nil { - log.Warnf("Failed to statfs: %v", err) - return false - } - log.Debugf("The type of path %v is %v", path, buf.Type) - if buf.Type != BTRFS_SUPER_MAGIC { - return false - } - log.Infof("The path %v is in btrfs", path) - return true -} - -// SetNOCOWFile sets NOCOW flag for file -func SetNOCOWFile(path string) error { - file, err := os.Open(path) - if err != nil { - return err - } - defer file.Close() - - fileinfo, err := file.Stat() - if err != nil { - return err - } - if fileinfo.IsDir() { - return fmt.Errorf("skip directory") - } - if fileinfo.Size() != 0 { - return fmt.Errorf("skip nonempty file") - } - - var attr int - if _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, file.Fd(), FS_IOC_GETFLAGS, uintptr(unsafe.Pointer(&attr))); errno != 0 { - return errno - } - attr |= FS_NOCOW_FL - if _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, file.Fd(), FS_IOC_SETFLAGS, uintptr(unsafe.Pointer(&attr))); errno != 0 { - return errno - } - log.Infof("Set NOCOW to path %v succeeded", path) - return nil -} diff --git a/pkg/btrfs/btrfs_stubs.go b/pkg/btrfs/btrfs_stubs.go deleted file mode 100644 index 179474738..000000000 --- a/pkg/btrfs/btrfs_stubs.go +++ /dev/null @@ -1,17 +0,0 @@ -// +build !linux !amd64 - -package btrfs - -import ( - "fmt" -) - -// IsBtrfs checks whether the file is in btrfs -func IsBtrfs(path string) bool { - return false -} - -// SetNOCOWFile sets NOCOW flag for file -func SetNOCOWFile(path string) error { - return fmt.Errorf("unsupported for the platform") -} diff --git a/pkg/btrfs/btrfs_test.go b/pkg/btrfs/btrfs_test.go deleted file mode 100644 index b841aa370..000000000 --- a/pkg/btrfs/btrfs_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package btrfs - -import ( - "io/ioutil" - "os" - "os/exec" - "strings" - "testing" -) - -func TestSetNOCOW(t *testing.T) { - f, err := ioutil.TempFile(".", "etcdtest") - if err != nil { - t.Fatal("Failed creating temp dir") - } - name := f.Name() - f.Close() - defer os.Remove(name) - - if IsBtrfs(name) { - SetNOCOWFile(name) - cmd := exec.Command("lsattr", name) - out, err := cmd.Output() - if err != nil { - t.Fatal("Failed executing lsattr") - } - if !strings.Contains(string(out), "---------------C") { - t.Fatal("Failed setting NOCOW:\n", string(out)) - } - } -}