ovl: remove the 'locked' argument of ovl_nlink_{start,end}

It just makes the interface strange without adding any significant value.
The only case where locked is false and return value is 0 is in
ovl_rename() when new is negative, so handle that case explicitly in
ovl_rename().

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
This commit is contained in:
Amir Goldstein 2018-10-18 18:37:13 +03:00 коммит произвёл Miklos Szeredi
Родитель 9df085f3c9
Коммит 0e32992f7f
3 изменённых файлов: 25 добавлений и 28 удалений

Просмотреть файл

@ -652,7 +652,6 @@ static int ovl_link(struct dentry *old, struct inode *newdir,
struct dentry *new) struct dentry *new)
{ {
int err; int err;
bool locked = false;
struct inode *inode; struct inode *inode;
err = ovl_want_write(old); err = ovl_want_write(old);
@ -673,7 +672,7 @@ static int ovl_link(struct dentry *old, struct inode *newdir,
goto out_drop_write; goto out_drop_write;
} }
err = ovl_nlink_start(old, &locked); err = ovl_nlink_start(old);
if (err) if (err)
goto out_drop_write; goto out_drop_write;
@ -686,7 +685,7 @@ static int ovl_link(struct dentry *old, struct inode *newdir,
if (err) if (err)
iput(inode); iput(inode);
ovl_nlink_end(old, locked); ovl_nlink_end(old);
out_drop_write: out_drop_write:
ovl_drop_write(old); ovl_drop_write(old);
out: out:
@ -811,7 +810,6 @@ static bool ovl_pure_upper(struct dentry *dentry)
static int ovl_do_remove(struct dentry *dentry, bool is_dir) static int ovl_do_remove(struct dentry *dentry, bool is_dir)
{ {
int err; int err;
bool locked = false;
const struct cred *old_cred; const struct cred *old_cred;
struct dentry *upperdentry; struct dentry *upperdentry;
bool lower_positive = ovl_lower_positive(dentry); bool lower_positive = ovl_lower_positive(dentry);
@ -832,7 +830,7 @@ static int ovl_do_remove(struct dentry *dentry, bool is_dir)
if (err) if (err)
goto out_drop_write; goto out_drop_write;
err = ovl_nlink_start(dentry, &locked); err = ovl_nlink_start(dentry);
if (err) if (err)
goto out_drop_write; goto out_drop_write;
@ -848,7 +846,7 @@ static int ovl_do_remove(struct dentry *dentry, bool is_dir)
else else
drop_nlink(dentry->d_inode); drop_nlink(dentry->d_inode);
} }
ovl_nlink_end(dentry, locked); ovl_nlink_end(dentry);
/* /*
* Copy ctime * Copy ctime
@ -1012,7 +1010,6 @@ static int ovl_rename(struct inode *olddir, struct dentry *old,
unsigned int flags) unsigned int flags)
{ {
int err; int err;
bool locked = false;
struct dentry *old_upperdir; struct dentry *old_upperdir;
struct dentry *new_upperdir; struct dentry *new_upperdir;
struct dentry *olddentry; struct dentry *olddentry;
@ -1021,6 +1018,7 @@ static int ovl_rename(struct inode *olddir, struct dentry *old,
bool old_opaque; bool old_opaque;
bool new_opaque; bool new_opaque;
bool cleanup_whiteout = false; bool cleanup_whiteout = false;
bool update_nlink = false;
bool overwrite = !(flags & RENAME_EXCHANGE); bool overwrite = !(flags & RENAME_EXCHANGE);
bool is_dir = d_is_dir(old); bool is_dir = d_is_dir(old);
bool new_is_dir = d_is_dir(new); bool new_is_dir = d_is_dir(new);
@ -1078,10 +1076,12 @@ static int ovl_rename(struct inode *olddir, struct dentry *old,
err = ovl_copy_up(new); err = ovl_copy_up(new);
if (err) if (err)
goto out_drop_write; goto out_drop_write;
} else { } else if (d_inode(new)) {
err = ovl_nlink_start(new, &locked); err = ovl_nlink_start(new);
if (err) if (err)
goto out_drop_write; goto out_drop_write;
update_nlink = true;
} }
old_cred = ovl_override_creds(old->d_sb); old_cred = ovl_override_creds(old->d_sb);
@ -1210,7 +1210,8 @@ out_unlock:
unlock_rename(new_upperdir, old_upperdir); unlock_rename(new_upperdir, old_upperdir);
out_revert_creds: out_revert_creds:
revert_creds(old_cred); revert_creds(old_cred);
ovl_nlink_end(new, locked); if (update_nlink)
ovl_nlink_end(new);
out_drop_write: out_drop_write:
ovl_drop_write(old); ovl_drop_write(old);
out: out:

Просмотреть файл

@ -271,8 +271,8 @@ bool ovl_test_flag(unsigned long flag, struct inode *inode);
bool ovl_inuse_trylock(struct dentry *dentry); bool ovl_inuse_trylock(struct dentry *dentry);
void ovl_inuse_unlock(struct dentry *dentry); void ovl_inuse_unlock(struct dentry *dentry);
bool ovl_need_index(struct dentry *dentry); bool ovl_need_index(struct dentry *dentry);
int ovl_nlink_start(struct dentry *dentry, bool *locked); int ovl_nlink_start(struct dentry *dentry);
void ovl_nlink_end(struct dentry *dentry, bool locked); void ovl_nlink_end(struct dentry *dentry);
int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir); int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir);
int ovl_check_metacopy_xattr(struct dentry *dentry); int ovl_check_metacopy_xattr(struct dentry *dentry);
bool ovl_is_metacopy_dentry(struct dentry *dentry); bool ovl_is_metacopy_dentry(struct dentry *dentry);

Просмотреть файл

@ -738,14 +738,14 @@ fail:
* Operations that change overlay inode and upper inode nlink need to be * Operations that change overlay inode and upper inode nlink need to be
* synchronized with copy up for persistent nlink accounting. * synchronized with copy up for persistent nlink accounting.
*/ */
int ovl_nlink_start(struct dentry *dentry, bool *locked) int ovl_nlink_start(struct dentry *dentry)
{ {
struct ovl_inode *oi = OVL_I(d_inode(dentry)); struct ovl_inode *oi = OVL_I(d_inode(dentry));
const struct cred *old_cred; const struct cred *old_cred;
int err; int err;
if (!d_inode(dentry)) if (WARN_ON(!d_inode(dentry)))
return 0; return -ENOENT;
/* /*
* With inodes index is enabled, we store the union overlay nlink * With inodes index is enabled, we store the union overlay nlink
@ -787,15 +787,12 @@ int ovl_nlink_start(struct dentry *dentry, bool *locked)
out: out:
if (err) if (err)
mutex_unlock(&oi->lock); mutex_unlock(&oi->lock);
else
*locked = true;
return err; return err;
} }
void ovl_nlink_end(struct dentry *dentry, bool locked) void ovl_nlink_end(struct dentry *dentry)
{ {
if (locked) {
if (ovl_test_flag(OVL_INDEX, d_inode(dentry)) && if (ovl_test_flag(OVL_INDEX, d_inode(dentry)) &&
d_inode(dentry)->i_nlink == 0) { d_inode(dentry)->i_nlink == 0) {
const struct cred *old_cred; const struct cred *old_cred;
@ -806,7 +803,6 @@ void ovl_nlink_end(struct dentry *dentry, bool locked)
} }
mutex_unlock(&OVL_I(d_inode(dentry))->lock); mutex_unlock(&OVL_I(d_inode(dentry))->lock);
}
} }
int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir) int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir)