X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/90198dc6c008ca60889dd4ef5f5def8dd272df82..910a5f7a8b4c1286beaae0c7c8c45ec092aec28a:/services/keepstore/volume_unix.go diff --git a/services/keepstore/volume_unix.go b/services/keepstore/volume_unix.go index 84877c0034..20bc9c50af 100644 --- a/services/keepstore/volume_unix.go +++ b/services/keepstore/volume_unix.go @@ -50,8 +50,9 @@ type IOResponse struct { // request. // type UnixVolume struct { - root string // path to this volume - queue chan *IORequest + root string // path to this volume + queue chan *IORequest + readonly bool } func (v *UnixVolume) IOHandler() { @@ -67,14 +68,17 @@ func (v *UnixVolume) IOHandler() { } } -func MakeUnixVolume(root string, serialize bool) (v UnixVolume) { +func MakeUnixVolume(root string, serialize bool, readonly bool) *UnixVolume { + v := &UnixVolume{ + root: root, + queue: nil, + readonly: readonly, + } if serialize { - v = UnixVolume{root, make(chan *IORequest)} + v.queue =make(chan *IORequest) go v.IOHandler() - } else { - v = UnixVolume{root, nil} } - return + return v } func (v *UnixVolume) Get(loc string) ([]byte, error) { @@ -88,6 +92,9 @@ func (v *UnixVolume) Get(loc string) ([]byte, error) { } func (v *UnixVolume) Put(loc string, block []byte) error { + if v.readonly { + return MethodDisabledError + } if v.queue == nil { return v.Write(loc, block) } @@ -98,6 +105,9 @@ func (v *UnixVolume) Put(loc string, block []byte) error { } func (v *UnixVolume) Touch(loc string) error { + if v.readonly { + return MethodDisabledError + } p := v.blockPath(loc) f, err := os.OpenFile(p, os.O_RDWR|os.O_APPEND, 0644) if err != nil { @@ -263,6 +273,9 @@ func (v *UnixVolume) Delete(loc string) error { // Delete() will read the correct up-to-date timestamp and choose not to // delete the file. + if v.readonly { + return MethodDisabledError + } p := v.blockPath(loc) f, err := os.OpenFile(p, os.O_RDWR|os.O_APPEND, 0644) if err != nil { @@ -350,6 +363,10 @@ func (v *UnixVolume) String() string { return fmt.Sprintf("[UnixVolume %s]", v.root) } +func (v *UnixVolume) Writable() bool { + return !v.readonly +} + // lockfile and unlockfile use flock(2) to manage kernel file locks. func lockfile(f *os.File) error { return syscall.Flock(int(f.Fd()), syscall.LOCK_EX)