diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index 2c3a68603b..dafb739227 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -250,17 +250,16 @@ func (d *Daemon) sharedFusedevMount(rafs *rafs.Rafs) error { return err } - c, err := daemonconfig.NewDaemonConfig(d.States.FsDriver, d.ConfigFile(rafs.SnapshotID)) - if err != nil { - return errors.Wrapf(err, "Failed to reload instance configuration %s", - d.ConfigFile(rafs.SnapshotID)) - } - + // c, err := daemonconfig.NewDaemonConfig(d.States.FsDriver, d.ConfigFile(rafs.SnapshotID)) + // if err != nil { + // return errors.Wrapf(err, "Failed to reload instance configuration %s", + // d.ConfigFile(rafs.SnapshotID)) + // } + c := d.Config cfg, err := c.DumpString() if err != nil { return errors.Wrap(err, "dump instance configuration") } - err = client.Mount(rafs.RelaMountpoint(), bootstrap, cfg) if err != nil { return errors.Wrapf(err, "mount rafs instance") @@ -280,11 +279,12 @@ func (d *Daemon) sharedErofsMount(ra *rafs.Rafs) error { return errors.Wrapf(err, "failed to create fscache work dir %s", ra.FscacheWorkDir()) } - c, err := daemonconfig.NewDaemonConfig(d.States.FsDriver, d.ConfigFile(ra.SnapshotID)) - if err != nil { - log.L.Errorf("Failed to reload daemon configuration %s, %s", d.ConfigFile(ra.SnapshotID), err) - return err - } + // c, err := daemonconfig.NewDaemonConfig(d.States.FsDriver, d.ConfigFile(ra.SnapshotID)) + // if err != nil { + // log.L.Errorf("Failed to reload daemon configuration %s, %s", d.ConfigFile(ra.SnapshotID), err) + // return err + // } + c := d.Config cfgStr, err := c.DumpString() if err != nil { @@ -650,3 +650,32 @@ func NewDaemon(opt ...NewDaemonOpt) (*Daemon, error) { return d, nil } + +func (d *Daemon) MountByAPI() error { + rafs := d.RafsCache.Head() + if rafs == nil { + return errors.Wrapf(errdefs.ErrNotFound, "daemon %s no rafs instance associated", d.ID()) + } + client, err := d.GetClient() + if err != nil { + return errors.Wrapf(err, "mount instance %s", rafs.SnapshotID) + } + + bootstrap, err := rafs.BootstrapFile() + if err != nil { + return err + } + c := d.Config + cfg, err := c.DumpString() + if err != nil { + return errors.Wrap(err, "dump instance configuration") + } + + err = client.Mount("/", bootstrap, cfg) + if err != nil { + return errors.Wrapf(err, "mount rafs instance") + } + + return nil + +} diff --git a/pkg/filesystem/fs.go b/pkg/filesystem/fs.go index 88b57f6e1b..a87dc8d32c 100644 --- a/pkg/filesystem/fs.go +++ b/pkg/filesystem/fs.go @@ -310,26 +310,32 @@ func (fs *Filesystem) Mount(ctx context.Context, snapshotID string, labels map[s // TODO: How to manage rafs configurations on-disk? separated json config file or DB record? // In order to recover erofs mount, the configuration file has to be persisted. - var configSubDir string - if useSharedDaemon { - configSubDir = snapshotID - } else { - // Associate daemon config object when creating a new daemon object to avoid - // reading disk file again and again. - // For shared daemon, each rafs instance has its own configuration, so we don't - // attach a config interface to daemon in this case. - d.Config = cfg - } - - err = cfg.DumpFile(d.ConfigFile(configSubDir)) - if err != nil { - if errors.Is(err, errdefs.ErrAlreadyExists) { - log.L.Debugf("Configuration file %s already exits", d.ConfigFile(configSubDir)) - } else { - return errors.Wrap(err, "dump daemon configuration file") - } - } - + // var configSubDir string + // if useSharedDaemon { + // configSubDir = snapshotID + // } else { + // // Associate daemon config object when creating a new daemon object to avoid + // // reading disk file again and again. + // // For shared daemon, each rafs instance has its own configuration, so we don't + // // attach a config interface to daemon in this case. + // d.Config = cfg + // } + + // err = cfg.DumpFile(d.ConfigFile(configSubDir)) + + // if err != nil { + // if errors.Is(err, errdefs.ErrAlreadyExists) { + // log.L.Debugf("Configuration file %s already exits", d.ConfigFile(configSubDir)) + // } else { + // return errors.Wrap(err, "dump daemon configuration file") + // } + // } + // content, errs := cfg.DumpString() + // if errs != nil { + // return errors.Wrap(err, "dump instance configuration") + // } + // log.L.Infof("content %s", content) + d.Config = cfg d.AddRafsInstance(rafs) // if publicKey is not empty we should verify bootstrap file of image @@ -596,10 +602,10 @@ func (fs *Filesystem) initSharedDaemon(fsManager *manager.Manager) (err error) { // it is loaded when requesting mount api // Dump the configuration file since it is reloaded when recovering the nydusd d.Config = *fsManager.DaemonConfig - err = d.Config.DumpFile(d.ConfigFile("")) - if err != nil && !errors.Is(err, errdefs.ErrAlreadyExists) { - return errors.Wrapf(err, "dump configuration file %s", d.ConfigFile("")) - } + // err = d.Config.DumpFile(d.ConfigFile("")) + // if err != nil && !errors.Is(err, errdefs.ErrAlreadyExists) { + // return errors.Wrapf(err, "dump configuration file %s", d.ConfigFile("")) + // } if err := fsManager.StartDaemon(d); err != nil { return errors.Wrap(err, "start shared daemon") diff --git a/pkg/manager/daemon_adaptor.go b/pkg/manager/daemon_adaptor.go index 44c61fbea4..75c62c7a13 100644 --- a/pkg/manager/daemon_adaptor.go +++ b/pkg/manager/daemon_adaptor.go @@ -44,6 +44,16 @@ func (m *Manager) StartDaemon(d *daemon.Daemon) error { if err := cmd.Start(); err != nil { return err } + fsDriver := config.GetFsDriver() + isSharedFusedev := fsDriver == config.FsDriverFusedev && config.GetDaemonMode() == config.DaemonModeShared + useSharedDaemon := fsDriver == config.FsDriverFscache || isSharedFusedev + + if !useSharedDaemon { + errs := d.MountByAPI() + if errs != nil { + return errors.Wrapf(err, "failed to mount") + } + } d.Lock() defer d.Unlock() @@ -155,10 +165,10 @@ func (m *Manager) BuildDaemonCommand(d *daemon.Daemon, bin string, upgrade bool) return nil, errors.Wrapf(err, "locate bootstrap %s", bootstrap) } - cmdOpts = append(cmdOpts, - command.WithConfig(d.ConfigFile("")), - command.WithBootstrap(bootstrap), - ) + // cmdOpts = append(cmdOpts, + // command.WithConfig(d.ConfigFile("")), + // command.WithBootstrap(bootstrap), + // ) if config.IsBackendSourceEnabled() { configAPIPath := fmt.Sprintf(endpointGetBackend, d.States.ID) cmdOpts = append(cmdOpts,