linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Galbraith <mikeg@wen-online.de>
To: linux-kernel <linux-kernel@vger.kernel.org>
Cc: Alexander Viro <viro@math.psu.edu>
Subject: [patch] Re: 2.5.7 rm -r in tmpfs problem
Date: Wed, 27 Mar 2002 11:24:46 +0100 (CET)	[thread overview]
Message-ID: <Pine.LNX.4.10.10203271112410.639-100000@mikeg.wen-online.de> (raw)
In-Reply-To: <Pine.LNX.4.10.10203261736010.440-100000@mikeg.wen-online.de>

On Tue, 26 Mar 2002, Mike Galbraith wrote:

> On Sat, 23 Mar 2002, Alexander Viro wrote:
> 
> > There are known problems with rm(1) on ramfs/tmpfs/etc. - the thing assumes
> > that offsets in directory remain stable after unlink(2), but locking changes
> > didn't affect.
> 
> Ok, I finally found a wee bit of clue.  I understand the assumption,
> and in virgin 2.5.4, that assumption is enforced... somefsckingwhere ;-)

I suppose that doesn't matter much though, since the assumption working
still doesn't make it right. (mentioned it because I can't figure out
why the behavior changed despite MUCH reading.. seemed odd/reportable)

Anyway, the hack below seems to work fine.  Is there a better way?

	-Mike


--- fs/libfs.c.org	Sun Mar 24 13:20:39 2002
+++ fs/libfs.c	Wed Mar 27 10:46:13 2002
@@ -29,6 +29,21 @@
 	return 0;
 }
 
+static int seek_ok(struct dentry *dir, int offset)
+{
+	struct list_head *list;
+	int count = 2;
+
+	list = dir->d_subdirs.next;
+
+	while(list != &dir->d_subdirs) {
+		list = list->next;
+		count++;
+	}
+	
+	return offset > count;
+}
+
 /*
  * Directory is locked and all positive dentries in it are safe, since
  * for ramfs-type trees they can't go away without unlink() or rmdir(),
@@ -37,10 +52,9 @@
 
 int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
 {
-	int i;
+	int i = filp->f_pos;
 	struct dentry *dentry = filp->f_dentry;
 
-	i = filp->f_pos;
 	switch (i) {
 		case 0:
 			if (filldir(dirent, ".", 1, i, dentry->d_inode->i_ino, DT_DIR) < 0)
@@ -57,11 +71,17 @@
 		default: {
 			struct list_head *list;
 			int j = i-2;
+			int abort;
 
 			spin_lock(&dcache_lock);
 			list = dentry->d_subdirs.next;
+			/*
+			 * HACK: if we're attempting to seek _past_ the last
+			 * entry, the directory is being modified. Abort seek.
+			 */
+			abort = seek_ok(dentry, i);
 
-			for (;;) {
+			for (;!abort;) {
 				if (list == &dentry->d_subdirs) {
 					spin_unlock(&dcache_lock);
 					return 0;



      reply	other threads:[~2002-03-27 10:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-22 11:52 2.5.7 rm -r in tmpfs problem Mike Galbraith
2002-03-23 15:36 ` [datapoint] " Mike Galbraith
2002-03-23 15:41   ` Alexander Viro
2002-03-23 16:04     ` Mike Galbraith
2002-03-26 16:55     ` Mike Galbraith
2002-03-27 10:24       ` Mike Galbraith [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.10.10203271112410.639-100000@mikeg.wen-online.de \
    --to=mikeg@wen-online.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@math.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).