]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/lockd/svclock.c
Merge rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[linux-2.6-omap-h63xx.git] / fs / lockd / svclock.c
index 7209712f3832aa93adc5d0829d05f3fdb97f4432..c7db0a5bccdc19bcff9134efe7df604e55cdab22 100644 (file)
@@ -139,19 +139,19 @@ static inline int nlm_cookie_match(struct nlm_cookie *a, struct nlm_cookie *b)
  * Find a block with a given NLM cookie.
  */
 static inline struct nlm_block *
-nlmsvc_find_block(struct nlm_cookie *cookie,  struct sockaddr_in *sin)
+nlmsvc_find_block(struct nlm_cookie *cookie)
 {
        struct nlm_block *block;
 
        list_for_each_entry(block, &nlm_blocked, b_list) {
-               if (nlm_cookie_match(&block->b_call->a_args.cookie,cookie)
-                               && nlm_cmp_addr(sin, &block->b_host->h_addr))
+               if (nlm_cookie_match(&block->b_call->a_args.cookie,cookie))
                        goto found;
        }
 
        return NULL;
 
 found:
+       dprintk("nlmsvc_find_block(%s): block=%p\n", nlmdbg_cookie2a(cookie), block);
        kref_get(&block->b_count);
        return block;
 }
@@ -165,6 +165,11 @@ found:
  * request, but (as I found out later) that's because some implementations
  * do just this. Never mind the standards comittees, they support our
  * logging industries.
