* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2010, 2013, Intel Corporation.
+ * Copyright (c) 2010, 2014, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#ifndef _LUSTRE_DLM_H__
#define _LUSTRE_DLM_H__
-#if defined(__linux__)
-#include <linux/lustre_dlm.h>
-#elif defined(__APPLE__)
-#include <darwin/lustre_dlm.h>
-#elif defined(__WINNT__)
-#include <winnt/lustre_dlm.h>
-#else
-#error Unsupported operating system.
-#endif
-
#include <lustre_lib.h>
#include <lustre_net.h>
#include <lustre_import.h>
#define OBD_LDLM_DEVICENAME "ldlm"
#define LDLM_DEFAULT_LRU_SIZE (100 * num_online_cpus())
-#define LDLM_DEFAULT_MAX_ALIVE (cfs_time_seconds(36000))
+#define LDLM_DEFAULT_MAX_ALIVE (cfs_time_seconds(3900)) /* 65 min */
#define LDLM_CTIME_AGE_LIMIT (10)
#define LDLM_DEFAULT_PARALLEL_AST_LIMIT 1024
*/
typedef enum {
ELDLM_OK = 0,
+ ELDLM_LOCK_MATCHED = 1,
ELDLM_LOCK_CHANGED = 300,
ELDLM_LOCK_ABORTED = 301,
/** Recalculate pool \a pl usage */
int (*po_recalc)(struct ldlm_pool *pl);
/** Cancel at least \a nr locks from pool \a pl */
- int (*po_shrink)(struct ldlm_pool *pl, int nr,
- unsigned int gfp_mask);
+ int (*po_shrink)(struct ldlm_pool *pl, int nr, gfp_t gfp_mask);
int (*po_setup)(struct ldlm_pool *pl, int limit);
};
* Currently LVBs are used by:
* - OSC-OST code to maintain current object size/times
* - layout lock code to return the layout when the layout lock is granted
+ *
+ * To ensure delayed LVB initialization, it is highly recommended to use the set
+ * of ldlm_[res_]lvbo_[init,update,fill]() functions.
*/
struct ldlm_valblock_ops {
int (*lvbo_init)(struct ldlm_resource *res);
* Position in global namespace list linking all namespaces on
* the node.
*/
- cfs_list_t ns_list_chain;
+ struct list_head ns_list_chain;
/**
* List of unused locks for this namespace. This list is also called
* to release from the head of this list.
* Locks are linked via l_lru field in \see struct ldlm_lock.
*/
- cfs_list_t ns_unused_list;
+ struct list_head ns_unused_list;
/** Number of locks in the LRU list above */
int ns_nr_unused;
/** Work list for sending GL ASTs to multiple locks. */
struct ldlm_glimpse_work {
struct ldlm_lock *gl_lock; /* lock to glimpse */
- cfs_list_t gl_list; /* linkage to other gl work structs */
+ struct list_head gl_list; /* linkage to other gl work structs */
__u32 gl_flags;/* see LDLM_GL_WORK_* below */
union ldlm_gl_desc *gl_desc; /* glimpse descriptor to be packed in
* glimpse callback request */
/** Interval node data for each LDLM_EXTENT lock. */
struct ldlm_interval {
struct interval_node li_node; /* node for tree management */
- cfs_list_t li_group; /* the locks which have the same
+ struct list_head li_group; /* the locks which have the same
* policy - group of the policy */
};
#define to_ldlm_interval(n) container_of(n, struct ldlm_interval, li_node)
};
/**
+ * LDLM_GID_ANY is used to match any group id in ldlm_lock_match().
+ */
+#define LDLM_GID_ANY ((__u64)-1)
+
+/**
* LDLM lock structure
*
* Represents a single LDLM lock and its state in memory. Each lock is
* List item for client side LRU list.
* Protected by ns_lock in struct ldlm_namespace.
*/
- cfs_list_t l_lru;
+ struct list_head l_lru;
/**
* Linkage to resource's lock queues according to current lock state.
* (could be granted, waiting or converting)
* Protected by lr_lock in struct ldlm_resource.
*/
- cfs_list_t l_res_link;
+ struct list_head l_res_link;
/**
* Tree node for ldlm_extent.
*/
* Per export hash of locks.
* Protected by per-bucket exp->exp_lock_hash locks.
*/
- cfs_hlist_node_t l_exp_hash;
+ struct hlist_node l_exp_hash;
/**
* Per export hash of flock locks.
* Protected by per-bucket exp->exp_flock_hash locks.
*/
- cfs_hlist_node_t l_exp_flock_hash;
+ struct hlist_node l_exp_flock_hash;
/**
* Requested mode.
* Protected by lr_lock.
* expired_lock_thread.elt_expired_locks for further processing.
* Protected by elt_lock.
*/
- cfs_list_t l_pending_chain;
+ struct list_head l_pending_chain;
/**
* Set when lock is sent a blocking AST. Time in seconds when timeout
*/
int l_bl_ast_run;
/** List item ldlm_add_ast_work_item() for case of blocking ASTs. */
- cfs_list_t l_bl_ast;
+ struct list_head l_bl_ast;
/** List item ldlm_add_ast_work_item() for case of completion ASTs. */
- cfs_list_t l_cp_ast;
+ struct list_head l_cp_ast;
/** For ldlm_add_ast_work_item() for "revoke" AST used in COS. */
- cfs_list_t l_rk_ast;
+ struct list_head l_rk_ast;
/**
* Pointer to a conflicting lock that caused blocking AST to be sent
* Protected by lr_lock, linkages to "skip lists".
* For more explanations of skip lists see ldlm/ldlm_inodebits.c
*/
- cfs_list_t l_sl_mode;
- cfs_list_t l_sl_policy;
+ struct list_head l_sl_mode;
+ struct list_head l_sl_policy;
/** Reference tracking structure to debug leaked locks. */
struct lu_ref l_reference;
/** number of export references taken */
int l_exp_refs_nr;
/** link all locks referencing one export */
- cfs_list_t l_exp_refs_link;
+ struct list_head l_exp_refs_link;
/** referenced export object */
struct obd_export *l_exp_refs_target;
#endif
* Lock order of waiting_lists_spinlock, exp_bl_list_lock and res lock
* is: res lock -> exp_bl_list_lock -> wanting_lists_spinlock.
*/
- cfs_list_t l_exp_list;
+ struct list_head l_exp_list;
};
/**
* List item for list in namespace hash.
* protected by ns_lock
*/
- cfs_hlist_node_t lr_hash;
+ struct hlist_node lr_hash;
/** Spinlock to protect locks under this resource. */
spinlock_t lr_lock;
* protected by lr_lock
* @{ */
/** List of locks in granted state */
- cfs_list_t lr_granted;
+ struct list_head lr_granted;
/** List of locks waiting to change their granted mode (converted) */
- cfs_list_t lr_converting;
+ struct list_head lr_converting;
/**
* List of locks that could not be granted due to conflicts and
* that are waiting for conflicts to go away */
- cfs_list_t lr_waiting;
+ struct list_head lr_waiting;
/** @} */
/* XXX No longer needed? Remove ASAP */
*/
struct mutex lr_lvb_mutex;
int lr_lvb_len;
+ /** is lvb initialized ? */
+ bool lr_lvb_initialized;
/** protected by lr_lock */
void *lr_lvb_data;
static inline int ldlm_lvbo_init(struct ldlm_resource *res)
{
struct ldlm_namespace *ns = ldlm_res_to_ns(res);
+ int rc = 0;
- if (ns->ns_lvbo != NULL && ns->ns_lvbo->lvbo_init != NULL)
- return ns->ns_lvbo->lvbo_init(res);
+ if (ns->ns_lvbo == NULL || ns->ns_lvbo->lvbo_init == NULL ||
+ res->lr_lvb_initialized)
+ return 0;
- return 0;
+ mutex_lock(&res->lr_lvb_mutex);
+ /* Did we lose the race? */
+ if (res->lr_lvb_initialized) {
+ mutex_unlock(&res->lr_lvb_mutex);
+ return 0;
+ }
+ rc = ns->ns_lvbo->lvbo_init(res);
+ if (rc < 0) {
+ CDEBUG(D_DLMTRACE, "lvbo_init failed for resource : rc = %d\n",
+ rc);
+ if (res->lr_lvb_data != NULL) {
+ OBD_FREE(res->lr_lvb_data, res->lr_lvb_len);
+ res->lr_lvb_data = NULL;
+ }
+ res->lr_lvb_len = rc;
+ } else {
+ res->lr_lvb_initialized = true;
+ }
+ mutex_unlock(&res->lr_lvb_mutex);
+ return rc;
}
static inline int ldlm_lvbo_size(struct ldlm_lock *lock)
static inline int ldlm_lvbo_fill(struct ldlm_lock *lock, void *buf, int len)
{
struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
+ int rc;
if (ns->ns_lvbo != NULL) {
LASSERT(ns->ns_lvbo->lvbo_fill != NULL);
+ /* init lvb now if not already */
+ rc = ldlm_lvbo_init(lock->l_resource);
+ if (rc < 0) {
+ CERROR("lock %p: delayed lvb init failed (rc %d)",
+ lock, rc);
+ return rc;
+ }
return ns->ns_lvbo->lvbo_fill(lock, buf, len);
}
return 0;
}
struct ldlm_ast_work {
- struct ldlm_lock *w_lock;
- int w_blocking;
- struct ldlm_lock_desc w_desc;
- cfs_list_t w_list;
- int w_flags;
- void *w_data;
- int w_datalen;
+ struct ldlm_lock *w_lock;
+ int w_blocking;
+ struct ldlm_lock_desc w_desc;
+ struct list_head w_list;
+ int w_flags;
+ void *w_data;
+ int w_datalen;
};
/**
#endif
typedef int (*ldlm_processing_policy)(struct ldlm_lock *lock, __u64 *flags,
- int first_enq, ldlm_error_t *err,
- cfs_list_t *work_list);
+ int first_enq, ldlm_error_t *err,
+ struct list_head *work_list);
/**
* Return values for lock iterators.
void *data, int flag);
int ldlm_server_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data);
int ldlm_server_glimpse_ast(struct ldlm_lock *lock, void *data);
-int ldlm_glimpse_locks(struct ldlm_resource *res, cfs_list_t *gl_work_list);
+int ldlm_glimpse_locks(struct ldlm_resource *res,
+ struct list_head *gl_work_list);
/** @} ldlm_srv_ast */
/** \defgroup ldlm_handlers Server LDLM handlers
const struct ldlm_request *dlm_req);
int ldlm_handle_cancel(struct ptlrpc_request *req);
int ldlm_request_cancel(struct ptlrpc_request *req,
- const struct ldlm_request *dlm_req, int first);
+ const struct ldlm_request *dlm_req,
+ int first, enum lustre_at_flags flags);
/** @} ldlm_handlers */
void ldlm_revoke_export_locks(struct obd_export *exp);
+unsigned int ldlm_bl_timeout(struct ldlm_lock *lock);
#endif
int ldlm_del_waiting_lock(struct ldlm_lock *lock);
int ldlm_refresh_waiting_lock(struct ldlm_lock *lock, int timeout);
/**
* Update Lock Value Block Operations (LVBO) on a resource taking into account
- * data from reqest \a r
+ * data from request \a r
*/
static inline int ldlm_res_lvbo_update(struct ldlm_resource *res,
struct ptlrpc_request *r, int increase)
{
+ int rc;
+
+ /* delayed lvb init may be required */
+ rc = ldlm_lvbo_init(res);
+ if (rc < 0) {
+ CERROR("delayed lvb init failed (rc %d)\n", rc);
+ return rc;
+ }
+
if (ldlm_res_to_ns(res)->ns_lvbo &&
ldlm_res_to_ns(res)->ns_lvbo->lvbo_update) {
return ldlm_res_to_ns(res)->ns_lvbo->lvbo_update(res, r,
lock; \
})
-#define ldlm_lock_list_put(head, member, count) \
-({ \
- struct ldlm_lock *_lock, *_next; \
- int c = count; \
- cfs_list_for_each_entry_safe(_lock, _next, head, member) { \
- if (c-- == 0) \
- break; \
- cfs_list_del_init(&_lock->member); \
- LDLM_LOCK_RELEASE(_lock); \
- } \
- LASSERT(c <= 0); \
+#define ldlm_lock_list_put(head, member, count) \
+({ \
+ struct ldlm_lock *_lock, *_next; \
+ int c = count; \
+ list_for_each_entry_safe(_lock, _next, head, member) { \
+ if (c-- == 0) \
+ break; \
+ list_del_init(&_lock->member); \
+ LDLM_LOCK_RELEASE(_lock); \
+ } \
+ LASSERT(c <= 0); \
})
struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock);
void ldlm_namespace_get(struct ldlm_namespace *ns);
void ldlm_namespace_put(struct ldlm_namespace *ns);
int ldlm_proc_setup(void);
-#ifdef LPROCFS
+#ifdef CONFIG_PROC_FS
void ldlm_proc_cleanup(void);
#else
static inline void ldlm_proc_cleanup(void) {}
struct ldlm_resource *ldlm_resource_getref(struct ldlm_resource *res);
int ldlm_resource_putref(struct ldlm_resource *res);
void ldlm_resource_add_lock(struct ldlm_resource *res,
- cfs_list_t *head,
- struct ldlm_lock *lock);
+ struct list_head *head,
+ struct ldlm_lock *lock);
void ldlm_resource_unlink_lock(struct ldlm_lock *lock);
void ldlm_res2desc(struct ldlm_resource *res, struct ldlm_resource_desc *desc);
void ldlm_dump_all_namespaces(ldlm_side_t client, int level);
void *lvb, __u32 lvb_len, enum lvb_type lvb_type,
struct lustre_handle *lockh, int async);
int ldlm_prep_enqueue_req(struct obd_export *exp,
- struct ptlrpc_request *req,
- cfs_list_t *cancels,
- int count);
-int ldlm_prep_elc_req(struct obd_export *exp,
- struct ptlrpc_request *req,
- int version, int opc, int canceloff,
- cfs_list_t *cancels, int count);
+ struct ptlrpc_request *req,
+ struct list_head *cancels,
+ int count);
+int ldlm_prep_elc_req(struct obd_export *exp, struct ptlrpc_request *req,
+ int version, int opc, int canceloff,
+ struct list_head *cancels, int count);
struct ptlrpc_request *ldlm_enqueue_pack(struct obd_export *exp, int lvb_len);
int ldlm_handle_enqueue0(struct ldlm_namespace *ns, struct ptlrpc_request *req,
ldlm_mode_t mode,
ldlm_cancel_flags_t flags,
void *opaque);
-int ldlm_cli_cancel_req(struct obd_export *exp, cfs_list_t *head,
- int count, ldlm_cancel_flags_t flags);
+int ldlm_cli_cancel_req(struct obd_export *exp, struct list_head *head,
+ int count, ldlm_cancel_flags_t flags);
int ldlm_cancel_resource_local(struct ldlm_resource *res,
- cfs_list_t *cancels,
+ struct list_head *cancels,
ldlm_policy_data_t *policy,
ldlm_mode_t mode, __u64 lock_flags,
ldlm_cancel_flags_t cancel_flags, void *opaque);
-int ldlm_cli_cancel_list_local(cfs_list_t *cancels, int count,
+int ldlm_cli_cancel_list_local(struct list_head *cancels, int count,
ldlm_cancel_flags_t flags);
-int ldlm_cli_cancel_list(cfs_list_t *head, int count,
+int ldlm_cli_cancel_list(struct list_head *head, int count,
struct ptlrpc_request *req, ldlm_cancel_flags_t flags);
/** @} ldlm_cli_api */
int ldlm_pool_init(struct ldlm_pool *pl, struct ldlm_namespace *ns,
int idx, ldlm_side_t client);
-int ldlm_pool_shrink(struct ldlm_pool *pl, int nr,
- unsigned int gfp_mask);
+int ldlm_pool_shrink(struct ldlm_pool *pl, int nr, gfp_t gfp_mask);
void ldlm_pool_fini(struct ldlm_pool *pl);
int ldlm_pool_setup(struct ldlm_pool *pl, int limit);
int ldlm_pool_recalc(struct ldlm_pool *pl);