Skip to content

Commit

Permalink
[PATCH] mutex subsystem, semaphore to mutex: VFS, ->i_sem
Browse files Browse the repository at this point in the history
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: Ingo Molnar <[email protected]>

(finished the conversion)

Signed-off-by: Jes Sorensen <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
Jes Sorensen authored and Ingo Molnar committed Jan 9, 2006
1 parent 794ee1b commit 1b1dcc1
Show file tree
Hide file tree
Showing 113 changed files with 563 additions and 573 deletions.
12 changes: 6 additions & 6 deletions arch/powerpc/platforms/cell/spufs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ spufs_delete_inode(struct inode *inode)
static void spufs_prune_dir(struct dentry *dir)
{
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) {
spin_lock(&dcache_lock);
spin_lock(&dentry->d_lock);
Expand All @@ -154,23 +154,23 @@ static void spufs_prune_dir(struct dentry *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)
{
struct spu_context *ctx;

/* remove all entries */
down(&root->i_sem);
mutex_lock(&root->i_mutex);
spufs_prune_dir(dir_dentry);
up(&root->i_sem);
mutex_unlock(&root->i_mutex);

/* We have to give up the mm_struct */
ctx = SPUFS_I(dir_dentry->d_inode)->i_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);
}

Expand Down Expand Up @@ -330,7 +330,7 @@ long spufs_create_thread(struct nameidata *nd,
out_dput:
dput(dentry);
out_dir:
up(&nd->dentry->d_inode->i_sem);
mutex_unlock(&nd->dentry->d_inode->i_mutex);
out:
return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/block/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static int do_lo_send_aops(struct loop_device *lo, struct bio_vec *bvec,
unsigned offset, bv_offs;
int len, ret;

down(&mapping->host->i_sem);
mutex_lock(&mapping->host->i_mutex);
index = pos >> PAGE_CACHE_SHIFT;
offset = pos & ((pgoff_t)PAGE_CACHE_SIZE - 1);
bv_offs = bvec->bv_offset;
Expand Down Expand Up @@ -278,7 +278,7 @@ static int do_lo_send_aops(struct loop_device *lo, struct bio_vec *bvec,
}
ret = 0;
out:
up(&mapping->host->i_sem);
mutex_unlock(&mapping->host->i_mutex);
return ret;
unlock:
unlock_page(page);
Expand Down
4 changes: 2 additions & 2 deletions drivers/char/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ static loff_t memory_lseek(struct file * file, loff_t offset, int orig)
{
loff_t ret;

down(&file->f_dentry->d_inode->i_sem);
mutex_lock(&file->f_dentry->d_inode->i_mutex);
switch (orig) {
case 0:
file->f_pos = offset;
Expand All @@ -756,7 +756,7 @@ static loff_t memory_lseek(struct file * file, loff_t offset, int orig)
default:
ret = -EINVAL;
}
up(&file->f_dentry->d_inode->i_sem);
mutex_unlock(&file->f_dentry->d_inode->i_mutex);
return ret;
}

Expand Down
6 changes: 3 additions & 3 deletions drivers/isdn/capi/capifs.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static struct dentry *get_node(int num)
{
char s[10];
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));
}

Expand All @@ -159,7 +159,7 @@ void capifs_new_ncci(unsigned int number, dev_t device)
dentry = get_node(number);
if (!IS_ERR(dentry) && !dentry->d_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)
Expand All @@ -175,7 +175,7 @@ void capifs_free_ncci(unsigned int number)
}
dput(dentry);
}
up(&capifs_root->d_inode->i_sem);
mutex_unlock(&capifs_root->d_inode->i_mutex);
}

static int __init capifs_init(void)
Expand Down
4 changes: 2 additions & 2 deletions drivers/md/dm.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,9 @@ static void __set_size(struct mapped_device *md, sector_t 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);
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)
Expand Down
8 changes: 4 additions & 4 deletions drivers/md/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -3460,9 +3460,9 @@ static int update_size(mddev_t *mddev, unsigned long size)

bdev = bdget_disk(mddev->gendisk, 0);
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);
up(&bdev->bd_inode->i_sem);
mutex_unlock(&bdev->bd_inode->i_mutex);
bdput(bdev);
}
}
Expand All @@ -3486,9 +3486,9 @@ static int update_raid_disks(mddev_t *mddev, int raid_disks)

