1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
6 * This code is issued under the GNU General Public License.
7 * See the file COPYING in this distribution
9 * by Cluster File Systems, Inc.
14 #define DEBUG_SUBSYSTEM S_LDLM
16 #include <linux/lustre_dlm.h>
18 int ldlm_cli_enqueue(struct ptlrpc_client *cl, struct lustre_peer *peer,
20 struct ldlm_handle *parent_lock_handle,
23 struct ldlm_extent *req_ex,
28 struct ldlm_handle *lockh,
29 struct ptlrpc_request **request)
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};
38 ldlm_local_lock_enqueue(obddev, ns_id, parent_lock_handle, res_id, type,
42 /* FIXME: if this is a local lock, stop here. */
44 req = ptlrpc_prep_req(cl, peer, LDLM_ENQUEUE, 2, size, bufs);
46 GOTO(out, rc = -ENOMEM);
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));
55 body->lock_desc.l_req_mode = mode;
57 memcpy(&body->lock_desc.l_extent, req_ex,
58 sizeof(body->lock_desc.l_extent));
61 /* FIXME: lock_handle1 will be the shadow handle */
63 if (parent_lock_handle)
64 memcpy(&body->lock_handle2, parent_lock_handle,
65 sizeof(body->lock_handle2));
67 /* Continue as normal. */
68 size[0] = sizeof(*reply);
69 req->rq_replen = lustre_msg_size(1, size);
71 rc = ptlrpc_queue_wait(cl, req);
72 rc = ptlrpc_check_status(req, rc);
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);
88 int ldlm_cli_namespace_new(struct ptlrpc_client *cl, struct lustre_peer *peer,
89 __u32 ns_id, struct ptlrpc_request **request)
91 struct ldlm_request *body;
92 struct ptlrpc_request *req;
93 int rc, size = sizeof(*body);
95 req = ptlrpc_prep_req(cl, peer, LDLM_NAMESPACE_NEW, 1, &size, NULL);
97 GOTO(out, rc = -ENOMEM);
99 body = lustre_msg_buf(req->rq_reqmsg, 0);
100 body->lock_desc.l_resource.lr_ns_id = ns_id;
102 req->rq_replen = lustre_msg_size(0, NULL);
104 rc = ptlrpc_queue_wait(cl, req);
105 rc = ptlrpc_check_status(req, rc);
113 int ldlm_cli_callback(struct ldlm_lock *lock, struct ldlm_lock *new,
114 void *data, __u32 data_len)
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};
123 req = ptlrpc_prep_req(cl, &lock->l_peer, LDLM_CALLBACK, 2, size, bufs);
125 GOTO(out, rc = -ENOMEM);
127 body = lustre_msg_buf(req->rq_reqmsg, 0);
128 memcpy(&body->lock_handle1, &lock->l_remote_handle,
129 sizeof(body->lock_handle1));
132 ldlm_lock2desc(new, &body->lock_desc);
134 req->rq_replen = lustre_msg_size(0, NULL);
136 rc = ptlrpc_queue_wait(cl, req);
137 rc = ptlrpc_check_status(req, rc);
138 ptlrpc_free_req(req);