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 <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: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
 #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>
 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
        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");
                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);
 
                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) {
        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;
 
                for (;;) {
                        if (!namelen) {
-                               up(&read_mutex);
+                               mutex_unlock(&read_mutex);
                                return ERR_PTR(-EIO);
                        }
                        if (name[namelen-1])
                        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;
                }
                if (sorted)
                        break;
        }
-       up(&read_mutex);
+       mutex_unlock(&read_mutex);
        d_add(dentry, NULL);
        return NULL;
 }
                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);
 
 #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
 };
 
 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;
        int err = 0;
        struct dcookie_struct * dcs;
 
-       down(&dcookie_sem);
+       mutex_lock(&dcookie_mutex);
 
        if (!is_live()) {
                err = -EINVAL;
        *cookie = dcookie_value(dcs);
 
 out:
-       up(&dcookie_sem);
+       mutex_unlock(&dcookie_mutex);
        return err;
 }
 
        if (!capable(CAP_SYS_ADMIN))
                return -EPERM;
 
-       down(&dcookie_sem);
+       mutex_lock(&dcookie_mutex);
 
        if (!is_live()) {
                err = -EINVAL;
 out_free:
        kfree(kbuf);
 out:
-       up(&dcookie_sem);
+       mutex_unlock(&dcookie_mutex);
        return err;
 }
 
 {
        struct dcookie_user * user;
 
-       down(&dcookie_sem);
+       mutex_lock(&dcookie_mutex);
 
        user = kmalloc(sizeof(struct dcookie_user), GFP_KERNEL);
        if (!user)
        list_add(&user->next, &dcookie_users);
 
 out:
-       up(&dcookie_sem);
+       mutex_unlock(&dcookie_mutex);
        return user;
 out_free:
        kfree(user);
 
 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);
 
        */
 #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)
 {
        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;
        }
 
                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;
                }
        }
        *sourcelen = def_strm.total_in;
        ret = 0;
  out:
-       up(&deflate_sem);
+       mutex_unlock(&deflate_mutex);
        return ret;
 }
 
        int ret;
        int wbits = MAX_WBITS;
 
-       down(&inflate_sem);
+       mutex_lock(&inflate_mutex);
 
        inf_strm.next_in = data_in;
        inf_strm.avail_in = srclen;
 
        if (Z_OK != zlib_inflateInit2(&inf_strm, wbits)) {
                printk(KERN_WARNING "inflateInit failed\n");
-               up(&inflate_sem);
+               mutex_unlock(&inflate_mutex);
                return 1;
        }
 
                printk(KERN_NOTICE "inflate returned %d\n", ret);
        }
        zlib_inflateEnd(&inf_strm);
-       up(&inflate_sem);
+       mutex_unlock(&inflate_mutex);
         return 0;
 }
 
 
 #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"
  */
 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
        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;
        }
 
        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);
        sbi->log = log;
        LOG_UNLOCK(log);
 
-       up(&jfs_log_sem);
+       mutex_unlock(&jfs_log_mutex);
        return 0;
 
        /*
        blkdev_put(bdev);
 
       free:            /* free log descriptor */
-       up(&jfs_log_sem);
+       mutex_unlock(&jfs_log_mutex);
        kfree(log);
 
        jfs_warn("lmLogOpen: exit(%d)", rc);
 {
        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);
                if (rc) {
                        kfree(dummy_log);
                        dummy_log = NULL;
-                       up(&jfs_log_sem);
+                       mutex_unlock(&jfs_log_mutex);
                        return rc;
                }
        }
        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;
 }
 
        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);
        kfree(log);
 
       out:
-       up(&jfs_log_sem);
+       mutex_unlock(&jfs_log_mutex);
        jfs_info("lmLogClose: exit(%d)", rc);
        return rc;
 }
 
 #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
 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);
        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();
                                nlm_hosts[hash] = host;
                        }
                        nlm_get_host(host);
-                       up(&nlm_host_sema);
+                       mutex_unlock(&nlm_host_mutex);
                        return host;
                }
        }
                next_gc = 0;
 
 nohost:
