From 50fd76eb9a6739058826fbe7ca3bf29062824906 Mon Sep 17 00:00:00 2001 From: Archana Shinde Date: Thu, 5 Apr 2018 12:03:14 -0700 Subject: [PATCH] virtcontainers: block: Factorize checks for evaluating block support Factorize configuration and hardware support for hotplugging block devices into a single function and use that. Signed-off-by: Archana Shinde --- virtcontainers/container.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/virtcontainers/container.go b/virtcontainers/container.go index 16a95d2e0..bc2eda71f 100644 --- a/virtcontainers/container.go +++ b/virtcontainers/container.go @@ -432,6 +432,19 @@ func (c *Container) rollbackFailingContainerCreation() { } } +func (c *Container) checkBlockDeviceSupport() bool { + if !c.pod.config.HypervisorConfig.DisableBlockDeviceUse { + agentCaps := c.pod.agent.capabilities() + hypervisorCaps := c.pod.hypervisor.capabilities() + + if agentCaps.isBlockDeviceSupported() && hypervisorCaps.isBlockDeviceHotplugSupported() { + return true + } + } + + return false +} + // createContainer creates and start a container inside a Pod. It has to be // called only when a new container, not known by the pod, has to be created. func createContainer(pod *Pod, contConfig ContainerConfig) (c *Container, err error) { @@ -456,8 +469,10 @@ func createContainer(pod *Pod, contConfig ContainerConfig) (c *Container, err er } }() - if err = c.hotplugDrive(); err != nil { - return + if c.checkBlockDeviceSupport() { + if err = c.hotplugDrive(); err != nil { + return + } } // Attach devices @@ -683,15 +698,6 @@ func (c *Container) processList(options ProcessListOptions) (ProcessList, error) } func (c *Container) hotplugDrive() error { - agentCaps := c.pod.agent.capabilities() - hypervisorCaps := c.pod.hypervisor.capabilities() - - if c.pod.config.HypervisorConfig.DisableBlockDeviceUse || - !agentCaps.isBlockDeviceSupported() || - !hypervisorCaps.isBlockDeviceHotplugSupported() { - return nil - } - dev, err := getDeviceForPath(c.rootFs) if err == errMountPointNotFound {