From 54d27ed721746ad569444b8021bad5133e432322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 3 Mar 2022 10:52:00 +0100 Subject: [PATCH] clh: introduce loadVirtiofsDaemon() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similarly to the `createVirtiofsDaemon` and `stopVirtiofsDaemon` methos, let's introduce and use loadVirtiofsDaemon, at it'll also be handy later in this series. Signed-off-by: Fabiano FidĂȘncio --- src/runtime/virtcontainers/clh.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index e3ae289075..d609d9ea1f 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -273,6 +273,20 @@ func (clh *cloudHypervisor) stopVirtiofsDaemon(ctx context.Context) (err error) return nil } +func (clh *cloudHypervisor) loadVirtiofsDaemon(sharedPath string) (VirtiofsDaemon, error) { + virtiofsdSocketPath, err := clh.virtioFsSocketPath(clh.id) + if err != nil { + return nil, err + } + + return &virtiofsd{ + PID: clh.state.VirtiofsDaemonPid, + sourcePath: sharedPath, + debug: clh.config.Debug, + socketPath: virtiofsdSocketPath, + }, nil +} + func (clh *cloudHypervisor) nydusdAPISocketPath(id string) (string, error) { return utils.BuildSocketPath(clh.config.VMStorePath, id, nydusdAPISock) } @@ -323,19 +337,15 @@ func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network Net clh.Logger().WithField("function", "CreateVM").Info("creating Sandbox") - virtiofsdSocketPath, err := clh.virtioFsSocketPath(clh.id) - if err != nil { - return nil - } - if clh.state.PID > 0 { clh.Logger().WithField("function", "CreateVM").Info("Sandbox already exist, loading from state") - clh.virtiofsDaemon = &virtiofsd{ - PID: clh.state.VirtiofsDaemonPid, - sourcePath: hypervisorConfig.SharedPath, - debug: clh.config.Debug, - socketPath: virtiofsdSocketPath, + + virtiofsDaemon, err := clh.loadVirtiofsDaemon(hypervisorConfig.SharedFS) + if err != nil { + return err } + clh.virtiofsDaemon = virtiofsDaemon + return nil }