1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ost/ost_handler.c
38 * Author: Peter J. Braam <braam@clusterfs.com>
39 * Author: Phil Schwan <phil@clusterfs.com>
43 # define EXPORT_SYMTAB
45 #define DEBUG_SUBSYSTEM S_OST
47 #include <linux/module.h>
48 #include <obd_cksum.h>
50 #include <lustre_net.h>
51 #include <lustre_dlm.h>
52 #include <lustre_export.h>
53 #include <lustre_debug.h>
54 #include <linux/init.h>
55 #include <lprocfs_status.h>
56 #include <libcfs/list.h>
57 #include <lustre_quota.h>
58 #include "ost_internal.h"
60 static int oss_num_threads;
61 CFS_MODULE_PARM(oss_num_threads, "i", int, 0444,
62 "number of OSS service threads to start");
64 static int ost_num_threads;
65 CFS_MODULE_PARM(ost_num_threads, "i", int, 0444,
66 "number of OST service threads to start (deprecated)");
68 static int oss_num_create_threads;
69 CFS_MODULE_PARM(oss_num_create_threads, "i", int, 0444,
70 "number of OSS create threads to start");
73 * Do not return server-side uid/gid to remote client
75 static void ost_drop_id(struct obd_export *exp, struct obdo *oa)
77 if (exp_connect_rmtclient(exp)) {
80 oa->o_valid &= ~(OBD_MD_FLUID | OBD_MD_FLGID);
85 * Validate oa from client.
86 * 1. If the request comes from 1.8 clients, it will reset o_seq with MDT0.
87 * 2. If the request comes from 2.0 clients, currently only RSVD seq and IDIF
89 * a. for single MDS seq = FID_SEQ_OST_MDT0,
90 * b. for CMD, seq = FID_SEQ_OST_MDT0, FID_SEQ_OST_MDT1 - FID_SEQ_OST_MAX
92 static int ost_validate_obdo(struct obd_export *exp, struct obdo *oa,
93 struct obd_ioobj *ioobj)
95 if (oa != NULL && (!(oa->o_valid & OBD_MD_FLGROUP) ||
96 !(exp->exp_connect_flags & OBD_CONNECT_FULL20))) {
97 oa->o_seq = FID_SEQ_OST_MDT0;
99 ioobj->ioo_seq = FID_SEQ_OST_MDT0;
100 /* remove fid_seq_is_rsvd() after FID-on-OST allows SEQ > 9 */
101 } else if (oa == NULL ||
102 !(fid_seq_is_rsvd(oa->o_seq) || fid_seq_is_idif(oa->o_seq))) {
103 CERROR("%s: client %s sent invalid object "POSTID"\n",
104 exp->exp_obd->obd_name, obd_export_nid2str(exp),
105 oa ? oa->o_id : -1, oa ? oa->o_seq : -1);
108 obdo_from_ostid(oa, &oa->o_oi);
110 ioobj_from_obdo(ioobj, oa);
114 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
116 struct oti_req_ack_lock *ack_lock;
122 if (req->rq_repmsg) {
123 __u64 versions[PTLRPC_NUM_VERSIONS] = { 0 };
124 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
125 versions[0] = oti->oti_pre_version;
126 lustre_msg_set_versions(req->rq_repmsg, versions);
128 req->rq_transno = oti->oti_transno;
130 /* XXX 4 == entries in oti_ack_locks??? */
131 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
134 /* XXX not even calling target_send_reply in some cases... */
135 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode, 0);
139 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
140 struct obd_trans_info *oti)
142 struct ost_body *body, *repbody;
143 struct lustre_capa *capa = NULL;
147 /* Get the request body */
148 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
152 if (body->oa.o_id == 0)
155 rc = ost_validate_obdo(exp, &body->oa, NULL);
159 /* If there's a DLM request, cancel the locks mentioned in it*/
160 if (req_capsule_field_present(&req->rq_pill, &RMF_DLM_REQ, RCL_CLIENT)) {
161 struct ldlm_request *dlm;
163 dlm = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
166 ldlm_request_cancel(req, dlm, 0);
169 /* If there's a capability, get it */
170 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
171 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
173 CERROR("Missing capability for OST DESTROY");
178 /* Prepare the reply */
179 rc = req_capsule_server_pack(&req->rq_pill);
183 /* Get the log cancellation cookie */
184 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
185 oti->oti_logcookies = &body->oa.o_lcookie;
187 /* Finish the reply */
188 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
189 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
191 /* Do the destroy and set the reply status accordingly */
192 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL, capa);
197 * Helper function for getting server side [start, start+count] DLM lock
198 * if asked by client.
200 static int ost_lock_get(struct obd_export *exp, struct obdo *oa,
201 __u64 start, __u64 count, struct lustre_handle *lh,
204 struct ldlm_res_id res_id;
205 ldlm_policy_data_t policy;
206 __u64 end = start + count;
210 LASSERT(!lustre_handle_is_used(lh));
211 /* o_id and o_gr are used for localizing resource, if client miss to set
212 * them, do not trigger ASSERTION. */
213 if (unlikely((oa->o_valid & (OBD_MD_FLID | OBD_MD_FLGROUP)) !=
214 (OBD_MD_FLID | OBD_MD_FLGROUP)))
217 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
218 !(oa->o_flags & OBD_FL_SRVLOCK))
221 osc_build_res_name(oa->o_id, oa->o_seq, &res_id);
222 CDEBUG(D_INODE, "OST-side extent lock.\n");
224 policy.l_extent.start = start & CFS_PAGE_MASK;
226 /* If ->o_blocks is EOF it means "lock till the end of the
227 * file". Otherwise, it's size of a hole being punched (in bytes) */
228 if (count == OBD_OBJECT_EOF || end < start)
229 policy.l_extent.end = OBD_OBJECT_EOF;
231 policy.l_extent.end = end | ~CFS_PAGE_MASK;
233 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
234 LDLM_EXTENT, &policy, mode, &flags,
235 ldlm_blocking_ast, ldlm_completion_ast,
236 ldlm_glimpse_ast, NULL, 0, NULL, lh));
239 /* Helper function: release lock, if any. */
240 static void ost_lock_put(struct obd_export *exp,
241 struct lustre_handle *lh, int mode)
244 if (lustre_handle_is_used(lh))
245 ldlm_lock_decref(lh, mode);
249 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
251 struct ost_body *body, *repbody;
252 struct obd_info *oinfo;
253 struct lustre_handle lh = { 0 };
254 struct lustre_capa *capa = NULL;
258 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
262 rc = ost_validate_obdo(exp, &body->oa, NULL);
266 rc = req_capsule_server_pack(&req->rq_pill);
270 rc = ost_lock_get(exp, &body->oa, 0, OBD_OBJECT_EOF, &lh, LCK_PR, 0);
274 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
275 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
277 CERROR("Missing capability for OST GETATTR");
282 OBD_ALLOC_PTR(oinfo);
285 oinfo->oi_oa = &body->oa;
286 oinfo->oi_capa = capa;
288 req->rq_status = obd_getattr(exp, oinfo);
292 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
293 repbody->oa = body->oa;
295 ost_lock_put(exp, &lh, LCK_PR);
297 ost_drop_id(exp, &repbody->oa);
301 static int ost_statfs(struct ptlrpc_request *req)
303 struct obd_statfs *osfs;
307 rc = req_capsule_server_pack(&req->rq_pill);
311 osfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
313 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
314 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
316 if (req->rq_status != 0)
317 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
322 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
323 struct obd_trans_info *oti)
325 struct ost_body *body, *repbody;
329 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
333 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
337 rc = req_capsule_server_pack(&req->rq_pill);
341 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
342 repbody->oa = body->oa;
343 oti->oti_logcookies = &body->oa.o_lcookie;
345 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
346 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
350 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
351 struct obd_trans_info *oti)
353 struct ost_body *body, *repbody;
355 struct lustre_handle lh = {0,};
358 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
359 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
361 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
365 rc = ost_validate_obdo(exp, &body->oa, NULL);
369 if ((body->oa.o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
370 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
373 rc = req_capsule_server_pack(&req->rq_pill);
377 /* standard truncate optimization: if file body is completely
378 * destroyed, don't send data back to the server. */
379 if (body->oa.o_size == 0)
380 flags |= LDLM_AST_DISCARD_DATA;
382 rc = ost_lock_get(exp, &body->oa, body->oa.o_size, body->oa.o_blocks,
385 struct obd_info *oinfo;
386 struct lustre_capa *capa = NULL;
388 if (body->oa.o_valid & OBD_MD_FLFLAGS &&
389 body->oa.o_flags == OBD_FL_SRVLOCK)
391 * If OBD_FL_SRVLOCK is the only bit set in
392 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
393 * through filter_setattr() to filter_iocontrol().
395 body->oa.o_valid &= ~OBD_MD_FLFLAGS;
397 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
398 capa = req_capsule_client_get(&req->rq_pill,
401 CERROR("Missing capability for OST PUNCH");
406 OBD_ALLOC_PTR(oinfo);
409 oinfo->oi_oa = &body->oa;
410 oinfo->oi_policy.l_extent.start = oinfo->oi_oa->o_size;
411 oinfo->oi_policy.l_extent.end = oinfo->oi_oa->o_blocks;
412 oinfo->oi_capa = capa;
414 req->rq_status = obd_punch(exp, oinfo, oti, NULL);
416 ost_lock_put(exp, &lh, LCK_PW);
419 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
420 repbody->oa = body->oa;
421 ost_drop_id(exp, &repbody->oa);
425 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
427 struct ost_body *body, *repbody;
428 struct obd_info *oinfo;
429 struct lustre_capa *capa = NULL;
433 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
437 rc = ost_validate_obdo(exp, &body->oa, NULL);
441 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
442 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
444 CERROR("Missing capability for OST SYNC");
449 rc = req_capsule_server_pack(&req->rq_pill);
453 OBD_ALLOC_PTR(oinfo);
457 oinfo->oi_oa = &body->oa;
458 oinfo->oi_capa = capa;
459 req->rq_status = obd_sync(exp, oinfo, body->oa.o_size,
460 body->oa.o_blocks, NULL);
463 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
464 repbody->oa = body->oa;
465 ost_drop_id(exp, &repbody->oa);
469 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
470 struct obd_trans_info *oti)
472 struct ost_body *body, *repbody;
473 struct obd_info *oinfo;
474 struct lustre_capa *capa = NULL;
478 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
482 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
486 rc = req_capsule_server_pack(&req->rq_pill);
490 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
491 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
493 CERROR("Missing capability for OST SETATTR");
498 OBD_ALLOC_PTR(oinfo);
501 oinfo->oi_oa = &body->oa;
502 oinfo->oi_capa = capa;
504 req->rq_status = obd_setattr(exp, oinfo, oti);
508 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
509 repbody->oa = body->oa;
510 ost_drop_id(exp, &repbody->oa);
514 static int ost_bulk_timeout(void *data)
517 /* We don't fail the connection here, because having the export
518 * killed makes the (vital) call to commitrw very sad.
523 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
524 cksum_type_t cksum_type)
529 cksum = init_checksum(cksum_type);
530 for (i = 0; i < desc->bd_iov_count; i++) {
531 struct page *page = desc->bd_iov[i].kiov_page;
532 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
533 char *ptr = kmap(page) + off;
534 int len = desc->bd_iov[i].kiov_len;
536 /* corrupt the data before we compute the checksum, to
537 * simulate a client->OST data error */
538 if (i == 0 && opc == OST_WRITE &&
539 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
540 memcpy(ptr, "bad3", min(4, len));
541 cksum = compute_checksum(cksum, ptr, len, cksum_type);
542 /* corrupt the data after we compute the checksum, to
543 * simulate an OST->client data error */
544 if (i == 0 && opc == OST_READ &&
545 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
546 memcpy(ptr, "bad4", min(4, len));
547 /* nobody should use corrupted page again */
548 ClearPageUptodate(page);
556 static int ost_brw_lock_get(int mode, struct obd_export *exp,
557 struct obd_ioobj *obj, struct niobuf_remote *nb,
558 struct lustre_handle *lh)
561 int nrbufs = obj->ioo_bufcnt;
562 struct ldlm_res_id res_id;
563 ldlm_policy_data_t policy;
567 osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id);
568 LASSERT(mode == LCK_PR || mode == LCK_PW);
569 LASSERT(!lustre_handle_is_used(lh));
571 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
574 for (i = 1; i < nrbufs; i ++)
575 if ((nb[0].flags & OBD_BRW_SRVLOCK) !=
576 (nb[i].flags & OBD_BRW_SRVLOCK))
579 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
580 policy.l_extent.end = (nb[nrbufs - 1].offset +
581 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
583 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
584 LDLM_EXTENT, &policy, mode, &flags,
585 ldlm_blocking_ast, ldlm_completion_ast,
586 ldlm_glimpse_ast, NULL, 0, NULL, lh));
589 static void ost_brw_lock_put(int mode,
590 struct obd_ioobj *obj, struct niobuf_remote *niob,
591 struct lustre_handle *lh)
594 LASSERT(mode == LCK_PR || mode == LCK_PW);
595 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
596 lustre_handle_is_used(lh));
597 if (lustre_handle_is_used(lh))
598 ldlm_lock_decref(lh, mode);
602 struct ost_prolong_data {
603 struct obd_export *opd_exp;
604 ldlm_policy_data_t opd_policy;
606 ldlm_mode_t opd_mode;
611 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
613 struct ost_prolong_data *opd = data;
615 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
617 if (lock->l_req_mode != lock->l_granted_mode) {
618 /* scan granted locks only */
619 return LDLM_ITER_STOP;
622 if (lock->l_export != opd->opd_exp) {
623 /* prolong locks only for given client */
624 return LDLM_ITER_CONTINUE;
627 if (!(lock->l_granted_mode & opd->opd_mode)) {
628 /* we aren't interesting in all type of locks */
629 return LDLM_ITER_CONTINUE;
632 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
633 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
634 /* the request doesn't cross the lock, skip it */
635 return LDLM_ITER_CONTINUE;
638 /* Fill the obdo with the matched lock handle.
639 * XXX: it is possible in some cases the IO RPC is covered by several
640 * locks, even for the write case, so it may need to be a lock list. */
641 if (opd->opd_oa && !(opd->opd_oa->o_valid & OBD_MD_FLHANDLE)) {
642 opd->opd_oa->o_handle.cookie = lock->l_handle.h_cookie;
643 opd->opd_oa->o_valid |= OBD_MD_FLHANDLE;
646 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
647 /* ignore locks not being cancelled */
648 return LDLM_ITER_CONTINUE;
651 CDEBUG(D_DLMTRACE,"refresh lock: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
652 lock->l_resource->lr_name.name[0],
653 lock->l_resource->lr_name.name[1],
654 opd->opd_policy.l_extent.start, opd->opd_policy.l_extent.end);
655 /* OK. this is a possible lock the user holds doing I/O
656 * let's refresh eviction timer for it */
657 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
658 opd->opd_lock_match = 1;
660 return LDLM_ITER_CONTINUE;
663 static int ost_rw_prolong_locks(struct ptlrpc_request *req, struct obd_ioobj *obj,
664 struct niobuf_remote *nb, struct obdo *oa,
667 struct ldlm_res_id res_id;
668 int nrbufs = obj->ioo_bufcnt;
669 struct ost_prolong_data opd = { 0 };
672 osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id);
675 opd.opd_exp = req->rq_export;
676 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
677 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
678 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
680 /* prolong locks for the current service time of the corresponding
681 * portal (= OST_IO_PORTAL) */
682 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
683 max(at_est2timeout(at_get(&req->rq_rqbd->
684 rqbd_service->srv_at_estimate)), ldlm_timeout);
686 CDEBUG(D_INFO,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
687 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
688 opd.opd_policy.l_extent.end);
690 if (oa->o_valid & OBD_MD_FLHANDLE) {
691 struct ldlm_lock *lock;
693 lock = ldlm_handle2lock(&oa->o_handle);
695 ost_prolong_locks_iter(lock, &opd);
696 if (opd.opd_lock_match) {
701 /* Check if the lock covers the whole IO region,
702 * otherwise iterate through the resource. */
703 if (lock->l_policy_data.l_extent.end >=
704 opd.opd_policy.l_extent.end &&
705 lock->l_policy_data.l_extent.start <=
706 opd.opd_policy.l_extent.start) {
715 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
716 ost_prolong_locks_iter, &opd);
717 RETURN(opd.opd_lock_match);
720 /* Allocate thread local buffers if needed */
721 static struct ost_thread_local_cache *ost_tls_get(struct ptlrpc_request *r)
723 struct ost_thread_local_cache *tls =
724 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
726 /* In normal mode of operation an I/O request is serviced only
727 * by ll_ost_io threads each of them has own tls buffers allocated by
729 * During recovery, an I/O request may be queued until any of the ost
730 * service threads process it. Not necessary it should be one of
731 * ll_ost_io threads. In that case we dynamically allocating tls
732 * buffers for the request service time. */
733 if (unlikely(tls == NULL)) {
734 LASSERT(r->rq_export->exp_in_recovery);
738 r->rq_svc_thread->t_data = tls;
744 /* Free thread local buffers if they were allocated only for servicing
745 * this one request */
746 static void ost_tls_put(struct ptlrpc_request *r)
748 struct ost_thread_local_cache *tls =
749 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
751 if (unlikely(tls->temporary)) {
753 r->rq_svc_thread->t_data = NULL;
757 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
759 struct ptlrpc_bulk_desc *desc = NULL;
760 struct obd_export *exp = req->rq_export;
761 struct niobuf_remote *remote_nb;
762 struct niobuf_local *local_nb;
763 struct obd_ioobj *ioo;
764 struct ost_body *body, *repbody;
765 struct lustre_capa *capa = NULL;
766 struct l_wait_info lwi;
767 struct lustre_handle lockh = { 0 };
768 int niocount, npages, nob = 0, rc, i;
770 struct ost_thread_local_cache *tls;
773 req->rq_bulk_read = 1;
775 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
776 GOTO(out, rc = -EIO);
778 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
780 /* Check if there is eviction in progress, and if so, wait for it to
782 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
783 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
784 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
785 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
789 GOTO(out, rc = -ENOTCONN);
791 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
792 * ost_rw_hpreq_check(). */
793 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
795 GOTO(out, rc = -EFAULT);
798 * A req_capsule_X_get_array(pill, field, ptr_to_element_count) function
799 * would be useful here and wherever we get &RMF_OBD_IOOBJ and
800 * &RMF_NIOBUF_REMOTE.
802 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
804 GOTO(out, rc = -EFAULT);
806 rc = ost_validate_obdo(exp, &body->oa, ioo);
810 niocount = ioo->ioo_bufcnt;
811 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
812 if (remote_nb == NULL)
813 GOTO(out, rc = -EFAULT);
815 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
816 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
818 CERROR("Missing capability for OST BRW READ");
819 GOTO(out, rc = -EFAULT);
823 rc = req_capsule_server_pack(&req->rq_pill);
827 tls = ost_tls_get(req);
829 GOTO(out_bulk, rc = -ENOMEM);
830 local_nb = tls->local;
832 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
837 * If getting the lock took more time than
838 * client was willing to wait, drop it. b=11330
840 if (cfs_time_current_sec() > req->rq_deadline ||
841 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
843 CERROR("Dropping timed-out read from %s because locking"
844 "object "LPX64" took %ld seconds (limit was %ld).\n",
845 libcfs_id2str(req->rq_peer), ioo->ioo_id,
846 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
847 req->rq_deadline - req->rq_arrival_time.tv_sec);
848 GOTO(out_lock, rc = -ETIMEDOUT);
851 npages = OST_THREAD_POOL_SIZE;
852 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
853 remote_nb, &npages, local_nb, oti, capa);
857 desc = ptlrpc_prep_bulk_exp(req, npages,
858 BULK_PUT_SOURCE, OST_BULK_PORTAL);
860 GOTO(out_commitrw, rc = -ENOMEM);
862 if (!lustre_handle_is_used(&lockh))
863 /* no needs to try to prolong lock if server is asked
864 * to handle locking (= OBD_BRW_SRVLOCK) */
865 ost_rw_prolong_locks(req, ioo, remote_nb, &body->oa,
869 for (i = 0; i < npages; i++) {
870 int page_rc = local_nb[i].rc;
872 if (page_rc < 0) { /* error */
878 if (page_rc != 0) { /* some data! */
879 LASSERT (local_nb[i].page != NULL);
880 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
881 local_nb[i].offset & ~CFS_PAGE_MASK,
885 if (page_rc != local_nb[i].len) { /* short read */
886 /* All subsequent pages should be 0 */
888 LASSERT(local_nb[i].rc == 0);
893 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
894 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
896 if (body->oa.o_valid & OBD_MD_FLFLAGS)
897 cksum_type = cksum_type_unpack(body->oa.o_flags);
898 body->oa.o_flags = cksum_type_pack(cksum_type);
899 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
900 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
901 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
903 body->oa.o_valid = 0;
905 /* We're finishing using body->oa as an input variable */
907 /* Check if client was evicted while we were doing i/o before touching
910 /* Check if there is eviction in progress, and if so, wait for
912 if (unlikely(cfs_atomic_read(&exp->exp_obd->
913 obd_evict_inprogress))) {
914 lwi = LWI_INTR(NULL, NULL);
915 rc = l_wait_event(exp->exp_obd->
916 obd_evict_inprogress_waitq,
917 !cfs_atomic_read(&exp->exp_obd->
918 obd_evict_inprogress),
921 /* Check if client was evicted or tried to reconnect already */
922 if (exp->exp_failed || exp->exp_abort_active_req)
925 rc = sptlrpc_svc_wrap_bulk(req, desc);
927 rc = ptlrpc_start_bulk_transfer(desc);
931 time_t start = cfs_time_current_sec();
933 long timeoutl = req->rq_deadline -
934 cfs_time_current_sec();
935 cfs_duration_t timeout = timeoutl <= 0 ?
936 CFS_TICK : cfs_time_seconds(timeoutl);
937 lwi = LWI_TIMEOUT_INTERVAL(timeout,
941 rc = l_wait_event(desc->bd_waitq,
942 !ptlrpc_server_bulk_active(desc) ||
944 exp->exp_abort_active_req,
946 LASSERT(rc == 0 || rc == -ETIMEDOUT);
947 /* Wait again if we changed deadline */
948 } while ((rc == -ETIMEDOUT) &&
949 (req->rq_deadline > cfs_time_current_sec()));
951 if (rc == -ETIMEDOUT) {
952 DEBUG_REQ(D_ERROR, req,
953 "timeout on bulk PUT after %ld%+lds",
954 req->rq_deadline - start,
955 cfs_time_current_sec() -
957 ptlrpc_abort_bulk(desc);
958 } else if (exp->exp_failed) {
959 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
961 ptlrpc_abort_bulk(desc);
962 } else if (exp->exp_abort_active_req) {
963 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk PUT");
964 /* we don't reply anyway */
966 ptlrpc_abort_bulk(desc);
967 } else if (!desc->bd_success ||
968 desc->bd_nob_transferred != desc->bd_nob) {
969 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
971 "truncated" : "network error on",
972 desc->bd_nob_transferred,
974 /* XXX should this be a different errno? */
978 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
984 /* Must commit after prep above in all cases */
985 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
986 remote_nb, npages, local_nb, oti, rc);
989 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
990 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
991 ost_drop_id(exp, &repbody->oa);
995 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
1000 ptlrpc_free_bulk(desc);
1004 req->rq_status = nob;
1005 ptlrpc_lprocfs_brw(req, nob);
1006 target_committed_to_req(req);
1008 } else if (!no_reply) {
1009 /* Only reply if there was no comms problem with bulk */
1010 target_committed_to_req(req);
1011 req->rq_status = rc;
1014 /* reply out callback would free */
1015 ptlrpc_req_drop_rs(req);
1016 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1017 "client will retry\n",
1018 exp->exp_obd->obd_name,
1019 exp->exp_client_uuid.uuid,
1020 exp->exp_connection->c_remote_uuid.uuid,
1021 libcfs_id2str(req->rq_peer));
1027 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
1029 struct ptlrpc_bulk_desc *desc = NULL;
1030 struct obd_export *exp = req->rq_export;
1031 struct niobuf_remote *remote_nb;
1032 struct niobuf_local *local_nb;
1033 struct obd_ioobj *ioo;
1034 struct ost_body *body, *repbody;
1035 struct l_wait_info lwi;
1036 struct lustre_handle lockh = {0};
1037 struct lustre_capa *capa = NULL;
1039 int objcount, niocount, npages;
1041 obd_count client_cksum = 0, server_cksum = 0;
1042 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
1043 int no_reply = 0, mmap = 0;
1044 __u32 o_uid = 0, o_gid = 0;
1045 struct ost_thread_local_cache *tls;
1048 req->rq_bulk_write = 1;
1050 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
1051 GOTO(out, rc = -EIO);
1052 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
1053 GOTO(out, rc = -EFAULT);
1055 /* pause before transaction has been started */
1056 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
1058 /* Check if there is eviction in progress, and if so, wait for it to
1060 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
1061 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
1062 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
1063 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
1066 if (exp->exp_failed)
1067 GOTO(out, rc = -ENOTCONN);
1069 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
1070 * ost_rw_hpreq_check(). */
1071 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1073 GOTO(out, rc = -EFAULT);
1075 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1076 RCL_CLIENT) / sizeof(*ioo);
1077 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1079 GOTO(out, rc = -EFAULT);
1081 rc = ost_validate_obdo(exp, &body->oa, ioo);
1085 for (niocount = i = 0; i < objcount; i++)
1086 niocount += ioo[i].ioo_bufcnt;
1089 * It'd be nice to have a capsule function to indicate how many elements
1090 * there were in a buffer for an RMF that's declared to be an array.
1091 * It's easy enough to compute the number of elements here though.
1093 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1094 if (remote_nb == NULL || niocount != (req_capsule_get_size(&req->rq_pill,
1095 &RMF_NIOBUF_REMOTE, RCL_CLIENT) / sizeof(*remote_nb)))
1096 GOTO(out, rc = -EFAULT);
1098 if ((remote_nb[0].flags & OBD_BRW_MEMALLOC) &&
1099 (exp->exp_connection->c_peer.nid == exp->exp_connection->c_self))
1100 cfs_memory_pressure_set();
1102 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
1103 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
1105 CERROR("Missing capability for OST BRW WRITE");
1106 GOTO(out, rc = -EFAULT);
1110 req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER,
1111 niocount * sizeof(*rcs));
1112 rc = req_capsule_server_pack(&req->rq_pill);
1115 CFS_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, cfs_fail_val);
1116 rcs = req_capsule_server_get(&req->rq_pill, &RMF_RCS);
1118 tls = ost_tls_get(req);
1120 GOTO(out_bulk, rc = -ENOMEM);
1121 local_nb = tls->local;
1123 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
1128 * If getting the lock took more time than
1129 * client was willing to wait, drop it. b=11330
1131 if (cfs_time_current_sec() > req->rq_deadline ||
1132 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
1134 CERROR("Dropping timed-out write from %s because locking "
1135 "object "LPX64" took %ld seconds (limit was %ld).\n",
1136 libcfs_id2str(req->rq_peer), ioo->ioo_id,
1137 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
1138 req->rq_deadline - req->rq_arrival_time.tv_sec);
1139 GOTO(out_lock, rc = -ETIMEDOUT);
1142 if (!lustre_handle_is_used(&lockh))
1143 /* no needs to try to prolong lock if server is asked
1144 * to handle locking (= OBD_BRW_SRVLOCK) */
1145 ost_rw_prolong_locks(req, ioo, remote_nb,&body->oa, LCK_PW);
1147 /* obd_preprw clobbers oa->valid, so save what we need */
1148 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
1149 client_cksum = body->oa.o_cksum;
1150 if (body->oa.o_valid & OBD_MD_FLFLAGS)
1151 cksum_type = cksum_type_unpack(body->oa.o_flags);
1153 if (body->oa.o_valid & OBD_MD_FLFLAGS && body->oa.o_flags & OBD_FL_MMAP)
1156 /* Because we already sync grant info with client when reconnect,
1157 * grant info will be cleared for resent req, then fed_grant and
1158 * total_grant will not be modified in following preprw_write */
1159 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1160 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1161 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1164 if (exp_connect_rmtclient(exp)) {
1165 o_uid = body->oa.o_uid;
1166 o_gid = body->oa.o_gid;
1168 npages = OST_THREAD_POOL_SIZE;
1169 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
1170 ioo, remote_nb, &npages, local_nb, oti, capa);
1174 desc = ptlrpc_prep_bulk_exp(req, npages,
1175 BULK_GET_SINK, OST_BULK_PORTAL);
1177 GOTO(skip_transfer, rc = -ENOMEM);
1179 /* NB Having prepped, we must commit... */
1181 for (i = 0; i < npages; i++)
1182 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1183 local_nb[i].offset & ~CFS_PAGE_MASK,
1186 rc = sptlrpc_svc_prep_bulk(req, desc);
1190 /* Check if client was evicted or tried to reconnect while we
1191 * were doing i/o before touching network */
1192 if (desc->bd_export->exp_failed ||
1193 desc->bd_export->exp_abort_active_req)
1196 rc = ptlrpc_start_bulk_transfer(desc);
1198 time_t start = cfs_time_current_sec();
1200 long timeoutl = req->rq_deadline -
1201 cfs_time_current_sec();
1202 cfs_duration_t timeout = timeoutl <= 0 ?
1203 CFS_TICK : cfs_time_seconds(timeoutl);
1204 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
1205 ost_bulk_timeout, desc);
1206 rc = l_wait_event(desc->bd_waitq,
1207 !ptlrpc_server_bulk_active(desc) ||
1208 desc->bd_export->exp_failed ||
1209 desc->bd_export->exp_abort_active_req,
1211 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1212 /* Wait again if we changed deadline */
1213 } while ((rc == -ETIMEDOUT) &&
1214 (req->rq_deadline > cfs_time_current_sec()));
1216 if (rc == -ETIMEDOUT) {
1217 DEBUG_REQ(D_ERROR, req,
1218 "timeout on bulk GET after %ld%+lds",
1219 req->rq_deadline - start,
1220 cfs_time_current_sec() -
1222 ptlrpc_abort_bulk(desc);
1223 } else if (desc->bd_export->exp_failed) {
1224 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1226 ptlrpc_abort_bulk(desc);
1227 } else if (desc->bd_export->exp_abort_active_req) {
1228 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk GET");
1229 /* we don't reply anyway */
1231 ptlrpc_abort_bulk(desc);
1232 } else if (!desc->bd_success) {
1233 DEBUG_REQ(D_ERROR, req, "network error on bulk GET");
1234 /* XXX should this be a different errno? */
1237 rc = sptlrpc_svc_unwrap_bulk(req, desc);
1240 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1245 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
1246 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1248 if (unlikely(client_cksum != 0 && rc == 0)) {
1249 static int cksum_counter;
1250 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1251 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1252 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1253 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1254 repbody->oa.o_cksum = server_cksum;
1256 if (unlikely(client_cksum != server_cksum)) {
1257 CDEBUG_LIMIT(mmap ? D_INFO : D_ERROR,
1258 "client csum %x, server csum %x\n",
1259 client_cksum, server_cksum);
1261 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1262 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1263 cksum_counter, libcfs_id2str(req->rq_peer),
1268 /* Must commit after prep above in all cases */
1269 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1270 remote_nb, npages, local_nb, oti, rc);
1271 if (rc == -ENOTCONN)
1272 /* quota acquire process has been given up because
1273 * either the client has been evicted or the client
1274 * has timed out the request already */
1277 if (exp_connect_rmtclient(exp)) {
1278 repbody->oa.o_uid = o_uid;
1279 repbody->oa.o_gid = o_gid;
1283 * Disable sending mtime back to the client. If the client locked the
1284 * whole object, then it has already updated the mtime on its side,
1285 * otherwise it will have to glimpse anyway (see bug 21489, comment 32)
1287 repbody->oa.o_valid &= ~(OBD_MD_FLMTIME | OBD_MD_FLATIME);
1289 if (unlikely(client_cksum != server_cksum && rc == 0 && !mmap)) {
1290 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1295 if (new_cksum == server_cksum)
1296 msg = "changed in transit before arrival at OST";
1297 else if (new_cksum == client_cksum)
1298 msg = "initial checksum before message complete";
1300 msg = "changed in transit AND after initial checksum";
1302 if (req->rq_peer.nid == desc->bd_sender) {
1306 router = libcfs_nid2str(desc->bd_sender);
1309 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1310 "%s%s%s inode "DFID" object "
1311 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1312 exp->exp_obd->obd_name, msg,
1313 libcfs_id2str(req->rq_peer),
1315 body->oa.o_valid & OBD_MD_FLFID ?
1316 body->oa.o_parent_seq : (__u64)0,
1317 body->oa.o_valid & OBD_MD_FLFID ?
1318 body->oa.o_parent_oid : 0,
1319 body->oa.o_valid & OBD_MD_FLFID ?
1320 body->oa.o_parent_ver : 0,
1322 body->oa.o_valid & OBD_MD_FLGROUP ?
1323 body->oa.o_seq : (__u64)0,
1325 local_nb[npages-1].offset +
1326 local_nb[npages-1].len - 1 );
1327 CERROR("client csum %x, original server csum %x, "
1328 "server csum now %x\n",
1329 client_cksum, server_cksum, new_cksum);
1335 /* set per-requested niobuf return codes */
1336 for (i = j = 0; i < niocount; i++) {
1337 int len = remote_nb[i].len;
1342 LASSERT(j < npages);
1343 if (local_nb[j].rc < 0)
1344 rcs[i] = local_nb[j].rc;
1345 len -= local_nb[j].len;
1350 LASSERT(j == npages);
1351 ptlrpc_lprocfs_brw(req, nob);
1355 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1360 ptlrpc_free_bulk(desc);
1363 oti_to_request(oti, req);
1364 target_committed_to_req(req);
1365 rc = ptlrpc_reply(req);
1366 } else if (!no_reply) {
1367 /* Only reply if there was no comms problem with bulk */
1368 target_committed_to_req(req);
1369 req->rq_status = rc;
1372 /* reply out callback would free */
1373 ptlrpc_req_drop_rs(req);
1374 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1375 "client will retry\n",
1376 exp->exp_obd->obd_name,
1377 exp->exp_client_uuid.uuid,
1378 exp->exp_connection->c_remote_uuid.uuid,
1379 libcfs_id2str(req->rq_peer));
1381 cfs_memory_pressure_clr();
1386 * Implementation of OST_SET_INFO.
1388 * OST_SET_INFO is like ioctl(): heavily overloaded. Specifically, it takes a
1389 * "key" and a value RPC buffers as arguments, with the value's contents
1390 * interpreted according to the key.
1392 * Value types that need swabbing have swabbing done explicitly, either here or
1393 * in functions called from here. This should be corrected: all swabbing should
1394 * be done in the capsule abstraction, as that will then allow us to move
1395 * swabbing exclusively to the client without having to modify server code
1396 * outside the capsule abstraction's implementation itself. To correct this
1397 * will require minor changes to the capsule abstraction; see the comments for
1398 * req_capsule_extend() in layout.c.
1400 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1402 struct ost_body *body = NULL, *repbody;
1403 char *key, *val = NULL;
1404 int keylen, vallen, rc = 0;
1405 int is_grant_shrink = 0;
1408 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1410 DEBUG_REQ(D_HA, req, "no set_info key");
1413 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1416 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1419 if ((is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK)))
1420 /* In this case the value is actually an RMF_OST_BODY, so we
1421 * transmutate the type of this PTLRPC */
1422 req_capsule_extend(&req->rq_pill, &RQF_OST_SET_GRANT_INFO);
1424 rc = req_capsule_server_pack(&req->rq_pill);
1429 if (is_grant_shrink) {
1430 body = req_capsule_client_get(&req->rq_pill,
1435 repbody = req_capsule_server_get(&req->rq_pill,
1437 memcpy(repbody, body, sizeof(*body));
1438 val = (char*)repbody;
1440 val = req_capsule_client_get(&req->rq_pill,
1445 if (KEY_IS(KEY_EVICT_BY_NID)) {
1447 obd_export_evict_by_nid(exp->exp_obd, val);
1449 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1450 if (vallen < sizeof(__u32))
1452 __swab32s((__u32 *)val);
1455 /* OBD will also check if KEY_IS(KEY_GRANT_SHRINK), and will cast val to
1456 * a struct ost_body * value */
1457 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1459 lustre_msg_set_status(req->rq_repmsg, 0);
1463 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1466 int keylen, replylen, rc = 0;
1467 struct req_capsule *pill = &req->rq_pill;
1470 /* this common part for get_info rpc */
1471 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1473 DEBUG_REQ(D_HA, req, "no get_info key");
1476 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1478 if (KEY_IS(KEY_FIEMAP)) {
1479 struct ll_fiemap_info_key *fm_key = key;
1482 rc = ost_validate_obdo(exp, &fm_key->oa, NULL);
1487 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1491 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1492 RCL_SERVER, replylen);
1494 rc = req_capsule_server_pack(pill);
1498 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1502 /* call again to fill in the reply buffer */
1503 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1505 lustre_msg_set_status(req->rq_repmsg, 0);
1509 #ifdef HAVE_QUOTA_SUPPORT
1510 static int ost_handle_quotactl(struct ptlrpc_request *req)
1512 struct obd_quotactl *oqctl, *repoqc;
1516 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1518 GOTO(out, rc = -EPROTO);
1520 rc = req_capsule_server_pack(&req->rq_pill);
1524 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1525 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1532 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1534 struct obd_quotactl *oqctl;
1538 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1542 rc = req_capsule_server_pack(&req->rq_pill);
1546 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1550 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1552 struct quota_adjust_qunit *oqaq, *repoqa;
1553 struct lustre_quota_ctxt *qctxt;
1557 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1558 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1560 GOTO(out, rc = -EPROTO);
1562 rc = req_capsule_server_pack(&req->rq_pill);
1566 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1567 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt, NULL);
1575 static int ost_llog_handle_connect(struct obd_export *exp,
1576 struct ptlrpc_request *req)
1578 struct llogd_conn_body *body;
1582 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
1583 rc = obd_llog_connect(exp, body);
1587 #define ost_init_sec_none(reply, exp) \
1589 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1590 OBD_CONNECT_RMT_CLIENT_FORCE | \
1591 OBD_CONNECT_OSS_CAPA); \
1592 cfs_spin_lock(&exp->exp_lock); \
1593 exp->exp_connect_flags = reply->ocd_connect_flags; \
1594 cfs_spin_unlock(&exp->exp_lock); \
1597 static int ost_init_sec_level(struct ptlrpc_request *req)
1599 struct obd_export *exp = req->rq_export;
1600 struct req_capsule *pill = &req->rq_pill;
1601 struct obd_device *obd = exp->exp_obd;
1602 struct filter_obd *filter = &obd->u.filter;
1603 char *client = libcfs_nid2str(req->rq_peer.nid);
1604 struct obd_connect_data *data, *reply;
1608 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1609 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1610 if (data == NULL || reply == NULL)
1613 /* connection from MDT is always trusted */
1614 if (req->rq_auth_usr_mdt) {
1615 ost_init_sec_none(reply, exp);
1619 /* no GSS support case */
1620 if (!req->rq_auth_gss) {
1621 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1622 CWARN("client %s -> target %s does not user GSS, "
1623 "can not run under security level %d.\n",
1624 client, obd->obd_name, filter->fo_sec_level);
1627 ost_init_sec_none(reply, exp);
1632 /* old version case */
1633 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1634 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1635 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1636 CWARN("client %s -> target %s uses old version, "
1637 "can not run under security level %d.\n",
1638 client, obd->obd_name, filter->fo_sec_level);
1641 CWARN("client %s -> target %s uses old version, "
1642 "run under security level %d.\n",
1643 client, obd->obd_name, filter->fo_sec_level);
1644 ost_init_sec_none(reply, exp);
1649 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1651 if (!req->rq_auth_remote)
1652 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1653 "asked to be remote.\n", client, obd->obd_name);
1654 } else if (req->rq_auth_remote) {
1656 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1657 "as remote by default.\n", client, obd->obd_name);
1661 if (!filter->fo_fl_oss_capa) {
1662 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1663 " but OSS capabilities are not enabled: %d.\n",
1664 client, obd->obd_name, filter->fo_fl_oss_capa);
1669 switch (filter->fo_sec_level) {
1670 case LUSTRE_SEC_NONE:
1672 ost_init_sec_none(reply, exp);
1675 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1676 "can not run under security level %d.\n",
1677 client, obd->obd_name, filter->fo_sec_level);
1680 case LUSTRE_SEC_REMOTE:
1682 ost_init_sec_none(reply, exp);
1684 case LUSTRE_SEC_ALL:
1686 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1687 OBD_CONNECT_RMT_CLIENT_FORCE);
1688 if (!filter->fo_fl_oss_capa)
1689 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1691 cfs_spin_lock(&exp->exp_lock);
1692 exp->exp_connect_flags = reply->ocd_connect_flags;
1693 cfs_spin_unlock(&exp->exp_lock);
1705 * this should be done in filter_connect()/filter_reconnect(), but
1706 * we can't obtain information like NID, which stored in incoming
1707 * request, thus can't decide what flavor to use. so we do it here.
1709 * This hack should be removed after the OST stack be rewritten, just
1710 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1712 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1714 struct obd_export *exp = req->rq_export;
1715 struct filter_obd *filter = &exp->exp_obd->u.filter;
1716 struct sptlrpc_flavor flvr;
1719 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1720 LUSTRE_ECHO_NAME) == 0)) {
1721 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1725 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1726 cfs_read_lock(&filter->fo_sptlrpc_lock);
1727 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1731 cfs_read_unlock(&filter->fo_sptlrpc_lock);
1733 cfs_spin_lock(&exp->exp_lock);
1735 exp->exp_sp_peer = req->rq_sp_from;
1736 exp->exp_flvr = flvr;
1738 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1739 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1740 CERROR("unauthorized rpc flavor %x from %s, "
1741 "expect %x\n", req->rq_flvr.sf_rpc,
1742 libcfs_nid2str(req->rq_peer.nid),
1743 exp->exp_flvr.sf_rpc);
1747 cfs_spin_unlock(&exp->exp_lock);
1749 if (exp->exp_sp_peer != req->rq_sp_from) {
1750 CERROR("RPC source %s doesn't match %s\n",
1751 sptlrpc_part2name(req->rq_sp_from),
1752 sptlrpc_part2name(exp->exp_sp_peer));
1755 rc = sptlrpc_target_export_check(exp, req);
1762 /* Ensure that data and metadata are synced to the disk when lock is cancelled
1764 int ost_blocking_ast(struct ldlm_lock *lock,
1765 struct ldlm_lock_desc *desc,
1766 void *data, int flag)
1768 __u32 sync_lock_cancel = 0;
1769 __u32 len = sizeof(sync_lock_cancel);
1773 rc = obd_get_info(lock->l_export, sizeof(KEY_SYNC_LOCK_CANCEL),
1774 KEY_SYNC_LOCK_CANCEL, &len, &sync_lock_cancel, NULL);
1776 if (!rc && flag == LDLM_CB_CANCELING &&
1777 (lock->l_granted_mode & (LCK_PW|LCK_GROUP)) &&
1778 (sync_lock_cancel == ALWAYS_SYNC_ON_CANCEL ||
1779 (sync_lock_cancel == BLOCKING_SYNC_ON_CANCEL &&
1780 lock->l_flags & LDLM_FL_CBPENDING))) {
1781 struct obd_info *oinfo;
1785 OBD_ALLOC_PTR(oinfo);
1793 oa->o_id = lock->l_resource->lr_name.name[0];
1794 oa->o_seq = lock->l_resource->lr_name.name[1];
1795 oa->o_valid = OBD_MD_FLID|OBD_MD_FLGROUP;
1798 rc = obd_sync(lock->l_export, oinfo,
1799 lock->l_policy_data.l_extent.start,
1800 lock->l_policy_data.l_extent.end, NULL);
1802 CERROR("Error %d syncing data on lock cancel\n", rc);
1805 OBD_FREE_PTR(oinfo);
1808 rc = ldlm_server_blocking_ast(lock, desc, data, flag);
1812 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1813 struct obd_device *obd, int *process)
1815 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1816 case OST_CONNECT: /* This will never get here, but for completeness. */
1817 case OST_DISCONNECT:
1828 case OBD_LOG_CANCEL:
1830 *process = target_queue_recovery_request(req, obd);
1834 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1840 int ost_msg_check_version(struct lustre_msg *msg)
1844 switch(lustre_msg_get_opc(msg)) {
1846 case OST_DISCONNECT:
1849 case SEC_CTX_INIT_CONT:
1851 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1853 CERROR("bad opc %u version %08x, expecting %08x\n",
1854 lustre_msg_get_opc(msg),
1855 lustre_msg_get_version(msg),
1856 LUSTRE_OBD_VERSION);
1869 #ifdef HAVE_QUOTA_SUPPORT
1870 case OST_QUOTACHECK:
1872 case OST_QUOTA_ADJUST_QUNIT:
1874 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1876 CERROR("bad opc %u version %08x, expecting %08x\n",
1877 lustre_msg_get_opc(msg),
1878 lustre_msg_get_version(msg),
1879 LUSTRE_OST_VERSION);
1884 case LDLM_BL_CALLBACK:
1885 case LDLM_CP_CALLBACK:
1886 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1888 CERROR("bad opc %u version %08x, expecting %08x\n",
1889 lustre_msg_get_opc(msg),
1890 lustre_msg_get_version(msg),
1891 LUSTRE_DLM_VERSION);
1893 case LLOG_ORIGIN_CONNECT:
1894 case OBD_LOG_CANCEL:
1895 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1897 CERROR("bad opc %u version %08x, expecting %08x\n",
1898 lustre_msg_get_opc(msg),
1899 lustre_msg_get_version(msg),
1900 LUSTRE_LOG_VERSION);
1903 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1910 * Returns 1 if the given PTLRPC matches the given LDLM locks, or 0 if it does
1913 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1914 struct ldlm_lock *lock)
1916 struct niobuf_remote *nb;
1917 struct obd_ioobj *ioo;
1918 struct ost_body *body;
1919 int objcount, niocount;
1920 int mode, opc, i, rc;
1924 opc = lustre_msg_get_opc(req->rq_reqmsg);
1925 LASSERT(opc == OST_READ || opc == OST_WRITE);
1927 /* As the request may be covered by several locks, do not look at
1928 * o_handle, look at the RPC IO region. */
1929 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1933 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1934 RCL_CLIENT) / sizeof(*ioo);
1935 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1939 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
1943 for (niocount = i = 0; i < objcount; i++)
1944 niocount += ioo[i].ioo_bufcnt;
1946 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1948 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
1949 RCL_CLIENT) / sizeof(*nb)))
1953 if (opc == OST_READ)
1956 start = nb[0].offset & CFS_PAGE_MASK;
1957 end = (nb[ioo->ioo_bufcnt - 1].offset +
1958 nb[ioo->ioo_bufcnt - 1].len - 1) | ~CFS_PAGE_MASK;
1960 LASSERT(lock->l_resource != NULL);
1961 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_seq,
1962 &lock->l_resource->lr_name))
1965 if (!(lock->l_granted_mode & mode))
1968 if (lock->l_policy_data.l_extent.end < start ||
1969 lock->l_policy_data.l_extent.start > end)
1976 * High-priority queue request check for whether the given PTLRPC request (\a
1977 * req) is blocking an LDLM lock cancel.
1979 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1980 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1982 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1983 * function looks only at OST_READs and OST_WRITEs.
1985 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1987 struct niobuf_remote *nb;
1988 struct obd_ioobj *ioo;
1989 struct ost_body *body;
1990 int objcount, niocount;
1991 int mode, opc, i, rc;
1994 opc = lustre_msg_get_opc(req->rq_reqmsg);
1995 LASSERT(opc == OST_READ || opc == OST_WRITE);
1997 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
2001 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
2002 RCL_CLIENT) / sizeof(*ioo);
2003 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
2007 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
2011 for (niocount = i = 0; i < objcount; i++)
2012 niocount += ioo[i].ioo_bufcnt;
2013 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
2015 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
2016 RCL_CLIENT) / sizeof(*nb)))
2018 if (niocount != 0 && (nb[0].flags & OBD_BRW_SRVLOCK))
2022 if (opc == OST_READ)
2024 RETURN(ost_rw_prolong_locks(req, ioo, nb, &body->oa, mode));
2027 static int ost_punch_prolong_locks(struct ptlrpc_request *req, struct obdo *oa)
2029 struct ldlm_res_id res_id = { .name = { oa->o_id } };
2030 struct ost_prolong_data opd = { 0 };
2035 end = start + oa->o_blocks;
2037 opd.opd_mode = LCK_PW;
2038 opd.opd_exp = req->rq_export;
2039 opd.opd_policy.l_extent.start = start & CFS_PAGE_MASK;
2040 if (oa->o_blocks == OBD_OBJECT_EOF || end < start)
2041 opd.opd_policy.l_extent.end = OBD_OBJECT_EOF;
2043 opd.opd_policy.l_extent.end = end | ~CFS_PAGE_MASK;
2045 /* prolong locks for the current service time of the corresponding
2046 * portal (= OST_IO_PORTAL) */
2047 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
2048 max(at_est2timeout(at_get(&req->rq_rqbd->
2049 rqbd_service->srv_at_estimate)), ldlm_timeout);
2051 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
2052 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
2053 opd.opd_policy.l_extent.end);
2056 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
2057 ost_prolong_locks_iter, &opd);
2058 RETURN(opd.opd_lock_match);
2062 * Like ost_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
2064 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
2065 struct ldlm_lock *lock)
2067 struct ost_body *body;
2071 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
2073 RETURN(0); /* can't return -EFAULT here */
2075 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
2079 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
2080 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
2086 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
2088 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
2090 struct ost_body *body;
2093 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
2097 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
2101 LASSERT(!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
2102 !(body->oa.o_flags & OBD_FL_SRVLOCK));
2104 RETURN(ost_punch_prolong_locks(req, &body->oa));
2107 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
2108 .hpreq_lock_match = ost_rw_hpreq_lock_match,
2109 .hpreq_check = ost_rw_hpreq_check,
2112 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
2113 .hpreq_lock_match = ost_punch_hpreq_lock_match,
2114 .hpreq_check = ost_punch_hpreq_check,
2117 /** Assign high priority operations to the request if needed. */
2118 static int ost_hpreq_handler(struct ptlrpc_request *req)
2121 if (req->rq_export) {
2122 int opc = lustre_msg_get_opc(req->rq_reqmsg);
2123 struct ost_body *body;
2125 if (opc == OST_READ || opc == OST_WRITE) {
2126 struct niobuf_remote *nb;
2127 struct obd_ioobj *ioo;
2128 int objcount, niocount;
2131 /* RPCs on the H-P queue can be inspected before
2132 * ost_handler() initializes their pills, so we
2133 * initialize that here. Capsule initialization is
2134 * idempotent, as is setting the pill's format (provided
2135 * it doesn't change).
2137 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2138 if (opc == OST_READ)
2139 req_capsule_set(&req->rq_pill,
2142 req_capsule_set(&req->rq_pill,
2143 &RQF_OST_BRW_WRITE);
2145 body = req_capsule_client_get(&req->rq_pill,
2148 CERROR("Missing/short ost_body\n");
2152 objcount = req_capsule_get_size(&req->rq_pill,
2156 if (objcount == 0) {
2157 CERROR("Missing/short ioobj\n");
2161 CERROR("too many ioobjs (%d)\n", objcount);
2165 ioo = req_capsule_client_get(&req->rq_pill,
2168 CERROR("Missing/short ioobj\n");
2172 for (niocount = i = 0; i < objcount; i++) {
2173 if (ioo[i].ioo_bufcnt == 0) {
2174 CERROR("ioo[%d] has zero bufcnt\n", i);
2177 niocount += ioo[i].ioo_bufcnt;
2179 if (niocount > PTLRPC_MAX_BRW_PAGES) {
2180 DEBUG_REQ(D_RPCTRACE, req,
2181 "bulk has too many pages (%d)",
2186 nb = req_capsule_client_get(&req->rq_pill,
2187 &RMF_NIOBUF_REMOTE);
2189 CERROR("Missing/short niobuf\n");
2193 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
2194 req->rq_ops = &ost_hpreq_rw;
2195 } else if (opc == OST_PUNCH) {
2196 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2197 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2199 body = req_capsule_client_get(&req->rq_pill,
2202 CERROR("Missing/short ost_body\n");
2206 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
2207 !(body->oa.o_flags & OBD_FL_SRVLOCK))
2208 req->rq_ops = &ost_hpreq_punch;
2214 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
2215 int ost_handle(struct ptlrpc_request *req)
2217 struct obd_trans_info trans_info = { 0, };
2218 struct obd_trans_info *oti = &trans_info;
2219 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
2220 struct obd_device *obd = NULL;
2223 LASSERT(current->journal_info == NULL);
2225 /* primordial rpcs don't affect server recovery */
2226 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2228 case SEC_CTX_INIT_CONT:
2233 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2235 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
2236 if (!class_connected_export(req->rq_export)) {
2237 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
2238 lustre_msg_get_opc(req->rq_reqmsg),
2239 libcfs_id2str(req->rq_peer));
2240 req->rq_status = -ENOTCONN;
2241 GOTO(out, rc = -ENOTCONN);
2244 obd = req->rq_export->exp_obd;
2246 /* Check for aborted recovery. */
2247 if (obd->obd_recovering) {
2248 rc = ost_filter_recovery_request(req, obd,
2250 if (rc || !should_process)
2252 else if (should_process < 0) {
2253 req->rq_status = should_process;
2254 rc = ptlrpc_error(req);
2262 rc = ost_msg_check_version(req->rq_reqmsg);
2266 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2268 CDEBUG(D_INODE, "connect\n");
2269 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
2270 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
2272 rc = target_handle_connect(req);
2273 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
2276 rc = ost_init_sec_level(req);
2278 rc = ost_connect_check_sptlrpc(req);
2282 case OST_DISCONNECT:
2283 CDEBUG(D_INODE, "disconnect\n");
2284 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
2285 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
2287 rc = target_handle_disconnect(req);
2290 CDEBUG(D_INODE, "create\n");
2291 req_capsule_set(&req->rq_pill, &RQF_OST_CREATE);
2292 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
2294 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2295 GOTO(out, rc = -EROFS);
2296 rc = ost_create(req->rq_export, req, oti);
2299 CDEBUG(D_INODE, "destroy\n");
2300 req_capsule_set(&req->rq_pill, &RQF_OST_DESTROY);
2301 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
2303 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2304 GOTO(out, rc = -EROFS);
2305 rc = ost_destroy(req->rq_export, req, oti);
2308 CDEBUG(D_INODE, "getattr\n");
2309 req_capsule_set(&req->rq_pill, &RQF_OST_GETATTR);
2310 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
2312 rc = ost_getattr(req->rq_export, req);
2315 CDEBUG(D_INODE, "setattr\n");
2316 req_capsule_set(&req->rq_pill, &RQF_OST_SETATTR);
2317 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
2319 rc = ost_setattr(req->rq_export, req, oti);
2322 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_WRITE);
2323 CDEBUG(D_INODE, "write\n");
2324 /* req->rq_request_portal would be nice, if it was set */
2325 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2326 CERROR("%s: deny write request from %s to portal %u\n",
2327 req->rq_export->exp_obd->obd_name,
2328 obd_export_nid2str(req->rq_export),
2329 req->rq_rqbd->rqbd_service->srv_req_portal);
2330 GOTO(out, rc = -EPROTO);
2332 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2334 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
2335 GOTO(out, rc = -ENOSPC);
2336 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2337 GOTO(out, rc = -EROFS);
2338 rc = ost_brw_write(req, oti);
2339 LASSERT(current->journal_info == NULL);
2340 /* ost_brw_write sends its own replies */
2343 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_READ);
2344 CDEBUG(D_INODE, "read\n");
2345 /* req->rq_request_portal would be nice, if it was set */
2346 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2347 CERROR("%s: deny read request from %s to portal %u\n",
2348 req->rq_export->exp_obd->obd_name,
2349 obd_export_nid2str(req->rq_export),
2350 req->rq_rqbd->rqbd_service->srv_req_portal);
2351 GOTO(out, rc = -EPROTO);
2353 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2355 rc = ost_brw_read(req, oti);
2356 LASSERT(current->journal_info == NULL);
2357 /* ost_brw_read sends its own replies */
2360 CDEBUG(D_INODE, "punch\n");
2361 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2362 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2364 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2365 GOTO(out, rc = -EROFS);
2366 rc = ost_punch(req->rq_export, req, oti);
2369 CDEBUG(D_INODE, "statfs\n");
2370 req_capsule_set(&req->rq_pill, &RQF_OST_STATFS);
2371 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2373 rc = ost_statfs(req);
2376 CDEBUG(D_INODE, "sync\n");
2377 req_capsule_set(&req->rq_pill, &RQF_OST_SYNC);
2378 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2380 rc = ost_sync(req->rq_export, req);
2383 DEBUG_REQ(D_INODE, req, "set_info");
2384 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
2385 rc = ost_set_info(req->rq_export, req);
2388 DEBUG_REQ(D_INODE, req, "get_info");
2389 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
2390 rc = ost_get_info(req->rq_export, req);
2392 #ifdef HAVE_QUOTA_SUPPORT
2393 case OST_QUOTACHECK:
2394 CDEBUG(D_INODE, "quotacheck\n");
2395 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2396 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2398 rc = ost_handle_quotacheck(req);
2401 CDEBUG(D_INODE, "quotactl\n");
2402 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2403 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2405 rc = ost_handle_quotactl(req);
2407 case OST_QUOTA_ADJUST_QUNIT:
2408 CDEBUG(D_INODE, "quota_adjust_qunit\n");
2409 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
2410 rc = ost_handle_quota_adjust_qunit(req);
2414 DEBUG_REQ(D_INODE, req, "ping");
2415 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2416 rc = target_handle_ping(req);
2418 /* FIXME - just reply status */
2419 case LLOG_ORIGIN_CONNECT:
2420 DEBUG_REQ(D_INODE, req, "log connect");
2421 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2422 rc = ost_llog_handle_connect(req->rq_export, req);
2423 req->rq_status = rc;
2424 rc = req_capsule_server_pack(&req->rq_pill);
2427 RETURN(ptlrpc_reply(req));
2428 case OBD_LOG_CANCEL:
2429 CDEBUG(D_INODE, "log cancel\n");
2430 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2431 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2433 rc = llog_origin_handle_cancel(req);
2434 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2436 req->rq_status = rc;
2437 rc = req_capsule_server_pack(&req->rq_pill);
2440 RETURN(ptlrpc_reply(req));
2442 CDEBUG(D_INODE, "enqueue\n");
2443 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2444 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2446 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2448 ldlm_server_glimpse_ast);
2449 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2452 CDEBUG(D_INODE, "convert\n");
2453 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2454 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2456 rc = ldlm_handle_convert(req);
2459 CDEBUG(D_INODE, "cancel\n");
2460 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2461 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2463 rc = ldlm_handle_cancel(req);
2465 case LDLM_BL_CALLBACK:
2466 case LDLM_CP_CALLBACK:
2467 CDEBUG(D_INODE, "callback\n");
2468 CERROR("callbacks should not happen on OST\n");
2471 CERROR("Unexpected opcode %d\n",
2472 lustre_msg_get_opc(req->rq_reqmsg));
2473 req->rq_status = -ENOTSUPP;
2474 rc = ptlrpc_error(req);
2478 LASSERT(current->journal_info == NULL);
2481 /* If we're DISCONNECTing, the export_data is already freed */
2482 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2483 target_committed_to_req(req);
2487 oti_to_request(oti, req);
2489 target_send_reply(req, rc, fail);
2492 EXPORT_SYMBOL(ost_handle);
2494 * free per-thread pool created by ost_thread_init().
2496 static void ost_thread_done(struct ptlrpc_thread *thread)
2498 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2503 LASSERT(thread != NULL);
2506 * be prepared to handle partially-initialized pools (because this is
2507 * called from ost_thread_init() for cleanup.
2509 tls = thread->t_data;
2512 thread->t_data = NULL;
2518 * initialize per-thread page pool (bug 5137).
2520 static int ost_thread_init(struct ptlrpc_thread *thread)
2522 struct ost_thread_local_cache *tls;
2526 LASSERT(thread != NULL);
2527 LASSERT(thread->t_data == NULL);
2528 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
2533 thread->t_data = tls;
2537 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2539 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2540 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2542 struct ost_obd *ost = &obd->u.ost;
2543 struct lprocfs_static_vars lvars;
2544 int oss_min_threads;
2545 int oss_max_threads;
2546 int oss_min_create_threads;
2547 int oss_max_create_threads;
2551 rc = cfs_cleanup_group_info();
2555 lprocfs_ost_init_vars(&lvars);
2556 lprocfs_obd_setup(obd, lvars.obd_vars);
2558 cfs_sema_init(&ost->ost_health_sem, 1);
2560 if (oss_num_threads) {
2561 /* If oss_num_threads is set, it is the min and the max. */
2562 if (oss_num_threads > OSS_THREADS_MAX)
2563 oss_num_threads = OSS_THREADS_MAX;
2564 if (oss_num_threads < OSS_THREADS_MIN)
2565 oss_num_threads = OSS_THREADS_MIN;
2566 oss_max_threads = oss_min_threads = oss_num_threads;
2568 /* Base min threads on memory and cpus */
2570 cfs_num_possible_cpus() * CFS_NUM_CACHEPAGES >>
2571 (27 - CFS_PAGE_SHIFT);
2572 if (oss_min_threads < OSS_THREADS_MIN)
2573 oss_min_threads = OSS_THREADS_MIN;
2574 /* Insure a 4x range for dynamic threads */
2575 if (oss_min_threads > OSS_THREADS_MAX / 4)
2576 oss_min_threads = OSS_THREADS_MAX / 4;
2577 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
2581 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2582 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
2583 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2584 ost_handle, LUSTRE_OSS_NAME,
2585 obd->obd_proc_entry, target_print_req,
2586 oss_min_threads, oss_max_threads,
2587 "ll_ost", LCT_DT_THREAD, NULL);
2588 if (ost->ost_service == NULL) {
2589 CERROR("failed to start service\n");
2590 GOTO(out_lprocfs, rc = -ENOMEM);
2593 rc = ptlrpc_start_threads(ost->ost_service);
2595 GOTO(out_service, rc = -EINVAL);
2597 if (oss_num_create_threads) {
2598 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
2599 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
2600 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
2601 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
2602 oss_min_create_threads = oss_max_create_threads =
2603 oss_num_create_threads;
2605 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
2606 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
2609 ost->ost_create_service =
2610 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2611 OST_MAXREPSIZE, OST_CREATE_PORTAL,
2612 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2613 ost_handle, "ost_create",
2614 obd->obd_proc_entry, target_print_req,
2615 oss_min_create_threads, oss_max_create_threads,
2616 "ll_ost_creat", LCT_DT_THREAD, NULL);
2617 if (ost->ost_create_service == NULL) {
2618 CERROR("failed to start OST create service\n");
2619 GOTO(out_service, rc = -ENOMEM);
2622 rc = ptlrpc_start_threads(ost->ost_create_service);
2624 GOTO(out_create, rc = -EINVAL);
2626 ost->ost_io_service =
2627 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2628 OST_MAXREPSIZE, OST_IO_PORTAL,
2629 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2630 ost_handle, "ost_io",
2631 obd->obd_proc_entry, target_print_req,
2632 oss_min_threads, oss_max_threads,
2633 "ll_ost_io", LCT_DT_THREAD, ost_hpreq_handler);
2634 if (ost->ost_io_service == NULL) {
2635 CERROR("failed to start OST I/O service\n");
2636 GOTO(out_create, rc = -ENOMEM);
2639 ost->ost_io_service->srv_init = ost_thread_init;
2640 ost->ost_io_service->srv_done = ost_thread_done;
2641 ost->ost_io_service->srv_cpu_affinity = 1;
2642 rc = ptlrpc_start_threads(ost->ost_io_service);
2644 GOTO(out_io, rc = -EINVAL);
2646 ping_evictor_start();
2651 ptlrpc_unregister_service(ost->ost_io_service);
2652 ost->ost_io_service = NULL;
2654 ptlrpc_unregister_service(ost->ost_create_service);
2655 ost->ost_create_service = NULL;
2657 ptlrpc_unregister_service(ost->ost_service);
2658 ost->ost_service = NULL;
2660 lprocfs_obd_cleanup(obd);
2664 static int ost_cleanup(struct obd_device *obd)
2666 struct ost_obd *ost = &obd->u.ost;
2670 ping_evictor_stop();
2672 /* there is no recovery for OST OBD, all recovery is controlled by
2674 LASSERT(obd->obd_recovering == 0);
2675 cfs_down(&ost->ost_health_sem);
2676 ptlrpc_unregister_service(ost->ost_service);
2677 ptlrpc_unregister_service(ost->ost_create_service);
2678 ptlrpc_unregister_service(ost->ost_io_service);
2679 ost->ost_service = NULL;
2680 ost->ost_create_service = NULL;
2681 cfs_up(&ost->ost_health_sem);
2683 lprocfs_obd_cleanup(obd);
2688 static int ost_health_check(struct obd_device *obd)
2690 struct ost_obd *ost = &obd->u.ost;
2693 cfs_down(&ost->ost_health_sem);
2694 rc |= ptlrpc_service_health_check(ost->ost_service);
2695 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2696 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2697 cfs_up(&ost->ost_health_sem);
2700 * health_check to return 0 on healthy
2701 * and 1 on unhealthy.
2709 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2711 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2714 /* use obd ops to offer management infrastructure */
2715 static struct obd_ops ost_obd_ops = {
2716 .o_owner = THIS_MODULE,
2717 .o_setup = ost_setup,
2718 .o_cleanup = ost_cleanup,
2719 .o_health_check = ost_health_check,
2723 static int __init ost_init(void)
2725 struct lprocfs_static_vars lvars;
2729 lprocfs_ost_init_vars(&lvars);
2730 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2731 LUSTRE_OSS_NAME, NULL);
2733 if (ost_num_threads != 0 && oss_num_threads == 0) {
2734 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2735 "use oss_num_threads instead or unset both for "
2736 "dynamic thread startup\n");
2737 oss_num_threads = ost_num_threads;
2743 static void /*__exit*/ ost_exit(void)
2745 class_unregister_type(LUSTRE_OSS_NAME);
2748 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2749 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2750 MODULE_LICENSE("GPL");
2752 module_init(ost_init);
2753 module_exit(ost_exit);