Browse Source

fuse mount: avoid lookup nil entry

fix https://github.com/chrislusf/seaweedfs/issues/1221
tikv
Chris Lu 5 years ago
parent
commit
8645283a7b
  1. 4
      weed/filer2/filer_client_util.go
  2. 9
      weed/filesys/xattr.go
  3. 24
      weed/pb/filer_pb/filer_pb_helper.go
  4. 7
      weed/replication/sink/filersink/filer_sink.go
  5. 11
      weed/s3api/filer_util.go
  6. 6
      weed/s3api/s3api_bucket_handlers.go
  7. 6
      weed/shell/command_fs_cat.go
  8. 5
      weed/shell/command_fs_meta_cat.go
  9. 4
      weed/shell/command_fs_mv.go
  10. 6
      weed/shell/commands.go

4
weed/filer2/filer_client_util.go

@ -102,9 +102,9 @@ func GetEntry(filerClient FilerClient, fullFilePath FullPath) (entry *filer_pb.E
}
// glog.V(3).Infof("read %s request: %v", fullFilePath, request)
resp, err := client.LookupDirectoryEntry(context.Background(), request)
resp, err := filer_pb.LookupEntry(client, request)
if err != nil {
if err == ErrNotFound || strings.Contains(err.Error(), ErrNotFound.Error()) {
if err == ErrNotFound {
return nil
}
glog.V(3).Infof("read %s %v: %v", fullFilePath, resp, err)

9
weed/filesys/xattr.go

@ -1,9 +1,6 @@
package filesys
import (
"context"
"strings"
"github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
@ -124,9 +121,9 @@ func (wfs *WFS) maybeLoadEntry(dir, name string) (entry *filer_pb.Entry, err err
Directory: dir,
}
resp, err := client.LookupDirectoryEntry(context.Background(), request)
if err != nil || resp == nil || resp.Entry == nil {
if err == filer2.ErrNotFound || strings.Contains(err.Error(), filer2.ErrNotFound.Error()) {
resp, err := filer_pb.LookupEntry(client, request)
if err != nil {
if err == filer2.ErrNotFound {
glog.V(3).Infof("file attr read not found file %v: %v", request, err)
return fuse.ENOENT
}

24
weed/pb/filer_pb/filer_pb_helper.go

@ -3,7 +3,9 @@ package filer_pb
import (
"context"
"fmt"
"strings"
"github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/storage/needle"
)
@ -84,3 +86,25 @@ func CreateEntry(client SeaweedFilerClient, request *CreateEntryRequest) error {
}
return nil
}
func LookupEntry(client SeaweedFilerClient, request *LookupDirectoryEntryRequest) (*LookupDirectoryEntryResponse, error) {
resp, err := filer_pb.LookupEntry(client, request)
if err != nil {
if err == filer2.ErrNotFound || strings.Contains(err.Error(), ErrNotFound.Error()) {
return nil, filer2.ErrNotFound
}
glog.V(3).Infof("read %s/%v: %v", request.Directory, request.Entry.Name, err)
return nil, fmt.Errorf("LookupEntry1: %v", err)
}
if resp.Error != "" && strings.Contains(resp.Error, ErrNotFound.Error()) {
return nil, filer2.ErrNotFound
}
if resp.Error != "" {
glog.V(3).Infof("lookup %s/%v: %v", request.Directory, request.Entry.Name, err)
return nil, fmt.Errorf("LookupEntry2: %v", err)
}
if resp.Entry == nil {
return nil, filer2.ErrNotFound
}
return resp, nil
}

7
weed/replication/sink/filersink/filer_sink.go

@ -98,7 +98,7 @@ func (fs *FilerSink) CreateEntry(key string, entry *filer_pb.Entry) error {
Name: name,
}
glog.V(1).Infof("lookup: %v", lookupRequest)
if resp, err := client.LookupDirectoryEntry(context.Background(), lookupRequest); err == nil && resp.Entry != nil {
if resp, err := filer_pb.LookupEntry(client, lookupRequest); err == nil {
if filer2.ETag(resp.Entry.Chunks) == filer2.ETag(entry.Chunks) {
glog.V(0).Infof("already replicated %s", key)
return nil
@ -148,14 +148,11 @@ func (fs *FilerSink) UpdateEntry(key string, oldEntry *filer_pb.Entry, newParent
}
glog.V(4).Infof("lookup entry: %v", request)
resp, err := client.LookupDirectoryEntry(context.Background(), request)
resp, err := filer_pb.LookupEntry(client, request)
if err != nil {
glog.V(0).Infof("lookup %s: %v", key, err)
return err
}
if resp.Entry == nil {
return filer2.ErrNotFound
}
existingEntry = resp.Entry

11
weed/s3api/filer_util.go

@ -8,6 +8,7 @@ import (
"strings"
"time"
"github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
)
@ -202,15 +203,15 @@ func (s3a *S3ApiServer) exists(parentDirectoryPath string, entryName string, isD
}
glog.V(4).Infof("exists entry %v/%v: %v", parentDirectoryPath, entryName, request)
resp, err := client.LookupDirectoryEntry(context.Background(), request)
resp, err := filer_pb.LookupEntry(client, request)
if err != nil {
glog.V(0).Infof("exists entry %v: %v", request, err)
return fmt.Errorf("exists entry %s/%s: %v", parentDirectoryPath, entryName, err)
}
if resp.Entry == nil {
if err == filer2.ErrNotFound {
exists = false
return nil
}
glog.V(0).Infof("exists entry %v: %v", request, err)
return fmt.Errorf("exists entry %s/%s: %v", parentDirectoryPath, entryName, err)
}
exists = resp.Entry.IsDirectory == isDirectory

6
weed/s3api/s3api_bucket_handlers.go

@ -13,6 +13,7 @@ import (
"github.com/aws/aws-sdk-go/service/s3"
"github.com/gorilla/mux"
"github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
)
@ -117,7 +118,10 @@ func (s3a *S3ApiServer) HeadBucketHandler(w http.ResponseWriter, r *http.Request
}
glog.V(1).Infof("lookup bucket: %v", request)
if resp, err := client.LookupDirectoryEntry(context.Background(), request); err != nil || resp.Entry == nil {
if _, err := filer_pb.LookupEntry(client, request); err != nil {
if err == filer2.ErrNotFound {
return filer2.ErrNotFound
}
return fmt.Errorf("lookup bucket %s/%s: %v", s3a.option.BucketsPath, bucket, err)
}

6
weed/shell/command_fs_cat.go

@ -1,7 +1,6 @@
package shell
import (
"context"
"fmt"
"io"
"math"
@ -50,13 +49,10 @@ func (c *commandFsCat) Do(args []string, commandEnv *CommandEnv, writer io.Write
Name: name,
Directory: dir,
}
respLookupEntry, err := client.LookupDirectoryEntry(context.Background(), request)
respLookupEntry, err := filer_pb.LookupEntry(client, request)
if err != nil {
return err
}
if respLookupEntry.Entry == nil {
return fmt.Errorf("file not found: %s", path)
}
return filer2.StreamContent(commandEnv.MasterClient, writer, respLookupEntry.Entry.Chunks, 0, math.MaxInt32)

5
weed/shell/command_fs_meta_cat.go

@ -49,13 +49,10 @@ func (c *commandFsMetaCat) Do(args []string, commandEnv *CommandEnv, writer io.W
Name: name,
Directory: dir,
}
respLookupEntry, err := client.LookupDirectoryEntry(context.Background(), request)
respLookupEntry, err := filer_pb.LookupEntry(client, request)
if err != nil {
return err
}
if respLookupEntry.Entry == nil {
return fmt.Errorf("file not found: %s", path)
}
m := jsonpb.Marshaler{
EmitDefaults: true,

4
weed/shell/command_fs_mv.go

@ -58,12 +58,12 @@ func (c *commandFsMv) Do(args []string, commandEnv *CommandEnv, writer io.Writer
Name: destinationDir,
Directory: destinationName,
}
respDestinationLookupEntry, err := client.LookupDirectoryEntry(context.Background(), destinationRequest)
respDestinationLookupEntry, err := filer_pb.LookupEntry(client, destinationRequest)
var targetDir, targetName string
// moving a file or folder
if err == nil && respDestinationLookupEntry.Entry != nil && respDestinationLookupEntry.Entry.IsDirectory {
if err == nil && respDestinationLookupEntry.Entry.IsDirectory {
// to a directory
targetDir = filepath.ToSlash(filepath.Join(destinationDir, destinationName))
targetName = sourceName

6
weed/shell/commands.go

@ -71,7 +71,7 @@ func (ce *CommandEnv) checkDirectory(filerServer string, filerPort int64, path s
return ce.withFilerClient(filerServer, filerPort, func(client filer_pb.SeaweedFilerClient) error {
resp, lookupErr := client.LookupDirectoryEntry(context.Background(), &filer_pb.LookupDirectoryEntryRequest{
resp, lookupErr := filer_pb.LookupEntry(client, &filer_pb.LookupDirectoryEntryRequest{
Directory: dir,
Name: name,
})
@ -79,10 +79,6 @@ func (ce *CommandEnv) checkDirectory(filerServer string, filerPort int64, path s
return lookupErr
}
if resp.Entry == nil {
return fmt.Errorf("entry not found")
}
if !resp.Entry.IsDirectory {
return fmt.Errorf("not a directory")
}

Loading…
Cancel
Save