10383: Merge branch 'master' into 10383-arv-put-incremental-upload
[arvados.git] / services / keepstore / volume_unix.go
index 1c676b12e1b99dc5569c789304e2ee2976fadec6..fff02aac260f59a6fc46fc24cbebea57b27e5743 100644 (file)
@@ -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]+$`)