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, 0);
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,
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 __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
394 cksum_type_t cksum_type)
399 cksum = init_checksum(cksum_type);
400 for (i = 0; i < desc->bd_iov_count; i++) {
401 struct page *page = desc->bd_iov[i].kiov_page;
402 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
403 char *ptr = kmap(page) + off;
404 int len = desc->bd_iov[i].kiov_len;
406 /* corrupt the data before we compute the checksum, to
407 * simulate a client->OST data error */
408 if (i == 0 && opc == OST_WRITE &&
409 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
410 memcpy(ptr, "bad3", min(4, len));
411 cksum = compute_checksum(cksum, ptr, len, cksum_type);
412 /* corrupt the data after we compute the checksum, to
413 * simulate an OST->client data error */
414 if (i == 0 && opc == OST_READ &&
415 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
416 memcpy(ptr, "bad4", min(4, len));
417 /* nobody should use corrupted page again */
418 ClearPageUptodate(page);
426 static int ost_brw_lock_get(int mode, struct obd_export *exp,
427 struct obd_ioobj *obj, struct niobuf_remote *nb,
428 struct lustre_handle *lh)
431 int nrbufs = obj->ioo_bufcnt;
432 struct ldlm_res_id res_id;
433 ldlm_policy_data_t policy;
437 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
438 LASSERT(mode == LCK_PR || mode == LCK_PW);
439 LASSERT(!lustre_handle_is_used(lh));
441 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
444 /* EXPENSIVE ASSERTION */
445 for (i = 1; i < nrbufs; i ++)
446 LASSERT((nb[0].flags & OBD_BRW_SRVLOCK) ==
447 (nb[i].flags & OBD_BRW_SRVLOCK));
449 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
450 policy.l_extent.end = (nb[nrbufs - 1].offset +
451 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
453 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
454 LDLM_EXTENT, &policy, mode, &flags,
455 ldlm_blocking_ast, ldlm_completion_ast,
456 ldlm_glimpse_ast, NULL, 0, NULL,
460 static void ost_brw_lock_put(int mode,
461 struct obd_ioobj *obj, struct niobuf_remote *niob,
462 struct lustre_handle *lh)
465 LASSERT(mode == LCK_PR || mode == LCK_PW);
466 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
467 lustre_handle_is_used(lh));
468 if (lustre_handle_is_used(lh))
469 ldlm_lock_decref(lh, mode);
473 struct ost_prolong_data {
474 struct obd_export *opd_exp;
475 ldlm_policy_data_t opd_policy;
476 ldlm_mode_t opd_mode;
479 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
481 struct ost_prolong_data *opd = data;
483 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
485 if (lock->l_req_mode != lock->l_granted_mode) {
486 /* scan granted locks only */
487 return LDLM_ITER_STOP;
490 if (lock->l_export != opd->opd_exp) {
491 /* prolong locks only for given client */
492 return LDLM_ITER_CONTINUE;
495 if (!(lock->l_granted_mode & opd->opd_mode)) {
496 /* we aren't interesting in all type of locks */
497 return LDLM_ITER_CONTINUE;
500 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
501 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
502 /* the request doesn't cross the lock, skip it */
503 return LDLM_ITER_CONTINUE;
506 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
507 /* ignore locks not being cancelled */
508 return LDLM_ITER_CONTINUE;
511 /* OK. this is a possible lock the user holds doing I/O
512 * let's refresh eviction timer for it */
513 ldlm_refresh_waiting_lock(lock);
515 return LDLM_ITER_CONTINUE;
518 static void ost_prolong_locks(struct obd_export *exp, struct obd_ioobj *obj,
519 struct niobuf_remote *nb, struct obdo *oa,
522 struct ldlm_res_id res_id;
523 int nrbufs = obj->ioo_bufcnt;
524 struct ost_prolong_data opd;
527 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
531 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
532 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
533 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
535 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
536 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
537 opd.opd_policy.l_extent.end);
539 if (oa->o_valid & OBD_MD_FLHANDLE) {
540 struct ldlm_lock *lock;
542 lock = ldlm_handle2lock(&oa->o_handle);
544 ost_prolong_locks_iter(lock, &opd);
551 ldlm_resource_iterate(exp->exp_obd->obd_namespace, &res_id,
552 ost_prolong_locks_iter, &opd);
557 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
559 struct ptlrpc_bulk_desc *desc = NULL;
560 struct obd_export *exp = req->rq_export;
561 struct niobuf_remote *remote_nb;
562 struct niobuf_local *local_nb;
563 struct obd_ioobj *ioo;
564 struct ost_body *body, *repbody;
565 struct lustre_capa *capa = NULL;
566 struct l_wait_info lwi;
567 struct lustre_handle lockh = { 0 };
568 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
569 int objcount, niocount, npages, nob = 0, rc, i;
573 req->rq_bulk_read = 1;
575 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
576 GOTO(out, rc = -EIO);
578 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
580 /* Check if there is eviction in progress, and if so, wait for it to
582 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
583 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
584 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
585 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
589 GOTO(out, rc = -ENOTCONN);
591 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
592 lustre_swab_ost_body);
594 CERROR("Missing/short ost_body\n");
595 GOTO(out, rc = -EFAULT);
598 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
601 CERROR("Missing/short ioobj\n");
602 GOTO(out, rc = -EFAULT);
605 CERROR("too many ioobjs (%d)\n", objcount);
606 GOTO(out, rc = -EFAULT);
609 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*ioo),
610 lustre_swab_obd_ioobj);
612 CERROR("Missing/short ioobj\n");
613 GOTO(out, rc = -EFAULT);
616 niocount = ioo->ioo_bufcnt;
617 if (niocount > PTLRPC_MAX_BRW_PAGES) {
618 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
620 GOTO(out, rc = -EFAULT);
623 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
624 niocount * sizeof(*remote_nb),
625 lustre_swab_niobuf_remote);
626 if (remote_nb == NULL) {
627 CERROR("Missing/short niobuf\n");
628 GOTO(out, rc = -EFAULT);
630 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
631 for (i = 1; i < niocount; i++)
632 lustre_swab_niobuf_remote (&remote_nb[i]);
635 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
636 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
638 rc = lustre_pack_reply(req, 2, size, NULL);
643 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
646 local_nb = ost_tls(req)->local;
648 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
653 * If getting the lock took more time than
654 * client was willing to wait, drop it. b=11330
656 if (cfs_time_current_sec() > req->rq_deadline ||
657 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
659 CERROR("Dropping timed-out read from %s because locking"
660 "object "LPX64" took %ld seconds (limit was %ld).\n",
661 libcfs_id2str(req->rq_peer), ioo->ioo_id,
662 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
663 req->rq_deadline - req->rq_arrival_time.tv_sec);
664 GOTO(out_lock, rc = -ETIMEDOUT);
667 npages = OST_THREAD_POOL_SIZE;
668 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
669 remote_nb, &npages, local_nb, oti, capa);
673 desc = ptlrpc_prep_bulk_exp(req, npages,
674 BULK_PUT_SOURCE, OST_BULK_PORTAL);
675 if (desc == NULL) /* XXX: check all cleanup stuff */
676 GOTO(out, rc = -ENOMEM);
678 ost_prolong_locks(exp, ioo, remote_nb, &body->oa, LCK_PW | LCK_PR);
681 for (i = 0; i < npages; i++) {
682 int page_rc = local_nb[i].rc;
684 if (page_rc < 0) { /* error */
690 if (page_rc != 0) { /* some data! */
691 LASSERT (local_nb[i].page != NULL);
692 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
693 local_nb[i].offset & ~CFS_PAGE_MASK,
697 if (page_rc != local_nb[i].len) { /* short read */
698 /* All subsequent pages should be 0 */
700 LASSERT(local_nb[i].rc == 0);
705 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
706 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
708 if (body->oa.o_valid & OBD_MD_FLFLAGS)
709 cksum_type = cksum_type_unpack(body->oa.o_flags);
710 body->oa.o_flags = cksum_type_pack(cksum_type);
711 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
712 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
713 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
715 body->oa.o_valid = 0;
717 /* We're finishing using body->oa as an input variable */
719 /* Check if client was evicted while we were doing i/o before touching
722 /* Check if there is eviction in progress, and if so, wait for
724 if (unlikely(atomic_read(&exp->exp_obd->
725 obd_evict_inprogress))) {
726 lwi = LWI_INTR(NULL, NULL);
727 rc = l_wait_event(exp->exp_obd->
728 obd_evict_inprogress_waitq,
729 !atomic_read(&exp->exp_obd->
730 obd_evict_inprogress),
736 sptlrpc_svc_wrap_bulk(req, desc);
738 rc = ptlrpc_start_bulk_transfer(desc);
742 time_t start = cfs_time_current_sec();
744 long timeoutl = req->rq_deadline -
745 cfs_time_current_sec();
746 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
747 CFS_TICK : cfs_time_seconds(timeoutl);
748 lwi = LWI_TIMEOUT_INTERVAL(timeout,
752 rc = l_wait_event(desc->bd_waitq,
753 !ptlrpc_bulk_active(desc) ||
754 exp->exp_failed, &lwi);
755 LASSERT(rc == 0 || rc == -ETIMEDOUT);
756 /* Wait again if we changed deadline */
757 } while ((rc == -ETIMEDOUT) &&
758 (req->rq_deadline > cfs_time_current_sec()));
760 if (rc == -ETIMEDOUT) {
761 DEBUG_REQ(D_ERROR, req,
762 "timeout on bulk PUT after %ld%+lds",
763 req->rq_deadline - start,
764 cfs_time_current_sec() -
766 ptlrpc_abort_bulk(desc);
767 } else if (exp->exp_failed) {
768 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
770 ptlrpc_abort_bulk(desc);
771 } else if (!desc->bd_success ||
772 desc->bd_nob_transferred != desc->bd_nob) {
773 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
775 "truncated" : "network error on",
776 desc->bd_nob_transferred,
778 /* XXX should this be a different errno? */
782 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
787 /* Must commit after prep above in all cases */
788 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
789 remote_nb, npages, local_nb, oti, rc);
792 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
794 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
798 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
801 ptlrpc_free_bulk(desc);
805 req->rq_status = nob;
806 ptlrpc_lprocfs_brw(req, nob);
807 target_committed_to_req(req);
809 } else if (!no_reply) {
810 /* Only reply if there was no comms problem with bulk */
811 target_committed_to_req(req);
815 /* reply out callback would free */
816 ptlrpc_req_drop_rs(req);
817 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
818 "client will retry\n",
819 exp->exp_obd->obd_name,
820 exp->exp_client_uuid.uuid,
821 exp->exp_connection->c_remote_uuid.uuid,
822 libcfs_id2str(req->rq_peer));
828 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
830 struct ptlrpc_bulk_desc *desc = NULL;
831 struct obd_export *exp = req->rq_export;
832 struct niobuf_remote *remote_nb;
833 struct niobuf_local *local_nb;
834 struct obd_ioobj *ioo;
835 struct ost_body *body, *repbody;
836 struct l_wait_info lwi;
837 struct lustre_handle lockh = {0};
838 struct lustre_capa *capa = NULL;
840 __u32 size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
841 int objcount, niocount, npages;
843 obd_count client_cksum = 0, server_cksum = 0;
844 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
848 req->rq_bulk_write = 1;
850 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
851 GOTO(out, rc = -EIO);
852 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
853 GOTO(out, rc = -EFAULT);
855 /* pause before transaction has been started */
856 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
858 /* Check if there is eviction in progress, and if so, wait for it to
860 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
861 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
862 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
863 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
867 GOTO(out, rc = -ENOTCONN);
869 swab = lustre_msg_swabbed(req->rq_reqmsg);
870 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
871 lustre_swab_ost_body);
873 CERROR("Missing/short ost_body\n");
874 GOTO(out, rc = -EFAULT);
877 lustre_set_req_swabbed(req, REQ_REC_OFF + 1);
878 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
881 CERROR("Missing/short ioobj\n");
882 GOTO(out, rc = -EFAULT);
885 CERROR("too many ioobjs (%d)\n", objcount);
886 GOTO(out, rc = -EFAULT);
889 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
890 objcount * sizeof(*ioo));
891 LASSERT (ioo != NULL);
892 for (niocount = i = 0; i < objcount; i++) {
894 lustre_swab_obd_ioobj(&ioo[i]);
895 if (ioo[i].ioo_bufcnt == 0) {
896 CERROR("ioo[%d] has zero bufcnt\n", i);
897 GOTO(out, rc = -EFAULT);
899 niocount += ioo[i].ioo_bufcnt;
902 if (niocount > PTLRPC_MAX_BRW_PAGES) {
903 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
905 GOTO(out, rc = -EFAULT);
908 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
909 niocount * sizeof(*remote_nb),
910 lustre_swab_niobuf_remote);
911 if (remote_nb == NULL) {
912 CERROR("Missing/short niobuf\n");
913 GOTO(out, rc = -EFAULT);
915 if (swab) { /* swab the remaining niobufs */
916 for (i = 1; i < niocount; i++)
917 lustre_swab_niobuf_remote (&remote_nb[i]);
920 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
921 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
923 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
924 rc = lustre_pack_reply(req, 3, size, NULL);
927 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, obd_fail_val);
928 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
929 niocount * sizeof(*rcs));
932 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
935 local_nb = ost_tls(req)->local;
937 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
942 * If getting the lock took more time than
943 * client was willing to wait, drop it. b=11330
945 if (cfs_time_current_sec() > req->rq_deadline ||
946 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
948 CERROR("Dropping timed-out write from %s because locking "
949 "object "LPX64" took %ld seconds (limit was %ld).\n",
950 libcfs_id2str(req->rq_peer), ioo->ioo_id,
951 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
952 req->rq_deadline - req->rq_arrival_time.tv_sec);
953 GOTO(out_lock, rc = -ETIMEDOUT);
956 ost_prolong_locks(exp, ioo, remote_nb,&body->oa, LCK_PW);
958 /* obd_preprw clobbers oa->valid, so save what we need */
959 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
960 client_cksum = body->oa.o_cksum;
961 if (body->oa.o_valid & OBD_MD_FLFLAGS)
962 cksum_type = cksum_type_unpack(body->oa.o_flags);
965 /* Because we already sync grant info with client when reconnect,
966 * grant info will be cleared for resent req, then fed_grant and
967 * total_grant will not be modified in following preprw_write */
968 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
969 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
970 body->oa.o_valid &= ~OBD_MD_FLGRANT;
973 npages = OST_THREAD_POOL_SIZE;
974 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
975 ioo, remote_nb, &npages, local_nb, oti, capa);
979 desc = ptlrpc_prep_bulk_exp(req, npages,
980 BULK_GET_SINK, OST_BULK_PORTAL);
982 GOTO(out, rc = -ENOMEM);
984 /* NB Having prepped, we must commit... */
986 for (i = 0; i < npages; i++)
987 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
988 local_nb[i].offset & ~CFS_PAGE_MASK,
991 /* Check if client was evicted while we were doing i/o before touching
993 if (desc->bd_export->exp_failed)
996 rc = ptlrpc_start_bulk_transfer (desc);
998 time_t start = cfs_time_current_sec();
1000 long timeoutl = req->rq_deadline -
1001 cfs_time_current_sec();
1002 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
1003 CFS_TICK : cfs_time_seconds(timeoutl);
1004 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
1005 ost_bulk_timeout, desc);
1006 rc = l_wait_event(desc->bd_waitq,
1007 !ptlrpc_bulk_active(desc) ||
1008 desc->bd_export->exp_failed, &lwi);
1009 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1010 /* Wait again if we changed deadline */
1011 } while ((rc == -ETIMEDOUT) &&
1012 (req->rq_deadline > cfs_time_current_sec()));
1014 if (rc == -ETIMEDOUT) {
1015 DEBUG_REQ(D_ERROR, req,
1016 "timeout on bulk GET after %ld%+lds",
1017 req->rq_deadline - start,
1018 cfs_time_current_sec() -
1020 ptlrpc_abort_bulk(desc);
1021 } else if (desc->bd_export->exp_failed) {
1022 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1024 ptlrpc_abort_bulk(desc);
1025 } else if (!desc->bd_success ||
1026 desc->bd_nob_transferred != desc->bd_nob) {
1027 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1029 "truncated" : "network error on",
1030 desc->bd_nob_transferred, desc->bd_nob);
1031 /* XXX should this be a different errno? */
1035 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1040 sptlrpc_svc_unwrap_bulk(req, desc);
1042 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1044 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1046 if (unlikely(client_cksum != 0 && rc == 0)) {
1047 static int cksum_counter;
1048 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1049 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1050 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1051 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1052 repbody->oa.o_cksum = server_cksum;
1054 if (unlikely(client_cksum != server_cksum)) {
1055 CERROR("client csum %x, server csum %x\n",
1056 client_cksum, server_cksum);
1058 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1059 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1060 cksum_counter, libcfs_id2str(req->rq_peer),
1065 /* Must commit after prep above in all cases */
1066 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1067 remote_nb, npages, local_nb, oti, rc);
1069 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1070 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1075 if (new_cksum == server_cksum)
1076 msg = "changed in transit before arrival at OST";
1077 else if (new_cksum == client_cksum)
1078 msg = "initial checksum before message complete";
1080 msg = "changed in transit AND after initial checksum";
1082 if (req->rq_peer.nid == desc->bd_sender) {
1086 router = libcfs_nid2str(desc->bd_sender);
1089 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1090 "%s%s%s inum "LPU64"/"LPU64" object "
1091 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1092 exp->exp_obd->obd_name, msg,
1093 libcfs_id2str(req->rq_peer),
1095 body->oa.o_valid & OBD_MD_FLFID ?
1096 body->oa.o_fid : (__u64)0,
1097 body->oa.o_valid & OBD_MD_FLFID ?
1098 body->oa.o_generation :(__u64)0,
1100 body->oa.o_valid & OBD_MD_FLGROUP ?
1101 body->oa.o_gr : (__u64)0,
1103 local_nb[npages-1].offset +
1104 local_nb[npages-1].len - 1 );
1105 CERROR("client csum %x, original server csum %x, "
1106 "server csum now %x\n",
1107 client_cksum, server_cksum, new_cksum);
1113 /* set per-requested niobuf return codes */
1114 for (i = j = 0; i < niocount; i++) {
1115 int len = remote_nb[i].len;
1120 LASSERT(j < npages);
1121 if (local_nb[j].rc < 0)
1122 rcs[i] = local_nb[j].rc;
1123 len -= local_nb[j].len;
1128 LASSERT(j == npages);
1129 ptlrpc_lprocfs_brw(req, nob);
1133 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1136 ptlrpc_free_bulk(desc);
1139 oti_to_request(oti, req);
1140 target_committed_to_req(req);
1141 rc = ptlrpc_reply(req);
1142 } else if (!no_reply) {
1143 /* Only reply if there was no comms problem with bulk */
1144 target_committed_to_req(req);
1145 req->rq_status = rc;
1148 /* reply out callback would free */
1149 ptlrpc_req_drop_rs(req);
1150 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1151 "client will retry\n",
1152 exp->exp_obd->obd_name,
1153 exp->exp_client_uuid.uuid,
1154 exp->exp_connection->c_remote_uuid.uuid,
1155 libcfs_id2str(req->rq_peer));
1160 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1162 char *key, *val = NULL;
1163 int keylen, vallen, rc = 0;
1166 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1168 DEBUG_REQ(D_HA, req, "no set_info key");
1171 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1173 rc = lustre_pack_reply(req, 1, NULL, NULL);
1177 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1179 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
1181 if (KEY_IS(KEY_EVICT_BY_NID)) {
1183 obd_export_evict_by_nid(exp->exp_obd, val);
1188 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1190 lustre_msg_set_status(req->rq_repmsg, 0);
1194 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1197 int keylen, replylen, rc = 0;
1198 struct req_capsule *pill = &req->rq_pill;
1201 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
1203 /* this common part for get_info rpc */
1204 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1206 DEBUG_REQ(D_HA, req, "no get_info key");
1209 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1211 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1215 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1216 RCL_SERVER, replylen);
1218 rc = req_capsule_server_pack(pill);
1222 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1226 /* call again to fill in the reply buffer */
1227 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1229 lustre_msg_set_status(req->rq_repmsg, 0);
1233 static int ost_handle_quotactl(struct ptlrpc_request *req)
1235 struct obd_quotactl *oqctl, *repoqc;
1236 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) };
1240 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1241 lustre_swab_obd_quotactl);
1243 GOTO(out, rc = -EPROTO);
1245 rc = lustre_pack_reply(req, 2, size, NULL);
1249 repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc));
1251 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1257 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1259 struct obd_quotactl *oqctl;
1263 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1267 rc = req_capsule_server_pack(&req->rq_pill);
1269 CERROR("ost: out of memory while packing quotacheck reply\n");
1273 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1277 static int ost_llog_handle_connect(struct obd_export *exp,
1278 struct ptlrpc_request *req)
1280 struct llogd_conn_body *body;
1284 body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body));
1285 rc = obd_llog_connect(exp, body);
1289 static int filter_export_check_flavor(struct filter_obd *filter,
1290 struct obd_export *exp,
1291 struct ptlrpc_request *req)
1296 * this should be done in filter_connect()/filter_reconnect(), but
1297 * we can't obtain information like NID, which stored in incoming
1298 * request, thus can't decide what flavor to use. so we do it here.
1300 * This hack should be removed after the OST stack be rewritten, just
1301 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1303 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_INVALID)
1306 CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from));
1307 spin_lock(&exp->exp_lock);
1308 exp->exp_sp_peer = req->rq_sp_from;
1310 read_lock(&filter->fo_sptlrpc_lock);
1311 sptlrpc_rule_set_choose(&filter->fo_sptlrpc_rset, exp->exp_sp_peer,
1312 req->rq_peer.nid, &exp->exp_flvr);
1313 read_unlock(&filter->fo_sptlrpc_lock);
1315 if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1316 CERROR("invalid rpc flavor %x, expect %x, from %s\n",
1317 req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
1318 libcfs_nid2str(req->rq_peer.nid));
1319 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID;
1323 spin_unlock(&exp->exp_lock);
1328 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1329 struct obd_device *obd, int *process)
1331 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1332 case OST_CONNECT: /* This will never get here, but for completeness. */
1333 case OST_DISCONNECT:
1344 case OBD_LOG_CANCEL:
1346 *process = target_queue_recovery_request(req, obd);
1350 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1356 int ost_msg_check_version(struct lustre_msg *msg)
1360 switch(lustre_msg_get_opc(msg)) {
1362 case OST_DISCONNECT:
1365 case SEC_CTX_INIT_CONT:
1367 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1369 CERROR("bad opc %u version %08x, expecting %08x\n",
1370 lustre_msg_get_opc(msg),
1371 lustre_msg_get_version(msg),
1372 LUSTRE_OBD_VERSION);
1385 case OST_QUOTACHECK:
1387 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1389 CERROR("bad opc %u version %08x, expecting %08x\n",
1390 lustre_msg_get_opc(msg),
1391 lustre_msg_get_version(msg),
1392 LUSTRE_OST_VERSION);
1397 case LDLM_BL_CALLBACK:
1398 case LDLM_CP_CALLBACK:
1399 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1401 CERROR("bad opc %u version %08x, expecting %08x\n",
1402 lustre_msg_get_opc(msg),
1403 lustre_msg_get_version(msg),
1404 LUSTRE_DLM_VERSION);
1406 case LLOG_ORIGIN_CONNECT:
1407 case OBD_LOG_CANCEL:
1408 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1410 CERROR("bad opc %u version %08x, expecting %08x\n",
1411 lustre_msg_get_opc(msg),
1412 lustre_msg_get_version(msg),
1413 LUSTRE_LOG_VERSION);
1416 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1422 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1423 int ost_handle(struct ptlrpc_request *req)
1425 struct obd_trans_info trans_info = { 0, };
1426 struct obd_trans_info *oti = &trans_info;
1427 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1428 struct obd_device *obd = NULL;
1431 LASSERT(current->journal_info == NULL);
1433 /* primordial rpcs don't affect server recovery */
1434 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1436 case SEC_CTX_INIT_CONT:
1441 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1443 /* XXX identical to MDS */
1444 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1447 if (req->rq_export == NULL) {
1448 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1449 lustre_msg_get_opc(req->rq_reqmsg),
1450 libcfs_id2str(req->rq_peer));
1451 req->rq_status = -ENOTCONN;
1452 GOTO(out, rc = -ENOTCONN);
1455 obd = req->rq_export->exp_obd;
1457 /* Check for aborted recovery. */
1458 spin_lock_bh(&obd->obd_processing_task_lock);
1459 recovering = obd->obd_recovering;
1460 spin_unlock_bh(&obd->obd_processing_task_lock);
1462 rc = ost_filter_recovery_request(req, obd,
1464 if (rc || !should_process)
1466 else if (should_process < 0) {
1467 req->rq_status = should_process;
1468 rc = ptlrpc_error(req);
1476 rc = ost_msg_check_version(req->rq_reqmsg);
1480 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1482 CDEBUG(D_INODE, "connect\n");
1483 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
1484 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
1486 rc = target_handle_connect(req);
1487 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
1490 struct obd_export *exp = req->rq_export;
1494 rc = filter_export_check_flavor(&obd->u.filter,
1499 case OST_DISCONNECT:
1500 CDEBUG(D_INODE, "disconnect\n");
1501 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
1502 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
1504 rc = target_handle_disconnect(req);
1507 CDEBUG(D_INODE, "create\n");
1508 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
1510 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1511 GOTO(out, rc = -ENOSPC);
1512 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1513 GOTO(out, rc = -EROFS);
1514 rc = ost_create(req->rq_export, req, oti);
1517 CDEBUG(D_INODE, "destroy\n");
1518 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
1520 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1521 GOTO(out, rc = -EROFS);
1522 rc = ost_destroy(req->rq_export, req, oti);
1525 CDEBUG(D_INODE, "getattr\n");
1526 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
1528 rc = ost_getattr(req->rq_export, req);
1531 CDEBUG(D_INODE, "setattr\n");
1532 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
1534 rc = ost_setattr(req->rq_export, req, oti);
1537 CDEBUG(D_INODE, "write\n");
1538 /* req->rq_request_portal would be nice, if it was set */
1539 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1540 CERROR("%s: deny write request from %s to portal %u\n",
1541 req->rq_export->exp_obd->obd_name,
1542 obd_export_nid2str(req->rq_export),
1543 req->rq_rqbd->rqbd_service->srv_req_portal);
1544 GOTO(out, rc = -EPROTO);
1546 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1548 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1549 GOTO(out, rc = -ENOSPC);
1550 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1551 GOTO(out, rc = -EROFS);
1552 rc = ost_brw_write(req, oti);
1553 LASSERT(current->journal_info == NULL);
1554 /* ost_brw_write sends its own replies */
1557 CDEBUG(D_INODE, "read\n");
1558 /* req->rq_request_portal would be nice, if it was set */
1559 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1560 CERROR("%s: deny read request from %s to portal %u\n",
1561 req->rq_export->exp_obd->obd_name,
1562 obd_export_nid2str(req->rq_export),
1563 req->rq_rqbd->rqbd_service->srv_req_portal);
1564 GOTO(out, rc = -EPROTO);
1566 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1568 rc = ost_brw_read(req, oti);
1569 LASSERT(current->journal_info == NULL);
1570 /* ost_brw_read sends its own replies */
1573 CDEBUG(D_INODE, "punch\n");
1574 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
1576 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1577 GOTO(out, rc = -EROFS);
1578 rc = ost_punch(req->rq_export, req, oti);
1581 CDEBUG(D_INODE, "statfs\n");
1582 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
1584 rc = ost_statfs(req);
1587 CDEBUG(D_INODE, "sync\n");
1588 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
1590 rc = ost_sync(req->rq_export, req);
1593 DEBUG_REQ(D_INODE, req, "set_info");
1594 req_capsule_set(&req->rq_pill, &RQF_OST_SET_INFO);
1595 rc = ost_set_info(req->rq_export, req);
1598 DEBUG_REQ(D_INODE, req, "get_info");
1599 rc = ost_get_info(req->rq_export, req);
1601 case OST_QUOTACHECK:
1602 CDEBUG(D_INODE, "quotacheck\n");
1603 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
1604 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
1606 rc = ost_handle_quotacheck(req);
1609 CDEBUG(D_INODE, "quotactl\n");
1610 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
1611 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
1613 rc = ost_handle_quotactl(req);
1616 DEBUG_REQ(D_INODE, req, "ping");
1617 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
1618 rc = target_handle_ping(req);
1620 /* FIXME - just reply status */
1621 case LLOG_ORIGIN_CONNECT:
1622 DEBUG_REQ(D_INODE, req, "log connect");
1623 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
1624 rc = ost_llog_handle_connect(req->rq_export, req);
1625 req->rq_status = rc;
1626 rc = req_capsule_server_pack(&req->rq_pill);
1629 RETURN(ptlrpc_reply(req));
1630 case OBD_LOG_CANCEL:
1631 CDEBUG(D_INODE, "log cancel\n");
1632 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
1633 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
1635 rc = llog_origin_handle_cancel(req);
1636 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
1638 req->rq_status = rc;
1639 rc = req_capsule_server_pack(&req->rq_pill);
1642 RETURN(ptlrpc_reply(req));
1644 CDEBUG(D_INODE, "enqueue\n");
1645 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
1646 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
1648 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1649 ldlm_server_blocking_ast,
1650 ldlm_server_glimpse_ast);
1651 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1654 CDEBUG(D_INODE, "convert\n");
1655 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
1656 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
1658 rc = ldlm_handle_convert(req);
1661 CDEBUG(D_INODE, "cancel\n");
1662 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
1663 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
1665 rc = ldlm_handle_cancel(req);
1667 case LDLM_BL_CALLBACK:
1668 case LDLM_CP_CALLBACK:
1669 CDEBUG(D_INODE, "callback\n");
1670 CERROR("callbacks should not happen on OST\n");
1673 CERROR("Unexpected opcode %d\n",
1674 lustre_msg_get_opc(req->rq_reqmsg));
1675 req->rq_status = -ENOTSUPP;
1676 rc = ptlrpc_error(req);
1680 LASSERT(current->journal_info == NULL);
1683 /* If we're DISCONNECTing, the export_data is already freed */
1684 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
1685 target_committed_to_req(req);
1689 oti_to_request(oti, req);
1691 target_send_reply(req, rc, fail);
1694 EXPORT_SYMBOL(ost_handle);
1696 * free per-thread pool created by ost_thread_init().
1698 static void ost_thread_done(struct ptlrpc_thread *thread)
1700 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
1705 LASSERT(thread != NULL);
1708 * be prepared to handle partially-initialized pools (because this is
1709 * called from ost_thread_init() for cleanup.
1711 tls = thread->t_data;
1714 thread->t_data = NULL;
1720 * initialize per-thread page pool (bug 5137).
1722 static int ost_thread_init(struct ptlrpc_thread *thread)
1724 struct ost_thread_local_cache *tls;
1728 LASSERT(thread != NULL);
1729 LASSERT(thread->t_data == NULL);
1730 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
1735 thread->t_data = tls;
1739 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
1741 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
1742 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
1744 struct ost_obd *ost = &obd->u.ost;
1745 struct lprocfs_static_vars lvars;
1746 int oss_min_threads;
1747 int oss_max_threads;
1748 int oss_min_create_threads;
1749 int oss_max_create_threads;
1753 rc = cleanup_group_info();
1757 lprocfs_ost_init_vars(&lvars);
1758 lprocfs_obd_setup(obd, lvars.obd_vars);
1760 sema_init(&ost->ost_health_sem, 1);
1762 if (oss_num_threads) {
1763 /* If oss_num_threads is set, it is the min and the max. */
1764 if (oss_num_threads > OSS_THREADS_MAX)
1765 oss_num_threads = OSS_THREADS_MAX;
1766 if (oss_num_threads < OSS_THREADS_MIN)
1767 oss_num_threads = OSS_THREADS_MIN;
1768 oss_max_threads = oss_min_threads = oss_num_threads;
1770 /* Base min threads on memory and cpus */
1771 oss_min_threads = num_possible_cpus() * num_physpages >>
1772 (27 - CFS_PAGE_SHIFT);
1773 if (oss_min_threads < OSS_THREADS_MIN)
1774 oss_min_threads = OSS_THREADS_MIN;
1775 /* Insure a 4x range for dynamic threads */
1776 if (oss_min_threads > OSS_THREADS_MAX / 4)
1777 oss_min_threads = OSS_THREADS_MAX / 4;
1778 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4);
1782 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1783 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
1784 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1785 ost_handle, LUSTRE_OSS_NAME,
1786 obd->obd_proc_entry, target_print_req,
1787 oss_min_threads, oss_max_threads,
1788 "ll_ost", LCT_DT_THREAD);
1789 if (ost->ost_service == NULL) {
1790 CERROR("failed to start service\n");
1791 GOTO(out_lprocfs, rc = -ENOMEM);
1794 rc = ptlrpc_start_threads(obd, ost->ost_service);
1796 GOTO(out_service, rc = -EINVAL);
1798 if (oss_num_create_threads) {
1799 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
1800 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
1801 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
1802 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
1803 oss_min_create_threads = oss_max_create_threads =
1804 oss_num_create_threads;
1806 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
1807 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
1810 ost->ost_create_service =
1811 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1812 OST_MAXREPSIZE, OST_CREATE_PORTAL,
1813 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1814 ost_handle, "ost_create",
1815 obd->obd_proc_entry, target_print_req,
1816 oss_min_create_threads, oss_max_create_threads,
1817 "ll_ost_creat", LCT_DT_THREAD);
1818 if (ost->ost_create_service == NULL) {
1819 CERROR("failed to start OST create service\n");
1820 GOTO(out_service, rc = -ENOMEM);
1823 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
1825 GOTO(out_create, rc = -EINVAL);
1827 ost->ost_io_service =
1828 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1829 OST_MAXREPSIZE, OST_IO_PORTAL,
1830 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1831 ost_handle, "ost_io",
1832 obd->obd_proc_entry, target_print_req,
1833 oss_min_threads, oss_max_threads,
1834 "ll_ost_io", LCT_DT_THREAD);
1835 if (ost->ost_io_service == NULL) {
1836 CERROR("failed to start OST I/O service\n");
1837 GOTO(out_create, rc = -ENOMEM);
1840 ost->ost_io_service->srv_init = ost_thread_init;
1841 ost->ost_io_service->srv_done = ost_thread_done;
1842 ost->ost_io_service->srv_cpu_affinity = 1;
1843 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
1845 GOTO(out_io, rc = -EINVAL);
1847 ping_evictor_start();
1852 ptlrpc_unregister_service(ost->ost_io_service);
1853 ost->ost_io_service = NULL;
1855 ptlrpc_unregister_service(ost->ost_create_service);
1856 ost->ost_create_service = NULL;
1858 ptlrpc_unregister_service(ost->ost_service);
1859 ost->ost_service = NULL;
1861 lprocfs_obd_cleanup(obd);
1865 static int ost_cleanup(struct obd_device *obd)
1867 struct ost_obd *ost = &obd->u.ost;
1871 ping_evictor_stop();
1873 spin_lock_bh(&obd->obd_processing_task_lock);
1874 if (obd->obd_recovering) {
1875 target_cancel_recovery_timer(obd);
1876 obd->obd_recovering = 0;
1878 spin_unlock_bh(&obd->obd_processing_task_lock);
1880 down(&ost->ost_health_sem);
1881 ptlrpc_unregister_service(ost->ost_service);
1882 ptlrpc_unregister_service(ost->ost_create_service);
1883 ptlrpc_unregister_service(ost->ost_io_service);
1884 ost->ost_service = NULL;
1885 ost->ost_create_service = NULL;
1886 up(&ost->ost_health_sem);
1888 lprocfs_obd_cleanup(obd);
1893 static int ost_health_check(struct obd_device *obd)
1895 struct ost_obd *ost = &obd->u.ost;
1898 down(&ost->ost_health_sem);
1899 rc |= ptlrpc_service_health_check(ost->ost_service);
1900 rc |= ptlrpc_service_health_check(ost->ost_create_service);
1901 rc |= ptlrpc_service_health_check(ost->ost_io_service);
1902 up(&ost->ost_health_sem);
1905 * health_check to return 0 on healthy
1906 * and 1 on unhealthy.
1914 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
1916 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
1919 /* use obd ops to offer management infrastructure */
1920 static struct obd_ops ost_obd_ops = {
1921 .o_owner = THIS_MODULE,
1922 .o_setup = ost_setup,
1923 .o_cleanup = ost_cleanup,
1924 .o_health_check = ost_health_check,
1928 static int __init ost_init(void)
1930 struct lprocfs_static_vars lvars;
1934 lprocfs_ost_init_vars(&lvars);
1935 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
1936 LUSTRE_OSS_NAME, NULL);
1938 if (ost_num_threads != 0 && oss_num_threads == 0) {
1939 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
1940 "use oss_num_threads instead or unset both for "
1941 "dynamic thread startup\n");
1942 oss_num_threads = ost_num_threads;
1948 static void /*__exit*/ ost_exit(void)
1950 class_unregister_type(LUSTRE_OSS_NAME);
1953 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
1954 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
1955 MODULE_LICENSE("GPL");
1957 module_init(ost_init);
1958 module_exit(ost_exit);