ALSA: usb-audio: add support for Akai MPD16
[safe/jmp/linux-2.6] / fs / locks.c
index 6222e4b..ab24d49 100644 (file)
@@ -151,7 +151,7 @@ static struct file_lock *locks_alloc_lock(void)
        return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
 }
 
-static void locks_release_private(struct file_lock *fl)
+void locks_release_private(struct file_lock *fl)
 {
        if (fl->fl_ops) {
                if (fl->fl_ops->fl_release_private)
@@ -165,6 +165,7 @@ static void locks_release_private(struct file_lock *fl)
        }
 
 }
+EXPORT_SYMBOL_GPL(locks_release_private);
 
 /* Free a lock which is not in use. */
 static void locks_free_lock(struct file_lock *fl)
@@ -201,7 +202,7 @@ EXPORT_SYMBOL(locks_init_lock);
  * Initialises the fields of the file lock which are invariant for
  * free file_locks.
  */
-static void init_once(struct kmem_cache *cache, void *foo)
+static void init_once(void *foo)
 {
        struct file_lock *lock = (struct file_lock *) foo;
 
@@ -433,7 +434,7 @@ static int lease_mylease_callback(struct file_lock *fl, struct file_lock *try)
        return fl->fl_file == try->fl_file;
 }
 
-static struct lock_manager_operations lease_manager_ops = {
+static const struct lock_manager_operations lease_manager_ops = {
        .fl_break = lease_break_callback,
        .fl_release_private = lease_release_private_callback,
        .fl_mylease = lease_mylease_callback,
@@ -767,7 +768,7 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
         * give it the opportunity to lock the file.
         */
        if (found)
-               cond_resched_bkl();
+               cond_resched();
 
 find_conflict:
        for_each_lock(inode, before) {
@@ -1181,8 +1182,9 @@ int __break_lease(struct inode *inode, unsigned int mode)
        struct file_lock *fl;
        unsigned long break_time;
        int i_have_this_lease = 0;
+       int want_write = (mode & O_ACCMODE) != O_RDONLY;
 
-       new_fl = lease_alloc(NULL, mode & FMODE_WRITE ? F_WRLCK : F_RDLCK);
+       new_fl = lease_alloc(NULL, want_write ? F_WRLCK : F_RDLCK);
 
        lock_kernel();
 
@@ -1196,7 +1198,7 @@ int __break_lease(struct inode *inode, unsigned int mode)
                if (fl->fl_owner == current->files)
                        i_have_this_lease = 1;
 
-       if (mode & FMODE_WRITE) {
+       if (want_write) {
                /* If we want write access, we have to revoke any lease. */
                future = F_UNLCK | F_INPROGRESS;
        } else if (flock->fl_type & F_INPROGRESS) {
@@ -1349,7 +1351,7 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
        struct inode *inode = dentry->d_inode;
        int error, rdlease_count = 0, wrlease_count = 0;
 
-       if ((current->fsuid != inode->i_uid) && !capable(CAP_LEASE))
+       if ((current_fsuid() != inode->i_uid) && !capable(CAP_LEASE))
                return -EACCES;
        if (!S_ISREG(inode->i_mode))
                return -EINVAL;
@@ -1453,7 +1455,7 @@ EXPORT_SYMBOL(generic_setlease);
  *     leases held by processes on this node.
  *
  *     There is also no break_lease method; filesystems that
- *     handle their own leases shoud break leases themselves from the
+ *     handle their own leases should break leases themselves from the
  *     filesystem's open, create, and (on truncate) setattr methods.
  *
  *     Warning: the only current setlease methods exist only to disable
@@ -1564,7 +1566,7 @@ EXPORT_SYMBOL(flock_lock_file_wait);
  *     %LOCK_MAND can be combined with %LOCK_READ or %LOCK_WRITE to allow other
  *     processes read and write access respectively.
  */
-asmlinkage long sys_flock(unsigned int fd, unsigned int cmd)
+SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
 {
        struct file *filp;
        struct file_lock *lock;
@@ -1580,7 +1582,8 @@ asmlinkage long sys_flock(unsigned int fd, unsigned int cmd)
        cmd &= ~LOCK_NB;
        unlock = (cmd == LOCK_UN);
 
-       if (!unlock && !(cmd & LOCK_MAND) && !(filp->f_mode & 3))
+       if (!unlock && !(cmd & LOCK_MAND) &&
+           !(filp->f_mode & (FMODE_READ|FMODE_WRITE)))
                goto out_putf;
 
        error = flock_make_lock(filp, &lock, cmd);
@@ -1589,7 +1592,7 @@ asmlinkage long sys_flock(unsigned int fd, unsigned int cmd)
        if (can_sleep)
                lock->fl_flags |= FL_SLEEP;
 
-       error = security_file_lock(filp, cmd);
+       error = security_file_lock(filp, lock->fl_type);
        if (error)
                goto out_free;
 
@@ -1747,21 +1750,16 @@ static int do_lock_file_wait(struct file *filp, unsigned int cmd,
        if (error)
                return error;
 
-       if (filp->f_op && filp->f_op->lock != NULL)
-               error = filp->f_op->lock(filp, cmd, fl);
-       else {
-               for (;;) {
-                       error = posix_lock_file(filp, fl, NULL);
-                       if (error != FILE_LOCK_DEFERRED)
-                               break;
-                       error = wait_event_interruptible(fl->fl_wait,
-                                                        !fl->fl_next);
-                       if (!error)
-                               continue;
-
-                       locks_delete_block(fl);
+       for (;;) {
+               error = vfs_lock_file(filp, cmd, fl, NULL);
+               if (error != FILE_LOCK_DEFERRED)
                        break;
-               }
+               error = wait_event_interruptible(fl->fl_wait, !fl->fl_next);
+               if (!error)
+                       continue;
+
+               locks_delete_block(fl);
+               break;
        }
 
        return error;
@@ -2083,6 +2081,7 @@ int vfs_cancel_lock(struct file *filp, struct file_lock *fl)
 EXPORT_SYMBOL_GPL(vfs_cancel_lock);
 
 #ifdef CONFIG_PROC_FS
+#include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 
 static void lock_get_status(struct seq_file *f, struct file_lock *fl,
@@ -2188,12 +2187,31 @@ static void locks_stop(struct seq_file *f, void *v)
        unlock_kernel();
 }
 
-struct seq_operations locks_seq_operations = {
+static const struct seq_operations locks_seq_operations = {
        .start  = locks_start,
        .next   = locks_next,
        .stop   = locks_stop,
        .show   = locks_show,
 };
+
+static int locks_open(struct inode *inode, struct file *filp)
+{
+       return seq_open(filp, &locks_seq_operations);
+}
+
+static const struct file_operations proc_locks_operations = {
+       .open           = locks_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = seq_release,
+};
+
+static int __init proc_locks_init(void)
+{
+       proc_create("locks", 0, NULL, &proc_locks_operations);
+       return 0;
+}
+module_init(proc_locks_init);
 #endif
 
 /**