1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ost/ost_handler.c
38 * Author: Peter J. Braam <braam@clusterfs.com>
39 * Author: Phil Schwan <phil@clusterfs.com>
43 # define EXPORT_SYMTAB
45 #define DEBUG_SUBSYSTEM S_OST
47 #include <linux/module.h>
48 #include <obd_cksum.h>
50 #include <lustre_net.h>
51 #include <lustre_dlm.h>
52 #include <lustre_export.h>
53 #include <lustre_debug.h>
54 #include <linux/init.h>
55 #include <lprocfs_status.h>
56 #include <libcfs/list.h>
57 #include <lustre_quota.h>
58 #include "ost_internal.h"
60 static int oss_num_threads;
61 CFS_MODULE_PARM(oss_num_threads, "i", int, 0444,
62 "number of OSS service threads to start");
64 static int ost_num_threads;
65 CFS_MODULE_PARM(ost_num_threads, "i", int, 0444,
66 "number of OST service threads to start (deprecated)");
68 static int oss_num_create_threads;
69 CFS_MODULE_PARM(oss_num_create_threads, "i", int, 0444,
70 "number of OSS create threads to start");
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 * 1. If the request comes from 1.8 clients, it will reset o_seq with MDT0.
87 * 2. If the request comes from 2.0 clients, currently only RSVD seq and IDIF
89 * a. for single MDS seq = FID_SEQ_OST_MDT0,
90 * b. for CMD, seq = FID_SEQ_OST_MDT0, FID_SEQ_OST_MDT1 - FID_SEQ_OST_MAX
92 static int ost_validate_obdo(struct obd_export *exp, struct obdo *oa,
93 struct obd_ioobj *ioobj)
95 if (oa != NULL && (!(oa->o_valid & OBD_MD_FLGROUP) ||
96 !(exp->exp_connect_flags & OBD_CONNECT_FULL20))) {
97 oa->o_seq = FID_SEQ_OST_MDT0;
99 ioobj->ioo_seq = FID_SEQ_OST_MDT0;
100 /* remove fid_seq_is_rsvd() after FID-on-OST allows SEQ > 9 */
101 } else if (oa == NULL ||
102 !(fid_seq_is_rsvd(oa->o_seq) || fid_seq_is_idif(oa->o_seq))) {
103 CERROR("%s: client %s sent invalid object "POSTID"\n",
104 exp->exp_obd->obd_name, obd_export_nid2str(exp),
105 oa ? oa->o_id : -1, oa ? oa->o_seq : -1);
108 obdo_from_ostid(oa, &oa->o_oi);
110 ioobj_from_obdo(ioobj, oa);
114 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
116 struct oti_req_ack_lock *ack_lock;
122 if (req->rq_repmsg) {
123 __u64 versions[PTLRPC_NUM_VERSIONS] = { 0 };
124 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
125 versions[0] = oti->oti_pre_version;
126 lustre_msg_set_versions(req->rq_repmsg, versions);
128 req->rq_transno = oti->oti_transno;
130 /* XXX 4 == entries in oti_ack_locks??? */
131 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
134 /* XXX not even calling target_send_reply in some cases... */
135 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode, 0);
139 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
140 struct obd_trans_info *oti)
142 struct ost_body *body, *repbody;
143 struct lustre_capa *capa = NULL;
147 /* Get the request body */
148 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
152 if (body->oa.o_id == 0)
155 rc = ost_validate_obdo(exp, &body->oa, NULL);
159 /* If there's a DLM request, cancel the locks mentioned in it*/
160 if (req_capsule_field_present(&req->rq_pill, &RMF_DLM_REQ, RCL_CLIENT)) {
161 struct ldlm_request *dlm;
163 dlm = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
166 ldlm_request_cancel(req, dlm, 0);
169 /* If there's a capability, get it */
170 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
171 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
173 CERROR("Missing capability for OST DESTROY");
178 /* Prepare the reply */
179 rc = req_capsule_server_pack(&req->rq_pill);
183 /* Get the log cancellation cookie */
184 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
185 oti->oti_logcookies = &body->oa.o_lcookie;
187 /* Finish the reply */
188 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
189 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
191 /* Do the destroy and set the reply status accordingly */
192 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL, capa);
197 * Helper function for getting server side [start, start+count] DLM lock
198 * if asked by client.
200 static int ost_lock_get(struct obd_export *exp, struct obdo *oa,
201 __u64 start, __u64 count, struct lustre_handle *lh,
204 struct ldlm_res_id res_id;
205 ldlm_policy_data_t policy;
206 __u64 end = start + count;
210 LASSERT(!lustre_handle_is_used(lh));
211 /* o_id and o_gr are used for localizing resource, if client miss to set
212 * them, do not trigger ASSERTION. */
213 if (unlikely((oa->o_valid & (OBD_MD_FLID | OBD_MD_FLGROUP)) !=
214 (OBD_MD_FLID | OBD_MD_FLGROUP)))
217 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
218 !(oa->o_flags & OBD_FL_SRVLOCK))
221 osc_build_res_name(oa->o_id, oa->o_seq, &res_id);
222 CDEBUG(D_INODE, "OST-side extent lock.\n");
224 policy.l_extent.start = start & CFS_PAGE_MASK;
226 /* If ->o_blocks is EOF it means "lock till the end of the
227 * file". Otherwise, it's size of a hole being punched (in bytes) */
228 if (count == OBD_OBJECT_EOF || end < start)
229 policy.l_extent.end = OBD_OBJECT_EOF;
231 policy.l_extent.end = end | ~CFS_PAGE_MASK;
233 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
234 LDLM_EXTENT, &policy, mode, &flags,
235 ldlm_blocking_ast, ldlm_completion_ast,
236 ldlm_glimpse_ast, NULL, 0, NULL, lh));
239 /* Helper function: release lock, if any. */
240 static void ost_lock_put(struct obd_export *exp,
241 struct lustre_handle *lh, int mode)
244 if (lustre_handle_is_used(lh))
245 ldlm_lock_decref(lh, mode);
249 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
251 struct ost_body *body, *repbody;
252 struct obd_info *oinfo;
253 struct lustre_handle lh = { 0 };
254 struct lustre_capa *capa = NULL;
258 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
262 rc = ost_validate_obdo(exp, &body->oa, NULL);
266 rc = req_capsule_server_pack(&req->rq_pill);
270 rc = ost_lock_get(exp, &body->oa, 0, OBD_OBJECT_EOF, &lh, LCK_PR, 0);
274 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
275 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
277 CERROR("Missing capability for OST GETATTR");
278 GOTO(unlock, rc = -EFAULT);
282 OBD_ALLOC_PTR(oinfo);
284 GOTO(unlock, rc = -ENOMEM);
285 oinfo->oi_oa = &body->oa;
286 oinfo->oi_capa = capa;
288 req->rq_status = obd_getattr(exp, oinfo);
292 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
293 repbody->oa = body->oa;
294 ost_drop_id(exp, &repbody->oa);
297 ost_lock_put(exp, &lh, LCK_PR);
302 static int ost_statfs(struct ptlrpc_request *req)
304 struct obd_statfs *osfs;
308 rc = req_capsule_server_pack(&req->rq_pill);
312 osfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
314 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
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(exp, &repbody->oa, NULL, oti);
347 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
351 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
352 struct obd_trans_info *oti)
354 struct ost_body *body, *repbody;
356 struct lustre_handle lh = {0,};
359 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
360 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
362 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
366 rc = ost_validate_obdo(exp, &body->oa, NULL);
370 if ((body->oa.o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
371 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
374 rc = req_capsule_server_pack(&req->rq_pill);
378 /* standard truncate optimization: if file body is completely
379 * destroyed, don't send data back to the server. */
380 if (body->oa.o_size == 0)
381 flags |= LDLM_AST_DISCARD_DATA;
383 rc = ost_lock_get(exp, &body->oa, body->oa.o_size, body->oa.o_blocks,
386 struct obd_info *oinfo;
387 struct lustre_capa *capa = NULL;
389 if (body->oa.o_valid & OBD_MD_FLFLAGS &&
390 body->oa.o_flags == OBD_FL_SRVLOCK)
392 * If OBD_FL_SRVLOCK is the only bit set in
393 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
394 * through filter_setattr() to filter_iocontrol().
396 body->oa.o_valid &= ~OBD_MD_FLFLAGS;
398 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
399 capa = req_capsule_client_get(&req->rq_pill,
402 CERROR("Missing capability for OST PUNCH");
403 GOTO(unlock, rc = -EFAULT);
407 OBD_ALLOC_PTR(oinfo);
409 GOTO(unlock, rc = -ENOMEM);
410 oinfo->oi_oa = &body->oa;
411 oinfo->oi_policy.l_extent.start = oinfo->oi_oa->o_size;
412 oinfo->oi_policy.l_extent.end = oinfo->oi_oa->o_blocks;
413 oinfo->oi_capa = capa;
415 req->rq_status = obd_punch(exp, oinfo, oti, NULL);
418 ost_lock_put(exp, &lh, LCK_PW);
421 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
422 repbody->oa = body->oa;
423 ost_drop_id(exp, &repbody->oa);
427 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
429 struct ost_body *body, *repbody;
430 struct obd_info *oinfo;
431 struct lustre_capa *capa = NULL;
435 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
439 rc = ost_validate_obdo(exp, &body->oa, NULL);
443 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
444 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
446 CERROR("Missing capability for OST SYNC");
451 rc = req_capsule_server_pack(&req->rq_pill);
455 OBD_ALLOC_PTR(oinfo);
459 oinfo->oi_oa = &body->oa;
460 oinfo->oi_capa = capa;
461 req->rq_status = obd_sync(exp, oinfo, body->oa.o_size,
462 body->oa.o_blocks, NULL);
465 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
466 repbody->oa = body->oa;
467 ost_drop_id(exp, &repbody->oa);
471 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
472 struct obd_trans_info *oti)
474 struct ost_body *body, *repbody;
475 struct obd_info *oinfo;
476 struct lustre_capa *capa = NULL;
480 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
484 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
488 rc = req_capsule_server_pack(&req->rq_pill);
492 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
493 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
495 CERROR("Missing capability for OST SETATTR");
500 OBD_ALLOC_PTR(oinfo);
503 oinfo->oi_oa = &body->oa;
504 oinfo->oi_capa = capa;
506 req->rq_status = obd_setattr(exp, oinfo, oti);
510 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
511 repbody->oa = body->oa;
512 ost_drop_id(exp, &repbody->oa);
516 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
517 cksum_type_t cksum_type)
522 cksum = init_checksum(cksum_type);
523 for (i = 0; i < desc->bd_iov_count; i++) {
524 struct page *page = desc->bd_iov[i].kiov_page;
525 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
526 char *ptr = kmap(page) + off;
527 int len = desc->bd_iov[i].kiov_len;
529 /* corrupt the data before we compute the checksum, to
530 * simulate a client->OST data error */
531 if (i == 0 && opc == OST_WRITE &&
532 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
533 memcpy(ptr, "bad3", min(4, len));
534 cksum = compute_checksum(cksum, ptr, len, cksum_type);
535 /* corrupt the data after we compute the checksum, to
536 * simulate an OST->client data error */
537 if (i == 0 && opc == OST_READ &&
538 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
539 memcpy(ptr, "bad4", min(4, len));
540 /* nobody should use corrupted page again */
541 ClearPageUptodate(page);
549 static int ost_brw_lock_get(int mode, struct obd_export *exp,
550 struct obd_ioobj *obj, struct niobuf_remote *nb,
551 struct lustre_handle *lh)
554 int nrbufs = obj->ioo_bufcnt;
555 struct ldlm_res_id res_id;
556 ldlm_policy_data_t policy;
560 osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id);
561 LASSERT(mode == LCK_PR || mode == LCK_PW);
562 LASSERT(!lustre_handle_is_used(lh));
564 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
567 for (i = 1; i < nrbufs; i ++)
568 if ((nb[0].flags & OBD_BRW_SRVLOCK) !=
569 (nb[i].flags & OBD_BRW_SRVLOCK))
572 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
573 policy.l_extent.end = (nb[nrbufs - 1].offset +
574 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
576 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
577 LDLM_EXTENT, &policy, mode, &flags,
578 ldlm_blocking_ast, ldlm_completion_ast,
579 ldlm_glimpse_ast, NULL, 0, NULL, lh));
582 static void ost_brw_lock_put(int mode,
583 struct obd_ioobj *obj, struct niobuf_remote *niob,
584 struct lustre_handle *lh)
587 LASSERT(mode == LCK_PR || mode == LCK_PW);
588 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
589 lustre_handle_is_used(lh));
590 if (lustre_handle_is_used(lh))
591 ldlm_lock_decref(lh, mode);
595 struct ost_prolong_data {
596 struct obd_export *opd_exp;
597 ldlm_policy_data_t opd_policy;
599 ldlm_mode_t opd_mode;
604 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
606 struct ost_prolong_data *opd = data;
608 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
610 if (lock->l_req_mode != lock->l_granted_mode) {
611 /* scan granted locks only */
612 return LDLM_ITER_STOP;
615 if (lock->l_export != opd->opd_exp) {
616 /* prolong locks only for given client */
617 return LDLM_ITER_CONTINUE;
620 if (!(lock->l_granted_mode & opd->opd_mode)) {
621 /* we aren't interesting in all type of locks */
622 return LDLM_ITER_CONTINUE;
625 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
626 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
627 /* the request doesn't cross the lock, skip it */
628 return LDLM_ITER_CONTINUE;
631 /* Fill the obdo with the matched lock handle.
632 * XXX: it is possible in some cases the IO RPC is covered by several
633 * locks, even for the write case, so it may need to be a lock list. */
634 if (opd->opd_oa && !(opd->opd_oa->o_valid & OBD_MD_FLHANDLE)) {
635 opd->opd_oa->o_handle.cookie = lock->l_handle.h_cookie;
636 opd->opd_oa->o_valid |= OBD_MD_FLHANDLE;
639 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
640 /* ignore locks not being cancelled */
641 return LDLM_ITER_CONTINUE;
644 CDEBUG(D_DLMTRACE,"refresh lock: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
645 lock->l_resource->lr_name.name[0],
646 lock->l_resource->lr_name.name[1],
647 opd->opd_policy.l_extent.start, opd->opd_policy.l_extent.end);
648 /* OK. this is a possible lock the user holds doing I/O
649 * let's refresh eviction timer for it */
650 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
651 opd->opd_lock_match = 1;
653 return LDLM_ITER_CONTINUE;
656 static int ost_rw_prolong_locks(struct ptlrpc_request *req, struct obd_ioobj *obj,
657 struct niobuf_remote *nb, struct obdo *oa,
660 struct ldlm_res_id res_id;
661 int nrbufs = obj->ioo_bufcnt;
662 struct ost_prolong_data opd = { 0 };
665 osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id);
668 opd.opd_exp = req->rq_export;
669 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
670 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
671 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
673 /* prolong locks for the current service time of the corresponding
674 * portal (= OST_IO_PORTAL) */
675 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
676 max(at_est2timeout(at_get(&req->rq_rqbd->
677 rqbd_service->srv_at_estimate)), ldlm_timeout);
679 CDEBUG(D_INFO,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
680 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
681 opd.opd_policy.l_extent.end);
683 if (oa->o_valid & OBD_MD_FLHANDLE) {
684 struct ldlm_lock *lock;
686 lock = ldlm_handle2lock(&oa->o_handle);
688 ost_prolong_locks_iter(lock, &opd);
689 if (opd.opd_lock_match) {
694 /* Check if the lock covers the whole IO region,
695 * otherwise iterate through the resource. */
696 if (lock->l_policy_data.l_extent.end >=
697 opd.opd_policy.l_extent.end &&
698 lock->l_policy_data.l_extent.start <=
699 opd.opd_policy.l_extent.start) {
708 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
709 ost_prolong_locks_iter, &opd);
710 RETURN(opd.opd_lock_match);
713 /* Allocate thread local buffers if needed */
714 static struct ost_thread_local_cache *ost_tls_get(struct ptlrpc_request *r)
716 struct ost_thread_local_cache *tls =
717 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
719 /* In normal mode of operation an I/O request is serviced only
720 * by ll_ost_io threads each of them has own tls buffers allocated by
722 * During recovery, an I/O request may be queued until any of the ost
723 * service threads process it. Not necessary it should be one of
724 * ll_ost_io threads. In that case we dynamically allocating tls
725 * buffers for the request service time. */
726 if (unlikely(tls == NULL)) {
727 LASSERT(r->rq_export->exp_in_recovery);
731 r->rq_svc_thread->t_data = tls;
737 /* Free thread local buffers if they were allocated only for servicing
738 * this one request */
739 static void ost_tls_put(struct ptlrpc_request *r)
741 struct ost_thread_local_cache *tls =
742 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
744 if (unlikely(tls->temporary)) {
746 r->rq_svc_thread->t_data = NULL;
750 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
752 struct ptlrpc_bulk_desc *desc = NULL;
753 struct obd_export *exp = req->rq_export;
754 struct niobuf_remote *remote_nb;
755 struct niobuf_local *local_nb;
756 struct obd_ioobj *ioo;
757 struct ost_body *body, *repbody;
758 struct lustre_capa *capa = NULL;
759 struct l_wait_info lwi;
760 struct lustre_handle lockh = { 0 };
761 int niocount, npages, nob = 0, rc, i;
763 struct ost_thread_local_cache *tls;
766 req->rq_bulk_read = 1;
768 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
769 GOTO(out, rc = -EIO);
771 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
773 /* Check if there is eviction in progress, and if so, wait for it to
775 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
776 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
777 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
778 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
782 GOTO(out, rc = -ENOTCONN);
784 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
785 * ost_rw_hpreq_check(). */
786 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
788 GOTO(out, rc = -EFAULT);
791 * A req_capsule_X_get_array(pill, field, ptr_to_element_count) function
792 * would be useful here and wherever we get &RMF_OBD_IOOBJ and
793 * &RMF_NIOBUF_REMOTE.
795 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
797 GOTO(out, rc = -EFAULT);
799 rc = ost_validate_obdo(exp, &body->oa, ioo);
803 niocount = ioo->ioo_bufcnt;
804 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
805 if (remote_nb == NULL)
806 GOTO(out, rc = -EFAULT);
808 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
809 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
811 CERROR("Missing capability for OST BRW READ");
812 GOTO(out, rc = -EFAULT);
816 rc = req_capsule_server_pack(&req->rq_pill);
820 tls = ost_tls_get(req);
822 GOTO(out_bulk, rc = -ENOMEM);
823 local_nb = tls->local;
825 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
830 * If getting the lock took more time than
831 * client was willing to wait, drop it. b=11330
833 if (cfs_time_current_sec() > req->rq_deadline ||
834 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
836 CERROR("Dropping timed-out read from %s because locking"
837 "object "LPX64" took %ld seconds (limit was %ld).\n",
838 libcfs_id2str(req->rq_peer), ioo->ioo_id,
839 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
840 req->rq_deadline - req->rq_arrival_time.tv_sec);
841 GOTO(out_lock, rc = -ETIMEDOUT);
844 npages = OST_THREAD_POOL_SIZE;
845 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
846 remote_nb, &npages, local_nb, oti, capa);
850 desc = ptlrpc_prep_bulk_exp(req, npages,
851 BULK_PUT_SOURCE, OST_BULK_PORTAL);
853 GOTO(out_commitrw, rc = -ENOMEM);
855 if (!lustre_handle_is_used(&lockh))
856 /* no needs to try to prolong lock if server is asked
857 * to handle locking (= OBD_BRW_SRVLOCK) */
858 ost_rw_prolong_locks(req, ioo, remote_nb, &body->oa,
862 for (i = 0; i < npages; i++) {
863 int page_rc = local_nb[i].rc;
865 if (page_rc < 0) { /* error */
871 if (page_rc != 0) { /* some data! */
872 LASSERT (local_nb[i].page != NULL);
873 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
874 local_nb[i].offset & ~CFS_PAGE_MASK,
878 if (page_rc != local_nb[i].len) { /* short read */
879 /* All subsequent pages should be 0 */
881 LASSERT(local_nb[i].rc == 0);
886 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
887 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
889 if (body->oa.o_valid & OBD_MD_FLFLAGS)
890 cksum_type = cksum_type_unpack(body->oa.o_flags);
891 body->oa.o_flags = cksum_type_pack(cksum_type);
892 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
893 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
894 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
896 body->oa.o_valid = 0;
898 /* We're finishing using body->oa as an input variable */
900 /* Check if client was evicted while we were doing i/o before touching
903 rc = target_bulk_io(exp, desc, &lwi);
908 /* Must commit after prep above in all cases */
909 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
910 remote_nb, npages, local_nb, oti, rc);
913 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
914 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
915 ost_drop_id(exp, &repbody->oa);
919 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
924 ptlrpc_free_bulk(desc);
928 req->rq_status = nob;
929 ptlrpc_lprocfs_brw(req, nob);
930 target_committed_to_req(req);
932 } else if (!no_reply) {
933 /* Only reply if there was no comms problem with bulk */
934 target_committed_to_req(req);
938 /* reply out callback would free */
939 ptlrpc_req_drop_rs(req);
940 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
941 "client will retry\n",
942 exp->exp_obd->obd_name,
943 exp->exp_client_uuid.uuid,
944 exp->exp_connection->c_remote_uuid.uuid,
945 libcfs_id2str(req->rq_peer));
951 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
953 struct ptlrpc_bulk_desc *desc = NULL;
954 struct obd_export *exp = req->rq_export;
955 struct niobuf_remote *remote_nb;
956 struct niobuf_local *local_nb;
957 struct obd_ioobj *ioo;
958 struct ost_body *body, *repbody;
959 struct l_wait_info lwi;
960 struct lustre_handle lockh = {0};
961 struct lustre_capa *capa = NULL;
963 int objcount, niocount, npages;
965 obd_count client_cksum = 0, server_cksum = 0;
966 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
967 int no_reply = 0, mmap = 0;
968 __u32 o_uid = 0, o_gid = 0;
969 struct ost_thread_local_cache *tls;
972 req->rq_bulk_write = 1;
974 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
975 GOTO(out, rc = -EIO);
976 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
977 GOTO(out, rc = -EFAULT);
979 /* pause before transaction has been started */
980 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
982 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
983 * ost_rw_hpreq_check(). */
984 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
986 GOTO(out, rc = -EFAULT);
988 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
989 RCL_CLIENT) / sizeof(*ioo);
990 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
992 GOTO(out, rc = -EFAULT);
994 rc = ost_validate_obdo(exp, &body->oa, ioo);
998 for (niocount = i = 0; i < objcount; i++)
999 niocount += ioo[i].ioo_bufcnt;
1002 * It'd be nice to have a capsule function to indicate how many elements
1003 * there were in a buffer for an RMF that's declared to be an array.
1004 * It's easy enough to compute the number of elements here though.
1006 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1007 if (remote_nb == NULL || niocount != (req_capsule_get_size(&req->rq_pill,
1008 &RMF_NIOBUF_REMOTE, RCL_CLIENT) / sizeof(*remote_nb)))
1009 GOTO(out, rc = -EFAULT);
1011 if ((remote_nb[0].flags & OBD_BRW_MEMALLOC) &&
1012 (exp->exp_connection->c_peer.nid == exp->exp_connection->c_self))
1013 cfs_memory_pressure_set();
1015 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
1016 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
1018 CERROR("Missing capability for OST BRW WRITE");
1019 GOTO(out, rc = -EFAULT);
1023 req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER,
1024 niocount * sizeof(*rcs));
1025 rc = req_capsule_server_pack(&req->rq_pill);
1028 CFS_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, cfs_fail_val);
1029 rcs = req_capsule_server_get(&req->rq_pill, &RMF_RCS);
1031 tls = ost_tls_get(req);
1033 GOTO(out_bulk, rc = -ENOMEM);
1034 local_nb = tls->local;
1036 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
1041 * If getting the lock took more time than
1042 * client was willing to wait, drop it. b=11330
1044 if (cfs_time_current_sec() > req->rq_deadline ||
1045 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
1047 CERROR("Dropping timed-out write from %s because locking "
1048 "object "LPX64" took %ld seconds (limit was %ld).\n",
1049 libcfs_id2str(req->rq_peer), ioo->ioo_id,
1050 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
1051 req->rq_deadline - req->rq_arrival_time.tv_sec);
1052 GOTO(out_lock, rc = -ETIMEDOUT);
1055 if (!lustre_handle_is_used(&lockh))
1056 /* no needs to try to prolong lock if server is asked
1057 * to handle locking (= OBD_BRW_SRVLOCK) */
1058 ost_rw_prolong_locks(req, ioo, remote_nb,&body->oa, LCK_PW);
1060 /* obd_preprw clobbers oa->valid, so save what we need */
1061 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
1062 client_cksum = body->oa.o_cksum;
1063 if (body->oa.o_valid & OBD_MD_FLFLAGS)
1064 cksum_type = cksum_type_unpack(body->oa.o_flags);
1066 if (body->oa.o_valid & OBD_MD_FLFLAGS && body->oa.o_flags & OBD_FL_MMAP)
1069 /* Because we already sync grant info with client when reconnect,
1070 * grant info will be cleared for resent req, then fed_grant and
1071 * total_grant will not be modified in following preprw_write */
1072 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1073 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1074 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1077 if (exp_connect_rmtclient(exp)) {
1078 o_uid = body->oa.o_uid;
1079 o_gid = body->oa.o_gid;
1081 npages = OST_THREAD_POOL_SIZE;
1082 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
1083 ioo, remote_nb, &npages, local_nb, oti, capa);
1087 desc = ptlrpc_prep_bulk_exp(req, npages,
1088 BULK_GET_SINK, OST_BULK_PORTAL);
1090 GOTO(skip_transfer, rc = -ENOMEM);
1092 /* NB Having prepped, we must commit... */
1094 for (i = 0; i < npages; i++)
1095 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1096 local_nb[i].offset & ~CFS_PAGE_MASK,
1099 rc = sptlrpc_svc_prep_bulk(req, desc);
1103 rc = target_bulk_io(exp, desc, &lwi);
1107 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
1108 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1110 if (unlikely(client_cksum != 0 && rc == 0)) {
1111 static int cksum_counter;
1112 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1113 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1114 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1115 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1116 repbody->oa.o_cksum = server_cksum;
1118 if (unlikely(client_cksum != server_cksum)) {
1119 CDEBUG_LIMIT(mmap ? D_INFO : D_ERROR,
1120 "client csum %x, server csum %x\n",
1121 client_cksum, server_cksum);
1123 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1124 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1125 cksum_counter, libcfs_id2str(req->rq_peer),
1130 /* Must commit after prep above in all cases */
1131 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1132 remote_nb, npages, local_nb, oti, rc);
1133 if (rc == -ENOTCONN)
1134 /* quota acquire process has been given up because
1135 * either the client has been evicted or the client
1136 * has timed out the request already */
1139 if (exp_connect_rmtclient(exp)) {
1140 repbody->oa.o_uid = o_uid;
1141 repbody->oa.o_gid = o_gid;
1145 * Disable sending mtime back to the client. If the client locked the
1146 * whole object, then it has already updated the mtime on its side,
1147 * otherwise it will have to glimpse anyway (see bug 21489, comment 32)
1149 repbody->oa.o_valid &= ~(OBD_MD_FLMTIME | OBD_MD_FLATIME);
1151 if (unlikely(client_cksum != server_cksum && rc == 0 && !mmap)) {
1152 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1157 if (new_cksum == server_cksum)
1158 msg = "changed in transit before arrival at OST";
1159 else if (new_cksum == client_cksum)
1160 msg = "initial checksum before message complete";
1162 msg = "changed in transit AND after initial checksum";
1164 if (req->rq_peer.nid == desc->bd_sender) {
1168 router = libcfs_nid2str(desc->bd_sender);
1171 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1172 "%s%s%s inode "DFID" object "
1173 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1174 exp->exp_obd->obd_name, msg,
1175 libcfs_id2str(req->rq_peer),
1177 body->oa.o_valid & OBD_MD_FLFID ?
1178 body->oa.o_parent_seq : (__u64)0,
1179 body->oa.o_valid & OBD_MD_FLFID ?
1180 body->oa.o_parent_oid : 0,
1181 body->oa.o_valid & OBD_MD_FLFID ?
1182 body->oa.o_parent_ver : 0,
1184 body->oa.o_valid & OBD_MD_FLGROUP ?
1185 body->oa.o_seq : (__u64)0,
1187 local_nb[npages-1].offset +
1188 local_nb[npages-1].len - 1 );
1189 CERROR("client csum %x, original server csum %x, "
1190 "server csum now %x\n",
1191 client_cksum, server_cksum, new_cksum);
1197 /* set per-requested niobuf return codes */
1198 for (i = j = 0; i < niocount; i++) {
1199 int len = remote_nb[i].len;
1204 LASSERT(j < npages);
1205 if (local_nb[j].rc < 0)
1206 rcs[i] = local_nb[j].rc;
1207 len -= local_nb[j].len;
1212 LASSERT(j == npages);
1213 ptlrpc_lprocfs_brw(req, nob);
1217 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1222 ptlrpc_free_bulk(desc);
1225 oti_to_request(oti, req);
1226 target_committed_to_req(req);
1227 rc = ptlrpc_reply(req);
1228 } else if (!no_reply) {
1229 /* Only reply if there was no comms problem with bulk */
1230 target_committed_to_req(req);
1231 req->rq_status = rc;
1234 /* reply out callback would free */
1235 ptlrpc_req_drop_rs(req);
1236 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1237 "client will retry\n",
1238 exp->exp_obd->obd_name,
1239 exp->exp_client_uuid.uuid,
1240 exp->exp_connection->c_remote_uuid.uuid,
1241 libcfs_id2str(req->rq_peer));
1243 cfs_memory_pressure_clr();
1248 * Implementation of OST_SET_INFO.
1250 * OST_SET_INFO is like ioctl(): heavily overloaded. Specifically, it takes a
1251 * "key" and a value RPC buffers as arguments, with the value's contents
1252 * interpreted according to the key.
1254 * Value types that need swabbing have swabbing done explicitly, either here or
1255 * in functions called from here. This should be corrected: all swabbing should
1256 * be done in the capsule abstraction, as that will then allow us to move
1257 * swabbing exclusively to the client without having to modify server code
1258 * outside the capsule abstraction's implementation itself. To correct this
1259 * will require minor changes to the capsule abstraction; see the comments for
1260 * req_capsule_extend() in layout.c.
1262 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1264 struct ost_body *body = NULL, *repbody;
1265 char *key, *val = NULL;
1266 int keylen, vallen, rc = 0;
1267 int is_grant_shrink = 0;
1270 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1272 DEBUG_REQ(D_HA, req, "no set_info key");
1275 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1278 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1281 if ((is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK)))
1282 /* In this case the value is actually an RMF_OST_BODY, so we
1283 * transmutate the type of this PTLRPC */
1284 req_capsule_extend(&req->rq_pill, &RQF_OST_SET_GRANT_INFO);
1286 rc = req_capsule_server_pack(&req->rq_pill);
1291 if (is_grant_shrink) {
1292 body = req_capsule_client_get(&req->rq_pill,
1297 repbody = req_capsule_server_get(&req->rq_pill,
1299 memcpy(repbody, body, sizeof(*body));
1300 val = (char*)repbody;
1302 val = req_capsule_client_get(&req->rq_pill,
1307 if (KEY_IS(KEY_EVICT_BY_NID)) {
1309 obd_export_evict_by_nid(exp->exp_obd, val);
1311 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1312 if (vallen < sizeof(__u32))
1314 __swab32s((__u32 *)val);
1317 /* OBD will also check if KEY_IS(KEY_GRANT_SHRINK), and will cast val to
1318 * a struct ost_body * value */
1319 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1321 lustre_msg_set_status(req->rq_repmsg, 0);
1325 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1328 int keylen, replylen, rc = 0;
1329 struct req_capsule *pill = &req->rq_pill;
1332 /* this common part for get_info rpc */
1333 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1335 DEBUG_REQ(D_HA, req, "no get_info key");
1338 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1340 if (KEY_IS(KEY_FIEMAP)) {
1341 struct ll_fiemap_info_key *fm_key = key;
1344 rc = ost_validate_obdo(exp, &fm_key->oa, NULL);
1349 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1353 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1354 RCL_SERVER, replylen);
1356 rc = req_capsule_server_pack(pill);
1360 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1364 /* call again to fill in the reply buffer */
1365 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1367 lustre_msg_set_status(req->rq_repmsg, 0);
1371 #ifdef HAVE_QUOTA_SUPPORT
1372 static int ost_handle_quotactl(struct ptlrpc_request *req)
1374 struct obd_quotactl *oqctl, *repoqc;
1378 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1380 GOTO(out, rc = -EPROTO);
1382 rc = req_capsule_server_pack(&req->rq_pill);
1386 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1387 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1394 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1396 struct obd_quotactl *oqctl;
1400 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1404 rc = req_capsule_server_pack(&req->rq_pill);
1408 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1412 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1414 struct quota_adjust_qunit *oqaq, *repoqa;
1415 struct lustre_quota_ctxt *qctxt;
1419 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1420 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1422 GOTO(out, rc = -EPROTO);
1424 rc = req_capsule_server_pack(&req->rq_pill);
1428 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1429 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt, NULL);
1437 static int ost_llog_handle_connect(struct obd_export *exp,
1438 struct ptlrpc_request *req)
1440 struct llogd_conn_body *body;
1444 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
1445 rc = obd_llog_connect(exp, body);
1449 #define ost_init_sec_none(reply, exp) \
1451 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1452 OBD_CONNECT_RMT_CLIENT_FORCE | \
1453 OBD_CONNECT_OSS_CAPA); \
1454 cfs_spin_lock(&exp->exp_lock); \
1455 exp->exp_connect_flags = reply->ocd_connect_flags; \
1456 cfs_spin_unlock(&exp->exp_lock); \
1459 static int ost_init_sec_level(struct ptlrpc_request *req)
1461 struct obd_export *exp = req->rq_export;
1462 struct req_capsule *pill = &req->rq_pill;
1463 struct obd_device *obd = exp->exp_obd;
1464 struct filter_obd *filter = &obd->u.filter;
1465 char *client = libcfs_nid2str(req->rq_peer.nid);
1466 struct obd_connect_data *data, *reply;
1470 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1471 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1472 if (data == NULL || reply == NULL)
1475 /* connection from MDT is always trusted */
1476 if (req->rq_auth_usr_mdt) {
1477 ost_init_sec_none(reply, exp);
1481 /* no GSS support case */
1482 if (!req->rq_auth_gss) {
1483 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1484 CWARN("client %s -> target %s does not user GSS, "
1485 "can not run under security level %d.\n",
1486 client, obd->obd_name, filter->fo_sec_level);
1489 ost_init_sec_none(reply, exp);
1494 /* old version case */
1495 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1496 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1497 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1498 CWARN("client %s -> target %s uses old version, "
1499 "can not run under security level %d.\n",
1500 client, obd->obd_name, filter->fo_sec_level);
1503 CWARN("client %s -> target %s uses old version, "
1504 "run under security level %d.\n",
1505 client, obd->obd_name, filter->fo_sec_level);
1506 ost_init_sec_none(reply, exp);
1511 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1513 if (!req->rq_auth_remote)
1514 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1515 "asked to be remote.\n", client, obd->obd_name);
1516 } else if (req->rq_auth_remote) {
1518 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1519 "as remote by default.\n", client, obd->obd_name);
1523 if (!filter->fo_fl_oss_capa) {
1524 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1525 " but OSS capabilities are not enabled: %d.\n",
1526 client, obd->obd_name, filter->fo_fl_oss_capa);
1531 switch (filter->fo_sec_level) {
1532 case LUSTRE_SEC_NONE:
1534 ost_init_sec_none(reply, exp);
1537 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1538 "can not run under security level %d.\n",
1539 client, obd->obd_name, filter->fo_sec_level);
1542 case LUSTRE_SEC_REMOTE:
1544 ost_init_sec_none(reply, exp);
1546 case LUSTRE_SEC_ALL:
1548 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1549 OBD_CONNECT_RMT_CLIENT_FORCE);
1550 if (!filter->fo_fl_oss_capa)
1551 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1553 cfs_spin_lock(&exp->exp_lock);
1554 exp->exp_connect_flags = reply->ocd_connect_flags;
1555 cfs_spin_unlock(&exp->exp_lock);
1567 * this should be done in filter_connect()/filter_reconnect(), but
1568 * we can't obtain information like NID, which stored in incoming
1569 * request, thus can't decide what flavor to use. so we do it here.
1571 * This hack should be removed after the OST stack be rewritten, just
1572 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1574 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1576 struct obd_export *exp = req->rq_export;
1577 struct filter_obd *filter = &exp->exp_obd->u.filter;
1578 struct sptlrpc_flavor flvr;
1581 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1582 LUSTRE_ECHO_NAME) == 0)) {
1583 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1587 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1588 cfs_read_lock(&filter->fo_sptlrpc_lock);
1589 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1593 cfs_read_unlock(&filter->fo_sptlrpc_lock);
1595 cfs_spin_lock(&exp->exp_lock);
1597 exp->exp_sp_peer = req->rq_sp_from;
1598 exp->exp_flvr = flvr;
1600 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1601 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1602 CERROR("unauthorized rpc flavor %x from %s, "
1603 "expect %x\n", req->rq_flvr.sf_rpc,
1604 libcfs_nid2str(req->rq_peer.nid),
1605 exp->exp_flvr.sf_rpc);
1609 cfs_spin_unlock(&exp->exp_lock);
1611 if (exp->exp_sp_peer != req->rq_sp_from) {
1612 CERROR("RPC source %s doesn't match %s\n",
1613 sptlrpc_part2name(req->rq_sp_from),
1614 sptlrpc_part2name(exp->exp_sp_peer));
1617 rc = sptlrpc_target_export_check(exp, req);
1624 /* Ensure that data and metadata are synced to the disk when lock is cancelled
1626 int ost_blocking_ast(struct ldlm_lock *lock,
1627 struct ldlm_lock_desc *desc,
1628 void *data, int flag)
1630 __u32 sync_lock_cancel = 0;
1631 __u32 len = sizeof(sync_lock_cancel);
1635 rc = obd_get_info(lock->l_export, sizeof(KEY_SYNC_LOCK_CANCEL),
1636 KEY_SYNC_LOCK_CANCEL, &len, &sync_lock_cancel, NULL);
1638 if (!rc && flag == LDLM_CB_CANCELING &&
1639 (lock->l_granted_mode & (LCK_PW|LCK_GROUP)) &&
1640 (sync_lock_cancel == ALWAYS_SYNC_ON_CANCEL ||
1641 (sync_lock_cancel == BLOCKING_SYNC_ON_CANCEL &&
1642 lock->l_flags & LDLM_FL_CBPENDING))) {
1643 struct obd_info *oinfo;
1647 OBD_ALLOC_PTR(oinfo);
1652 OBD_FREE_PTR(oinfo);
1655 oa->o_id = lock->l_resource->lr_name.name[0];
1656 oa->o_seq = lock->l_resource->lr_name.name[1];
1657 oa->o_valid = OBD_MD_FLID|OBD_MD_FLGROUP;
1660 rc = obd_sync(lock->l_export, oinfo,
1661 lock->l_policy_data.l_extent.start,
1662 lock->l_policy_data.l_extent.end, NULL);
1664 CERROR("Error %d syncing data on lock cancel\n", rc);
1667 OBD_FREE_PTR(oinfo);
1670 rc = ldlm_server_blocking_ast(lock, desc, data, flag);
1674 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1675 struct obd_device *obd, int *process)
1677 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1678 case OST_CONNECT: /* This will never get here, but for completeness. */
1679 case OST_DISCONNECT:
1690 case OBD_LOG_CANCEL:
1692 *process = target_queue_recovery_request(req, obd);
1696 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1702 int ost_msg_check_version(struct lustre_msg *msg)
1706 switch(lustre_msg_get_opc(msg)) {
1708 case OST_DISCONNECT:
1711 case SEC_CTX_INIT_CONT:
1713 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1715 CERROR("bad opc %u version %08x, expecting %08x\n",
1716 lustre_msg_get_opc(msg),
1717 lustre_msg_get_version(msg),
1718 LUSTRE_OBD_VERSION);
1731 #ifdef HAVE_QUOTA_SUPPORT
1732 case OST_QUOTACHECK:
1734 case OST_QUOTA_ADJUST_QUNIT:
1736 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1738 CERROR("bad opc %u version %08x, expecting %08x\n",
1739 lustre_msg_get_opc(msg),
1740 lustre_msg_get_version(msg),
1741 LUSTRE_OST_VERSION);
1746 case LDLM_BL_CALLBACK:
1747 case LDLM_CP_CALLBACK:
1748 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1750 CERROR("bad opc %u version %08x, expecting %08x\n",
1751 lustre_msg_get_opc(msg),
1752 lustre_msg_get_version(msg),
1753 LUSTRE_DLM_VERSION);
1755 case LLOG_ORIGIN_CONNECT:
1756 case OBD_LOG_CANCEL:
1757 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1759 CERROR("bad opc %u version %08x, expecting %08x\n",
1760 lustre_msg_get_opc(msg),
1761 lustre_msg_get_version(msg),
1762 LUSTRE_LOG_VERSION);
1765 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1772 * Returns 1 if the given PTLRPC matches the given LDLM locks, or 0 if it does
1775 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1776 struct ldlm_lock *lock)
1778 struct niobuf_remote *nb;
1779 struct obd_ioobj *ioo;
1780 struct ost_body *body;
1781 int objcount, niocount;
1782 int mode, opc, i, rc;
1786 opc = lustre_msg_get_opc(req->rq_reqmsg);
1787 LASSERT(opc == OST_READ || opc == OST_WRITE);
1789 /* As the request may be covered by several locks, do not look at
1790 * o_handle, look at the RPC IO region. */
1791 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1795 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1796 RCL_CLIENT) / sizeof(*ioo);
1797 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1801 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
1805 for (niocount = i = 0; i < objcount; i++)
1806 niocount += ioo[i].ioo_bufcnt;
1808 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1810 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
1811 RCL_CLIENT) / sizeof(*nb)))
1815 if (opc == OST_READ)
1818 start = nb[0].offset & CFS_PAGE_MASK;
1819 end = (nb[ioo->ioo_bufcnt - 1].offset +
1820 nb[ioo->ioo_bufcnt - 1].len - 1) | ~CFS_PAGE_MASK;
1822 LASSERT(lock->l_resource != NULL);
1823 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_seq,
1824 &lock->l_resource->lr_name))
1827 if (!(lock->l_granted_mode & mode))
1830 if (lock->l_policy_data.l_extent.end < start ||
1831 lock->l_policy_data.l_extent.start > end)
1838 * High-priority queue request check for whether the given PTLRPC request (\a
1839 * req) is blocking an LDLM lock cancel.
1841 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1842 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1844 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1845 * function looks only at OST_READs and OST_WRITEs.
1847 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1849 struct niobuf_remote *nb;
1850 struct obd_ioobj *ioo;
1851 struct ost_body *body;
1852 int objcount, niocount;
1853 int mode, opc, i, rc;
1856 opc = lustre_msg_get_opc(req->rq_reqmsg);
1857 LASSERT(opc == OST_READ || opc == OST_WRITE);
1859 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1863 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1864 RCL_CLIENT) / sizeof(*ioo);
1865 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1869 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
1873 for (niocount = i = 0; i < objcount; i++)
1874 niocount += ioo[i].ioo_bufcnt;
1875 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1877 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
1878 RCL_CLIENT) / sizeof(*nb)))
1880 if (niocount != 0 && (nb[0].flags & OBD_BRW_SRVLOCK))
1884 if (opc == OST_READ)
1886 RETURN(ost_rw_prolong_locks(req, ioo, nb, &body->oa, mode));
1889 static int ost_punch_prolong_locks(struct ptlrpc_request *req, struct obdo *oa)
1891 struct ldlm_res_id res_id = { .name = { oa->o_id } };
1892 struct ost_prolong_data opd = { 0 };
1897 end = start + oa->o_blocks;
1899 opd.opd_mode = LCK_PW;
1900 opd.opd_exp = req->rq_export;
1901 opd.opd_policy.l_extent.start = start & CFS_PAGE_MASK;
1902 if (oa->o_blocks == OBD_OBJECT_EOF || end < start)
1903 opd.opd_policy.l_extent.end = OBD_OBJECT_EOF;
1905 opd.opd_policy.l_extent.end = end | ~CFS_PAGE_MASK;
1907 /* prolong locks for the current service time of the corresponding
1908 * portal (= OST_IO_PORTAL) */
1909 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
1910 max(at_est2timeout(at_get(&req->rq_rqbd->
1911 rqbd_service->srv_at_estimate)), ldlm_timeout);
1913 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1914 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
1915 opd.opd_policy.l_extent.end);
1918 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
1919 ost_prolong_locks_iter, &opd);
1920 RETURN(opd.opd_lock_match);
1924 * Like ost_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
1926 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1927 struct ldlm_lock *lock)
1929 struct ost_body *body;
1933 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1935 RETURN(0); /* can't return -EFAULT here */
1937 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
1941 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1942 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1948 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
1950 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1952 struct ost_body *body;
1955 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1959 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
1963 LASSERT(!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1964 !(body->oa.o_flags & OBD_FL_SRVLOCK));
1966 RETURN(ost_punch_prolong_locks(req, &body->oa));
1969 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
1970 .hpreq_lock_match = ost_rw_hpreq_lock_match,
1971 .hpreq_check = ost_rw_hpreq_check,
1974 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
1975 .hpreq_lock_match = ost_punch_hpreq_lock_match,
1976 .hpreq_check = ost_punch_hpreq_check,
1979 /** Assign high priority operations to the request if needed. */
1980 static int ost_hpreq_handler(struct ptlrpc_request *req)
1983 if (req->rq_export) {
1984 int opc = lustre_msg_get_opc(req->rq_reqmsg);
1985 struct ost_body *body;
1987 if (opc == OST_READ || opc == OST_WRITE) {
1988 struct niobuf_remote *nb;
1989 struct obd_ioobj *ioo;
1990 int objcount, niocount;
1993 /* RPCs on the H-P queue can be inspected before
1994 * ost_handler() initializes their pills, so we
1995 * initialize that here. Capsule initialization is
1996 * idempotent, as is setting the pill's format (provided
1997 * it doesn't change).
1999 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2000 if (opc == OST_READ)
2001 req_capsule_set(&req->rq_pill,
2004 req_capsule_set(&req->rq_pill,
2005 &RQF_OST_BRW_WRITE);
2007 body = req_capsule_client_get(&req->rq_pill,
2010 CERROR("Missing/short ost_body\n");
2014 objcount = req_capsule_get_size(&req->rq_pill,
2018 if (objcount == 0) {
2019 CERROR("Missing/short ioobj\n");
2023 CERROR("too many ioobjs (%d)\n", objcount);
2027 ioo = req_capsule_client_get(&req->rq_pill,
2030 CERROR("Missing/short ioobj\n");
2034 for (niocount = i = 0; i < objcount; i++) {
2035 if (ioo[i].ioo_bufcnt == 0) {
2036 CERROR("ioo[%d] has zero bufcnt\n", i);
2039 niocount += ioo[i].ioo_bufcnt;
2041 if (niocount > PTLRPC_MAX_BRW_PAGES) {
2042 DEBUG_REQ(D_RPCTRACE, req,
2043 "bulk has too many pages (%d)",
2048 nb = req_capsule_client_get(&req->rq_pill,
2049 &RMF_NIOBUF_REMOTE);
2051 CERROR("Missing/short niobuf\n");
2055 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
2056 req->rq_ops = &ost_hpreq_rw;
2057 } else if (opc == OST_PUNCH) {
2058 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2059 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2061 body = req_capsule_client_get(&req->rq_pill,
2064 CERROR("Missing/short ost_body\n");
2068 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
2069 !(body->oa.o_flags & OBD_FL_SRVLOCK))
2070 req->rq_ops = &ost_hpreq_punch;
2076 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
2077 int ost_handle(struct ptlrpc_request *req)
2079 struct obd_trans_info trans_info = { 0, };
2080 struct obd_trans_info *oti = &trans_info;
2081 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
2082 struct obd_device *obd = NULL;
2085 LASSERT(current->journal_info == NULL);
2087 /* primordial rpcs don't affect server recovery */
2088 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2090 case SEC_CTX_INIT_CONT:
2095 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2097 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
2098 if (!class_connected_export(req->rq_export)) {
2099 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
2100 lustre_msg_get_opc(req->rq_reqmsg),
2101 libcfs_id2str(req->rq_peer));
2102 req->rq_status = -ENOTCONN;
2103 GOTO(out, rc = -ENOTCONN);
2106 obd = req->rq_export->exp_obd;
2108 /* Check for aborted recovery. */
2109 if (obd->obd_recovering) {
2110 rc = ost_filter_recovery_request(req, obd,
2112 if (rc || !should_process)
2114 else if (should_process < 0) {
2115 req->rq_status = should_process;
2116 rc = ptlrpc_error(req);
2124 rc = ost_msg_check_version(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);
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_sema_init(&ost->ost_health_sem, 1);
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_down(&ost->ost_health_sem);
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_up(&ost->ost_health_sem);
2545 lprocfs_obd_cleanup(obd);
2550 static int ost_health_check(struct obd_device *obd)
2552 struct ost_obd *ost = &obd->u.ost;
2555 cfs_down(&ost->ost_health_sem);
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_up(&ost->ost_health_sem);
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);