+ *
+ * 10 years later: I hope we can safely ignore these old and broken
+ * clients by now. Let's fix this so we can uniquely identify an incoming
+ * GRANTED_RES message by cookie, without having to rely on the client's IP
+ * address. --okir
  */
 static inline struct nlm_block *
 nlmsvc_create_block(struct svc_rqst *rqstp, struct nlm_file *file,
@@ -197,7 +202,7 @@ nlmsvc_create_block(struct svc_rqst *rqstp, struct nlm_file *file,
        /* Set notifier function for VFS, and init args */
        call->a_args.lock.fl.fl_flags |= FL_SLEEP;
        call->a_args.lock.fl.fl_lmops = &nlmsvc_lock_operations;
-       call->a_args.cookie = *cookie;  /* see above */
+       nlmclnt_next_cookie(&call->a_args.cookie);
 
        dprintk("lockd: created block %p...\n", block);
 
@@ -249,9 +254,9 @@ static void nlmsvc_free_block(struct kref *kref)
        dprintk("lockd: freeing block %p...\n", block);
 
        /* Remove block from file's list of blocks */
-       down(&file->f_sema);
+       mutex_lock(&file->f_mutex);
        list_del_init(&block->b_flist);
-       up(&file->f_sema);
+       mutex_unlock(&file->f_mutex);
 
        nlmsvc_freegrantargs(block->b_call);
        nlm_release_call(block->b_call);
@@ -265,49 +270,32 @@ static void nlmsvc_release_block(struct nlm_block *block)
                kref_put(&block->b_count, nlmsvc_free_block);
 }
 
-static void nlmsvc_act_mark(struct nlm_host *host, struct nlm_file *file)
-{
-       struct nlm_block *block;
-
-       down(&file->f_sema);
-       list_for_each_entry(block, &file->f_blocks, b_flist)
-               block->b_host->h_inuse = 1;
-       up(&file->f_sema);
-}
-
-static void nlmsvc_act_unlock(struct nlm_host *host, struct nlm_file *file)
+/*
+ * Loop over all blocks and delete blocks held by
+ * a matching host.
+ */
+void nlmsvc_traverse_blocks(struct nlm_host *host,
+                       struct nlm_file *file,
+                       nlm_host_match_fn_t match)
 {
        struct nlm_block *block, *next;
 
 restart:
-       down(&file->f_sema);
+       mutex_lock(&file->f_mutex);
        list_for_each_entry_safe(block, next, &file->f_blocks, b_flist) {
-               if (host != NULL && host != block->b_host)
+               if (!match(block->b_host, host))
                        continue;
                /* Do not destroy blocks that are not on
                 * the global retry list - why? */
                if (list_empty(&block->b_list))
                        continue;
                kref_get(&block->b_count);
-               up(&file->f_sema);
+               mutex_unlock(&file->f_mutex);
                nlmsvc_unlink_block(block);
                nlmsvc_release_block(block);
                goto restart;
        }
-       up(&file->f_sema);
-}
-
-/*
- * Loop over all blocks and perform the action specified.
- * (NLM_ACT_CHECK handled by nlmsvc_inspect_file).
- */
-void
-nlmsvc_traverse_blocks(struct nlm_host *host, struct nlm_file *file, int action)
-{
-       if (action == NLM_ACT_MARK)
-               nlmsvc_act_mark(host, file);
-       else
-               nlmsvc_act_unlock(host, file);
+       mutex_unlock(&file->f_mutex);
 }
 
 /*
@@ -346,17 +334,17 @@ static void nlmsvc_freegrantargs(struct nlm_rqst *call)
  * Attempt to establish a lock, and if it can't be granted, block it
  * if required.
  */
-u32
+__be32
 nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
                        struct nlm_lock *lock, int wait, struct nlm_cookie *cookie)
 {
        struct nlm_block        *block, *newblock = NULL;
        int                     error;
-       u32                     ret;
+       __be32                  ret;
 
        dprintk("lockd: nlmsvc_lock(%s/%ld, ty=%d, pi=%d, %Ld-%Ld, bl=%d)\n",
-                               file->f_file->f_dentry->d_inode->i_sb->s_id,
-                               file->f_file->f_dentry->d_inode->i_ino,
+                               file->f_file->f_path.dentry->d_inode->i_sb->s_id,
+                               file->f_file->f_path.dentry->d_inode->i_ino,
                                lock->fl.fl_type, lock->fl.fl_pid,
                                (long long)lock->fl.fl_start,
                                (long long)lock->fl.fl_end,
@@ -366,7 +354,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
        lock->fl.fl_flags &= ~FL_SLEEP;
 again:
        /* Lock file against concurrent access */
-       down(&file->f_sema);
+       mutex_lock(&file->f_mutex);
        /* Get existing block (in case client is busy-waiting) */
        block = nlmsvc_lookup_block(file, lock);
        if (block == NULL) {
@@ -404,10 +392,10 @@ again:
 
        /* If we don't have a block, create and initialize it. Then
         * retry because we may have slept in kmalloc. */
-       /* We have to release f_sema as nlmsvc_create_block may try to
+       /* We have to release f_mutex as nlmsvc_create_block may try to
         * to claim it while doing host garbage collection */
        if (newblock == NULL) {
-               up(&file->f_sema);
+               mutex_unlock(&file->f_mutex);
                dprintk("lockd: blocking on this lock (allocating).\n");
                if (!(newblock = nlmsvc_create_block(rqstp, file, lock, cookie)))
                        return nlm_lck_denied_nolocks;
@@ -417,7 +405,7 @@ again:
        /* Append to list of blocked */
        nlmsvc_insert_block(newblock, NLM_NEVER);
 out:
-       up(&file->f_sema);
+       mutex_unlock(&file->f_mutex);
        nlmsvc_release_block(newblock);
        nlmsvc_release_block(block);
        dprintk("lockd: nlmsvc_lock returned %u\n", ret);
@@ -427,13 +415,13 @@ out:
 /*
  * Test for presence of a conflicting lock.
  */
-u32
+__be32
 nlmsvc_testlock(struct nlm_file *file, struct nlm_lock *lock,
                                       struct nlm_lock *conflock)
 {
        dprintk("lockd: nlmsvc_testlock(%s/%ld, ty=%d, %Ld-%Ld)\n",
-                               file->f_file->f_dentry->d_inode->i_sb->s_id,
-                               file->f_file->f_dentry->d_inode->i_ino,
+                               file->f_file->f_path.dentry->d_inode->i_sb->s_id,
+                               file->f_file->f_path.dentry->d_inode->i_ino,
                                lock->fl.fl_type,
                                (long long)lock->fl.fl_start,
                                (long long)lock->fl.fl_end);
@@ -460,14 +448,14 @@ nlmsvc_testlock(struct nlm_file *file, struct nlm_lock *lock,
  * afterwards. In this case the block will still be there, and hence
  * must be removed.
  */
-u32
+__be32
 nlmsvc_unlock(struct nlm_file *file, struct nlm_lock *lock)
 {
        int     error;
 
        dprintk("lockd: nlmsvc_unlock(%s/%ld, pi=%d, %Ld-%Ld)\n",
-                               file->f_file->f_dentry->d_inode->i_sb->s_id,
-                               file->f_file->f_dentry->d_inode->i_ino,
+                               file->f_file->f_path.dentry->d_inode->i_sb->s_id,
+                               file->f_file->f_path.dentry->d_inode->i_ino,
                                lock->fl.fl_pid,
                                (long long)lock->fl.fl_start,
                                (long long)lock->fl.fl_end);
@@ -488,22 +476,22 @@ nlmsvc_unlock(struct nlm_file *file, struct nlm_lock *lock)
  * be in progress.
  * The calling procedure must check whether the file can be closed.
  */
-u32
+__be32
 nlmsvc_cancel_blocked(struct nlm_file *file, struct nlm_lock *lock)
 {
        struct nlm_block        *block;
        int status = 0;
 
        dprintk("lockd: nlmsvc_cancel(%s/%ld, pi=%d, %Ld-%Ld)\n",
-                               file->f_file->f_dentry->d_inode->i_sb->s_id,
-                               file->f_file->f_dentry->d_inode->i_ino,
+                               file->f_file->f_path.dentry->d_inode->i_sb->s_id,
+                               file->f_file->f_path.dentry->d_inode->i_ino,
                                lock->fl.fl_pid,
                                (long long)lock->fl.fl_start,
                                (long long)lock->fl.fl_end);
 
-       down(&file->f_sema);
+       mutex_lock(&file->f_mutex);
        block = nlmsvc_lookup_block(file, lock);
-       up(&file->f_sema);
+       mutex_unlock(&file->f_mutex);
        if (block != NULL) {
                status = nlmsvc_unlink_block(block);
                nlmsvc_release_block(block);
@@ -657,20 +645,17 @@ static const struct rpc_call_ops nlmsvc_grant_ops = {
  * block.
  */
 void
-nlmsvc_grant_reply(struct svc_rqst *rqstp, struct nlm_cookie *cookie, u32 status)
+nlmsvc_grant_reply(struct nlm_cookie *cookie, __be32 status)
 {
        struct nlm_block        *block;
-       struct nlm_file         *file;
 
-       dprintk("grant_reply: looking for cookie %x, host (%08x), s=%d \n", 
-               *(unsigned int *)(cookie->data), 
-               ntohl(rqstp->rq_addr.sin_addr.s_addr), status);
-       if (!(block = nlmsvc_find_block(cookie, &rqstp->rq_addr)))
+       dprintk("grant_reply: looking for cookie %x, s=%d \n",
+               *(unsigned int *)(cookie->data), status);
+       if (!(block = nlmsvc_find_block(cookie)))
                return;
-       file = block->b_file;
 
        if (block) {
-               if (status == NLM_LCK_DENIED_GRACE_PERIOD) {
+               if (status == nlm_lck_denied_grace_period) {
                        /* Try again in a couple of seconds */
                        nlmsvc_insert_block(block, 10 * HZ);
                } else {