1 /* -*- MODE: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Lustre Metadata Server (mdd) routines
7 * Copyright (C) 2006 Cluster File Systems, Inc.
8 * Author: Mike Pershin <tappro@clusterfs.com>
10 * This file is part of the Lustre file system, http://www.lustre.org
11 * Lustre is a trademark of Cluster File Systems, Inc.
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.
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.
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.
29 # define EXPORT_SYMTAB
31 #define DEBUG_SUBSYSTEM S_MDS
33 #include <linux/module.h>
34 #include <lustre_ver.h>
35 #include "mdd_internal.h"
37 void mdd_write_lock(const struct lu_env *env, struct mdd_object *obj)
39 struct dt_object *next = mdd_object_child(obj);
41 next->do_ops->do_write_lock(env, next);
44 void mdd_read_lock(const struct lu_env *env, struct mdd_object *obj)
46 struct dt_object *next = mdd_object_child(obj);
48 next->do_ops->do_read_lock(env, next);
51 void mdd_write_unlock(const struct lu_env *env, struct mdd_object *obj)
53 struct dt_object *next = mdd_object_child(obj);
55 next->do_ops->do_write_unlock(env, next);
58 void mdd_read_unlock(const struct lu_env *env, struct mdd_object *obj)
60 struct dt_object *next = mdd_object_child(obj);
62 next->do_ops->do_read_unlock(env, next);
66 /* Methods for parallel directory locking */
68 void mdd_pdlock_init(struct mdd_object *obj)
70 dynlock_init(&obj->mod_pdlock);
74 unsigned long mdd_name2hash(const char *name)
76 unsigned long value = 0;
77 int namelen = strlen(name);
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 */
82 value += name[i] * (i << 7);
88 struct dynlock_handle *mdd_pdo_write_lock(const struct lu_env *env,
89 struct mdd_object *obj,
92 unsigned long value = mdd_name2hash(name);
93 return dynlock_lock(&obj->mod_pdlock, value, DLT_WRITE, GFP_NOFS);
96 struct dynlock_handle *mdd_pdo_read_lock(const struct lu_env *env,
97 struct mdd_object *obj,
100 unsigned long value = mdd_name2hash(name);
101 return dynlock_lock(&obj->mod_pdlock, value, DLT_READ, GFP_NOFS);
104 void mdd_pdo_write_unlock(const struct lu_env *env, struct mdd_object *obj,
105 struct dynlock_handle *dlh)
107 return dynlock_unlock(&obj->mod_pdlock, dlh);
110 void mdd_pdo_read_unlock(const struct lu_env *env, struct mdd_object *obj,
111 struct dynlock_handle *dlh)
113 return dynlock_unlock(&obj->mod_pdlock, dlh);