1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ost/ost_handler.c
38 * Author: Peter J. Braam <braam@clusterfs.com>
39 * Author: Phil Schwan <phil@clusterfs.com>
43 # define EXPORT_SYMTAB
45 #define DEBUG_SUBSYSTEM S_OST
47 #include <linux/module.h>
48 #include <obd_cksum.h>
50 #include <lustre_net.h>
51 #include <lustre_dlm.h>
52 #include <lustre_export.h>
53 #include <lustre_debug.h>
54 #include <linux/init.h>
55 #include <lprocfs_status.h>
56 #include <libcfs/list.h>
57 #include <lustre_quota.h>
58 #include "ost_internal.h"
60 static int oss_num_threads;
61 CFS_MODULE_PARM(oss_num_threads, "i", int, 0444,
62 "number of OSS service threads to start");
64 static int ost_num_threads;
65 CFS_MODULE_PARM(ost_num_threads, "i", int, 0444,
66 "number of OST service threads to start (deprecated)");
68 static int oss_num_create_threads;
69 CFS_MODULE_PARM(oss_num_create_threads, "i", int, 0444,
70 "number of OSS create threads to start");
72 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
74 struct oti_req_ack_lock *ack_lock;
81 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
82 req->rq_transno = oti->oti_transno;
84 /* XXX 4 == entries in oti_ack_locks??? */
85 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
88 /* XXX not even calling target_send_reply in some cases... */
89 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode);
93 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
94 struct obd_trans_info *oti)
96 struct ost_body *body, *repbody;
97 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
101 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
102 lustre_swab_ost_body);
106 if (body->oa.o_id == 0)
109 if (lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1)) {
110 struct ldlm_request *dlm;
111 dlm = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*dlm),
112 lustre_swab_ldlm_request);
115 ldlm_request_cancel(req, dlm, 0);
118 rc = lustre_pack_reply(req, 2, size, NULL);
122 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
123 oti->oti_logcookies = &body->oa.o_lcookie;
124 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
126 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
127 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL);
131 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
133 struct ost_body *body, *repbody;
134 struct obd_info oinfo = { { { 0 } } };
135 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
139 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
140 lustre_swab_ost_body);
144 rc = lustre_pack_reply(req, 2, size, NULL);
148 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
150 repbody->oa = body->oa;
152 oinfo.oi_oa = &repbody->oa;
153 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
154 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
156 req->rq_status = obd_getattr(exp, &oinfo);
160 static int ost_statfs(struct ptlrpc_request *req)
162 struct obd_statfs *osfs;
163 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*osfs) };
167 rc = lustre_pack_reply(req, 2, size, NULL);
171 osfs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*osfs));
173 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
174 cfs_time_current_64() - HZ, 0);
175 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
176 osfs->os_bfree = osfs->os_bavail = 64;
177 if (req->rq_status != 0)
178 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
183 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
184 struct obd_trans_info *oti)
186 struct ost_body *body, *repbody;
187 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
191 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
192 lustre_swab_ost_body);
196 rc = lustre_pack_reply(req, 2, size, NULL);
200 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
202 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
203 oti->oti_logcookies = &repbody->oa.o_lcookie;
204 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
205 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
210 * Helper function for ost_punch(): if asked by client, acquire [size, EOF]
211 * lock on the file being truncated.
213 static int ost_punch_lock_get(struct obd_export *exp, struct obdo *oa,
214 struct lustre_handle *lh)
217 struct ldlm_res_id res_id;
218 ldlm_policy_data_t policy;
224 osc_build_res_name(oa->o_id, oa->o_gr, &res_id);
225 LASSERT(!lustre_handle_is_used(lh));
227 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
228 !(oa->o_flags & OBD_FL_TRUNCLOCK))
231 CDEBUG(D_INODE, "OST-side truncate lock.\n");
234 finis = start + oa->o_blocks;
237 * standard truncate optimization: if file body is completely
238 * destroyed, don't send data back to the server.
240 flags = (start == 0) ? LDLM_AST_DISCARD_DATA : 0;
242 policy.l_extent.start = start & CFS_PAGE_MASK;
245 * If ->o_blocks is EOF it means "lock till the end of the
246 * file". Otherwise, it's size of a hole being punched (in bytes)
248 if (oa->o_blocks == OBD_OBJECT_EOF || finis < start)
249 policy.l_extent.end = OBD_OBJECT_EOF;
251 policy.l_extent.end = finis | ~CFS_PAGE_MASK;
253 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
254 LDLM_EXTENT, &policy, LCK_PW, &flags,
255 ldlm_blocking_ast, ldlm_completion_ast,
256 ldlm_glimpse_ast, NULL, 0, NULL, lh));
260 * Helper function for ost_punch(): release lock acquired by
261 * ost_punch_lock_get(), if any.
263 static void ost_punch_lock_put(struct obd_export *exp, struct obdo *oa,
264 struct lustre_handle *lh)
267 if (lustre_handle_is_used(lh))
268 ldlm_lock_decref(lh, LCK_PW);
272 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
273 struct obd_trans_info *oti)
275 struct obd_info oinfo = { { { 0 } } };
276 struct ost_body *body, *repbody;
277 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
279 struct lustre_handle lh = {0,};
282 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
283 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
285 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
286 lustre_swab_ost_body);
290 oinfo.oi_oa = &body->oa;
291 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
292 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
294 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
295 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
298 rc = lustre_pack_reply(req, 2, size, NULL);
302 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
304 rc = ost_punch_lock_get(exp, oinfo.oi_oa, &lh);
306 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
307 oinfo.oi_oa->o_flags == OBD_FL_TRUNCLOCK)
309 * If OBD_FL_TRUNCLOCK is the only bit set in
310 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
311 * through filter_setattr() to filter_iocontrol().
313 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
315 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
316 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
318 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
319 ost_punch_lock_put(exp, oinfo.oi_oa, &lh);
321 repbody->oa = *oinfo.oi_oa;
325 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
327 struct ost_body *body, *repbody;
328 struct lustre_capa *capa = NULL;
329 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
333 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
334 lustre_swab_ost_body);
338 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
339 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 1);
341 rc = lustre_pack_reply(req, 2, size, NULL);
345 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
347 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
348 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
349 repbody->oa.o_blocks, capa);
353 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
354 struct obd_trans_info *oti)
356 struct ost_body *body, *repbody;
357 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
359 struct obd_info oinfo = { { { 0 } } };
362 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
363 lustre_swab_ost_body);
367 rc = lustre_pack_reply(req, 2, size, NULL);
371 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
373 repbody->oa = body->oa;
375 oinfo.oi_oa = &repbody->oa;
376 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
377 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
379 req->rq_status = obd_setattr(exp, &oinfo, oti);
383 static int ost_bulk_timeout(void *data)
386 /* We don't fail the connection here, because having the export
387 * killed makes the (vital) call to commitrw very sad.
392 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
393 cksum_type_t cksum_type)
398 cksum = init_checksum(cksum_type);
399 for (i = 0; i < desc->bd_iov_count; i++) {
400 struct page *page = desc->bd_iov[i].kiov_page;
401 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
402 char *ptr = kmap(page) + off;
403 int len = desc->bd_iov[i].kiov_len;
405 /* corrupt the data before we compute the checksum, to
406 * simulate a client->OST data error */
407 if (i == 0 && opc == OST_WRITE &&
408 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
409 memcpy(ptr, "bad3", min(4, len));
410 cksum = compute_checksum(cksum, ptr, len, cksum_type);
411 /* corrupt the data after we compute the checksum, to
412 * simulate an OST->client data error */
413 if (i == 0 && opc == OST_READ &&
414 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
415 memcpy(ptr, "bad4", min(4, len));
416 /* nobody should use corrupted page again */
417 ClearPageUptodate(page);
425 static int ost_brw_lock_get(int mode, struct obd_export *exp,
426 struct obd_ioobj *obj, struct niobuf_remote *nb,
427 struct lustre_handle *lh)
430 int nrbufs = obj->ioo_bufcnt;
431 struct ldlm_res_id res_id;
432 ldlm_policy_data_t policy;
436 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
437 LASSERT(mode == LCK_PR || mode == LCK_PW);
438 LASSERT(!lustre_handle_is_used(lh));
440 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
443 /* EXPENSIVE ASSERTION */
444 for (i = 1; i < nrbufs; i ++)
445 LASSERT((nb[0].flags & OBD_BRW_SRVLOCK) ==
446 (nb[i].flags & OBD_BRW_SRVLOCK));
448 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
449 policy.l_extent.end = (nb[nrbufs - 1].offset +
450 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
452 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
453 LDLM_EXTENT, &policy, mode, &flags,
454 ldlm_blocking_ast, ldlm_completion_ast,
455 ldlm_glimpse_ast, NULL, 0, NULL, lh));
458 static void ost_brw_lock_put(int mode,
459 struct obd_ioobj *obj, struct niobuf_remote *niob,
460 struct lustre_handle *lh)
463 LASSERT(mode == LCK_PR || mode == LCK_PW);
464 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
465 lustre_handle_is_used(lh));
466 if (lustre_handle_is_used(lh))
467 ldlm_lock_decref(lh, mode);
471 struct ost_prolong_data {
472 struct obd_export *opd_exp;
473 ldlm_policy_data_t opd_policy;
474 ldlm_mode_t opd_mode;
477 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
479 struct ost_prolong_data *opd = data;
481 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
483 if (lock->l_req_mode != lock->l_granted_mode) {
484 /* scan granted locks only */
485 return LDLM_ITER_STOP;
488 if (lock->l_export != opd->opd_exp) {
489 /* prolong locks only for given client */
490 return LDLM_ITER_CONTINUE;
493 if (!(lock->l_granted_mode & opd->opd_mode)) {
494 /* we aren't interesting in all type of locks */
495 return LDLM_ITER_CONTINUE;
498 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
499 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
500 /* the request doesn't cross the lock, skip it */
501 return LDLM_ITER_CONTINUE;
504 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
505 /* ignore locks not being cancelled */
506 return LDLM_ITER_CONTINUE;
509 /* OK. this is a possible lock the user holds doing I/O
510 * let's refresh eviction timer for it */
511 ldlm_refresh_waiting_lock(lock);
513 return LDLM_ITER_CONTINUE;
516 static void ost_prolong_locks(struct obd_export *exp, struct obd_ioobj *obj,
517 struct niobuf_remote *nb, struct obdo *oa,
520 struct ldlm_res_id res_id;
521 int nrbufs = obj->ioo_bufcnt;
522 struct ost_prolong_data opd;
525 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
529 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
530 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
531 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
533 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
534 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
535 opd.opd_policy.l_extent.end);
537 if (oa->o_valid & OBD_MD_FLHANDLE) {
538 struct ldlm_lock *lock;
540 lock = ldlm_handle2lock(&oa->o_handle);
542 ost_prolong_locks_iter(lock, &opd);
549 ldlm_resource_iterate(exp->exp_obd->obd_namespace, &res_id,
550 ost_prolong_locks_iter, &opd);
555 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
557 struct ptlrpc_bulk_desc *desc = NULL;
558 struct obd_export *exp = req->rq_export;
559 struct niobuf_remote *remote_nb;
560 struct niobuf_local *local_nb;
561 struct obd_ioobj *ioo;
562 struct ost_body *body, *repbody;
563 struct lustre_capa *capa = NULL;
564 struct l_wait_info lwi;
565 struct lustre_handle lockh = { 0 };
566 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
567 int objcount, niocount, npages, nob = 0, rc, i;
571 req->rq_bulk_read = 1;
573 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
574 GOTO(out, rc = -EIO);
576 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
578 /* Check if there is eviction in progress, and if so, wait for it to
580 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
581 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
582 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
583 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
587 GOTO(out, rc = -ENOTCONN);
589 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
590 lustre_swab_ost_body);
592 CERROR("Missing/short ost_body\n");
593 GOTO(out, rc = -EFAULT);
596 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
599 CERROR("Missing/short ioobj\n");
600 GOTO(out, rc = -EFAULT);
603 CERROR("too many ioobjs (%d)\n", objcount);
604 GOTO(out, rc = -EFAULT);
607 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*ioo),
608 lustre_swab_obd_ioobj);
610 CERROR("Missing/short ioobj\n");
611 GOTO(out, rc = -EFAULT);
614 niocount = ioo->ioo_bufcnt;
615 if (niocount > PTLRPC_MAX_BRW_PAGES) {
616 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
618 GOTO(out, rc = -EFAULT);
621 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
622 niocount * sizeof(*remote_nb),
623 lustre_swab_niobuf_remote);
624 if (remote_nb == NULL) {
625 CERROR("Missing/short niobuf\n");
626 GOTO(out, rc = -EFAULT);
628 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
629 for (i = 1; i < niocount; i++)
630 lustre_swab_niobuf_remote (&remote_nb[i]);
633 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
634 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
636 rc = lustre_pack_reply(req, 2, size, NULL);
641 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
644 local_nb = ost_tls(req)->local;
646 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
651 * If getting the lock took more time than
652 * client was willing to wait, drop it. b=11330
654 if (cfs_time_current_sec() > req->rq_deadline ||
655 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
657 CERROR("Dropping timed-out read from %s because locking"
658 "object "LPX64" took %ld seconds (limit was %ld).\n",
659 libcfs_id2str(req->rq_peer), ioo->ioo_id,
660 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
661 req->rq_deadline - req->rq_arrival_time.tv_sec);
662 GOTO(out_lock, rc = -ETIMEDOUT);
665 npages = OST_THREAD_POOL_SIZE;
666 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
667 remote_nb, &npages, local_nb, oti, capa);
671 desc = ptlrpc_prep_bulk_exp(req, npages,
672 BULK_PUT_SOURCE, OST_BULK_PORTAL);
673 if (desc == NULL) /* XXX: check all cleanup stuff */
674 GOTO(out, rc = -ENOMEM);
676 ost_prolong_locks(exp, ioo, remote_nb, &body->oa, LCK_PW | LCK_PR);
679 for (i = 0; i < npages; i++) {
680 int page_rc = local_nb[i].rc;
682 if (page_rc < 0) { /* error */
688 if (page_rc != 0) { /* some data! */
689 LASSERT (local_nb[i].page != NULL);
690 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
691 local_nb[i].offset & ~CFS_PAGE_MASK,
695 if (page_rc != local_nb[i].len) { /* short read */
696 /* All subsequent pages should be 0 */
698 LASSERT(local_nb[i].rc == 0);
703 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
704 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
706 if (body->oa.o_valid & OBD_MD_FLFLAGS)
707 cksum_type = cksum_type_unpack(body->oa.o_flags);
708 body->oa.o_flags = cksum_type_pack(cksum_type);
709 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
710 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
711 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
713 body->oa.o_valid = 0;
715 /* We're finishing using body->oa as an input variable */
717 /* Check if client was evicted while we were doing i/o before touching
720 /* Check if there is eviction in progress, and if so, wait for
722 if (unlikely(atomic_read(&exp->exp_obd->
723 obd_evict_inprogress))) {
724 lwi = LWI_INTR(NULL, NULL);
725 rc = l_wait_event(exp->exp_obd->
726 obd_evict_inprogress_waitq,
727 !atomic_read(&exp->exp_obd->
728 obd_evict_inprogress),
734 sptlrpc_svc_wrap_bulk(req, desc);
736 rc = ptlrpc_start_bulk_transfer(desc);
740 time_t start = cfs_time_current_sec();
742 long timeoutl = req->rq_deadline -
743 cfs_time_current_sec();
744 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
745 CFS_TICK : cfs_time_seconds(timeoutl);
746 lwi = LWI_TIMEOUT_INTERVAL(timeout,
750 rc = l_wait_event(desc->bd_waitq,
751 !ptlrpc_bulk_active(desc) ||
752 exp->exp_failed, &lwi);
753 LASSERT(rc == 0 || rc == -ETIMEDOUT);
754 /* Wait again if we changed deadline */
755 } while ((rc == -ETIMEDOUT) &&
756 (req->rq_deadline > cfs_time_current_sec()));
758 if (rc == -ETIMEDOUT) {
759 DEBUG_REQ(D_ERROR, req,
760 "timeout on bulk PUT after %ld%+lds",
761 req->rq_deadline - start,
762 cfs_time_current_sec() -
764 ptlrpc_abort_bulk(desc);
765 } else if (exp->exp_failed) {
766 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
768 ptlrpc_abort_bulk(desc);
769 } else if (!desc->bd_success ||
770 desc->bd_nob_transferred != desc->bd_nob) {
771 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
773 "truncated" : "network error on",
774 desc->bd_nob_transferred,
776 /* XXX should this be a different errno? */
780 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
785 /* Must commit after prep above in all cases */
786 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
787 remote_nb, npages, local_nb, oti, rc);
790 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
792 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
796 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
799 ptlrpc_free_bulk(desc);
803 req->rq_status = nob;
804 ptlrpc_lprocfs_brw(req, nob);
805 target_committed_to_req(req);
807 } else if (!no_reply) {
808 /* Only reply if there was no comms problem with bulk */
809 target_committed_to_req(req);
813 /* reply out callback would free */
814 ptlrpc_req_drop_rs(req);
815 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
816 "client will retry\n",
817 exp->exp_obd->obd_name,
818 exp->exp_client_uuid.uuid,
819 exp->exp_connection->c_remote_uuid.uuid,
820 libcfs_id2str(req->rq_peer));
826 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
828 struct ptlrpc_bulk_desc *desc = NULL;
829 struct obd_export *exp = req->rq_export;
830 struct niobuf_remote *remote_nb;
831 struct niobuf_local *local_nb;
832 struct obd_ioobj *ioo;
833 struct ost_body *body, *repbody;
834 struct l_wait_info lwi;
835 struct lustre_handle lockh = {0};
836 struct lustre_capa *capa = NULL;
838 __u32 size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
839 int objcount, niocount, npages;
841 obd_count client_cksum = 0, server_cksum = 0;
842 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
846 req->rq_bulk_write = 1;
848 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
849 GOTO(out, rc = -EIO);
850 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
851 GOTO(out, rc = -EFAULT);
853 /* pause before transaction has been started */
854 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
856 /* Check if there is eviction in progress, and if so, wait for it to
858 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
859 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
860 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
861 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
865 GOTO(out, rc = -ENOTCONN);
867 swab = lustre_msg_swabbed(req->rq_reqmsg);
868 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
869 lustre_swab_ost_body);
871 CERROR("Missing/short ost_body\n");
872 GOTO(out, rc = -EFAULT);
875 lustre_set_req_swabbed(req, REQ_REC_OFF + 1);
876 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
879 CERROR("Missing/short ioobj\n");
880 GOTO(out, rc = -EFAULT);
883 CERROR("too many ioobjs (%d)\n", objcount);
884 GOTO(out, rc = -EFAULT);
887 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
888 objcount * sizeof(*ioo));
889 LASSERT (ioo != NULL);
890 for (niocount = i = 0; i < objcount; i++) {
892 lustre_swab_obd_ioobj(&ioo[i]);
893 if (ioo[i].ioo_bufcnt == 0) {
894 CERROR("ioo[%d] has zero bufcnt\n", i);
895 GOTO(out, rc = -EFAULT);
897 niocount += ioo[i].ioo_bufcnt;
900 if (niocount > PTLRPC_MAX_BRW_PAGES) {
901 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
903 GOTO(out, rc = -EFAULT);
906 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
907 niocount * sizeof(*remote_nb),
908 lustre_swab_niobuf_remote);
909 if (remote_nb == NULL) {
910 CERROR("Missing/short niobuf\n");
911 GOTO(out, rc = -EFAULT);
913 if (swab) { /* swab the remaining niobufs */
914 for (i = 1; i < niocount; i++)
915 lustre_swab_niobuf_remote (&remote_nb[i]);
918 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
919 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
921 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
922 rc = lustre_pack_reply(req, 3, size, NULL);
925 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, obd_fail_val);
926 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
927 niocount * sizeof(*rcs));
930 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
933 local_nb = ost_tls(req)->local;
935 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
940 * If getting the lock took more time than
941 * client was willing to wait, drop it. b=11330
943 if (cfs_time_current_sec() > req->rq_deadline ||
944 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
946 CERROR("Dropping timed-out write from %s because locking "
947 "object "LPX64" took %ld seconds (limit was %ld).\n",
948 libcfs_id2str(req->rq_peer), ioo->ioo_id,
949 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
950 req->rq_deadline - req->rq_arrival_time.tv_sec);
951 GOTO(out_lock, rc = -ETIMEDOUT);
954 ost_prolong_locks(exp, ioo, remote_nb,&body->oa, LCK_PW);
956 /* obd_preprw clobbers oa->valid, so save what we need */
957 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
958 client_cksum = body->oa.o_cksum;
959 if (body->oa.o_valid & OBD_MD_FLFLAGS)
960 cksum_type = cksum_type_unpack(body->oa.o_flags);
963 /* Because we already sync grant info with client when reconnect,
964 * grant info will be cleared for resent req, then fed_grant and
965 * total_grant will not be modified in following preprw_write */
966 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
967 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
968 body->oa.o_valid &= ~OBD_MD_FLGRANT;
971 npages = OST_THREAD_POOL_SIZE;
972 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
973 ioo, remote_nb, &npages, local_nb, oti, capa);
977 desc = ptlrpc_prep_bulk_exp(req, npages,
978 BULK_GET_SINK, OST_BULK_PORTAL);
980 GOTO(out, rc = -ENOMEM);
982 /* NB Having prepped, we must commit... */
984 for (i = 0; i < npages; i++)
985 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
986 local_nb[i].offset & ~CFS_PAGE_MASK,
989 /* Check if client was evicted while we were doing i/o before touching
991 if (desc->bd_export->exp_failed)
994 rc = ptlrpc_start_bulk_transfer (desc);
996 time_t start = cfs_time_current_sec();
998 long timeoutl = req->rq_deadline -
999 cfs_time_current_sec();
1000 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
1001 CFS_TICK : cfs_time_seconds(timeoutl);
1002 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
1003 ost_bulk_timeout, desc);
1004 rc = l_wait_event(desc->bd_waitq,
1005 !ptlrpc_bulk_active(desc) ||
1006 desc->bd_export->exp_failed, &lwi);
1007 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1008 /* Wait again if we changed deadline */
1009 } while ((rc == -ETIMEDOUT) &&
1010 (req->rq_deadline > cfs_time_current_sec()));
1012 if (rc == -ETIMEDOUT) {
1013 DEBUG_REQ(D_ERROR, req,
1014 "timeout on bulk GET after %ld%+lds",
1015 req->rq_deadline - start,
1016 cfs_time_current_sec() -
1018 ptlrpc_abort_bulk(desc);
1019 } else if (desc->bd_export->exp_failed) {
1020 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1022 ptlrpc_abort_bulk(desc);
1023 } else if (!desc->bd_success ||
1024 desc->bd_nob_transferred != desc->bd_nob) {
1025 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1027 "truncated" : "network error on",
1028 desc->bd_nob_transferred, desc->bd_nob);
1029 /* XXX should this be a different errno? */
1033 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1038 sptlrpc_svc_unwrap_bulk(req, desc);
1040 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1042 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1044 if (unlikely(client_cksum != 0 && rc == 0)) {
1045 static int cksum_counter;
1046 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1047 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1048 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1049 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1050 repbody->oa.o_cksum = server_cksum;
1052 if (unlikely(client_cksum != server_cksum)) {
1053 CERROR("client csum %x, server csum %x\n",
1054 client_cksum, server_cksum);
1056 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1057 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1058 cksum_counter, libcfs_id2str(req->rq_peer),
1063 /* Must commit after prep above in all cases */
1064 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1065 remote_nb, npages, local_nb, oti, rc);
1067 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1068 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1073 if (new_cksum == server_cksum)
1074 msg = "changed in transit before arrival at OST";
1075 else if (new_cksum == client_cksum)
1076 msg = "initial checksum before message complete";
1078 msg = "changed in transit AND after initial checksum";
1080 if (req->rq_peer.nid == desc->bd_sender) {
1084 router = libcfs_nid2str(desc->bd_sender);
1087 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1088 "%s%s%s inum "LPU64"/"LPU64" object "
1089 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1090 exp->exp_obd->obd_name, msg,
1091 libcfs_id2str(req->rq_peer),
1093 body->oa.o_valid & OBD_MD_FLFID ?
1094 body->oa.o_fid : (__u64)0,
1095 body->oa.o_valid & OBD_MD_FLFID ?
1096 body->oa.o_generation :(__u64)0,
1098 body->oa.o_valid & OBD_MD_FLGROUP ?
1099 body->oa.o_gr : (__u64)0,
1101 local_nb[npages-1].offset +
1102 local_nb[npages-1].len - 1 );
1103 CERROR("client csum %x, original server csum %x, "
1104 "server csum now %x\n",
1105 client_cksum, server_cksum, new_cksum);
1111 /* set per-requested niobuf return codes */
1112 for (i = j = 0; i < niocount; i++) {
1113 int len = remote_nb[i].len;
1118 LASSERT(j < npages);
1119 if (local_nb[j].rc < 0)
1120 rcs[i] = local_nb[j].rc;
1121 len -= local_nb[j].len;
1126 LASSERT(j == npages);
1127 ptlrpc_lprocfs_brw(req, nob);
1131 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1134 ptlrpc_free_bulk(desc);
1137 oti_to_request(oti, req);
1138 target_committed_to_req(req);
1139 rc = ptlrpc_reply(req);
1140 } else if (!no_reply) {
1141 /* Only reply if there was no comms problem with bulk */
1142 target_committed_to_req(req);
1143 req->rq_status = rc;
1146 /* reply out callback would free */
1147 ptlrpc_req_drop_rs(req);
1148 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1149 "client will retry\n",
1150 exp->exp_obd->obd_name,
1151 exp->exp_client_uuid.uuid,
1152 exp->exp_connection->c_remote_uuid.uuid,
1153 libcfs_id2str(req->rq_peer));
1158 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1160 char *key, *val = NULL;
1161 int keylen, vallen, rc = 0;
1164 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1166 DEBUG_REQ(D_HA, req, "no set_info key");
1169 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1171 rc = lustre_pack_reply(req, 1, NULL, NULL);
1175 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1177 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
1179 if (KEY_IS(KEY_EVICT_BY_NID)) {
1181 obd_export_evict_by_nid(exp->exp_obd, val);
1186 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1188 lustre_msg_set_status(req->rq_repmsg, 0);
1192 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1195 int keylen, replylen, rc = 0;
1196 struct req_capsule *pill = &req->rq_pill;
1199 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
1201 /* this common part for get_info rpc */
1202 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1204 DEBUG_REQ(D_HA, req, "no get_info key");
1207 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1209 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1213 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1214 RCL_SERVER, replylen);
1216 rc = req_capsule_server_pack(pill);
1220 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1224 /* call again to fill in the reply buffer */
1225 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1227 lustre_msg_set_status(req->rq_repmsg, 0);
1231 static int ost_handle_quotactl(struct ptlrpc_request *req)
1233 struct obd_quotactl *oqctl, *repoqc;
1234 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) };
1238 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1239 lustre_swab_obd_quotactl);
1241 GOTO(out, rc = -EPROTO);
1243 rc = lustre_pack_reply(req, 2, size, NULL);
1247 repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc));
1249 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1255 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1257 struct obd_quotactl *oqctl;
1261 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1265 rc = req_capsule_server_pack(&req->rq_pill);
1267 CERROR("ost: out of memory while packing quotacheck reply\n");
1271 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1275 static int ost_llog_handle_connect(struct obd_export *exp,
1276 struct ptlrpc_request *req)
1278 struct llogd_conn_body *body;
1282 body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body));
1283 rc = obd_llog_connect(exp, body);
1287 static int filter_export_check_flavor(struct filter_obd *filter,
1288 struct obd_export *exp,
1289 struct ptlrpc_request *req)
1294 * this should be done in filter_connect()/filter_reconnect(), but
1295 * we can't obtain information like NID, which stored in incoming
1296 * request, thus can't decide what flavor to use. so we do it here.
1298 * This hack should be removed after the OST stack be rewritten, just
1299 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1301 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_INVALID)
1304 CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from));
1305 spin_lock(&exp->exp_lock);
1306 exp->exp_sp_peer = req->rq_sp_from;
1308 read_lock(&filter->fo_sptlrpc_lock);
1309 sptlrpc_rule_set_choose(&filter->fo_sptlrpc_rset, exp->exp_sp_peer,
1310 req->rq_peer.nid, &exp->exp_flvr);
1311 read_unlock(&filter->fo_sptlrpc_lock);
1313 if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1314 CERROR("invalid rpc flavor %x, expect %x, from %s\n",
1315 req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
1316 libcfs_nid2str(req->rq_peer.nid));
1317 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID;
1321 spin_unlock(&exp->exp_lock);
1326 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1327 struct obd_device *obd, int *process)
1329 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1330 case OST_CONNECT: /* This will never get here, but for completeness. */
1331 case OST_DISCONNECT:
1342 case OBD_LOG_CANCEL:
1344 *process = target_queue_recovery_request(req, obd);
1348 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1354 int ost_msg_check_version(struct lustre_msg *msg)
1358 switch(lustre_msg_get_opc(msg)) {
1360 case OST_DISCONNECT:
1363 case SEC_CTX_INIT_CONT:
1365 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1367 CERROR("bad opc %u version %08x, expecting %08x\n",
1368 lustre_msg_get_opc(msg),
1369 lustre_msg_get_version(msg),
1370 LUSTRE_OBD_VERSION);
1383 case OST_QUOTACHECK:
1385 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1387 CERROR("bad opc %u version %08x, expecting %08x\n",
1388 lustre_msg_get_opc(msg),
1389 lustre_msg_get_version(msg),
1390 LUSTRE_OST_VERSION);
1395 case LDLM_BL_CALLBACK:
1396 case LDLM_CP_CALLBACK:
1397 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1399 CERROR("bad opc %u version %08x, expecting %08x\n",
1400 lustre_msg_get_opc(msg),
1401 lustre_msg_get_version(msg),
1402 LUSTRE_DLM_VERSION);
1404 case LLOG_ORIGIN_CONNECT:
1405 case OBD_LOG_CANCEL:
1406 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1408 CERROR("bad opc %u version %08x, expecting %08x\n",
1409 lustre_msg_get_opc(msg),
1410 lustre_msg_get_version(msg),
1411 LUSTRE_LOG_VERSION);
1414 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1420 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1421 int ost_handle(struct ptlrpc_request *req)
1423 struct obd_trans_info trans_info = { 0, };
1424 struct obd_trans_info *oti = &trans_info;
1425 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1426 struct obd_device *obd = NULL;
1429 LASSERT(current->journal_info == NULL);
1431 /* primordial rpcs don't affect server recovery */
1432 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1434 case SEC_CTX_INIT_CONT:
1439 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1441 /* XXX identical to MDS */
1442 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1445 if (req->rq_export == NULL) {
1446 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1447 lustre_msg_get_opc(req->rq_reqmsg),
1448 libcfs_id2str(req->rq_peer));
1449 req->rq_status = -ENOTCONN;
1450 GOTO(out, rc = -ENOTCONN);
1453 obd = req->rq_export->exp_obd;
1455 /* Check for aborted recovery. */
1456 spin_lock_bh(&obd->obd_processing_task_lock);
1457 recovering = obd->obd_recovering;
1458 spin_unlock_bh(&obd->obd_processing_task_lock);
1460 rc = ost_filter_recovery_request(req, obd,
1462 if (rc || !should_process)
1464 else if (should_process < 0) {
1465 req->rq_status = should_process;
1466 rc = ptlrpc_error(req);
1474 rc = ost_msg_check_version(req->rq_reqmsg);
1478 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1480 CDEBUG(D_INODE, "connect\n");
1481 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
1482 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
1484 rc = target_handle_connect(req);
1485 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
1488 struct obd_export *exp = req->rq_export;
1492 rc = filter_export_check_flavor(&obd->u.filter,
1497 case OST_DISCONNECT:
1498 CDEBUG(D_INODE, "disconnect\n");
1499 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
1500 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
1502 rc = target_handle_disconnect(req);
1505 CDEBUG(D_INODE, "create\n");
1506 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
1508 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1509 GOTO(out, rc = -ENOSPC);
1510 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1511 GOTO(out, rc = -EROFS);
1512 rc = ost_create(req->rq_export, req, oti);
1515 CDEBUG(D_INODE, "destroy\n");
1516 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
1518 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1519 GOTO(out, rc = -EROFS);
1520 rc = ost_destroy(req->rq_export, req, oti);
1523 CDEBUG(D_INODE, "getattr\n");
1524 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
1526 rc = ost_getattr(req->rq_export, req);
1529 CDEBUG(D_INODE, "setattr\n");
1530 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
1532 rc = ost_setattr(req->rq_export, req, oti);
1535 CDEBUG(D_INODE, "write\n");
1536 /* req->rq_request_portal would be nice, if it was set */
1537 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1538 CERROR("%s: deny write request from %s to portal %u\n",
1539 req->rq_export->exp_obd->obd_name,
1540 obd_export_nid2str(req->rq_export),
1541 req->rq_rqbd->rqbd_service->srv_req_portal);
1542 GOTO(out, rc = -EPROTO);
1544 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1546 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1547 GOTO(out, rc = -ENOSPC);
1548 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1549 GOTO(out, rc = -EROFS);
1550 rc = ost_brw_write(req, oti);
1551 LASSERT(current->journal_info == NULL);
1552 /* ost_brw_write sends its own replies */
1555 CDEBUG(D_INODE, "read\n");
1556 /* req->rq_request_portal would be nice, if it was set */
1557 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1558 CERROR("%s: deny read request from %s to portal %u\n",
1559 req->rq_export->exp_obd->obd_name,
1560 obd_export_nid2str(req->rq_export),
1561 req->rq_rqbd->rqbd_service->srv_req_portal);
1562 GOTO(out, rc = -EPROTO);
1564 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1566 rc = ost_brw_read(req, oti);
1567 LASSERT(current->journal_info == NULL);
1568 /* ost_brw_read sends its own replies */
1571 CDEBUG(D_INODE, "punch\n");
1572 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
1574 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1575 GOTO(out, rc = -EROFS);
1576 rc = ost_punch(req->rq_export, req, oti);
1579 CDEBUG(D_INODE, "statfs\n");
1580 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
1582 rc = ost_statfs(req);
1585 CDEBUG(D_INODE, "sync\n");
1586 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
1588 rc = ost_sync(req->rq_export, req);
1591 DEBUG_REQ(D_INODE, req, "set_info");
1592 req_capsule_set(&req->rq_pill, &RQF_OST_SET_INFO);
1593 rc = ost_set_info(req->rq_export, req);
1596 DEBUG_REQ(D_INODE, req, "get_info");
1597 rc = ost_get_info(req->rq_export, req);
1599 case OST_QUOTACHECK:
1600 CDEBUG(D_INODE, "quotacheck\n");
1601 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
1602 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
1604 rc = ost_handle_quotacheck(req);
1607 CDEBUG(D_INODE, "quotactl\n");
1608 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
1609 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
1611 rc = ost_handle_quotactl(req);
1614 DEBUG_REQ(D_INODE, req, "ping");
1615 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
1616 rc = target_handle_ping(req);
1618 /* FIXME - just reply status */
1619 case LLOG_ORIGIN_CONNECT:
1620 DEBUG_REQ(D_INODE, req, "log connect");
1621 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
1622 rc = ost_llog_handle_connect(req->rq_export, req);
1623 req->rq_status = rc;
1624 rc = req_capsule_server_pack(&req->rq_pill);
1627 RETURN(ptlrpc_reply(req));
1628 case OBD_LOG_CANCEL:
1629 CDEBUG(D_INODE, "log cancel\n");
1630 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
1631 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
1633 rc = llog_origin_handle_cancel(req);
1634 req->rq_status = rc;
1635 rc = req_capsule_server_pack(&req->rq_pill);
1638 RETURN(ptlrpc_reply(req));
1640 CDEBUG(D_INODE, "enqueue\n");
1641 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
1642 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
1644 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1645 ldlm_server_blocking_ast,
1646 ldlm_server_glimpse_ast);
1647 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1650 CDEBUG(D_INODE, "convert\n");
1651 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
1652 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
1654 rc = ldlm_handle_convert(req);
1657 CDEBUG(D_INODE, "cancel\n");
1658 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
1659 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
1661 rc = ldlm_handle_cancel(req);
1663 case LDLM_BL_CALLBACK:
1664 case LDLM_CP_CALLBACK:
1665 CDEBUG(D_INODE, "callback\n");
1666 CERROR("callbacks should not happen on OST\n");
1669 CERROR("Unexpected opcode %d\n",
1670 lustre_msg_get_opc(req->rq_reqmsg));
1671 req->rq_status = -ENOTSUPP;
1672 rc = ptlrpc_error(req);
1676 LASSERT(current->journal_info == NULL);
1679 /* If we're DISCONNECTing, the export_data is already freed */
1680 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
1681 target_committed_to_req(req);
1685 oti_to_request(oti, req);
1687 target_send_reply(req, rc, fail);
1690 EXPORT_SYMBOL(ost_handle);
1692 * free per-thread pool created by ost_thread_init().
1694 static void ost_thread_done(struct ptlrpc_thread *thread)
1696 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
1701 LASSERT(thread != NULL);
1704 * be prepared to handle partially-initialized pools (because this is
1705 * called from ost_thread_init() for cleanup.
1707 tls = thread->t_data;
1710 thread->t_data = NULL;
1716 * initialize per-thread page pool (bug 5137).
1718 static int ost_thread_init(struct ptlrpc_thread *thread)
1720 struct ost_thread_local_cache *tls;
1724 LASSERT(thread != NULL);
1725 LASSERT(thread->t_data == NULL);
1726 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
1731 thread->t_data = tls;
1735 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
1737 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
1738 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
1740 struct ost_obd *ost = &obd->u.ost;
1741 struct lprocfs_static_vars lvars;
1742 int oss_min_threads;
1743 int oss_max_threads;
1744 int oss_min_create_threads;
1745 int oss_max_create_threads;
1749 rc = cleanup_group_info();
1753 lprocfs_ost_init_vars(&lvars);
1754 lprocfs_obd_setup(obd, lvars.obd_vars);
1756 sema_init(&ost->ost_health_sem, 1);
1758 if (oss_num_threads) {
1759 /* If oss_num_threads is set, it is the min and the max. */
1760 if (oss_num_threads > OSS_THREADS_MAX)
1761 oss_num_threads = OSS_THREADS_MAX;
1762 if (oss_num_threads < OSS_THREADS_MIN)
1763 oss_num_threads = OSS_THREADS_MIN;
1764 oss_max_threads = oss_min_threads = oss_num_threads;
1766 /* Base min threads on memory and cpus */
1767 oss_min_threads = num_possible_cpus() * num_physpages >>
1768 (27 - CFS_PAGE_SHIFT);
1769 if (oss_min_threads < OSS_THREADS_MIN)
1770 oss_min_threads = OSS_THREADS_MIN;
1771 /* Insure a 4x range for dynamic threads */
1772 if (oss_min_threads > OSS_THREADS_MAX / 4)
1773 oss_min_threads = OSS_THREADS_MAX / 4;
1774 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4);
1778 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1779 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
1780 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1781 ost_handle, LUSTRE_OSS_NAME,
1782 obd->obd_proc_entry, target_print_req,
1783 oss_min_threads, oss_max_threads,
1784 "ll_ost", LCT_DT_THREAD);
1785 if (ost->ost_service == NULL) {
1786 CERROR("failed to start service\n");
1787 GOTO(out_lprocfs, rc = -ENOMEM);
1790 rc = ptlrpc_start_threads(obd, ost->ost_service);
1792 GOTO(out_service, rc = -EINVAL);
1794 if (oss_num_create_threads) {
1795 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
1796 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
1797 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
1798 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
1799 oss_min_create_threads = oss_max_create_threads =
1800 oss_num_create_threads;
1802 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
1803 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
1806 ost->ost_create_service =
1807 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1808 OST_MAXREPSIZE, OST_CREATE_PORTAL,
1809 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1810 ost_handle, "ost_create",
1811 obd->obd_proc_entry, target_print_req,
1812 oss_min_create_threads, oss_max_create_threads,
1813 "ll_ost_creat", LCT_DT_THREAD);
1814 if (ost->ost_create_service == NULL) {
1815 CERROR("failed to start OST create service\n");
1816 GOTO(out_service, rc = -ENOMEM);
1819 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
1821 GOTO(out_create, rc = -EINVAL);
1823 ost->ost_io_service =
1824 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1825 OST_MAXREPSIZE, OST_IO_PORTAL,
1826 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1827 ost_handle, "ost_io",
1828 obd->obd_proc_entry, target_print_req,
1829 oss_min_threads, oss_max_threads,
1830 "ll_ost_io", LCT_DT_THREAD);
1831 if (ost->ost_io_service == NULL) {
1832 CERROR("failed to start OST I/O service\n");
1833 GOTO(out_create, rc = -ENOMEM);
1836 ost->ost_io_service->srv_init = ost_thread_init;
1837 ost->ost_io_service->srv_done = ost_thread_done;
1838 ost->ost_io_service->srv_cpu_affinity = 1;
1839 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
1841 GOTO(out_io, rc = -EINVAL);
1843 ping_evictor_start();
1848 ptlrpc_unregister_service(ost->ost_io_service);
1849 ost->ost_io_service = NULL;
1851 ptlrpc_unregister_service(ost->ost_create_service);
1852 ost->ost_create_service = NULL;
1854 ptlrpc_unregister_service(ost->ost_service);
1855 ost->ost_service = NULL;
1857 lprocfs_obd_cleanup(obd);
1861 static int ost_cleanup(struct obd_device *obd)
1863 struct ost_obd *ost = &obd->u.ost;
1867 ping_evictor_stop();
1869 spin_lock_bh(&obd->obd_processing_task_lock);
1870 if (obd->obd_recovering) {
1871 target_cancel_recovery_timer(obd);
1872 obd->obd_recovering = 0;
1874 spin_unlock_bh(&obd->obd_processing_task_lock);
1876 down(&ost->ost_health_sem);
1877 ptlrpc_unregister_service(ost->ost_service);
1878 ptlrpc_unregister_service(ost->ost_create_service);
1879 ptlrpc_unregister_service(ost->ost_io_service);
1880 ost->ost_service = NULL;
1881 ost->ost_create_service = NULL;
1882 up(&ost->ost_health_sem);
1884 lprocfs_obd_cleanup(obd);
1889 static int ost_health_check(struct obd_device *obd)
1891 struct ost_obd *ost = &obd->u.ost;
1894 down(&ost->ost_health_sem);
1895 rc |= ptlrpc_service_health_check(ost->ost_service);
1896 rc |= ptlrpc_service_health_check(ost->ost_create_service);
1897 rc |= ptlrpc_service_health_check(ost->ost_io_service);
1898 up(&ost->ost_health_sem);
1901 * health_check to return 0 on healthy
1902 * and 1 on unhealthy.
1910 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
1912 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
1915 /* use obd ops to offer management infrastructure */
1916 static struct obd_ops ost_obd_ops = {
1917 .o_owner = THIS_MODULE,
1918 .o_setup = ost_setup,
1919 .o_cleanup = ost_cleanup,
1920 .o_health_check = ost_health_check,
1924 static int __init ost_init(void)
1926 struct lprocfs_static_vars lvars;
1930 lprocfs_ost_init_vars(&lvars);
1931 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
1932 LUSTRE_OSS_NAME, NULL);
1934 if (ost_num_threads != 0 && oss_num_threads == 0) {
1935 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
1936 "use oss_num_threads instead or unset both for "
1937 "dynamic thread startup\n");
1938 oss_num_threads = ost_num_threads;
1944 static void /*__exit*/ ost_exit(void)
1946 class_unregister_type(LUSTRE_OSS_NAME);
1949 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
1950 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
1951 MODULE_LICENSE("GPL");
1953 module_init(ost_init);
1954 module_exit(ost_exit);