Whamcloud - gitweb
- comment out the noisy get/put LDLM_DEBUGs; I'll remove them when I'm sure
[fs/lustre-release.git] / lustre / include / linux / lustre_dlm.h
index cabe734..e98475c 100644 (file)
@@ -7,6 +7,7 @@
 
 #ifdef __KERNEL__
 
+#include <linux/proc_fs.h>
 #include <linux/obd_class.h>
 #include <linux/lustre_net.h>
 
@@ -30,9 +31,10 @@ typedef enum {
 #define LDLM_FL_BLOCK_GRANTED  (1 << 1)
 #define LDLM_FL_BLOCK_CONV     (1 << 2)
 #define LDLM_FL_BLOCK_WAIT     (1 << 3)
-#define LDLM_FL_DYING          (1 << 4)
+#define LDLM_FL_CBPENDING      (1 << 4)
 #define LDLM_FL_AST_SENT       (1 << 5)
-#define LDLM_FL_BLOCKED_PENDING (1 << 6)
+#define LDLM_FL_DESTROYED      (1 << 6)
+#define LDLM_FL_WAIT_NOREPROC  (1 << 7)
 
 #define L2B(c) (1 << c)
 
@@ -79,13 +81,15 @@ static inline int lockmode_compat(ldlm_mode_t exist, ldlm_mode_t new)
 */
 
 struct ldlm_namespace {
-        char                 *ns_name;
-        struct ptlrpc_client  ns_rpc_client; /* used for revocation callbacks */
-        __u32                 ns_client; /* is this a client-side lock tree? */
-        struct list_head     *ns_hash; /* hash table for ns */
-        __u32                 ns_refcount; /* count of resources in the hash */
-        struct list_head      ns_root_list; /* all root resources in ns */
-        struct lustre_lock    ns_lock; /* protects hash, refcount, list */
+        char                  *ns_name;
+        struct ptlrpc_client   ns_rpc_client;/* used for revocation callbacks */
+        __u32                  ns_client; /* is this a client-side lock tree? */
+        struct list_head      *ns_hash; /* hash table for ns */
+        __u32                  ns_refcount; /* count of resources in the hash */
+        struct list_head       ns_root_list; /* all root resources in ns */
+        struct lustre_lock     ns_lock; /* protects hash, refcount, list */
+        struct list_head       ns_list_chain; /* position in global NS list */
+        struct proc_dir_entry *ns_proc_dir;
 };
 
 /* 
@@ -100,26 +104,30 @@ struct ldlm_namespace {
 
 struct ldlm_lock;
 
-typedef int (*ldlm_lock_callback)(struct ldlm_lock *lock, struct ldlm_lock *new,
-                                  void *data, __u32 data_len,
-                                  struct ptlrpc_request **req);
+typedef int (*ldlm_blocking_callback)(struct ldlm_lock *lock,
+                                      struct ldlm_lock_desc *new, void *data,
+                                      __u32 data_len);
+
+typedef int (*ldlm_completion_callback)(struct ldlm_lock *lock, int flags); 
 
 struct ldlm_lock {
+        __u64                  l_random;
+        int                   l_refc;
         struct ldlm_resource *l_resource;
         struct ldlm_lock     *l_parent;
         struct list_head      l_children;
         struct list_head      l_childof;
         struct list_head      l_res_link; /*position in one of three res lists*/
-        atomic_t              l_refcount;
 
         ldlm_mode_t           l_req_mode;
         ldlm_mode_t           l_granted_mode;
 
-        ldlm_lock_callback    l_completion_ast;
-        ldlm_lock_callback    l_blocking_ast;
+        ldlm_completion_callback    l_completion_ast;
+        ldlm_blocking_callback    l_blocking_ast;
 
         struct ptlrpc_connection *l_connection;
         struct ptlrpc_client *l_client;
+        struct lustre_handle *l_connh;
         __u32                 l_flags;
         struct lustre_handle    l_remote_handle;
         void                 *l_data;
@@ -155,10 +163,10 @@ extern ldlm_res_policy ldlm_res_policy_table [];
 struct ldlm_resource {
         struct ldlm_namespace *lr_namespace;
         struct list_head       lr_hash;
-        struct list_head       lr_rootlink; /* link all root resources in NS */
         struct ldlm_resource  *lr_parent;   /* 0 for a root resource */
         struct list_head       lr_children; /* list head for child resources */
-        struct list_head       lr_childof;  /* part of child list of parent */
+        struct list_head       lr_childof;  /* part of ns_root_list if root res,
+                                             * part of lr_children if child */
 
         struct list_head       lr_granted;
         struct list_head       lr_converting;
@@ -172,6 +180,16 @@ struct ldlm_resource {
         void                  *lr_tmp;
 };
 
+struct ldlm_ast_work { 
+        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;
+};
+        
 static inline struct ldlm_extent *ldlm_res2extent(struct ldlm_resource *res)
 {
         return (struct ldlm_extent *)(res->lr_name);
@@ -179,17 +197,34 @@ static inline struct ldlm_extent *ldlm_res2extent(struct ldlm_resource *res)
 
 extern struct obd_ops ldlm_obd_ops;
 
-#define LDLM_DEBUG(lock, format, a...)                          \
-do {                                                            \
-        CDEBUG(D_DLMTRACE, "### " format                        \
-               " (%s: lock %p mode %d/%d on res %Lu (rc %d) "   \
-               " type %d remote %Lx)\n" , ## a,                 \
-               lock->l_resource->lr_namespace->ns_name, lock,   \
-               lock->l_granted_mode, lock->l_req_mode,          \
-               lock->l_resource->lr_name[0],                    \
-               atomic_read(&lock->l_resource->lr_refcount),     \
-               lock->l_resource->lr_type,                       \
-               lock->l_remote_handle.addr);                     \
+
+extern char *ldlm_lockname[];
+extern char *ldlm_typename[];
+extern char *ldlm_it2str(int it);
+
+#define LDLM_DEBUG(lock, format, a...)                                  \
+do {                                                                    \
+        if (lock->l_resource == NULL)                                   \
+                CDEBUG(D_DLMTRACE, "### " format                        \
+                       " (UNKNOWN: lock %p(rc=%d/%d,%d) mode %s/%s on " \
+                       "res \?\? (rc=\?\?) type \?\?\? remote %Lx)\n" , \
+                       ## a, lock, lock->l_refc, lock->l_readers,       \
+                       lock->l_writers,                                 \
+                       ldlm_lockname[lock->l_granted_mode],             \
+                       ldlm_lockname[lock->l_req_mode],                 \
+                       lock->l_remote_handle.addr);                     \
+        else                                                            \
+                CDEBUG(D_DLMTRACE, "### " format                        \
+                       " (%s: lock %p(rc=%d/%d,%d) mode %s/%s on res "  \
+                       "%Lu (rc=%d) type %s remote %Lx)\n" , ## a,      \
+                       lock->l_resource->lr_namespace->ns_name, lock,   \
+                       lock->l_refc, lock->l_readers, lock->l_writers,  \
+                       ldlm_lockname[lock->l_granted_mode],             \
+                       ldlm_lockname[lock->l_req_mode],                 \
+                       lock->l_resource->lr_name[0],                    \
+                       atomic_read(&lock->l_resource->lr_refcount),     \
+                       ldlm_typename[lock->l_resource->lr_type],        \
+                       lock->l_remote_handle.addr);                     \
 } while (0)
 
 #define LDLM_DEBUG_NOLOCK(format, a...)                 \
@@ -199,55 +234,89 @@ do {                                                            \
 int ldlm_extent_compat(struct ldlm_lock *, struct ldlm_lock *);
 int ldlm_extent_policy(struct ldlm_lock *, void *, ldlm_mode_t, void *);
 
+/* ldlm_lockd.c */
+int ldlm_handle_enqueue(struct ptlrpc_request *req);
+int ldlm_handle_convert(struct ptlrpc_request *req);
+int ldlm_handle_cancel(struct ptlrpc_request *req);
+
 /* ldlm_lock.c */
-void ldlm_lock_free(struct ldlm_lock *lock);
+void ldlm_register_intent(int (*arg)(struct ldlm_lock *lock, void *req_cookie,
+                                     ldlm_mode_t mode, void *data));
+void ldlm_unregister_intent(void);
+void ldlm_lock2handle(struct ldlm_lock *lock, struct lustre_handle *lockh);
+struct ldlm_lock *ldlm_handle2lock(struct lustre_handle *handle);
+void ldlm_lock2handle(struct ldlm_lock *lock, struct lustre_handle *lockh);
+
+#define LDLM_LOCK_PUT(lock)                     \
+do {                                            \
+        /*LDLM_DEBUG(lock, "put");*/            \
+        ldlm_lock_put(lock);                    \
+} while (0)
+
+#define LDLM_LOCK_GET(lock)                     \
+({                                              \
+        ldlm_lock_get(lock);                    \
+        /*LDLM_DEBUG(lock, "get");*/            \
+        lock;                                   \
+})
+
+void ldlm_lock_put(struct ldlm_lock *lock);
+void ldlm_lock_destroy(struct ldlm_lock *lock);
 void ldlm_lock2desc(struct ldlm_lock *lock, struct ldlm_lock_desc *desc);
-void ldlm_lock_addref(struct ldlm_lock *lock, __u32 mode);
-void ldlm_lock_decref(struct ldlm_lock *lock, __u32 mode);
-void ldlm_grant_lock(struct ldlm_resource *res, struct ldlm_lock *lock);
-int ldlm_local_lock_match(struct ldlm_namespace *ns, __u64 *res_id, __u32 type,
-                          void *cookie, int cookielen, ldlm_mode_t mode,
-                          struct lustre_handle *lockh);
-ldlm_error_t ldlm_local_lock_create(struct ldlm_namespace *ns,
-                                    struct lustre_handle *parent_lock_handle,
-                                    __u64 *res_id, __u32 type,
-                                     ldlm_mode_t mode,
-                                    void *data,
-                                    __u32 data_len,
-                                    struct lustre_handle *lockh);
-ldlm_error_t ldlm_local_lock_enqueue(struct lustre_handle *lockh,
-                                     void *cookie, int cookie_len,
-                                     int *flags,
-                                     ldlm_lock_callback completion,
-                                     ldlm_lock_callback blocking);
-struct ldlm_resource *ldlm_local_lock_convert(struct lustre_handle *lockh,
-                                              int new_mode, int *flags);
-struct ldlm_resource *ldlm_local_lock_cancel(struct ldlm_lock *lock);
+void ldlm_lock_addref(struct lustre_handle *lockh, __u32 mode);
+void ldlm_lock_addref_internal(struct ldlm_lock* , __u32 mode);
+void ldlm_lock_decref(struct lustre_handle *lockh, __u32 mode);
+void ldlm_grant_lock(struct ldlm_lock *lock);
+int ldlm_lock_match(struct ldlm_namespace *ns, __u64 *res_id, __u32 type,
+                    void *cookie, int cookielen, ldlm_mode_t mode,
+                    struct lustre_handle *lockh);
+struct ldlm_lock *
+ldlm_lock_create(struct ldlm_namespace *ns,
+                 struct lustre_handle *parent_lock_handle,
+                 __u64 *res_id, __u32 type, ldlm_mode_t mode, void *data,
+                 __u32 data_len);
+ldlm_error_t ldlm_lock_enqueue(struct ldlm_lock *lock, void *cookie,
+                               int cookie_len, int *flags,
+                               ldlm_completion_callback completion,
+                               ldlm_blocking_callback blocking);
+struct ldlm_resource *ldlm_lock_convert(struct ldlm_lock *lock, int new_mode,
+                                        int *flags);
+void ldlm_lock_cancel(struct ldlm_lock *lock);
+void ldlm_run_ast_work(struct list_head *rpc_list);
 void ldlm_reprocess_all(struct ldlm_resource *res);
 void ldlm_lock_dump(struct ldlm_lock *lock);
 
 /* ldlm_test.c */
-int ldlm_test(struct obd_device *device, struct ptlrpc_connection *conn);
+int ldlm_test(struct obd_device *device, struct lustre_handle *connh);
+int ldlm_regression_start(struct obd_device *obddev, 
+                struct lustre_handle *connh, int count);
+int ldlm_regression_stop(void);
+
 
 /* resource.c */
 struct ldlm_namespace *ldlm_namespace_new(char *name, __u32 local);
 int ldlm_namespace_free(struct ldlm_namespace *ns);
+int ldlm_proc_setup(struct obd_device *obd);
+void ldlm_proc_cleanup(struct obd_device *obd);
 
 /* resource.c - internal */
 struct ldlm_resource *ldlm_resource_get(struct ldlm_namespace *ns,
                                         struct ldlm_resource *parent,
                                         __u64 *name, __u32 type, int create);
-struct ldlm_resource *ldlm_resource_addref(struct ldlm_resource *res);
+struct ldlm_resource *ldlm_resource_getref(struct ldlm_resource *res);
 int ldlm_resource_put(struct ldlm_resource *res);
 void ldlm_resource_add_lock(struct ldlm_resource *res, struct list_head *head,
                             struct ldlm_lock *lock);
-void ldlm_resource_del_lock(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_resource_dump(struct ldlm_resource *res);
+void ldlm_dump_all_namespaces(void);
+void ldlm_namespace_dump(struct ldlm_namespace *);
+void ldlm_resource_dump(struct ldlm_resource *);
+int ldlm_lock_change_resource(struct ldlm_lock *, __u64 new_resid[3]);
 
 /* ldlm_request.c */
-int ldlm_cli_enqueue(struct ptlrpc_client *cl, 
-                     struct ptlrpc_connection *peer,
+int ldlm_completion_ast(struct ldlm_lock *lock, int flags);
+int ldlm_cli_enqueue(struct lustre_handle *conn,
                      struct ptlrpc_request *req,
                      struct ldlm_namespace *ns,
                      struct lustre_handle *parent_lock_handle,
@@ -256,15 +325,34 @@ int ldlm_cli_enqueue(struct ptlrpc_client *cl,
                      void *cookie, int cookielen,
                      ldlm_mode_t mode,
                      int *flags,
-                     ldlm_lock_callback callback,
+                     ldlm_completion_callback completion,
+                     ldlm_blocking_callback callback,
                      void *data,
                      __u32 data_len,
                      struct lustre_handle *lockh);
-int ldlm_cli_callback(struct ldlm_lock *lock, struct ldlm_lock *new,
-                      void *data, __u32 data_len, struct ptlrpc_request **reqp);
-int ldlm_cli_convert(struct ptlrpc_client *, struct lustre_handle *,
-                     int new_mode, int *flags);
-int ldlm_cli_cancel(struct ptlrpc_client *, struct ldlm_lock *);
+int ldlm_match_or_enqueue(struct lustre_handle *connh, 
+                          struct ptlrpc_request *req,
+                          struct ldlm_namespace *ns,
+                          struct lustre_handle *parent_lock_handle,
+                          __u64 *res_id,
+                          __u32 type,
+                          void *cookie, int cookielen,
+                          ldlm_mode_t mode,
+                          int *flags,
+                          ldlm_completion_callback completion,
+                          ldlm_blocking_callback callback,
+                          void *data,
+                          __u32 data_len,
+                          struct lustre_handle *lockh);
+int ldlm_server_ast(struct lustre_handle *lockh, struct ldlm_lock_desc *new,
+                    void *data, __u32 data_len);
+int ldlm_cli_convert(struct lustre_handle *, int new_mode, int *flags);
+int ldlm_cli_cancel(struct lustre_handle *lockh);
+
+/* mds/handler.c */
+/* This has to be here because recurisve inclusion sucks. */
+int mds_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
+                     void *data, __u32 data_len);
 
 #endif /* __KERNEL__ */
 
@@ -273,6 +361,9 @@ int ldlm_cli_cancel(struct ptlrpc_client *, struct ldlm_lock *);
 #define IOC_LDLM_MIN_NR                 40
 
 #define IOC_LDLM_TEST                   _IOWR('f', 40, long)
-#define IOC_LDLM_MAX_NR                 41
+#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
 
 #endif