From 8ae0cd5c19f7479f99352f42f401116b259d1dd7 Mon Sep 17 00:00:00 2001 From: wujing Date: Mon, 27 Jun 2022 16:48:15 +0800 Subject: [PATCH] attempt to force delete when deleting directory fails Signed-off-by: wujing --- ...-delete-when-deleting-directory-fail.patch | 66 +++++++++++++++++++ lxc.spec | 9 ++- series.conf | 1 + 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 0044-attempt-to-force-delete-when-deleting-directory-fail.patch diff --git a/0044-attempt-to-force-delete-when-deleting-directory-fail.patch b/0044-attempt-to-force-delete-when-deleting-directory-fail.patch new file mode 100644 index 0000000..4085e32 --- /dev/null +++ b/0044-attempt-to-force-delete-when-deleting-directory-fail.patch @@ -0,0 +1,66 @@ +From 93429c7beedb977b44f6ea914582b49cb26a5a60 Mon Sep 17 00:00:00 2001 +From: wujing +Date: Mon, 27 Jun 2022 16:37:33 +0800 +Subject: [PATCH] attempt to force delete when deleting directory fails + +Signed-off-by: wujing +--- + src/lxc/utils.c | 35 +++++++++++++++++++++++++++++++++++ + 1 file changed, 35 insertions(+) + +diff --git a/src/lxc/utils.c b/src/lxc/utils.c +index b39b6a8..5aa8f94 100644 +--- a/src/lxc/utils.c ++++ b/src/lxc/utils.c +@@ -63,6 +63,33 @@ lxc_log_define(utils, lxc); + * if path is btrfs, tries to remove it and any subvolumes beneath it + */ + extern bool btrfs_try_remove_subvol(const char *path); ++#ifdef HAVE_ISULAD ++static int force_rmdir_exec(void *args) ++{ ++ const char *dirname = (const char *)args; ++ ++ execlp("rm", "rm", "-rf", dirname, (char *)NULL); ++ return -1; ++} ++ ++static int execute_force_rmdir(const char *dirname) ++{ ++ int ret; ++ char cmd_output[PATH_MAX]; ++ ++ if (dirname == NULL) { ++ ERROR("Directory path is NULL"); ++ return -1; ++ } ++ ++ ret = run_command(cmd_output, sizeof(cmd_output), force_rmdir_exec, (void *)dirname); ++ if (ret < 0) { ++ return log_error(-1, "Failed to delete directory forcely with command: rm -rf %s", dirname); ++ } ++ ++ return 0; ++} ++#endif + + static int _recursive_rmdir(const char *dirname, dev_t pdev, + const char *exclude, int level, bool onedev) +@@ -178,6 +205,14 @@ static int _recursive_rmdir(const char *dirname, dev_t pdev, + } + + #ifdef HAVE_ISULAD ++ if (failed != 0) { ++ WARN("Failed to recursive delete directory: \"%s\", try to delete it forcely", dirname); ++ failed = execute_force_rmdir(dirname); ++ if (failed != 0) { ++ ERROR("Failed to recursive delete directory forcely"); ++ } ++ } ++ + errno = saved_errno; + #endif + return failed ? -1 : 0; +-- +2.36.1 + diff --git a/lxc.spec b/lxc.spec index c907607..cc7dd2a 100644 --- a/lxc.spec +++ b/lxc.spec @@ -1,4 +1,4 @@ -%global _release 2022052501 +%global _release 2022062701 Name: lxc Version: 4.0.3 @@ -51,6 +51,7 @@ Patch0040: 0040-refactor-the-way-to-convert-selinux-label-to-shared.path Patch0041: 0041-do-not-free-the-pointer-returned-by-dirname.patch Patch0042: 0042-add-x-permission-when-create-directory.patch Patch0043: 0043-do-not-operate-playload-and-attach-cgroup-if-no-cont.patch +Patch0044: 0044-attempt-to-force-delete-when-deleting-directory-fail.patch BuildRequires: systemd-units git libtool graphviz docbook2X doxygen chrpath BuildRequires: pkgconfig(libseccomp) @@ -222,6 +223,12 @@ make check %{_mandir}/*/man7/%{name}* %changelog +* Mon Jun 2022 wujing - 4.0.3-2022062701 +- Type:improve +- ID:NA +- SUG:NA +- DESC: attempt to force delete when deleting directory fails + * Wed May 25 2022 hejunjie - 4.0.3-2022052501 - Type:bugfix - ID:NA diff --git a/series.conf b/series.conf index 00d07d0..bdc95fb 100644 --- a/series.conf +++ b/series.conf @@ -41,3 +41,4 @@ 0041-do-not-free-the-pointer-returned-by-dirname.patch 0042-add-x-permission-when-create-directory.patch 0043-do-not-operate-playload-and-attach-cgroup-if-no-cont.patch +0044-attempt-to-force-delete-when-deleting-directory-fail.patch -- Gitee