Whamcloud - gitweb
No new functionality outside of the DLM. ptlrpc_client no longer contains
[fs/lustre-release.git] / lustre / ldlm / ldlm_request.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  *
9  * by Cluster File Systems, Inc.
10  */
11
12 #define EXPORT_SYMTAB
13
14 #define DEBUG_SUBSYSTEM S_LDLM
15
16 #include <linux/lustre_dlm.h>
17
18 int ldlm_cli_enqueue(struct ptlrpc_client *cl, struct lustre_peer *peer,
19                      __u32 ns_id,
20                      struct ldlm_handle *parent_lock_handle,
21                      __u64 *res_id,
22                      __u32 type,
23                      struct ldlm_extent *req_ex,
24                      ldlm_mode_t mode,
25                      int *flags,
26                      void *data,
27                      __u32 data_len,
28                      struct ldlm_handle *lockh,
29                      struct ptlrpc_request **request)
30 {
31         struct ldlm_request *body;
32         struct ldlm_reply *reply;
33         struct ptlrpc_request *req;
34         char *bufs[2] = {NULL, data};
35         int rc, size[2] = {sizeof(*body), data_len};
36
37 #if 0
38         ldlm_local_lock_enqueue(obddev, ns_id, parent_lock_handle, res_id, type,
39                                 req_ex, mode, flags);
40 #endif                           
41
42         /* FIXME: if this is a local lock, stop here. */
43
44         req = ptlrpc_prep_req(cl, peer, LDLM_ENQUEUE, 2, size, bufs);
45         if (!req)
46                 GOTO(out, rc = -ENOMEM);
47
48         /* Dump all of this data into the request buffer */
49         body = lustre_msg_buf(req->rq_reqmsg, 0);
50         body->lock_desc.l_resource.lr_ns_id = ns_id;
51         body->lock_desc.l_resource.lr_type = type;
52         memcpy(body->lock_desc.l_resource.lr_name, res_id,
53                sizeof(body->lock_desc.l_resource.lr_name));
54
55         body->lock_desc.l_req_mode = mode;
56         if (req_ex)
57                 memcpy(&body->lock_desc.l_extent, req_ex,
58                        sizeof(body->lock_desc.l_extent));
59         body->flags = *flags;
60
61         /* FIXME: lock_handle1 will be the shadow handle */
62
63         if (parent_lock_handle)
64                 memcpy(&body->lock_handle2, parent_lock_handle,
65                        sizeof(body->lock_handle2));
66
67         /* Continue as normal. */
68         size[0] = sizeof(*reply);
69         req->rq_replen = lustre_msg_size(1, size);
70
71         rc = ptlrpc_queue_wait(cl, req);
72         rc = ptlrpc_check_status(req, rc);
73         if (rc != ELDLM_OK)
74                 GOTO(out, rc);
75
76         reply = lustre_msg_buf(req->rq_repmsg, 0);
77         CERROR("remote handle: %p\n",
78                (void *)(unsigned long)reply->lock_handle.addr);
79         CERROR("extent: %Lu -> %Lu\n", reply->lock_extent.start,
80                reply->lock_extent.end);
81
82         EXIT;
83  out:
84         *request = req;
85         return rc;
86 }
87
88 int ldlm_cli_namespace_new(struct ptlrpc_client *cl, struct lustre_peer *peer,
89                            __u32 ns_id, struct ptlrpc_request **request)
90 {
91         struct ldlm_request *body;
92         struct ptlrpc_request *req;
93         int rc, size = sizeof(*body);
94
95         req = ptlrpc_prep_req(cl, peer, LDLM_NAMESPACE_NEW, 1, &size, NULL);
96         if (!req)
97                 GOTO(out, rc = -ENOMEM);
98
99         body = lustre_msg_buf(req->rq_reqmsg, 0);
100         body->lock_desc.l_resource.lr_ns_id = ns_id;
101
102         req->rq_replen = lustre_msg_size(0, NULL);
103
104         rc = ptlrpc_queue_wait(cl, req);
105         rc = ptlrpc_check_status(req, rc);
106
107         EXIT;
108  out:
109         *request = req;
110         return rc;
111 }
112
113 int ldlm_cli_callback(struct ldlm_lock *lock, struct ldlm_lock *new,
114                       void *data, __u32 data_len)
115 {
116         struct ldlm_request *body;
117         struct ptlrpc_request *req;
118         struct obd_device *obddev = lock->l_resource->lr_namespace->ns_obddev;
119         struct ptlrpc_client *cl = obddev->u.ldlm.ldlm_client;
120         int rc, size[2] = {sizeof(*body), data_len};
121         char *bufs[2] = {NULL, data};
122
123         req = ptlrpc_prep_req(cl, &lock->l_peer, LDLM_CALLBACK, 2, size, bufs);
124         if (!req)
125                 GOTO(out, rc = -ENOMEM);
126
127         body = lustre_msg_buf(req->rq_reqmsg, 0);
128         memcpy(&body->lock_handle1, &lock->l_remote_handle,
129                sizeof(body->lock_handle1));
130
131         if (new != NULL)
132                 ldlm_lock2desc(new, &body->lock_desc);
133
134         req->rq_replen = lustre_msg_size(0, NULL);
135
136         rc = ptlrpc_queue_wait(cl, req);
137         rc = ptlrpc_check_status(req, rc);
138         ptlrpc_free_req(req);
139
140         EXIT;
141  out:
142         return rc;
143 }