Commit 5955102c authored by Al Viro's avatar Al Viro

wrappers for ->i_mutex access

parallel to mutex_{lock,unlock,trylock,is_locked,lock_nested},
inode_foo(inode) being mutex_foo(&inode->i_mutex).

Please, use those for access to ->i_mutex; over the coming cycle
->i_mutex will become rwsem, with ->lookup() done with it held
only shared.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 57b8f112
......@@ -1799,9 +1799,9 @@ static int spufs_mfc_fsync(struct file *file, loff_t start, loff_t end, int data
struct inode *inode = file_inode(file);
int err = filemap_write_and_wait_range(inode->i_mapping, start, end);
if (!err) {
mutex_lock(&inode->i_mutex);
inode_lock(inode);
err = spufs_mfc_flush(file, NULL);
mutex_unlock(&inode->i_mutex);
inode_unlock(inode);
}
return err;
}
......
......@@ -163,7 +163,7 @@ static void spufs_prune_dir(struct dentry *dir)
{
struct dentry *dentry, *tmp;
mutex_lock(&d_inode(dir)->i_mutex);
inode_lock(d_inode(dir));
list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_child) {
spin_lock(&dentry->d_lock);
if (simple_positive(dentry)) {
......@@ -180,7 +180,7 @@ static void spufs_prune_dir(struct dentry *dir)
}
}
shrink_dcache_parent(dir);
mutex_unlock(&d_inode(dir)->i_mutex);
inode_unlock(d_inode(dir));
}
/* Caller must hold parent->i_mutex */
......@@ -225,9 +225,9 @@ static int spufs_dir_close(struct inode *inode, struct file *file)
parent = d_inode(dir->d_parent);
ctx = SPUFS_I(d_inode(dir))->i_ctx;
mutex_lock_nested(&parent->i_mutex, I_MUTEX_PARENT);
inode_lock_nested(parent, I_MUTEX_PARENT);
ret = spufs_rmdir(parent, dir);
mutex_unlock(&parent->i_mutex);
inode_unlock(parent);
WARN_ON(ret);
return dcache_dir_close(inode, file);
......@@ -270,7 +270,7 @@ spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags,
inode->i_op = &simple_dir_inode_operations;
inode->i_fop = &simple_dir_operations;
mutex_lock(&inode->i_mutex);
inode_lock(inode);
dget(dentry);
inc_nlink(dir);
......@@ -291,7 +291,7 @@ spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags,
if (ret)
spufs_rmdir(dir, dentry);
mutex_unlock(&inode->i_mutex);
inode_unlock(inode);
return ret;
}
......
......@@ -67,7 +67,7 @@ static void hypfs_remove(struct dentry *dentry)
struct dentry *parent;
parent = dentry->d_parent;
mutex_lock(&d_inode(parent)->i_mutex);
inode_lock(d_inode(parent));
if (simple_positive(dentry)) {
if (d_is_dir(dentry))
simple_rmdir(d_inode(parent), dentry);
......@@ -76,7 +76,7 @@ static void hypfs_remove(struct dentry *dentry)
}
d_delete(dentry);
dput(dentry);
mutex_unlock(&d_inode(parent)->i_mutex);
inode_unlock(d_inode(parent));
}
static void hypfs_delete_tree(struct dentry *root)
......@@ -331,7 +331,7 @@ static struct dentry *hypfs_create_file(struct dentry *parent, const char *name,
struct dentry *dentry;
struct inode *inode;
mutex_lock(&d_inode(parent)->i_mutex);
inode_lock(d_inode(parent));
dentry = lookup_one_len(name, parent, strlen(name));
if (IS_ERR(dentry)) {
dentry = ERR_PTR(-ENOMEM);
......@@ -359,7 +359,7 @@ static struct dentry *hypfs_create_file(struct dentry *parent, const char *name,
d_instantiate(dentry, inode);
dget(dentry);
fail:
mutex_unlock(&d_inode(parent)->i_mutex);
inode_unlock(d_inode(parent));
return dentry;
}
......
......@@ -455,12 +455,12 @@ static int blkdev_daxset(struct block_device *bdev, unsigned long argp)
if (arg && !blkdev_dax_capable(bdev))
return -ENOTTY;
mutex_lock(&bdev->bd_inode->i_mutex);
inode_lock(bdev->bd_inode);
if (bdev->bd_map_count == 0)
inode_set_flags(bdev->bd_inode, arg, S_DAX);
else
rc = -EBUSY;
mutex_unlock(&bdev->bd_inode->i_mutex);
inode_unlock(bdev->bd_inode);
return rc;
}
#else
......
......@@ -215,9 +215,9 @@ static int handle_create(const char *nodename, umode_t mode, kuid_t uid,
newattrs.ia_uid = uid;
newattrs.ia_gid = gid;
newattrs.ia_valid = ATTR_MODE|ATTR_UID|ATTR_GID;
mutex_lock(&d_inode(dentry)->i_mutex);
inode_lock(d_inode(dentry));
notify_change(dentry, &newattrs, NULL);
mutex_unlock(&d_inode(dentry)->i_mutex);
inode_unlock(d_inode(dentry));
/* mark as kernel-created inode */
d_inode(dentry)->i_private = &thread;
......@@ -244,7 +244,7 @@ static int dev_rmdir(const char *name)
err = -ENOENT;
}
dput(dentry);
mutex_unlock(&d_inode(parent.dentry)->i_mutex);
inode_unlock(d_inode(parent.dentry));
path_put(&parent);
return err;
}
......@@ -321,9 +321,9 @@ static int handle_remove(const char *nodename, struct device *dev)
newattrs.ia_mode = stat.mode & ~0777;
newattrs.ia_valid =
ATTR_UID|ATTR_GID|ATTR_MODE;
mutex_lock(&d_inode(dentry)->i_mutex);
inode_lock(d_inode(dentry));
notify_change(dentry, &newattrs, NULL);
mutex_unlock(&d_inode(dentry)->i_mutex);
inode_unlock(d_inode(dentry));
err = vfs_unlink(d_inode(parent.dentry), dentry, NULL);
if (!err || err == -ENOENT)
deleted = 1;
......@@ -332,7 +332,7 @@ static int handle_remove(const char *nodename, struct device *dev)
err = -ENOENT;
}
dput(dentry);
mutex_unlock(&d_inode(parent.dentry)->i_mutex);
inode_unlock(d_inode(parent.dentry));
path_put(&parent);
if (deleted && strchr(nodename, '/'))
......
......@@ -964,9 +964,9 @@ aoecmd_sleepwork(struct work_struct *work)
ssize = get_capacity(d->gd);
bd = bdget_disk(d->gd, 0);
if (bd) {
mutex_lock(&bd->bd_inode->i_mutex);
inode_lock(bd->bd_inode);
i_size_write(bd->bd_inode, (loff_t)ssize<<9);
mutex_unlock(&bd->bd_inode->i_mutex);
inode_unlock(bd->bd_inode);
bdput(bd);
}
spin_lock_irq(&d->lock);
......
......@@ -434,12 +434,12 @@ static int drbd_single_open(struct file *file, int (*show)(struct seq_file *, vo
if (!parent || d_really_is_negative(parent))
goto out;
/* serialize with d_delete() */
mutex_lock(&d_inode(parent)->i_mutex);
inode_lock(d_inode(parent));
/* Make sure the object is still alive */
if (simple_positive(file->f_path.dentry)
&& kref_get_unless_zero(kref))
ret = 0;
mutex_unlock(&d_inode(parent)->i_mutex);
inode_unlock(d_inode(parent));
if (!ret) {
ret = single_open(file, show, data);
if (ret)
......
......@@ -689,7 +689,7 @@ static loff_t memory_lseek(struct file *file, loff_t offset, int orig)
{
loff_t ret;
mutex_lock(&file_inode(file)->i_mutex);
inode_lock(file_inode(file));
switch (orig) {
case SEEK_CUR:
offset += file->f_pos;
......@@ -706,7 +706,7 @@ static loff_t memory_lseek(struct file *file, loff_t offset, int orig)
default:
ret = -EINVAL;
}
mutex_unlock(&file_inode(file)->i_mutex);
inode_unlock(file_inode(file));
return ret;
}
......
......@@ -290,9 +290,9 @@ static int ps3flash_fsync(struct file *file, loff_t start, loff_t end, int datas
{
struct inode *inode = file_inode(file);
int err;
mutex_lock(&inode->i_mutex);
inode_lock(inode);
err = ps3flash_writeback(ps3flash_dev);
mutex_unlock(&inode->i_mutex);
inode_unlock(inode);
return err;
}
......
......@@ -89,14 +89,14 @@ static int create_file(const char *name, umode_t mode,
{
int error;
mutex_lock(&d_inode(parent)->i_mutex);
inode_lock(d_inode(parent));
*dentry = lookup_one_len(name, parent, strlen(name));
if (!IS_ERR(*dentry))
error = qibfs_mknod(d_inode(parent), *dentry,
mode, fops, data);
else
error = PTR_ERR(*dentry);
mutex_unlock(&d_inode(parent)->i_mutex);
inode_unlock(d_inode(parent));
return error;
}
......@@ -481,7 +481,7 @@ static int remove_device_files(struct super_block *sb,
int ret, i;
root = dget(sb->s_root);
mutex_lock(&d_inode(root)->i_mutex);
inode_lock(d_inode(root));
snprintf(unit, sizeof(unit), "%u", dd->unit);
dir = lookup_one_len(unit, root, strlen(unit));
......@@ -491,7 +491,7 @@ static int remove_device_files(struct super_block *sb,
goto bail;
}
mutex_lock(&d_inode(dir)->i_mutex);
inode_lock(d_inode(dir));
remove_file(dir, "counters");
remove_file(dir, "counter_names");
remove_file(dir, "portcounter_names");
......@@ -506,13 +506,13 @@ static int remove_device_files(struct super_block *sb,
}
}
remove_file(dir, "flash");
mutex_unlock(&d_inode(dir)->i_mutex);
inode_unlock(d_inode(dir));
ret = simple_rmdir(d_inode(root), dir);
d_delete(dir);
dput(dir);
bail:
mutex_unlock(&d_inode(root)->i_mutex);
inode_unlock(d_inode(root));
dput(root);
return ret;
}
......
......@@ -174,9 +174,9 @@ static int vol_cdev_fsync(struct file *file, loff_t start, loff_t end,
struct ubi_device *ubi = desc->vol->ubi;
struct inode *inode = file_inode(file);
int err;
mutex_lock(&inode->i_mutex);
inode_lock(inode);
err = ubi_sync(ubi->ubi_num);
mutex_unlock(&inode->i_mutex);
inode_unlock(inode);
return err;
}
......
......@@ -138,22 +138,22 @@ static int __oprofilefs_create_file(struct dentry *root, char const *name,
struct dentry *dentry;
struct inode *inode;
mutex_lock(&d_inode(root)->i_mutex);
inode_lock(d_inode(root));
dentry = d_alloc_name(root, name);
if (!dentry) {
mutex_unlock(&d_inode(root)->i_mutex);
inode_unlock(d_inode(root));
return -ENOMEM;
}
inode = oprofilefs_get_inode(root->d_sb, S_IFREG | perm);
if (!inode) {
dput(dentry);
mutex_unlock(&d_inode(root)->i_mutex);
inode_unlock(d_inode(root));
return -ENOMEM;
}
inode->i_fop = fops;
inode->i_private = priv;
d_add(dentry, inode);
mutex_unlock(&d_inode(root)->i_mutex);
inode_unlock(d_inode(root));
return 0;
}
......@@ -215,22 +215,22 @@ struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name)
struct dentry *dentry;
struct inode *inode;
mutex_lock(&d_inode(parent)->i_mutex);
inode_lock(d_inode(parent));
dentry = d_alloc_name(parent, name);
if (!dentry) {
mutex_unlock(&d_inode(parent)->i_mutex);
inode_unlock(d_inode(parent));
return NULL;
}
inode = oprofilefs_get_inode(parent->d_sb, S_IFDIR | 0755);
if (!inode) {
dput(dentry);
mutex_unlock(&d_inode(parent)->i_mutex);
inode_unlock(d_inode(parent));
return NULL;
}
inode->i_op = &simple_dir_inode_operations;
inode->i_fop = &simple_dir_operations;
d_add(dentry, inode);
mutex_unlock(&d_inode(parent)->i_mutex);
inode_unlock(d_inode(parent));
return dentry;
}
......
......@@ -1858,7 +1858,7 @@ static loff_t ll_dir_seek(struct file *file, loff_t offset, int origin)
int api32 = ll_need_32bit_api(sbi);
loff_t ret = -EINVAL;
mutex_lock(&inode->i_mutex);
inode_lock(inode);
switch (origin) {
case SEEK_SET:
break;
......@@ -1896,7 +1896,7 @@ static loff_t ll_dir_seek(struct file *file, loff_t offset, int origin)
goto out;
out:
mutex_unlock(&inode->i_mutex);
inode_unlock(inode);
return ret;
}
......
......@@ -2082,17 +2082,17 @@ static int ll_swap_layouts(struct file *file1, struct file *file2,
/* update time if requested */
rc = 0;
if (llss->ia2.ia_valid != 0) {
mutex_lock(&llss->inode1->i_mutex);
inode_lock(llss->inode1);
rc = ll_setattr(file1->f_path.dentry, &llss->ia2);
mutex_unlock(&llss->inode1->i_mutex);
inode_unlock(llss->inode1);
}
if (llss->ia1.ia_valid != 0) {
int rc1;
mutex_lock(&llss->inode2->i_mutex);
inode_lock(llss->inode2);
rc1 = ll_setattr(file2->f_path.dentry, &llss->ia1);
mutex_unlock(&llss->inode2->i_mutex);
inode_unlock(llss->inode2);
if (rc == 0)
rc = rc1;
}
......@@ -2179,13 +2179,13 @@ static int ll_hsm_import(struct inode *inode, struct file *file,
ATTR_MTIME | ATTR_MTIME_SET |
ATTR_ATIME | ATTR_ATIME_SET;
mutex_lock(&inode->i_mutex);
inode_lock(inode);
rc = ll_setattr_raw(file->f_path.dentry, attr, true);
if (rc == -ENODATA)
rc = 0;
mutex_unlock(&inode->i_mutex);
inode_unlock(inode);
kfree(attr);
free_hss:
......@@ -2609,7 +2609,7 @@ int ll_fsync(struct file *file, loff_t start, loff_t end, int datasync)
ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_FSYNC, 1);
rc = filemap_write_and_wait_range(inode->i_mapping, start, end);
mutex_lock(&inode->i_mutex);
inode_lock(inode);
/* catch async errors that were recorded back when async writeback
* failed for pages in this mapping. */
......@@ -2641,7 +2641,7 @@ int ll_fsync(struct file *file, loff_t start, loff_t end, int datasync)
fd->fd_write_failed = false;
}
mutex_unlock(&inode->i_mutex);
inode_unlock(inode);
return rc;
}
......
......@@ -1277,7 +1277,7 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
return -ENOMEM;
if (!S_ISDIR(inode->i_mode))
mutex_unlock(&inode->i_mutex);
inode_unlock(inode);
memcpy(&op_data->op_attr, attr, sizeof(*attr));
......@@ -1358,7 +1358,7 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
ll_finish_md_op_data(op_data);
if (!S_ISDIR(inode->i_mode)) {
mutex_lock(&inode->i_mutex);
inode_lock(inode);
if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
inode_dio_wait(inode);
}
......
......@@ -245,9 +245,9 @@ static int ll_get_name(struct dentry *dentry, char *name,
goto out;
}
mutex_lock(&dir->i_mutex);
inode_lock(dir);
rc = ll_dir_read(dir, &lgd.ctx);
mutex_unlock(&dir->i_mutex);
inode_unlock(dir);
if (!rc && !lgd.lgd_found)
rc = -ENOENT;
out:
......
......@@ -257,9 +257,9 @@ static int do_bio_lustrebacked(struct lloop_device *lo, struct bio *head)
* be asked to write less pages once, this purely depends on
* implementation. Anyway, we should be careful to avoid deadlocking.
*/
mutex_lock(&inode->i_mutex);
inode_lock(inode);
bytes = ll_direct_rw_pages(env, io, rw, inode, pvec);
mutex_unlock(&inode->i_mutex);
inode_unlock(inode);
cl_io_fini(env, io);
return (bytes == pvec->ldp_size) ? 0 : (int)bytes;
}
......
......@@ -115,8 +115,8 @@ static struct ll_cl_context *ll_cl_init(struct file *file,
struct inode *inode = vmpage->mapping->host;
loff_t pos;
if (mutex_trylock(&inode->i_mutex)) {
mutex_unlock(&(inode)->i_mutex);
if (inode_trylock(inode)) {
inode_unlock((inode));
/* this is too bad. Someone is trying to write the
* page w/o holding inode mutex. This means we can
......
......@@ -403,7 +403,7 @@ static ssize_t ll_direct_IO_26(struct kiocb *iocb, struct iov_iter *iter,
* 1. Need inode mutex to operate transient pages.
*/
if (iov_iter_rw(iter) == READ)
mutex_lock(&inode->i_mutex);
inode_lock(inode);
LASSERT(obj->cob_transient_pages == 0);
while (iov_iter_count(iter)) {
......@@ -454,7 +454,7 @@ static ssize_t ll_direct_IO_26(struct kiocb *iocb, struct iov_iter *iter,
out:
LASSERT(obj->cob_transient_pages == 0);
if (iov_iter_rw(iter) == READ)
mutex_unlock(&inode->i_mutex);
inode_unlock(inode);
if (tot_bytes > 0) {
if (iov_iter_rw(iter) == WRITE) {
......
......@@ -439,7 +439,7 @@ static int vvp_io_setattr_start(const struct lu_env *env,
struct inode *inode = ccc_object_inode(io->ci_obj);
int result = 0;
mutex_lock(&inode->i_mutex);
inode_lock(inode);
if (cl_io_is_trunc(io))
result = vvp_io_setattr_trunc(env, ios, inode,
io->u.ci_setattr.sa_attr.lvb_size);
......@@ -459,7 +459,7 @@ static void vvp_io_setattr_end(const struct lu_env *env,
* because osc has already notified to destroy osc_extents. */
vvp_do_vmtruncate(inode, io->u.ci_setattr.sa_attr.lvb_size);
mutex_unlock(&inode->i_mutex);
inode_unlock(inode);
}
static void vvp_io_setattr_fini(const struct lu_env *env,
......
......@@ -428,7 +428,7 @@ static void vvp_transient_page_verify(const struct cl_page *page)
{
struct inode *inode = ccc_object_inode(page->cp_obj);
LASSERT(!mutex_trylock(&inode->i_mutex));
LASSERT(!inode_trylock(inode));
}
static int vvp_transient_page_own(const struct lu_env *env,
......@@ -480,9 +480,9 @@ static int vvp_transient_page_is_vmlocked(const struct lu_env *env,
struct inode *inode = ccc_object_inode(slice->cpl_obj);
int locked;
locked = !mutex_trylock(&inode->i_mutex);
locked = !inode_trylock(inode);
if (!locked)
mutex_unlock(&inode->i_mutex);
inode_unlock(inode);
return locked ? -EBUSY : -ENODATA;
}
......@@ -502,7 +502,7 @@ static void vvp_transient_page_fini(const struct lu_env *env,
struct ccc_object *clobj = cl2ccc(clp->cp_obj);
vvp_page_fini_common(cp);
LASSERT(!mutex_trylock(&clobj->cob_inode->i_mutex));
LASSERT(!inode_trylock(clobj->cob_inode));
clobj->cob_transient_pages--;
}
......@@ -548,7 +548,7 @@ int vvp_page_init(const struct lu_env *env, struct cl_object *obj,
} else {
struct ccc_object *clobj = cl2ccc(obj);
LASSERT(!mutex_trylock(&clobj->cob_inode->i_mutex));
LASSERT(!inode_trylock(clobj->cob_inode));
cl_page_slice_add(page, &cpg->cpg_cl, obj,
&vvp_transient_page_ops);
clobj->cob_transient_pages++;
......
......@@ -82,14 +82,14 @@ static int create_file(const char *name, umode_t mode,
{
int error;
mutex_lock(&d_inode(parent)->i_mutex);
inode_lock(d_inode(parent));
*dentry = lookup_one_len(name, parent, strlen(name));
if (!IS_ERR(*dentry))
error = ipathfs_mknod(d_inode(parent), *dentry,
mode, fops, data);
else
error = PTR_ERR(*dentry);
mutex_unlock(&d_inode(parent)->i_mutex);
inode_unlock(d_inode(parent));
return error;
}
......@@ -295,7 +295,7 @@ static int remove_device_files(struct super_block *sb,
int ret;
root = dget(sb->s_root);
mutex_lock(&d_inode(root)->i_mutex);
inode_lock(d_inode(root));
snprintf(unit, sizeof unit, "%02d", dd->ipath_unit);
dir = lookup_one_len(unit, root, strlen(unit));
......@@ -311,7 +311,7 @@ static int remove_device_files(struct super_block *sb,
ret = simple_rmdir(d_inode(root), dir);
bail:
mutex_unlock(&d_inode(root)->i_mutex);
inode_unlock(d_inode(root));
dput(root);
return ret;
}
......
......@@ -673,7 +673,7 @@ printer_fsync(struct file *fd, loff_t start, loff_t end, int datasync)
unsigned long flags;
int tx_list_empty;
mutex_lock(&inode->i_mutex);
inode_lock(inode);
spin_lock_irqsave(&dev->lock, flags);
tx_list_empty = (likely(list_empty(&dev->tx_reqs)));
spin_unlock_irqrestore(&dev->lock, flags);
......@@ -683,7 +683,7 @@ printer_fsync(struct file *fd, loff_t start, loff_t end, int datasync)
wait_event_interruptible(dev->tx_flush_wait,
(likely(list_empty(&dev->tx_reqs_active))));
}
mutex_unlock(&inode->i_mutex);
inode_unlock(inode);
return 0;
}
......
......@@ -1521,10 +1521,10 @@ static void destroy_ep_files (struct dev_data *dev)
spin_unlock_irq (&dev->lock);
/* break link to dcache */
mutex_lock (&parent->i_mutex);
inode_lock(parent);
d_delete (dentry);
dput (dentry);
mutex_unlock (&parent->i_mutex);
inode_unlock(parent);
spin_lock_irq (&dev->lock);
}
......
......@@ -91,7 +91,7 @@ static ssize_t queue_dbg_read(struct file *file, char __user *buf,
if (!access_ok(VERIFY_WRITE, buf, nbytes))
return -EFAULT;
mutex_lock(&file_inode(file)->i_mutex);
inode_lock(file_inode(file));
list_for_each_entry_safe(req, tmp_req, queue, queue) {
len = snprintf(tmpbuf, sizeof(tmpbuf),
"%8p %08x %c%c%c %5d %c%c%c\n",
......@@ -118,7 +118,7 @@ static ssize_t queue_dbg_read(struct file *file, char __user *buf,
nbytes -= len;
buf += len;
}
mutex_unlock(&file_inode(file)->i_mutex);
inode_unlock(file_inode(file));
return actual;
}
......@@ -143,7 +143,7 @@ static int regs_dbg_open(struct inode *inode, struct file *file)
u32 *data;
int ret = -ENOMEM;
mutex_lock(&inode->i_mutex);
inode_lock(inode);
udc = inode->i_private;
data = kmalloc(inode->i_size, GFP_KERNEL);
if (!data)
......@@ -158,7 +158,7 @@ static int regs_dbg_open(struct inode *inode, struct file *file)
ret = 0;