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 ldlm_put_lock_into_req(req, &ack_lock->lock, ack_lock->mode);
77 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
78 struct obd_trans_info *oti)
80 struct ost_body *body, *repbody;
81 int rc, size = sizeof(*body);
84 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
88 rc = lustre_pack_reply(req, 1, &size, NULL);
92 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
93 oti->oti_logcookies = obdo_logcookie(&body->oa);
94 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
95 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
96 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti);
100 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
102 struct ost_body *body, *repbody;
103 int rc, size = sizeof(*body);
106 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
110 rc = lustre_pack_reply(req, 1, &size, NULL);
114 repbody = lustre_msg_buf (req->rq_repmsg, 0, sizeof(*repbody));
115 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
116 req->rq_status = obd_getattr(exp, &repbody->oa, NULL);
120 static int ost_statfs(struct ptlrpc_request *req)
122 struct obd_statfs *osfs;
123 int rc, size = sizeof(*osfs);
126 rc = lustre_pack_reply(req, 1, &size, NULL);
130 osfs = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*osfs));
132 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs, jiffies-HZ);
133 if (req->rq_status != 0)
134 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
139 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
140 struct obd_trans_info *oti)
142 struct ost_body *body, *repbody;
143 int rc, size = sizeof(*repbody);
146 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
150 rc = lustre_pack_reply(req, 1, &size, NULL);
154 repbody = lustre_msg_buf (req->rq_repmsg, 0, sizeof(*repbody));
155 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
156 oti->oti_logcookies = obdo_logcookie(&repbody->oa);
157 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
158 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
162 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
163 struct obd_trans_info *oti)
165 struct ost_body *body, *repbody;
166 int rc, size = sizeof(*repbody);
169 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
173 if ((body->oa.o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
174 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
177 rc = lustre_pack_reply(req, 1, &size, NULL);
181 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
182 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
183 req->rq_status = obd_punch(exp, &repbody->oa, NULL, repbody->oa.o_size,
184 repbody->oa.o_blocks, oti);
188 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
190 struct ost_body *body, *repbody;
191 int rc, size = sizeof(*repbody);
194 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
198 rc = lustre_pack_reply(req, 1, &size, NULL);
202 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
203 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
204 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
205 repbody->oa.o_blocks);
209 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
210 struct obd_trans_info *oti)
212 struct ost_body *body, *repbody;
213 int rc, size = sizeof(*repbody);
216 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
220 rc = lustre_pack_reply(req, 1, &size, NULL);
224 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
225 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
227 req->rq_status = obd_setattr(exp, &repbody->oa, NULL, oti);
231 static int ost_bulk_timeout(void *data)
234 /* We don't fail the connection here, because having the export
235 * killed makes the (vital) call to commitrw very sad.
240 static int get_per_page_niobufs(struct obd_ioobj *ioo, int nioo,
241 struct niobuf_remote *rnb, int nrnb,
242 struct niobuf_remote **pp_rnbp)
244 /* Copy a remote niobuf, splitting it into page-sized chunks
245 * and setting ioo[i].ioo_bufcnt accordingly */
246 struct niobuf_remote *pp_rnb;
253 /* first count and check the number of pages required */
254 for (i = 0; i < nioo; i++)
255 for (j = 0; j < ioo->ioo_bufcnt; j++, rnbidx++) {
256 obd_off offset = rnb[rnbidx].offset;
257 obd_off p0 = offset >> PAGE_SHIFT;
258 obd_off pn = (offset + rnb[rnbidx].len - 1)>>PAGE_SHIFT;
260 LASSERT(rnbidx < nrnb);
262 npages += (pn + 1 - p0);
264 if (rnb[rnbidx].len == 0) {
265 CERROR("zero len BRW: obj %d objid "LPX64
266 " buf %u\n", i, ioo[i].ioo_id, j);
270 rnb[rnbidx].offset <= rnb[rnbidx-1].offset) {
271 CERROR("unordered BRW: obj %d objid "LPX64
272 " buf %u offset "LPX64" <= "LPX64"\n",
273 i, ioo[i].ioo_id, j, rnb[rnbidx].offset,
279 LASSERT(rnbidx == nrnb);
281 if (npages == nrnb) { /* all niobufs are for single pages */
286 OBD_ALLOC(pp_rnb, sizeof(*pp_rnb) * npages);
290 /* now do the actual split */
292 for (i = 0; i < nioo; i++) {
295 for (j = 0; j < ioo[i].ioo_bufcnt; j++, rnbidx++) {
296 obd_off off = rnb[rnbidx].offset;
297 int nob = rnb[rnbidx].len;
299 LASSERT(rnbidx < nrnb);
301 obd_off poff = off & (PAGE_SIZE - 1);
302 int pnob = (poff + nob > PAGE_SIZE) ?
303 PAGE_SIZE - poff : nob;
305 LASSERT(page < npages);
306 pp_rnb[page].len = pnob;
307 pp_rnb[page].offset = off;
308 pp_rnb[page].flags = rnb->flags;
310 CDEBUG(D_PAGE, " obj %d id "LPX64
311 "page %d(%d) "LPX64" for %d\n",
312 i, ioo[i].ioo_id, obj_pages, page,
313 pp_rnb[page].offset, pp_rnb[page].len);
322 ioo[i].ioo_bufcnt = obj_pages;
324 LASSERT(page == npages);
330 static void free_per_page_niobufs (int npages, struct niobuf_remote *pp_rnb,
331 struct niobuf_remote *rnb)
333 if (pp_rnb == rnb) /* didn't allocate above */
336 OBD_FREE(pp_rnb, sizeof(*pp_rnb) * npages);
340 obd_count ost_checksum_bulk(struct ptlrpc_bulk_desc *desc)
343 struct ptlrpc_bulk_page *bp;
345 list_for_each_entry(bp, &desc->bd_page_list, bp_link) {
346 ost_checksum(&cksum, kmap(bp->bp_page) + bp->bp_pageoffset,
355 static int ost_brw_read(struct ptlrpc_request *req)
357 struct ptlrpc_bulk_desc *desc;
358 struct niobuf_remote *remote_nb;
359 struct niobuf_remote *pp_rnb;
360 struct niobuf_local *local_nb;
361 struct obd_ioobj *ioo;
362 struct ost_body *body, *repbody;
363 struct l_wait_info lwi;
364 struct obd_trans_info oti = { 0 };
365 char str[PTL_NALFMT_SIZE];
366 int size[1] = { sizeof(*body) };
375 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
376 GOTO(out, rc = -EIO);
378 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
379 (obd_timeout + 1) / 4);
381 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
383 CERROR("Missing/short ost_body\n");
384 GOTO(out, rc = -EFAULT);
387 /* BUG 974: when we send back cache grants, don't clear this flag */
388 body->oa.o_valid &= ~OBD_MD_FLRDEV;
390 ioo = lustre_swab_reqbuf(req, 1, sizeof(*ioo), lustre_swab_obd_ioobj);
392 CERROR("Missing/short ioobj\n");
393 GOTO(out, rc = -EFAULT);
396 niocount = ioo->ioo_bufcnt;
397 remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb),
398 lustre_swab_niobuf_remote);
399 if (remote_nb == NULL) {
400 CERROR("Missing/short niobuf\n");
401 GOTO(out, rc = -EFAULT);
403 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
404 for (i = 1; i < niocount; i++)
405 lustre_swab_niobuf_remote (&remote_nb[i]);
408 rc = lustre_pack_reply(req, 1, size, NULL);
412 /* FIXME all niobuf splitting should be done in obdfilter if needed */
413 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
414 npages = get_per_page_niobufs(ioo, 1, remote_nb, niocount, &pp_rnb);
416 GOTO(out, rc = npages);
418 OBD_ALLOC(local_nb, sizeof(*local_nb) * npages);
419 if (local_nb == NULL)
420 GOTO(out_pp_rnb, rc = -ENOMEM);
422 desc = ptlrpc_prep_bulk_exp(req, 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 rc = ptlrpc_prep_bulk_page(desc, local_nb[i].page,
445 pp_rnb[i].offset& ~PAGE_MASK,
451 if (page_rc != pp_rnb[i].len) { /* short read */
452 /* All subsequent pages should be 0 */
454 LASSERT(local_nb[i].rc == 0);
460 rc = ptlrpc_bulk_put(desc);
462 lwi = LWI_TIMEOUT(obd_timeout * HZ / 4,
463 ost_bulk_timeout, desc);
464 rc = l_wait_event(desc->bd_waitq,
465 ptlrpc_bulk_complete(desc), &lwi);
467 LASSERT(rc == -ETIMEDOUT);
468 DEBUG_REQ(D_ERROR, req, "timeout on bulk PUT");
469 ptlrpc_abort_bulk(desc);
472 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d\n", rc);
474 comms_error = rc != 0;
477 /* Must commit after prep above in all cases */
478 rc = obd_commitrw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
479 ioo, npages, local_nb, &oti);
481 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
482 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
486 repbody->oa.o_nlink = ost_checksum_bulk(desc);
487 repbody->oa.o_valid |= OBD_MD_FLCKSUM;
492 ptlrpc_free_bulk(desc);
494 OBD_FREE(local_nb, sizeof(*local_nb) * npages);
496 free_per_page_niobufs(npages, pp_rnb, remote_nb);
500 req->rq_status = nob;
502 } else if (!comms_error) {
503 /* only reply if comms OK */
507 if (req->rq_repmsg != NULL) {
508 /* reply out callback would free */
509 OBD_FREE(req->rq_repmsg, req->rq_replen);
511 if (req->rq_reqmsg->conn_cnt == req->rq_export->exp_conn_cnt) {
512 CERROR("bulk IO comms error: "
513 "evicting %s@%s nid "LPX64" (%s)\n",
514 req->rq_export->exp_client_uuid.uuid,
515 req->rq_connection->c_remote_uuid.uuid,
516 req->rq_connection->c_peer.peer_nid,
517 portals_nid2str(req->rq_connection->c_peer.peer_ni->pni_number,
518 req->rq_connection->c_peer.peer_nid,
520 ptlrpc_fail_export(req->rq_export);
522 CERROR("ignoring bulk IO comms error: "
523 "client reconnected %s@%s nid "LPX64" (%s)\n",
524 req->rq_export->exp_client_uuid.uuid,
525 req->rq_connection->c_remote_uuid.uuid,
526 req->rq_connection->c_peer.peer_nid,
527 portals_nid2str(req->rq_connection->c_peer.peer_ni->pni_number,
528 req->rq_connection->c_peer.peer_nid,
536 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
538 struct ptlrpc_bulk_desc *desc;
539 struct niobuf_remote *remote_nb;
540 struct niobuf_remote *pp_rnb;
541 struct niobuf_local *local_nb;
542 struct obd_ioobj *ioo;
543 struct ost_body *body, *repbody;
544 struct l_wait_info lwi;
546 int size[2] = { sizeof(*body) };
547 int objcount, niocount, npages;
549 int rc, rc2, swab, i, j;
550 char str[PTL_NALFMT_SIZE];
553 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
554 GOTO(out, rc = -EIO);
556 /* pause before transaction has been started */
557 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
558 (obd_timeout + 1) / 4);
560 swab = lustre_msg_swabbed(req->rq_reqmsg);
561 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
563 CERROR("Missing/short ost_body\n");
564 GOTO(out, rc = -EFAULT);
567 /* BUG 974: when we send back cache grants, don't clear this flag */
568 body->oa.o_valid &= ~OBD_MD_FLRDEV;
570 LASSERT_REQSWAB(req, 1);
571 objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
573 CERROR("Missing/short ioobj\n");
574 GOTO(out, rc = -EFAULT);
576 ioo = lustre_msg_buf (req->rq_reqmsg, 1, objcount * sizeof(*ioo));
577 LASSERT (ioo != NULL);
578 for (niocount = i = 0; i < objcount; i++) {
580 lustre_swab_obd_ioobj (&ioo[i]);
581 if (ioo[i].ioo_bufcnt == 0) {
582 CERROR("ioo[%d] has zero bufcnt\n", i);
583 GOTO(out, rc = -EFAULT);
585 niocount += ioo[i].ioo_bufcnt;
588 remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb),
589 lustre_swab_niobuf_remote);
590 if (remote_nb == NULL) {
591 CERROR("Missing/short niobuf\n");
592 GOTO(out, rc = -EFAULT);
594 if (swab) { /* swab the remaining niobufs */
595 for (i = 1; i < niocount; i++)
596 lustre_swab_niobuf_remote (&remote_nb[i]);
599 size[1] = niocount * sizeof(*rcs);
600 rc = lustre_pack_reply(req, 2, size, NULL);
603 rcs = lustre_msg_buf(req->rq_repmsg, 1, niocount * sizeof(*rcs));
605 /* FIXME all niobuf splitting should be done in obdfilter if needed */
606 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
607 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
609 GOTO(out, rc = npages);
611 OBD_ALLOC(local_nb, sizeof(*local_nb) * npages);
612 if (local_nb == NULL)
613 GOTO(out_pp_rnb, rc = -ENOMEM);
615 desc = ptlrpc_prep_bulk_exp(req, BULK_GET_SINK, OST_BULK_PORTAL);
617 GOTO(out_local, rc = -ENOMEM);
619 rc = obd_preprw(OBD_BRW_WRITE, req->rq_export, &body->oa, objcount,
620 ioo, npages, pp_rnb, local_nb, oti);
624 /* NB Having prepped, we must commit... */
626 for (i = 0; i < npages; i++) {
627 rc = ptlrpc_prep_bulk_page(desc, local_nb[i].page,
628 pp_rnb[i].offset & (PAGE_SIZE - 1),
635 rc = ptlrpc_bulk_get(desc);
637 lwi = LWI_TIMEOUT(obd_timeout * HZ / 4,
638 ost_bulk_timeout, desc);
639 rc = l_wait_event(desc->bd_waitq,
640 ptlrpc_bulk_complete(desc), &lwi);
642 LASSERT(rc == -ETIMEDOUT);
643 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
644 ptlrpc_abort_bulk(desc);
647 DEBUG_REQ(D_ERROR, req, "bulk GET failed: rc %d\n", rc);
649 comms_error = rc != 0;
652 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
653 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
656 if (rc == 0 && (body->oa.o_valid & OBD_MD_FLCKSUM) != 0) {
657 static int cksum_counter;
658 obd_count client_cksum = body->oa.o_nlink;
659 obd_count cksum = ost_checksum_bulk(desc);
661 portals_nid2str(req->rq_connection->c_peer.peer_ni->pni_number,
662 req->rq_connection->c_peer.peer_nid, str);
663 if (client_cksum != cksum) {
664 CERROR("Bad checksum: client %x, server %x, client NID "
665 LPX64" (%s)\n", client_cksum, cksum,
666 req->rq_connection->c_peer.peer_nid, str);
668 repbody->oa.o_nlink = cksum;
671 if ((cksum_counter & (-cksum_counter)) == cksum_counter)
672 CWARN("Checksum %u from "LPX64": %x OK\n",
674 req->rq_connection->c_peer.peer_nid,
679 /* Must commit after prep above in all cases */
680 rc2 = obd_commitrw(OBD_BRW_WRITE, req->rq_export, &repbody->oa,
681 objcount, ioo, npages, local_nb, oti);
684 /* set per-requested niobuf return codes */
685 for (i = j = 0; i < niocount; i++) {
686 int nob = remote_nb[i].len;
691 if (local_nb[j].rc < 0)
692 rcs[i] = local_nb[j].rc;
693 nob -= pp_rnb[j].len;
698 LASSERT(j == npages);
704 ptlrpc_free_bulk(desc);
706 OBD_FREE(local_nb, sizeof(*local_nb) * npages);
708 free_per_page_niobufs(npages, pp_rnb, remote_nb);
711 oti_to_request(oti, req);
712 rc = ptlrpc_reply(req);
713 } else if (!comms_error) {
714 /* Only reply if there was no comms problem with bulk */
718 if (req->rq_repmsg != NULL) {
719 /* reply out callback would free */
720 OBD_FREE (req->rq_repmsg, req->rq_replen);
722 if (req->rq_reqmsg->conn_cnt == req->rq_export->exp_conn_cnt) {
723 CERROR("bulk IO comms error: "
724 "evicting %s@%s nid "LPX64" (%s)\n",
725 req->rq_export->exp_client_uuid.uuid,
726 req->rq_connection->c_remote_uuid.uuid,
727 req->rq_connection->c_peer.peer_nid,
728 portals_nid2str(req->rq_connection->c_peer.peer_ni->pni_number,
729 req->rq_connection->c_peer.peer_nid,
731 ptlrpc_fail_export(req->rq_export);
733 CERROR("ignoring bulk IO comms error: "
734 "client reconnected %s@%s nid "LPX64" (%s)\n",
735 req->rq_export->exp_client_uuid.uuid,
736 req->rq_connection->c_remote_uuid.uuid,
737 req->rq_connection->c_peer.peer_nid,
738 portals_nid2str(req->rq_connection->c_peer.peer_ni->pni_number,
739 req->rq_connection->c_peer.peer_nid,
746 static int ost_san_brw(struct ptlrpc_request *req, int cmd)
748 struct niobuf_remote *remote_nb, *res_nb, *pp_rnb;
749 struct obd_ioobj *ioo;
750 struct ost_body *body, *repbody;
751 int rc, i, objcount, niocount, size[2] = {sizeof(*body)}, npages;
755 /* XXX not set to use latest protocol */
757 swab = lustre_msg_swabbed(req->rq_reqmsg);
758 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
760 CERROR("Missing/short ost_body\n");
761 GOTO(out, rc = -EFAULT);
764 ioo = lustre_swab_reqbuf(req, 1, sizeof(*ioo), lustre_swab_obd_ioobj);
766 CERROR("Missing/short ioobj\n");
767 GOTO(out, rc = -EFAULT);
769 objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
770 niocount = ioo[0].ioo_bufcnt;
771 for (i = 1; i < objcount; i++) {
773 lustre_swab_obd_ioobj (&ioo[i]);
774 niocount += ioo[i].ioo_bufcnt;
777 remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb),
778 lustre_swab_niobuf_remote);
779 if (remote_nb == NULL) {
780 CERROR("Missing/short niobuf\n");
781 GOTO(out, rc = -EFAULT);
783 if (swab) { /* swab the remaining niobufs */
784 for (i = 1; i < niocount; i++)
785 lustre_swab_niobuf_remote (&remote_nb[i]);
788 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
789 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
791 GOTO (out, rc = npages);
793 size[1] = npages * sizeof(*pp_rnb);
794 rc = lustre_pack_reply(req, 2, size, NULL);
796 GOTO(out_pp_rnb, rc);
798 req->rq_status = obd_san_preprw(cmd, req->rq_export, &body->oa,
799 objcount, ioo, npages, pp_rnb);
802 GOTO(out_pp_rnb, rc = 0);
804 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
805 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
807 res_nb = lustre_msg_buf(req->rq_repmsg, 1, size[1]);
808 memcpy(res_nb, remote_nb, size[1]);
811 free_per_page_niobufs(npages, pp_rnb, remote_nb);
814 OBD_FREE(req->rq_repmsg, req->rq_replen);
815 req->rq_repmsg = NULL;
825 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
831 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
833 DEBUG_REQ(D_HA, req, "no set_info key");
836 keylen = req->rq_reqmsg->buflens[0];
838 rc = lustre_pack_reply(req, 0, NULL, NULL);
842 rc = obd_set_info(exp, keylen, key, 0, NULL);
843 req->rq_repmsg->status = 0;
847 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
850 int keylen, rc = 0, size = sizeof(obd_id);
854 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
856 DEBUG_REQ(D_HA, req, "no get_info key");
859 keylen = req->rq_reqmsg->buflens[0];
861 if (keylen < strlen("last_id") || memcmp(key, "last_id", 7) != 0)
864 rc = lustre_pack_reply(req, 1, &size, NULL);
868 reply = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*reply));
869 rc = obd_get_info(exp, keylen, key, &size, reply);
870 req->rq_repmsg->status = 0;
874 static int ost_filter_recovery_request(struct ptlrpc_request *req,
875 struct obd_device *obd, int *process)
877 switch (req->rq_reqmsg->opc) {
878 case OST_CONNECT: /* This will never get here, but for completeness. */
892 *process = target_queue_recovery_request(req, obd);
896 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
898 /* XXX what should we set rq_status to here? */
899 req->rq_status = -EAGAIN;
900 RETURN(ptlrpc_error(req));
906 static int ost_handle(struct ptlrpc_request *req)
908 struct obd_trans_info trans_info = { 0, };
909 struct obd_trans_info *oti = &trans_info;
910 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
911 struct obd_export *exp = NULL;
914 LASSERT(current->journal_info == NULL);
915 /* XXX identical to MDS */
916 if (req->rq_reqmsg->opc != OST_CONNECT) {
917 struct obd_device *obd;
918 int abort_recovery, recovering;
920 exp = req->rq_export;
923 CDEBUG(D_HA, "operation %d on unconnected OST\n",
924 req->rq_reqmsg->opc);
925 req->rq_status = -ENOTCONN;
926 GOTO(out, rc = -ENOTCONN);
931 /* Check for aborted recovery. */
932 spin_lock_bh(&obd->obd_processing_task_lock);
933 abort_recovery = obd->obd_abort_recovery;
934 recovering = obd->obd_recovering;
935 spin_unlock_bh(&obd->obd_processing_task_lock);
936 if (abort_recovery) {
937 target_abort_recovery(obd);
938 } else if (recovering) {
939 rc = ost_filter_recovery_request(req, obd,
941 if (rc || !should_process)
948 switch (req->rq_reqmsg->opc) {
950 CDEBUG(D_INODE, "connect\n");
951 OBD_FAIL_RETURN(OBD_FAIL_OST_CONNECT_NET, 0);
952 rc = target_handle_connect(req, ost_handle);
955 CDEBUG(D_INODE, "disconnect\n");
956 OBD_FAIL_RETURN(OBD_FAIL_OST_DISCONNECT_NET, 0);
957 rc = target_handle_disconnect(req);
960 CDEBUG(D_INODE, "create\n");
961 OBD_FAIL_RETURN(OBD_FAIL_OST_CREATE_NET, 0);
962 rc = ost_create(exp, req, oti);
965 CDEBUG(D_INODE, "destroy\n");
966 OBD_FAIL_RETURN(OBD_FAIL_OST_DESTROY_NET, 0);
967 rc = ost_destroy(exp, req, oti);
970 CDEBUG(D_INODE, "getattr\n");
971 OBD_FAIL_RETURN(OBD_FAIL_OST_GETATTR_NET, 0);
972 rc = ost_getattr(exp, req);
975 CDEBUG(D_INODE, "setattr\n");
976 OBD_FAIL_RETURN(OBD_FAIL_OST_SETATTR_NET, 0);
977 rc = ost_setattr(exp, req, oti);
980 CDEBUG(D_INODE, "write\n");
981 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
982 rc = ost_brw_write(req, oti);
983 LASSERT(current->journal_info == NULL);
984 /* ost_brw sends its own replies */
987 CDEBUG(D_INODE, "read\n");
988 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
989 rc = ost_brw_read(req);
990 LASSERT(current->journal_info == NULL);
991 /* ost_brw sends its own replies */
994 CDEBUG(D_INODE, "san read\n");
995 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
996 rc = ost_san_brw(req, OBD_BRW_READ);
997 /* ost_san_brw sends its own replies */
1000 CDEBUG(D_INODE, "san write\n");
1001 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1002 rc = ost_san_brw(req, OBD_BRW_WRITE);
1003 /* ost_san_brw sends its own replies */
1006 CDEBUG(D_INODE, "punch\n");
1007 OBD_FAIL_RETURN(OBD_FAIL_OST_PUNCH_NET, 0);
1008 rc = ost_punch(exp, req, oti);
1011 CDEBUG(D_INODE, "statfs\n");
1012 OBD_FAIL_RETURN(OBD_FAIL_OST_STATFS_NET, 0);
1013 rc = ost_statfs(req);
1016 CDEBUG(D_INODE, "sync\n");
1017 OBD_FAIL_RETURN(OBD_FAIL_OST_SYNC_NET, 0);
1018 rc = ost_sync(exp, req);
1021 DEBUG_REQ(D_INODE, req, "set_info");
1022 rc = ost_set_info(exp, req);
1025 DEBUG_REQ(D_INODE, req, "get_info");
1026 rc = ost_get_info(exp, req);
1029 DEBUG_REQ(D_INODE, req, "ping");
1030 rc = target_handle_ping(req);
1032 /* FIXME - just reply status */
1033 case LLOG_ORIGIN_CONNECT:
1034 DEBUG_REQ(D_INODE, req, "log connect\n");
1035 rc = llog_handle_connect(req);
1036 req->rq_status = rc;
1037 rc = lustre_pack_reply(req, 0, NULL, NULL);
1040 RETURN(ptlrpc_reply(req));
1041 case OBD_LOG_CANCEL:
1042 CDEBUG(D_INODE, "log cancel\n");
1043 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
1044 rc = llog_origin_handle_cancel(req);
1045 req->rq_status = rc;
1046 rc = lustre_pack_reply(req, 0, NULL, NULL);
1049 RETURN(ptlrpc_reply(req));
1051 CDEBUG(D_INODE, "enqueue\n");
1052 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
1053 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1054 ldlm_server_blocking_ast);
1055 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1058 CDEBUG(D_INODE, "convert\n");
1059 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
1060 rc = ldlm_handle_convert(req);
1063 CDEBUG(D_INODE, "cancel\n");
1064 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CANCEL, 0);
1065 rc = ldlm_handle_cancel(req);
1067 case LDLM_BL_CALLBACK:
1068 case LDLM_CP_CALLBACK:
1069 CDEBUG(D_INODE, "callback\n");
1070 CERROR("callbacks should not happen on OST\n");
1073 CERROR("Unexpected opcode %d\n", req->rq_reqmsg->opc);
1074 req->rq_status = -ENOTSUPP;
1075 rc = ptlrpc_error(req);
1079 LASSERT(current->journal_info == NULL);
1082 /* If we're DISCONNECTing, the export_data is already freed */
1083 if (!rc && req->rq_reqmsg->opc != OST_DISCONNECT) {
1084 struct obd_device *obd = req->rq_export->exp_obd;
1085 if (!obd->obd_no_transno) {
1086 req->rq_repmsg->last_committed =
1087 obd->obd_last_committed;
1089 DEBUG_REQ(D_IOCTL, req,
1090 "not sending last_committed update");
1092 CDEBUG(D_INFO, "last_committed "LPU64", xid "LPX64"\n",
1093 obd->obd_last_committed, req->rq_xid);
1097 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LAST_REPLAY) {
1098 struct obd_device *obd = req->rq_export->exp_obd;
1100 if (obd && obd->obd_recovering) {
1101 DEBUG_REQ(D_HA, req, "LAST_REPLAY, queuing reply");
1102 return target_queue_final_reply(req, rc);
1104 /* Lost a race with recovery; let the error path DTRT. */
1105 rc = req->rq_status = -ENOTCONN;
1109 oti_to_request(oti, req);
1111 target_send_reply(req, rc, fail);
1115 static int ost_setup(struct obd_device *obddev, obd_count len, void *buf)
1117 struct ost_obd *ost = &obddev->u.ost;
1121 /* Get rid of unneeded supplementary groups */
1122 current->ngroups = 0;
1123 memset(current->groups, 0, sizeof(current->groups));
1125 rc = llog_start_commit_thread();
1129 ost->ost_service = ptlrpc_init_svc(OST_NEVENTS, OST_NBUFS,
1130 OST_BUFSIZE, OST_MAXREQSIZE,
1131 OST_REQUEST_PORTAL, OSC_REPLY_PORTAL,
1133 obddev->obd_proc_entry);
1134 if (ost->ost_service == NULL) {
1135 CERROR("failed to start service\n");
1139 rc = ptlrpc_start_n_threads(obddev, ost->ost_service, OST_NUM_THREADS,
1142 GOTO(out, rc = -EINVAL);
1144 ost->ost_create_service =
1145 ptlrpc_init_svc(OST_NEVENTS, OST_NBUFS, OST_BUFSIZE,
1146 OST_MAXREQSIZE, OST_CREATE_PORTAL,
1147 OSC_REPLY_PORTAL, ost_handle, "ost_create",
1148 obddev->obd_proc_entry);
1149 if (ost->ost_create_service == NULL) {
1150 CERROR("failed to start OST create service\n");
1151 GOTO(out, rc = -ENOMEM);
1154 rc = ptlrpc_start_n_threads(obddev, ost->ost_create_service, 1,
1157 GOTO(out_create, rc = -EINVAL);
1162 ptlrpc_unregister_service(ost->ost_create_service);
1164 ptlrpc_unregister_service(ost->ost_service);
1168 static int ost_cleanup(struct obd_device *obddev, int flags)
1170 struct ost_obd *ost = &obddev->u.ost;
1174 if (obddev->obd_recovering)
1175 target_cancel_recovery_timer(obddev);
1177 ptlrpc_stop_all_threads(ost->ost_service);
1178 ptlrpc_unregister_service(ost->ost_service);
1180 ptlrpc_stop_all_threads(ost->ost_create_service);
1181 ptlrpc_unregister_service(ost->ost_create_service);
1186 int ost_attach(struct obd_device *dev, obd_count len, void *data)
1188 struct lprocfs_static_vars lvars;
1190 lprocfs_init_vars(ost,&lvars);
1191 return lprocfs_obd_attach(dev, lvars.obd_vars);
1194 int ost_detach(struct obd_device *dev)
1196 return lprocfs_obd_detach(dev);
1199 /* use obd ops to offer management infrastructure */
1200 static struct obd_ops ost_obd_ops = {
1201 o_owner: THIS_MODULE,
1202 o_attach: ost_attach,
1203 o_detach: ost_detach,
1205 o_cleanup: ost_cleanup,
1208 static int __init ost_init(void)
1210 struct lprocfs_static_vars lvars;
1213 lprocfs_init_vars(ost,&lvars);
1214 RETURN(class_register_type(&ost_obd_ops, lvars.module_vars,
1218 static void /*__exit*/ ost_exit(void)
1220 class_unregister_type(LUSTRE_OST_NAME);
1223 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1224 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
1225 MODULE_LICENSE("GPL");
1227 module_init(ost_init);
1228 module_exit(ost_exit);