diff options
| author | Chris Lu <chris.lu@gmail.com> | 2018-09-22 00:11:46 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2018-09-22 00:11:46 -0700 |
| commit | 7bb62b9f21c92ad8c218eab236c136606fc7153a (patch) | |
| tree | 64dd12151ef2a335b85bea4e46d7bc4de5268503 /weed/filesys/dir.go | |
| parent | f905a1e779fdb9333f0fc08817cdbe33c261a25d (diff) | |
| download | seaweedfs-7bb62b9f21c92ad8c218eab236c136606fc7153a.tar.xz seaweedfs-7bb62b9f21c92ad8c218eab236c136606fc7153a.zip | |
delay file creation without chunks from dir.Create to file.Flush
Diffstat (limited to 'weed/filesys/dir.go')
| -rw-r--r-- | weed/filesys/dir.go | 74 |
1 files changed, 38 insertions, 36 deletions
diff --git a/weed/filesys/dir.go b/weed/filesys/dir.go index 06c5f2569..c0771159a 100644 --- a/weed/filesys/dir.go +++ b/weed/filesys/dir.go @@ -91,55 +91,57 @@ func (dir *Dir) Attr(context context.Context, attr *fuse.Attr) error { return nil } -func (dir *Dir) newFile(name string, chunks []*filer_pb.FileChunk, attr *filer_pb.FuseAttributes) *File { +func (dir *Dir) newFile(name string, entry *filer_pb.Entry) *File { return &File{ - Name: name, - dir: dir, - wfs: dir.wfs, - attributes: attr, - Chunks: chunks, + Name: name, + dir: dir, + wfs: dir.wfs, + entry: entry, } } func (dir *Dir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (fs.Node, fs.Handle, error) { - err := dir.wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error { - - request := &filer_pb.CreateEntryRequest{ - Directory: dir.Path, - Entry: &filer_pb.Entry{ - Name: req.Name, - IsDirectory: req.Mode&os.ModeDir > 0, - Attributes: &filer_pb.FuseAttributes{ - Mtime: time.Now().Unix(), - Crtime: time.Now().Unix(), - FileMode: uint32(req.Mode), - Uid: req.Uid, - Gid: req.Gid, - Collection: dir.wfs.option.Collection, - Replication: dir.wfs.option.Replication, - TtlSec: dir.wfs.option.TtlSec, - }, + request := &filer_pb.CreateEntryRequest{ + Directory: dir.Path, + Entry: &filer_pb.Entry{ + Name: req.Name, + IsDirectory: req.Mode&os.ModeDir > 0, + Attributes: &filer_pb.FuseAttributes{ + Mtime: time.Now().Unix(), + Crtime: time.Now().Unix(), + FileMode: uint32(req.Mode), + Uid: req.Uid, + Gid: req.Gid, + Collection: dir.wfs.option.Collection, + Replication: dir.wfs.option.Replication, + TtlSec: dir.wfs.option.TtlSec, }, - } + }, + } + glog.V(1).Infof("create: %v", request) - glog.V(1).Infof("create: %v", request) - if _, err := client.CreateEntry(ctx, request); err != nil { - glog.V(0).Infof("create %s/%s: %v", dir.Path, req.Name, err) - return fuse.EIO + if request.Entry.IsDirectory { + if err := dir.wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error { + if _, err := client.CreateEntry(ctx, request); err != nil { + glog.V(0).Infof("create %s/%s: %v", dir.Path, req.Name, err) + return fuse.EIO + } + return nil + }); err != nil { + return nil, nil, err } + } - return nil - }) - - if err == nil { - file := dir.newFile(req.Name, nil, &filer_pb.FuseAttributes{}) + file := dir.newFile(req.Name, request.Entry) + if !request.Entry.IsDirectory { file.isOpen = true - return file, dir.wfs.AcquireHandle(file, req.Uid, req.Gid), nil } + fh := dir.wfs.AcquireHandle(file, req.Uid, req.Gid) + fh.dirtyMetadata = true + return file, fh, nil - return nil, nil, err } func (dir *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, error) { @@ -204,7 +206,7 @@ func (dir *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse. if entry.IsDirectory { node = &Dir{Path: path.Join(dir.Path, req.Name), wfs: dir.wfs, attributes: entry.Attributes} } else { - node = dir.newFile(req.Name, entry.Chunks, entry.Attributes) + node = dir.newFile(req.Name, entry) } resp.EntryValid = time.Duration(0) |
