From 6ee6bc966e1dc9810ea8dc8fa9c64b5bdbd81986 Mon Sep 17 00:00:00 2001 From: jikui Date: Fri, 10 Dec 2021 10:28:43 +0800 Subject: [PATCH] kata-runtime: add removeMountBlockDevices for container Signed-off-by: jikui --- kata-containers.spec | 8 ++- ...-removeMountBlockDevices-for-contain.patch | 51 +++++++++++++++++++ series.conf | 1 + 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 patches/0023-kata-containers-add-removeMountBlockDevices-for-contain.patch diff --git a/kata-containers.spec b/kata-containers.spec index 8b846e3..e26812c 100644 --- a/kata-containers.spec +++ b/kata-containers.spec @@ -2,7 +2,7 @@ %global debug_package %{nil} %define VERSION 2.1.0 -%define RELEASE 19 +%define RELEASE 20 Name: kata-containers Version: %{VERSION} @@ -108,6 +108,12 @@ strip %{buildroot}/usr/bin/containerd-shim-kata-v2 %doc %changelog +* Fri Dec 10 2021 jikui - 2.1.0-20 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:add removeMountBlockDevices for container + * Fri Dec 10 2021 yangfeiyu - 2.1.0-19 - Type:bugfix - ID:NA diff --git a/patches/0023-kata-containers-add-removeMountBlockDevices-for-contain.patch b/patches/0023-kata-containers-add-removeMountBlockDevices-for-contain.patch new file mode 100644 index 0000000..089090e --- /dev/null +++ b/patches/0023-kata-containers-add-removeMountBlockDevices-for-contain.patch @@ -0,0 +1,51 @@ +From 502b7ed70369bfb8963fc38395d48e978dd6de50 Mon Sep 17 00:00:00 2001 +From: jikui +Date: Tue, 30 Nov 2021 17:03:26 +0800 +Subject: [PATCH] kata-runtime: add removeMountBlockDevices for container + +Signed-off-by: jikui +--- + src/runtime/virtcontainers/container.go | 20 ++++++++++++++++++++ + 1 file changed, 20 insertions(+) + +diff --git a/src/runtime/virtcontainers/container.go b/src/runtime/virtcontainers/container.go +index dd4317e..f348e2d 100644 +--- a/src/runtime/virtcontainers/container.go ++++ b/src/runtime/virtcontainers/container.go +@@ -799,6 +799,10 @@ func (c *Container) rollbackFailingContainerCreation(ctx context.Context) { + if err := c.detachDevices(ctx); err != nil { + c.Logger().WithError(err).Error("rollback failed detachDevices()") + } ++ ++ if errs := c.removeMountBlockDevices(); len(errs) > 0 { ++ c.Logger().Error("rollback failed removeMountBlockDevices()") ++ } + if err := c.removeDrive(ctx); err != nil { + c.Logger().WithError(err).Error("rollback failed removeDrive()") + } +@@ -1337,6 +1341,22 @@ func (c *Container) isDriveUsed() bool { + return !(c.state.Fstype == "") + } + ++func (c *Container) removeMountBlockDevices() []error { ++ var result []error ++ for _, mount := range c.mounts { ++ if len(mount.BlockDeviceID) > 0 { ++ if err := c.sandbox.devManager.RemoveDevice(mount.BlockDeviceID); err != nil { ++ result = append(result, err) ++ c.Logger().WithFields(logrus.Fields{ ++ "container": c.id, ++ "block-device": mount.BlockDeviceID, ++ }).WithError(err).Error("remove block device failed") ++ } ++ } ++ } ++ return result ++} ++ + func (c *Container) removeDrive(ctx context.Context) (err error) { + if c.isDriveUsed() { + c.Logger().Info("unplugging block device") +-- +2.25.1 + diff --git a/series.conf b/series.conf index dabfa90..447a52f 100644 --- a/series.conf +++ b/series.conf @@ -20,3 +20,4 @@ 0020-kata-containers-do-not-ignore-updateInterface-return-er.patch 0021-kata-containers-fix-the-block-device-not-remove-in-devM.patch 0022-kata-containers-modify-stratovirt-config-file.patch +0023-kata-containers-add-removeMountBlockDevices-for-contain.patch -- Gitee