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 <libcfs/list.h>
47 #include <linux/lustre_sec.h>
48 #include <linux/lustre_audit.h>
50 void oti_init(struct obd_trans_info *oti, struct ptlrpc_request *req)
54 memset(oti, 0, sizeof *oti);
55 oti->oti_nid = req->rq_peer.peer_id.nid;
56 if (req->rq_repmsg && req->rq_reqmsg != 0)
57 oti->oti_transno = req->rq_repmsg->transno;
60 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
62 struct oti_req_ack_lock *ack_lock;
69 req->rq_repmsg->transno = oti->oti_transno;
71 /* XXX 4 == entries in oti_ack_locks??? */
72 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
75 /* XXX not even calling target_send_reply in some cases... */
76 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode);
80 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
81 struct obd_trans_info *oti)
83 struct ost_body *body, *repbody;
84 int rc, size = sizeof(*body);
87 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
91 rc = lustre_pack_reply(req, 1, &size, NULL);
95 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
96 oti->oti_logcookies = obdo_logcookie(&body->oa);
97 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
98 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
99 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti);
103 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
105 struct ost_body *body, *repbody;
106 int rc, size = sizeof(*body);
109 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
113 rc = lustre_pack_reply(req, 1, &size, NULL);
117 repbody = lustre_msg_buf (req->rq_repmsg, 0, sizeof(*repbody));
118 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
119 req->rq_status = obd_getattr(exp, &repbody->oa, NULL);
123 static int ost_statfs(struct ptlrpc_request *req)
125 struct obd_statfs *osfs;
126 int rc, size = sizeof(*osfs);
129 rc = lustre_pack_reply(req, 1, &size, NULL);
133 osfs = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*osfs));
135 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs, jiffies-HZ);
136 if (req->rq_status != 0)
137 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
142 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
143 struct obd_trans_info *oti)
145 struct ost_body *body, *repbody;
146 int rc, size = sizeof(*repbody);
149 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
153 rc = lustre_pack_reply(req, 1, &size, NULL);
157 repbody = lustre_msg_buf (req->rq_repmsg, 0, sizeof(*repbody));
158 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
159 oti->oti_logcookies = obdo_logcookie(&repbody->oa);
160 req->rq_status = obd_create(exp, &repbody->oa, NULL, 0, NULL, oti);
161 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
165 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
166 struct obd_trans_info *oti)
168 struct ost_body *body, *repbody;
169 struct lustre_capa *capa = NULL;
170 int rc, size = sizeof(*repbody);
173 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
177 if ((body->oa.o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
178 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
181 if (body->oa.o_valid & OBD_MD_CAPA) {
182 capa = lustre_swab_reqbuf(req, 1, sizeof(*capa),
183 lustre_swab_lustre_capa);
185 CERROR("Missing/short capa\n");
190 rc = lustre_pack_reply(req, 1, &size, NULL);
194 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
195 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
196 req->rq_status = obd_punch(exp, &repbody->oa, NULL, repbody->oa.o_size,
197 repbody->oa.o_blocks, oti, capa);
201 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
203 struct ost_body *body, *repbody;
204 int rc, size = sizeof(*repbody);
207 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
211 rc = lustre_pack_reply(req, 1, &size, NULL);
215 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
216 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
217 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
218 repbody->oa.o_blocks);
222 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
223 struct obd_trans_info *oti)
225 struct ost_body *body, *repbody;
226 int rc, size = sizeof(*repbody);
229 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
233 rc = lustre_pack_reply(req, 1, &size, NULL);
237 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
238 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
240 req->rq_status = obd_setattr(exp, &repbody->oa, NULL, oti, NULL);
244 static int ost_bulk_timeout(void *data)
247 /* We don't fail the connection here, because having the export
248 * killed makes the (vital) call to commitrw very sad.
253 static int get_per_page_niobufs(struct obd_ioobj *ioo, int nioo,
254 struct niobuf_remote *rnb, int nrnb,
255 struct niobuf_remote **pp_rnbp)
257 /* Copy a remote niobuf, splitting it into page-sized chunks
258 * and setting ioo[i].ioo_bufcnt accordingly */
259 struct niobuf_remote *pp_rnb;
266 /* first count and check the number of pages required */
267 for (i = 0; i < nioo; i++)
268 for (j = 0; j < ioo->ioo_bufcnt; j++, rnbidx++) {
269 obd_off offset = rnb[rnbidx].offset;
270 obd_off p0 = offset >> PAGE_SHIFT;
271 obd_off pn = (offset + rnb[rnbidx].len - 1)>>PAGE_SHIFT;
273 LASSERT(rnbidx < nrnb);
275 npages += (pn + 1 - p0);
277 if (rnb[rnbidx].len == 0) {
278 CERROR("zero len BRW: obj %d objid "LPX64
279 " buf %u\n", i, ioo[i].ioo_id, j);
283 rnb[rnbidx].offset <= rnb[rnbidx-1].offset) {
284 CERROR("unordered BRW: obj %d objid "LPX64
285 " buf %u offset "LPX64" <= "LPX64"\n",
286 i, ioo[i].ioo_id, j, rnb[rnbidx].offset,
292 LASSERT(rnbidx == nrnb);
294 if (npages == nrnb) { /* all niobufs are for single pages */
299 OBD_ALLOC(pp_rnb, sizeof(*pp_rnb) * npages);
303 /* now do the actual split */
305 for (i = 0; i < nioo; i++) {
308 for (j = 0; j < ioo[i].ioo_bufcnt; j++, rnbidx++) {
309 obd_off off = rnb[rnbidx].offset;
310 int nob = rnb[rnbidx].len;
312 LASSERT(rnbidx < nrnb);
314 obd_off poff = off & (PAGE_SIZE - 1);
315 int pnob = (poff + nob > PAGE_SIZE) ?
316 PAGE_SIZE - poff : nob;
318 LASSERT(page < npages);
319 pp_rnb[page].len = pnob;
320 pp_rnb[page].offset = off;
321 pp_rnb[page].flags = rnb[rnbidx].flags;
323 CDEBUG(0, " obj %d id "LPX64
324 "page %d(%d) "LPX64" for %d, flg %x\n",
325 i, ioo[i].ioo_id, obj_pages, page,
326 pp_rnb[page].offset, pp_rnb[page].len,
336 ioo[i].ioo_bufcnt = obj_pages;
338 LASSERT(page == npages);
344 static void free_per_page_niobufs (int npages, struct niobuf_remote *pp_rnb,
345 struct niobuf_remote *rnb)
347 if (pp_rnb == rnb) /* didn't allocate above */
350 OBD_FREE(pp_rnb, sizeof(*pp_rnb) * npages);
354 obd_count ost_checksum_bulk(struct ptlrpc_bulk_desc *desc)
357 struct ptlrpc_bulk_page *bp;
359 list_for_each_entry(bp, &desc->bd_page_list, bp_link) {
360 ost_checksum(&cksum, kmap(bp->bp_page) + bp->bp_pageoffset,
369 static void ost_stime_record(struct ptlrpc_request *req, struct timeval *start,
370 unsigned rw, unsigned phase)
372 struct obd_device *obd = req->rq_svc->srv_obddev;
374 int ind = rw *3 + phase;
376 if (obd && obd->obd_type && obd->obd_type->typ_name) {
377 if (!strcmp(obd->obd_type->typ_name, OBD_OST_DEVICENAME)) {
378 struct ost_obd *ost = NULL;
381 if (ind >= (sizeof(ost->ost_stimes) /
382 sizeof(ost->ost_stimes[0])))
384 do_gettimeofday(&stop);
386 spin_lock(&ost->ost_lock);
387 lprocfs_stime_record(&ost->ost_stimes[ind],&stop,start);
388 spin_unlock(&ost->ost_lock);
389 memcpy(start, &stop, sizeof(*start));
394 static int ost_brw_read(struct ptlrpc_request *req)
396 struct ptlrpc_bulk_desc *desc;
397 struct niobuf_remote *remote_nb;
398 struct niobuf_remote *pp_rnb;
399 struct niobuf_local *local_nb;
400 struct obd_ioobj *ioo;
401 struct ost_body *body, *repbody;
402 struct lustre_capa *capa = NULL;
403 struct l_wait_info lwi;
404 struct obd_trans_info oti = { 0 };
405 int size[1] = { sizeof(*body) };
412 struct timeval start;
415 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
416 GOTO(out, rc = -EIO);
418 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
419 (obd_timeout + 1) / 4);
421 body = lustre_swab_reqbuf(req, bufcnt++, sizeof(*body),
422 lustre_swab_ost_body);
424 CERROR("Missing/short ost_body\n");
425 GOTO(out, rc = -EFAULT);
428 ioo = lustre_swab_reqbuf(req, bufcnt++, sizeof(*ioo),
429 lustre_swab_obd_ioobj);
431 CERROR("Missing/short ioobj\n");
432 GOTO(out, rc = -EFAULT);
435 if (body->oa.o_valid & OBD_MD_CAPA) {
436 capa = lustre_swab_reqbuf(req, bufcnt++, sizeof(*capa),
437 lustre_swab_lustre_capa);
439 CERROR("Missing/short capa\n");
440 GOTO(out, rc = -EFAULT);
444 niocount = ioo->ioo_bufcnt;
445 remote_nb = lustre_swab_reqbuf(req, bufcnt++,
446 niocount * sizeof(*remote_nb),
447 lustre_swab_niobuf_remote);
448 if (remote_nb == NULL) {
449 CERROR("Missing/short niobuf\n");
450 GOTO(out, rc = -EFAULT);
452 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
453 for (i = 1; i < niocount; i++)
454 lustre_swab_niobuf_remote (&remote_nb[i]);
457 rc = lustre_pack_reply(req, 1, size, NULL);
461 /* FIXME all niobuf splitting should be done in obdfilter if needed */
462 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
463 npages = get_per_page_niobufs(ioo, 1, remote_nb, niocount, &pp_rnb);
465 GOTO(out, rc = npages);
467 OBD_ALLOC(local_nb, sizeof(*local_nb) * npages);
468 if (local_nb == NULL)
469 GOTO(out_pp_rnb, rc = -ENOMEM);
471 desc = ptlrpc_prep_bulk_exp (req, npages,
472 BULK_PUT_SOURCE, OST_BULK_PORTAL);
474 GOTO(out_local, rc = -ENOMEM);
476 do_gettimeofday(&start);
477 rc = obd_preprw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
478 ioo, npages, pp_rnb, local_nb, &oti, capa);
479 ost_stime_record(req, &start, 0, 0);
483 /* We're finishing using body->oa as an input variable */
484 body->oa.o_valid = 0;
487 for (i = 0; i < npages; i++) {
488 int page_rc = local_nb[i].rc;
490 if (page_rc < 0) { /* error */
495 LASSERT(page_rc <= pp_rnb[i].len);
497 if (page_rc != 0) { /* some data! */
498 LASSERT (local_nb[i].page != NULL);
499 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
500 pp_rnb[i].offset & (PAGE_SIZE-1),
504 if (page_rc != pp_rnb[i].len) { /* short read */
505 /* All subsequent pages should be 0 */
507 LASSERT(local_nb[i].rc == 0);
513 rc = ptlrpc_start_bulk_transfer(desc);
515 struct timeval tstart, now;
516 do_gettimeofday(&tstart);
517 lwi = LWI_TIMEOUT(obd_timeout * HZ / 4,
518 ost_bulk_timeout, desc);
519 rc = l_wait_event(desc->bd_waitq,
520 !ptlrpc_bulk_active(desc), &lwi);
521 LASSERT(rc == 0 || rc == -ETIMEDOUT);
522 do_gettimeofday(&now);
523 if (rc == -ETIMEDOUT) {
524 DEBUG_REQ(D_ERROR, req, "timeout on bulk PUT"
525 ", expt_conn_cnt = %u, real wait %us"
526 ", arrived %u.%u, served %u.%u",
527 req->rq_export->exp_conn_cnt,
528 (unsigned) (now.tv_sec - tstart.tv_sec),
529 (unsigned) req->rq_arrival_time.tv_sec,
530 (unsigned) req->rq_arrival_time.tv_usec,
531 (unsigned) req->rq_rpcd_start.tv_sec,
532 (unsigned) req->rq_rpcd_start.tv_usec);
533 ptlrpc_abort_bulk(desc);
534 } else if (!desc->bd_success ||
535 desc->bd_nob_transferred != desc->bd_nob) {
536 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
538 "truncated" : "network error on",
539 desc->bd_nob_transferred,
541 /* XXX should this be a different errno? */
545 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d\n", rc);
547 comms_error = rc != 0;
550 ost_stime_record(req, &start, 0, 1);
551 /* Must commit after prep above in all cases */
552 rc = obd_commitrw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
553 ioo, npages, local_nb, &oti, rc);
554 ost_stime_record(req, &start, 0, 2);
557 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
558 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
561 repbody->oa.o_cksum = ost_checksum_bulk(desc);
562 repbody->oa.o_valid |= OBD_MD_FLCKSUM;
567 ptlrpc_free_bulk(desc);
569 OBD_FREE(local_nb, sizeof(*local_nb) * npages);
571 free_per_page_niobufs(npages, pp_rnb, remote_nb);
575 req->rq_status = nob;
577 } else if (!comms_error) {
578 /* only reply if comms OK */
582 if (req->rq_reply_state != NULL) {
583 /* reply out callback would free */
584 lustre_free_reply_state (req->rq_reply_state);
586 if (req->rq_reqmsg->conn_cnt == req->rq_export->exp_conn_cnt) {
587 CERROR("bulk IO comms error: "
588 "evicting %s@%s id %s\n",
589 req->rq_export->exp_client_uuid.uuid,
590 req->rq_export->exp_connection->c_remote_uuid.uuid,
592 ptlrpc_fail_export(req->rq_export);
594 CERROR("ignoring bulk IO comms error: "
595 "client reconnected %s@%s id %s\n",
596 req->rq_export->exp_client_uuid.uuid,
597 req->rq_export->exp_connection->c_remote_uuid.uuid,
605 int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
607 struct ptlrpc_bulk_desc *desc;
608 struct niobuf_remote *remote_nb;
609 struct niobuf_remote *pp_rnb;
610 struct niobuf_local *local_nb;
611 struct obd_ioobj *ioo;
612 struct lustre_capa *capa = NULL;
613 struct ost_body *body, *repbody;
614 struct l_wait_info lwi;
616 int size[2] = { sizeof(*body) };
617 int objcount, niocount, npages;
619 int rc, swab, i, j, bufcnt = 0;
620 struct timeval start;
623 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
624 GOTO(out, rc = -EIO);
626 /* pause before transaction has been started */
627 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
628 (obd_timeout + 1) / 4);
630 swab = lustre_msg_swabbed(req->rq_reqmsg);
631 body = lustre_swab_reqbuf(req, bufcnt++, sizeof(*body),
632 lustre_swab_ost_body);
634 CERROR("Missing/short ost_body\n");
635 GOTO(out, rc = -EFAULT);
638 LASSERT_REQSWAB(req, 1);
639 objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
641 CERROR("Missing/short ioobj\n");
642 GOTO(out, rc = -EFAULT);
644 ioo = lustre_msg_buf(req->rq_reqmsg, bufcnt++,
645 objcount * sizeof(*ioo));
646 LASSERT (ioo != NULL);
647 for (niocount = i = 0; i < objcount; i++) {
649 lustre_swab_obd_ioobj (&ioo[i]);
650 if (ioo[i].ioo_bufcnt == 0) {
651 CERROR("ioo[%d] has zero bufcnt\n", i);
652 GOTO(out, rc = -EFAULT);
654 niocount += ioo[i].ioo_bufcnt;
657 if (body->oa.o_valid & OBD_MD_CAPA) {
658 capa = lustre_swab_reqbuf(req, bufcnt++, sizeof(*capa),
659 lustre_swab_lustre_capa);
661 CERROR("Missing/short capa\n");
662 GOTO(out, rc = -EFAULT);
666 remote_nb = lustre_swab_reqbuf(req, bufcnt++,
667 niocount * sizeof(*remote_nb),
668 lustre_swab_niobuf_remote);
669 if (remote_nb == NULL) {
670 CERROR("Missing/short niobuf\n");
671 GOTO(out, rc = -EFAULT);
673 if (swab) { /* swab the remaining niobufs */
674 for (i = 1; i < niocount; i++)
675 lustre_swab_niobuf_remote (&remote_nb[i]);
678 size[1] = niocount * sizeof(*rcs);
679 rc = lustre_pack_reply(req, 2, size, NULL);
682 rcs = lustre_msg_buf(req->rq_repmsg, 1, niocount * sizeof(*rcs));
685 /* Do snap options here*/
686 rc = obd_do_cow(req->rq_export, ioo, objcount, remote_nb);
691 /* FIXME all niobuf splitting should be done in obdfilter if needed */
692 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
693 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
695 GOTO(out, rc = npages);
697 OBD_ALLOC(local_nb, sizeof(*local_nb) * npages);
698 if (local_nb == NULL)
699 GOTO(out_pp_rnb, rc = -ENOMEM);
701 desc = ptlrpc_prep_bulk_exp (req, npages,
702 BULK_GET_SINK, OST_BULK_PORTAL);
704 GOTO(out_local, rc = -ENOMEM);
706 do_gettimeofday(&start);
707 rc = obd_preprw(OBD_BRW_WRITE, req->rq_export, &body->oa, objcount,
708 ioo, npages, pp_rnb, local_nb, oti, capa);
709 ost_stime_record(req, &start, 1, 0);
713 /* NB Having prepped, we must commit... */
715 for (i = 0; i < npages; i++)
716 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
717 pp_rnb[i].offset & (PAGE_SIZE - 1),
720 rc = ptlrpc_start_bulk_transfer (desc);
722 lwi = LWI_TIMEOUT(obd_timeout * HZ / 4,
723 ost_bulk_timeout, desc);
724 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc),
726 LASSERT(rc == 0 || rc == -ETIMEDOUT);
727 if (rc == -ETIMEDOUT) {
728 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
729 ptlrpc_abort_bulk(desc);
730 } else if (!desc->bd_success ||
731 desc->bd_nob_transferred != desc->bd_nob) {
732 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
734 "truncated" : "network error on",
735 desc->bd_nob_transferred, desc->bd_nob);
736 /* XXX should this be a different errno? */
740 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d\n", rc);
742 comms_error = rc != 0;
744 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
745 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
748 if (rc == 0 && (body->oa.o_valid & OBD_MD_FLCKSUM) != 0) {
749 static int cksum_counter;
750 obd_count client_cksum = body->oa.o_cksum;
751 obd_count cksum = ost_checksum_bulk(desc);
753 if (client_cksum != cksum) {
754 CERROR("Bad checksum: client %x, server %x id %s\n",
758 repbody->oa.o_cksum = cksum;
761 if ((cksum_counter & (-cksum_counter)) == cksum_counter)
762 CWARN("Checksum %u from NID %s: %x OK\n",
763 cksum_counter, req->rq_peerstr, cksum);
767 ost_stime_record(req, &start, 1, 1);
768 /* Must commit after prep above in all cases */
769 rc = obd_commitrw(OBD_BRW_WRITE, req->rq_export, &repbody->oa,
770 objcount, ioo, npages, local_nb, oti, rc);
772 ost_stime_record(req, &start, 1, 2);
775 repbody->oa.o_cksum = ost_checksum_bulk(desc);
776 repbody->oa.o_valid |= OBD_MD_FLCKSUM;
778 /* set per-requested niobuf return codes */
779 for (i = j = 0; i < niocount; i++) {
780 int nob = remote_nb[i].len;
785 if (local_nb[j].rc < 0)
786 rcs[i] = local_nb[j].rc;
787 nob -= pp_rnb[j].len;
792 LASSERT(j == npages);
794 /*XXX This write extents only for write-back cache extents*/
795 rc = obd_write_extents(req->rq_export, ioo, objcount, niocount,
798 ptlrpc_free_bulk(desc);
800 OBD_FREE(local_nb, sizeof(*local_nb) * npages);
802 free_per_page_niobufs(npages, pp_rnb, remote_nb);
805 oti_to_request(oti, req);
806 rc = ptlrpc_reply(req);
807 } else if (!comms_error) {
808 /* Only reply if there was no comms problem with bulk */
812 if (req->rq_reply_state != NULL) {
813 /* reply out callback would free */
814 lustre_free_reply_state (req->rq_reply_state);
816 if (req->rq_reqmsg->conn_cnt == req->rq_export->exp_conn_cnt) {
817 CERROR("%s: bulk IO comm error evicting %s@%s id %s\n",
818 req->rq_export->exp_obd->obd_name,
819 req->rq_export->exp_client_uuid.uuid,
820 req->rq_export->exp_connection->c_remote_uuid.uuid,
822 ptlrpc_fail_export(req->rq_export);
824 CERROR("ignoring bulk IO comms error: "
825 "client reconnected %s@%s id %s\n",
826 req->rq_export->exp_client_uuid.uuid,
827 req->rq_export->exp_connection->c_remote_uuid.uuid,
833 EXPORT_SYMBOL(ost_brw_write);
835 static int ost_san_brw(struct ptlrpc_request *req, int cmd)
837 struct niobuf_remote *remote_nb, *res_nb, *pp_rnb;
838 struct obd_ioobj *ioo;
839 struct ost_body *body, *repbody;
840 int rc, i, objcount, niocount, size[2] = {sizeof(*body)}, npages;
844 /* XXX not set to use latest protocol */
846 swab = lustre_msg_swabbed(req->rq_reqmsg);
847 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
849 CERROR("Missing/short ost_body\n");
850 GOTO(out, rc = -EFAULT);
853 ioo = lustre_swab_reqbuf(req, 1, sizeof(*ioo), lustre_swab_obd_ioobj);
855 CERROR("Missing/short ioobj\n");
856 GOTO(out, rc = -EFAULT);
858 objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
859 niocount = ioo[0].ioo_bufcnt;
860 for (i = 1; i < objcount; i++) {
862 lustre_swab_obd_ioobj (&ioo[i]);
863 niocount += ioo[i].ioo_bufcnt;
866 remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb),
867 lustre_swab_niobuf_remote);
868 if (remote_nb == NULL) {
869 CERROR("Missing/short niobuf\n");
870 GOTO(out, rc = -EFAULT);
872 if (swab) { /* swab the remaining niobufs */
873 for (i = 1; i < niocount; i++)
874 lustre_swab_niobuf_remote (&remote_nb[i]);
877 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
878 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
880 GOTO (out, rc = npages);
882 size[1] = npages * sizeof(*pp_rnb);
883 rc = lustre_pack_reply(req, 2, size, NULL);
885 GOTO(out_pp_rnb, rc);
887 req->rq_status = obd_san_preprw(cmd, req->rq_export, &body->oa,
888 objcount, ioo, npages, pp_rnb);
891 GOTO(out_pp_rnb, rc = 0);
893 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
894 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
896 res_nb = lustre_msg_buf(req->rq_repmsg, 1, size[1]);
897 memcpy(res_nb, remote_nb, size[1]);
900 free_per_page_niobufs(npages, pp_rnb, remote_nb);
911 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
917 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
919 DEBUG_REQ(D_HA, req, "no set_info key");
922 keylen = req->rq_reqmsg->buflens[0];
924 rc = lustre_pack_reply(req, 0, NULL, NULL);
928 val = lustre_msg_buf(req->rq_reqmsg, 1, 0);
930 CERROR("val for setinfo can't be NULL\n");
934 if (keylen == 8 && memcmp(key, "auditlog", 8) == 0) {
935 lustre_swab_reqbuf(req, 1, sizeof(struct audit_msg),
936 lustre_swab_audit_msg);
937 } else if (keylen == 5 && strcmp(key, "audit") == 0) {
938 lustre_swab_reqbuf(req, 1, sizeof(struct audit_attr_msg),
939 lustre_swab_audit_attr);
940 } else if (keylen == 9 && strcmp(key, "audit_obj") == 0) {
941 lustre_swab_reqbuf(req, 1, sizeof(struct obdo),
943 } else if (keylen == 8 && memcmp(key, "capa_key", 8) == 0) {
944 lustre_swab_reqbuf(req, 1, sizeof(struct lustre_capa_key),
945 lustre_swab_lustre_capa_key);
948 rc = obd_set_info(exp, keylen, key, req->rq_reqmsg->buflens[1], val);
949 req->rq_repmsg->status = 0;
953 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
956 int keylen, rc = 0, size = sizeof(obd_id);
960 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
962 DEBUG_REQ(D_HA, req, "no get_info key");
965 keylen = req->rq_reqmsg->buflens[0];
967 if (keylen < strlen("last_id") || memcmp(key, "last_id", 7) != 0)
970 rc = lustre_pack_reply(req, 1, &size, NULL);
974 reply = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*reply));
975 rc = obd_get_info(exp, keylen, key, (__u32 *)&size, reply);
976 req->rq_repmsg->status = 0;
980 static int ost_llog_handle_connect(struct obd_export *exp,
981 struct ptlrpc_request *req)
983 struct llogd_conn_body *body;
987 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
988 rc = obd_llog_connect(exp, body);
992 static int ost_filter_recovery_request(struct ptlrpc_request *req,
993 struct obd_device *obd, int *process)
995 switch (req->rq_reqmsg->opc) {
996 case OST_CONNECT: /* This will never get here, but for completeness. */
1008 case OBD_LOG_CANCEL:
1010 *process = target_queue_recovery_request(req, obd);
1014 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1016 /* XXX what should we set rq_status to here? */
1017 req->rq_status = -EAGAIN;
1018 RETURN(ptlrpc_error(req));
1022 int ost_msg_check_version(struct lustre_msg *msg)
1028 case OST_DISCONNECT:
1043 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1045 CERROR("bad opc %u version %08x, expecting %08x\n",
1046 msg->opc, msg->version, LUSTRE_OBD_VERSION);
1051 case LDLM_BL_CALLBACK:
1052 case LDLM_CP_CALLBACK:
1053 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1055 CERROR("bad opc %u version %08x, expecting %08x\n",
1056 msg->opc, msg->version, LUSTRE_DLM_VERSION);
1058 case OBD_LOG_CANCEL:
1059 case LLOG_ORIGIN_CONNECT:
1060 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1062 CERROR("bad opc %u version %08x, expecting %08x\n",
1063 msg->opc, msg->version, LUSTRE_LOG_VERSION);
1066 case SEC_INIT_CONTINUE:
1071 CERROR("OST unexpected opcode %d\n", msg->opc);
1078 int ost_handle(struct ptlrpc_request *req)
1080 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1081 struct obd_trans_info *oti = NULL;
1082 struct obd_device *obd = NULL;
1085 LASSERT(current->journal_info == NULL);
1087 rc = ost_msg_check_version(req->rq_reqmsg);
1089 CERROR("OST drop mal-formed request\n");
1093 /* Security opc should NOT trigger any recovery events */
1094 if (req->rq_reqmsg->opc == SEC_INIT ||
1095 req->rq_reqmsg->opc == SEC_INIT_CONTINUE ||
1096 req->rq_reqmsg->opc == SEC_FINI) {
1097 GOTO(out_check_req, rc = 0);
1100 /* XXX identical to MDS */
1101 if (req->rq_reqmsg->opc != OST_CONNECT) {
1104 if (req->rq_export == NULL) {
1105 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1106 req->rq_reqmsg->opc,
1108 req->rq_status = -ENOTCONN;
1109 GOTO(out_check_req, rc = -ENOTCONN);
1112 obd = req->rq_export->exp_obd;
1114 /* Check for aborted recovery. */
1115 spin_lock_bh(&obd->obd_processing_task_lock);
1116 recovering = obd->obd_recovering;
1117 spin_unlock_bh(&obd->obd_processing_task_lock);
1119 rc = ost_filter_recovery_request(req, obd,
1121 if (rc || !should_process)
1123 if (should_process < 0) {
1124 req->rq_status = should_process;
1125 rc = ptlrpc_error(req);
1131 OBD_ALLOC(oti, sizeof(*oti));
1137 switch (req->rq_reqmsg->opc) {
1139 CDEBUG(D_INODE, "connect\n");
1140 OBD_FAIL_GOTO(OBD_FAIL_OST_CONNECT_NET, out_free_oti, rc = 0);
1141 rc = target_handle_connect(req);
1143 obd = req->rq_export->exp_obd;
1146 case OST_DISCONNECT:
1147 CDEBUG(D_INODE, "disconnect\n");
1148 OBD_FAIL_GOTO(OBD_FAIL_OST_DISCONNECT_NET, out_free_oti, rc = 0);
1149 rc = target_handle_disconnect(req);
1152 CDEBUG(D_INODE, "create\n");
1153 OBD_FAIL_GOTO(OBD_FAIL_OST_ENOSPC, out_check_req, rc = -ENOSPC);
1154 OBD_FAIL_GOTO(OBD_FAIL_OST_EROFS, out_check_req, rc = -EROFS);
1155 OBD_FAIL_GOTO(OBD_FAIL_OST_CREATE_NET, out_free_oti, rc = 0);
1156 rc = ost_create(req->rq_export, req, oti);
1159 CDEBUG(D_INODE, "destroy\n");
1160 OBD_FAIL_GOTO(OBD_FAIL_OST_DESTROY_NET, out_free_oti, rc = 0);
1161 OBD_FAIL_GOTO(OBD_FAIL_OST_EROFS, out_check_req, rc = -EROFS);
1162 rc = ost_destroy(req->rq_export, req, oti);
1165 CDEBUG(D_INODE, "getattr\n");
1166 OBD_FAIL_GOTO(OBD_FAIL_OST_GETATTR_NET, out_free_oti, rc = 0);
1167 rc = ost_getattr(req->rq_export, req);
1170 CDEBUG(D_INODE, "setattr\n");
1171 OBD_FAIL_GOTO(OBD_FAIL_OST_SETATTR_NET, out_free_oti, rc = 0);
1172 rc = ost_setattr(req->rq_export, req, oti);
1175 CDEBUG(D_INODE, "write\n");
1176 OBD_FAIL_GOTO(OBD_FAIL_OST_BRW_NET, out_free_oti, rc = 0);
1177 OBD_FAIL_GOTO(OBD_FAIL_OST_ENOSPC, out_check_req, rc = -ENOSPC);
1178 OBD_FAIL_GOTO(OBD_FAIL_OST_EROFS, out_check_req, rc = -EROFS);
1179 rc = ost_brw_write(req, oti);
1180 LASSERT(current->journal_info == NULL);
1181 /* ost_brw sends its own replies */
1182 GOTO(out_free_oti, rc);
1184 CDEBUG(D_INODE, "read\n");
1185 OBD_FAIL_GOTO(OBD_FAIL_OST_BRW_NET, out_free_oti, rc = 0);
1186 rc = ost_brw_read(req);
1187 LASSERT(current->journal_info == NULL);
1188 /* ost_brw sends its own replies */
1189 GOTO(out_free_oti, rc);
1191 CDEBUG(D_INODE, "san read\n");
1192 OBD_FAIL_GOTO(OBD_FAIL_OST_BRW_NET, out_free_oti, rc = 0);
1193 rc = ost_san_brw(req, OBD_BRW_READ);
1194 /* ost_san_brw sends its own replies */
1195 GOTO(out_free_oti, rc);
1197 CDEBUG(D_INODE, "san write\n");
1198 OBD_FAIL_GOTO(OBD_FAIL_OST_BRW_NET, out_free_oti, rc = 0);
1199 rc = ost_san_brw(req, OBD_BRW_WRITE);
1200 /* ost_san_brw sends its own replies */
1201 GOTO(out_free_oti, rc);
1203 CDEBUG(D_INODE, "punch\n");
1204 OBD_FAIL_GOTO(OBD_FAIL_OST_PUNCH_NET, out_free_oti, rc = 0);
1205 OBD_FAIL_GOTO(OBD_FAIL_OST_EROFS, out_check_req, rc = -EROFS);
1206 rc = ost_punch(req->rq_export, req, oti);
1209 CDEBUG(D_INODE, "statfs\n");
1210 OBD_FAIL_GOTO(OBD_FAIL_OST_STATFS_NET, out_free_oti, rc = 0);
1211 rc = ost_statfs(req);
1214 CDEBUG(D_INODE, "sync\n");
1215 OBD_FAIL_GOTO(OBD_FAIL_OST_SYNC_NET, out_free_oti, rc = 0);
1216 rc = ost_sync(req->rq_export, req);
1219 DEBUG_REQ(D_INODE, req, "set_info");
1220 rc = ost_set_info(req->rq_export, req);
1223 DEBUG_REQ(D_INODE, req, "get_info");
1224 rc = ost_get_info(req->rq_export, req);
1227 DEBUG_REQ(D_INODE, req, "ping");
1228 rc = target_handle_ping(req);
1230 /* FIXME - just reply status */
1231 case LLOG_ORIGIN_CONNECT:
1232 DEBUG_REQ(D_INODE, req, "log connect\n");
1233 rc = ost_llog_handle_connect(req->rq_export, req);
1234 req->rq_status = rc;
1235 rc = lustre_pack_reply(req, 0, NULL, NULL);
1237 GOTO(out_free_oti, rc);
1238 GOTO(out_free_oti, rc = ptlrpc_reply(req));
1239 case OBD_LOG_CANCEL:
1240 CDEBUG(D_INODE, "log cancel\n");
1241 OBD_FAIL_GOTO(OBD_FAIL_OBD_LOG_CANCEL_NET, out_free_oti, rc = 0);
1242 rc = llog_origin_handle_cancel(req);
1243 req->rq_status = rc;
1244 rc = lustre_pack_reply(req, 0, NULL, NULL);
1246 GOTO(out_free_oti, rc);
1247 GOTO(out_free_oti, rc = ptlrpc_reply(req));
1249 CDEBUG(D_INODE, "enqueue\n");
1250 OBD_FAIL_GOTO(OBD_FAIL_LDLM_ENQUEUE, out_free_oti, rc = 0);
1251 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1252 ldlm_server_blocking_ast,
1253 ldlm_server_glimpse_ast);
1254 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1257 CDEBUG(D_INODE, "convert\n");
1258 OBD_FAIL_GOTO(OBD_FAIL_LDLM_CONVERT, out_free_oti, rc = 0);
1259 rc = ldlm_handle_convert(req);
1262 CDEBUG(D_INODE, "cancel\n");
1263 OBD_FAIL_GOTO(OBD_FAIL_LDLM_CANCEL, out_free_oti, rc = 0);
1264 rc = ldlm_handle_cancel(req);
1266 case LDLM_BL_CALLBACK:
1267 case LDLM_CP_CALLBACK:
1268 CDEBUG(D_INODE, "callback\n");
1269 CERROR("callbacks should not happen on OST\n");
1272 CERROR("Unexpected opcode %d\n", req->rq_reqmsg->opc);
1273 req->rq_status = -ENOTSUPP;
1274 rc = ptlrpc_error(req);
1275 GOTO(out_free_oti, rc);
1278 LASSERT(current->journal_info == NULL);
1281 /* If we're DISCONNECTing, the export_data is already freed */
1282 if (!rc && req->rq_reqmsg->opc != OST_DISCONNECT) {
1283 if (!obd->obd_no_transno) {
1284 req->rq_repmsg->last_committed =
1285 obd->obd_last_committed;
1287 DEBUG_REQ(D_IOCTL, req,
1288 "not sending last_committed update");
1290 CDEBUG(D_INFO, "last_committed "LPU64", xid "LPX64"\n",
1291 obd->obd_last_committed, req->rq_xid);
1297 oti_to_request(oti, req);
1298 target_send_reply(req, rc, fail);
1303 OBD_FREE(oti, sizeof(*oti));
1306 EXPORT_SYMBOL(ost_handle);
1308 int ost_attach(struct obd_device *dev, obd_count len, void *data)
1310 struct lprocfs_static_vars lvars;
1312 lprocfs_init_vars(ost,&lvars);
1313 return lprocfs_obd_attach(dev, lvars.obd_vars);
1316 int ost_detach(struct obd_device *dev)
1318 return lprocfs_obd_detach(dev);
1321 extern struct file_operations ost_stimes_fops;
1323 static int ost_setup(struct obd_device *obd, obd_count len, void *buf)
1325 struct ost_obd *ost = &obd->u.ost;
1329 rc = cleanup_group_info();
1333 rc = llog_start_commit_thread();
1337 lprocfs_obd_seq_create(obd, "service_times", 0444, &ost_stimes_fops,
1341 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1342 OST_REQUEST_PORTAL, OSC_REPLY_PORTAL, 30000,
1344 obd->obd_proc_entry);
1345 if (ost->ost_service == NULL) {
1346 CERROR("failed to start service\n");
1350 rc = ptlrpc_start_n_threads(obd, ost->ost_service, OST_NUM_THREADS,
1353 GOTO(out_service, rc = -EINVAL);
1355 ost->ost_create_service =
1356 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1357 OST_CREATE_PORTAL, OSC_REPLY_PORTAL, 30000,
1358 ost_handle, "ost_create",
1359 obd->obd_proc_entry);
1360 if (ost->ost_create_service == NULL) {
1361 CERROR("failed to start OST create service\n");
1362 GOTO(out_service, rc = -ENOMEM);
1366 spin_lock_init(&ost->ost_lock);
1367 ost->ost_service->srv_obddev = obd;
1369 rc = ptlrpc_start_n_threads(obd, ost->ost_create_service, 1,
1372 GOTO(out_create, rc = -EINVAL);
1374 ost->ost_destroy_service =
1375 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1376 OST_DESTROY_PORTAL, OSC_REPLY_PORTAL, 30000,
1377 ost_handle, "ost_destroy",
1378 obd->obd_proc_entry);
1379 if (ost->ost_destroy_service == NULL) {
1380 CERROR("failed to start service\n");
1381 GOTO(out_create, rc = -ENOMEM);
1384 rc = ptlrpc_start_n_threads(obd, ost->ost_destroy_service,
1385 OST_NUM_THREADS, "ll_dstr_ost");
1387 GOTO(out_destroy, rc = -EINVAL);
1392 ptlrpc_unregister_service(ost->ost_destroy_service);
1394 ptlrpc_unregister_service(ost->ost_create_service);
1396 ptlrpc_unregister_service(ost->ost_service);
1400 extern void lgss_svc_cache_purge_all(void);
1401 static int ost_cleanup(struct obd_device *obd, int flags)
1403 struct ost_obd *ost = &obd->u.ost;
1407 spin_lock_bh(&obd->obd_processing_task_lock);
1408 if (obd->obd_recovering) {
1409 target_cancel_recovery_timer(obd);
1410 obd->obd_recovering = 0;
1412 spin_unlock_bh(&obd->obd_processing_task_lock);
1414 ptlrpc_stop_all_threads(ost->ost_service);
1415 ptlrpc_unregister_service(ost->ost_service);
1417 ptlrpc_stop_all_threads(ost->ost_create_service);
1418 ptlrpc_unregister_service(ost->ost_create_service);
1420 ptlrpc_stop_all_threads(ost->ost_destroy_service);
1421 ptlrpc_unregister_service(ost->ost_destroy_service);
1425 lgss_svc_cache_purge_all();
1430 /* use obd ops to offer management infrastructure */
1431 static struct obd_ops ost_obd_ops = {
1432 .o_owner = THIS_MODULE,
1433 .o_attach = ost_attach,
1434 .o_detach = ost_detach,
1435 .o_setup = ost_setup,
1436 .o_cleanup = ost_cleanup,
1439 static int __init ost_init(void)
1441 struct lprocfs_static_vars lvars;
1444 lprocfs_init_vars(ost,&lvars);
1445 RETURN(class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
1446 OBD_OST_DEVICENAME));
1449 static void /*__exit*/ ost_exit(void)
1451 class_unregister_type(OBD_OST_DEVICENAME);
1454 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1455 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
1456 MODULE_LICENSE("GPL");
1458 module_init(ost_init);
1459 module_exit(ost_exit);