Whamcloud - gitweb
- more LDLM refcount locking infrastructure
[fs/lustre-release.git] / lustre / include / linux / lustre_dlm.h
index 96cef52..898e182 100644 (file)
@@ -5,30 +5,34 @@
 #ifndef _LUSTRE_DLM_H__
 #define _LUSTRE_DLM_H__
 
-#include <linux/kp30.h>
-#include <linux/list.h>
+#ifdef __KERNEL__
 
 #include <linux/obd_class.h>
-
-#ifdef __KERNEL__
+#include <linux/lustre_net.h>
 
 #define OBD_LDLM_DEVICENAME  "ldlm"
 
-typedef  int cluster_host;
-typedef  int cluster_pid;
-
 typedef enum {
         ELDLM_OK = 0,
-        ELDLM_BLOCK_GRANTED = 600,
-        ELDLM_BLOCK_CONV,
-        ELDLM_BLOCK_WAIT,
-        ELDLM_BAD_NAMESPACE,
-        ELDLM_RES_CHANGED
+
+        ELDLM_LOCK_CHANGED = 300,
+        ELDLM_LOCK_ABORTED = 301,
+        ELDLM_RESOURCE_FREED = 302,
+
+        ELDLM_NAMESPACE_EXISTS = 400,
+        ELDLM_BAD_NAMESPACE    = 401
 } ldlm_error_t;
 
-#define LDLM_FL_RES_CHANGED    (1 << 0)
-#define LDLM_FL_COMPLETION_AST (1 << 1)
-#define LDLM_FL_BLOCKING_AST   (1 << 2)
+#define LDLM_NAMESPACE_SERVER 0
+#define LDLM_NAMESPACE_CLIENT 1
+
+#define LDLM_FL_LOCK_CHANGED   (1 << 0)
+#define LDLM_FL_BLOCK_GRANTED  (1 << 1)
+#define LDLM_FL_BLOCK_CONV     (1 << 2)
+#define LDLM_FL_BLOCK_WAIT     (1 << 3)
+#define LDLM_FL_CBPENDING      (1 << 4)
+#define LDLM_FL_AST_SENT       (1 << 5)
+#define LDLM_FL_DESTROYED      (1 << 6)
 
 #define L2B(c) (1 << c)
 
@@ -75,11 +79,13 @@ static inline int lockmode_compat(ldlm_mode_t exist, ldlm_mode_t new)
 */
 
 struct ldlm_namespace {
-        struct list_head      ns_link;      /* in the list of ns's */
-        __u32                 ns_id;        /* identifier of ns */
-        struct list_head     *ns_hash;      /* hash table for ns */
+        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 obd_device    *ns_obddev;
+        struct lustre_lock    ns_lock; /* protects hash, refcount, list */
 };
 
 /* 
@@ -94,33 +100,56 @@ struct ldlm_namespace {
 
 struct ldlm_lock;
 
-typedef int (*ldlm_lock_callback)(struct ldlm_lock *lock, struct ldlm_lock *new,
-                                  void *data); 
+typedef int (*ldlm_lock_callback)(struct lustre_handle *lockh,
+                                  struct ldlm_lock_desc *new, void *data,
+                                  __u32 data_len);
 
 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;
-        struct lustre_peer   *l_peer;
-        //void                 *l_event;
-        //XXX cluster_host    l_holder;
+
+        struct ptlrpc_connection *l_connection;
+        struct ptlrpc_client *l_client;
+        __u32                 l_flags;
+        struct lustre_handle    l_remote_handle;
+        void                 *l_data;
+        __u32                 l_data_len;
+        void                 *l_cookie;
+        int                   l_cookie_len;
+        struct ldlm_extent    l_extent;
         __u32                 l_version[RES_VERSION_SIZE];
+
+        __u32                 l_readers;
+        __u32                 l_writers;
+
+        /* If the lock is granted, a process sleeps on this waitq to learn when
+         * it's no longer in use.  If the lock is not granted, a process sleeps
+         * on this waitq to learn when it becomes granted. */
+        wait_queue_head_t     l_waitq;
 };
 
-typedef int (*ldlm_res_compat)(struct ldlm_resource *child,
-                               struct ldlm_resource *new);
-typedef int (*ldlm_res_policy)(struct ldlm_resource *parent, __u64 *res_id_in,
-                               __u64 *res_id_out, ldlm_mode_t mode, void *data);
+typedef int (*ldlm_res_compat)(struct ldlm_lock *child, struct ldlm_lock *new);
+typedef int (*ldlm_res_policy)(struct ldlm_lock *lock, void *req_cookie,
+                               ldlm_mode_t mode, void *data);
 
-#define LDLM_PLAIN       0x0
-#define LDLM_EXTENT      0x1
-#define LDLM_MDSINTENT   0x2
+#define LDLM_PLAIN       10
+#define LDLM_EXTENT      11
+#define LDLM_MDSINTENT   12
+
+#define LDLM_MIN_TYPE 10
+#define LDLM_MAX_TYPE 12
 
 extern ldlm_res_compat ldlm_res_compat_table []; 
 extern ldlm_res_policy ldlm_res_policy_table []; 
