Skip to content

Commit 4e35b70

Browse files
committed
Alternate implementation of GetLock
1 parent 96b6b2e commit 4e35b70

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

pkg/storage/fs/cephfs/cephfs.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -700,14 +700,25 @@ func (fs *cephfs) GetLock(ctx context.Context, ref *provider.Reference) (*provid
700700
return nil, getRevaError(err)
701701
}
702702

703+
// prepare the metadata
703704
var l *provider.Lock
705+
buf, errXattr := cv.mount.GetXattr(path, xattrLock)
706+
if errXattr == nil {
707+
if l, err = decodeLock(string(buf)); err != nil {
708+
return nil, errors.Wrap(err, "cephfs: malformed lock payload")
709+
}
710+
}
711+
704712
user.op(func(cv *cacheVal) {
705713
var file *goceph.File
706714
defer closeFile(file)
707715
if file, err = cv.mount.Open(path, os.O_RDWR, fs.conf.FilePerms); err != nil {
708-
// TODO(lopresti) if user has read-only permissions, here we fail because
709-
// we want to try and grab a lock to probe if a lock existed. Alternatively,
710-
// we could just return the metadata if present.
716+
// try and open with read-only permissions: if this succeeds, we just return
717+
// the metadata as is, otherwise we return the error on Open()
718+
_, err = cv.mount.Open(path, os.O_RDONLY, fs.conf.FilePerms)
719+
if err != nil {
720+
l = nil
721+
}
711722
return
712723
}
713724

@@ -718,21 +729,14 @@ func (fs *cephfs) GetLock(ctx context.Context, ref *provider.Reference) (*provid
718729
return
719730
}
720731

721-
buf, err := cv.mount.GetXattr(path, xattrLock)
722-
if err != nil {
732+
if errXattr != nil {
723733
// error here means we have a "foreign" flock with no CS3 metadata
724734
err = nil
725735
l = new(provider.Lock)
726736
l.AppName = "External"
727737
return
728738
}
729739

730-
if l, err = decodeLock(string(buf)); err != nil {
731-
l = nil
732-
err = errors.Wrap(err, "cephfs: malformed lock payload")
733-
return
734-
}
735-
736740
if time.Unix(int64(l.Expiration.Seconds), 0).After(time.Now()) {
737741
// the lock expired, drop
738742
fs.UnsetArbitraryMetadata(ctx, ref, []string{xattrLock})

0 commit comments

Comments
 (0)