Whamcloud - gitweb
- make HEAD from b_post_cmd3
[fs/lustre-release.git] / lustre / mdd / mdd_lock.c
1 /* -*- MODE: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  mdd/mdd_handler.c
5  *  Lustre Metadata Server (mdd) routines
6  *
7  *  Copyright (C) 2006 Cluster File Systems, Inc.
8  *   Author: Mike Pershin <tappro@clusterfs.com>
9  *
10  *   This file is part of the Lustre file system, http://www.lustre.org
11  *   Lustre is a trademark of Cluster File Systems, Inc.
12  *
13  *   You may have signed or agreed to another license before downloading
14  *   this software.  If so, you are bound by the terms and conditions
15  *   of that agreement, and the following does not apply to you.  See the
16  *   LICENSE file included with this distribution for more information.
17  *
18  *   If you did not agree to a different license, then this copy of Lustre
19  *   is open source software; you can redistribute it and/or modify it
20  *   under the terms of version 2 of the GNU General Public License as
21  *   published by the Free Software Foundation.
22  *
23  *   In either case, Lustre is distributed in the hope that it will be
24  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
25  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  *   license text for more details.
27  */
28 #ifndef EXPORT_SYMTAB
29 # define EXPORT_SYMTAB
30 #endif
31 #define DEBUG_SUBSYSTEM S_MDS
32
33 #include <linux/module.h>
34 #include <lustre_ver.h>
35 #include "mdd_internal.h"
36
37 void mdd_write_lock(const struct lu_env *env, struct mdd_object *obj)
38 {
39         struct dt_object  *next = mdd_object_child(obj);
40
41         next->do_ops->do_write_lock(env, next);
42 }
43
44 void mdd_read_lock(const struct lu_env *env, struct mdd_object *obj)
45 {
46         struct dt_object  *next = mdd_object_child(obj);
47         next->do_ops->do_read_lock(env, next);
48 }
49
50 void mdd_write_unlock(const struct lu_env *env, struct mdd_object *obj)
51 {
52         struct dt_object  *next = mdd_object_child(obj);
53
54         next->do_ops->do_write_unlock(env, next);
55 }
56
57 void mdd_read_unlock(const struct lu_env *env, struct mdd_object *obj)
58 {
59         struct dt_object  *next = mdd_object_child(obj);
60
61         next->do_ops->do_read_unlock(env, next);
62 }
63
64
65 /* Methods for parallel directory locking */
66
67 void mdd_pdlock_init(struct mdd_object *obj)
68 {
69         dynlock_init(&obj->mod_pdlock);
70
71 }
72
73 unsigned long mdd_name2hash(const char *name)
74 {
75         return full_name_hash((unsigned char*)name, strlen(name));
76 }
77
78 struct dynlock_handle *mdd_pdo_write_lock(const struct lu_env *env,
79                                           struct mdd_object *obj,
80                                           const char *name)
81 {
82         unsigned long value = mdd_name2hash(name);
83         return dynlock_lock(&obj->mod_pdlock, value, DLT_WRITE, GFP_NOFS);
84 }
85
86 struct dynlock_handle *mdd_pdo_read_lock(const struct lu_env *env,
87                                          struct mdd_object *obj,
88                                          const char *name)
89 {
90         unsigned long value = mdd_name2hash(name);
91         return dynlock_lock(&obj->mod_pdlock, value, DLT_READ, GFP_NOFS);
92 }
93
94 void mdd_pdo_write_unlock(const struct lu_env *env, struct mdd_object *obj,
95                           struct dynlock_handle *dlh)
96 {
97         return dynlock_unlock(&obj->mod_pdlock, dlh);
98 }
99
100 void mdd_pdo_read_unlock(const struct lu_env *env, struct mdd_object *obj,
101                          struct dynlock_handle *dlh)
102 {
103         return dynlock_unlock(&obj->mod_pdlock, dlh);
104 }
105