Whamcloud - gitweb
LU-6028 ldlm: move LDLM_GID_ANY to lustre_dlm.h
[fs/lustre-release.git] / lustre / include / lustre_dlm.h
index 2aa2e7d..8d36603 100644 (file)
 #ifndef _LUSTRE_DLM_H__
 #define _LUSTRE_DLM_H__
 
-#if defined(__linux__)
-#include <linux/lustre_dlm.h>
-#else
-#error Unsupported operating system.
-#endif
-
 #include <lustre_lib.h>
 #include <lustre_net.h>
 #include <lustre_import.h>
@@ -78,6 +72,7 @@ struct obd_device;
  */
 typedef enum {
         ELDLM_OK = 0,
+       ELDLM_LOCK_MATCHED = 1,
 
         ELDLM_LOCK_CHANGED = 300,
         ELDLM_LOCK_ABORTED = 301,
@@ -215,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);
 };
 
@@ -286,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);
@@ -653,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
@@ -956,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;
 
@@ -1006,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)
@@ -1026,9 +1051,17 @@ 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;
@@ -1191,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);
@@ -1245,6 +1280,15 @@ ldlm_handle2lock_long(const struct lustre_handle *h, __u64 flags)
 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,
@@ -1504,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);