-       up(&nlm_host_sema);
+       mutex_unlock(&nlm_host_mutex);
        return host;
 }
 
         * 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;
 }
 
        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");
 
        /* 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) {
 
 #include <linux/slab.h>
 #include <linux/smp.h>
 #include <linux/smp_lock.h>
+#include <linux/mutex.h>
 
 #include <linux/sunrpc/types.h>
 #include <linux/sunrpc/stats.h>
 struct nlmsvc_binding *                nlmsvc_ops;
 EXPORT_SYMBOL(nlmsvc_ops);
 
-static DECLARE_MUTEX(nlmsvc_sema);
+static DEFINE_MUTEX(nlmsvc_mutex);
 static unsigned int            nlmsvc_users;
 static pid_t                   nlmsvc_pid;
 int                            nlmsvc_grace_period;
 unsigned long                  nlmsvc_timeout;
 
-static DECLARE_MUTEX_LOCKED(lockd_start);
+static DECLARE_COMPLETION(lockd_start_done);
 static DECLARE_WAIT_QUEUE_HEAD(lockd_exit);
 
 /*
         * Let our maker know we're running.
         */
        nlmsvc_pid = current->pid;
-       up(&lockd_start);
+       complete(&lockd_start_done);
 
        daemonize("lockd");
 
        struct svc_serv *       serv;
        int                     error = 0;
 
-       down(&nlmsvc_sema);
+       mutex_lock(&nlmsvc_mutex);
        /*
         * Unconditionally increment the user count ... this is
         * the number of clients who _want_ a lockd process.
                        "lockd_up: create thread failed, error=%d\n", error);
                goto destroy_and_out;
        }
-       down(&lockd_start);
+       wait_for_completion(&lockd_start_done);
 
        /*
         * Note: svc_serv structures have an initial use count of 1,
 destroy_and_out:
        svc_destroy(serv);
 out:
-       up(&nlmsvc_sema);
+       mutex_unlock(&nlmsvc_mutex);
        return error;
 }
 EXPORT_SYMBOL(lockd_up);
 {
        static int warned;
 
-       down(&nlmsvc_sema);
+       mutex_lock(&nlmsvc_mutex);
        if (nlmsvc_users) {
                if (--nlmsvc_users)
                        goto out;
        recalc_sigpending();
        spin_unlock_irq(¤t->sighand->siglock);
 out:
-       up(&nlmsvc_sema);
+       mutex_unlock(&nlmsvc_mutex);
 }
 EXPORT_SYMBOL(lockd_down);
 
 
 #include <linux/string.h>
 #include <linux/time.h>
 #include <linux/in.h>
+#include <linux/mutex.h>
 #include <linux/sunrpc/svc.h>
 #include <linux/sunrpc/clnt.h>
 #include <linux/nfsd/nfsfh.h>
 #define FILE_HASH_BITS         5
 #define FILE_NRHASH            (1<<FILE_HASH_BITS)
 static struct nlm_file *       nlm_files[FILE_NRHASH];
-static DECLARE_MUTEX(nlm_file_sema);
+static DEFINE_MUTEX(nlm_file_mutex);
 
 #ifdef NFSD_DEBUG
 static inline void nlm_debug_print_fh(char *msg, struct nfs_fh *f)
        hash = file_hash(f);
 
        /* Lock file table */
-       down(&nlm_file_sema);
+       mutex_lock(&nlm_file_mutex);
 
        for (file = nlm_files[hash]; file; file = file->f_next)
                if (!nfs_compare_fh(&file->f_handle, f))
        nfserr = 0;
 
 out_unlock:
-       up(&nlm_file_sema);
+       mutex_unlock(&nlm_file_mutex);
        return nfserr;
 
 out_free:
        struct nlm_file *file, **fp;
        int             i;
 
-       down(&nlm_file_sema);
+       mutex_lock(&nlm_file_mutex);
        for (i = 0; i < FILE_NRHASH; i++) {
                fp = nlm_files + i;
                while ((file = *fp) != NULL) {
                        /* Traverse locks, blocks and shares of this file
                         * and update file->f_locks count */
                        if (nlm_inspect_file(host, file, action)) {
-                               up(&nlm_file_sema);
+                               mutex_unlock(&nlm_file_mutex);
                                return 1;
                        }
 
                        }
                }
        }
-       up(&nlm_file_sema);
+       mutex_unlock(&nlm_file_mutex);
        return 0;
 }
 
                                file, file->f_count);
 
        /* Lock file table */
-       down(&nlm_file_sema);
+       mutex_lock(&nlm_file_mutex);
 
        /* If there are no more locks etc, delete the file */
        if(--file->f_count == 0) {
                        nlm_delete_file(file);
        }
 
