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.
32 * Copyright (c) 2011 Whamcloud, Inc.
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
39 * lustre/ost/ost_handler.c
41 * Author: Peter J. Braam <braam@clusterfs.com>
42 * Author: Phil Schwan <phil@clusterfs.com>
46 # define EXPORT_SYMTAB
48 #define DEBUG_SUBSYSTEM S_OST
50 #include <linux/module.h>
51 #include <obd_cksum.h>
53 #include <lustre_net.h>
54 #include <lustre_dlm.h>
55 #include <lustre_export.h>
56 #include <lustre_debug.h>
57 #include <linux/init.h>
58 #include <lprocfs_status.h>
59 #include <libcfs/list.h>
60 #include <lustre_quota.h>
61 #include "ost_internal.h"
63 static int oss_num_threads;
64 CFS_MODULE_PARM(oss_num_threads, "i", int, 0444,
65 "number of OSS service threads to start");
67 static int ost_num_threads;
68 CFS_MODULE_PARM(ost_num_threads, "i", int, 0444,
69 "number of OST service threads to start (deprecated)");
71 static int oss_num_create_threads;
72 CFS_MODULE_PARM(oss_num_create_threads, "i", int, 0444,
73 "number of OSS create threads to start");
76 * Do not return server-side uid/gid to remote client
78 static void ost_drop_id(struct obd_export *exp, struct obdo *oa)
80 if (exp_connect_rmtclient(exp)) {
83 oa->o_valid &= ~(OBD_MD_FLUID | OBD_MD_FLGID);
88 * Validate oa from client.
89 * If the request comes from 2.0 clients, currently only RSVD seq and IDIF
91 * a. for single MDS seq = FID_SEQ_OST_MDT0,
92 * b. for CMD, seq = FID_SEQ_OST_MDT0, FID_SEQ_OST_MDT1 - FID_SEQ_OST_MAX
94 static int ost_validate_obdo(struct obd_export *exp, struct obdo *oa,
95 struct obd_ioobj *ioobj)
97 if (oa != NULL && !(oa->o_valid & OBD_MD_FLGROUP)) {
98 oa->o_seq = FID_SEQ_OST_MDT0;
100 ioobj->ioo_seq = FID_SEQ_OST_MDT0;
101 /* remove fid_seq_is_rsvd() after FID-on-OST allows SEQ > 9 */
102 } else if (oa == NULL ||
103 !(fid_seq_is_rsvd(oa->o_seq) || fid_seq_is_idif(oa->o_seq))) {
104 CERROR("%s: client %s sent invalid object "POSTID"\n",
105 exp->exp_obd->obd_name, obd_export_nid2str(exp),
106 oa ? oa->o_id : -1, oa ? oa->o_seq : -1);
109 obdo_from_ostid(oa, &oa->o_oi);
111 ioobj_from_obdo(ioobj, oa);
115 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
117 struct oti_req_ack_lock *ack_lock;
123 if (req->rq_repmsg) {
124 __u64 versions[PTLRPC_NUM_VERSIONS] = { 0 };
125 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
126 versions[0] = oti->oti_pre_version;
127 lustre_msg_set_versions(req->rq_repmsg, versions);
129 req->rq_transno = oti->oti_transno;
131 /* XXX 4 == entries in oti_ack_locks??? */
132 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
135 /* XXX not even calling target_send_reply in some cases... */
136 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode, 0);
140 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
141 struct obd_trans_info *oti)
143 struct ost_body *body, *repbody;
144 struct lustre_capa *capa = NULL;
148 /* Get the request body */
149 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
153 if (body->oa.o_id == 0)
156 rc = ost_validate_obdo(exp, &body->oa, NULL);
160 /* If there's a DLM request, cancel the locks mentioned in it*/
161 if (req_capsule_field_present(&req->rq_pill, &RMF_DLM_REQ, RCL_CLIENT)) {
162 struct ldlm_request *dlm;
164 dlm = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
167 ldlm_request_cancel(req, dlm, 0);
170 /* If there's a capability, get it */
171 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
172 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
174 CERROR("Missing capability for OST DESTROY");
179 /* Prepare the reply */
180 rc = req_capsule_server_pack(&req->rq_pill);
184 /* Get the log cancellation cookie */
185 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
186 oti->oti_logcookies = &body->oa.o_lcookie;
188 /* Finish the reply */
189 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
190 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
192 /* Do the destroy and set the reply status accordingly */
193 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL, capa);
198 * Helper function for getting server side [start, start+count] DLM lock
199 * if asked by client.
201 static int ost_lock_get(struct obd_export *exp, struct obdo *oa,
202 __u64 start, __u64 count, struct lustre_handle *lh,
205 struct ldlm_res_id res_id;
206 ldlm_policy_data_t policy;
207 __u64 end = start + count;
211 LASSERT(!lustre_handle_is_used(lh));
212 /* o_id and o_gr are used for localizing resource, if client miss to set
213 * them, do not trigger ASSERTION. */
214 if (unlikely((oa->o_valid & (OBD_MD_FLID | OBD_MD_FLGROUP)) !=
215 (OBD_MD_FLID | OBD_MD_FLGROUP)))
218 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
219 !(oa->o_flags & OBD_FL_SRVLOCK))
222 osc_build_res_name(oa->o_id, oa->o_seq, &res_id);
223 CDEBUG(D_INODE, "OST-side extent lock.\n");
225 policy.l_extent.start = start & CFS_PAGE_MASK;
227 /* If ->o_blocks is EOF it means "lock till the end of the
228 * file". Otherwise, it's size of a hole being punched (in bytes) */
229 if (count == OBD_OBJECT_EOF || end < start)
230 policy.l_extent.end = OBD_OBJECT_EOF;
232 policy.l_extent.end = end | ~CFS_PAGE_MASK;
234 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
235 LDLM_EXTENT, &policy, mode, &flags,
236 ldlm_blocking_ast, ldlm_completion_ast,
237 ldlm_glimpse_ast, NULL, 0, NULL, lh));
240 /* Helper function: release lock, if any. */
241 static void ost_lock_put(struct obd_export *exp,
242 struct lustre_handle *lh, int mode)
245 if (lustre_handle_is_used(lh))
246 ldlm_lock_decref(lh, mode);
250 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
252 struct ost_body *body, *repbody;
253 struct obd_info *oinfo;
254 struct lustre_handle lh = { 0 };
255 struct lustre_capa *capa = NULL;
259 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
263 rc = ost_validate_obdo(exp, &body->oa, NULL);
267 rc = req_capsule_server_pack(&req->rq_pill);
271 rc = ost_lock_get(exp, &body->oa, 0, OBD_OBJECT_EOF, &lh, LCK_PR, 0);
275 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
276 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
278 CERROR("Missing capability for OST GETATTR");
279 GOTO(unlock, rc = -EFAULT);
283 OBD_ALLOC_PTR(oinfo);
285 GOTO(unlock, rc = -ENOMEM);
286 oinfo->oi_oa = &body->oa;
287 oinfo->oi_capa = capa;
289 req->rq_status = obd_getattr(exp, oinfo);
293 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
294 repbody->oa = body->oa;
295 ost_drop_id(exp, &repbody->oa);
298 ost_lock_put(exp, &lh, LCK_PR);
303 static int ost_statfs(struct ptlrpc_request *req)
305 struct obd_statfs *osfs;
309 rc = req_capsule_server_pack(&req->rq_pill);
313 osfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
315 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
316 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
318 if (req->rq_status != 0)
319 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
324 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
325 struct obd_trans_info *oti)
327 struct ost_body *body, *repbody;
331 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
335 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
339 rc = req_capsule_server_pack(&req->rq_pill);
343 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
344 repbody->oa = body->oa;
345 oti->oti_logcookies = &body->oa.o_lcookie;
347 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
348 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
352 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
353 struct obd_trans_info *oti)
355 struct ost_body *body, *repbody;
357 struct lustre_handle lh = {0,};
360 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
361 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
363 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
367 rc = ost_validate_obdo(exp, &body->oa, NULL);
371 if ((body->oa.o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
372 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
375 rc = req_capsule_server_pack(&req->rq_pill);
379 /* standard truncate optimization: if file body is completely
380 * destroyed, don't send data back to the server. */
381 if (body->oa.o_size == 0)
382 flags |= LDLM_AST_DISCARD_DATA;
384 rc = ost_lock_get(exp, &body->oa, body->oa.o_size, body->oa.o_blocks,
387 struct obd_info *oinfo;
388 struct lustre_capa *capa = NULL;
390 if (body->oa.o_valid & OBD_MD_FLFLAGS &&
391 body->oa.o_flags == OBD_FL_SRVLOCK)
393 * If OBD_FL_SRVLOCK is the only bit set in
394 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
395 * through filter_setattr() to filter_iocontrol().
397 body->oa.o_valid &= ~OBD_MD_FLFLAGS;
399 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
400 capa = req_capsule_client_get(&req->rq_pill,
403 CERROR("Missing capability for OST PUNCH");
404 GOTO(unlock, rc = -EFAULT);
408 OBD_ALLOC_PTR(oinfo);
410 GOTO(unlock, rc = -ENOMEM);
411 oinfo->oi_oa = &body->oa;
412 oinfo->oi_policy.l_extent.start = oinfo->oi_oa->o_size;
413 oinfo->oi_policy.l_extent.end = oinfo->oi_oa->o_blocks;
414 oinfo->oi_capa = capa;
416 req->rq_status = obd_punch(exp, oinfo, oti, NULL);
419 ost_lock_put(exp, &lh, LCK_PW);
422 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
423 repbody->oa = body->oa;
424 ost_drop_id(exp, &repbody->oa);
428 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
430 struct ost_body *body, *repbody;
431 struct obd_info *oinfo;
432 struct lustre_capa *capa = NULL;
436 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
440 rc = ost_validate_obdo(exp, &body->oa, NULL);
444 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
445 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
447 CERROR("Missing capability for OST SYNC");
452 rc = req_capsule_server_pack(&req->rq_pill);
456 OBD_ALLOC_PTR(oinfo);
460 oinfo->oi_oa = &body->oa;
461 oinfo->oi_capa = capa;
462 req->rq_status = obd_sync(exp, oinfo, body->oa.o_size,
463 body->oa.o_blocks, NULL);
466 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
467 repbody->oa = body->oa;
468 ost_drop_id(exp, &repbody->oa);
472 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
473 struct obd_trans_info *oti)
475 struct ost_body *body, *repbody;
476 struct obd_info *oinfo;
477 struct lustre_capa *capa = NULL;
481 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
485 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
489 rc = req_capsule_server_pack(&req->rq_pill);
493 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
494 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
496 CERROR("Missing capability for OST SETATTR");
501 OBD_ALLOC_PTR(oinfo);
504 oinfo->oi_oa = &body->oa;
505 oinfo->oi_capa = capa;
507 req->rq_status = obd_setattr(exp, oinfo, oti);
511 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
512 repbody->oa = body->oa;
513 ost_drop_id(exp, &repbody->oa);
517 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
518 cksum_type_t cksum_type)
523 cksum = init_checksum(cksum_type);
524 for (i = 0; i < desc->bd_iov_count; i++) {
525 struct page *page = desc->bd_iov[i].kiov_page;
526 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
527 char *ptr = kmap(page) + off;
528 int len = desc->bd_iov[i].kiov_len;
530 /* corrupt the data before we compute the checksum, to
531 * simulate a client->OST data error */
532 if (i == 0 && opc == OST_WRITE &&
533 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
534 memcpy(ptr, "bad3", min(4, len));
535 cksum = compute_checksum(cksum, ptr, len, cksum_type);
536 /* corrupt the data after we compute the checksum, to
537 * simulate an OST->client data error */
538 if (i == 0 && opc == OST_READ &&
539 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
540 memcpy(ptr, "bad4", min(4, len));
541 /* nobody should use corrupted page again */
542 ClearPageUptodate(page);
550 static int ost_brw_lock_get(int mode, struct obd_export *exp,
551 struct obd_ioobj *obj, struct niobuf_remote *nb,
552 struct lustre_handle *lh)
555 int nrbufs = obj->ioo_bufcnt;
556 struct ldlm_res_id res_id;
557 ldlm_policy_data_t policy;
561 osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id);
562 LASSERT(mode == LCK_PR || mode == LCK_PW);
563 LASSERT(!lustre_handle_is_used(lh));
565 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
568 for (i = 1; i < nrbufs; i ++)
569 if ((nb[0].flags & OBD_BRW_SRVLOCK) !=
570 (nb[i].flags & OBD_BRW_SRVLOCK))
573 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
574 policy.l_extent.end = (nb[nrbufs - 1].offset +
575 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
577 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
578 LDLM_EXTENT, &policy, mode, &flags,
579 ldlm_blocking_ast, ldlm_completion_ast,
580 ldlm_glimpse_ast, NULL, 0, NULL, lh));
583 static void ost_brw_lock_put(int mode,
584 struct obd_ioobj *obj, struct niobuf_remote *niob,
585 struct lustre_handle *lh)
588 LASSERT(mode == LCK_PR || mode == LCK_PW);
589 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
590 lustre_handle_is_used(lh));
591 if (lustre_handle_is_used(lh))
592 ldlm_lock_decref(lh, mode);
596 struct ost_prolong_data {
597 struct obd_export *opd_exp;
598 ldlm_policy_data_t opd_policy;
600 ldlm_mode_t opd_mode;
605 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
607 struct ost_prolong_data *opd = data;
609 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
611 if (lock->l_req_mode != lock->l_granted_mode) {
612 /* scan granted locks only */
613 return LDLM_ITER_STOP;
616 if (lock->l_export != opd->opd_exp) {
617 /* prolong locks only for given client */
618 return LDLM_ITER_CONTINUE;
621 if (!(lock->l_granted_mode & opd->opd_mode)) {
622 /* we aren't interesting in all type of locks */
623 return LDLM_ITER_CONTINUE;
626 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
627 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
628 /* the request doesn't cross the lock, skip it */
629 return LDLM_ITER_CONTINUE;
632 /* Fill the obdo with the matched lock handle.
633 * XXX: it is possible in some cases the IO RPC is covered by several
634 * locks, even for the write case, so it may need to be a lock list. */
635 if (opd->opd_oa && !(opd->opd_oa->o_valid & OBD_MD_FLHANDLE)) {
636 opd->opd_oa->o_handle.cookie = lock->l_handle.h_cookie;
637 opd->opd_oa->o_valid |= OBD_MD_FLHANDLE;
640 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
641 /* ignore locks not being cancelled */
642 return LDLM_ITER_CONTINUE;
645 CDEBUG(D_DLMTRACE,"refresh lock: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
646 lock->l_resource->lr_name.name[0],
647 lock->l_resource->lr_name.name[1],
648 opd->opd_policy.l_extent.start, opd->opd_policy.l_extent.end);
649 /* OK. this is a possible lock the user holds doing I/O
650 * let's refresh eviction timer for it */
651 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
652 opd->opd_lock_match = 1;
654 return LDLM_ITER_CONTINUE;
657 static int ost_rw_prolong_locks(struct ptlrpc_request *req, struct obd_ioobj *obj,
658 struct niobuf_remote *nb, struct obdo *oa,
661 struct ldlm_res_id res_id;
662 int nrbufs = obj->ioo_bufcnt;
663 struct ost_prolong_data opd = { 0 };
666 osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id);
669 opd.opd_exp = req->rq_export;
670 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
671 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
672 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
674 /* prolong locks for the current service time of the corresponding
675 * portal (= OST_IO_PORTAL) */
676 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
677 max(at_est2timeout(at_get(&req->rq_rqbd->
678 rqbd_service->srv_at_estimate)), ldlm_timeout);
680 CDEBUG(D_INFO,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
681 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
682 opd.opd_policy.l_extent.end);
684 if (oa->o_valid & OBD_MD_FLHANDLE) {
685 struct ldlm_lock *lock;
687 lock = ldlm_handle2lock(&oa->o_handle);
689 ost_prolong_locks_iter(lock, &opd);
690 if (opd.opd_lock_match) {
695 /* Check if the lock covers the whole IO region,
696 * otherwise iterate through the resource. */
697 if (lock->l_policy_data.l_extent.end >=
698 opd.opd_policy.l_extent.end &&
699 lock->l_policy_data.l_extent.start <=
700 opd.opd_policy.l_extent.start) {
709 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
710 ost_prolong_locks_iter, &opd);
711 RETURN(opd.opd_lock_match);
714 /* Allocate thread local buffers if needed */
715 static struct ost_thread_local_cache *ost_tls_get(struct ptlrpc_request *r)
717 struct ost_thread_local_cache *tls =
718 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
720 /* In normal mode of operation an I/O request is serviced only
721 * by ll_ost_io threads each of them has own tls buffers allocated by
723 * During recovery, an I/O request may be queued until any of the ost
724 * service threads process it. Not necessary it should be one of
725 * ll_ost_io threads. In that case we dynamically allocating tls
726 * buffers for the request service time. */
727 if (unlikely(tls == NULL)) {
728 LASSERT(r->rq_export->exp_in_recovery);
732 r->rq_svc_thread->t_data = tls;
738 /* Free thread local buffers if they were allocated only for servicing
739 * this one request */
740 static void ost_tls_put(struct ptlrpc_request *r)
742 struct ost_thread_local_cache *tls =
743 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
745 if (unlikely(tls->temporary)) {
747 r->rq_svc_thread->t_data = NULL;
751 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
753 struct ptlrpc_bulk_desc *desc = NULL;
754 struct obd_export *exp = req->rq_export;
755 struct niobuf_remote *remote_nb;
756 struct niobuf_local *local_nb;
757 struct obd_ioobj *ioo;
758 struct ost_body *body, *repbody;
759 struct lustre_capa *capa = NULL;
760 struct l_wait_info lwi;
761 struct lustre_handle lockh = { 0 };
762 int niocount, npages, nob = 0, rc, i;
764 struct ost_thread_local_cache *tls;
767 req->rq_bulk_read = 1;
769 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
770 GOTO(out, rc = -EIO);
772 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
774 /* Check if there is eviction in progress, and if so, wait for it to
776 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
777 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
778 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
779 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
783 GOTO(out, rc = -ENOTCONN);
785 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
786 * ost_rw_hpreq_check(). */
787 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
789 GOTO(out, rc = -EFAULT);
792 * A req_capsule_X_get_array(pill, field, ptr_to_element_count) function
793 * would be useful here and wherever we get &RMF_OBD_IOOBJ and
794 * &RMF_NIOBUF_REMOTE.
796 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
798 GOTO(out, rc = -EFAULT);
800 rc = ost_validate_obdo(exp, &body->oa, ioo);
804 niocount = ioo->ioo_bufcnt;
805 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
806 if (remote_nb == NULL)
807 GOTO(out, rc = -EFAULT);
809 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
810 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
812 CERROR("Missing capability for OST BRW READ");
813 GOTO(out, rc = -EFAULT);
817 rc = req_capsule_server_pack(&req->rq_pill);
821 tls = ost_tls_get(req);
823 GOTO(out_bulk, rc = -ENOMEM);
824 local_nb = tls->local;
826 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
831 * If getting the lock took more time than
832 * client was willing to wait, drop it. b=11330
834 if (cfs_time_current_sec() > req->rq_deadline ||
835 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
837 CERROR("Dropping timed-out read from %s because locking"
838 "object "LPX64" took %ld seconds (limit was %ld).\n",
839 libcfs_id2str(req->rq_peer), ioo->ioo_id,
840 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
841 req->rq_deadline - req->rq_arrival_time.tv_sec);
842 GOTO(out_lock, rc = -ETIMEDOUT);
845 npages = OST_THREAD_POOL_SIZE;
846 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
847 remote_nb, &npages, local_nb, oti, capa);
851 desc = ptlrpc_prep_bulk_exp(req, npages,
852 BULK_PUT_SOURCE, OST_BULK_PORTAL);
854 GOTO(out_commitrw, rc = -ENOMEM);
856 if (!lustre_handle_is_used(&lockh))
857 /* no needs to try to prolong lock if server is asked
858 * to handle locking (= OBD_BRW_SRVLOCK) */
859 ost_rw_prolong_locks(req, ioo, remote_nb, &body->oa,
863 for (i = 0; i < npages; i++) {
864 int page_rc = local_nb[i].rc;
866 if (page_rc < 0) { /* error */
872 if (page_rc != 0) { /* some data! */
873 LASSERT (local_nb[i].page != NULL);
874 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
875 local_nb[i].offset & ~CFS_PAGE_MASK,
879 if (page_rc != local_nb[i].len) { /* short read */
880 /* All subsequent pages should be 0 */
882 LASSERT(local_nb[i].rc == 0);
887 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
888 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
890 if (body->oa.o_valid & OBD_MD_FLFLAGS)
891 cksum_type = cksum_type_unpack(body->oa.o_flags);
892 body->oa.o_flags = cksum_type_pack(cksum_type);
893 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
894 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
895 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
897 body->oa.o_valid = 0;
899 /* We're finishing using body->oa as an input variable */
901 /* Check if client was evicted while we were doing i/o before touching
904 rc = target_bulk_io(exp, desc, &lwi);
909 /* Must commit after prep above in all cases */
910 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
911 remote_nb, npages, local_nb, oti, rc);
914 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
915 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
916 ost_drop_id(exp, &repbody->oa);
920 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
925 ptlrpc_free_bulk(desc);
929 req->rq_status = nob;
930 ptlrpc_lprocfs_brw(req, nob);
931 target_committed_to_req(req);
933 } else if (!no_reply) {
934 /* Only reply if there was no comms problem with bulk */
935 target_committed_to_req(req);
939 /* reply out callback would free */
940 ptlrpc_req_drop_rs(req);
941 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
942 "client will retry\n",
943 exp->exp_obd->obd_name,
944 exp->exp_client_uuid.uuid,
945 exp->exp_connection->c_remote_uuid.uuid,
946 libcfs_id2str(req->rq_peer));
952 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
954 struct ptlrpc_bulk_desc *desc = NULL;
955 struct obd_export *exp = req->rq_export;
956 struct niobuf_remote *remote_nb;
957 struct niobuf_local *local_nb;
958 struct obd_ioobj *ioo;
959 struct ost_body *body, *repbody;
960 struct l_wait_info lwi;
961 struct lustre_handle lockh = {0};
962 struct lustre_capa *capa = NULL;
964 int objcount, niocount, npages;
966 obd_count client_cksum = 0, server_cksum = 0;
967 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
968 int no_reply = 0, mmap = 0;
969 __u32 o_uid = 0, o_gid = 0;
970 struct ost_thread_local_cache *tls;
973 req->rq_bulk_write = 1;
975 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
976 GOTO(out, rc = -EIO);
977 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
978 GOTO(out, rc = -EFAULT);
980 /* pause before transaction has been started */
981 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
983 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
984 * ost_rw_hpreq_check(). */
985 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
987 GOTO(out, rc = -EFAULT);
989 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
990 RCL_CLIENT) / sizeof(*ioo);
991 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
993 GOTO(out, rc = -EFAULT);
995 rc = ost_validate_obdo(exp, &body->oa, ioo);
999 for (niocount = i = 0; i < objcount; i++)
1000 niocount += ioo[i].ioo_bufcnt;
1003 * It'd be nice to have a capsule function to indicate how many elements
1004 * there were in a buffer for an RMF that's declared to be an array.
1005 * It's easy enough to compute the number of elements here though.
1007 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1008 if (remote_nb == NULL || niocount != (req_capsule_get_size(&req->rq_pill,
1009 &RMF_NIOBUF_REMOTE, RCL_CLIENT) / sizeof(*remote_nb)))
1010 GOTO(out, rc = -EFAULT);
1012 if ((remote_nb[0].flags & OBD_BRW_MEMALLOC) &&
1013 (exp->exp_connection->c_peer.nid == exp->exp_connection->c_self))
1014 cfs_memory_pressure_set();
1016 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
1017 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
1019 CERROR("Missing capability for OST BRW WRITE");
1020 GOTO(out, rc = -EFAULT);
1024 req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER,
1025 niocount * sizeof(*rcs));
1026 rc = req_capsule_server_pack(&req->rq_pill);
1029 CFS_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, cfs_fail_val);
1030 rcs = req_capsule_server_get(&req->rq_pill, &RMF_RCS);
1032 tls = ost_tls_get(req);
1034 GOTO(out_bulk, rc = -ENOMEM);
1035 local_nb = tls->local;
1037 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
1042 * If getting the lock took more time than
1043 * client was willing to wait, drop it. b=11330
1045 if (cfs_time_current_sec() > req->rq_deadline ||
1046 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
1048 CERROR("Dropping timed-out write from %s because locking "
1049 "object "LPX64" took %ld seconds (limit was %ld).\n",
1050 libcfs_id2str(req->rq_peer), ioo->ioo_id,
1051 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
1052 req->rq_deadline - req->rq_arrival_time.tv_sec);
1053 GOTO(out_lock, rc = -ETIMEDOUT);
1056 if (!lustre_handle_is_used(&lockh))
1057 /* no needs to try to prolong lock if server is asked
1058 * to handle locking (= OBD_BRW_SRVLOCK) */
1059 ost_rw_prolong_locks(req, ioo, remote_nb,&body->oa, LCK_PW);
1061 /* obd_preprw clobbers oa->valid, so save what we need */
1062 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
1063 client_cksum = body->oa.o_cksum;
1064 if (body->oa.o_valid & OBD_MD_FLFLAGS)
1065 cksum_type = cksum_type_unpack(body->oa.o_flags);
1067 if (body->oa.o_valid & OBD_MD_FLFLAGS && body->oa.o_flags & OBD_FL_MMAP)
1070 /* Because we already sync grant info with client when reconnect,
1071 * grant info will be cleared for resent req, then fed_grant and
1072 * total_grant will not be modified in following preprw_write */
1073 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1074 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1075 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1078 if (exp_connect_rmtclient(exp)) {
1079 o_uid = body->oa.o_uid;
1080 o_gid = body->oa.o_gid;
1082 npages = OST_THREAD_POOL_SIZE;
1083 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
1084 ioo, remote_nb, &npages, local_nb, oti, capa);
1088 desc = ptlrpc_prep_bulk_exp(req, npages,
1089 BULK_GET_SINK, OST_BULK_PORTAL);
1091 GOTO(skip_transfer, rc = -ENOMEM);
1093 /* NB Having prepped, we must commit... */
1095 for (i = 0; i < npages; i++)
1096 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1097 local_nb[i].offset & ~CFS_PAGE_MASK,
1100 rc = sptlrpc_svc_prep_bulk(req, desc);
1104 rc = target_bulk_io(exp, desc, &lwi);
1108 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
1109 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1111 if (unlikely(client_cksum != 0 && rc == 0)) {
1112 static int cksum_counter;
1113 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1114 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1115 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1116 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1117 repbody->oa.o_cksum = server_cksum;
1119 if (unlikely(client_cksum != server_cksum)) {
1120 CDEBUG_LIMIT(mmap ? D_INFO : D_ERROR,
1121 "client csum %x, server csum %x\n",
1122 client_cksum, server_cksum);
1124 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1125 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1126 cksum_counter, libcfs_id2str(req->rq_peer),
1131 /* Must commit after prep above in all cases */
1132 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1133 remote_nb, npages, local_nb, oti, rc);
1134 if (rc == -ENOTCONN)
1135 /* quota acquire process has been given up because
1136 * either the client has been evicted or the client
1137 * has timed out the request already */
1140 if (exp_connect_rmtclient(exp)) {
1141 repbody->oa.o_uid = o_uid;
1142 repbody->oa.o_gid = o_gid;
1146 * Disable sending mtime back to the client. If the client locked the
1147 * whole object, then it has already updated the mtime on its side,
1148 * otherwise it will have to glimpse anyway (see bug 21489, comment 32)
1150 repbody->oa.o_valid &= ~(OBD_MD_FLMTIME | OBD_MD_FLATIME);
1152 if (unlikely(client_cksum != server_cksum && rc == 0 && !mmap)) {
1153 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1158 if (new_cksum == server_cksum)
1159 msg = "changed in transit before arrival at OST";
1160 else if (new_cksum == client_cksum)
1161 msg = "initial checksum before message complete";
1163 msg = "changed in transit AND after initial checksum";
1165 if (req->rq_peer.nid == desc->bd_sender) {
1169 router = libcfs_nid2str(desc->bd_sender);
1172 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1173 "%s%s%s inode "DFID" object "
1174 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1175 exp->exp_obd->obd_name, msg,
1176 libcfs_id2str(req->rq_peer),
1178 body->oa.o_valid & OBD_MD_FLFID ?
1179 body->oa.o_parent_seq : (__u64)0,
1180 body->oa.o_valid & OBD_MD_FLFID ?
1181 body->oa.o_parent_oid : 0,
1182 body->oa.o_valid & OBD_MD_FLFID ?
1183 body->oa.o_parent_ver : 0,
1185 body->oa.o_valid & OBD_MD_FLGROUP ?
1186 body->oa.o_seq : (__u64)0,
1188 local_nb[npages-1].offset +
1189 local_nb[npages-1].len - 1 );
1190 CERROR("client csum %x, original server csum %x, "
1191 "server csum now %x\n",
1192 client_cksum, server_cksum, new_cksum);
1198 /* set per-requested niobuf return codes */
1199 for (i = j = 0; i < niocount; i++) {
1200 int len = remote_nb[i].len;
1205 LASSERT(j < npages);
1206 if (local_nb[j].rc < 0)
1207 rcs[i] = local_nb[j].rc;
1208 len -= local_nb[j].len;
1213 LASSERT(j == npages);
1214 ptlrpc_lprocfs_brw(req, nob);
1218 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1223 ptlrpc_free_bulk(desc);
1226 oti_to_request(oti, req);
1227 target_committed_to_req(req);
1228 rc = ptlrpc_reply(req);
1229 } else if (!no_reply) {
1230 /* Only reply if there was no comms problem with bulk */
1231 target_committed_to_req(req);
1232 req->rq_status = rc;
1235 /* reply out callback would free */
1236 ptlrpc_req_drop_rs(req);
1237 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1238 "client will retry\n",
1239 exp->exp_obd->obd_name,
1240 exp->exp_client_uuid.uuid,
1241 exp->exp_connection->c_remote_uuid.uuid,
1242 libcfs_id2str(req->rq_peer));
1244 cfs_memory_pressure_clr();
1249 * Implementation of OST_SET_INFO.
1251 * OST_SET_INFO is like ioctl(): heavily overloaded. Specifically, it takes a
1252 * "key" and a value RPC buffers as arguments, with the value's contents
1253 * interpreted according to the key.
1255 * Value types that need swabbing have swabbing done explicitly, either here or
1256 * in functions called from here. This should be corrected: all swabbing should
1257 * be done in the capsule abstraction, as that will then allow us to move
1258 * swabbing exclusively to the client without having to modify server code
1259 * outside the capsule abstraction's implementation itself. To correct this
1260 * will require minor changes to the capsule abstraction; see the comments for
1261 * req_capsule_extend() in layout.c.
1263 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1265 struct ost_body *body = NULL, *repbody;
1266 char *key, *val = NULL;
1267 int keylen, vallen, rc = 0;
1268 int is_grant_shrink = 0;
1271 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1273 DEBUG_REQ(D_HA, req, "no set_info key");
1276 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1279 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1282 if ((is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK)))
1283 /* In this case the value is actually an RMF_OST_BODY, so we
1284 * transmutate the type of this PTLRPC */
1285 req_capsule_extend(&req->rq_pill, &RQF_OST_SET_GRANT_INFO);
1287 rc = req_capsule_server_pack(&req->rq_pill);
1292 if (is_grant_shrink) {
1293 body = req_capsule_client_get(&req->rq_pill,
1298 repbody = req_capsule_server_get(&req->rq_pill,
1300 memcpy(repbody, body, sizeof(*body));
1301 val = (char*)repbody;
1303 val = req_capsule_client_get(&req->rq_pill,
1308 if (KEY_IS(KEY_EVICT_BY_NID)) {
1310 obd_export_evict_by_nid(exp->exp_obd, val);
1312 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1313 if (vallen < sizeof(__u32))
1315 __swab32s((__u32 *)val);
1318 /* OBD will also check if KEY_IS(KEY_GRANT_SHRINK), and will cast val to
1319 * a struct ost_body * value */
1320 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1322 lustre_msg_set_status(req->rq_repmsg, 0);
1326 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1329 int keylen, replylen, rc = 0;
1330 struct req_capsule *pill = &req->rq_pill;
1333 /* this common part for get_info rpc */
1334 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1336 DEBUG_REQ(D_HA, req, "no get_info key");
1339 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1341 if (KEY_IS(KEY_FIEMAP)) {
1342 struct ll_fiemap_info_key *fm_key = key;
1345 rc = ost_validate_obdo(exp, &fm_key->oa, NULL);
1350 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1354 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1355 RCL_SERVER, replylen);
1357 rc = req_capsule_server_pack(pill);
1361 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1365 /* call again to fill in the reply buffer */
1366 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1368 lustre_msg_set_status(req->rq_repmsg, 0);
1372 #ifdef HAVE_QUOTA_SUPPORT
1373 static int ost_handle_quotactl(struct ptlrpc_request *req)
1375 struct obd_quotactl *oqctl, *repoqc;
1379 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1381 GOTO(out, rc = -EPROTO);
1383 rc = req_capsule_server_pack(&req->rq_pill);
1387 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1388 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1395 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1397 struct obd_quotactl *oqctl;
1401 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1405 rc = req_capsule_server_pack(&req->rq_pill);
1409 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1413 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1415 struct quota_adjust_qunit *oqaq, *repoqa;
1416 struct lustre_quota_ctxt *qctxt;
1420 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1421 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1423 GOTO(out, rc = -EPROTO);
1425 rc = req_capsule_server_pack(&req->rq_pill);
1429 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1430 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt, NULL);
1438 static int ost_llog_handle_connect(struct obd_export *exp,
1439 struct ptlrpc_request *req)
1441 struct llogd_conn_body *body;
1445 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
1446 rc = obd_llog_connect(exp, body);
1450 #define ost_init_sec_none(reply, exp) \
1452 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1453 OBD_CONNECT_RMT_CLIENT_FORCE | \
1454 OBD_CONNECT_OSS_CAPA); \
1455 cfs_spin_lock(&exp->exp_lock); \
1456 exp->exp_connect_flags = reply->ocd_connect_flags; \
1457 cfs_spin_unlock(&exp->exp_lock); \
1460 static int ost_init_sec_level(struct ptlrpc_request *req)
1462 struct obd_export *exp = req->rq_export;
1463 struct req_capsule *pill = &req->rq_pill;
1464 struct obd_device *obd = exp->exp_obd;
1465 struct filter_obd *filter = &obd->u.filter;
1466 char *client = libcfs_nid2str(req->rq_peer.nid);
1467 struct obd_connect_data *data, *reply;
1471 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1472 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1473 if (data == NULL || reply == NULL)
1476 /* connection from MDT is always trusted */
1477 if (req->rq_auth_usr_mdt) {
1478 ost_init_sec_none(reply, exp);
1482 /* no GSS support case */
1483 if (!req->rq_auth_gss) {
1484 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1485 CWARN("client %s -> target %s does not user GSS, "
1486 "can not run under security level %d.\n",
1487 client, obd->obd_name, filter->fo_sec_level);
1490 ost_init_sec_none(reply, exp);
1495 /* old version case */
1496 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1497 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1498 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1499 CWARN("client %s -> target %s uses old version, "
1500 "can not run under security level %d.\n",
1501 client, obd->obd_name, filter->fo_sec_level);
1504 CWARN("client %s -> target %s uses old version, "
1505 "run under security level %d.\n",
1506 client, obd->obd_name, filter->fo_sec_level);
1507 ost_init_sec_none(reply, exp);
1512 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1514 if (!req->rq_auth_remote)
1515 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1516 "asked to be remote.\n", client, obd->obd_name);
1517 } else if (req->rq_auth_remote) {
1519 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1520 "as remote by default.\n", client, obd->obd_name);
1524 if (!filter->fo_fl_oss_capa) {
1525 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1526 " but OSS capabilities are not enabled: %d.\n",
1527 client, obd->obd_name, filter->fo_fl_oss_capa);
1532 switch (filter->fo_sec_level) {
1533 case LUSTRE_SEC_NONE:
1535 ost_init_sec_none(reply, exp);
1538 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1539 "can not run under security level %d.\n",
1540 client, obd->obd_name, filter->fo_sec_level);
1543 case LUSTRE_SEC_REMOTE:
1545 ost_init_sec_none(reply, exp);
1547 case LUSTRE_SEC_ALL:
1549 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1550 OBD_CONNECT_RMT_CLIENT_FORCE);
1551 if (!filter->fo_fl_oss_capa)
1552 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1554 cfs_spin_lock(&exp->exp_lock);
1555 exp->exp_connect_flags = reply->ocd_connect_flags;
1556 cfs_spin_unlock(&exp->exp_lock);
1568 * this should be done in filter_connect()/filter_reconnect(), but
1569 * we can't obtain information like NID, which stored in incoming
1570 * request, thus can't decide what flavor to use. so we do it here.
1572 * This hack should be removed after the OST stack be rewritten, just
1573 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1575 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1577 struct obd_export *exp = req->rq_export;
1578 struct filter_obd *filter = &exp->exp_obd->u.filter;
1579 struct sptlrpc_flavor flvr;
1582 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1583 LUSTRE_ECHO_NAME) == 0)) {
1584 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1588 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1589 cfs_read_lock(&filter->fo_sptlrpc_lock);
1590 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1594 cfs_read_unlock(&filter->fo_sptlrpc_lock);
1596 cfs_spin_lock(&exp->exp_lock);
1598 exp->exp_sp_peer = req->rq_sp_from;
1599 exp->exp_flvr = flvr;
1601 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1602 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1603 CERROR("unauthorized rpc flavor %x from %s, "
1604 "expect %x\n", req->rq_flvr.sf_rpc,
1605 libcfs_nid2str(req->rq_peer.nid),
1606 exp->exp_flvr.sf_rpc);
1610 cfs_spin_unlock(&exp->exp_lock);
1612 if (exp->exp_sp_peer != req->rq_sp_from) {
1613 CERROR("RPC source %s doesn't match %s\n",
1614 sptlrpc_part2name(req->rq_sp_from),
1615 sptlrpc_part2name(exp->exp_sp_peer));
1618 rc = sptlrpc_target_export_check(exp, req);
1625 /* Ensure that data and metadata are synced to the disk when lock is cancelled
1627 int ost_blocking_ast(struct ldlm_lock *lock,
1628 struct ldlm_lock_desc *desc,
1629 void *data, int flag)
1631 __u32 sync_lock_cancel = 0;
1632 __u32 len = sizeof(sync_lock_cancel);
1636 rc = obd_get_info(lock->l_export, sizeof(KEY_SYNC_LOCK_CANCEL),
1637 KEY_SYNC_LOCK_CANCEL, &len, &sync_lock_cancel, NULL);
1639 if (!rc && flag == LDLM_CB_CANCELING &&
1640 (lock->l_granted_mode & (LCK_PW|LCK_GROUP)) &&
1641 (sync_lock_cancel == ALWAYS_SYNC_ON_CANCEL ||
1642 (sync_lock_cancel == BLOCKING_SYNC_ON_CANCEL &&
1643 lock->l_flags & LDLM_FL_CBPENDING))) {
1644 struct obd_info *oinfo;
1648 OBD_ALLOC_PTR(oinfo);
1653 OBD_FREE_PTR(oinfo);
1656 oa->o_id = lock->l_resource->lr_name.name[0];
1657 oa->o_seq = lock->l_resource->lr_name.name[1];
1658 oa->o_valid = OBD_MD_FLID|OBD_MD_FLGROUP;
1661 rc = obd_sync(lock->l_export, oinfo,
1662 lock->l_policy_data.l_extent.start,
1663 lock->l_policy_data.l_extent.end, NULL);
1665 CERROR("Error %d syncing data on lock cancel\n", rc);
1668 OBD_FREE_PTR(oinfo);
1671 rc = ldlm_server_blocking_ast(lock, desc, data, flag);
1675 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1676 struct obd_device *obd, int *process)
1678 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1679 case OST_CONNECT: /* This will never get here, but for completeness. */
1680 case OST_DISCONNECT:
1691 case OBD_LOG_CANCEL:
1693 *process = target_queue_recovery_request(req, obd);
1697 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1703 int ost_msg_check_version(struct lustre_msg *msg)
1707 switch(lustre_msg_get_opc(msg)) {
1709 case OST_DISCONNECT:
1712 case SEC_CTX_INIT_CONT:
1714 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1716 CERROR("bad opc %u version %08x, expecting %08x\n",
1717 lustre_msg_get_opc(msg),
1718 lustre_msg_get_version(msg),
1719 LUSTRE_OBD_VERSION);
1732 #ifdef HAVE_QUOTA_SUPPORT
1733 case OST_QUOTACHECK:
1735 case OST_QUOTA_ADJUST_QUNIT:
1737 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1739 CERROR("bad opc %u version %08x, expecting %08x\n",
1740 lustre_msg_get_opc(msg),
1741 lustre_msg_get_version(msg),
1742 LUSTRE_OST_VERSION);
1747 case LDLM_BL_CALLBACK:
1748 case LDLM_CP_CALLBACK:
1749 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1751 CERROR("bad opc %u version %08x, expecting %08x\n",
1752 lustre_msg_get_opc(msg),
1753 lustre_msg_get_version(msg),
1754 LUSTRE_DLM_VERSION);
1756 case LLOG_ORIGIN_CONNECT:
1757 case OBD_LOG_CANCEL:
1758 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1760 CERROR("bad opc %u version %08x, expecting %08x\n",
1761 lustre_msg_get_opc(msg),
1762 lustre_msg_get_version(msg),
1763 LUSTRE_LOG_VERSION);
1766 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1773 * Returns 1 if the given PTLRPC matches the given LDLM locks, or 0 if it does
1776 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1777 struct ldlm_lock *lock)
1779 struct niobuf_remote *nb;
1780 struct obd_ioobj *ioo;
1781 struct ost_body *body;
1782 int objcount, niocount;
1783 int mode, opc, i, rc;
1787 opc = lustre_msg_get_opc(req->rq_reqmsg);
1788 LASSERT(opc == OST_READ || opc == OST_WRITE);
1790 /* As the request may be covered by several locks, do not look at
1791 * o_handle, look at the RPC IO region. */
1792 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1796 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1797 RCL_CLIENT) / sizeof(*ioo);
1798 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1802 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
1806 for (niocount = i = 0; i < objcount; i++)
1807 niocount += ioo[i].ioo_bufcnt;
1809 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1811 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
1812 RCL_CLIENT) / sizeof(*nb)))
1816 if (opc == OST_READ)
1819 start = nb[0].offset & CFS_PAGE_MASK;
1820 end = (nb[ioo->ioo_bufcnt - 1].offset +
1821 nb[ioo->ioo_bufcnt - 1].len - 1) | ~CFS_PAGE_MASK;
1823 LASSERT(lock->l_resource != NULL);
1824 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_seq,
1825 &lock->l_resource->lr_name))
1828 if (!(lock->l_granted_mode & mode))
1831 if (lock->l_policy_data.l_extent.end < start ||
1832 lock->l_policy_data.l_extent.start > end)
1839 * High-priority queue request check for whether the given PTLRPC request (\a
1840 * req) is blocking an LDLM lock cancel.
1842 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1843 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1845 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1846 * function looks only at OST_READs and OST_WRITEs.
1848 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1850 struct niobuf_remote *nb;
1851 struct obd_ioobj *ioo;
1852 struct ost_body *body;
1853 int objcount, niocount;
1854 int mode, opc, i, rc;
1857 opc = lustre_msg_get_opc(req->rq_reqmsg);
1858 LASSERT(opc == OST_READ || opc == OST_WRITE);
1860 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1864 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1865 RCL_CLIENT) / sizeof(*ioo);
1866 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1870 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
1874 for (niocount = i = 0; i < objcount; i++)
1875 niocount += ioo[i].ioo_bufcnt;
1876 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1878 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
1879 RCL_CLIENT) / sizeof(*nb)))
1881 if (niocount != 0 && (nb[0].flags & OBD_BRW_SRVLOCK))
1885 if (opc == OST_READ)
1887 RETURN(ost_rw_prolong_locks(req, ioo, nb, &body->oa, mode));
1890 static int ost_punch_prolong_locks(struct ptlrpc_request *req, struct obdo *oa)
1892 struct ldlm_res_id res_id = { .name = { oa->o_id } };
1893 struct ost_prolong_data opd = { 0 };
1898 end = start + oa->o_blocks;
1900 opd.opd_mode = LCK_PW;
1901 opd.opd_exp = req->rq_export;
1902 opd.opd_policy.l_extent.start = start & CFS_PAGE_MASK;
1903 if (oa->o_blocks == OBD_OBJECT_EOF || end < start)
1904 opd.opd_policy.l_extent.end = OBD_OBJECT_EOF;
1906 opd.opd_policy.l_extent.end = end | ~CFS_PAGE_MASK;
1908 /* prolong locks for the current service time of the corresponding
1909 * portal (= OST_IO_PORTAL) */
1910 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
1911 max(at_est2timeout(at_get(&req->rq_rqbd->
1912 rqbd_service->srv_at_estimate)), ldlm_timeout);
1914 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1915 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
1916 opd.opd_policy.l_extent.end);
1919 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
1920 ost_prolong_locks_iter, &opd);
1921 RETURN(opd.opd_lock_match);
1925 * Like ost_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
1927 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1928 struct ldlm_lock *lock)
1930 struct ost_body *body;
1934 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1936 RETURN(0); /* can't return -EFAULT here */
1938 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
1942 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1943 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1949 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
1951 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1953 struct ost_body *body;
1956 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1960 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
1964 LASSERT(!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1965 !(body->oa.o_flags & OBD_FL_SRVLOCK));
1967 RETURN(ost_punch_prolong_locks(req, &body->oa));
1970 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
1971 .hpreq_lock_match = ost_rw_hpreq_lock_match,
1972 .hpreq_check = ost_rw_hpreq_check,
1975 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
1976 .hpreq_lock_match = ost_punch_hpreq_lock_match,
1977 .hpreq_check = ost_punch_hpreq_check,
1980 /** Assign high priority operations to the request if needed. */
1981 static int ost_hpreq_handler(struct ptlrpc_request *req)
1984 if (req->rq_export) {
1985 int opc = lustre_msg_get_opc(req->rq_reqmsg);
1986 struct ost_body *body;
1988 if (opc == OST_READ || opc == OST_WRITE) {
1989 struct niobuf_remote *nb;
1990 struct obd_ioobj *ioo;
1991 int objcount, niocount;
1994 /* RPCs on the H-P queue can be inspected before
1995 * ost_handler() initializes their pills, so we
1996 * initialize that here. Capsule initialization is
1997 * idempotent, as is setting the pill's format (provided
1998 * it doesn't change).
2000 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2001 if (opc == OST_READ)
2002 req_capsule_set(&req->rq_pill,
2005 req_capsule_set(&req->rq_pill,
2006 &RQF_OST_BRW_WRITE);
2008 body = req_capsule_client_get(&req->rq_pill,
2011 CERROR("Missing/short ost_body\n");
2015 objcount = req_capsule_get_size(&req->rq_pill,
2019 if (objcount == 0) {
2020 CERROR("Missing/short ioobj\n");
2024 CERROR("too many ioobjs (%d)\n", objcount);
2028 ioo = req_capsule_client_get(&req->rq_pill,
2031 CERROR("Missing/short ioobj\n");
2035 for (niocount = i = 0; i < objcount; i++) {
2036 if (ioo[i].ioo_bufcnt == 0) {
2037 CERROR("ioo[%d] has zero bufcnt\n", i);
2040 niocount += ioo[i].ioo_bufcnt;
2042 if (niocount > PTLRPC_MAX_BRW_PAGES) {
2043 DEBUG_REQ(D_RPCTRACE, req,
2044 "bulk has too many pages (%d)",
2049 nb = req_capsule_client_get(&req->rq_pill,
2050 &RMF_NIOBUF_REMOTE);
2052 CERROR("Missing/short niobuf\n");
2056 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
2057 req->rq_ops = &ost_hpreq_rw;
2058 } else if (opc == OST_PUNCH) {
2059 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2060 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2062 body = req_capsule_client_get(&req->rq_pill,
2065 CERROR("Missing/short ost_body\n");
2069 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
2070 !(body->oa.o_flags & OBD_FL_SRVLOCK))
2071 req->rq_ops = &ost_hpreq_punch;
2077 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
2078 int ost_handle(struct ptlrpc_request *req)
2080 struct obd_trans_info trans_info = { 0, };
2081 struct obd_trans_info *oti = &trans_info;
2082 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
2083 struct obd_device *obd = NULL;
2086 LASSERT(current->journal_info == NULL);
2088 /* primordial rpcs don't affect server recovery */
2089 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2091 case SEC_CTX_INIT_CONT:
2096 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2098 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
2099 if (!class_connected_export(req->rq_export)) {
2100 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
2101 lustre_msg_get_opc(req->rq_reqmsg),
2102 libcfs_id2str(req->rq_peer));
2103 req->rq_status = -ENOTCONN;
2104 GOTO(out, rc = -ENOTCONN);
2107 obd = req->rq_export->exp_obd;
2109 /* Check for aborted recovery. */
2110 if (obd->obd_recovering) {
2111 rc = ost_filter_recovery_request(req, obd,
2113 if (rc || !should_process)
2115 else if (should_process < 0) {
2116 req->rq_status = should_process;
2117 rc = ptlrpc_error(req);
2125 rc = ost_msg_check_version(req->rq_reqmsg);
2129 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2131 CDEBUG(D_INODE, "connect\n");
2132 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
2133 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
2135 rc = target_handle_connect(req);
2136 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
2139 rc = ost_init_sec_level(req);
2141 rc = ost_connect_check_sptlrpc(req);
2145 case OST_DISCONNECT:
2146 CDEBUG(D_INODE, "disconnect\n");
2147 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
2148 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
2150 rc = target_handle_disconnect(req);
2153 CDEBUG(D_INODE, "create\n");
2154 req_capsule_set(&req->rq_pill, &RQF_OST_CREATE);
2155 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
2157 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2158 GOTO(out, rc = -EROFS);
2159 rc = ost_create(req->rq_export, req, oti);
2162 CDEBUG(D_INODE, "destroy\n");
2163 req_capsule_set(&req->rq_pill, &RQF_OST_DESTROY);
2164 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
2166 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2167 GOTO(out, rc = -EROFS);
2168 rc = ost_destroy(req->rq_export, req, oti);
2171 CDEBUG(D_INODE, "getattr\n");
2172 req_capsule_set(&req->rq_pill, &RQF_OST_GETATTR);
2173 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
2175 rc = ost_getattr(req->rq_export, req);
2178 CDEBUG(D_INODE, "setattr\n");
2179 req_capsule_set(&req->rq_pill, &RQF_OST_SETATTR);
2180 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
2182 rc = ost_setattr(req->rq_export, req, oti);
2185 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_WRITE);
2186 CDEBUG(D_INODE, "write\n");
2187 /* req->rq_request_portal would be nice, if it was set */
2188 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2189 CERROR("%s: deny write request from %s to portal %u\n",
2190 req->rq_export->exp_obd->obd_name,
2191 obd_export_nid2str(req->rq_export),
2192 req->rq_rqbd->rqbd_service->srv_req_portal);
2193 GOTO(out, rc = -EPROTO);
2195 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2197 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
2198 GOTO(out, rc = -ENOSPC);
2199 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2200 GOTO(out, rc = -EROFS);
2201 rc = ost_brw_write(req, oti);
2202 LASSERT(current->journal_info == NULL);
2203 /* ost_brw_write sends its own replies */
2206 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_READ);
2207 CDEBUG(D_INODE, "read\n");
2208 /* req->rq_request_portal would be nice, if it was set */
2209 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2210 CERROR("%s: deny read request from %s to portal %u\n",
2211 req->rq_export->exp_obd->obd_name,
2212 obd_export_nid2str(req->rq_export),
2213 req->rq_rqbd->rqbd_service->srv_req_portal);
2214 GOTO(out, rc = -EPROTO);
2216 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2218 rc = ost_brw_read(req, oti);
2219 LASSERT(current->journal_info == NULL);
2220 /* ost_brw_read sends its own replies */
2223 CDEBUG(D_INODE, "punch\n");
2224 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2225 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2227 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2228 GOTO(out, rc = -EROFS);
2229 rc = ost_punch(req->rq_export, req, oti);
2232 CDEBUG(D_INODE, "statfs\n");
2233 req_capsule_set(&req->rq_pill, &RQF_OST_STATFS);
2234 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2236 rc = ost_statfs(req);
2239 CDEBUG(D_INODE, "sync\n");
2240 req_capsule_set(&req->rq_pill, &RQF_OST_SYNC);
2241 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2243 rc = ost_sync(req->rq_export, req);
2246 DEBUG_REQ(D_INODE, req, "set_info");
2247 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
2248 rc = ost_set_info(req->rq_export, req);
2251 DEBUG_REQ(D_INODE, req, "get_info");
2252 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
2253 rc = ost_get_info(req->rq_export, req);
2255 #ifdef HAVE_QUOTA_SUPPORT
2256 case OST_QUOTACHECK:
2257 CDEBUG(D_INODE, "quotacheck\n");
2258 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2259 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2261 rc = ost_handle_quotacheck(req);
2264 CDEBUG(D_INODE, "quotactl\n");
2265 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2266 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2268 rc = ost_handle_quotactl(req);
2270 case OST_QUOTA_ADJUST_QUNIT:
2271 CDEBUG(D_INODE, "quota_adjust_qunit\n");
2272 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
2273 rc = ost_handle_quota_adjust_qunit(req);
2277 DEBUG_REQ(D_INODE, req, "ping");
2278 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2279 rc = target_handle_ping(req);
2281 /* FIXME - just reply status */
2282 case LLOG_ORIGIN_CONNECT:
2283 DEBUG_REQ(D_INODE, req, "log connect");
2284 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2285 rc = ost_llog_handle_connect(req->rq_export, req);
2286 req->rq_status = rc;
2287 rc = req_capsule_server_pack(&req->rq_pill);
2290 RETURN(ptlrpc_reply(req));
2291 case OBD_LOG_CANCEL:
2292 CDEBUG(D_INODE, "log cancel\n");
2293 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2294 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2296 rc = llog_origin_handle_cancel(req);
2297 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2299 req->rq_status = rc;
2300 rc = req_capsule_server_pack(&req->rq_pill);
2303 RETURN(ptlrpc_reply(req));
2305 CDEBUG(D_INODE, "enqueue\n");
2306 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2307 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2309 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2311 ldlm_server_glimpse_ast);
2312 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2315 CDEBUG(D_INODE, "convert\n");
2316 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2317 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2319 rc = ldlm_handle_convert(req);
2322 CDEBUG(D_INODE, "cancel\n");
2323 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2324 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2326 rc = ldlm_handle_cancel(req);
2328 case LDLM_BL_CALLBACK:
2329 case LDLM_CP_CALLBACK:
2330 CDEBUG(D_INODE, "callback\n");
2331 CERROR("callbacks should not happen on OST\n");
2334 CERROR("Unexpected opcode %d\n",
2335 lustre_msg_get_opc(req->rq_reqmsg));
2336 req->rq_status = -ENOTSUPP;
2337 rc = ptlrpc_error(req);
2341 LASSERT(current->journal_info == NULL);
2344 /* If we're DISCONNECTing, the export_data is already freed */
2345 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2346 target_committed_to_req(req);
2350 oti_to_request(oti, req);
2352 target_send_reply(req, rc, fail);
2355 EXPORT_SYMBOL(ost_handle);
2357 * free per-thread pool created by ost_thread_init().
2359 static void ost_thread_done(struct ptlrpc_thread *thread)
2361 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2366 LASSERT(thread != NULL);
2369 * be prepared to handle partially-initialized pools (because this is
2370 * called from ost_thread_init() for cleanup.
2372 tls = thread->t_data;
2375 thread->t_data = NULL;
2381 * initialize per-thread page pool (bug 5137).
2383 static int ost_thread_init(struct ptlrpc_thread *thread)
2385 struct ost_thread_local_cache *tls;
2389 LASSERT(thread != NULL);
2390 LASSERT(thread->t_data == NULL);
2391 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
2396 thread->t_data = tls;
2400 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2402 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2403 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2405 struct ost_obd *ost = &obd->u.ost;
2406 struct lprocfs_static_vars lvars;
2407 int oss_min_threads;
2408 int oss_max_threads;
2409 int oss_min_create_threads;
2410 int oss_max_create_threads;
2414 rc = cfs_cleanup_group_info();
2418 lprocfs_ost_init_vars(&lvars);
2419 lprocfs_obd_setup(obd, lvars.obd_vars);
2421 cfs_sema_init(&ost->ost_health_sem, 1);
2423 if (oss_num_threads) {
2424 /* If oss_num_threads is set, it is the min and the max. */
2425 if (oss_num_threads > OSS_THREADS_MAX)
2426 oss_num_threads = OSS_THREADS_MAX;
2427 if (oss_num_threads < OSS_THREADS_MIN)
2428 oss_num_threads = OSS_THREADS_MIN;
2429 oss_max_threads = oss_min_threads = oss_num_threads;
2431 /* Base min threads on memory and cpus */
2433 cfs_num_possible_cpus() * CFS_NUM_CACHEPAGES >>
2434 (27 - CFS_PAGE_SHIFT);
2435 if (oss_min_threads < OSS_THREADS_MIN)
2436 oss_min_threads = OSS_THREADS_MIN;
2437 /* Insure a 4x range for dynamic threads */
2438 if (oss_min_threads > OSS_THREADS_MAX / 4)
2439 oss_min_threads = OSS_THREADS_MAX / 4;
2440 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
2444 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2445 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
2446 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2447 ost_handle, LUSTRE_OSS_NAME,
2448 obd->obd_proc_entry, target_print_req,
2449 oss_min_threads, oss_max_threads,
2450 "ll_ost", LCT_DT_THREAD, NULL);
2451 if (ost->ost_service == NULL) {
2452 CERROR("failed to start service\n");
2453 GOTO(out_lprocfs, rc = -ENOMEM);
2456 rc = ptlrpc_start_threads(ost->ost_service);
2458 GOTO(out_service, rc = -EINVAL);
2460 if (oss_num_create_threads) {
2461 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
2462 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
2463 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
2464 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
2465 oss_min_create_threads = oss_max_create_threads =
2466 oss_num_create_threads;
2468 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
2469 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
2472 ost->ost_create_service =
2473 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2474 OST_MAXREPSIZE, OST_CREATE_PORTAL,
2475 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2476 ost_handle, "ost_create",
2477 obd->obd_proc_entry, target_print_req,
2478 oss_min_create_threads, oss_max_create_threads,
2479 "ll_ost_creat", LCT_DT_THREAD, NULL);
2480 if (ost->ost_create_service == NULL) {
2481 CERROR("failed to start OST create service\n");
2482 GOTO(out_service, rc = -ENOMEM);
2485 rc = ptlrpc_start_threads(ost->ost_create_service);
2487 GOTO(out_create, rc = -EINVAL);
2489 ost->ost_io_service =
2490 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2491 OST_MAXREPSIZE, OST_IO_PORTAL,
2492 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2493 ost_handle, "ost_io",
2494 obd->obd_proc_entry, target_print_req,
2495 oss_min_threads, oss_max_threads,
2496 "ll_ost_io", LCT_DT_THREAD, ost_hpreq_handler);
2497 if (ost->ost_io_service == NULL) {
2498 CERROR("failed to start OST I/O service\n");
2499 GOTO(out_create, rc = -ENOMEM);
2502 ost->ost_io_service->srv_init = ost_thread_init;
2503 ost->ost_io_service->srv_done = ost_thread_done;
2504 ost->ost_io_service->srv_cpu_affinity = 1;
2505 rc = ptlrpc_start_threads(ost->ost_io_service);
2507 GOTO(out_io, rc = -EINVAL);
2509 ping_evictor_start();
2514 ptlrpc_unregister_service(ost->ost_io_service);
2515 ost->ost_io_service = NULL;
2517 ptlrpc_unregister_service(ost->ost_create_service);
2518 ost->ost_create_service = NULL;
2520 ptlrpc_unregister_service(ost->ost_service);
2521 ost->ost_service = NULL;
2523 lprocfs_obd_cleanup(obd);
2527 static int ost_cleanup(struct obd_device *obd)
2529 struct ost_obd *ost = &obd->u.ost;
2533 ping_evictor_stop();
2535 /* there is no recovery for OST OBD, all recovery is controlled by
2537 LASSERT(obd->obd_recovering == 0);
2538 cfs_down(&ost->ost_health_sem);
2539 ptlrpc_unregister_service(ost->ost_service);
2540 ptlrpc_unregister_service(ost->ost_create_service);
2541 ptlrpc_unregister_service(ost->ost_io_service);
2542 ost->ost_service = NULL;
2543 ost->ost_create_service = NULL;
2544 cfs_up(&ost->ost_health_sem);
2546 lprocfs_obd_cleanup(obd);
2551 static int ost_health_check(struct obd_device *obd)
2553 struct ost_obd *ost = &obd->u.ost;
2556 cfs_down(&ost->ost_health_sem);
2557 rc |= ptlrpc_service_health_check(ost->ost_service);
2558 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2559 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2560 cfs_up(&ost->ost_health_sem);
2563 * health_check to return 0 on healthy
2564 * and 1 on unhealthy.
2572 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2574 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2577 /* use obd ops to offer management infrastructure */
2578 static struct obd_ops ost_obd_ops = {
2579 .o_owner = THIS_MODULE,
2580 .o_setup = ost_setup,
2581 .o_cleanup = ost_cleanup,
2582 .o_health_check = ost_health_check,
2586 static int __init ost_init(void)
2588 struct lprocfs_static_vars lvars;
2592 lprocfs_ost_init_vars(&lvars);
2593 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2594 LUSTRE_OSS_NAME, NULL);
2596 if (ost_num_threads != 0 && oss_num_threads == 0) {
2597 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2598 "use oss_num_threads instead or unset both for "
2599 "dynamic thread startup\n");
2600 oss_num_threads = ost_num_threads;
2606 static void /*__exit*/ ost_exit(void)
2608 class_unregister_type(LUSTRE_OSS_NAME);
2611 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2612 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2613 MODULE_LICENSE("GPL");
2615 module_init(ost_init);
2616 module_exit(ost_exit);