+ uml-rename-and-improve-actually_do_remove.patch added to -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled

     uml: rename and improve actually_do_remove()

has been added to the -mm tree.  Its filename is

     uml-rename-and-improve-actually_do_remove.patch

See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find
out what to do about this


From: Paolo 'Blaisorblade' Giarrusso <blaisorblade@xxxxxxxx>

Rename actually_do_remove() to remove_files_and_dir(), make it call
closedir(), make it ignore ENOENT (I see it frequently enough).

ENOENT is probably due to multiple threads calling the exitcall functions
together*, but fixing that is non-trivial; and ignoring it is perfectly ok
in any case.

* it can surely happen: last_ditch_exit() is installed as SIGTERM handler
  at boot, and it's not removed on thread creation.  So killall vmlinux
  (which I do) surely causes that.  I've seen also a crash which seems to
  do the same.

Installing the handler on only the main thread would make UML do no cleanup
when another thread exits, and we're not sure we want that.  And mutual
exclusion in that context is tricky - we can't use spinlock in code not on
a kernel stack (spinlock debugging uses "current" a lot).

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@xxxxxxxx>
Cc: Jeff Dike <jdike@xxxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxx>
---

 arch/um/os-Linux/umid.c |   53 ++++++++++++++++++++++++++------------
 1 files changed, 37 insertions(+), 16 deletions(-)

diff -puN arch/um/os-Linux/umid.c~uml-rename-and-improve-actually_do_remove arch/um/os-Linux/umid.c
--- devel/arch/um/os-Linux/umid.c~uml-rename-and-improve-actually_do_remove	2006-04-30 13:23:30.000000000 -0700
+++ devel-akpm/arch/um/os-Linux/umid.c	2006-04-30 13:23:30.000000000 -0700
@@ -67,32 +67,53 @@ err:
 	return err;
 }
 
-static int actually_do_remove(char *dir)
+/*
+ * Unlinks the files contained in @dir and then removes @dir.
+ * Doesn't handle directory trees, so it's not like rm -rf, but almost such. We
+ * ignore ENOENT errors for anything (they happen, strangely enough - possibly due
+ * to races between multiple dying UML threads).
+ */
+static int remove_files_and_dir(char *dir)
 {
 	DIR *directory;
 	struct dirent *ent;
 	int len;
 	char file[256];
+	int ret;
 
 	directory = opendir(dir);
-	if(directory == NULL)
-		return -errno;
+	if (directory == NULL) {
+		if (errno != ENOENT)
+			return -errno;
+		else
+			return 0;
+	}
 
-	while((ent = readdir(directory)) != NULL){
-		if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
+	while ((ent = readdir(directory)) != NULL) {
+		if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
 			continue;
 		len = strlen(dir) + sizeof("/") + strlen(ent->d_name) + 1;
-		if(len > sizeof(file))
-			return -E2BIG;
+		if (len > sizeof(file)) {
+			ret = -E2BIG;
+			goto out;
+		}
 
 		sprintf(file, "%s/%s", dir, ent->d_name);
-		if(unlink(file) < 0)
-			return -errno;
+		if (unlink(file) < 0 && errno != ENOENT) {
+			ret = -errno;
+			goto out;
+		}
 	}
-	if(rmdir(dir) < 0)
-		return -errno;
 
-	return 0;
+	if (rmdir(dir) < 0 && errno != ENOENT) {
+		ret = -errno;
+		goto out;
+	}
+
+	ret = 0;
+out:
+	closedir(directory);
+	return ret;
 }
 
 /* This says that there isn't already a user of the specified directory even if
@@ -172,9 +193,9 @@ static int umdir_take_if_dead(char *dir)
 	if (is_umdir_used(dir))
 		return -EEXIST;
 
-	ret = actually_do_remove(dir);
+	ret = remove_files_and_dir(dir);
 	if (ret) {
-		printk("is_umdir_used - actually_do_remove failed with "
+		printk("is_umdir_used - remove_files_and_dir failed with "
 		       "err = %d\n", ret);
 	}
 	return ret;
@@ -354,9 +375,9 @@ static void remove_umid_dir(void)
 	char dir[strlen(uml_dir) + UMID_LEN + 1], err;
 
 	sprintf(dir, "%s%s", uml_dir, umid);
-	err = actually_do_remove(dir);
+	err = remove_files_and_dir(dir);
 	if(err)
-		printf("remove_umid_dir - actually_do_remove failed with "
+		printf("remove_umid_dir - remove_files_and_dir failed with "
 		       "err = %d\n", err);
 }
 
_

Patches currently in -mm which might be from blaisorblade@xxxxxxxx are

uml-fix-iomem-list-traversal.patch
uml-skas0-support-for-2g-2g-hosts.patch
uml-remove-null-checks-and-add-some-codingstyle.patch
uml-clean-up-after-madvise_remove.patch
uml-update-defconfig.patch
uml-error-handling-fixes.patch
uml-fix-patch-mismerge.patch
uml-search-from-uml_net-in-a-more-reasonable-path.patch
uml-use-kbuild-tracking-for-all-files-and-fix-compilation-output.patch
uml-fix-compilation-and-execution-with-hardened-gcc.patch
uml-cleanup-unprofile-expression-and-build-infrastructure.patch
uml-export-symbols-added-by-gcc-hardened.patch
uml-make-copy__user-atomic.patch
uml-fix-not_dead_yet-when-directory-is-in-bad-state.patch
uml-rename-and-improve-actually_do_remove.patch

-
To unsubscribe from this list: send the line "unsubscribe mm-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Kernel Newbies FAQ]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Photo]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux