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 = { { { 0 } } };
253 struct lustre_handle lh = { 0 };
257 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
261 rc = ost_validate_obdo(exp, &body->oa, NULL);
265 rc = req_capsule_server_pack(&req->rq_pill);
269 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
270 repbody->oa = body->oa;
272 rc = ost_lock_get(exp, &body->oa, 0, OBD_OBJECT_EOF, &lh, LCK_PR, 0);
276 oinfo.oi_oa = &repbody->oa;
277 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA) {
278 oinfo.oi_capa = req_capsule_client_get(&req->rq_pill,
280 if (oinfo.oi_capa == NULL) {
281 CERROR("Missing capability for OST GETATTR");
286 req->rq_status = obd_getattr(exp, &oinfo);
287 ost_lock_put(exp, &lh, LCK_PR);
289 ost_drop_id(exp, &repbody->oa);
293 static int ost_statfs(struct ptlrpc_request *req)
295 struct obd_statfs *osfs;
299 rc = req_capsule_server_pack(&req->rq_pill);
303 osfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
305 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
306 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
308 if (req->rq_status != 0)
309 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
314 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
315 struct obd_trans_info *oti)
317 struct ost_body *body, *repbody;
321 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
325 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
329 rc = req_capsule_server_pack(&req->rq_pill);
333 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
334 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
335 oti->oti_logcookies = &repbody->oa.o_lcookie;
337 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
338 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
342 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
343 struct obd_trans_info *oti)
345 struct obd_info oinfo = { { { 0 } } };
346 struct ost_body *body, *repbody;
348 struct lustre_handle lh = {0,};
351 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
352 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
354 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
358 rc = ost_validate_obdo(exp, &body->oa, NULL);
362 oinfo.oi_oa = &body->oa;
363 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
364 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
366 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
367 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
370 rc = req_capsule_server_pack(&req->rq_pill);
374 /* standard truncate optimization: if file body is completely
375 * destroyed, don't send data back to the server. */
376 if (oinfo.oi_oa->o_size == 0)
377 flags |= LDLM_AST_DISCARD_DATA;
379 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
380 rc = ost_lock_get(exp, oinfo.oi_oa, oinfo.oi_oa->o_size,
381 oinfo.oi_oa->o_blocks, &lh, LCK_PW, flags);
383 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
384 oinfo.oi_oa->o_flags == OBD_FL_SRVLOCK)
386 * If OBD_FL_SRVLOCK is the only bit set in
387 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
388 * through filter_setattr() to filter_iocontrol().
390 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
392 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA) {
393 oinfo.oi_capa = req_capsule_client_get(&req->rq_pill,
395 if (oinfo.oi_capa == NULL) {
396 CERROR("Missing capability for OST PUNCH");
400 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
401 ost_lock_put(exp, &lh, LCK_PW);
403 repbody->oa = *oinfo.oi_oa;
404 ost_drop_id(exp, &repbody->oa);
408 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
410 struct ost_body *body, *repbody;
411 struct lustre_capa *capa = NULL;
415 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
419 rc = ost_validate_obdo(exp, &body->oa, NULL);
423 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
424 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
426 CERROR("Missing capability for OST SYNC");
431 rc = req_capsule_server_pack(&req->rq_pill);
435 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
436 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
437 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
438 repbody->oa.o_blocks, capa);
439 ost_drop_id(exp, &repbody->oa);
443 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
444 struct obd_trans_info *oti)
446 struct ost_body *body, *repbody;
448 struct obd_info oinfo = { { { 0 } } };
451 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
455 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
459 rc = req_capsule_server_pack(&req->rq_pill);
463 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
464 repbody->oa = body->oa;
466 oinfo.oi_oa = &repbody->oa;
467 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA) {
468 oinfo.oi_capa = req_capsule_client_get(&req->rq_pill,
470 if (oinfo.oi_capa == NULL) {
471 CERROR("Missing capability for OST SETATTR");
475 req->rq_status = obd_setattr(exp, &oinfo, oti);
476 ost_drop_id(exp, &repbody->oa);
480 static int ost_bulk_timeout(void *data)
483 /* We don't fail the connection here, because having the export
484 * killed makes the (vital) call to commitrw very sad.
489 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
490 cksum_type_t cksum_type)
495 cksum = init_checksum(cksum_type);
496 for (i = 0; i < desc->bd_iov_count; i++) {
497 struct page *page = desc->bd_iov[i].kiov_page;
498 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
499 char *ptr = kmap(page) + off;
500 int len = desc->bd_iov[i].kiov_len;
502 /* corrupt the data before we compute the checksum, to
503 * simulate a client->OST data error */
504 if (i == 0 && opc == OST_WRITE &&
505 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
506 memcpy(ptr, "bad3", min(4, len));
507 cksum = compute_checksum(cksum, ptr, len, cksum_type);
508 /* corrupt the data after we compute the checksum, to
509 * simulate an OST->client data error */
510 if (i == 0 && opc == OST_READ &&
511 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
512 memcpy(ptr, "bad4", min(4, len));
513 /* nobody should use corrupted page again */
514 ClearPageUptodate(page);
522 static int ost_brw_lock_get(int mode, struct obd_export *exp,
523 struct obd_ioobj *obj, struct niobuf_remote *nb,
524 struct lustre_handle *lh)
527 int nrbufs = obj->ioo_bufcnt;
528 struct ldlm_res_id res_id;
529 ldlm_policy_data_t policy;
533 osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id);
534 LASSERT(mode == LCK_PR || mode == LCK_PW);
535 LASSERT(!lustre_handle_is_used(lh));
537 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
540 for (i = 1; i < nrbufs; i ++)
541 if ((nb[0].flags & OBD_BRW_SRVLOCK) !=
542 (nb[i].flags & OBD_BRW_SRVLOCK))
545 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
546 policy.l_extent.end = (nb[nrbufs - 1].offset +
547 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
549 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
550 LDLM_EXTENT, &policy, mode, &flags,
551 ldlm_blocking_ast, ldlm_completion_ast,
552 ldlm_glimpse_ast, NULL, 0, NULL, lh));
555 static void ost_brw_lock_put(int mode,
556 struct obd_ioobj *obj, struct niobuf_remote *niob,
557 struct lustre_handle *lh)
560 LASSERT(mode == LCK_PR || mode == LCK_PW);
561 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
562 lustre_handle_is_used(lh));
563 if (lustre_handle_is_used(lh))
564 ldlm_lock_decref(lh, mode);
568 struct ost_prolong_data {
569 struct obd_export *opd_exp;
570 ldlm_policy_data_t opd_policy;
572 ldlm_mode_t opd_mode;
577 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
579 struct ost_prolong_data *opd = data;
581 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
583 if (lock->l_req_mode != lock->l_granted_mode) {
584 /* scan granted locks only */
585 return LDLM_ITER_STOP;
588 if (lock->l_export != opd->opd_exp) {
589 /* prolong locks only for given client */
590 return LDLM_ITER_CONTINUE;
593 if (!(lock->l_granted_mode & opd->opd_mode)) {
594 /* we aren't interesting in all type of locks */
595 return LDLM_ITER_CONTINUE;
598 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
599 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
600 /* the request doesn't cross the lock, skip it */
601 return LDLM_ITER_CONTINUE;
604 /* Fill the obdo with the matched lock handle.
605 * XXX: it is possible in some cases the IO RPC is covered by several
606 * locks, even for the write case, so it may need to be a lock list. */
607 if (opd->opd_oa && !(opd->opd_oa->o_valid & OBD_MD_FLHANDLE)) {
608 opd->opd_oa->o_handle.cookie = lock->l_handle.h_cookie;
609 opd->opd_oa->o_valid |= OBD_MD_FLHANDLE;
612 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
613 /* ignore locks not being cancelled */
614 return LDLM_ITER_CONTINUE;
617 CDEBUG(D_DLMTRACE,"refresh lock: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
618 lock->l_resource->lr_name.name[0],
619 lock->l_resource->lr_name.name[1],
620 opd->opd_policy.l_extent.start, opd->opd_policy.l_extent.end);
621 /* OK. this is a possible lock the user holds doing I/O
622 * let's refresh eviction timer for it */
623 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
624 opd->opd_lock_match = 1;
626 return LDLM_ITER_CONTINUE;
629 static int ost_rw_prolong_locks(struct ptlrpc_request *req, struct obd_ioobj *obj,
630 struct niobuf_remote *nb, struct obdo *oa,
633 struct ldlm_res_id res_id;
634 int nrbufs = obj->ioo_bufcnt;
635 struct ost_prolong_data opd = { 0 };
638 osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id);
641 opd.opd_exp = req->rq_export;
642 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
643 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
644 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
646 /* prolong locks for the current service time of the corresponding
647 * portal (= OST_IO_PORTAL) */
648 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
649 max(at_est2timeout(at_get(&req->rq_rqbd->
650 rqbd_service->srv_at_estimate)), ldlm_timeout);
652 CDEBUG(D_INFO,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
653 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
654 opd.opd_policy.l_extent.end);
656 if (oa->o_valid & OBD_MD_FLHANDLE) {
657 struct ldlm_lock *lock;
659 lock = ldlm_handle2lock(&oa->o_handle);
661 ost_prolong_locks_iter(lock, &opd);
662 if (opd.opd_lock_match) {
667 /* Check if the lock covers the whole IO region,
668 * otherwise iterate through the resource. */
669 if (lock->l_policy_data.l_extent.end >=
670 opd.opd_policy.l_extent.end &&
671 lock->l_policy_data.l_extent.start <=
672 opd.opd_policy.l_extent.start) {
681 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
682 ost_prolong_locks_iter, &opd);
683 RETURN(opd.opd_lock_match);
686 /* Allocate thread local buffers if needed */
687 static struct ost_thread_local_cache *ost_tls_get(struct ptlrpc_request *r)
689 struct ost_thread_local_cache *tls =
690 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
692 /* In normal mode of operation an I/O request is serviced only
693 * by ll_ost_io threads each of them has own tls buffers allocated by
695 * During recovery, an I/O request may be queued until any of the ost
696 * service threads process it. Not necessary it should be one of
697 * ll_ost_io threads. In that case we dynamically allocating tls
698 * buffers for the request service time. */
699 if (unlikely(tls == NULL)) {
700 LASSERT(r->rq_export->exp_in_recovery);
704 r->rq_svc_thread->t_data = tls;
710 /* Free thread local buffers if they were allocated only for servicing
711 * this one request */
712 static void ost_tls_put(struct ptlrpc_request *r)
714 struct ost_thread_local_cache *tls =
715 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
717 if (unlikely(tls->temporary)) {
719 r->rq_svc_thread->t_data = NULL;
723 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
725 struct ptlrpc_bulk_desc *desc = NULL;
726 struct obd_export *exp = req->rq_export;
727 struct niobuf_remote *remote_nb;
728 struct niobuf_local *local_nb;
729 struct obd_ioobj *ioo;
730 struct ost_body *body, *repbody;
731 struct lustre_capa *capa = NULL;
732 struct l_wait_info lwi;
733 struct lustre_handle lockh = { 0 };
734 int niocount, npages, nob = 0, rc, i;
736 struct ost_thread_local_cache *tls;
739 req->rq_bulk_read = 1;
741 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
742 GOTO(out, rc = -EIO);
744 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
746 /* Check if there is eviction in progress, and if so, wait for it to
748 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
749 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
750 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
751 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
755 GOTO(out, rc = -ENOTCONN);
757 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
758 * ost_rw_hpreq_check(). */
759 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
761 GOTO(out, rc = -EFAULT);
764 * A req_capsule_X_get_array(pill, field, ptr_to_element_count) function
765 * would be useful here and wherever we get &RMF_OBD_IOOBJ and
766 * &RMF_NIOBUF_REMOTE.
768 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
770 GOTO(out, rc = -EFAULT);
772 rc = ost_validate_obdo(exp, &body->oa, ioo);
776 niocount = ioo->ioo_bufcnt;
777 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
778 if (remote_nb == NULL)
779 GOTO(out, rc = -EFAULT);
781 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
782 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
784 CERROR("Missing capability for OST BRW READ");
785 GOTO(out, rc = -EFAULT);
789 rc = req_capsule_server_pack(&req->rq_pill);
793 tls = ost_tls_get(req);
795 GOTO(out_bulk, rc = -ENOMEM);
796 local_nb = tls->local;
798 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
803 * If getting the lock took more time than
804 * client was willing to wait, drop it. b=11330
806 if (cfs_time_current_sec() > req->rq_deadline ||
807 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
809 CERROR("Dropping timed-out read from %s because locking"
810 "object "LPX64" took %ld seconds (limit was %ld).\n",
811 libcfs_id2str(req->rq_peer), ioo->ioo_id,
812 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
813 req->rq_deadline - req->rq_arrival_time.tv_sec);
814 GOTO(out_lock, rc = -ETIMEDOUT);
817 npages = OST_THREAD_POOL_SIZE;
818 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
819 remote_nb, &npages, local_nb, oti, capa);
823 desc = ptlrpc_prep_bulk_exp(req, npages,
824 BULK_PUT_SOURCE, OST_BULK_PORTAL);
826 GOTO(out_lock, rc = -ENOMEM);
828 if (!lustre_handle_is_used(&lockh))
829 /* no needs to try to prolong lock if server is asked
830 * to handle locking (= OBD_BRW_SRVLOCK) */
831 ost_rw_prolong_locks(req, ioo, remote_nb, &body->oa,
835 for (i = 0; i < npages; i++) {
836 int page_rc = local_nb[i].rc;
838 if (page_rc < 0) { /* error */
844 if (page_rc != 0) { /* some data! */
845 LASSERT (local_nb[i].page != NULL);
846 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
847 local_nb[i].offset & ~CFS_PAGE_MASK,
851 if (page_rc != local_nb[i].len) { /* short read */
852 /* All subsequent pages should be 0 */
854 LASSERT(local_nb[i].rc == 0);
859 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
860 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
862 if (body->oa.o_valid & OBD_MD_FLFLAGS)
863 cksum_type = cksum_type_unpack(body->oa.o_flags);
864 body->oa.o_flags = cksum_type_pack(cksum_type);
865 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
866 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
867 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
869 body->oa.o_valid = 0;
871 /* We're finishing using body->oa as an input variable */
873 /* Check if client was evicted while we were doing i/o before touching
876 /* Check if there is eviction in progress, and if so, wait for
878 if (unlikely(cfs_atomic_read(&exp->exp_obd->
879 obd_evict_inprogress))) {
880 lwi = LWI_INTR(NULL, NULL);
881 rc = l_wait_event(exp->exp_obd->
882 obd_evict_inprogress_waitq,
883 !cfs_atomic_read(&exp->exp_obd->
884 obd_evict_inprogress),
887 /* Check if client was evicted or tried to reconnect already */
888 if (exp->exp_failed || exp->exp_abort_active_req)
891 rc = sptlrpc_svc_wrap_bulk(req, desc);
893 rc = ptlrpc_start_bulk_transfer(desc);
897 time_t start = cfs_time_current_sec();
899 long timeoutl = req->rq_deadline -
900 cfs_time_current_sec();
901 cfs_duration_t timeout = timeoutl <= 0 ?
902 CFS_TICK : cfs_time_seconds(timeoutl);
903 lwi = LWI_TIMEOUT_INTERVAL(timeout,
907 rc = l_wait_event(desc->bd_waitq,
908 !ptlrpc_server_bulk_active(desc) ||
910 exp->exp_abort_active_req,
912 LASSERT(rc == 0 || rc == -ETIMEDOUT);
913 /* Wait again if we changed deadline */
914 } while ((rc == -ETIMEDOUT) &&
915 (req->rq_deadline > cfs_time_current_sec()));
917 if (rc == -ETIMEDOUT) {
918 DEBUG_REQ(D_ERROR, req,
919 "timeout on bulk PUT after %ld%+lds",
920 req->rq_deadline - start,
921 cfs_time_current_sec() -
923 ptlrpc_abort_bulk(desc);
924 } else if (exp->exp_failed) {
925 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
927 ptlrpc_abort_bulk(desc);
928 } else if (exp->exp_abort_active_req) {
929 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk PUT");
930 /* we don't reply anyway */
932 ptlrpc_abort_bulk(desc);
933 } else if (!desc->bd_success ||
934 desc->bd_nob_transferred != desc->bd_nob) {
935 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
937 "truncated" : "network error on",
938 desc->bd_nob_transferred,
940 /* XXX should this be a different errno? */
944 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
949 /* Must commit after prep above in all cases */
950 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
951 remote_nb, npages, local_nb, oti, rc);
954 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
955 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
956 ost_drop_id(exp, &repbody->oa);
960 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
965 ptlrpc_free_bulk(desc);
969 req->rq_status = nob;
970 ptlrpc_lprocfs_brw(req, nob);
971 target_committed_to_req(req);
973 } else if (!no_reply) {
974 /* Only reply if there was no comms problem with bulk */
975 target_committed_to_req(req);
979 /* reply out callback would free */
980 ptlrpc_req_drop_rs(req);
981 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
982 "client will retry\n",
983 exp->exp_obd->obd_name,
984 exp->exp_client_uuid.uuid,
985 exp->exp_connection->c_remote_uuid.uuid,
986 libcfs_id2str(req->rq_peer));
992 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
994 struct ptlrpc_bulk_desc *desc = NULL;
995 struct obd_export *exp = req->rq_export;
996 struct niobuf_remote *remote_nb;
997 struct niobuf_local *local_nb;
998 struct obd_ioobj *ioo;
999 struct ost_body *body, *repbody;
1000 struct l_wait_info lwi;
1001 struct lustre_handle lockh = {0};
1002 struct lustre_capa *capa = NULL;
1004 int objcount, niocount, npages;
1006 obd_count client_cksum = 0, server_cksum = 0;
1007 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
1008 int no_reply = 0, mmap = 0;
1009 __u32 o_uid = 0, o_gid = 0;
1010 struct ost_thread_local_cache *tls;
1013 req->rq_bulk_write = 1;
1015 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
1016 GOTO(out, rc = -EIO);
1017 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
1018 GOTO(out, rc = -EFAULT);
1020 /* pause before transaction has been started */
1021 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
1023 /* Check if there is eviction in progress, and if so, wait for it to
1025 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
1026 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
1027 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
1028 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
1031 if (exp->exp_failed)
1032 GOTO(out, rc = -ENOTCONN);
1034 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
1035 * ost_rw_hpreq_check(). */
1036 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1038 GOTO(out, rc = -EFAULT);
1040 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1041 RCL_CLIENT) / sizeof(*ioo);
1042 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1044 GOTO(out, rc = -EFAULT);
1046 rc = ost_validate_obdo(exp, &body->oa, ioo);
1050 for (niocount = i = 0; i < objcount; i++)
1051 niocount += ioo[i].ioo_bufcnt;
1054 * It'd be nice to have a capsule function to indicate how many elements
1055 * there were in a buffer for an RMF that's declared to be an array.
1056 * It's easy enough to compute the number of elements here though.
1058 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1059 if (remote_nb == NULL || niocount != (req_capsule_get_size(&req->rq_pill,
1060 &RMF_NIOBUF_REMOTE, RCL_CLIENT) / sizeof(*remote_nb)))
1061 GOTO(out, rc = -EFAULT);
1063 if ((remote_nb[0].flags & OBD_BRW_MEMALLOC) &&
1064 (exp->exp_connection->c_peer.nid == exp->exp_connection->c_self))
1065 cfs_memory_pressure_set();
1067 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
1068 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
1070 CERROR("Missing capability for OST BRW WRITE");
1071 GOTO(out, rc = -EFAULT);
1075 req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER,
1076 niocount * sizeof(*rcs));
1077 rc = req_capsule_server_pack(&req->rq_pill);
1080 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, obd_fail_val);
1081 rcs = req_capsule_server_get(&req->rq_pill, &RMF_RCS);
1083 tls = ost_tls_get(req);
1085 GOTO(out_bulk, rc = -ENOMEM);
1086 local_nb = tls->local;
1088 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
1093 * If getting the lock took more time than
1094 * client was willing to wait, drop it. b=11330
1096 if (cfs_time_current_sec() > req->rq_deadline ||
1097 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
1099 CERROR("Dropping timed-out write from %s because locking "
1100 "object "LPX64" took %ld seconds (limit was %ld).\n",
1101 libcfs_id2str(req->rq_peer), ioo->ioo_id,
1102 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
1103 req->rq_deadline - req->rq_arrival_time.tv_sec);
1104 GOTO(out_lock, rc = -ETIMEDOUT);
1107 if (!lustre_handle_is_used(&lockh))
1108 /* no needs to try to prolong lock if server is asked
1109 * to handle locking (= OBD_BRW_SRVLOCK) */
1110 ost_rw_prolong_locks(req, ioo, remote_nb,&body->oa, LCK_PW);
1112 /* obd_preprw clobbers oa->valid, so save what we need */
1113 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
1114 client_cksum = body->oa.o_cksum;
1115 if (body->oa.o_valid & OBD_MD_FLFLAGS)
1116 cksum_type = cksum_type_unpack(body->oa.o_flags);
1118 if (body->oa.o_valid & OBD_MD_FLFLAGS && body->oa.o_flags & OBD_FL_MMAP)
1121 /* Because we already sync grant info with client when reconnect,
1122 * grant info will be cleared for resent req, then fed_grant and
1123 * total_grant will not be modified in following preprw_write */
1124 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1125 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1126 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1129 if (exp_connect_rmtclient(exp)) {
1130 o_uid = body->oa.o_uid;
1131 o_gid = body->oa.o_gid;
1133 npages = OST_THREAD_POOL_SIZE;
1134 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
1135 ioo, remote_nb, &npages, local_nb, oti, capa);
1139 desc = ptlrpc_prep_bulk_exp(req, npages,
1140 BULK_GET_SINK, OST_BULK_PORTAL);
1142 GOTO(out_lock, rc = -ENOMEM);
1144 /* NB Having prepped, we must commit... */
1146 for (i = 0; i < npages; i++)
1147 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1148 local_nb[i].offset & ~CFS_PAGE_MASK,
1151 rc = sptlrpc_svc_prep_bulk(req, desc);
1155 /* Check if client was evicted or tried to reconnect while we
1156 * were doing i/o before touching network */
1157 if (desc->bd_export->exp_failed ||
1158 desc->bd_export->exp_abort_active_req)
1161 rc = ptlrpc_start_bulk_transfer(desc);
1163 time_t start = cfs_time_current_sec();
1165 long timeoutl = req->rq_deadline -
1166 cfs_time_current_sec();
1167 cfs_duration_t timeout = timeoutl <= 0 ?
1168 CFS_TICK : cfs_time_seconds(timeoutl);
1169 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
1170 ost_bulk_timeout, desc);
1171 rc = l_wait_event(desc->bd_waitq,
1172 !ptlrpc_server_bulk_active(desc) ||
1173 desc->bd_export->exp_failed ||
1174 desc->bd_export->exp_abort_active_req,
1176 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1177 /* Wait again if we changed deadline */
1178 } while ((rc == -ETIMEDOUT) &&
1179 (req->rq_deadline > cfs_time_current_sec()));
1181 if (rc == -ETIMEDOUT) {
1182 DEBUG_REQ(D_ERROR, req,
1183 "timeout on bulk GET after %ld%+lds",
1184 req->rq_deadline - start,
1185 cfs_time_current_sec() -
1187 ptlrpc_abort_bulk(desc);
1188 } else if (desc->bd_export->exp_failed) {
1189 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1191 ptlrpc_abort_bulk(desc);
1192 } else if (desc->bd_export->exp_abort_active_req) {
1193 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk GET");
1194 /* we don't reply anyway */
1196 ptlrpc_abort_bulk(desc);
1197 } else if (!desc->bd_success) {
1198 DEBUG_REQ(D_ERROR, req, "network error on bulk GET");
1199 /* XXX should this be a different errno? */
1202 rc = sptlrpc_svc_unwrap_bulk(req, desc);
1205 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1209 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
1210 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1212 if (unlikely(client_cksum != 0 && rc == 0)) {
1213 static int cksum_counter;
1214 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1215 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1216 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1217 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1218 repbody->oa.o_cksum = server_cksum;
1220 if (unlikely(client_cksum != server_cksum)) {
1221 CDEBUG_LIMIT(mmap ? D_INFO : D_ERROR,
1222 "client csum %x, server csum %x\n",
1223 client_cksum, server_cksum);
1225 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1226 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1227 cksum_counter, libcfs_id2str(req->rq_peer),
1232 /* Must commit after prep above in all cases */
1233 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1234 remote_nb, npages, local_nb, oti, rc);
1235 if (rc == -ENOTCONN)
1236 /* quota acquire process has been given up because
1237 * either the client has been evicted or the client
1238 * has timed out the request already */
1241 if (exp_connect_rmtclient(exp)) {
1242 repbody->oa.o_uid = o_uid;
1243 repbody->oa.o_gid = o_gid;
1247 * Disable sending mtime back to the client. If the client locked the
1248 * whole object, then it has already updated the mtime on its side,
1249 * otherwise it will have to glimpse anyway (see bug 21489, comment 32)
1251 repbody->oa.o_valid &= ~(OBD_MD_FLMTIME | OBD_MD_FLATIME);
1253 if (unlikely(client_cksum != server_cksum && rc == 0 && !mmap)) {
1254 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1259 if (new_cksum == server_cksum)
1260 msg = "changed in transit before arrival at OST";
1261 else if (new_cksum == client_cksum)
1262 msg = "initial checksum before message complete";
1264 msg = "changed in transit AND after initial checksum";
1266 if (req->rq_peer.nid == desc->bd_sender) {
1270 router = libcfs_nid2str(desc->bd_sender);
1273 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1274 "%s%s%s inode "DFID" object "
1275 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1276 exp->exp_obd->obd_name, msg,
1277 libcfs_id2str(req->rq_peer),
1279 body->oa.o_valid & OBD_MD_FLFID ?
1280 body->oa.o_parent_seq : (__u64)0,
1281 body->oa.o_valid & OBD_MD_FLFID ?
1282 body->oa.o_parent_oid : 0,
1283 body->oa.o_valid & OBD_MD_FLFID ?
1284 body->oa.o_parent_ver : 0,
1286 body->oa.o_valid & OBD_MD_FLGROUP ?
1287 body->oa.o_seq : (__u64)0,
1289 local_nb[npages-1].offset +
1290 local_nb[npages-1].len - 1 );
1291 CERROR("client csum %x, original server csum %x, "
1292 "server csum now %x\n",
1293 client_cksum, server_cksum, new_cksum);
1299 /* set per-requested niobuf return codes */
1300 for (i = j = 0; i < niocount; i++) {
1301 int len = remote_nb[i].len;
1306 LASSERT(j < npages);
1307 if (local_nb[j].rc < 0)
1308 rcs[i] = local_nb[j].rc;
1309 len -= local_nb[j].len;
1314 LASSERT(j == npages);
1315 ptlrpc_lprocfs_brw(req, nob);
1319 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1324 ptlrpc_free_bulk(desc);
1327 oti_to_request(oti, req);
1328 target_committed_to_req(req);
1329 rc = ptlrpc_reply(req);
1330 } else if (!no_reply) {
1331 /* Only reply if there was no comms problem with bulk */
1332 target_committed_to_req(req);
1333 req->rq_status = rc;
1336 /* reply out callback would free */
1337 ptlrpc_req_drop_rs(req);
1338 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1339 "client will retry\n",
1340 exp->exp_obd->obd_name,
1341 exp->exp_client_uuid.uuid,
1342 exp->exp_connection->c_remote_uuid.uuid,
1343 libcfs_id2str(req->rq_peer));
1345 cfs_memory_pressure_clr();
1350 * Implementation of OST_SET_INFO.
1352 * OST_SET_INFO is like ioctl(): heavily overloaded. Specifically, it takes a
1353 * "key" and a value RPC buffers as arguments, with the value's contents
1354 * interpreted according to the key.
1356 * Value types that need swabbing have swabbing done explicitly, either here or
1357 * in functions called from here. This should be corrected: all swabbing should
1358 * be done in the capsule abstraction, as that will then allow us to move
1359 * swabbing exclusively to the client without having to modify server code
1360 * outside the capsule abstraction's implementation itself. To correct this
1361 * will require minor changes to the capsule abstraction; see the comments for
1362 * req_capsule_extend() in layout.c.
1364 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1366 struct ost_body *body = NULL, *repbody;
1367 char *key, *val = NULL;
1368 int keylen, vallen, rc = 0;
1369 int is_grant_shrink = 0;
1372 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1374 DEBUG_REQ(D_HA, req, "no set_info key");
1377 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1380 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1383 if ((is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK)))
1384 /* In this case the value is actually an RMF_OST_BODY, so we
1385 * transmutate the type of this PTLRPC */
1386 req_capsule_extend(&req->rq_pill, &RQF_OST_SET_GRANT_INFO);
1388 rc = req_capsule_server_pack(&req->rq_pill);
1393 if (is_grant_shrink) {
1394 body = req_capsule_client_get(&req->rq_pill,
1399 repbody = req_capsule_server_get(&req->rq_pill,
1401 memcpy(repbody, body, sizeof(*body));
1402 val = (char*)repbody;
1404 val = req_capsule_client_get(&req->rq_pill,
1409 if (KEY_IS(KEY_EVICT_BY_NID)) {
1411 obd_export_evict_by_nid(exp->exp_obd, val);
1413 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1414 if (vallen < sizeof(__u32))
1416 __swab32s((__u32 *)val);
1419 /* OBD will also check if KEY_IS(KEY_GRANT_SHRINK), and will cast val to
1420 * a struct ost_body * value */
1421 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1423 lustre_msg_set_status(req->rq_repmsg, 0);
1427 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1430 int keylen, replylen, rc = 0;
1431 struct req_capsule *pill = &req->rq_pill;
1434 /* this common part for get_info rpc */
1435 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1437 DEBUG_REQ(D_HA, req, "no get_info key");
1440 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1442 if (KEY_IS(KEY_FIEMAP)) {
1443 struct ll_fiemap_info_key *fm_key = key;
1446 rc = ost_validate_obdo(exp, &fm_key->oa, NULL);
1451 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1455 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1456 RCL_SERVER, replylen);
1458 rc = req_capsule_server_pack(pill);
1462 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1466 /* call again to fill in the reply buffer */
1467 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1469 lustre_msg_set_status(req->rq_repmsg, 0);
1473 #ifdef HAVE_QUOTA_SUPPORT
1474 static int ost_handle_quotactl(struct ptlrpc_request *req)
1476 struct obd_quotactl *oqctl, *repoqc;
1480 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1482 GOTO(out, rc = -EPROTO);
1484 rc = req_capsule_server_pack(&req->rq_pill);
1488 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1489 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1496 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1498 struct obd_quotactl *oqctl;
1502 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1506 rc = req_capsule_server_pack(&req->rq_pill);
1510 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1514 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1516 struct quota_adjust_qunit *oqaq, *repoqa;
1517 struct lustre_quota_ctxt *qctxt;
1521 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1522 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1524 GOTO(out, rc = -EPROTO);
1526 rc = req_capsule_server_pack(&req->rq_pill);
1530 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1531 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt);
1539 static int ost_llog_handle_connect(struct obd_export *exp,
1540 struct ptlrpc_request *req)
1542 struct llogd_conn_body *body;
1546 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
1547 rc = obd_llog_connect(exp, body);
1551 #define ost_init_sec_none(reply, exp) \
1553 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1554 OBD_CONNECT_RMT_CLIENT_FORCE | \
1555 OBD_CONNECT_OSS_CAPA); \
1556 cfs_spin_lock(&exp->exp_lock); \
1557 exp->exp_connect_flags = reply->ocd_connect_flags; \
1558 cfs_spin_unlock(&exp->exp_lock); \
1561 static int ost_init_sec_level(struct ptlrpc_request *req)
1563 struct obd_export *exp = req->rq_export;
1564 struct req_capsule *pill = &req->rq_pill;
1565 struct obd_device *obd = exp->exp_obd;
1566 struct filter_obd *filter = &obd->u.filter;
1567 char *client = libcfs_nid2str(req->rq_peer.nid);
1568 struct obd_connect_data *data, *reply;
1572 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1573 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1574 if (data == NULL || reply == NULL)
1577 /* connection from MDT is always trusted */
1578 if (req->rq_auth_usr_mdt) {
1579 ost_init_sec_none(reply, exp);
1583 /* no GSS support case */
1584 if (!req->rq_auth_gss) {
1585 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1586 CWARN("client %s -> target %s does not user GSS, "
1587 "can not run under security level %d.\n",
1588 client, obd->obd_name, filter->fo_sec_level);
1591 ost_init_sec_none(reply, exp);
1596 /* old version case */
1597 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1598 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1599 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1600 CWARN("client %s -> target %s uses old version, "
1601 "can not run under security level %d.\n",
1602 client, obd->obd_name, filter->fo_sec_level);
1605 CWARN("client %s -> target %s uses old version, "
1606 "run under security level %d.\n",
1607 client, obd->obd_name, filter->fo_sec_level);
1608 ost_init_sec_none(reply, exp);
1613 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1615 if (!req->rq_auth_remote)
1616 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1617 "asked to be remote.\n", client, obd->obd_name);
1618 } else if (req->rq_auth_remote) {
1620 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1621 "as remote by default.\n", client, obd->obd_name);
1625 if (!filter->fo_fl_oss_capa) {
1626 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1627 " but OSS capabilities are not enabled: %d.\n",
1628 client, obd->obd_name, filter->fo_fl_oss_capa);
1633 switch (filter->fo_sec_level) {
1634 case LUSTRE_SEC_NONE:
1636 ost_init_sec_none(reply, exp);
1639 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1640 "can not run under security level %d.\n",
1641 client, obd->obd_name, filter->fo_sec_level);
1644 case LUSTRE_SEC_REMOTE:
1646 ost_init_sec_none(reply, exp);
1648 case LUSTRE_SEC_ALL:
1650 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1651 OBD_CONNECT_RMT_CLIENT_FORCE);
1652 if (!filter->fo_fl_oss_capa)
1653 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1655 cfs_spin_lock(&exp->exp_lock);
1656 exp->exp_connect_flags = reply->ocd_connect_flags;
1657 cfs_spin_unlock(&exp->exp_lock);
1669 * this should be done in filter_connect()/filter_reconnect(), but
1670 * we can't obtain information like NID, which stored in incoming
1671 * request, thus can't decide what flavor to use. so we do it here.
1673 * This hack should be removed after the OST stack be rewritten, just
1674 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1676 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1678 struct obd_export *exp = req->rq_export;
1679 struct filter_obd *filter = &exp->exp_obd->u.filter;
1680 struct sptlrpc_flavor flvr;
1683 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1684 LUSTRE_ECHO_NAME) == 0)) {
1685 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1689 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1690 cfs_read_lock(&filter->fo_sptlrpc_lock);
1691 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1695 cfs_read_unlock(&filter->fo_sptlrpc_lock);
1697 cfs_spin_lock(&exp->exp_lock);
1699 exp->exp_sp_peer = req->rq_sp_from;
1700 exp->exp_flvr = flvr;
1702 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1703 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1704 CERROR("unauthorized rpc flavor %x from %s, "
1705 "expect %x\n", req->rq_flvr.sf_rpc,
1706 libcfs_nid2str(req->rq_peer.nid),
1707 exp->exp_flvr.sf_rpc);
1711 cfs_spin_unlock(&exp->exp_lock);
1713 if (exp->exp_sp_peer != req->rq_sp_from) {
1714 CERROR("RPC source %s doesn't match %s\n",
1715 sptlrpc_part2name(req->rq_sp_from),
1716 sptlrpc_part2name(exp->exp_sp_peer));
1719 rc = sptlrpc_target_export_check(exp, req);
1726 /* Ensure that data and metadata are synced to the disk when lock is cancelled
1728 int ost_blocking_ast(struct ldlm_lock *lock,
1729 struct ldlm_lock_desc *desc,
1730 void *data, int flag)
1732 __u32 sync_lock_cancel = 0;
1733 __u32 len = sizeof(sync_lock_cancel);
1737 rc = obd_get_info(lock->l_export, sizeof(KEY_SYNC_LOCK_CANCEL),
1738 KEY_SYNC_LOCK_CANCEL, &len, &sync_lock_cancel, NULL);
1740 if (!rc && flag == LDLM_CB_CANCELING &&
1741 (lock->l_granted_mode & (LCK_PW|LCK_GROUP)) &&
1742 (sync_lock_cancel == ALWAYS_SYNC_ON_CANCEL ||
1743 (sync_lock_cancel == BLOCKING_SYNC_ON_CANCEL &&
1744 lock->l_flags & LDLM_FL_CBPENDING))) {
1749 oa->o_id = lock->l_resource->lr_name.name[0];
1750 oa->o_seq = lock->l_resource->lr_name.name[1];
1751 oa->o_valid = OBD_MD_FLID|OBD_MD_FLGROUP;
1753 rc = obd_sync(lock->l_export, oa, NULL,
1754 lock->l_policy_data.l_extent.start,
1755 lock->l_policy_data.l_extent.end, NULL);
1757 CERROR("Error %d syncing data on lock cancel\n", rc);
1762 return ldlm_server_blocking_ast(lock, desc, data, flag);
1765 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1766 struct obd_device *obd, int *process)
1768 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1769 case OST_CONNECT: /* This will never get here, but for completeness. */
1770 case OST_DISCONNECT:
1781 case OBD_LOG_CANCEL:
1783 *process = target_queue_recovery_request(req, obd);
1787 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1793 int ost_msg_check_version(struct lustre_msg *msg)
1797 switch(lustre_msg_get_opc(msg)) {
1799 case OST_DISCONNECT:
1802 case SEC_CTX_INIT_CONT:
1804 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1806 CERROR("bad opc %u version %08x, expecting %08x\n",
1807 lustre_msg_get_opc(msg),
1808 lustre_msg_get_version(msg),
1809 LUSTRE_OBD_VERSION);
1822 #ifdef HAVE_QUOTA_SUPPORT
1823 case OST_QUOTACHECK:
1825 case OST_QUOTA_ADJUST_QUNIT:
1827 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1829 CERROR("bad opc %u version %08x, expecting %08x\n",
1830 lustre_msg_get_opc(msg),
1831 lustre_msg_get_version(msg),
1832 LUSTRE_OST_VERSION);
1837 case LDLM_BL_CALLBACK:
1838 case LDLM_CP_CALLBACK:
1839 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1841 CERROR("bad opc %u version %08x, expecting %08x\n",
1842 lustre_msg_get_opc(msg),
1843 lustre_msg_get_version(msg),
1844 LUSTRE_DLM_VERSION);
1846 case LLOG_ORIGIN_CONNECT:
1847 case OBD_LOG_CANCEL:
1848 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1850 CERROR("bad opc %u version %08x, expecting %08x\n",
1851 lustre_msg_get_opc(msg),
1852 lustre_msg_get_version(msg),
1853 LUSTRE_LOG_VERSION);
1856 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1863 * Returns 1 if the given PTLRPC matches the given LDLM locks, or 0 if it does
1866 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1867 struct ldlm_lock *lock)
1869 struct niobuf_remote *nb;
1870 struct obd_ioobj *ioo;
1871 struct ost_body *body;
1872 int objcount, niocount;
1873 int mode, opc, i, rc;
1877 opc = lustre_msg_get_opc(req->rq_reqmsg);
1878 LASSERT(opc == OST_READ || opc == OST_WRITE);
1880 /* As the request may be covered by several locks, do not look at
1881 * o_handle, look at the RPC IO region. */
1882 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1886 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1887 RCL_CLIENT) / sizeof(*ioo);
1888 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1892 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
1896 for (niocount = i = 0; i < objcount; i++)
1897 niocount += ioo[i].ioo_bufcnt;
1899 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1901 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
1902 RCL_CLIENT) / sizeof(*nb)))
1906 if (opc == OST_READ)
1909 start = nb[0].offset & CFS_PAGE_MASK;
1910 end = (nb[ioo->ioo_bufcnt - 1].offset +
1911 nb[ioo->ioo_bufcnt - 1].len - 1) | ~CFS_PAGE_MASK;
1913 LASSERT(lock->l_resource != NULL);
1914 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_seq,
1915 &lock->l_resource->lr_name))
1918 if (!(lock->l_granted_mode & mode))
1921 if (lock->l_policy_data.l_extent.end < start ||
1922 lock->l_policy_data.l_extent.start > end)
1929 * High-priority queue request check for whether the given PTLRPC request (\a
1930 * req) is blocking an LDLM lock cancel.
1932 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1933 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1935 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1936 * function looks only at OST_READs and OST_WRITEs.
1938 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1940 struct niobuf_remote *nb;
1941 struct obd_ioobj *ioo;
1942 struct ost_body *body;
1943 int objcount, niocount;
1944 int mode, opc, i, rc;
1947 opc = lustre_msg_get_opc(req->rq_reqmsg);
1948 LASSERT(opc == OST_READ || opc == OST_WRITE);
1950 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1954 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1955 RCL_CLIENT) / sizeof(*ioo);
1956 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1960 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
1964 for (niocount = i = 0; i < objcount; i++)
1965 niocount += ioo[i].ioo_bufcnt;
1966 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1968 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
1969 RCL_CLIENT) / sizeof(*nb)))
1971 if (niocount != 0 && (nb[0].flags & OBD_BRW_SRVLOCK))
1975 if (opc == OST_READ)
1977 RETURN(ost_rw_prolong_locks(req, ioo, nb, &body->oa, mode));
1980 static int ost_punch_prolong_locks(struct ptlrpc_request *req, struct obdo *oa)
1982 struct ldlm_res_id res_id = { .name = { oa->o_id } };
1983 struct ost_prolong_data opd = { 0 };
1988 end = start + oa->o_blocks;
1990 opd.opd_mode = LCK_PW;
1991 opd.opd_exp = req->rq_export;
1992 opd.opd_policy.l_extent.start = start & CFS_PAGE_MASK;
1993 if (oa->o_blocks == OBD_OBJECT_EOF || end < start)
1994 opd.opd_policy.l_extent.end = OBD_OBJECT_EOF;
1996 opd.opd_policy.l_extent.end = end | ~CFS_PAGE_MASK;
1998 /* prolong locks for the current service time of the corresponding
1999 * portal (= OST_IO_PORTAL) */
2000 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
2001 max(at_est2timeout(at_get(&req->rq_rqbd->
2002 rqbd_service->srv_at_estimate)), ldlm_timeout);
2004 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
2005 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
2006 opd.opd_policy.l_extent.end);
2009 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
2010 ost_prolong_locks_iter, &opd);
2011 RETURN(opd.opd_lock_match);
2015 * Like ost_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
2017 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
2018 struct ldlm_lock *lock)
2020 struct ost_body *body;
2024 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
2026 RETURN(0); /* can't return -EFAULT here */
2028 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
2032 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
2033 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
2039 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
2041 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
2043 struct ost_body *body;
2046 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
2050 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
2054 LASSERT(!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
2055 !(body->oa.o_flags & OBD_FL_SRVLOCK));
2057 RETURN(ost_punch_prolong_locks(req, &body->oa));
2060 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
2061 .hpreq_lock_match = ost_rw_hpreq_lock_match,
2062 .hpreq_check = ost_rw_hpreq_check,
2065 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
2066 .hpreq_lock_match = ost_punch_hpreq_lock_match,
2067 .hpreq_check = ost_punch_hpreq_check,
2070 /** Assign high priority operations to the request if needed. */
2071 static int ost_hpreq_handler(struct ptlrpc_request *req)
2074 if (req->rq_export) {
2075 int opc = lustre_msg_get_opc(req->rq_reqmsg);
2076 struct ost_body *body;
2078 if (opc == OST_READ || opc == OST_WRITE) {
2079 struct niobuf_remote *nb;
2080 struct obd_ioobj *ioo;
2081 int objcount, niocount;
2084 /* RPCs on the H-P queue can be inspected before
2085 * ost_handler() initializes their pills, so we
2086 * initialize that here. Capsule initialization is
2087 * idempotent, as is setting the pill's format (provided
2088 * it doesn't change).
2090 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2091 if (opc == OST_READ)
2092 req_capsule_set(&req->rq_pill,
2095 req_capsule_set(&req->rq_pill,
2096 &RQF_OST_BRW_WRITE);
2098 body = req_capsule_client_get(&req->rq_pill,
2101 CERROR("Missing/short ost_body\n");
2105 objcount = req_capsule_get_size(&req->rq_pill,
2109 if (objcount == 0) {
2110 CERROR("Missing/short ioobj\n");
2114 CERROR("too many ioobjs (%d)\n", objcount);
2118 ioo = req_capsule_client_get(&req->rq_pill,
2121 CERROR("Missing/short ioobj\n");
2125 for (niocount = i = 0; i < objcount; i++) {
2126 if (ioo[i].ioo_bufcnt == 0) {
2127 CERROR("ioo[%d] has zero bufcnt\n", i);
2130 niocount += ioo[i].ioo_bufcnt;
2132 if (niocount > PTLRPC_MAX_BRW_PAGES) {
2133 DEBUG_REQ(D_RPCTRACE, req,
2134 "bulk has too many pages (%d)",
2139 nb = req_capsule_client_get(&req->rq_pill,
2140 &RMF_NIOBUF_REMOTE);
2142 CERROR("Missing/short niobuf\n");
2146 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
2147 req->rq_ops = &ost_hpreq_rw;
2148 } else if (opc == OST_PUNCH) {
2149 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2150 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2152 body = req_capsule_client_get(&req->rq_pill,
2155 CERROR("Missing/short ost_body\n");
2159 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
2160 !(body->oa.o_flags & OBD_FL_SRVLOCK))
2161 req->rq_ops = &ost_hpreq_punch;
2167 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
2168 int ost_handle(struct ptlrpc_request *req)
2170 struct obd_trans_info trans_info = { 0, };
2171 struct obd_trans_info *oti = &trans_info;
2172 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
2173 struct obd_device *obd = NULL;
2176 LASSERT(current->journal_info == NULL);
2178 /* primordial rpcs don't affect server recovery */
2179 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2181 case SEC_CTX_INIT_CONT:
2186 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2188 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
2189 if (!class_connected_export(req->rq_export)) {
2190 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
2191 lustre_msg_get_opc(req->rq_reqmsg),
2192 libcfs_id2str(req->rq_peer));
2193 req->rq_status = -ENOTCONN;
2194 GOTO(out, rc = -ENOTCONN);
2197 obd = req->rq_export->exp_obd;
2199 /* Check for aborted recovery. */
2200 if (obd->obd_recovering) {
2201 rc = ost_filter_recovery_request(req, obd,
2203 if (rc || !should_process)
2205 else if (should_process < 0) {
2206 req->rq_status = should_process;
2207 rc = ptlrpc_error(req);
2215 rc = ost_msg_check_version(req->rq_reqmsg);
2219 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2221 CDEBUG(D_INODE, "connect\n");
2222 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
2223 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
2225 rc = target_handle_connect(req);
2226 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
2229 rc = ost_init_sec_level(req);
2231 rc = ost_connect_check_sptlrpc(req);
2235 case OST_DISCONNECT:
2236 CDEBUG(D_INODE, "disconnect\n");
2237 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
2238 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
2240 rc = target_handle_disconnect(req);
2243 CDEBUG(D_INODE, "create\n");
2244 req_capsule_set(&req->rq_pill, &RQF_OST_CREATE);
2245 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
2247 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2248 GOTO(out, rc = -EROFS);
2249 rc = ost_create(req->rq_export, req, oti);
2252 CDEBUG(D_INODE, "destroy\n");
2253 req_capsule_set(&req->rq_pill, &RQF_OST_DESTROY);
2254 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
2256 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2257 GOTO(out, rc = -EROFS);
2258 rc = ost_destroy(req->rq_export, req, oti);
2261 CDEBUG(D_INODE, "getattr\n");
2262 req_capsule_set(&req->rq_pill, &RQF_OST_GETATTR);
2263 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
2265 rc = ost_getattr(req->rq_export, req);
2268 CDEBUG(D_INODE, "setattr\n");
2269 req_capsule_set(&req->rq_pill, &RQF_OST_SETATTR);
2270 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
2272 rc = ost_setattr(req->rq_export, req, oti);
2275 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_WRITE);
2276 CDEBUG(D_INODE, "write\n");
2277 /* req->rq_request_portal would be nice, if it was set */
2278 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2279 CERROR("%s: deny write request from %s to portal %u\n",
2280 req->rq_export->exp_obd->obd_name,
2281 obd_export_nid2str(req->rq_export),
2282 req->rq_rqbd->rqbd_service->srv_req_portal);
2283 GOTO(out, rc = -EPROTO);
2285 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2287 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
2288 GOTO(out, rc = -ENOSPC);
2289 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2290 GOTO(out, rc = -EROFS);
2291 rc = ost_brw_write(req, oti);
2292 LASSERT(current->journal_info == NULL);
2293 /* ost_brw_write sends its own replies */
2296 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_READ);
2297 CDEBUG(D_INODE, "read\n");
2298 /* req->rq_request_portal would be nice, if it was set */
2299 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2300 CERROR("%s: deny read request from %s to portal %u\n",
2301 req->rq_export->exp_obd->obd_name,
2302 obd_export_nid2str(req->rq_export),
2303 req->rq_rqbd->rqbd_service->srv_req_portal);
2304 GOTO(out, rc = -EPROTO);
2306 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2308 rc = ost_brw_read(req, oti);
2309 LASSERT(current->journal_info == NULL);
2310 /* ost_brw_read sends its own replies */
2313 CDEBUG(D_INODE, "punch\n");
2314 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2315 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2317 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2318 GOTO(out, rc = -EROFS);
2319 rc = ost_punch(req->rq_export, req, oti);
2322 CDEBUG(D_INODE, "statfs\n");
2323 req_capsule_set(&req->rq_pill, &RQF_OST_STATFS);
2324 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2326 rc = ost_statfs(req);
2329 CDEBUG(D_INODE, "sync\n");
2330 req_capsule_set(&req->rq_pill, &RQF_OST_SYNC);
2331 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2333 rc = ost_sync(req->rq_export, req);
2336 DEBUG_REQ(D_INODE, req, "set_info");
2337 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
2338 rc = ost_set_info(req->rq_export, req);
2341 DEBUG_REQ(D_INODE, req, "get_info");
2342 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
2343 rc = ost_get_info(req->rq_export, req);
2345 #ifdef HAVE_QUOTA_SUPPORT
2346 case OST_QUOTACHECK:
2347 CDEBUG(D_INODE, "quotacheck\n");
2348 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2349 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2351 rc = ost_handle_quotacheck(req);
2354 CDEBUG(D_INODE, "quotactl\n");
2355 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2356 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2358 rc = ost_handle_quotactl(req);
2360 case OST_QUOTA_ADJUST_QUNIT:
2361 CDEBUG(D_INODE, "quota_adjust_qunit\n");
2362 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
2363 rc = ost_handle_quota_adjust_qunit(req);
2367 DEBUG_REQ(D_INODE, req, "ping");
2368 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2369 rc = target_handle_ping(req);
2371 /* FIXME - just reply status */
2372 case LLOG_ORIGIN_CONNECT:
2373 DEBUG_REQ(D_INODE, req, "log connect");
2374 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2375 rc = ost_llog_handle_connect(req->rq_export, req);
2376 req->rq_status = rc;
2377 rc = req_capsule_server_pack(&req->rq_pill);
2380 RETURN(ptlrpc_reply(req));
2381 case OBD_LOG_CANCEL:
2382 CDEBUG(D_INODE, "log cancel\n");
2383 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2384 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2386 rc = llog_origin_handle_cancel(req);
2387 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2389 req->rq_status = rc;
2390 rc = req_capsule_server_pack(&req->rq_pill);
2393 RETURN(ptlrpc_reply(req));
2395 CDEBUG(D_INODE, "enqueue\n");
2396 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2397 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2399 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2401 ldlm_server_glimpse_ast);
2402 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2405 CDEBUG(D_INODE, "convert\n");
2406 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2407 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2409 rc = ldlm_handle_convert(req);
2412 CDEBUG(D_INODE, "cancel\n");
2413 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2414 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2416 rc = ldlm_handle_cancel(req);
2418 case LDLM_BL_CALLBACK:
2419 case LDLM_CP_CALLBACK:
2420 CDEBUG(D_INODE, "callback\n");
2421 CERROR("callbacks should not happen on OST\n");
2424 CERROR("Unexpected opcode %d\n",
2425 lustre_msg_get_opc(req->rq_reqmsg));
2426 req->rq_status = -ENOTSUPP;
2427 rc = ptlrpc_error(req);
2431 LASSERT(current->journal_info == NULL);
2434 /* If we're DISCONNECTing, the export_data is already freed */
2435 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2436 target_committed_to_req(req);
2440 oti_to_request(oti, req);
2442 target_send_reply(req, rc, fail);
2445 EXPORT_SYMBOL(ost_handle);
2447 * free per-thread pool created by ost_thread_init().
2449 static void ost_thread_done(struct ptlrpc_thread *thread)
2451 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2456 LASSERT(thread != NULL);
2459 * be prepared to handle partially-initialized pools (because this is
2460 * called from ost_thread_init() for cleanup.
2462 tls = thread->t_data;
2465 thread->t_data = NULL;
2471 * initialize per-thread page pool (bug 5137).
2473 static int ost_thread_init(struct ptlrpc_thread *thread)
2475 struct ost_thread_local_cache *tls;
2479 LASSERT(thread != NULL);
2480 LASSERT(thread->t_data == NULL);
2481 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
2486 thread->t_data = tls;
2490 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2492 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2493 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2495 struct ost_obd *ost = &obd->u.ost;
2496 struct lprocfs_static_vars lvars;
2497 int oss_min_threads;
2498 int oss_max_threads;
2499 int oss_min_create_threads;
2500 int oss_max_create_threads;
2504 rc = cfs_cleanup_group_info();
2508 lprocfs_ost_init_vars(&lvars);
2509 lprocfs_obd_setup(obd, lvars.obd_vars);
2511 cfs_sema_init(&ost->ost_health_sem, 1);
2513 if (oss_num_threads) {
2514 /* If oss_num_threads is set, it is the min and the max. */
2515 if (oss_num_threads > OSS_THREADS_MAX)
2516 oss_num_threads = OSS_THREADS_MAX;
2517 if (oss_num_threads < OSS_THREADS_MIN)
2518 oss_num_threads = OSS_THREADS_MIN;
2519 oss_max_threads = oss_min_threads = oss_num_threads;
2521 /* Base min threads on memory and cpus */
2523 cfs_num_possible_cpus() * CFS_NUM_CACHEPAGES >>
2524 (27 - CFS_PAGE_SHIFT);
2525 if (oss_min_threads < OSS_THREADS_MIN)
2526 oss_min_threads = OSS_THREADS_MIN;
2527 /* Insure a 4x range for dynamic threads */
2528 if (oss_min_threads > OSS_THREADS_MAX / 4)
2529 oss_min_threads = OSS_THREADS_MAX / 4;
2530 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
2534 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2535 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
2536 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2537 ost_handle, LUSTRE_OSS_NAME,
2538 obd->obd_proc_entry, target_print_req,
2539 oss_min_threads, oss_max_threads,
2540 "ll_ost", LCT_DT_THREAD, NULL);
2541 if (ost->ost_service == NULL) {
2542 CERROR("failed to start service\n");
2543 GOTO(out_lprocfs, rc = -ENOMEM);
2546 rc = ptlrpc_start_threads(obd, ost->ost_service);
2548 GOTO(out_service, rc = -EINVAL);
2550 if (oss_num_create_threads) {
2551 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
2552 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
2553 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
2554 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
2555 oss_min_create_threads = oss_max_create_threads =
2556 oss_num_create_threads;
2558 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
2559 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
2562 ost->ost_create_service =
2563 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2564 OST_MAXREPSIZE, OST_CREATE_PORTAL,
2565 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2566 ost_handle, "ost_create",
2567 obd->obd_proc_entry, target_print_req,
2568 oss_min_create_threads, oss_max_create_threads,
2569 "ll_ost_creat", LCT_DT_THREAD, NULL);
2570 if (ost->ost_create_service == NULL) {
2571 CERROR("failed to start OST create service\n");
2572 GOTO(out_service, rc = -ENOMEM);
2575 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
2577 GOTO(out_create, rc = -EINVAL);
2579 ost->ost_io_service =
2580 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2581 OST_MAXREPSIZE, OST_IO_PORTAL,
2582 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2583 ost_handle, "ost_io",
2584 obd->obd_proc_entry, target_print_req,
2585 oss_min_threads, oss_max_threads,
2586 "ll_ost_io", LCT_DT_THREAD, ost_hpreq_handler);
2587 if (ost->ost_io_service == NULL) {
2588 CERROR("failed to start OST I/O service\n");
2589 GOTO(out_create, rc = -ENOMEM);
2592 ost->ost_io_service->srv_init = ost_thread_init;
2593 ost->ost_io_service->srv_done = ost_thread_done;
2594 ost->ost_io_service->srv_cpu_affinity = 1;
2595 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
2597 GOTO(out_io, rc = -EINVAL);
2599 ping_evictor_start();
2604 ptlrpc_unregister_service(ost->ost_io_service);
2605 ost->ost_io_service = NULL;
2607 ptlrpc_unregister_service(ost->ost_create_service);
2608 ost->ost_create_service = NULL;
2610 ptlrpc_unregister_service(ost->ost_service);
2611 ost->ost_service = NULL;
2613 lprocfs_obd_cleanup(obd);
2617 static int ost_cleanup(struct obd_device *obd)
2619 struct ost_obd *ost = &obd->u.ost;
2623 ping_evictor_stop();
2625 cfs_spin_lock_bh(&obd->obd_processing_task_lock);
2626 if (obd->obd_recovering) {
2627 target_cancel_recovery_timer(obd);
2628 obd->obd_recovering = 0;
2630 cfs_spin_unlock_bh(&obd->obd_processing_task_lock);
2632 cfs_down(&ost->ost_health_sem);
2633 ptlrpc_unregister_service(ost->ost_service);
2634 ptlrpc_unregister_service(ost->ost_create_service);
2635 ptlrpc_unregister_service(ost->ost_io_service);
2636 ost->ost_service = NULL;
2637 ost->ost_create_service = NULL;
2638 cfs_up(&ost->ost_health_sem);
2640 lprocfs_obd_cleanup(obd);
2645 static int ost_health_check(struct obd_device *obd)
2647 struct ost_obd *ost = &obd->u.ost;
2650 cfs_down(&ost->ost_health_sem);
2651 rc |= ptlrpc_service_health_check(ost->ost_service);
2652 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2653 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2654 cfs_up(&ost->ost_health_sem);
2657 * health_check to return 0 on healthy
2658 * and 1 on unhealthy.
2666 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2668 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2671 /* use obd ops to offer management infrastructure */
2672 static struct obd_ops ost_obd_ops = {
2673 .o_owner = THIS_MODULE,
2674 .o_setup = ost_setup,
2675 .o_cleanup = ost_cleanup,
2676 .o_health_check = ost_health_check,
2680 static int __init ost_init(void)
2682 struct lprocfs_static_vars lvars;
2686 lprocfs_ost_init_vars(&lvars);
2687 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2688 LUSTRE_OSS_NAME, NULL);
2690 if (ost_num_threads != 0 && oss_num_threads == 0) {
2691 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2692 "use oss_num_threads instead or unset both for "
2693 "dynamic thread startup\n");
2694 oss_num_threads = ost_num_threads;
2700 static void /*__exit*/ ost_exit(void)
2702 class_unregister_type(LUSTRE_OSS_NAME);
2705 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2706 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2707 MODULE_LICENSE("GPL");
2709 module_init(ost_init);
2710 module_exit(ost_exit);