4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
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");
73 * Do not return server-side uid/gid to remote client
75 static void ost_drop_id(struct obd_export *exp, struct obdo *oa)
77 if (exp_connect_rmtclient(exp)) {
80 oa->o_valid &= ~(OBD_MD_FLUID | OBD_MD_FLGID);
85 * Validate oa from client.
86 * If the request comes from 2.0 clients, currently only RSVD seq and IDIF
88 * a. for single MDS seq = FID_SEQ_OST_MDT0,
89 * b. for CMD, seq = FID_SEQ_OST_MDT0, FID_SEQ_OST_MDT1 - FID_SEQ_OST_MAX
91 static int ost_validate_obdo(struct obd_export *exp, struct obdo *oa,
92 struct obd_ioobj *ioobj)
94 if (oa != NULL && !(oa->o_valid & OBD_MD_FLGROUP)) {
95 oa->o_seq = FID_SEQ_OST_MDT0;
97 ioobj->ioo_seq = FID_SEQ_OST_MDT0;
98 /* remove fid_seq_is_rsvd() after FID-on-OST allows SEQ > 9 */
99 } else if (oa == NULL || !(fid_seq_is_rsvd(oa->o_seq) ||
100 fid_seq_is_mdt0(oa->o_seq))) {
101 CERROR("%s: client %s sent invalid object "POSTID"\n",
102 exp->exp_obd->obd_name, obd_export_nid2str(exp),
103 oa ? oa->o_id : -1, oa ? oa->o_seq : -1);
106 obdo_from_ostid(oa, &oa->o_oi);
108 ioobj_from_obdo(ioobj, oa);
112 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
114 struct oti_req_ack_lock *ack_lock;
120 if (req->rq_repmsg) {
121 __u64 versions[PTLRPC_NUM_VERSIONS] = { 0 };
122 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
123 versions[0] = oti->oti_pre_version;
124 lustre_msg_set_versions(req->rq_repmsg, versions);
126 req->rq_transno = oti->oti_transno;
128 /* XXX 4 == entries in oti_ack_locks??? */
129 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
132 /* XXX not even calling target_send_reply in some cases... */
133 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode, 0);
137 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
138 struct obd_trans_info *oti)
140 struct ost_body *body, *repbody;
141 struct lustre_capa *capa = NULL;
145 /* Get the request body */
146 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
150 if (body->oa.o_id == 0)
153 rc = ost_validate_obdo(exp, &body->oa, NULL);
157 /* If there's a DLM request, cancel the locks mentioned in it*/
158 if (req_capsule_field_present(&req->rq_pill, &RMF_DLM_REQ, RCL_CLIENT)) {
159 struct ldlm_request *dlm;
161 dlm = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
164 ldlm_request_cancel(req, dlm, 0);
167 /* If there's a capability, get it */
168 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
169 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
171 CERROR("Missing capability for OST DESTROY");
176 /* Prepare the reply */
177 rc = req_capsule_server_pack(&req->rq_pill);
181 /* Get the log cancellation cookie */
182 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
183 oti->oti_logcookies = &body->oa.o_lcookie;
185 /* Finish the reply */
186 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
187 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
189 /* Do the destroy and set the reply status accordingly */
190 req->rq_status = obd_destroy(req->rq_svc_thread->t_env, exp,
191 &repbody->oa, NULL, oti, NULL, capa);
196 * Helper function for getting server side [start, start+count] DLM lock
197 * if asked by client.
199 static int ost_lock_get(struct obd_export *exp, struct obdo *oa,
200 __u64 start, __u64 count, struct lustre_handle *lh,
203 struct ldlm_res_id res_id;
204 ldlm_policy_data_t policy;
205 __u64 end = start + count;
209 LASSERT(!lustre_handle_is_used(lh));
210 /* o_id and o_gr are used for localizing resource, if client miss to set
211 * them, do not trigger ASSERTION. */
212 if (unlikely((oa->o_valid & (OBD_MD_FLID | OBD_MD_FLGROUP)) !=
213 (OBD_MD_FLID | OBD_MD_FLGROUP)))
216 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
217 !(oa->o_flags & OBD_FL_SRVLOCK))
220 osc_build_res_name(oa->o_id, oa->o_seq, &res_id);
221 CDEBUG(D_INODE, "OST-side extent lock.\n");
223 policy.l_extent.start = start & CFS_PAGE_MASK;
225 /* If ->o_blocks is EOF it means "lock till the end of the
226 * file". Otherwise, it's size of a hole being punched (in bytes) */
227 if (count == OBD_OBJECT_EOF || end < start)
228 policy.l_extent.end = OBD_OBJECT_EOF;
230 policy.l_extent.end = end | ~CFS_PAGE_MASK;
232 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
233 LDLM_EXTENT, &policy, mode, &flags,
234 ldlm_blocking_ast, ldlm_completion_ast,
235 ldlm_glimpse_ast, NULL, 0, NULL, lh));
238 /* Helper function: release lock, if any. */
239 static void ost_lock_put(struct obd_export *exp,
240 struct lustre_handle *lh, int mode)
243 if (lustre_handle_is_used(lh))
244 ldlm_lock_decref(lh, mode);
248 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
250 struct ost_body *body, *repbody;
251 struct obd_info *oinfo;
252 struct lustre_handle lh = { 0 };
253 struct lustre_capa *capa = NULL;
257 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
261 rc = ost_validate_obdo(exp, &body->oa, NULL);
265 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
266 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
268 CERROR("Missing capability for OST GETATTR");
273 rc = req_capsule_server_pack(&req->rq_pill);
277 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
278 repbody->oa = body->oa;
280 rc = ost_lock_get(exp, &repbody->oa, 0, OBD_OBJECT_EOF, &lh, LCK_PR, 0);
284 OBD_ALLOC_PTR(oinfo);
286 GOTO(unlock, rc = -ENOMEM);
287 oinfo->oi_oa = &repbody->oa;
288 oinfo->oi_capa = capa;
290 req->rq_status = obd_getattr(req->rq_svc_thread->t_env, exp, oinfo);
294 ost_drop_id(exp, &repbody->oa);
297 ost_lock_put(exp, &lh, LCK_PR);
301 static int ost_statfs(struct ptlrpc_request *req)
303 struct obd_statfs *osfs;
307 rc = req_capsule_server_pack(&req->rq_pill);
311 osfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
313 req->rq_status = obd_statfs(req->rq_svc_thread->t_env, req->rq_export,
315 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
317 if (req->rq_status != 0)
318 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
323 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
324 struct obd_trans_info *oti)
326 struct ost_body *body, *repbody;
330 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
334 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
338 rc = req_capsule_server_pack(&req->rq_pill);
342 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
343 repbody->oa = body->oa;
344 oti->oti_logcookies = &body->oa.o_lcookie;
346 req->rq_status = obd_create(req->rq_svc_thread->t_env, exp,
347 &repbody->oa, NULL, oti);
348 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
352 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
353 struct obd_trans_info *oti)
355 struct ost_body *body, *repbody;
357 struct lustre_handle lh = {0,};
360 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
361 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
363 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
367 rc = ost_validate_obdo(exp, &body->oa, NULL);
371 if ((body->oa.o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
372 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
375 rc = req_capsule_server_pack(&req->rq_pill);
379 /* standard truncate optimization: if file body is completely
380 * destroyed, don't send data back to the server. */
381 if (body->oa.o_size == 0)
382 flags |= LDLM_AST_DISCARD_DATA;
384 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
385 repbody->oa = body->oa;
387 rc = ost_lock_get(exp, &repbody->oa, repbody->oa.o_size,
388 repbody->oa.o_blocks, &lh, LCK_PW, flags);
390 struct obd_info *oinfo;
391 struct lustre_capa *capa = NULL;
393 if (repbody->oa.o_valid & OBD_MD_FLFLAGS &&
394 repbody->oa.o_flags == OBD_FL_SRVLOCK)
396 * If OBD_FL_SRVLOCK is the only bit set in
397 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
398 * through filter_setattr() to filter_iocontrol().
400 repbody->oa.o_valid &= ~OBD_MD_FLFLAGS;
402 if (repbody->oa.o_valid & OBD_MD_FLOSSCAPA) {
403 capa = req_capsule_client_get(&req->rq_pill,
406 CERROR("Missing capability for OST PUNCH");
407 GOTO(unlock, rc = -EFAULT);
411 OBD_ALLOC_PTR(oinfo);
413 GOTO(unlock, rc = -ENOMEM);
414 oinfo->oi_oa = &repbody->oa;
415 oinfo->oi_policy.l_extent.start = oinfo->oi_oa->o_size;
416 oinfo->oi_policy.l_extent.end = oinfo->oi_oa->o_blocks;
417 oinfo->oi_capa = capa;
418 oinfo->oi_flags = OBD_FL_PUNCH;
420 req->rq_status = obd_punch(req->rq_svc_thread->t_env, exp,
424 ost_lock_put(exp, &lh, LCK_PW);
427 ost_drop_id(exp, &repbody->oa);
431 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
433 struct ost_body *body, *repbody;
434 struct obd_info *oinfo;
435 struct lustre_capa *capa = NULL;
439 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
443 rc = ost_validate_obdo(exp, &body->oa, NULL);
447 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
448 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
450 CERROR("Missing capability for OST SYNC");
455 rc = req_capsule_server_pack(&req->rq_pill);
459 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
460 repbody->oa = body->oa;
462 OBD_ALLOC_PTR(oinfo);
466 oinfo->oi_oa = &repbody->oa;
467 oinfo->oi_capa = capa;
468 req->rq_status = obd_sync(req->rq_svc_thread->t_env, exp, oinfo,
469 repbody->oa.o_size, repbody->oa.o_blocks,
473 ost_drop_id(exp, &repbody->oa);
477 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
478 struct obd_trans_info *oti)
480 struct ost_body *body, *repbody;
481 struct obd_info *oinfo;
482 struct lustre_capa *capa = NULL;
486 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
490 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
494 rc = req_capsule_server_pack(&req->rq_pill);
498 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
499 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
501 CERROR("Missing capability for OST SETATTR");
506 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
507 repbody->oa = body->oa;
509 OBD_ALLOC_PTR(oinfo);
512 oinfo->oi_oa = &repbody->oa;
513 oinfo->oi_capa = capa;
515 req->rq_status = obd_setattr(req->rq_svc_thread->t_env, exp, oinfo,
520 ost_drop_id(exp, &repbody->oa);
524 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
525 cksum_type_t cksum_type)
530 cksum = init_checksum(cksum_type);
531 for (i = 0; i < desc->bd_iov_count; i++) {
532 struct page *page = desc->bd_iov[i].kiov_page;
533 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
534 char *ptr = kmap(page) + off;
535 int len = desc->bd_iov[i].kiov_len;
537 /* corrupt the data before we compute the checksum, to
538 * simulate a client->OST data error */
539 if (i == 0 && opc == OST_WRITE &&
540 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
541 memcpy(ptr, "bad3", min(4, len));
542 cksum = compute_checksum(cksum, ptr, len, cksum_type);
543 /* corrupt the data after we compute the checksum, to
544 * simulate an OST->client data error */
545 if (i == 0 && opc == OST_READ &&
546 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
547 memcpy(ptr, "bad4", min(4, len));
548 /* nobody should use corrupted page again */
549 ClearPageUptodate(page);
554 return fini_checksum(cksum, cksum_type);
557 static int ost_brw_lock_get(int mode, struct obd_export *exp,
558 struct obd_ioobj *obj, struct niobuf_remote *nb,
559 struct lustre_handle *lh)
562 int nrbufs = obj->ioo_bufcnt;
563 struct ldlm_res_id res_id;
564 ldlm_policy_data_t policy;
568 osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id);
569 LASSERT(mode == LCK_PR || mode == LCK_PW);
570 LASSERT(!lustre_handle_is_used(lh));
572 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
575 for (i = 1; i < nrbufs; i ++)
576 if ((nb[0].flags & OBD_BRW_SRVLOCK) !=
577 (nb[i].flags & OBD_BRW_SRVLOCK))
580 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
581 policy.l_extent.end = (nb[nrbufs - 1].offset +
582 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
584 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
585 LDLM_EXTENT, &policy, mode, &flags,
586 ldlm_blocking_ast, ldlm_completion_ast,
587 ldlm_glimpse_ast, NULL, 0, NULL, lh));
590 static void ost_brw_lock_put(int mode,
591 struct obd_ioobj *obj, struct niobuf_remote *niob,
592 struct lustre_handle *lh)
595 LASSERT(mode == LCK_PR || mode == LCK_PW);
596 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
597 lustre_handle_is_used(lh));
598 if (lustre_handle_is_used(lh))
599 ldlm_lock_decref(lh, mode);
603 /* Allocate thread local buffers if needed */
604 static struct ost_thread_local_cache *ost_tls_get(struct ptlrpc_request *r)
606 struct ost_thread_local_cache *tls =
607 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
609 /* In normal mode of operation an I/O request is serviced only
610 * by ll_ost_io threads each of them has own tls buffers allocated by
612 * During recovery, an I/O request may be queued until any of the ost
613 * service threads process it. Not necessary it should be one of
614 * ll_ost_io threads. In that case we dynamically allocating tls
615 * buffers for the request service time. */
616 if (unlikely(tls == NULL)) {
617 LASSERT(r->rq_export->exp_in_recovery);
621 r->rq_svc_thread->t_data = tls;
627 /* Free thread local buffers if they were allocated only for servicing
628 * this one request */
629 static void ost_tls_put(struct ptlrpc_request *r)
631 struct ost_thread_local_cache *tls =
632 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
634 if (unlikely(tls->temporary)) {
636 r->rq_svc_thread->t_data = NULL;
640 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
642 struct ptlrpc_bulk_desc *desc = NULL;
643 struct obd_export *exp = req->rq_export;
644 struct niobuf_remote *remote_nb;
645 struct niobuf_local *local_nb;
646 struct obd_ioobj *ioo;
647 struct ost_body *body, *repbody;
648 struct lustre_capa *capa = NULL;
649 struct l_wait_info lwi;
650 struct lustre_handle lockh = { 0 };
651 int niocount, npages, nob = 0, rc, i;
653 struct ost_thread_local_cache *tls;
656 req->rq_bulk_read = 1;
658 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
659 GOTO(out, rc = -EIO);
661 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
663 /* Check if there is eviction in progress, and if so, wait for it to
665 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
666 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
667 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
668 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
672 GOTO(out, rc = -ENOTCONN);
674 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
675 * ost_rw_hpreq_check(). */
676 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
678 GOTO(out, rc = -EFAULT);
681 * A req_capsule_X_get_array(pill, field, ptr_to_element_count) function
682 * would be useful here and wherever we get &RMF_OBD_IOOBJ and
683 * &RMF_NIOBUF_REMOTE.
685 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
687 GOTO(out, rc = -EFAULT);
689 rc = ost_validate_obdo(exp, &body->oa, ioo);
693 niocount = ioo->ioo_bufcnt;
694 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
695 if (remote_nb == NULL)
696 GOTO(out, rc = -EFAULT);
698 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
699 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
701 CERROR("Missing capability for OST BRW READ");
702 GOTO(out, rc = -EFAULT);
706 rc = req_capsule_server_pack(&req->rq_pill);
710 tls = ost_tls_get(req);
712 GOTO(out_bulk, rc = -ENOMEM);
713 local_nb = tls->local;
715 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
720 * If getting the lock took more time than
721 * client was willing to wait, drop it. b=11330
723 if (cfs_time_current_sec() > req->rq_deadline ||
724 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
726 CERROR("Dropping timed-out read from %s because locking"
727 "object "LPX64" took %ld seconds (limit was %ld).\n",
728 libcfs_id2str(req->rq_peer), ioo->ioo_id,
729 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
730 req->rq_deadline - req->rq_arrival_time.tv_sec);
731 GOTO(out_lock, rc = -ETIMEDOUT);
734 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
735 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
737 npages = OST_THREAD_POOL_SIZE;
738 rc = obd_preprw(req->rq_svc_thread->t_env, OBD_BRW_READ, exp,
739 &repbody->oa, 1, ioo, remote_nb, &npages, local_nb,
744 desc = ptlrpc_prep_bulk_exp(req, npages,
745 BULK_PUT_SOURCE, OST_BULK_PORTAL);
747 GOTO(out_commitrw, rc = -ENOMEM);
750 for (i = 0; i < npages; i++) {
751 int page_rc = local_nb[i].rc;
753 if (page_rc < 0) { /* error */
759 if (page_rc != 0) { /* some data! */
760 LASSERT (local_nb[i].page != NULL);
761 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
762 local_nb[i].offset & ~CFS_PAGE_MASK,
766 if (page_rc != local_nb[i].len) { /* short read */
767 /* All subsequent pages should be 0 */
769 LASSERT(local_nb[i].rc == 0);
774 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
775 cksum_type_t cksum_type =
776 cksum_type_unpack(repbody->oa.o_valid & OBD_MD_FLFLAGS ?
777 repbody->oa.o_flags : 0);
778 repbody->oa.o_flags = cksum_type_pack(cksum_type);
779 repbody->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
780 repbody->oa.o_cksum = ost_checksum_bulk(desc, OST_READ,cksum_type);
781 CDEBUG(D_PAGE, "checksum at read origin: %x\n",
782 repbody->oa.o_cksum);
784 repbody->oa.o_valid = 0;
786 /* We're finishing using body->oa as an input variable */
788 /* Check if client was evicted while we were doing i/o before touching
791 if (likely(!CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2)))
792 rc = target_bulk_io(exp, desc, &lwi);
797 /* Must commit after prep above in all cases */
798 rc = obd_commitrw(req->rq_svc_thread->t_env, OBD_BRW_READ, exp,
799 &repbody->oa, 1, ioo, remote_nb, npages, local_nb,
803 ost_drop_id(exp, &repbody->oa);
806 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
810 if (desc && !CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2))
811 ptlrpc_free_bulk(desc);
815 req->rq_status = nob;
816 ptlrpc_lprocfs_brw(req, nob);
817 target_committed_to_req(req);
819 } else if (!no_reply) {
820 /* Only reply if there was no comms problem with bulk */
821 target_committed_to_req(req);
825 /* reply out callback would free */
826 ptlrpc_req_drop_rs(req);
827 LCONSOLE_WARN("%s: Bulk IO read error with %s (at %s), "
828 "client will retry: rc %d\n",
829 exp->exp_obd->obd_name,
830 obd_uuid2str(&exp->exp_client_uuid),
831 obd_export_nid2str(exp), rc);
833 /* send a bulk after reply to simulate a network delay or reordering
835 if (unlikely(CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2))) {
837 struct l_wait_info lwi1;
839 CDEBUG(D_INFO, "reorder BULK\n");
840 cfs_waitq_init(&waitq);
842 lwi1 = LWI_TIMEOUT_INTR(cfs_time_seconds(3), NULL, NULL, NULL);
843 l_wait_event(waitq, 0, &lwi1);
844 rc = target_bulk_io(exp, desc, &lwi);
845 ptlrpc_free_bulk(desc);
851 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
853 struct ptlrpc_bulk_desc *desc = NULL;
854 struct obd_export *exp = req->rq_export;
855 struct niobuf_remote *remote_nb;
856 struct niobuf_local *local_nb;
857 struct obd_ioobj *ioo;
858 struct ost_body *body, *repbody;
859 struct l_wait_info lwi;
860 struct lustre_handle lockh = {0};
861 struct lustre_capa *capa = NULL;
863 int objcount, niocount, npages;
865 obd_count client_cksum = 0, server_cksum = 0;
866 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
867 int no_reply = 0, mmap = 0;
868 __u32 o_uid = 0, o_gid = 0;
869 struct ost_thread_local_cache *tls;
872 req->rq_bulk_write = 1;
874 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
875 GOTO(out, rc = -EIO);
876 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
877 GOTO(out, rc = -EFAULT);
879 /* pause before transaction has been started */
880 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
882 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
883 * ost_rw_hpreq_check(). */
884 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
886 GOTO(out, rc = -EFAULT);
888 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
889 RCL_CLIENT) / sizeof(*ioo);
890 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
892 GOTO(out, rc = -EFAULT);
894 rc = ost_validate_obdo(exp, &body->oa, ioo);
898 for (niocount = i = 0; i < objcount; i++)
899 niocount += ioo[i].ioo_bufcnt;
902 * It'd be nice to have a capsule function to indicate how many elements
903 * there were in a buffer for an RMF that's declared to be an array.
904 * It's easy enough to compute the number of elements here though.
906 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
907 if (remote_nb == NULL || niocount != (req_capsule_get_size(&req->rq_pill,
908 &RMF_NIOBUF_REMOTE, RCL_CLIENT) / sizeof(*remote_nb)))
909 GOTO(out, rc = -EFAULT);
911 if ((remote_nb[0].flags & OBD_BRW_MEMALLOC) &&
912 (exp->exp_connection->c_peer.nid == exp->exp_connection->c_self))
913 cfs_memory_pressure_set();
915 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
916 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
918 CERROR("Missing capability for OST BRW WRITE");
919 GOTO(out, rc = -EFAULT);
923 req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER,
924 niocount * sizeof(*rcs));
925 rc = req_capsule_server_pack(&req->rq_pill);
928 CFS_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, cfs_fail_val);
929 rcs = req_capsule_server_get(&req->rq_pill, &RMF_RCS);
931 tls = ost_tls_get(req);
933 GOTO(out_bulk, rc = -ENOMEM);
934 local_nb = tls->local;
936 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
941 * If getting the lock took more time than
942 * client was willing to wait, drop it. b=11330
944 if (cfs_time_current_sec() > req->rq_deadline ||
945 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
947 CERROR("Dropping timed-out write from %s because locking "
948 "object "LPX64" took %ld seconds (limit was %ld).\n",
949 libcfs_id2str(req->rq_peer), ioo->ioo_id,
950 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
951 req->rq_deadline - req->rq_arrival_time.tv_sec);
952 GOTO(out_lock, rc = -ETIMEDOUT);
955 /* obd_preprw clobbers oa->valid, so save what we need */
956 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
957 client_cksum = body->oa.o_cksum;
958 if (body->oa.o_valid & OBD_MD_FLFLAGS)
959 cksum_type = cksum_type_unpack(body->oa.o_flags);
961 if (body->oa.o_valid & OBD_MD_FLFLAGS && body->oa.o_flags & OBD_FL_MMAP)
964 /* Because we already sync grant info with client when reconnect,
965 * grant info will be cleared for resent req, then fed_grant and
966 * total_grant will not be modified in following preprw_write */
967 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
968 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
969 body->oa.o_valid &= ~OBD_MD_FLGRANT;
972 if (exp_connect_rmtclient(exp)) {
973 o_uid = body->oa.o_uid;
974 o_gid = body->oa.o_gid;
977 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
978 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
980 npages = OST_THREAD_POOL_SIZE;
981 rc = obd_preprw(req->rq_svc_thread->t_env, OBD_BRW_WRITE, exp,
982 &repbody->oa, objcount, ioo, remote_nb, &npages,
983 local_nb, oti, capa);
987 desc = ptlrpc_prep_bulk_exp(req, npages,
988 BULK_GET_SINK, OST_BULK_PORTAL);
990 GOTO(skip_transfer, rc = -ENOMEM);
992 /* NB Having prepped, we must commit... */
994 for (i = 0; i < npages; i++)
995 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
996 local_nb[i].offset & ~CFS_PAGE_MASK,
999 rc = sptlrpc_svc_prep_bulk(req, desc);
1003 rc = target_bulk_io(exp, desc, &lwi);
1007 if (client_cksum != 0 && rc == 0) {
1008 static int cksum_counter;
1009 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1010 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1011 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1012 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1013 repbody->oa.o_cksum = server_cksum;
1015 if (unlikely(client_cksum != server_cksum)) {
1016 CDEBUG_LIMIT(mmap ? D_INFO : D_ERROR,
1017 "client csum %x, server csum %x\n",
1018 client_cksum, server_cksum);
1020 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1021 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1022 cksum_counter, libcfs_id2str(req->rq_peer),
1027 /* Must commit after prep above in all cases */
1028 rc = obd_commitrw(req->rq_svc_thread->t_env, OBD_BRW_WRITE, exp,
1029 &repbody->oa, objcount, ioo, remote_nb, npages,
1031 if (rc == -ENOTCONN)
1032 /* quota acquire process has been given up because
1033 * either the client has been evicted or the client
1034 * has timed out the request already */
1037 if (exp_connect_rmtclient(exp)) {
1038 repbody->oa.o_uid = o_uid;
1039 repbody->oa.o_gid = o_gid;
1043 * Disable sending mtime back to the client. If the client locked the
1044 * whole object, then it has already updated the mtime on its side,
1045 * otherwise it will have to glimpse anyway (see bug 21489, comment 32)
1047 repbody->oa.o_valid &= ~(OBD_MD_FLMTIME | OBD_MD_FLATIME);
1049 if (unlikely(client_cksum != server_cksum && rc == 0 && !mmap)) {
1050 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1055 if (new_cksum == server_cksum)
1056 msg = "changed in transit before arrival at OST";
1057 else if (new_cksum == client_cksum)
1058 msg = "initial checksum before message complete";
1060 msg = "changed in transit AND after initial checksum";
1062 if (req->rq_peer.nid == desc->bd_sender) {
1066 router = libcfs_nid2str(desc->bd_sender);
1069 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1070 "%s%s%s inode "DFID" object "
1071 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1072 exp->exp_obd->obd_name, msg,
1073 libcfs_id2str(req->rq_peer),
1075 body->oa.o_valid & OBD_MD_FLFID ?
1076 body->oa.o_parent_seq : (__u64)0,
1077 body->oa.o_valid & OBD_MD_FLFID ?
1078 body->oa.o_parent_oid : 0,
1079 body->oa.o_valid & OBD_MD_FLFID ?
1080 body->oa.o_parent_ver : 0,
1082 body->oa.o_valid & OBD_MD_FLGROUP ?
1083 body->oa.o_seq : (__u64)0,
1085 local_nb[npages-1].offset +
1086 local_nb[npages-1].len - 1 );
1087 CERROR("client csum %x, original server csum %x, "
1088 "server csum now %x\n",
1089 client_cksum, server_cksum, new_cksum);
1095 /* set per-requested niobuf return codes */
1096 for (i = j = 0; i < niocount; i++) {
1097 int len = remote_nb[i].len;
1102 LASSERT(j < npages);
1103 if (local_nb[j].rc < 0)
1104 rcs[i] = local_nb[j].rc;
1105 len -= local_nb[j].len;
1110 LASSERT(j == npages);
1111 ptlrpc_lprocfs_brw(req, nob);
1115 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1120 ptlrpc_free_bulk(desc);
1123 oti_to_request(oti, req);
1124 target_committed_to_req(req);
1125 rc = ptlrpc_reply(req);
1126 } else if (!no_reply) {
1127 /* Only reply if there was no comms problem with bulk */
1128 target_committed_to_req(req);
1129 req->rq_status = rc;
1132 /* reply out callback would free */
1133 ptlrpc_req_drop_rs(req);
1134 LCONSOLE_WARN("%s: Bulk IO write error with %s (at %s), "
1135 "client will retry: rc %d\n",
1136 exp->exp_obd->obd_name,
1137 obd_uuid2str(&exp->exp_client_uuid),
1138 obd_export_nid2str(exp), rc);
1140 cfs_memory_pressure_clr();
1145 * Implementation of OST_SET_INFO.
1147 * OST_SET_INFO is like ioctl(): heavily overloaded. Specifically, it takes a
1148 * "key" and a value RPC buffers as arguments, with the value's contents
1149 * interpreted according to the key.
1151 * Value types that need swabbing have swabbing done explicitly, either here or
1152 * in functions called from here. This should be corrected: all swabbing should
1153 * be done in the capsule abstraction, as that will then allow us to move
1154 * swabbing exclusively to the client without having to modify server code
1155 * outside the capsule abstraction's implementation itself. To correct this
1156 * will require minor changes to the capsule abstraction; see the comments for
1157 * req_capsule_extend() in layout.c.
1159 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1161 struct ost_body *body = NULL, *repbody;
1162 char *key, *val = NULL;
1163 int keylen, vallen, rc = 0;
1164 int is_grant_shrink = 0;
1167 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1169 DEBUG_REQ(D_HA, req, "no set_info key");
1172 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1175 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1178 if ((is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK)))
1179 /* In this case the value is actually an RMF_OST_BODY, so we
1180 * transmutate the type of this PTLRPC */
1181 req_capsule_extend(&req->rq_pill, &RQF_OST_SET_GRANT_INFO);
1183 rc = req_capsule_server_pack(&req->rq_pill);
1188 if (is_grant_shrink) {
1189 body = req_capsule_client_get(&req->rq_pill,
1194 repbody = req_capsule_server_get(&req->rq_pill,
1196 memcpy(repbody, body, sizeof(*body));
1197 val = (char*)repbody;
1199 val = req_capsule_client_get(&req->rq_pill,
1204 if (KEY_IS(KEY_EVICT_BY_NID)) {
1206 obd_export_evict_by_nid(exp->exp_obd, val);
1208 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1209 if (vallen < sizeof(__u32))
1211 __swab32s((__u32 *)val);
1214 /* OBD will also check if KEY_IS(KEY_GRANT_SHRINK), and will cast val to
1215 * a struct ost_body * value */
1216 rc = obd_set_info_async(req->rq_svc_thread->t_env, exp, keylen,
1217 key, vallen, val, NULL);
1219 lustre_msg_set_status(req->rq_repmsg, 0);
1223 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1226 int keylen, replylen, rc = 0;
1227 struct req_capsule *pill = &req->rq_pill;
1230 /* this common part for get_info rpc */
1231 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1233 DEBUG_REQ(D_HA, req, "no get_info key");
1236 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1238 if (KEY_IS(KEY_FIEMAP)) {
1239 struct ll_fiemap_info_key *fm_key = key;
1242 rc = ost_validate_obdo(exp, &fm_key->oa, NULL);
1247 rc = obd_get_info(req->rq_svc_thread->t_env, exp, keylen, key,
1248 &replylen, NULL, NULL);
1252 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1253 RCL_SERVER, replylen);
1255 rc = req_capsule_server_pack(pill);
1259 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1263 /* call again to fill in the reply buffer */
1264 rc = obd_get_info(req->rq_svc_thread->t_env, exp, keylen, key,
1265 &replylen, reply, NULL);
1267 lustre_msg_set_status(req->rq_repmsg, 0);
1271 #ifdef HAVE_QUOTA_SUPPORT
1272 static int ost_handle_quotactl(struct ptlrpc_request *req)
1274 struct obd_quotactl *oqctl, *repoqc;
1278 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1280 GOTO(out, rc = -EPROTO);
1282 rc = req_capsule_server_pack(&req->rq_pill);
1286 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1287 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1294 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1296 struct obd_quotactl *oqctl;
1300 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1304 rc = req_capsule_server_pack(&req->rq_pill);
1308 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1312 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1314 struct quota_adjust_qunit *oqaq, *repoqa;
1315 struct lustre_quota_ctxt *qctxt;
1319 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1320 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1322 GOTO(out, rc = -EPROTO);
1324 rc = req_capsule_server_pack(&req->rq_pill);
1328 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1329 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt, NULL);
1337 static int ost_llog_handle_connect(struct obd_export *exp,
1338 struct ptlrpc_request *req)
1340 struct llogd_conn_body *body;
1344 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
1345 rc = obd_llog_connect(exp, body);
1349 #define ost_init_sec_none(reply, exp) \
1351 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1352 OBD_CONNECT_RMT_CLIENT_FORCE | \
1353 OBD_CONNECT_OSS_CAPA); \
1354 cfs_spin_lock(&exp->exp_lock); \
1355 exp->exp_connect_flags = reply->ocd_connect_flags; \
1356 cfs_spin_unlock(&exp->exp_lock); \
1359 static int ost_init_sec_level(struct ptlrpc_request *req)
1361 struct obd_export *exp = req->rq_export;
1362 struct req_capsule *pill = &req->rq_pill;
1363 struct obd_device *obd = exp->exp_obd;
1364 struct filter_obd *filter = &obd->u.filter;
1365 char *client = libcfs_nid2str(req->rq_peer.nid);
1366 struct obd_connect_data *data, *reply;
1370 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1371 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1372 if (data == NULL || reply == NULL)
1375 /* connection from MDT is always trusted */
1376 if (req->rq_auth_usr_mdt) {
1377 ost_init_sec_none(reply, exp);
1381 /* no GSS support case */
1382 if (!req->rq_auth_gss) {
1383 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1384 CWARN("client %s -> target %s does not user GSS, "
1385 "can not run under security level %d.\n",
1386 client, obd->obd_name, filter->fo_sec_level);
1389 ost_init_sec_none(reply, exp);
1394 /* old version case */
1395 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1396 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1397 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1398 CWARN("client %s -> target %s uses old version, "
1399 "can not run under security level %d.\n",
1400 client, obd->obd_name, filter->fo_sec_level);
1403 CWARN("client %s -> target %s uses old version, "
1404 "run under security level %d.\n",
1405 client, obd->obd_name, filter->fo_sec_level);
1406 ost_init_sec_none(reply, exp);
1411 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1413 if (!req->rq_auth_remote)
1414 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1415 "asked to be remote.\n", client, obd->obd_name);
1416 } else if (req->rq_auth_remote) {
1418 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1419 "as remote by default.\n", client, obd->obd_name);
1423 if (!filter->fo_fl_oss_capa) {
1424 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1425 " but OSS capabilities are not enabled: %d.\n",
1426 client, obd->obd_name, filter->fo_fl_oss_capa);
1431 switch (filter->fo_sec_level) {
1432 case LUSTRE_SEC_NONE:
1434 ost_init_sec_none(reply, exp);
1437 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1438 "can not run under security level %d.\n",
1439 client, obd->obd_name, filter->fo_sec_level);
1442 case LUSTRE_SEC_REMOTE:
1444 ost_init_sec_none(reply, exp);
1446 case LUSTRE_SEC_ALL:
1448 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1449 OBD_CONNECT_RMT_CLIENT_FORCE);
1450 if (!filter->fo_fl_oss_capa)
1451 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1453 cfs_spin_lock(&exp->exp_lock);
1454 exp->exp_connect_flags = reply->ocd_connect_flags;
1455 cfs_spin_unlock(&exp->exp_lock);
1467 * this should be done in filter_connect()/filter_reconnect(), but
1468 * we can't obtain information like NID, which stored in incoming
1469 * request, thus can't decide what flavor to use. so we do it here.
1471 * This hack should be removed after the OST stack be rewritten, just
1472 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1474 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1476 struct obd_export *exp = req->rq_export;
1477 struct filter_obd *filter = &exp->exp_obd->u.filter;
1478 struct sptlrpc_flavor flvr;
1481 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1482 LUSTRE_ECHO_NAME) == 0)) {
1483 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1487 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1488 cfs_read_lock(&filter->fo_sptlrpc_lock);
1489 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1493 cfs_read_unlock(&filter->fo_sptlrpc_lock);
1495 cfs_spin_lock(&exp->exp_lock);
1497 exp->exp_sp_peer = req->rq_sp_from;
1498 exp->exp_flvr = flvr;
1500 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1501 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1502 CERROR("unauthorized rpc flavor %x from %s, "
1503 "expect %x\n", req->rq_flvr.sf_rpc,
1504 libcfs_nid2str(req->rq_peer.nid),
1505 exp->exp_flvr.sf_rpc);
1509 cfs_spin_unlock(&exp->exp_lock);
1511 if (exp->exp_sp_peer != req->rq_sp_from) {
1512 CERROR("RPC source %s doesn't match %s\n",
1513 sptlrpc_part2name(req->rq_sp_from),
1514 sptlrpc_part2name(exp->exp_sp_peer));
1517 rc = sptlrpc_target_export_check(exp, req);
1524 /* Ensure that data and metadata are synced to the disk when lock is cancelled
1526 int ost_blocking_ast(struct ldlm_lock *lock,
1527 struct ldlm_lock_desc *desc,
1528 void *data, int flag)
1530 __u32 sync_lock_cancel = 0;
1531 __u32 len = sizeof(sync_lock_cancel);
1535 rc = obd_get_info(NULL, lock->l_export, sizeof(KEY_SYNC_LOCK_CANCEL),
1536 KEY_SYNC_LOCK_CANCEL, &len, &sync_lock_cancel, NULL);
1538 if (!rc && flag == LDLM_CB_CANCELING &&
1539 (lock->l_granted_mode & (LCK_PW|LCK_GROUP)) &&
1540 (sync_lock_cancel == ALWAYS_SYNC_ON_CANCEL ||
1541 (sync_lock_cancel == BLOCKING_SYNC_ON_CANCEL &&
1542 lock->l_flags & LDLM_FL_CBPENDING))) {
1543 struct obd_info *oinfo;
1547 OBD_ALLOC_PTR(oinfo);
1552 OBD_FREE_PTR(oinfo);
1555 oa->o_id = lock->l_resource->lr_name.name[0];
1556 oa->o_seq = lock->l_resource->lr_name.name[1];
1557 oa->o_valid = OBD_MD_FLID|OBD_MD_FLGROUP;
1560 rc = obd_sync(NULL, lock->l_export, oinfo,
1561 lock->l_policy_data.l_extent.start,
1562 lock->l_policy_data.l_extent.end, NULL);
1564 CERROR("Error %d syncing data on lock cancel\n", rc);
1567 OBD_FREE_PTR(oinfo);
1570 rc = ldlm_server_blocking_ast(lock, desc, data, flag);
1574 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1575 struct obd_device *obd, int *process)
1577 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1578 case OST_CONNECT: /* This will never get here, but for completeness. */
1579 case OST_DISCONNECT:
1590 case OBD_LOG_CANCEL:
1592 *process = target_queue_recovery_request(req, obd);
1596 DEBUG_REQ(D_WARNING, req, "not permitted during recovery");
1602 int ost_msg_check_version(struct lustre_msg *msg)
1606 switch(lustre_msg_get_opc(msg)) {
1608 case OST_DISCONNECT:
1611 case SEC_CTX_INIT_CONT:
1613 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1615 CERROR("bad opc %u version %08x, expecting %08x\n",
1616 lustre_msg_get_opc(msg),
1617 lustre_msg_get_version(msg),
1618 LUSTRE_OBD_VERSION);
1631 #ifdef HAVE_QUOTA_SUPPORT
1632 case OST_QUOTACHECK:
1634 case OST_QUOTA_ADJUST_QUNIT:
1636 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1638 CERROR("bad opc %u version %08x, expecting %08x\n",
1639 lustre_msg_get_opc(msg),
1640 lustre_msg_get_version(msg),
1641 LUSTRE_OST_VERSION);
1646 case LDLM_BL_CALLBACK:
1647 case LDLM_CP_CALLBACK:
1648 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1650 CERROR("bad opc %u version %08x, expecting %08x\n",
1651 lustre_msg_get_opc(msg),
1652 lustre_msg_get_version(msg),
1653 LUSTRE_DLM_VERSION);
1655 case LLOG_ORIGIN_CONNECT:
1656 case OBD_LOG_CANCEL:
1657 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1659 CERROR("bad opc %u version %08x, expecting %08x\n",
1660 lustre_msg_get_opc(msg),
1661 lustre_msg_get_version(msg),
1662 LUSTRE_LOG_VERSION);
1665 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1671 struct ost_prolong_data {
1672 struct ptlrpc_request *opd_req;
1673 struct obd_export *opd_exp;
1674 struct obdo *opd_oa;
1675 struct ldlm_res_id opd_resid;
1676 struct ldlm_extent opd_extent;
1677 ldlm_mode_t opd_mode;
1678 unsigned int opd_locks;
1682 /* prolong locks for the current service time of the corresponding
1683 * portal (= OST_IO_PORTAL)
1685 static inline int prolong_timeout(struct ptlrpc_request *req)
1687 struct ptlrpc_service *svc = req->rq_rqbd->rqbd_service;
1690 return obd_timeout / 2;
1692 return max(at_est2timeout(at_get(&svc->srv_at_estimate)), ldlm_timeout);
1695 static void ost_prolong_lock_one(struct ost_prolong_data *opd,
1696 struct ldlm_lock *lock)
1698 LASSERT(lock->l_req_mode == lock->l_granted_mode);
1699 LASSERT(lock->l_export == opd->opd_exp);
1701 /* XXX: never try to grab resource lock here because we're inside
1702 * exp_bl_list_lock; in ldlm_lockd.c to handle waiting list we take
1703 * res lock and then exp_bl_list_lock. */
1705 if (!(lock->l_flags & LDLM_FL_AST_SENT))
1706 /* ignore locks not being cancelled */
1710 "refreshed for req x"LPU64" ext("LPU64"->"LPU64") to %ds.\n",
1711 opd->opd_req->rq_xid, opd->opd_extent.start,
1712 opd->opd_extent.end, opd->opd_timeout);
1714 /* OK. this is a possible lock the user holds doing I/O
1715 * let's refresh eviction timer for it */
1716 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
1720 static void ost_prolong_locks(struct ost_prolong_data *data)
1722 struct obd_export *exp = data->opd_exp;
1723 struct obdo *oa = data->opd_oa;
1724 struct ldlm_lock *lock;
1727 if (oa->o_valid & OBD_MD_FLHANDLE) {
1728 /* mostly a request should be covered by only one lock, try
1730 lock = ldlm_handle2lock(&oa->o_handle);
1732 /* Fast path to check if the lock covers the whole IO
1733 * region exclusively. */
1734 if (lock->l_granted_mode == LCK_PW &&
1735 ldlm_extent_contain(&lock->l_policy_data.l_extent,
1736 &data->opd_extent)) {
1738 ost_prolong_lock_one(data, lock);
1739 LDLM_LOCK_PUT(lock);
1742 LDLM_LOCK_PUT(lock);
1747 cfs_spin_lock_bh(&exp->exp_bl_list_lock);
1748 cfs_list_for_each_entry(lock, &exp->exp_bl_list, l_exp_list) {
1749 LASSERT(lock->l_flags & LDLM_FL_AST_SENT);
1750 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
1752 if (!ldlm_res_eq(&data->opd_resid, &lock->l_resource->lr_name))
1755 if (!ldlm_extent_overlap(&lock->l_policy_data.l_extent,
1759 ost_prolong_lock_one(data, lock);
1761 cfs_spin_unlock_bh(&exp->exp_bl_list_lock);
1767 * Returns 1 if the given PTLRPC matches the given LDLM locks, or 0 if it does
1770 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1771 struct ldlm_lock *lock)
1773 struct niobuf_remote *nb;
1774 struct obd_ioobj *ioo;
1776 struct ldlm_extent ext;
1779 opc = lustre_msg_get_opc(req->rq_reqmsg);
1780 LASSERT(opc == OST_READ || opc == OST_WRITE);
1782 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1783 LASSERT(ioo != NULL);
1785 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1786 LASSERT(nb != NULL);
1788 ext.start = nb->offset;
1789 nb += ioo->ioo_bufcnt - 1;
1790 ext.end = nb->offset + nb->len - 1;
1792 LASSERT(lock->l_resource != NULL);
1793 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_seq,
1794 &lock->l_resource->lr_name))
1798 if (opc == OST_READ)
1800 if (!(lock->l_granted_mode & mode))
1803 RETURN(ldlm_extent_overlap(&lock->l_policy_data.l_extent, &ext));
1807 * High-priority queue request check for whether the given PTLRPC request (\a
1808 * req) is blocking an LDLM lock cancel.
1810 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1811 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1813 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1814 * function looks only at OST_READs and OST_WRITEs.
1816 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1818 struct obd_device *obd = req->rq_export->exp_obd;
1819 struct ost_body *body;
1820 struct obd_ioobj *ioo;
1821 struct niobuf_remote *nb;
1822 struct ost_prolong_data opd = { 0 };
1827 * Use LASSERT to do sanity check because malformed RPCs should have
1828 * been filtered out in ost_hpreq_handler().
1830 opc = lustre_msg_get_opc(req->rq_reqmsg);
1831 LASSERT(opc == OST_READ || opc == OST_WRITE);
1833 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1834 LASSERT(body != NULL);
1836 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1837 LASSERT(ioo != NULL);
1839 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1840 LASSERT(nb != NULL);
1841 LASSERT(!(nb->flags & OBD_BRW_SRVLOCK));
1843 osc_build_res_name(ioo->ioo_id, ioo->ioo_seq, &opd.opd_resid);
1847 if (opc == OST_READ)
1849 opd.opd_mode = mode;
1850 opd.opd_exp = req->rq_export;
1851 opd.opd_oa = &body->oa;
1852 opd.opd_extent.start = nb->offset;
1853 nb += ioo->ioo_bufcnt - 1;
1854 opd.opd_extent.end = nb->offset + nb->len - 1;
1855 opd.opd_timeout = prolong_timeout(req);
1857 DEBUG_REQ(D_RPCTRACE, req,
1858 "%s %s: refresh rw locks: " LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1859 obd->obd_name, cfs_current()->comm,
1860 opd.opd_resid.name[0], opd.opd_resid.name[1],
1861 opd.opd_extent.start, opd.opd_extent.end);
1863 ost_prolong_locks(&opd);
1865 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
1866 obd->obd_name, opd.opd_locks, req);
1868 RETURN(opd.opd_locks);
1871 static void ost_rw_hpreq_fini(struct ptlrpc_request *req)
1873 (void)ost_rw_hpreq_check(req);
1877 * Like ost_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
1879 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1880 struct ldlm_lock *lock)
1882 struct ost_body *body;
1885 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1886 LASSERT(body != NULL);
1888 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1889 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1896 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
1898 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1900 struct obd_device *obd = req->rq_export->exp_obd;
1901 struct ost_body *body;
1903 struct ost_prolong_data opd = { 0 };
1907 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1908 LASSERT(body != NULL);
1911 LASSERT(!(oa->o_valid & OBD_MD_FLFLAGS) ||
1912 !(oa->o_flags & OBD_FL_SRVLOCK));
1915 end = start + oa->o_blocks;
1918 opd.opd_mode = LCK_PW;
1919 opd.opd_exp = req->rq_export;
1921 opd.opd_extent.start = start;
1922 opd.opd_extent.end = end;
1923 if (oa->o_blocks == OBD_OBJECT_EOF)
1924 opd.opd_extent.end = OBD_OBJECT_EOF;
1925 opd.opd_timeout = prolong_timeout(req);
1927 osc_build_res_name(oa->o_id, oa->o_seq, &opd.opd_resid);
1930 "%s: refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1932 opd.opd_resid.name[0], opd.opd_resid.name[1],
1933 opd.opd_extent.start, opd.opd_extent.end);
1935 ost_prolong_locks(&opd);
1937 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
1938 obd->obd_name, opd.opd_locks, req);
1940 RETURN(opd.opd_locks > 0);
1943 static void ost_punch_hpreq_fini(struct ptlrpc_request *req)
1945 (void)ost_punch_hpreq_check(req);
1948 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
1949 .hpreq_lock_match = ost_rw_hpreq_lock_match,
1950 .hpreq_check = ost_rw_hpreq_check,
1951 .hpreq_fini = ost_rw_hpreq_fini
1954 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
1955 .hpreq_lock_match = ost_punch_hpreq_lock_match,
1956 .hpreq_check = ost_punch_hpreq_check,
1957 .hpreq_fini = ost_punch_hpreq_fini
1960 /** Assign high priority operations to the request if needed. */
1961 static int ost_hpreq_handler(struct ptlrpc_request *req)
1964 if (req->rq_export) {
1965 int opc = lustre_msg_get_opc(req->rq_reqmsg);
1966 struct ost_body *body;
1968 if (opc == OST_READ || opc == OST_WRITE) {
1969 struct niobuf_remote *nb;
1970 struct obd_ioobj *ioo;
1971 int objcount, niocount;
1975 /* RPCs on the H-P queue can be inspected before
1976 * ost_handler() initializes their pills, so we
1977 * initialize that here. Capsule initialization is
1978 * idempotent, as is setting the pill's format (provided
1979 * it doesn't change).
1981 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1982 if (opc == OST_READ)
1983 req_capsule_set(&req->rq_pill,
1986 req_capsule_set(&req->rq_pill,
1987 &RQF_OST_BRW_WRITE);
1989 body = req_capsule_client_get(&req->rq_pill,
1992 CERROR("Missing/short ost_body\n");
1996 objcount = req_capsule_get_size(&req->rq_pill,
2000 if (objcount == 0) {
2001 CERROR("Missing/short ioobj\n");
2005 CERROR("too many ioobjs (%d)\n", objcount);
2009 ioo = req_capsule_client_get(&req->rq_pill,
2012 CERROR("Missing/short ioobj\n");
2016 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
2018 CERROR("invalid object ids\n");
2022 for (niocount = i = 0; i < objcount; i++) {
2023 if (ioo[i].ioo_bufcnt == 0) {
2024 CERROR("ioo[%d] has zero bufcnt\n", i);
2027 niocount += ioo[i].ioo_bufcnt;
2029 if (niocount > PTLRPC_MAX_BRW_PAGES) {
2030 DEBUG_REQ(D_RPCTRACE, req,
2031 "bulk has too many pages (%d)",
2036 nb = req_capsule_client_get(&req->rq_pill,
2037 &RMF_NIOBUF_REMOTE);
2039 CERROR("Missing/short niobuf\n");
2043 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
2044 req->rq_ops = &ost_hpreq_rw;
2045 } else if (opc == OST_PUNCH) {
2046 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2047 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2049 body = req_capsule_client_get(&req->rq_pill,
2052 CERROR("Missing/short ost_body\n");
2056 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
2057 !(body->oa.o_flags & OBD_FL_SRVLOCK))
2058 req->rq_ops = &ost_hpreq_punch;
2064 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
2065 int ost_handle(struct ptlrpc_request *req)
2067 struct obd_trans_info trans_info = { 0, };
2068 struct obd_trans_info *oti = &trans_info;
2069 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
2070 struct obd_device *obd = NULL;
2073 /* OST module is kept between remounts, but the last reference
2074 * to specific module (say, osd or ofd) kills all related keys
2075 * from the environment. so we have to refill it until the root
2076 * cause is fixed properly */
2077 lu_env_refill(req->rq_svc_thread->t_env);
2079 LASSERT(current->journal_info == NULL);
2081 /* primordial rpcs don't affect server recovery */
2082 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2084 case SEC_CTX_INIT_CONT:
2089 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2091 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
2092 if (!class_connected_export(req->rq_export)) {
2093 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
2094 lustre_msg_get_opc(req->rq_reqmsg),
2095 libcfs_id2str(req->rq_peer));
2096 req->rq_status = -ENOTCONN;
2097 GOTO(out, rc = -ENOTCONN);
2100 obd = req->rq_export->exp_obd;
2102 /* Check for aborted recovery. */
2103 if (obd->obd_recovering) {
2104 rc = ost_filter_recovery_request(req, obd,
2106 if (rc || !should_process)
2108 else if (should_process < 0) {
2109 req->rq_status = should_process;
2110 rc = ptlrpc_error(req);
2118 rc = ost_msg_check_version(req->rq_reqmsg);
2122 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2124 CDEBUG(D_INODE, "connect\n");
2125 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
2126 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
2128 rc = target_handle_connect(req);
2129 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
2132 rc = ost_init_sec_level(req);
2134 rc = ost_connect_check_sptlrpc(req);
2138 case OST_DISCONNECT:
2139 CDEBUG(D_INODE, "disconnect\n");
2140 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
2141 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
2143 rc = target_handle_disconnect(req);
2146 CDEBUG(D_INODE, "create\n");
2147 req_capsule_set(&req->rq_pill, &RQF_OST_CREATE);
2148 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
2150 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2151 GOTO(out, rc = -EROFS);
2152 rc = ost_create(req->rq_export, req, oti);
2155 CDEBUG(D_INODE, "destroy\n");
2156 req_capsule_set(&req->rq_pill, &RQF_OST_DESTROY);
2157 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
2159 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2160 GOTO(out, rc = -EROFS);
2161 rc = ost_destroy(req->rq_export, req, oti);
2164 CDEBUG(D_INODE, "getattr\n");
2165 req_capsule_set(&req->rq_pill, &RQF_OST_GETATTR);
2166 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
2168 rc = ost_getattr(req->rq_export, req);
2171 CDEBUG(D_INODE, "setattr\n");
2172 req_capsule_set(&req->rq_pill, &RQF_OST_SETATTR);
2173 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
2175 rc = ost_setattr(req->rq_export, req, oti);
2178 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_WRITE);
2179 CDEBUG(D_INODE, "write\n");
2180 /* req->rq_request_portal would be nice, if it was set */
2181 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2182 CERROR("%s: deny write request from %s to portal %u\n",
2183 req->rq_export->exp_obd->obd_name,
2184 obd_export_nid2str(req->rq_export),
2185 req->rq_rqbd->rqbd_service->srv_req_portal);
2186 GOTO(out, rc = -EPROTO);
2188 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2190 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
2191 GOTO(out, rc = -ENOSPC);
2192 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2193 GOTO(out, rc = -EROFS);
2194 rc = ost_brw_write(req, oti);
2195 LASSERT(current->journal_info == NULL);
2196 /* ost_brw_write sends its own replies */
2199 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_READ);
2200 CDEBUG(D_INODE, "read\n");
2201 /* req->rq_request_portal would be nice, if it was set */
2202 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2203 CERROR("%s: deny read request from %s to portal %u\n",
2204 req->rq_export->exp_obd->obd_name,
2205 obd_export_nid2str(req->rq_export),
2206 req->rq_rqbd->rqbd_service->srv_req_portal);
2207 GOTO(out, rc = -EPROTO);
2209 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2211 rc = ost_brw_read(req, oti);
2212 LASSERT(current->journal_info == NULL);
2213 /* ost_brw_read sends its own replies */
2216 CDEBUG(D_INODE, "punch\n");
2217 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2218 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2220 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2221 GOTO(out, rc = -EROFS);
2222 rc = ost_punch(req->rq_export, req, oti);
2225 CDEBUG(D_INODE, "statfs\n");
2226 req_capsule_set(&req->rq_pill, &RQF_OST_STATFS);
2227 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2229 rc = ost_statfs(req);
2232 CDEBUG(D_INODE, "sync\n");
2233 req_capsule_set(&req->rq_pill, &RQF_OST_SYNC);
2234 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2236 rc = ost_sync(req->rq_export, req);
2239 DEBUG_REQ(D_INODE, req, "set_info");
2240 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
2241 rc = ost_set_info(req->rq_export, req);
2244 DEBUG_REQ(D_INODE, req, "get_info");
2245 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
2246 rc = ost_get_info(req->rq_export, req);
2248 #ifdef HAVE_QUOTA_SUPPORT
2249 case OST_QUOTACHECK:
2250 CDEBUG(D_INODE, "quotacheck\n");
2251 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2252 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2254 rc = ost_handle_quotacheck(req);
2257 CDEBUG(D_INODE, "quotactl\n");
2258 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2259 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2261 rc = ost_handle_quotactl(req);
2263 case OST_QUOTA_ADJUST_QUNIT:
2264 CDEBUG(D_INODE, "quota_adjust_qunit\n");
2265 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
2266 rc = ost_handle_quota_adjust_qunit(req);
2270 DEBUG_REQ(D_INODE, req, "ping");
2271 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2272 rc = target_handle_ping(req);
2274 /* FIXME - just reply status */
2275 case LLOG_ORIGIN_CONNECT:
2276 DEBUG_REQ(D_INODE, req, "log connect");
2277 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2278 rc = ost_llog_handle_connect(req->rq_export, req);
2279 req->rq_status = rc;
2280 rc = req_capsule_server_pack(&req->rq_pill);
2283 RETURN(ptlrpc_reply(req));
2284 case OBD_LOG_CANCEL:
2285 CDEBUG(D_INODE, "log cancel\n");
2286 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2287 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2289 rc = llog_origin_handle_cancel(req);
2290 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2292 req->rq_status = rc;
2293 rc = req_capsule_server_pack(&req->rq_pill);
2296 RETURN(ptlrpc_reply(req));
2298 CDEBUG(D_INODE, "enqueue\n");
2299 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2300 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2302 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2304 ldlm_server_glimpse_ast);
2305 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2308 CDEBUG(D_INODE, "convert\n");
2309 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2310 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2312 rc = ldlm_handle_convert(req);
2315 CDEBUG(D_INODE, "cancel\n");
2316 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2317 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2319 rc = ldlm_handle_cancel(req);
2321 case LDLM_BL_CALLBACK:
2322 case LDLM_CP_CALLBACK:
2323 CDEBUG(D_INODE, "callback\n");
2324 CERROR("callbacks should not happen on OST\n");
2327 CERROR("Unexpected opcode %d\n",
2328 lustre_msg_get_opc(req->rq_reqmsg));
2329 req->rq_status = -ENOTSUPP;
2330 rc = ptlrpc_error(req);
2334 LASSERT(current->journal_info == NULL);
2337 /* If we're DISCONNECTing, the export_data is already freed */
2338 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2339 target_committed_to_req(req);
2343 oti_to_request(oti, req);
2345 target_send_reply(req, rc, fail);
2348 EXPORT_SYMBOL(ost_handle);
2350 * free per-thread pool created by ost_thread_init().
2352 static void ost_thread_done(struct ptlrpc_thread *thread)
2354 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2359 LASSERT(thread != NULL);
2362 * be prepared to handle partially-initialized pools (because this is
2363 * called from ost_thread_init() for cleanup.
2365 tls = thread->t_data;
2368 thread->t_data = NULL;
2374 * initialize per-thread page pool (bug 5137).
2376 static int ost_thread_init(struct ptlrpc_thread *thread)
2378 struct ost_thread_local_cache *tls;
2382 LASSERT(thread != NULL);
2383 LASSERT(thread->t_data == NULL);
2384 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
2389 thread->t_data = tls;
2393 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2395 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2396 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2398 struct ost_obd *ost = &obd->u.ost;
2399 struct lprocfs_static_vars lvars;
2400 int oss_min_threads;
2401 int oss_max_threads;
2402 int oss_min_create_threads;
2403 int oss_max_create_threads;
2407 rc = cfs_cleanup_group_info();
2411 lprocfs_ost_init_vars(&lvars);
2412 lprocfs_obd_setup(obd, lvars.obd_vars);
2414 cfs_mutex_init(&ost->ost_health_mutex);
2416 if (oss_num_threads) {
2417 /* If oss_num_threads is set, it is the min and the max. */
2418 if (oss_num_threads > OSS_THREADS_MAX)
2419 oss_num_threads = OSS_THREADS_MAX;
2420 if (oss_num_threads < OSS_THREADS_MIN)
2421 oss_num_threads = OSS_THREADS_MIN;
2422 oss_max_threads = oss_min_threads = oss_num_threads;
2424 /* Base min threads on memory and cpus */
2426 cfs_num_possible_cpus() * CFS_NUM_CACHEPAGES >>
2427 (27 - CFS_PAGE_SHIFT);
2428 if (oss_min_threads < OSS_THREADS_MIN)
2429 oss_min_threads = OSS_THREADS_MIN;
2430 /* Insure a 4x range for dynamic threads */
2431 if (oss_min_threads > OSS_THREADS_MAX / 4)
2432 oss_min_threads = OSS_THREADS_MAX / 4;
2433 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
2437 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2438 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
2439 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2440 ost_handle, LUSTRE_OSS_NAME,
2441 obd->obd_proc_entry, target_print_req,
2442 oss_min_threads, oss_max_threads,
2443 "ll_ost", LCT_DT_THREAD, NULL);
2444 if (ost->ost_service == NULL) {
2445 CERROR("failed to start service\n");
2446 GOTO(out_lprocfs, rc = -ENOMEM);
2449 rc = ptlrpc_start_threads(ost->ost_service);
2451 GOTO(out_service, rc = -EINVAL);
2453 if (oss_num_create_threads) {
2454 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
2455 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
2456 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
2457 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
2458 oss_min_create_threads = oss_max_create_threads =
2459 oss_num_create_threads;
2461 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
2462 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
2465 ost->ost_create_service =
2466 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2467 OST_MAXREPSIZE, OST_CREATE_PORTAL,
2468 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2469 ost_handle, "ost_create",
2470 obd->obd_proc_entry, target_print_req,
2471 oss_min_create_threads, oss_max_create_threads,
2472 "ll_ost_creat", LCT_DT_THREAD, NULL);
2473 if (ost->ost_create_service == NULL) {
2474 CERROR("failed to start OST create service\n");
2475 GOTO(out_service, rc = -ENOMEM);
2478 rc = ptlrpc_start_threads(ost->ost_create_service);
2480 GOTO(out_create, rc = -EINVAL);
2482 ost->ost_io_service =
2483 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2484 OST_MAXREPSIZE, OST_IO_PORTAL,
2485 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2486 ost_handle, "ost_io",
2487 obd->obd_proc_entry, target_print_req,
2488 oss_min_threads, oss_max_threads,
2489 "ll_ost_io", LCT_DT_THREAD, ost_hpreq_handler);
2490 if (ost->ost_io_service == NULL) {
2491 CERROR("failed to start OST I/O service\n");
2492 GOTO(out_create, rc = -ENOMEM);
2495 ost->ost_io_service->srv_init = ost_thread_init;
2496 ost->ost_io_service->srv_done = ost_thread_done;
2497 ost->ost_io_service->srv_cpu_affinity = 1;
2498 rc = ptlrpc_start_threads(ost->ost_io_service);
2500 GOTO(out_io, rc = -EINVAL);
2502 ping_evictor_start();
2507 ptlrpc_unregister_service(ost->ost_io_service);
2508 ost->ost_io_service = NULL;
2510 ptlrpc_unregister_service(ost->ost_create_service);
2511 ost->ost_create_service = NULL;
2513 ptlrpc_unregister_service(ost->ost_service);
2514 ost->ost_service = NULL;
2516 lprocfs_obd_cleanup(obd);
2520 static int ost_cleanup(struct obd_device *obd)
2522 struct ost_obd *ost = &obd->u.ost;
2526 ping_evictor_stop();
2528 /* there is no recovery for OST OBD, all recovery is controlled by
2530 LASSERT(obd->obd_recovering == 0);
2531 cfs_mutex_lock(&ost->ost_health_mutex);
2532 ptlrpc_unregister_service(ost->ost_service);
2533 ptlrpc_unregister_service(ost->ost_create_service);
2534 ptlrpc_unregister_service(ost->ost_io_service);
2535 ost->ost_service = NULL;
2536 ost->ost_create_service = NULL;
2537 cfs_mutex_unlock(&ost->ost_health_mutex);
2539 lprocfs_obd_cleanup(obd);
2544 static int ost_health_check(const struct lu_env *env, struct obd_device *obd)
2546 struct ost_obd *ost = &obd->u.ost;
2549 cfs_mutex_lock(&ost->ost_health_mutex);
2550 rc |= ptlrpc_service_health_check(ost->ost_service);
2551 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2552 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2553 cfs_mutex_unlock(&ost->ost_health_mutex);
2556 * health_check to return 0 on healthy
2557 * and 1 on unhealthy.
2565 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2567 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2570 /* use obd ops to offer management infrastructure */
2571 static struct obd_ops ost_obd_ops = {
2572 .o_owner = THIS_MODULE,
2573 .o_setup = ost_setup,
2574 .o_cleanup = ost_cleanup,
2575 .o_health_check = ost_health_check,
2579 static int __init ost_init(void)
2581 struct lprocfs_static_vars lvars;
2585 lprocfs_ost_init_vars(&lvars);
2586 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2587 LUSTRE_OSS_NAME, NULL);
2589 if (ost_num_threads != 0 && oss_num_threads == 0) {
2590 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2591 "use oss_num_threads instead or unset both for "
2592 "dynamic thread startup\n");
2593 oss_num_threads = ost_num_threads;
2599 static void /*__exit*/ ost_exit(void)
2601 class_unregister_type(LUSTRE_OSS_NAME);
2604 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2605 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2606 MODULE_LICENSE("GPL");
2608 module_init(ost_init);
2609 module_exit(ost_exit);