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 DEBUG_SUBSYSTEM S_OST
36 #include <linux/module.h>
37 #include <linux/obd_ost.h>
38 #include <linux/lustre_net.h>
39 #include <linux/lustre_dlm.h>
40 #include <linux/lustre_export.h>
41 #include <linux/init.h>
42 #include <linux/lprocfs_status.h>
44 inline void oti_to_request(struct obd_trans_info *oti,
45 struct ptlrpc_request *req)
48 struct oti_req_ack_lock *ack_lock;
54 req->rq_repmsg->transno = oti->oti_transno;
56 /* XXX 4 == entries in oti_ack_locks??? */
57 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
60 memcpy(&req->rq_ack_locks[i].lock, &ack_lock->lock,
61 sizeof(req->rq_ack_locks[i].lock));
62 req->rq_ack_locks[i].mode = ack_lock->mode;
67 static int ost_destroy(struct ptlrpc_request *req, struct obd_trans_info *oti)
69 struct lustre_handle *conn = &req->rq_reqmsg->handle;
70 struct ost_body *body;
71 int rc, size = sizeof(*body);
74 body = lustre_swab_reqbuf (req, 0, sizeof (*body),
75 lustre_swab_ost_body);
79 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
83 req->rq_status = obd_destroy(conn, &body->oa, NULL, oti);
87 static int ost_getattr(struct ptlrpc_request *req)
89 struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg;
90 struct ost_body *body, *repbody;
91 int rc, size = sizeof(*body);
94 body = lustre_swab_reqbuf (req, 0, sizeof (*body),
95 lustre_swab_ost_body);
99 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
103 repbody = lustre_msg_buf (req->rq_repmsg, 0, sizeof (*repbody));
104 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
105 req->rq_status = obd_getattr(conn, &repbody->oa, NULL);
109 static int ost_statfs(struct ptlrpc_request *req)
111 struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg;
112 struct obd_statfs *osfs;
113 int rc, size = sizeof(*osfs);
116 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
120 osfs = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*osfs));
121 memset(osfs, 0, size);
123 req->rq_status = obd_statfs(conn, osfs);
124 if (req->rq_status != 0)
125 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
130 static int ost_syncfs(struct ptlrpc_request *req)
132 struct obd_statfs *osfs;
133 int rc, size = sizeof(*osfs);
136 rc = lustre_pack_msg(0, &size, NULL, &req->rq_replen, &req->rq_repmsg);
140 rc = obd_syncfs(req->rq_export);
142 CERROR("ost: syncfs failed: rc %d\n", rc);
150 static int ost_open(struct ptlrpc_request *req, struct obd_trans_info *oti)
152 struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg;
153 struct ost_body *body, *repbody;
154 int rc, size = sizeof(*repbody);
157 body = lustre_swab_reqbuf (req, 0, sizeof (*body),
158 lustre_swab_ost_body);
162 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
166 repbody = lustre_msg_buf (req->rq_repmsg, 0, sizeof (*repbody));
167 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
168 req->rq_status = obd_open(conn, &repbody->oa, NULL, oti, NULL);
172 static int ost_close(struct ptlrpc_request *req, struct obd_trans_info *oti)
174 struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg;
175 struct ost_body *body, *repbody;
176 int rc, size = sizeof(*repbody);
179 body = lustre_swab_reqbuf (req, 0, sizeof (*body),
180 lustre_swab_ost_body);
184 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
188 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*repbody));
189 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
190 req->rq_status = obd_close(conn, &repbody->oa, NULL, oti);
194 static int ost_create(struct ptlrpc_request *req, struct obd_trans_info *oti)
196 struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg;
197 struct ost_body *body, *repbody;
198 int rc, size = sizeof(*repbody);
201 body = lustre_swab_reqbuf (req, 0, sizeof (*body),
202 lustre_swab_ost_body);
206 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
210 repbody = lustre_msg_buf (req->rq_repmsg, 0, sizeof (*repbody));
211 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
212 req->rq_status = obd_create(conn, &repbody->oa, NULL, oti);
216 static int ost_punch(struct ptlrpc_request *req, struct obd_trans_info *oti)
218 struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg;
219 struct ost_body *body, *repbody;
220 int rc, size = sizeof(*repbody);
223 body = lustre_swab_reqbuf (req, 0, sizeof (*body),
224 lustre_swab_ost_body);
228 if ((body->oa.o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
229 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
232 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
236 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*repbody));
237 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
238 req->rq_status = obd_punch(conn, &repbody->oa, NULL, repbody->oa.o_size,
239 repbody->oa.o_blocks, oti);
243 static int ost_setattr(struct ptlrpc_request *req, struct obd_trans_info *oti)
245 struct lustre_handle *conn = &req->rq_reqmsg->handle;
246 struct ost_body *body, *repbody;
247 int rc, size = sizeof(*repbody);
250 body = lustre_swab_reqbuf (req, 0, sizeof (*body),
251 lustre_swab_ost_body);
255 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
259 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*repbody));
260 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
262 req->rq_status = obd_setattr(conn, &repbody->oa, NULL, oti);
266 static int ost_bulk_timeout(void *data)
269 /* We don't fail the connection here, because having the export
270 * killed makes the (vital) call to commitrw very sad.
275 static int get_per_page_niobufs (struct obd_ioobj *ioo, int nioo,
276 struct niobuf_remote *rnb, int nrnb,
277 struct niobuf_remote **pp_rnbp)
279 /* Copy a remote niobuf, splitting it into page-sized chunks
280 * and setting ioo[i].ioo_bufcnt accordingly */
281 struct niobuf_remote *pp_rnb;
288 /* first count and check the number of pages required */
289 for (i = 0; i < nioo; i++)
290 for (j = 0; j < ioo->ioo_bufcnt; j++, rnbidx++) {
291 obd_off offset = rnb[rnbidx].offset;
292 obd_off p0 = offset >> PAGE_SHIFT;
293 obd_off pn = (offset + rnb[rnbidx].len - 1)>>PAGE_SHIFT;
295 LASSERT (rnbidx < nrnb);
297 npages += (pn + 1 - p0);
299 if (rnb[rnbidx].len == 0) {
300 CERROR("zero len BRW: obj %d objid "LPX64
301 " buf %u\n", i, ioo[i].ioo_id, j);
305 rnb[rnbidx].offset <= rnb[rnbidx-1].offset) {
306 CERROR("unordered BRW: obj %d objid "LPX64
307 " buf %u offset "LPX64" <= "LPX64"\n",
308 i, ioo[i].ioo_id, j, rnb[rnbidx].offset,
314 LASSERT (rnbidx == nrnb);
316 if (npages == nrnb) { /* all niobufs are for single pages */
321 OBD_ALLOC (pp_rnb, sizeof (*pp_rnb) * npages);
325 /* now do the actual split */
327 for (i = 0; i < nioo; i++) {
330 for (j = 0; j < ioo[i].ioo_bufcnt; j++, rnbidx++) {
331 obd_off off = rnb[rnbidx].offset;
332 int nob = rnb[rnbidx].len;
334 LASSERT (rnbidx < nrnb);
336 obd_off poff = off & (PAGE_SIZE - 1);
337 int pnob = (poff + nob > PAGE_SIZE) ?
338 PAGE_SIZE - poff : nob;
340 LASSERT (page < npages);
341 pp_rnb[page].len = pnob;
342 pp_rnb[page].offset = off;
343 pp_rnb[page].flags = rnb->flags;
345 CDEBUG (D_PAGE, " obj %d id "LPX64
346 "page %d(%d) "LPX64" for %d\n",
347 i, ioo[i].ioo_id, obj_pages, page,
348 pp_rnb[page].offset, pp_rnb[page].len);
357 ioo[i].ioo_bufcnt = obj_pages;
359 LASSERT (page == npages);
365 static void free_per_page_niobufs (int npages, struct niobuf_remote *pp_rnb,
366 struct niobuf_remote *rnb)
368 if (pp_rnb == rnb) /* didn't allocate above */
371 OBD_FREE (pp_rnb, sizeof (*pp_rnb) * npages);
375 __u64 ost_checksum_bulk (struct ptlrpc_bulk_desc *desc)
378 struct list_head *tmp;
381 list_for_each (tmp, &desc->bd_page_list) {
382 struct ptlrpc_bulk_page *bp;
384 bp = list_entry (tmp, struct ptlrpc_bulk_page, bp_link);
385 ptr = kmap (bp->bp_page);
386 ost_checksum (&cksum, ptr + bp->bp_pageoffset, bp->bp_buflen);
387 kunmap (bp->bp_page);
392 static int ost_brw_read(struct ptlrpc_request *req)
394 struct ptlrpc_bulk_desc *desc;
395 struct niobuf_remote *remote_nb;
396 struct niobuf_remote *pp_rnb;
397 struct niobuf_local *local_nb;
398 struct obd_ioobj *ioo;
399 struct ost_body *body;
400 struct l_wait_info lwi;
401 void *desc_priv = NULL;
402 int size[1] = { sizeof(*body) };
411 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
412 GOTO(out, rc = -EIO);
414 body = lustre_swab_reqbuf (req, 0, sizeof (*body),
415 lustre_swab_ost_body);
417 CERROR ("Missing/short ost_body\n");
418 GOTO (out, rc = -EFAULT);
421 ioo = lustre_swab_reqbuf (req, 1, sizeof (*ioo),
422 lustre_swab_obd_ioobj);
424 CERROR ("Missing/short ioobj\n");
425 GOTO (out, rc = -EFAULT);
428 niocount = ioo->ioo_bufcnt;
429 remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof (*remote_nb),
430 lustre_swab_niobuf_remote);
431 if (remote_nb == NULL) {
432 CERROR ("Missing/short niobuf\n");
433 GOTO (out, rc = -EFAULT);
435 if (lustre_msg_swabbed (req->rq_reqmsg)) { /* swab remaining niobufs */
436 for (i = 1; i < niocount; i++)
437 lustre_swab_niobuf_remote (&remote_nb[i]);
440 rc = lustre_pack_msg(1, size, NULL, &req->rq_replen, &req->rq_repmsg);
444 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
445 npages = get_per_page_niobufs (ioo, 1, remote_nb, niocount, &pp_rnb);
447 GOTO(out, rc = npages);
449 OBD_ALLOC(local_nb, sizeof(*local_nb) * npages);
450 if (local_nb == NULL)
451 GOTO(out_pp_rnb, rc = -ENOMEM);
453 desc = ptlrpc_prep_bulk_exp (req, BULK_PUT_SOURCE, OST_BULK_PORTAL);
455 GOTO(out_local, rc = -ENOMEM);
457 rc = obd_preprw(OBD_BRW_READ, req->rq_export, 1, ioo, npages,
458 pp_rnb, local_nb, &desc_priv, NULL);
463 for (i = 0; i < npages; i++) {
464 int page_rc = local_nb[i].rc;
466 if (page_rc < 0) { /* error */
471 LASSERT (page_rc <= pp_rnb[i].len);
473 if (page_rc != 0) { /* some data! */
474 LASSERT (local_nb[i].page != NULL);
475 rc = ptlrpc_prep_bulk_page(desc, local_nb[i].page,
476 pp_rnb[i].offset& ~PAGE_MASK,
482 if (page_rc != pp_rnb[i].len) { /* short read */
483 /* All subsequent pages should be 0 */
485 LASSERT (local_nb[i].rc == 0);
491 rc = ptlrpc_bulk_put(desc);
493 lwi = LWI_TIMEOUT(obd_timeout * HZ, ost_bulk_timeout,
495 rc = l_wait_event(desc->bd_waitq,
496 ptlrpc_bulk_complete(desc), &lwi);
498 LASSERT(rc == -ETIMEDOUT);
499 CERROR ("timeout waiting for bulk PUT\n");
500 ptlrpc_abort_bulk (desc);
503 comms_error = rc != 0;
506 /* Must commit after prep above in all cases */
507 rc = obd_commitrw(OBD_BRW_READ, req->rq_export, 1, ioo, npages,
508 local_nb, desc_priv, NULL);
512 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body));
513 body->oa.o_rdev = ost_checksum_bulk (desc);
514 body->oa.o_valid |= OBD_MD_FLCKSUM;
519 ptlrpc_free_bulk (desc);
521 OBD_FREE(local_nb, sizeof(*local_nb) * npages);
523 free_per_page_niobufs (npages, pp_rnb, remote_nb);
527 req->rq_status = nob;
529 } else if (!comms_error) {
530 /* only reply if comms OK */
534 if (req->rq_repmsg != NULL) {
535 /* reply out callback would free */
536 OBD_FREE (req->rq_repmsg, req->rq_replen);
538 CERROR("bulk IO comms error: evicting %s@%s nid "LPU64"\n",
539 req->rq_export->exp_client_uuid.uuid,
540 req->rq_connection->c_remote_uuid.uuid,
541 req->rq_connection->c_peer.peer_nid);
542 ptlrpc_fail_export(req->rq_export);
548 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
550 struct ptlrpc_bulk_desc *desc;
551 struct niobuf_remote *remote_nb;
552 struct niobuf_remote *pp_rnb;
553 struct niobuf_local *local_nb;
554 struct obd_ioobj *ioo;
555 struct ost_body *body;
556 struct l_wait_info lwi;
557 void *desc_priv = NULL;
559 int size[2] = { sizeof (*body) };
560 int objcount, niocount, npages;
562 int rc, rc2, swab, i, j;
565 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
566 GOTO(out, rc = -EIO);
568 swab = lustre_msg_swabbed (req->rq_reqmsg);
569 body = lustre_swab_reqbuf (req, 0, sizeof (*body),
570 lustre_swab_ost_body);
572 CERROR ("Missing/short ost_body\n");
573 GOTO(out, rc = -EFAULT);
576 LASSERT_REQSWAB (req, 1);
577 objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
579 CERROR ("Missing/short ioobj\n");
580 GOTO (out, rc = -EFAULT);
582 ioo = lustre_msg_buf (req->rq_reqmsg, 1, objcount * sizeof (*ioo));
583 LASSERT (ioo != NULL);
584 for (niocount = i = 0; i < objcount; i++) {
586 lustre_swab_obd_ioobj (&ioo[i]);
587 if (ioo[i].ioo_bufcnt == 0) {
588 CERROR ("ioo[%d] has zero bufcnt\n", i);
589 GOTO (out, rc = -EFAULT);
591 niocount += ioo[i].ioo_bufcnt;
594 remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof (*remote_nb),
595 lustre_swab_niobuf_remote);
596 if (remote_nb == NULL) {
597 CERROR ("Missing/short niobuf\n");
598 GOTO(out, rc = -EFAULT);
600 if (swab) { /* swab the remaining niobufs */
601 for (i = 1; i < niocount; i++)
602 lustre_swab_niobuf_remote (&remote_nb[i]);
605 size[1] = niocount * sizeof (*rcs);
606 rc = lustre_pack_msg(2, size, NULL, &req->rq_replen,
610 rcs = lustre_msg_buf (req->rq_repmsg, 1, niocount * sizeof (*rcs));
612 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
613 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
615 GOTO (out, rc = npages);
617 OBD_ALLOC(local_nb, sizeof(*local_nb) * npages);
618 if (local_nb == NULL)
619 GOTO(out_pp_rnb, rc = -ENOMEM);
621 desc = ptlrpc_prep_bulk_exp (req, BULK_GET_SINK, OST_BULK_PORTAL);
623 GOTO(out_local, rc = -ENOMEM);
625 rc = obd_preprw(OBD_BRW_WRITE, req->rq_export, objcount, ioo,
626 npages, pp_rnb, local_nb, &desc_priv, oti);
630 /* NB Having prepped, we must commit... */
632 for (i = 0; i < npages; i++) {
633 rc = ptlrpc_prep_bulk_page(desc, local_nb[i].page,
634 pp_rnb[i].offset & (PAGE_SIZE - 1),
641 rc = ptlrpc_bulk_get(desc);
643 lwi = LWI_TIMEOUT(obd_timeout * HZ, ost_bulk_timeout,
645 rc = l_wait_event(desc->bd_waitq,
646 ptlrpc_bulk_complete(desc), &lwi);
648 LASSERT(rc == -ETIMEDOUT);
649 CERROR ("timeout waiting for bulk GET\n");
650 ptlrpc_abort_bulk (desc);
653 comms_error = rc != 0;
657 if (rc == 0 && (body->oa.o_valid & OBD_MD_FLCKSUM) != 0) {
658 static int cksum_counter;
659 __u64 client_cksum = body->oa.o_rdev;
660 __u64 cksum = ost_checksum_bulk (desc);
662 if (client_cksum != cksum) {
663 CERROR("Bad checksum: client "LPX64", server "LPX64
664 ", client NID "LPX64"\n", client_cksum, cksum,
665 req->rq_connection->c_peer.peer_nid);
669 if ((cksum_counter & (-cksum_counter)) == cksum_counter)
670 CERROR("Checksum %d from "LPX64": "LPX64" OK\n",
672 req->rq_connection->c_peer.peer_nid,
677 /* Must commit after prep above in all cases */
678 rc2 = obd_commitrw(OBD_BRW_WRITE, req->rq_export, objcount, ioo,
679 npages, local_nb, desc_priv, oti);
682 /* set per-requested niobuf return codes */
683 for (i = j = 0; i < niocount; i++) {
684 int nob = remote_nb[i].len;
688 LASSERT (j < npages);
689 if (local_nb[j].rc < 0)
690 rcs[i] = local_nb[j].rc;
691 nob -= pp_rnb[j].len;
696 LASSERT (j == npages);
702 ptlrpc_free_bulk (desc);
704 OBD_FREE(local_nb, sizeof(*local_nb) * npages);
706 free_per_page_niobufs (npages, pp_rnb, remote_nb);
709 oti_to_request(oti, req);
710 rc = ptlrpc_reply(req);
711 } else if (!comms_error) {
712 /* Only reply if there was no comms problem with bulk */
716 if (req->rq_repmsg != NULL) {
717 /* reply out callback would free */
718 OBD_FREE (req->rq_repmsg, req->rq_replen);
720 CERROR("bulk IO comms error: evicting %s@%s nid "LPU64"\n",
721 req->rq_export->exp_client_uuid.uuid,
722 req->rq_connection->c_remote_uuid.uuid,
723 req->rq_connection->c_peer.peer_nid);
724 ptlrpc_fail_export(req->rq_export);
729 static int ost_san_brw(struct ptlrpc_request *req, int cmd)
731 struct lustre_handle *conn = &req->rq_reqmsg->handle;
732 struct niobuf_remote *remote_nb, *res_nb;
733 struct obd_ioobj *ioo;
734 struct ost_body *body;
735 int rc, i, j, objcount, niocount, size[2] = {sizeof(*body)};
740 /* XXX not set to use latest protocol */
742 swab = lustre_msg_swabbed (req->rq_reqmsg);
743 body = lustre_swab_reqbuf (req, 0, sizeof (*body),
744 lustre_swab_ost_body);
746 CERROR ("Missing/short ost_body\n");
747 GOTO (out, rc = -EFAULT);
750 ioo = lustre_swab_reqbuf(req, 1, sizeof (*ioo),
751 lustre_swab_obd_ioobj);
753 CERROR ("Missing/short ioobj\n");
754 GOTO (out, rc = -EFAULT);
756 objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
757 niocount = ioo[0].ioo_bufcnt;
758 for (i = 1; i < objcount; i++) {
760 lustre_swab_obd_ioobj (&ioo[i]);
761 niocount += ioo[i].ioo_bufcnt;
764 remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof (*remote_nb),
765 lustre_swab_niobuf_remote);
766 if (remote_nb == NULL) {
767 CERROR ("Missing/short niobuf\n");
768 GOTO (out, rc = -EFAULT);
770 if (swab) { /* swab the remaining niobufs */
771 for (i = 1; i < niocount; i++)
772 lustre_swab_niobuf_remote (&remote_nb[i]);
775 for (i = n = 0; i < objcount; i++) {
776 for (j = 0; j < ioo[i].ioo_bufcnt; j++, n++) {
777 if (remote_nb[n].len == 0) {
778 CERROR("zero len BRW: objid "LPX64" buf %u\n",
780 GOTO(out, rc = -EINVAL);
782 if (j && remote_nb[n].offset <= remote_nb[n-1].offset) {
783 CERROR("unordered BRW: objid "LPX64
784 " buf %u offset "LPX64" <= "LPX64"\n",
785 ioo[i].ioo_id, j, remote_nb[n].offset,
786 remote_nb[n-1].offset);
787 GOTO(out, rc = -EINVAL);
792 size[1] = niocount * sizeof(*remote_nb);
793 rc = lustre_pack_msg(2, size, NULL, &req->rq_replen, &req->rq_repmsg);
797 req->rq_status = obd_san_preprw(cmd, conn, objcount, ioo,
798 niocount, remote_nb);
803 res_nb = lustre_msg_buf(req->rq_repmsg, 1, size[1]);
804 memcpy (res_nb, remote_nb, size[1]);
808 OBD_FREE(req->rq_repmsg, req->rq_replen);
809 req->rq_repmsg = NULL;
818 static int filter_recovery_request(struct ptlrpc_request *req,
819 struct obd_device *obd, int *process)
821 switch (req->rq_reqmsg->opc) {
822 case OST_CONNECT: /* This will never get here, but for completeness. */
837 *process = target_queue_recovery_request(req, obd);
841 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
843 /* XXX what should we set rq_status to here? */
844 req->rq_status = -EAGAIN;
845 RETURN(ptlrpc_error(req));
851 static int ost_handle(struct ptlrpc_request *req)
853 struct obd_trans_info trans_info = { 0, }, *oti = &trans_info;
854 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
857 /* XXX identical to MDS */
858 if (req->rq_reqmsg->opc != OST_CONNECT) {
859 struct obd_device *obd;
860 int abort_recovery, recovering;
862 if (req->rq_export == NULL) {
863 CERROR("lustre_ost: operation %d on unconnected OST\n",
864 req->rq_reqmsg->opc);
865 req->rq_status = -ENOTCONN;
866 GOTO(out, rc = -ENOTCONN);
869 obd = req->rq_export->exp_obd;
871 /* Check for aborted recovery. */
872 spin_lock_bh(&obd->obd_processing_task_lock);
873 abort_recovery = obd->obd_abort_recovery;
874 recovering = obd->obd_recovering;
875 spin_unlock_bh(&obd->obd_processing_task_lock);
876 if (abort_recovery) {
877 target_abort_recovery(obd);
878 } else if (recovering) {
879 rc = filter_recovery_request(req, obd, &should_process);
880 if (rc || !should_process)
885 if (strcmp(req->rq_obd->obd_type->typ_name, "ost") != 0)
886 GOTO(out, rc = -EINVAL);
888 switch (req->rq_reqmsg->opc) {
890 CDEBUG(D_INODE, "connect\n");
891 OBD_FAIL_RETURN(OBD_FAIL_OST_CONNECT_NET, 0);
892 rc = target_handle_connect(req, ost_handle);
895 CDEBUG(D_INODE, "disconnect\n");
896 OBD_FAIL_RETURN(OBD_FAIL_OST_DISCONNECT_NET, 0);
897 rc = target_handle_disconnect(req);
900 CDEBUG(D_INODE, "create\n");
901 OBD_FAIL_RETURN(OBD_FAIL_OST_CREATE_NET, 0);
902 rc = ost_create(req, oti);
905 CDEBUG(D_INODE, "destroy\n");
906 OBD_FAIL_RETURN(OBD_FAIL_OST_DESTROY_NET, 0);
907 rc = ost_destroy(req, oti);
910 CDEBUG(D_INODE, "getattr\n");
911 OBD_FAIL_RETURN(OBD_FAIL_OST_GETATTR_NET, 0);
912 rc = ost_getattr(req);
915 CDEBUG(D_INODE, "setattr\n");
916 OBD_FAIL_RETURN(OBD_FAIL_OST_SETATTR_NET, 0);
917 rc = ost_setattr(req, oti);
920 CDEBUG(D_INODE, "open\n");
921 OBD_FAIL_RETURN(OBD_FAIL_OST_OPEN_NET, 0);
922 rc = ost_open(req, oti);
925 CDEBUG(D_INODE, "close\n");
926 OBD_FAIL_RETURN(OBD_FAIL_OST_CLOSE_NET, 0);
927 rc = ost_close(req, oti);
930 CDEBUG(D_INODE, "write\n");
931 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
932 rc = ost_brw_write(req, oti);
933 /* ost_brw sends its own replies */
936 CDEBUG(D_INODE, "read\n");
937 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
938 rc = ost_brw_read(req);
939 /* ost_brw sends its own replies */
942 CDEBUG(D_INODE, "san read\n");
943 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
944 rc = ost_san_brw(req, OBD_BRW_READ);
945 /* ost_san_brw sends its own replies */
948 CDEBUG(D_INODE, "san write\n");
949 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
950 rc = ost_san_brw(req, OBD_BRW_WRITE);
951 /* ost_san_brw sends its own replies */
954 CDEBUG(D_INODE, "punch\n");
955 OBD_FAIL_RETURN(OBD_FAIL_OST_PUNCH_NET, 0);
956 rc = ost_punch(req, oti);
959 CDEBUG(D_INODE, "statfs\n");
960 OBD_FAIL_RETURN(OBD_FAIL_OST_STATFS_NET, 0);
961 rc = ost_statfs(req);
964 CDEBUG(D_INODE, "sync\n");
965 OBD_FAIL_RETURN(OBD_FAIL_OST_SYNCFS_NET, 0);
966 rc = ost_syncfs(req);
969 DEBUG_REQ(D_INODE, req, "ping");
970 rc = target_handle_ping(req);
973 CDEBUG(D_INODE, "enqueue\n");
974 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
975 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
976 ldlm_server_blocking_ast);
977 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
980 CDEBUG(D_INODE, "convert\n");
981 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
982 rc = ldlm_handle_convert(req);
985 CDEBUG(D_INODE, "cancel\n");
986 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CANCEL, 0);
987 rc = ldlm_handle_cancel(req);
989 case LDLM_BL_CALLBACK:
990 case LDLM_CP_CALLBACK:
991 CDEBUG(D_INODE, "callback\n");
992 CERROR("callbacks should not happen on OST\n");
995 CERROR("Unexpected opcode %d\n", req->rq_reqmsg->opc);
996 req->rq_status = -ENOTSUPP;
997 rc = ptlrpc_error(req);
1002 /* If we're DISCONNECTing, the export_data is already freed */
1003 if (!rc && req->rq_reqmsg->opc != OST_DISCONNECT) {
1004 struct obd_device *obd = req->rq_export->exp_obd;
1005 if (!obd->obd_no_transno) {
1006 req->rq_repmsg->last_committed =
1007 obd->obd_last_committed;
1009 DEBUG_REQ(D_IOCTL, req,
1010 "not sending last_committed update");
1012 CDEBUG(D_INFO, "last_committed "LPU64", xid "LPX64"\n",
1013 obd->obd_last_committed, req->rq_xid);
1017 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LAST_REPLAY) {
1018 struct obd_device *obd = req->rq_export->exp_obd;
1020 if (obd && obd->obd_recovering) {
1021 DEBUG_REQ(D_HA, req, "LAST_REPLAY, queuing reply");
1022 return target_queue_final_reply(req, rc);
1024 /* Lost a race with recovery; let the error path DTRT. */
1025 rc = req->rq_status = -ENOTCONN;
1029 oti_to_request(oti, req);
1031 target_send_reply(req, rc, fail);
1035 static int ost_setup(struct obd_device *obddev, obd_count len, void *buf)
1037 struct ost_obd *ost = &obddev->u.ost;
1042 ost->ost_service = ptlrpc_init_svc(OST_NEVENTS, OST_NBUFS,
1043 OST_BUFSIZE, OST_MAXREQSIZE,
1044 OST_REQUEST_PORTAL, OSC_REPLY_PORTAL,
1045 ost_handle, "ost", obddev);
1046 if (!ost->ost_service) {
1047 CERROR("failed to start service\n");
1048 GOTO(error_disc, err = -ENOMEM);
1051 for (i = 0; i < OST_NUM_THREADS; i++) {
1053 sprintf(name, "ll_ost_%02d", i);
1054 err = ptlrpc_start_thread(obddev, ost->ost_service, name);
1056 CERROR("error starting thread #%d: rc %d\n", i, err);
1057 GOTO(error_disc, err = -EINVAL);
1067 static int ost_cleanup(struct obd_device *obddev, int force, int failover)
1069 struct ost_obd *ost = &obddev->u.ost;
1073 if (obddev->obd_recovering)
1074 target_cancel_recovery_timer(obddev);
1076 ptlrpc_stop_all_threads(ost->ost_service);
1077 ptlrpc_unregister_service(ost->ost_service);
1082 int ost_attach(struct obd_device *dev, obd_count len, void *data)
1084 struct lprocfs_static_vars lvars;
1086 lprocfs_init_vars(&lvars);
1087 return lprocfs_obd_attach(dev, lvars.obd_vars);
1090 int ost_detach(struct obd_device *dev)
1092 return lprocfs_obd_detach(dev);
1095 /* I don't think this function is ever used, since nothing
1096 * connects directly to this module.
1098 static int ost_connect(struct lustre_handle *conn,
1099 struct obd_device *obd, struct obd_uuid *cluuid)
1101 struct obd_export *exp;
1105 if (!conn || !obd || !cluuid)
1108 rc = class_connect(conn, obd, cluuid);
1111 exp = class_conn2export(conn);
1113 class_export_put(exp);
1118 /* use obd ops to offer management infrastructure */
1119 static struct obd_ops ost_obd_ops = {
1120 o_owner: THIS_MODULE,
1121 o_attach: ost_attach,
1122 o_detach: ost_detach,
1124 o_cleanup: ost_cleanup,
1125 o_connect: ost_connect,
1128 static int __init ost_init(void)
1130 struct lprocfs_static_vars lvars;
1133 lprocfs_init_vars(&lvars);
1134 RETURN(class_register_type(&ost_obd_ops, lvars.module_vars,
1138 static void __exit ost_exit(void)
1140 class_unregister_type(LUSTRE_OST_NAME);
1143 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1144 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
1145 MODULE_LICENSE("GPL");
1147 module_init(ost_init);
1148 module_exit(ost_exit);