2005-04-17 06:20:36 +08:00
|
|
|
/* -*- c -*- --------------------------------------------------------------- *
|
|
|
|
*
|
|
|
|
* linux/fs/autofs/expire.c
|
|
|
|
*
|
|
|
|
* Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
|
|
|
|
* Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org>
|
2006-03-27 17:14:55 +08:00
|
|
|
* Copyright 2001-2006 Ian Kent <raven@themaw.net>
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* This file is part of the Linux kernel and is made available under
|
|
|
|
* the terms of the GNU General Public License, version 2, or at your
|
|
|
|
* option, any later version, incorporated herein by reference.
|
|
|
|
*
|
|
|
|
* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#include "autofs_i.h"
|
|
|
|
|
|
|
|
static unsigned long now;
|
|
|
|
|
2006-03-27 17:14:44 +08:00
|
|
|
/* Check if a dentry can be expired */
|
2005-04-17 06:20:36 +08:00
|
|
|
static inline int autofs4_can_expire(struct dentry *dentry,
|
|
|
|
unsigned long timeout, int do_now)
|
|
|
|
{
|
|
|
|
struct autofs_info *ino = autofs4_dentry_ino(dentry);
|
|
|
|
|
|
|
|
/* dentry in the process of being deleted */
|
|
|
|
if (ino == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* No point expiring a pending mount */
|
|
|
|
if (dentry->d_flags & DCACHE_AUTOFS_PENDING)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!do_now) {
|
|
|
|
/* Too young to die */
|
|
|
|
if (time_after(ino->last_used + timeout, now))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* update last_used here :-
|
|
|
|
- obviously makes sense if it is in use now
|
|
|
|
- less obviously, prevents rapid-fire expire
|
|
|
|
attempts if expire fails the first time */
|
|
|
|
ino->last_used = now;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-03-27 17:14:44 +08:00
|
|
|
/* Check a mount point for busyness */
|
|
|
|
static int autofs4_mount_busy(struct vfsmount *mnt, struct dentry *dentry)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-03-27 17:14:47 +08:00
|
|
|
struct dentry *top = dentry;
|
2006-03-27 17:14:44 +08:00
|
|
|
int status = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
DPRINTK("dentry %p %.*s",
|
|
|
|
dentry, (int)dentry->d_name.len, dentry->d_name.name);
|
|
|
|
|
|
|
|
mntget(mnt);
|
|
|
|
dget(dentry);
|
|
|
|
|
2005-06-22 08:16:38 +08:00
|
|
|
if (!autofs4_follow_mount(&mnt, &dentry))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* This is an autofs submount, we can't expire it */
|
|
|
|
if (is_autofs4_dentry(dentry))
|
|
|
|
goto done;
|
|
|
|
|
2006-03-27 17:14:47 +08:00
|
|
|
/* Update the expiry counter if fs is busy */
|
2006-03-27 17:14:51 +08:00
|
|
|
if (!may_umount_tree(mnt)) {
|
2006-03-27 17:14:47 +08:00
|
|
|
struct autofs_info *ino = autofs4_dentry_ino(top);
|
|
|
|
ino->last_used = jiffies;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
done:
|
|
|
|
DPRINTK("returning = %d", status);
|
|
|
|
mntput(mnt);
|
|
|
|
dput(dentry);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2006-03-27 17:14:45 +08:00
|
|
|
/*
|
|
|
|
* Calculate next entry in top down tree traversal.
|
|
|
|
* From next_mnt in namespace.c - elegant.
|
|
|
|
*/
|
|
|
|
static struct dentry *next_dentry(struct dentry *p, struct dentry *root)
|
|
|
|
{
|
|
|
|
struct list_head *next = p->d_subdirs.next;
|
|
|
|
|
|
|
|
if (next == &p->d_subdirs) {
|
|
|
|
while (1) {
|
|
|
|
if (p == root)
|
|
|
|
return NULL;
|
|
|
|
next = p->d_u.d_child.next;
|
|
|
|
if (next != &p->d_parent->d_subdirs)
|
|
|
|
break;
|
|
|
|
p = p->d_parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list_entry(next, struct dentry, d_u.d_child);
|
|
|
|
}
|
|
|
|
|
2006-03-27 17:14:55 +08:00
|
|
|
/*
|
|
|
|
* Check a direct mount point for busyness.
|
|
|
|
* Direct mounts have similar expiry semantics to tree mounts.
|
|
|
|
* The tree is not busy iff no mountpoints are busy and there are no
|
|
|
|
* autofs submounts.
|
|
|
|
*/
|
|
|
|
static int autofs4_direct_busy(struct vfsmount *mnt,
|
|
|
|
struct dentry *top,
|
|
|
|
unsigned long timeout,
|
|
|
|
int do_now)
|
|
|
|
{
|
|
|
|
DPRINTK("top %p %.*s",
|
|
|
|
top, (int) top->d_name.len, top->d_name.name);
|
|
|
|
|
|
|
|
/* If it's busy update the expiry counters */
|
|
|
|
if (!may_umount_tree(mnt)) {
|
|
|
|
struct autofs_info *ino = autofs4_dentry_ino(top);
|
|
|
|
if (ino)
|
|
|
|
ino->last_used = jiffies;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Timeout of a direct mount is determined by its top dentry */
|
|
|
|
if (!autofs4_can_expire(top, timeout, do_now))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Check a directory tree of mount points for busyness
|
|
|
|
* The tree is not busy iff no mountpoints are busy
|
|
|
|
*/
|
2006-03-27 17:14:44 +08:00
|
|
|
static int autofs4_tree_busy(struct vfsmount *mnt,
|
|
|
|
struct dentry *top,
|
|
|
|
unsigned long timeout,
|
|
|
|
int do_now)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-03-27 17:14:47 +08:00
|
|
|
struct autofs_info *top_ino = autofs4_dentry_ino(top);
|
2006-03-27 17:14:45 +08:00
|
|
|
struct dentry *p;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-27 17:14:44 +08:00
|
|
|
DPRINTK("top %p %.*s",
|
2005-04-17 06:20:36 +08:00
|
|
|
top, (int)top->d_name.len, top->d_name.name);
|
|
|
|
|
|
|
|
/* Negative dentry - give up */
|
|
|
|
if (!simple_positive(top))
|
2006-03-27 17:14:44 +08:00
|
|
|
return 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock(&dcache_lock);
|
2006-03-27 17:14:45 +08:00
|
|
|
for (p = top; p; p = next_dentry(p, top)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Negative dentry - give up */
|
2006-03-27 17:14:45 +08:00
|
|
|
if (!simple_positive(p))
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
DPRINTK("dentry %p %.*s",
|
2006-03-27 17:14:45 +08:00
|
|
|
p, (int) p->d_name.len, p->d_name.name);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-27 17:14:45 +08:00
|
|
|
p = dget(p);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock(&dcache_lock);
|
|
|
|
|
2006-03-27 17:14:46 +08:00
|
|
|
/*
|
|
|
|
* Is someone visiting anywhere in the subtree ?
|
|
|
|
* If there's no mount we need to check the usage
|
|
|
|
* count for the autofs dentry.
|
2006-03-27 17:14:47 +08:00
|
|
|
* If the fs is busy update the expiry counter.
|
2006-03-27 17:14:46 +08:00
|
|
|
*/
|
2006-03-27 17:14:45 +08:00
|
|
|
if (d_mountpoint(p)) {
|
|
|
|
if (autofs4_mount_busy(mnt, p)) {
|
2006-03-27 17:14:47 +08:00
|
|
|
top_ino->last_used = jiffies;
|
2006-03-27 17:14:45 +08:00
|
|
|
dput(p);
|
2006-03-27 17:14:44 +08:00
|
|
|
return 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-03-27 17:14:46 +08:00
|
|
|
} else {
|
2006-03-27 17:14:47 +08:00
|
|
|
struct autofs_info *ino = autofs4_dentry_ino(p);
|
2006-03-27 17:14:46 +08:00
|
|
|
unsigned int ino_count = atomic_read(&ino->count);
|
|
|
|
|
|
|
|
/* allow for dget above and top is already dgot */
|
|
|
|
if (p == top)
|
|
|
|
ino_count += 2;
|
|
|
|
else
|
|
|
|
ino_count++;
|
|
|
|
|
|
|
|
if (atomic_read(&p->d_count) > ino_count) {
|
2006-03-27 17:14:47 +08:00
|
|
|
top_ino->last_used = jiffies;
|
2006-03-27 17:14:46 +08:00
|
|
|
dput(p);
|
|
|
|
return 1;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-03-27 17:14:45 +08:00
|
|
|
dput(p);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock(&dcache_lock);
|
|
|
|
}
|
|
|
|
spin_unlock(&dcache_lock);
|
2006-03-27 17:14:46 +08:00
|
|
|
|
|
|
|
/* Timeout of a tree mount is ultimately determined by its top dentry */
|
|
|
|
if (!autofs4_can_expire(top, timeout, do_now))
|
|
|
|
return 1;
|
|
|
|
|
2006-03-27 17:14:44 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct dentry *autofs4_check_leaves(struct vfsmount *mnt,
|
|
|
|
struct dentry *parent,
|
|
|
|
unsigned long timeout,
|
|
|
|
int do_now)
|
|
|
|
{
|
2006-03-27 17:14:45 +08:00
|
|
|
struct dentry *p;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
DPRINTK("parent %p %.*s",
|
|
|
|
parent, (int)parent->d_name.len, parent->d_name.name);
|
|
|
|
|
|
|
|
spin_lock(&dcache_lock);
|
2006-03-27 17:14:45 +08:00
|
|
|
for (p = parent; p; p = next_dentry(p, parent)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Negative dentry - give up */
|
2006-03-27 17:14:45 +08:00
|
|
|
if (!simple_positive(p))
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
DPRINTK("dentry %p %.*s",
|
2006-03-27 17:14:45 +08:00
|
|
|
p, (int) p->d_name.len, p->d_name.name);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-27 17:14:45 +08:00
|
|
|
p = dget(p);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock(&dcache_lock);
|
|
|
|
|
2006-03-27 17:14:45 +08:00
|
|
|
if (d_mountpoint(p)) {
|
2006-03-27 17:14:47 +08:00
|
|
|
/* Can we umount this guy */
|
|
|
|
if (autofs4_mount_busy(mnt, p))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto cont;
|
|
|
|
|
2006-03-27 17:14:47 +08:00
|
|
|
/* Can we expire this guy */
|
|
|
|
if (autofs4_can_expire(p, timeout, do_now))
|
2006-03-27 17:14:45 +08:00
|
|
|
return p;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
cont:
|
2006-03-27 17:14:45 +08:00
|
|
|
dput(p);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock(&dcache_lock);
|
|
|
|
}
|
|
|
|
spin_unlock(&dcache_lock);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-03-27 17:14:55 +08:00
|
|
|
/* Check if we can expire a direct mount (possibly a tree) */
|
|
|
|
static struct dentry *autofs4_expire_direct(struct super_block *sb,
|
|
|
|
struct vfsmount *mnt,
|
|
|
|
struct autofs_sb_info *sbi,
|
|
|
|
int how)
|
|
|
|
{
|
|
|
|
unsigned long timeout;
|
|
|
|
struct dentry *root = dget(sb->s_root);
|
|
|
|
int do_now = how & AUTOFS_EXP_IMMEDIATE;
|
|
|
|
|
|
|
|
if (!sbi->exp_timeout || !root)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
now = jiffies;
|
|
|
|
timeout = sbi->exp_timeout;
|
|
|
|
|
|
|
|
/* Lock the tree as we must expire as a whole */
|
|
|
|
spin_lock(&sbi->fs_lock);
|
|
|
|
if (!autofs4_direct_busy(mnt, root, timeout, do_now)) {
|
|
|
|
struct autofs_info *ino = autofs4_dentry_ino(root);
|
|
|
|
|
|
|
|
/* Set this flag early to catch sys_chdir and the like */
|
|
|
|
ino->flags |= AUTOFS_INF_EXPIRING;
|
|
|
|
spin_unlock(&sbi->fs_lock);
|
|
|
|
return root;
|
|
|
|
}
|
|
|
|
spin_unlock(&sbi->fs_lock);
|
|
|
|
dput(root);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Find an eligible tree to time-out
|
|
|
|
* A tree is eligible if :-
|
|
|
|
* - it is unused by any user process
|
|
|
|
* - it has been unused for exp_timeout time
|
|
|
|
*/
|
2006-03-27 17:14:55 +08:00
|
|
|
static struct dentry *autofs4_expire_indirect(struct super_block *sb,
|
|
|
|
struct vfsmount *mnt,
|
|
|
|
struct autofs_sb_info *sbi,
|
|
|
|
int how)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long timeout;
|
|
|
|
struct dentry *root = sb->s_root;
|
|
|
|
struct dentry *expired = NULL;
|
|
|
|
struct list_head *next;
|
|
|
|
int do_now = how & AUTOFS_EXP_IMMEDIATE;
|
|
|
|
int exp_leaves = how & AUTOFS_EXP_LEAVES;
|
|
|
|
|
|
|
|
if ( !sbi->exp_timeout || !root )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
now = jiffies;
|
|
|
|
timeout = sbi->exp_timeout;
|
|
|
|
|
|
|
|
spin_lock(&dcache_lock);
|
|
|
|
next = root->d_subdirs.next;
|
|
|
|
|
|
|
|
/* On exit from the loop expire is set to a dgot dentry
|
|
|
|
* to expire or it's NULL */
|
|
|
|
while ( next != &root->d_subdirs ) {
|
[PATCH] shrink dentry struct
Some long time ago, dentry struct was carefully tuned so that on 32 bits
UP, sizeof(struct dentry) was exactly 128, ie a power of 2, and a multiple
of memory cache lines.
Then RCU was added and dentry struct enlarged by two pointers, with nice
results for SMP, but not so good on UP, because breaking the above tuning
(128 + 8 = 136 bytes)
This patch reverts this unwanted side effect, by using an union (d_u),
where d_rcu and d_child are placed so that these two fields can share their
memory needs.
At the time d_free() is called (and d_rcu is really used), d_child is known
to be empty and not touched by the dentry freeing.
Lockless lookups only access d_name, d_parent, d_lock, d_op, d_flags (so
the previous content of d_child is not needed if said dentry was unhashed
but still accessed by a CPU because of RCU constraints)
As dentry cache easily contains millions of entries, a size reduction is
worth the extra complexity of the ugly C union.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Cc: Dipankar Sarma <dipankar@in.ibm.com>
Cc: Maneesh Soni <maneesh@in.ibm.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>
Cc: "Paul E. McKenney" <paulmck@us.ibm.com>
Cc: Ian Kent <raven@themaw.net>
Cc: Paul Jackson <pj@sgi.com>
Cc: Al Viro <viro@ftp.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Trond Myklebust <trond.myklebust@fys.uio.no>
Cc: Neil Brown <neilb@cse.unsw.edu.au>
Cc: James Morris <jmorris@namei.org>
Cc: Stephen Smalley <sds@epoch.ncsc.mil>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-08 17:03:32 +08:00
|
|
|
struct dentry *dentry = list_entry(next, struct dentry, d_u.d_child);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Negative dentry - give up */
|
2006-03-27 17:14:44 +08:00
|
|
|
if (!simple_positive(dentry)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
next = next->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
dentry = dget(dentry);
|
|
|
|
spin_unlock(&dcache_lock);
|
|
|
|
|
2006-03-27 17:14:55 +08:00
|
|
|
/*
|
|
|
|
* Case 1: (i) indirect mount or top level pseudo direct mount
|
|
|
|
* (autofs-4.1).
|
|
|
|
* (ii) indirect mount with offset mount, check the "/"
|
|
|
|
* offset (autofs-5.0+).
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if (d_mountpoint(dentry)) {
|
|
|
|
DPRINTK("checking mountpoint %p %.*s",
|
|
|
|
dentry, (int)dentry->d_name.len, dentry->d_name.name);
|
|
|
|
|
2006-03-27 17:14:47 +08:00
|
|
|
/* Can we umount this guy */
|
|
|
|
if (autofs4_mount_busy(mnt, dentry))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto next;
|
|
|
|
|
2006-03-27 17:14:47 +08:00
|
|
|
/* Can we expire this guy */
|
|
|
|
if (autofs4_can_expire(dentry, timeout, do_now)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
expired = dentry;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
2006-03-27 17:14:44 +08:00
|
|
|
if (simple_empty(dentry))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto next;
|
|
|
|
|
|
|
|
/* Case 2: tree mount, expire iff entire tree is not busy */
|
|
|
|
if (!exp_leaves) {
|
2005-05-01 23:59:17 +08:00
|
|
|
/* Lock the tree as we must expire as a whole */
|
|
|
|
spin_lock(&sbi->fs_lock);
|
2006-03-27 17:14:44 +08:00
|
|
|
if (!autofs4_tree_busy(mnt, dentry, timeout, do_now)) {
|
2005-05-01 23:59:17 +08:00
|
|
|
struct autofs_info *inf = autofs4_dentry_ino(dentry);
|
|
|
|
|
|
|
|
/* Set this flag early to catch sys_chdir and the like */
|
|
|
|
inf->flags |= AUTOFS_INF_EXPIRING;
|
|
|
|
spin_unlock(&sbi->fs_lock);
|
|
|
|
expired = dentry;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-05-01 23:59:17 +08:00
|
|
|
spin_unlock(&sbi->fs_lock);
|
2006-03-27 17:14:55 +08:00
|
|
|
/*
|
|
|
|
* Case 3: pseudo direct mount, expire individual leaves
|
|
|
|
* (autofs-4.1).
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
expired = autofs4_check_leaves(mnt, dentry, timeout, do_now);
|
|
|
|
if (expired) {
|
|
|
|
dput(dentry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
next:
|
|
|
|
dput(dentry);
|
|
|
|
spin_lock(&dcache_lock);
|
|
|
|
next = next->next;
|
|
|
|
}
|
|
|
|
|
2006-03-27 17:14:44 +08:00
|
|
|
if (expired) {
|
2005-04-17 06:20:36 +08:00
|
|
|
DPRINTK("returning %p %.*s",
|
|
|
|
expired, (int)expired->d_name.len, expired->d_name.name);
|
|
|
|
spin_lock(&dcache_lock);
|
|
|
|
list_del(&expired->d_parent->d_subdirs);
|
[PATCH] shrink dentry struct
Some long time ago, dentry struct was carefully tuned so that on 32 bits
UP, sizeof(struct dentry) was exactly 128, ie a power of 2, and a multiple
of memory cache lines.
Then RCU was added and dentry struct enlarged by two pointers, with nice
results for SMP, but not so good on UP, because breaking the above tuning
(128 + 8 = 136 bytes)
This patch reverts this unwanted side effect, by using an union (d_u),
where d_rcu and d_child are placed so that these two fields can share their
memory needs.
At the time d_free() is called (and d_rcu is really used), d_child is known
to be empty and not touched by the dentry freeing.
Lockless lookups only access d_name, d_parent, d_lock, d_op, d_flags (so
the previous content of d_child is not needed if said dentry was unhashed
but still accessed by a CPU because of RCU constraints)
As dentry cache easily contains millions of entries, a size reduction is
worth the extra complexity of the ugly C union.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Cc: Dipankar Sarma <dipankar@in.ibm.com>
Cc: Maneesh Soni <maneesh@in.ibm.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>
Cc: "Paul E. McKenney" <paulmck@us.ibm.com>
Cc: Ian Kent <raven@themaw.net>
Cc: Paul Jackson <pj@sgi.com>
Cc: Al Viro <viro@ftp.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Trond Myklebust <trond.myklebust@fys.uio.no>
Cc: Neil Brown <neilb@cse.unsw.edu.au>
Cc: James Morris <jmorris@namei.org>
Cc: Stephen Smalley <sds@epoch.ncsc.mil>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-08 17:03:32 +08:00
|
|
|
list_add(&expired->d_parent->d_subdirs, &expired->d_u.d_child);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock(&dcache_lock);
|
|
|
|
return expired;
|
|
|
|
}
|
|
|
|
spin_unlock(&dcache_lock);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform an expiry operation */
|
|
|
|
int autofs4_expire_run(struct super_block *sb,
|
|
|
|
struct vfsmount *mnt,
|
|
|
|
struct autofs_sb_info *sbi,
|
|
|
|
struct autofs_packet_expire __user *pkt_p)
|
|
|
|
{
|
|
|
|
struct autofs_packet_expire pkt;
|
|
|
|
struct dentry *dentry;
|
|
|
|
|
|
|
|
memset(&pkt,0,sizeof pkt);
|
|
|
|
|
|
|
|
pkt.hdr.proto_version = sbi->version;
|
|
|
|
pkt.hdr.type = autofs_ptype_expire;
|
|
|
|
|
2006-03-27 17:14:55 +08:00
|
|
|
if ((dentry = autofs4_expire_indirect(sb, mnt, sbi, 0)) == NULL)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
pkt.len = dentry->d_name.len;
|
|
|
|
memcpy(pkt.name, dentry->d_name.name, pkt.len);
|
|
|
|
pkt.name[pkt.len] = '\0';
|
|
|
|
dput(dentry);
|
|
|
|
|
|
|
|
if ( copy_to_user(pkt_p, &pkt, sizeof(struct autofs_packet_expire)) )
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call repeatedly until it returns -EAGAIN, meaning there's nothing
|
|
|
|
more to be done */
|
|
|
|
int autofs4_expire_multi(struct super_block *sb, struct vfsmount *mnt,
|
|
|
|
struct autofs_sb_info *sbi, int __user *arg)
|
|
|
|
{
|
|
|
|
struct dentry *dentry;
|
|
|
|
int ret = -EAGAIN;
|
|
|
|
int do_now = 0;
|
|
|
|
|
|
|
|
if (arg && get_user(do_now, arg))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2006-03-27 17:14:56 +08:00
|
|
|
if (sbi->type & AUTOFS_TYPE_DIRECT)
|
2006-03-27 17:14:55 +08:00
|
|
|
dentry = autofs4_expire_direct(sb, mnt, sbi, do_now);
|
|
|
|
else
|
|
|
|
dentry = autofs4_expire_indirect(sb, mnt, sbi, do_now);
|
|
|
|
|
|
|
|
if (dentry) {
|
2006-03-27 17:14:44 +08:00
|
|
|
struct autofs_info *ino = autofs4_dentry_ino(dentry);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* This is synchronous because it makes the daemon a
|
|
|
|
little easier */
|
2006-03-27 17:14:44 +08:00
|
|
|
ino->flags |= AUTOFS_INF_EXPIRING;
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = autofs4_wait(sbi, dentry, NFY_EXPIRE);
|
2006-03-27 17:14:44 +08:00
|
|
|
ino->flags &= ~AUTOFS_INF_EXPIRING;
|
2005-04-17 06:20:36 +08:00
|
|
|
dput(dentry);
|
|
|
|
}
|
2006-03-27 17:14:44 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|