1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 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 * Author Peter Braam <braam@clusterfs.com>
11 * This server is single threaded at present (but can easily be multi
12 * threaded). For testing and management it is treated as an
13 * obd_device, although it does not export a full OBD method table
14 * (the requests are coming in over the wire, so object target
15 * modules do not have a full method table.)
20 #define DEBUG_SUBSYSTEM S_OSC
22 #include <linux/module.h>
23 #include <linux/lustre_dlm.h>
24 #include <linux/lustre_mds.h> /* for mds_objid */
25 #include <linux/obd_ost.h>
26 #include <linux/obd_lov.h>
28 static void osc_con2cl(struct lustre_handle *conn, struct ptlrpc_client **cl,
29 struct ptlrpc_connection **connection,
30 struct lustre_handle **rconn)
32 struct obd_export *export = class_conn2export(conn);
33 struct osc_obd *osc = &export->exp_obd->u.osc;
35 *cl = osc->osc_client;
36 *connection = osc->osc_conn;
37 *rconn = &export->exp_rconnh;
40 static void osc_con2dlmcl(struct lustre_handle *conn, struct ptlrpc_client **cl,
41 struct ptlrpc_connection **connection,
42 struct lustre_handle **rconn)
44 struct obd_export *export = class_conn2export(conn);
45 struct osc_obd *osc = &export->exp_obd->u.osc;
47 *cl = osc->osc_ldlm_client;
48 *connection = osc->osc_conn;
49 *rconn = &export->exp_rconnh;
52 static int osc_connect(struct lustre_handle *conn, struct obd_device *obd)
54 struct osc_obd *osc = &obd->u.osc;
55 //struct obd_import *import;
56 struct ptlrpc_request *request;
57 char *tmp = osc->osc_target_uuid;
58 int rc, size = sizeof(osc->osc_target_uuid);
62 OBD_ALLOC(import, sizeof(*import));
68 rc = class_connect(conn, obd);
72 request = ptlrpc_prep_req(osc->osc_client, osc->osc_conn,
73 OST_CONNECT, 1, &size, &tmp);
75 GOTO(out_disco, rc = -ENOMEM);
77 request->rq_level = LUSTRE_CONN_NEW;
78 request->rq_replen = lustre_msg_size(0, NULL);
79 request->rq_reqmsg->addr = -1;
80 /* Sending our local connection info breaks for local connections
81 request->rq_reqmsg->addr = conn->addr;
82 request->rq_reqmsg->cookie = conn->cookie;
85 rc = ptlrpc_queue_wait(request);
86 rc = ptlrpc_check_status(request, rc);
88 CERROR("%s failed: rc = %d\n", __FUNCTION__, rc);
92 /* XXX eventually maybe more refinement */
93 osc->osc_conn->c_level = LUSTRE_CONN_FULL;
95 class_rconn2export(conn, (struct lustre_handle *)request->rq_repmsg);
99 ptlrpc_free_req(request);
102 class_disconnect(conn);
108 static int osc_disconnect(struct lustre_handle *conn)
110 struct ptlrpc_request *request;
111 struct ptlrpc_client *cl;
112 struct ptlrpc_connection *connection;
113 struct lustre_handle *rconn;
117 osc_con2cl(conn, &cl, &connection, &rconn);
118 request = ptlrpc_prep_req2(cl, connection, rconn,
119 OST_DISCONNECT, 0, NULL, NULL);
122 request->rq_replen = lustre_msg_size(0, NULL);
124 rc = ptlrpc_queue_wait(request);
127 rc = class_disconnect(conn);
132 ptlrpc_free_req(request);
136 static int osc_getattr(struct lustre_handle *conn, struct obdo *oa)
138 struct ptlrpc_request *request;
139 struct ptlrpc_client *cl;
140 struct ptlrpc_connection *connection;
141 struct lustre_handle *rconn;
142 struct ost_body *body;
143 int rc, size = sizeof(*body);
146 osc_con2cl(conn, &cl, &connection, &rconn);
147 request = ptlrpc_prep_req2(cl, connection, rconn,
148 OST_GETATTR, 1, &size, NULL);
152 body = lustre_msg_buf(request->rq_reqmsg, 0);
153 memcpy(&body->oa, oa, sizeof(*oa));
154 body->oa.o_valid = ~0;
156 request->rq_replen = lustre_msg_size(1, &size);
158 rc = ptlrpc_queue_wait(request);
159 rc = ptlrpc_check_status(request, rc);
161 CERROR("%s failed: rc = %d\n", __FUNCTION__, rc);
165 body = lustre_msg_buf(request->rq_repmsg, 0);
166 CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
168 memcpy(oa, &body->oa, sizeof(*oa));
172 ptlrpc_free_req(request);
176 static int osc_open(struct lustre_handle *conn, struct obdo *oa,
177 struct lov_stripe_md *md)
179 struct ptlrpc_request *request;
180 struct ptlrpc_client *cl;
181 struct ptlrpc_connection *connection;
182 struct lustre_handle *rconn;
183 struct ost_body *body;
184 int rc, size = sizeof(*body);
187 osc_con2cl(conn, &cl, &connection, &rconn);
188 request = ptlrpc_prep_req2(cl, connection, rconn,
189 OST_OPEN, 1, &size, NULL);
193 body = lustre_msg_buf(request->rq_reqmsg, 0);
194 memcpy(&body->oa, oa, sizeof(*oa));
195 body->oa.o_valid = (OBD_MD_FLMODE | OBD_MD_FLID);
197 request->rq_replen = lustre_msg_size(1, &size);
199 rc = ptlrpc_queue_wait(request);
200 rc = ptlrpc_check_status(request, rc);
204 body = lustre_msg_buf(request->rq_repmsg, 0);
205 CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
207 memcpy(oa, &body->oa, sizeof(*oa));
211 ptlrpc_free_req(request);
215 static int osc_close(struct lustre_handle *conn, struct obdo *oa,
216 struct lov_stripe_md *md)
218 struct ptlrpc_request *request;
219 struct ptlrpc_client *cl;
220 struct ptlrpc_connection *connection;
221 struct lustre_handle *rconn;
222 struct ost_body *body;
223 int rc, size = sizeof(*body);
226 osc_con2cl(conn, &cl, &connection, &rconn);
227 request = ptlrpc_prep_req2(cl, connection, rconn,
228 OST_CLOSE, 1, &size, NULL);
232 oa->o_id = md->lmd_object_id;
233 oa->o_mode = S_IFREG;
234 oa->o_valid = (OBD_MD_FLMODE | OBD_MD_FLID);
235 body = lustre_msg_buf(request->rq_reqmsg, 0);
236 memcpy(&body->oa, oa, sizeof(*oa));
238 request->rq_replen = lustre_msg_size(1, &size);
240 rc = ptlrpc_queue_wait(request);
241 rc = ptlrpc_check_status(request, rc);
245 body = lustre_msg_buf(request->rq_repmsg, 0);
246 CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
248 memcpy(oa, &body->oa, sizeof(*oa));
252 ptlrpc_free_req(request);
256 static int osc_setattr(struct lustre_handle *conn, struct obdo *oa)
258 struct ptlrpc_request *request;
259 struct ptlrpc_client *cl;
260 struct ptlrpc_connection *connection;
261 struct lustre_handle *rconn;
262 struct ost_body *body;
263 int rc, size = sizeof(*body);
266 osc_con2cl(conn, &cl, &connection, &rconn);
267 request = ptlrpc_prep_req2(cl, connection, rconn,
268 OST_SETATTR, 1, &size, NULL);
272 body = lustre_msg_buf(request->rq_reqmsg, 0);
273 memcpy(&body->oa, oa, sizeof(*oa));
275 request->rq_replen = lustre_msg_size(1, &size);
277 rc = ptlrpc_queue_wait(request);
278 rc = ptlrpc_check_status(request, rc);
282 ptlrpc_free_req(request);
286 static int osc_create(struct lustre_handle *conn, struct obdo *oa,
287 struct lov_stripe_md **ea)
289 struct ptlrpc_request *request;
290 struct ptlrpc_client *cl;
291 struct ptlrpc_connection *connection;
292 struct lustre_handle *rconn;
293 struct ost_body *body;
294 int rc, size = sizeof(*body);
307 OBD_ALLOC(*ea, oa->o_easize);
310 (*ea)->lmd_size = oa->o_easize;
313 osc_con2cl(conn, &cl, &connection, &rconn);
314 request = ptlrpc_prep_req2(cl, connection, rconn,
315 OST_CREATE, 1, &size, NULL);
319 body = lustre_msg_buf(request->rq_reqmsg, 0);
320 memcpy(&body->oa, oa, sizeof(*oa));
322 request->rq_replen = lustre_msg_size(1, &size);
324 rc = ptlrpc_queue_wait(request);
325 rc = ptlrpc_check_status(request, rc);
329 body = lustre_msg_buf(request->rq_repmsg, 0);
330 memcpy(oa, &body->oa, sizeof(*oa));
332 (*ea)->lmd_object_id = oa->o_id;
333 (*ea)->lmd_stripe_count = 1;
336 ptlrpc_free_req(request);
340 static int osc_punch(struct lustre_handle *conn, struct obdo *oa,
341 struct lov_stripe_md *md, obd_size count,
344 struct ptlrpc_request *request;
345 struct ptlrpc_client *cl;
346 struct ptlrpc_connection *connection;
347 struct lustre_handle *rconn;
348 struct ost_body *body;
349 int rc, size = sizeof(*body);
356 osc_con2cl(conn, &cl, &connection, &rconn);
357 request = ptlrpc_prep_req2(cl, connection, rconn,
358 OST_PUNCH, 1, &size, NULL);
362 body = lustre_msg_buf(request->rq_reqmsg, 0);
363 memcpy(&body->oa, oa, sizeof(*oa));
364 body->oa.o_blocks = count;
365 body->oa.o_valid |= OBD_MD_FLBLOCKS;
367 request->rq_replen = lustre_msg_size(1, &size);
369 rc = ptlrpc_queue_wait(request);
370 rc = ptlrpc_check_status(request, rc);
374 body = lustre_msg_buf(request->rq_repmsg, 0);
375 memcpy(oa, &body->oa, sizeof(*oa));
379 ptlrpc_free_req(request);
383 static int osc_destroy(struct lustre_handle *conn, struct obdo *oa,
384 struct lov_stripe_md *ea)
386 struct ptlrpc_request *request;
387 struct ptlrpc_client *cl;
388 struct ptlrpc_connection *connection;
389 struct lustre_handle *rconn;
390 struct ost_body *body;
391 int rc, size = sizeof(*body);
398 osc_con2cl(conn, &cl, &connection, &rconn);
399 request = ptlrpc_prep_req2(cl, connection, rconn,
400 OST_DESTROY, 1, &size, NULL);
404 body = lustre_msg_buf(request->rq_reqmsg, 0);
405 memcpy(&body->oa, oa, sizeof(*oa));
406 body->oa.o_valid = ~0;
408 request->rq_replen = lustre_msg_size(1, &size);
410 rc = ptlrpc_queue_wait(request);
411 rc = ptlrpc_check_status(request, rc);
415 body = lustre_msg_buf(request->rq_repmsg, 0);
416 memcpy(oa, &body->oa, sizeof(*oa));
420 ptlrpc_free_req(request);
424 struct osc_brw_cb_data {
425 bulk_callback_t callback;
431 /* Our bulk-unmapping bottom half. */
432 static void unmap_and_decref_bulk_desc(void *data)
434 struct ptlrpc_bulk_desc *desc = data;
435 struct list_head *tmp, *next;
437 /* This feels wrong to me. */
438 list_for_each_safe(tmp, next, &desc->b_page_list) {
439 struct ptlrpc_bulk_page *bulk;
440 bulk = list_entry(tmp, struct ptlrpc_bulk_page, b_link);
442 kunmap(bulk->b_page);
445 ptlrpc_bulk_decref(desc);
449 static void brw_finish(struct ptlrpc_bulk_desc *desc, void *data)
451 struct osc_brw_cb_data *cb_data = data;
454 if (desc->b_flags & PTL_RPC_FL_INTR)
455 CERROR("got signal\n");
457 if (cb_data->callback)
458 (cb_data->callback)(desc, cb_data->cb_data);
460 if (cb_data->obd_data)
461 OBD_FREE(cb_data->obd_data, cb_data->obd_size);
462 OBD_FREE(cb_data, sizeof(*cb_data));
464 /* We can't kunmap the desc from interrupt context, so we do it from
465 * the bottom half above. */
466 INIT_TQUEUE(&desc->b_queue, 0, 0);
467 PREPARE_TQUEUE(&desc->b_queue, unmap_and_decref_bulk_desc, desc);
468 schedule_task(&desc->b_queue);
473 static int osc_brw_read(struct lustre_handle *conn, struct lov_stripe_md *md,
474 obd_count page_count, struct page **page_array,
475 obd_size *count, obd_off *offset, obd_flag *flags,
476 bulk_callback_t callback)
478 struct ptlrpc_client *cl;
479 struct ptlrpc_connection *connection;
480 struct lustre_handle *rconn;
481 struct ptlrpc_request *request = NULL;
482 struct ptlrpc_bulk_desc *desc = NULL;
483 struct ost_body *body;
484 int rc, j, size[3] = {sizeof(*body)};
485 void *iooptr, *nioptr;
486 struct osc_brw_cb_data *cb_data = NULL;
489 size[1] = sizeof(struct obd_ioobj);
490 size[2] = page_count * sizeof(struct niobuf_remote);
492 osc_con2cl(conn, &cl, &connection, &rconn);
493 request = ptlrpc_prep_req2(cl, connection, rconn,
494 OST_BRW, 3, size, NULL);
498 body = lustre_msg_buf(request->rq_reqmsg, 0);
499 body->data = OBD_BRW_READ;
501 desc = ptlrpc_prep_bulk(connection);
503 GOTO(out_free, rc = -ENOMEM);
504 desc->b_portal = OST_BULK_PORTAL;
505 desc->b_cb = brw_finish;
506 OBD_ALLOC(cb_data, sizeof(*cb_data));
508 GOTO(out_free, rc = -ENOMEM);
509 cb_data->callback = callback;
510 desc->b_cb_data = cb_data;
511 /* XXX end almost identical to brw_write case */
513 iooptr = lustre_msg_buf(request->rq_reqmsg, 1);
514 nioptr = lustre_msg_buf(request->rq_reqmsg, 2);
515 ost_pack_ioo(&iooptr, md, page_count);
516 for (j = 0; j < page_count; j++) {
517 struct ptlrpc_bulk_page *bulk;
518 bulk = ptlrpc_prep_bulk_page(desc);
520 GOTO(out_unmap, rc = -ENOMEM);
522 spin_lock(&connection->c_lock);
523 bulk->b_xid = ++connection->c_xid_out;
524 spin_unlock(&connection->c_lock);
526 bulk->b_buf = kmap(page_array[j]);
527 bulk->b_page = page_array[j];
528 bulk->b_buflen = PAGE_SIZE;
529 ost_pack_niobuf(&nioptr, offset[j], count[j],
530 flags[j], bulk->b_xid);
534 * Register the bulk first, because the reply could arrive out of order,
535 * and we want to be ready for the bulk data.
537 * One reference is released by the bulk callback, the other when
538 * we finish sleeping on it (if we don't have a callback).
540 atomic_set(&desc->b_refcount, callback ? 1 : 2);
541 rc = ptlrpc_register_bulk(desc);
545 request->rq_replen = lustre_msg_size(1, size);
546 rc = ptlrpc_queue_wait(request);
547 rc = ptlrpc_check_status(request, rc);
549 ptlrpc_bulk_decref(desc);
553 /* Callbacks cause asynchronous handling. */
557 l_wait_event_killable(desc->b_waitq, ptlrpc_check_bulk_received(desc));
558 rc = desc->b_flags & PTL_RPC_FL_INTR ? -EINTR : 0;
559 ptlrpc_bulk_decref(desc);
562 /* Clean up on error. */
564 for (j = 0; j < desc->b_page_count; j++)
565 kunmap(page_array[j]);
568 OBD_FREE(cb_data, sizeof(*cb_data));
569 ptlrpc_free_bulk(desc);
570 ptlrpc_free_req(request);
574 static int osc_brw_write(struct lustre_handle *conn,
575 struct lov_stripe_md *md, obd_count page_count,
576 struct page **pagearray, obd_size *count,
577 obd_off *offset, obd_flag *flags,
578 bulk_callback_t callback)
580 struct ptlrpc_client *cl;
581 struct ptlrpc_connection *connection;
582 struct lustre_handle *rconn;
583 struct ptlrpc_request *request = NULL;
584 struct ptlrpc_bulk_desc *desc = NULL;
585 struct ost_body *body;
586 struct niobuf_local *local = NULL;
587 struct niobuf_remote *remote;
588 struct osc_brw_cb_data *cb_data = NULL;
589 int rc, j, size[3] = {sizeof(*body)};
590 void *iooptr, *nioptr;
593 size[1] = sizeof(struct obd_ioobj);
594 size[2] = page_count * sizeof(*remote);
596 osc_con2cl(conn, &cl, &connection, &rconn);
597 request = ptlrpc_prep_req2(cl, connection, rconn,
598 OST_BRW, 3, size, NULL);
602 body = lustre_msg_buf(request->rq_reqmsg, 0);
603 body->data = OBD_BRW_WRITE;
605 OBD_ALLOC(local, page_count * sizeof(*local));
607 GOTO(out_free, rc = -ENOMEM);
609 desc = ptlrpc_prep_bulk(connection);
611 GOTO(out_free, rc = -ENOMEM);
612 desc->b_portal = OSC_BULK_PORTAL;
613 desc->b_cb = brw_finish;
614 OBD_ALLOC(cb_data, sizeof(*cb_data));
616 GOTO(out_free, rc = -ENOMEM);
617 cb_data->callback = callback;
618 desc->b_cb_data = cb_data;
619 /* XXX end almost identical to brw_read case */
620 cb_data->obd_data = local;
621 cb_data->obd_size = page_count * sizeof(*local);
623 iooptr = lustre_msg_buf(request->rq_reqmsg, 1);
624 nioptr = lustre_msg_buf(request->rq_reqmsg, 2);
625 ost_pack_ioo(&iooptr, md, page_count);
626 for (j = 0; j < page_count; j++) {
627 local[j].addr = kmap(pagearray[j]);
628 local[j].offset = offset[j];
629 local[j].len = count[j];
630 ost_pack_niobuf(&nioptr, offset[j], count[j], flags[j], 0);
633 size[1] = page_count * sizeof(struct niobuf_remote);
634 request->rq_replen = lustre_msg_size(2, size);
635 rc = ptlrpc_queue_wait(request);
636 rc = ptlrpc_check_status(request, rc);
640 nioptr = lustre_msg_buf(request->rq_repmsg, 1);
642 GOTO(out_unmap, rc = -EINVAL);
644 if (request->rq_repmsg->buflens[1] !=
645 page_count * sizeof(struct niobuf_remote)) {
646 CERROR("buffer length wrong (%d vs. %d)\n",
647 request->rq_repmsg->buflens[1],
648 page_count * sizeof(struct niobuf_remote));
649 GOTO(out_unmap, rc = -EINVAL);
652 for (j = 0; j < page_count; j++) {
653 struct ptlrpc_bulk_page *page;
655 ost_unpack_niobuf(&nioptr, &remote);
657 page = ptlrpc_prep_bulk_page(desc);
659 GOTO(out_unmap, rc = -ENOMEM);
661 page->b_buf = (void *)(unsigned long)local[j].addr;
662 page->b_buflen = local[j].len;
663 page->b_xid = remote->xid;
666 if (desc->b_page_count != page_count)
670 * One is released when the bulk is complete, the other when we finish
671 * waiting on it. (Callback cases don't sleep, so only one ref for
674 atomic_set(&desc->b_refcount, callback ? 1 : 2);
675 CDEBUG(D_PAGE, "Set refcount of %p to %d\n", desc,
676 atomic_read(&desc->b_refcount));
677 rc = ptlrpc_send_bulk(desc);
681 /* Callbacks cause asynchronous handling. */
685 /* If there's no callback function, sleep here until complete. */
686 l_wait_event_killable(desc->b_waitq, ptlrpc_check_bulk_sent(desc));
687 ptlrpc_bulk_decref(desc);
688 if (desc->b_flags & PTL_RPC_FL_INTR)
692 /* Clean up on error. */
694 for (j = 0; j < page_count; j++)
695 kunmap(pagearray[j]);
699 OBD_FREE(cb_data, sizeof(*cb_data));
701 OBD_FREE(local, page_count * sizeof(*local));
702 ptlrpc_free_bulk(desc);
703 ptlrpc_req_finished(request);
707 static int osc_brw(int cmd, struct lustre_handle *conn,
708 struct lov_stripe_md *md, obd_count page_count,
709 struct page **page_array,
715 if (cmd & OBD_BRW_WRITE)
716 return osc_brw_write(conn, md, page_count, page_array, count,
717 offset, flags, (bulk_callback_t)callback);
719 return osc_brw_read(conn, md, page_count, page_array, count,
720 offset, flags, (bulk_callback_t)callback);
723 static int osc_enqueue(struct lustre_handle *conn,
724 struct lustre_handle *parent_lock, __u64 *res_id,
725 __u32 type, void *extentp, int extent_len, __u32 mode,
726 int *flags, void *callback, void *data, int datalen,
727 struct lustre_handle *lockh)
729 struct obd_device *obddev = class_conn2obd(conn);
730 struct ptlrpc_connection *connection;
731 struct ptlrpc_client *cl;
732 struct lustre_handle *rconn;
733 struct ldlm_extent *extent = extentp;
737 /* Filesystem locks are given a bit of special treatment: first we
738 * fixup the lock to start and end on page boundaries. */
739 extent->start &= PAGE_MASK;
740 extent->end = (extent->end + PAGE_SIZE - 1) & PAGE_MASK;
742 /* Next, search for already existing extent locks that will cover us */
743 osc_con2dlmcl(conn, &cl, &connection, &rconn);
744 rc = ldlm_lock_match(obddev->obd_namespace, res_id, type, extent,
745 sizeof(extent), mode, lockh);
747 /* We already have a lock, and it's referenced */
751 /* Next, search for locks that we can upgrade (if we're trying to write)
752 * or are more than we need (if we're trying to read). Because the VFS
753 * and page cache already protect us locally, lots of readers/writers
754 * can share a single PW lock. */
760 rc = ldlm_lock_match(obddev->obd_namespace, res_id, type, extent,
761 sizeof(extent), mode2, lockh);
764 /* FIXME: This is not incredibly elegant, but it might
765 * be more elegant than adding another parameter to
766 * lock_match. I want a second opinion. */
767 ldlm_lock_addref(lockh, mode);
768 ldlm_lock_decref(lockh, mode2);
773 rc = ldlm_cli_convert(cl, lockh, rconn, mode, &flags);
780 rc = ldlm_cli_enqueue(cl, connection, rconn, NULL,obddev->obd_namespace,
781 parent_lock, res_id, type, extent, sizeof(extent),
782 mode, flags, callback, data, datalen, lockh);
786 static int osc_cancel(struct lustre_handle *oconn, __u32 mode,
787 struct lustre_handle *lockh)
791 ldlm_lock_decref(lockh, mode);
796 static int osc_setup(struct obd_device *obddev, obd_count len, void *buf)
798 struct obd_ioctl_data* data = buf;
799 struct osc_obd *osc = &obddev->u.osc;
800 char server_uuid[37];
804 if (data->ioc_inllen1 < 1) {
805 CERROR("osc setup requires a TARGET UUID\n");
809 if (data->ioc_inllen1 > 37) {
810 CERROR("osc TARGET UUID must be less than 38 characters\n");
814 if (data->ioc_inllen2 < 1) {
815 CERROR("osc setup requires a SERVER UUID\n");
819 if (data->ioc_inllen2 > 37) {
820 CERROR("osc SERVER UUID must be less than 38 characters\n");
824 memcpy(osc->osc_target_uuid, data->ioc_inlbuf1, data->ioc_inllen1);
825 memcpy(server_uuid, data->ioc_inlbuf2, MIN(data->ioc_inllen2,
826 sizeof(server_uuid)));
828 osc->osc_conn = ptlrpc_uuid_to_connection(server_uuid);
832 obddev->obd_namespace =
833 ldlm_namespace_new("osc", LDLM_NAMESPACE_CLIENT);
834 if (obddev->obd_namespace == NULL)
835 GOTO(out_conn, rc = -ENOMEM);
837 OBD_ALLOC(osc->osc_client, sizeof(*osc->osc_client));
838 if (osc->osc_client == NULL)
839 GOTO(out_ns, rc = -ENOMEM);
841 OBD_ALLOC(osc->osc_ldlm_client, sizeof(*osc->osc_ldlm_client));
842 if (osc->osc_ldlm_client == NULL)
843 GOTO(out_client, rc = -ENOMEM);
845 ptlrpc_init_client(NULL, NULL, OST_REQUEST_PORTAL, OSC_REPLY_PORTAL,
847 ptlrpc_init_client(NULL, NULL, LDLM_REQUEST_PORTAL, LDLM_REPLY_PORTAL,
848 osc->osc_ldlm_client);
849 osc->osc_client->cli_name = "osc";
850 osc->osc_ldlm_client->cli_name = "ldlm";
856 OBD_FREE(osc->osc_client, sizeof(*osc->osc_client));
858 ldlm_namespace_free(obddev->obd_namespace);
860 ptlrpc_put_connection(osc->osc_conn);
864 static int osc_cleanup(struct obd_device * obddev)
866 struct osc_obd *osc = &obddev->u.osc;
868 ldlm_namespace_free(obddev->obd_namespace);
870 ptlrpc_cleanup_client(osc->osc_client);
871 OBD_FREE(osc->osc_client, sizeof(*osc->osc_client));
872 ptlrpc_cleanup_client(osc->osc_ldlm_client);
873 OBD_FREE(osc->osc_ldlm_client, sizeof(*osc->osc_ldlm_client));
874 ptlrpc_put_connection(osc->osc_conn);
880 static int osc_statfs(struct lustre_handle *conn, struct statfs *sfs)
882 struct ptlrpc_request *request;
883 struct ptlrpc_client *cl;
884 struct ptlrpc_connection *connection;
885 struct lustre_handle *rconn;
886 struct obd_statfs *osfs;
887 int rc, size = sizeof(*osfs);
890 osc_con2cl(conn, &cl, &connection, &rconn);
891 request = ptlrpc_prep_req2(cl, connection, rconn,
892 OST_STATFS, 0, NULL, NULL);
896 request->rq_replen = lustre_msg_size(1, &size);
898 rc = ptlrpc_queue_wait(request);
899 rc = ptlrpc_check_status(request, rc);
901 CERROR("%s failed: rc = %d\n", __FUNCTION__, rc);
905 osfs = lustre_msg_buf(request->rq_repmsg, 0);
906 obd_statfs_unpack(osfs, sfs);
910 ptlrpc_free_req(request);
914 struct obd_ops osc_obd_ops = {
916 o_cleanup: osc_cleanup,
917 o_statfs: osc_statfs,
918 o_create: osc_create,
919 o_destroy: osc_destroy,
920 o_getattr: osc_getattr,
921 o_setattr: osc_setattr,
924 o_connect: osc_connect,
925 o_disconnect: osc_disconnect,
928 o_enqueue: osc_enqueue,
932 static int __init osc_init(void)
934 return class_register_type(&osc_obd_ops, LUSTRE_OSC_NAME);
937 static void __exit osc_exit(void)
939 class_unregister_type(LUSTRE_OSC_NAME);
942 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
943 MODULE_DESCRIPTION("Lustre Object Storage Client (OSC) v1.0");
944 MODULE_LICENSE("GPL");
946 module_init(osc_init);
947 module_exit(osc_exit);