bdev = bdget_disk(mddev->gendisk, 0);
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);
up(&bdev->bd_inode->i_sem);
mutex_unlock(&bdev->bd_inode->i_mutex);
bdput(bdev);
}
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/pci/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ proc_bus_pci_lseek(struct file *file, loff_t off, int whence)
loff_t new = -1;
struct inode *inode = file->f_dentry->d_inode;

down(&inode->i_sem);
mutex_lock(&inode->i_mutex);
switch (whence) {
case 0:
new = off;
Expand All @@ -41,7 +41,7 @@ proc_bus_pci_lseek(struct file *file, loff_t off, int whence)
new = -EINVAL;
else
file->f_pos = new;
up(&inode->i_sem);
mutex_unlock(&inode->i_mutex);
return new;
}

Expand Down
28 changes: 14 additions & 14 deletions drivers/usb/core/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ static void update_bus(struct dentry *bus)
bus->d_inode->i_gid = busgid;
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)
if (dev->d_inode)
update_dev(dev);

up(&bus->d_inode->i_sem);
mutex_unlock(&bus->d_inode->i_mutex);
}

static void update_sb(struct super_block *sb)
Expand All @@ -201,7 +201,7 @@ static void update_sb(struct super_block *sb)
if (!root)
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) {
if (bus->d_inode) {
Expand All @@ -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)
Expand Down Expand Up @@ -333,10 +333,10 @@ static int usbfs_empty (struct dentry *dentry)
static int usbfs_unlink (struct inode *dir, struct dentry *dentry)
{
struct inode *inode = dentry->d_inode;
down(&inode->i_sem);
mutex_lock(&inode->i_mutex);
dentry->d_inode->i_nlink--;
dput(dentry);
up(&inode->i_sem);
mutex_unlock(&inode->i_mutex);
d_delete(dentry);
return 0;
}
Expand All @@ -346,7 +346,7 @@ static int usbfs_rmdir(struct inode *dir, struct dentry *dentry)
int error = -ENOTEMPTY;
struct inode * inode = dentry->d_inode;

down(&inode->i_sem);
mutex_lock(&inode->i_mutex);
dentry_unhash(dentry);
if (usbfs_empty(dentry)) {
dentry->d_inode->i_nlink -= 2;
Expand All @@ -355,7 +355,7 @@ static int usbfs_rmdir(struct inode *dir, struct dentry *dentry)
dir->i_nlink--;
error = 0;
}
up(&inode->i_sem);
mutex_unlock(&inode->i_mutex);
if (!error)
d_delete(dentry);
dput(dentry);
Expand All @@ -380,7 +380,7 @@ static loff_t default_file_lseek (struct file *file, loff_t offset, int orig)
{
loff_t retval = -EINVAL;

down(&file->f_dentry->d_inode->i_sem);
mutex_lock(&file->f_dentry->d_inode->i_mutex);
switch(orig) {
case 0:
if (offset > 0) {
Expand All @@ -397,7 +397,7 @@ static loff_t default_file_lseek (struct file *file, loff_t offset, int orig)
default:
break;
}
up(&file->f_dentry->d_inode->i_sem);
mutex_unlock(&file->f_dentry->d_inode->i_mutex);
return retval;
}

Expand Down Expand Up @@ -480,7 +480,7 @@ static int fs_create_by_name (const char *name, mode_t mode,
}

*dentry = NULL;
down(&parent->d_inode->i_sem);
mutex_lock(&parent->d_inode->i_mutex);
*dentry = lookup_one_len(name, parent, strlen(name));
if (!IS_ERR(dentry)) {
if ((mode & S_IFMT) == S_IFDIR)
Expand All @@ -489,7 +489,7 @@ static int fs_create_by_name (const char *name, mode_t mode,
error = usbfs_create (parent->d_inode, *dentry, mode);
} else
error = PTR_ERR(dentry);
up(&parent->d_inode->i_sem);
mutex_unlock(&parent->d_inode->i_mutex);

return error;
}
Expand Down Expand Up @@ -528,7 +528,7 @@ static void fs_remove_file (struct dentry *dentry)
if (!parent || !parent->d_inode)
return;

down(&parent->d_inode->i_sem);
mutex_lock(&parent->d_inode->i_mutex);
if (usbfs_positive(dentry)) {
if (dentry->d_inode) {
if (S_ISDIR(dentry->d_inode->i_mode))
Expand All @@ -538,7 +538,7 @@ static void fs_remove_file (struct dentry *dentry)
dput(dentry);
}
}
up(&parent->d_inode->i_sem);
mutex_unlock(&parent->d_inode->i_mutex);
}

/* --------------------------------------------------------------------- */
Expand Down
4 changes: 2 additions & 2 deletions drivers/usb/gadget/file_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1891,7 +1891,7 @@ static int fsync_sub(struct lun *curlun)
return -EINVAL;

inode = filp->f_dentry->d_inode;
down(&inode->i_sem);
mutex_lock(&inode->i_mutex);
current->flags |= PF_SYNCWRITE;
rc = filemap_fdatawrite(inode->i_mapping);
err = filp->f_op->fsync(filp, filp->f_dentry, 1);
Expand All @@ -1901,7 +1901,7 @@ static int fsync_sub(struct lun *curlun)
if (!rc)
rc = err;
current->flags &= ~PF_SYNCWRITE;
up(&inode->i_sem);
mutex_unlock(&inode->i_mutex);
VLDBG(curlun, "fdatasync -> %d\n", rc);
return rc;
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/usb/gadget/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1562,10 +1562,10 @@ static void destroy_ep_files (struct dev_data *dev)
spin_unlock_irq (&dev->lock);

/* break link to dcache */
down (&parent->i_sem);
mutex_lock (&parent->i_mutex);
d_delete (dentry);
dput (dentry);
up (&parent->i_sem);
mutex_unlock (&parent->i_mutex);

/* fds may still be open */
goto restart;
Expand Down
4 changes: 2 additions & 2 deletions fs/affs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
affs_free_prealloc(inode);
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)
affs_truncate(inode);
up(&inode->i_sem);
mutex_unlock(&inode->i_mutex);
}
}

