Skip to content

Commit 76fa666

Browse files
jtlaytonTrond Myklebust
authored andcommitted
rpc_pipe: set dentry operations at d_alloc time
Currently the way these get set is a little convoluted. If the dentry is allocated via lookup from userland, then it gets set by simple_lookup. If it gets allocated when the kernel is populating the directory, then it gets set via __rpc_lookup_create_exclusive, which has to check whether they might already be set. Between both of these, this ensures that all dentries have their d_op pointer set. Instead of doing that, just have them set at d_alloc time by pointing sb->s_d_op at them. With that change, we no longer want the lookup op to set them, so we must move to using our own lookup routine. Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent cda57a1 commit 76fa666

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

‎net/sunrpc/rpc_pipe.c‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,23 @@ static const struct dentry_operations rpc_dentry_operations = {
480480
.d_delete = rpc_delete_dentry,
481481
};
482482

483+
/*
484+
* Lookup the data. This is trivial - if the dentry didn't already
485+
* exist, we know it is negative.
486+
*/
487+
static struct dentry *
488+
rpc_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
489+
{
490+
if (dentry->d_name.len > NAME_MAX)
491+
return ERR_PTR(-ENAMETOOLONG);
492+
d_add(dentry, NULL);
493+
return NULL;
494+
}
495+
496+
const struct inode_operations rpc_dir_inode_operations = {
497+
.lookup = rpc_lookup,
498+
};
499+
483500
static struct inode *
484501
rpc_get_inode(struct super_block *sb, umode_t mode)
485502
{
@@ -492,7 +509,7 @@ rpc_get_inode(struct super_block *sb, umode_t mode)
492509
switch (mode & S_IFMT) {
493510
case S_IFDIR:
494511
inode->i_fop = &simple_dir_operations;
495-
inode->i_op = &simple_dir_inode_operations;
512+
inode->i_op = &rpc_dir_inode_operations;
496513
inc_nlink(inode);
497514
default:
498515
break;
@@ -666,11 +683,8 @@ static struct dentry *__rpc_lookup_create_exclusive(struct dentry *parent,
666683
if (!dentry)
667684
return ERR_PTR(-ENOMEM);
668685
}
669-
if (dentry->d_inode == NULL) {
670-
if (!dentry->d_op)
671-
d_set_d_op(dentry, &rpc_dentry_operations);
686+
if (dentry->d_inode == NULL)
672687
return dentry;
673-
}
674688
dput(dentry);
675689
return ERR_PTR(-EEXIST);
676690
}
@@ -1117,6 +1131,7 @@ rpc_fill_super(struct super_block *sb, void *data, int silent)
11171131
sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
11181132
sb->s_magic = RPCAUTH_GSSMAGIC;
11191133
sb->s_op = &s_ops;
1134+
sb->s_d_op = &rpc_dentry_operations;
11201135
sb->s_time_gran = 1;
11211136

11221137
inode = rpc_get_inode(sb, S_IFDIR | S_IRUGO | S_IXUGO);

0 commit comments

Comments
 (0)