docker: remove useless mount point dir

fix #I7UQ2Y

Signed-off-by: flyflyflypeng <jiangpengfei9@huawei.com>
(cherry picked from commit 7179c48dbcd22d05fa3c84d6bcc15dad0bda9ecf)
This commit is contained in:
flyflyflypeng 2023-08-26 16:49:16 +08:00 committed by openeuler-sync-bot
parent 05b08ee965
commit 027945c03a
4 changed files with 92 additions and 2 deletions

View File

@ -1 +1 @@
18.09.0.258
18.09.0.259

View File

@ -1,6 +1,6 @@
Name: docker-engine
Version: 18.09.0
Release: 258
Release: 259
Epoch: 1
Summary: The open-source application container engine
Group: Tools/Docker
@ -199,6 +199,12 @@ fi
%endif
%changelog
* Mon Aug 28 2023 chenjiankun<chenjiankun1@huawei.com> - 18.09.0-259
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:remove useless mount point dir
* Fri Jul 28 2023 jingxiaolu<lujingxiao@huawei.com> - 18.09.0-258
- Type:bugfix
- CVE:NA

View File

@ -0,0 +1,83 @@
From bd1ebe87b72eaad2f213d554139eef478af95285 Mon Sep 17 00:00:00 2001
From: chenjiankun <chenjiankun1@huawei.com>
Date: Tue, 4 Jul 2023 19:43:54 +0800
Subject: [PATCH] docker: remove useless mount point dir
Concurrent execution of docker pull and restart dockerd, some mount point
dir may be left over. The reason is there is no time to do cleanup operation.
So we can cleanup the mount point dir when start dockerd.
---
.../daemon/graphdriver/devmapper/driver.go | 32 +++++++++++++++----
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/components/engine/daemon/graphdriver/devmapper/driver.go b/components/engine/daemon/graphdriver/devmapper/driver.go
index a1a6e17af..e6ad26e32 100644
--- a/components/engine/daemon/graphdriver/devmapper/driver.go
+++ b/components/engine/daemon/graphdriver/devmapper/driver.go
@@ -19,6 +19,7 @@ import (
"github.com/docker/go-units"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
+ "golang.org/x/sys/unix"
)
func init() {
@@ -127,11 +128,25 @@ func (d *Driver) GetMetadata(id string) (map[string]string, error) {
// GetAll not implemented
func (d *Driver) GetAll() []string {
- ids := []string{}
- for id, _ := range d.DeviceSet.Devices {
- ids = append(ids, id)
- }
- return ids
+ ids := []string{}
+
+ for id, _ := range d.DeviceSet.Devices {
+ ids = append(ids, id)
+ }
+
+ fs, err := ioutil.ReadDir(path.Join(d.home, "mnt"))
+ if err != nil {
+ logrus.Errorf("open directory(%s) failed: %s", d.home, err)
+ return ids
+ }
+
+ for _, f := range fs {
+ if dir, _ := ioutil.ReadDir(path.Join(d.home, "mnt", f.Name())); len(f.Name()) >= 64 && len(dir) == 0 {
+ ids = append(ids, f.Name())
+ }
+ }
+
+ return ids
}
// CheckParent not implemented
@@ -175,10 +190,15 @@ func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error {
func (d *Driver) Remove(id string) error {
d.locker.Lock(id)
defer d.locker.Unlock(id)
+
+ mp := path.Join(d.home, "mnt", id)
if !d.DeviceSet.HasDevice(id) {
// Consider removing a non-existing device a no-op
// This is useful to be able to progress on container removal
// if the underlying device has gone away due to earlier errors
+ if err := unix.Rmdir(mp); err != nil {
+ logrus.WithField("storage-driver", "devicemapper").Warnf("unable to remove redundancy mount point %q: %s", mp, err)
+ }
return nil
}
@@ -194,7 +214,7 @@ func (d *Driver) Remove(id string) error {
// to other mount namespaces. A failure to remove the container's
// mount point is not important and should not be treated
// as a failure to remove the container.
- mp := path.Join(d.home, "mnt", id)
+
// In some cases, there are some files in the mount point dir, so we can't use
// unix.Rmdir to remove mount point dir. os.RemoveAll is more appropriate
err := os.RemoveAll(mp)
--
2.33.0

View File

@ -250,4 +250,5 @@ patch/0258-docker-thinpool-full-because-kill-docker-daemon-when.patch
patch/0259-backport-fix-blockThreshold-full-bug.patch
patch/0260-docker-repalce-unix.Rmdir-with-os.RemoveAll-when-rem.patch
patch/0261-backport-client-define-a-dummy-hostname-to-use-for-local-conn.patch
patch/0262-docker-remove-useless-mount-point-dir.patch
#end