Expand Down
4 changes: 2 additions & 2 deletions fs/autofs/root.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ static struct dentry *autofs_root_lookup(struct inode *dir, struct dentry *dentr
dentry->d_flags |= DCACHE_AUTOFS_PENDING;
d_add(dentry, NULL);

up(&dir->i_sem);
mutex_unlock(&dir->i_mutex);
autofs_revalidate(dentry, nd);
down(&dir->i_sem);
mutex_lock(&dir->i_mutex);

/*
* If we are still pending, check if we had to handle
Expand Down
4 changes: 2 additions & 2 deletions fs/autofs4/root.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,9 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
d_add(dentry, NULL);

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);
down(&dir->i_sem);
mutex_lock(&dir->i_mutex);
}

/*
Expand Down
12 changes: 6 additions & 6 deletions fs/binfmt_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,11 @@ static ssize_t bm_entry_write(struct file *file, const char __user *buffer,
case 2: set_bit(Enabled, &e->flags);
break;
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);

up(&root->d_inode->i_sem);
mutex_unlock(&root->d_inode->i_mutex);
dput(root);
break;
default: return res;
Expand Down Expand Up @@ -622,7 +622,7 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,
return PTR_ERR(e);

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));
err = PTR_ERR(dentry);
if (IS_ERR(dentry))
Expand Down Expand Up @@ -658,7 +658,7 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,
out2:
dput(dentry);
out:
up(&root->d_inode->i_sem);
mutex_unlock(&root->d_inode->i_mutex);
dput(root);

if (err) {
Expand Down Expand Up @@ -703,12 +703,12 @@ static ssize_t bm_status_write(struct file * file, const char __user * buffer,
case 1: enabled = 0; break;
case 2: enabled = 1; break;
case 3: root = dget(file->f_vfsmnt->mnt_sb->s_root);
down(&root->d_inode->i_sem);
mutex_lock(&root->d_inode->i_mutex);

while (!list_empty(&entries))
kill_node(list_entry(entries.next, Node, list));

up(&root->d_inode->i_sem);
mutex_unlock(&root->d_inode->i_mutex);
dput(root);
default: return res;
}
Expand Down
Loading

0 comments on commit 1b1dcc1

Please sign in to comment.