Skip to content

Commit f378ec4

Browse files
mjguzikbrauner
authored andcommitted
vfs: rename parent_ino to d_parent_ino and make it use RCU
The routine is used by procfs through dir_emit_dots. The combined RCU and lock fallback implementation is too big for an inline. Given that the routine takes a dentry argument fs/dcache.c seems like the place to put it in. Signed-off-by: Mateusz Guzik <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 0ef625b commit f378ec4

File tree

5 files changed

+34
-18
lines changed

5 files changed

+34
-18
lines changed

fs/dcache.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3099,6 +3099,34 @@ void d_tmpfile(struct file *file, struct inode *inode)
30993099
}
31003100
EXPORT_SYMBOL(d_tmpfile);
31013101

3102+
/*
3103+
* Obtain inode number of the parent dentry.
3104+
*/
3105+
ino_t d_parent_ino(struct dentry *dentry)
3106+
{
3107+
struct dentry *parent;
3108+
struct inode *iparent;
3109+
unsigned seq;
3110+
ino_t ret;
3111+
3112+
scoped_guard(rcu) {
3113+
seq = raw_seqcount_begin(&dentry->d_seq);
3114+
parent = READ_ONCE(dentry->d_parent);
3115+
iparent = d_inode_rcu(parent);
3116+
if (likely(iparent)) {
3117+
ret = iparent->i_ino;
3118+
if (!read_seqcount_retry(&dentry->d_seq, seq))
3119+
return ret;
3120+
}
3121+
}
3122+
3123+
spin_lock(&dentry->d_lock);
3124+
ret = dentry->d_parent->d_inode->i_ino;
3125+
spin_unlock(&dentry->d_lock);
3126+
return ret;
3127+
}
3128+
EXPORT_SYMBOL(d_parent_ino);
3129+
31023130
static __initdata unsigned long dhash_entries;
31033131
static int __init set_dhash_entries(char *str)
31043132
{

fs/f2fs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static int get_parent_ino(struct inode *inode, nid_t *pino)
185185
if (!dentry)
186186
return 0;
187187

188-
*pino = parent_ino(dentry);
188+
*pino = d_parent_ino(dentry);
189189
dput(dentry);
190190
return 1;
191191
}

fs/hfsplus/ioctl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static int hfsplus_ioctl_bless(struct file *file, int __user *user_flags)
4040

4141
/* Directory containing the bootable system */
4242
vh->finder_info[0] = bvh->finder_info[0] =
43-
cpu_to_be32(parent_ino(dentry));
43+
cpu_to_be32(d_parent_ino(dentry));
4444

4545
/*
4646
* Bootloader. Just using the inode here breaks in the case of
@@ -51,7 +51,7 @@ static int hfsplus_ioctl_bless(struct file *file, int __user *user_flags)
5151

5252
/* Per spec, the OS X system folder - same as finder_info[0] here */
5353
vh->finder_info[5] = bvh->finder_info[5] =
54-
cpu_to_be32(parent_ino(dentry));
54+
cpu_to_be32(d_parent_ino(dentry));
5555

5656
mutex_unlock(&sbi->vh_mutex);
5757
return 0;

include/linux/dcache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ static inline unsigned d_count(const struct dentry *dentry)
278278
return dentry->d_lockref.count;
279279
}
280280

281+
ino_t d_parent_ino(struct dentry *dentry);
282+
281283
/*
282284
* helper function for dentry_operations.d_dname() members
283285
*/

include/linux/fs.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3454,20 +3454,6 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags)
34543454
return 0;
34553455
}
34563456

3457-
static inline ino_t parent_ino(struct dentry *dentry)
3458-
{
3459-
ino_t res;
3460-
3461-
/*
3462-
* Don't strictly need d_lock here? If the parent ino could change
3463-
* then surely we'd have a deeper race in the caller?
3464-
*/
3465-
spin_lock(&dentry->d_lock);
3466-
res = dentry->d_parent->d_inode->i_ino;
3467-
spin_unlock(&dentry->d_lock);
3468-
return res;
3469-
}
3470-
34713457
/* Transaction based IO helpers */
34723458

34733459
/*
@@ -3592,7 +3578,7 @@ static inline bool dir_emit_dot(struct file *file, struct dir_context *ctx)
35923578
static inline bool dir_emit_dotdot(struct file *file, struct dir_context *ctx)
35933579
{
35943580
return ctx->actor(ctx, "..", 2, ctx->pos,
3595-
parent_ino(file->f_path.dentry), DT_DIR);
3581+
d_parent_ino(file->f_path.dentry), DT_DIR);
35963582
}
35973583
static inline bool dir_emit_dots(struct file *file, struct dir_context *ctx)
35983584
{

0 commit comments

Comments
 (0)