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_current_64() - CFS_HZ, 0);
307 if (req->rq_status != 0)
308 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
313 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
314 struct obd_trans_info *oti)
316 struct ost_body *body, *repbody;
320 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
324 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
328 rc = req_capsule_server_pack(&req->rq_pill);
332 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
333 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
334 oti->oti_logcookies = &repbody->oa.o_lcookie;
336 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
337 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
341 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
342 struct obd_trans_info *oti)
344 struct obd_info oinfo = { { { 0 } } };
345 struct ost_body *body, *repbody;
347 struct lustre_handle lh = {0,};
350 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
351 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
353 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
357 rc = ost_validate_obdo(exp, &body->oa, NULL);
361 oinfo.oi_oa = &body->oa;
362 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
363 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
365 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
366 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
369 rc = req_capsule_server_pack(&req->rq_pill);
373 /* standard truncate optimization: if file body is completely
374 * destroyed, don't send data back to the server. */
375 if (oinfo.oi_oa->o_size == 0)
376 flags |= LDLM_AST_DISCARD_DATA;
378 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
379 rc = ost_lock_get(exp, oinfo.oi_oa, oinfo.oi_oa->o_size,
380 oinfo.oi_oa->o_blocks, &lh, LCK_PW, flags);
382 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
383 oinfo.oi_oa->o_flags == OBD_FL_SRVLOCK)
385 * If OBD_FL_SRVLOCK is the only bit set in
386 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
387 * through filter_setattr() to filter_iocontrol().
389 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
391 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA) {
392 oinfo.oi_capa = req_capsule_client_get(&req->rq_pill,
394 if (oinfo.oi_capa == NULL) {
395 CERROR("Missing capability for OST PUNCH");
399 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
400 ost_lock_put(exp, &lh, LCK_PW);
402 repbody->oa = *oinfo.oi_oa;
403 ost_drop_id(exp, &repbody->oa);
407 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
409 struct ost_body *body, *repbody;
410 struct lustre_capa *capa = NULL;
414 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
418 rc = ost_validate_obdo(exp, &body->oa, NULL);
422 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
423 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
425 CERROR("Missing capability for OST SYNC");
430 rc = req_capsule_server_pack(&req->rq_pill);
434 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
435 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
436 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
437 repbody->oa.o_blocks, capa);
438 ost_drop_id(exp, &repbody->oa);
442 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
443 struct obd_trans_info *oti)
445 struct ost_body *body, *repbody;
447 struct obd_info oinfo = { { { 0 } } };
450 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
454 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
458 rc = req_capsule_server_pack(&req->rq_pill);
462 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
463 repbody->oa = body->oa;
465 oinfo.oi_oa = &repbody->oa;
466 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA) {
467 oinfo.oi_capa = req_capsule_client_get(&req->rq_pill,
469 if (oinfo.oi_capa == NULL) {
470 CERROR("Missing capability for OST SETATTR");
474 req->rq_status = obd_setattr(exp, &oinfo, oti);
475 ost_drop_id(exp, &repbody->oa);
479 static int ost_bulk_timeout(void *data)
482 /* We don't fail the connection here, because having the export
483 * killed makes the (vital) call to commitrw very sad.
488 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
489 cksum_type_t cksum_type)
494 cksum = init_checksum(cksum_type);
495 for (i = 0; i < desc->bd_iov_count; i++) {
496 struct page *page = desc->bd_iov[i].kiov_page;
497 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
498 char *ptr = kmap(page) + off;
499 int len = desc->bd_iov[i].kiov_len;
501 /* corrupt the data before we compute the checksum, to
502 * simulate a client->OST data error */
503 if (i == 0 && opc == OST_WRITE &&
504 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
505 memcpy(ptr, "bad3", min(4, len));
506 cksum = compute_checksum(cksum, ptr, len, cksum_type);
507 /* corrupt the data after we compute the checksum, to
508 * simulate an OST->client data error */
509 if (i == 0 && opc == OST_READ &&
510 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
511 memcpy(ptr, "bad4", min(4, len));
512 /* nobody should use corrupted page again */
513 ClearPageUptodate(page);
521 static int ost_brw_lock_get(int mode, struct obd_export *exp,
522 struct obd_ioobj *obj, struct niobuf_remote *nb,
523 struct lustre_handle *lh)
526 int nrbufs = obj->ioo_bufcnt;
527 struct ldlm_res_id res_id;
528 ldlm_policy_data_t policy;
532 osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id);
533 LASSERT(mode == LCK_PR || mode == LCK_PW);
534 LASSERT(!lustre_handle_is_used(lh));
536 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
539 for (i = 1; i < nrbufs; i ++)
540 if ((nb[0].flags & OBD_BRW_SRVLOCK) !=
541 (nb[i].flags & OBD_BRW_SRVLOCK))
544 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
545 policy.l_extent.end = (nb[nrbufs - 1].offset +
546 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
548 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
549 LDLM_EXTENT, &policy, mode, &flags,
550 ldlm_blocking_ast, ldlm_completion_ast,
551 ldlm_glimpse_ast, NULL, 0, NULL, lh));
554 static void ost_brw_lock_put(int mode,
555 struct obd_ioobj *obj, struct niobuf_remote *niob,
556 struct lustre_handle *lh)
559 LASSERT(mode == LCK_PR || mode == LCK_PW);
560 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
561 lustre_handle_is_used(lh));
562 if (lustre_handle_is_used(lh))
563 ldlm_lock_decref(lh, mode);
567 struct ost_prolong_data {
568 struct obd_export *opd_exp;
569 ldlm_policy_data_t opd_policy;
571 ldlm_mode_t opd_mode;
576 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
578 struct ost_prolong_data *opd = data;
580 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
582 if (lock->l_req_mode != lock->l_granted_mode) {
583 /* scan granted locks only */
584 return LDLM_ITER_STOP;
587 if (lock->l_export != opd->opd_exp) {
588 /* prolong locks only for given client */
589 return LDLM_ITER_CONTINUE;
592 if (!(lock->l_granted_mode & opd->opd_mode)) {
593 /* we aren't interesting in all type of locks */
594 return LDLM_ITER_CONTINUE;
597 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
598 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
599 /* the request doesn't cross the lock, skip it */
600 return LDLM_ITER_CONTINUE;
603 /* Fill the obdo with the matched lock handle.
604 * XXX: it is possible in some cases the IO RPC is covered by several
605 * locks, even for the write case, so it may need to be a lock list. */
606 if (opd->opd_oa && !(opd->opd_oa->o_valid & OBD_MD_FLHANDLE)) {
607 opd->opd_oa->o_handle.cookie = lock->l_handle.h_cookie;
608 opd->opd_oa->o_valid |= OBD_MD_FLHANDLE;
611 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
612 /* ignore locks not being cancelled */
613 return LDLM_ITER_CONTINUE;
616 CDEBUG(D_DLMTRACE,"refresh lock: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
617 lock->l_resource->lr_name.name[0],
618 lock->l_resource->lr_name.name[1],
619 opd->opd_policy.l_extent.start, opd->opd_policy.l_extent.end);
620 /* OK. this is a possible lock the user holds doing I/O
621 * let's refresh eviction timer for it */
622 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
623 opd->opd_lock_match = 1;
625 return LDLM_ITER_CONTINUE;
628 static int ost_rw_prolong_locks(struct ptlrpc_request *req, struct obd_ioobj *obj,
629 struct niobuf_remote *nb, struct obdo *oa,
632 struct ldlm_res_id res_id;
633 int nrbufs = obj->ioo_bufcnt;
634 struct ost_prolong_data opd = { 0 };
637 osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id);
640 opd.opd_exp = req->rq_export;
641 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
642 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
643 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
645 /* prolong locks for the current service time of the corresponding
646 * portal (= OST_IO_PORTAL) */
647 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
648 max(at_est2timeout(at_get(&req->rq_rqbd->
649 rqbd_service->srv_at_estimate)), ldlm_timeout);
651 CDEBUG(D_INFO,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
652 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
653 opd.opd_policy.l_extent.end);
655 if (oa->o_valid & OBD_MD_FLHANDLE) {
656 struct ldlm_lock *lock;
658 lock = ldlm_handle2lock(&oa->o_handle);
660 ost_prolong_locks_iter(lock, &opd);
661 if (opd.opd_lock_match) {
666 /* Check if the lock covers the whole IO region,
667 * otherwise iterate through the resource. */
668 if (lock->l_policy_data.l_extent.end >=
669 opd.opd_policy.l_extent.end &&
670 lock->l_policy_data.l_extent.start <=
671 opd.opd_policy.l_extent.start) {
680 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
681 ost_prolong_locks_iter, &opd);
682 RETURN(opd.opd_lock_match);
685 /* Allocate thread local buffers if needed */
686 static struct ost_thread_local_cache *ost_tls_get(struct ptlrpc_request *r)
688 struct ost_thread_local_cache *tls =
689 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
691 /* In normal mode of operation an I/O request is serviced only
692 * by ll_ost_io threads each of them has own tls buffers allocated by
694 * During recovery, an I/O request may be queued until any of the ost
695 * service threads process it. Not necessary it should be one of
696 * ll_ost_io threads. In that case we dynamically allocating tls
697 * buffers for the request service time. */
698 if (unlikely(tls == NULL)) {
699 LASSERT(r->rq_export->exp_in_recovery);
703 r->rq_svc_thread->t_data = tls;
709 /* Free thread local buffers if they were allocated only for servicing
710 * this one request */
711 static void ost_tls_put(struct ptlrpc_request *r)
713 struct ost_thread_local_cache *tls =
714 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
716 if (unlikely(tls->temporary)) {
718 r->rq_svc_thread->t_data = NULL;
722 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
724 struct ptlrpc_bulk_desc *desc = NULL;
725 struct obd_export *exp = req->rq_export;
726 struct niobuf_remote *remote_nb;
727 struct niobuf_local *local_nb;
728 struct obd_ioobj *ioo;
729 struct ost_body *body, *repbody;
730 struct lustre_capa *capa = NULL;
731 struct l_wait_info lwi;
732 struct lustre_handle lockh = { 0 };
733 int niocount, npages, nob = 0, rc, i;
735 struct ost_thread_local_cache *tls;
738 req->rq_bulk_read = 1;
740 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
741 GOTO(out, rc = -EIO);
743 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
745 /* Check if there is eviction in progress, and if so, wait for it to
747 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
748 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
749 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
750 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
754 GOTO(out, rc = -ENOTCONN);
756 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
757 * ost_rw_hpreq_check(). */
758 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
760 GOTO(out, rc = -EFAULT);
763 * A req_capsule_X_get_array(pill, field, ptr_to_element_count) function
764 * would be useful here and wherever we get &RMF_OBD_IOOBJ and
765 * &RMF_NIOBUF_REMOTE.
767 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
769 GOTO(out, rc = -EFAULT);
771 rc = ost_validate_obdo(exp, &body->oa, ioo);
775 niocount = ioo->ioo_bufcnt;
776 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
777 if (remote_nb == NULL)
778 GOTO(out, rc = -EFAULT);
780 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
781 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
783 CERROR("Missing capability for OST BRW READ");
784 GOTO(out, rc = -EFAULT);
788 rc = req_capsule_server_pack(&req->rq_pill);
792 tls = ost_tls_get(req);
794 GOTO(out_bulk, rc = -ENOMEM);
795 local_nb = tls->local;
797 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
802 * If getting the lock took more time than
803 * client was willing to wait, drop it. b=11330
805 if (cfs_time_current_sec() > req->rq_deadline ||
806 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
808 CERROR("Dropping timed-out read from %s because locking"
809 "object "LPX64" took %ld seconds (limit was %ld).\n",
810 libcfs_id2str(req->rq_peer), ioo->ioo_id,
811 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
812 req->rq_deadline - req->rq_arrival_time.tv_sec);
813 GOTO(out_lock, rc = -ETIMEDOUT);
816 npages = OST_THREAD_POOL_SIZE;
817 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
818 remote_nb, &npages, local_nb, oti, capa);
822 desc = ptlrpc_prep_bulk_exp(req, npages,
823 BULK_PUT_SOURCE, OST_BULK_PORTAL);
825 GOTO(out_lock, rc = -ENOMEM);
827 if (!lustre_handle_is_used(&lockh))
828 /* no needs to try to prolong lock if server is asked
829 * to handle locking (= OBD_BRW_SRVLOCK) */
830 ost_rw_prolong_locks(req, ioo, remote_nb, &body->oa,
834 for (i = 0; i < npages; i++) {
835 int page_rc = local_nb[i].rc;
837 if (page_rc < 0) { /* error */
843 if (page_rc != 0) { /* some data! */
844 LASSERT (local_nb[i].page != NULL);
845 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
846 local_nb[i].offset & ~CFS_PAGE_MASK,
850 if (page_rc != local_nb[i].len) { /* short read */
851 /* All subsequent pages should be 0 */
853 LASSERT(local_nb[i].rc == 0);
858 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
859 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
861 if (body->oa.o_valid & OBD_MD_FLFLAGS)
862 cksum_type = cksum_type_unpack(body->oa.o_flags);
863 body->oa.o_flags = cksum_type_pack(cksum_type);
864 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
865 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
866 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
868 body->oa.o_valid = 0;
870 /* We're finishing using body->oa as an input variable */
872 /* Check if client was evicted while we were doing i/o before touching
875 /* Check if there is eviction in progress, and if so, wait for
877 if (unlikely(cfs_atomic_read(&exp->exp_obd->
878 obd_evict_inprogress))) {
879 lwi = LWI_INTR(NULL, NULL);
880 rc = l_wait_event(exp->exp_obd->
881 obd_evict_inprogress_waitq,
882 !cfs_atomic_read(&exp->exp_obd->
883 obd_evict_inprogress),
886 /* Check if client was evicted or tried to reconnect already */
887 if (exp->exp_failed || exp->exp_abort_active_req)
890 rc = sptlrpc_svc_wrap_bulk(req, desc);
892 rc = ptlrpc_start_bulk_transfer(desc);
896 time_t start = cfs_time_current_sec();
898 long timeoutl = req->rq_deadline -
899 cfs_time_current_sec();
900 cfs_duration_t timeout = timeoutl <= 0 ?
901 CFS_TICK : cfs_time_seconds(timeoutl);
902 lwi = LWI_TIMEOUT_INTERVAL(timeout,
906 rc = l_wait_event(desc->bd_waitq,
907 !ptlrpc_server_bulk_active(desc) ||
909 exp->exp_abort_active_req,
911 LASSERT(rc == 0 || rc == -ETIMEDOUT);
912 /* Wait again if we changed deadline */
913 } while ((rc == -ETIMEDOUT) &&
914 (req->rq_deadline > cfs_time_current_sec()));
916 if (rc == -ETIMEDOUT) {
917 DEBUG_REQ(D_ERROR, req,
918 "timeout on bulk PUT after %ld%+lds",
919 req->rq_deadline - start,
920 cfs_time_current_sec() -
922 ptlrpc_abort_bulk(desc);
923 } else if (exp->exp_failed) {
924 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
926 ptlrpc_abort_bulk(desc);
927 } else if (exp->exp_abort_active_req) {
928 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk PUT");
929 /* we don't reply anyway */
931 ptlrpc_abort_bulk(desc);
932 } else if (!desc->bd_success ||
933 desc->bd_nob_transferred != desc->bd_nob) {
934 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
936 "truncated" : "network error on",
937 desc->bd_nob_transferred,
939 /* XXX should this be a different errno? */
943 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
948 /* Must commit after prep above in all cases */
949 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
950 remote_nb, npages, local_nb, oti, rc);
953 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
954 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
955 ost_drop_id(exp, &repbody->oa);
959 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
964 ptlrpc_free_bulk(desc);
968 req->rq_status = nob;
969 ptlrpc_lprocfs_brw(req, nob);
970 target_committed_to_req(req);
972 } else if (!no_reply) {
973 /* Only reply if there was no comms problem with bulk */
974 target_committed_to_req(req);
978 /* reply out callback would free */
979 ptlrpc_req_drop_rs(req);
980 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
981 "client will retry\n",
982 exp->exp_obd->obd_name,
983 exp->exp_client_uuid.uuid,
984 exp->exp_connection->c_remote_uuid.uuid,
985 libcfs_id2str(req->rq_peer));
991 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
993 struct ptlrpc_bulk_desc *desc = NULL;
994 struct obd_export *exp = req->rq_export;
995 struct niobuf_remote *remote_nb;
996 struct niobuf_local *local_nb;
997 struct obd_ioobj *ioo;
998 struct ost_body *body, *repbody;
999 struct l_wait_info lwi;
1000 struct lustre_handle lockh = {0};
1001 struct lustre_capa *capa = NULL;
1003 int objcount, niocount, npages;
1005 obd_count client_cksum = 0, server_cksum = 0;
1006 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
1008 __u32 o_uid = 0, o_gid = 0;
1009 struct ost_thread_local_cache *tls;
1012 req->rq_bulk_write = 1;
1014 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
1015 GOTO(out, rc = -EIO);
1016 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
1017 GOTO(out, rc = -EFAULT);
1019 /* pause before transaction has been started */
1020 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
1022 /* Check if there is eviction in progress, and if so, wait for it to
1024 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
1025 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
1026 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
1027 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
1030 if (exp->exp_failed)
1031 GOTO(out, rc = -ENOTCONN);
1033 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
1034 * ost_rw_hpreq_check(). */
1035 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1037 GOTO(out, rc = -EFAULT);
1039 if ((body->oa.o_flags & OBD_BRW_MEMALLOC) &&
1040 (exp->exp_connection->c_peer.nid == exp->exp_connection->c_self))
1041 libcfs_memory_pressure_set();
1043 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1044 RCL_CLIENT) / sizeof(*ioo);
1045 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1047 GOTO(out, rc = -EFAULT);
1049 rc = ost_validate_obdo(exp, &body->oa, ioo);
1053 for (niocount = i = 0; i < objcount; i++)
1054 niocount += ioo[i].ioo_bufcnt;
1057 * It'd be nice to have a capsule function to indicate how many elements
1058 * there were in a buffer for an RMF that's declared to be an array.
1059 * It's easy enough to compute the number of elements here though.
1061 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1062 if (remote_nb == NULL || niocount != (req_capsule_get_size(&req->rq_pill,
1063 &RMF_NIOBUF_REMOTE, RCL_CLIENT) / sizeof(*remote_nb)))
1064 GOTO(out, rc = -EFAULT);
1066 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
1067 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
1069 CERROR("Missing capability for OST BRW WRITE");
1070 GOTO(out, rc = -EFAULT);
1074 req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER,
1075 niocount * sizeof(*rcs));
1076 rc = req_capsule_server_pack(&req->rq_pill);
1079 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, obd_fail_val);
1080 rcs = req_capsule_server_get(&req->rq_pill, &RMF_RCS);
1082 tls = ost_tls_get(req);
1084 GOTO(out_bulk, rc = -ENOMEM);
1085 local_nb = tls->local;
1087 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
1092 * If getting the lock took more time than
1093 * client was willing to wait, drop it. b=11330
1095 if (cfs_time_current_sec() > req->rq_deadline ||
1096 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
1098 CERROR("Dropping timed-out write from %s because locking "
1099 "object "LPX64" took %ld seconds (limit was %ld).\n",
1100 libcfs_id2str(req->rq_peer), ioo->ioo_id,
1101 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
1102 req->rq_deadline - req->rq_arrival_time.tv_sec);
1103 GOTO(out_lock, rc = -ETIMEDOUT);
1106 if (!lustre_handle_is_used(&lockh))
1107 /* no needs to try to prolong lock if server is asked
1108 * to handle locking (= OBD_BRW_SRVLOCK) */
1109 ost_rw_prolong_locks(req, ioo, remote_nb,&body->oa, LCK_PW);
1111 /* obd_preprw clobbers oa->valid, so save what we need */
1112 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
1113 client_cksum = body->oa.o_cksum;
1114 if (body->oa.o_valid & OBD_MD_FLFLAGS)
1115 cksum_type = cksum_type_unpack(body->oa.o_flags);
1118 /* Because we already sync grant info with client when reconnect,
1119 * grant info will be cleared for resent req, then fed_grant and
1120 * total_grant will not be modified in following preprw_write */
1121 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1122 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1123 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1126 if (exp_connect_rmtclient(exp)) {
1127 o_uid = body->oa.o_uid;
1128 o_gid = body->oa.o_gid;
1130 npages = OST_THREAD_POOL_SIZE;
1131 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
1132 ioo, remote_nb, &npages, local_nb, oti, capa);
1136 desc = ptlrpc_prep_bulk_exp(req, npages,
1137 BULK_GET_SINK, OST_BULK_PORTAL);
1139 GOTO(out_lock, rc = -ENOMEM);
1141 /* NB Having prepped, we must commit... */
1143 for (i = 0; i < npages; i++)
1144 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1145 local_nb[i].offset & ~CFS_PAGE_MASK,
1148 rc = sptlrpc_svc_prep_bulk(req, desc);
1152 /* Check if client was evicted or tried to reconnect while we
1153 * were doing i/o before touching network */
1154 if (desc->bd_export->exp_failed ||
1155 desc->bd_export->exp_abort_active_req)
1158 rc = ptlrpc_start_bulk_transfer(desc);
1160 time_t start = cfs_time_current_sec();
1162 long timeoutl = req->rq_deadline -
1163 cfs_time_current_sec();
1164 cfs_duration_t timeout = timeoutl <= 0 ?
1165 CFS_TICK : cfs_time_seconds(timeoutl);
1166 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
1167 ost_bulk_timeout, desc);
1168 rc = l_wait_event(desc->bd_waitq,
1169 !ptlrpc_server_bulk_active(desc) ||
1170 desc->bd_export->exp_failed ||
1171 desc->bd_export->exp_abort_active_req,
1173 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1174 /* Wait again if we changed deadline */
1175 } while ((rc == -ETIMEDOUT) &&
1176 (req->rq_deadline > cfs_time_current_sec()));
1178 if (rc == -ETIMEDOUT) {
1179 DEBUG_REQ(D_ERROR, req,
1180 "timeout on bulk GET after %ld%+lds",
1181 req->rq_deadline - start,
1182 cfs_time_current_sec() -
1184 ptlrpc_abort_bulk(desc);
1185 } else if (desc->bd_export->exp_failed) {
1186 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1188 ptlrpc_abort_bulk(desc);
1189 } else if (desc->bd_export->exp_abort_active_req) {
1190 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk GET");
1191 /* we don't reply anyway */
1193 ptlrpc_abort_bulk(desc);
1194 } else if (!desc->bd_success) {
1195 DEBUG_REQ(D_ERROR, req, "network error on bulk GET");
1196 /* XXX should this be a different errno? */
1199 rc = sptlrpc_svc_unwrap_bulk(req, desc);
1202 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1206 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
1207 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1209 if (unlikely(client_cksum != 0 && rc == 0)) {
1210 static int cksum_counter;
1211 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1212 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1213 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1214 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1215 repbody->oa.o_cksum = server_cksum;
1217 if (unlikely(client_cksum != server_cksum)) {
1218 CERROR("client csum %x, server csum %x\n",
1219 client_cksum, server_cksum);
1221 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1222 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1223 cksum_counter, libcfs_id2str(req->rq_peer),
1228 /* Must commit after prep above in all cases */
1229 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1230 remote_nb, npages, local_nb, oti, rc);
1231 if (rc == -ENOTCONN)
1232 /* quota acquire process has been given up because
1233 * either the client has been evicted or the client
1234 * has timed out the request already */
1237 if (exp_connect_rmtclient(exp)) {
1238 repbody->oa.o_uid = o_uid;
1239 repbody->oa.o_gid = o_gid;
1243 * Disable sending mtime back to the client. If the client locked the
1244 * whole object, then it has already updated the mtime on its side,
1245 * otherwise it will have to glimpse anyway (see bug 21489, comment 32)
1247 repbody->oa.o_valid &= ~(OBD_MD_FLMTIME | OBD_MD_FLATIME);
1249 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1250 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1255 if (new_cksum == server_cksum)
1256 msg = "changed in transit before arrival at OST";
1257 else if (new_cksum == client_cksum)
1258 msg = "initial checksum before message complete";
1260 msg = "changed in transit AND after initial checksum";
1262 if (req->rq_peer.nid == desc->bd_sender) {
1266 router = libcfs_nid2str(desc->bd_sender);
1269 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1270 "%s%s%s inode "DFID" object "
1271 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1272 exp->exp_obd->obd_name, msg,
1273 libcfs_id2str(req->rq_peer),
1275 body->oa.o_valid & OBD_MD_FLFID ?
1276 body->oa.o_parent_seq : (__u64)0,
1277 body->oa.o_valid & OBD_MD_FLFID ?
1278 body->oa.o_parent_oid : 0,
1279 body->oa.o_valid & OBD_MD_FLFID ?
1280 body->oa.o_parent_ver : 0,
1282 body->oa.o_valid & OBD_MD_FLGROUP ?
1283 body->oa.o_seq : (__u64)0,
1285 local_nb[npages-1].offset +
1286 local_nb[npages-1].len - 1 );
1287 CERROR("client csum %x, original server csum %x, "
1288 "server csum now %x\n",
1289 client_cksum, server_cksum, new_cksum);
1295 /* set per-requested niobuf return codes */
1296 for (i = j = 0; i < niocount; i++) {
1297 int len = remote_nb[i].len;
1302 LASSERT(j < npages);
1303 if (local_nb[j].rc < 0)
1304 rcs[i] = local_nb[j].rc;
1305 len -= local_nb[j].len;
1310 LASSERT(j == npages);
1311 ptlrpc_lprocfs_brw(req, nob);
1315 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1320 ptlrpc_free_bulk(desc);
1322 /* XXX: don't send reply if obd rdonly mode, this can cause data loss
1323 * on client, see bug 22190. Remove this when async bulk will be done.
1324 * Meanwhile, if this is umount then don't reply anything. */
1325 if (req->rq_export->exp_obd->obd_no_transno) {
1326 no_reply = req->rq_export->exp_obd->obd_stopping;
1331 oti_to_request(oti, req);
1332 target_committed_to_req(req);
1333 rc = ptlrpc_reply(req);
1334 } else if (!no_reply) {
1335 /* Only reply if there was no comms problem with bulk */
1336 target_committed_to_req(req);
1337 req->rq_status = rc;
1340 /* reply out callback would free */
1341 ptlrpc_req_drop_rs(req);
1342 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1343 "client will retry\n",
1344 exp->exp_obd->obd_name,
1345 exp->exp_client_uuid.uuid,
1346 exp->exp_connection->c_remote_uuid.uuid,
1347 libcfs_id2str(req->rq_peer));
1349 libcfs_memory_pressure_clr();
1354 * Implementation of OST_SET_INFO.
1356 * OST_SET_INFO is like ioctl(): heavily overloaded. Specifically, it takes a
1357 * "key" and a value RPC buffers as arguments, with the value's contents
1358 * interpreted according to the key.
1360 * Value types that need swabbing have swabbing done explicitly, either here or
1361 * in functions called from here. This should be corrected: all swabbing should
1362 * be done in the capsule abstraction, as that will then allow us to move
1363 * swabbing exclusively to the client without having to modify server code
1364 * outside the capsule abstraction's implementation itself. To correct this
1365 * will require minor changes to the capsule abstraction; see the comments for
1366 * req_capsule_extend() in layout.c.
1368 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1370 struct ost_body *body = NULL, *repbody;
1371 char *key, *val = NULL;
1372 int keylen, vallen, rc = 0;
1373 int is_grant_shrink = 0;
1376 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1378 DEBUG_REQ(D_HA, req, "no set_info key");
1381 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1384 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1387 if ((is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK)))
1388 /* In this case the value is actually an RMF_OST_BODY, so we
1389 * transmutate the type of this PTLRPC */
1390 req_capsule_extend(&req->rq_pill, &RQF_OST_SET_GRANT_INFO);
1392 rc = req_capsule_server_pack(&req->rq_pill);
1397 if (is_grant_shrink) {
1398 body = req_capsule_client_get(&req->rq_pill,
1403 repbody = req_capsule_server_get(&req->rq_pill,
1405 memcpy(repbody, body, sizeof(*body));
1406 val = (char*)repbody;
1408 val = req_capsule_client_get(&req->rq_pill,
1413 if (KEY_IS(KEY_EVICT_BY_NID)) {
1415 obd_export_evict_by_nid(exp->exp_obd, val);
1417 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1418 if (vallen < sizeof(__u32))
1420 __swab32s((__u32 *)val);
1423 /* OBD will also check if KEY_IS(KEY_GRANT_SHRINK), and will cast val to
1424 * a struct ost_body * value */
1425 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1427 lustre_msg_set_status(req->rq_repmsg, 0);
1431 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1434 int keylen, replylen, rc = 0;
1435 struct req_capsule *pill = &req->rq_pill;
1438 /* this common part for get_info rpc */
1439 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1441 DEBUG_REQ(D_HA, req, "no get_info key");
1444 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1446 if (KEY_IS(KEY_FIEMAP)) {
1447 struct ll_fiemap_info_key *fm_key = key;
1450 rc = ost_validate_obdo(exp, &fm_key->oa, NULL);
1455 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1459 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1460 RCL_SERVER, replylen);
1462 rc = req_capsule_server_pack(pill);
1466 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1470 /* call again to fill in the reply buffer */
1471 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1473 lustre_msg_set_status(req->rq_repmsg, 0);
1477 #ifdef HAVE_QUOTA_SUPPORT
1478 static int ost_handle_quotactl(struct ptlrpc_request *req)
1480 struct obd_quotactl *oqctl, *repoqc;
1484 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1486 GOTO(out, rc = -EPROTO);
1488 rc = req_capsule_server_pack(&req->rq_pill);
1492 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1493 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1500 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1502 struct obd_quotactl *oqctl;
1506 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1510 rc = req_capsule_server_pack(&req->rq_pill);
1514 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1518 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1520 struct quota_adjust_qunit *oqaq, *repoqa;
1521 struct lustre_quota_ctxt *qctxt;
1525 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1526 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1528 GOTO(out, rc = -EPROTO);
1530 rc = req_capsule_server_pack(&req->rq_pill);
1534 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1535 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt);
1543 static int ost_llog_handle_connect(struct obd_export *exp,
1544 struct ptlrpc_request *req)
1546 struct llogd_conn_body *body;
1550 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
1551 rc = obd_llog_connect(exp, body);
1555 #define ost_init_sec_none(reply, exp) \
1557 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1558 OBD_CONNECT_RMT_CLIENT_FORCE | \
1559 OBD_CONNECT_OSS_CAPA); \
1560 cfs_spin_lock(&exp->exp_lock); \
1561 exp->exp_connect_flags = reply->ocd_connect_flags; \
1562 cfs_spin_unlock(&exp->exp_lock); \
1565 static int ost_init_sec_level(struct ptlrpc_request *req)
1567 struct obd_export *exp = req->rq_export;
1568 struct req_capsule *pill = &req->rq_pill;
1569 struct obd_device *obd = exp->exp_obd;
1570 struct filter_obd *filter = &obd->u.filter;
1571 char *client = libcfs_nid2str(req->rq_peer.nid);
1572 struct obd_connect_data *data, *reply;
1576 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1577 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1578 if (data == NULL || reply == NULL)
1581 /* connection from MDT is always trusted */
1582 if (req->rq_auth_usr_mdt) {
1583 ost_init_sec_none(reply, exp);
1587 /* no GSS support case */
1588 if (!req->rq_auth_gss) {
1589 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1590 CWARN("client %s -> target %s does not user GSS, "
1591 "can not run under security level %d.\n",
1592 client, obd->obd_name, filter->fo_sec_level);
1595 ost_init_sec_none(reply, exp);
1600 /* old version case */
1601 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1602 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1603 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1604 CWARN("client %s -> target %s uses old version, "
1605 "can not run under security level %d.\n",
1606 client, obd->obd_name, filter->fo_sec_level);
1609 CWARN("client %s -> target %s uses old version, "
1610 "run under security level %d.\n",
1611 client, obd->obd_name, filter->fo_sec_level);
1612 ost_init_sec_none(reply, exp);
1617 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1619 if (!req->rq_auth_remote)
1620 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1621 "asked to be remote.\n", client, obd->obd_name);
1622 } else if (req->rq_auth_remote) {
1624 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1625 "as remote by default.\n", client, obd->obd_name);
1629 if (!filter->fo_fl_oss_capa) {
1630 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1631 " but OSS capabilities are not enabled: %d.\n",
1632 client, obd->obd_name, filter->fo_fl_oss_capa);
1637 switch (filter->fo_sec_level) {
1638 case LUSTRE_SEC_NONE:
1640 ost_init_sec_none(reply, exp);
1643 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1644 "can not run under security level %d.\n",
1645 client, obd->obd_name, filter->fo_sec_level);
1648 case LUSTRE_SEC_REMOTE:
1650 ost_init_sec_none(reply, exp);
1652 case LUSTRE_SEC_ALL:
1654 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1655 OBD_CONNECT_RMT_CLIENT_FORCE);
1656 if (!filter->fo_fl_oss_capa)
1657 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1659 cfs_spin_lock(&exp->exp_lock);
1660 exp->exp_connect_flags = reply->ocd_connect_flags;
1661 cfs_spin_unlock(&exp->exp_lock);
1673 * this should be done in filter_connect()/filter_reconnect(), but
1674 * we can't obtain information like NID, which stored in incoming
1675 * request, thus can't decide what flavor to use. so we do it here.
1677 * This hack should be removed after the OST stack be rewritten, just
1678 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1680 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1682 struct obd_export *exp = req->rq_export;
1683 struct filter_obd *filter = &exp->exp_obd->u.filter;
1684 struct sptlrpc_flavor flvr;
1687 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1688 LUSTRE_ECHO_NAME) == 0)) {
1689 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1693 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1694 cfs_read_lock(&filter->fo_sptlrpc_lock);
1695 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1699 cfs_read_unlock(&filter->fo_sptlrpc_lock);
1701 cfs_spin_lock(&exp->exp_lock);
1703 exp->exp_sp_peer = req->rq_sp_from;
1704 exp->exp_flvr = flvr;
1706 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1707 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1708 CERROR("unauthorized rpc flavor %x from %s, "
1709 "expect %x\n", req->rq_flvr.sf_rpc,
1710 libcfs_nid2str(req->rq_peer.nid),
1711 exp->exp_flvr.sf_rpc);
1715 cfs_spin_unlock(&exp->exp_lock);
1717 if (exp->exp_sp_peer != req->rq_sp_from) {
1718 CERROR("RPC source %s doesn't match %s\n",
1719 sptlrpc_part2name(req->rq_sp_from),
1720 sptlrpc_part2name(exp->exp_sp_peer));
1723 rc = sptlrpc_target_export_check(exp, req);
1730 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1731 struct obd_device *obd, int *process)
1733 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1734 case OST_CONNECT: /* This will never get here, but for completeness. */
1735 case OST_DISCONNECT:
1746 case OBD_LOG_CANCEL:
1748 *process = target_queue_recovery_request(req, obd);
1752 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1758 int ost_msg_check_version(struct lustre_msg *msg)
1762 switch(lustre_msg_get_opc(msg)) {
1764 case OST_DISCONNECT:
1767 case SEC_CTX_INIT_CONT:
1769 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1771 CERROR("bad opc %u version %08x, expecting %08x\n",
1772 lustre_msg_get_opc(msg),
1773 lustre_msg_get_version(msg),
1774 LUSTRE_OBD_VERSION);
1787 #ifdef HAVE_QUOTA_SUPPORT
1788 case OST_QUOTACHECK:
1790 case OST_QUOTA_ADJUST_QUNIT:
1792 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1794 CERROR("bad opc %u version %08x, expecting %08x\n",
1795 lustre_msg_get_opc(msg),
1796 lustre_msg_get_version(msg),
1797 LUSTRE_OST_VERSION);
1802 case LDLM_BL_CALLBACK:
1803 case LDLM_CP_CALLBACK:
1804 rc = lustre_msg_check_version(msg, LUSTRE_DLM_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_DLM_VERSION);
1811 case LLOG_ORIGIN_CONNECT:
1812 case OBD_LOG_CANCEL:
1813 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1815 CERROR("bad opc %u version %08x, expecting %08x\n",
1816 lustre_msg_get_opc(msg),
1817 lustre_msg_get_version(msg),
1818 LUSTRE_LOG_VERSION);
1821 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1828 * Returns 1 if the given PTLRPC matches the given LDLM locks, or 0 if it does
1831 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1832 struct ldlm_lock *lock)
1834 struct niobuf_remote *nb;
1835 struct obd_ioobj *ioo;
1836 struct ost_body *body;
1837 int objcount, niocount;
1838 int mode, opc, i, rc;
1842 opc = lustre_msg_get_opc(req->rq_reqmsg);
1843 LASSERT(opc == OST_READ || opc == OST_WRITE);
1845 /* As the request may be covered by several locks, do not look at
1846 * o_handle, look at the RPC IO region. */
1847 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1851 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1852 RCL_CLIENT) / sizeof(*ioo);
1853 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1857 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
1861 for (niocount = i = 0; i < objcount; i++)
1862 niocount += ioo[i].ioo_bufcnt;
1864 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1866 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
1867 RCL_CLIENT) / sizeof(*nb)))
1871 if (opc == OST_READ)
1874 start = nb[0].offset & CFS_PAGE_MASK;
1875 end = (nb[ioo->ioo_bufcnt - 1].offset +
1876 nb[ioo->ioo_bufcnt - 1].len - 1) | ~CFS_PAGE_MASK;
1878 LASSERT(lock->l_resource != NULL);
1879 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_seq,
1880 &lock->l_resource->lr_name))
1883 if (!(lock->l_granted_mode & mode))
1886 if (lock->l_policy_data.l_extent.end < start ||
1887 lock->l_policy_data.l_extent.start > end)
1894 * High-priority queue request check for whether the given PTLRPC request (\a
1895 * req) is blocking an LDLM lock cancel.
1897 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1898 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1900 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1901 * function looks only at OST_READs and OST_WRITEs.
1903 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1905 struct niobuf_remote *nb;
1906 struct obd_ioobj *ioo;
1907 struct ost_body *body;
1908 int objcount, niocount;
1909 int mode, opc, i, rc;
1912 opc = lustre_msg_get_opc(req->rq_reqmsg);
1913 LASSERT(opc == OST_READ || opc == OST_WRITE);
1915 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1919 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1920 RCL_CLIENT) / sizeof(*ioo);
1921 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1925 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
1929 for (niocount = i = 0; i < objcount; i++)
1930 niocount += ioo[i].ioo_bufcnt;
1931 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1933 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
1934 RCL_CLIENT) / sizeof(*nb)))
1936 if (niocount != 0 && (nb[0].flags & OBD_BRW_SRVLOCK))
1940 if (opc == OST_READ)
1942 RETURN(ost_rw_prolong_locks(req, ioo, nb, &body->oa, mode));
1945 static int ost_punch_prolong_locks(struct ptlrpc_request *req, struct obdo *oa)
1947 struct ldlm_res_id res_id = { .name = { oa->o_id } };
1948 struct ost_prolong_data opd = { 0 };
1953 end = start + oa->o_blocks;
1955 opd.opd_mode = LCK_PW;
1956 opd.opd_exp = req->rq_export;
1957 opd.opd_policy.l_extent.start = start & CFS_PAGE_MASK;
1958 if (oa->o_blocks == OBD_OBJECT_EOF || end < start)
1959 opd.opd_policy.l_extent.end = OBD_OBJECT_EOF;
1961 opd.opd_policy.l_extent.end = end | ~CFS_PAGE_MASK;
1963 /* prolong locks for the current service time of the corresponding
1964 * portal (= OST_IO_PORTAL) */
1965 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
1966 max(at_est2timeout(at_get(&req->rq_rqbd->
1967 rqbd_service->srv_at_estimate)), ldlm_timeout);
1969 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1970 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
1971 opd.opd_policy.l_extent.end);
1974 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
1975 ost_prolong_locks_iter, &opd);
1976 RETURN(opd.opd_lock_match);
1980 * Like ost_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
1982 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1983 struct ldlm_lock *lock)
1985 struct ost_body *body;
1989 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1991 RETURN(0); /* can't return -EFAULT here */
1993 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
1997 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1998 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
2004 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
2006 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
2008 struct ost_body *body;
2011 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
2015 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
2019 LASSERT(!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
2020 !(body->oa.o_flags & OBD_FL_SRVLOCK));
2022 RETURN(ost_punch_prolong_locks(req, &body->oa));
2025 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
2026 .hpreq_lock_match = ost_rw_hpreq_lock_match,
2027 .hpreq_check = ost_rw_hpreq_check,
2030 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
2031 .hpreq_lock_match = ost_punch_hpreq_lock_match,
2032 .hpreq_check = ost_punch_hpreq_check,
2035 /** Assign high priority operations to the request if needed. */
2036 static int ost_hpreq_handler(struct ptlrpc_request *req)
2039 if (req->rq_export) {
2040 int opc = lustre_msg_get_opc(req->rq_reqmsg);
2041 struct ost_body *body;
2043 if (opc == OST_READ || opc == OST_WRITE) {
2044 struct niobuf_remote *nb;
2045 struct obd_ioobj *ioo;
2046 int objcount, niocount;
2049 /* RPCs on the H-P queue can be inspected before
2050 * ost_handler() initializes their pills, so we
2051 * initialize that here. Capsule initialization is
2052 * idempotent, as is setting the pill's format (provided
2053 * it doesn't change).
2055 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2056 if (opc == OST_READ)
2057 req_capsule_set(&req->rq_pill,
2060 req_capsule_set(&req->rq_pill,
2061 &RQF_OST_BRW_WRITE);
2063 body = req_capsule_client_get(&req->rq_pill,
2066 CERROR("Missing/short ost_body\n");
2070 objcount = req_capsule_get_size(&req->rq_pill,
2074 if (objcount == 0) {
2075 CERROR("Missing/short ioobj\n");
2079 CERROR("too many ioobjs (%d)\n", objcount);
2083 ioo = req_capsule_client_get(&req->rq_pill,
2086 CERROR("Missing/short ioobj\n");
2090 for (niocount = i = 0; i < objcount; i++) {
2091 if (ioo[i].ioo_bufcnt == 0) {
2092 CERROR("ioo[%d] has zero bufcnt\n", i);
2095 niocount += ioo[i].ioo_bufcnt;
2097 if (niocount > PTLRPC_MAX_BRW_PAGES) {
2098 DEBUG_REQ(D_RPCTRACE, req,
2099 "bulk has too many pages (%d)",
2104 nb = req_capsule_client_get(&req->rq_pill,
2105 &RMF_NIOBUF_REMOTE);
2107 CERROR("Missing/short niobuf\n");
2111 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
2112 req->rq_ops = &ost_hpreq_rw;
2113 } else if (opc == OST_PUNCH) {
2114 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2115 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2117 body = req_capsule_client_get(&req->rq_pill,
2120 CERROR("Missing/short ost_body\n");
2124 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
2125 !(body->oa.o_flags & OBD_FL_SRVLOCK))
2126 req->rq_ops = &ost_hpreq_punch;
2132 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
2133 int ost_handle(struct ptlrpc_request *req)
2135 struct obd_trans_info trans_info = { 0, };
2136 struct obd_trans_info *oti = &trans_info;
2137 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
2138 struct obd_device *obd = NULL;
2141 LASSERT(current->journal_info == NULL);
2143 /* primordial rpcs don't affect server recovery */
2144 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2146 case SEC_CTX_INIT_CONT:
2151 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2153 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
2154 if (!class_connected_export(req->rq_export)) {
2155 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
2156 lustre_msg_get_opc(req->rq_reqmsg),
2157 libcfs_id2str(req->rq_peer));
2158 req->rq_status = -ENOTCONN;
2159 GOTO(out, rc = -ENOTCONN);
2162 obd = req->rq_export->exp_obd;
2164 /* Check for aborted recovery. */
2165 if (obd->obd_recovering) {
2166 rc = ost_filter_recovery_request(req, obd,
2168 if (rc || !should_process)
2170 else if (should_process < 0) {
2171 req->rq_status = should_process;
2172 rc = ptlrpc_error(req);
2180 rc = ost_msg_check_version(req->rq_reqmsg);
2184 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2186 CDEBUG(D_INODE, "connect\n");
2187 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
2188 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
2190 rc = target_handle_connect(req);
2191 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
2194 rc = ost_init_sec_level(req);
2196 rc = ost_connect_check_sptlrpc(req);
2200 case OST_DISCONNECT:
2201 CDEBUG(D_INODE, "disconnect\n");
2202 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
2203 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
2205 rc = target_handle_disconnect(req);
2208 CDEBUG(D_INODE, "create\n");
2209 req_capsule_set(&req->rq_pill, &RQF_OST_CREATE);
2210 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
2212 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2213 GOTO(out, rc = -EROFS);
2214 rc = ost_create(req->rq_export, req, oti);
2217 CDEBUG(D_INODE, "destroy\n");
2218 req_capsule_set(&req->rq_pill, &RQF_OST_DESTROY);
2219 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
2221 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2222 GOTO(out, rc = -EROFS);
2223 rc = ost_destroy(req->rq_export, req, oti);
2226 CDEBUG(D_INODE, "getattr\n");
2227 req_capsule_set(&req->rq_pill, &RQF_OST_GETATTR);
2228 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
2230 rc = ost_getattr(req->rq_export, req);
2233 CDEBUG(D_INODE, "setattr\n");
2234 req_capsule_set(&req->rq_pill, &RQF_OST_SETATTR);
2235 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
2237 rc = ost_setattr(req->rq_export, req, oti);
2240 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_WRITE);
2241 CDEBUG(D_INODE, "write\n");
2242 /* req->rq_request_portal would be nice, if it was set */
2243 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2244 CERROR("%s: deny write request from %s to portal %u\n",
2245 req->rq_export->exp_obd->obd_name,
2246 obd_export_nid2str(req->rq_export),
2247 req->rq_rqbd->rqbd_service->srv_req_portal);
2248 GOTO(out, rc = -EPROTO);
2250 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2252 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
2253 GOTO(out, rc = -ENOSPC);
2254 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2255 GOTO(out, rc = -EROFS);
2256 rc = ost_brw_write(req, oti);
2257 LASSERT(current->journal_info == NULL);
2258 /* ost_brw_write sends its own replies */
2261 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_READ);
2262 CDEBUG(D_INODE, "read\n");
2263 /* req->rq_request_portal would be nice, if it was set */
2264 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2265 CERROR("%s: deny read request from %s to portal %u\n",
2266 req->rq_export->exp_obd->obd_name,
2267 obd_export_nid2str(req->rq_export),
2268 req->rq_rqbd->rqbd_service->srv_req_portal);
2269 GOTO(out, rc = -EPROTO);
2271 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2273 rc = ost_brw_read(req, oti);
2274 LASSERT(current->journal_info == NULL);
2275 /* ost_brw_read sends its own replies */
2278 CDEBUG(D_INODE, "punch\n");
2279 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2280 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2282 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2283 GOTO(out, rc = -EROFS);
2284 rc = ost_punch(req->rq_export, req, oti);
2287 CDEBUG(D_INODE, "statfs\n");
2288 req_capsule_set(&req->rq_pill, &RQF_OST_STATFS);
2289 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2291 rc = ost_statfs(req);
2294 CDEBUG(D_INODE, "sync\n");
2295 req_capsule_set(&req->rq_pill, &RQF_OST_SYNC);
2296 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2298 rc = ost_sync(req->rq_export, req);
2301 DEBUG_REQ(D_INODE, req, "set_info");
2302 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
2303 rc = ost_set_info(req->rq_export, req);
2306 DEBUG_REQ(D_INODE, req, "get_info");
2307 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
2308 rc = ost_get_info(req->rq_export, req);
2310 #ifdef HAVE_QUOTA_SUPPORT
2311 case OST_QUOTACHECK:
2312 CDEBUG(D_INODE, "quotacheck\n");
2313 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2314 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2316 rc = ost_handle_quotacheck(req);
2319 CDEBUG(D_INODE, "quotactl\n");
2320 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2321 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2323 rc = ost_handle_quotactl(req);
2325 case OST_QUOTA_ADJUST_QUNIT:
2326 CDEBUG(D_INODE, "quota_adjust_qunit\n");
2327 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
2328 rc = ost_handle_quota_adjust_qunit(req);
2332 DEBUG_REQ(D_INODE, req, "ping");
2333 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2334 rc = target_handle_ping(req);
2336 /* FIXME - just reply status */
2337 case LLOG_ORIGIN_CONNECT:
2338 DEBUG_REQ(D_INODE, req, "log connect");
2339 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2340 rc = ost_llog_handle_connect(req->rq_export, req);
2341 req->rq_status = rc;
2342 rc = req_capsule_server_pack(&req->rq_pill);
2345 RETURN(ptlrpc_reply(req));
2346 case OBD_LOG_CANCEL:
2347 CDEBUG(D_INODE, "log cancel\n");
2348 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2349 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2351 rc = llog_origin_handle_cancel(req);
2352 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2354 req->rq_status = rc;
2355 rc = req_capsule_server_pack(&req->rq_pill);
2358 RETURN(ptlrpc_reply(req));
2360 CDEBUG(D_INODE, "enqueue\n");
2361 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2362 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2364 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2365 ldlm_server_blocking_ast,
2366 ldlm_server_glimpse_ast);
2367 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2370 CDEBUG(D_INODE, "convert\n");
2371 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2372 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2374 rc = ldlm_handle_convert(req);
2377 CDEBUG(D_INODE, "cancel\n");
2378 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2379 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2381 rc = ldlm_handle_cancel(req);
2383 case LDLM_BL_CALLBACK:
2384 case LDLM_CP_CALLBACK:
2385 CDEBUG(D_INODE, "callback\n");
2386 CERROR("callbacks should not happen on OST\n");
2389 CERROR("Unexpected opcode %d\n",
2390 lustre_msg_get_opc(req->rq_reqmsg));
2391 req->rq_status = -ENOTSUPP;
2392 rc = ptlrpc_error(req);
2396 LASSERT(current->journal_info == NULL);
2399 /* If we're DISCONNECTing, the export_data is already freed */
2400 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2401 target_committed_to_req(req);
2405 oti_to_request(oti, req);
2407 target_send_reply(req, rc, fail);
2410 EXPORT_SYMBOL(ost_handle);
2412 * free per-thread pool created by ost_thread_init().
2414 static void ost_thread_done(struct ptlrpc_thread *thread)
2416 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2421 LASSERT(thread != NULL);
2424 * be prepared to handle partially-initialized pools (because this is
2425 * called from ost_thread_init() for cleanup.
2427 tls = thread->t_data;
2430 thread->t_data = NULL;
2436 * initialize per-thread page pool (bug 5137).
2438 static int ost_thread_init(struct ptlrpc_thread *thread)
2440 struct ost_thread_local_cache *tls;
2444 LASSERT(thread != NULL);
2445 LASSERT(thread->t_data == NULL);
2446 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
2451 thread->t_data = tls;
2455 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2457 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2458 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2460 struct ost_obd *ost = &obd->u.ost;
2461 struct lprocfs_static_vars lvars;
2462 int oss_min_threads;
2463 int oss_max_threads;
2464 int oss_min_create_threads;
2465 int oss_max_create_threads;
2469 rc = cfs_cleanup_group_info();
2473 lprocfs_ost_init_vars(&lvars);
2474 lprocfs_obd_setup(obd, lvars.obd_vars);
2476 cfs_sema_init(&ost->ost_health_sem, 1);
2478 if (oss_num_threads) {
2479 /* If oss_num_threads is set, it is the min and the max. */
2480 if (oss_num_threads > OSS_THREADS_MAX)
2481 oss_num_threads = OSS_THREADS_MAX;
2482 if (oss_num_threads < OSS_THREADS_MIN)
2483 oss_num_threads = OSS_THREADS_MIN;
2484 oss_max_threads = oss_min_threads = oss_num_threads;
2486 /* Base min threads on memory and cpus */
2488 cfs_num_possible_cpus() * CFS_NUM_CACHEPAGES >>
2489 (27 - CFS_PAGE_SHIFT);
2490 if (oss_min_threads < OSS_THREADS_MIN)
2491 oss_min_threads = OSS_THREADS_MIN;
2492 /* Insure a 4x range for dynamic threads */
2493 if (oss_min_threads > OSS_THREADS_MAX / 4)
2494 oss_min_threads = OSS_THREADS_MAX / 4;
2495 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
2499 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2500 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
2501 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2502 ost_handle, LUSTRE_OSS_NAME,
2503 obd->obd_proc_entry, target_print_req,
2504 oss_min_threads, oss_max_threads,
2505 "ll_ost", LCT_DT_THREAD, NULL);
2506 if (ost->ost_service == NULL) {
2507 CERROR("failed to start service\n");
2508 GOTO(out_lprocfs, rc = -ENOMEM);
2511 rc = ptlrpc_start_threads(obd, ost->ost_service);
2513 GOTO(out_service, rc = -EINVAL);
2515 if (oss_num_create_threads) {
2516 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
2517 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
2518 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
2519 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
2520 oss_min_create_threads = oss_max_create_threads =
2521 oss_num_create_threads;
2523 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
2524 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
2527 ost->ost_create_service =
2528 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2529 OST_MAXREPSIZE, OST_CREATE_PORTAL,
2530 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2531 ost_handle, "ost_create",
2532 obd->obd_proc_entry, target_print_req,
2533 oss_min_create_threads, oss_max_create_threads,
2534 "ll_ost_creat", LCT_DT_THREAD, NULL);
2535 if (ost->ost_create_service == NULL) {
2536 CERROR("failed to start OST create service\n");
2537 GOTO(out_service, rc = -ENOMEM);
2540 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
2542 GOTO(out_create, rc = -EINVAL);
2544 ost->ost_io_service =
2545 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2546 OST_MAXREPSIZE, OST_IO_PORTAL,
2547 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2548 ost_handle, "ost_io",
2549 obd->obd_proc_entry, target_print_req,
2550 oss_min_threads, oss_max_threads,
2551 "ll_ost_io", LCT_DT_THREAD, ost_hpreq_handler);
2552 if (ost->ost_io_service == NULL) {
2553 CERROR("failed to start OST I/O service\n");
2554 GOTO(out_create, rc = -ENOMEM);
2557 ost->ost_io_service->srv_init = ost_thread_init;
2558 ost->ost_io_service->srv_done = ost_thread_done;
2559 ost->ost_io_service->srv_cpu_affinity = 1;
2560 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
2562 GOTO(out_io, rc = -EINVAL);
2564 ping_evictor_start();
2569 ptlrpc_unregister_service(ost->ost_io_service);
2570 ost->ost_io_service = NULL;
2572 ptlrpc_unregister_service(ost->ost_create_service);
2573 ost->ost_create_service = NULL;
2575 ptlrpc_unregister_service(ost->ost_service);
2576 ost->ost_service = NULL;
2578 lprocfs_obd_cleanup(obd);
2582 static int ost_cleanup(struct obd_device *obd)
2584 struct ost_obd *ost = &obd->u.ost;
2588 ping_evictor_stop();
2590 cfs_spin_lock_bh(&obd->obd_processing_task_lock);
2591 if (obd->obd_recovering) {
2592 target_cancel_recovery_timer(obd);
2593 obd->obd_recovering = 0;
2595 cfs_spin_unlock_bh(&obd->obd_processing_task_lock);
2597 cfs_down(&ost->ost_health_sem);
2598 ptlrpc_unregister_service(ost->ost_service);
2599 ptlrpc_unregister_service(ost->ost_create_service);
2600 ptlrpc_unregister_service(ost->ost_io_service);
2601 ost->ost_service = NULL;
2602 ost->ost_create_service = NULL;
2603 cfs_up(&ost->ost_health_sem);
2605 lprocfs_obd_cleanup(obd);
2610 static int ost_health_check(struct obd_device *obd)
2612 struct ost_obd *ost = &obd->u.ost;
2615 cfs_down(&ost->ost_health_sem);
2616 rc |= ptlrpc_service_health_check(ost->ost_service);
2617 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2618 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2619 cfs_up(&ost->ost_health_sem);
2622 * health_check to return 0 on healthy
2623 * and 1 on unhealthy.
2631 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2633 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2636 /* use obd ops to offer management infrastructure */
2637 static struct obd_ops ost_obd_ops = {
2638 .o_owner = THIS_MODULE,
2639 .o_setup = ost_setup,
2640 .o_cleanup = ost_cleanup,
2641 .o_health_check = ost_health_check,
2645 static int __init ost_init(void)
2647 struct lprocfs_static_vars lvars;
2651 lprocfs_ost_init_vars(&lvars);
2652 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2653 LUSTRE_OSS_NAME, NULL);
2655 if (ost_num_threads != 0 && oss_num_threads == 0) {
2656 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2657 "use oss_num_threads instead or unset both for "
2658 "dynamic thread startup\n");
2659 oss_num_threads = ost_num_threads;
2665 static void /*__exit*/ ost_exit(void)
2667 class_unregister_type(LUSTRE_OSS_NAME);
2670 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2671 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2672 MODULE_LICENSE("GPL");
2674 module_init(ost_init);
2675 module_exit(ost_exit);