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

mount: pass next fh id #4509

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Changes from all 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
21 changes: 14 additions & 7 deletions pkg/vfs/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ func (v *VFS) invalidateDirHandle(parent Ino, name string, inode Ino, attr *Attr
}
}

type state struct {
Handler map[uint64]saveHandle
NextFh uint64
}

type saveHandle struct {
Inode uint64
Length uint64
Expand All @@ -289,8 +294,8 @@ type saveHandle struct {
func (v *VFS) dumpAllHandles(path string) (err error) {
v.hanleM.Lock()
defer v.hanleM.Unlock()

var toSave = make(map[uint64]saveHandle)
var vfsState state
vfsState.Handler = make(map[uint64]saveHandle)
for ino, hs := range v.handles {
if ino == logInode {
continue // will be recovered
Expand Down Expand Up @@ -319,10 +324,11 @@ func (v *VFS) dumpAllHandles(path string) (err error) {
Off: h.off,
Data: hex.EncodeToString(h.data),
}
toSave[h.fh] = s
vfsState.Handler[h.fh] = s
}
}
d, err := json.Marshal(toSave)
vfsState.NextFh = v.nextfh
d, err := json.Marshal(vfsState)
if err != nil {
return err
}
Expand All @@ -348,14 +354,14 @@ func (v *VFS) loadAllHandles(path string) error {
if err != nil {
return err
}
var toRestore map[uint64]saveHandle
err = json.Unmarshal(d, &toRestore)
var vfsState state
err = json.Unmarshal(d, &vfsState)
if err != nil {
return err
}
v.hanleM.Lock()
defer v.hanleM.Unlock()
for fh, s := range toRestore {
for fh, s := range vfsState.Handler {
data, err := hex.DecodeString(s.Data)
if err != nil {
logger.Warnf("decode data for inode %d: %s", s.Inode, err)
Expand Down Expand Up @@ -385,6 +391,7 @@ func (v *VFS) loadAllHandles(path string) error {
if len(v.handleIno) > 0 {
logger.Infof("load %d handles from %s", len(v.handleIno), path)
}
v.nextfh = vfsState.NextFh
// _ = os.Remove(path)
return nil
}
Loading