@@ -137,80 +166,127 @@ struct ldlm_resource {
         struct list_head       lr_converting;
         struct list_head       lr_waiting;
         ldlm_mode_t            lr_most_restr;
-        atomic_t               lr_refcount;
+        __u32                  lr_type; /* PLAIN, EXTENT, or MDSINTENT */
         struct ldlm_resource  *lr_root;
-        //XXX cluster_host          lr_master;
         __u64                  lr_name[RES_NAME_SIZE];
         __u32                  lr_version[RES_VERSION_SIZE];
-        __u32                  lr_type; /* PLAIN, EXTENT, or MDSINTENT */
-        spinlock_t             lr_lock;
-
-        void (*lr_blocking)(struct ldlm_lock *lock, struct ldlm_lock *new);
+        atomic_t               lr_refcount;
+        void                  *lr_tmp;
 };
 
-struct ldlm_extent {
-        __u64 start;
-        __u64 end;
+struct ldlm_ast_work { 
+        struct ldlm_lock *w_lock;
+        int               w_blocking;
+        struct ldlm_lock_desc w_desc;
+        struct list_head   w_list;
+        void *w_data;
+        int w_datalen;
 };
-
+        
 static inline struct ldlm_extent *ldlm_res2extent(struct ldlm_resource *res)
 {
         return (struct ldlm_extent *)(res->lr_name);
 }
 
-static inline void *ldlm_handle2object(struct ldlm_handle *handle)
-{
-        return (void *)(unsigned long)(handle->addr);
-}
+extern struct obd_ops ldlm_obd_ops;
 
-static inline void ldlm_object2handle(void *object, struct ldlm_handle *handle)
-{
-        handle->addr = (__u64)(unsigned long)object;
-}
 
-static inline void ldlm_lock(struct obd_device *obddev)
-{
-        spin_lock(&obddev->u.ldlm.ldlm_lock);
-}
+extern char *ldlm_lockname[];
+extern char *ldlm_typename[];
 
-static inline void ldlm_unlock(struct obd_device *obddev)
-{
-        spin_unlock(&obddev->u.ldlm.ldlm_lock);
-}
+#define LDLM_DEBUG(lock, format, a...)                                  \
+do {                                                                    \
+        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)
 
-extern struct obd_ops ldlm_obd_ops;
+#define LDLM_DEBUG_NOLOCK(format, a...)                 \
+        CDEBUG(D_DLMTRACE, "### " format "\n" , ## a)
 
 /* ldlm_extent.c */
-int ldlm_extent_compat(struct ldlm_resource *, struct ldlm_resource *);
-int ldlm_extent_policy(struct ldlm_resource *, __u64 *, __u64 *,
-                       ldlm_mode_t, void *);
+int ldlm_extent_compat(struct ldlm_lock *, struct ldlm_lock *);
+int ldlm_extent_policy(struct ldlm_lock *, void *, ldlm_mode_t, void *);
 
 /* ldlm_lock.c */
-ldlm_error_t ldlm_local_lock_enqueue(struct obd_device *obddev,
-                                     __u32 ns_id,
-                                     struct ldlm_handle *parent_res_handle,
-                                     struct ldlm_handle *parent_lock_handle,
-                                     __u64 *res_id,
-                                     ldlm_mode_t mode,
-                                     int *flags,
-                                     ldlm_lock_callback completion,
-                                     ldlm_lock_callback blocking,
-                                     __u32 data_len,
-                                     void *data,
-                                     struct ldlm_handle *lockh);
+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);
+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 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_lock_callback completion,
+                               ldlm_lock_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);
+int ldlm_test(struct obd_device *device, struct ptlrpc_connection *conn);
 
 /* resource.c */
-struct ldlm_namespace *ldlm_namespace_find(struct obd_device *obddev, __u32 id);
-struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obddev, __u32 id);
-void ldlm_resource_dump(struct ldlm_resource *res);
+struct ldlm_namespace *ldlm_namespace_new(char *name, __u32 local);
+int ldlm_namespace_free(struct ldlm_namespace *ns);
+
+/* resource.c - internal */
 struct ldlm_resource *ldlm_resource_get(struct ldlm_namespace *ns,
                                         struct ldlm_resource *parent,
-                                        __u64 *name, int create);
+                                        __u64 *name, __u32 type, int create);
+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_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);
+int ldlm_lock_change_resource(struct ldlm_lock *lock, __u64 new_resid[3]);
+
+/* ldlm_request.c */
+int ldlm_cli_enqueue(struct ptlrpc_client *cl, 
+                     struct ptlrpc_connection *peer,
+                     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_lock_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 ptlrpc_client *, struct lustre_handle *, struct lustre_handle *connh, 
+                     int new_mode, int *flags);
+int ldlm_cli_cancel(struct lustre_handle *lockh, struct lustre_handle *connh);
 
 #endif /* __KERNEL__ */