Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 353ab6e9 authored by Ingo Molnar's avatar Ingo Molnar Committed by Linus Torvalds
Browse files

[PATCH] sem2mutex: fs/



Semaphore to mutex conversion.

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

Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Cc: Eric Van Hensbergen <ericvh@ericvh.myip.org>
Cc: Robert Love <rml@tech9.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Neil Brown <neilb@cse.unsw.edu.au>
Cc: Trond Myklebust <trond.myklebust@fys.uio.no>
Cc: Dave Kleikamp <shaggy@austin.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent e655a250
Loading
Loading
Loading
Loading
+16 −15
Original line number Diff line number Diff line
@@ -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>
@@ -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
@@ -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");
@@ -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);

@@ -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) {
@@ -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;
@@ -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])
@@ -447,7 +448,7 @@ 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;
		}
@@ -455,7 +456,7 @@ static struct dentry * cramfs_lookup(struct inode *dir, struct dentry *dentry, s
		if (sorted)
			break;
	}
	up(&read_mutex);
	mutex_unlock(&read_mutex);
	d_add(dentry, NULL);
	return NULL;
}
@@ -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);
+10 −9
Original line number Diff line number Diff line
@@ -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
@@ -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;
@@ -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;
@@ -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;
}

@@ -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;
@@ -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;
}

@@ -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)
@@ -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);
@@ -313,7 +314,7 @@ 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);
@@ -321,7 +322,7 @@ void dcookie_unregister(struct dcookie_user * user)
	if (!is_live())
		dcookie_exit();

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

EXPORT_SYMBOL_GPL(dcookie_register);
+10 −9
Original line number Diff line number Diff line
@@ -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)
{
@@ -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;
	}

@@ -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;
		}
	}
@@ -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;
}

@@ -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;
@@ -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;
	}

@@ -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;
}

+14 −13
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@
#include <linux/bio.h>
#include <linux/suspend.h>
#include <linux/delay.h>
#include <linux/mutex.h>
#include "jfs_incore.h"
#include "jfs_filsys.h"
#include "jfs_metapage.h"
@@ -165,7 +166,7 @@ do { \
 */
static LIST_HEAD(jfs_external_logs);
static struct jfs_log *dummy_log = NULL;
static DECLARE_MUTEX(jfs_log_sem);
static DEFINE_MUTEX(jfs_log_mutex);

/*
 * forward references
@@ -1085,20 +1086,20 @@ int lmLogOpen(struct super_block *sb)
	if (sbi->mntflag & JFS_INLINELOG)
		return open_inline_log(sb);

	down(&jfs_log_sem);
	mutex_lock(&jfs_log_mutex);
	list_for_each_entry(log, &jfs_external_logs, journal_list) {
		if (log->bdev->bd_dev == sbi->logdev) {
			if (memcmp(log->uuid, sbi->loguuid,
				   sizeof(log->uuid))) {
				jfs_warn("wrong uuid on JFS journal\n");
				up(&jfs_log_sem);
				mutex_unlock(&jfs_log_mutex);
				return -EINVAL;
			}
			/*
			 * add file system to log active file system list
			 */
			if ((rc = lmLogFileSystem(log, sbi, 1))) {
				up(&jfs_log_sem);
				mutex_unlock(&jfs_log_mutex);
				return rc;
			}
			goto journal_found;
@@ -1106,7 +1107,7 @@ int lmLogOpen(struct super_block *sb)
	}

	if (!(log = kzalloc(sizeof(struct jfs_log), GFP_KERNEL))) {
		up(&jfs_log_sem);
		mutex_unlock(&jfs_log_mutex);
		return -ENOMEM;
	}
	INIT_LIST_HEAD(&log->sb_list);
@@ -1151,7 +1152,7 @@ int lmLogOpen(struct super_block *sb)
	sbi->log = log;
	LOG_UNLOCK(log);

	up(&jfs_log_sem);
	mutex_unlock(&jfs_log_mutex);
	return 0;

	/*
@@ -1168,7 +1169,7 @@ int lmLogOpen(struct super_block *sb)
	blkdev_put(bdev);

      free:		/* free log descriptor */
	up(&jfs_log_sem);
	mutex_unlock(&jfs_log_mutex);
	kfree(log);

	jfs_warn("lmLogOpen: exit(%d)", rc);
