minor patch for 2.1.108 fs/dcache.c

Bill Hawes (whawes@star.net)
Fri, 10 Jul 1998 12:32:37 -0400


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

This has been on my TODO list for a while ... this patch implements a
function is_root_busy() to test whether a filesystem can be unmounted
without destroying its dcache structure. This will help make autofs
considerably friendlier.

The code is straightforward -- it uses the root dentry's child lists to
look for any busy leaf nodes, and otherwise tests whether the number of
top-level child dentries exceeds the root use count.

I wasn't sure of the best way to integrate it into autofs, but Peter
Anvin will know what to do.

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

--- linux-2.1.108/include/linux/dcache.h.old Sun May 17 12:19:38 1998
+++ linux-2.1.108/include/linux/dcache.h Fri Jul 10 11:14:40 1998
@@ -138,6 +138,9 @@
/* only used at mount-time */
extern struct dentry * d_alloc_root(struct inode * root_inode, struct dentry * old_root);

+/* test whether root is busy without destroying dcache */
+extern int is_root_busy(struct dentry *);
+
/*
* This adds the entry to the hash queues and initializes "d_inode".
* The entry was actually filled in earlier during "d_alloc()"
--- linux-2.1.108/fs/dcache.c.old Sun May 17 12:19:36 1998
+++ linux-2.1.108/fs/dcache.c Fri Jul 10 10:54:20 1998
@@ -363,6 +363,46 @@
}

/*
+ * Check whether a root dentry would be in use if all of its
+ * child dentries were freed. This allows a non-destructive
+ * test for unmounting a device.
+ */
+int is_root_busy(struct dentry *root)
+{
+ struct dentry *this_parent = root;
+ struct list_head *next;
+ int count = 1; /* initial use count */
+
+repeat:
+ next = this_parent->d_subdirs.next;
+resume:
+ while (next != &this_parent->d_subdirs) {
+ struct list_head *tmp = next;
+ struct dentry *dentry = list_entry(tmp, struct dentry, d_child);
+ next = tmp->next;
+ /* count the top-level children */
+ if (this_parent == root)
+ count++;
+ if (!list_empty(&dentry->d_subdirs)) {
+ this_parent = dentry;
+ goto repeat;
+ }
+ /* root is busy if any leaf is busy */
+ if (dentry->d_count)
+ return 1;
+ }
+ /*
+ * All done at this level ... ascend and resume the search.
+ */
+ if (this_parent != root) {
+ next = this_parent->d_child.next;
+ this_parent = this_parent->d_parent;
+ goto resume;
+ }
+ return (root->d_count > count);
+}
+
+/*
* Search the dentry child list for the specified parent,
* and move any unused dentries to the end of the unused
* list for prune_dcache(). We descend to the next level
--- linux-2.1.108/kernel/ksyms.c.old Fri Jul 3 10:31:41 1998
+++ linux-2.1.108/kernel/ksyms.c Fri Jul 10 11:49:41 1998
@@ -189,6 +189,7 @@
EXPORT_SYMBOL(shrink_dcache_parent);
EXPORT_SYMBOL(find_inode_number);
EXPORT_SYMBOL(is_subdir);
+EXPORT_SYMBOL(is_root_busy);

#if !defined(CONFIG_NFSD) && defined(CONFIG_NFSD_MODULE)
EXPORT_SYMBOL(do_nfsservctl);

--------------EEE6305BCF53C0E5AE121592--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu