-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
* GPL HEADER START
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
/*
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2012, Whamcloud, Inc.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
cfs_atomic_t ldlm_srv_namespace_nr = CFS_ATOMIC_INIT(0);
cfs_atomic_t ldlm_cli_namespace_nr = CFS_ATOMIC_INIT(0);
-cfs_semaphore_t ldlm_srv_namespace_lock;
+cfs_mutex_t ldlm_srv_namespace_lock;
CFS_LIST_HEAD(ldlm_srv_namespace_list);
-cfs_semaphore_t ldlm_cli_namespace_lock;
+cfs_mutex_t ldlm_cli_namespace_lock;
CFS_LIST_HEAD(ldlm_cli_namespace_list);
cfs_proc_dir_entry_t *ldlm_type_proc_dir = NULL;
extern unsigned int ldlm_cancel_unused_locks_before_replay;
+/* during debug dump certain amount of granted locks for one resource to avoid
+ * DDOS. */
+unsigned int ldlm_dump_granted_max = 256;
+
#ifdef LPROCFS
static int ldlm_proc_dump_ns(struct file *file, const char *buffer,
unsigned long count, void *data)
int rc;
struct lprocfs_vars list[] = {
{ "dump_namespaces", NULL, ldlm_proc_dump_ns, NULL },
+ { "dump_granted_max",
+ lprocfs_rd_uint, lprocfs_wr_uint,
+ &ldlm_dump_granted_max, NULL },
{ "cancel_unused_locks_before_replay",
lprocfs_rd_uint, lprocfs_wr_uint,
&ldlm_cancel_unused_locks_before_replay, NULL },
lock_vars[0].read_fptr = lprocfs_rd_uint;
lock_vars[0].write_fptr = lprocfs_wr_uint;
lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
+
+ snprintf(lock_name, MAX_STRING_SIZE, "%s/max_parallel_ast",
+ ldlm_ns_name(ns));
+ lock_vars[0].data = &ns->ns_max_parallel_ast;
+ lock_vars[0].read_fptr = lprocfs_rd_uint;
+ lock_vars[0].write_fptr = lprocfs_wr_uint;
+ lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
}
return 0;
}
#endif /* LPROCFS */
-static unsigned ldlm_res_hop_hash(cfs_hash_t *hs, void *key, unsigned mask)
+static unsigned ldlm_res_hop_hash(cfs_hash_t *hs,
+ const void *key, unsigned mask)
{
- struct ldlm_res_id *id = key;
+ const struct ldlm_res_id *id = key;
unsigned val = 0;
unsigned i;
return val & mask;
}
-static unsigned ldlm_res_hop_fid_hash(cfs_hash_t *hs, void *key, unsigned mask)
+static unsigned ldlm_res_hop_fid_hash(cfs_hash_t *hs,
+ const void *key, unsigned mask)
{
- struct ldlm_res_id *id = key;
+ const struct ldlm_res_id *id = key;
struct lu_fid fid;
- __u64 hash;
+ __u32 hash;
+ __u32 val;
fid.f_seq = id->name[LUSTRE_RES_ID_SEQ_OFF];
- fid.f_oid = (__u32)id->name[LUSTRE_RES_ID_OID_OFF];
- fid.f_ver = (__u32)id->name[LUSTRE_RES_ID_VER_OFF];
-
- hash = fid_flatten(&fid);
+ fid.f_oid = (__u32)id->name[LUSTRE_RES_ID_VER_OID_OFF];
+ fid.f_ver = (__u32)(id->name[LUSTRE_RES_ID_VER_OID_OFF] >> 32);
+
+ hash = fid_flatten32(&fid);
+ hash += (hash >> 4) + (hash << 12); /* mixing oid and seq */
+ if (id->name[LUSTRE_RES_ID_HSH_OFF] != 0) {
+ val = id->name[LUSTRE_RES_ID_HSH_OFF];
+ hash += (val >> 5) + (val << 11);
+ } else {
+ val = fid_oid(&fid);
+ }
hash = cfs_hash_long(hash, hs->hs_bkt_bits);
- /* ignore a few low bits */
- if (id->name[LUSTRE_RES_ID_HSH_OFF] != 0)
- hash += id->name[LUSTRE_RES_ID_HSH_OFF] >> 5;
- else
- hash = hash >> 5;
+ /* give me another random factor */
+ hash -= cfs_hash_long((unsigned long)hs, val % 11 + 3);
+
hash <<= hs->hs_cur_bits - hs->hs_bkt_bits;
hash |= ldlm_res_hop_hash(hs, key, CFS_HASH_NBKT(hs) - 1);
return &res->lr_name;
}
-static int ldlm_res_eq(const struct ldlm_res_id *res0,
- const struct ldlm_res_id *res1)
-{
- return !memcmp(res0, res1, sizeof(*res0));
-}
-
-static int ldlm_res_hop_keycmp(void *key, cfs_hlist_node_t *hnode)
+static int ldlm_res_hop_keycmp(const void *key, cfs_hlist_node_t *hnode)
{
struct ldlm_resource *res;
res = cfs_hlist_entry(hnode, struct ldlm_resource, lr_hash);
ldlm_resource_getref(res);
- LDLM_RESOURCE_ADDREF(res);
}
static void ldlm_res_hop_put_locked(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
res = cfs_hlist_entry(hnode, struct ldlm_resource, lr_hash);
/* cfs_hash_for_each_nolock is the only chance we call it */
- LDLM_RESOURCE_DELREF(res);
ldlm_resource_putref_locked(res);
}
struct ldlm_resource *res;
res = cfs_hlist_entry(hnode, struct ldlm_resource, lr_hash);
- LDLM_RESOURCE_DELREF(res);
ldlm_resource_putref(res);
}
{
.nsd_type = LDLM_NS_TYPE_MDC,
.nsd_bkt_bits = 11,
- .nsd_all_bits = 15,
+ .nsd_all_bits = 16,
.nsd_hops = &ldlm_ns_fid_hash_ops,
},
{
ns->ns_contention_time = NS_DEFAULT_CONTENTION_SECONDS;
ns->ns_contended_locks = NS_DEFAULT_CONTENDED_LOCKS;
+ ns->ns_max_parallel_ast = LDLM_DEFAULT_PARALLEL_AST_LIMIT;
ns->ns_nr_unused = 0;
ns->ns_max_unused = LDLM_DEFAULT_LRU_SIZE;
ns->ns_max_age = LDLM_DEFAULT_MAX_ALIVE;
ns->ns_timeouts = 0;
ns->ns_orig_connect_flags = 0;
ns->ns_connect_flags = 0;
+ ns->ns_stopping = 0;
rc = ldlm_namespace_proc_register(ns);
if (rc != 0) {
CERROR("Can't initialize ns proc, rc %d\n", rc);
ldlm_put_ref();
RETURN(NULL);
}
+EXPORT_SYMBOL(ldlm_namespace_new);
extern struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock);
cfs_hash_for_each_nolock(ns->ns_rs_hash, ldlm_resource_complain, NULL);
return ELDLM_OK;
}
+EXPORT_SYMBOL(ldlm_namespace_cleanup);
static int __ldlm_namespace_free(struct ldlm_namespace *ns, int force)
{
return;
}
+ cfs_spin_lock(&ns->ns_lock);
+ ns->ns_stopping = 1;
+ cfs_spin_unlock(&ns->ns_lock);
/*
* Can fail with -EINTR when force == 0 in which case try harder.
ldlm_namespace_free_prior(ns, imp, force);
ldlm_namespace_free_post(ns);
}
+EXPORT_SYMBOL(ldlm_namespace_free);
void ldlm_namespace_get(struct ldlm_namespace *ns)
{
cfs_atomic_inc(&ns->ns_bref);
}
+EXPORT_SYMBOL(ldlm_namespace_get);
void ldlm_namespace_put(struct ldlm_namespace *ns)
{
cfs_spin_unlock(&ns->ns_lock);
}
}
+EXPORT_SYMBOL(ldlm_namespace_put);
/* Register @ns in the list of namespaces */
void ldlm_namespace_register(struct ldlm_namespace *ns, ldlm_side_t client)
{
- cfs_mutex_down(ldlm_namespace_lock(client));
+ cfs_mutex_lock(ldlm_namespace_lock(client));
LASSERT(cfs_list_empty(&ns->ns_list_chain));
cfs_list_add(&ns->ns_list_chain, ldlm_namespace_list(client));
cfs_atomic_inc(ldlm_namespace_nr(client));
- cfs_mutex_up(ldlm_namespace_lock(client));
+ cfs_mutex_unlock(ldlm_namespace_lock(client));
}
/* Unregister @ns from the list of namespaces */
void ldlm_namespace_unregister(struct ldlm_namespace *ns, ldlm_side_t client)
{
- cfs_mutex_down(ldlm_namespace_lock(client));
+ cfs_mutex_lock(ldlm_namespace_lock(client));
LASSERT(!cfs_list_empty(&ns->ns_list_chain));
/*
* Some asserts and possibly other parts of code still using
*/
cfs_list_del_init(&ns->ns_list_chain);
cfs_atomic_dec(ldlm_namespace_nr(client));
- cfs_mutex_up(ldlm_namespace_lock(client));
+ cfs_mutex_unlock(ldlm_namespace_lock(client));
}
/* Should be called under ldlm_namespace_lock(client) taken */
void ldlm_namespace_move_locked(struct ldlm_namespace *ns, ldlm_side_t client)
{
LASSERT(!cfs_list_empty(&ns->ns_list_chain));
- LASSERT_SEM_LOCKED(ldlm_namespace_lock(client));
+ LASSERT_MUTEX_LOCKED(ldlm_namespace_lock(client));
cfs_list_move_tail(&ns->ns_list_chain, ldlm_namespace_list(client));
}
/* Should be called under ldlm_namespace_lock(client) taken */
struct ldlm_namespace *ldlm_namespace_first_locked(ldlm_side_t client)
{
- LASSERT_SEM_LOCKED(ldlm_namespace_lock(client));
+ LASSERT_MUTEX_LOCKED(ldlm_namespace_lock(client));
LASSERT(!cfs_list_empty(ldlm_namespace_list(client)));
return container_of(ldlm_namespace_list(client)->next,
struct ldlm_namespace, ns_list_chain);
lu_ref_init(&res->lr_reference);
/* one who creates the resource must unlock
- * the semaphore after lvb initialization */
- cfs_init_mutex_locked(&res->lr_lvb_sem);
+ * the mutex after lvb initialization */
+ cfs_mutex_init(&res->lr_lvb_mutex);
+ cfs_mutex_lock(&res->lr_lvb_mutex);
return res;
}
res = cfs_hlist_entry(hnode, struct ldlm_resource, lr_hash);
/* synchronize WRT resource creation */
if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
- cfs_down(&res->lr_lvb_sem);
- cfs_up(&res->lr_lvb_sem);
+ cfs_mutex_lock(&res->lr_lvb_mutex);
+ cfs_mutex_unlock(&res->lr_lvb_mutex);
}
return res;
}
res = cfs_hlist_entry(hnode, struct ldlm_resource, lr_hash);
/* synchronize WRT resource creation */
if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
- cfs_down(&res->lr_lvb_sem);
- cfs_up(&res->lr_lvb_sem);
+ cfs_mutex_lock(&res->lr_lvb_mutex);
+ cfs_mutex_unlock(&res->lr_lvb_mutex);
}
return res;
}
if (rc)
CERROR("lvbo_init failed for resource "
LPU64": rc %d\n", name->name[0], rc);
- /* we create resource with locked lr_lvb_sem */
- cfs_up(&res->lr_lvb_sem);
+ /* we create resource with locked lr_lvb_mutex */
+ cfs_mutex_unlock(&res->lr_lvb_mutex);
}
return res;
}
+EXPORT_SYMBOL(ldlm_resource_get);
struct ldlm_resource *ldlm_resource_getref(struct ldlm_resource *res)
{
}
return 0;
}
+EXPORT_SYMBOL(ldlm_resource_putref);
/* Returns 1 if the resource was freed, 0 if it remains. */
int ldlm_resource_putref_locked(struct ldlm_resource *res)
{
check_res_locked(res);
- ldlm_resource_dump(D_INFO, res);
- CDEBUG(D_OTHER, "About to add this lock:\n");
- ldlm_lock_dump(D_OTHER, lock, 0);
+ LDLM_DEBUG(lock, "About to add this lock:\n");
if (lock->l_destroyed) {
CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
check_res_locked(res);
ldlm_resource_dump(D_INFO, res);
- CDEBUG(D_OTHER, "About to insert this lock after %p:\n", original);
- ldlm_lock_dump(D_OTHER, new, 0);
+ LDLM_DEBUG(new, "About to insert this lock after %p:\n", original);
if (new->l_destroyed) {
CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
ldlm_extent_unlink_lock(lock);
cfs_list_del_init(&lock->l_res_link);
}
+EXPORT_SYMBOL(ldlm_resource_unlink_lock);
void ldlm_res2desc(struct ldlm_resource *res, struct ldlm_resource_desc *desc)
{
if (!((libcfs_debug | D_ERROR) & level))
return;
- cfs_mutex_down(ldlm_namespace_lock(client));
+ cfs_mutex_lock(ldlm_namespace_lock(client));
cfs_list_for_each(tmp, ldlm_namespace_list(client)) {
struct ldlm_namespace *ns;
ldlm_namespace_dump(level, ns);
}
- cfs_mutex_up(ldlm_namespace_lock(client));
+ cfs_mutex_unlock(ldlm_namespace_lock(client));
}
+EXPORT_SYMBOL(ldlm_dump_all_namespaces);
static int ldlm_res_hash_dump(cfs_hash_t *hs, cfs_hash_bd_t *bd,
cfs_hlist_node_t *hnode, void *arg)
ns->ns_next_dump = cfs_time_shift(10);
cfs_spin_unlock(&ns->ns_lock);
}
+EXPORT_SYMBOL(ldlm_namespace_dump);
void ldlm_resource_dump(int level, struct ldlm_resource *res)
{
- cfs_list_t *tmp;
- int pos;
+ struct ldlm_lock *lock;
+ unsigned int granted = 0;
CLASSERT(RES_NAME_SIZE == 4);
cfs_atomic_read(&res->lr_refcount));
if (!cfs_list_empty(&res->lr_granted)) {
- pos = 0;
- CDEBUG(level, "Granted locks:\n");
- cfs_list_for_each(tmp, &res->lr_granted) {
- struct ldlm_lock *lock;
- lock = cfs_list_entry(tmp, struct ldlm_lock,
- l_res_link);
- ldlm_lock_dump(level, lock, ++pos);
+ CDEBUG(level, "Granted locks (in reverse order):\n");
+ cfs_list_for_each_entry_reverse(lock, &res->lr_granted,
+ l_res_link) {
+ LDLM_DEBUG_LIMIT(level, lock, "###");
+ if (!(level & D_CANTMASK) &&
+ ++granted > ldlm_dump_granted_max) {
+ CDEBUG(level, "only dump %d granted locks to "
+ "avoid DDOS.\n", granted);
+ break;
+ }
}
}
if (!cfs_list_empty(&res->lr_converting)) {
- pos = 0;
CDEBUG(level, "Converting locks:\n");
- cfs_list_for_each(tmp, &res->lr_converting) {
- struct ldlm_lock *lock;
- lock = cfs_list_entry(tmp, struct ldlm_lock,
- l_res_link);
- ldlm_lock_dump(level, lock, ++pos);
- }
+ cfs_list_for_each_entry(lock, &res->lr_converting, l_res_link)
+ LDLM_DEBUG_LIMIT(level, lock, "###");
}
if (!cfs_list_empty(&res->lr_waiting)) {
- pos = 0;
CDEBUG(level, "Waiting locks:\n");
- cfs_list_for_each(tmp, &res->lr_waiting) {
- struct ldlm_lock *lock;
- lock = cfs_list_entry(tmp, struct ldlm_lock,
- l_res_link);
- ldlm_lock_dump(level, lock, ++pos);
- }
+ cfs_list_for_each_entry(lock, &res->lr_waiting, l_res_link)
+ LDLM_DEBUG_LIMIT(level, lock, "###");
}
}