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 [sun.com URL with a
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 <lustre_commit_confd.h>
57 #include <libcfs/list.h>
58 #include <lustre_quota.h>
59 #include "ost_internal.h"
61 static int oss_num_threads;
62 CFS_MODULE_PARM(oss_num_threads, "i", int, 0444,
63 "number of OSS service threads to start");
65 static int ost_num_threads;
66 CFS_MODULE_PARM(ost_num_threads, "i", int, 0444,
67 "number of OST service threads to start (deprecated)");
69 static int oss_num_create_threads;
70 CFS_MODULE_PARM(oss_num_create_threads, "i", int, 0444,
71 "number of OSS create threads to start");
73 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
75 struct oti_req_ack_lock *ack_lock;
82 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
83 req->rq_transno = oti->oti_transno;
85 /* XXX 4 == entries in oti_ack_locks??? */
86 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
89 /* XXX not even calling target_send_reply in some cases... */
90 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode);
94 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
95 struct obd_trans_info *oti)
97 struct ost_body *body, *repbody;
98 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
102 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
103 lustre_swab_ost_body);
107 if (body->oa.o_id == 0)
110 if (lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1)) {
111 struct ldlm_request *dlm;
112 dlm = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*dlm),
113 lustre_swab_ldlm_request);
116 ldlm_request_cancel(req, dlm, 0);
119 rc = lustre_pack_reply(req, 2, size, NULL);
123 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
124 oti->oti_logcookies = obdo_logcookie(&body->oa);
125 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
127 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
128 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL);
132 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
134 struct ost_body *body, *repbody;
135 struct obd_info oinfo = { { { 0 } } };
136 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
140 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
141 lustre_swab_ost_body);
145 rc = lustre_pack_reply(req, 2, size, NULL);
149 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
151 repbody->oa = body->oa;
153 oinfo.oi_oa = &repbody->oa;
154 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
155 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
157 req->rq_status = obd_getattr(exp, &oinfo);
161 static int ost_statfs(struct ptlrpc_request *req)
163 struct obd_statfs *osfs;
164 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*osfs) };
168 rc = lustre_pack_reply(req, 2, size, NULL);
172 osfs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*osfs));
174 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
175 cfs_time_current_64() - HZ, 0);
176 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
177 osfs->os_bfree = osfs->os_bavail = 64;
178 if (req->rq_status != 0)
179 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
184 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
185 struct obd_trans_info *oti)
187 struct ost_body *body, *repbody;
188 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
192 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
193 lustre_swab_ost_body);
197 rc = lustre_pack_reply(req, 2, size, NULL);
201 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
203 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
204 oti->oti_logcookies = obdo_logcookie(&repbody->oa);
205 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
206 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
211 * Helper function for ost_punch(): if asked by client, acquire [size, EOF]
212 * lock on the file being truncated.
214 static int ost_punch_lock_get(struct obd_export *exp, struct obdo *oa,
215 struct lustre_handle *lh)
218 struct ldlm_res_id res_id;
219 ldlm_policy_data_t policy;
225 osc_build_res_name(oa->o_id, oa->o_gr, &res_id);
226 LASSERT(!lustre_handle_is_used(lh));
228 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
229 !(oa->o_flags & OBD_FL_TRUNCLOCK))
232 CDEBUG(D_INODE, "OST-side truncate lock.\n");
235 finis = start + oa->o_blocks;
238 * standard truncate optimization: if file body is completely
239 * destroyed, don't send data back to the server.
241 flags = (start == 0) ? LDLM_AST_DISCARD_DATA : 0;
243 policy.l_extent.start = start & CFS_PAGE_MASK;
246 * If ->o_blocks is EOF it means "lock till the end of the
247 * file". Otherwise, it's size of a hole being punched (in bytes)
249 if (oa->o_blocks == OBD_OBJECT_EOF || finis < start)
250 policy.l_extent.end = OBD_OBJECT_EOF;
252 policy.l_extent.end = finis | ~CFS_PAGE_MASK;
254 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
255 LDLM_EXTENT, &policy, LCK_PW, &flags,
256 ldlm_blocking_ast, ldlm_completion_ast,
257 ldlm_glimpse_ast, NULL, 0, NULL, lh));
261 * Helper function for ost_punch(): release lock acquired by
262 * ost_punch_lock_get(), if any.
264 static void ost_punch_lock_put(struct obd_export *exp, struct obdo *oa,
265 struct lustre_handle *lh)
268 if (lustre_handle_is_used(lh))
269 ldlm_lock_decref(lh, LCK_PW);
273 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
274 struct obd_trans_info *oti)
276 struct obd_info oinfo = { { { 0 } } };
277 struct ost_body *body, *repbody;
278 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
280 struct lustre_handle lh = {0,};
283 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
284 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
286 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
287 lustre_swab_ost_body);
291 oinfo.oi_oa = &body->oa;
292 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
293 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
295 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
296 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
299 rc = lustre_pack_reply(req, 2, size, NULL);
303 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
305 rc = ost_punch_lock_get(exp, oinfo.oi_oa, &lh);
307 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
308 oinfo.oi_oa->o_flags == OBD_FL_TRUNCLOCK)
310 * If OBD_FL_TRUNCLOCK is the only bit set in
311 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
312 * through filter_setattr() to filter_iocontrol().
314 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
316 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
317 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
319 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
320 ost_punch_lock_put(exp, oinfo.oi_oa, &lh);
322 repbody->oa = *oinfo.oi_oa;
326 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
328 struct ost_body *body, *repbody;
329 struct lustre_capa *capa = NULL;
330 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
334 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
335 lustre_swab_ost_body);
339 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
340 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 1);
342 rc = lustre_pack_reply(req, 2, size, NULL);
346 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
348 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
349 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
350 repbody->oa.o_blocks, capa);
354 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
355 struct obd_trans_info *oti)
357 struct ost_body *body, *repbody;
358 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
360 struct obd_info oinfo = { { { 0 } } };
363 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
364 lustre_swab_ost_body);
368 rc = lustre_pack_reply(req, 2, size, NULL);
372 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
374 repbody->oa = body->oa;
376 oinfo.oi_oa = &repbody->oa;
377 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
378 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
380 req->rq_status = obd_setattr(exp, &oinfo, oti);
384 static int ost_bulk_timeout(void *data)
387 /* We don't fail the connection here, because having the export
388 * killed makes the (vital) call to commitrw very sad.
393 static int get_per_page_niobufs(struct obd_ioobj *ioo, int nioo,
394 struct niobuf_remote *rnb, int nrnb,
395 struct niobuf_remote **pp_rnbp)
397 /* Copy a remote niobuf, splitting it into page-sized chunks
398 * and setting ioo[i].ioo_bufcnt accordingly */
399 struct niobuf_remote *pp_rnb;
407 * array of sufficient size already preallocated by caller
409 LASSERT(pp_rnbp != NULL);
410 LASSERT(*pp_rnbp != NULL);
412 /* first count and check the number of pages required */
413 for (i = 0; i < nioo; i++)
414 for (j = 0; j < ioo->ioo_bufcnt; j++, rnbidx++) {
415 obd_off offset = rnb[rnbidx].offset;
416 obd_off p0 = offset >> CFS_PAGE_SHIFT;
417 obd_off pn = (offset + rnb[rnbidx].len - 1) >>
420 LASSERT(rnbidx < nrnb);
422 npages += (pn + 1 - p0);
424 if (rnb[rnbidx].len == 0) {
425 CERROR("zero len BRW: obj %d objid "LPX64
426 " buf %u\n", i, ioo[i].ioo_id, j);
430 rnb[rnbidx].offset <= rnb[rnbidx-1].offset) {
431 CERROR("unordered BRW: obj %d objid "LPX64
432 " buf %u offset "LPX64" <= "LPX64"\n",
433 i, ioo[i].ioo_id, j, rnb[rnbidx].offset,
439 LASSERT(rnbidx == nrnb);
441 if (npages == nrnb) { /* all niobufs are for single pages */
448 /* now do the actual split */
450 for (i = 0; i < nioo; i++) {
453 for (j = 0; j < ioo[i].ioo_bufcnt; j++, rnbidx++) {
454 obd_off off = rnb[rnbidx].offset;
455 int nob = rnb[rnbidx].len;
457 LASSERT(rnbidx < nrnb);
459 obd_off poff = off & ~CFS_PAGE_MASK;
460 int pnob = (poff + nob > CFS_PAGE_SIZE) ?
461 CFS_PAGE_SIZE - poff : nob;
463 LASSERT(page < npages);
464 pp_rnb[page].len = pnob;
465 pp_rnb[page].offset = off;
466 pp_rnb[page].flags = rnb[rnbidx].flags;
468 CDEBUG(0, " obj %d id "LPX64
469 "page %d(%d) "LPX64" for %d, flg %x\n",
470 i, ioo[i].ioo_id, obj_pages, page,
471 pp_rnb[page].offset, pp_rnb[page].len,
481 ioo[i].ioo_bufcnt = obj_pages;
483 LASSERT(page == npages);
488 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
489 cksum_type_t cksum_type)
494 cksum = init_checksum(cksum_type);
495 for (i = 0; i < desc->bd_iov_count; i++) {
496 struct page *page = desc->bd_iov[i].kiov_page;
497 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
498 char *ptr = kmap(page) + off;
499 int len = desc->bd_iov[i].kiov_len;
501 /* corrupt the data before we compute the checksum, to
502 * simulate a client->OST data error */
503 if (i == 0 && opc == OST_WRITE &&
504 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
505 memcpy(ptr, "bad3", min(4, len));
506 cksum = compute_checksum(cksum, ptr, len, cksum_type);
507 /* corrupt the data after we compute the checksum, to
508 * simulate an OST->client data error */
509 if (i == 0 && opc == OST_READ &&
510 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND))
511 memcpy(ptr, "bad4", min(4, len));
519 * populate @nio by @nrpages pages from per-thread page pool
521 static void ost_nio_pages_get(struct ptlrpc_request *req,
522 struct niobuf_local *nio, int nrpages)
525 struct ost_thread_local_cache *tls;
529 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
530 LASSERT(req != NULL);
531 LASSERT(req->rq_svc_thread != NULL);
534 LASSERT(tls != NULL);
536 memset(nio, 0, nrpages * sizeof *nio);
537 for (i = 0; i < nrpages; ++ i) {
541 LASSERT(page != NULL);
542 POISON_PAGE(page, 0xf1);
544 LL_CDEBUG_PAGE(D_INFO, page, "%d\n", i);
550 * Dual for ost_nio_pages_get(). Poison pages in pool for debugging
552 static void ost_nio_pages_put(struct ptlrpc_request *req,
553 struct niobuf_local *nio, int nrpages)
559 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
561 for (i = 0; i < nrpages; ++ i)
562 POISON_PAGE(nio[i].page, 0xf2);
566 static int ost_brw_lock_get(int mode, struct obd_export *exp,
567 struct obd_ioobj *obj, struct niobuf_remote *nb,
568 struct lustre_handle *lh)
571 int nrbufs = obj->ioo_bufcnt;
572 struct ldlm_res_id res_id;
573 ldlm_policy_data_t policy;
577 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
578 LASSERT(mode == LCK_PR || mode == LCK_PW);
579 LASSERT(!lustre_handle_is_used(lh));
581 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
584 /* EXPENSIVE ASSERTION */
585 for (i = 1; i < nrbufs; i ++)
586 LASSERT((nb[0].flags & OBD_BRW_SRVLOCK) ==
587 (nb[i].flags & OBD_BRW_SRVLOCK));
589 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
590 policy.l_extent.end = (nb[nrbufs - 1].offset +
591 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
593 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
594 LDLM_EXTENT, &policy, mode, &flags,
595 ldlm_blocking_ast, ldlm_completion_ast,
596 ldlm_glimpse_ast, NULL, 0, NULL, lh));
599 static void ost_brw_lock_put(int mode,
600 struct obd_ioobj *obj, struct niobuf_remote *niob,
601 struct lustre_handle *lh)
604 LASSERT(mode == LCK_PR || mode == LCK_PW);
605 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
606 lustre_handle_is_used(lh));
607 if (lustre_handle_is_used(lh))
608 ldlm_lock_decref(lh, mode);
612 struct ost_prolong_data {
613 struct obd_export *opd_exp;
614 ldlm_policy_data_t opd_policy;
615 ldlm_mode_t opd_mode;
618 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
620 struct ost_prolong_data *opd = data;
622 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
624 if (lock->l_req_mode != lock->l_granted_mode) {
625 /* scan granted locks only */
626 return LDLM_ITER_STOP;
629 if (lock->l_export != opd->opd_exp) {
630 /* prolong locks only for given client */
631 return LDLM_ITER_CONTINUE;
634 if (!(lock->l_granted_mode & opd->opd_mode)) {
635 /* we aren't interesting in all type of locks */
636 return LDLM_ITER_CONTINUE;
639 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
640 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
641 /* the request doesn't cross the lock, skip it */
642 return LDLM_ITER_CONTINUE;
645 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
646 /* ignore locks not being cancelled */
647 return LDLM_ITER_CONTINUE;
650 /* OK. this is a possible lock the user holds doing I/O
651 * let's refresh eviction timer for it */
652 ldlm_refresh_waiting_lock(lock);
654 return LDLM_ITER_CONTINUE;
657 static void ost_prolong_locks(struct obd_export *exp, struct obd_ioobj *obj,
658 struct niobuf_remote *nb, ldlm_mode_t mode)
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);
676 ldlm_resource_iterate(exp->exp_obd->obd_namespace, &res_id,
677 ost_prolong_locks_iter, &opd);
680 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
682 struct ptlrpc_bulk_desc *desc;
683 struct obd_export *exp = req->rq_export;
684 struct niobuf_remote *remote_nb;
685 struct niobuf_remote *pp_rnb = NULL;
686 struct niobuf_local *local_nb;
687 struct obd_ioobj *ioo;
688 struct ost_body *body, *repbody;
689 struct lustre_capa *capa = NULL;
690 struct l_wait_info lwi;
691 struct lustre_handle lockh = { 0 };
692 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
693 int niocount, npages, nob = 0, rc, i;
697 req->rq_bulk_read = 1;
699 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
700 GOTO(out, rc = -EIO);
702 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
704 /* Check if there is eviction in progress, and if so, wait for it to
706 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
707 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
708 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
709 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
713 GOTO(out, rc = -ENOTCONN);
715 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
716 lustre_swab_ost_body);
718 CERROR("Missing/short ost_body\n");
719 GOTO(out, rc = -EFAULT);
722 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*ioo),
723 lustre_swab_obd_ioobj);
725 CERROR("Missing/short ioobj\n");
726 GOTO(out, rc = -EFAULT);
729 niocount = ioo->ioo_bufcnt;
730 if (niocount > PTLRPC_MAX_BRW_PAGES) {
731 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
733 GOTO(out, rc = -EFAULT);
736 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
737 niocount * sizeof(*remote_nb),
738 lustre_swab_niobuf_remote);
739 if (remote_nb == NULL) {
740 CERROR("Missing/short niobuf\n");
741 GOTO(out, rc = -EFAULT);
743 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
744 for (i = 1; i < niocount; i++)
745 lustre_swab_niobuf_remote (&remote_nb[i]);
748 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
749 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
751 rc = lustre_pack_reply(req, 2, size, NULL);
756 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
759 local_nb = ost_tls(req)->local;
760 pp_rnb = ost_tls(req)->remote;
762 /* FIXME all niobuf splitting should be done in obdfilter if needed */
763 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
764 npages = get_per_page_niobufs(ioo, 1, remote_nb, niocount, &pp_rnb);
766 GOTO(out, rc = npages);
768 LASSERT(npages <= OST_THREAD_POOL_SIZE);
770 ost_nio_pages_get(req, local_nb, npages);
772 desc = ptlrpc_prep_bulk_exp(req, npages,
773 BULK_PUT_SOURCE, OST_BULK_PORTAL);
775 GOTO(out, rc = -ENOMEM);
777 rc = ost_brw_lock_get(LCK_PR, exp, ioo, pp_rnb, &lockh);
782 * If getting the lock took more time than
783 * client was willing to wait, drop it. b=11330
785 if (cfs_time_current_sec() > req->rq_deadline ||
786 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
788 CERROR("Dropping timed-out read from %s because locking"
789 "object "LPX64" took %ld seconds (limit was %ld).\n",
790 libcfs_id2str(req->rq_peer), ioo->ioo_id,
791 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
792 req->rq_deadline - req->rq_arrival_time.tv_sec);
793 GOTO(out_lock, rc = -ETIMEDOUT);
796 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1,
797 ioo, npages, pp_rnb, local_nb, oti, capa);
801 ost_prolong_locks(exp, ioo, pp_rnb, LCK_PW | LCK_PR);
804 for (i = 0; i < npages; i++) {
805 int page_rc = local_nb[i].rc;
807 if (page_rc < 0) { /* error */
812 LASSERTF(page_rc <= pp_rnb[i].len, "page_rc (%d) > "
813 "pp_rnb[%d].len (%d)\n", page_rc, i, pp_rnb[i].len);
815 if (page_rc != 0) { /* some data! */
816 LASSERT (local_nb[i].page != NULL);
817 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
818 pp_rnb[i].offset & ~CFS_PAGE_MASK,
822 if (page_rc != pp_rnb[i].len) { /* short read */
823 /* All subsequent pages should be 0 */
825 LASSERT(local_nb[i].rc == 0);
830 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
831 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
833 if (body->oa.o_valid & OBD_MD_FLFLAGS)
834 cksum_type = cksum_type_unpack(body->oa.o_flags);
835 body->oa.o_flags = cksum_type_pack(cksum_type);
836 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
837 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
838 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
840 body->oa.o_valid = 0;
842 /* We're finishing using body->oa as an input variable */
844 /* Check if client was evicted while we were doing i/o before touching
847 /* Check if there is eviction in progress, and if so, wait for
849 if (unlikely(atomic_read(&exp->exp_obd->
850 obd_evict_inprogress))) {
851 lwi = LWI_INTR(NULL, NULL);
852 rc = l_wait_event(exp->exp_obd->
853 obd_evict_inprogress_waitq,
854 !atomic_read(&exp->exp_obd->
855 obd_evict_inprogress),
861 sptlrpc_svc_wrap_bulk(req, desc);
863 rc = ptlrpc_start_bulk_transfer(desc);
867 time_t start = cfs_time_current_sec();
869 long timeoutl = req->rq_deadline -
870 cfs_time_current_sec();
871 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
872 CFS_TICK : cfs_time_seconds(timeoutl);
873 lwi = LWI_TIMEOUT_INTERVAL(timeout,
877 rc = l_wait_event(desc->bd_waitq,
878 !ptlrpc_bulk_active(desc) ||
879 exp->exp_failed, &lwi);
880 LASSERT(rc == 0 || rc == -ETIMEDOUT);
881 /* Wait again if we changed deadline */
882 } while ((rc == -ETIMEDOUT) &&
883 (req->rq_deadline > cfs_time_current_sec()));
885 if (rc == -ETIMEDOUT) {
886 DEBUG_REQ(D_ERROR, req,
887 "timeout on bulk PUT after %ld%+lds",
888 req->rq_deadline - start,
889 cfs_time_current_sec() -
891 ptlrpc_abort_bulk(desc);
892 } else if (exp->exp_failed) {
893 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
895 ptlrpc_abort_bulk(desc);
896 } else if (!desc->bd_success ||
897 desc->bd_nob_transferred != desc->bd_nob) {
898 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
900 "truncated" : "network error on",
901 desc->bd_nob_transferred,
903 /* XXX should this be a different errno? */
907 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
912 /* Must commit after prep above in all cases */
913 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1,
914 ioo, npages, local_nb, oti, rc);
916 ost_nio_pages_put(req, local_nb, npages);
919 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
921 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
925 ost_brw_lock_put(LCK_PR, ioo, pp_rnb, &lockh);
927 ptlrpc_free_bulk(desc);
931 req->rq_status = nob;
932 target_committed_to_req(req);
934 } else if (!no_reply) {
935 /* Only reply if there was no comms problem with bulk */
936 target_committed_to_req(req);
940 /* reply out callback would free */
941 ptlrpc_req_drop_rs(req);
942 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
943 "client will retry\n",
944 exp->exp_obd->obd_name,
945 exp->exp_client_uuid.uuid,
946 exp->exp_connection->c_remote_uuid.uuid,
947 libcfs_id2str(req->rq_peer));
953 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
955 struct ptlrpc_bulk_desc *desc;
956 struct obd_export *exp = req->rq_export;
957 struct niobuf_remote *remote_nb;
958 struct niobuf_remote *pp_rnb;
959 struct niobuf_local *local_nb;
960 struct obd_ioobj *ioo;
961 struct ost_body *body, *repbody;
962 struct l_wait_info lwi;
963 struct lustre_handle lockh = {0};
964 struct lustre_capa *capa = NULL;
966 __u32 size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
967 int objcount, niocount, npages;
969 obd_count client_cksum = 0, server_cksum = 0;
970 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
974 req->rq_bulk_write = 1;
976 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
977 GOTO(out, rc = -EIO);
978 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
979 GOTO(out, rc = -EFAULT);
981 /* pause before transaction has been started */
982 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
984 /* Check if there is eviction in progress, and if so, wait for it to
986 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
987 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
988 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
989 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
993 GOTO(out, rc = -ENOTCONN);
995 swab = lustre_msg_swabbed(req->rq_reqmsg);
996 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
997 lustre_swab_ost_body);
999 CERROR("Missing/short ost_body\n");
1000 GOTO(out, rc = -EFAULT);
1003 lustre_set_req_swabbed(req, REQ_REC_OFF + 1);
1004 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
1006 if (objcount == 0) {
1007 CERROR("Missing/short ioobj\n");
1008 GOTO(out, rc = -EFAULT);
1011 CERROR("too many ioobjs (%d)\n", objcount);
1012 GOTO(out, rc = -EFAULT);
1015 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
1016 objcount * sizeof(*ioo));
1017 LASSERT (ioo != NULL);
1018 for (niocount = i = 0; i < objcount; i++) {
1020 lustre_swab_obd_ioobj(&ioo[i]);
1021 if (ioo[i].ioo_bufcnt == 0) {
1022 CERROR("ioo[%d] has zero bufcnt\n", i);
1023 GOTO(out, rc = -EFAULT);
1025 niocount += ioo[i].ioo_bufcnt;
1028 if (niocount > PTLRPC_MAX_BRW_PAGES) {
1029 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
1031 GOTO(out, rc = -EFAULT);
1034 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
1035 niocount * sizeof(*remote_nb),
1036 lustre_swab_niobuf_remote);
1037 if (remote_nb == NULL) {
1038 CERROR("Missing/short niobuf\n");
1039 GOTO(out, rc = -EFAULT);
1041 if (swab) { /* swab the remaining niobufs */
1042 for (i = 1; i < niocount; i++)
1043 lustre_swab_niobuf_remote (&remote_nb[i]);
1046 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
1047 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
1049 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
1050 rc = lustre_pack_reply(req, 3, size, NULL);
1053 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, obd_fail_val);
1054 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
1055 niocount * sizeof(*rcs));
1058 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
1059 * ost_thread_init().
1061 local_nb = ost_tls(req)->local;
1062 pp_rnb = ost_tls(req)->remote;
1064 /* FIXME all niobuf splitting should be done in obdfilter if needed */
1065 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
1066 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
1068 GOTO(out, rc = npages);
1070 LASSERT(npages <= OST_THREAD_POOL_SIZE);
1072 ost_nio_pages_get(req, local_nb, npages);
1074 desc = ptlrpc_prep_bulk_exp(req, npages,
1075 BULK_GET_SINK, OST_BULK_PORTAL);
1077 GOTO(out, rc = -ENOMEM);
1079 rc = ost_brw_lock_get(LCK_PW, exp, ioo, pp_rnb, &lockh);
1084 * If getting the lock took more time than
1085 * client was willing to wait, drop it. b=11330
1087 if (cfs_time_current_sec() > req->rq_deadline ||
1088 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
1090 CERROR("Dropping timed-out write from %s because locking "
1091 "object "LPX64" took %ld seconds (limit was %ld).\n",
1092 libcfs_id2str(req->rq_peer), ioo->ioo_id,
1093 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
1094 req->rq_deadline - req->rq_arrival_time.tv_sec);
1095 GOTO(out_lock, rc = -ETIMEDOUT);
1098 ost_prolong_locks(exp, ioo, pp_rnb, LCK_PW);
1100 /* obd_preprw clobbers oa->valid, so save what we need */
1101 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
1102 client_cksum = body->oa.o_cksum;
1103 if (body->oa.o_valid & OBD_MD_FLFLAGS)
1104 cksum_type = cksum_type_unpack(body->oa.o_flags);
1107 /* Because we already sync grant info with client when reconnect,
1108 * grant info will be cleared for resent req, then fed_grant and
1109 * total_grant will not be modified in following preprw_write */
1110 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1111 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1112 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1115 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
1116 ioo, npages, pp_rnb, local_nb, oti, capa);
1120 /* NB Having prepped, we must commit... */
1122 for (i = 0; i < npages; i++)
1123 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1124 pp_rnb[i].offset & ~CFS_PAGE_MASK,
1127 /* Check if client was evicted while we were doing i/o before touching
1129 if (desc->bd_export->exp_failed)
1132 rc = ptlrpc_start_bulk_transfer (desc);
1134 time_t start = cfs_time_current_sec();
1136 long timeoutl = req->rq_deadline -
1137 cfs_time_current_sec();
1138 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
1139 CFS_TICK : cfs_time_seconds(timeoutl);
1140 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
1141 ost_bulk_timeout, desc);
1142 rc = l_wait_event(desc->bd_waitq,
1143 !ptlrpc_bulk_active(desc) ||
1144 desc->bd_export->exp_failed, &lwi);
1145 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1146 /* Wait again if we changed deadline */
1147 } while ((rc == -ETIMEDOUT) &&
1148 (req->rq_deadline > cfs_time_current_sec()));
1150 if (rc == -ETIMEDOUT) {
1151 DEBUG_REQ(D_ERROR, req,
1152 "timeout on bulk GET after %ld%+lds",
1153 req->rq_deadline - start,
1154 cfs_time_current_sec() -
1156 ptlrpc_abort_bulk(desc);
1157 } else if (desc->bd_export->exp_failed) {
1158 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1160 ptlrpc_abort_bulk(desc);
1161 } else if (!desc->bd_success ||
1162 desc->bd_nob_transferred != desc->bd_nob) {
1163 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1165 "truncated" : "network error on",
1166 desc->bd_nob_transferred, desc->bd_nob);
1167 /* XXX should this be a different errno? */
1171 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1176 sptlrpc_svc_unwrap_bulk(req, desc);
1178 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1180 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1182 if (unlikely(client_cksum != 0 && rc == 0)) {
1183 static int cksum_counter;
1184 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1185 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1186 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1187 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1188 repbody->oa.o_cksum = server_cksum;
1190 if (unlikely(client_cksum != server_cksum)) {
1191 CERROR("client csum %x, server csum %x\n",
1192 client_cksum, server_cksum);
1194 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1195 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1196 cksum_counter, libcfs_id2str(req->rq_peer),
1201 /* Must commit after prep above in all cases */
1202 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa,
1203 objcount, ioo, npages, local_nb, oti, rc);
1205 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1206 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1211 if (new_cksum == server_cksum)
1212 msg = "changed in transit before arrival at OST";
1213 else if (new_cksum == client_cksum)
1214 msg = "initial checksum before message complete";
1216 msg = "changed in transit AND after initial checksum";
1218 if (req->rq_peer.nid == desc->bd_sender) {
1222 router = libcfs_nid2str(desc->bd_sender);
1225 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1226 "%s%s%s inum "LPU64"/"LPU64" object "
1227 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1228 exp->exp_obd->obd_name, msg,
1229 libcfs_id2str(req->rq_peer),
1231 body->oa.o_valid & OBD_MD_FLFID ?
1232 body->oa.o_fid : (__u64)0,
1233 body->oa.o_valid & OBD_MD_FLFID ?
1234 body->oa.o_generation :(__u64)0,
1236 body->oa.o_valid & OBD_MD_FLGROUP ?
1237 body->oa.o_gr : (__u64)0,
1239 pp_rnb[npages-1].offset+pp_rnb[npages-1].len
1241 CERROR("client csum %x, original server csum %x, "
1242 "server csum now %x\n",
1243 client_cksum, server_cksum, new_cksum);
1246 ost_nio_pages_put(req, local_nb, npages);
1249 /* set per-requested niobuf return codes */
1250 for (i = j = 0; i < niocount; i++) {
1251 int nob = remote_nb[i].len;
1255 LASSERT(j < npages);
1256 if (local_nb[j].rc < 0)
1257 rcs[i] = local_nb[j].rc;
1258 nob -= pp_rnb[j].len;
1263 LASSERT(j == npages);
1267 ost_brw_lock_put(LCK_PW, ioo, pp_rnb, &lockh);
1269 ptlrpc_free_bulk(desc);
1272 oti_to_request(oti, req);
1273 target_committed_to_req(req);
1274 rc = ptlrpc_reply(req);
1275 } else if (!no_reply) {
1276 /* Only reply if there was no comms problem with bulk */
1277 target_committed_to_req(req);
1278 req->rq_status = rc;
1281 /* reply out callback would free */
1282 ptlrpc_req_drop_rs(req);
1283 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1284 "client will retry\n",
1285 exp->exp_obd->obd_name,
1286 exp->exp_client_uuid.uuid,
1287 exp->exp_connection->c_remote_uuid.uuid,
1288 libcfs_id2str(req->rq_peer));
1293 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1295 char *key, *val = NULL;
1296 int keylen, vallen, rc = 0;
1299 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1301 DEBUG_REQ(D_HA, req, "no set_info key");
1304 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1306 rc = lustre_pack_reply(req, 1, NULL, NULL);
1310 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1312 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
1314 if (KEY_IS(KEY_EVICT_BY_NID)) {
1316 obd_export_evict_by_nid(exp->exp_obd, val);
1321 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1323 lustre_msg_set_status(req->rq_repmsg, 0);
1327 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1330 int keylen, replylen, rc = 0;
1331 struct req_capsule *pill = &req->rq_pill;
1334 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
1336 /* this common part for get_info rpc */
1337 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1339 DEBUG_REQ(D_HA, req, "no get_info key");
1342 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1344 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1348 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1349 RCL_SERVER, replylen);
1351 rc = req_capsule_server_pack(pill);
1355 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1359 /* call again to fill in the reply buffer */
1360 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1362 lustre_msg_set_status(req->rq_repmsg, 0);
1366 static int ost_handle_quotactl(struct ptlrpc_request *req)
1368 struct obd_quotactl *oqctl, *repoqc;
1369 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) };
1373 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1374 lustre_swab_obd_quotactl);
1376 GOTO(out, rc = -EPROTO);
1378 rc = lustre_pack_reply(req, 2, size, NULL);
1382 repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc));
1384 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1390 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1392 struct obd_quotactl *oqctl;
1396 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1400 rc = req_capsule_server_pack(&req->rq_pill);
1402 CERROR("ost: out of memory while packing quotacheck reply\n");
1406 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1410 static int ost_llog_handle_connect(struct obd_export *exp,
1411 struct ptlrpc_request *req)
1413 struct llogd_conn_body *body;
1417 body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body));
1418 rc = obd_llog_connect(exp, body);
1422 static int filter_export_check_flavor(struct filter_obd *filter,
1423 struct obd_export *exp,
1424 struct ptlrpc_request *req)
1429 * this should be done in filter_connect()/filter_reconnect(), but
1430 * we can't obtain information like NID, which stored in incoming
1431 * request, thus can't decide what flavor to use. so we do it here.
1433 * This hack should be removed after the OST stack be rewritten, just
1434 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1436 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_INVALID)
1439 CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from));
1440 spin_lock(&exp->exp_lock);
1441 exp->exp_sp_peer = req->rq_sp_from;
1443 read_lock(&filter->fo_sptlrpc_lock);
1444 sptlrpc_rule_set_choose(&filter->fo_sptlrpc_rset, exp->exp_sp_peer,
1445 req->rq_peer.nid, &exp->exp_flvr);
1446 read_unlock(&filter->fo_sptlrpc_lock);
1448 if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1449 CERROR("invalid rpc flavor %x, expect %x, from %s\n",
1450 req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
1451 libcfs_nid2str(req->rq_peer.nid));
1452 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID;
1456 spin_unlock(&exp->exp_lock);
1461 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1462 struct obd_device *obd, int *process)
1464 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1465 case OST_CONNECT: /* This will never get here, but for completeness. */
1466 case OST_DISCONNECT:
1477 case OBD_LOG_CANCEL:
1479 *process = target_queue_recovery_request(req, obd);
1483 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1489 int ost_msg_check_version(struct lustre_msg *msg)
1493 switch(lustre_msg_get_opc(msg)) {
1495 case OST_DISCONNECT:
1498 case SEC_CTX_INIT_CONT:
1500 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1502 CERROR("bad opc %u version %08x, expecting %08x\n",
1503 lustre_msg_get_opc(msg),
1504 lustre_msg_get_version(msg),
1505 LUSTRE_OBD_VERSION);
1518 case OST_QUOTACHECK:
1520 rc = lustre_msg_check_version(msg, LUSTRE_OST_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_OST_VERSION);
1530 case LDLM_BL_CALLBACK:
1531 case LDLM_CP_CALLBACK:
1532 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1534 CERROR("bad opc %u version %08x, expecting %08x\n",
1535 lustre_msg_get_opc(msg),
1536 lustre_msg_get_version(msg),
1537 LUSTRE_DLM_VERSION);
1539 case LLOG_ORIGIN_CONNECT:
1540 case OBD_LOG_CANCEL:
1541 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1543 CERROR("bad opc %u version %08x, expecting %08x\n",
1544 lustre_msg_get_opc(msg),
1545 lustre_msg_get_version(msg),
1546 LUSTRE_LOG_VERSION);
1549 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1555 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1556 int ost_handle(struct ptlrpc_request *req)
1558 struct obd_trans_info trans_info = { 0, };
1559 struct obd_trans_info *oti = &trans_info;
1560 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1561 struct obd_device *obd = NULL;
1564 LASSERT(current->journal_info == NULL);
1566 /* primordial rpcs don't affect server recovery */
1567 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1569 case SEC_CTX_INIT_CONT:
1574 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1576 /* XXX identical to MDS */
1577 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1580 if (req->rq_export == NULL) {
1581 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1582 lustre_msg_get_opc(req->rq_reqmsg),
1583 libcfs_id2str(req->rq_peer));
1584 req->rq_status = -ENOTCONN;
1585 GOTO(out, rc = -ENOTCONN);
1588 obd = req->rq_export->exp_obd;
1590 /* Check for aborted recovery. */
1591 spin_lock_bh(&obd->obd_processing_task_lock);
1592 recovering = obd->obd_recovering;
1593 spin_unlock_bh(&obd->obd_processing_task_lock);
1595 rc = ost_filter_recovery_request(req, obd,
1597 if (rc || !should_process)
1599 else if (should_process < 0) {
1600 req->rq_status = should_process;
1601 rc = ptlrpc_error(req);
1609 rc = ost_msg_check_version(req->rq_reqmsg);
1613 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1615 CDEBUG(D_INODE, "connect\n");
1616 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
1617 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
1619 rc = target_handle_connect(req);
1620 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
1623 struct obd_export *exp = req->rq_export;
1627 rc = filter_export_check_flavor(&obd->u.filter,
1632 case OST_DISCONNECT:
1633 CDEBUG(D_INODE, "disconnect\n");
1634 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
1635 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
1637 rc = target_handle_disconnect(req);
1640 CDEBUG(D_INODE, "create\n");
1641 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
1643 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1644 GOTO(out, rc = -ENOSPC);
1645 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1646 GOTO(out, rc = -EROFS);
1647 rc = ost_create(req->rq_export, req, oti);
1650 CDEBUG(D_INODE, "destroy\n");
1651 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
1653 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1654 GOTO(out, rc = -EROFS);
1655 rc = ost_destroy(req->rq_export, req, oti);
1658 CDEBUG(D_INODE, "getattr\n");
1659 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
1661 rc = ost_getattr(req->rq_export, req);
1664 CDEBUG(D_INODE, "setattr\n");
1665 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
1667 rc = ost_setattr(req->rq_export, req, oti);
1670 CDEBUG(D_INODE, "write\n");
1671 /* req->rq_request_portal would be nice, if it was set */
1672 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1673 CERROR("%s: deny write request from %s to portal %u\n",
1674 req->rq_export->exp_obd->obd_name,
1675 obd_export_nid2str(req->rq_export),
1676 req->rq_rqbd->rqbd_service->srv_req_portal);
1677 GOTO(out, rc = -EPROTO);
1679 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1681 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1682 GOTO(out, rc = -ENOSPC);
1683 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1684 GOTO(out, rc = -EROFS);
1685 rc = ost_brw_write(req, oti);
1686 LASSERT(current->journal_info == NULL);
1687 /* ost_brw_write sends its own replies */
1690 CDEBUG(D_INODE, "read\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 read 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 rc = ost_brw_read(req, oti);
1702 LASSERT(current->journal_info == NULL);
1703 /* ost_brw_read sends its own replies */
1706 CDEBUG(D_INODE, "punch\n");
1707 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
1709 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1710 GOTO(out, rc = -EROFS);
1711 rc = ost_punch(req->rq_export, req, oti);
1714 CDEBUG(D_INODE, "statfs\n");
1715 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
1717 rc = ost_statfs(req);
1720 CDEBUG(D_INODE, "sync\n");
1721 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
1723 rc = ost_sync(req->rq_export, req);
1726 DEBUG_REQ(D_INODE, req, "set_info");
1727 req_capsule_set(&req->rq_pill, &RQF_OST_SET_INFO);
1728 rc = ost_set_info(req->rq_export, req);
1731 DEBUG_REQ(D_INODE, req, "get_info");
1732 rc = ost_get_info(req->rq_export, req);
1734 case OST_QUOTACHECK:
1735 CDEBUG(D_INODE, "quotacheck\n");
1736 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
1737 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
1739 rc = ost_handle_quotacheck(req);
1742 CDEBUG(D_INODE, "quotactl\n");
1743 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
1744 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
1746 rc = ost_handle_quotactl(req);
1749 DEBUG_REQ(D_INODE, req, "ping");
1750 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
1751 rc = target_handle_ping(req);
1753 /* FIXME - just reply status */
1754 case LLOG_ORIGIN_CONNECT:
1755 DEBUG_REQ(D_INODE, req, "log connect");
1756 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
1757 rc = ost_llog_handle_connect(req->rq_export, req);
1758 req->rq_status = rc;
1759 rc = req_capsule_server_pack(&req->rq_pill);
1762 RETURN(ptlrpc_reply(req));
1763 case OBD_LOG_CANCEL:
1764 CDEBUG(D_INODE, "log cancel\n");
1765 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
1766 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
1768 rc = llog_origin_handle_cancel(req);
1769 req->rq_status = rc;
1770 rc = req_capsule_server_pack(&req->rq_pill);
1773 RETURN(ptlrpc_reply(req));
1775 CDEBUG(D_INODE, "enqueue\n");
1776 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
1777 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
1779 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1780 ldlm_server_blocking_ast,
1781 ldlm_server_glimpse_ast);
1782 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1785 CDEBUG(D_INODE, "convert\n");
1786 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
1787 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
1789 rc = ldlm_handle_convert(req);
1792 CDEBUG(D_INODE, "cancel\n");
1793 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
1794 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
1796 rc = ldlm_handle_cancel(req);
1798 case LDLM_BL_CALLBACK:
1799 case LDLM_CP_CALLBACK:
1800 CDEBUG(D_INODE, "callback\n");
1801 CERROR("callbacks should not happen on OST\n");
1804 CERROR("Unexpected opcode %d\n",
1805 lustre_msg_get_opc(req->rq_reqmsg));
1806 req->rq_status = -ENOTSUPP;
1807 rc = ptlrpc_error(req);
1811 LASSERT(current->journal_info == NULL);
1814 /* If we're DISCONNECTing, the export_data is already freed */
1815 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
1816 target_committed_to_req(req);
1820 oti_to_request(oti, req);
1822 target_send_reply(req, rc, fail);
1825 EXPORT_SYMBOL(ost_handle);
1827 * free per-thread pool created by ost_thread_init().
1829 static void ost_thread_done(struct ptlrpc_thread *thread)
1832 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
1837 LASSERT(thread != NULL);
1840 * be prepared to handle partially-initialized pools (because this is
1841 * called from ost_thread_init() for cleanup.
1843 tls = thread->t_data;
1845 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1846 if (tls->page[i] != NULL)
1847 OBD_PAGE_FREE(tls->page[i]);
1850 thread->t_data = NULL;
1856 * initialize per-thread page pool (bug 5137).
1858 static int ost_thread_init(struct ptlrpc_thread *thread)
1862 struct ost_thread_local_cache *tls;
1866 LASSERT(thread != NULL);
1867 LASSERT(thread->t_data == NULL);
1868 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
1873 thread->t_data = tls;
1877 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1878 OBD_PAGE_ALLOC(tls->page[i], OST_THREAD_POOL_GFP);
1879 if (tls->page[i] == NULL) {
1880 ost_thread_done(thread);
1890 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
1892 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
1893 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
1895 struct ost_obd *ost = &obd->u.ost;
1896 struct lprocfs_static_vars lvars;
1897 int oss_min_threads;
1898 int oss_max_threads;
1899 int oss_min_create_threads;
1900 int oss_max_create_threads;
1904 rc = cleanup_group_info();
1908 lprocfs_ost_init_vars(&lvars);
1909 lprocfs_obd_setup(obd, lvars.obd_vars);
1911 sema_init(&ost->ost_health_sem, 1);
1913 if (oss_num_threads) {
1914 /* If oss_num_threads is set, it is the min and the max. */
1915 if (oss_num_threads > OSS_THREADS_MAX)
1916 oss_num_threads = OSS_THREADS_MAX;
1917 if (oss_num_threads < OSS_THREADS_MIN)
1918 oss_num_threads = OSS_THREADS_MIN;
1919 oss_max_threads = oss_min_threads = oss_num_threads;
1921 /* Base min threads on memory and cpus */
1922 oss_min_threads = num_possible_cpus() * num_physpages >>
1923 (27 - CFS_PAGE_SHIFT);
1924 if (oss_min_threads < OSS_THREADS_MIN)
1925 oss_min_threads = OSS_THREADS_MIN;
1926 /* Insure a 4x range for dynamic threads */
1927 if (oss_min_threads > OSS_THREADS_MAX / 4)
1928 oss_min_threads = OSS_THREADS_MAX / 4;
1929 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4);
1933 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1934 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
1935 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1936 ost_handle, LUSTRE_OSS_NAME,
1937 obd->obd_proc_entry, target_print_req,
1938 oss_min_threads, oss_max_threads,
1939 "ll_ost", LCT_DT_THREAD);
1940 if (ost->ost_service == NULL) {
1941 CERROR("failed to start service\n");
1942 GOTO(out_lprocfs, rc = -ENOMEM);
1945 rc = ptlrpc_start_threads(obd, ost->ost_service);
1947 GOTO(out_service, rc = -EINVAL);
1949 if (oss_num_create_threads) {
1950 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
1951 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
1952 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
1953 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
1954 oss_min_create_threads = oss_max_create_threads =
1955 oss_num_create_threads;
1957 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
1958 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
1961 ost->ost_create_service =
1962 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1963 OST_MAXREPSIZE, OST_CREATE_PORTAL,
1964 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1965 ost_handle, "ost_create",
1966 obd->obd_proc_entry, target_print_req,
1967 oss_min_create_threads, oss_max_create_threads,
1968 "ll_ost_creat", LCT_DT_THREAD);
1969 if (ost->ost_create_service == NULL) {
1970 CERROR("failed to start OST create service\n");
1971 GOTO(out_service, rc = -ENOMEM);
1974 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
1976 GOTO(out_create, rc = -EINVAL);
1978 ost->ost_io_service =
1979 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1980 OST_MAXREPSIZE, OST_IO_PORTAL,
1981 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1982 ost_handle, "ost_io",
1983 obd->obd_proc_entry, target_print_req,
1984 oss_min_threads, oss_max_threads,
1985 "ll_ost_io", LCT_DT_THREAD);
1986 if (ost->ost_io_service == NULL) {
1987 CERROR("failed to start OST I/O service\n");
1988 GOTO(out_create, rc = -ENOMEM);
1991 ost->ost_io_service->srv_init = ost_thread_init;
1992 ost->ost_io_service->srv_done = ost_thread_done;
1993 ost->ost_io_service->srv_cpu_affinity = 1;
1994 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
1996 GOTO(out_io, rc = -EINVAL);
1998 ping_evictor_start();
2003 ptlrpc_unregister_service(ost->ost_io_service);
2004 ost->ost_io_service = NULL;
2006 ptlrpc_unregister_service(ost->ost_create_service);
2007 ost->ost_create_service = NULL;
2009 ptlrpc_unregister_service(ost->ost_service);
2010 ost->ost_service = NULL;
2012 lprocfs_obd_cleanup(obd);
2016 static int ost_cleanup(struct obd_device *obd)
2018 struct ost_obd *ost = &obd->u.ost;
2022 ping_evictor_stop();
2024 spin_lock_bh(&obd->obd_processing_task_lock);
2025 if (obd->obd_recovering) {
2026 target_cancel_recovery_timer(obd);
2027 obd->obd_recovering = 0;
2029 spin_unlock_bh(&obd->obd_processing_task_lock);
2031 down(&ost->ost_health_sem);
2032 ptlrpc_unregister_service(ost->ost_service);
2033 ptlrpc_unregister_service(ost->ost_create_service);
2034 ptlrpc_unregister_service(ost->ost_io_service);
2035 ost->ost_service = NULL;
2036 ost->ost_create_service = NULL;
2037 up(&ost->ost_health_sem);
2039 lprocfs_obd_cleanup(obd);
2044 static int ost_health_check(struct obd_device *obd)
2046 struct ost_obd *ost = &obd->u.ost;
2049 down(&ost->ost_health_sem);
2050 rc |= ptlrpc_service_health_check(ost->ost_service);
2051 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2052 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2053 up(&ost->ost_health_sem);
2056 * health_check to return 0 on healthy
2057 * and 1 on unhealthy.
2065 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2067 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2070 /* use obd ops to offer management infrastructure */
2071 static struct obd_ops ost_obd_ops = {
2072 .o_owner = THIS_MODULE,
2073 .o_setup = ost_setup,
2074 .o_cleanup = ost_cleanup,
2075 .o_health_check = ost_health_check,
2079 static int __init ost_init(void)
2081 struct lprocfs_static_vars lvars;
2085 lprocfs_ost_init_vars(&lvars);
2086 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2087 LUSTRE_OSS_NAME, NULL);
2089 if (ost_num_threads != 0 && oss_num_threads == 0) {
2090 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2091 "use oss_num_threads instead or unset both for "
2092 "dynamic thread startup\n");
2093 oss_num_threads = ost_num_threads;
2099 static void /*__exit*/ ost_exit(void)
2101 class_unregister_type(LUSTRE_OSS_NAME);
2104 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2105 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2106 MODULE_LICENSE("GPL");
2108 module_init(ost_init);
2109 module_exit(ost_exit);