Skip to content

Commit

Permalink
[PATCH] sem2mutex: fs/
Browse files Browse the repository at this point in the history
Semaphore to mutex conversion.

The conversion was generated via scripts, and the result was validated
automatically via a script as well.

Signed-off-by: Ingo Molnar <[email protected]>
Cc: Eric Van Hensbergen <[email protected]>
Cc: Robert Love <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: Neil Brown <[email protected]>
Cc: Trond Myklebust <[email protected]>
Cc: Dave Kleikamp <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Ingo Molnar authored and Linus Torvalds committed Mar 26, 2006
1 parent e655a25 commit 353ab6e
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 89 deletions.
31 changes: 16 additions & 15 deletions fs/cramfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <linux/cramfs_fs_sb.h>
#include <linux/buffer_head.h>
#include <linux/vfs.h>
#include <linux/mutex.h>
#include <asm/semaphore.h>

#include <asm/uaccess.h>
Expand All @@ -31,7 +32,7 @@ static struct inode_operations cramfs_dir_inode_operations;
static struct file_operations cramfs_directory_operations;
static struct address_space_operations cramfs_aops;

static DECLARE_MUTEX(read_mutex);
static DEFINE_MUTEX(read_mutex);


/* These two macros may change in future, to provide better st_ino
Expand Down Expand Up @@ -250,20 +251,20 @@ static int cramfs_fill_super(struct super_block *sb, void *data, int silent)
memset(sbi, 0, sizeof(struct cramfs_sb_info));

/* Invalidate the read buffers on mount: think disk change.. */
down(&read_mutex);
mutex_lock(&read_mutex);
for (i = 0; i < READ_BUFFERS; i++)
buffer_blocknr[i] = -1;

/* Read the first block and get the superblock from it */
memcpy(&super, cramfs_read(sb, 0, sizeof(super)), sizeof(super));
up(&read_mutex);
mutex_unlock(&read_mutex);

