Skip to content

Commit

Permalink
daemon: send states when umount
Browse files Browse the repository at this point in the history
So we can get the correct state after umount.

Signed-off-by: Huang Jianan <[email protected]>
  • Loading branch information
mofishzz committed Feb 27, 2023
1 parent c3bacbe commit c1971c3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 46 deletions.
40 changes: 22 additions & 18 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,23 +211,7 @@ func (d *Daemon) SharedMount(rafs *Rafs) error {
return errors.Wrapf(err, "mount instance %s", rafs.SnapshotID)
}

defer func() {
su := d.Supervisor
if su != nil {
// TODO: This should be optional by checking snapshotter's configuration.
// FIXME: Is it possible the states are overwritten during two API mounts.
// FIXME: What if nydusd does not support sending states.
err = su.FetchDaemonStates(func() error {
if err := d.SendStates(); err != nil {
return errors.Wrapf(err, "send daemon %s states", d.ID())
}
return nil
})
if err != nil {
log.L.Warnf("Daemon %s does not support sending states, %v", d.ID(), err)
}
}
}()
defer d.SendStates()

if d.States.FsDriver == config.FsDriverFscache {
if err := d.sharedErofsMount(rafs); err != nil {
Expand Down Expand Up @@ -266,6 +250,8 @@ func (d *Daemon) SharedUmount(rafs *Rafs) error {
return errors.Wrapf(err, "umount instance %s", rafs.SnapshotID)
}

defer d.SendStates()

if d.States.FsDriver == config.FsDriverFscache {
if err := d.sharedErofsUmount(rafs); err != nil {
return errors.Wrapf(err, "failed to erofs mount")
Expand Down Expand Up @@ -357,7 +343,25 @@ func (d *Daemon) sharedErofsUmount(rafs *Rafs) error {
return nil
}

func (d *Daemon) SendStates() error {
func (d *Daemon) SendStates() {
su := d.Supervisor
if su != nil {
// TODO: This should be optional by checking snapshotter's configuration.
// FIXME: Is it possible the states are overwritten during two API mounts.
// FIXME: What if nydusd does not support sending states.
err := su.FetchDaemonStates(func() error {
if err := d.doSendStates(); err != nil {
return errors.Wrapf(err, "send daemon %s states", d.ID())
}
return nil
})
if err != nil {
log.L.Warnf("Daemon %s does not support sending states, %v", d.ID(), err)
}
}
}

func (d *Daemon) doSendStates() error {
c, err := d.GetClient()
if err != nil {
return errors.Wrapf(err, "send states %s", d.ID())
Expand Down
16 changes: 1 addition & 15 deletions pkg/manager/daemon_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,7 @@ func (m *Manager) StartDaemon(d *daemon.Daemon) error {
collector.NewDaemonInfoCollector(&d.Version, 1).Collect()
d.Unlock()

if d.Supervisor == nil {
return
}

su := d.Supervisor
err = su.FetchDaemonStates(func() error {
if err := d.SendStates(); err != nil {
return errors.Wrapf(err, "send daemon %s states", d.ID())
}
return nil
})
if err != nil {
log.L.Errorf("send states")
return
}
d.SendStates()
}()

return nil
Expand Down
14 changes: 1 addition & 13 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,19 +566,7 @@ func (m *Manager) Recover(ctx context.Context) (map[string]*daemon.Daemon, map[s
}

// Snapshotter's lost the daemons' states after exit, refetch them.
su := d.Supervisor
if su != nil {
err = su.FetchDaemonStates(func() error {
if err := d.SendStates(); err != nil {
return errors.Wrapf(err, "send daemon %s states", d.ID())
}
return nil
})
if err != nil {
log.L.Errorf("Send daemon %s states", d.ID())
return
}
}
d.SendStates()
}()

return nil
Expand Down

0 comments on commit c1971c3

Please sign in to comment.