@@ -1212,11 +1213,11 @@ static int open_dummy_log(struct super_block *sb)
{
	int rc;

	down(&jfs_log_sem);
	mutex_lock(&jfs_log_mutex);
	if (!dummy_log) {
		dummy_log = kzalloc(sizeof(struct jfs_log), GFP_KERNEL);
		if (!dummy_log) {
			up(&jfs_log_sem);
			mutex_unlock(&jfs_log_mutex);
			return -ENOMEM;
		}
		INIT_LIST_HEAD(&dummy_log->sb_list);
@@ -1229,7 +1230,7 @@ static int open_dummy_log(struct super_block *sb)
		if (rc) {
			kfree(dummy_log);
			dummy_log = NULL;
			up(&jfs_log_sem);
			mutex_unlock(&jfs_log_mutex);
			return rc;
		}
	}
@@ -1238,7 +1239,7 @@ static int open_dummy_log(struct super_block *sb)
	list_add(&JFS_SBI(sb)->log_list, &dummy_log->sb_list);
	JFS_SBI(sb)->log = dummy_log;
	LOG_UNLOCK(dummy_log);
	up(&jfs_log_sem);
	mutex_unlock(&jfs_log_mutex);

	return 0;
}
@@ -1466,7 +1467,7 @@ int lmLogClose(struct super_block *sb)

	jfs_info("lmLogClose: log:0x%p", log);

	down(&jfs_log_sem);
	mutex_lock(&jfs_log_mutex);
	LOG_LOCK(log);
	list_del(&sbi->log_list);
	LOG_UNLOCK(log);
@@ -1516,7 +1517,7 @@ int lmLogClose(struct super_block *sb)
	kfree(log);

      out:
	up(&jfs_log_sem);
	mutex_unlock(&jfs_log_mutex);
	jfs_info("lmLogClose: exit(%d)", rc);
	return rc;
}
+10 −9
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
#include <linux/sunrpc/svc.h>
#include <linux/lockd/lockd.h>
#include <linux/lockd/sm_inter.h>
#include <linux/mutex.h>


#define NLMDBG_FACILITY		NLMDBG_HOSTCACHE
@@ -30,7 +31,7 @@
static struct nlm_host *	nlm_hosts[NLM_HOST_NRHASH];
static unsigned long		next_gc;
static int			nrhosts;
static DECLARE_MUTEX(nlm_host_sema);
static DEFINE_MUTEX(nlm_host_mutex);


static void			nlm_gc_hosts(void);
@@ -71,7 +72,7 @@ nlm_lookup_host(int server, struct sockaddr_in *sin,
	hash = NLM_ADDRHASH(sin->sin_addr.s_addr);

	/* Lock hash table */
	down(&nlm_host_sema);
	mutex_lock(&nlm_host_mutex);

	if (time_after_eq(jiffies, next_gc))
		nlm_gc_hosts();
@@ -91,7 +92,7 @@ nlm_lookup_host(int server, struct sockaddr_in *sin,
				nlm_hosts[hash] = host;
			}
			nlm_get_host(host);
			up(&nlm_host_sema);
			mutex_unlock(&nlm_host_mutex);
			return host;
		}
	}
@@ -130,7 +131,7 @@ nlm_lookup_host(int server, struct sockaddr_in *sin,
		next_gc = 0;

nohost:
	up(&nlm_host_sema);
	mutex_unlock(&nlm_host_mutex);
	return host;
}

@@ -141,19 +142,19 @@ nlm_find_client(void)
	 * and return it
	 */
	int hash;
	down(&nlm_host_sema);
	mutex_lock(&nlm_host_mutex);
	for (hash = 0 ; hash < NLM_HOST_NRHASH; hash++) {
		struct nlm_host *host, **hp;
		for (hp = &nlm_hosts[hash]; (host = *hp) != 0; hp = &host->h_next) {
			if (host->h_server &&
			    host->h_killed == 0) {
				nlm_get_host(host);
				up(&nlm_host_sema);
				mutex_unlock(&nlm_host_mutex);
				return host;
			}
		}
	}
	up(&nlm_host_sema);
	mutex_unlock(&nlm_host_mutex);
	return NULL;
}

@@ -265,7 +266,7 @@ nlm_shutdown_hosts(void)
	int		i;

	dprintk("lockd: shutting down host module\n");
	down(&nlm_host_sema);
	mutex_lock(&nlm_host_mutex);

	/* First, make all hosts eligible for gc */
	dprintk("lockd: nuking all hosts...\n");
@@ -276,7 +277,7 @@ nlm_shutdown_hosts(void)

	/* Then, perform a garbage collection pass */
	nlm_gc_hosts();
	up(&nlm_host_sema);
	mutex_unlock(&nlm_host_mutex);

	/* complain if any hosts are left */
	if (nrhosts) {
Loading