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>
49 #include <lustre_net.h>
50 #include <lustre_dlm.h>
51 #include <lustre_export.h>
52 #include <lustre_debug.h>
53 #include <linux/init.h>
54 #include <lprocfs_status.h>
55 #include <libcfs/list.h>
56 #include <lustre_quota.h>
57 #include <lustre_log.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 __u64 versions[PTLRPC_NUM_VERSIONS] = { 0 };
82 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
83 versions[0] = oti->oti_pre_version;
84 lustre_msg_set_versions(req->rq_repmsg, versions);
86 req->rq_transno = oti->oti_transno;
88 /* XXX 4 == entries in oti_ack_locks??? */
89 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
92 /* XXX not even calling target_send_reply in some cases... */
93 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode);
97 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
98 struct obd_trans_info *oti)
100 struct ost_body *body, *repbody;
101 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
105 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
106 lustre_swab_ost_body);
110 if (body->oa.o_id == 0)
113 if (lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1)) {
114 struct ldlm_request *dlm;
115 dlm = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*dlm),
116 lustre_swab_ldlm_request);
119 ldlm_request_cancel(req, dlm, 0);
122 rc = lustre_pack_reply(req, 2, size, NULL);
126 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
127 oti->oti_logcookies = &body->oa.o_lcookie;
128 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
130 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
131 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL);
135 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
137 struct ost_body *body, *repbody;
138 struct obd_info oinfo = { { { 0 } } };
139 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
143 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
144 lustre_swab_ost_body);
148 rc = lustre_pack_reply(req, 2, size, NULL);
152 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
154 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
156 oinfo.oi_oa = &repbody->oa;
157 req->rq_status = obd_getattr(exp, &oinfo);
161 static int ost_statfs(struct ptlrpc_request *req)
163 struct obd_statfs *osfs;
164 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*osfs) };
168 rc = lustre_pack_reply(req, 2, size, NULL);
172 osfs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*osfs));
174 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
175 cfs_time_current_64() - HZ, 0);
176 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
177 osfs->os_bfree = osfs->os_bavail = 64;
178 if (req->rq_status != 0)
179 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
184 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
185 struct obd_trans_info *oti)
187 struct ost_body *body, *repbody;
188 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
192 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
193 lustre_swab_ost_body);
197 rc = lustre_pack_reply(req, 2, size, NULL);
201 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
203 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
204 oti->oti_logcookies = &repbody->oa.o_lcookie;
205 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
206 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
211 * Helper function for ost_punch(): if asked by client, acquire [size, EOF]
212 * lock on the file being truncated.
214 static int ost_punch_lock_get(struct obd_export *exp, struct obdo *oa,
215 struct lustre_handle *lh)
218 struct ldlm_res_id res_id = { .name = { oa->o_id } };
219 ldlm_policy_data_t policy;
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 /* ost_body is varified and swabbed in ost_hpreq_handler() */
286 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
287 LASSERT(body != NULL);
289 oinfo.oi_oa = &body->oa;
290 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
291 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
293 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
294 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
297 rc = lustre_pack_reply(req, 2, size, NULL);
301 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
303 rc = ost_punch_lock_get(exp, oinfo.oi_oa, &lh);
305 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
306 oinfo.oi_oa->o_flags == OBD_FL_TRUNCLOCK)
308 * If OBD_FL_TRUNCLOCK is the only bit set in
309 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
310 * through filter_setattr() to filter_iocontrol().
312 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
314 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
315 ost_punch_lock_put(exp, oinfo.oi_oa, &lh);
317 repbody->oa = *oinfo.oi_oa;
321 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
323 struct obd_info oinfo = { { { 0 } } };
324 struct ost_body *body, *repbody;
325 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
329 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
330 lustre_swab_ost_body);
334 rc = lustre_pack_reply(req, 2, size, NULL);
338 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
341 oinfo.oi_oa = &body->oa;
342 req->rq_status = obd_sync(exp, &oinfo, repbody->oa.o_size,
343 repbody->oa.o_blocks, NULL);
344 repbody->oa = *oinfo.oi_oa;
348 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
349 struct obd_trans_info *oti)
351 struct ost_body *body, *repbody;
352 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
354 struct obd_info oinfo = { { { 0 } } };
357 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
358 lustre_swab_ost_body);
362 rc = lustre_pack_reply(req, 2, size, NULL);
366 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
368 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
370 oinfo.oi_oa = &repbody->oa;
371 req->rq_status = obd_setattr(exp, &oinfo, oti);
375 static int ost_bulk_timeout(void *data)
378 /* We don't fail the connection here, because having the export
379 * killed makes the (vital) call to commitrw very sad.
384 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
385 cksum_type_t cksum_type)
390 cksum = init_checksum(cksum_type);
391 for (i = 0; i < desc->bd_iov_count; i++) {
392 struct page *page = desc->bd_iov[i].kiov_page;
393 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
394 char *ptr = kmap(page) + off;
395 int len = desc->bd_iov[i].kiov_len;
397 /* corrupt the data before we compute the checksum, to
398 * simulate a client->OST data error */
399 if (i == 0 && opc == OST_WRITE &&
400 OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_CHECKSUM_RECEIVE))
401 memcpy(ptr, "bad3", min(4, len));
402 cksum = compute_checksum(cksum, ptr, len, cksum_type);
403 /* corrupt the data after we compute the checksum, to
404 * simulate an OST->client data error */
405 if (i == 0 && opc == OST_READ &&
406 OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_CHECKSUM_SEND)) {
407 memcpy(ptr, "bad4", min(4, len));
408 /* nobody should use corrupted page again */
409 ClearPageUptodate(page);
417 static int ost_brw_lock_get(int mode, struct obd_export *exp,
418 struct obd_ioobj *obj, struct niobuf_remote *nb,
419 struct lustre_handle *lh)
422 int nrbufs = obj->ioo_bufcnt;
423 struct ldlm_res_id res_id = { .name = { obj->ioo_id } };
424 ldlm_policy_data_t policy;
429 LASSERT(mode == LCK_PR || mode == LCK_PW);
430 LASSERT(!lustre_handle_is_used(lh));
432 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
435 /* EXPENSIVE ASSERTION */
436 for (i = 1; i < nrbufs; i ++)
437 LASSERT((nb[0].flags & OBD_BRW_SRVLOCK) ==
438 (nb[i].flags & OBD_BRW_SRVLOCK));
440 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
441 policy.l_extent.end = (nb[nrbufs - 1].offset +
442 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
444 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
445 LDLM_EXTENT, &policy, mode, &flags,
446 ldlm_blocking_ast, ldlm_completion_ast,
447 ldlm_glimpse_ast, NULL, 0, NULL, lh));
450 static void ost_brw_lock_put(int mode,
451 struct obd_ioobj *obj, struct niobuf_remote *niob,
452 struct lustre_handle *lh)
455 LASSERT(mode == LCK_PR || mode == LCK_PW);
456 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
457 lustre_handle_is_used(lh));
458 if (lustre_handle_is_used(lh))
459 ldlm_lock_decref(lh, mode);
463 struct ost_prolong_data {
464 struct obd_export *opd_exp;
465 ldlm_policy_data_t opd_policy;
467 ldlm_mode_t opd_mode;
472 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
474 struct ost_prolong_data *opd = data;
476 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
478 if (lock->l_req_mode != lock->l_granted_mode) {
479 /* scan granted locks only */
480 return LDLM_ITER_STOP;
483 if (lock->l_export != opd->opd_exp) {
484 /* prolong locks only for given client */
485 return LDLM_ITER_CONTINUE;
488 if (!(lock->l_granted_mode & opd->opd_mode)) {
489 /* we aren't interesting in all type of locks */
490 return LDLM_ITER_CONTINUE;
493 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
494 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
495 /* the request doesn't cross the lock, skip it */
496 return LDLM_ITER_CONTINUE;
499 /* Fill the obdo with the matched lock handle.
500 * XXX: it is possible in some cases the IO RPC is covered by several
501 * locks, even for the write case, so it may need to be a lock list. */
502 if (opd->opd_oa && !(opd->opd_oa->o_valid & OBD_MD_FLHANDLE)) {
503 opd->opd_oa->o_handle.cookie = lock->l_handle.h_cookie;
504 opd->opd_oa->o_valid |= OBD_MD_FLHANDLE;
507 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
508 /* ignore locks not being cancelled */
509 return LDLM_ITER_CONTINUE;
512 /* OK. this is a possible lock the user holds doing I/O
513 * let's refresh eviction timer for it */
514 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
515 opd->opd_lock_match = 1;
517 return LDLM_ITER_CONTINUE;
520 static int ost_rw_prolong_locks(struct ptlrpc_request *req, struct obd_ioobj *obj,
521 struct niobuf_remote *nb, struct obdo *oa,
526 struct ldlm_res_id res_id = { .name = { obj->ioo_id } };
527 struct ost_prolong_data opd = { 0 };
528 int nrbufs = obj->ioo_bufcnt;
533 opd.opd_exp = req->rq_export;
534 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
535 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
536 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
538 /* prolong locks for the current service time of the corresponding
539 * portal (= OST_IO_PORTAL) */
540 opd.opd_timeout = AT_OFF ? obd_timeout / 2 :
541 max(at_est2timeout(at_get(&req->rq_rqbd->
542 rqbd_service->srv_at_estimate)), ldlm_timeout);
544 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
545 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
546 opd.opd_policy.l_extent.end);
548 if (oa->o_valid & OBD_MD_FLHANDLE) {
549 struct ldlm_lock *lock;
551 lock = ldlm_handle2lock(&oa->o_handle);
553 ost_prolong_locks_iter(lock, &opd);
554 if (opd.opd_lock_match) {
559 /* Check if the lock covers the whole IO region,
560 * otherwise iterate through the resource. */
561 if (lock->l_policy_data.l_extent.end >=
562 opd.opd_policy.l_extent.end &&
563 lock->l_policy_data.l_extent.start <=
564 opd.opd_policy.l_extent.start) {
573 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
574 ost_prolong_locks_iter, &opd);
575 RETURN(opd.opd_lock_match);
578 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
580 struct ptlrpc_bulk_desc *desc = NULL;
581 struct obd_export *exp = req->rq_export;
582 struct niobuf_remote *remote_nb;
583 struct niobuf_local *local_nb;
584 struct obd_ioobj *ioo;
585 struct ost_body *body, *repbody;
586 struct l_wait_info lwi;
587 struct lustre_handle lockh = { 0 };
588 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
589 int niocount, npages, nob = 0, rc, i;
593 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
594 GOTO(out, rc = -EIO);
596 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
598 /* Check if there is eviction in progress, and if so, wait for it to
600 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
601 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
602 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
603 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
607 GOTO(out, rc = -ENOTCONN);
609 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
610 * ost_rw_hpreq_check(). */
611 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
612 LASSERT(body != NULL);
614 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, sizeof(*ioo));
615 LASSERT(ioo != NULL);
617 niocount = ioo->ioo_bufcnt;
618 remote_nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
619 niocount * sizeof(*remote_nb));
620 LASSERT(remote_nb != NULL);
622 rc = lustre_pack_reply(req, 2, size, NULL);
627 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
630 local_nb = ost_tls(req)->local;
632 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
637 * If getting the lock took more time than
638 * client was willing to wait, drop it. b=11330
640 if (cfs_time_current_sec() > req->rq_deadline ||
641 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
643 CERROR("Dropping timed-out read from %s because locking"
644 "object "LPX64" took %ld seconds (limit was %ld).\n",
645 libcfs_id2str(req->rq_peer), ioo->ioo_id,
646 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
647 req->rq_deadline - req->rq_arrival_time.tv_sec);
648 GOTO(out_lock, rc = -ETIMEDOUT);
651 npages = OST_THREAD_POOL_SIZE;
652 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
653 remote_nb, &npages, local_nb, oti);
657 desc = ptlrpc_prep_bulk_exp(req, npages,
658 BULK_PUT_SOURCE, OST_BULK_PORTAL);
659 if (desc == NULL) /* XXX: check all cleanup stuff */
660 GOTO(out, rc = -ENOMEM);
662 ost_rw_prolong_locks(req, ioo, remote_nb, &body->oa, LCK_PW | LCK_PR);
665 for (i = 0; i < npages; i++) {
666 int page_rc = local_nb[i].rc;
668 if (page_rc < 0) { /* error */
674 if (page_rc != 0) { /* some data! */
675 LASSERT (local_nb[i].page != NULL);
676 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
677 local_nb[i].offset & ~CFS_PAGE_MASK,
681 if (page_rc != local_nb[i].len) { /* short read */
682 /* All subsequent pages should be 0 */
684 LASSERT(local_nb[i].rc == 0);
689 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
690 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
692 if (body->oa.o_valid & OBD_MD_FLFLAGS)
693 cksum_type = cksum_type_unpack(body->oa.o_flags);
694 body->oa.o_flags = cksum_type_pack(cksum_type);
695 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
696 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
697 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
699 body->oa.o_valid = 0;
701 /* We're finishing using body->oa as an input variable */
703 /* Check if client was evicted while we were doing i/o before touching
706 /* Check if there is eviction in progress, and if so, wait for
708 if (unlikely(atomic_read(&exp->exp_obd->
709 obd_evict_inprogress))) {
710 lwi = LWI_INTR(NULL, NULL);
711 rc = l_wait_event(exp->exp_obd->
712 obd_evict_inprogress_waitq,
713 !atomic_read(&exp->exp_obd->
714 obd_evict_inprogress),
720 rc = ptlrpc_start_bulk_transfer(desc);
722 time_t start = cfs_time_current_sec();
724 long timeoutl = req->rq_deadline -
725 cfs_time_current_sec();
726 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
727 CFS_TICK : cfs_time_seconds(timeoutl);
728 lwi = LWI_TIMEOUT_INTERVAL(timeout,
732 rc = l_wait_event(desc->bd_waitq,
733 !ptlrpc_server_bulk_active(desc) ||
734 exp->exp_failed, &lwi);
735 LASSERT(rc == 0 || rc == -ETIMEDOUT);
736 /* Wait again if we changed deadline */
737 } while ((rc == -ETIMEDOUT) &&
738 (req->rq_deadline > cfs_time_current_sec()));
740 if (rc == -ETIMEDOUT) {
741 DEBUG_REQ(D_ERROR, req,
742 "timeout on bulk PUT after %ld%+lds",
743 req->rq_deadline - start,
744 cfs_time_current_sec() -
746 ptlrpc_abort_bulk(desc);
747 } else if (exp->exp_failed) {
748 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
750 ptlrpc_abort_bulk(desc);
751 } else if (!desc->bd_success ||
752 desc->bd_nob_transferred != desc->bd_nob) {
753 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
755 "truncated" : "network error on",
756 desc->bd_nob_transferred,
758 /* XXX should this be a different errno? */
762 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
767 /* Must commit after prep above in all cases */
768 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
769 remote_nb, npages, local_nb, oti, rc);
772 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
774 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
778 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
781 ptlrpc_free_bulk(desc);
785 req->rq_status = nob;
786 ptlrpc_lprocfs_brw(req, nob);
787 target_committed_to_req(req);
789 } else if (!no_reply) {
790 /* Only reply if there was no comms problem with bulk */
791 target_committed_to_req(req);
795 /* reply out callback would free */
796 ptlrpc_req_drop_rs(req);
797 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
798 "client will retry\n",
799 exp->exp_obd->obd_name,
800 exp->exp_client_uuid.uuid,
801 exp->exp_connection->c_remote_uuid.uuid,
802 libcfs_id2str(req->rq_peer));
808 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
810 struct ptlrpc_bulk_desc *desc = NULL;
811 struct obd_export *exp = req->rq_export;
812 struct niobuf_remote *remote_nb;
813 struct niobuf_local *local_nb;
814 struct obd_ioobj *ioo;
815 struct ost_body *body, *repbody;
816 struct l_wait_info lwi;
817 struct lustre_handle lockh = {0};
819 __u32 size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
820 int objcount, niocount, npages;
822 obd_count client_cksum = 0, server_cksum = 0;
823 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
827 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
828 GOTO(out, rc = -EIO);
829 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
830 GOTO(out, rc = -EFAULT);
832 /* pause before transaction has been started */
833 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
835 /* Check if there is eviction in progress, and if so, wait for it to
837 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
838 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
839 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
840 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
844 GOTO(out, rc = -ENOTCONN);
846 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
847 * ost_rw_hpreq_check(). */
848 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
849 LASSERT(body != NULL);
851 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
853 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
854 objcount * sizeof(*ioo));
855 LASSERT(ioo != NULL);
856 for (niocount = i = 0; i < objcount; i++)
857 niocount += ioo[i].ioo_bufcnt;
859 remote_nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
860 niocount * sizeof(*remote_nb));
861 LASSERT(remote_nb != NULL);
863 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
864 rc = lustre_pack_reply(req, 3, size, NULL);
868 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, obd_fail_val);
869 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
870 niocount * sizeof(*rcs));
873 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
876 local_nb = ost_tls(req)->local;
878 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
883 * If getting the lock took more time than
884 * client was willing to wait, drop it. b=11330
886 if (cfs_time_current_sec() > req->rq_deadline ||
887 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
889 CERROR("Dropping timed-out write from %s because locking "
890 "object "LPX64" took %ld seconds (limit was %ld).\n",
891 libcfs_id2str(req->rq_peer), ioo->ioo_id,
892 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
893 req->rq_deadline - req->rq_arrival_time.tv_sec);
894 GOTO(out_lock, rc = -ETIMEDOUT);
897 ost_rw_prolong_locks(req, ioo, remote_nb,&body->oa, LCK_PW);
899 /* obd_preprw clobbers oa->valid, so save what we need */
900 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
901 client_cksum = body->oa.o_cksum;
902 if (body->oa.o_valid & OBD_MD_FLFLAGS)
903 cksum_type = cksum_type_unpack(body->oa.o_flags);
906 /* Because we already sync grant info with client when reconnect,
907 * grant info will be cleared for resent req, then fed_grant and
908 * total_grant will not be modified in following preprw_write*/
909 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
910 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
911 body->oa.o_valid &= ~OBD_MD_FLGRANT;
914 npages = OST_THREAD_POOL_SIZE;
915 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
916 ioo, remote_nb, &npages, local_nb, oti);
920 desc = ptlrpc_prep_bulk_exp(req, npages,
921 BULK_GET_SINK, OST_BULK_PORTAL);
923 GOTO(out, rc = -ENOMEM);
925 /* NB Having prepped, we must commit... */
927 for (i = 0; i < npages; i++)
928 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
929 local_nb[i].offset & ~CFS_PAGE_MASK,
932 /* Check if client was evicted while we were doing i/o before touching
934 if (desc->bd_export->exp_failed)
937 rc = ptlrpc_start_bulk_transfer(desc);
939 time_t start = cfs_time_current_sec();
941 long timeoutl = req->rq_deadline -
942 cfs_time_current_sec();
943 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
944 CFS_TICK : cfs_time_seconds(timeoutl);
945 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
946 ost_bulk_timeout, desc);
947 rc = l_wait_event(desc->bd_waitq,
948 !ptlrpc_server_bulk_active(desc) ||
949 desc->bd_export->exp_failed, &lwi);
950 LASSERT(rc == 0 || rc == -ETIMEDOUT);
951 /* Wait again if we changed deadline */
952 } while ((rc == -ETIMEDOUT) &&
953 (req->rq_deadline > cfs_time_current_sec()));
955 if (rc == -ETIMEDOUT) {
956 DEBUG_REQ(D_ERROR, req,
957 "timeout on bulk GET after %ld%+lds",
958 req->rq_deadline - start,
959 cfs_time_current_sec() -
961 ptlrpc_abort_bulk(desc);
962 } else if (desc->bd_export->exp_failed) {
963 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
965 ptlrpc_abort_bulk(desc);
966 } else if (!desc->bd_success ||
967 desc->bd_nob_transferred != desc->bd_nob) {
968 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
970 "truncated" : "network error on",
971 desc->bd_nob_transferred, desc->bd_nob);
972 /* XXX should this be a different errno? */
976 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
980 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
982 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
984 if (client_cksum != 0 && rc == 0) {
985 static int cksum_counter;
987 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
988 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
989 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
990 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
991 repbody->oa.o_cksum = server_cksum;
993 if (unlikely(client_cksum != server_cksum)) {
994 CERROR("client csum %x, server csum %x\n",
995 client_cksum, server_cksum);
997 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
998 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
999 cksum_counter, libcfs_id2str(req->rq_peer),
1004 /* Check if there is eviction in progress, and if so, wait for
1006 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
1007 lwi = LWI_INTR(NULL, NULL);
1008 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
1009 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
1012 if (rc == 0 && exp->exp_failed)
1015 /* Must commit after prep above in all cases */
1016 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1017 remote_nb, npages, local_nb, oti, rc);
1019 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1020 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1025 if (new_cksum == server_cksum)
1026 msg = "changed in transit before arrival at OST";
1027 else if (new_cksum == client_cksum)
1028 msg = "initial checksum before message complete";
1030 msg = "changed in transit AND after initial checksum";
1032 if (req->rq_peer.nid == desc->bd_sender) {
1036 router = libcfs_nid2str(desc->bd_sender);
1039 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from %s"
1040 "%s%s inum "LPU64"/"LPU64" object "LPU64"/"
1041 LPU64" extent ["LPU64"-"LPU64"]\n",
1042 exp->exp_obd->obd_name, msg,
1043 libcfs_id2str(req->rq_peer),
1045 body->oa.o_valid & OBD_MD_FLFID ?
1046 body->oa.o_fid : (__u64)0,
1047 body->oa.o_valid & OBD_MD_FLFID ?
1048 body->oa.o_generation :(__u64)0,
1050 body->oa.o_valid & OBD_MD_FLGROUP ?
1051 body->oa.o_gr : (__u64)0,
1053 local_nb[npages-1].offset +
1054 local_nb[npages-1].len - 1 );
1055 CERROR("client csum %x, original server csum %x, "
1056 "server csum now %x\n",
1057 client_cksum, server_cksum, new_cksum);
1063 /* set per-requested niobuf return codes */
1064 for (i = j = 0; i < niocount; i++) {
1065 int len = remote_nb[i].len;
1070 LASSERT(j < npages);
1071 if (local_nb[j].rc < 0)
1072 rcs[i] = local_nb[j].rc;
1073 len -= local_nb[j].len;
1078 LASSERT(j == npages);
1079 ptlrpc_lprocfs_brw(req, nob);
1083 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1086 ptlrpc_free_bulk(desc);
1089 oti_to_request(oti, req);
1090 target_committed_to_req(req);
1091 rc = ptlrpc_reply(req);
1092 } else if (!no_reply) {
1093 /* Only reply if there was no comms problem with bulk */
1094 target_committed_to_req(req);
1095 req->rq_status = rc;
1098 /* reply out callback would free */
1099 ptlrpc_req_drop_rs(req);
1100 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1101 "client will retry\n",
1102 exp->exp_obd->obd_name,
1103 exp->exp_client_uuid.uuid,
1104 exp->exp_connection->c_remote_uuid.uuid,
1105 libcfs_id2str(req->rq_peer));
1110 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1112 char *key, *val = NULL;
1113 int keylen, vallen, rc = 0;
1116 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1118 DEBUG_REQ(D_HA, req, "no set_info key");
1121 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1123 rc = lustre_pack_reply(req, 1, NULL, NULL);
1127 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1129 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
1131 if (KEY_IS(KEY_EVICT_BY_NID)) {
1133 obd_export_evict_by_nid(exp->exp_obd, val);
1138 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1140 lustre_msg_set_status(req->rq_repmsg, 0);
1144 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1148 int size[2] = { sizeof(struct ptlrpc_body), 0 };
1151 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1153 DEBUG_REQ(D_HA, req, "no get_info key");
1156 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1158 /* call once to get the size to allocate the reply buffer */
1159 rc = obd_get_info(exp, keylen, key, &size[1], NULL, NULL);
1163 rc = lustre_pack_reply(req, 2, size, NULL);
1167 reply = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*reply));
1168 /* call again to fill in the reply buffer */
1169 rc = obd_get_info(exp, keylen, key, size, reply, NULL);
1170 lustre_msg_set_status(req->rq_repmsg, 0);
1175 #ifdef HAVE_QUOTA_SUPPORT
1176 static int ost_handle_quotactl(struct ptlrpc_request *req)
1178 struct obd_quotactl *oqctl, *repoqc;
1179 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) };
1183 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1184 lustre_swab_obd_quotactl);
1186 GOTO(out, rc = -EPROTO);
1188 rc = lustre_pack_reply(req, 2, size, NULL);
1192 repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc));
1194 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1200 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1202 struct obd_quotactl *oqctl;
1206 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1207 lustre_swab_obd_quotactl);
1211 rc = lustre_pack_reply(req, 1, NULL, NULL);
1215 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1219 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1221 struct quota_adjust_qunit *oqaq, *repoqa;
1222 struct lustre_quota_ctxt *qctxt;
1223 int size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqa) };
1227 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1228 oqaq = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqaq),
1229 lustre_swab_quota_adjust_qunit);
1232 GOTO(out, rc = -EPROTO);
1233 rc = lustre_pack_reply(req, 2, size, NULL);
1236 repoqa = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqa));
1237 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt);
1244 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1245 struct obd_device *obd, int *process)
1247 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1248 case OST_CONNECT: /* This will never get here, but for completeness. */
1249 case OST_DISCONNECT:
1260 case OBD_LOG_CANCEL:
1262 *process = target_queue_recovery_request(req, obd);
1266 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1268 /* XXX what should we set rq_status to here? */
1269 req->rq_status = -EAGAIN;
1270 RETURN(ptlrpc_error(req));
1274 int ost_msg_check_version(struct lustre_msg *msg)
1278 switch(lustre_msg_get_opc(msg)) {
1280 case OST_DISCONNECT:
1282 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1284 CERROR("bad opc %u version %08x, expecting %08x\n",
1285 lustre_msg_get_opc(msg),
1286 lustre_msg_get_version(msg),
1287 LUSTRE_OBD_VERSION);
1300 #ifdef HAVE_QUOTA_SUPPORT
1301 case OST_QUOTACHECK:
1303 case OST_QUOTA_ADJUST_QUNIT:
1305 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1307 CERROR("bad opc %u version %08x, expecting %08x\n",
1308 lustre_msg_get_opc(msg),
1309 lustre_msg_get_version(msg),
1310 LUSTRE_OST_VERSION);
1315 case LDLM_BL_CALLBACK:
1316 case LDLM_CP_CALLBACK:
1317 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1319 CERROR("bad opc %u version %08x, expecting %08x\n",
1320 lustre_msg_get_opc(msg),
1321 lustre_msg_get_version(msg),
1322 LUSTRE_DLM_VERSION);
1324 case LLOG_ORIGIN_CONNECT:
1325 case OBD_LOG_CANCEL:
1326 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1328 CERROR("bad opc %u version %08x, expecting %08x\n",
1329 lustre_msg_get_opc(msg),
1330 lustre_msg_get_version(msg),
1331 LUSTRE_LOG_VERSION);
1334 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1340 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1341 struct ldlm_lock *lock)
1343 struct niobuf_remote *nb;
1344 struct obd_ioobj *ioo;
1345 struct ost_body *body;
1346 int objcount, niocount;
1351 opc = lustre_msg_get_opc(req->rq_reqmsg);
1352 LASSERT(opc == OST_READ || opc == OST_WRITE);
1354 /* As the request may be covered by several locks, do not look at
1355 * o_handle, look at the RPC IO region. */
1356 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
1358 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
1360 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
1361 objcount * sizeof(*ioo));
1362 LASSERT(ioo != NULL);
1363 for (niocount = i = 0; i < objcount; i++)
1364 niocount += ioo[i].ioo_bufcnt;
1366 nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
1367 niocount * sizeof(*nb));
1368 LASSERT(nb != NULL);
1371 if (opc == OST_READ)
1374 start = nb[0].offset & CFS_PAGE_MASK;
1375 end = (nb[ioo->ioo_bufcnt - 1].offset +
1376 nb[ioo->ioo_bufcnt - 1].len - 1) | ~CFS_PAGE_MASK;
1378 if (!(lock->l_granted_mode & mode))
1381 if (lock->l_policy_data.l_extent.end < start ||
1382 lock->l_policy_data.l_extent.start > end)
1389 * Swab buffers needed to call ost_rw_prolong_locks() and call it.
1390 * Return the value from ost_rw_prolong_locks() which is non-zero if
1391 * there is a cancelled lock which is waiting for this IO request.
1393 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1395 struct niobuf_remote *nb;
1396 struct obd_ioobj *ioo;
1397 struct ost_body *body;
1398 int objcount, niocount;
1402 opc = lustre_msg_get_opc(req->rq_reqmsg);
1403 LASSERT(opc == OST_READ || opc == OST_WRITE);
1405 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
1406 LASSERT(body != NULL);
1408 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
1410 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
1411 objcount * sizeof(*ioo));
1412 LASSERT(ioo != NULL);
1414 for (niocount = i = 0; i < objcount; i++)
1415 niocount += ioo[i].ioo_bufcnt;
1416 nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
1417 niocount * sizeof(*nb));
1418 LASSERT(nb != NULL);
1419 LASSERT(niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK));
1422 if (opc == OST_READ)
1424 RETURN(ost_rw_prolong_locks(req, ioo, nb, &body->oa, mode));
1427 static int ost_punch_prolong_locks(struct ptlrpc_request *req, struct obdo *oa)
1429 struct ldlm_res_id res_id = { .name = { oa->o_id } };
1430 struct ost_prolong_data opd = { 0 };
1435 end = start + oa->o_blocks;
1437 opd.opd_mode = LCK_PW;
1438 opd.opd_exp = req->rq_export;
1439 opd.opd_policy.l_extent.start = start & CFS_PAGE_MASK;
1440 if (oa->o_blocks == OBD_OBJECT_EOF || end < start)
1441 opd.opd_policy.l_extent.end = OBD_OBJECT_EOF;
1443 opd.opd_policy.l_extent.end = end | ~CFS_PAGE_MASK;
1445 /* prolong locks for the current service time of the corresponding
1446 * portal (= OST_IO_PORTAL) */
1447 opd.opd_timeout = AT_OFF ? obd_timeout / 2 :
1448 max(at_est2timeout(at_get(&req->rq_rqbd->
1449 rqbd_service->srv_at_estimate)), ldlm_timeout);
1451 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1452 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
1453 opd.opd_policy.l_extent.end);
1457 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
1458 ost_prolong_locks_iter, &opd);
1459 RETURN(opd.opd_lock_match);
1462 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1463 struct ldlm_lock *lock)
1465 struct ost_body *body;
1468 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
1470 LASSERT(body != NULL);
1472 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1473 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1478 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1480 struct ost_body *body = lustre_msg_buf(req->rq_reqmsg,
1481 REQ_REC_OFF, sizeof(*body));
1482 LASSERT(body != NULL);
1483 LASSERT(!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1484 !(body->oa.o_flags & OBD_FL_TRUNCLOCK));
1486 RETURN(ost_punch_prolong_locks(req, &body->oa));
1489 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
1490 .hpreq_lock_match = ost_rw_hpreq_lock_match,
1491 .hpreq_check = ost_rw_hpreq_check,
1494 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
1495 .hpreq_lock_match = ost_punch_hpreq_lock_match,
1496 .hpreq_check = ost_punch_hpreq_check,
1499 /** Assign high priority operations to the request if needed. */
1500 static int ost_hpreq_handler(struct ptlrpc_request *req)
1503 if (req->rq_export) {
1504 int opc = lustre_msg_get_opc(req->rq_reqmsg);
1505 struct ost_body *body;
1507 if (opc == OST_READ || opc == OST_WRITE) {
1508 struct niobuf_remote *nb;
1509 struct obd_ioobj *ioo;
1510 int objcount, niocount;
1513 body = lustre_swab_reqbuf(req, REQ_REC_OFF,
1517 CERROR("Missing/short ost_body\n");
1520 objcount = lustre_msg_buflen(req->rq_reqmsg,
1523 if (objcount == 0) {
1524 CERROR("Missing/short ioobj\n");
1528 CERROR("too many ioobjs (%d)\n", objcount);
1532 swab = !lustre_req_swabbed(req, REQ_REC_OFF + 1) &&
1533 lustre_req_need_swab(req);
1534 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1,
1535 objcount * sizeof(*ioo),
1536 lustre_swab_obd_ioobj);
1538 CERROR("Missing/short ioobj\n");
1541 for (niocount = i = 0; i < objcount; i++) {
1543 lustre_swab_obd_ioobj(&ioo[i]);
1544 if (ioo[i].ioo_bufcnt == 0) {
1545 CERROR("ioo[%d] has zero bufcnt\n", i);
1548 niocount += ioo[i].ioo_bufcnt;
1550 if (niocount > PTLRPC_MAX_BRW_PAGES) {
1551 DEBUG_REQ(D_ERROR, req, "bulk has too many "
1552 "pages (%d)", niocount);
1556 swab = !lustre_req_swabbed(req, REQ_REC_OFF + 2) &&
1557 lustre_req_need_swab(req);
1558 nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
1559 niocount * sizeof(*nb),
1560 lustre_swab_niobuf_remote);
1562 CERROR("Missing/short niobuf\n");
1567 /* swab remaining niobufs */
1568 for (i = 1; i < niocount; i++)
1569 lustre_swab_niobuf_remote(&nb[i]);
1572 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
1573 req->rq_ops = &ost_hpreq_rw;
1574 } else if (opc == OST_PUNCH) {
1575 body = lustre_swab_reqbuf(req, REQ_REC_OFF,
1579 CERROR("Missing/short ost_body\n");
1583 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1584 !(body->oa.o_flags & OBD_FL_TRUNCLOCK))
1585 req->rq_ops = &ost_hpreq_punch;
1591 static int ost_handle(struct ptlrpc_request *req)
1593 struct obd_trans_info trans_info = { 0, };
1594 struct obd_trans_info *oti = &trans_info;
1595 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1596 struct obd_device *obd = NULL;
1599 LASSERT(current->journal_info == NULL);
1600 /* XXX identical to MDS */
1601 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1604 if (req->rq_export == NULL) {
1605 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1606 lustre_msg_get_opc(req->rq_reqmsg),
1607 libcfs_id2str(req->rq_peer));
1608 req->rq_status = -ENOTCONN;
1609 GOTO(out, rc = -ENOTCONN);
1612 obd = req->rq_export->exp_obd;
1614 /* Check for aborted recovery. */
1615 spin_lock_bh(&obd->obd_processing_task_lock);
1616 recovering = obd->obd_recovering;
1617 spin_unlock_bh(&obd->obd_processing_task_lock);
1619 target_recovery_check_and_stop(obd) == 0) {
1620 rc = ost_filter_recovery_request(req, obd,
1622 if (rc || !should_process)
1628 rc = ost_msg_check_version(req->rq_reqmsg);
1632 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1634 CDEBUG(D_INODE, "connect\n");
1635 OBD_FAIL_RETURN(OBD_FAIL_OST_CONNECT_NET, 0);
1636 rc = target_handle_connect(req, ost_handle);
1637 OBD_FAIL_RETURN(OBD_FAIL_OST_CONNECT_NET2, 0);
1639 obd = req->rq_export->exp_obd;
1642 case OST_DISCONNECT:
1643 CDEBUG(D_INODE, "disconnect\n");
1644 OBD_FAIL_RETURN(OBD_FAIL_OST_DISCONNECT_NET, 0);
1645 rc = target_handle_disconnect(req);
1648 CDEBUG(D_INODE, "create\n");
1649 OBD_FAIL_RETURN(OBD_FAIL_OST_CREATE_NET, 0);
1650 OBD_FAIL_TIMEOUT_MS(OBD_FAIL_OST_PAUSE_CREATE, obd_fail_val);
1651 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
1652 GOTO(out, rc = -ENOSPC);
1653 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1654 GOTO(out, rc = -EROFS);
1655 rc = ost_create(req->rq_export, req, oti);
1658 CDEBUG(D_INODE, "destroy\n");
1659 OBD_FAIL_RETURN(OBD_FAIL_OST_DESTROY_NET, 0);
1660 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1661 GOTO(out, rc = -EROFS);
1662 rc = ost_destroy(req->rq_export, req, oti);
1665 CDEBUG(D_INODE, "getattr\n");
1666 OBD_FAIL_RETURN(OBD_FAIL_OST_GETATTR_NET, 0);
1667 rc = ost_getattr(req->rq_export, req);
1670 CDEBUG(D_INODE, "setattr\n");
1671 OBD_FAIL_RETURN(OBD_FAIL_OST_SETATTR_NET, 0);
1672 rc = ost_setattr(req->rq_export, req, oti);
1675 CDEBUG(D_INODE, "write\n");
1676 /* req->rq_request_portal would be nice, if it was set */
1677 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1678 CERROR("%s: deny write request from %s to portal %u\n",
1679 req->rq_export->exp_obd->obd_name,
1680 obd_export_nid2str(req->rq_export),
1681 req->rq_rqbd->rqbd_service->srv_req_portal);
1682 GOTO(out, rc = -EPROTO);
1684 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1685 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
1686 GOTO(out, rc = -ENOSPC);
1687 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1688 GOTO(out, rc = -EROFS);
1689 rc = ost_brw_write(req, oti);
1690 LASSERT(current->journal_info == NULL);
1691 /* ost_brw_write sends its own replies */
1694 CDEBUG(D_INODE, "read\n");
1695 /* req->rq_request_portal would be nice, if it was set */
1696 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1697 CERROR("%s: deny read request from %s to portal %u\n",
1698 req->rq_export->exp_obd->obd_name,
1699 obd_export_nid2str(req->rq_export),
1700 req->rq_rqbd->rqbd_service->srv_req_portal);
1701 GOTO(out, rc = -EPROTO);
1703 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1704 rc = ost_brw_read(req, oti);
1705 LASSERT(current->journal_info == NULL);
1706 /* ost_brw_read sends its own replies */
1709 CDEBUG(D_INODE, "punch\n");
1710 OBD_FAIL_RETURN(OBD_FAIL_OST_PUNCH_NET, 0);
1711 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1712 GOTO(out, rc = -EROFS);
1713 rc = ost_punch(req->rq_export, req, oti);
1716 CDEBUG(D_INODE, "statfs\n");
1717 OBD_FAIL_RETURN(OBD_FAIL_OST_STATFS_NET, 0);
1718 rc = ost_statfs(req);
1721 CDEBUG(D_INODE, "sync\n");
1722 OBD_FAIL_RETURN(OBD_FAIL_OST_SYNC_NET, 0);
1723 rc = ost_sync(req->rq_export, req);
1726 DEBUG_REQ(D_INODE, req, "set_info");
1727 rc = ost_set_info(req->rq_export, req);
1730 DEBUG_REQ(D_INODE, req, "get_info");
1731 rc = ost_get_info(req->rq_export, req);
1733 #ifdef HAVE_QUOTA_SUPPORT
1734 case OST_QUOTACHECK:
1735 CDEBUG(D_INODE, "quotacheck\n");
1736 OBD_FAIL_RETURN(OBD_FAIL_OST_QUOTACHECK_NET, 0);
1737 rc = ost_handle_quotacheck(req);
1740 CDEBUG(D_INODE, "quotactl\n");
1741 OBD_FAIL_RETURN(OBD_FAIL_OST_QUOTACTL_NET, 0);
1742 rc = ost_handle_quotactl(req);
1744 case OST_QUOTA_ADJUST_QUNIT:
1745 CDEBUG(D_INODE, "quota_adjust_qunit\n");
1746 rc = ost_handle_quota_adjust_qunit(req);
1750 DEBUG_REQ(D_INODE, req, "ping");
1751 rc = target_handle_ping(req);
1753 /* FIXME - just reply status */
1754 case LLOG_ORIGIN_CONNECT:
1755 DEBUG_REQ(D_INODE, req, "log connect");
1756 rc = llog_handle_connect(req);
1757 req->rq_status = rc;
1758 rc = lustre_pack_reply(req, 1, NULL, NULL);
1761 RETURN(ptlrpc_reply(req));
1762 case OBD_LOG_CANCEL:
1763 CDEBUG(D_INODE, "log cancel\n");
1764 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
1765 rc = llog_origin_handle_cancel(req);
1766 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_REP, 0);
1767 req->rq_status = rc;
1768 rc = lustre_pack_reply(req, 1, NULL, NULL);
1771 RETURN(ptlrpc_reply(req));
1773 CDEBUG(D_INODE, "enqueue\n");
1774 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
1775 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1776 ldlm_server_blocking_ast,
1777 ldlm_server_glimpse_ast);
1778 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1781 CDEBUG(D_INODE, "convert\n");
1782 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
1783 rc = ldlm_handle_convert(req);
1786 CDEBUG(D_INODE, "cancel\n");
1787 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CANCEL, 0);
1788 rc = ldlm_handle_cancel(req);
1790 case LDLM_BL_CALLBACK:
1791 case LDLM_CP_CALLBACK:
1792 CDEBUG(D_INODE, "callback\n");
1793 CERROR("callbacks should not happen on OST\n");
1796 CERROR("Unexpected opcode %d\n",
1797 lustre_msg_get_opc(req->rq_reqmsg));
1798 req->rq_status = -ENOTSUPP;
1799 rc = ptlrpc_error(req);
1803 LASSERT(current->journal_info == NULL);
1806 /* If we're DISCONNECTing, the export_data is already freed */
1807 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
1808 target_committed_to_req(req);
1812 oti_to_request(oti, req);
1813 return target_handle_reply(req, rc, fail);
1817 * free per-thread pool created by ost_thread_init().
1819 static void ost_thread_done(struct ptlrpc_thread *thread)
1821 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
1826 LASSERT(thread != NULL);
1829 * be prepared to handle partially-initialized pools (because this is
1830 * called from ost_thread_init() for cleanup.
1832 tls = thread->t_data;
1835 thread->t_data = NULL;
1841 * initialize per-thread page pool (bug 5137).
1843 static int ost_thread_init(struct ptlrpc_thread *thread)
1845 struct ost_thread_local_cache *tls;
1849 LASSERT(thread != NULL);
1850 LASSERT(thread->t_data == NULL);
1851 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
1856 thread->t_data = tls;
1860 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
1861 static int ost_setup(struct obd_device *obd, obd_count len, void *buf)
1863 struct ost_obd *ost = &obd->u.ost;
1864 struct lprocfs_static_vars lvars;
1865 int oss_min_threads;
1866 int oss_max_threads;
1867 int oss_min_create_threads;
1868 int oss_max_create_threads;
1872 rc = cleanup_group_info();
1875 lprocfs_ost_init_vars(&lvars);
1876 lprocfs_obd_setup(obd, lvars.obd_vars);
1878 sema_init(&ost->ost_health_sem, 1);
1880 if (oss_num_threads) {
1881 /* If oss_num_threads is set, it is the min and the max. */
1882 if (oss_num_threads > OSS_THREADS_MAX)
1883 oss_num_threads = OSS_THREADS_MAX;
1884 if (oss_num_threads < OSS_THREADS_MIN)
1885 oss_num_threads = OSS_THREADS_MIN;
1886 oss_max_threads = oss_min_threads = oss_num_threads;
1888 /* Base min threads on memory and cpus */
1889 oss_min_threads = num_possible_cpus() * num_physpages >>
1890 (27 - CFS_PAGE_SHIFT);
1891 if (oss_min_threads < OSS_THREADS_MIN)
1892 oss_min_threads = OSS_THREADS_MIN;
1893 /* Insure a 4x range for dynamic threads */
1894 if (oss_min_threads > OSS_THREADS_MAX / 4)
1895 oss_min_threads = OSS_THREADS_MAX / 4;
1896 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
1900 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1901 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
1902 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1903 ost_handle, LUSTRE_OSS_NAME,
1904 obd->obd_proc_entry, target_print_req,
1905 oss_min_threads, oss_max_threads, "ll_ost",
1907 if (ost->ost_service == NULL) {
1908 CERROR("failed to start OST service\n");
1909 GOTO(out_lprocfs, rc = -ENOMEM);
1912 rc = ptlrpc_start_threads(obd, ost->ost_service);
1914 GOTO(out_service, rc = -EINVAL);
1916 if (oss_num_create_threads) {
1917 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
1918 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
1919 if (oss_num_create_threads < OSS_DEF_CREATE_THREADS)
1920 oss_num_create_threads = OSS_DEF_CREATE_THREADS;
1921 oss_min_create_threads = oss_max_create_threads =
1922 oss_num_create_threads;
1924 oss_min_create_threads = OSS_DEF_CREATE_THREADS;
1925 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
1928 ost->ost_create_service =
1929 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1930 OST_MAXREPSIZE, OST_CREATE_PORTAL,
1931 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1932 ost_handle, "ost_create",
1933 obd->obd_proc_entry, target_print_req,
1934 oss_min_create_threads,
1935 oss_max_create_threads,
1936 "ll_ost_creat", NULL);
1937 if (ost->ost_create_service == NULL) {
1938 CERROR("failed to start OST create service\n");
1939 GOTO(out_service, rc = -ENOMEM);
1942 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
1944 GOTO(out_create, rc = -EINVAL);
1946 ost->ost_io_service =
1947 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1948 OST_MAXREPSIZE, OST_IO_PORTAL,
1949 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1950 ost_handle, "ost_io",
1951 obd->obd_proc_entry, target_print_req,
1952 oss_min_threads, oss_max_threads, "ll_ost_io",
1954 if (ost->ost_io_service == NULL) {
1955 CERROR("failed to start OST I/O service\n");
1956 GOTO(out_create, rc = -ENOMEM);
1959 ost->ost_io_service->srv_init = ost_thread_init;
1960 ost->ost_io_service->srv_done = ost_thread_done;
1961 ost->ost_io_service->srv_cpu_affinity = 1;
1962 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
1964 GOTO(out_io, rc = -EINVAL);
1966 ping_evictor_start();
1971 ptlrpc_unregister_service(ost->ost_io_service);
1972 ost->ost_io_service = NULL;
1974 ptlrpc_unregister_service(ost->ost_create_service);
1975 ost->ost_create_service = NULL;
1977 ptlrpc_unregister_service(ost->ost_service);
1978 ost->ost_service = NULL;
1980 lprocfs_obd_cleanup(obd);
1984 static int ost_cleanup(struct obd_device *obd)
1986 struct ost_obd *ost = &obd->u.ost;
1990 ping_evictor_stop();
1992 spin_lock_bh(&obd->obd_processing_task_lock);
1993 if (obd->obd_recovering) {
1994 target_cancel_recovery_timer(obd);
1995 obd->obd_recovering = 0;
1997 spin_unlock_bh(&obd->obd_processing_task_lock);
1999 down(&ost->ost_health_sem);
2000 ptlrpc_unregister_service(ost->ost_service);
2001 ptlrpc_unregister_service(ost->ost_create_service);
2002 ptlrpc_unregister_service(ost->ost_io_service);
2003 ost->ost_service = NULL;
2004 ost->ost_create_service = NULL;
2005 up(&ost->ost_health_sem);
2007 lprocfs_obd_cleanup(obd);
2012 static int ost_health_check(struct obd_device *obd)
2014 struct ost_obd *ost = &obd->u.ost;
2017 down(&ost->ost_health_sem);
2018 rc |= ptlrpc_service_health_check(ost->ost_service);
2019 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2020 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2021 up(&ost->ost_health_sem);
2024 * health_check to return 0 on healthy
2025 * and 1 on unhealthy.
2033 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2035 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2038 /* use obd ops to offer management infrastructure */
2039 static struct obd_ops ost_obd_ops = {
2040 .o_owner = THIS_MODULE,
2041 .o_setup = ost_setup,
2042 .o_cleanup = ost_cleanup,
2043 .o_health_check = ost_health_check,
2047 static int __init ost_init(void)
2049 struct lprocfs_static_vars lvars;
2053 lprocfs_ost_init_vars(&lvars);
2054 rc = class_register_type(&ost_obd_ops, lvars.module_vars,
2057 if (ost_num_threads != 0 && oss_num_threads == 0) {
2058 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2059 "use oss_num_threads instead or unset both for "
2060 "dynamic thread startup\n");
2061 oss_num_threads = ost_num_threads;
2067 static void /*__exit*/ ost_exit(void)
2069 class_unregister_type(LUSTRE_OSS_NAME);
2072 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2073 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2074 MODULE_LICENSE("GPL");
2076 module_init(ost_init);
2077 module_exit(ost_exit);