Skip to content

Commit

Permalink
ovl: abstract ovl_inode lock with a helper
Browse files Browse the repository at this point in the history
The abstraction improves code readabilty (to some).

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  • Loading branch information
Amir Goldstein authored and Miklos Szeredi committed Oct 26, 2018
1 parent 0e32992 commit 1e92e30
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
10 changes: 10 additions & 0 deletions fs/overlayfs/overlayfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,16 @@ static inline unsigned int ovl_xino_bits(struct super_block *sb)
return ofs->xino_bits;
}

static inline int ovl_inode_lock(struct inode *inode)
{
return mutex_lock_interruptible(&OVL_I(inode)->lock);
}

static inline void ovl_inode_unlock(struct inode *inode)
{
mutex_unlock(&OVL_I(inode)->lock);
}


/* namei.c */
int ovl_check_fh_len(struct ovl_fh *fh, int fh_len);
Expand Down
25 changes: 13 additions & 12 deletions fs/overlayfs/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,21 +521,21 @@ bool ovl_already_copied_up(struct dentry *dentry, int flags)

int ovl_copy_up_start(struct dentry *dentry, int flags)
{
struct ovl_inode *oi = OVL_I(d_inode(dentry));
struct inode *inode = d_inode(dentry);
int err;

err = mutex_lock_interruptible(&oi->lock);
err = ovl_inode_lock(inode);
if (!err && ovl_already_copied_up_locked(dentry, flags)) {
err = 1; /* Already copied up */
mutex_unlock(&oi->lock);
ovl_inode_unlock(inode);
}

return err;
}

void ovl_copy_up_end(struct dentry *dentry)
{
mutex_unlock(&OVL_I(d_inode(dentry))->lock);
ovl_inode_unlock(d_inode(dentry));
}

bool ovl_check_origin_xattr(struct dentry *dentry)
Expand Down Expand Up @@ -740,11 +740,11 @@ static void ovl_cleanup_index(struct dentry *dentry)
*/
int ovl_nlink_start(struct dentry *dentry)
{
struct ovl_inode *oi = OVL_I(d_inode(dentry));
struct inode *inode = d_inode(dentry);
const struct cred *old_cred;
int err;

if (WARN_ON(!d_inode(dentry)))
if (WARN_ON(!inode))
return -ENOENT;

/*
Expand All @@ -767,11 +767,11 @@ int ovl_nlink_start(struct dentry *dentry)
return err;
}

err = mutex_lock_interruptible(&oi->lock);
err = ovl_inode_lock(inode);
if (err)
return err;

if (d_is_dir(dentry) || !ovl_test_flag(OVL_INDEX, d_inode(dentry)))
if (d_is_dir(dentry) || !ovl_test_flag(OVL_INDEX, inode))
goto out;

old_cred = ovl_override_creds(dentry->d_sb);
Expand All @@ -786,23 +786,24 @@ int ovl_nlink_start(struct dentry *dentry)

out:
if (err)
mutex_unlock(&oi->lock);
ovl_inode_unlock(inode);

return err;
}

void ovl_nlink_end(struct dentry *dentry)
{
if (ovl_test_flag(OVL_INDEX, d_inode(dentry)) &&
d_inode(dentry)->i_nlink == 0) {
struct inode *inode = d_inode(dentry);

if (ovl_test_flag(OVL_INDEX, inode) && inode->i_nlink == 0) {
const struct cred *old_cred;

old_cred = ovl_override_creds(dentry->d_sb);
ovl_cleanup_index(dentry);
revert_creds(old_cred);
}

mutex_unlock(&OVL_I(d_inode(dentry))->lock);
ovl_inode_unlock(inode);
}

int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir)
Expand Down

0 comments on commit 1e92e30

Please sign in to comment.