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);
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 int rc, size = sizeof(*repbody);
172 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
176 if ((body->oa.o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
177 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
180 rc = lustre_pack_reply(req, 1, &size, NULL);
184 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
185 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
186 req->rq_status = obd_punch(exp, &repbody->oa, NULL, repbody->oa.o_size,
187 repbody->oa.o_blocks, oti);
191 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
193 struct ost_body *body, *repbody;
194 int rc, size = sizeof(*repbody);
197 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
201 rc = lustre_pack_reply(req, 1, &size, NULL);
205 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
206 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
207 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
208 repbody->oa.o_blocks);
212 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
213 struct obd_trans_info *oti)
215 struct ost_body *body, *repbody;
216 int rc, size = sizeof(*repbody);
219 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
223 rc = lustre_pack_reply(req, 1, &size, NULL);
227 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
228 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
230 req->rq_status = obd_setattr(exp, &repbody->oa, NULL, oti);
234 static int ost_bulk_timeout(void *data)
237 /* We don't fail the connection here, because having the export
238 * killed makes the (vital) call to commitrw very sad.
243 static int get_per_page_niobufs(struct obd_ioobj *ioo, int nioo,
244 struct niobuf_remote *rnb, int nrnb,
245 struct niobuf_remote **pp_rnbp)
247 /* Copy a remote niobuf, splitting it into page-sized chunks
248 * and setting ioo[i].ioo_bufcnt accordingly */
249 struct niobuf_remote *pp_rnb;
256 /* first count and check the number of pages required */
257 for (i = 0; i < nioo; i++)
258 for (j = 0; j < ioo->ioo_bufcnt; j++, rnbidx++) {
259 obd_off offset = rnb[rnbidx].offset;
260 obd_off p0 = offset >> PAGE_SHIFT;
261 obd_off pn = (offset + rnb[rnbidx].len - 1)>>PAGE_SHIFT;
263 LASSERT(rnbidx < nrnb);
265 npages += (pn + 1 - p0);
267 if (rnb[rnbidx].len == 0) {
268 CERROR("zero len BRW: obj %d objid "LPX64
269 " buf %u\n", i, ioo[i].ioo_id, j);
273 rnb[rnbidx].offset <= rnb[rnbidx-1].offset) {
274 CERROR("unordered BRW: obj %d objid "LPX64
275 " buf %u offset "LPX64" <= "LPX64"\n",
276 i, ioo[i].ioo_id, j, rnb[rnbidx].offset,
282 LASSERT(rnbidx == nrnb);
284 if (npages == nrnb) { /* all niobufs are for single pages */
289 OBD_ALLOC(pp_rnb, sizeof(*pp_rnb) * npages);
293 /* now do the actual split */
295 for (i = 0; i < nioo; i++) {
298 for (j = 0; j < ioo[i].ioo_bufcnt; j++, rnbidx++) {
299 obd_off off = rnb[rnbidx].offset;
300 int nob = rnb[rnbidx].len;
302 LASSERT(rnbidx < nrnb);
304 obd_off poff = off & (PAGE_SIZE - 1);
305 int pnob = (poff + nob > PAGE_SIZE) ?
306 PAGE_SIZE - poff : nob;
308 LASSERT(page < npages);
309 pp_rnb[page].len = pnob;
310 pp_rnb[page].offset = off;
311 pp_rnb[page].flags = rnb[rnbidx].flags;
313 CDEBUG(0, " obj %d id "LPX64
314 "page %d(%d) "LPX64" for %d, flg %x\n",
315 i, ioo[i].ioo_id, obj_pages, page,
316 pp_rnb[page].offset, pp_rnb[page].len,
326 ioo[i].ioo_bufcnt = obj_pages;
328 LASSERT(page == npages);
334 static void free_per_page_niobufs (int npages, struct niobuf_remote *pp_rnb,
335 struct niobuf_remote *rnb)
337 if (pp_rnb == rnb) /* didn't allocate above */
340 OBD_FREE(pp_rnb, sizeof(*pp_rnb) * npages);
344 obd_count ost_checksum_bulk(struct ptlrpc_bulk_desc *desc)
347 struct ptlrpc_bulk_page *bp;
349 list_for_each_entry(bp, &desc->bd_page_list, bp_link) {
350 ost_checksum(&cksum, kmap(bp->bp_page) + bp->bp_pageoffset,
359 static void ost_stime_record(struct ptlrpc_request *req, struct timeval *start,
360 unsigned rw, unsigned phase)
362 struct obd_device *obd = req->rq_svc->srv_obddev;
364 int ind = rw *3 + phase;
366 if (obd && obd->obd_type && obd->obd_type->typ_name) {
367 if (!strcmp(obd->obd_type->typ_name, OBD_OST_DEVICENAME)) {
368 struct ost_obd *ost = NULL;
371 if (ind >= (sizeof(ost->ost_stimes) /
372 sizeof(ost->ost_stimes[0])))
374 do_gettimeofday(&stop);
376 spin_lock(&ost->ost_lock);
377 lprocfs_stime_record(&ost->ost_stimes[ind],&stop,start);
378 spin_unlock(&ost->ost_lock);
379 memcpy(start, &stop, sizeof(*start));
384 static int ost_brw_read(struct ptlrpc_request *req)
386 struct ptlrpc_bulk_desc *desc;
387 struct niobuf_remote *remote_nb;
388 struct niobuf_remote *pp_rnb;
389 struct niobuf_local *local_nb;
390 struct obd_ioobj *ioo;
391 struct ost_body *body, *repbody;
392 struct l_wait_info lwi;
393 struct obd_trans_info oti = { 0 };
394 int size[1] = { sizeof(*body) };
401 struct timeval start;
404 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
405 GOTO(out, rc = -EIO);
407 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
408 (obd_timeout + 1) / 4);
410 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
412 CERROR("Missing/short ost_body\n");
413 GOTO(out, rc = -EFAULT);
416 ioo = lustre_swab_reqbuf(req, 1, sizeof(*ioo), lustre_swab_obd_ioobj);
418 CERROR("Missing/short ioobj\n");
419 GOTO(out, rc = -EFAULT);
422 niocount = ioo->ioo_bufcnt;
423 remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb),
424 lustre_swab_niobuf_remote);
425 if (remote_nb == NULL) {
426 CERROR("Missing/short niobuf\n");
427 GOTO(out, rc = -EFAULT);
429 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
430 for (i = 1; i < niocount; i++)
431 lustre_swab_niobuf_remote (&remote_nb[i]);
434 rc = lustre_pack_reply(req, 1, size, NULL);
438 /* FIXME all niobuf splitting should be done in obdfilter if needed */
439 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
440 npages = get_per_page_niobufs(ioo, 1, remote_nb, niocount, &pp_rnb);
442 GOTO(out, rc = npages);
444 OBD_ALLOC(local_nb, sizeof(*local_nb) * npages);
445 if (local_nb == NULL)
446 GOTO(out_pp_rnb, rc = -ENOMEM);
448 desc = ptlrpc_prep_bulk_exp (req, npages,
449 BULK_PUT_SOURCE, OST_BULK_PORTAL);
451 GOTO(out_local, rc = -ENOMEM);
453 do_gettimeofday(&start);
454 rc = obd_preprw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
455 ioo, npages, pp_rnb, local_nb, &oti);
456 ost_stime_record(req, &start, 0, 0);
460 /* We're finishing using body->oa as an input variable */
461 body->oa.o_valid = 0;
464 for (i = 0; i < npages; i++) {
465 int page_rc = local_nb[i].rc;
467 if (page_rc < 0) { /* error */
472 LASSERT(page_rc <= pp_rnb[i].len);
474 if (page_rc != 0) { /* some data! */
475 LASSERT (local_nb[i].page != NULL);
476 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
477 pp_rnb[i].offset & (PAGE_SIZE-1),
481 if (page_rc != pp_rnb[i].len) { /* short read */
482 /* All subsequent pages should be 0 */
484 LASSERT(local_nb[i].rc == 0);
490 rc = ptlrpc_start_bulk_transfer(desc);
492 lwi = LWI_TIMEOUT(obd_timeout * HZ / 4,
493 ost_bulk_timeout, desc);
494 rc = l_wait_event(desc->bd_waitq,
495 !ptlrpc_bulk_active(desc), &lwi);
496 LASSERT(rc == 0 || rc == -ETIMEDOUT);
497 if (rc == -ETIMEDOUT) {
498 DEBUG_REQ(D_ERROR, req, "timeout on bulk PUT");
499 ptlrpc_abort_bulk(desc);
500 } else if (!desc->bd_success ||
501 desc->bd_nob_transferred != desc->bd_nob) {
502 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
504 "truncated" : "network error on",
505 desc->bd_nob_transferred,
507 /* XXX should this be a different errno? */
511 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d\n", rc);
513 comms_error = rc != 0;
516 ost_stime_record(req, &start, 0, 1);
517 /* Must commit after prep above in all cases */
518 rc = obd_commitrw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
519 ioo, npages, local_nb, &oti, rc);
520 ost_stime_record(req, &start, 0, 2);
523 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
524 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
527 repbody->oa.o_cksum = ost_checksum_bulk(desc);
528 repbody->oa.o_valid |= OBD_MD_FLCKSUM;
533 ptlrpc_free_bulk(desc);
535 OBD_FREE(local_nb, sizeof(*local_nb) * npages);
537 free_per_page_niobufs(npages, pp_rnb, remote_nb);
541 req->rq_status = nob;
543 } else if (!comms_error) {
544 /* only reply if comms OK */
548 if (req->rq_reply_state != NULL) {
549 /* reply out callback would free */
550 lustre_free_reply_state (req->rq_reply_state);
552 if (req->rq_reqmsg->conn_cnt == req->rq_export->exp_conn_cnt) {
553 CERROR("bulk IO comms error: "
554 "evicting %s@%s id %s\n",
555 req->rq_export->exp_client_uuid.uuid,
556 req->rq_export->exp_connection->c_remote_uuid.uuid,
558 ptlrpc_fail_export(req->rq_export);
560 CERROR("ignoring bulk IO comms error: "
561 "client reconnected %s@%s id %s\n",
562 req->rq_export->exp_client_uuid.uuid,
563 req->rq_export->exp_connection->c_remote_uuid.uuid,
571 int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
573 struct ptlrpc_bulk_desc *desc;
574 struct niobuf_remote *remote_nb;
575 struct niobuf_remote *pp_rnb;
576 struct niobuf_local *local_nb;
577 struct obd_ioobj *ioo;
578 struct ost_body *body, *repbody;
579 struct l_wait_info lwi;
581 int size[2] = { sizeof(*body) };
582 int objcount, niocount, npages;
585 struct timeval start;
588 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
589 GOTO(out, rc = -EIO);
591 /* pause before transaction has been started */
592 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
593 (obd_timeout + 1) / 4);
595 swab = lustre_msg_swabbed(req->rq_reqmsg);
596 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
598 CERROR("Missing/short ost_body\n");
599 GOTO(out, rc = -EFAULT);
602 LASSERT_REQSWAB(req, 1);
603 objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
605 CERROR("Missing/short ioobj\n");
606 GOTO(out, rc = -EFAULT);
608 ioo = lustre_msg_buf (req->rq_reqmsg, 1, objcount * sizeof(*ioo));
609 LASSERT (ioo != NULL);
610 for (niocount = i = 0; i < objcount; i++) {
612 lustre_swab_obd_ioobj (&ioo[i]);
613 if (ioo[i].ioo_bufcnt == 0) {
614 CERROR("ioo[%d] has zero bufcnt\n", i);
615 GOTO(out, rc = -EFAULT);
617 niocount += ioo[i].ioo_bufcnt;
620 remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb),
621 lustre_swab_niobuf_remote);
622 if (remote_nb == NULL) {
623 CERROR("Missing/short niobuf\n");
624 GOTO(out, rc = -EFAULT);
626 if (swab) { /* swab the remaining niobufs */
627 for (i = 1; i < niocount; i++)
628 lustre_swab_niobuf_remote (&remote_nb[i]);
631 size[1] = niocount * sizeof(*rcs);
632 rc = lustre_pack_reply(req, 2, size, NULL);
635 rcs = lustre_msg_buf(req->rq_repmsg, 1, niocount * sizeof(*rcs));
638 /* Do snap options here*/
639 rc = obd_do_cow(req->rq_export, ioo, objcount, remote_nb);
644 /* FIXME all niobuf splitting should be done in obdfilter if needed */
645 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
646 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
648 GOTO(out, rc = npages);
650 OBD_ALLOC(local_nb, sizeof(*local_nb) * npages);
651 if (local_nb == NULL)
652 GOTO(out_pp_rnb, rc = -ENOMEM);
654 desc = ptlrpc_prep_bulk_exp (req, npages,
655 BULK_GET_SINK, OST_BULK_PORTAL);
657 GOTO(out_local, rc = -ENOMEM);
659 do_gettimeofday(&start);
660 rc = obd_preprw(OBD_BRW_WRITE, req->rq_export, &body->oa, objcount,
661 ioo, npages, pp_rnb, local_nb, oti);
662 ost_stime_record(req, &start, 1, 0);
666 /* NB Having prepped, we must commit... */
668 for (i = 0; i < npages; i++)
669 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
670 pp_rnb[i].offset & (PAGE_SIZE - 1),
673 rc = ptlrpc_start_bulk_transfer (desc);
675 lwi = LWI_TIMEOUT(obd_timeout * HZ / 4,
676 ost_bulk_timeout, desc);
677 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc),
679 LASSERT(rc == 0 || rc == -ETIMEDOUT);
680 if (rc == -ETIMEDOUT) {
681 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
682 ptlrpc_abort_bulk(desc);
683 } else if (!desc->bd_success ||
684 desc->bd_nob_transferred != desc->bd_nob) {
685 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
687 "truncated" : "network error on",
688 desc->bd_nob_transferred, desc->bd_nob);
689 /* XXX should this be a different errno? */
693 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d\n", rc);
695 comms_error = rc != 0;
697 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
698 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
701 if (rc == 0 && (body->oa.o_valid & OBD_MD_FLCKSUM) != 0) {
702 static int cksum_counter;
703 obd_count client_cksum = body->oa.o_cksum;
704 obd_count cksum = ost_checksum_bulk(desc);
706 if (client_cksum != cksum) {
707 CERROR("Bad checksum: client %x, server %x id %s\n",
711 repbody->oa.o_cksum = cksum;
714 if ((cksum_counter & (-cksum_counter)) == cksum_counter)
715 CWARN("Checksum %u from NID %s: %x OK\n",
716 cksum_counter, req->rq_peerstr, cksum);
720 ost_stime_record(req, &start, 1, 1);
721 /* Must commit after prep above in all cases */
722 rc = obd_commitrw(OBD_BRW_WRITE, req->rq_export, &repbody->oa,
723 objcount, ioo, npages, local_nb, oti, rc);
725 ost_stime_record(req, &start, 1, 2);
728 repbody->oa.o_cksum = ost_checksum_bulk(desc);
729 repbody->oa.o_valid |= OBD_MD_FLCKSUM;
731 /* set per-requested niobuf return codes */
732 for (i = j = 0; i < niocount; i++) {
733 int nob = remote_nb[i].len;
738 if (local_nb[j].rc < 0)
739 rcs[i] = local_nb[j].rc;
740 nob -= pp_rnb[j].len;
745 LASSERT(j == npages);
747 /*XXX This write extents only for write-back cache extents*/
748 rc = obd_write_extents(req->rq_export, ioo, objcount, niocount,
751 ptlrpc_free_bulk(desc);
753 OBD_FREE(local_nb, sizeof(*local_nb) * npages);
755 free_per_page_niobufs(npages, pp_rnb, remote_nb);
758 oti_to_request(oti, req);
759 rc = ptlrpc_reply(req);
760 } else if (!comms_error) {
761 /* Only reply if there was no comms problem with bulk */
765 if (req->rq_reply_state != NULL) {
766 /* reply out callback would free */
767 lustre_free_reply_state (req->rq_reply_state);
769 if (req->rq_reqmsg->conn_cnt == req->rq_export->exp_conn_cnt) {
770 CERROR("%s: bulk IO comm error evicting %s@%s id %s\n",
771 req->rq_export->exp_obd->obd_name,
772 req->rq_export->exp_client_uuid.uuid,
773 req->rq_export->exp_connection->c_remote_uuid.uuid,
775 ptlrpc_fail_export(req->rq_export);
777 CERROR("ignoring bulk IO comms error: "
778 "client reconnected %s@%s id %s\n",
779 req->rq_export->exp_client_uuid.uuid,
780 req->rq_export->exp_connection->c_remote_uuid.uuid,
786 EXPORT_SYMBOL(ost_brw_write);
788 static int ost_san_brw(struct ptlrpc_request *req, int cmd)
790 struct niobuf_remote *remote_nb, *res_nb, *pp_rnb;
791 struct obd_ioobj *ioo;
792 struct ost_body *body, *repbody;
793 int rc, i, objcount, niocount, size[2] = {sizeof(*body)}, npages;
797 /* XXX not set to use latest protocol */
799 swab = lustre_msg_swabbed(req->rq_reqmsg);
800 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
802 CERROR("Missing/short ost_body\n");
803 GOTO(out, rc = -EFAULT);
806 ioo = lustre_swab_reqbuf(req, 1, sizeof(*ioo), lustre_swab_obd_ioobj);
808 CERROR("Missing/short ioobj\n");
809 GOTO(out, rc = -EFAULT);
811 objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
812 niocount = ioo[0].ioo_bufcnt;
813 for (i = 1; i < objcount; i++) {
815 lustre_swab_obd_ioobj (&ioo[i]);
816 niocount += ioo[i].ioo_bufcnt;
819 remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb),
820 lustre_swab_niobuf_remote);
821 if (remote_nb == NULL) {
822 CERROR("Missing/short niobuf\n");
823 GOTO(out, rc = -EFAULT);
825 if (swab) { /* swab the remaining niobufs */
826 for (i = 1; i < niocount; i++)
827 lustre_swab_niobuf_remote (&remote_nb[i]);
830 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
831 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
833 GOTO (out, rc = npages);
835 size[1] = npages * sizeof(*pp_rnb);
836 rc = lustre_pack_reply(req, 2, size, NULL);
838 GOTO(out_pp_rnb, rc);
840 req->rq_status = obd_san_preprw(cmd, req->rq_export, &body->oa,
841 objcount, ioo, npages, pp_rnb);
844 GOTO(out_pp_rnb, rc = 0);
846 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
847 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
849 res_nb = lustre_msg_buf(req->rq_repmsg, 1, size[1]);
850 memcpy(res_nb, remote_nb, size[1]);
853 free_per_page_niobufs(npages, pp_rnb, remote_nb);
864 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
870 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
872 DEBUG_REQ(D_HA, req, "no set_info key");
875 keylen = req->rq_reqmsg->buflens[0];
877 rc = lustre_pack_reply(req, 0, NULL, NULL);
881 val = lustre_msg_buf(req->rq_reqmsg, 1, 0);
883 if (keylen == 8 && memcmp(key, "auditlog", 8) == 0) {
884 lustre_swab_reqbuf(req, 1, sizeof(struct audit_msg),
885 lustre_swab_audit_msg);
887 else if (keylen == 5 && strcmp(key, "audit") == 0) {
888 lustre_swab_reqbuf(req, 1, sizeof(struct audit_attr_msg),
889 lustre_swab_audit_attr);
891 else if (keylen == 9 && strcmp(key, "audit_obj") == 0) {
892 lustre_swab_reqbuf(req, 1, sizeof(struct obdo),
896 rc = obd_set_info(exp, keylen, key, req->rq_reqmsg->buflens[1], val);
897 req->rq_repmsg->status = 0;
901 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
904 int keylen, rc = 0, size = sizeof(obd_id);
908 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
910 DEBUG_REQ(D_HA, req, "no get_info key");
913 keylen = req->rq_reqmsg->buflens[0];
915 if (keylen < strlen("last_id") || memcmp(key, "last_id", 7) != 0)
918 rc = lustre_pack_reply(req, 1, &size, NULL);
922 reply = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*reply));
923 rc = obd_get_info(exp, keylen, key, (__u32 *)&size, reply);
924 req->rq_repmsg->status = 0;
928 static int ost_llog_handle_connect(struct obd_export *exp,
929 struct ptlrpc_request *req)
931 struct llogd_conn_body *body;
935 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
936 rc = obd_llog_connect(exp, body);
940 static int ost_filter_recovery_request(struct ptlrpc_request *req,
941 struct obd_device *obd, int *process)
943 switch (req->rq_reqmsg->opc) {
944 case OST_CONNECT: /* This will never get here, but for completeness. */
958 *process = target_queue_recovery_request(req, obd);
962 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
964 /* XXX what should we set rq_status to here? */
965 req->rq_status = -EAGAIN;
966 RETURN(ptlrpc_error(req));
970 int ost_msg_check_version(struct lustre_msg *msg)
991 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
993 CERROR("bad opc %u version %08x, expecting %08x\n",
994 msg->opc, msg->version, LUSTRE_OBD_VERSION);
999 case LDLM_BL_CALLBACK:
1000 case LDLM_CP_CALLBACK:
1001 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1003 CERROR("bad opc %u version %08x, expecting %08x\n",
1004 msg->opc, msg->version, LUSTRE_DLM_VERSION);
1006 case OBD_LOG_CANCEL:
1007 case LLOG_ORIGIN_CONNECT:
1008 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1010 CERROR("bad opc %u version %08x, expecting %08x\n",
1011 msg->opc, msg->version, LUSTRE_LOG_VERSION);
1014 case SEC_INIT_CONTINUE:
1019 CERROR("OST unexpected opcode %d\n", msg->opc);
1026 int ost_handle(struct ptlrpc_request *req)
1028 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1029 struct obd_trans_info *oti = NULL;
1030 struct obd_device *obd = NULL;
1033 LASSERT(current->journal_info == NULL);
1035 rc = ost_msg_check_version(req->rq_reqmsg);
1037 CERROR("OST drop mal-formed request\n");
1041 /* Security opc should NOT trigger any recovery events */
1042 if (req->rq_reqmsg->opc == SEC_INIT ||
1043 req->rq_reqmsg->opc == SEC_INIT_CONTINUE ||
1044 req->rq_reqmsg->opc == SEC_FINI) {
1045 GOTO(out_check_req, rc = 0);
1048 /* XXX identical to MDS */
1049 if (req->rq_reqmsg->opc != OST_CONNECT) {
1052 if (req->rq_export == NULL) {
1053 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1054 req->rq_reqmsg->opc,
1056 req->rq_status = -ENOTCONN;
1057 GOTO(out_check_req, rc = -ENOTCONN);
1060 obd = req->rq_export->exp_obd;
1062 /* Check for aborted recovery. */
1063 spin_lock_bh(&obd->obd_processing_task_lock);
1064 recovering = obd->obd_recovering;
1065 spin_unlock_bh(&obd->obd_processing_task_lock);
1067 rc = ost_filter_recovery_request(req, obd,
1069 if (rc || !should_process)
1071 if (should_process < 0) {
1072 req->rq_status = should_process;
1073 rc = ptlrpc_error(req);
1079 OBD_ALLOC(oti, sizeof(*oti));
1085 switch (req->rq_reqmsg->opc) {
1087 CDEBUG(D_INODE, "connect\n");
1088 OBD_FAIL_GOTO(OBD_FAIL_OST_CONNECT_NET, out_free_oti, rc = 0);
1089 rc = target_handle_connect(req);
1091 obd = req->rq_export->exp_obd;
1094 case OST_DISCONNECT:
1095 CDEBUG(D_INODE, "disconnect\n");
1096 OBD_FAIL_GOTO(OBD_FAIL_OST_DISCONNECT_NET, out_free_oti, rc = 0);
1097 rc = target_handle_disconnect(req);
1100 CDEBUG(D_INODE, "create\n");
1101 OBD_FAIL_GOTO(OBD_FAIL_OST_ENOSPC, out_check_req, rc = -ENOSPC);
1102 OBD_FAIL_GOTO(OBD_FAIL_OST_EROFS, out_check_req, rc = -EROFS);
1103 OBD_FAIL_GOTO(OBD_FAIL_OST_CREATE_NET, out_free_oti, rc = 0);
1104 rc = ost_create(req->rq_export, req, oti);
1107 CDEBUG(D_INODE, "destroy\n");
1108 OBD_FAIL_GOTO(OBD_FAIL_OST_DESTROY_NET, out_free_oti, rc = 0);
1109 OBD_FAIL_GOTO(OBD_FAIL_OST_EROFS, out_check_req, rc = -EROFS);
1110 rc = ost_destroy(req->rq_export, req, oti);
1113 CDEBUG(D_INODE, "getattr\n");
1114 OBD_FAIL_GOTO(OBD_FAIL_OST_GETATTR_NET, out_free_oti, rc = 0);
1115 rc = ost_getattr(req->rq_export, req);
1118 CDEBUG(D_INODE, "setattr\n");
1119 OBD_FAIL_GOTO(OBD_FAIL_OST_SETATTR_NET, out_free_oti, rc = 0);
1120 rc = ost_setattr(req->rq_export, req, oti);
1123 CDEBUG(D_INODE, "write\n");
1124 OBD_FAIL_GOTO(OBD_FAIL_OST_BRW_NET, out_free_oti, rc = 0);
1125 OBD_FAIL_GOTO(OBD_FAIL_OST_ENOSPC, out_check_req, rc = -ENOSPC);
1126 OBD_FAIL_GOTO(OBD_FAIL_OST_EROFS, out_check_req, rc = -EROFS);
1127 rc = ost_brw_write(req, oti);
1128 LASSERT(current->journal_info == NULL);
1129 /* ost_brw sends its own replies */
1130 GOTO(out_free_oti, rc);
1132 CDEBUG(D_INODE, "read\n");
1133 OBD_FAIL_GOTO(OBD_FAIL_OST_BRW_NET, out_free_oti, rc = 0);
1134 rc = ost_brw_read(req);
1135 LASSERT(current->journal_info == NULL);
1136 /* ost_brw sends its own replies */
1137 GOTO(out_free_oti, rc);
1139 CDEBUG(D_INODE, "san read\n");
1140 OBD_FAIL_GOTO(OBD_FAIL_OST_BRW_NET, out_free_oti, rc = 0);
1141 rc = ost_san_brw(req, OBD_BRW_READ);
1142 /* ost_san_brw sends its own replies */
1143 GOTO(out_free_oti, rc);
1145 CDEBUG(D_INODE, "san write\n");
1146 OBD_FAIL_GOTO(OBD_FAIL_OST_BRW_NET, out_free_oti, rc = 0);
1147 rc = ost_san_brw(req, OBD_BRW_WRITE);
1148 /* ost_san_brw sends its own replies */
1149 GOTO(out_free_oti, rc);
1151 CDEBUG(D_INODE, "punch\n");
1152 OBD_FAIL_GOTO(OBD_FAIL_OST_PUNCH_NET, out_free_oti, rc = 0);
1153 OBD_FAIL_GOTO(OBD_FAIL_OST_EROFS, out_check_req, rc = -EROFS);
1154 rc = ost_punch(req->rq_export, req, oti);
1157 CDEBUG(D_INODE, "statfs\n");
1158 OBD_FAIL_GOTO(OBD_FAIL_OST_STATFS_NET, out_free_oti, rc = 0);
1159 rc = ost_statfs(req);
1162 CDEBUG(D_INODE, "sync\n");
1163 OBD_FAIL_GOTO(OBD_FAIL_OST_SYNC_NET, out_free_oti, rc = 0);
1164 rc = ost_sync(req->rq_export, req);
1167 DEBUG_REQ(D_INODE, req, "set_info");
1168 rc = ost_set_info(req->rq_export, req);
1171 DEBUG_REQ(D_INODE, req, "get_info");
1172 rc = ost_get_info(req->rq_export, req);
1175 DEBUG_REQ(D_INODE, req, "ping");
1176 rc = target_handle_ping(req);
1178 /* FIXME - just reply status */
1179 case LLOG_ORIGIN_CONNECT:
1180 DEBUG_REQ(D_INODE, req, "log connect\n");
1181 rc = ost_llog_handle_connect(req->rq_export, req);
1182 req->rq_status = rc;
1183 rc = lustre_pack_reply(req, 0, NULL, NULL);
1185 GOTO(out_free_oti, rc);
1186 GOTO(out_free_oti, rc = ptlrpc_reply(req));
1187 case OBD_LOG_CANCEL:
1188 CDEBUG(D_INODE, "log cancel\n");
1189 OBD_FAIL_GOTO(OBD_FAIL_OBD_LOG_CANCEL_NET, out_free_oti, rc = 0);
1190 rc = llog_origin_handle_cancel(req);
1191 req->rq_status = rc;
1192 rc = lustre_pack_reply(req, 0, NULL, NULL);
1194 GOTO(out_free_oti, rc);
1195 GOTO(out_free_oti, rc = ptlrpc_reply(req));
1197 CDEBUG(D_INODE, "enqueue\n");
1198 OBD_FAIL_GOTO(OBD_FAIL_LDLM_ENQUEUE, out_free_oti, rc = 0);
1199 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1200 ldlm_server_blocking_ast,
1201 ldlm_server_glimpse_ast);
1202 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1205 CDEBUG(D_INODE, "convert\n");
1206 OBD_FAIL_GOTO(OBD_FAIL_LDLM_CONVERT, out_free_oti, rc = 0);
1207 rc = ldlm_handle_convert(req);
1210 CDEBUG(D_INODE, "cancel\n");
1211 OBD_FAIL_GOTO(OBD_FAIL_LDLM_CANCEL, out_free_oti, rc = 0);
1212 rc = ldlm_handle_cancel(req);
1214 case LDLM_BL_CALLBACK:
1215 case LDLM_CP_CALLBACK:
1216 CDEBUG(D_INODE, "callback\n");
1217 CERROR("callbacks should not happen on OST\n");
1220 CERROR("Unexpected opcode %d\n", req->rq_reqmsg->opc);
1221 req->rq_status = -ENOTSUPP;
1222 rc = ptlrpc_error(req);
1223 GOTO(out_free_oti, rc);
1226 LASSERT(current->journal_info == NULL);
1229 /* If we're DISCONNECTing, the export_data is already freed */
1230 if (!rc && req->rq_reqmsg->opc != OST_DISCONNECT) {
1231 if (!obd->obd_no_transno) {
1232 req->rq_repmsg->last_committed =
1233 obd->obd_last_committed;
1235 DEBUG_REQ(D_IOCTL, req,
1236 "not sending last_committed update");
1238 CDEBUG(D_INFO, "last_committed "LPU64", xid "LPX64"\n",
1239 obd->obd_last_committed, req->rq_xid);
1245 oti_to_request(oti, req);
1246 target_send_reply(req, rc, fail);
1251 OBD_FREE(oti, sizeof(*oti));
1254 EXPORT_SYMBOL(ost_handle);
1256 int ost_attach(struct obd_device *dev, obd_count len, void *data)
1258 struct lprocfs_static_vars lvars;
1260 lprocfs_init_vars(ost,&lvars);
1261 return lprocfs_obd_attach(dev, lvars.obd_vars);
1264 int ost_detach(struct obd_device *dev)
1266 return lprocfs_obd_detach(dev);
1269 extern struct file_operations ost_stimes_fops;
1271 static int ost_setup(struct obd_device *obd, obd_count len, void *buf)
1273 struct ost_obd *ost = &obd->u.ost;
1277 rc = cleanup_group_info();
1281 rc = llog_start_commit_thread();
1285 lprocfs_obd_seq_create(obd, "service_times", 0444, &ost_stimes_fops,
1289 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1290 OST_REQUEST_PORTAL, OSC_REPLY_PORTAL, 30000,
1292 obd->obd_proc_entry);
1293 if (ost->ost_service == NULL) {
1294 CERROR("failed to start service\n");
1298 rc = ptlrpc_start_n_threads(obd, ost->ost_service, OST_NUM_THREADS,
1301 GOTO(out_service, rc = -EINVAL);
1303 ost->ost_create_service =
1304 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1305 OST_CREATE_PORTAL, OSC_REPLY_PORTAL, 30000,
1306 ost_handle, "ost_create",
1307 obd->obd_proc_entry);
1308 if (ost->ost_create_service == NULL) {
1309 CERROR("failed to start OST create service\n");
1310 GOTO(out_service, rc = -ENOMEM);
1314 spin_lock_init(&ost->ost_lock);
1315 ost->ost_service->srv_obddev = obd;
1317 rc = ptlrpc_start_n_threads(obd, ost->ost_create_service, 1,
1320 GOTO(out_create, rc = -EINVAL);
1322 ost->ost_destroy_service =
1323 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1324 OST_DESTROY_PORTAL, OSC_REPLY_PORTAL, 30000,
1325 ost_handle, "ost_destroy",
1326 obd->obd_proc_entry);
1327 if (ost->ost_destroy_service == NULL) {
1328 CERROR("failed to start service\n");
1329 GOTO(out_create, rc = -ENOMEM);
1332 rc = ptlrpc_start_n_threads(obd, ost->ost_destroy_service,
1333 OST_NUM_THREADS, "ll_dstr_ost");
1335 GOTO(out_destroy, rc = -EINVAL);
1340 ptlrpc_unregister_service(ost->ost_destroy_service);
1342 ptlrpc_unregister_service(ost->ost_create_service);
1344 ptlrpc_unregister_service(ost->ost_service);
1348 extern void lgss_svc_cache_purge_all(void);
1349 static int ost_cleanup(struct obd_device *obd, int flags)
1351 struct ost_obd *ost = &obd->u.ost;
1355 spin_lock_bh(&obd->obd_processing_task_lock);
1356 if (obd->obd_recovering) {
1357 target_cancel_recovery_timer(obd);
1358 obd->obd_recovering = 0;
1360 spin_unlock_bh(&obd->obd_processing_task_lock);
1362 ptlrpc_stop_all_threads(ost->ost_service);
1363 ptlrpc_unregister_service(ost->ost_service);
1365 ptlrpc_stop_all_threads(ost->ost_create_service);
1366 ptlrpc_unregister_service(ost->ost_create_service);
1368 ptlrpc_stop_all_threads(ost->ost_destroy_service);
1369 ptlrpc_unregister_service(ost->ost_destroy_service);
1373 lgss_svc_cache_purge_all();
1378 /* use obd ops to offer management infrastructure */
1379 static struct obd_ops ost_obd_ops = {
1380 .o_owner = THIS_MODULE,
1381 .o_attach = ost_attach,
1382 .o_detach = ost_detach,
1383 .o_setup = ost_setup,
1384 .o_cleanup = ost_cleanup,
1387 static int __init ost_init(void)
1389 struct lprocfs_static_vars lvars;
1392 lprocfs_init_vars(ost,&lvars);
1393 RETURN(class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
1394 OBD_OST_DEVICENAME));
1397 static void /*__exit*/ ost_exit(void)
1399 class_unregister_type(OBD_OST_DEVICENAME);
1402 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1403 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
1404 MODULE_LICENSE("GPL");
1406 module_init(ost_init);
1407 module_exit(ost_exit);