From 413b3b477a709fc345831f3e533c190ffc8c5bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 3 Mar 2022 10:25:18 +0100 Subject: [PATCH] clh: introduce createVirtiofsDaemon() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's introduce and use a new `createVirtiofsDaemon` method. Its name says it all, and it'll be handy later in this series when, spoiler alert, SharedFS cannot be used (in such cases as in Confidential Guests). Signed-off-by: Fabiano FidĂȘncio --- src/runtime/virtcontainers/clh.go | 65 ++++++++++++++++++------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index a25cd019a..8db4b6e07 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -198,6 +198,42 @@ func (clh *cloudHypervisor) setConfig(config *HypervisorConfig) error { return nil } +func (clh *cloudHypervisor) createVirtiofsDaemon(sharedPath string) (VirtiofsDaemon, error) { + virtiofsdSocketPath, err := clh.virtioFsSocketPath(clh.id) + if err != nil { + return nil, err + } + + if clh.config.SharedFS == config.VirtioFSNydus { + apiSockPath, err := clh.nydusdAPISocketPath(clh.id) + if err != nil { + clh.Logger().WithError(err).Error("Invalid api socket path for nydusd") + return nil, err + } + nd := &nydusd{ + path: clh.config.VirtioFSDaemon, + sockPath: virtiofsdSocketPath, + apiSockPath: apiSockPath, + sourcePath: sharedPath, + debug: clh.config.Debug, + extraArgs: clh.config.VirtioFSExtraArgs, + startFn: startInShimNS, + } + nd.setupShareDirFn = nd.setupPassthroughFS + return nd, nil + } + + // default: use virtiofsd + return &virtiofsd{ + path: clh.config.VirtioFSDaemon, + sourcePath: sharedPath, + socketPath: virtiofsdSocketPath, + extraArgs: clh.config.VirtioFSExtraArgs, + debug: clh.config.Debug, + cache: clh.config.VirtioFSCache, + }, nil +} + func (clh *cloudHypervisor) nydusdAPISocketPath(id string) (string, error) { return utils.BuildSocketPath(clh.config.VMStorePath, id, nydusdAPISock) } @@ -402,32 +438,9 @@ func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network Net ApiInternal: chclient.NewAPIClient(cfg).DefaultApi, } - clh.virtiofsDaemon = &virtiofsd{ - path: clh.config.VirtioFSDaemon, - sourcePath: filepath.Join(GetSharePath(clh.id)), - socketPath: virtiofsdSocketPath, - extraArgs: clh.config.VirtioFSExtraArgs, - debug: clh.config.Debug, - cache: clh.config.VirtioFSCache, - } - - if clh.config.SharedFS == config.VirtioFSNydus { - apiSockPath, err := clh.nydusdAPISocketPath(clh.id) - if err != nil { - clh.Logger().WithError(err).Error("Invalid api socket path for nydusd") - return err - } - nd := &nydusd{ - path: clh.config.VirtioFSDaemon, - sockPath: virtiofsdSocketPath, - apiSockPath: apiSockPath, - sourcePath: filepath.Join(GetSharePath(clh.id)), - debug: clh.config.Debug, - extraArgs: clh.config.VirtioFSExtraArgs, - startFn: startInShimNS, - } - nd.setupShareDirFn = nd.setupPassthroughFS - clh.virtiofsDaemon = nd + clh.virtiofsDaemon, err = clh.createVirtiofsDaemon(filepath.Join(GetSharePath(clh.id))) + if err != nil { + return err } if clh.config.SGXEPCSize > 0 {