X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=fs%2Fexportfs%2Fexpfs.c;h=93e77c3d24906af5156254b29ee1cd3e39ba1ac3;hb=refs%2Fheads%2Fvserver;hp=edde9a5d5414f5a06245432e5f6012d4c394810e;hpb=9213980e6a70d8473e0ffd4b39ab5b6caaba9ff5;p=linux-2.6.git diff --git a/fs/exportfs/expfs.c b/fs/exportfs/expfs.c index edde9a5d5..93e77c3d2 100644 --- a/fs/exportfs/expfs.c +++ b/fs/exportfs/expfs.c @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -10,6 +11,33 @@ struct export_operations export_op_default; #define dprintk(fmt, args...) do{}while(0) +static struct dentry * +find_acceptable_alias(struct dentry *result, + int (*acceptable)(void *context, struct dentry *dentry), + void *context) +{ + struct dentry *dentry, *toput = NULL; + + spin_lock(&dcache_lock); + list_for_each_entry(dentry, &result->d_inode->i_dentry, d_alias) { + dget_locked(dentry); + spin_unlock(&dcache_lock); + if (toput) + dput(toput); + if (dentry != result && acceptable(context, dentry)) { + dput(result); + return dentry; + } + spin_lock(&dcache_lock); + toput = dentry; + } + spin_unlock(&dcache_lock); + + if (toput) + dput(toput); + return NULL; +} + /** * find_exported_dentry - helper routine to implement export_operations->decode_fh * @sb: The &super_block identifying the filesystem @@ -51,10 +79,9 @@ find_exported_dentry(struct super_block *sb, void *obj, void *parent, struct dentry *target_dir; int err; struct export_operations *nops = sb->s_export_op; - struct list_head *le, *head; - struct dentry *toput = NULL; + struct dentry *alias; int noprogress; - + char nbuf[NAME_MAX+1]; /* * Attempt to find the inode. @@ -75,30 +102,13 @@ find_exported_dentry(struct super_block *sb, void *obj, void *parent, if (acceptable(context, result)) return result; if (S_ISDIR(result->d_inode->i_mode)) { - /* there is no other dentry, so fail */ + err = -EACCES; goto err_result; } - /* try any other aliases */ - spin_lock(&dcache_lock); - head = &result->d_inode->i_dentry; - list_for_each(le, head) { - struct dentry *dentry = list_entry(le, struct dentry, d_alias); - dget_locked(dentry); - spin_unlock(&dcache_lock); - if (toput) - dput(toput); - toput = NULL; - if (dentry != result && - acceptable(context, dentry)) { - dput(result); - return dentry; - } - spin_lock(&dcache_lock); - toput = dentry; - } - spin_unlock(&dcache_lock); - if (toput) - dput(toput); + + alias = find_acceptable_alias(result, acceptable, context); + if (alias) + return alias; } /* It's a directory, or we are required to confirm the file's @@ -175,11 +185,10 @@ find_exported_dentry(struct super_block *sb, void *obj, void *parent, */ struct dentry *ppd; struct dentry *npd; - char nbuf[NAME_MAX+1]; - down(&pd->d_inode->i_sem); + mutex_lock(&pd->d_inode->i_mutex); ppd = CALL(nops,get_parent)(pd); - up(&pd->d_inode->i_sem); + mutex_unlock(&pd->d_inode->i_mutex); if (IS_ERR(ppd)) { err = PTR_ERR(ppd); @@ -201,9 +210,9 @@ find_exported_dentry(struct super_block *sb, void *obj, void *parent, break; } dprintk("find_exported_dentry: found name: %s\n", nbuf); - down(&ppd->d_inode->i_sem); + mutex_lock(&ppd->d_inode->i_mutex); npd = lookup_one_len(nbuf, ppd, strlen(nbuf)); - up(&ppd->d_inode->i_sem); + mutex_unlock(&ppd->d_inode->i_mutex); if (IS_ERR(npd)) { err = PTR_ERR(npd); dprintk("find_exported_dentry: lookup failed: %d\n", err); @@ -240,12 +249,11 @@ find_exported_dentry(struct super_block *sb, void *obj, void *parent, /* if we weren't after a directory, have one more step to go */ if (result != target_dir) { struct dentry *nresult; - char nbuf[NAME_MAX+1]; err = CALL(nops,get_name)(target_dir, nbuf, result); if (!err) { - down(&target_dir->d_inode->i_sem); + mutex_lock(&target_dir->d_inode->i_mutex); nresult = lookup_one_len(nbuf, target_dir, strlen(nbuf)); - up(&target_dir->d_inode->i_sem); + mutex_unlock(&target_dir->d_inode->i_mutex); if (!IS_ERR(nresult)) { if (nresult->d_inode) { dput(result); @@ -259,30 +267,19 @@ find_exported_dentry(struct super_block *sb, void *obj, void *parent, /* now result is properly connected, it is our best bet */ if (acceptable(context, result)) return result; - /* one last try of the aliases.. */ - spin_lock(&dcache_lock); - toput = NULL; - head = &result->d_inode->i_dentry; - list_for_each(le, head) { - struct dentry *dentry = list_entry(le, struct dentry, d_alias); - dget_locked(dentry); - spin_unlock(&dcache_lock); - if (toput) dput(toput); - if (dentry != result && - acceptable(context, dentry)) { - dput(result); - return dentry; - } - spin_lock(&dcache_lock); - toput = dentry; - } - spin_unlock(&dcache_lock); - if (toput) - dput(toput); + + alias = find_acceptable_alias(result, acceptable, context); + if (alias) + return alias; /* drat - I just cannot find anything acceptable */ dput(result); - return ERR_PTR(-ESTALE); + /* It might be justifiable to return ESTALE here, + * but the filehandle at-least looks reasonable good + * and it just be a permission problem, so returning + * -EACCESS is safer + */ + return ERR_PTR(-EACCES); err_target: dput(target_dir); @@ -318,7 +315,7 @@ struct getdents_callback { * the name matching the specified inode number. */ static int filldir_one(void * __buf, const char * name, int len, - loff_t pos, ino_t ino, unsigned int d_type) + loff_t pos, u64 ino, unsigned int d_type) { struct getdents_callback *buf = __buf; int result = 0; @@ -347,7 +344,7 @@ static int get_name(struct dentry *dentry, char *name, { struct inode *dir = dentry->d_inode; int error; - struct file file; + struct file *file; struct getdents_callback buffer; error = -ENOTDIR; @@ -359,11 +356,13 @@ static int get_name(struct dentry *dentry, char *name, /* * Open the directory ... */ - error = open_private_file(&file, dentry, O_RDONLY); - if (error) + file = dentry_open(dget(dentry), NULL, O_RDONLY); + error = PTR_ERR(file); + if (IS_ERR(file)) goto out; + error = -EINVAL; - if (!file.f_op->readdir) + if (!file->f_op->readdir) goto out_close; buffer.name = name; @@ -373,7 +372,7 @@ static int get_name(struct dentry *dentry, char *name, while (1) { int old_seq = buffer.sequence; - error = vfs_readdir(&file, filldir_one, &buffer); + error = vfs_readdir(file, filldir_one, &buffer); if (error < 0) break; @@ -387,7 +386,7 @@ static int get_name(struct dentry *dentry, char *name, } out_close: - close_private_file(&file); + fput(file); out: return error; }