Skip to content

Commit

Permalink
mount: exit when the file system changes (#4555)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijian-pro authored Mar 22, 2024
1 parent de2611c commit 5292c28
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
19 changes: 14 additions & 5 deletions cmd/mount_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,12 +698,21 @@ func launchMount(mp string, conf *vfs.Config) error {
cancel()
if err == nil {
return nil
} else {
var exitError *exec.ExitError
if ok := errors.As(err, &exitError); ok {
if waitStatus, ok := exitError.Sys().(syscall.WaitStatus); ok && waitStatus.ExitStatus() == meta.UmountCode {
logger.Errorf("received umount exit code")
_ = doUmount(mp, true)
return nil
}
}
if fuseFd < 0 {
logger.Info("transfer FUSE session to others")
return nil
}
time.Sleep(time.Second)
}
if fuseFd < 0 {
logger.Info("transfer FUSE session to others")
return nil
}
time.Sleep(time.Second)
}
}

Expand Down
12 changes: 10 additions & 2 deletions pkg/meta/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ func (m *baseMeta) OnReload(fn func(f *Format)) {
m.reloadCb = append(m.reloadCb, fn)
}

const UmountCode = 11

func (m *baseMeta) refresh() {
for {
if m.conf.Heartbeat > 0 {
Expand All @@ -571,11 +573,17 @@ func (m *baseMeta) refresh() {

old := m.getFormat()
if format, err := m.Load(false); err != nil {
if strings.HasPrefix(err.Error(), "database is not formatted") {
logger.Errorf("reload setting: %s", err)
os.Exit(UmountCode)
}
logger.Warnf("reload setting: %s", err)
} else if format.MetaVersion > MaxVersion {
logger.Fatalf("incompatible metadata version %d > max version %d", format.MetaVersion, MaxVersion)
logger.Errorf("incompatible metadata version %d > max version %d", format.MetaVersion, MaxVersion)
os.Exit(UmountCode)
} else if format.UUID != old.UUID {
logger.Fatalf("UUID changed from %s to %s", old, format.UUID)
logger.Errorf("UUID changed from %s to %s", old.UUID, format.UUID)
os.Exit(UmountCode)
} else if !reflect.DeepEqual(format, old) {
m.msgCallbacks.Lock()
cbs := m.reloadCb
Expand Down

0 comments on commit 5292c28

Please sign in to comment.