Whamcloud - gitweb
land b1_5 onto HEAD
[fs/lustre-release.git] / lustre / ldlm / l_lock.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of the Lustre file system, http://www.lustre.org
7  *   Lustre is a trademark of Cluster File Systems, Inc.
8  *
9  *   You may have signed or agreed to another license before downloading
10  *   this software.  If so, you are bound by the terms and conditions
11  *   of that agreement, and the following does not apply to you.  See the
12  *   LICENSE file included with this distribution for more information.
13  *
14  *   If you did not agree to a different license, then this copy of Lustre
15  *   is open source software; you can redistribute it and/or modify it
16  *   under the terms of version 2 of the GNU General Public License as
17  *   published by the Free Software Foundation.
18  *
19  *   In either case, Lustre is distributed in the hope that it will be
20  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *   license text for more details.
23  *
24  */
25
26 #define DEBUG_SUBSYSTEM S_LDLM
27 #ifdef __KERNEL__
28 #include <libcfs/libcfs.h>
29 #else 
30 #include <liblustre.h>
31 #endif
32
33 #include <lustre_dlm.h>
34 #include <lustre_lib.h>
35
36 /*
37  * ldlm locking uses resource to serialize access to locks
38  * but there is a case when we change resource of lock upon
39  * enqueue reply. we rely on that lock->l_resource = new_res
40  * is atomic
41  */
42 struct ldlm_resource * lock_res_and_lock(struct ldlm_lock *lock)
43 {
44         struct ldlm_resource *res = lock->l_resource;
45
46         if (!res->lr_namespace->ns_client) {
47                 /* on server-side resource of lock doesn't change */
48                 lock_res(res);
49                 return res;
50         } 
51
52         lock_bitlock(lock);
53         res = lock->l_resource;
54         lock_res(res);
55         return res;
56 }
57
58 void unlock_res_and_lock(struct ldlm_lock *lock)
59 {
60         struct ldlm_resource *res = lock->l_resource;
61
62         if (!res->lr_namespace->ns_client) {
63                 /* on server-side resource of lock doesn't change */
64                 unlock_res(res);
65                 return;
66         }
67
68         unlock_res(res);
69         unlock_bitlock(lock);
70 }
71