1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copryright (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_obd2cl(struct obd_device *obd, struct ptlrpc_client **cl,
29 struct ptlrpc_connection **connection)
31 struct osc_obd *osc = &obd->u.osc;
32 *cl = osc->osc_client;
33 *connection = osc->osc_conn;
36 static void osc_con2cl(struct lustre_handle *conn, struct ptlrpc_client **cl,
37 struct ptlrpc_connection **connection)
39 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
40 *cl = osc->osc_client;
41 *connection = osc->osc_conn;
44 static void osc_con2dlmcl(struct lustre_handle *conn, struct ptlrpc_client **cl,
45 struct ptlrpc_connection **connection)
47 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
48 *cl = osc->osc_ldlm_client;
49 *connection = osc->osc_conn;
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 struct ptlrpc_client *cl;
58 struct ptlrpc_connection *connection;
59 char *tmp = osc->osc_target_uuid;
60 int rc, size = sizeof(osc->osc_target_uuid);
63 OBD_ALLOC(import, sizeof(*import));
68 rc = class_connect(conn, obd);
72 osc_obd2cl(obd, &cl, &connection);
73 request = ptlrpc_prep_req(osc->osc_client, osc->osc_conn,
74 OST_CONNECT, 1, &size, &tmp);
76 GOTO(out_disco, -ENOMEM);
78 request->rq_replen = lustre_msg_size(0, NULL);
80 rc = ptlrpc_queue_wait(request);
81 rc = ptlrpc_check_status(request, rc);
83 CERROR("%s failed: rc = %d\n", __FUNCTION__, rc);
87 /* XXX: Make this a handle */
88 osc->osc_connh.addr = request->rq_repmsg->addr;
89 osc->osc_connh.cookie = request->rq_repmsg->cookie;
94 ptlrpc_free_req(request);
96 class_disconnect(conn);
102 static int osc_disconnect(struct lustre_handle *conn)
104 struct ptlrpc_request *request;
105 struct ptlrpc_client *cl;
106 struct ptlrpc_connection *connection;
107 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
111 osc_con2cl(conn, &cl, &connection);
112 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
113 OST_DISCONNECT, 0, NULL, NULL);
116 request->rq_replen = lustre_msg_size(0, NULL);
118 rc = ptlrpc_queue_wait(request);
121 rc = class_disconnect(conn);
126 ptlrpc_free_req(request);
130 static int osc_getattr(struct lustre_handle *conn, struct obdo *oa)
132 struct ptlrpc_request *request;
133 struct ptlrpc_client *cl;
134 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
135 struct ptlrpc_connection *connection;
136 struct ost_body *body;
137 int rc, size = sizeof(*body);
140 osc_con2cl(conn, &cl, &connection);
141 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
142 OST_GETATTR, 1, &size, NULL);
146 body = lustre_msg_buf(request->rq_reqmsg, 0);
147 memcpy(&body->oa, oa, sizeof(*oa));
148 body->oa.o_valid = ~0;
150 request->rq_replen = lustre_msg_size(1, &size);
152 rc = ptlrpc_queue_wait(request);
153 rc = ptlrpc_check_status(request, rc);
155 CERROR("%s failed: rc = %d\n", __FUNCTION__, rc);
159 body = lustre_msg_buf(request->rq_repmsg, 0);
160 CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
162 memcpy(oa, &body->oa, sizeof(*oa));
166 ptlrpc_free_req(request);
170 static int osc_open(struct lustre_handle *conn, struct obdo *oa)
172 struct ptlrpc_request *request;
173 struct ptlrpc_client *cl;
174 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
175 struct ptlrpc_connection *connection;
176 struct ost_body *body;
177 int rc, size = sizeof(*body);
180 osc_con2cl(conn, &cl, &connection);
181 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
182 OST_OPEN, 1, &size, NULL);
186 body = lustre_msg_buf(request->rq_reqmsg, 0);
187 memcpy(&body->oa, oa, sizeof(*oa));
188 body->oa.o_valid = (OBD_MD_FLMODE | OBD_MD_FLID);
190 request->rq_replen = lustre_msg_size(1, &size);
192 rc = ptlrpc_queue_wait(request);
193 rc = ptlrpc_check_status(request, rc);
197 body = lustre_msg_buf(request->rq_repmsg, 0);
198 CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
200 memcpy(oa, &body->oa, sizeof(*oa));
204 ptlrpc_free_req(request);
208 static int osc_close(struct lustre_handle *conn, struct obdo *oa)
210 struct ptlrpc_request *request;
211 struct ptlrpc_client *cl;
212 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
213 struct ptlrpc_connection *connection;
214 struct ost_body *body;
215 int rc, size = sizeof(*body);
218 osc_con2cl(conn, &cl, &connection);
219 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
220 OST_CLOSE, 1, &size, NULL);
224 body = lustre_msg_buf(request->rq_reqmsg, 0);
225 memcpy(&body->oa, oa, sizeof(*oa));
227 request->rq_replen = lustre_msg_size(1, &size);
229 rc = ptlrpc_queue_wait(request);
230 rc = ptlrpc_check_status(request, rc);
234 body = lustre_msg_buf(request->rq_repmsg, 0);
235 CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
237 memcpy(oa, &body->oa, sizeof(*oa));
241 ptlrpc_free_req(request);
245 static int osc_setattr(struct lustre_handle *conn, struct obdo *oa)
247 struct ptlrpc_request *request;
248 struct ptlrpc_client *cl;
249 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
250 struct ptlrpc_connection *connection;
251 struct ost_body *body;
252 int rc, size = sizeof(*body);
255 osc_con2cl(conn, &cl, &connection);
256 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
257 OST_SETATTR, 1, &size, NULL);
261 body = lustre_msg_buf(request->rq_reqmsg, 0);
262 memcpy(&body->oa, oa, sizeof(*oa));
264 request->rq_replen = lustre_msg_size(1, &size);
266 rc = ptlrpc_queue_wait(request);
267 rc = ptlrpc_check_status(request, rc);
271 ptlrpc_free_req(request);
275 static int osc_create(struct lustre_handle *conn, struct obdo *oa)
277 struct ptlrpc_request *request;
278 struct ptlrpc_client *cl;
279 struct ptlrpc_connection *connection;
280 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
281 struct ost_body *body;
282 struct mds_objid *objid;
283 struct lov_object_id *lov_id;
284 int rc, size = sizeof(*body);
291 osc_con2cl(conn, &cl, &connection);
292 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
293 OST_CREATE, 1, &size, NULL);
297 body = lustre_msg_buf(request->rq_reqmsg, 0);
298 memcpy(&body->oa, oa, sizeof(*oa));
300 request->rq_replen = lustre_msg_size(1, &size);
302 rc = ptlrpc_queue_wait(request);
303 rc = ptlrpc_check_status(request, rc);
307 body = lustre_msg_buf(request->rq_repmsg, 0);
308 memcpy(oa, &body->oa, sizeof(*oa));
310 memset(oa->o_inline, 0, sizeof(oa->o_inline));
311 objid = (struct mds_objid *)oa->o_inline;
312 objid->mo_lov_md.lmd_object_id = oa->o_id;
313 objid->mo_lov_md.lmd_stripe_count = 1;
314 lov_id = (struct lov_object_id *)(oa->o_inline + sizeof(*objid));
315 lov_id->l_device_id = 0;
316 lov_id->l_object_id = oa->o_id;
320 ptlrpc_free_req(request);
324 static int osc_punch(struct lustre_handle *conn, struct obdo *oa, obd_size count,
327 struct ptlrpc_request *request;
328 struct ptlrpc_client *cl;
329 struct ptlrpc_connection *connection;
330 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
331 struct ost_body *body;
332 int rc, size = sizeof(*body);
339 osc_con2cl(conn, &cl, &connection);
340 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
341 OST_PUNCH, 1, &size, NULL);
345 body = lustre_msg_buf(request->rq_reqmsg, 0);
346 memcpy(&body->oa, oa, sizeof(*oa));
347 body->oa.o_blocks = count;
348 body->oa.o_valid |= OBD_MD_FLBLOCKS;
350 request->rq_replen = lustre_msg_size(1, &size);
352 rc = ptlrpc_queue_wait(request);
353 rc = ptlrpc_check_status(request, rc);
357 body = lustre_msg_buf(request->rq_repmsg, 0);
358 memcpy(oa, &body->oa, sizeof(*oa));
362 ptlrpc_free_req(request);
366 static int osc_destroy(struct lustre_handle *conn, struct obdo *oa)
368 struct ptlrpc_request *request;
369 struct ptlrpc_client *cl;
370 struct ptlrpc_connection *connection;
371 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
372 struct ost_body *body;
373 int rc, size = sizeof(*body);
380 osc_con2cl(conn, &cl, &connection);
381 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
382 OST_DESTROY, 1, &size, NULL);
386 body = lustre_msg_buf(request->rq_reqmsg, 0);
387 memcpy(&body->oa, oa, sizeof(*oa));
388 body->oa.o_valid = ~0;
390 request->rq_replen = lustre_msg_size(1, &size);
392 rc = ptlrpc_queue_wait(request);
393 rc = ptlrpc_check_status(request, rc);
397 body = lustre_msg_buf(request->rq_repmsg, 0);
398 memcpy(oa, &body->oa, sizeof(*oa));
402 ptlrpc_free_req(request);
406 struct osc_brw_cb_data {
408 struct ptlrpc_request *req;
409 bulk_callback_t callback;
413 static void brw_read_finish(struct ptlrpc_bulk_desc *desc, void *data)
415 struct osc_brw_cb_data *cb_data = data;
417 if (desc->b_flags & PTL_RPC_FL_INTR)
418 CERROR("got signal\n");
420 (cb_data->callback)(desc, cb_data->cb_data);
422 ptlrpc_free_bulk(desc);
423 ptlrpc_free_req(cb_data->req);
425 OBD_FREE(cb_data, sizeof(*cb_data));
428 static int osc_brw_read(struct lustre_handle *conn, obd_count num_oa,
429 struct obdo **oa, obd_count *oa_bufs, struct page **buf,
430 obd_size *count, obd_off *offset, obd_flag *flags,
431 bulk_callback_t callback)
433 struct ptlrpc_client *cl;
434 struct ptlrpc_connection *connection;
435 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
436 struct ptlrpc_request *request;
437 struct ost_body *body;
438 struct list_head *tmp;
439 int pages, rc, i, j, size[3] = {sizeof(*body)};
441 struct ptlrpc_bulk_desc *desc;
444 size[1] = num_oa * sizeof(struct obd_ioobj);
446 for (i = 0; i < num_oa; i++)
448 size[2] = pages * sizeof(struct niobuf_remote);
450 osc_con2cl(conn, &cl, &connection);
451 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
452 OST_BRW, 3, size, NULL);
454 GOTO(out, rc = -ENOMEM);
456 body = lustre_msg_buf(request->rq_reqmsg, 0);
457 body->data = OBD_BRW_READ;
459 desc = ptlrpc_prep_bulk(connection);
461 GOTO(out2, rc = -ENOMEM);
462 desc->b_portal = OST_BULK_PORTAL;
464 ptr1 = lustre_msg_buf(request->rq_reqmsg, 1);
465 ptr2 = lustre_msg_buf(request->rq_reqmsg, 2);
466 for (pages = 0, i = 0; i < num_oa; i++) {
467 ost_pack_ioo(&ptr1, oa[i], oa_bufs[i]);
468 /* FIXME: this inner loop is wrong for multiple OAs */
469 for (j = 0; j < oa_bufs[i]; j++, pages++) {
470 struct ptlrpc_bulk_page *bulk;
471 bulk = ptlrpc_prep_bulk_page(desc);
473 GOTO(out3, rc = -ENOMEM);
475 spin_lock(&connection->c_lock);
476 bulk->b_xid = ++connection->c_xid_out;
477 spin_unlock(&connection->c_lock);
479 bulk->b_buf = kmap(buf[pages]);
480 bulk->b_page = buf[pages];
481 bulk->b_buflen = PAGE_SIZE;
482 ost_pack_niobuf(&ptr2, offset[pages], count[pages],
483 flags[pages], bulk->b_xid);
487 rc = ptlrpc_register_bulk(desc);
491 request->rq_replen = lustre_msg_size(1, size);
492 rc = ptlrpc_queue_wait(request);
493 rc = ptlrpc_check_status(request, rc);
495 ptlrpc_abort_bulk(desc);
499 list_for_each(tmp, &desc->b_page_list) {
500 struct ptlrpc_bulk_page *bulk;
501 bulk = list_entry(tmp, struct ptlrpc_bulk_page, b_link);
502 if (bulk->b_page != NULL)
503 kunmap(bulk->b_page);
505 ptlrpc_free_bulk(desc);
507 ptlrpc_free_req(request);
512 static void brw_write_finish(struct ptlrpc_bulk_desc *desc, void *data)
514 struct osc_brw_cb_data *cb_data = data;
518 if (desc->b_flags & PTL_RPC_FL_INTR)
519 CERROR("got signal\n");
521 for (i = 0; i < desc->b_page_count; i++)
522 kunmap(cb_data->buf[i]);
524 (cb_data->callback)(desc, cb_data->cb_data);
526 ptlrpc_free_bulk(desc);
527 ptlrpc_free_req(cb_data->req);
529 OBD_FREE(cb_data, sizeof(*cb_data));
533 static int osc_brw_write(struct lustre_handle *conn, obd_count num_oa,
534 struct obdo **oa, obd_count *oa_bufs,
535 struct page **pagearray, obd_size *count,
536 obd_off *offset, obd_flag *flags,
537 bulk_callback_t callback)
539 struct ptlrpc_client *cl;
540 struct ptlrpc_connection *connection;
541 struct ptlrpc_request *request;
542 struct ptlrpc_bulk_desc *desc;
543 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
544 struct obd_ioobj ioo;
545 struct ost_body *body;
546 struct niobuf_local *local;
547 struct niobuf_remote *remote;
548 struct osc_brw_cb_data *cb_data;
550 int rc, i, j, size[3] = {sizeof(*body)};
554 size[1] = num_oa * sizeof(ioo);
556 for (i = 0; i < num_oa; i++)
558 size[2] = pages * sizeof(*remote);
560 OBD_ALLOC(local, pages * sizeof(*local));
564 osc_con2cl(conn, &cl, &connection);
565 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
566 OST_BRW, 3, size, NULL);
568 GOTO(out, rc = -ENOMEM);
569 body = lustre_msg_buf(request->rq_reqmsg, 0);
570 body->data = OBD_BRW_WRITE;
572 ptr1 = lustre_msg_buf(request->rq_reqmsg, 1);
573 ptr2 = lustre_msg_buf(request->rq_reqmsg, 2);
574 for (pages = 0, i = 0; i < num_oa; i++) {
575 ost_pack_ioo(&ptr1, oa[i], oa_bufs[i]);
576 for (j = 0; j < oa_bufs[i]; j++, pages++) {
577 local[pages].addr = kmap(pagearray[pages]);
578 local[pages].offset = offset[pages];
579 local[pages].len = count[pages];
580 ost_pack_niobuf(&ptr2, offset[pages], count[pages],
585 size[1] = pages * sizeof(struct niobuf_remote);
586 request->rq_replen = lustre_msg_size(2, size);
588 rc = ptlrpc_queue_wait(request);
589 rc = ptlrpc_check_status(request, rc);
593 ptr2 = lustre_msg_buf(request->rq_repmsg, 1);
595 GOTO(out2, rc = -EINVAL);
597 if (request->rq_repmsg->buflens[1] !=
598 pages * sizeof(struct niobuf_remote)) {
599 CERROR("buffer length wrong (%d vs. %ld)\n",
600 request->rq_repmsg->buflens[1],
601 pages * sizeof(struct niobuf_remote));
602 GOTO(out2, rc = -EINVAL);
605 desc = ptlrpc_prep_bulk(connection);
606 desc->b_portal = OSC_BULK_PORTAL;
608 desc->b_cb = brw_write_finish;
609 OBD_ALLOC(cb_data, sizeof(*cb_data));
610 cb_data->buf = pagearray;
611 cb_data->callback = callback;
612 desc->b_cb_data = cb_data;
615 for (pages = 0, i = 0; i < num_oa; i++) {
616 for (j = 0; j < oa_bufs[i]; j++, pages++) {
617 struct ptlrpc_bulk_page *page;
619 ost_unpack_niobuf(&ptr2, &remote);
621 page = ptlrpc_prep_bulk_page(desc);
623 GOTO(out3, rc = -ENOMEM);
625 page->b_buf = (void *)(unsigned long)local[pages].addr;
626 page->b_buflen = local[pages].len;
627 page->b_xid = remote->xid;
631 if (desc->b_page_count != pages)
634 rc = ptlrpc_send_bulk(desc);
640 /* If there's no callback function, sleep here until complete. */
641 wait_event_interruptible(desc->b_waitq, ptlrpc_check_bulk_sent(desc));
642 if (desc->b_flags & PTL_RPC_FL_INTR)
648 ptlrpc_free_bulk(desc);
650 ptlrpc_free_req(request);
651 for (pages = 0, i = 0; i < num_oa; i++)
652 for (j = 0; j < oa_bufs[i]; j++, pages++)
653 kunmap(pagearray[pages]);
655 OBD_FREE(local, pages * sizeof(*local));
660 static int osc_brw(int cmd, struct lustre_handle *conn, obd_count num_oa,
661 struct obdo **oa, obd_count *oa_bufs, struct page **buf,
662 obd_size *count, obd_off *offset, obd_flag *flags,
668 if (cmd & OBD_BRW_WRITE)
669 return osc_brw_write(conn, num_oa, oa, oa_bufs, buf, count,
670 offset, flags, (bulk_callback_t)callback);
672 return osc_brw_read(conn, num_oa, oa, oa_bufs, buf, count,
673 offset, flags, (bulk_callback_t)callback);
676 static int osc_enqueue(struct lustre_handle *oconn,
677 struct lustre_handle *parent_lock, __u64 *res_id,
678 __u32 type, void *extentp, int extent_len, __u32 mode,
679 int *flags, void *callback, void *data, int datalen,
680 struct lustre_handle *lockh)
682 struct obd_device *obddev = class_conn2obd(oconn);
683 struct osc_obd *osc = &obddev->u.osc;
684 struct ptlrpc_connection *conn;
685 struct ptlrpc_client *cl;
686 struct ldlm_extent *extent = extentp;
690 /* Filesystem locks are given a bit of special treatment: first we
691 * fixup the lock to start and end on page boundaries. */
692 extent->start &= PAGE_MASK;
693 extent->end = (extent->end + PAGE_SIZE - 1) & PAGE_MASK;
695 /* Next, search for already existing extent locks that will cover us */
696 osc_con2dlmcl(oconn, &cl, &conn);
697 rc = ldlm_lock_match(obddev->obd_namespace, res_id, type, extent,
698 sizeof(extent), mode, lockh);
700 /* We already have a lock, and it's referenced */
704 /* Next, search for locks that we can upgrade (if we're trying to write)
705 * or are more than we need (if we're trying to read). Because the VFS
706 * and page cache already protect us locally, lots of readers/writers
707 * can share a single PW lock. */
713 rc = ldlm_lock_match(obddev->obd_namespace, res_id, type, extent,
714 sizeof(extent), mode2, lockh);
717 /* FIXME: This is not incredibly elegant, but it might
718 * be more elegant than adding another parameter to
719 * lock_match. I want a second opinion. */
720 ldlm_lock_addref(lockh, mode);
721 ldlm_lock_decref(lockh, mode2);
726 rc = ldlm_cli_convert(cl, lockh, &osc->osc_connh,
734 rc = ldlm_cli_enqueue(cl, conn, &osc->osc_connh,
735 NULL, obddev->obd_namespace,
736 parent_lock, res_id, type, extent, sizeof(extent),
737 mode, flags, callback, data, datalen, lockh);
741 static int osc_cancel(struct lustre_handle *oconn, __u32 mode,
742 struct lustre_handle *lockh)
746 ldlm_lock_decref(lockh, mode);
751 static int osc_setup(struct obd_device *obddev, obd_count len, void *buf)
753 struct obd_ioctl_data* data = buf;
754 struct osc_obd *osc = &obddev->u.osc;
755 char server_uuid[37];
759 if (data->ioc_inllen1 < 1) {
760 CERROR("osc setup requires a TARGET UUID\n");
764 if (data->ioc_inllen1 > 37) {
765 CERROR("osc TARGET UUID must be less than 38 characters\n");
769 if (data->ioc_inllen2 < 1) {
770 CERROR("osc setup requires a SERVER UUID\n");
774 if (data->ioc_inllen2 > 37) {
775 CERROR("osc SERVER UUID must be less than 38 characters\n");
779 memcpy(osc->osc_target_uuid, data->ioc_inlbuf1, data->ioc_inllen1);
780 memcpy(server_uuid, data->ioc_inlbuf2, MIN(data->ioc_inllen2,
781 sizeof(server_uuid)));
783 osc->osc_conn = ptlrpc_uuid_to_connection(server_uuid);
787 obddev->obd_namespace =
788 ldlm_namespace_new("osc", LDLM_NAMESPACE_CLIENT);
789 if (obddev->obd_namespace == NULL)
790 GOTO(out_conn, rc = -ENOMEM);
792 OBD_ALLOC(osc->osc_client, sizeof(*osc->osc_client));
793 if (osc->osc_client == NULL)
794 GOTO(out_ns, rc = -ENOMEM);
796 OBD_ALLOC(osc->osc_ldlm_client, sizeof(*osc->osc_ldlm_client));
797 if (osc->osc_ldlm_client == NULL)
798 GOTO(out_client, rc = -ENOMEM);
800 ptlrpc_init_client(NULL, NULL, OST_REQUEST_PORTAL, OSC_REPLY_PORTAL,
802 ptlrpc_init_client(NULL, NULL, LDLM_REQUEST_PORTAL, LDLM_REPLY_PORTAL,
803 osc->osc_ldlm_client);
804 osc->osc_client->cli_name = "osc";
805 osc->osc_ldlm_client->cli_name = "ldlm";
811 OBD_FREE(osc->osc_client, sizeof(*osc->osc_client));
813 ldlm_namespace_free(obddev->obd_namespace);
815 ptlrpc_put_connection(osc->osc_conn);
819 static int osc_cleanup(struct obd_device * obddev)
821 struct osc_obd *osc = &obddev->u.osc;
823 ldlm_namespace_free(obddev->obd_namespace);
825 ptlrpc_cleanup_client(osc->osc_client);
826 OBD_FREE(osc->osc_client, sizeof(*osc->osc_client));
827 ptlrpc_cleanup_client(osc->osc_ldlm_client);
828 OBD_FREE(osc->osc_ldlm_client, sizeof(*osc->osc_ldlm_client));
829 ptlrpc_put_connection(osc->osc_conn);
836 static int osc_statfs(struct lustre_handle *conn, struct statfs *sfs);
838 struct ptlrpc_request *request;
839 struct ptlrpc_client *cl;
840 struct ptlrpc_connection *connection;
841 struct obd_statfs *osfs;
842 int rc, size = sizeof(*osfs);
845 osc_con2cl(conn, &cl, &connection);
846 request = ptlrpc_prep_req(cl, connection, OST_STATFS, 0, NULL, NULL);
850 request->rq_replen = lustre_msg_size(1, &size);
852 rc = ptlrpc_queue_wait(request);
853 rc = ptlrpc_check_status(request, rc);
857 osfs = lustre_msg_buf(request->rq_repmsg, 0);
858 obd_statfs_unpack(sfs, osfs);
862 ptlrpc_free_req(request);
867 struct obd_ops osc_obd_ops = {
869 o_cleanup: osc_cleanup,
870 o_create: osc_create,
871 o_destroy: osc_destroy,
872 o_getattr: osc_getattr,
873 o_setattr: osc_setattr,
876 o_connect: osc_connect,
877 o_disconnect: osc_disconnect,
880 o_enqueue: osc_enqueue,
884 static int __init osc_init(void)
886 return class_register_type(&osc_obd_ops, LUSTRE_OSC_NAME);
889 static void __exit osc_exit(void)
891 class_unregister_type(LUSTRE_OSC_NAME);
894 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
895 MODULE_DESCRIPTION("Lustre Object Storage Client (OSC) v1.0");
896 MODULE_LICENSE("GPL");
898 module_init(osc_init);
899 module_exit(osc_exit);