@@ -700,14 +700,25 @@ func (fs *cephfs) GetLock(ctx context.Context, ref *provider.Reference) (*provid
700
700
return nil , getRevaError (err )
701
701
}
702
702
703
+ // prepare the metadata
703
704
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
+
704
712
user .op (func (cv * cacheVal ) {
705
713
var file * goceph.File
706
714
defer closeFile (file )
707
715
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
+ }
711
722
return
712
723
}
713
724
@@ -718,21 +729,14 @@ func (fs *cephfs) GetLock(ctx context.Context, ref *provider.Reference) (*provid
718
729
return
719
730
}
720
731
721
- buf , err := cv .mount .GetXattr (path , xattrLock )
722
- if err != nil {
732
+ if errXattr != nil {
723
733
// error here means we have a "foreign" flock with no CS3 metadata
724
734
err = nil
725
735
l = new (provider.Lock )
726
736
l .AppName = "External"
727
737
return
728
738
}
729
739
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
-
736
740
if time .Unix (int64 (l .Expiration .Seconds ), 0 ).After (time .Now ()) {
737
741
// the lock expired, drop
738
742
fs .UnsetArbitraryMetadata (ctx , ref , []string {xattrLock })
0 commit comments