Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ceph driver fixes #4200

Merged
merged 8 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions changelog/unreleased/fix-ceph-driver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Enhancement: Multiple fixes for Ceph driver

* Avoid usage/creation of user homes when they are disabled in the config
* Simplify the regular uploads (not chunked)
* Avoid creation of shadow folders at the root if they are already there
* Clean up the chunked upload
* Fix panic on shutdown

https://github.com/cs3org/reva/pull/4200
11 changes: 7 additions & 4 deletions pkg/storage/fs/cephfs/cephfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func init() {
registry.Register("cephfs", New)
}

// New returns an implementation to of the storage.FS interface that talk to
// New returns an implementation to of the storage.FS interface that talks to
// a ceph filesystem.
func New(ctx context.Context, m map[string]interface{}) (fs storage.FS, err error) {
var o Options
Expand All @@ -81,9 +81,12 @@ func New(ctx context.Context, m map[string]interface{}) (fs storage.FS, err erro
}

for _, dir := range []string{o.ShadowFolder, o.UploadFolder} {
err = adminConn.adminMount.MakeDir(dir, dirPermFull)
if err != nil && err.Error() != errFileExists {
return nil, errors.New("cephfs: can't initialise system dir " + dir + ":" + err.Error())
_, err := adminConn.adminMount.Statx(dir, cephfs2.StatxMask(cephfs2.StatxIno), 0)
if err != nil {
err = adminConn.adminMount.MakeDir(dir, dirPermFull)
if err != nil && err.Error() != errFileExists {
return nil, errors.New("cephfs: can't initialise system dir " + dir + ":" + err.Error())
}
}
}

Expand Down
122 changes: 1 addition & 121 deletions pkg/storage/fs/cephfs/chunking.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ func (c *ChunkHandler) getChunkFolderName(i *ChunkBLOBInfo) (path string, err er
}

func (c *ChunkHandler) saveChunk(path string, r io.ReadCloser) (finish bool, chunk string, err error) {
var chunkInfo *ChunkBLOBInfo

chunkInfo, err = GetChunkBLOBInfo(path)
chunkInfo, err := GetChunkBLOBInfo(path)
if err != nil {
err = fmt.Errorf("error getting chunk info from path: %s", path)
return
Expand Down Expand Up @@ -223,122 +221,4 @@ func (c *ChunkHandler) WriteChunk(fn string, r io.ReadCloser) (string, string, e
}

return chunkInfo.Path, chunk, nil

// TODO(labkode): implement old chunking

/*
req2 := &provider.StartWriteSessionRequest{}
res2, err := client.StartWriteSession(ctx, req2)
if err != nil {
logger.Error(ctx, err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if res2.Status.Code != rpc.Code_CODE_OK {
logger.Println(ctx, res2.Status)
w.WriteHeader(http.StatusInternalServerError)
return
}
sessID := res2.SessionId
logger.Build().Str("sessID", sessID).Msg(ctx, "got write session id")
stream, err := client.Write(ctx)
if err != nil {
logger.Error(ctx, err)
w.WriteHeader(http.StatusInternalServerError)
return
}
buffer := make([]byte, 1024*1024*3)
var offset uint64
var numChunks uint64
for {
n, err := fd.Read(buffer)
if n > 0 {
req := &provider.WriteRequest{Data: buffer, Length: uint64(n), SessionId: sessID, Offset: offset}
err = stream.Send(req)
if err != nil {
logger.Error(ctx, err)
w.WriteHeader(http.StatusInternalServerError)
return
}
numChunks++
offset += uint64(n)
}
if err == io.EOF {
break
}
if err != nil {
logger.Error(ctx, err)
w.WriteHeader(http.StatusInternalServerError)
return
}
}
res3, err := stream.CloseAndRecv()
if err != nil {
logger.Error(ctx, err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if res3.Status.Code != rpc.Code_CODE_OK {
logger.Println(ctx, err)
w.WriteHeader(http.StatusInternalServerError)
return
}
req4 := &provider.FinishWriteSessionRequest{Filename: chunkInfo.path, SessionId: sessID}
res4, err := client.FinishWriteSession(ctx, req4)
if err != nil {
logger.Error(ctx, err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if res4.Status.Code != rpc.Code_CODE_OK {
logger.Println(ctx, res4.Status)
w.WriteHeader(http.StatusInternalServerError)
return
}
req.Filename = chunkInfo.path
res, err = client.Stat(ctx, req)
if err != nil {
logger.Error(ctx, err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if res.Status.Code != rpc.Code_CODE_OK {
logger.Println(ctx, res.Status)
w.WriteHeader(http.StatusInternalServerError)
return
}
md2 := res.Metadata
w.Header().Add("Content-Type", md2.Mime)
w.Header().Set("ETag", md2.Etag)
w.Header().Set("OC-FileId", md2.Id)
w.Header().Set("OC-ETag", md2.Etag)
t := time.Unix(int64(md2.Mtime), 0)
lastModifiedString := t.Format(time.RFC1123Z)
w.Header().Set("Last-Modified", lastModifiedString)
w.Header().Set("X-OC-MTime", "accepted")
if md == nil {
w.WriteHeader(http.StatusCreated)
return
}
w.WriteHeader(http.StatusNoContent)
return
*/
}
4 changes: 2 additions & 2 deletions pkg/storage/fs/cephfs/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func newCache() (c *connections, err error) {
MaxCost: usrLimit,
BufferItems: 64,
OnEvict: func(item *ristretto.Item) {
v := item.Value.(cacheVal)
v := item.Value.(*cacheVal)
javfg marked this conversation as resolved.
Show resolved Hide resolved
v.perm.Destroy()
_ = v.mount.Unmount()
_ = v.mount.Release()
Expand Down Expand Up @@ -212,7 +212,7 @@ func newConn(user *User) *cacheVal {
return destroyCephConn(mount, perm)
}

if user != nil {
if user != nil && !user.fs.conf.DisableHome {
if err = mount.ChangeDir(user.fs.conf.Root); err != nil {
return destroyCephConn(mount, perm)
}
Expand Down
Loading