Skip to content
Permalink
Browse files

upspinfs: use client.PutSequenced.

Change-Id: If2a6cd37d9c3533ece23b35c673196e2c0f54169
Reviewed-on: https://upspin-review.googlesource.com/c/upspin/+/19540
Reviewed-by: David Presotto <presotto@gmail.com>
  • Loading branch information
presotto committed Dec 23, 2019
1 parent 155e6ef commit 000a6b9e74c6444c2ac296d8657adc2808a4a83c
Showing with 18 additions and 5 deletions.
  1. +15 −4 cmd/upspinfs/cache.go
  2. +3 −1 cmd/upspinfs/errors_unix.go
@@ -119,7 +119,8 @@ func (c *cache) mkTemp() string {
return filepath.Join(c.dir, fmt.Sprintf("tmp/%d", next))
}

// create creates a file in the cache.
// create creates a file in the cache. This file will not be added to the cache LRU
// until close & writeback.
// The corresponding node should be locked.
func (c *cache) create(h *handle) error {
const op errors.Op = "cache.create"
@@ -135,6 +136,13 @@ func (c *cache) create(h *handle) error {
}
h.n.cf = cf
cf.n = h.n

// create is only called in response to a Create request from FUSE. FUSE
// only sends Create requests when it believes the file doesn't exist so
// set the sequence for this file to SeqNotExist thus conditioning writeback
// succeeding on none else having created the file in the mean time.
h.n.seq = upspin.SeqNotExist

return nil
}

@@ -176,14 +184,16 @@ func (c *cache) open(h *handle, flags fuse.OpenFlags) error {
c.lruBytes -= cf.cachedSize
c.Unlock()

// Is it the right version and can we open it?
if cf.de.Sequence == entry.Sequence {
// Is it the right version and can we open it? cf.de is nil if the cached file
// never got committed to the DirServer.
if cf.de != nil && cf.de.Sequence == entry.Sequence {
cf.file, err = os.OpenFile(cf.fname, os.O_RDWR, cachedFilePerms)
if err == nil {
h.flags = flags
n.cf = cf
cf.n = n
n.attr.Size = uint64(cf.size)
h.n.seq = entry.Sequence
return nil
}
}
@@ -201,6 +211,7 @@ func (c *cache) open(h *handle, flags fuse.OpenFlags) error {
n: n,
fname: fname,
}
h.n.seq = entry.Sequence

// Invalidate the kernel cache, this is a new version.
n.f.watched.invalidateChan <- n
@@ -550,7 +561,7 @@ func (cf *cachedFile) writeback(n *node) error {
// Use the client library to write it back. Try multiple times on error.
var de *upspin.DirEntry
for tries := 0; ; tries++ {
de, err = cf.c.client.Put(n.uname, cleartext)
de, err = cf.c.client.PutSequenced(n.uname, n.seq, cleartext)
if err == nil {
n.seq = de.Sequence
cf.attachDirEntry(n.f.config, de, true)
@@ -39,6 +39,7 @@ var errs = []struct {
{"no such", syscall.ENOENT},
{"permission", syscall.EPERM},
{"not empty", syscall.ENOTEMPTY},
{"sequence number", syscall.EEXIST},
}

var errnoToKind = map[syscall.Errno]errors.Kind{
@@ -73,7 +74,8 @@ func e2e(err error) *errnoError {
if e, ok := kindToErrno[ue.Kind]; ok {
errno = e
}
} else {
}
if errno == syscall.EIO {
for _, e := range errs {
if strings.Contains(err.Error(), e.str) {
errno = e.errno

0 comments on commit 000a6b9

Please sign in to comment.
You can’t perform that action at this time.