Whamcloud - gitweb
- error handling for dynlocks
[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
48         next->do_ops->do_read_lock(env, next);
49 }
50
51 void mdd_write_unlock(const struct lu_env *env, struct mdd_object *obj)
52 {
53         struct dt_object  *next = mdd_object_child(obj);
54
55         next->do_ops->do_write_unlock(env, next);
56 }
57
58 void mdd_read_unlock(const struct lu_env *env, struct mdd_object *obj)
59 {
60         struct dt_object  *next = mdd_object_child(obj);
61
62         next->do_ops->do_read_unlock(env, next);
63 }
64
65
66 /* Methods for parallel directory locking */
67
68 void mdd_pdlock_init(struct mdd_object *obj)
69 {
70         dynlock_init(&obj->mod_pdlock);
71
72 }
73
74 unsigned long mdd_name2hash(const char *name)
75 {
76         unsigned long value = 0;
77         int namelen = strlen(name);
78         int i = 0;
79         /*XXX the hash should be simple, fast but differ from split one
80          * Current one is just fast solution to see how dynlocks will help */
81         while (namelen > i) {
82                 value += name[i] * (i << 7);
83                 i++;
84         }
85         return value;
86 }
87
88 struct dynlock_handle *mdd_pdo_write_lock(const struct lu_env *env,
89                                           struct mdd_object *obj,
90                                           const char *name)
91 {
92         unsigned long value = mdd_name2hash(name);
93         return dynlock_lock(&obj->mod_pdlock, value, DLT_WRITE, GFP_NOFS);
94 }
95
96 struct dynlock_handle *mdd_pdo_read_lock(const struct lu_env *env,
97                                          struct mdd_object *obj,
98                                          const char *name)
99 {
100         unsigned long value = mdd_name2hash(name);
101         return dynlock_lock(&obj->mod_pdlock, value, DLT_READ, GFP_NOFS);
102 }
103
104 void mdd_pdo_write_unlock(const struct lu_env *env, struct mdd_object *obj,
105                           struct dynlock_handle *dlh)
106 {
107         return dynlock_unlock(&obj->mod_pdlock, dlh);
108 }
109
110 void mdd_pdo_read_unlock(const struct lu_env *env, struct mdd_object *obj,
111                          struct dynlock_handle *dlh)
112 {
113         return dynlock_unlock(&obj->mod_pdlock, dlh);
114 }
115