1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ost/ost_handler.c
38 * Author: Peter J. Braam <braam@clusterfs.com>
39 * Author: Phil Schwan <phil@clusterfs.com>
43 # define EXPORT_SYMTAB
45 #define DEBUG_SUBSYSTEM S_OST
47 #include <linux/module.h>
48 #include <obd_cksum.h>
50 #include <lustre_net.h>
51 #include <lustre_dlm.h>
52 #include <lustre_export.h>
53 #include <lustre_debug.h>
54 #include <linux/init.h>
55 #include <lprocfs_status.h>
56 #include <libcfs/list.h>
57 #include <lustre_quota.h>
58 #include "ost_internal.h"
60 static int oss_num_threads;
61 CFS_MODULE_PARM(oss_num_threads, "i", int, 0444,
62 "number of OSS service threads to start");
64 static int ost_num_threads;
65 CFS_MODULE_PARM(ost_num_threads, "i", int, 0444,
66 "number of OST service threads to start (deprecated)");
68 static int oss_num_create_threads;
69 CFS_MODULE_PARM(oss_num_create_threads, "i", int, 0444,
70 "number of OSS create threads to start");
72 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
74 struct oti_req_ack_lock *ack_lock;
81 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
82 req->rq_transno = oti->oti_transno;
84 /* XXX 4 == entries in oti_ack_locks??? */
85 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
88 /* XXX not even calling target_send_reply in some cases... */
89 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode);
93 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
94 struct obd_trans_info *oti)
96 struct ost_body *body, *repbody;
97 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
101 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
102 lustre_swab_ost_body);
106 if (body->oa.o_id == 0)
109 if (lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1)) {
110 struct ldlm_request *dlm;
111 dlm = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*dlm),
112 lustre_swab_ldlm_request);
115 ldlm_request_cancel(req, dlm, 0);
118 rc = lustre_pack_reply(req, 2, size, NULL);
122 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
123 oti->oti_logcookies = &body->oa.o_lcookie;
124 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
126 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
127 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL);
131 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
133 struct ost_body *body, *repbody;
134 struct obd_info oinfo = { { { 0 } } };
135 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
139 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
140 lustre_swab_ost_body);
144 rc = lustre_pack_reply(req, 2, size, NULL);
148 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
150 repbody->oa = body->oa;
152 oinfo.oi_oa = &repbody->oa;
153 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
154 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
156 req->rq_status = obd_getattr(exp, &oinfo);
160 static int ost_statfs(struct ptlrpc_request *req)
162 struct obd_statfs *osfs;
163 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*osfs) };
167 rc = lustre_pack_reply(req, 2, size, NULL);
171 osfs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*osfs));
173 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
174 cfs_time_current_64() - HZ, 0);
175 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
176 osfs->os_bfree = osfs->os_bavail = 64;
177 if (req->rq_status != 0)
178 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
183 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
184 struct obd_trans_info *oti)
186 struct ost_body *body, *repbody;
187 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
191 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
192 lustre_swab_ost_body);
196 rc = lustre_pack_reply(req, 2, size, NULL);
200 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
202 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
203 oti->oti_logcookies = &repbody->oa.o_lcookie;
204 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
205 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
210 * Helper function for ost_punch(): if asked by client, acquire [size, EOF]
211 * lock on the file being truncated.
213 static int ost_punch_lock_get(struct obd_export *exp, struct obdo *oa,
214 struct lustre_handle *lh)
217 struct ldlm_res_id res_id;
218 ldlm_policy_data_t policy;
224 osc_build_res_name(oa->o_id, oa->o_gr, &res_id);
225 LASSERT(!lustre_handle_is_used(lh));
227 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
228 !(oa->o_flags & OBD_FL_TRUNCLOCK))
231 CDEBUG(D_INODE, "OST-side truncate lock.\n");
234 finis = start + oa->o_blocks;
237 * standard truncate optimization: if file body is completely
238 * destroyed, don't send data back to the server.
240 flags = (start == 0) ? LDLM_AST_DISCARD_DATA : 0;
242 policy.l_extent.start = start & CFS_PAGE_MASK;
245 * If ->o_blocks is EOF it means "lock till the end of the
246 * file". Otherwise, it's size of a hole being punched (in bytes)
248 if (oa->o_blocks == OBD_OBJECT_EOF || finis < start)
249 policy.l_extent.end = OBD_OBJECT_EOF;
251 policy.l_extent.end = finis | ~CFS_PAGE_MASK;
253 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
254 LDLM_EXTENT, &policy, LCK_PW, &flags,
255 ldlm_blocking_ast, ldlm_completion_ast,
256 ldlm_glimpse_ast, NULL, 0, NULL, lh));
260 * Helper function for ost_punch(): release lock acquired by
261 * ost_punch_lock_get(), if any.
263 static void ost_punch_lock_put(struct obd_export *exp, struct obdo *oa,
264 struct lustre_handle *lh)
267 if (lustre_handle_is_used(lh))
268 ldlm_lock_decref(lh, LCK_PW);
272 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
273 struct obd_trans_info *oti)
275 struct obd_info oinfo = { { { 0 } } };
276 struct ost_body *body, *repbody;
277 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
279 struct lustre_handle lh = {0,};
282 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
283 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
285 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
286 lustre_swab_ost_body);
290 oinfo.oi_oa = &body->oa;
291 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
292 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
294 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
295 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
298 rc = lustre_pack_reply(req, 2, size, NULL);
302 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
304 rc = ost_punch_lock_get(exp, oinfo.oi_oa, &lh);
306 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
307 oinfo.oi_oa->o_flags == OBD_FL_TRUNCLOCK)
309 * If OBD_FL_TRUNCLOCK is the only bit set in
310 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
311 * through filter_setattr() to filter_iocontrol().
313 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
315 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
316 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
318 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
319 ost_punch_lock_put(exp, oinfo.oi_oa, &lh);
321 repbody->oa = *oinfo.oi_oa;
325 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
327 struct ost_body *body, *repbody;
328 struct lustre_capa *capa = NULL;
329 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
333 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
334 lustre_swab_ost_body);
338 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
339 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 1);
341 rc = lustre_pack_reply(req, 2, size, NULL);
345 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
347 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
348 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
349 repbody->oa.o_blocks, capa);
353 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
354 struct obd_trans_info *oti)
356 struct ost_body *body, *repbody;
357 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
359 struct obd_info oinfo = { { { 0 } } };
362 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
363 lustre_swab_ost_body);
367 rc = lustre_pack_reply(req, 2, size, NULL);
371 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
373 repbody->oa = body->oa;
375 oinfo.oi_oa = &repbody->oa;
376 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
377 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
379 req->rq_status = obd_setattr(exp, &oinfo, oti);
383 static int ost_bulk_timeout(void *data)
386 /* We don't fail the connection here, because having the export
387 * killed makes the (vital) call to commitrw very sad.
392 static int get_per_page_niobufs(struct obd_ioobj *ioo, int nioo,
393 struct niobuf_remote *rnb, int nrnb,
394 struct niobuf_remote **pp_rnbp)
396 /* Copy a remote niobuf, splitting it into page-sized chunks
397 * and setting ioo[i].ioo_bufcnt accordingly */
398 struct niobuf_remote *pp_rnb;
406 * array of sufficient size already preallocated by caller
408 LASSERT(pp_rnbp != NULL);
409 LASSERT(*pp_rnbp != NULL);
411 /* first count and check the number of pages required */
412 for (i = 0; i < nioo; i++)
413 for (j = 0; j < ioo->ioo_bufcnt; j++, rnbidx++) {
414 obd_off offset = rnb[rnbidx].offset;
415 obd_off p0 = offset >> CFS_PAGE_SHIFT;
416 obd_off pn = (offset + rnb[rnbidx].len - 1) >>
419 LASSERT(rnbidx < nrnb);
421 npages += (pn + 1 - p0);
423 if (rnb[rnbidx].len == 0) {
424 CERROR("zero len BRW: obj %d objid "LPX64
425 " buf %u\n", i, ioo[i].ioo_id, j);
429 rnb[rnbidx].offset <= rnb[rnbidx-1].offset) {
430 CERROR("unordered BRW: obj %d objid "LPX64
431 " buf %u offset "LPX64" <= "LPX64"\n",
432 i, ioo[i].ioo_id, j, rnb[rnbidx].offset,
438 LASSERT(rnbidx == nrnb);
440 if (npages == nrnb) { /* all niobufs are for single pages */
447 /* now do the actual split */
449 for (i = 0; i < nioo; i++) {
452 for (j = 0; j < ioo[i].ioo_bufcnt; j++, rnbidx++) {
453 obd_off off = rnb[rnbidx].offset;
454 int nob = rnb[rnbidx].len;
456 LASSERT(rnbidx < nrnb);
458 obd_off poff = off & ~CFS_PAGE_MASK;
459 int pnob = (poff + nob > CFS_PAGE_SIZE) ?
460 CFS_PAGE_SIZE - poff : nob;
462 LASSERT(page < npages);
463 pp_rnb[page].len = pnob;
464 pp_rnb[page].offset = off;
465 pp_rnb[page].flags = rnb[rnbidx].flags;
467 CDEBUG(0, " obj %d id "LPX64
468 "page %d(%d) "LPX64" for %d, flg %x\n",
469 i, ioo[i].ioo_id, obj_pages, page,
470 pp_rnb[page].offset, pp_rnb[page].len,
480 ioo[i].ioo_bufcnt = obj_pages;
482 LASSERT(page == npages);
487 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
488 cksum_type_t cksum_type)
493 cksum = init_checksum(cksum_type);
494 for (i = 0; i < desc->bd_iov_count; i++) {
495 struct page *page = desc->bd_iov[i].kiov_page;
496 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
497 char *ptr = kmap(page) + off;
498 int len = desc->bd_iov[i].kiov_len;
500 /* corrupt the data before we compute the checksum, to
501 * simulate a client->OST data error */
502 if (i == 0 && opc == OST_WRITE &&
503 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
504 memcpy(ptr, "bad3", min(4, len));
505 cksum = compute_checksum(cksum, ptr, len, cksum_type);
506 /* corrupt the data after we compute the checksum, to
507 * simulate an OST->client data error */
508 if (i == 0 && opc == OST_READ &&
509 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND))
510 memcpy(ptr, "bad4", min(4, len));
518 * populate @nio by @nrpages pages from per-thread page pool
520 static void ost_nio_pages_get(struct ptlrpc_request *req,
521 struct niobuf_local *nio, int nrpages)
524 struct ost_thread_local_cache *tls;
528 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
529 LASSERT(req != NULL);
530 LASSERT(req->rq_svc_thread != NULL);
533 LASSERT(tls != NULL);
535 memset(nio, 0, nrpages * sizeof *nio);
536 for (i = 0; i < nrpages; ++ i) {
540 LASSERT(page != NULL);
541 POISON_PAGE(page, 0xf1);
543 LL_CDEBUG_PAGE(D_INFO, page, "%d\n", i);
549 * Dual for ost_nio_pages_get(). Poison pages in pool for debugging
551 static void ost_nio_pages_put(struct ptlrpc_request *req,
552 struct niobuf_local *nio, int nrpages)
558 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
560 for (i = 0; i < nrpages; ++ i)
561 POISON_PAGE(nio[i].page, 0xf2);
565 static int ost_brw_lock_get(int mode, struct obd_export *exp,
566 struct obd_ioobj *obj, struct niobuf_remote *nb,
567 struct lustre_handle *lh)
570 int nrbufs = obj->ioo_bufcnt;
571 struct ldlm_res_id res_id;
572 ldlm_policy_data_t policy;
576 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
577 LASSERT(mode == LCK_PR || mode == LCK_PW);
578 LASSERT(!lustre_handle_is_used(lh));
580 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
583 /* EXPENSIVE ASSERTION */
584 for (i = 1; i < nrbufs; i ++)
585 LASSERT((nb[0].flags & OBD_BRW_SRVLOCK) ==
586 (nb[i].flags & OBD_BRW_SRVLOCK));
588 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
589 policy.l_extent.end = (nb[nrbufs - 1].offset +
590 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
592 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
593 LDLM_EXTENT, &policy, mode, &flags,
594 ldlm_blocking_ast, ldlm_completion_ast,
595 ldlm_glimpse_ast, NULL, 0, NULL, lh));
598 static void ost_brw_lock_put(int mode,
599 struct obd_ioobj *obj, struct niobuf_remote *niob,
600 struct lustre_handle *lh)
603 LASSERT(mode == LCK_PR || mode == LCK_PW);
604 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
605 lustre_handle_is_used(lh));
606 if (lustre_handle_is_used(lh))
607 ldlm_lock_decref(lh, mode);
611 struct ost_prolong_data {
612 struct obd_export *opd_exp;
613 ldlm_policy_data_t opd_policy;
614 ldlm_mode_t opd_mode;
617 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
619 struct ost_prolong_data *opd = data;
621 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
623 if (lock->l_req_mode != lock->l_granted_mode) {
624 /* scan granted locks only */
625 return LDLM_ITER_STOP;
628 if (lock->l_export != opd->opd_exp) {
629 /* prolong locks only for given client */
630 return LDLM_ITER_CONTINUE;
633 if (!(lock->l_granted_mode & opd->opd_mode)) {
634 /* we aren't interesting in all type of locks */
635 return LDLM_ITER_CONTINUE;
638 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
639 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
640 /* the request doesn't cross the lock, skip it */
641 return LDLM_ITER_CONTINUE;
644 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
645 /* ignore locks not being cancelled */
646 return LDLM_ITER_CONTINUE;
649 /* OK. this is a possible lock the user holds doing I/O
650 * let's refresh eviction timer for it */
651 ldlm_refresh_waiting_lock(lock);
653 return LDLM_ITER_CONTINUE;
656 static void ost_prolong_locks(struct obd_export *exp, struct obd_ioobj *obj,
657 struct niobuf_remote *nb, struct obdo *oa,
660 struct ldlm_res_id res_id;
661 int nrbufs = obj->ioo_bufcnt;
662 struct ost_prolong_data opd;
665 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
669 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
670 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
671 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
673 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
674 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
675 opd.opd_policy.l_extent.end);
677 if (oa->o_valid & OBD_MD_FLHANDLE) {
678 struct ldlm_lock *lock;
680 lock = ldlm_handle2lock(&oa->o_handle);
682 ost_prolong_locks_iter(lock, &opd);
689 ldlm_resource_iterate(exp->exp_obd->obd_namespace, &res_id,
690 ost_prolong_locks_iter, &opd);
695 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
697 struct ptlrpc_bulk_desc *desc;
698 struct obd_export *exp = req->rq_export;
699 struct niobuf_remote *remote_nb;
700 struct niobuf_remote *pp_rnb = NULL;
701 struct niobuf_local *local_nb;
702 struct obd_ioobj *ioo;
703 struct ost_body *body, *repbody;
704 struct lustre_capa *capa = NULL;
705 struct l_wait_info lwi;
706 struct lustre_handle lockh = { 0 };
707 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
708 int niocount, npages, nob = 0, rc, i;
712 req->rq_bulk_read = 1;
714 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
715 GOTO(out, rc = -EIO);
717 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
719 /* Check if there is eviction in progress, and if so, wait for it to
721 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
722 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
723 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
724 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
728 GOTO(out, rc = -ENOTCONN);
730 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
731 lustre_swab_ost_body);
733 CERROR("Missing/short ost_body\n");
734 GOTO(out, rc = -EFAULT);
737 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*ioo),
738 lustre_swab_obd_ioobj);
740 CERROR("Missing/short ioobj\n");
741 GOTO(out, rc = -EFAULT);
744 niocount = ioo->ioo_bufcnt;
745 if (niocount > PTLRPC_MAX_BRW_PAGES) {
746 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
748 GOTO(out, rc = -EFAULT);
751 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
752 niocount * sizeof(*remote_nb),
753 lustre_swab_niobuf_remote);
754 if (remote_nb == NULL) {
755 CERROR("Missing/short niobuf\n");
756 GOTO(out, rc = -EFAULT);
758 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
759 for (i = 1; i < niocount; i++)
760 lustre_swab_niobuf_remote (&remote_nb[i]);
763 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
764 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
766 rc = lustre_pack_reply(req, 2, size, NULL);
771 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
774 local_nb = ost_tls(req)->local;
775 pp_rnb = ost_tls(req)->remote;
777 /* FIXME all niobuf splitting should be done in obdfilter if needed */
778 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
779 npages = get_per_page_niobufs(ioo, 1, remote_nb, niocount, &pp_rnb);
781 GOTO(out, rc = npages);
783 LASSERT(npages <= OST_THREAD_POOL_SIZE);
785 ost_nio_pages_get(req, local_nb, npages);
787 desc = ptlrpc_prep_bulk_exp(req, npages,
788 BULK_PUT_SOURCE, OST_BULK_PORTAL);
790 GOTO(out, rc = -ENOMEM);
792 rc = ost_brw_lock_get(LCK_PR, exp, ioo, pp_rnb, &lockh);
797 * If getting the lock took more time than
798 * client was willing to wait, drop it. b=11330
800 if (cfs_time_current_sec() > req->rq_deadline ||
801 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
803 CERROR("Dropping timed-out read from %s because locking"
804 "object "LPX64" took %ld seconds (limit was %ld).\n",
805 libcfs_id2str(req->rq_peer), ioo->ioo_id,
806 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
807 req->rq_deadline - req->rq_arrival_time.tv_sec);
808 GOTO(out_lock, rc = -ETIMEDOUT);
811 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1,
812 ioo, npages, pp_rnb, local_nb, oti, capa);
816 ost_prolong_locks(exp, ioo, pp_rnb, &body->oa, LCK_PW | LCK_PR);
819 for (i = 0; i < npages; i++) {
820 int page_rc = local_nb[i].rc;
822 if (page_rc < 0) { /* error */
827 LASSERTF(page_rc <= pp_rnb[i].len, "page_rc (%d) > "
828 "pp_rnb[%d].len (%d)\n", page_rc, i, pp_rnb[i].len);
830 if (page_rc != 0) { /* some data! */
831 LASSERT (local_nb[i].page != NULL);
832 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
833 pp_rnb[i].offset & ~CFS_PAGE_MASK,
837 if (page_rc != pp_rnb[i].len) { /* short read */
838 /* All subsequent pages should be 0 */
840 LASSERT(local_nb[i].rc == 0);
845 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
846 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
848 if (body->oa.o_valid & OBD_MD_FLFLAGS)
849 cksum_type = cksum_type_unpack(body->oa.o_flags);
850 body->oa.o_flags = cksum_type_pack(cksum_type);
851 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
852 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
853 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
855 body->oa.o_valid = 0;
857 /* We're finishing using body->oa as an input variable */
859 /* Check if client was evicted while we were doing i/o before touching
862 /* Check if there is eviction in progress, and if so, wait for
864 if (unlikely(atomic_read(&exp->exp_obd->
865 obd_evict_inprogress))) {
866 lwi = LWI_INTR(NULL, NULL);
867 rc = l_wait_event(exp->exp_obd->
868 obd_evict_inprogress_waitq,
869 !atomic_read(&exp->exp_obd->
870 obd_evict_inprogress),
876 sptlrpc_svc_wrap_bulk(req, desc);
878 rc = ptlrpc_start_bulk_transfer(desc);
882 time_t start = cfs_time_current_sec();
884 long timeoutl = req->rq_deadline -
885 cfs_time_current_sec();
886 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
887 CFS_TICK : cfs_time_seconds(timeoutl);
888 lwi = LWI_TIMEOUT_INTERVAL(timeout,
892 rc = l_wait_event(desc->bd_waitq,
893 !ptlrpc_bulk_active(desc) ||
894 exp->exp_failed, &lwi);
895 LASSERT(rc == 0 || rc == -ETIMEDOUT);
896 /* Wait again if we changed deadline */
897 } while ((rc == -ETIMEDOUT) &&
898 (req->rq_deadline > cfs_time_current_sec()));
900 if (rc == -ETIMEDOUT) {
901 DEBUG_REQ(D_ERROR, req,
902 "timeout on bulk PUT after %ld%+lds",
903 req->rq_deadline - start,
904 cfs_time_current_sec() -
906 ptlrpc_abort_bulk(desc);
907 } else if (exp->exp_failed) {
908 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
910 ptlrpc_abort_bulk(desc);
911 } else if (!desc->bd_success ||
912 desc->bd_nob_transferred != desc->bd_nob) {
913 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
915 "truncated" : "network error on",
916 desc->bd_nob_transferred,
918 /* XXX should this be a different errno? */
922 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
927 /* Must commit after prep above in all cases */
928 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1,
929 ioo, npages, local_nb, oti, rc);
931 ost_nio_pages_put(req, local_nb, npages);
934 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
936 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
940 ost_brw_lock_put(LCK_PR, ioo, pp_rnb, &lockh);
942 ptlrpc_free_bulk(desc);
946 req->rq_status = nob;
947 ptlrpc_lprocfs_brw(req, nob);
948 target_committed_to_req(req);
950 } else if (!no_reply) {
951 /* Only reply if there was no comms problem with bulk */
952 target_committed_to_req(req);
956 /* reply out callback would free */
957 ptlrpc_req_drop_rs(req);
958 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
959 "client will retry\n",
960 exp->exp_obd->obd_name,
961 exp->exp_client_uuid.uuid,
962 exp->exp_connection->c_remote_uuid.uuid,
963 libcfs_id2str(req->rq_peer));
969 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
971 struct ptlrpc_bulk_desc *desc;
972 struct obd_export *exp = req->rq_export;
973 struct niobuf_remote *remote_nb;
974 struct niobuf_remote *pp_rnb;
975 struct niobuf_local *local_nb;
976 struct obd_ioobj *ioo;
977 struct ost_body *body, *repbody;
978 struct l_wait_info lwi;
979 struct lustre_handle lockh = {0};
980 struct lustre_capa *capa = NULL;
982 __u32 size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
983 int objcount, niocount, npages;
985 obd_count client_cksum = 0, server_cksum = 0;
986 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
990 req->rq_bulk_write = 1;
992 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
993 GOTO(out, rc = -EIO);
994 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
995 GOTO(out, rc = -EFAULT);
997 /* pause before transaction has been started */
998 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
1000 /* Check if there is eviction in progress, and if so, wait for it to
1002 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
1003 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
1004 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
1005 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
1008 if (exp->exp_failed)
1009 GOTO(out, rc = -ENOTCONN);
1011 swab = lustre_msg_swabbed(req->rq_reqmsg);
1012 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
1013 lustre_swab_ost_body);
1015 CERROR("Missing/short ost_body\n");
1016 GOTO(out, rc = -EFAULT);
1019 lustre_set_req_swabbed(req, REQ_REC_OFF + 1);
1020 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
1022 if (objcount == 0) {
1023 CERROR("Missing/short ioobj\n");
1024 GOTO(out, rc = -EFAULT);
1027 CERROR("too many ioobjs (%d)\n", objcount);
1028 GOTO(out, rc = -EFAULT);
1031 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
1032 objcount * sizeof(*ioo));
1033 LASSERT (ioo != NULL);
1034 for (niocount = i = 0; i < objcount; i++) {
1036 lustre_swab_obd_ioobj(&ioo[i]);
1037 if (ioo[i].ioo_bufcnt == 0) {
1038 CERROR("ioo[%d] has zero bufcnt\n", i);
1039 GOTO(out, rc = -EFAULT);
1041 niocount += ioo[i].ioo_bufcnt;
1044 if (niocount > PTLRPC_MAX_BRW_PAGES) {
1045 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
1047 GOTO(out, rc = -EFAULT);
1050 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
1051 niocount * sizeof(*remote_nb),
1052 lustre_swab_niobuf_remote);
1053 if (remote_nb == NULL) {
1054 CERROR("Missing/short niobuf\n");
1055 GOTO(out, rc = -EFAULT);
1057 if (swab) { /* swab the remaining niobufs */
1058 for (i = 1; i < niocount; i++)
1059 lustre_swab_niobuf_remote (&remote_nb[i]);
1062 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
1063 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
1065 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
1066 rc = lustre_pack_reply(req, 3, size, NULL);
1069 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, obd_fail_val);
1070 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
1071 niocount * sizeof(*rcs));
1074 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
1075 * ost_thread_init().
1077 local_nb = ost_tls(req)->local;
1078 pp_rnb = ost_tls(req)->remote;
1080 /* FIXME all niobuf splitting should be done in obdfilter if needed */
1081 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
1082 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
1084 GOTO(out, rc = npages);
1086 LASSERT(npages <= OST_THREAD_POOL_SIZE);
1088 ost_nio_pages_get(req, local_nb, npages);
1090 desc = ptlrpc_prep_bulk_exp(req, npages,
1091 BULK_GET_SINK, OST_BULK_PORTAL);
1093 GOTO(out, rc = -ENOMEM);
1095 rc = ost_brw_lock_get(LCK_PW, exp, ioo, pp_rnb, &lockh);
1100 * If getting the lock took more time than
1101 * client was willing to wait, drop it. b=11330
1103 if (cfs_time_current_sec() > req->rq_deadline ||
1104 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
1106 CERROR("Dropping timed-out write from %s because locking "
1107 "object "LPX64" took %ld seconds (limit was %ld).\n",
1108 libcfs_id2str(req->rq_peer), ioo->ioo_id,
1109 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
1110 req->rq_deadline - req->rq_arrival_time.tv_sec);
1111 GOTO(out_lock, rc = -ETIMEDOUT);
1114 ost_prolong_locks(exp, ioo, pp_rnb, &body->oa, LCK_PW);
1116 /* obd_preprw clobbers oa->valid, so save what we need */
1117 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
1118 client_cksum = body->oa.o_cksum;
1119 if (body->oa.o_valid & OBD_MD_FLFLAGS)
1120 cksum_type = cksum_type_unpack(body->oa.o_flags);
1123 /* Because we already sync grant info with client when reconnect,
1124 * grant info will be cleared for resent req, then fed_grant and
1125 * total_grant will not be modified in following preprw_write */
1126 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1127 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1128 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1131 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
1132 ioo, npages, pp_rnb, local_nb, oti, capa);
1136 /* NB Having prepped, we must commit... */
1138 for (i = 0; i < npages; i++)
1139 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1140 pp_rnb[i].offset & ~CFS_PAGE_MASK,
1143 /* Check if client was evicted while we were doing i/o before touching
1145 if (desc->bd_export->exp_failed)
1148 rc = ptlrpc_start_bulk_transfer (desc);
1150 time_t start = cfs_time_current_sec();
1152 long timeoutl = req->rq_deadline -
1153 cfs_time_current_sec();
1154 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
1155 CFS_TICK : cfs_time_seconds(timeoutl);
1156 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
1157 ost_bulk_timeout, desc);
1158 rc = l_wait_event(desc->bd_waitq,
1159 !ptlrpc_bulk_active(desc) ||
1160 desc->bd_export->exp_failed, &lwi);
1161 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1162 /* Wait again if we changed deadline */
1163 } while ((rc == -ETIMEDOUT) &&
1164 (req->rq_deadline > cfs_time_current_sec()));
1166 if (rc == -ETIMEDOUT) {
1167 DEBUG_REQ(D_ERROR, req,
1168 "timeout on bulk GET after %ld%+lds",
1169 req->rq_deadline - start,
1170 cfs_time_current_sec() -
1172 ptlrpc_abort_bulk(desc);
1173 } else if (desc->bd_export->exp_failed) {
1174 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1176 ptlrpc_abort_bulk(desc);
1177 } else if (!desc->bd_success ||
1178 desc->bd_nob_transferred != desc->bd_nob) {
1179 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1181 "truncated" : "network error on",
1182 desc->bd_nob_transferred, desc->bd_nob);
1183 /* XXX should this be a different errno? */
1187 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1192 sptlrpc_svc_unwrap_bulk(req, desc);
1194 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1196 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1198 if (unlikely(client_cksum != 0 && rc == 0)) {
1199 static int cksum_counter;
1200 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1201 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1202 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1203 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1204 repbody->oa.o_cksum = server_cksum;
1206 if (unlikely(client_cksum != server_cksum)) {
1207 CERROR("client csum %x, server csum %x\n",
1208 client_cksum, server_cksum);
1210 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1211 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1212 cksum_counter, libcfs_id2str(req->rq_peer),
1217 /* Must commit after prep above in all cases */
1218 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa,
1219 objcount, ioo, npages, local_nb, oti, rc);
1221 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1222 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1227 if (new_cksum == server_cksum)
1228 msg = "changed in transit before arrival at OST";
1229 else if (new_cksum == client_cksum)
1230 msg = "initial checksum before message complete";
1232 msg = "changed in transit AND after initial checksum";
1234 if (req->rq_peer.nid == desc->bd_sender) {
1238 router = libcfs_nid2str(desc->bd_sender);
1241 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1242 "%s%s%s inum "LPU64"/"LPU64" object "
1243 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1244 exp->exp_obd->obd_name, msg,
1245 libcfs_id2str(req->rq_peer),
1247 body->oa.o_valid & OBD_MD_FLFID ?
1248 body->oa.o_fid : (__u64)0,
1249 body->oa.o_valid & OBD_MD_FLFID ?
1250 body->oa.o_generation :(__u64)0,
1252 body->oa.o_valid & OBD_MD_FLGROUP ?
1253 body->oa.o_gr : (__u64)0,
1255 pp_rnb[npages-1].offset+pp_rnb[npages-1].len
1257 CERROR("client csum %x, original server csum %x, "
1258 "server csum now %x\n",
1259 client_cksum, server_cksum, new_cksum);
1262 ost_nio_pages_put(req, local_nb, npages);
1267 /* set per-requested niobuf return codes */
1268 for (i = j = 0; i < niocount; i++) {
1269 int len = remote_nb[i].len;
1274 LASSERT(j < npages);
1275 if (local_nb[j].rc < 0)
1276 rcs[i] = local_nb[j].rc;
1277 len -= pp_rnb[j].len;
1282 LASSERT(j == npages);
1283 ptlrpc_lprocfs_brw(req, nob);
1287 ost_brw_lock_put(LCK_PW, ioo, pp_rnb, &lockh);
1289 ptlrpc_free_bulk(desc);
1292 oti_to_request(oti, req);
1293 target_committed_to_req(req);
1294 rc = ptlrpc_reply(req);
1295 } else if (!no_reply) {
1296 /* Only reply if there was no comms problem with bulk */
1297 target_committed_to_req(req);
1298 req->rq_status = rc;
1301 /* reply out callback would free */
1302 ptlrpc_req_drop_rs(req);
1303 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1304 "client will retry\n",
1305 exp->exp_obd->obd_name,
1306 exp->exp_client_uuid.uuid,
1307 exp->exp_connection->c_remote_uuid.uuid,
1308 libcfs_id2str(req->rq_peer));
1313 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1315 char *key, *val = NULL;
1316 int keylen, vallen, rc = 0;
1319 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1321 DEBUG_REQ(D_HA, req, "no set_info key");
1324 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1326 rc = lustre_pack_reply(req, 1, NULL, NULL);
1330 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1332 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
1334 if (KEY_IS(KEY_EVICT_BY_NID)) {
1336 obd_export_evict_by_nid(exp->exp_obd, val);
1341 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1343 lustre_msg_set_status(req->rq_repmsg, 0);
1347 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1350 int keylen, replylen, rc = 0;
1351 struct req_capsule *pill = &req->rq_pill;
1354 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
1356 /* this common part for get_info rpc */
1357 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1359 DEBUG_REQ(D_HA, req, "no get_info key");
1362 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1364 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1368 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1369 RCL_SERVER, replylen);
1371 rc = req_capsule_server_pack(pill);
1375 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1379 /* call again to fill in the reply buffer */
1380 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1382 lustre_msg_set_status(req->rq_repmsg, 0);
1386 static int ost_handle_quotactl(struct ptlrpc_request *req)
1388 struct obd_quotactl *oqctl, *repoqc;
1389 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) };
1393 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1394 lustre_swab_obd_quotactl);
1396 GOTO(out, rc = -EPROTO);
1398 rc = lustre_pack_reply(req, 2, size, NULL);
1402 repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc));
1404 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1410 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1412 struct obd_quotactl *oqctl;
1416 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1420 rc = req_capsule_server_pack(&req->rq_pill);
1422 CERROR("ost: out of memory while packing quotacheck reply\n");
1426 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1430 static int ost_llog_handle_connect(struct obd_export *exp,
1431 struct ptlrpc_request *req)
1433 struct llogd_conn_body *body;
1437 body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body));
1438 rc = obd_llog_connect(exp, body);
1442 static int filter_export_check_flavor(struct filter_obd *filter,
1443 struct obd_export *exp,
1444 struct ptlrpc_request *req)
1449 * this should be done in filter_connect()/filter_reconnect(), but
1450 * we can't obtain information like NID, which stored in incoming
1451 * request, thus can't decide what flavor to use. so we do it here.
1453 * This hack should be removed after the OST stack be rewritten, just
1454 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1456 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_INVALID)
1459 CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from));
1460 spin_lock(&exp->exp_lock);
1461 exp->exp_sp_peer = req->rq_sp_from;
1463 read_lock(&filter->fo_sptlrpc_lock);
1464 sptlrpc_rule_set_choose(&filter->fo_sptlrpc_rset, exp->exp_sp_peer,
1465 req->rq_peer.nid, &exp->exp_flvr);
1466 read_unlock(&filter->fo_sptlrpc_lock);
1468 if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1469 CERROR("invalid rpc flavor %x, expect %x, from %s\n",
1470 req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
1471 libcfs_nid2str(req->rq_peer.nid));
1472 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID;
1476 spin_unlock(&exp->exp_lock);
1481 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1482 struct obd_device *obd, int *process)
1484 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1485 case OST_CONNECT: /* This will never get here, but for completeness. */
1486 case OST_DISCONNECT:
1497 case OBD_LOG_CANCEL:
1499 *process = target_queue_recovery_request(req, obd);
1503 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1509 int ost_msg_check_version(struct lustre_msg *msg)
1513 switch(lustre_msg_get_opc(msg)) {
1515 case OST_DISCONNECT:
1518 case SEC_CTX_INIT_CONT:
1520 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1522 CERROR("bad opc %u version %08x, expecting %08x\n",
1523 lustre_msg_get_opc(msg),
1524 lustre_msg_get_version(msg),
1525 LUSTRE_OBD_VERSION);
1538 case OST_QUOTACHECK:
1540 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1542 CERROR("bad opc %u version %08x, expecting %08x\n",
1543 lustre_msg_get_opc(msg),
1544 lustre_msg_get_version(msg),
1545 LUSTRE_OST_VERSION);
1550 case LDLM_BL_CALLBACK:
1551 case LDLM_CP_CALLBACK:
1552 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1554 CERROR("bad opc %u version %08x, expecting %08x\n",
1555 lustre_msg_get_opc(msg),
1556 lustre_msg_get_version(msg),
1557 LUSTRE_DLM_VERSION);
1559 case LLOG_ORIGIN_CONNECT:
1560 case OBD_LOG_CANCEL:
1561 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1563 CERROR("bad opc %u version %08x, expecting %08x\n",
1564 lustre_msg_get_opc(msg),
1565 lustre_msg_get_version(msg),
1566 LUSTRE_LOG_VERSION);
1569 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1575 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1576 int ost_handle(struct ptlrpc_request *req)
1578 struct obd_trans_info trans_info = { 0, };
1579 struct obd_trans_info *oti = &trans_info;
1580 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1581 struct obd_device *obd = NULL;
1584 LASSERT(current->journal_info == NULL);
1586 /* primordial rpcs don't affect server recovery */
1587 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1589 case SEC_CTX_INIT_CONT:
1594 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1596 /* XXX identical to MDS */
1597 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1600 if (req->rq_export == NULL) {
1601 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1602 lustre_msg_get_opc(req->rq_reqmsg),
1603 libcfs_id2str(req->rq_peer));
1604 req->rq_status = -ENOTCONN;
1605 GOTO(out, rc = -ENOTCONN);
1608 obd = req->rq_export->exp_obd;
1610 /* Check for aborted recovery. */
1611 spin_lock_bh(&obd->obd_processing_task_lock);
1612 recovering = obd->obd_recovering;
1613 spin_unlock_bh(&obd->obd_processing_task_lock);
1615 rc = ost_filter_recovery_request(req, obd,
1617 if (rc || !should_process)
1619 else if (should_process < 0) {
1620 req->rq_status = should_process;
1621 rc = ptlrpc_error(req);
1629 rc = ost_msg_check_version(req->rq_reqmsg);
1633 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1635 CDEBUG(D_INODE, "connect\n");
1636 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
1637 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
1639 rc = target_handle_connect(req);
1640 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
1643 struct obd_export *exp = req->rq_export;
1647 rc = filter_export_check_flavor(&obd->u.filter,
1652 case OST_DISCONNECT:
1653 CDEBUG(D_INODE, "disconnect\n");
1654 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
1655 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
1657 rc = target_handle_disconnect(req);
1660 CDEBUG(D_INODE, "create\n");
1661 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
1663 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1664 GOTO(out, rc = -ENOSPC);
1665 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1666 GOTO(out, rc = -EROFS);
1667 rc = ost_create(req->rq_export, req, oti);
1670 CDEBUG(D_INODE, "destroy\n");
1671 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
1673 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1674 GOTO(out, rc = -EROFS);
1675 rc = ost_destroy(req->rq_export, req, oti);
1678 CDEBUG(D_INODE, "getattr\n");
1679 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
1681 rc = ost_getattr(req->rq_export, req);
1684 CDEBUG(D_INODE, "setattr\n");
1685 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
1687 rc = ost_setattr(req->rq_export, req, oti);
1690 CDEBUG(D_INODE, "write\n");
1691 /* req->rq_request_portal would be nice, if it was set */
1692 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1693 CERROR("%s: deny write request from %s to portal %u\n",
1694 req->rq_export->exp_obd->obd_name,
1695 obd_export_nid2str(req->rq_export),
1696 req->rq_rqbd->rqbd_service->srv_req_portal);
1697 GOTO(out, rc = -EPROTO);
1699 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1701 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1702 GOTO(out, rc = -ENOSPC);
1703 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1704 GOTO(out, rc = -EROFS);
1705 rc = ost_brw_write(req, oti);
1706 LASSERT(current->journal_info == NULL);
1707 /* ost_brw_write sends its own replies */
1710 CDEBUG(D_INODE, "read\n");
1711 /* req->rq_request_portal would be nice, if it was set */
1712 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1713 CERROR("%s: deny read request from %s to portal %u\n",
1714 req->rq_export->exp_obd->obd_name,
1715 obd_export_nid2str(req->rq_export),
1716 req->rq_rqbd->rqbd_service->srv_req_portal);
1717 GOTO(out, rc = -EPROTO);
1719 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1721 rc = ost_brw_read(req, oti);
1722 LASSERT(current->journal_info == NULL);
1723 /* ost_brw_read sends its own replies */
1726 CDEBUG(D_INODE, "punch\n");
1727 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
1729 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1730 GOTO(out, rc = -EROFS);
1731 rc = ost_punch(req->rq_export, req, oti);
1734 CDEBUG(D_INODE, "statfs\n");
1735 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
1737 rc = ost_statfs(req);
1740 CDEBUG(D_INODE, "sync\n");
1741 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
1743 rc = ost_sync(req->rq_export, req);
1746 DEBUG_REQ(D_INODE, req, "set_info");
1747 req_capsule_set(&req->rq_pill, &RQF_OST_SET_INFO);
1748 rc = ost_set_info(req->rq_export, req);
1751 DEBUG_REQ(D_INODE, req, "get_info");
1752 rc = ost_get_info(req->rq_export, req);
1754 case OST_QUOTACHECK:
1755 CDEBUG(D_INODE, "quotacheck\n");
1756 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
1757 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
1759 rc = ost_handle_quotacheck(req);
1762 CDEBUG(D_INODE, "quotactl\n");
1763 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
1764 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
1766 rc = ost_handle_quotactl(req);
1769 DEBUG_REQ(D_INODE, req, "ping");
1770 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
1771 rc = target_handle_ping(req);
1773 /* FIXME - just reply status */
1774 case LLOG_ORIGIN_CONNECT:
1775 DEBUG_REQ(D_INODE, req, "log connect");
1776 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
1777 rc = ost_llog_handle_connect(req->rq_export, req);
1778 req->rq_status = rc;
1779 rc = req_capsule_server_pack(&req->rq_pill);
1782 RETURN(ptlrpc_reply(req));
1783 case OBD_LOG_CANCEL:
1784 CDEBUG(D_INODE, "log cancel\n");
1785 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
1786 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
1788 rc = llog_origin_handle_cancel(req);
1789 req->rq_status = rc;
1790 rc = req_capsule_server_pack(&req->rq_pill);
1793 RETURN(ptlrpc_reply(req));
1795 CDEBUG(D_INODE, "enqueue\n");
1796 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
1797 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
1799 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1800 ldlm_server_blocking_ast,
1801 ldlm_server_glimpse_ast);
1802 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1805 CDEBUG(D_INODE, "convert\n");
1806 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
1807 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
1809 rc = ldlm_handle_convert(req);
1812 CDEBUG(D_INODE, "cancel\n");
1813 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
1814 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
1816 rc = ldlm_handle_cancel(req);
1818 case LDLM_BL_CALLBACK:
1819 case LDLM_CP_CALLBACK:
1820 CDEBUG(D_INODE, "callback\n");
1821 CERROR("callbacks should not happen on OST\n");
1824 CERROR("Unexpected opcode %d\n",
1825 lustre_msg_get_opc(req->rq_reqmsg));
1826 req->rq_status = -ENOTSUPP;
1827 rc = ptlrpc_error(req);
1831 LASSERT(current->journal_info == NULL);
1834 /* If we're DISCONNECTing, the export_data is already freed */
1835 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
1836 target_committed_to_req(req);
1840 oti_to_request(oti, req);
1842 target_send_reply(req, rc, fail);
1845 EXPORT_SYMBOL(ost_handle);
1847 * free per-thread pool created by ost_thread_init().
1849 static void ost_thread_done(struct ptlrpc_thread *thread)
1852 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
1857 LASSERT(thread != NULL);
1860 * be prepared to handle partially-initialized pools (because this is
1861 * called from ost_thread_init() for cleanup.
1863 tls = thread->t_data;
1865 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1866 if (tls->page[i] != NULL)
1867 OBD_PAGE_FREE(tls->page[i]);
1870 thread->t_data = NULL;
1876 * initialize per-thread page pool (bug 5137).
1878 static int ost_thread_init(struct ptlrpc_thread *thread)
1882 struct ost_thread_local_cache *tls;
1886 LASSERT(thread != NULL);
1887 LASSERT(thread->t_data == NULL);
1888 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
1893 thread->t_data = tls;
1897 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1898 OBD_PAGE_ALLOC(tls->page[i], OST_THREAD_POOL_GFP);
1899 if (tls->page[i] == NULL) {
1900 ost_thread_done(thread);
1910 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
1912 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
1913 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
1915 struct ost_obd *ost = &obd->u.ost;
1916 struct lprocfs_static_vars lvars;
1917 int oss_min_threads;
1918 int oss_max_threads;
1919 int oss_min_create_threads;
1920 int oss_max_create_threads;
1924 rc = cleanup_group_info();
1928 lprocfs_ost_init_vars(&lvars);
1929 lprocfs_obd_setup(obd, lvars.obd_vars);
1931 sema_init(&ost->ost_health_sem, 1);
1933 if (oss_num_threads) {
1934 /* If oss_num_threads is set, it is the min and the max. */
1935 if (oss_num_threads > OSS_THREADS_MAX)
1936 oss_num_threads = OSS_THREADS_MAX;
1937 if (oss_num_threads < OSS_THREADS_MIN)
1938 oss_num_threads = OSS_THREADS_MIN;
1939 oss_max_threads = oss_min_threads = oss_num_threads;
1941 /* Base min threads on memory and cpus */
1942 oss_min_threads = num_possible_cpus() * num_physpages >>
1943 (27 - CFS_PAGE_SHIFT);
1944 if (oss_min_threads < OSS_THREADS_MIN)
1945 oss_min_threads = OSS_THREADS_MIN;
1946 /* Insure a 4x range for dynamic threads */
1947 if (oss_min_threads > OSS_THREADS_MAX / 4)
1948 oss_min_threads = OSS_THREADS_MAX / 4;
1949 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4);
1953 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1954 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
1955 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1956 ost_handle, LUSTRE_OSS_NAME,
1957 obd->obd_proc_entry, target_print_req,
1958 oss_min_threads, oss_max_threads,
1959 "ll_ost", LCT_DT_THREAD);
1960 if (ost->ost_service == NULL) {
1961 CERROR("failed to start service\n");
1962 GOTO(out_lprocfs, rc = -ENOMEM);
1965 rc = ptlrpc_start_threads(obd, ost->ost_service);
1967 GOTO(out_service, rc = -EINVAL);
1969 if (oss_num_create_threads) {
1970 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
1971 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
1972 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
1973 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
1974 oss_min_create_threads = oss_max_create_threads =
1975 oss_num_create_threads;
1977 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
1978 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
1981 ost->ost_create_service =
1982 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1983 OST_MAXREPSIZE, OST_CREATE_PORTAL,
1984 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1985 ost_handle, "ost_create",
1986 obd->obd_proc_entry, target_print_req,
1987 oss_min_create_threads, oss_max_create_threads,
1988 "ll_ost_creat", LCT_DT_THREAD);
1989 if (ost->ost_create_service == NULL) {
1990 CERROR("failed to start OST create service\n");
1991 GOTO(out_service, rc = -ENOMEM);
1994 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
1996 GOTO(out_create, rc = -EINVAL);
1998 ost->ost_io_service =
1999 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2000 OST_MAXREPSIZE, OST_IO_PORTAL,
2001 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2002 ost_handle, "ost_io",
2003 obd->obd_proc_entry, target_print_req,
2004 oss_min_threads, oss_max_threads,
2005 "ll_ost_io", LCT_DT_THREAD);
2006 if (ost->ost_io_service == NULL) {
2007 CERROR("failed to start OST I/O service\n");
2008 GOTO(out_create, rc = -ENOMEM);
2011 ost->ost_io_service->srv_init = ost_thread_init;
2012 ost->ost_io_service->srv_done = ost_thread_done;
2013 ost->ost_io_service->srv_cpu_affinity = 1;
2014 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
2016 GOTO(out_io, rc = -EINVAL);
2018 ping_evictor_start();
2023 ptlrpc_unregister_service(ost->ost_io_service);
2024 ost->ost_io_service = NULL;
2026 ptlrpc_unregister_service(ost->ost_create_service);
2027 ost->ost_create_service = NULL;
2029 ptlrpc_unregister_service(ost->ost_service);
2030 ost->ost_service = NULL;
2032 lprocfs_obd_cleanup(obd);
2036 static int ost_cleanup(struct obd_device *obd)
2038 struct ost_obd *ost = &obd->u.ost;
2042 ping_evictor_stop();
2044 spin_lock_bh(&obd->obd_processing_task_lock);
2045 if (obd->obd_recovering) {
2046 target_cancel_recovery_timer(obd);
2047 obd->obd_recovering = 0;
2049 spin_unlock_bh(&obd->obd_processing_task_lock);
2051 down(&ost->ost_health_sem);
2052 ptlrpc_unregister_service(ost->ost_service);
2053 ptlrpc_unregister_service(ost->ost_create_service);
2054 ptlrpc_unregister_service(ost->ost_io_service);
2055 ost->ost_service = NULL;
2056 ost->ost_create_service = NULL;
2057 up(&ost->ost_health_sem);
2059 lprocfs_obd_cleanup(obd);
2064 static int ost_health_check(struct obd_device *obd)
2066 struct ost_obd *ost = &obd->u.ost;
2069 down(&ost->ost_health_sem);
2070 rc |= ptlrpc_service_health_check(ost->ost_service);
2071 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2072 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2073 up(&ost->ost_health_sem);
2076 * health_check to return 0 on healthy
2077 * and 1 on unhealthy.
2085 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2087 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2090 /* use obd ops to offer management infrastructure */
2091 static struct obd_ops ost_obd_ops = {
2092 .o_owner = THIS_MODULE,
2093 .o_setup = ost_setup,
2094 .o_cleanup = ost_cleanup,
2095 .o_health_check = ost_health_check,
2099 static int __init ost_init(void)
2101 struct lprocfs_static_vars lvars;
2105 lprocfs_ost_init_vars(&lvars);
2106 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2107 LUSTRE_OSS_NAME, NULL);
2109 if (ost_num_threads != 0 && oss_num_threads == 0) {
2110 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2111 "use oss_num_threads instead or unset both for "
2112 "dynamic thread startup\n");
2113 oss_num_threads = ost_num_threads;
2119 static void /*__exit*/ ost_exit(void)
2121 class_unregister_type(LUSTRE_OSS_NAME);
2124 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2125 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2126 MODULE_LICENSE("GPL");
2128 module_init(ost_init);
2129 module_exit(ost_exit);