Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e176cecd authored by Eric Biggers's avatar Eric Biggers Committed by Jaegeuk Kim
Browse files

vfs: use READ_ONCE() to access ->i_link



Use 'READ_ONCE(inode->i_link)' to explicitly support filesystems caching
the symlink target in ->i_link later if it was unavailable at iget()
time, or wasn't easily available.  I'll be doing this in fscrypt, to
improve the performance of encrypted symlinks on ext4, f2fs, and ubifs.

->i_link will start NULL and may later be set to a non-NULL value by a
smp_store_release() or cmpxchg_release().  READ_ONCE() is needed on the
read side.  smp_load_acquire() is unnecessary because only a data
dependency barrier is required.  (Thanks to Al for pointing this out.)

Acked-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 7bc138e6
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -1027,7 +1027,7 @@ const char *get_link(struct nameidata *nd)
		return ERR_PTR(error);
		return ERR_PTR(error);


	nd->last_type = LAST_BIND;
	nd->last_type = LAST_BIND;
	res = inode->i_link;
	res = READ_ONCE(inode->i_link);
	if (!res) {
	if (!res) {
		const char * (*get)(struct dentry *, struct inode *,
		const char * (*get)(struct dentry *, struct inode *,
				struct delayed_call *);
				struct delayed_call *);
@@ -4651,9 +4651,11 @@ int generic_readlink(struct dentry *dentry, char __user *buffer, int buflen)
{
{
	DEFINE_DELAYED_CALL(done);
	DEFINE_DELAYED_CALL(done);
	struct inode *inode = d_inode(dentry);
	struct inode *inode = d_inode(dentry);
	const char *link = inode->i_link;
	const char *link;
	int res;
	int res;


	link = READ_ONCE(inode->i_link);

	if (!link) {
	if (!link) {
		link = inode->i_op->get_link(dentry, inode, &done);
		link = inode->i_op->get_link(dentry, inode, &done);
		if (IS_ERR(link))
		if (IS_ERR(link))