[PATCH 10/10] [RFC] Use call_usermodehelper to cleanup after failure

Matt Helsley matthltc at us.ibm.com
Mon Feb 28 20:05:16 PST 2011


Without this sys_checkpoint may fail yet still leave files relinked
in <mnt>/lost+found/checkpoint-N/. This patch uses call_usermodehelper()
to clean up those files if sys_checkpoint has failed.

It is possible to do this from userspace instead but due to the
need to parse the image and/or traverse all mount namespaces and mounts
the complexity of the code will be much higher there. That said, this
is an "rm -rf" invoked by the kernel -- not something we want to stuff in
the kernel without considerable forethought. So I've made ths an RFC and,
until this patch gets accepted, we can plan on cleaning up from userspace.

Signed-off-by: Matt Helsley <matthltc at us.ibm.com>
---
 fs/namei.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index f6361f8..0084ceb 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2599,6 +2599,21 @@ static void mkdirname(char *path, char **delim_p)
 	}
 }
 
+static int checkpoint_rm_relink_collection(void *dq_data)
+{
+	char *argv[4], *envp[2];
+
+	argv[0] = "rm";
+	argv[1] = "-rf";
+	argv[2] = dq_data;
+	argv[3] = NULL;
+
+	envp[0] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
+	envp[1] = NULL;
+
+	return call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC);
+}
+
 /*
  * Make the directory used to collect all of the links in. Remove it
  * if checkpoint fails.
@@ -2614,6 +2629,9 @@ static int checkpoint_make_relink_collection(struct ckpt_ctx *ctx,
 	if (!delim || (strlen(new_path) < 2)) /* Need a non-empty dirname */
 		return -ENOENT;
 	ret = kernel_sys_mkdir(new_path, S_IRWXU & ~current_umask());
+	if (!ret)
+		deferqueue_add(ctx->err_deferq, new_path, delim - new_path + 1,
+			       checkpoint_rm_relink_collection, NULL);
 	if (delim)
 		*delim = '/';
 	if (ret == -EEXIST) /* already created the collection dir */
-- 
1.6.3.3



More information about the Containers mailing list