-       up(&nlm_file_sema);
+       mutex_unlock(&nlm_file_mutex);
 }
 
 /*
 
 #include <linux/sunrpc/svc.h>
 #include <linux/sunrpc/svcsock.h>
 #include <linux/nfs_fs.h>
+#include <linux/mutex.h>
 
 #include <net/inet_sock.h>
 
 };
 
 static struct nfs_callback_data nfs_callback_info;
-static DECLARE_MUTEX(nfs_callback_sema);
+static DEFINE_MUTEX(nfs_callback_mutex);
 static struct svc_program nfs4_callback_program;
 
 unsigned int nfs_callback_set_tcpport;
        int ret = 0;
 
        lock_kernel();
-       down(&nfs_callback_sema);
+       mutex_lock(&nfs_callback_mutex);
        if (nfs_callback_info.users++ || nfs_callback_info.pid != 0)
                goto out;
        init_completion(&nfs_callback_info.started);
        nfs_callback_info.serv = serv;
        wait_for_completion(&nfs_callback_info.started);
 out:
-       up(&nfs_callback_sema);
+       mutex_unlock(&nfs_callback_mutex);
        unlock_kernel();
        return ret;
 out_destroy:
        int ret = 0;
 
        lock_kernel();
-       down(&nfs_callback_sema);
+       mutex_lock(&nfs_callback_mutex);
        nfs_callback_info.users--;
        do {
                if (nfs_callback_info.users != 0 || nfs_callback_info.pid == 0)
                if (kill_proc(nfs_callback_info.pid, SIGKILL, 1) < 0)
                        break;
        } while (wait_for_completion_timeout(&nfs_callback_info.stopped, 5*HZ) == 0);
-       up(&nfs_callback_sema);
+       mutex_unlock(&nfs_callback_mutex);
        unlock_kernel();
        return ret;
 }
 
 #include <linux/nfsd/state.h>
 #include <linux/nfsd/xdr4.h>
 #include <linux/namei.h>
+#include <linux/mutex.h>
 
 #define NFSDDBG_FACILITY                NFSDDBG_PROC
 
 
 /* Locking:
  *
- * client_sema: 
+ * client_mutex:
  *     protects clientid_hashtbl[], clientstr_hashtbl[],
  *     unconfstr_hashtbl[], uncofid_hashtbl[].
  */
-static DECLARE_MUTEX(client_sema);
+static DEFINE_MUTEX(client_mutex);
 
 static kmem_cache_t *stateowner_slab = NULL;
 static kmem_cache_t *file_slab = NULL;
 void
 nfs4_lock_state(void)
 {
-       down(&client_sema);
+       mutex_lock(&client_mutex);
 }
 
 void
 nfs4_unlock_state(void)
 {
-       up(&client_sema);
+       mutex_unlock(&client_mutex);
 }
 
 static inline u32
 
 #include <linux/vmalloc.h>
 #include <linux/genhd.h>
 #include <linux/bitops.h>
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 
 
 struct unique_numspace {
        struct semaphore  mutex;
 };
 
-static DECLARE_MUTEX(numspace_mutex);
+static DEFINE_MUTEX(numspace_mutex);
 
 static int expand_numspace(struct unique_numspace *s)
 {
 {
        int rval = 0;
 
-       down(&numspace_mutex);
+       mutex_lock(&numspace_mutex);
        if (s->num_free < 1)
                rval = expand_numspace(s);
        if (!rval) {
                --s->num_free;
                __set_bit(rval, s->bits);
        }
-       up(&numspace_mutex);
+       mutex_unlock(&numspace_mutex);
 
        return rval;
 }
        int old_val;
 
        if (number >= 0) {
-               down(&numspace_mutex);
+               mutex_lock(&numspace_mutex);
                old_val = __test_and_clear_bit(number, s->bits);
                if (old_val)
                        ++s->num_free;
-               up(&numspace_mutex);
+               mutex_unlock(&numspace_mutex);
        }
 }
 
 
 #include <linux/writeback.h>           /* for the emergency remount stuff */
 #include <linux/idr.h>
 #include <linux/kobject.h>
+#include <linux/mutex.h>
 #include <asm/uaccess.h>
 
 
 void sync_filesystems(int wait)
 {
        struct super_block *sb;
-       static DECLARE_MUTEX(mutex);
+       static DEFINE_MUTEX(mutex);
 
-       down(&mutex);           /* Could be down_interruptible */
+       mutex_lock(&mutex);             /* Could be down_interruptible */
        spin_lock(&sb_lock);
        list_for_each_entry(sb, &super_blocks, s_list) {
                if (!sb->s_op->sync_fs)
                        goto restart;
        }
        spin_unlock(&sb_lock);
-       up(&mutex);
+       mutex_unlock(&mutex);
 }
 
 /**