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 the Lustre file system, http://www.lustre.org
9 * Lustre is a trademark of Cluster File Systems, Inc.
11 * You may have signed or agreed to another license before downloading
12 * this software. If so, you are bound by the terms and conditions
13 * of that agreement, and the following does not apply to you. See the
14 * LICENSE file included with this distribution for more information.
16 * If you did not agree to a different license, then this copy of Lustre
17 * is open source software; you can redistribute it and/or modify it
18 * under the terms of version 2 of the GNU General Public License as
19 * published by the Free Software Foundation.
21 * In either case, Lustre is distributed in the hope that it will be
22 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
23 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * license text for more details.
26 * Storage Target Handling functions
27 * Lustre Object Server Module (OST)
29 * This server is single threaded at present (but can easily be multi
30 * threaded). For testing and management it is treated as an
31 * obd_device, although it does not export a full OBD method table
32 * (the requests are coming in over the wire, so object target
33 * modules do not have a full method table.)
37 # define EXPORT_SYMTAB
39 #define DEBUG_SUBSYSTEM S_OST
41 #include <linux/module.h>
43 #include <lustre_net.h>
44 #include <lustre_dlm.h>
45 #include <lustre_export.h>
46 #include <lustre_debug.h>
47 #include <linux/init.h>
48 #include <lprocfs_status.h>
49 #include <lustre_commit_confd.h>
50 #include <libcfs/list.h>
51 #include <lustre_quota.h>
52 #include "ost_internal.h"
54 static int oss_num_threads;
55 CFS_MODULE_PARM(oss_num_threads, "i", int, 0444,
56 "number of OSS service threads to start");
58 static int ost_num_threads;
59 CFS_MODULE_PARM(ost_num_threads, "i", int, 0444,
60 "number of OST service threads to start (deprecated)");
62 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
64 struct oti_req_ack_lock *ack_lock;
71 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
72 req->rq_transno = oti->oti_transno;
74 /* XXX 4 == entries in oti_ack_locks??? */
75 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
78 /* XXX not even calling target_send_reply in some cases... */
79 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode);
83 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
84 struct obd_trans_info *oti)
86 struct ost_body *body, *repbody;
87 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
90 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
91 lustre_swab_ost_body);
95 if (lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1)) {
96 struct ldlm_request *dlm;
97 dlm = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*dlm),
98 lustre_swab_ldlm_request);
101 ldlm_request_cancel(req, dlm, 0);
104 rc = lustre_pack_reply(req, 2, size, NULL);
108 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
109 oti->oti_logcookies = obdo_logcookie(&body->oa);
110 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
112 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
113 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL);
117 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
119 struct ost_body *body, *repbody;
120 struct obd_info oinfo = { { { 0 } } };
121 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
124 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
125 lustre_swab_ost_body);
129 rc = lustre_pack_reply(req, 2, size, NULL);
133 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
135 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
137 oinfo.oi_oa = &repbody->oa;
138 req->rq_status = obd_getattr(exp, &oinfo);
142 static int ost_statfs(struct ptlrpc_request *req)
144 struct obd_statfs *osfs;
145 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*osfs) };
148 rc = lustre_pack_reply(req, 2, size, NULL);
152 osfs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*osfs));
154 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
155 cfs_time_current_64() - HZ);
156 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
157 osfs->os_bfree = osfs->os_bavail = 64;
158 if (req->rq_status != 0)
159 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
164 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
165 struct obd_trans_info *oti)
167 struct ost_body *body, *repbody;
168 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
171 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
172 lustre_swab_ost_body);
176 rc = lustre_pack_reply(req, 2, size, NULL);
180 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
182 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
183 oti->oti_logcookies = obdo_logcookie(&repbody->oa);
184 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
185 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
190 * Helper function for ost_punch(): if asked by client, acquire [size, EOF]
191 * lock on the file being truncated.
193 static int ost_punch_lock_get(struct obd_export *exp, struct obdo *oa,
194 struct lustre_handle *lh)
197 struct ldlm_res_id res_id = { .name = { oa->o_id } };
198 ldlm_policy_data_t policy;
204 LASSERT(!lustre_handle_is_used(lh));
206 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
207 !(oa->o_flags & OBD_FL_TRUNCLOCK))
210 CDEBUG(D_INODE, "OST-side truncate lock.\n");
213 finis = start + oa->o_blocks;
216 * standard truncate optimization: if file body is completely
217 * destroyed, don't send data back to the server.
219 flags = (start == 0) ? LDLM_AST_DISCARD_DATA : 0;
221 policy.l_extent.start = start & CFS_PAGE_MASK;
224 * If ->o_blocks is EOF it means "lock till the end of the
225 * file". Otherwise, it's size of a hole being punched (in bytes)
227 if (oa->o_blocks == OBD_OBJECT_EOF || finis < start)
228 policy.l_extent.end = OBD_OBJECT_EOF;
230 policy.l_extent.end = finis | ~CFS_PAGE_MASK;
232 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, res_id,
233 LDLM_EXTENT, &policy, LCK_PW, &flags,
234 ldlm_blocking_ast, ldlm_completion_ast,
235 ldlm_glimpse_ast, NULL, 0, NULL, lh));
239 * Helper function for ost_punch(): release lock acquired by
240 * ost_punch_lock_get(), if any.
242 static void ost_punch_lock_put(struct obd_export *exp, struct obdo *oa,
243 struct lustre_handle *lh)
246 if (lustre_handle_is_used(lh))
247 ldlm_lock_decref(lh, LCK_PW);
251 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
252 struct obd_trans_info *oti)
254 struct obd_info oinfo = { { { 0 } } };
255 struct ost_body *body, *repbody;
256 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
257 struct lustre_handle lh = {0,};
260 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
261 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
263 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
264 lustre_swab_ost_body);
268 oinfo.oi_oa = &body->oa;
269 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
270 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
272 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
273 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
276 rc = lustre_pack_reply(req, 2, size, NULL);
280 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
282 rc = ost_punch_lock_get(exp, oinfo.oi_oa, &lh);
284 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
285 oinfo.oi_oa->o_flags == OBD_FL_TRUNCLOCK)
287 * If OBD_FL_TRUNCLOCK is the only bit set in
288 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
289 * through filter_setattr() to filter_iocontrol().
291 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
293 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
294 ost_punch_lock_put(exp, oinfo.oi_oa, &lh);
296 repbody->oa = *oinfo.oi_oa;
300 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
302 struct ost_body *body, *repbody;
303 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
306 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
307 lustre_swab_ost_body);
311 rc = lustre_pack_reply(req, 2, size, NULL);
315 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
317 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
318 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
319 repbody->oa.o_blocks);
323 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
324 struct obd_trans_info *oti)
326 struct ost_body *body, *repbody;
327 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
328 struct obd_info oinfo = { { { 0 } } };
331 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
332 lustre_swab_ost_body);
336 rc = lustre_pack_reply(req, 2, size, NULL);
340 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
342 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
344 oinfo.oi_oa = &repbody->oa;
345 req->rq_status = obd_setattr(exp, &oinfo, oti);
349 static int ost_bulk_timeout(void *data)
352 /* We don't fail the connection here, because having the export
353 * killed makes the (vital) call to commitrw very sad.
358 static int get_per_page_niobufs(struct obd_ioobj *ioo, int nioo,
359 struct niobuf_remote *rnb, int nrnb,
360 struct niobuf_remote **pp_rnbp)
362 /* Copy a remote niobuf, splitting it into page-sized chunks
363 * and setting ioo[i].ioo_bufcnt accordingly */
364 struct niobuf_remote *pp_rnb;
372 * array of sufficient size already preallocated by caller
374 LASSERT(pp_rnbp != NULL);
375 LASSERT(*pp_rnbp != NULL);
377 /* first count and check the number of pages required */
378 for (i = 0; i < nioo; i++)
379 for (j = 0; j < ioo->ioo_bufcnt; j++, rnbidx++) {
380 obd_off offset = rnb[rnbidx].offset;
381 obd_off p0 = offset >> CFS_PAGE_SHIFT;
382 obd_off pn = (offset + rnb[rnbidx].len - 1)>>CFS_PAGE_SHIFT;
384 LASSERT(rnbidx < nrnb);
386 npages += (pn + 1 - p0);
388 if (rnb[rnbidx].len == 0) {
389 CERROR("zero len BRW: obj %d objid "LPX64
390 " buf %u\n", i, ioo[i].ioo_id, j);
394 rnb[rnbidx].offset <= rnb[rnbidx-1].offset) {
395 CERROR("unordered BRW: obj %d objid "LPX64
396 " buf %u offset "LPX64" <= "LPX64"\n",
397 i, ioo[i].ioo_id, j, rnb[rnbidx].offset,
403 LASSERT(rnbidx == nrnb);
405 if (npages == nrnb) { /* all niobufs are for single pages */
412 /* now do the actual split */
414 for (i = 0; i < nioo; i++) {
417 for (j = 0; j < ioo[i].ioo_bufcnt; j++, rnbidx++) {
418 obd_off off = rnb[rnbidx].offset;
419 int nob = rnb[rnbidx].len;
421 LASSERT(rnbidx < nrnb);
423 obd_off poff = off & ~CFS_PAGE_MASK;
424 int pnob = (poff + nob > CFS_PAGE_SIZE) ?
425 CFS_PAGE_SIZE - poff : nob;
427 LASSERT(page < npages);
428 pp_rnb[page].len = pnob;
429 pp_rnb[page].offset = off;
430 pp_rnb[page].flags = rnb[rnbidx].flags;
432 CDEBUG(0, " obj %d id "LPX64
433 "page %d(%d) "LPX64" for %d, flg %x\n",
434 i, ioo[i].ioo_id, obj_pages, page,
435 pp_rnb[page].offset, pp_rnb[page].len,
445 ioo[i].ioo_bufcnt = obj_pages;
447 LASSERT(page == npages);
452 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc)
457 for (i = 0; i < desc->bd_iov_count; i++) {
458 struct page *page = desc->bd_iov[i].kiov_page;
459 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
460 char *ptr = kmap(page) + off;
461 int len = desc->bd_iov[i].kiov_len;
463 /* corrupt the data before we compute the checksum, to
464 * simulate a client->OST data error */
465 if (i == 0 &&OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_CHECKSUM_RECEIVE))
466 memcpy(ptr, "bad3", min(4, len));
467 cksum = crc32_le(cksum, ptr, len);
468 /* corrupt the data after we compute the checksum, to
469 * simulate an OST->client data error */
470 if (i == 0 && OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_CHECKSUM_SEND))
471 memcpy(ptr, "bad4", min(4, len));
479 * populate @nio by @nrpages pages from per-thread page pool
481 static void ost_nio_pages_get(struct ptlrpc_request *req,
482 struct niobuf_local *nio, int nrpages)
485 struct ost_thread_local_cache *tls;
489 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
490 LASSERT(req != NULL);
491 LASSERT(req->rq_svc_thread != NULL);
494 LASSERT(tls != NULL);
496 memset(nio, 0, nrpages * sizeof *nio);
497 for (i = 0; i < nrpages; ++ i) {
501 LASSERT(page != NULL);
502 POISON_PAGE(page, 0xf1);
504 LL_CDEBUG_PAGE(D_INFO, page, "%d\n", i);
510 * Dual for ost_nio_pages_get(). Poison pages in pool for debugging
512 static void ost_nio_pages_put(struct ptlrpc_request *req,
513 struct niobuf_local *nio, int nrpages)
519 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
521 for (i = 0; i < nrpages; ++ i)
522 POISON_PAGE(nio[i].page, 0xf2);
526 static int ost_brw_lock_get(int mode, struct obd_export *exp,
527 struct obd_ioobj *obj, struct niobuf_remote *nb,
528 struct lustre_handle *lh)
531 int nrbufs = obj->ioo_bufcnt;
532 struct ldlm_res_id res_id = { .name = { obj->ioo_id } };
533 ldlm_policy_data_t policy;
538 LASSERT(mode == LCK_PR || mode == LCK_PW);
539 LASSERT(!lustre_handle_is_used(lh));
541 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
544 /* EXPENSIVE ASSERTION */
545 for (i = 1; i < nrbufs; i ++)
546 LASSERT((nb[0].flags & OBD_BRW_SRVLOCK) ==
547 (nb[i].flags & OBD_BRW_SRVLOCK));
549 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
550 policy.l_extent.end = (nb[nrbufs - 1].offset +
551 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
553 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, res_id,
554 LDLM_EXTENT, &policy, mode, &flags,
555 ldlm_blocking_ast, ldlm_completion_ast,
556 ldlm_glimpse_ast, NULL, 0, NULL, lh));
559 static void ost_brw_lock_put(int mode,
560 struct obd_ioobj *obj, struct niobuf_remote *niob,
561 struct lustre_handle *lh)
564 LASSERT(mode == LCK_PR || mode == LCK_PW);
565 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
566 lustre_handle_is_used(lh));
567 if (lustre_handle_is_used(lh))
568 ldlm_lock_decref(lh, mode);
572 struct ost_prolong_data {
573 struct obd_export *opd_exp;
574 ldlm_policy_data_t opd_policy;
575 ldlm_mode_t opd_mode;
578 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
580 struct ost_prolong_data *opd = data;
582 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
584 if (lock->l_req_mode != lock->l_granted_mode) {
585 /* scan granted locks only */
586 return LDLM_ITER_STOP;
589 if (lock->l_export != opd->opd_exp) {
590 /* prolong locks only for given client */
591 return LDLM_ITER_CONTINUE;
594 if (!(lock->l_granted_mode & opd->opd_mode)) {
595 /* we aren't interesting in all type of locks */
596 return LDLM_ITER_CONTINUE;
599 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
600 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
601 /* the request doesn't cross the lock, skip it */
602 return LDLM_ITER_CONTINUE;
605 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
606 /* ignore locks not being cancelled */
607 return LDLM_ITER_CONTINUE;
610 /* OK. this is a possible lock the user holds doing I/O
611 * let's refresh eviction timer for it */
612 ldlm_refresh_waiting_lock(lock);
614 return LDLM_ITER_CONTINUE;
617 static void ost_prolong_locks(struct obd_export *exp, struct obd_ioobj *obj,
618 struct niobuf_remote *nb, ldlm_mode_t mode)
620 struct ldlm_res_id res_id = { .name = { obj->ioo_id } };
621 int nrbufs = obj->ioo_bufcnt;
622 struct ost_prolong_data opd;
628 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
629 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
630 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
632 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
633 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
634 opd.opd_policy.l_extent.end);
635 ldlm_resource_iterate(exp->exp_obd->obd_namespace, &res_id,
636 ost_prolong_locks_iter, &opd);
639 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
641 struct ptlrpc_bulk_desc *desc;
642 struct niobuf_remote *remote_nb;
643 struct niobuf_remote *pp_rnb = NULL;
644 struct niobuf_local *local_nb;
645 struct obd_ioobj *ioo;
646 struct ost_body *body, *repbody;
647 struct l_wait_info lwi;
648 struct lustre_handle lockh = { 0 };
649 int size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
650 int comms_error = 0, niocount, npages, nob = 0, rc, i;
654 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
655 GOTO(out, rc = -EIO);
657 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
658 (obd_timeout + 1) / 4);
660 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
661 lustre_swab_ost_body);
663 CERROR("Missing/short ost_body\n");
664 GOTO(out, rc = -EFAULT);
667 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*ioo),
668 lustre_swab_obd_ioobj);
670 CERROR("Missing/short ioobj\n");
671 GOTO(out, rc = -EFAULT);
674 niocount = ioo->ioo_bufcnt;
675 if (niocount > PTLRPC_MAX_BRW_PAGES) {
676 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)\n",
678 GOTO(out, rc = -EFAULT);
681 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
682 niocount * sizeof(*remote_nb),
683 lustre_swab_niobuf_remote);
684 if (remote_nb == NULL) {
685 CERROR("Missing/short niobuf\n");
686 GOTO(out, rc = -EFAULT);
688 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
689 for (i = 1; i < niocount; i++)
690 lustre_swab_niobuf_remote (&remote_nb[i]);
693 rc = lustre_pack_reply(req, 2, size, NULL);
698 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
701 local_nb = ost_tls(req)->local;
702 pp_rnb = ost_tls(req)->remote;
704 /* FIXME all niobuf splitting should be done in obdfilter if needed */
705 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
706 npages = get_per_page_niobufs(ioo, 1, remote_nb, niocount, &pp_rnb);
708 GOTO(out, rc = npages);
710 LASSERT(npages <= OST_THREAD_POOL_SIZE);
712 ost_nio_pages_get(req, local_nb, npages);
714 desc = ptlrpc_prep_bulk_exp(req, npages,
715 BULK_PUT_SOURCE, OST_BULK_PORTAL);
717 GOTO(out, rc = -ENOMEM);
719 rc = ost_brw_lock_get(LCK_PR, req->rq_export, ioo, pp_rnb, &lockh);
724 * If getting the lock took more time than
725 * client was willing to wait, drop it. b=11330
727 if (cfs_time_current_sec() > req->rq_arrival_time.tv_sec + obd_timeout ||
728 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
730 CERROR("Dropping timed-out read from %s because locking"
731 "object "LPX64" took %ld seconds.\n",
732 libcfs_id2str(req->rq_peer), ioo->ioo_id,
733 cfs_time_current_sec() - req->rq_arrival_time.tv_sec);
737 rc = obd_preprw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
738 ioo, npages, pp_rnb, local_nb, oti);
742 ost_prolong_locks(req->rq_export, ioo, pp_rnb, LCK_PW | LCK_PR);
745 for (i = 0; i < npages; i++) {
746 int page_rc = local_nb[i].rc;
748 if (page_rc < 0) { /* error */
753 LASSERTF(page_rc <= pp_rnb[i].len, "page_rc (%d) > "
754 "pp_rnb[%d].len (%d)\n", page_rc, i, pp_rnb[i].len);
756 if (page_rc != 0) { /* some data! */
757 LASSERT (local_nb[i].page != NULL);
758 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
759 pp_rnb[i].offset & ~CFS_PAGE_MASK,
763 if (page_rc != pp_rnb[i].len) { /* short read */
764 /* All subsequent pages should be 0 */
766 LASSERT(local_nb[i].rc == 0);
771 if (unlikely(body->oa.o_valid & OBD_MD_FLCKSUM)) {
772 body->oa.o_cksum = ost_checksum_bulk(desc);
773 body->oa.o_valid = OBD_MD_FLCKSUM;
774 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
776 body->oa.o_valid = 0;
778 /* We're finishing using body->oa as an input variable */
780 /* Check if client was evicted while we were doing i/o before touching
783 if (desc->bd_export->exp_failed)
786 rc = ptlrpc_start_bulk_transfer(desc);
788 lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 4, HZ,
789 ost_bulk_timeout, desc);
790 rc = l_wait_event(desc->bd_waitq,
791 !ptlrpc_bulk_active(desc) ||
792 desc->bd_export->exp_failed, &lwi);
793 LASSERT(rc == 0 || rc == -ETIMEDOUT);
794 if (rc == -ETIMEDOUT) {
795 DEBUG_REQ(D_ERROR, req, "timeout on bulk PUT");
796 ptlrpc_abort_bulk(desc);
797 } else if (desc->bd_export->exp_failed) {
798 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
800 ptlrpc_abort_bulk(desc);
801 } else if (!desc->bd_success ||
802 desc->bd_nob_transferred != desc->bd_nob) {
803 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
805 "truncated" : "network error on",
806 desc->bd_nob_transferred,
808 /* XXX should this be a different errno? */
812 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d\n", rc);
814 comms_error = rc != 0;
817 /* Must commit after prep above in all cases */
818 rc = obd_commitrw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
819 ioo, npages, local_nb, oti, rc);
821 ost_nio_pages_put(req, local_nb, npages);
824 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
826 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
830 ost_brw_lock_put(LCK_PR, ioo, pp_rnb, &lockh);
832 ptlrpc_free_bulk(desc);
838 req->rq_status = nob;
839 target_committed_to_req(req);
841 } else if (!comms_error) {
842 /* Only reply if there was no comms problem with bulk */
843 target_committed_to_req(req);
847 if (req->rq_reply_state != NULL) {
848 /* reply out callback would free */
849 ptlrpc_rs_decref(req->rq_reply_state);
850 req->rq_reply_state = NULL;
852 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
853 "client will retry\n",
854 req->rq_export->exp_obd->obd_name,
855 req->rq_export->exp_client_uuid.uuid,
856 req->rq_export->exp_connection->c_remote_uuid.uuid,
857 libcfs_id2str(req->rq_peer));
863 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
865 struct ptlrpc_bulk_desc *desc;
866 struct niobuf_remote *remote_nb;
867 struct niobuf_remote *pp_rnb;
868 struct niobuf_local *local_nb;
869 struct obd_ioobj *ioo;
870 struct ost_body *body, *repbody;
871 struct l_wait_info lwi;
872 struct lustre_handle lockh = {0};
874 int size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
875 int objcount, niocount, npages, comms_error = 0;
877 obd_count client_cksum, server_cksum = 0;
881 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
882 GOTO(out, rc = -EIO);
884 /* pause before transaction has been started */
885 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
886 (obd_timeout + 1) / 4);
888 swab = lustre_msg_swabbed(req->rq_reqmsg);
889 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
890 lustre_swab_ost_body);
892 CERROR("Missing/short ost_body\n");
893 GOTO(out, rc = -EFAULT);
896 LASSERT_REQSWAB(req, REQ_REC_OFF + 1);
897 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
900 CERROR("Missing/short ioobj\n");
901 GOTO(out, rc = -EFAULT);
904 CERROR("too many ioobjs (%d)\n", objcount);
905 GOTO(out, rc = -EFAULT);
908 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
909 objcount * sizeof(*ioo));
910 LASSERT (ioo != NULL);
911 for (niocount = i = 0; i < objcount; i++) {
913 lustre_swab_obd_ioobj(&ioo[i]);
914 if (ioo[i].ioo_bufcnt == 0) {
915 CERROR("ioo[%d] has zero bufcnt\n", i);
916 GOTO(out, rc = -EFAULT);
918 niocount += ioo[i].ioo_bufcnt;
921 if (niocount > PTLRPC_MAX_BRW_PAGES) {
922 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)\n",
924 GOTO(out, rc = -EFAULT);
927 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
928 niocount * sizeof(*remote_nb),
929 lustre_swab_niobuf_remote);
930 if (remote_nb == NULL) {
931 CERROR("Missing/short niobuf\n");
932 GOTO(out, rc = -EFAULT);
934 if (swab) { /* swab the remaining niobufs */
935 for (i = 1; i < niocount; i++)
936 lustre_swab_niobuf_remote (&remote_nb[i]);
939 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
940 rc = lustre_pack_reply(req, 3, size, NULL);
943 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
944 niocount * sizeof(*rcs));
947 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
950 local_nb = ost_tls(req)->local;
951 pp_rnb = ost_tls(req)->remote;
953 /* FIXME all niobuf splitting should be done in obdfilter if needed */
954 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
955 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
957 GOTO(out, rc = npages);
959 LASSERT(npages <= OST_THREAD_POOL_SIZE);
961 ost_nio_pages_get(req, local_nb, npages);
963 desc = ptlrpc_prep_bulk_exp(req, npages,
964 BULK_GET_SINK, OST_BULK_PORTAL);
966 GOTO(out, rc = -ENOMEM);
968 rc = ost_brw_lock_get(LCK_PW, req->rq_export, ioo, pp_rnb, &lockh);
973 * If getting the lock took more time than
974 * client was willing to wait, drop it. b=11330
976 if (cfs_time_current_sec() > req->rq_arrival_time.tv_sec + obd_timeout ||
977 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
979 CERROR("Dropping timed-out write from %s because locking"
980 "object "LPX64" took %ld seconds.\n",
981 libcfs_id2str(req->rq_peer), ioo->ioo_id,
982 cfs_time_current_sec() - req->rq_arrival_time.tv_sec);
986 ost_prolong_locks(req->rq_export, ioo, pp_rnb, LCK_PW);
988 /* obd_preprw clobbers oa->valid, so save what we need */
989 client_cksum = body->oa.o_valid & OBD_MD_FLCKSUM ? body->oa.o_cksum : 0;
991 /* Because we already sync grant info with client when reconnect,
992 * grant info will be cleared for resent req, then fed_grant and
993 * total_grant will not be modified in following preprw_write*/
994 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
995 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info\n");
996 body->oa.o_valid &= ~OBD_MD_FLGRANT;
999 rc = obd_preprw(OBD_BRW_WRITE, req->rq_export, &body->oa, objcount,
1000 ioo, npages, pp_rnb, local_nb, oti);
1004 /* NB Having prepped, we must commit... */
1006 for (i = 0; i < npages; i++)
1007 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1008 pp_rnb[i].offset & ~CFS_PAGE_MASK,
1011 /* Check if client was evicted while we were doing i/o before touching
1013 if (desc->bd_export->exp_failed)
1016 rc = ptlrpc_start_bulk_transfer (desc);
1018 lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 2, HZ,
1019 ost_bulk_timeout, desc);
1020 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1021 desc->bd_export->exp_failed, &lwi);
1022 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1023 if (rc == -ETIMEDOUT) {
1024 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1025 ptlrpc_abort_bulk(desc);
1026 } else if (desc->bd_export->exp_failed) {
1027 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1029 ptlrpc_abort_bulk(desc);
1030 } else if (!desc->bd_success ||
1031 desc->bd_nob_transferred != desc->bd_nob) {
1032 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1034 "truncated" : "network error on",
1035 desc->bd_nob_transferred, desc->bd_nob);
1036 /* XXX should this be a different errno? */
1040 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d\n", rc);
1042 comms_error = rc != 0;
1044 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1046 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1048 if (unlikely(client_cksum != 0 && rc == 0)) {
1049 static int cksum_counter;
1051 server_cksum = ost_checksum_bulk(desc);
1052 repbody->oa.o_valid |= OBD_MD_FLCKSUM;
1053 repbody->oa.o_cksum = server_cksum;
1055 if (unlikely(client_cksum != server_cksum)) {
1056 CERROR("client csum %x, server csum %x\n",
1057 client_cksum, server_cksum);
1059 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1060 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1061 cksum_counter, libcfs_id2str(req->rq_peer),
1066 /* Must commit after prep above in all cases */
1067 rc = obd_commitrw(OBD_BRW_WRITE, req->rq_export, &repbody->oa,
1068 objcount, ioo, npages, local_nb, oti, rc);
1070 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1071 int new_cksum = ost_checksum_bulk(desc);
1076 if (new_cksum == server_cksum)
1077 msg = "changed in transit before arrival at OST";
1078 else if (new_cksum == client_cksum)
1079 msg = "initial checksum before message complete";
1081 msg = "changed in transit AND after initial checksum";
1083 if (req->rq_peer.nid == desc->bd_sender) {
1087 router = libcfs_nid2str(desc->bd_sender);
1090 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from %s"
1091 "%s%s inum "LPU64"/"LPU64" object "LPU64"/"
1092 LPU64" extent ["LPU64"-"LPU64"]\n",
1093 req->rq_export->exp_obd->obd_name, msg,
1094 libcfs_id2str(req->rq_peer),
1096 body->oa.o_valid & OBD_MD_FLFID ?
1097 body->oa.o_fid : (__u64)0,
1098 body->oa.o_valid & OBD_MD_FLFID ?
1099 body->oa.o_generation :(__u64)0,
1101 body->oa.o_valid & OBD_MD_FLGROUP ?
1102 body->oa.o_gr : (__u64)0,
1104 pp_rnb[npages-1].offset+pp_rnb[npages-1].len
1106 CERROR("client csum %x, original server csum %x, "
1107 "server csum now %x\n",
1108 client_cksum, server_cksum, new_cksum);
1111 ost_nio_pages_put(req, local_nb, npages);
1114 /* set per-requested niobuf return codes */
1115 for (i = j = 0; i < niocount; i++) {
1116 int nob = remote_nb[i].len;
1120 LASSERT(j < npages);
1121 if (local_nb[j].rc < 0)
1122 rcs[i] = local_nb[j].rc;
1123 nob -= pp_rnb[j].len;
1128 LASSERT(j == npages);
1132 ost_brw_lock_put(LCK_PW, ioo, pp_rnb, &lockh);
1134 ptlrpc_free_bulk(desc);
1139 oti_to_request(oti, req);
1140 target_committed_to_req(req);
1141 rc = ptlrpc_reply(req);
1142 } else if (!comms_error) {
1143 /* Only reply if there was no comms problem with bulk */
1144 target_committed_to_req(req);
1145 req->rq_status = rc;
1148 if (req->rq_reply_state != NULL) {
1149 /* reply out callback would free */
1150 ptlrpc_rs_decref(req->rq_reply_state);
1151 req->rq_reply_state = NULL;
1153 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1154 "client will retry\n",
1155 req->rq_export->exp_obd->obd_name,
1156 req->rq_export->exp_client_uuid.uuid,
1157 req->rq_export->exp_connection->c_remote_uuid.uuid,
1158 libcfs_id2str(req->rq_peer));
1163 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1165 char *key, *val = NULL;
1166 int keylen, vallen, rc = 0;
1169 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1171 DEBUG_REQ(D_HA, req, "no set_info key");
1174 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1176 rc = lustre_pack_reply(req, 1, NULL, NULL);
1180 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1182 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
1184 if (KEY_IS("evict_by_nid")) {
1186 obd_export_evict_by_nid(exp->exp_obd, val);
1191 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1193 lustre_msg_set_status(req->rq_repmsg, 0);
1197 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1201 int size[2] = { sizeof(struct ptlrpc_body), sizeof(obd_id) };
1205 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1207 DEBUG_REQ(D_HA, req, "no get_info key");
1210 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1212 if (keylen < strlen("last_id") || memcmp(key, "last_id", 7) != 0)
1215 rc = lustre_pack_reply(req, 2, size, NULL);
1219 reply = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*reply));
1220 rc = obd_get_info(exp, keylen, key, size, reply);
1221 lustre_msg_set_status(req->rq_repmsg, 0);
1225 static int ost_handle_quotactl(struct ptlrpc_request *req)
1227 struct obd_quotactl *oqctl, *repoqc;
1228 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) };
1231 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1232 lustre_swab_obd_quotactl);
1234 GOTO(out, rc = -EPROTO);
1236 rc = lustre_pack_reply(req, 2, size, NULL);
1240 repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc));
1242 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1248 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1250 struct obd_quotactl *oqctl;
1254 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1255 lustre_swab_obd_quotactl);
1259 rc = lustre_pack_reply(req, 1, NULL, NULL);
1261 CERROR("ost: out of memory while packing quotacheck reply\n");
1265 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1269 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1270 struct obd_device *obd, int *process)
1272 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1273 case OST_CONNECT: /* This will never get here, but for completeness. */
1274 case OST_DISCONNECT:
1285 case OBD_LOG_CANCEL:
1287 *process = target_queue_recovery_request(req, obd);
1291 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1293 /* XXX what should we set rq_status to here? */
1294 req->rq_status = -EAGAIN;
1295 RETURN(ptlrpc_error(req));
1299 int ost_msg_check_version(struct lustre_msg *msg)
1303 switch(lustre_msg_get_opc(msg)) {
1305 case OST_DISCONNECT:
1307 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1309 CERROR("bad opc %u version %08x, expecting %08x\n",
1310 lustre_msg_get_opc(msg),
1311 lustre_msg_get_version(msg),
1312 LUSTRE_OBD_VERSION);
1325 case OST_QUOTACHECK:
1327 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1329 CERROR("bad opc %u version %08x, expecting %08x\n",
1330 lustre_msg_get_opc(msg),
1331 lustre_msg_get_version(msg),
1332 LUSTRE_OST_VERSION);
1337 case LDLM_BL_CALLBACK:
1338 case LDLM_CP_CALLBACK:
1339 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1341 CERROR("bad opc %u version %08x, expecting %08x\n",
1342 lustre_msg_get_opc(msg),
1343 lustre_msg_get_version(msg),
1344 LUSTRE_DLM_VERSION);
1346 case LLOG_ORIGIN_CONNECT:
1347 case OBD_LOG_CANCEL:
1348 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1350 CERROR("bad opc %u version %08x, expecting %08x\n",
1351 lustre_msg_get_opc(msg),
1352 lustre_msg_get_version(msg),
1353 LUSTRE_LOG_VERSION);
1356 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1362 static int ost_handle(struct ptlrpc_request *req)
1364 struct obd_trans_info trans_info = { 0, };
1365 struct obd_trans_info *oti = &trans_info;
1366 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1367 struct obd_device *obd = NULL;
1370 LASSERT(current->journal_info == NULL);
1371 /* XXX identical to MDS */
1372 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1373 int abort_recovery, recovering;
1375 if (req->rq_export == NULL) {
1376 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1377 lustre_msg_get_opc(req->rq_reqmsg),
1378 libcfs_id2str(req->rq_peer));
1379 req->rq_status = -ENOTCONN;
1380 GOTO(out, rc = -ENOTCONN);
1383 obd = req->rq_export->exp_obd;
1385 /* Check for aborted recovery. */
1386 spin_lock_bh(&obd->obd_processing_task_lock);
1387 abort_recovery = obd->obd_abort_recovery;
1388 recovering = obd->obd_recovering;
1389 spin_unlock_bh(&obd->obd_processing_task_lock);
1390 if (abort_recovery) {
1391 target_abort_recovery(obd);
1392 } else if (recovering) {
1393 rc = ost_filter_recovery_request(req, obd,
1395 if (rc || !should_process)
1401 rc = ost_msg_check_version(req->rq_reqmsg);
1405 rc = ost_msg_check_version(req->rq_reqmsg);
1409 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1411 CDEBUG(D_INODE, "connect\n");
1412 OBD_FAIL_RETURN(OBD_FAIL_OST_CONNECT_NET, 0);
1413 rc = target_handle_connect(req, ost_handle);
1415 obd = req->rq_export->exp_obd;
1418 case OST_DISCONNECT:
1419 CDEBUG(D_INODE, "disconnect\n");
1420 OBD_FAIL_RETURN(OBD_FAIL_OST_DISCONNECT_NET, 0);
1421 rc = target_handle_disconnect(req);
1424 CDEBUG(D_INODE, "create\n");
1425 OBD_FAIL_RETURN(OBD_FAIL_OST_CREATE_NET, 0);
1426 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
1427 GOTO(out, rc = -ENOSPC);
1428 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1429 GOTO(out, rc = -EROFS);
1430 rc = ost_create(req->rq_export, req, oti);
1433 CDEBUG(D_INODE, "destroy\n");
1434 OBD_FAIL_RETURN(OBD_FAIL_OST_DESTROY_NET, 0);
1435 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1436 GOTO(out, rc = -EROFS);
1437 rc = ost_destroy(req->rq_export, req, oti);
1440 CDEBUG(D_INODE, "getattr\n");
1441 OBD_FAIL_RETURN(OBD_FAIL_OST_GETATTR_NET, 0);
1442 rc = ost_getattr(req->rq_export, req);
1445 CDEBUG(D_INODE, "setattr\n");
1446 OBD_FAIL_RETURN(OBD_FAIL_OST_SETATTR_NET, 0);
1447 rc = ost_setattr(req->rq_export, req, oti);
1450 CDEBUG(D_INODE, "write\n");
1451 /* req->rq_request_portal would be nice, if it was set */
1452 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1453 CERROR("%s: deny write request from %s to portal %u\n",
1454 req->rq_export->exp_obd->obd_name,
1455 obd_export_nid2str(req->rq_export),
1456 req->rq_rqbd->rqbd_service->srv_req_portal);
1457 GOTO(out, rc = -EPROTO);
1459 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1460 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
1461 GOTO(out, rc = -ENOSPC);
1462 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1463 GOTO(out, rc = -EROFS);
1464 rc = ost_brw_write(req, oti);
1465 LASSERT(current->journal_info == NULL);
1466 /* ost_brw_write sends its own replies */
1469 CDEBUG(D_INODE, "read\n");
1470 /* req->rq_request_portal would be nice, if it was set */
1471 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1472 CERROR("%s: deny read request from %s to portal %u\n",
1473 req->rq_export->exp_obd->obd_name,
1474 obd_export_nid2str(req->rq_export),
1475 req->rq_rqbd->rqbd_service->srv_req_portal);
1476 GOTO(out, rc = -EPROTO);
1478 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1479 rc = ost_brw_read(req, oti);
1480 LASSERT(current->journal_info == NULL);
1481 /* ost_brw_read sends its own replies */
1484 CDEBUG(D_INODE, "punch\n");
1485 OBD_FAIL_RETURN(OBD_FAIL_OST_PUNCH_NET, 0);
1486 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1487 GOTO(out, rc = -EROFS);
1488 rc = ost_punch(req->rq_export, req, oti);
1491 CDEBUG(D_INODE, "statfs\n");
1492 OBD_FAIL_RETURN(OBD_FAIL_OST_STATFS_NET, 0);
1493 rc = ost_statfs(req);
1496 CDEBUG(D_INODE, "sync\n");
1497 OBD_FAIL_RETURN(OBD_FAIL_OST_SYNC_NET, 0);
1498 rc = ost_sync(req->rq_export, req);
1501 DEBUG_REQ(D_INODE, req, "set_info");
1502 rc = ost_set_info(req->rq_export, req);
1505 DEBUG_REQ(D_INODE, req, "get_info");
1506 rc = ost_get_info(req->rq_export, req);
1508 case OST_QUOTACHECK:
1509 CDEBUG(D_INODE, "quotacheck\n");
1510 OBD_FAIL_RETURN(OBD_FAIL_OST_QUOTACHECK_NET, 0);
1511 rc = ost_handle_quotacheck(req);
1514 CDEBUG(D_INODE, "quotactl\n");
1515 OBD_FAIL_RETURN(OBD_FAIL_OST_QUOTACTL_NET, 0);
1516 rc = ost_handle_quotactl(req);
1519 DEBUG_REQ(D_INODE, req, "ping");
1520 rc = target_handle_ping(req);
1522 /* FIXME - just reply status */
1523 case LLOG_ORIGIN_CONNECT:
1524 DEBUG_REQ(D_INODE, req, "log connect\n");
1525 rc = llog_handle_connect(req);
1526 req->rq_status = rc;
1527 rc = lustre_pack_reply(req, 1, NULL, NULL);
1530 RETURN(ptlrpc_reply(req));
1531 case OBD_LOG_CANCEL:
1532 CDEBUG(D_INODE, "log cancel\n");
1533 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
1534 rc = llog_origin_handle_cancel(req);
1535 req->rq_status = rc;
1536 rc = lustre_pack_reply(req, 1, NULL, NULL);
1539 RETURN(ptlrpc_reply(req));
1541 CDEBUG(D_INODE, "enqueue\n");
1542 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
1543 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1544 ldlm_server_blocking_ast,
1545 ldlm_server_glimpse_ast);
1546 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1549 CDEBUG(D_INODE, "convert\n");
1550 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
1551 rc = ldlm_handle_convert(req);
1554 CDEBUG(D_INODE, "cancel\n");
1555 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CANCEL, 0);
1556 rc = ldlm_handle_cancel(req);
1558 case LDLM_BL_CALLBACK:
1559 case LDLM_CP_CALLBACK:
1560 CDEBUG(D_INODE, "callback\n");
1561 CERROR("callbacks should not happen on OST\n");
1564 CERROR("Unexpected opcode %d\n",
1565 lustre_msg_get_opc(req->rq_reqmsg));
1566 req->rq_status = -ENOTSUPP;
1567 rc = ptlrpc_error(req);
1571 LASSERT(current->journal_info == NULL);
1574 /* If we're DISCONNECTing, the export_data is already freed */
1575 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
1576 target_committed_to_req(req);
1579 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LAST_REPLAY) {
1580 if (obd && obd->obd_recovering) {
1581 DEBUG_REQ(D_HA, req, "LAST_REPLAY, queuing reply");
1582 return target_queue_final_reply(req, rc);
1584 /* Lost a race with recovery; let the error path DTRT. */
1585 rc = req->rq_status = -ENOTCONN;
1589 oti_to_request(oti, req);
1591 target_send_reply(req, rc, fail);
1596 * free per-thread pool created by ost_thread_init().
1598 static void ost_thread_done(struct ptlrpc_thread *thread)
1601 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
1606 LASSERT(thread != NULL);
1609 * be prepared to handle partially-initialized pools (because this is
1610 * called from ost_thread_init() for cleanup.
1612 tls = thread->t_data;
1614 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1615 if (tls->page[i] != NULL)
1616 __free_page(tls->page[i]);
1619 thread->t_data = NULL;
1625 * initialize per-thread page pool (bug 5137).
1627 static int ost_thread_init(struct ptlrpc_thread *thread)
1631 struct ost_thread_local_cache *tls;
1635 LASSERT(thread != NULL);
1636 LASSERT(thread->t_data == NULL);
1637 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
1642 thread->t_data = tls;
1646 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1647 tls->page[i] = alloc_page(OST_THREAD_POOL_GFP);
1648 if (tls->page[i] == NULL) {
1649 ost_thread_done(thread);
1659 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
1660 static int ost_setup(struct obd_device *obd, obd_count len, void *buf)
1662 struct ost_obd *ost = &obd->u.ost;
1663 struct lprocfs_static_vars lvars;
1664 int oss_min_threads;
1665 int oss_max_threads;
1669 rc = cleanup_group_info();
1673 rc = llog_start_commit_thread();
1677 lprocfs_init_vars(ost, &lvars);
1678 lprocfs_obd_setup(obd, lvars.obd_vars);
1680 sema_init(&ost->ost_health_sem, 1);
1682 if (oss_num_threads) {
1683 /* If oss_num_threads is set, it is the min and the max. */
1684 if (oss_num_threads > OSS_THREADS_MAX)
1685 oss_num_threads = OSS_THREADS_MAX;
1686 if (oss_num_threads < OSS_THREADS_MIN)
1687 oss_num_threads = OSS_THREADS_MIN;
1688 oss_max_threads = oss_min_threads = oss_num_threads;
1690 /* Base min threads on memory and cpus */
1691 oss_min_threads = smp_num_cpus * num_physpages >>
1692 (27 - CFS_PAGE_SHIFT);
1693 if (oss_min_threads < OSS_THREADS_MIN)
1694 oss_min_threads = OSS_THREADS_MIN;
1695 /* Insure a 4x range for dynamic threads */
1696 if (oss_min_threads > OSS_THREADS_MAX / 4)
1697 oss_min_threads = OSS_THREADS_MAX / 4;
1698 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4);
1702 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1703 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
1705 obd_timeout * 1000, ost_handle, LUSTRE_OSS_NAME,
1706 obd->obd_proc_entry, ost_print_req,
1707 oss_min_threads, oss_max_threads, "ll_ost");
1708 if (ost->ost_service == NULL) {
1709 CERROR("failed to start OST service\n");
1710 GOTO(out_lprocfs, rc = -ENOMEM);
1713 rc = ptlrpc_start_threads(obd, ost->ost_service);
1715 GOTO(out_service, rc = -EINVAL);
1717 ost->ost_create_service =
1718 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1719 OST_MAXREPSIZE, OST_CREATE_PORTAL,
1721 obd_timeout * 1000, ost_handle, "ost_create",
1722 obd->obd_proc_entry, ost_print_req,
1723 1, 1, "ll_ost_creat");
1724 if (ost->ost_create_service == NULL) {
1725 CERROR("failed to start OST create service\n");
1726 GOTO(out_service, rc = -ENOMEM);
1729 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
1731 GOTO(out_create, rc = -EINVAL);
1733 ost->ost_io_service =
1734 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1735 OST_MAXREPSIZE, OST_IO_PORTAL,
1737 obd_timeout * 1000, ost_handle, "ost_io",
1738 obd->obd_proc_entry, ost_print_req,
1739 oss_min_threads, oss_max_threads, "ll_ost_io");
1740 if (ost->ost_io_service == NULL) {
1741 CERROR("failed to start OST I/O service\n");
1742 GOTO(out_create, rc = -ENOMEM);
1745 ost->ost_io_service->srv_init = ost_thread_init;
1746 ost->ost_io_service->srv_done = ost_thread_done;
1747 ost->ost_io_service->srv_cpu_affinity = 1;
1748 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
1750 GOTO(out_io, rc = -EINVAL);
1752 ping_evictor_start();
1757 ptlrpc_unregister_service(ost->ost_io_service);
1758 ost->ost_io_service = NULL;
1760 ptlrpc_unregister_service(ost->ost_create_service);
1761 ost->ost_create_service = NULL;
1763 ptlrpc_unregister_service(ost->ost_service);
1764 ost->ost_service = NULL;
1766 lprocfs_obd_cleanup(obd);
1770 static int ost_cleanup(struct obd_device *obd)
1772 struct ost_obd *ost = &obd->u.ost;
1776 ping_evictor_stop();
1778 spin_lock_bh(&obd->obd_processing_task_lock);
1779 if (obd->obd_recovering) {
1780 target_cancel_recovery_timer(obd);
1781 obd->obd_recovering = 0;
1783 spin_unlock_bh(&obd->obd_processing_task_lock);
1785 down(&ost->ost_health_sem);
1786 ptlrpc_unregister_service(ost->ost_service);
1787 ptlrpc_unregister_service(ost->ost_create_service);
1788 ptlrpc_unregister_service(ost->ost_io_service);
1789 ost->ost_service = NULL;
1790 ost->ost_create_service = NULL;
1791 up(&ost->ost_health_sem);
1793 lprocfs_obd_cleanup(obd);
1798 static int ost_health_check(struct obd_device *obd)
1800 struct ost_obd *ost = &obd->u.ost;
1803 down(&ost->ost_health_sem);
1804 rc |= ptlrpc_service_health_check(ost->ost_service);
1805 rc |= ptlrpc_service_health_check(ost->ost_create_service);
1806 rc |= ptlrpc_service_health_check(ost->ost_io_service);
1807 up(&ost->ost_health_sem);
1810 * health_check to return 0 on healthy
1811 * and 1 on unhealthy.
1819 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
1821 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
1824 /* use obd ops to offer management infrastructure */
1825 static struct obd_ops ost_obd_ops = {
1826 .o_owner = THIS_MODULE,
1827 .o_setup = ost_setup,
1828 .o_cleanup = ost_cleanup,
1829 .o_health_check = ost_health_check,
1833 static int __init ost_init(void)
1835 struct lprocfs_static_vars lvars;
1839 lprocfs_init_vars(ost, &lvars);
1840 rc = class_register_type(&ost_obd_ops, lvars.module_vars,
1843 if (ost_num_threads != 0 && oss_num_threads == 0) {
1844 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
1845 "use oss_num_threads instead or unset both for "
1846 "dynamic thread startup\n");
1847 oss_num_threads = ost_num_threads;
1853 static void /*__exit*/ ost_exit(void)
1855 class_unregister_type(LUSTRE_OSS_NAME);
1858 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1859 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
1860 MODULE_LICENSE("GPL");
1862 module_init(ost_init);
1863 module_exit(ost_exit);