1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
5 * Author: Peter J. Braam <braam@clusterfs.com>
6 * Author: Phil Schwan <phil@clusterfs.com>
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Storage Target Handling functions
24 * Lustre Object Server Module (OST)
26 * This server is single threaded at present (but can easily be multi
27 * threaded). For testing and management it is treated as an
28 * obd_device, although it does not export a full OBD method table
29 * (the requests are coming in over the wire, so object target
30 * modules do not have a full method table.)
34 # define EXPORT_SYMTAB
36 #define DEBUG_SUBSYSTEM S_OST
38 #include <linux/module.h>
39 #include <linux/obd_ost.h>
40 #include <linux/lustre_net.h>
41 #include <linux/lustre_dlm.h>
42 #include <linux/lustre_export.h>
43 #include <linux/init.h>
44 #include <linux/lprocfs_status.h>
45 #include <linux/lustre_commit_confd.h>
46 #include <portals/list.h>
48 void oti_init(struct obd_trans_info *oti, struct ptlrpc_request *req)
52 memset(oti, 0, sizeof *oti);
54 if (req->rq_repmsg && req->rq_reqmsg != 0)
55 oti->oti_transno = req->rq_repmsg->transno;
58 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
60 struct oti_req_ack_lock *ack_lock;
67 req->rq_repmsg->transno = oti->oti_transno;
69 /* XXX 4 == entries in oti_ack_locks??? */
70 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
73 /* XXX not even calling target_send_reply in some cases... */
74 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode);
78 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
79 struct obd_trans_info *oti)
81 struct ost_body *body, *repbody;
82 int rc, size = sizeof(*body);
85 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
89 rc = lustre_pack_reply(req, 1, &size, NULL);
93 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
94 oti->oti_logcookies = obdo_logcookie(&body->oa);
95 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
96 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
97 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti);
101 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
103 struct ost_body *body, *repbody;
104 int rc, size = sizeof(*body);
107 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
111 rc = lustre_pack_reply(req, 1, &size, NULL);
115 repbody = lustre_msg_buf (req->rq_repmsg, 0, sizeof(*repbody));
116 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
117 req->rq_status = obd_getattr(exp, &repbody->oa, NULL);
121 static int ost_statfs(struct ptlrpc_request *req)
123 struct obd_statfs *osfs;
124 int rc, size = sizeof(*osfs);
127 rc = lustre_pack_reply(req, 1, &size, NULL);
131 osfs = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*osfs));
133 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs, jiffies-HZ);
134 if (req->rq_status != 0)
135 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
140 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
141 struct obd_trans_info *oti)
143 struct ost_body *body, *repbody;
144 int rc, size = sizeof(*repbody);
147 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
151 rc = lustre_pack_reply(req, 1, &size, NULL);
155 repbody = lustre_msg_buf (req->rq_repmsg, 0, sizeof(*repbody));
156 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
157 oti->oti_logcookies = obdo_logcookie(&repbody->oa);
158 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
159 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
163 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
164 struct obd_trans_info *oti)
166 struct ost_body *body, *repbody;
167 int rc, size = sizeof(*repbody);
170 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
174 if ((body->oa.o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
175 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
178 rc = lustre_pack_reply(req, 1, &size, NULL);
182 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
183 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
184 req->rq_status = obd_punch(exp, &repbody->oa, NULL, repbody->oa.o_size,
185 repbody->oa.o_blocks, oti);
189 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
191 struct ost_body *body, *repbody;
192 int rc, size = sizeof(*repbody);
195 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
199 rc = lustre_pack_reply(req, 1, &size, NULL);
203 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
204 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
205 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
206 repbody->oa.o_blocks);
210 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
211 struct obd_trans_info *oti)
213 struct ost_body *body, *repbody;
214 int rc, size = sizeof(*repbody);
217 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
221 rc = lustre_pack_reply(req, 1, &size, NULL);
225 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
226 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
228 req->rq_status = obd_setattr(exp, &repbody->oa, NULL, oti);
232 static int ost_bulk_timeout(void *data)
235 /* We don't fail the connection here, because having the export
236 * killed makes the (vital) call to commitrw very sad.
241 static int get_per_page_niobufs(struct obd_ioobj *ioo, int nioo,
242 struct niobuf_remote *rnb, int nrnb,
243 struct niobuf_remote **pp_rnbp)
245 /* Copy a remote niobuf, splitting it into page-sized chunks
246 * and setting ioo[i].ioo_bufcnt accordingly */
247 struct niobuf_remote *pp_rnb;
254 /* first count and check the number of pages required */
255 for (i = 0; i < nioo; i++)
256 for (j = 0; j < ioo->ioo_bufcnt; j++, rnbidx++) {
257 obd_off offset = rnb[rnbidx].offset;
258 obd_off p0 = offset >> PAGE_SHIFT;
259 obd_off pn = (offset + rnb[rnbidx].len - 1)>>PAGE_SHIFT;
261 LASSERT(rnbidx < nrnb);
263 npages += (pn + 1 - p0);
265 if (rnb[rnbidx].len == 0) {
266 CERROR("zero len BRW: obj %d objid "LPX64
267 " buf %u\n", i, ioo[i].ioo_id, j);
271 rnb[rnbidx].offset <= rnb[rnbidx-1].offset) {
272 CERROR("unordered BRW: obj %d objid "LPX64
273 " buf %u offset "LPX64" <= "LPX64"\n",
274 i, ioo[i].ioo_id, j, rnb[rnbidx].offset,
280 LASSERT(rnbidx == nrnb);
282 if (npages == nrnb) { /* all niobufs are for single pages */
287 OBD_ALLOC(pp_rnb, sizeof(*pp_rnb) * npages);
291 /* now do the actual split */
293 for (i = 0; i < nioo; i++) {
296 for (j = 0; j < ioo[i].ioo_bufcnt; j++, rnbidx++) {
297 obd_off off = rnb[rnbidx].offset;
298 int nob = rnb[rnbidx].len;
300 LASSERT(rnbidx < nrnb);
302 obd_off poff = off & (PAGE_SIZE - 1);
303 int pnob = (poff + nob > PAGE_SIZE) ?
304 PAGE_SIZE - poff : nob;
306 LASSERT(page < npages);
307 pp_rnb[page].len = pnob;
308 pp_rnb[page].offset = off;
309 pp_rnb[page].flags = rnb[rnbidx].flags;
311 CDEBUG(0, " obj %d id "LPX64
312 "page %d(%d) "LPX64" for %d, flg %x\n",
313 i, ioo[i].ioo_id, obj_pages, page,
314 pp_rnb[page].offset, pp_rnb[page].len,
324 ioo[i].ioo_bufcnt = obj_pages;
326 LASSERT(page == npages);
332 static void free_per_page_niobufs (int npages, struct niobuf_remote *pp_rnb,
333 struct niobuf_remote *rnb)
335 if (pp_rnb == rnb) /* didn't allocate above */
338 OBD_FREE(pp_rnb, sizeof(*pp_rnb) * npages);
342 obd_count ost_checksum_bulk(struct ptlrpc_bulk_desc *desc)
345 struct ptlrpc_bulk_page *bp;
347 list_for_each_entry(bp, &desc->bd_page_list, bp_link) {
348 ost_checksum(&cksum, kmap(bp->bp_page) + bp->bp_pageoffset,
357 static int ost_brw_read(struct ptlrpc_request *req)
359 struct ptlrpc_bulk_desc *desc;
360 struct niobuf_remote *remote_nb;
361 struct niobuf_remote *pp_rnb;
362 struct niobuf_local *local_nb;
363 struct obd_ioobj *ioo;
364 struct ost_body *body, *repbody;
365 struct l_wait_info lwi;
366 struct obd_trans_info oti = { 0 };
367 char str[PTL_NALFMT_SIZE];
368 int size[1] = { sizeof(*body) };
377 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
378 GOTO(out, rc = -EIO);
380 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
381 (obd_timeout + 1) / 4);
383 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
385 CERROR("Missing/short ost_body\n");
386 GOTO(out, rc = -EFAULT);
389 ioo = lustre_swab_reqbuf(req, 1, sizeof(*ioo), lustre_swab_obd_ioobj);
391 CERROR("Missing/short ioobj\n");
392 GOTO(out, rc = -EFAULT);
395 niocount = ioo->ioo_bufcnt;
396 remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb),
397 lustre_swab_niobuf_remote);
398 if (remote_nb == NULL) {
399 CERROR("Missing/short niobuf\n");
400 GOTO(out, rc = -EFAULT);
402 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
403 for (i = 1; i < niocount; i++)
404 lustre_swab_niobuf_remote (&remote_nb[i]);
407 rc = lustre_pack_reply(req, 1, size, NULL);
411 /* FIXME all niobuf splitting should be done in obdfilter if needed */
412 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
413 npages = get_per_page_niobufs(ioo, 1, remote_nb, niocount, &pp_rnb);
415 GOTO(out, rc = npages);
417 OBD_ALLOC(local_nb, sizeof(*local_nb) * npages);
418 if (local_nb == NULL)
419 GOTO(out_pp_rnb, rc = -ENOMEM);
421 desc = ptlrpc_prep_bulk_exp (req, npages,
422 BULK_PUT_SOURCE, OST_BULK_PORTAL);
424 GOTO(out_local, rc = -ENOMEM);
426 rc = obd_preprw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
427 ioo, npages, pp_rnb, local_nb, &oti);
432 for (i = 0; i < npages; i++) {
433 int page_rc = local_nb[i].rc;
435 if (page_rc < 0) { /* error */
440 LASSERT(page_rc <= pp_rnb[i].len);
442 if (page_rc != 0) { /* some data! */
443 LASSERT (local_nb[i].page != NULL);
444 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
445 pp_rnb[i].offset & (PAGE_SIZE-1),
449 if (page_rc != pp_rnb[i].len) { /* short read */
450 /* All subsequent pages should be 0 */
452 LASSERT(local_nb[i].rc == 0);
458 rc = ptlrpc_start_bulk_transfer(desc);
460 lwi = LWI_TIMEOUT(obd_timeout * HZ / 4,
461 ost_bulk_timeout, desc);
462 rc = l_wait_event(desc->bd_waitq,
463 !ptlrpc_bulk_active(desc), &lwi);
464 LASSERT(rc == 0 || rc == -ETIMEDOUT);
465 if (rc == -ETIMEDOUT) {
466 DEBUG_REQ(D_ERROR, req, "timeout on bulk PUT");
467 ptlrpc_abort_bulk(desc);
468 } else if (!desc->bd_success ||
469 desc->bd_nob_transferred != desc->bd_nob) {
470 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
472 "truncated" : "network error on",
473 desc->bd_nob_transferred,
475 /* XXX should this be a different errno? */
479 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d\n", rc);
481 comms_error = rc != 0;
484 /* Must commit after prep above in all cases */
485 rc = obd_commitrw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
486 ioo, npages, local_nb, &oti, rc);
489 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
490 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
493 repbody->oa.o_cksum = ost_checksum_bulk(desc);
494 repbody->oa.o_valid |= OBD_MD_FLCKSUM;
499 ptlrpc_free_bulk(desc);
501 OBD_FREE(local_nb, sizeof(*local_nb) * npages);
503 free_per_page_niobufs(npages, pp_rnb, remote_nb);
507 req->rq_status = nob;
509 } else if (!comms_error) {
510 /* only reply if comms OK */
514 if (req->rq_reply_state != NULL) {
515 /* reply out callback would free */
516 lustre_free_reply_state (req->rq_reply_state);
518 if (req->rq_reqmsg->conn_cnt == req->rq_export->exp_conn_cnt) {
519 CERROR("bulk IO comms error: "
520 "evicting %s@%s nid "LPX64" (%s)\n",
521 req->rq_export->exp_client_uuid.uuid,
522 req->rq_export->exp_connection->c_remote_uuid.uuid,
523 req->rq_peer.peer_nid,
524 portals_nid2str(req->rq_peer.peer_ni->pni_number,
525 req->rq_peer.peer_nid,
527 ptlrpc_fail_export(req->rq_export);
529 CERROR("ignoring bulk IO comms error: "
530 "client reconnected %s@%s nid "LPX64" (%s)\n",
531 req->rq_export->exp_client_uuid.uuid,
532 req->rq_export->exp_connection->c_remote_uuid.uuid,
533 req->rq_peer.peer_nid,
534 portals_nid2str(req->rq_peer.peer_ni->pni_number,
535 req->rq_peer.peer_nid,
543 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
545 struct ptlrpc_bulk_desc *desc;
546 struct niobuf_remote *remote_nb;
547 struct niobuf_remote *pp_rnb;
548 struct niobuf_local *local_nb;
549 struct obd_ioobj *ioo;
550 struct ost_body *body, *repbody;
551 struct l_wait_info lwi;
553 int size[2] = { sizeof(*body) };
554 int objcount, niocount, npages;
557 char str[PTL_NALFMT_SIZE];
560 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
561 GOTO(out, rc = -EIO);
563 /* pause before transaction has been started */
564 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
565 (obd_timeout + 1) / 4);
567 swab = lustre_msg_swabbed(req->rq_reqmsg);
568 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
570 CERROR("Missing/short ost_body\n");
571 GOTO(out, rc = -EFAULT);
574 LASSERT_REQSWAB(req, 1);
575 objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
577 CERROR("Missing/short ioobj\n");
578 GOTO(out, rc = -EFAULT);
580 ioo = lustre_msg_buf (req->rq_reqmsg, 1, objcount * sizeof(*ioo));
581 LASSERT (ioo != NULL);
582 for (niocount = i = 0; i < objcount; i++) {
584 lustre_swab_obd_ioobj (&ioo[i]);
585 if (ioo[i].ioo_bufcnt == 0) {
586 CERROR("ioo[%d] has zero bufcnt\n", i);
587 GOTO(out, rc = -EFAULT);
589 niocount += ioo[i].ioo_bufcnt;
592 remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb),
593 lustre_swab_niobuf_remote);
594 if (remote_nb == NULL) {
595 CERROR("Missing/short niobuf\n");
596 GOTO(out, rc = -EFAULT);
598 if (swab) { /* swab the remaining niobufs */
599 for (i = 1; i < niocount; i++)
600 lustre_swab_niobuf_remote (&remote_nb[i]);
603 size[1] = niocount * sizeof(*rcs);
604 rc = lustre_pack_reply(req, 2, size, NULL);
607 rcs = lustre_msg_buf(req->rq_repmsg, 1, niocount * sizeof(*rcs));
609 /* FIXME all niobuf splitting should be done in obdfilter if needed */
610 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
611 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
613 GOTO(out, rc = npages);
615 OBD_ALLOC(local_nb, sizeof(*local_nb) * npages);
616 if (local_nb == NULL)
617 GOTO(out_pp_rnb, rc = -ENOMEM);
619 desc = ptlrpc_prep_bulk_exp (req, npages,
620 BULK_GET_SINK, OST_BULK_PORTAL);
622 GOTO(out_local, rc = -ENOMEM);
624 rc = obd_preprw(OBD_BRW_WRITE, req->rq_export, &body->oa, objcount,
625 ioo, npages, pp_rnb, local_nb, oti);
629 /* NB Having prepped, we must commit... */
631 for (i = 0; i < npages; i++)
632 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
633 pp_rnb[i].offset & (PAGE_SIZE - 1),
636 rc = ptlrpc_start_bulk_transfer (desc);
638 lwi = LWI_TIMEOUT(obd_timeout * HZ / 4,
639 ost_bulk_timeout, desc);
640 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc),
642 LASSERT(rc == 0 || rc == -ETIMEDOUT);
643 if (rc == -ETIMEDOUT) {
644 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
645 ptlrpc_abort_bulk(desc);
646 } else if (!desc->bd_success ||
647 desc->bd_nob_transferred != desc->bd_nob) {
648 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
650 "truncated" : "network error on",
651 desc->bd_nob_transferred, desc->bd_nob);
652 /* XXX should this be a different errno? */
656 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d\n", rc);
658 comms_error = rc != 0;
660 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
661 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
664 if (rc == 0 && (body->oa.o_valid & OBD_MD_FLCKSUM) != 0) {
665 static int cksum_counter;
666 obd_count client_cksum = body->oa.o_cksum;
667 obd_count cksum = ost_checksum_bulk(desc);
669 portals_nid2str(req->rq_connection->c_peer.peer_ni->pni_number,
670 req->rq_connection->c_peer.peer_nid, str);
671 if (client_cksum != cksum) {
672 CERROR("Bad checksum: client %x, server %x, client NID "
673 LPX64" (%s)\n", client_cksum, cksum,
674 req->rq_connection->c_peer.peer_nid, str);
676 repbody->oa.o_cksum = cksum;
679 if ((cksum_counter & (-cksum_counter)) == cksum_counter)
680 CWARN("Checksum %u from "LPX64": %x OK\n",
682 req->rq_connection->c_peer.peer_nid,
687 /* Must commit after prep above in all cases */
688 rc = obd_commitrw(OBD_BRW_WRITE, req->rq_export, &repbody->oa,
689 objcount, ioo, npages, local_nb, oti, rc);
692 /* set per-requested niobuf return codes */
693 for (i = j = 0; i < niocount; i++) {
694 int nob = remote_nb[i].len;
699 if (local_nb[j].rc < 0)
700 rcs[i] = local_nb[j].rc;
701 nob -= pp_rnb[j].len;
706 LASSERT(j == npages);
710 ptlrpc_free_bulk(desc);
712 OBD_FREE(local_nb, sizeof(*local_nb) * npages);
714 free_per_page_niobufs(npages, pp_rnb, remote_nb);
717 oti_to_request(oti, req);
718 rc = ptlrpc_reply(req);
719 } else if (!comms_error) {
720 /* Only reply if there was no comms problem with bulk */
724 if (req->rq_reply_state != NULL) {
725 /* reply out callback would free */
726 lustre_free_reply_state (req->rq_reply_state);
728 if (req->rq_reqmsg->conn_cnt == req->rq_export->exp_conn_cnt) {
729 CERROR("bulk IO comms error: "
730 "evicting %s@%s nid "LPX64" (%s)\n",
731 req->rq_export->exp_client_uuid.uuid,
732 req->rq_export->exp_connection->c_remote_uuid.uuid,
733 req->rq_peer.peer_nid,
734 portals_nid2str(req->rq_peer.peer_ni->pni_number,
735 req->rq_peer.peer_nid,
737 ptlrpc_fail_export(req->rq_export);
739 CERROR("ignoring bulk IO comms error: "
740 "client reconnected %s@%s nid "LPX64" (%s)\n",
741 req->rq_export->exp_client_uuid.uuid,
742 req->rq_export->exp_connection->c_remote_uuid.uuid,
743 req->rq_peer.peer_nid,
744 portals_nid2str(req->rq_peer.peer_ni->pni_number,
745 req->rq_peer.peer_nid,
752 static int ost_san_brw(struct ptlrpc_request *req, int cmd)
754 struct niobuf_remote *remote_nb, *res_nb, *pp_rnb;
755 struct obd_ioobj *ioo;
756 struct ost_body *body, *repbody;
757 int rc, i, objcount, niocount, size[2] = {sizeof(*body)}, npages;
761 /* XXX not set to use latest protocol */
763 swab = lustre_msg_swabbed(req->rq_reqmsg);
764 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
766 CERROR("Missing/short ost_body\n");
767 GOTO(out, rc = -EFAULT);
770 ioo = lustre_swab_reqbuf(req, 1, sizeof(*ioo), lustre_swab_obd_ioobj);
772 CERROR("Missing/short ioobj\n");
773 GOTO(out, rc = -EFAULT);
775 objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
776 niocount = ioo[0].ioo_bufcnt;
777 for (i = 1; i < objcount; i++) {
779 lustre_swab_obd_ioobj (&ioo[i]);
780 niocount += ioo[i].ioo_bufcnt;
783 remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb),
784 lustre_swab_niobuf_remote);
785 if (remote_nb == NULL) {
786 CERROR("Missing/short niobuf\n");
787 GOTO(out, rc = -EFAULT);
789 if (swab) { /* swab the remaining niobufs */
790 for (i = 1; i < niocount; i++)
791 lustre_swab_niobuf_remote (&remote_nb[i]);
794 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
795 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
797 GOTO (out, rc = npages);
799 size[1] = npages * sizeof(*pp_rnb);
800 rc = lustre_pack_reply(req, 2, size, NULL);
802 GOTO(out_pp_rnb, rc);
804 req->rq_status = obd_san_preprw(cmd, req->rq_export, &body->oa,
805 objcount, ioo, npages, pp_rnb);
808 GOTO(out_pp_rnb, rc = 0);
810 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
811 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
813 res_nb = lustre_msg_buf(req->rq_repmsg, 1, size[1]);
814 memcpy(res_nb, remote_nb, size[1]);
817 free_per_page_niobufs(npages, pp_rnb, remote_nb);
829 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
835 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
837 DEBUG_REQ(D_HA, req, "no set_info key");
840 keylen = req->rq_reqmsg->buflens[0];
842 rc = lustre_pack_reply(req, 0, NULL, NULL);
846 rc = obd_set_info(exp, keylen, key, 0, NULL);
847 req->rq_repmsg->status = 0;
851 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
854 int keylen, rc = 0, size = sizeof(obd_id);
858 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
860 DEBUG_REQ(D_HA, req, "no get_info key");
863 keylen = req->rq_reqmsg->buflens[0];
865 if (keylen < strlen("last_id") || memcmp(key, "last_id", 7) != 0)
868 rc = lustre_pack_reply(req, 1, &size, NULL);
872 reply = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*reply));
873 rc = obd_get_info(exp, keylen, key, &size, reply);
874 req->rq_repmsg->status = 0;
878 static int ost_filter_recovery_request(struct ptlrpc_request *req,
879 struct obd_device *obd, int *process)
881 switch (req->rq_reqmsg->opc) {
882 case OST_CONNECT: /* This will never get here, but for completeness. */
896 *process = target_queue_recovery_request(req, obd);
900 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
902 /* XXX what should we set rq_status to here? */
903 req->rq_status = -EAGAIN;
904 RETURN(ptlrpc_error(req));
910 static int ost_handle(struct ptlrpc_request *req)
912 struct obd_trans_info trans_info = { 0, };
913 struct obd_trans_info *oti = &trans_info;
914 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
915 struct obd_export *exp = NULL;
918 LASSERT(current->journal_info == NULL);
919 /* XXX identical to MDS */
920 if (req->rq_reqmsg->opc != OST_CONNECT) {
921 struct obd_device *obd;
922 int abort_recovery, recovering;
924 exp = req->rq_export;
927 CDEBUG(D_HA, "operation %d on unconnected OST\n",
928 req->rq_reqmsg->opc);
929 req->rq_status = -ENOTCONN;
930 GOTO(out, rc = -ENOTCONN);
935 /* Check for aborted recovery. */
936 spin_lock_bh(&obd->obd_processing_task_lock);
937 abort_recovery = obd->obd_abort_recovery;
938 recovering = obd->obd_recovering;
939 spin_unlock_bh(&obd->obd_processing_task_lock);
940 if (abort_recovery) {
941 target_abort_recovery(obd);
942 } else if (recovering) {
943 rc = ost_filter_recovery_request(req, obd,
945 if (rc || !should_process)
952 switch (req->rq_reqmsg->opc) {
954 CDEBUG(D_INODE, "connect\n");
955 OBD_FAIL_RETURN(OBD_FAIL_OST_CONNECT_NET, 0);
956 rc = target_handle_connect(req, ost_handle);
960 CDEBUG(D_INODE, "disconnect\n");
961 OBD_FAIL_RETURN(OBD_FAIL_OST_DISCONNECT_NET, 0);
962 rc = target_handle_disconnect(req);
965 CDEBUG(D_INODE, "create\n");
966 OBD_FAIL_RETURN(OBD_FAIL_OST_CREATE_NET, 0);
967 rc = ost_create(exp, req, oti);
970 CDEBUG(D_INODE, "destroy\n");
971 OBD_FAIL_RETURN(OBD_FAIL_OST_DESTROY_NET, 0);
972 rc = ost_destroy(exp, req, oti);
975 CDEBUG(D_INODE, "getattr\n");
976 OBD_FAIL_RETURN(OBD_FAIL_OST_GETATTR_NET, 0);
977 rc = ost_getattr(exp, req);
980 CDEBUG(D_INODE, "setattr\n");
981 OBD_FAIL_RETURN(OBD_FAIL_OST_SETATTR_NET, 0);
982 rc = ost_setattr(exp, req, oti);
985 CDEBUG(D_INODE, "write\n");
986 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
987 rc = ost_brw_write(req, oti);
988 LASSERT(current->journal_info == NULL);
989 /* ost_brw sends its own replies */
992 CDEBUG(D_INODE, "read\n");
993 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
994 rc = ost_brw_read(req);
995 LASSERT(current->journal_info == NULL);
996 /* ost_brw sends its own replies */
999 CDEBUG(D_INODE, "san read\n");
1000 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1001 rc = ost_san_brw(req, OBD_BRW_READ);
1002 /* ost_san_brw sends its own replies */
1005 CDEBUG(D_INODE, "san write\n");
1006 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1007 rc = ost_san_brw(req, OBD_BRW_WRITE);
1008 /* ost_san_brw sends its own replies */
1011 CDEBUG(D_INODE, "punch\n");
1012 OBD_FAIL_RETURN(OBD_FAIL_OST_PUNCH_NET, 0);
1013 rc = ost_punch(exp, req, oti);
1016 CDEBUG(D_INODE, "statfs\n");
1017 OBD_FAIL_RETURN(OBD_FAIL_OST_STATFS_NET, 0);
1018 rc = ost_statfs(req);
1021 CDEBUG(D_INODE, "sync\n");
1022 OBD_FAIL_RETURN(OBD_FAIL_OST_SYNC_NET, 0);
1023 rc = ost_sync(exp, req);
1026 DEBUG_REQ(D_INODE, req, "set_info");
1027 rc = ost_set_info(exp, req);
1030 DEBUG_REQ(D_INODE, req, "get_info");
1031 rc = ost_get_info(exp, req);
1034 DEBUG_REQ(D_INODE, req, "ping");
1035 rc = target_handle_ping(req);
1037 /* FIXME - just reply status */
1038 case LLOG_ORIGIN_CONNECT:
1039 DEBUG_REQ(D_INODE, req, "log connect\n");
1040 rc = llog_handle_connect(req);
1041 req->rq_status = rc;
1042 rc = lustre_pack_reply(req, 0, NULL, NULL);
1045 RETURN(ptlrpc_reply(req));
1046 case OBD_LOG_CANCEL:
1047 CDEBUG(D_INODE, "log cancel\n");
1048 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
1049 rc = llog_origin_handle_cancel(req);
1050 req->rq_status = rc;
1051 rc = lustre_pack_reply(req, 0, NULL, NULL);
1054 RETURN(ptlrpc_reply(req));
1056 CDEBUG(D_INODE, "enqueue\n");
1057 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
1058 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1059 ldlm_server_blocking_ast,
1060 ldlm_server_glimpse_ast);
1061 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1064 CDEBUG(D_INODE, "convert\n");
1065 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
1066 rc = ldlm_handle_convert(req);
1069 CDEBUG(D_INODE, "cancel\n");
1070 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CANCEL, 0);
1071 rc = ldlm_handle_cancel(req);
1073 case LDLM_BL_CALLBACK:
1074 case LDLM_CP_CALLBACK:
1075 CDEBUG(D_INODE, "callback\n");
1076 CERROR("callbacks should not happen on OST\n");
1079 CERROR("Unexpected opcode %d\n", req->rq_reqmsg->opc);
1080 req->rq_status = -ENOTSUPP;
1081 rc = ptlrpc_error(req);
1085 LASSERT(current->journal_info == NULL);
1088 /* If we're DISCONNECTing, the export_data is already freed */
1089 if (!rc && req->rq_reqmsg->opc != OST_DISCONNECT) {
1090 struct obd_device *obd = req->rq_export->exp_obd;
1091 if (!obd->obd_no_transno) {
1092 req->rq_repmsg->last_committed =
1093 obd->obd_last_committed;
1095 DEBUG_REQ(D_IOCTL, req,
1096 "not sending last_committed update");
1098 CDEBUG(D_INFO, "last_committed "LPU64", xid "LPX64"\n",
1099 obd->obd_last_committed, req->rq_xid);
1103 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LAST_REPLAY) {
1104 struct obd_device *obd = req->rq_export->exp_obd;
1106 if (obd && obd->obd_recovering) {
1107 DEBUG_REQ(D_HA, req, "LAST_REPLAY, queuing reply");
1108 return target_queue_final_reply(req, rc);
1110 /* Lost a race with recovery; let the error path DTRT. */
1111 rc = req->rq_status = -ENOTCONN;
1115 oti_to_request(oti, req);
1117 target_send_reply(req, rc, fail);
1121 static int ost_setup(struct obd_device *obd, obd_count len, void *buf)
1123 struct ost_obd *ost = &obd->u.ost;
1124 struct lprocfs_static_vars lvars;
1128 rc = cleanup_group_info();
1132 rc = llog_start_commit_thread();
1136 lprocfs_init_vars(ost, &lvars);
1137 lprocfs_obd_setup(obd, lvars.obd_vars);
1140 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1141 OST_REQUEST_PORTAL, OSC_REPLY_PORTAL,
1143 obd->obd_proc_entry);
1144 if (ost->ost_service == NULL) {
1145 CERROR("failed to start service\n");
1146 GOTO(out_lprocfs, rc = -ENOMEM);
1149 rc = ptlrpc_start_n_threads(obd, ost->ost_service, OST_NUM_THREADS,
1152 GOTO(out_service, rc = -EINVAL);
1154 ost->ost_create_service =
1155 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1156 OST_CREATE_PORTAL, OSC_REPLY_PORTAL,
1157 ost_handle, "ost_create",
1158 obd->obd_proc_entry);
1159 if (ost->ost_create_service == NULL) {
1160 CERROR("failed to start OST create service\n");
1161 GOTO(out_service, rc = -ENOMEM);
1164 rc = ptlrpc_start_n_threads(obd, ost->ost_create_service, 1,
1167 GOTO(out_create, rc = -EINVAL);
1172 ptlrpc_unregister_service(ost->ost_create_service);
1174 ptlrpc_unregister_service(ost->ost_service);
1176 lprocfs_obd_cleanup(obd);
1180 static int ost_cleanup(struct obd_device *obd, int flags)
1182 struct ost_obd *ost = &obd->u.ost;
1186 spin_lock_bh(&obd->obd_processing_task_lock);
1187 if (obd->obd_recovering) {
1188 target_cancel_recovery_timer(obd);
1189 obd->obd_recovering = 0;
1191 spin_unlock_bh(&obd->obd_processing_task_lock);
1193 ptlrpc_stop_all_threads(ost->ost_service);
1194 ptlrpc_unregister_service(ost->ost_service);
1196 ptlrpc_stop_all_threads(ost->ost_create_service);
1197 ptlrpc_unregister_service(ost->ost_create_service);
1199 lprocfs_obd_cleanup(obd);
1204 /* use obd ops to offer management infrastructure */
1205 static struct obd_ops ost_obd_ops = {
1206 o_owner: THIS_MODULE,
1208 o_cleanup: ost_cleanup,
1211 static int __init ost_init(void)
1213 struct lprocfs_static_vars lvars;
1216 lprocfs_init_vars(ost,&lvars);
1217 RETURN(class_register_type(&ost_obd_ops, lvars.module_vars,
1221 static void /*__exit*/ ost_exit(void)
1223 class_unregister_type(LUSTRE_OST_NAME);
1226 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1227 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
1228 MODULE_LICENSE("GPL");
1230 module_init(ost_init);
1231 module_exit(ost_exit);