2 * Copryright (C) 2001 Cluster File Systems, Inc.
8 #include <linux/config.h>
9 #include <linux/module.h>
10 #include <linux/kernel.h>
12 #include <linux/string.h>
13 #include <linux/stat.h>
14 #include <linux/errno.h>
15 #include <linux/locks.h>
16 #include <linux/unistd.h>
18 #include <asm/system.h>
19 #include <asm/uaccess.h>
22 #include <linux/stat.h>
23 #include <asm/uaccess.h>
24 #include <linux/vmalloc.h>
25 #include <asm/segment.h>
26 #include <linux/miscdevice.h>
28 #include <linux/obd_support.h>
29 #include <linux/obd_class.h>
30 #include <linux/lustre_lib.h>
31 #include <linux/lustre_idl.h>
33 extern int ost_queue_req(struct obd_device *, struct ptlrpc_request *);
35 /* FIXME: this belongs in some sort of service struct */
36 static int osc_xid = 1;
38 struct ptlrpc_request *ost_prep_req(int opcode, int buflen1, char *buf1,
39 int buflen2, char *buf2)
41 struct ptlrpc_request *request;
45 request = (struct ptlrpc_request *)kmalloc(sizeof(*request), GFP_KERNEL);
47 printk("osc_prep_req: request allocation out of memory\n");
51 memset(request, 0, sizeof(*request));
52 request->rq_xid = osc_xid++;
54 rc = ost_pack_req(buf1, buflen1, buf2, buflen2,
55 &request->rq_reqhdr, &request->rq_req.ost,
56 &request->rq_reqlen, &request->rq_reqbuf);
58 printk("llight request: cannot pack request %d\n", rc);
61 request->rq_reqhdr->opc = opcode;
67 /* XXX: unify with mdc_queue_wait */
68 extern int osc_queue_wait(struct obd_conn *conn, struct ptlrpc_request *req)
70 struct obd_device *client = conn->oc_dev;
71 struct lustre_peer *peer = &conn->oc_dev->u.osc.osc_peer;
76 /* set the connection id */
77 req->rq_req.ost->connid = conn->oc_id;
79 /* XXX fix the race here (wait_for_event?)*/
82 CDEBUG(D_INODE, "\n");
83 rc = ost_queue_req(client, req);
85 /* Remote delivery via portals. */
86 req->rq_req_portal = OST_REQUEST_PORTAL;
87 req->rq_reply_portal = OST_REPLY_PORTAL;
88 rc = ptl_send_rpc(req, peer);
91 printk(__FUNCTION__ ": error %d, opcode %d\n", rc,
96 CDEBUG(D_INODE, "tgt at %p, conn id %d, opcode %d request at: %p\n",
97 &conn->oc_dev->u.osc.osc_tgt->u.ost,
98 conn->oc_id, req->rq_reqhdr->opc, req);
100 /* wait for the reply */
101 init_waitqueue_head(&req->rq_wait_for_rep);
102 CDEBUG(D_INODE, "-- sleeping\n");
103 interruptible_sleep_on(&req->rq_wait_for_rep);
104 CDEBUG(D_INODE, "-- done\n");
106 rc = ost_unpack_rep(req->rq_repbuf, req->rq_replen, &req->rq_rephdr,
109 printk(__FUNCTION__ ": mds_unpack_rep failed: %d\n", rc);
113 if ( req->rq_rephdr->status == 0 )
114 CDEBUG(D_INODE, "buf %p len %d status %d\n",
115 req->rq_repbuf, req->rq_replen,
116 req->rq_rephdr->status);
122 void osc_free_req(struct ptlrpc_request *request)
127 int osc_connect(struct obd_conn *conn)
129 struct ptlrpc_request *request;
133 request = ost_prep_req(OST_CONNECT, 0, NULL, 0, NULL);
135 printk(__FUNCTION__ ": cannot pack req!\n");
140 sizeof(struct ptlrep_hdr) + sizeof(struct ost_rep);
142 rc = osc_queue_wait(conn, request);
148 CDEBUG(D_INODE, "received connid %d\n", request->rq_rep.ost->connid);
150 conn->oc_id = request->rq_rep.ost->connid;
152 osc_free_req(request);
157 int osc_disconnect(struct obd_conn *conn)
159 struct ptlrpc_request *request;
163 request = ost_prep_req(OST_DISCONNECT, 0, NULL, 0, NULL);
165 printk(__FUNCTION__ ": cannot pack req!\n");
170 sizeof(struct ptlrep_hdr) + sizeof(struct ost_rep);
172 rc = osc_queue_wait(conn, request);
178 osc_free_req(request);
184 int osc_getattr(struct obd_conn *conn, struct obdo *oa)
186 struct ptlrpc_request *request;
189 request = ost_prep_req(OST_GETATTR, 0, NULL, 0, NULL);
191 printk(__FUNCTION__ ": cannot pack req!\n");
195 memcpy(&request->rq_req.ost->oa, oa, sizeof(*oa));
196 request->rq_req.ost->oa.o_valid = ~0;
198 sizeof(struct ptlrep_hdr) + sizeof(struct ost_rep);
200 rc = osc_queue_wait(conn, request);
206 CDEBUG(D_INODE, "mode: %o\n", request->rq_rep.ost->oa.o_mode);
208 memcpy(oa, &request->rq_rep.ost->oa, sizeof(*oa));
212 osc_free_req(request);
216 int osc_setattr(struct obd_conn *conn, struct obdo *oa)
218 struct ptlrpc_request *request;
221 request = ost_prep_req(OST_SETATTR, 0, NULL, 0, NULL);
223 printk(__FUNCTION__ ": cannot pack req!\n");
227 memcpy(&request->rq_req.ost->oa, oa, sizeof(*oa));
229 sizeof(struct ptlrep_hdr) + sizeof(struct ost_rep);
231 rc = osc_queue_wait(conn, request);
238 osc_free_req(request);
242 int osc_create(struct obd_conn *conn, struct obdo *oa)
244 struct ptlrpc_request *request;
248 printk(__FUNCTION__ ": oa NULL\n");
250 request = ost_prep_req(OST_CREATE, 0, NULL, 0, NULL);
252 printk("osc_connect: cannot pack req!\n");
256 memcpy(&request->rq_req.ost->oa, oa, sizeof(*oa));
257 request->rq_req.ost->oa.o_valid = ~0;
259 sizeof(struct ptlrep_hdr) + sizeof(struct ost_rep);
261 rc = osc_queue_wait(conn, request);
266 memcpy(oa, &request->rq_rep.ost->oa, sizeof(*oa));
269 osc_free_req(request);
274 /* mount the file system (secretly) */
275 static int osc_setup(struct obd_device *obddev, obd_count len,
279 struct obd_ioctl_data* data = buf;
280 struct osc_obd *osc = &obddev->u.osc;
283 if (data->ioc_dev >= 0 && data->ioc_dev < MAX_OBD_DEVICES) {
284 /* This is a local connection */
285 osc->osc_tgt = &obd_dev[data->ioc_dev];
287 printk("OSC: tgt %d ost at %p\n", data->ioc_dev,
288 &osc->osc_tgt->u.ost);
289 if ( ! (osc->osc_tgt->obd_flags & OBD_ATTACHED) ||
290 ! (osc->osc_tgt->obd_flags & OBD_SET_UP) ){
291 printk("device not attached or not set up (%d)\n",
298 /* This is a remote connection using Portals */
300 /* XXX: this should become something like ioc_inlbuf1 */
301 err = kportal_uuid_to_peer("ost", &osc->osc_peer);
303 printk("Cannot find 'ost' peer.\n");
314 void osc_sendpage(struct niobuf *dst, struct niobuf *src)
316 memcpy((char *)(unsigned long)dst->addr,
317 (char *)(unsigned long)src->addr,
323 int osc_brw(int rw, struct obd_conn *conn, obd_count num_oa,
324 struct obdo **oa, obd_count *oa_bufs, struct page **buf,
325 obd_size *count, obd_off *offset, obd_flag *flags)
327 struct ptlrpc_request *request;
329 struct obd_ioobj ioo;
331 int size1, size2 = 0;
335 size1 = num_oa * sizeof(ioo);
336 for (i = 0; i < num_oa; i++) {
337 size2 += oa_bufs[i] * sizeof(src);
340 request = ost_prep_req(OST_PREPW, size1, NULL, size2, NULL);
342 printk("osc_connect: cannot pack req!\n");
347 ptr1 = ost_req_buf1(request->rq_req.ost);
348 ptr2 = ost_req_buf2(request->rq_req.ost);
349 for (i=0; i < num_oa; i++) {
350 ost_pack_ioo(&ptr1, oa[i], oa_bufs[i]);
351 for (j = 0 ; j < oa_bufs[i] ; j++) {
352 ost_pack_niobuf(&ptr2, kmap(buf[n]), offset[n],
358 rc = osc_queue_wait(conn, request);
364 ptr2 = ost_rep_buf2(request->rq_rep.ost);
365 if (request->rq_rep.ost->buflen2 != n * sizeof(struct niobuf)) {
366 printk(__FUNCTION__ ": buffer length wrong\n");
370 for (i=0; i < num_oa; i++) {
371 for (j = 0 ; j < oa_bufs[i] ; j++) {
373 src.addr = (__u64)(unsigned long)buf[n];
375 ost_unpack_niobuf(&ptr2, &dst);
376 osc_sendpage(dst, &src);
380 //ost_complete_brw(rep);
383 if (request->rq_rephdr)
384 kfree(request->rq_rephdr);
386 for (i=0; i < num_oa; i++) {
387 for (j = 0 ; j < oa_bufs[i] ; j++) {
393 osc_free_req(request);
397 static int osc_cleanup(struct obd_device * obddev)
403 struct obd_ops osc_obd_ops = {
405 o_cleanup: osc_cleanup,
406 o_create: osc_create,
407 o_getattr: osc_getattr,
408 o_setattr: osc_setattr,
409 o_connect: osc_connect,
410 o_disconnect: osc_disconnect
413 static int __init osc_init(void)
415 obd_register_type(&osc_obd_ops, LUSTRE_OSC_NAME);
419 static void __exit osc_exit(void)
421 obd_unregister_type(LUSTRE_OSC_NAME);
424 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
425 MODULE_DESCRIPTION("Lustre Object Storage Client (OSC) v1.0");
426 MODULE_LICENSE("GPL");
428 module_init(osc_init);
429 module_exit(osc_exit);