docker: remove useless mount point dir

fix #I7UQ2Y

Signed-off-by: flyflyflypeng <jiangpengfei9@huawei.com>
This commit is contained in:
flyflyflypeng 2023-08-26 16:44:48 +08:00
parent 26bff3a4ab
commit e519069449
5 changed files with 93 additions and 3 deletions

View File

@ -1 +1 @@
18.09.0.328
18.09.0.329

View File

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

View File

@ -1 +1 @@
458f41acf23755199655213371d48851fd11256e
b6b7823cc9a4211b105d0082b0f2f2308d739b9f

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

@ -259,4 +259,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