Commit 1b1dcc1b authored by Jes Sorensen's avatar Jes Sorensen Committed by Ingo Molnar

[PATCH] mutex subsystem, semaphore to mutex: VFS, ->i_sem

This patch converts the inode semaphore to a mutex. I have tested it on
XFS and compiled as much as one can consider on an ia64. Anyway your
luck with it might be different.
Modified-by: default avatarIngo Molnar <mingo@elte.hu>

(finished the conversion)
Signed-off-by: default avatarJes Sorensen <jes@sgi.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 794ee1ba
...@@ -137,7 +137,7 @@ spufs_delete_inode(struct inode *inode) ...@@ -137,7 +137,7 @@ spufs_delete_inode(struct inode *inode)
static void spufs_prune_dir(struct dentry *dir) static void spufs_prune_dir(struct dentry *dir)
{ {
struct dentry *dentry, *tmp; struct dentry *dentry, *tmp;
down(&dir->d_inode->i_sem); mutex_lock(&dir->d_inode->i_mutex);
list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_child) { list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_child) {
spin_lock(&dcache_lock); spin_lock(&dcache_lock);
spin_lock(&dentry->d_lock); spin_lock(&dentry->d_lock);
...@@ -154,7 +154,7 @@ static void spufs_prune_dir(struct dentry *dir) ...@@ -154,7 +154,7 @@ static void spufs_prune_dir(struct dentry *dir)
} }
} }
shrink_dcache_parent(dir); shrink_dcache_parent(dir);
up(&dir->d_inode->i_sem); mutex_unlock(&dir->d_inode->i_mutex);
} }
static int spufs_rmdir(struct inode *root, struct dentry *dir_dentry) static int spufs_rmdir(struct inode *root, struct dentry *dir_dentry)
...@@ -162,15 +162,15 @@ static int spufs_rmdir(struct inode *root, struct dentry *dir_dentry) ...@@ -162,15 +162,15 @@ static int spufs_rmdir(struct inode *root, struct dentry *dir_dentry)
struct spu_context *ctx; struct spu_context *ctx;
/* remove all entries */ /* remove all entries */
down(&root->i_sem); mutex_lock(&root->i_mutex);
spufs_prune_dir(dir_dentry); spufs_prune_dir(dir_dentry);
up(&root->i_sem); mutex_unlock(&root->i_mutex);
/* We have to give up the mm_struct */ /* We have to give up the mm_struct */
ctx = SPUFS_I(dir_dentry->d_inode)->i_ctx; ctx = SPUFS_I(dir_dentry->d_inode)->i_ctx;
spu_forget(ctx); spu_forget(ctx);
/* XXX Do we need to hold i_sem here ? */ /* XXX Do we need to hold i_mutex here ? */
return simple_rmdir(root, dir_dentry); return simple_rmdir(root, dir_dentry);
} }
...@@ -330,7 +330,7 @@ long spufs_create_thread(struct nameidata *nd, ...@@ -330,7 +330,7 @@ long spufs_create_thread(struct nameidata *nd,
out_dput: out_dput:
dput(dentry); dput(dentry);
out_dir: out_dir:
up(&nd->dentry->d_inode->i_sem); mutex_unlock(&nd->dentry->d_inode->i_mutex);
out: out:
return ret; return ret;
} }
......
...@@ -215,7 +215,7 @@ static int do_lo_send_aops(struct loop_device *lo, struct bio_vec *bvec, ...@@ -215,7 +215,7 @@ static int do_lo_send_aops(struct loop_device *lo, struct bio_vec *bvec,
unsigned offset, bv_offs; unsigned offset, bv_offs;
int len, ret; int len, ret;
down(&mapping->host->i_sem); mutex_lock(&mapping->host->i_mutex);
index = pos >> PAGE_CACHE_SHIFT; index = pos >> PAGE_CACHE_SHIFT;
offset = pos & ((pgoff_t)PAGE_CACHE_SIZE - 1); offset = pos & ((pgoff_t)PAGE_CACHE_SIZE - 1);
bv_offs = bvec->bv_offset; bv_offs = bvec->bv_offset;
...@@ -278,7 +278,7 @@ static int do_lo_send_aops(struct loop_device *lo, struct bio_vec *bvec, ...@@ -278,7 +278,7 @@ static int do_lo_send_aops(struct loop_device *lo, struct bio_vec *bvec,
} }
ret = 0; ret = 0;
out: out:
up(&mapping->host->i_sem); mutex_unlock(&mapping->host->i_mutex);
return ret; return ret;
unlock: unlock:
unlock_page(page); unlock_page(page);
......
...@@ -741,7 +741,7 @@ static loff_t memory_lseek(struct file * file, loff_t offset, int orig) ...@@ -741,7 +741,7 @@ static loff_t memory_lseek(struct file * file, loff_t offset, int orig)
{ {
loff_t ret; loff_t ret;
down(&file->f_dentry->d_inode->i_sem); mutex_lock(&file->f_dentry->d_inode->i_mutex);
switch (orig) { switch (orig) {
case 0: case 0:
file->f_pos = offset; file->f_pos = offset;
...@@ -756,7 +756,7 @@ static loff_t memory_lseek(struct file * file, loff_t offset, int orig) ...@@ -756,7 +756,7 @@ static loff_t memory_lseek(struct file * file, loff_t offset, int orig)
default: default:
ret = -EINVAL; ret = -EINVAL;
} }
up(&file->f_dentry->d_inode->i_sem); mutex_unlock(&file->f_dentry->d_inode->i_mutex);
return ret; return ret;
} }
......
...@@ -138,7 +138,7 @@ static struct dentry *get_node(int num) ...@@ -138,7 +138,7 @@ static struct dentry *get_node(int num)
{ {
char s[10]; char s[10];
struct dentry *root = capifs_root; struct dentry *root = capifs_root;
down(&root->d_inode->i_sem); mutex_lock(&root->d_inode->i_mutex);
return lookup_one_len(s, root, sprintf(s, "%d", num)); return lookup_one_len(s, root, sprintf(s, "%d", num));
} }
...@@ -159,7 +159,7 @@ void capifs_new_ncci(unsigned int number, dev_t device) ...@@ -159,7 +159,7 @@ void capifs_new_ncci(unsigned int number, dev_t device)
dentry = get_node(number); dentry = get_node(number);
if (!IS_ERR(dentry) && !dentry->d_inode) if (!IS_ERR(dentry) && !dentry->d_inode)
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
up(&capifs_root->d_inode->i_sem); mutex_unlock(&capifs_root->d_inode->i_mutex);
} }
void capifs_free_ncci(unsigned int number) void capifs_free_ncci(unsigned int number)
...@@ -175,7 +175,7 @@ void capifs_free_ncci(unsigned int number) ...@@ -175,7 +175,7 @@ void capifs_free_ncci(unsigned int number)
} }
dput(dentry); dput(dentry);
} }
up(&capifs_root->d_inode->i_sem); mutex_unlock(&capifs_root->d_inode->i_mutex);
} }
static int __init capifs_init(void) static int __init capifs_init(void)
......
...@@ -837,9 +837,9 @@ static void __set_size(struct mapped_device *md, sector_t size) ...@@ -837,9 +837,9 @@ static void __set_size(struct mapped_device *md, sector_t size)
{ {
set_capacity(md->disk, size); set_capacity(md->disk, size);
down(&md->suspended_bdev->bd_inode->i_sem); mutex_lock(&md->suspended_bdev->bd_inode->i_mutex);
i_size_write(md->suspended_bdev->bd_inode, (loff_t)size << SECTOR_SHIFT); i_size_write(md->suspended_bdev->bd_inode, (loff_t)size << SECTOR_SHIFT);
up(&md->suspended_bdev->bd_inode->i_sem); mutex_unlock(&md->suspended_bdev->bd_inode->i_mutex);
} }
static int __bind(struct mapped_device *md, struct dm_table *t) static int __bind(struct mapped_device *md, struct dm_table *t)
......
...@@ -3460,9 +3460,9 @@ static int update_size(mddev_t *mddev, unsigned long size) ...@@ -3460,9 +3460,9 @@ static int update_size(mddev_t *mddev, unsigned long size)
bdev = bdget_disk(mddev->gendisk, 0); bdev = bdget_disk(mddev->gendisk, 0);
if (bdev) { if (bdev) {
down(&bdev->bd_inode->i_sem); mutex_lock(&bdev->bd_inode->i_mutex);
i_size_write(bdev->bd_inode, mddev->array_size << 10); i_size_write(bdev->bd_inode, mddev->array_size << 10);
up(&bdev->bd_inode->i_sem); mutex_unlock(&bdev->bd_inode->i_mutex);
bdput(bdev); bdput(bdev);
} }
} }
...@@ -3486,9 +3486,9 @@ static int update_raid_disks(mddev_t *mddev, int raid_disks) ...@@ -3486,9 +3486,9 @@ static int update_raid_disks(mddev_t *mddev, int raid_disks)
bdev = bdget_disk(mddev->gendisk, 0); bdev = bdget_disk(mddev->gendisk, 0);
if (bdev) { if (bdev) {
down(&bdev->bd_inode->i_sem); mutex_lock(&bdev->bd_inode->i_mutex);
i_size_write(bdev->bd_inode, mddev->array_size << 10); i_size_write(bdev->bd_inode, mddev->array_size << 10);
up(&bdev->bd_inode->i_sem); mutex_unlock(&bdev->bd_inode->i_mutex);
bdput(bdev); bdput(bdev);
} }
} }
......
...@@ -25,7 +25,7 @@ proc_bus_pci_lseek(struct file *file, loff_t off, int whence) ...@@ -25,7 +25,7 @@ proc_bus_pci_lseek(struct file *file, loff_t off, int whence)
loff_t new = -1; loff_t new = -1;
struct inode *inode = file->f_dentry->d_inode; struct inode *inode = file->f_dentry->d_inode;
down(&inode->i_sem); mutex_lock(&inode->i_mutex);
switch (whence) { switch (whence) {
case 0: case 0:
new = off; new = off;
...@@ -41,7 +41,7 @@ proc_bus_pci_lseek(struct file *file, loff_t off, int whence) ...@@ -41,7 +41,7 @@ proc_bus_pci_lseek(struct file *file, loff_t off, int whence)
new = -EINVAL; new = -EINVAL;
else else
file->f_pos = new; file->f_pos = new;
up(&inode->i_sem); mutex_unlock(&inode->i_mutex);
return new; return new;
} }
......
...@@ -184,13 +184,13 @@ static void update_bus(struct dentry *bus) ...@@ -184,13 +184,13 @@ static void update_bus(struct dentry *bus)
bus->d_inode->i_gid = busgid; bus->d_inode->i_gid = busgid;
bus->d_inode->i_mode = S_IFDIR | busmode; bus->d_inode->i_mode = S_IFDIR | busmode;
down(&bus->d_inode->i_sem); mutex_lock(&bus->d_inode->i_mutex);
list_for_each_entry(dev, &bus->d_subdirs, d_u.d_child) list_for_each_entry(dev, &bus->d_subdirs, d_u.d_child)
if (dev->d_inode) if (dev->d_inode)
update_dev(dev); update_dev(dev);
up(&bus->d_inode->i_sem); mutex_unlock(&bus->d_inode->i_mutex);
} }
static void update_sb(struct super_block *sb) static void update_sb(struct super_block *sb)
...@@ -201,7 +201,7 @@ static void update_sb(struct super_block *sb) ...@@ -201,7 +201,7 @@ static void update_sb(struct super_block *sb)
if (!root) if (!root)
return; return;
down(&root->d_inode->i_sem); mutex_lock(&root->d_inode->i_mutex);
list_for_each_entry(bus, &root->d_subdirs, d_u.d_child) { list_for_each_entry(bus, &root->d_subdirs, d_u.d_child) {
if (bus->d_inode) { if (bus->d_inode) {
...@@ -219,7 +219,7 @@ static void update_sb(struct super_block *sb) ...@@ -219,7 +219,7 @@ static void update_sb(struct super_block *sb)
} }
} }
up(&root->d_inode->i_sem); mutex_unlock(&root->d_inode->i_mutex);
} }
static int remount(struct super_block *sb, int *flags, char *data) static int remount(struct super_block *sb, int *flags, char *data)
...@@ -333,10 +333,10 @@ static int usbfs_empty (struct dentry *dentry) ...@@ -333,10 +333,10 @@ static int usbfs_empty (struct dentry *dentry)
static int usbfs_unlink (struct inode *dir, struct dentry *dentry) static int usbfs_unlink (struct inode *dir, struct dentry *dentry)
{ {
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
down(&inode->i_sem); mutex_lock(&inode->i_mutex);
dentry->d_inode->i_nlink--; dentry->d_inode->i_nlink--;
dput(dentry); dput(dentry);
up(&inode->i_sem); mutex_unlock(&inode->i_mutex);
d_delete(dentry); d_delete(dentry);
return 0; return 0;
} }
...@@ -346,7 +346,7 @@ static int usbfs_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -346,7 +346,7 @@ static int usbfs_rmdir(struct inode *dir, struct dentry *dentry)
int error = -ENOTEMPTY; int error = -ENOTEMPTY;
struct inode * inode = dentry->d_inode; struct inode * inode = dentry->d_inode;
down(&inode->i_sem); mutex_lock(&inode->i_mutex);
dentry_unhash(dentry); dentry_unhash(dentry);
if (usbfs_empty(dentry)) { if (usbfs_empty(dentry)) {
dentry->d_inode->i_nlink -= 2; dentry->d_inode->i_nlink -= 2;
...@@ -355,7 +355,7 @@ static int usbfs_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -355,7 +355,7 @@ static int usbfs_rmdir(struct inode *dir, struct dentry *dentry)
dir->i_nlink--; dir->i_nlink--;
error = 0; error = 0;
} }
up(&inode->i_sem); mutex_unlock(&inode->i_mutex);
if (!error) if (!error)
d_delete(dentry); d_delete(dentry);
dput(dentry); dput(dentry);
...@@ -380,7 +380,7 @@ static loff_t default_file_lseek (struct file *file, loff_t offset, int orig) ...@@ -380,7 +380,7 @@ static loff_t default_file_lseek (struct file *file, loff_t offset, int orig)
{ {
loff_t retval = -EINVAL; loff_t retval = -EINVAL;
down(&file->f_dentry->d_inode->i_sem); mutex_lock(&file->f_dentry->d_inode->i_mutex);
switch(orig) { switch(orig) {
case 0: case 0:
if (offset > 0) { if (offset > 0) {
...@@ -397,7 +397,7 @@ static loff_t default_file_lseek (struct file *file, loff_t offset, int orig) ...@@ -397,7 +397,7 @@ static loff_t default_file_lseek (struct file *file, loff_t offset, int orig)
default: default:
break; break;
} }
up(&file->f_dentry->d_inode->i_sem); mutex_unlock(&file->f_dentry->d_inode->i_mutex);
return retval; return retval;
} }
...@@ -480,7 +480,7 @@ static int fs_create_by_name (const char *name, mode_t mode, ...@@ -480,7 +480,7 @@ static int fs_create_by_name (const char *name, mode_t mode,
} }
*dentry = NULL; *dentry = NULL;
down(&parent->d_inode->i_sem); mutex_lock(&parent->d_inode->i_mutex);
*dentry = lookup_one_len(name, parent, strlen(name)); *dentry = lookup_one_len(name, parent, strlen(name));
if (!IS_ERR(dentry)) { if (!IS_ERR(dentry)) {
if ((mode & S_IFMT) == S_IFDIR) if ((mode & S_IFMT) == S_IFDIR)
...@@ -489,7 +489,7 @@ static int fs_create_by_name (const char *name, mode_t mode, ...@@ -489,7 +489,7 @@ static int fs_create_by_name (const char *name, mode_t mode,
error = usbfs_create (parent->d_inode, *dentry, mode); error = usbfs_create (parent->d_inode, *dentry, mode);
} else } else
error = PTR_ERR(dentry); error = PTR_ERR(dentry);
up(&parent->d_inode->i_sem); mutex_unlock(&parent->d_inode->i_mutex);
return error; return error;
} }
...@@ -528,7 +528,7 @@ static void fs_remove_file (struct dentry *dentry) ...@@ -528,7 +528,7 @@ static void fs_remove_file (struct dentry *dentry)
if (!parent || !parent->d_inode) if (!parent || !parent->d_inode)
return; return;
down(&parent->d_inode->i_sem); mutex_lock(&parent->d_inode->i_mutex);
if (usbfs_positive(dentry)) { if (usbfs_positive(dentry)) {
if (dentry->d_inode) { if (dentry->d_inode) {
if (S_ISDIR(dentry->d_inode->i_mode)) if (S_ISDIR(dentry->d_inode->i_mode))
...@@ -538,7 +538,7 @@ static void fs_remove_file (struct dentry *dentry) ...@@ -538,7 +538,7 @@ static void fs_remove_file (struct dentry *dentry)
dput(dentry); dput(dentry);
} }
} }
up(&parent->d_inode->i_sem); mutex_unlock(&parent->d_inode->i_mutex);
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
......
...@@ -1891,7 +1891,7 @@ static int fsync_sub(struct lun *curlun) ...@@ -1891,7 +1891,7 @@ static int fsync_sub(struct lun *curlun)
return -EINVAL; return -EINVAL;
inode = filp->f_dentry->d_inode; inode = filp->f_dentry->d_inode;
down(&inode->i_sem); mutex_lock(&inode->i_mutex);
current->flags |= PF_SYNCWRITE; current->flags |= PF_SYNCWRITE;
rc = filemap_fdatawrite(inode->i_mapping); rc = filemap_fdatawrite(inode->i_mapping);
err = filp->f_op->fsync(filp, filp->f_dentry, 1); err = filp->f_op->fsync(filp, filp->f_dentry, 1);
...@@ -1901,7 +1901,7 @@ static int fsync_sub(struct lun *curlun) ...@@ -1901,7 +1901,7 @@ static int fsync_sub(struct lun *curlun)
if (!rc) if (!rc)
rc = err; rc = err;
current->flags &= ~PF_SYNCWRITE; current->flags &= ~PF_SYNCWRITE;
up(&inode->i_sem); mutex_unlock(&inode->i_mutex);
VLDBG(curlun, "fdatasync -> %d\n", rc); VLDBG(curlun, "fdatasync -> %d\n", rc);
return rc; return rc;
} }
......
...@@ -1562,10 +1562,10 @@ restart: ...@@ -1562,10 +1562,10 @@ restart:
spin_unlock_irq (&dev->lock); spin_unlock_irq (&dev->lock);
/* break link to dcache */ /* break link to dcache */
down (&parent->i_sem); mutex_lock (&parent->i_mutex);
d_delete (dentry); d_delete (dentry);
dput (dentry); dput (dentry);
up (&parent->i_sem); mutex_unlock (&parent->i_mutex);
/* fds may still be open */ /* fds may still be open */
goto restart; goto restart;
......
...@@ -244,10 +244,10 @@ affs_put_inode(struct inode *inode) ...@@ -244,10 +244,10 @@ affs_put_inode(struct inode *inode)
pr_debug("AFFS: put_inode(ino=%lu, nlink=%u)\n", inode->i_ino, inode->i_nlink); pr_debug("AFFS: put_inode(ino=%lu, nlink=%u)\n", inode->i_ino, inode->i_nlink);
affs_free_prealloc(inode); affs_free_prealloc(inode);
if (atomic_read(&inode->i_count) == 1) { if (atomic_read(&inode->i_count) == 1) {
down(&inode->i_sem); mutex_lock(&inode->i_mutex);
if (inode->i_size != AFFS_I(inode)->mmu_private) if (inode->i_size != AFFS_I(inode)->mmu_private)
affs_truncate(inode); affs_truncate(inode);
up(&inode->i_sem); mutex_unlock(&inode->i_mutex);
} }
} }
......
...@@ -229,9 +229,9 @@ static struct dentry *autofs_root_lookup(struct inode *dir, struct dentry *dentr ...@@ -229,9 +229,9 @@ static struct dentry *autofs_root_lookup(struct inode *dir, struct dentry *dentr
dentry->d_flags |= DCACHE_AUTOFS_PENDING; dentry->d_flags |= DCACHE_AUTOFS_PENDING;
d_add(dentry, NULL); d_add(dentry, NULL);
up(&dir->i_sem); mutex_unlock(&dir->i_mutex);
autofs_revalidate(dentry, nd); autofs_revalidate(dentry, nd);
down(&dir->i_sem); mutex_lock(&dir->i_mutex);
/* /*
* If we are still pending, check if we had to handle * If we are still pending, check if we had to handle
......
...@@ -489,9 +489,9 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s ...@@ -489,9 +489,9 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
d_add(dentry, NULL); d_add(dentry, NULL);
if (dentry->d_op && dentry->d_op->d_revalidate) { if (dentry->d_op && dentry->d_op->d_revalidate) {
up(&dir->i_sem); mutex_unlock(&dir->i_mutex);
(dentry->d_op->d_revalidate)(dentry, nd); (dentry->d_op->d_revalidate)(dentry, nd);
down(&dir->i_sem); mutex_lock(&dir->i_mutex);
} }
/* /*
......
...@@ -588,11 +588,11 @@ static ssize_t bm_entry_write(struct file *file, const char __user *buffer, ...@@ -588,11 +588,11 @@ static ssize_t bm_entry_write(struct file *file, const char __user *buffer,
case 2: set_bit(Enabled, &e->flags); case 2: set_bit(Enabled, &e->flags);
break; break;
case 3: root = dget(file->f_vfsmnt->mnt_sb->s_root); case 3: root = dget(file->f_vfsmnt->mnt_sb->s_root);
down(&root->d_inode->i_sem); mutex_lock(&root->d_inode->i_mutex);
kill_node(e); kill_node(e);
up(&root->d_inode->i_sem); mutex_unlock(&root->d_inode->i_mutex);
dput(root); dput(root);
break; break;
default: return res; default: return res;
...@@ -622,7 +622,7 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer, ...@@ -622,7 +622,7 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,
return PTR_ERR(e); return PTR_ERR(e);
root = dget(sb->s_root); root = dget(sb->s_root);
down(&root->d_inode->i_sem); mutex_lock(&root->d_inode->i_mutex);
dentry = lookup_one_len(e->name, root, strlen(e->name)); dentry = lookup_one_len(e->name, root, strlen(e->name));
err = PTR_ERR(dentry); err = PTR_ERR(dentry);
if (IS_ERR(dentry)) if (IS_ERR(dentry))
...@@ -658,7 +658,7 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer, ...@@ -658,7 +658,7 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,
out2: out2:
dput(dentry); dput(dentry);
out: out:
up(&root->d_inode->i_sem); mutex_unlock(&root->d_inode->i_mutex);
dput(root);