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_con2cl(struct lustre_handle *conn, struct ptlrpc_client **cl,
29 struct ptlrpc_connection **connection)
31 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
32 *cl = osc->osc_client;
33 *connection = osc->osc_conn;
36 static void osc_con2dlmcl(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_ldlm_client;
41 *connection = osc->osc_conn;
44 static int osc_connect(struct lustre_handle *conn, struct obd_device *obd)
46 struct osc_obd *osc = &obd->u.osc;
47 struct obd_import *import;
48 struct ptlrpc_request *request;
49 char *tmp = osc->osc_target_uuid;
50 int rc, size = sizeof(osc->osc_target_uuid);
53 OBD_ALLOC(import, sizeof(*import));
58 rc = class_connect(conn, obd);
62 request = ptlrpc_prep_req(osc->osc_client, osc->osc_conn,
63 OST_CONNECT, 1, &size, &tmp);
65 GOTO(out_disco, rc = -ENOMEM);
67 request->rq_level = LUSTRE_CONN_NEW;
68 request->rq_replen = lustre_msg_size(0, NULL);
70 rc = ptlrpc_queue_wait(request);
71 rc = ptlrpc_check_status(request, rc);
73 CERROR("%s failed: rc = %d\n", __FUNCTION__, rc);
77 /* XXX: Make this a handle */
78 osc->osc_connh.addr = request->rq_repmsg->addr;
79 osc->osc_connh.cookie = request->rq_repmsg->cookie;
83 ptlrpc_free_req(request);
86 class_disconnect(conn);
92 static int osc_disconnect(struct lustre_handle *conn)
94 struct ptlrpc_request *request;
95 struct ptlrpc_client *cl;
96 struct ptlrpc_connection *connection;
97 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
101 osc_con2cl(conn, &cl, &connection);
102 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
103 OST_DISCONNECT, 0, NULL, NULL);
106 request->rq_replen = lustre_msg_size(0, NULL);
108 rc = ptlrpc_queue_wait(request);
111 rc = class_disconnect(conn);
116 ptlrpc_free_req(request);
120 static int osc_getattr(struct lustre_handle *conn, struct obdo *oa)
122 struct ptlrpc_request *request;
123 struct ptlrpc_client *cl;
124 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
125 struct ptlrpc_connection *connection;
126 struct ost_body *body;
127 int rc, size = sizeof(*body);
130 osc_con2cl(conn, &cl, &connection);
131 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
132 OST_GETATTR, 1, &size, NULL);
136 body = lustre_msg_buf(request->rq_reqmsg, 0);
137 memcpy(&body->oa, oa, sizeof(*oa));
138 body->oa.o_valid = ~0;
140 request->rq_replen = lustre_msg_size(1, &size);
142 rc = ptlrpc_queue_wait(request);
143 rc = ptlrpc_check_status(request, rc);
145 CERROR("%s failed: rc = %d\n", __FUNCTION__, rc);
149 body = lustre_msg_buf(request->rq_repmsg, 0);
150 CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
152 memcpy(oa, &body->oa, sizeof(*oa));
156 ptlrpc_free_req(request);
160 static int osc_open(struct lustre_handle *conn, struct obdo *oa)
162 struct ptlrpc_request *request;
163 struct ptlrpc_client *cl;
164 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
165 struct ptlrpc_connection *connection;
166 struct ost_body *body;
167 int rc, size = sizeof(*body);
170 osc_con2cl(conn, &cl, &connection);
171 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
172 OST_OPEN, 1, &size, NULL);
176 body = lustre_msg_buf(request->rq_reqmsg, 0);
177 memcpy(&body->oa, oa, sizeof(*oa));
178 body->oa.o_valid = (OBD_MD_FLMODE | OBD_MD_FLID);
180 request->rq_replen = lustre_msg_size(1, &size);
182 rc = ptlrpc_queue_wait(request);
183 rc = ptlrpc_check_status(request, rc);
187 body = lustre_msg_buf(request->rq_repmsg, 0);
188 CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
190 memcpy(oa, &body->oa, sizeof(*oa));
194 ptlrpc_free_req(request);
198 static int osc_close(struct lustre_handle *conn, struct obdo *oa)
200 struct ptlrpc_request *request;
201 struct ptlrpc_client *cl;
202 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
203 struct ptlrpc_connection *connection;
204 struct ost_body *body;
205 int rc, size = sizeof(*body);
208 osc_con2cl(conn, &cl, &connection);
209 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
210 OST_CLOSE, 1, &size, NULL);
214 body = lustre_msg_buf(request->rq_reqmsg, 0);
215 memcpy(&body->oa, oa, sizeof(*oa));
217 request->rq_replen = lustre_msg_size(1, &size);
219 rc = ptlrpc_queue_wait(request);
220 rc = ptlrpc_check_status(request, rc);
224 body = lustre_msg_buf(request->rq_repmsg, 0);
225 CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
227 memcpy(oa, &body->oa, sizeof(*oa));
231 ptlrpc_free_req(request);
235 static int osc_setattr(struct lustre_handle *conn, struct obdo *oa)
237 struct ptlrpc_request *request;
238 struct ptlrpc_client *cl;
239 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
240 struct ptlrpc_connection *connection;
241 struct ost_body *body;
242 int rc, size = sizeof(*body);
245 osc_con2cl(conn, &cl, &connection);
246 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
247 OST_SETATTR, 1, &size, NULL);
251 body = lustre_msg_buf(request->rq_reqmsg, 0);
252 memcpy(&body->oa, oa, sizeof(*oa));
254 request->rq_replen = lustre_msg_size(1, &size);
256 rc = ptlrpc_queue_wait(request);
257 rc = ptlrpc_check_status(request, rc);
261 ptlrpc_free_req(request);
265 static int osc_create(struct lustre_handle *conn, struct obdo *oa)
267 struct ptlrpc_request *request;
268 struct ptlrpc_client *cl;
269 struct ptlrpc_connection *connection;
270 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
271 struct ost_body *body;
272 struct mds_objid *objid;
273 struct lov_object_id *lov_id;
274 int rc, size = sizeof(*body);
281 osc_con2cl(conn, &cl, &connection);
282 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
283 OST_CREATE, 1, &size, NULL);
287 body = lustre_msg_buf(request->rq_reqmsg, 0);
288 memcpy(&body->oa, oa, sizeof(*oa));
290 request->rq_replen = lustre_msg_size(1, &size);
292 rc = ptlrpc_queue_wait(request);
293 rc = ptlrpc_check_status(request, rc);
297 body = lustre_msg_buf(request->rq_repmsg, 0);
298 memcpy(oa, &body->oa, sizeof(*oa));
300 memset(oa->o_inline, 0, sizeof(oa->o_inline));
301 objid = (struct mds_objid *)oa->o_inline;
302 objid->mo_lov_md.lmd_object_id = oa->o_id;
303 objid->mo_lov_md.lmd_stripe_count = 1;
304 lov_id = (struct lov_object_id *)(oa->o_inline + sizeof(*objid));
305 lov_id->l_device_id = 0;
306 lov_id->l_object_id = oa->o_id;
310 ptlrpc_free_req(request);
314 static int osc_punch(struct lustre_handle *conn, struct obdo *oa, obd_size count,
317 struct ptlrpc_request *request;
318 struct ptlrpc_client *cl;
319 struct ptlrpc_connection *connection;
320 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
321 struct ost_body *body;
322 int rc, size = sizeof(*body);
329 osc_con2cl(conn, &cl, &connection);
330 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
331 OST_PUNCH, 1, &size, NULL);
335 body = lustre_msg_buf(request->rq_reqmsg, 0);
336 memcpy(&body->oa, oa, sizeof(*oa));
337 body->oa.o_blocks = count;
338 body->oa.o_valid |= OBD_MD_FLBLOCKS;
340 request->rq_replen = lustre_msg_size(1, &size);
342 rc = ptlrpc_queue_wait(request);
343 rc = ptlrpc_check_status(request, rc);
347 body = lustre_msg_buf(request->rq_repmsg, 0);
348 memcpy(oa, &body->oa, sizeof(*oa));
352 ptlrpc_free_req(request);
356 static int osc_destroy(struct lustre_handle *conn, struct obdo *oa)
358 struct ptlrpc_request *request;
359 struct ptlrpc_client *cl;
360 struct ptlrpc_connection *connection;
361 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
362 struct ost_body *body;
363 int rc, size = sizeof(*body);
370 osc_con2cl(conn, &cl, &connection);
371 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
372 OST_DESTROY, 1, &size, NULL);
376 body = lustre_msg_buf(request->rq_reqmsg, 0);
377 memcpy(&body->oa, oa, sizeof(*oa));
378 body->oa.o_valid = ~0;
380 request->rq_replen = lustre_msg_size(1, &size);
382 rc = ptlrpc_queue_wait(request);
383 rc = ptlrpc_check_status(request, rc);
387 body = lustre_msg_buf(request->rq_repmsg, 0);
388 memcpy(oa, &body->oa, sizeof(*oa));
392 ptlrpc_free_req(request);
396 struct osc_brw_cb_data {
398 struct ptlrpc_request *req;
399 bulk_callback_t callback;
403 static void brw_read_finish(struct ptlrpc_bulk_desc *desc, void *data)
405 struct osc_brw_cb_data *cb_data = data;
407 if (desc->b_flags & PTL_RPC_FL_INTR)
408 CERROR("got signal\n");
410 (cb_data->callback)(desc, cb_data->cb_data);
412 ptlrpc_free_bulk(desc);
413 ptlrpc_free_req(cb_data->req);
415 OBD_FREE(cb_data, sizeof(*cb_data));
418 static int osc_brw_read(struct lustre_handle *conn, obd_count num_oa,
419 struct obdo **oa, obd_count *oa_bufs, struct page **buf,
420 obd_size *count, obd_off *offset, obd_flag *flags,
421 bulk_callback_t callback)
423 struct ptlrpc_client *cl;
424 struct ptlrpc_connection *connection;
425 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
426 struct ptlrpc_request *request;
427 struct ost_body *body;
428 struct list_head *tmp;
429 int pages, rc, i, j, size[3] = {sizeof(*body)};
431 struct ptlrpc_bulk_desc *desc;
434 size[1] = num_oa * sizeof(struct obd_ioobj);
436 for (i = 0; i < num_oa; i++)
438 size[2] = pages * sizeof(struct niobuf_remote);
440 osc_con2cl(conn, &cl, &connection);
441 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
442 OST_BRW, 3, size, NULL);
444 GOTO(out, rc = -ENOMEM);
446 body = lustre_msg_buf(request->rq_reqmsg, 0);
447 body->data = OBD_BRW_READ;
449 desc = ptlrpc_prep_bulk(connection);
451 GOTO(out2, rc = -ENOMEM);
452 desc->b_portal = OST_BULK_PORTAL;
454 ptr1 = lustre_msg_buf(request->rq_reqmsg, 1);
455 ptr2 = lustre_msg_buf(request->rq_reqmsg, 2);
456 for (pages = 0, i = 0; i < num_oa; i++) {
457 ost_pack_ioo(&ptr1, oa[i], oa_bufs[i]);
458 /* FIXME: this inner loop is wrong for multiple OAs */
459 for (j = 0; j < oa_bufs[i]; j++, pages++) {
460 struct ptlrpc_bulk_page *bulk;
461 bulk = ptlrpc_prep_bulk_page(desc);
463 GOTO(out3, rc = -ENOMEM);
465 spin_lock(&connection->c_lock);
466 bulk->b_xid = ++connection->c_xid_out;
467 spin_unlock(&connection->c_lock);
469 bulk->b_buf = kmap(buf[pages]);
470 bulk->b_page = buf[pages];
471 bulk->b_buflen = PAGE_SIZE;
472 ost_pack_niobuf(&ptr2, offset[pages], count[pages],
473 flags[pages], bulk->b_xid);
477 rc = ptlrpc_register_bulk(desc);
481 request->rq_replen = lustre_msg_size(1, size);
482 rc = ptlrpc_queue_wait(request);
483 rc = ptlrpc_check_status(request, rc);
485 ptlrpc_abort_bulk(desc);
489 list_for_each(tmp, &desc->b_page_list) {
490 struct ptlrpc_bulk_page *bulk;
491 bulk = list_entry(tmp, struct ptlrpc_bulk_page, b_link);
492 if (bulk->b_page != NULL)
493 kunmap(bulk->b_page);
495 ptlrpc_free_bulk(desc);
497 ptlrpc_free_req(request);
502 static void brw_write_finish(struct ptlrpc_bulk_desc *desc, void *data)
504 struct osc_brw_cb_data *cb_data = data;
508 if (desc->b_flags & PTL_RPC_FL_INTR)
509 CERROR("got signal\n");
511 for (i = 0; i < desc->b_page_count; i++)
512 kunmap(cb_data->buf[i]);
514 (cb_data->callback)(desc, cb_data->cb_data);
516 ptlrpc_free_bulk(desc);
517 ptlrpc_free_req(cb_data->req);
519 OBD_FREE(cb_data, sizeof(*cb_data));
523 static int osc_brw_write(struct lustre_handle *conn, obd_count num_oa,
524 struct obdo **oa, obd_count *oa_bufs,
525 struct page **pagearray, obd_size *count,
526 obd_off *offset, obd_flag *flags,
527 bulk_callback_t callback)
529 struct ptlrpc_client *cl;
530 struct ptlrpc_connection *connection;
531 struct ptlrpc_request *request;
532 struct ptlrpc_bulk_desc *desc;
533 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
534 struct obd_ioobj ioo;
535 struct ost_body *body;
536 struct niobuf_local *local;
537 struct niobuf_remote *remote;
538 struct osc_brw_cb_data *cb_data;
540 int rc, i, j, size[3] = {sizeof(*body)};
544 size[1] = num_oa * sizeof(ioo);
546 for (i = 0; i < num_oa; i++)
548 size[2] = pages * sizeof(*remote);
550 OBD_ALLOC(local, pages * sizeof(*local));
554 osc_con2cl(conn, &cl, &connection);
555 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
556 OST_BRW, 3, size, NULL);
558 GOTO(out, rc = -ENOMEM);
559 body = lustre_msg_buf(request->rq_reqmsg, 0);
560 body->data = OBD_BRW_WRITE;
562 ptr1 = lustre_msg_buf(request->rq_reqmsg, 1);
563 ptr2 = lustre_msg_buf(request->rq_reqmsg, 2);
564 for (pages = 0, i = 0; i < num_oa; i++) {
565 ost_pack_ioo(&ptr1, oa[i], oa_bufs[i]);
566 for (j = 0; j < oa_bufs[i]; j++, pages++) {
567 local[pages].addr = kmap(pagearray[pages]);
568 local[pages].offset = offset[pages];
569 local[pages].len = count[pages];
570 ost_pack_niobuf(&ptr2, offset[pages], count[pages],
575 size[1] = pages * sizeof(struct niobuf_remote);
576 request->rq_replen = lustre_msg_size(2, size);
578 rc = ptlrpc_queue_wait(request);
579 rc = ptlrpc_check_status(request, rc);
583 ptr2 = lustre_msg_buf(request->rq_repmsg, 1);
585 GOTO(out2, rc = -EINVAL);
587 if (request->rq_repmsg->buflens[1] !=
588 pages * sizeof(struct niobuf_remote)) {
589 CERROR("buffer length wrong (%d vs. %ld)\n",
590 request->rq_repmsg->buflens[1],
591 pages * sizeof(struct niobuf_remote));
592 GOTO(out2, rc = -EINVAL);
595 desc = ptlrpc_prep_bulk(connection);
596 desc->b_portal = OSC_BULK_PORTAL;
598 desc->b_cb = brw_write_finish;
599 OBD_ALLOC(cb_data, sizeof(*cb_data));
600 cb_data->buf = pagearray;
601 cb_data->callback = callback;
602 desc->b_cb_data = cb_data;
605 for (pages = 0, i = 0; i < num_oa; i++) {
606 for (j = 0; j < oa_bufs[i]; j++, pages++) {
607 struct ptlrpc_bulk_page *page;
609 ost_unpack_niobuf(&ptr2, &remote);
611 page = ptlrpc_prep_bulk_page(desc);
613 GOTO(out3, rc = -ENOMEM);
615 page->b_buf = (void *)(unsigned long)local[pages].addr;
616 page->b_buflen = local[pages].len;
617 page->b_xid = remote->xid;
621 if (desc->b_page_count != pages)
624 rc = ptlrpc_send_bulk(desc);
630 /* If there's no callback function, sleep here until complete. */
631 l_wait_event_killable(desc->b_waitq, ptlrpc_check_bulk_sent(desc));
632 if (desc->b_flags & PTL_RPC_FL_INTR)
638 ptlrpc_free_bulk(desc);
640 ptlrpc_free_req(request);
641 for (pages = 0, i = 0; i < num_oa; i++)
642 for (j = 0; j < oa_bufs[i]; j++, pages++)
643 kunmap(pagearray[pages]);
645 OBD_FREE(local, pages * sizeof(*local));
650 static int osc_brw(int cmd, struct lustre_handle *conn, obd_count num_oa,
651 struct obdo **oa, obd_count *oa_bufs, struct page **buf,
652 obd_size *count, obd_off *offset, obd_flag *flags,
658 if (cmd & OBD_BRW_WRITE)
659 return osc_brw_write(conn, num_oa, oa, oa_bufs, buf, count,
660 offset, flags, (bulk_callback_t)callback);
662 return osc_brw_read(conn, num_oa, oa, oa_bufs, buf, count,
663 offset, flags, (bulk_callback_t)callback);
666 static int osc_enqueue(struct lustre_handle *oconn,
667 struct lustre_handle *parent_lock, __u64 *res_id,
668 __u32 type, void *extentp, int extent_len, __u32 mode,
669 int *flags, void *callback, void *data, int datalen,
670 struct lustre_handle *lockh)
672 struct obd_device *obddev = class_conn2obd(oconn);
673 struct osc_obd *osc = &obddev->u.osc;
674 struct ptlrpc_connection *conn;
675 struct ptlrpc_client *cl;
676 struct ldlm_extent *extent = extentp;
680 /* Filesystem locks are given a bit of special treatment: first we
681 * fixup the lock to start and end on page boundaries. */
682 extent->start &= PAGE_MASK;
683 extent->end = (extent->end + PAGE_SIZE - 1) & PAGE_MASK;
685 /* Next, search for already existing extent locks that will cover us */
686 osc_con2dlmcl(oconn, &cl, &conn);
687 rc = ldlm_lock_match(obddev->obd_namespace, res_id, type, extent,
688 sizeof(extent), mode, lockh);
690 /* We already have a lock, and it's referenced */
694 /* Next, search for locks that we can upgrade (if we're trying to write)
695 * or are more than we need (if we're trying to read). Because the VFS
696 * and page cache already protect us locally, lots of readers/writers
697 * can share a single PW lock. */
703 rc = ldlm_lock_match(obddev->obd_namespace, res_id, type, extent,
704 sizeof(extent), mode2, lockh);
707 /* FIXME: This is not incredibly elegant, but it might
708 * be more elegant than adding another parameter to
709 * lock_match. I want a second opinion. */
710 ldlm_lock_addref(lockh, mode);
711 ldlm_lock_decref(lockh, mode2);
716 rc = ldlm_cli_convert(cl, lockh, &osc->osc_connh,
724 rc = ldlm_cli_enqueue(cl, conn, &osc->osc_connh,
725 NULL, obddev->obd_namespace,
726 parent_lock, res_id, type, extent, sizeof(extent),
727 mode, flags, callback, data, datalen, lockh);
731 static int osc_cancel(struct lustre_handle *oconn, __u32 mode,
732 struct lustre_handle *lockh)
736 ldlm_lock_decref(lockh, mode);
741 static int osc_setup(struct obd_device *obddev, obd_count len, void *buf)
743 struct obd_ioctl_data* data = buf;
744 struct osc_obd *osc = &obddev->u.osc;
745 char server_uuid[37];
749 if (data->ioc_inllen1 < 1) {
750 CERROR("osc setup requires a TARGET UUID\n");
754 if (data->ioc_inllen1 > 37) {
755 CERROR("osc TARGET UUID must be less than 38 characters\n");
759 if (data->ioc_inllen2 < 1) {
760 CERROR("osc setup requires a SERVER UUID\n");
764 if (data->ioc_inllen2 > 37) {
765 CERROR("osc SERVER UUID must be less than 38 characters\n");
769 memcpy(osc->osc_target_uuid, data->ioc_inlbuf1, data->ioc_inllen1);
770 memcpy(server_uuid, data->ioc_inlbuf2, MIN(data->ioc_inllen2,
771 sizeof(server_uuid)));
773 osc->osc_conn = ptlrpc_uuid_to_connection(server_uuid);
777 obddev->obd_namespace =
778 ldlm_namespace_new("osc", LDLM_NAMESPACE_CLIENT);
779 if (obddev->obd_namespace == NULL)
780 GOTO(out_conn, rc = -ENOMEM);
782 OBD_ALLOC(osc->osc_client, sizeof(*osc->osc_client));
783 if (osc->osc_client == NULL)
784 GOTO(out_ns, rc = -ENOMEM);
786 OBD_ALLOC(osc->osc_ldlm_client, sizeof(*osc->osc_ldlm_client));
787 if (osc->osc_ldlm_client == NULL)
788 GOTO(out_client, rc = -ENOMEM);
790 ptlrpc_init_client(NULL, NULL, OST_REQUEST_PORTAL, OSC_REPLY_PORTAL,
792 ptlrpc_init_client(NULL, NULL, LDLM_REQUEST_PORTAL, LDLM_REPLY_PORTAL,
793 osc->osc_ldlm_client);
794 osc->osc_client->cli_name = "osc";
795 osc->osc_ldlm_client->cli_name = "ldlm";
801 OBD_FREE(osc->osc_client, sizeof(*osc->osc_client));
803 ldlm_namespace_free(obddev->obd_namespace);
805 ptlrpc_put_connection(osc->osc_conn);
809 static int osc_cleanup(struct obd_device * obddev)
811 struct osc_obd *osc = &obddev->u.osc;
813 ldlm_namespace_free(obddev->obd_namespace);
815 ptlrpc_cleanup_client(osc->osc_client);
816 OBD_FREE(osc->osc_client, sizeof(*osc->osc_client));
817 ptlrpc_cleanup_client(osc->osc_ldlm_client);
818 OBD_FREE(osc->osc_ldlm_client, sizeof(*osc->osc_ldlm_client));
819 ptlrpc_put_connection(osc->osc_conn);
825 static int osc_statfs(struct lustre_handle *conn, struct statfs *sfs)
827 struct ptlrpc_request *request;
828 struct ptlrpc_client *cl;
829 struct osc_obd *osc = &class_conn2obd(conn)->u.osc;
830 struct ptlrpc_connection *connection;
831 struct obd_statfs *osfs;
832 int rc, size = sizeof(*osfs);
835 osc_con2cl(conn, &cl, &connection);
836 request = ptlrpc_prep_req2(cl, connection, &osc->osc_connh,
837 OST_STATFS, 0, NULL, NULL);
841 request->rq_replen = lustre_msg_size(1, &size);
843 rc = ptlrpc_queue_wait(request);
844 rc = ptlrpc_check_status(request, rc);
846 CERROR("%s failed: rc = %d\n", __FUNCTION__, rc);
850 osfs = lustre_msg_buf(request->rq_repmsg, 0);
851 obd_statfs_unpack(osfs, sfs);
855 ptlrpc_free_req(request);
859 struct obd_ops osc_obd_ops = {
861 o_cleanup: osc_cleanup,
862 o_statfs: osc_statfs,
863 o_create: osc_create,
864 o_destroy: osc_destroy,
865 o_getattr: osc_getattr,
866 o_setattr: osc_setattr,
869 o_connect: osc_connect,
870 o_disconnect: osc_disconnect,
873 o_enqueue: osc_enqueue,
877 static int __init osc_init(void)
879 return class_register_type(&osc_obd_ops, LUSTRE_OSC_NAME);
882 static void __exit osc_exit(void)
884 class_unregister_type(LUSTRE_OSC_NAME);
887 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
888 MODULE_DESCRIPTION("Lustre Object Storage Client (OSC) v1.0");
889 MODULE_LICENSE("GPL");
891 module_init(osc_init);
892 module_exit(osc_exit);