From 938dfa8a858e43bf6588d8fcfe8f8af64039b005 Mon Sep 17 00:00:00 2001 From: jikui Date: Tue, 7 Dec 2021 09:38:28 +0800 Subject: [PATCH] kata-runtime: fix the block device not removed in devManager Signed-off-by: jikui --- kata-containers.spec | 8 +++- ...-the-block-device-not-remove-in-devM.patch | 46 +++++++++++++++++++ series.conf | 1 + 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 patches/0021-kata-containers-fix-the-block-device-not-remove-in-devM.patch diff --git a/kata-containers.spec b/kata-containers.spec index 6a39bf7..961e998 100644 --- a/kata-containers.spec +++ b/kata-containers.spec @@ -2,7 +2,7 @@ %global debug_package %{nil} %define VERSION 2.1.0 -%define RELEASE 17 +%define RELEASE 18 Name: kata-containers Version: %{VERSION} @@ -108,6 +108,12 @@ strip %{buildroot}/usr/bin/containerd-shim-kata-v2 %doc %changelog +* Tue Dec 7 2021 jikui - 2.1.0-18 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:fix the block device not removed in devManager + * Thu Dec 2 2021 jikui - 2.1.0-17 - Type:bugfix - ID:NA diff --git a/patches/0021-kata-containers-fix-the-block-device-not-remove-in-devM.patch b/patches/0021-kata-containers-fix-the-block-device-not-remove-in-devM.patch new file mode 100644 index 0000000..7cbf2e3 --- /dev/null +++ b/patches/0021-kata-containers-fix-the-block-device-not-remove-in-devM.patch @@ -0,0 +1,46 @@ +From 1bb584ac783d057b64058b02cc96c1c67dd7bf30 Mon Sep 17 00:00:00 2001 +From: jikui +Date: Tue, 30 Nov 2021 12:02:42 +0800 +Subject: [PATCH 3/4] kata-runtime: fix the block device not remove in + devManager + +Signed-off-by: jikui +--- + src/runtime/virtcontainers/container.go | 11 ++++++++++- + 1 file changed, 10 insertions(+), 1 deletion(-) + +diff --git a/src/runtime/virtcontainers/container.go b/src/runtime/virtcontainers/container.go +index 224f096..dd4317e 100644 +--- a/src/runtime/virtcontainers/container.go ++++ b/src/runtime/virtcontainers/container.go +@@ -1302,6 +1302,7 @@ func (c *Container) plugDevice(ctx context.Context, devicePath string) error { + } + + if c.checkBlockDeviceSupport(ctx) && stat.Mode&unix.S_IFBLK == unix.S_IFBLK { ++ var err error + b, err := c.sandbox.devManager.NewDevice(config.DeviceInfo{ + HostPath: devicePath, + ContainerPath: filepath.Join(kataGuestSharedDir(), c.id), +@@ -1313,10 +1314,18 @@ func (c *Container) plugDevice(ctx context.Context, devicePath string) error { + return fmt.Errorf("device manager failed to create rootfs device for %q: %v", devicePath, err) + } + ++ defer func() { ++ if err != nil { ++ if newErr := c.sandbox.devManager.RemoveDevice(b.DeviceID()); newErr != nil { ++ c.Logger().WithError(newErr).Error("fail rollback to remove block device") ++ } ++ } ++ }() ++ + c.state.BlockDeviceID = b.DeviceID() + + // attach rootfs device +- if err := c.sandbox.devManager.AttachDevice(ctx, b.DeviceID(), c.sandbox); err != nil { ++ if err = c.sandbox.devManager.AttachDevice(ctx, b.DeviceID(), c.sandbox); err != nil { + return err + } + } +-- +2.25.1 + diff --git a/series.conf b/series.conf index cbc50db..83a316b 100644 --- a/series.conf +++ b/series.conf @@ -18,3 +18,4 @@ 0018-kata-containers-check-VFIO-when-create-device.patch 0019-kata-containers-do-not-delete-the-exist-tap-device-in-t.patch 0020-kata-containers-do-not-ignore-updateInterface-return-er.patch +0021-kata-containers-fix-the-block-device-not-remove-in-devM.patch -- Gitee