#ifndef _LUSTRE_DLM_H__
#define _LUSTRE_DLM_H__
-#if defined(__linux__)
-#include <linux/lustre_dlm.h>
-#elif defined(__APPLE__)
-#include <darwin/lustre_dlm.h>
-#else
-#error Unsupported operating system.
-#endif
-
#include <lustre_lib.h>
#include <lustre_net.h>
#include <lustre_import.h>
*/
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);
};
/**
+ * 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
*/
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;
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);
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,
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);