2019-12-25 15:57:42 +08:00
|
|
|
From 5e13dd95a5e96b3d9bc9e28b6d8912625b92ce20 Mon Sep 17 00:00:00 2001
|
2019-09-30 11:03:07 -04:00
|
|
|
From: tanyifeng <tanyifeng1@huawei.com>
|
|
|
|
|
Date: Sat, 16 Mar 2019 10:06:13 +0800
|
2019-12-25 15:57:42 +08:00
|
|
|
Subject: [PATCH 067/131] lxc: report error when remove directory failed
|
2019-09-30 11:03:07 -04:00
|
|
|
|
|
|
|
|
Signed-off-by: tanyifeng <tanyifeng1@huawei.com>
|
|
|
|
|
Signed-off-by: LiFeng <lifeng68@huawei.com>
|
|
|
|
|
---
|
|
|
|
|
src/lxc/lxccontainer.c | 3 +++
|
|
|
|
|
src/lxc/utils.c | 9 ++++++++-
|
|
|
|
|
2 files changed, 11 insertions(+), 1 deletion(-)
|
|
|
|
|
|
|
|
|
|
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
|
2019-12-25 15:57:42 +08:00
|
|
|
index bfbf223b..3fd1a66c 100644
|
2019-09-30 11:03:07 -04:00
|
|
|
--- a/src/lxc/lxccontainer.c
|
|
|
|
|
+++ b/src/lxc/lxccontainer.c
|
|
|
|
|
@@ -3148,8 +3148,11 @@ static bool container_destroy(struct lxc_container *c,
|
|
|
|
|
else
|
|
|
|
|
ret = lxc_rmdir_onedev(path, "snaps");
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
+ char msg[BUFSIZ] = { 0 };
|
|
|
|
|
ERROR("Failed to destroy directory \"%s\" for \"%s\"", path,
|
|
|
|
|
c->name);
|
|
|
|
|
+ sprintf(msg, "Failed to destroy directory \"%s\": %s", path, errno ? strerror(errno) : "error");
|
|
|
|
|
+ c->error_string = strdup(msg);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
INFO("Destroyed directory \"%s\" for \"%s\"", path, c->name);
|
|
|
|
|
diff --git a/src/lxc/utils.c b/src/lxc/utils.c
|
2019-12-25 15:57:42 +08:00
|
|
|
index 91ba4935..480e6d0a 100644
|
2019-09-30 11:03:07 -04:00
|
|
|
--- a/src/lxc/utils.c
|
|
|
|
|
+++ b/src/lxc/utils.c
|
|
|
|
|
@@ -88,6 +88,7 @@ static int _recursive_rmdir(const char *dirname, dev_t pdev,
|
|
|
|
|
int ret, failed = 0;
|
|
|
|
|
char pathname[PATH_MAX];
|
|
|
|
|
bool hadexclude = false;
|
|
|
|
|
+ int saved_errno = 0;
|
|
|
|
|
|
|
|
|
|
dir = opendir(dirname);
|
|
|
|
|
if (!dir) {
|
|
|
|
|
@@ -153,6 +154,9 @@ static int _recursive_rmdir(const char *dirname, dev_t pdev,
|
|
|
|
|
failed=1;
|
|
|
|
|
} else {
|
|
|
|
|
if (unlink(pathname) < 0) {
|
|
|
|
|
+ if (saved_errno == 0) {
|
|
|
|
|
+ saved_errno = errno;
|
|
|
|
|
+ }
|
|
|
|
|
SYSERROR("Failed to delete \"%s\"", pathname);
|
|
|
|
|
failed=1;
|
|
|
|
|
}
|
|
|
|
|
@@ -160,6 +164,9 @@ static int _recursive_rmdir(const char *dirname, dev_t pdev,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rmdir(dirname) < 0 && !btrfs_try_remove_subvol(dirname) && !hadexclude) {
|
|
|
|
|
+ if (saved_errno == 0) {
|
|
|
|
|
+ saved_errno = errno;
|
|
|
|
|
+ }
|
|
|
|
|
SYSERROR("Failed to delete \"%s\"", dirname);
|
|
|
|
|
failed=1;
|
|
|
|
|
}
|
|
|
|
|
@@ -169,7 +176,7 @@ static int _recursive_rmdir(const char *dirname, dev_t pdev,
|
|
|
|
|
SYSERROR("Failed to close directory \"%s\"", dirname);
|
|
|
|
|
failed=1;
|
|
|
|
|
}
|
|
|
|
|
-
|
|
|
|
|
+ errno = saved_errno;
|
|
|
|
|
return failed ? -1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
--
|
2019-12-25 15:57:42 +08:00
|
|
|
2.23.0
|
2019-09-30 11:03:07 -04:00
|
|
|
|