patch for 2.1.56 fs/readdir

Bill Hawes (whawes@star.net)
Sat, 20 Sep 1997 10:38:31 -0400


This is a multi-part message in MIME format.
--------------8670B4DD9B67941E31F2E009
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

In reviewing the ext2 readdir routine I noticed a lot of heuristic
checks to try to avoid changes in directory blocks while a directory
scan is in progress. As the new VFS now holds the parent directory
semaphore for operations that change directories, we can use this to
protect i_op->readdir against changes.

The attached patch adds semaphore locking to fs/readdir.c, and if this
checks out OK we should be able to remove a lot of time-consuming checks
from the ext2 readdir code. I'm running it here with no problems.

Regards,
Bill
--------------8670B4DD9B67941E31F2E009
Content-Type: text/plain; charset=us-ascii; name="readdir_56-patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="readdir_56-patch"

--- fs/readdir.c.old Wed Sep 10 09:21:27 1997
+++ fs/readdir.c Fri Sep 19 17:42:54 1997
@@ -87,7 +87,13 @@
if (!file->f_op || !file->f_op->readdir)
goto out;

+ /*
+ * Get the inode's semaphore to prevent changes
+ * to the directory while we read it.
+ */
+ down(&inode->i_sem);
error = file->f_op->readdir(file, &buf, fillonedir);
+ up(&inode->i_sem);
if (error < 0)
goto out;
error = buf.count;
@@ -173,7 +179,13 @@
if (!file->f_op || !file->f_op->readdir)
goto out;

+ /*
+ * Get the inode's semaphore to prevent changes
+ * to the directory while we read it.
+ */
+ down(&inode->i_sem);
error = file->f_op->readdir(file, &buf, filldir);
+ up(&inode->i_sem);
if (error < 0)
goto out;
lastdirent = buf.previous;

--------------8670B4DD9B67941E31F2E009--