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,
432 struct obd_trans_info *oti)
434 struct ost_body *body, *repbody;
435 struct obd_info *oinfo;
436 struct lustre_capa *capa = NULL;
440 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
444 rc = ost_validate_obdo(exp, &body->oa, NULL);
448 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
449 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
451 CERROR("Missing capability for OST SYNC");
456 rc = req_capsule_server_pack(&req->rq_pill);
460 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
461 repbody->oa = body->oa;
463 OBD_ALLOC_PTR(oinfo);
467 oinfo->oi_oa = &repbody->oa;
468 oinfo->oi_capa = capa;
469 oinfo->oi_jobid = oti->oti_jobid;
470 req->rq_status = obd_sync(req->rq_svc_thread->t_env, exp, oinfo,
471 repbody->oa.o_size, repbody->oa.o_blocks,
475 ost_drop_id(exp, &repbody->oa);
479 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
480 struct obd_trans_info *oti)
482 struct ost_body *body, *repbody;
483 struct obd_info *oinfo;
484 struct lustre_capa *capa = NULL;
488 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
492 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
496 rc = req_capsule_server_pack(&req->rq_pill);
500 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
501 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
503 CERROR("Missing capability for OST SETATTR");
508 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
509 repbody->oa = body->oa;
511 OBD_ALLOC_PTR(oinfo);
514 oinfo->oi_oa = &repbody->oa;
515 oinfo->oi_capa = capa;
517 req->rq_status = obd_setattr(req->rq_svc_thread->t_env, exp, oinfo,
522 ost_drop_id(exp, &repbody->oa);
526 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
527 cksum_type_t cksum_type)
532 cksum = init_checksum(cksum_type);
533 for (i = 0; i < desc->bd_iov_count; i++) {
534 struct page *page = desc->bd_iov[i].kiov_page;
535 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
536 char *ptr = kmap(page) + off;
537 int len = desc->bd_iov[i].kiov_len;
539 /* corrupt the data before we compute the checksum, to
540 * simulate a client->OST data error */
541 if (i == 0 && opc == OST_WRITE &&
542 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
543 memcpy(ptr, "bad3", min(4, len));
544 cksum = compute_checksum(cksum, ptr, len, cksum_type);
545 /* corrupt the data after we compute the checksum, to
546 * simulate an OST->client data error */
547 if (i == 0 && opc == OST_READ &&
548 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
549 memcpy(ptr, "bad4", min(4, len));
550 /* nobody should use corrupted page again */
551 ClearPageUptodate(page);
556 return fini_checksum(cksum, cksum_type);
559 static int ost_brw_lock_get(int mode, struct obd_export *exp,
560 struct obd_ioobj *obj, struct niobuf_remote *nb,
561 struct lustre_handle *lh)
564 int nrbufs = obj->ioo_bufcnt;
565 struct ldlm_res_id res_id;
566 ldlm_policy_data_t policy;
570 osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id);
571 LASSERT(mode == LCK_PR || mode == LCK_PW);
572 LASSERT(!lustre_handle_is_used(lh));
574 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
577 for (i = 1; i < nrbufs; i ++)
578 if ((nb[0].flags & OBD_BRW_SRVLOCK) !=
579 (nb[i].flags & OBD_BRW_SRVLOCK))
582 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
583 policy.l_extent.end = (nb[nrbufs - 1].offset +
584 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
586 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
587 LDLM_EXTENT, &policy, mode, &flags,
588 ldlm_blocking_ast, ldlm_completion_ast,
589 ldlm_glimpse_ast, NULL, 0, NULL, lh));
592 static void ost_brw_lock_put(int mode,
593 struct obd_ioobj *obj, struct niobuf_remote *niob,
594 struct lustre_handle *lh)
597 LASSERT(mode == LCK_PR || mode == LCK_PW);
598 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
599 lustre_handle_is_used(lh));
600 if (lustre_handle_is_used(lh))
601 ldlm_lock_decref(lh, mode);
605 /* Allocate thread local buffers if needed */
606 static struct ost_thread_local_cache *ost_tls_get(struct ptlrpc_request *r)
608 struct ost_thread_local_cache *tls =
609 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
611 /* In normal mode of operation an I/O request is serviced only
612 * by ll_ost_io threads each of them has own tls buffers allocated by
614 * During recovery, an I/O request may be queued until any of the ost
615 * service threads process it. Not necessary it should be one of
616 * ll_ost_io threads. In that case we dynamically allocating tls
617 * buffers for the request service time. */
618 if (unlikely(tls == NULL)) {
619 LASSERT(r->rq_export->exp_in_recovery);
623 r->rq_svc_thread->t_data = tls;
629 /* Free thread local buffers if they were allocated only for servicing
630 * this one request */
631 static void ost_tls_put(struct ptlrpc_request *r)
633 struct ost_thread_local_cache *tls =
634 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
636 if (unlikely(tls->temporary)) {
638 r->rq_svc_thread->t_data = NULL;
642 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
644 struct ptlrpc_bulk_desc *desc = NULL;
645 struct obd_export *exp = req->rq_export;
646 struct niobuf_remote *remote_nb;
647 struct niobuf_local *local_nb;
648 struct obd_ioobj *ioo;
649 struct ost_body *body, *repbody;
650 struct lustre_capa *capa = NULL;
651 struct l_wait_info lwi;
652 struct lustre_handle lockh = { 0 };
653 int niocount, npages, nob = 0, rc, i;
655 struct ost_thread_local_cache *tls;
658 req->rq_bulk_read = 1;
660 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
661 GOTO(out, rc = -EIO);
663 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
665 /* Check if there is eviction in progress, and if so, wait for it to
667 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
668 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
669 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
670 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
674 GOTO(out, rc = -ENOTCONN);
676 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
677 * ost_rw_hpreq_check(). */
678 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
680 GOTO(out, rc = -EFAULT);
683 * A req_capsule_X_get_array(pill, field, ptr_to_element_count) function
684 * would be useful here and wherever we get &RMF_OBD_IOOBJ and
685 * &RMF_NIOBUF_REMOTE.
687 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
689 GOTO(out, rc = -EFAULT);
691 rc = ost_validate_obdo(exp, &body->oa, ioo);
695 niocount = ioo->ioo_bufcnt;
696 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
697 if (remote_nb == NULL)
698 GOTO(out, rc = -EFAULT);
700 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
701 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
703 CERROR("Missing capability for OST BRW READ");
704 GOTO(out, rc = -EFAULT);
708 rc = req_capsule_server_pack(&req->rq_pill);
712 tls = ost_tls_get(req);
714 GOTO(out_bulk, rc = -ENOMEM);
715 local_nb = tls->local;
717 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
722 * If getting the lock took more time than
723 * client was willing to wait, drop it. b=11330
725 if (cfs_time_current_sec() > req->rq_deadline ||
726 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
728 CERROR("Dropping timed-out read from %s because locking"
729 "object "LPX64" took %ld seconds (limit was %ld).\n",
730 libcfs_id2str(req->rq_peer), ioo->ioo_id,
731 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
732 req->rq_deadline - req->rq_arrival_time.tv_sec);
733 GOTO(out_lock, rc = -ETIMEDOUT);
736 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
737 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
739 npages = OST_THREAD_POOL_SIZE;
740 rc = obd_preprw(req->rq_svc_thread->t_env, OBD_BRW_READ, exp,
741 &repbody->oa, 1, ioo, remote_nb, &npages, local_nb,
746 desc = ptlrpc_prep_bulk_exp(req, npages,
747 BULK_PUT_SOURCE, OST_BULK_PORTAL);
749 GOTO(out_commitrw, rc = -ENOMEM);
752 for (i = 0; i < npages; i++) {
753 int page_rc = local_nb[i].rc;
755 if (page_rc < 0) { /* error */
761 if (page_rc != 0) { /* some data! */
762 LASSERT (local_nb[i].page != NULL);
763 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
764 local_nb[i].offset & ~CFS_PAGE_MASK,
768 if (page_rc != local_nb[i].len) { /* short read */
769 /* All subsequent pages should be 0 */
771 LASSERT(local_nb[i].rc == 0);
776 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
777 cksum_type_t cksum_type =
778 cksum_type_unpack(repbody->oa.o_valid & OBD_MD_FLFLAGS ?
779 repbody->oa.o_flags : 0);
780 repbody->oa.o_flags = cksum_type_pack(cksum_type);
781 repbody->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
782 repbody->oa.o_cksum = ost_checksum_bulk(desc, OST_READ,cksum_type);
783 CDEBUG(D_PAGE, "checksum at read origin: %x\n",
784 repbody->oa.o_cksum);
786 repbody->oa.o_valid = 0;
788 /* We're finishing using body->oa as an input variable */
790 /* Check if client was evicted while we were doing i/o before touching
793 if (likely(!CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2)))
794 rc = target_bulk_io(exp, desc, &lwi);
799 /* Must commit after prep above in all cases */
800 rc = obd_commitrw(req->rq_svc_thread->t_env, OBD_BRW_READ, exp,
801 &repbody->oa, 1, ioo, remote_nb, npages, local_nb,
805 ost_drop_id(exp, &repbody->oa);
808 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
812 if (desc && !CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2))
813 ptlrpc_free_bulk(desc);
817 req->rq_status = nob;
818 ptlrpc_lprocfs_brw(req, nob);
819 target_committed_to_req(req);
821 } else if (!no_reply) {
822 /* Only reply if there was no comms problem with bulk */
823 target_committed_to_req(req);
827 /* reply out callback would free */
828 ptlrpc_req_drop_rs(req);
829 LCONSOLE_WARN("%s: Bulk IO read error with %s (at %s), "
830 "client will retry: rc %d\n",
831 exp->exp_obd->obd_name,
832 obd_uuid2str(&exp->exp_client_uuid),
833 obd_export_nid2str(exp), rc);
835 /* send a bulk after reply to simulate a network delay or reordering
837 if (unlikely(CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2))) {
839 struct l_wait_info lwi1;
841 CDEBUG(D_INFO, "reorder BULK\n");
842 cfs_waitq_init(&waitq);
844 lwi1 = LWI_TIMEOUT_INTR(cfs_time_seconds(3), NULL, NULL, NULL);
845 l_wait_event(waitq, 0, &lwi1);
846 rc = target_bulk_io(exp, desc, &lwi);
847 ptlrpc_free_bulk(desc);
853 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
855 struct ptlrpc_bulk_desc *desc = NULL;
856 struct obd_export *exp = req->rq_export;
857 struct niobuf_remote *remote_nb;
858 struct niobuf_local *local_nb;
859 struct obd_ioobj *ioo;
860 struct ost_body *body, *repbody;
861 struct l_wait_info lwi;
862 struct lustre_handle lockh = {0};
863 struct lustre_capa *capa = NULL;
865 int objcount, niocount, npages;
867 obd_count client_cksum = 0, server_cksum = 0;
868 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
869 int no_reply = 0, mmap = 0;
870 __u32 o_uid = 0, o_gid = 0;
871 struct ost_thread_local_cache *tls;
874 req->rq_bulk_write = 1;
876 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
877 GOTO(out, rc = -EIO);
878 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
879 GOTO(out, rc = -EFAULT);
881 /* pause before transaction has been started */
882 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
884 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
885 * ost_rw_hpreq_check(). */
886 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
888 GOTO(out, rc = -EFAULT);
890 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
891 RCL_CLIENT) / sizeof(*ioo);
892 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
894 GOTO(out, rc = -EFAULT);
896 rc = ost_validate_obdo(exp, &body->oa, ioo);
900 for (niocount = i = 0; i < objcount; i++)
901 niocount += ioo[i].ioo_bufcnt;
904 * It'd be nice to have a capsule function to indicate how many elements
905 * there were in a buffer for an RMF that's declared to be an array.
906 * It's easy enough to compute the number of elements here though.
908 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
909 if (remote_nb == NULL || niocount != (req_capsule_get_size(&req->rq_pill,
910 &RMF_NIOBUF_REMOTE, RCL_CLIENT) / sizeof(*remote_nb)))
911 GOTO(out, rc = -EFAULT);
913 if ((remote_nb[0].flags & OBD_BRW_MEMALLOC) &&
914 (exp->exp_connection->c_peer.nid == exp->exp_connection->c_self))
915 cfs_memory_pressure_set();
917 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
918 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
920 CERROR("Missing capability for OST BRW WRITE");
921 GOTO(out, rc = -EFAULT);
925 req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER,
926 niocount * sizeof(*rcs));
927 rc = req_capsule_server_pack(&req->rq_pill);
930 CFS_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, cfs_fail_val);
931 rcs = req_capsule_server_get(&req->rq_pill, &RMF_RCS);
933 tls = ost_tls_get(req);
935 GOTO(out_bulk, rc = -ENOMEM);
936 local_nb = tls->local;
938 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
943 * If getting the lock took more time than
944 * client was willing to wait, drop it. b=11330
946 if (cfs_time_current_sec() > req->rq_deadline ||
947 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
949 CERROR("Dropping timed-out write from %s because locking "
950 "object "LPX64" took %ld seconds (limit was %ld).\n",
951 libcfs_id2str(req->rq_peer), ioo->ioo_id,
952 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
953 req->rq_deadline - req->rq_arrival_time.tv_sec);
954 GOTO(out_lock, rc = -ETIMEDOUT);
957 /* obd_preprw clobbers oa->valid, so save what we need */
958 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
959 client_cksum = body->oa.o_cksum;
960 if (body->oa.o_valid & OBD_MD_FLFLAGS)
961 cksum_type = cksum_type_unpack(body->oa.o_flags);
963 if (body->oa.o_valid & OBD_MD_FLFLAGS && body->oa.o_flags & OBD_FL_MMAP)
966 /* Because we already sync grant info with client when reconnect,
967 * grant info will be cleared for resent req, then fed_grant and
968 * total_grant will not be modified in following preprw_write */
969 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
970 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
971 body->oa.o_valid &= ~OBD_MD_FLGRANT;
974 if (exp_connect_rmtclient(exp)) {
975 o_uid = body->oa.o_uid;
976 o_gid = body->oa.o_gid;
979 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
980 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
982 npages = OST_THREAD_POOL_SIZE;
983 rc = obd_preprw(req->rq_svc_thread->t_env, OBD_BRW_WRITE, exp,
984 &repbody->oa, objcount, ioo, remote_nb, &npages,
985 local_nb, oti, capa);
989 desc = ptlrpc_prep_bulk_exp(req, npages,
990 BULK_GET_SINK, OST_BULK_PORTAL);
992 GOTO(skip_transfer, rc = -ENOMEM);
994 /* NB Having prepped, we must commit... */
996 for (i = 0; i < npages; i++)
997 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
998 local_nb[i].offset & ~CFS_PAGE_MASK,
1001 rc = sptlrpc_svc_prep_bulk(req, desc);
1005 rc = target_bulk_io(exp, desc, &lwi);
1009 if (client_cksum != 0 && rc == 0) {
1010 static int cksum_counter;
1011 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1012 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1013 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1014 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1015 repbody->oa.o_cksum = server_cksum;
1017 if (unlikely(client_cksum != server_cksum)) {
1018 CDEBUG_LIMIT(mmap ? D_INFO : D_ERROR,
1019 "client csum %x, server csum %x\n",
1020 client_cksum, server_cksum);
1022 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1023 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1024 cksum_counter, libcfs_id2str(req->rq_peer),
1029 /* Must commit after prep above in all cases */
1030 rc = obd_commitrw(req->rq_svc_thread->t_env, OBD_BRW_WRITE, exp,
1031 &repbody->oa, objcount, ioo, remote_nb, npages,
1033 if (rc == -ENOTCONN)
1034 /* quota acquire process has been given up because
1035 * either the client has been evicted or the client
1036 * has timed out the request already */
1039 if (exp_connect_rmtclient(exp)) {
1040 repbody->oa.o_uid = o_uid;
1041 repbody->oa.o_gid = o_gid;
1045 * Disable sending mtime back to the client. If the client locked the
1046 * whole object, then it has already updated the mtime on its side,
1047 * otherwise it will have to glimpse anyway (see bug 21489, comment 32)
1049 repbody->oa.o_valid &= ~(OBD_MD_FLMTIME | OBD_MD_FLATIME);
1051 if (unlikely(client_cksum != server_cksum && rc == 0 && !mmap)) {
1052 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1057 if (new_cksum == server_cksum)
1058 msg = "changed in transit before arrival at OST";
1059 else if (new_cksum == client_cksum)
1060 msg = "initial checksum before message complete";
1062 msg = "changed in transit AND after initial checksum";
1064 if (req->rq_peer.nid == desc->bd_sender) {
1068 router = libcfs_nid2str(desc->bd_sender);
1071 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1072 "%s%s%s inode "DFID" object "
1073 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1074 exp->exp_obd->obd_name, msg,
1075 libcfs_id2str(req->rq_peer),
1077 body->oa.o_valid & OBD_MD_FLFID ?
1078 body->oa.o_parent_seq : (__u64)0,
1079 body->oa.o_valid & OBD_MD_FLFID ?
1080 body->oa.o_parent_oid : 0,
1081 body->oa.o_valid & OBD_MD_FLFID ?
1082 body->oa.o_parent_ver : 0,
1084 body->oa.o_valid & OBD_MD_FLGROUP ?
1085 body->oa.o_seq : (__u64)0,
1087 local_nb[npages-1].offset +
1088 local_nb[npages-1].len - 1 );
1089 CERROR("client csum %x, original server csum %x, "
1090 "server csum now %x\n",
1091 client_cksum, server_cksum, new_cksum);
1097 /* set per-requested niobuf return codes */
1098 for (i = j = 0; i < niocount; i++) {
1099 int len = remote_nb[i].len;
1104 LASSERT(j < npages);
1105 if (local_nb[j].rc < 0)
1106 rcs[i] = local_nb[j].rc;
1107 len -= local_nb[j].len;
1112 LASSERT(j == npages);
1113 ptlrpc_lprocfs_brw(req, nob);
1117 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1122 ptlrpc_free_bulk(desc);
1125 oti_to_request(oti, req);
1126 target_committed_to_req(req);
1127 rc = ptlrpc_reply(req);
1128 } else if (!no_reply) {
1129 /* Only reply if there was no comms problem with bulk */
1130 target_committed_to_req(req);
1131 req->rq_status = rc;
1134 /* reply out callback would free */
1135 ptlrpc_req_drop_rs(req);
1136 LCONSOLE_WARN("%s: Bulk IO write error with %s (at %s), "
1137 "client will retry: rc %d\n",
1138 exp->exp_obd->obd_name,
1139 obd_uuid2str(&exp->exp_client_uuid),
1140 obd_export_nid2str(exp), rc);
1142 cfs_memory_pressure_clr();
1147 * Implementation of OST_SET_INFO.
1149 * OST_SET_INFO is like ioctl(): heavily overloaded. Specifically, it takes a
1150 * "key" and a value RPC buffers as arguments, with the value's contents
1151 * interpreted according to the key.
1153 * Value types that need swabbing have swabbing done explicitly, either here or
1154 * in functions called from here. This should be corrected: all swabbing should
1155 * be done in the capsule abstraction, as that will then allow us to move
1156 * swabbing exclusively to the client without having to modify server code
1157 * outside the capsule abstraction's implementation itself. To correct this
1158 * will require minor changes to the capsule abstraction; see the comments for
1159 * req_capsule_extend() in layout.c.
1161 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1163 struct ost_body *body = NULL, *repbody;
1164 char *key, *val = NULL;
1165 int keylen, vallen, rc = 0;
1166 int is_grant_shrink = 0;
1169 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1171 DEBUG_REQ(D_HA, req, "no set_info key");
1174 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1177 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1180 if ((is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK)))
1181 /* In this case the value is actually an RMF_OST_BODY, so we
1182 * transmutate the type of this PTLRPC */
1183 req_capsule_extend(&req->rq_pill, &RQF_OST_SET_GRANT_INFO);
1185 rc = req_capsule_server_pack(&req->rq_pill);
1190 if (is_grant_shrink) {
1191 body = req_capsule_client_get(&req->rq_pill,
1196 repbody = req_capsule_server_get(&req->rq_pill,
1198 memcpy(repbody, body, sizeof(*body));
1199 val = (char*)repbody;
1201 val = req_capsule_client_get(&req->rq_pill,
1206 if (KEY_IS(KEY_EVICT_BY_NID)) {
1208 obd_export_evict_by_nid(exp->exp_obd, val);
1210 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1211 if (vallen < sizeof(__u32))
1213 __swab32s((__u32 *)val);
1216 /* OBD will also check if KEY_IS(KEY_GRANT_SHRINK), and will cast val to
1217 * a struct ost_body * value */
1218 rc = obd_set_info_async(req->rq_svc_thread->t_env, exp, keylen,
1219 key, vallen, val, NULL);
1221 lustre_msg_set_status(req->rq_repmsg, 0);
1225 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1228 int keylen, replylen, rc = 0;
1229 struct req_capsule *pill = &req->rq_pill;
1232 /* this common part for get_info rpc */
1233 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1235 DEBUG_REQ(D_HA, req, "no get_info key");
1238 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1240 if (KEY_IS(KEY_FIEMAP)) {
1241 struct ll_fiemap_info_key *fm_key = key;
1244 rc = ost_validate_obdo(exp, &fm_key->oa, NULL);
1249 rc = obd_get_info(req->rq_svc_thread->t_env, exp, keylen, key,
1250 &replylen, NULL, NULL);
1254 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1255 RCL_SERVER, replylen);
1257 rc = req_capsule_server_pack(pill);
1261 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1265 /* call again to fill in the reply buffer */
1266 rc = obd_get_info(req->rq_svc_thread->t_env, exp, keylen, key,
1267 &replylen, reply, NULL);
1269 lustre_msg_set_status(req->rq_repmsg, 0);
1273 #ifdef HAVE_QUOTA_SUPPORT
1274 static int ost_handle_quotactl(struct ptlrpc_request *req)
1276 struct obd_quotactl *oqctl, *repoqc;
1280 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1282 GOTO(out, rc = -EPROTO);
1284 rc = req_capsule_server_pack(&req->rq_pill);
1288 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1289 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1296 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1298 struct obd_quotactl *oqctl;
1302 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1306 rc = req_capsule_server_pack(&req->rq_pill);
1310 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1314 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1316 struct quota_adjust_qunit *oqaq, *repoqa;
1317 struct lustre_quota_ctxt *qctxt;
1321 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1322 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1324 GOTO(out, rc = -EPROTO);
1326 rc = req_capsule_server_pack(&req->rq_pill);
1330 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1331 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt, NULL);
1339 static int ost_llog_handle_connect(struct obd_export *exp,
1340 struct ptlrpc_request *req)
1342 struct llogd_conn_body *body;
1346 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
1347 rc = obd_llog_connect(exp, body);
1351 #define ost_init_sec_none(reply, exp) \
1353 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1354 OBD_CONNECT_RMT_CLIENT_FORCE | \
1355 OBD_CONNECT_OSS_CAPA); \
1356 cfs_spin_lock(&exp->exp_lock); \
1357 exp->exp_connect_flags = reply->ocd_connect_flags; \
1358 cfs_spin_unlock(&exp->exp_lock); \
1361 static int ost_init_sec_level(struct ptlrpc_request *req)
1363 struct obd_export *exp = req->rq_export;
1364 struct req_capsule *pill = &req->rq_pill;
1365 struct obd_device *obd = exp->exp_obd;
1366 struct filter_obd *filter = &obd->u.filter;
1367 char *client = libcfs_nid2str(req->rq_peer.nid);
1368 struct obd_connect_data *data, *reply;
1372 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1373 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1374 if (data == NULL || reply == NULL)
1377 /* connection from MDT is always trusted */
1378 if (req->rq_auth_usr_mdt) {
1379 ost_init_sec_none(reply, exp);
1383 /* no GSS support case */
1384 if (!req->rq_auth_gss) {
1385 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1386 CWARN("client %s -> target %s does not user GSS, "
1387 "can not run under security level %d.\n",
1388 client, obd->obd_name, filter->fo_sec_level);
1391 ost_init_sec_none(reply, exp);
1396 /* old version case */
1397 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1398 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1399 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1400 CWARN("client %s -> target %s uses old version, "
1401 "can not run under security level %d.\n",
1402 client, obd->obd_name, filter->fo_sec_level);
1405 CWARN("client %s -> target %s uses old version, "
1406 "run under security level %d.\n",
1407 client, obd->obd_name, filter->fo_sec_level);
1408 ost_init_sec_none(reply, exp);
1413 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1415 if (!req->rq_auth_remote)
1416 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1417 "asked to be remote.\n", client, obd->obd_name);
1418 } else if (req->rq_auth_remote) {
1420 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1421 "as remote by default.\n", client, obd->obd_name);
1425 if (!filter->fo_fl_oss_capa) {
1426 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1427 " but OSS capabilities are not enabled: %d.\n",
1428 client, obd->obd_name, filter->fo_fl_oss_capa);
1433 switch (filter->fo_sec_level) {
1434 case LUSTRE_SEC_NONE:
1436 ost_init_sec_none(reply, exp);
1439 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1440 "can not run under security level %d.\n",
1441 client, obd->obd_name, filter->fo_sec_level);
1444 case LUSTRE_SEC_REMOTE:
1446 ost_init_sec_none(reply, exp);
1448 case LUSTRE_SEC_ALL:
1450 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1451 OBD_CONNECT_RMT_CLIENT_FORCE);
1452 if (!filter->fo_fl_oss_capa)
1453 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1455 cfs_spin_lock(&exp->exp_lock);
1456 exp->exp_connect_flags = reply->ocd_connect_flags;
1457 cfs_spin_unlock(&exp->exp_lock);
1469 * this should be done in filter_connect()/filter_reconnect(), but
1470 * we can't obtain information like NID, which stored in incoming
1471 * request, thus can't decide what flavor to use. so we do it here.
1473 * This hack should be removed after the OST stack be rewritten, just
1474 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1476 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1478 struct obd_export *exp = req->rq_export;
1479 struct filter_obd *filter = &exp->exp_obd->u.filter;
1480 struct sptlrpc_flavor flvr;
1483 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1484 LUSTRE_ECHO_NAME) == 0)) {
1485 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1489 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1490 cfs_read_lock(&filter->fo_sptlrpc_lock);
1491 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1495 cfs_read_unlock(&filter->fo_sptlrpc_lock);
1497 cfs_spin_lock(&exp->exp_lock);
1499 exp->exp_sp_peer = req->rq_sp_from;
1500 exp->exp_flvr = flvr;
1502 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1503 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1504 CERROR("unauthorized rpc flavor %x from %s, "
1505 "expect %x\n", req->rq_flvr.sf_rpc,
1506 libcfs_nid2str(req->rq_peer.nid),
1507 exp->exp_flvr.sf_rpc);
1511 cfs_spin_unlock(&exp->exp_lock);
1513 if (exp->exp_sp_peer != req->rq_sp_from) {
1514 CERROR("RPC source %s doesn't match %s\n",
1515 sptlrpc_part2name(req->rq_sp_from),
1516 sptlrpc_part2name(exp->exp_sp_peer));
1519 rc = sptlrpc_target_export_check(exp, req);
1526 /* Ensure that data and metadata are synced to the disk when lock is cancelled
1528 int ost_blocking_ast(struct ldlm_lock *lock,
1529 struct ldlm_lock_desc *desc,
1530 void *data, int flag)
1532 __u32 sync_lock_cancel = 0;
1533 __u32 len = sizeof(sync_lock_cancel);
1537 rc = obd_get_info(NULL, lock->l_export, sizeof(KEY_SYNC_LOCK_CANCEL),
1538 KEY_SYNC_LOCK_CANCEL, &len, &sync_lock_cancel, NULL);
1540 if (!rc && flag == LDLM_CB_CANCELING &&
1541 (lock->l_granted_mode & (LCK_PW|LCK_GROUP)) &&
1542 (sync_lock_cancel == ALWAYS_SYNC_ON_CANCEL ||
1543 (sync_lock_cancel == BLOCKING_SYNC_ON_CANCEL &&
1544 lock->l_flags & LDLM_FL_CBPENDING))) {
1545 struct obd_info *oinfo;
1549 OBD_ALLOC_PTR(oinfo);
1554 OBD_FREE_PTR(oinfo);
1557 oa->o_id = lock->l_resource->lr_name.name[0];
1558 oa->o_seq = lock->l_resource->lr_name.name[1];
1559 oa->o_valid = OBD_MD_FLID|OBD_MD_FLGROUP;
1562 rc = obd_sync(NULL, lock->l_export, oinfo,
1563 lock->l_policy_data.l_extent.start,
1564 lock->l_policy_data.l_extent.end, NULL);
1566 CERROR("Error %d syncing data on lock cancel\n", rc);
1569 OBD_FREE_PTR(oinfo);
1572 rc = ldlm_server_blocking_ast(lock, desc, data, flag);
1576 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1577 struct obd_device *obd, int *process)
1579 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1580 case OST_CONNECT: /* This will never get here, but for completeness. */
1581 case OST_DISCONNECT:
1592 case OBD_LOG_CANCEL:
1594 *process = target_queue_recovery_request(req, obd);
1598 DEBUG_REQ(D_WARNING, req, "not permitted during recovery");
1604 int ost_msg_check_version(struct lustre_msg *msg)
1608 switch(lustre_msg_get_opc(msg)) {
1610 case OST_DISCONNECT:
1613 case SEC_CTX_INIT_CONT:
1615 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1617 CERROR("bad opc %u version %08x, expecting %08x\n",
1618 lustre_msg_get_opc(msg),
1619 lustre_msg_get_version(msg),
1620 LUSTRE_OBD_VERSION);
1633 #ifdef HAVE_QUOTA_SUPPORT
1634 case OST_QUOTACHECK:
1636 case OST_QUOTA_ADJUST_QUNIT:
1638 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1640 CERROR("bad opc %u version %08x, expecting %08x\n",
1641 lustre_msg_get_opc(msg),
1642 lustre_msg_get_version(msg),
1643 LUSTRE_OST_VERSION);
1648 case LDLM_BL_CALLBACK:
1649 case LDLM_CP_CALLBACK:
1650 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1652 CERROR("bad opc %u version %08x, expecting %08x\n",
1653 lustre_msg_get_opc(msg),
1654 lustre_msg_get_version(msg),
1655 LUSTRE_DLM_VERSION);
1657 case LLOG_ORIGIN_CONNECT:
1658 case OBD_LOG_CANCEL:
1659 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1661 CERROR("bad opc %u version %08x, expecting %08x\n",
1662 lustre_msg_get_opc(msg),
1663 lustre_msg_get_version(msg),
1664 LUSTRE_LOG_VERSION);
1667 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1673 struct ost_prolong_data {
1674 struct ptlrpc_request *opd_req;
1675 struct obd_export *opd_exp;
1676 struct obdo *opd_oa;
1677 struct ldlm_res_id opd_resid;
1678 struct ldlm_extent opd_extent;
1679 ldlm_mode_t opd_mode;
1680 unsigned int opd_locks;
1684 /* prolong locks for the current service time of the corresponding
1685 * portal (= OST_IO_PORTAL)
1687 static inline int prolong_timeout(struct ptlrpc_request *req)
1689 struct ptlrpc_service *svc = req->rq_rqbd->rqbd_service;
1692 return obd_timeout / 2;
1694 return max(at_est2timeout(at_get(&svc->srv_at_estimate)), ldlm_timeout);
1697 static void ost_prolong_lock_one(struct ost_prolong_data *opd,
1698 struct ldlm_lock *lock)
1700 LASSERT(lock->l_req_mode == lock->l_granted_mode);
1701 LASSERT(lock->l_export == opd->opd_exp);
1703 /* XXX: never try to grab resource lock here because we're inside
1704 * exp_bl_list_lock; in ldlm_lockd.c to handle waiting list we take
1705 * res lock and then exp_bl_list_lock. */
1707 if (!(lock->l_flags & LDLM_FL_AST_SENT))
1708 /* ignore locks not being cancelled */
1712 "refreshed for req x"LPU64" ext("LPU64"->"LPU64") to %ds.\n",
1713 opd->opd_req->rq_xid, opd->opd_extent.start,
1714 opd->opd_extent.end, opd->opd_timeout);
1716 /* OK. this is a possible lock the user holds doing I/O
1717 * let's refresh eviction timer for it */
1718 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
1722 static void ost_prolong_locks(struct ost_prolong_data *data)
1724 struct obd_export *exp = data->opd_exp;
1725 struct obdo *oa = data->opd_oa;
1726 struct ldlm_lock *lock;
1729 if (oa->o_valid & OBD_MD_FLHANDLE) {
1730 /* mostly a request should be covered by only one lock, try
1732 lock = ldlm_handle2lock(&oa->o_handle);
1734 /* Fast path to check if the lock covers the whole IO
1735 * region exclusively. */
1736 if (lock->l_granted_mode == LCK_PW &&
1737 ldlm_extent_contain(&lock->l_policy_data.l_extent,
1738 &data->opd_extent)) {
1740 ost_prolong_lock_one(data, lock);
1741 LDLM_LOCK_PUT(lock);
1744 LDLM_LOCK_PUT(lock);
1749 cfs_spin_lock_bh(&exp->exp_bl_list_lock);
1750 cfs_list_for_each_entry(lock, &exp->exp_bl_list, l_exp_list) {
1751 LASSERT(lock->l_flags & LDLM_FL_AST_SENT);
1752 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
1754 if (!ldlm_res_eq(&data->opd_resid, &lock->l_resource->lr_name))
1757 if (!ldlm_extent_overlap(&lock->l_policy_data.l_extent,
1761 ost_prolong_lock_one(data, lock);
1763 cfs_spin_unlock_bh(&exp->exp_bl_list_lock);
1769 * Returns 1 if the given PTLRPC matches the given LDLM locks, or 0 if it does
1772 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1773 struct ldlm_lock *lock)
1775 struct niobuf_remote *nb;
1776 struct obd_ioobj *ioo;
1778 struct ldlm_extent ext;
1781 opc = lustre_msg_get_opc(req->rq_reqmsg);
1782 LASSERT(opc == OST_READ || opc == OST_WRITE);
1784 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1785 LASSERT(ioo != NULL);
1787 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1788 LASSERT(nb != NULL);
1790 ext.start = nb->offset;
1791 nb += ioo->ioo_bufcnt - 1;
1792 ext.end = nb->offset + nb->len - 1;
1794 LASSERT(lock->l_resource != NULL);
1795 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_seq,
1796 &lock->l_resource->lr_name))
1800 if (opc == OST_READ)
1802 if (!(lock->l_granted_mode & mode))
1805 RETURN(ldlm_extent_overlap(&lock->l_policy_data.l_extent, &ext));
1809 * High-priority queue request check for whether the given PTLRPC request (\a
1810 * req) is blocking an LDLM lock cancel.
1812 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1813 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1815 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1816 * function looks only at OST_READs and OST_WRITEs.
1818 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1820 struct obd_device *obd = req->rq_export->exp_obd;
1821 struct ost_body *body;
1822 struct obd_ioobj *ioo;
1823 struct niobuf_remote *nb;
1824 struct ost_prolong_data opd = { 0 };
1829 * Use LASSERT to do sanity check because malformed RPCs should have
1830 * been filtered out in ost_hpreq_handler().
1832 opc = lustre_msg_get_opc(req->rq_reqmsg);
1833 LASSERT(opc == OST_READ || opc == OST_WRITE);
1835 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1836 LASSERT(body != NULL);
1838 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1839 LASSERT(ioo != NULL);
1841 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1842 LASSERT(nb != NULL);
1843 LASSERT(!(nb->flags & OBD_BRW_SRVLOCK));
1845 osc_build_res_name(ioo->ioo_id, ioo->ioo_seq, &opd.opd_resid);
1849 if (opc == OST_READ)
1851 opd.opd_mode = mode;
1852 opd.opd_exp = req->rq_export;
1853 opd.opd_oa = &body->oa;
1854 opd.opd_extent.start = nb->offset;
1855 nb += ioo->ioo_bufcnt - 1;
1856 opd.opd_extent.end = nb->offset + nb->len - 1;
1857 opd.opd_timeout = prolong_timeout(req);
1859 DEBUG_REQ(D_RPCTRACE, req,
1860 "%s %s: refresh rw locks: " LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1861 obd->obd_name, cfs_current()->comm,
1862 opd.opd_resid.name[0], opd.opd_resid.name[1],
1863 opd.opd_extent.start, opd.opd_extent.end);
1865 ost_prolong_locks(&opd);
1867 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
1868 obd->obd_name, opd.opd_locks, req);
1870 RETURN(opd.opd_locks);
1873 static void ost_rw_hpreq_fini(struct ptlrpc_request *req)
1875 (void)ost_rw_hpreq_check(req);
1879 * Like ost_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
1881 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1882 struct ldlm_lock *lock)
1884 struct ost_body *body;
1887 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1888 LASSERT(body != NULL);
1890 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1891 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1898 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
1900 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1902 struct obd_device *obd = req->rq_export->exp_obd;
1903 struct ost_body *body;
1905 struct ost_prolong_data opd = { 0 };
1909 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1910 LASSERT(body != NULL);
1913 LASSERT(!(oa->o_valid & OBD_MD_FLFLAGS) ||
1914 !(oa->o_flags & OBD_FL_SRVLOCK));
1917 end = start + oa->o_blocks;
1920 opd.opd_mode = LCK_PW;
1921 opd.opd_exp = req->rq_export;
1923 opd.opd_extent.start = start;
1924 opd.opd_extent.end = end;
1925 if (oa->o_blocks == OBD_OBJECT_EOF)
1926 opd.opd_extent.end = OBD_OBJECT_EOF;
1927 opd.opd_timeout = prolong_timeout(req);
1929 osc_build_res_name(oa->o_id, oa->o_seq, &opd.opd_resid);
1932 "%s: refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1934 opd.opd_resid.name[0], opd.opd_resid.name[1],
1935 opd.opd_extent.start, opd.opd_extent.end);
1937 ost_prolong_locks(&opd);
1939 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
1940 obd->obd_name, opd.opd_locks, req);
1942 RETURN(opd.opd_locks > 0);
1945 static void ost_punch_hpreq_fini(struct ptlrpc_request *req)
1947 (void)ost_punch_hpreq_check(req);
1950 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
1951 .hpreq_lock_match = ost_rw_hpreq_lock_match,
1952 .hpreq_check = ost_rw_hpreq_check,
1953 .hpreq_fini = ost_rw_hpreq_fini
1956 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
1957 .hpreq_lock_match = ost_punch_hpreq_lock_match,
1958 .hpreq_check = ost_punch_hpreq_check,
1959 .hpreq_fini = ost_punch_hpreq_fini
1962 /** Assign high priority operations to the request if needed. */
1963 static int ost_hpreq_handler(struct ptlrpc_request *req)
1966 if (req->rq_export) {
1967 int opc = lustre_msg_get_opc(req->rq_reqmsg);
1968 struct ost_body *body;
1970 if (opc == OST_READ || opc == OST_WRITE) {
1971 struct niobuf_remote *nb;
1972 struct obd_ioobj *ioo;
1973 int objcount, niocount;
1977 /* RPCs on the H-P queue can be inspected before
1978 * ost_handler() initializes their pills, so we
1979 * initialize that here. Capsule initialization is
1980 * idempotent, as is setting the pill's format (provided
1981 * it doesn't change).
1983 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1984 if (opc == OST_READ)
1985 req_capsule_set(&req->rq_pill,
1988 req_capsule_set(&req->rq_pill,
1989 &RQF_OST_BRW_WRITE);
1991 body = req_capsule_client_get(&req->rq_pill,
1994 CERROR("Missing/short ost_body\n");
1998 objcount = req_capsule_get_size(&req->rq_pill,
2002 if (objcount == 0) {
2003 CERROR("Missing/short ioobj\n");
2007 CERROR("too many ioobjs (%d)\n", objcount);
2011 ioo = req_capsule_client_get(&req->rq_pill,
2014 CERROR("Missing/short ioobj\n");
2018 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
2020 CERROR("invalid object ids\n");
2024 for (niocount = i = 0; i < objcount; i++) {
2025 if (ioo[i].ioo_bufcnt == 0) {
2026 CERROR("ioo[%d] has zero bufcnt\n", i);
2029 niocount += ioo[i].ioo_bufcnt;
2031 if (niocount > PTLRPC_MAX_BRW_PAGES) {
2032 DEBUG_REQ(D_RPCTRACE, req,
2033 "bulk has too many pages (%d)",
2038 nb = req_capsule_client_get(&req->rq_pill,
2039 &RMF_NIOBUF_REMOTE);
2041 CERROR("Missing/short niobuf\n");
2045 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
2046 req->rq_ops = &ost_hpreq_rw;
2047 } else if (opc == OST_PUNCH) {
2048 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2049 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2051 body = req_capsule_client_get(&req->rq_pill,
2054 CERROR("Missing/short ost_body\n");
2058 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
2059 !(body->oa.o_flags & OBD_FL_SRVLOCK))
2060 req->rq_ops = &ost_hpreq_punch;
2066 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
2067 int ost_handle(struct ptlrpc_request *req)
2069 struct obd_trans_info trans_info = { 0, };
2070 struct obd_trans_info *oti = &trans_info;
2071 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
2072 struct obd_device *obd = NULL;
2075 /* OST module is kept between remounts, but the last reference
2076 * to specific module (say, osd or ofd) kills all related keys
2077 * from the environment. so we have to refill it until the root
2078 * cause is fixed properly */
2079 lu_env_refill(req->rq_svc_thread->t_env);
2081 LASSERT(current->journal_info == NULL);
2083 /* primordial rpcs don't affect server recovery */
2084 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2086 case SEC_CTX_INIT_CONT:
2091 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2093 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
2094 if (!class_connected_export(req->rq_export)) {
2095 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
2096 lustre_msg_get_opc(req->rq_reqmsg),
2097 libcfs_id2str(req->rq_peer));
2098 req->rq_status = -ENOTCONN;
2099 GOTO(out, rc = -ENOTCONN);
2102 obd = req->rq_export->exp_obd;
2104 /* Check for aborted recovery. */
2105 if (obd->obd_recovering) {
2106 rc = ost_filter_recovery_request(req, obd,
2108 if (rc || !should_process)
2110 else if (should_process < 0) {
2111 req->rq_status = should_process;
2112 rc = ptlrpc_error(req);
2120 rc = ost_msg_check_version(req->rq_reqmsg);
2124 if (req && req->rq_reqmsg && req->rq_export &&
2125 (req->rq_export->exp_connect_flags & OBD_CONNECT_JOBSTATS))
2126 oti->oti_jobid = lustre_msg_get_jobid(req->rq_reqmsg);
2128 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2130 CDEBUG(D_INODE, "connect\n");
2131 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
2132 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
2134 rc = target_handle_connect(req);
2135 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
2138 rc = ost_init_sec_level(req);
2140 rc = ost_connect_check_sptlrpc(req);
2144 case OST_DISCONNECT:
2145 CDEBUG(D_INODE, "disconnect\n");
2146 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
2147 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
2149 rc = target_handle_disconnect(req);
2152 CDEBUG(D_INODE, "create\n");
2153 req_capsule_set(&req->rq_pill, &RQF_OST_CREATE);
2154 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
2156 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2157 GOTO(out, rc = -EROFS);
2158 rc = ost_create(req->rq_export, req, oti);
2161 CDEBUG(D_INODE, "destroy\n");
2162 req_capsule_set(&req->rq_pill, &RQF_OST_DESTROY);
2163 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
2165 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2166 GOTO(out, rc = -EROFS);
2167 rc = ost_destroy(req->rq_export, req, oti);
2170 CDEBUG(D_INODE, "getattr\n");
2171 req_capsule_set(&req->rq_pill, &RQF_OST_GETATTR);
2172 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
2174 rc = ost_getattr(req->rq_export, req);
2177 CDEBUG(D_INODE, "setattr\n");
2178 req_capsule_set(&req->rq_pill, &RQF_OST_SETATTR);
2179 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
2181 rc = ost_setattr(req->rq_export, req, oti);
2184 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_WRITE);
2185 CDEBUG(D_INODE, "write\n");
2186 /* req->rq_request_portal would be nice, if it was set */
2187 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2188 CERROR("%s: deny write request from %s to portal %u\n",
2189 req->rq_export->exp_obd->obd_name,
2190 obd_export_nid2str(req->rq_export),
2191 req->rq_rqbd->rqbd_service->srv_req_portal);
2192 GOTO(out, rc = -EPROTO);
2194 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2196 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
2197 GOTO(out, rc = -ENOSPC);
2198 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2199 GOTO(out, rc = -EROFS);
2200 rc = ost_brw_write(req, oti);
2201 LASSERT(current->journal_info == NULL);
2202 /* ost_brw_write sends its own replies */
2205 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_READ);
2206 CDEBUG(D_INODE, "read\n");
2207 /* req->rq_request_portal would be nice, if it was set */
2208 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2209 CERROR("%s: deny read request from %s to portal %u\n",
2210 req->rq_export->exp_obd->obd_name,
2211 obd_export_nid2str(req->rq_export),
2212 req->rq_rqbd->rqbd_service->srv_req_portal);
2213 GOTO(out, rc = -EPROTO);
2215 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2217 rc = ost_brw_read(req, oti);
2218 LASSERT(current->journal_info == NULL);
2219 /* ost_brw_read sends its own replies */
2222 CDEBUG(D_INODE, "punch\n");
2223 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2224 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2226 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2227 GOTO(out, rc = -EROFS);
2228 rc = ost_punch(req->rq_export, req, oti);
2231 CDEBUG(D_INODE, "statfs\n");
2232 req_capsule_set(&req->rq_pill, &RQF_OST_STATFS);
2233 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2235 rc = ost_statfs(req);
2238 CDEBUG(D_INODE, "sync\n");
2239 req_capsule_set(&req->rq_pill, &RQF_OST_SYNC);
2240 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2242 rc = ost_sync(req->rq_export, req, oti);
2245 DEBUG_REQ(D_INODE, req, "set_info");
2246 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
2247 rc = ost_set_info(req->rq_export, req);
2250 DEBUG_REQ(D_INODE, req, "get_info");
2251 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
2252 rc = ost_get_info(req->rq_export, req);
2254 #ifdef HAVE_QUOTA_SUPPORT
2255 case OST_QUOTACHECK:
2256 CDEBUG(D_INODE, "quotacheck\n");
2257 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2258 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2260 rc = ost_handle_quotacheck(req);
2263 CDEBUG(D_INODE, "quotactl\n");
2264 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2265 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2267 rc = ost_handle_quotactl(req);
2269 case OST_QUOTA_ADJUST_QUNIT:
2270 CDEBUG(D_INODE, "quota_adjust_qunit\n");
2271 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
2272 rc = ost_handle_quota_adjust_qunit(req);
2276 DEBUG_REQ(D_INODE, req, "ping");
2277 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2278 rc = target_handle_ping(req);
2280 /* FIXME - just reply status */
2281 case LLOG_ORIGIN_CONNECT:
2282 DEBUG_REQ(D_INODE, req, "log connect");
2283 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2284 rc = ost_llog_handle_connect(req->rq_export, req);
2285 req->rq_status = rc;
2286 rc = req_capsule_server_pack(&req->rq_pill);
2289 RETURN(ptlrpc_reply(req));
2290 case OBD_LOG_CANCEL:
2291 CDEBUG(D_INODE, "log cancel\n");
2292 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2293 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2295 rc = llog_origin_handle_cancel(req);
2296 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2298 req->rq_status = rc;
2299 rc = req_capsule_server_pack(&req->rq_pill);
2302 RETURN(ptlrpc_reply(req));
2304 CDEBUG(D_INODE, "enqueue\n");
2305 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2306 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2308 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2310 ldlm_server_glimpse_ast);
2311 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2314 CDEBUG(D_INODE, "convert\n");
2315 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2316 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2318 rc = ldlm_handle_convert(req);
2321 CDEBUG(D_INODE, "cancel\n");
2322 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2323 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2325 rc = ldlm_handle_cancel(req);
2327 case LDLM_BL_CALLBACK:
2328 case LDLM_CP_CALLBACK:
2329 CDEBUG(D_INODE, "callback\n");
2330 CERROR("callbacks should not happen on OST\n");
2333 CERROR("Unexpected opcode %d\n",
2334 lustre_msg_get_opc(req->rq_reqmsg));
2335 req->rq_status = -ENOTSUPP;
2336 rc = ptlrpc_error(req);
2340 LASSERT(current->journal_info == NULL);
2343 /* If we're DISCONNECTing, the export_data is already freed */
2344 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2345 target_committed_to_req(req);
2349 oti_to_request(oti, req);
2351 target_send_reply(req, rc, fail);
2354 EXPORT_SYMBOL(ost_handle);
2356 * free per-thread pool created by ost_thread_init().
2358 static void ost_thread_done(struct ptlrpc_thread *thread)
2360 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2365 LASSERT(thread != NULL);
2368 * be prepared to handle partially-initialized pools (because this is
2369 * called from ost_thread_init() for cleanup.
2371 tls = thread->t_data;
2374 thread->t_data = NULL;
2380 * initialize per-thread page pool (bug 5137).
2382 static int ost_thread_init(struct ptlrpc_thread *thread)
2384 struct ost_thread_local_cache *tls;
2388 LASSERT(thread != NULL);
2389 LASSERT(thread->t_data == NULL);
2390 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
2395 thread->t_data = tls;
2399 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2401 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2402 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2404 struct ost_obd *ost = &obd->u.ost;
2405 struct lprocfs_static_vars lvars;
2406 int oss_min_threads;
2407 int oss_max_threads;
2408 int oss_min_create_threads;
2409 int oss_max_create_threads;
2413 rc = cfs_cleanup_group_info();
2417 lprocfs_ost_init_vars(&lvars);
2418 lprocfs_obd_setup(obd, lvars.obd_vars);
2420 cfs_mutex_init(&ost->ost_health_mutex);
2422 if (oss_num_threads) {
2423 /* If oss_num_threads is set, it is the min and the max. */
2424 if (oss_num_threads > OSS_THREADS_MAX)
2425 oss_num_threads = OSS_THREADS_MAX;
2426 if (oss_num_threads < OSS_THREADS_MIN)
2427 oss_num_threads = OSS_THREADS_MIN;
2428 oss_max_threads = oss_min_threads = oss_num_threads;
2430 /* Base min threads on memory and cpus */
2432 cfs_num_possible_cpus() * CFS_NUM_CACHEPAGES >>
2433 (27 - CFS_PAGE_SHIFT);
2434 if (oss_min_threads < OSS_THREADS_MIN)
2435 oss_min_threads = OSS_THREADS_MIN;
2436 /* Insure a 4x range for dynamic threads */
2437 if (oss_min_threads > OSS_THREADS_MAX / 4)
2438 oss_min_threads = OSS_THREADS_MAX / 4;
2439 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
2443 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2444 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
2445 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2446 ost_handle, LUSTRE_OSS_NAME,
2447 obd->obd_proc_entry, target_print_req,
2448 oss_min_threads, oss_max_threads,
2449 "ll_ost", LCT_DT_THREAD, NULL);
2450 if (ost->ost_service == NULL) {
2451 CERROR("failed to start service\n");
2452 GOTO(out_lprocfs, rc = -ENOMEM);
2455 rc = ptlrpc_start_threads(ost->ost_service);
2457 GOTO(out_service, rc = -EINVAL);
2459 if (oss_num_create_threads) {
2460 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
2461 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
2462 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
2463 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
2464 oss_min_create_threads = oss_max_create_threads =
2465 oss_num_create_threads;
2467 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
2468 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
2471 ost->ost_create_service =
2472 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2473 OST_MAXREPSIZE, OST_CREATE_PORTAL,
2474 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2475 ost_handle, "ost_create",
2476 obd->obd_proc_entry, target_print_req,
2477 oss_min_create_threads, oss_max_create_threads,
2478 "ll_ost_creat", LCT_DT_THREAD, NULL);
2479 if (ost->ost_create_service == NULL) {
2480 CERROR("failed to start OST create service\n");
2481 GOTO(out_service, rc = -ENOMEM);
2484 rc = ptlrpc_start_threads(ost->ost_create_service);
2486 GOTO(out_create, rc = -EINVAL);
2488 ost->ost_io_service =
2489 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2490 OST_MAXREPSIZE, OST_IO_PORTAL,
2491 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2492 ost_handle, "ost_io",
2493 obd->obd_proc_entry, target_print_req,
2494 oss_min_threads, oss_max_threads,
2495 "ll_ost_io", LCT_DT_THREAD, ost_hpreq_handler);
2496 if (ost->ost_io_service == NULL) {
2497 CERROR("failed to start OST I/O service\n");
2498 GOTO(out_create, rc = -ENOMEM);
2501 ost->ost_io_service->srv_init = ost_thread_init;
2502 ost->ost_io_service->srv_done = ost_thread_done;
2503 ost->ost_io_service->srv_cpu_affinity = 1;
2504 rc = ptlrpc_start_threads(ost->ost_io_service);
2506 GOTO(out_io, rc = -EINVAL);
2508 ping_evictor_start();
2513 ptlrpc_unregister_service(ost->ost_io_service);
2514 ost->ost_io_service = NULL;
2516 ptlrpc_unregister_service(ost->ost_create_service);
2517 ost->ost_create_service = NULL;
2519 ptlrpc_unregister_service(ost->ost_service);
2520 ost->ost_service = NULL;
2522 lprocfs_obd_cleanup(obd);
2526 static int ost_cleanup(struct obd_device *obd)
2528 struct ost_obd *ost = &obd->u.ost;
2532 ping_evictor_stop();
2534 /* there is no recovery for OST OBD, all recovery is controlled by
2536 LASSERT(obd->obd_recovering == 0);
2537 cfs_mutex_lock(&ost->ost_health_mutex);
2538 ptlrpc_unregister_service(ost->ost_service);
2539 ptlrpc_unregister_service(ost->ost_create_service);
2540 ptlrpc_unregister_service(ost->ost_io_service);
2541 ost->ost_service = NULL;
2542 ost->ost_create_service = NULL;
2543 cfs_mutex_unlock(&ost->ost_health_mutex);
2545 lprocfs_obd_cleanup(obd);
2550 static int ost_health_check(const struct lu_env *env, struct obd_device *obd)
2552 struct ost_obd *ost = &obd->u.ost;
2555 cfs_mutex_lock(&ost->ost_health_mutex);
2556 rc |= ptlrpc_service_health_check(ost->ost_service);
2557 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2558 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2559 cfs_mutex_unlock(&ost->ost_health_mutex);
2562 * health_check to return 0 on healthy
2563 * and 1 on unhealthy.
2571 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2573 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2576 /* use obd ops to offer management infrastructure */
2577 static struct obd_ops ost_obd_ops = {
2578 .o_owner = THIS_MODULE,
2579 .o_setup = ost_setup,
2580 .o_cleanup = ost_cleanup,
2581 .o_health_check = ost_health_check,
2585 static int __init ost_init(void)
2587 struct lprocfs_static_vars lvars;
2591 lprocfs_ost_init_vars(&lvars);
2592 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2593 LUSTRE_OSS_NAME, NULL);
2595 if (ost_num_threads != 0 && oss_num_threads == 0) {
2596 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2597 "use oss_num_threads instead or unset both for "
2598 "dynamic thread startup\n");
2599 oss_num_threads = ost_num_threads;
2605 static void /*__exit*/ ost_exit(void)
2607 class_unregister_type(LUSTRE_OSS_NAME);
2610 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2611 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2612 MODULE_LICENSE("GPL");
2614 module_init(ost_init);
2615 module_exit(ost_exit);