X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/da13bb400f87fdd4157146e2d0b171b730fa3208..2e104941dbf1e4bf92e0632cadeb946be0595d67:/services/keepstore/volume_unix.go diff --git a/services/keepstore/volume_unix.go b/services/keepstore/volume_unix.go index 1c676b12e1..fff02aac26 100644 --- a/services/keepstore/volume_unix.go +++ b/services/keepstore/volume_unix.go @@ -7,7 +7,6 @@ import ( "fmt" "io" "io/ioutil" - "log" "os" "path/filepath" "regexp" @@ -16,6 +15,8 @@ import ( "sync" "syscall" "time" + + log "github.com/Sirupsen/logrus" ) type unixVolumeAdder struct { @@ -183,11 +184,14 @@ func (v *UnixVolume) Mtime(loc string) (time.Time, error) { // Lock the locker (if one is in use), open the file for reading, and // call the given function if and when the file is ready to read. -func (v *UnixVolume) getFunc(path string, fn func(io.Reader) error) error { +func (v *UnixVolume) getFunc(ctx context.Context, path string, fn func(io.Reader) error) error { if v.locker != nil { v.locker.Lock() defer v.locker.Unlock() } + if ctx.Err() != nil { + return ctx.Err() + } f, err := os.Open(path) if err != nil { return err @@ -222,7 +226,7 @@ func (v *UnixVolume) Get(ctx context.Context, loc string, buf []byte) (int, erro } var read int size := int(stat.Size()) - err = v.getFunc(path, func(rdr io.Reader) error { + err = v.getFunc(ctx, path, func(rdr io.Reader) error { read, err = io.ReadFull(rdr, buf[:size]) return err }) @@ -232,13 +236,13 @@ func (v *UnixVolume) Get(ctx context.Context, loc string, buf []byte) (int, erro // Compare returns nil if Get(loc) would return the same content as // expect. It is functionally equivalent to Get() followed by // bytes.Compare(), but uses less memory. -func (v *UnixVolume) Compare(loc string, expect []byte) error { +func (v *UnixVolume) Compare(ctx context.Context, loc string, expect []byte) error { path := v.blockPath(loc) if _, err := v.stat(path); err != nil { return v.translateError(err) } - return v.getFunc(path, func(rdr io.Reader) error { - return compareReaderWithBuf(rdr, expect, loc[:32]) + return v.getFunc(ctx, path, func(rdr io.Reader) error { + return compareReaderWithBuf(ctx, rdr, expect, loc[:32]) }) } @@ -319,7 +323,12 @@ func (v *UnixVolume) Status() *VolumeStatus { // uses fs.Blocks - fs.Bfree. free := fs.Bavail * uint64(fs.Bsize) used := (fs.Blocks - fs.Bfree) * uint64(fs.Bsize) - return &VolumeStatus{v.Root, devnum, free, used} + return &VolumeStatus{ + MountPoint: v.Root, + DeviceNum: devnum, + BytesFree: free, + BytesUsed: used, + } } var blockDirRe = regexp.MustCompile(`^[0-9a-f]+$`)