Whamcloud - gitweb
LU-5710 all: second batch of corrected typos and grammar errors
[fs/lustre-release.git] / lustre / include / lustre_dlm.h
index 0c669cc..1935e2f 100644 (file)
@@ -27,7 +27,7 @@
  * 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>
@@ -82,6 +72,7 @@ struct obd_device;
  */
 typedef enum {
         ELDLM_OK = 0,
+       ELDLM_LOCK_MATCHED = 1,
 
         ELDLM_LOCK_CHANGED = 300,
         ELDLM_LOCK_ABORTED = 301,
@@ -219,8 +210,7 @@ struct ldlm_pool_ops {
        /** 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);
 };
 
@@ -290,6 +280,9 @@ typedef int (*ldlm_cancel_cbt)(struct ldlm_lock *lock);
  * 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);
@@ -407,7 +400,7 @@ struct ldlm_namespace {
         * 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
@@ -419,7 +412,7 @@ struct ldlm_namespace {
         * 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;
 
@@ -582,7 +575,7 @@ typedef int (*ldlm_glimpse_callback)(struct ldlm_lock *lock, void *data);
 /** 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 */
@@ -594,7 +587,7 @@ struct ldlm_glimpse_work {
 /** 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)
@@ -657,6 +650,11 @@ enum lvb_type {
 };
 
 /**
+ * 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
@@ -698,13 +696,13 @@ struct ldlm_lock {
         * 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.
         */
@@ -713,12 +711,12 @@ struct ldlm_lock {
         * 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.
@@ -841,7 +839,7 @@ struct ldlm_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
@@ -863,11 +861,11 @@ struct ldlm_lock {
         */
        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
@@ -879,8 +877,8 @@ struct ldlm_lock {
         * 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;
@@ -889,7 +887,7 @@ struct ldlm_lock {
        /** 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
@@ -899,7 +897,7 @@ struct ldlm_lock {
         * 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;
 };
 
 /**
@@ -920,7 +918,7 @@ struct ldlm_resource {
         * 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;
@@ -929,13 +927,13 @@ struct ldlm_resource {
         * 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 */
@@ -960,6 +958,8 @@ struct ldlm_resource {
         */
        struct mutex            lr_lvb_mutex;
        int                     lr_lvb_len;
+       /** is lvb initialized ? */
+       bool                    lr_lvb_initialized;
        /** protected by lr_lock */
        void                    *lr_lvb_data;
 
@@ -1010,11 +1010,32 @@ ldlm_lock_to_ns_at(struct ldlm_lock *lock)
 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)
@@ -1030,22 +1051,30 @@ 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;
 };
 
 /**
@@ -1125,8 +1154,8 @@ void _ldlm_lock_debug(struct ldlm_lock *lock,
 #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.
@@ -1176,7 +1205,8 @@ int ldlm_server_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
                             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
@@ -1194,10 +1224,12 @@ int ldlm_handle_convert0(struct ptlrpc_request *req,
                          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);
@@ -1243,11 +1275,20 @@ ldlm_handle2lock_long(const struct lustre_handle *h, __u64 flags)
 
 /**
  * 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,
@@ -1291,17 +1332,17 @@ do {                                            \
         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);
@@ -1344,7 +1385,7 @@ void ldlm_namespace_unregister(struct ldlm_namespace *ns, ldlm_side_t client);
 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) {}
@@ -1358,8 +1399,8 @@ struct ldlm_resource *ldlm_resource_get(struct ldlm_namespace *ns,
 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);
@@ -1402,13 +1443,12 @@ int ldlm_cli_enqueue(struct obd_export *exp, struct ptlrpc_request **reqp,
                     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,
@@ -1442,16 +1482,16 @@ int ldlm_cli_cancel_unused_resource(struct ldlm_namespace *ns,
                                     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 */
 
@@ -1460,17 +1500,6 @@ int ldlm_cli_cancel_list(cfs_list_t *head, int count,
 int intent_disposition(struct ldlm_reply *rep, int flag);
 void intent_set_disposition(struct ldlm_reply *rep, int flag);
 
-
-/* ioctls for trying requests */
-#define IOC_LDLM_TYPE                   'f'
-#define IOC_LDLM_MIN_NR                 40
-
-#define IOC_LDLM_TEST                   _IOWR('f', 40, long)
-#define IOC_LDLM_DUMP                   _IOWR('f', 41, long)
-#define IOC_LDLM_REGRESS_START          _IOWR('f', 42, long)
-#define IOC_LDLM_REGRESS_STOP           _IOWR('f', 43, long)
-#define IOC_LDLM_MAX_NR                 43
-
 /**
  * "Modes" of acquiring lock_res, necessary to tell lockdep that taking more
  * than one lock_res is dead-lock safe.
@@ -1519,8 +1548,7 @@ void ldlm_pools_fini(void);
 
 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);