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 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
60 struct oti_req_ack_lock *ack_lock;
67 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
68 req->rq_transno = oti->oti_transno;
70 /* XXX 4 == entries in oti_ack_locks??? */
71 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
74 /* XXX not even calling target_send_reply in some cases... */
75 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode);
79 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
80 struct obd_trans_info *oti)
82 struct ost_body *body, *repbody;
83 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
86 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
87 lustre_swab_ost_body);
91 rc = lustre_pack_reply(req, 2, 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, REPLY_REC_OFF,
99 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
100 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL);
104 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
106 struct ost_body *body, *repbody;
107 struct obd_info oinfo = { { { 0 } } };
108 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
111 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
112 lustre_swab_ost_body);
116 rc = lustre_pack_reply(req, 2, size, NULL);
120 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
122 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
124 oinfo.oi_oa = &repbody->oa;
125 req->rq_status = obd_getattr(exp, &oinfo);
129 static int ost_statfs(struct ptlrpc_request *req)
131 struct obd_statfs *osfs;
132 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*osfs) };
135 rc = lustre_pack_reply(req, 2, size, NULL);
139 osfs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*osfs));
141 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
142 cfs_time_current_64() - HZ);
143 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
144 osfs->os_bfree = osfs->os_bavail = 64;
145 if (req->rq_status != 0)
146 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
151 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
152 struct obd_trans_info *oti)
154 struct ost_body *body, *repbody;
155 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
158 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
159 lustre_swab_ost_body);
163 rc = lustre_pack_reply(req, 2, size, NULL);
167 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
169 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
170 oti->oti_logcookies = obdo_logcookie(&repbody->oa);
171 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
172 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
177 * Helper function for ost_punch(): if asked by client, acquire [size, EOF]
178 * lock on the file being truncated.
180 static int ost_punch_lock_get(struct obd_export *exp, struct obdo *oa,
181 struct lustre_handle *lh)
184 struct ldlm_res_id res_id = { .name = { oa->o_id } };
185 ldlm_policy_data_t policy;
191 LASSERT(!lustre_handle_is_used(lh));
193 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
194 !(oa->o_flags & OBD_FL_TRUNCLOCK))
197 CDEBUG(D_INODE, "OST-side truncate lock.\n");
200 finis = start + oa->o_blocks;
203 * standard truncate optimization: if file body is completely
204 * destroyed, don't send data back to the server.
206 flags = (start == 0) ? LDLM_AST_DISCARD_DATA : 0;
208 policy.l_extent.start = start & CFS_PAGE_MASK;
211 * If ->o_blocks is EOF it means "lock till the end of the
212 * file". Otherwise, it's size of a hole being punched (in bytes)
214 if (oa->o_blocks == OBD_OBJECT_EOF || finis < start)
215 policy.l_extent.end = OBD_OBJECT_EOF;
217 policy.l_extent.end = finis | ~CFS_PAGE_MASK;
219 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, res_id,
220 LDLM_EXTENT, &policy, LCK_PW, &flags,
221 ldlm_blocking_ast, ldlm_completion_ast,
222 ldlm_glimpse_ast, NULL, 0, NULL, lh));
226 * Helper function for ost_punch(): release lock acquired by
227 * ost_punch_lock_get(), if any.
229 static void ost_punch_lock_put(struct obd_export *exp, struct obdo *oa,
230 struct lustre_handle *lh)
233 if (lustre_handle_is_used(lh))
234 ldlm_lock_decref(lh, LCK_PW);
238 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
239 struct obd_trans_info *oti)
241 struct obd_info oinfo = { { { 0 } } };
242 struct ost_body *body, *repbody;
243 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
244 struct lustre_handle lh = {0,};
247 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
248 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
250 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
251 lustre_swab_ost_body);
255 oinfo.oi_oa = &body->oa;
256 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
257 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
259 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
260 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
263 rc = lustre_pack_reply(req, 2, size, NULL);
267 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
269 rc = ost_punch_lock_get(exp, oinfo.oi_oa, &lh);
271 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
272 oinfo.oi_oa->o_flags == OBD_FL_TRUNCLOCK)
274 * If OBD_FL_TRUNCLOCK is the only bit set in
275 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
276 * through filter_setattr() to filter_iocontrol().
278 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
280 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
281 ost_punch_lock_put(exp, oinfo.oi_oa, &lh);
283 repbody->oa = *oinfo.oi_oa;
287 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
289 struct ost_body *body, *repbody;
290 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
293 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
294 lustre_swab_ost_body);
298 rc = lustre_pack_reply(req, 2, size, NULL);
302 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
304 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
305 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
306 repbody->oa.o_blocks);
310 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
311 struct obd_trans_info *oti)
313 struct ost_body *body, *repbody;
314 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
315 struct obd_info oinfo = { { { 0 } } };
318 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
319 lustre_swab_ost_body);
323 rc = lustre_pack_reply(req, 2, size, NULL);
327 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
329 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
331 oinfo.oi_oa = &repbody->oa;
332 req->rq_status = obd_setattr(exp, &oinfo, oti);
336 static int ost_bulk_timeout(void *data)
339 /* We don't fail the connection here, because having the export
340 * killed makes the (vital) call to commitrw very sad.
345 static int get_per_page_niobufs(struct obd_ioobj *ioo, int nioo,
346 struct niobuf_remote *rnb, int nrnb,
347 struct niobuf_remote **pp_rnbp)
349 /* Copy a remote niobuf, splitting it into page-sized chunks
350 * and setting ioo[i].ioo_bufcnt accordingly */
351 struct niobuf_remote *pp_rnb;
359 * array of sufficient size already preallocated by caller
361 LASSERT(pp_rnbp != NULL);
362 LASSERT(*pp_rnbp != NULL);
364 /* first count and check the number of pages required */
365 for (i = 0; i < nioo; i++)
366 for (j = 0; j < ioo->ioo_bufcnt; j++, rnbidx++) {
367 obd_off offset = rnb[rnbidx].offset;
368 obd_off p0 = offset >> CFS_PAGE_SHIFT;
369 obd_off pn = (offset + rnb[rnbidx].len - 1)>>CFS_PAGE_SHIFT;
371 LASSERT(rnbidx < nrnb);
373 npages += (pn + 1 - p0);
375 if (rnb[rnbidx].len == 0) {
376 CERROR("zero len BRW: obj %d objid "LPX64
377 " buf %u\n", i, ioo[i].ioo_id, j);
381 rnb[rnbidx].offset <= rnb[rnbidx-1].offset) {
382 CERROR("unordered BRW: obj %d objid "LPX64
383 " buf %u offset "LPX64" <= "LPX64"\n",
384 i, ioo[i].ioo_id, j, rnb[rnbidx].offset,
390 LASSERT(rnbidx == nrnb);
392 if (npages == nrnb) { /* all niobufs are for single pages */
399 /* now do the actual split */
401 for (i = 0; i < nioo; i++) {
404 for (j = 0; j < ioo[i].ioo_bufcnt; j++, rnbidx++) {
405 obd_off off = rnb[rnbidx].offset;
406 int nob = rnb[rnbidx].len;
408 LASSERT(rnbidx < nrnb);
410 obd_off poff = off & ~CFS_PAGE_MASK;
411 int pnob = (poff + nob > CFS_PAGE_SIZE) ?
412 CFS_PAGE_SIZE - poff : nob;
414 LASSERT(page < npages);
415 pp_rnb[page].len = pnob;
416 pp_rnb[page].offset = off;
417 pp_rnb[page].flags = rnb[rnbidx].flags;
419 CDEBUG(0, " obj %d id "LPX64
420 "page %d(%d) "LPX64" for %d, flg %x\n",
421 i, ioo[i].ioo_id, obj_pages, page,
422 pp_rnb[page].offset, pp_rnb[page].len,
432 ioo[i].ioo_bufcnt = obj_pages;
434 LASSERT(page == npages);
439 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc)
444 for (i = 0; i < desc->bd_iov_count; i++) {
445 struct page *page = desc->bd_iov[i].kiov_page;
446 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
447 char *ptr = kmap(page) + off;
448 int len = desc->bd_iov[i].kiov_len;
450 /* corrupt the data before we compute the checksum, to
451 * simulate a client->OST data error */
452 if (i == 0 &&OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_CHECKSUM_RECEIVE))
453 memcpy(ptr, "bad3", min(4, len));
454 cksum = crc32_le(cksum, ptr, len);
455 /* corrupt the data after we compute the checksum, to
456 * simulate an OST->client data error */
457 if (i == 0 && OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_CHECKSUM_SEND))
458 memcpy(ptr, "bad4", min(4, len));
466 * populate @nio by @nrpages pages from per-thread page pool
468 static void ost_nio_pages_get(struct ptlrpc_request *req,
469 struct niobuf_local *nio, int nrpages)
472 struct ost_thread_local_cache *tls;
476 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
477 LASSERT(req != NULL);
478 LASSERT(req->rq_svc_thread != NULL);
481 LASSERT(tls != NULL);
483 memset(nio, 0, nrpages * sizeof *nio);
484 for (i = 0; i < nrpages; ++ i) {
488 LASSERT(page != NULL);
489 POISON_PAGE(page, 0xf1);
491 LL_CDEBUG_PAGE(D_INFO, page, "%d\n", i);
497 * Dual for ost_nio_pages_get(). Poison pages in pool for debugging
499 static void ost_nio_pages_put(struct ptlrpc_request *req,
500 struct niobuf_local *nio, int nrpages)
506 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
508 for (i = 0; i < nrpages; ++ i)
509 POISON_PAGE(nio[i].page, 0xf2);
513 static int ost_brw_lock_get(int mode, struct obd_export *exp,
514 struct obd_ioobj *obj, struct niobuf_remote *nb,
515 struct lustre_handle *lh)
518 int nrbufs = obj->ioo_bufcnt;
519 struct ldlm_res_id res_id = { .name = { obj->ioo_id } };
520 ldlm_policy_data_t policy;
525 LASSERT(mode == LCK_PR || mode == LCK_PW);
526 LASSERT(!lustre_handle_is_used(lh));
528 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
531 /* EXPENSIVE ASSERTION */
532 for (i = 1; i < nrbufs; i ++)
533 LASSERT((nb[0].flags & OBD_BRW_SRVLOCK) ==
534 (nb[i].flags & OBD_BRW_SRVLOCK));
536 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
537 policy.l_extent.end = (nb[nrbufs - 1].offset +
538 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
540 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, res_id,
541 LDLM_EXTENT, &policy, mode, &flags,
542 ldlm_blocking_ast, ldlm_completion_ast,
543 ldlm_glimpse_ast, NULL, 0, NULL, lh));
546 static void ost_brw_lock_put(int mode,
547 struct obd_ioobj *obj, struct niobuf_remote *niob,
548 struct lustre_handle *lh)
551 LASSERT(mode == LCK_PR || mode == LCK_PW);
552 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
553 lustre_handle_is_used(lh));
554 if (lustre_handle_is_used(lh))
555 ldlm_lock_decref(lh, mode);
559 struct ost_prolong_data {
560 struct obd_export *opd_exp;
561 ldlm_policy_data_t opd_policy;
562 ldlm_mode_t opd_mode;
565 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
567 struct ost_prolong_data *opd = data;
569 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
571 if (lock->l_req_mode != lock->l_granted_mode) {
572 /* scan granted locks only */
573 return LDLM_ITER_STOP;
576 if (lock->l_export != opd->opd_exp) {
577 /* prolong locks only for given client */
578 return LDLM_ITER_CONTINUE;
581 if (!(lock->l_granted_mode & opd->opd_mode)) {
582 /* we aren't interesting in all type of locks */
583 return LDLM_ITER_CONTINUE;
586 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
587 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
588 /* the request doesn't cross the lock, skip it */
589 return LDLM_ITER_CONTINUE;
592 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
593 /* ignore locks not being cancelled */
594 return LDLM_ITER_CONTINUE;
597 /* OK. this is a possible lock the user holds doing I/O
598 * let's refresh eviction timer for it */
599 ldlm_refresh_waiting_lock(lock);
601 return LDLM_ITER_CONTINUE;
604 static void ost_prolong_locks(struct obd_export *exp, struct obd_ioobj *obj,
605 struct niobuf_remote *nb, ldlm_mode_t mode)
607 struct ldlm_res_id res_id = { .name = { obj->ioo_id } };
608 int nrbufs = obj->ioo_bufcnt;
609 struct ost_prolong_data opd;
615 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
616 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
617 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
619 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
620 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
621 opd.opd_policy.l_extent.end);
622 ldlm_resource_iterate(exp->exp_obd->obd_namespace, &res_id,
623 ost_prolong_locks_iter, &opd);
626 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
628 struct ptlrpc_bulk_desc *desc;
629 struct niobuf_remote *remote_nb;
630 struct niobuf_remote *pp_rnb = NULL;
631 struct niobuf_local *local_nb;
632 struct obd_ioobj *ioo;
633 struct ost_body *body, *repbody;
634 struct l_wait_info lwi;
635 struct lustre_handle lockh = { 0 };
636 int size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
637 int comms_error = 0, niocount, npages, nob = 0, rc, i;
641 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
642 GOTO(out, rc = -EIO);
644 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
645 (obd_timeout + 1) / 4);
647 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
648 lustre_swab_ost_body);
650 CERROR("Missing/short ost_body\n");
651 GOTO(out, rc = -EFAULT);
654 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*ioo),
655 lustre_swab_obd_ioobj);
657 CERROR("Missing/short ioobj\n");
658 GOTO(out, rc = -EFAULT);
661 niocount = ioo->ioo_bufcnt;
662 if (niocount > PTLRPC_MAX_BRW_PAGES) {
663 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)\n",
665 GOTO(out, rc = -EFAULT);
668 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
669 niocount * sizeof(*remote_nb),
670 lustre_swab_niobuf_remote);
671 if (remote_nb == NULL) {
672 CERROR("Missing/short niobuf\n");
673 GOTO(out, rc = -EFAULT);
675 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
676 for (i = 1; i < niocount; i++)
677 lustre_swab_niobuf_remote (&remote_nb[i]);
680 rc = lustre_pack_reply(req, 2, size, NULL);
685 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
688 local_nb = ost_tls(req)->local;
689 pp_rnb = ost_tls(req)->remote;
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, 1, remote_nb, niocount, &pp_rnb);
695 GOTO(out, rc = npages);
697 LASSERT(npages <= OST_THREAD_POOL_SIZE);
699 ost_nio_pages_get(req, local_nb, npages);
701 desc = ptlrpc_prep_bulk_exp(req, npages,
702 BULK_PUT_SOURCE, OST_BULK_PORTAL);
704 GOTO(out, rc = -ENOMEM);
706 rc = ost_brw_lock_get(LCK_PR, req->rq_export, ioo, pp_rnb, &lockh);
711 * If getting the lock took more time than
712 * client was willing to wait, drop it. b=11330
714 if (cfs_time_current_sec() > req->rq_arrival_time.tv_sec + obd_timeout ||
715 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
717 CERROR("Dropping timed-out read from %s because locking"
718 "object "LPX64" took %ld seconds.\n",
719 libcfs_id2str(req->rq_peer), ioo->ioo_id,
720 cfs_time_current_sec() - req->rq_arrival_time.tv_sec);
724 rc = obd_preprw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
725 ioo, npages, pp_rnb, local_nb, oti);
729 ost_prolong_locks(req->rq_export, ioo, pp_rnb, LCK_PW | LCK_PR);
732 for (i = 0; i < npages; i++) {
733 int page_rc = local_nb[i].rc;
735 if (page_rc < 0) { /* error */
740 LASSERTF(page_rc <= pp_rnb[i].len, "page_rc (%d) > "
741 "pp_rnb[%d].len (%d)\n", page_rc, i, pp_rnb[i].len);
743 if (page_rc != 0) { /* some data! */
744 LASSERT (local_nb[i].page != NULL);
745 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
746 pp_rnb[i].offset & ~CFS_PAGE_MASK,
750 if (page_rc != pp_rnb[i].len) { /* short read */
751 /* All subsequent pages should be 0 */
753 LASSERT(local_nb[i].rc == 0);
758 if (unlikely(body->oa.o_valid & OBD_MD_FLCKSUM)) {
759 body->oa.o_cksum = ost_checksum_bulk(desc);
760 body->oa.o_valid = OBD_MD_FLCKSUM;
761 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
763 body->oa.o_valid = 0;
765 /* We're finishing using body->oa as an input variable */
767 /* Check if client was evicted while we were doing i/o before touching
770 if (desc->bd_export->exp_failed)
773 rc = ptlrpc_start_bulk_transfer(desc);
775 lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 4, HZ,
776 ost_bulk_timeout, desc);
777 rc = l_wait_event(desc->bd_waitq,
778 !ptlrpc_bulk_active(desc) ||
779 desc->bd_export->exp_failed, &lwi);
780 LASSERT(rc == 0 || rc == -ETIMEDOUT);
781 if (rc == -ETIMEDOUT) {
782 DEBUG_REQ(D_ERROR, req, "timeout on bulk PUT");
783 ptlrpc_abort_bulk(desc);
784 } else if (desc->bd_export->exp_failed) {
785 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
787 ptlrpc_abort_bulk(desc);
788 } else if (!desc->bd_success ||
789 desc->bd_nob_transferred != desc->bd_nob) {
790 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
792 "truncated" : "network error on",
793 desc->bd_nob_transferred,
795 /* XXX should this be a different errno? */
799 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d\n", rc);
801 comms_error = rc != 0;
804 /* Must commit after prep above in all cases */
805 rc = obd_commitrw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
806 ioo, npages, local_nb, oti, rc);
808 ost_nio_pages_put(req, local_nb, npages);
811 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
813 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
817 ost_brw_lock_put(LCK_PR, ioo, pp_rnb, &lockh);
819 ptlrpc_free_bulk(desc);
825 req->rq_status = nob;
826 target_committed_to_req(req);
828 } else if (!comms_error) {
829 /* Only reply if there was no comms problem with bulk */
830 target_committed_to_req(req);
834 if (req->rq_reply_state != NULL) {
835 /* reply out callback would free */
836 ptlrpc_rs_decref(req->rq_reply_state);
837 req->rq_reply_state = NULL;
839 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
840 "client will retry\n",
841 req->rq_export->exp_obd->obd_name,
842 req->rq_export->exp_client_uuid.uuid,
843 req->rq_export->exp_connection->c_remote_uuid.uuid,
844 libcfs_id2str(req->rq_peer));
850 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
852 struct ptlrpc_bulk_desc *desc;
853 struct niobuf_remote *remote_nb;
854 struct niobuf_remote *pp_rnb;
855 struct niobuf_local *local_nb;
856 struct obd_ioobj *ioo;
857 struct ost_body *body, *repbody;
858 struct l_wait_info lwi;
859 struct lustre_handle lockh = {0};
861 int size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
862 int objcount, niocount, npages, comms_error = 0;
864 obd_count client_cksum, server_cksum = 0;
868 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
869 GOTO(out, rc = -EIO);
871 /* pause before transaction has been started */
872 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
873 (obd_timeout + 1) / 4);
875 swab = lustre_msg_swabbed(req->rq_reqmsg);
876 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
877 lustre_swab_ost_body);
879 CERROR("Missing/short ost_body\n");
880 GOTO(out, rc = -EFAULT);
883 LASSERT_REQSWAB(req, REQ_REC_OFF + 1);
884 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
887 CERROR("Missing/short ioobj\n");
888 GOTO(out, rc = -EFAULT);
891 CERROR("too many ioobjs (%d)\n", objcount);
892 GOTO(out, rc = -EFAULT);
895 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
896 objcount * sizeof(*ioo));
897 LASSERT (ioo != NULL);
898 for (niocount = i = 0; i < objcount; i++) {
900 lustre_swab_obd_ioobj(&ioo[i]);
901 if (ioo[i].ioo_bufcnt == 0) {
902 CERROR("ioo[%d] has zero bufcnt\n", i);
903 GOTO(out, rc = -EFAULT);
905 niocount += ioo[i].ioo_bufcnt;
908 if (niocount > PTLRPC_MAX_BRW_PAGES) {
909 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)\n",
911 GOTO(out, rc = -EFAULT);
914 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
915 niocount * sizeof(*remote_nb),
916 lustre_swab_niobuf_remote);
917 if (remote_nb == NULL) {
918 CERROR("Missing/short niobuf\n");
919 GOTO(out, rc = -EFAULT);
921 if (swab) { /* swab the remaining niobufs */
922 for (i = 1; i < niocount; i++)
923 lustre_swab_niobuf_remote (&remote_nb[i]);
926 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
927 rc = lustre_pack_reply(req, 3, size, NULL);
930 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
931 niocount * sizeof(*rcs));
934 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
937 local_nb = ost_tls(req)->local;
938 pp_rnb = ost_tls(req)->remote;
940 /* FIXME all niobuf splitting should be done in obdfilter if needed */
941 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
942 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
944 GOTO(out, rc = npages);
946 LASSERT(npages <= OST_THREAD_POOL_SIZE);
948 ost_nio_pages_get(req, local_nb, npages);
950 desc = ptlrpc_prep_bulk_exp(req, npages,
951 BULK_GET_SINK, OST_BULK_PORTAL);
953 GOTO(out, rc = -ENOMEM);
955 rc = ost_brw_lock_get(LCK_PW, req->rq_export, ioo, pp_rnb, &lockh);
960 * If getting the lock took more time than
961 * client was willing to wait, drop it. b=11330
963 if (cfs_time_current_sec() > req->rq_arrival_time.tv_sec + obd_timeout ||
964 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
966 CERROR("Dropping timed-out write from %s because locking"
967 "object "LPX64" took %ld seconds.\n",
968 libcfs_id2str(req->rq_peer), ioo->ioo_id,
969 cfs_time_current_sec() - req->rq_arrival_time.tv_sec);
973 ost_prolong_locks(req->rq_export, ioo, pp_rnb, LCK_PW);
975 /* obd_preprw clobbers oa->valid, so save what we need */
976 client_cksum = body->oa.o_valid & OBD_MD_FLCKSUM ? body->oa.o_cksum : 0;
978 rc = obd_preprw(OBD_BRW_WRITE, req->rq_export, &body->oa, objcount,
979 ioo, npages, pp_rnb, local_nb, oti);
983 /* NB Having prepped, we must commit... */
985 for (i = 0; i < npages; i++)
986 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
987 pp_rnb[i].offset & ~CFS_PAGE_MASK,
990 /* Check if client was evicted while we were doing i/o before touching
992 if (desc->bd_export->exp_failed)
995 rc = ptlrpc_start_bulk_transfer (desc);
997 lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 2, HZ,
998 ost_bulk_timeout, desc);
999 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1000 desc->bd_export->exp_failed, &lwi);
1001 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1002 if (rc == -ETIMEDOUT) {
1003 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1004 ptlrpc_abort_bulk(desc);
1005 } else if (desc->bd_export->exp_failed) {
1006 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1008 ptlrpc_abort_bulk(desc);
1009 } else if (!desc->bd_success ||
1010 desc->bd_nob_transferred != desc->bd_nob) {
1011 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1013 "truncated" : "network error on",
1014 desc->bd_nob_transferred, desc->bd_nob);
1015 /* XXX should this be a different errno? */
1019 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d\n", rc);
1021 comms_error = rc != 0;
1023 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1025 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1027 if (unlikely(client_cksum != 0 && rc == 0)) {
1028 static int cksum_counter;
1030 server_cksum = ost_checksum_bulk(desc);
1031 repbody->oa.o_valid |= OBD_MD_FLCKSUM;
1032 repbody->oa.o_cksum = server_cksum;
1034 if (unlikely(client_cksum != server_cksum)) {
1035 CERROR("client csum %x, server csum %x\n",
1036 client_cksum, server_cksum);
1038 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1039 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1040 cksum_counter, libcfs_id2str(req->rq_peer),
1045 /* Must commit after prep above in all cases */
1046 rc = obd_commitrw(OBD_BRW_WRITE, req->rq_export, &repbody->oa,
1047 objcount, ioo, npages, local_nb, oti, rc);
1049 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1050 int new_cksum = ost_checksum_bulk(desc);
1055 if (new_cksum == server_cksum)
1056 msg = "changed in transit before arrival at OST";
1057 else if (new_cksum == client_cksum)
1058 msg = "initial checksum before message complete";
1060 msg = "changed in transit AND after initial checksum";
1062 if (req->rq_peer.nid == desc->bd_sender) {
1066 router = libcfs_nid2str(desc->bd_sender);
1069 LCONSOLE_ERROR("%s: BAD WRITE CHECKSUM: %s from %s%s%s inum "
1070 LPU64"/"LPU64" object "LPU64"/"LPU64
1071 " extent ["LPU64"-"LPU64"]\n",
1072 req->rq_export->exp_obd->obd_name, msg,
1073 libcfs_id2str(req->rq_peer),
1075 body->oa.o_valid & OBD_MD_FLFID ?
1076 body->oa.o_fid : (__u64)0,
1077 body->oa.o_valid & OBD_MD_FLFID ?
1078 body->oa.o_generation :(__u64)0,
1080 body->oa.o_valid & OBD_MD_FLGROUP ?
1081 body->oa.o_gr : (__u64)0,
1083 pp_rnb[npages-1].offset+pp_rnb[npages-1].len-1);
1084 CERROR("client csum %x, original server csum %x, "
1085 "server csum now %x\n",
1086 client_cksum, server_cksum, new_cksum);
1089 ost_nio_pages_put(req, local_nb, npages);
1092 /* set per-requested niobuf return codes */
1093 for (i = j = 0; i < niocount; i++) {
1094 int nob = remote_nb[i].len;
1098 LASSERT(j < npages);
1099 if (local_nb[j].rc < 0)
1100 rcs[i] = local_nb[j].rc;
1101 nob -= pp_rnb[j].len;
1106 LASSERT(j == npages);
1110 ost_brw_lock_put(LCK_PW, ioo, pp_rnb, &lockh);
1112 ptlrpc_free_bulk(desc);
1117 oti_to_request(oti, req);
1118 target_committed_to_req(req);
1119 rc = ptlrpc_reply(req);
1120 } else if (!comms_error) {
1121 /* Only reply if there was no comms problem with bulk */
1122 target_committed_to_req(req);
1123 req->rq_status = rc;
1126 if (req->rq_reply_state != NULL) {
1127 /* reply out callback would free */
1128 ptlrpc_rs_decref(req->rq_reply_state);
1129 req->rq_reply_state = NULL;
1131 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1132 "client will retry\n",
1133 req->rq_export->exp_obd->obd_name,
1134 req->rq_export->exp_client_uuid.uuid,
1135 req->rq_export->exp_connection->c_remote_uuid.uuid,
1136 libcfs_id2str(req->rq_peer));
1141 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1143 char *key, *val = NULL;
1144 int keylen, vallen, rc = 0;
1147 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1149 DEBUG_REQ(D_HA, req, "no set_info key");
1152 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1154 rc = lustre_pack_reply(req, 1, NULL, NULL);
1158 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1160 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
1162 if (KEY_IS("evict_by_nid")) {
1164 obd_export_evict_by_nid(exp->exp_obd, val);
1169 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1171 lustre_msg_set_status(req->rq_repmsg, 0);
1175 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1179 int size[2] = { sizeof(struct ptlrpc_body), sizeof(obd_id) };
1183 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1185 DEBUG_REQ(D_HA, req, "no get_info key");
1188 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1190 if (keylen < strlen("last_id") || memcmp(key, "last_id", 7) != 0)
1193 rc = lustre_pack_reply(req, 2, size, NULL);
1197 reply = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*reply));
1198 rc = obd_get_info(exp, keylen, key, size, reply);
1199 lustre_msg_set_status(req->rq_repmsg, 0);
1203 static int ost_handle_quotactl(struct ptlrpc_request *req)
1205 struct obd_quotactl *oqctl, *repoqc;
1206 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) };
1209 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1210 lustre_swab_obd_quotactl);
1212 GOTO(out, rc = -EPROTO);
1214 rc = lustre_pack_reply(req, 2, size, NULL);
1218 repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc));
1220 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1226 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1228 struct obd_quotactl *oqctl;
1232 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1233 lustre_swab_obd_quotactl);
1237 rc = lustre_pack_reply(req, 1, NULL, NULL);
1239 CERROR("ost: out of memory while packing quotacheck reply\n");
1243 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1247 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1248 struct obd_device *obd, int *process)
1250 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1251 case OST_CONNECT: /* This will never get here, but for completeness. */
1252 case OST_DISCONNECT:
1263 case OBD_LOG_CANCEL:
1265 *process = target_queue_recovery_request(req, obd);
1269 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1271 /* XXX what should we set rq_status to here? */
1272 req->rq_status = -EAGAIN;
1273 RETURN(ptlrpc_error(req));
1277 int ost_msg_check_version(struct lustre_msg *msg)
1281 switch(lustre_msg_get_opc(msg)) {
1283 case OST_DISCONNECT:
1285 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1287 CERROR("bad opc %u version %08x, expecting %08x\n",
1288 lustre_msg_get_opc(msg),
1289 lustre_msg_get_version(msg),
1290 LUSTRE_OBD_VERSION);
1303 case OST_QUOTACHECK:
1305 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1307 CERROR("bad opc %u version %08x, expecting %08x\n",
1308 lustre_msg_get_opc(msg),
1309 lustre_msg_get_version(msg),
1310 LUSTRE_OST_VERSION);
1315 case LDLM_BL_CALLBACK:
1316 case LDLM_CP_CALLBACK:
1317 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1319 CERROR("bad opc %u version %08x, expecting %08x\n",
1320 lustre_msg_get_opc(msg),
1321 lustre_msg_get_version(msg),
1322 LUSTRE_DLM_VERSION);
1324 case LLOG_ORIGIN_CONNECT:
1325 case OBD_LOG_CANCEL:
1326 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1328 CERROR("bad opc %u version %08x, expecting %08x\n",
1329 lustre_msg_get_opc(msg),
1330 lustre_msg_get_version(msg),
1331 LUSTRE_LOG_VERSION);
1334 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1340 static int ost_handle(struct ptlrpc_request *req)
1342 struct obd_trans_info trans_info = { 0, };
1343 struct obd_trans_info *oti = &trans_info;
1344 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1345 struct obd_device *obd = NULL;
1348 LASSERT(current->journal_info == NULL);
1349 /* XXX identical to MDS */
1350 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1351 int abort_recovery, recovering;
1353 if (req->rq_export == NULL) {
1354 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1355 lustre_msg_get_opc(req->rq_reqmsg),
1356 libcfs_id2str(req->rq_peer));
1357 req->rq_status = -ENOTCONN;
1358 GOTO(out, rc = -ENOTCONN);
1361 obd = req->rq_export->exp_obd;
1363 /* Check for aborted recovery. */
1364 spin_lock_bh(&obd->obd_processing_task_lock);
1365 abort_recovery = obd->obd_abort_recovery;
1366 recovering = obd->obd_recovering;
1367 spin_unlock_bh(&obd->obd_processing_task_lock);
1368 if (abort_recovery) {
1369 target_abort_recovery(obd);
1370 } else if (recovering) {
1371 rc = ost_filter_recovery_request(req, obd,
1373 if (rc || !should_process)
1379 rc = ost_msg_check_version(req->rq_reqmsg);
1383 rc = ost_msg_check_version(req->rq_reqmsg);
1387 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1389 CDEBUG(D_INODE, "connect\n");
1390 OBD_FAIL_RETURN(OBD_FAIL_OST_CONNECT_NET, 0);
1391 rc = target_handle_connect(req, ost_handle);
1393 obd = req->rq_export->exp_obd;
1396 case OST_DISCONNECT:
1397 CDEBUG(D_INODE, "disconnect\n");
1398 OBD_FAIL_RETURN(OBD_FAIL_OST_DISCONNECT_NET, 0);
1399 rc = target_handle_disconnect(req);
1402 CDEBUG(D_INODE, "create\n");
1403 OBD_FAIL_RETURN(OBD_FAIL_OST_CREATE_NET, 0);
1404 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
1405 GOTO(out, rc = -ENOSPC);
1406 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1407 GOTO(out, rc = -EROFS);
1408 rc = ost_create(req->rq_export, req, oti);
1411 CDEBUG(D_INODE, "destroy\n");
1412 OBD_FAIL_RETURN(OBD_FAIL_OST_DESTROY_NET, 0);
1413 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1414 GOTO(out, rc = -EROFS);
1415 rc = ost_destroy(req->rq_export, req, oti);
1418 CDEBUG(D_INODE, "getattr\n");
1419 OBD_FAIL_RETURN(OBD_FAIL_OST_GETATTR_NET, 0);
1420 rc = ost_getattr(req->rq_export, req);
1423 CDEBUG(D_INODE, "setattr\n");
1424 OBD_FAIL_RETURN(OBD_FAIL_OST_SETATTR_NET, 0);
1425 rc = ost_setattr(req->rq_export, req, oti);
1428 CDEBUG(D_INODE, "write\n");
1429 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1430 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
1431 GOTO(out, rc = -ENOSPC);
1432 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1433 GOTO(out, rc = -EROFS);
1434 rc = ost_brw_write(req, oti);
1435 LASSERT(current->journal_info == NULL);
1436 /* ost_brw_write sends its own replies */
1439 CDEBUG(D_INODE, "read\n");
1440 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1441 rc = ost_brw_read(req, oti);
1442 LASSERT(current->journal_info == NULL);
1443 /* ost_brw_read sends its own replies */
1446 CDEBUG(D_INODE, "punch\n");
1447 OBD_FAIL_RETURN(OBD_FAIL_OST_PUNCH_NET, 0);
1448 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1449 GOTO(out, rc = -EROFS);
1450 rc = ost_punch(req->rq_export, req, oti);
1453 CDEBUG(D_INODE, "statfs\n");
1454 OBD_FAIL_RETURN(OBD_FAIL_OST_STATFS_NET, 0);
1455 rc = ost_statfs(req);
1458 CDEBUG(D_INODE, "sync\n");
1459 OBD_FAIL_RETURN(OBD_FAIL_OST_SYNC_NET, 0);
1460 rc = ost_sync(req->rq_export, req);
1463 DEBUG_REQ(D_INODE, req, "set_info");
1464 rc = ost_set_info(req->rq_export, req);
1467 DEBUG_REQ(D_INODE, req, "get_info");
1468 rc = ost_get_info(req->rq_export, req);
1470 case OST_QUOTACHECK:
1471 CDEBUG(D_INODE, "quotacheck\n");
1472 OBD_FAIL_RETURN(OBD_FAIL_OST_QUOTACHECK_NET, 0);
1473 rc = ost_handle_quotacheck(req);
1476 CDEBUG(D_INODE, "quotactl\n");
1477 OBD_FAIL_RETURN(OBD_FAIL_OST_QUOTACTL_NET, 0);
1478 rc = ost_handle_quotactl(req);
1481 DEBUG_REQ(D_INODE, req, "ping");
1482 rc = target_handle_ping(req);
1484 /* FIXME - just reply status */
1485 case LLOG_ORIGIN_CONNECT:
1486 DEBUG_REQ(D_INODE, req, "log connect\n");
1487 rc = llog_handle_connect(req);
1488 req->rq_status = rc;
1489 rc = lustre_pack_reply(req, 1, NULL, NULL);
1492 RETURN(ptlrpc_reply(req));
1493 case OBD_LOG_CANCEL:
1494 CDEBUG(D_INODE, "log cancel\n");
1495 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
1496 rc = llog_origin_handle_cancel(req);
1497 req->rq_status = rc;
1498 rc = lustre_pack_reply(req, 1, NULL, NULL);
1501 RETURN(ptlrpc_reply(req));
1503 CDEBUG(D_INODE, "enqueue\n");
1504 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
1505 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1506 ldlm_server_blocking_ast,
1507 ldlm_server_glimpse_ast);
1508 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1511 CDEBUG(D_INODE, "convert\n");
1512 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
1513 rc = ldlm_handle_convert(req);
1516 CDEBUG(D_INODE, "cancel\n");
1517 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CANCEL, 0);
1518 rc = ldlm_handle_cancel(req);
1520 case LDLM_BL_CALLBACK:
1521 case LDLM_CP_CALLBACK:
1522 CDEBUG(D_INODE, "callback\n");
1523 CERROR("callbacks should not happen on OST\n");
1526 CERROR("Unexpected opcode %d\n",
1527 lustre_msg_get_opc(req->rq_reqmsg));
1528 req->rq_status = -ENOTSUPP;
1529 rc = ptlrpc_error(req);
1533 LASSERT(current->journal_info == NULL);
1536 /* If we're DISCONNECTing, the export_data is already freed */
1537 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
1538 target_committed_to_req(req);
1541 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LAST_REPLAY) {
1542 if (obd && obd->obd_recovering) {
1543 DEBUG_REQ(D_HA, req, "LAST_REPLAY, queuing reply");
1544 return target_queue_final_reply(req, rc);
1546 /* Lost a race with recovery; let the error path DTRT. */
1547 rc = req->rq_status = -ENOTCONN;
1551 oti_to_request(oti, req);
1553 target_send_reply(req, rc, fail);
1558 * free per-thread pool created by ost_thread_init().
1560 static void ost_thread_done(struct ptlrpc_thread *thread)
1563 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
1568 LASSERT(thread != NULL);
1571 * be prepared to handle partially-initialized pools (because this is
1572 * called from ost_thread_init() for cleanup.
1574 tls = thread->t_data;
1576 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1577 if (tls->page[i] != NULL)
1578 __free_page(tls->page[i]);
1581 thread->t_data = NULL;
1587 * initialize per-thread page pool (bug 5137).
1589 static int ost_thread_init(struct ptlrpc_thread *thread)
1593 struct ost_thread_local_cache *tls;
1597 LASSERT(thread != NULL);
1598 LASSERT(thread->t_data == NULL);
1599 LASSERT(thread->t_id <= OSS_THREADS_MAX);
1604 thread->t_data = tls;
1608 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1609 tls->page[i] = alloc_page(OST_THREAD_POOL_GFP);
1610 if (tls->page[i] == NULL) {
1611 ost_thread_done(thread);
1621 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
1622 static int ost_setup(struct obd_device *obd, obd_count len, void *buf)
1624 struct ost_obd *ost = &obd->u.ost;
1625 struct lprocfs_static_vars lvars;
1626 int oss_min_threads;
1627 int oss_max_threads;
1631 rc = cleanup_group_info();
1635 rc = llog_start_commit_thread();
1639 lprocfs_init_vars(ost, &lvars);
1640 lprocfs_obd_setup(obd, lvars.obd_vars);
1642 sema_init(&ost->ost_health_sem, 1);
1644 if (oss_num_threads) {
1645 /* If oss_num_threads is set, it is the min and the max. */
1646 if (oss_num_threads > OSS_THREADS_MAX)
1647 oss_num_threads = OSS_THREADS_MAX;
1648 if (oss_num_threads < OSS_THREADS_MIN)
1649 oss_num_threads = OSS_THREADS_MIN;
1650 oss_max_threads = oss_min_threads = oss_num_threads;
1652 /* Base min threads on memory and cpus */
1653 oss_min_threads = smp_num_cpus * num_physpages >>
1654 (27 - CFS_PAGE_SHIFT);
1655 if (oss_min_threads < OSS_THREADS_MIN)
1656 oss_min_threads = OSS_THREADS_MIN;
1657 /* Insure a 4x range for dynamic threads */
1658 if (oss_min_threads > OSS_THREADS_MAX / 4)
1659 oss_min_threads = OSS_THREADS_MAX / 4;
1660 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4);
1664 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1665 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
1667 obd_timeout * 1000, ost_handle, LUSTRE_OSS_NAME,
1668 obd->obd_proc_entry, ost_print_req,
1669 oss_min_threads, oss_max_threads, "ll_ost");
1670 if (ost->ost_service == NULL) {
1671 CERROR("failed to start OST service\n");
1672 GOTO(out_lprocfs, rc = -ENOMEM);
1675 rc = ptlrpc_start_threads(obd, ost->ost_service);
1677 GOTO(out_service, rc = -EINVAL);
1679 ost->ost_create_service =
1680 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1681 OST_MAXREPSIZE, OST_CREATE_PORTAL,
1683 obd_timeout * 1000, ost_handle, "ost_create",
1684 obd->obd_proc_entry, ost_print_req,
1685 1, 1, "ll_ost_creat");
1686 if (ost->ost_create_service == NULL) {
1687 CERROR("failed to start OST create service\n");
1688 GOTO(out_service, rc = -ENOMEM);
1691 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
1693 GOTO(out_create, rc = -EINVAL);
1695 ost->ost_io_service =
1696 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1697 OST_MAXREPSIZE, OST_IO_PORTAL,
1699 obd_timeout * 1000, ost_handle, "ost_io",
1700 obd->obd_proc_entry, ost_print_req,
1701 oss_min_threads, oss_max_threads, "ll_ost_io");
1702 if (ost->ost_io_service == NULL) {
1703 CERROR("failed to start OST I/O service\n");
1704 GOTO(out_create, rc = -ENOMEM);
1707 ost->ost_io_service->srv_init = ost_thread_init;
1708 ost->ost_io_service->srv_done = ost_thread_done;
1709 ost->ost_io_service->srv_cpu_affinity = 1;
1710 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
1712 GOTO(out_io, rc = -EINVAL);
1714 ping_evictor_start();
1719 ptlrpc_unregister_service(ost->ost_io_service);
1720 ost->ost_io_service = NULL;
1722 ptlrpc_unregister_service(ost->ost_create_service);
1723 ost->ost_create_service = NULL;
1725 ptlrpc_unregister_service(ost->ost_service);
1726 ost->ost_service = NULL;
1728 lprocfs_obd_cleanup(obd);
1732 static int ost_cleanup(struct obd_device *obd)
1734 struct ost_obd *ost = &obd->u.ost;
1738 ping_evictor_stop();
1740 spin_lock_bh(&obd->obd_processing_task_lock);
1741 if (obd->obd_recovering) {
1742 target_cancel_recovery_timer(obd);
1743 obd->obd_recovering = 0;
1745 spin_unlock_bh(&obd->obd_processing_task_lock);
1747 down(&ost->ost_health_sem);
1748 ptlrpc_unregister_service(ost->ost_service);
1749 ptlrpc_unregister_service(ost->ost_create_service);
1750 ptlrpc_unregister_service(ost->ost_io_service);
1751 ost->ost_service = NULL;
1752 ost->ost_create_service = NULL;
1753 up(&ost->ost_health_sem);
1755 lprocfs_obd_cleanup(obd);
1760 static int ost_health_check(struct obd_device *obd)
1762 struct ost_obd *ost = &obd->u.ost;
1765 down(&ost->ost_health_sem);
1766 rc |= ptlrpc_service_health_check(ost->ost_service);
1767 rc |= ptlrpc_service_health_check(ost->ost_create_service);
1768 rc |= ptlrpc_service_health_check(ost->ost_io_service);
1769 up(&ost->ost_health_sem);
1772 * health_check to return 0 on healthy
1773 * and 1 on unhealthy.
1781 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
1783 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
1786 /* use obd ops to offer management infrastructure */
1787 static struct obd_ops ost_obd_ops = {
1788 .o_owner = THIS_MODULE,
1789 .o_setup = ost_setup,
1790 .o_cleanup = ost_cleanup,
1791 .o_health_check = ost_health_check,
1795 static int __init ost_init(void)
1797 struct lprocfs_static_vars lvars;
1801 lprocfs_init_vars(ost, &lvars);
1802 rc = class_register_type(&ost_obd_ops, lvars.module_vars,
1807 static void /*__exit*/ ost_exit(void)
1809 class_unregister_type(LUSTRE_OSS_NAME);
1812 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1813 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
1814 MODULE_LICENSE("GPL");
1816 module_init(ost_init);
1817 module_exit(ost_exit);