/* Do sanity checks on the superblock */
if (super.magic != CRAMFS_MAGIC) {
/* check at 512 byte offset */
down(&read_mutex);
mutex_lock(&read_mutex);
memcpy(&super, cramfs_read(sb, 512, sizeof(super)), sizeof(super));
up(&read_mutex);
mutex_unlock(&read_mutex);
if (super.magic != CRAMFS_MAGIC) {
if (!silent)
printk(KERN_ERR "cramfs: wrong magic\n");
Expand Down Expand Up @@ -366,7 +367,7 @@ static int cramfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
mode_t mode;
int namelen, error;

down(&read_mutex);
mutex_lock(&read_mutex);
de = cramfs_read(sb, OFFSET(inode) + offset, sizeof(*de)+256);
name = (char *)(de+1);

Expand All @@ -379,7 +380,7 @@ static int cramfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
memcpy(buf, name, namelen);
ino = CRAMINO(de);
mode = de->mode;
up(&read_mutex);
mutex_unlock(&read_mutex);
nextoffset = offset + sizeof(*de) + namelen;
for (;;) {
if (!namelen) {
Expand Down Expand Up @@ -410,7 +411,7 @@ static struct dentry * cramfs_lookup(struct inode *dir, struct dentry *dentry, s
unsigned int offset = 0;
int sorted;

down(&read_mutex);
mutex_lock(&read_mutex);
sorted = CRAMFS_SB(dir->i_sb)->flags & CRAMFS_FLAG_SORTED_DIRS;
while (offset < dir->i_size) {
struct cramfs_inode *de;
Expand All @@ -433,7 +434,7 @@ static struct dentry * cramfs_lookup(struct inode *dir, struct dentry *dentry, s

for (;;) {
if (!namelen) {
up(&read_mutex);
mutex_unlock(&read_mutex);
return ERR_PTR(-EIO);
}
if (name[namelen-1])
Expand All @@ -447,15 +448,15 @@ static struct dentry * cramfs_lookup(struct inode *dir, struct dentry *dentry, s
continue;
if (!retval) {
struct cramfs_inode entry = *de;
up(&read_mutex);
mutex_unlock(&read_mutex);
d_add(dentry, get_cramfs_inode(dir->i_sb, &entry));
return NULL;
}
/* else (retval < 0) */
if (sorted)
break;
}
up(&read_mutex);
mutex_unlock(&read_mutex);
d_add(dentry, NULL);
return NULL;
}
Expand All @@ -474,21 +475,21 @@ static int cramfs_readpage(struct file *file, struct page * page)
u32 start_offset, compr_len;

start_offset = OFFSET(inode) + maxblock*4;
down(&read_mutex);
mutex_lock(&read_mutex);
if (page->index)
start_offset = *(u32 *) cramfs_read(sb, blkptr_offset-4, 4);
compr_len = (*(u32 *) cramfs_read(sb, blkptr_offset, 4) - start_offset);
up(&read_mutex);
mutex_unlock(&read_mutex);
pgdata = kmap(page);
if (compr_len == 0)
; /* hole */
else {
down(&read_mutex);
mutex_lock(&read_mutex);
bytes_filled = cramfs_uncompress_block(pgdata,
PAGE_CACHE_SIZE,
cramfs_read(sb, start_offset, compr_len),
compr_len);
up(&read_mutex);
mutex_unlock(&read_mutex);
}
} else
pgdata = kmap(page);
Expand Down
19 changes: 10 additions & 9 deletions fs/dcookies.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <linux/mm.h>
#include <linux/errno.h>
#include <linux/dcookies.h>
#include <linux/mutex.h>
#include <asm/uaccess.h>

/* The dcookies are allocated from a kmem_cache and
Expand All @@ -36,7 +37,7 @@ struct dcookie_struct {
};

static LIST_HEAD(dcookie_users);
static DECLARE_MUTEX(dcookie_sem);
static DEFINE_MUTEX(dcookie_mutex);
static kmem_cache_t * dcookie_cache;
static struct list_head * dcookie_hashtable;
static size_t hash_size;
Expand Down Expand Up @@ -114,7 +115,7 @@ int get_dcookie(struct dentry * dentry, struct vfsmount * vfsmnt,
int err = 0;
struct dcookie_struct * dcs;

down(&dcookie_sem);
mutex_lock(&dcookie_mutex);

if (!is_live()) {
err = -EINVAL;
Expand All @@ -134,7 +135,7 @@ int get_dcookie(struct dentry * dentry, struct vfsmount * vfsmnt,
*cookie = dcookie_value(dcs);

out:
up(&dcookie_sem);
mutex_unlock(&dcookie_mutex);
return err;
}

Expand All @@ -157,7 +158,7 @@ asmlinkage long sys_lookup_dcookie(u64 cookie64, char __user * buf, size_t len)
if (!capable(CAP_SYS_ADMIN))
return -EPERM;

down(&dcookie_sem);
mutex_lock(&dcookie_mutex);

if (!is_live()) {
err = -EINVAL;
Expand Down Expand Up @@ -192,7 +193,7 @@ asmlinkage long sys_lookup_dcookie(u64 cookie64, char __user * buf, size_t len)
out_free:
kfree(kbuf);
out:
up(&dcookie_sem);
mutex_unlock(&dcookie_mutex);
return err;
}

Expand Down Expand Up @@ -290,7 +291,7 @@ struct dcookie_user * dcookie_register(void)
{
struct dcookie_user * user;

down(&dcookie_sem);
mutex_lock(&dcookie_mutex);

user = kmalloc(sizeof(struct dcookie_user), GFP_KERNEL);
if (!user)
Expand All @@ -302,7 +303,7 @@ struct dcookie_user * dcookie_register(void)
list_add(&user->next, &dcookie_users);

out:
up(&dcookie_sem);
mutex_unlock(&dcookie_mutex);
return user;
out_free:
kfree(user);
Expand All @@ -313,15 +314,15 @@ struct dcookie_user * dcookie_register(void)

void dcookie_unregister(struct dcookie_user * user)
{
down(&dcookie_sem);
mutex_lock(&dcookie_mutex);

list_del(&user->next);
kfree(user);

if (!is_live())
dcookie_exit();

up(&dcookie_sem);
mutex_unlock(&dcookie_mutex);
}

EXPORT_SYMBOL_GPL(dcookie_register);
Expand Down
19 changes: 10 additions & 9 deletions fs/jffs2/compr_zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
*/
#define STREAM_END_SPACE 12

static DECLARE_MUTEX(deflate_sem);
static DECLARE_MUTEX(inflate_sem);
static DEFINE_MUTEX(deflate_mutex);
static DEFINE_MUTEX(inflate_mutex);
static z_stream inf_strm, def_strm;

#ifdef __KERNEL__ /* Linux-only */
#include <linux/vmalloc.h>
#include <linux/init.h>
#include <linux/mutex.h>

static int __init alloc_workspaces(void)
{
Expand Down Expand Up @@ -79,11 +80,11 @@ static int jffs2_zlib_compress(unsigned char *data_in,
if (*dstlen <= STREAM_END_SPACE)
return -1;

down(&deflate_sem);
mutex_lock(&deflate_mutex);

if (Z_OK != zlib_deflateInit(&def_strm, 3)) {
printk(KERN_WARNING "deflateInit failed\n");
up(&deflate_sem);
mutex_unlock(&deflate_mutex);
return -1;
}

Expand All @@ -104,7 +105,7 @@ static int jffs2_zlib_compress(unsigned char *data_in,
if (ret != Z_OK) {
D1(printk(KERN_DEBUG "deflate in loop returned %d\n", ret));
zlib_deflateEnd(&def_strm);
up(&deflate_sem);
mutex_unlock(&deflate_mutex);
return -1;
}
}
Expand Down Expand Up @@ -133,7 +134,7 @@ static int jffs2_zlib_compress(unsigned char *data_in,
*sourcelen = def_strm.total_in;
ret = 0;
out:
up(&deflate_sem);
mutex_unlock(&deflate_mutex);
return ret;
}

Expand All @@ -145,7 +146,7 @@ static int jffs2_zlib_decompress(unsigned char *data_in,
int ret;
int wbits = MAX_WBITS;

down(&inflate_sem);
mutex_lock(&inflate_mutex);

inf_strm.next_in = data_in;
inf_strm.avail_in = srclen;
Expand Down Expand Up @@ -173,7 +174,7 @@ static int jffs2_zlib_decompress(unsigned char *data_in,

if (Z_OK != zlib_inflateInit2(&inf_strm, wbits)) {
printk(KERN_WARNING "inflateInit failed\n");
up(&inflate_sem);
mutex_unlock(&inflate_mutex);
return 1;
}

Expand All @@ -183,7 +184,7 @@ static int jffs2_zlib_decompress(unsigned char *data_in,
printk(KERN_NOTICE "inflate returned %d\n", ret);
}
zlib_inflateEnd(&inf_strm);
up(&inflate_sem);
mutex_unlock(&inflate_mutex);
return 0;
}

Expand Down
Loading

0 comments on commit 353ab6e

Please sign in to comment.