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, 2012, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 * lustre/ost/ost_handler.c
40 * Author: Peter J. Braam <braam@clusterfs.com>
41 * Author: Phil Schwan <phil@clusterfs.com>
45 # define EXPORT_SYMTAB
47 #define DEBUG_SUBSYSTEM S_OST
49 #include <linux/module.h>
50 #include <obd_cksum.h>
52 #include <lustre_net.h>
53 #include <lustre_dlm.h>
54 #include <lustre_export.h>
55 #include <lustre_debug.h>
56 #include <linux/init.h>
57 #include <lprocfs_status.h>
58 #include <libcfs/list.h>
59 #include <lustre_quota.h>
60 #include "ost_internal.h"
62 static int oss_num_threads;
63 CFS_MODULE_PARM(oss_num_threads, "i", int, 0444,
64 "number of OSS service threads to start");
66 static int ost_num_threads;
67 CFS_MODULE_PARM(ost_num_threads, "i", int, 0444,
68 "number of OST service threads to start (deprecated)");
70 static int oss_num_create_threads;
71 CFS_MODULE_PARM(oss_num_create_threads, "i", int, 0444,
72 "number of OSS create threads to start");
75 * Do not return server-side uid/gid to remote client
77 static void ost_drop_id(struct obd_export *exp, struct obdo *oa)
79 if (exp_connect_rmtclient(exp)) {
82 oa->o_valid &= ~(OBD_MD_FLUID | OBD_MD_FLGID);
87 * Validate oa from client.
88 * If the request comes from 2.0 clients, currently only RSVD seq and IDIF
90 * a. for single MDS seq = FID_SEQ_OST_MDT0,
91 * b. for CMD, seq = FID_SEQ_OST_MDT0, FID_SEQ_OST_MDT1 - FID_SEQ_OST_MAX
93 static int ost_validate_obdo(struct obd_export *exp, struct obdo *oa,
94 struct obd_ioobj *ioobj)
96 if (oa != NULL && !(oa->o_valid & OBD_MD_FLGROUP)) {
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, &repbody->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 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
267 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
269 CERROR("Missing capability for OST GETATTR");
274 rc = req_capsule_server_pack(&req->rq_pill);
278 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
279 repbody->oa = body->oa;
281 rc = ost_lock_get(exp, &repbody->oa, 0, OBD_OBJECT_EOF, &lh, LCK_PR, 0);
285 OBD_ALLOC_PTR(oinfo);
287 GOTO(unlock, rc = -ENOMEM);
288 oinfo->oi_oa = &repbody->oa;
289 oinfo->oi_capa = capa;
291 req->rq_status = obd_getattr(exp, oinfo);
295 ost_drop_id(exp, &repbody->oa);
298 ost_lock_put(exp, &lh, LCK_PR);
302 static int ost_statfs(struct ptlrpc_request *req)
304 struct obd_statfs *osfs;
308 rc = req_capsule_server_pack(&req->rq_pill);
312 osfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
314 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
315 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
317 if (req->rq_status != 0)
318 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
323 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
324 struct obd_trans_info *oti)
326 struct ost_body *body, *repbody;
330 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
334 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
338 rc = req_capsule_server_pack(&req->rq_pill);
342 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
343 repbody->oa = body->oa;
344 oti->oti_logcookies = &body->oa.o_lcookie;
346 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
347 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
351 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
352 struct obd_trans_info *oti)
354 struct ost_body *body, *repbody;
356 struct lustre_handle lh = {0,};
359 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
360 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
362 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
366 rc = ost_validate_obdo(exp, &body->oa, NULL);
370 if ((body->oa.o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
371 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
374 rc = req_capsule_server_pack(&req->rq_pill);
378 /* standard truncate optimization: if file body is completely
379 * destroyed, don't send data back to the server. */
380 if (body->oa.o_size == 0)
381 flags |= LDLM_AST_DISCARD_DATA;
383 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
384 repbody->oa = body->oa;
386 rc = ost_lock_get(exp, &repbody->oa, repbody->oa.o_size,
387 repbody->oa.o_blocks, &lh, LCK_PW, flags);
389 struct obd_info *oinfo;
390 struct lustre_capa *capa = NULL;
392 if (repbody->oa.o_valid & OBD_MD_FLFLAGS &&
393 repbody->oa.o_flags == OBD_FL_SRVLOCK)
395 * If OBD_FL_SRVLOCK is the only bit set in
396 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
397 * through filter_setattr() to filter_iocontrol().
399 repbody->oa.o_valid &= ~OBD_MD_FLFLAGS;
401 if (repbody->oa.o_valid & OBD_MD_FLOSSCAPA) {
402 capa = req_capsule_client_get(&req->rq_pill,
405 CERROR("Missing capability for OST PUNCH");
406 GOTO(unlock, rc = -EFAULT);
410 OBD_ALLOC_PTR(oinfo);
412 GOTO(unlock, rc = -ENOMEM);
413 oinfo->oi_oa = &repbody->oa;
414 oinfo->oi_policy.l_extent.start = oinfo->oi_oa->o_size;
415 oinfo->oi_policy.l_extent.end = oinfo->oi_oa->o_blocks;
416 oinfo->oi_capa = capa;
417 oinfo->oi_flags = OBD_FL_PUNCH;
419 req->rq_status = obd_punch(exp, oinfo, oti, NULL);
422 ost_lock_put(exp, &lh, LCK_PW);
425 ost_drop_id(exp, &repbody->oa);
429 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
431 struct ost_body *body, *repbody;
432 struct obd_info *oinfo;
433 struct lustre_capa *capa = NULL;
437 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
441 rc = ost_validate_obdo(exp, &body->oa, NULL);
445 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
446 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
448 CERROR("Missing capability for OST SYNC");
453 rc = req_capsule_server_pack(&req->rq_pill);
457 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
458 repbody->oa = body->oa;
460 OBD_ALLOC_PTR(oinfo);
464 oinfo->oi_oa = &repbody->oa;
465 oinfo->oi_capa = capa;
466 req->rq_status = obd_sync(exp, oinfo, repbody->oa.o_size,
467 repbody->oa.o_blocks, NULL);
470 ost_drop_id(exp, &repbody->oa);
474 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
475 struct obd_trans_info *oti)
477 struct ost_body *body, *repbody;
478 struct obd_info *oinfo;
479 struct lustre_capa *capa = NULL;
483 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
487 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
491 rc = req_capsule_server_pack(&req->rq_pill);
495 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
496 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
498 CERROR("Missing capability for OST SETATTR");
503 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
504 repbody->oa = body->oa;
506 OBD_ALLOC_PTR(oinfo);
509 oinfo->oi_oa = &repbody->oa;
510 oinfo->oi_capa = capa;
512 req->rq_status = obd_setattr(exp, oinfo, oti);
516 ost_drop_id(exp, &repbody->oa);
520 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
521 cksum_type_t cksum_type)
526 cksum = init_checksum(cksum_type);
527 for (i = 0; i < desc->bd_iov_count; i++) {
528 struct page *page = desc->bd_iov[i].kiov_page;
529 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
530 char *ptr = kmap(page) + off;
531 int len = desc->bd_iov[i].kiov_len;
533 /* corrupt the data before we compute the checksum, to
534 * simulate a client->OST data error */
535 if (i == 0 && opc == OST_WRITE &&
536 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
537 memcpy(ptr, "bad3", min(4, len));
538 cksum = compute_checksum(cksum, ptr, len, cksum_type);
539 /* corrupt the data after we compute the checksum, to
540 * simulate an OST->client data error */
541 if (i == 0 && opc == OST_READ &&
542 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
543 memcpy(ptr, "bad4", min(4, len));
544 /* nobody should use corrupted page again */
545 ClearPageUptodate(page);
550 return fini_checksum(cksum, cksum_type);
553 static int ost_brw_lock_get(int mode, struct obd_export *exp,
554 struct obd_ioobj *obj, struct niobuf_remote *nb,
555 struct lustre_handle *lh)
558 int nrbufs = obj->ioo_bufcnt;
559 struct ldlm_res_id res_id;
560 ldlm_policy_data_t policy;
564 osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id);
565 LASSERT(mode == LCK_PR || mode == LCK_PW);
566 LASSERT(!lustre_handle_is_used(lh));
568 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
571 for (i = 1; i < nrbufs; i ++)
572 if ((nb[0].flags & OBD_BRW_SRVLOCK) !=
573 (nb[i].flags & OBD_BRW_SRVLOCK))
576 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
577 policy.l_extent.end = (nb[nrbufs - 1].offset +
578 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
580 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
581 LDLM_EXTENT, &policy, mode, &flags,
582 ldlm_blocking_ast, ldlm_completion_ast,
583 ldlm_glimpse_ast, NULL, 0, NULL, lh));
586 static void ost_brw_lock_put(int mode,
587 struct obd_ioobj *obj, struct niobuf_remote *niob,
588 struct lustre_handle *lh)
591 LASSERT(mode == LCK_PR || mode == LCK_PW);
592 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
593 lustre_handle_is_used(lh));
594 if (lustre_handle_is_used(lh))
595 ldlm_lock_decref(lh, mode);
599 /* Allocate thread local buffers if needed */
600 static struct ost_thread_local_cache *ost_tls_get(struct ptlrpc_request *r)
602 struct ost_thread_local_cache *tls =
603 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
605 /* In normal mode of operation an I/O request is serviced only
606 * by ll_ost_io threads each of them has own tls buffers allocated by
608 * During recovery, an I/O request may be queued until any of the ost
609 * service threads process it. Not necessary it should be one of
610 * ll_ost_io threads. In that case we dynamically allocating tls
611 * buffers for the request service time. */
612 if (unlikely(tls == NULL)) {
613 LASSERT(r->rq_export->exp_in_recovery);
617 r->rq_svc_thread->t_data = tls;
623 /* Free thread local buffers if they were allocated only for servicing
624 * this one request */
625 static void ost_tls_put(struct ptlrpc_request *r)
627 struct ost_thread_local_cache *tls =
628 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
630 if (unlikely(tls->temporary)) {
632 r->rq_svc_thread->t_data = NULL;
636 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
638 struct ptlrpc_bulk_desc *desc = NULL;
639 struct obd_export *exp = req->rq_export;
640 struct niobuf_remote *remote_nb;
641 struct niobuf_local *local_nb;
642 struct obd_ioobj *ioo;
643 struct ost_body *body, *repbody;
644 struct lustre_capa *capa = NULL;
645 struct l_wait_info lwi;
646 struct lustre_handle lockh = { 0 };
647 int niocount, npages, nob = 0, rc, i;
649 struct ost_thread_local_cache *tls;
652 req->rq_bulk_read = 1;
654 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
655 GOTO(out, rc = -EIO);
657 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
659 /* Check if there is eviction in progress, and if so, wait for it to
661 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
662 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
663 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
664 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
668 GOTO(out, rc = -ENOTCONN);
670 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
671 * ost_rw_hpreq_check(). */
672 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
674 GOTO(out, rc = -EFAULT);
677 * A req_capsule_X_get_array(pill, field, ptr_to_element_count) function
678 * would be useful here and wherever we get &RMF_OBD_IOOBJ and
679 * &RMF_NIOBUF_REMOTE.
681 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
683 GOTO(out, rc = -EFAULT);
685 rc = ost_validate_obdo(exp, &body->oa, ioo);
689 niocount = ioo->ioo_bufcnt;
690 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
691 if (remote_nb == NULL)
692 GOTO(out, rc = -EFAULT);
694 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
695 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
697 CERROR("Missing capability for OST BRW READ");
698 GOTO(out, rc = -EFAULT);
702 rc = req_capsule_server_pack(&req->rq_pill);
706 tls = ost_tls_get(req);
708 GOTO(out_bulk, rc = -ENOMEM);
709 local_nb = tls->local;
711 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
716 * If getting the lock took more time than
717 * client was willing to wait, drop it. b=11330
719 if (cfs_time_current_sec() > req->rq_deadline ||
720 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
722 CERROR("Dropping timed-out read from %s because locking"
723 "object "LPX64" took %ld seconds (limit was %ld).\n",
724 libcfs_id2str(req->rq_peer), ioo->ioo_id,
725 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
726 req->rq_deadline - req->rq_arrival_time.tv_sec);
727 GOTO(out_lock, rc = -ETIMEDOUT);
730 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
731 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
733 npages = OST_THREAD_POOL_SIZE;
734 rc = obd_preprw(OBD_BRW_READ, exp, &repbody->oa, 1, ioo,
735 remote_nb, &npages, local_nb, oti, capa);
739 desc = ptlrpc_prep_bulk_exp(req, npages,
740 BULK_PUT_SOURCE, OST_BULK_PORTAL);
742 GOTO(out_commitrw, rc = -ENOMEM);
745 for (i = 0; i < npages; i++) {
746 int page_rc = local_nb[i].rc;
748 if (page_rc < 0) { /* error */
754 if (page_rc != 0) { /* some data! */
755 LASSERT (local_nb[i].page != NULL);
756 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
757 local_nb[i].offset & ~CFS_PAGE_MASK,
761 if (page_rc != local_nb[i].len) { /* short read */
762 /* All subsequent pages should be 0 */
764 LASSERT(local_nb[i].rc == 0);
769 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
770 cksum_type_t cksum_type =
771 cksum_type_unpack(repbody->oa.o_valid & OBD_MD_FLFLAGS ?
772 repbody->oa.o_flags : 0);
773 repbody->oa.o_flags = cksum_type_pack(cksum_type);
774 repbody->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
775 repbody->oa.o_cksum = ost_checksum_bulk(desc, OST_READ,cksum_type);
776 CDEBUG(D_PAGE, "checksum at read origin: %x\n",
777 repbody->oa.o_cksum);
779 repbody->oa.o_valid = 0;
781 /* We're finishing using body->oa as an input variable */
783 /* Check if client was evicted while we were doing i/o before touching
786 rc = target_bulk_io(exp, desc, &lwi);
791 /* Must commit after prep above in all cases */
792 rc = obd_commitrw(OBD_BRW_READ, exp, &repbody->oa, 1, ioo,
793 remote_nb, npages, local_nb, oti, rc);
796 ost_drop_id(exp, &repbody->oa);
799 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
804 ptlrpc_free_bulk(desc);
808 req->rq_status = nob;
809 ptlrpc_lprocfs_brw(req, nob);
810 target_committed_to_req(req);
812 } else if (!no_reply) {
813 /* Only reply if there was no comms problem with bulk */
814 target_committed_to_req(req);
818 /* reply out callback would free */
819 ptlrpc_req_drop_rs(req);
820 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
821 "client will retry\n",
822 exp->exp_obd->obd_name,
823 exp->exp_client_uuid.uuid,
824 exp->exp_connection->c_remote_uuid.uuid,
825 libcfs_id2str(req->rq_peer));
831 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
833 struct ptlrpc_bulk_desc *desc = NULL;
834 struct obd_export *exp = req->rq_export;
835 struct niobuf_remote *remote_nb;
836 struct niobuf_local *local_nb;
837 struct obd_ioobj *ioo;
838 struct ost_body *body, *repbody;
839 struct l_wait_info lwi;
840 struct lustre_handle lockh = {0};
841 struct lustre_capa *capa = NULL;
843 int objcount, niocount, npages;
845 obd_count client_cksum = 0, server_cksum = 0;
846 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
847 int no_reply = 0, mmap = 0;
848 __u32 o_uid = 0, o_gid = 0;
849 struct ost_thread_local_cache *tls;
852 req->rq_bulk_write = 1;
854 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
855 GOTO(out, rc = -EIO);
856 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
857 GOTO(out, rc = -EFAULT);
859 /* pause before transaction has been started */
860 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
862 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
863 * ost_rw_hpreq_check(). */
864 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
866 GOTO(out, rc = -EFAULT);
868 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
869 RCL_CLIENT) / sizeof(*ioo);
870 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
872 GOTO(out, rc = -EFAULT);
874 rc = ost_validate_obdo(exp, &body->oa, ioo);
878 for (niocount = i = 0; i < objcount; i++)
879 niocount += ioo[i].ioo_bufcnt;
882 * It'd be nice to have a capsule function to indicate how many elements
883 * there were in a buffer for an RMF that's declared to be an array.
884 * It's easy enough to compute the number of elements here though.
886 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
887 if (remote_nb == NULL || niocount != (req_capsule_get_size(&req->rq_pill,
888 &RMF_NIOBUF_REMOTE, RCL_CLIENT) / sizeof(*remote_nb)))
889 GOTO(out, rc = -EFAULT);
891 if ((remote_nb[0].flags & OBD_BRW_MEMALLOC) &&
892 (exp->exp_connection->c_peer.nid == exp->exp_connection->c_self))
893 cfs_memory_pressure_set();
895 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
896 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
898 CERROR("Missing capability for OST BRW WRITE");
899 GOTO(out, rc = -EFAULT);
903 req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER,
904 niocount * sizeof(*rcs));
905 rc = req_capsule_server_pack(&req->rq_pill);
908 CFS_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, cfs_fail_val);
909 rcs = req_capsule_server_get(&req->rq_pill, &RMF_RCS);
911 tls = ost_tls_get(req);
913 GOTO(out_bulk, rc = -ENOMEM);
914 local_nb = tls->local;
916 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
921 * If getting the lock took more time than
922 * client was willing to wait, drop it. b=11330
924 if (cfs_time_current_sec() > req->rq_deadline ||
925 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
927 CERROR("Dropping timed-out write from %s because locking "
928 "object "LPX64" took %ld seconds (limit was %ld).\n",
929 libcfs_id2str(req->rq_peer), ioo->ioo_id,
930 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
931 req->rq_deadline - req->rq_arrival_time.tv_sec);
932 GOTO(out_lock, rc = -ETIMEDOUT);
935 /* obd_preprw clobbers oa->valid, so save what we need */
936 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
937 client_cksum = body->oa.o_cksum;
938 if (body->oa.o_valid & OBD_MD_FLFLAGS)
939 cksum_type = cksum_type_unpack(body->oa.o_flags);
941 if (body->oa.o_valid & OBD_MD_FLFLAGS && body->oa.o_flags & OBD_FL_MMAP)
944 /* Because we already sync grant info with client when reconnect,
945 * grant info will be cleared for resent req, then fed_grant and
946 * total_grant will not be modified in following preprw_write */
947 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
948 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
949 body->oa.o_valid &= ~OBD_MD_FLGRANT;
952 if (exp_connect_rmtclient(exp)) {
953 o_uid = body->oa.o_uid;
954 o_gid = body->oa.o_gid;
957 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
958 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
960 npages = OST_THREAD_POOL_SIZE;
961 rc = obd_preprw(OBD_BRW_WRITE, exp, &repbody->oa, objcount,
962 ioo, remote_nb, &npages, local_nb, oti, capa);
966 desc = ptlrpc_prep_bulk_exp(req, npages,
967 BULK_GET_SINK, OST_BULK_PORTAL);
969 GOTO(skip_transfer, rc = -ENOMEM);
971 /* NB Having prepped, we must commit... */
973 for (i = 0; i < npages; i++)
974 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
975 local_nb[i].offset & ~CFS_PAGE_MASK,
978 rc = sptlrpc_svc_prep_bulk(req, desc);
982 rc = target_bulk_io(exp, desc, &lwi);
986 if (unlikely(client_cksum != 0 && rc == 0)) {
987 static int cksum_counter;
988 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
989 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
990 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
991 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
992 repbody->oa.o_cksum = server_cksum;
994 if (unlikely(client_cksum != server_cksum)) {
995 CDEBUG_LIMIT(mmap ? D_INFO : D_ERROR,
996 "client csum %x, server csum %x\n",
997 client_cksum, server_cksum);
999 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1000 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1001 cksum_counter, libcfs_id2str(req->rq_peer),
1006 /* Must commit after prep above in all cases */
1007 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1008 remote_nb, npages, local_nb, oti, rc);
1009 if (rc == -ENOTCONN)
1010 /* quota acquire process has been given up because
1011 * either the client has been evicted or the client
1012 * has timed out the request already */
1015 if (exp_connect_rmtclient(exp)) {
1016 repbody->oa.o_uid = o_uid;
1017 repbody->oa.o_gid = o_gid;
1021 * Disable sending mtime back to the client. If the client locked the
1022 * whole object, then it has already updated the mtime on its side,
1023 * otherwise it will have to glimpse anyway (see bug 21489, comment 32)
1025 repbody->oa.o_valid &= ~(OBD_MD_FLMTIME | OBD_MD_FLATIME);
1027 if (unlikely(client_cksum != server_cksum && rc == 0 && !mmap)) {
1028 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1033 if (new_cksum == server_cksum)
1034 msg = "changed in transit before arrival at OST";
1035 else if (new_cksum == client_cksum)
1036 msg = "initial checksum before message complete";
1038 msg = "changed in transit AND after initial checksum";
1040 if (req->rq_peer.nid == desc->bd_sender) {
1044 router = libcfs_nid2str(desc->bd_sender);
1047 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1048 "%s%s%s inode "DFID" object "
1049 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1050 exp->exp_obd->obd_name, msg,
1051 libcfs_id2str(req->rq_peer),
1053 body->oa.o_valid & OBD_MD_FLFID ?
1054 body->oa.o_parent_seq : (__u64)0,
1055 body->oa.o_valid & OBD_MD_FLFID ?
1056 body->oa.o_parent_oid : 0,
1057 body->oa.o_valid & OBD_MD_FLFID ?
1058 body->oa.o_parent_ver : 0,
1060 body->oa.o_valid & OBD_MD_FLGROUP ?
1061 body->oa.o_seq : (__u64)0,
1063 local_nb[npages-1].offset +
1064 local_nb[npages-1].len - 1 );
1065 CERROR("client csum %x, original server csum %x, "
1066 "server csum now %x\n",
1067 client_cksum, server_cksum, new_cksum);
1073 /* set per-requested niobuf return codes */
1074 for (i = j = 0; i < niocount; i++) {
1075 int len = remote_nb[i].len;
1080 LASSERT(j < npages);
1081 if (local_nb[j].rc < 0)
1082 rcs[i] = local_nb[j].rc;
1083 len -= local_nb[j].len;
1088 LASSERT(j == npages);
1089 ptlrpc_lprocfs_brw(req, nob);
1093 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1098 ptlrpc_free_bulk(desc);
1101 oti_to_request(oti, req);
1102 target_committed_to_req(req);
1103 rc = ptlrpc_reply(req);
1104 } else if (!no_reply) {
1105 /* Only reply if there was no comms problem with bulk */
1106 target_committed_to_req(req);
1107 req->rq_status = rc;
1110 /* reply out callback would free */
1111 ptlrpc_req_drop_rs(req);
1112 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1113 "client will retry\n",
1114 exp->exp_obd->obd_name,
1115 exp->exp_client_uuid.uuid,
1116 exp->exp_connection->c_remote_uuid.uuid,
1117 libcfs_id2str(req->rq_peer));
1119 cfs_memory_pressure_clr();
1124 * Implementation of OST_SET_INFO.
1126 * OST_SET_INFO is like ioctl(): heavily overloaded. Specifically, it takes a
1127 * "key" and a value RPC buffers as arguments, with the value's contents
1128 * interpreted according to the key.
1130 * Value types that need swabbing have swabbing done explicitly, either here or
1131 * in functions called from here. This should be corrected: all swabbing should
1132 * be done in the capsule abstraction, as that will then allow us to move
1133 * swabbing exclusively to the client without having to modify server code
1134 * outside the capsule abstraction's implementation itself. To correct this
1135 * will require minor changes to the capsule abstraction; see the comments for
1136 * req_capsule_extend() in layout.c.
1138 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1140 struct ost_body *body = NULL, *repbody;
1141 char *key, *val = NULL;
1142 int keylen, vallen, rc = 0;
1143 int is_grant_shrink = 0;
1146 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1148 DEBUG_REQ(D_HA, req, "no set_info key");
1151 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1154 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1157 if ((is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK)))
1158 /* In this case the value is actually an RMF_OST_BODY, so we
1159 * transmutate the type of this PTLRPC */
1160 req_capsule_extend(&req->rq_pill, &RQF_OST_SET_GRANT_INFO);
1162 rc = req_capsule_server_pack(&req->rq_pill);
1167 if (is_grant_shrink) {
1168 body = req_capsule_client_get(&req->rq_pill,
1173 repbody = req_capsule_server_get(&req->rq_pill,
1175 memcpy(repbody, body, sizeof(*body));
1176 val = (char*)repbody;
1178 val = req_capsule_client_get(&req->rq_pill,
1183 if (KEY_IS(KEY_EVICT_BY_NID)) {
1185 obd_export_evict_by_nid(exp->exp_obd, val);
1187 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1188 if (vallen < sizeof(__u32))
1190 __swab32s((__u32 *)val);
1193 /* OBD will also check if KEY_IS(KEY_GRANT_SHRINK), and will cast val to
1194 * a struct ost_body * value */
1195 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1197 lustre_msg_set_status(req->rq_repmsg, 0);
1201 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1204 int keylen, replylen, rc = 0;
1205 struct req_capsule *pill = &req->rq_pill;
1208 /* this common part for get_info rpc */
1209 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1211 DEBUG_REQ(D_HA, req, "no get_info key");
1214 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1216 if (KEY_IS(KEY_FIEMAP)) {
1217 struct ll_fiemap_info_key *fm_key = key;
1220 rc = ost_validate_obdo(exp, &fm_key->oa, NULL);
1225 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1229 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1230 RCL_SERVER, replylen);
1232 rc = req_capsule_server_pack(pill);
1236 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1240 /* call again to fill in the reply buffer */
1241 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1243 lustre_msg_set_status(req->rq_repmsg, 0);
1247 #ifdef HAVE_QUOTA_SUPPORT
1248 static int ost_handle_quotactl(struct ptlrpc_request *req)
1250 struct obd_quotactl *oqctl, *repoqc;
1254 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1256 GOTO(out, rc = -EPROTO);
1258 rc = req_capsule_server_pack(&req->rq_pill);
1262 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1263 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1270 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1272 struct obd_quotactl *oqctl;
1276 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1280 rc = req_capsule_server_pack(&req->rq_pill);
1284 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1288 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1290 struct quota_adjust_qunit *oqaq, *repoqa;
1291 struct lustre_quota_ctxt *qctxt;
1295 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1296 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1298 GOTO(out, rc = -EPROTO);
1300 rc = req_capsule_server_pack(&req->rq_pill);
1304 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1305 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt, NULL);
1313 static int ost_llog_handle_connect(struct obd_export *exp,
1314 struct ptlrpc_request *req)
1316 struct llogd_conn_body *body;
1320 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
1321 rc = obd_llog_connect(exp, body);
1325 #define ost_init_sec_none(reply, exp) \
1327 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1328 OBD_CONNECT_RMT_CLIENT_FORCE | \
1329 OBD_CONNECT_OSS_CAPA); \
1330 cfs_spin_lock(&exp->exp_lock); \
1331 exp->exp_connect_flags = reply->ocd_connect_flags; \
1332 cfs_spin_unlock(&exp->exp_lock); \
1335 static int ost_init_sec_level(struct ptlrpc_request *req)
1337 struct obd_export *exp = req->rq_export;
1338 struct req_capsule *pill = &req->rq_pill;
1339 struct obd_device *obd = exp->exp_obd;
1340 struct filter_obd *filter = &obd->u.filter;
1341 char *client = libcfs_nid2str(req->rq_peer.nid);
1342 struct obd_connect_data *data, *reply;
1346 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1347 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1348 if (data == NULL || reply == NULL)
1351 /* connection from MDT is always trusted */
1352 if (req->rq_auth_usr_mdt) {
1353 ost_init_sec_none(reply, exp);
1357 /* no GSS support case */
1358 if (!req->rq_auth_gss) {
1359 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1360 CWARN("client %s -> target %s does not user GSS, "
1361 "can not run under security level %d.\n",
1362 client, obd->obd_name, filter->fo_sec_level);
1365 ost_init_sec_none(reply, exp);
1370 /* old version case */
1371 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1372 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1373 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1374 CWARN("client %s -> target %s uses old version, "
1375 "can not run under security level %d.\n",
1376 client, obd->obd_name, filter->fo_sec_level);
1379 CWARN("client %s -> target %s uses old version, "
1380 "run under security level %d.\n",
1381 client, obd->obd_name, filter->fo_sec_level);
1382 ost_init_sec_none(reply, exp);
1387 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1389 if (!req->rq_auth_remote)
1390 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1391 "asked to be remote.\n", client, obd->obd_name);
1392 } else if (req->rq_auth_remote) {
1394 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1395 "as remote by default.\n", client, obd->obd_name);
1399 if (!filter->fo_fl_oss_capa) {
1400 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1401 " but OSS capabilities are not enabled: %d.\n",
1402 client, obd->obd_name, filter->fo_fl_oss_capa);
1407 switch (filter->fo_sec_level) {
1408 case LUSTRE_SEC_NONE:
1410 ost_init_sec_none(reply, exp);
1413 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1414 "can not run under security level %d.\n",
1415 client, obd->obd_name, filter->fo_sec_level);
1418 case LUSTRE_SEC_REMOTE:
1420 ost_init_sec_none(reply, exp);
1422 case LUSTRE_SEC_ALL:
1424 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1425 OBD_CONNECT_RMT_CLIENT_FORCE);
1426 if (!filter->fo_fl_oss_capa)
1427 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1429 cfs_spin_lock(&exp->exp_lock);
1430 exp->exp_connect_flags = reply->ocd_connect_flags;
1431 cfs_spin_unlock(&exp->exp_lock);
1443 * this should be done in filter_connect()/filter_reconnect(), but
1444 * we can't obtain information like NID, which stored in incoming
1445 * request, thus can't decide what flavor to use. so we do it here.
1447 * This hack should be removed after the OST stack be rewritten, just
1448 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1450 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1452 struct obd_export *exp = req->rq_export;
1453 struct filter_obd *filter = &exp->exp_obd->u.filter;
1454 struct sptlrpc_flavor flvr;
1457 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1458 LUSTRE_ECHO_NAME) == 0)) {
1459 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1463 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1464 cfs_read_lock(&filter->fo_sptlrpc_lock);
1465 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1469 cfs_read_unlock(&filter->fo_sptlrpc_lock);
1471 cfs_spin_lock(&exp->exp_lock);
1473 exp->exp_sp_peer = req->rq_sp_from;
1474 exp->exp_flvr = flvr;
1476 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1477 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1478 CERROR("unauthorized rpc flavor %x from %s, "
1479 "expect %x\n", req->rq_flvr.sf_rpc,
1480 libcfs_nid2str(req->rq_peer.nid),
1481 exp->exp_flvr.sf_rpc);
1485 cfs_spin_unlock(&exp->exp_lock);
1487 if (exp->exp_sp_peer != req->rq_sp_from) {
1488 CERROR("RPC source %s doesn't match %s\n",
1489 sptlrpc_part2name(req->rq_sp_from),
1490 sptlrpc_part2name(exp->exp_sp_peer));
1493 rc = sptlrpc_target_export_check(exp, req);
1500 /* Ensure that data and metadata are synced to the disk when lock is cancelled
1502 int ost_blocking_ast(struct ldlm_lock *lock,
1503 struct ldlm_lock_desc *desc,
1504 void *data, int flag)
1506 __u32 sync_lock_cancel = 0;
1507 __u32 len = sizeof(sync_lock_cancel);
1511 rc = obd_get_info(lock->l_export, sizeof(KEY_SYNC_LOCK_CANCEL),
1512 KEY_SYNC_LOCK_CANCEL, &len, &sync_lock_cancel, NULL);
1514 if (!rc && flag == LDLM_CB_CANCELING &&
1515 (lock->l_granted_mode & (LCK_PW|LCK_GROUP)) &&
1516 (sync_lock_cancel == ALWAYS_SYNC_ON_CANCEL ||
1517 (sync_lock_cancel == BLOCKING_SYNC_ON_CANCEL &&
1518 lock->l_flags & LDLM_FL_CBPENDING))) {
1519 struct obd_info *oinfo;
1523 OBD_ALLOC_PTR(oinfo);
1528 OBD_FREE_PTR(oinfo);
1531 oa->o_id = lock->l_resource->lr_name.name[0];
1532 oa->o_seq = lock->l_resource->lr_name.name[1];
1533 oa->o_valid = OBD_MD_FLID|OBD_MD_FLGROUP;
1536 rc = obd_sync(lock->l_export, oinfo,
1537 lock->l_policy_data.l_extent.start,
1538 lock->l_policy_data.l_extent.end, NULL);
1540 CERROR("Error %d syncing data on lock cancel\n", rc);
1543 OBD_FREE_PTR(oinfo);
1546 rc = ldlm_server_blocking_ast(lock, desc, data, flag);
1550 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1551 struct obd_device *obd, int *process)
1553 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1554 case OST_CONNECT: /* This will never get here, but for completeness. */
1555 case OST_DISCONNECT:
1566 case OBD_LOG_CANCEL:
1568 *process = target_queue_recovery_request(req, obd);
1572 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1578 int ost_msg_check_version(struct lustre_msg *msg)
1582 switch(lustre_msg_get_opc(msg)) {
1584 case OST_DISCONNECT:
1587 case SEC_CTX_INIT_CONT:
1589 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1591 CERROR("bad opc %u version %08x, expecting %08x\n",
1592 lustre_msg_get_opc(msg),
1593 lustre_msg_get_version(msg),
1594 LUSTRE_OBD_VERSION);
1607 #ifdef HAVE_QUOTA_SUPPORT
1608 case OST_QUOTACHECK:
1610 case OST_QUOTA_ADJUST_QUNIT:
1612 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1614 CERROR("bad opc %u version %08x, expecting %08x\n",
1615 lustre_msg_get_opc(msg),
1616 lustre_msg_get_version(msg),
1617 LUSTRE_OST_VERSION);
1622 case LDLM_BL_CALLBACK:
1623 case LDLM_CP_CALLBACK:
1624 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1626 CERROR("bad opc %u version %08x, expecting %08x\n",
1627 lustre_msg_get_opc(msg),
1628 lustre_msg_get_version(msg),
1629 LUSTRE_DLM_VERSION);
1631 case LLOG_ORIGIN_CONNECT:
1632 case OBD_LOG_CANCEL:
1633 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1635 CERROR("bad opc %u version %08x, expecting %08x\n",
1636 lustre_msg_get_opc(msg),
1637 lustre_msg_get_version(msg),
1638 LUSTRE_LOG_VERSION);
1641 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1647 struct ost_prolong_data {
1648 struct ptlrpc_request *opd_req;
1649 struct obd_export *opd_exp;
1650 struct obdo *opd_oa;
1651 struct ldlm_res_id opd_resid;
1652 struct ldlm_extent opd_extent;
1653 ldlm_mode_t opd_mode;
1654 unsigned int opd_locks;
1658 /* prolong locks for the current service time of the corresponding
1659 * portal (= OST_IO_PORTAL)
1661 static inline int prolong_timeout(struct ptlrpc_request *req)
1663 struct ptlrpc_service *svc = req->rq_rqbd->rqbd_service;
1666 return obd_timeout / 2;
1668 return max(at_est2timeout(at_get(&svc->srv_at_estimate)), ldlm_timeout);
1671 static void ost_prolong_lock_one(struct ost_prolong_data *opd,
1672 struct ldlm_lock *lock)
1674 LASSERT(lock->l_req_mode == lock->l_granted_mode);
1675 LASSERT(lock->l_export == opd->opd_exp);
1677 /* XXX: never try to grab resource lock here because we're inside
1678 * exp_bl_list_lock; in ldlm_lockd.c to handle waiting list we take
1679 * res lock and then exp_bl_list_lock. */
1681 if (!(lock->l_flags & LDLM_FL_AST_SENT))
1682 /* ignore locks not being cancelled */
1686 "refreshed for req x"LPU64" ext("LPU64"->"LPU64") to %ds.\n",
1687 opd->opd_req->rq_xid, opd->opd_extent.start,
1688 opd->opd_extent.end, opd->opd_timeout);
1690 /* OK. this is a possible lock the user holds doing I/O
1691 * let's refresh eviction timer for it */
1692 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
1696 static void ost_prolong_locks(struct ost_prolong_data *data)
1698 struct obd_export *exp = data->opd_exp;
1699 struct obdo *oa = data->opd_oa;
1700 struct ldlm_lock *lock;
1703 if (oa->o_valid & OBD_MD_FLHANDLE) {
1704 /* mostly a request should be covered by only one lock, try
1706 lock = ldlm_handle2lock(&oa->o_handle);
1708 /* Fast path to check if the lock covers the whole IO
1709 * region exclusively. */
1710 if (lock->l_granted_mode == LCK_PW &&
1711 ldlm_extent_contain(&lock->l_policy_data.l_extent,
1712 &data->opd_extent)) {
1714 ost_prolong_lock_one(data, lock);
1715 LDLM_LOCK_PUT(lock);
1718 LDLM_LOCK_PUT(lock);
1723 cfs_spin_lock_bh(&exp->exp_bl_list_lock);
1724 cfs_list_for_each_entry(lock, &exp->exp_bl_list, l_exp_list) {
1725 LASSERT(lock->l_flags & LDLM_FL_AST_SENT);
1726 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
1728 if (!ldlm_res_eq(&data->opd_resid, &lock->l_resource->lr_name))
1731 if (!ldlm_extent_overlap(&lock->l_policy_data.l_extent,
1735 ost_prolong_lock_one(data, lock);
1737 cfs_spin_unlock_bh(&exp->exp_bl_list_lock);
1743 * Returns 1 if the given PTLRPC matches the given LDLM locks, or 0 if it does
1746 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1747 struct ldlm_lock *lock)
1749 struct niobuf_remote *nb;
1750 struct obd_ioobj *ioo;
1752 struct ldlm_extent ext;
1755 opc = lustre_msg_get_opc(req->rq_reqmsg);
1756 LASSERT(opc == OST_READ || opc == OST_WRITE);
1758 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1759 LASSERT(ioo != NULL);
1761 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1762 LASSERT(nb != NULL);
1764 ext.start = nb->offset;
1765 nb += ioo->ioo_bufcnt - 1;
1766 ext.end = nb->offset + nb->len - 1;
1768 LASSERT(lock->l_resource != NULL);
1769 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_seq,
1770 &lock->l_resource->lr_name))
1774 if (opc == OST_READ)
1776 if (!(lock->l_granted_mode & mode))
1779 RETURN(ldlm_extent_overlap(&lock->l_policy_data.l_extent, &ext));
1783 * High-priority queue request check for whether the given PTLRPC request (\a
1784 * req) is blocking an LDLM lock cancel.
1786 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1787 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1789 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1790 * function looks only at OST_READs and OST_WRITEs.
1792 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1794 struct obd_device *obd = req->rq_export->exp_obd;
1795 struct ost_body *body;
1796 struct obd_ioobj *ioo;
1797 struct niobuf_remote *nb;
1798 struct ost_prolong_data opd = { 0 };
1803 * Use LASSERT to do sanity check because malformed RPCs should have
1804 * been filtered out in ost_hpreq_handler().
1806 opc = lustre_msg_get_opc(req->rq_reqmsg);
1807 LASSERT(opc == OST_READ || opc == OST_WRITE);
1809 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1810 LASSERT(body != NULL);
1812 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1813 LASSERT(ioo != NULL);
1815 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1816 LASSERT(nb != NULL);
1817 LASSERT(!(nb->flags & OBD_BRW_SRVLOCK));
1819 osc_build_res_name(ioo->ioo_id, ioo->ioo_seq, &opd.opd_resid);
1823 if (opc == OST_READ)
1825 opd.opd_mode = mode;
1826 opd.opd_exp = req->rq_export;
1827 opd.opd_oa = &body->oa;
1828 opd.opd_extent.start = nb->offset;
1829 nb += ioo->ioo_bufcnt - 1;
1830 opd.opd_extent.end = nb->offset + nb->len - 1;
1831 opd.opd_timeout = prolong_timeout(req);
1833 DEBUG_REQ(D_RPCTRACE, req,
1834 "%s %s: refresh rw locks: " LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1835 obd->obd_name, cfs_current()->comm,
1836 opd.opd_resid.name[0], opd.opd_resid.name[1],
1837 opd.opd_extent.start, opd.opd_extent.end);
1839 ost_prolong_locks(&opd);
1841 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
1842 obd->obd_name, opd.opd_locks, req);
1844 RETURN(opd.opd_locks);
1847 static void ost_rw_hpreq_fini(struct ptlrpc_request *req)
1849 (void)ost_rw_hpreq_check(req);
1853 * Like ost_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
1855 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1856 struct ldlm_lock *lock)
1858 struct ost_body *body;
1861 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1862 LASSERT(body != NULL);
1864 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1865 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1872 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
1874 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1876 struct obd_device *obd = req->rq_export->exp_obd;
1877 struct ost_body *body;
1879 struct ost_prolong_data opd = { 0 };
1883 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1884 LASSERT(body != NULL);
1887 LASSERT(!(oa->o_valid & OBD_MD_FLFLAGS) ||
1888 !(oa->o_flags & OBD_FL_SRVLOCK));
1891 end = start + oa->o_blocks;
1894 opd.opd_mode = LCK_PW;
1895 opd.opd_exp = req->rq_export;
1897 opd.opd_extent.start = start;
1898 opd.opd_extent.end = end;
1899 if (oa->o_blocks == OBD_OBJECT_EOF)
1900 opd.opd_extent.end = OBD_OBJECT_EOF;
1901 opd.opd_timeout = prolong_timeout(req);
1903 osc_build_res_name(oa->o_id, oa->o_seq, &opd.opd_resid);
1906 "%s: refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1908 opd.opd_resid.name[0], opd.opd_resid.name[1],
1909 opd.opd_extent.start, opd.opd_extent.end);
1911 ost_prolong_locks(&opd);
1913 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
1914 obd->obd_name, opd.opd_locks, req);
1916 RETURN(opd.opd_locks > 0);
1919 static void ost_punch_hpreq_fini(struct ptlrpc_request *req)
1921 (void)ost_punch_hpreq_check(req);
1924 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
1925 .hpreq_lock_match = ost_rw_hpreq_lock_match,
1926 .hpreq_check = ost_rw_hpreq_check,
1927 .hpreq_fini = ost_rw_hpreq_fini
1930 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
1931 .hpreq_lock_match = ost_punch_hpreq_lock_match,
1932 .hpreq_check = ost_punch_hpreq_check,
1933 .hpreq_fini = ost_punch_hpreq_fini
1936 /** Assign high priority operations to the request if needed. */
1937 static int ost_hpreq_handler(struct ptlrpc_request *req)
1940 if (req->rq_export) {
1941 int opc = lustre_msg_get_opc(req->rq_reqmsg);
1942 struct ost_body *body;
1944 if (opc == OST_READ || opc == OST_WRITE) {
1945 struct niobuf_remote *nb;
1946 struct obd_ioobj *ioo;
1947 int objcount, niocount;
1951 /* RPCs on the H-P queue can be inspected before
1952 * ost_handler() initializes their pills, so we
1953 * initialize that here. Capsule initialization is
1954 * idempotent, as is setting the pill's format (provided
1955 * it doesn't change).
1957 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1958 if (opc == OST_READ)
1959 req_capsule_set(&req->rq_pill,
1962 req_capsule_set(&req->rq_pill,
1963 &RQF_OST_BRW_WRITE);
1965 body = req_capsule_client_get(&req->rq_pill,
1968 CERROR("Missing/short ost_body\n");
1972 objcount = req_capsule_get_size(&req->rq_pill,
1976 if (objcount == 0) {
1977 CERROR("Missing/short ioobj\n");
1981 CERROR("too many ioobjs (%d)\n", objcount);
1985 ioo = req_capsule_client_get(&req->rq_pill,
1988 CERROR("Missing/short ioobj\n");
1992 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
1994 CERROR("invalid object ids\n");
1998 for (niocount = i = 0; i < objcount; i++) {
1999 if (ioo[i].ioo_bufcnt == 0) {
2000 CERROR("ioo[%d] has zero bufcnt\n", i);
2003 niocount += ioo[i].ioo_bufcnt;
2005 if (niocount > PTLRPC_MAX_BRW_PAGES) {
2006 DEBUG_REQ(D_RPCTRACE, req,
2007 "bulk has too many pages (%d)",
2012 nb = req_capsule_client_get(&req->rq_pill,
2013 &RMF_NIOBUF_REMOTE);
2015 CERROR("Missing/short niobuf\n");
2019 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
2020 req->rq_ops = &ost_hpreq_rw;
2021 } else if (opc == OST_PUNCH) {
2022 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2023 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2025 body = req_capsule_client_get(&req->rq_pill,
2028 CERROR("Missing/short ost_body\n");
2032 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
2033 !(body->oa.o_flags & OBD_FL_SRVLOCK))
2034 req->rq_ops = &ost_hpreq_punch;
2040 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
2041 int ost_handle(struct ptlrpc_request *req)
2043 struct obd_trans_info trans_info = { 0, };
2044 struct obd_trans_info *oti = &trans_info;
2045 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
2046 struct obd_device *obd = NULL;
2049 LASSERT(current->journal_info == NULL);
2051 /* primordial rpcs don't affect server recovery */
2052 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2054 case SEC_CTX_INIT_CONT:
2059 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2061 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
2062 if (!class_connected_export(req->rq_export)) {
2063 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
2064 lustre_msg_get_opc(req->rq_reqmsg),
2065 libcfs_id2str(req->rq_peer));
2066 req->rq_status = -ENOTCONN;
2067 GOTO(out, rc = -ENOTCONN);
2070 obd = req->rq_export->exp_obd;
2072 /* Check for aborted recovery. */
2073 if (obd->obd_recovering) {
2074 rc = ost_filter_recovery_request(req, obd,
2076 if (rc || !should_process)
2078 else if (should_process < 0) {
2079 req->rq_status = should_process;
2080 rc = ptlrpc_error(req);
2088 rc = ost_msg_check_version(req->rq_reqmsg);
2092 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2094 CDEBUG(D_INODE, "connect\n");
2095 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
2096 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
2098 rc = target_handle_connect(req);
2099 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
2102 rc = ost_init_sec_level(req);
2104 rc = ost_connect_check_sptlrpc(req);
2108 case OST_DISCONNECT:
2109 CDEBUG(D_INODE, "disconnect\n");
2110 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
2111 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
2113 rc = target_handle_disconnect(req);
2116 CDEBUG(D_INODE, "create\n");
2117 req_capsule_set(&req->rq_pill, &RQF_OST_CREATE);
2118 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
2120 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2121 GOTO(out, rc = -EROFS);
2122 rc = ost_create(req->rq_export, req, oti);
2125 CDEBUG(D_INODE, "destroy\n");
2126 req_capsule_set(&req->rq_pill, &RQF_OST_DESTROY);
2127 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
2129 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2130 GOTO(out, rc = -EROFS);
2131 rc = ost_destroy(req->rq_export, req, oti);
2134 CDEBUG(D_INODE, "getattr\n");
2135 req_capsule_set(&req->rq_pill, &RQF_OST_GETATTR);
2136 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
2138 rc = ost_getattr(req->rq_export, req);
2141 CDEBUG(D_INODE, "setattr\n");
2142 req_capsule_set(&req->rq_pill, &RQF_OST_SETATTR);
2143 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
2145 rc = ost_setattr(req->rq_export, req, oti);
2148 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_WRITE);
2149 CDEBUG(D_INODE, "write\n");
2150 /* req->rq_request_portal would be nice, if it was set */
2151 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2152 CERROR("%s: deny write request from %s to portal %u\n",
2153 req->rq_export->exp_obd->obd_name,
2154 obd_export_nid2str(req->rq_export),
2155 req->rq_rqbd->rqbd_service->srv_req_portal);
2156 GOTO(out, rc = -EPROTO);
2158 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2160 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
2161 GOTO(out, rc = -ENOSPC);
2162 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2163 GOTO(out, rc = -EROFS);
2164 rc = ost_brw_write(req, oti);
2165 LASSERT(current->journal_info == NULL);
2166 /* ost_brw_write sends its own replies */
2169 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_READ);
2170 CDEBUG(D_INODE, "read\n");
2171 /* req->rq_request_portal would be nice, if it was set */
2172 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2173 CERROR("%s: deny read request from %s to portal %u\n",
2174 req->rq_export->exp_obd->obd_name,
2175 obd_export_nid2str(req->rq_export),
2176 req->rq_rqbd->rqbd_service->srv_req_portal);
2177 GOTO(out, rc = -EPROTO);
2179 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2181 rc = ost_brw_read(req, oti);
2182 LASSERT(current->journal_info == NULL);
2183 /* ost_brw_read sends its own replies */
2186 CDEBUG(D_INODE, "punch\n");
2187 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2188 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2190 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2191 GOTO(out, rc = -EROFS);
2192 rc = ost_punch(req->rq_export, req, oti);
2195 CDEBUG(D_INODE, "statfs\n");
2196 req_capsule_set(&req->rq_pill, &RQF_OST_STATFS);
2197 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2199 rc = ost_statfs(req);
2202 CDEBUG(D_INODE, "sync\n");
2203 req_capsule_set(&req->rq_pill, &RQF_OST_SYNC);
2204 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2206 rc = ost_sync(req->rq_export, req);
2209 DEBUG_REQ(D_INODE, req, "set_info");
2210 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
2211 rc = ost_set_info(req->rq_export, req);
2214 DEBUG_REQ(D_INODE, req, "get_info");
2215 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
2216 rc = ost_get_info(req->rq_export, req);
2218 #ifdef HAVE_QUOTA_SUPPORT
2219 case OST_QUOTACHECK:
2220 CDEBUG(D_INODE, "quotacheck\n");
2221 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2222 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2224 rc = ost_handle_quotacheck(req);
2227 CDEBUG(D_INODE, "quotactl\n");
2228 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2229 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2231 rc = ost_handle_quotactl(req);
2233 case OST_QUOTA_ADJUST_QUNIT:
2234 CDEBUG(D_INODE, "quota_adjust_qunit\n");
2235 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
2236 rc = ost_handle_quota_adjust_qunit(req);
2240 DEBUG_REQ(D_INODE, req, "ping");
2241 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2242 rc = target_handle_ping(req);
2244 /* FIXME - just reply status */
2245 case LLOG_ORIGIN_CONNECT:
2246 DEBUG_REQ(D_INODE, req, "log connect");
2247 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2248 rc = ost_llog_handle_connect(req->rq_export, req);
2249 req->rq_status = rc;
2250 rc = req_capsule_server_pack(&req->rq_pill);
2253 RETURN(ptlrpc_reply(req));
2254 case OBD_LOG_CANCEL:
2255 CDEBUG(D_INODE, "log cancel\n");
2256 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2257 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2259 rc = llog_origin_handle_cancel(req);
2260 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2262 req->rq_status = rc;
2263 rc = req_capsule_server_pack(&req->rq_pill);
2266 RETURN(ptlrpc_reply(req));
2268 CDEBUG(D_INODE, "enqueue\n");
2269 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2270 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2272 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2274 ldlm_server_glimpse_ast);
2275 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2278 CDEBUG(D_INODE, "convert\n");
2279 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2280 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2282 rc = ldlm_handle_convert(req);
2285 CDEBUG(D_INODE, "cancel\n");
2286 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2287 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2289 rc = ldlm_handle_cancel(req);
2291 case LDLM_BL_CALLBACK:
2292 case LDLM_CP_CALLBACK:
2293 CDEBUG(D_INODE, "callback\n");
2294 CERROR("callbacks should not happen on OST\n");
2297 CERROR("Unexpected opcode %d\n",
2298 lustre_msg_get_opc(req->rq_reqmsg));
2299 req->rq_status = -ENOTSUPP;
2300 rc = ptlrpc_error(req);
2304 LASSERT(current->journal_info == NULL);
2307 /* If we're DISCONNECTing, the export_data is already freed */
2308 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2309 target_committed_to_req(req);
2313 oti_to_request(oti, req);
2315 target_send_reply(req, rc, fail);
2318 EXPORT_SYMBOL(ost_handle);
2320 * free per-thread pool created by ost_thread_init().
2322 static void ost_thread_done(struct ptlrpc_thread *thread)
2324 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2329 LASSERT(thread != NULL);
2332 * be prepared to handle partially-initialized pools (because this is
2333 * called from ost_thread_init() for cleanup.
2335 tls = thread->t_data;
2338 thread->t_data = NULL;
2344 * initialize per-thread page pool (bug 5137).
2346 static int ost_thread_init(struct ptlrpc_thread *thread)
2348 struct ost_thread_local_cache *tls;
2352 LASSERT(thread != NULL);
2353 LASSERT(thread->t_data == NULL);
2354 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
2359 thread->t_data = tls;
2363 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2365 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2366 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2368 struct ost_obd *ost = &obd->u.ost;
2369 struct lprocfs_static_vars lvars;
2370 int oss_min_threads;
2371 int oss_max_threads;
2372 int oss_min_create_threads;
2373 int oss_max_create_threads;
2377 rc = cfs_cleanup_group_info();
2381 lprocfs_ost_init_vars(&lvars);
2382 lprocfs_obd_setup(obd, lvars.obd_vars);
2384 cfs_sema_init(&ost->ost_health_sem, 1);
2386 if (oss_num_threads) {
2387 /* If oss_num_threads is set, it is the min and the max. */
2388 if (oss_num_threads > OSS_THREADS_MAX)
2389 oss_num_threads = OSS_THREADS_MAX;
2390 if (oss_num_threads < OSS_THREADS_MIN)
2391 oss_num_threads = OSS_THREADS_MIN;
2392 oss_max_threads = oss_min_threads = oss_num_threads;
2394 /* Base min threads on memory and cpus */
2396 cfs_num_possible_cpus() * CFS_NUM_CACHEPAGES >>
2397 (27 - CFS_PAGE_SHIFT);
2398 if (oss_min_threads < OSS_THREADS_MIN)
2399 oss_min_threads = OSS_THREADS_MIN;
2400 /* Insure a 4x range for dynamic threads */
2401 if (oss_min_threads > OSS_THREADS_MAX / 4)
2402 oss_min_threads = OSS_THREADS_MAX / 4;
2403 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
2407 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2408 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
2409 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2410 ost_handle, LUSTRE_OSS_NAME,
2411 obd->obd_proc_entry, target_print_req,
2412 oss_min_threads, oss_max_threads,
2413 "ll_ost", LCT_DT_THREAD, NULL);
2414 if (ost->ost_service == NULL) {
2415 CERROR("failed to start service\n");
2416 GOTO(out_lprocfs, rc = -ENOMEM);
2419 rc = ptlrpc_start_threads(ost->ost_service);
2421 GOTO(out_service, rc = -EINVAL);
2423 if (oss_num_create_threads) {
2424 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
2425 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
2426 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
2427 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
2428 oss_min_create_threads = oss_max_create_threads =
2429 oss_num_create_threads;
2431 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
2432 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
2435 ost->ost_create_service =
2436 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2437 OST_MAXREPSIZE, OST_CREATE_PORTAL,
2438 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2439 ost_handle, "ost_create",
2440 obd->obd_proc_entry, target_print_req,
2441 oss_min_create_threads, oss_max_create_threads,
2442 "ll_ost_creat", LCT_DT_THREAD, NULL);
2443 if (ost->ost_create_service == NULL) {
2444 CERROR("failed to start OST create service\n");
2445 GOTO(out_service, rc = -ENOMEM);
2448 rc = ptlrpc_start_threads(ost->ost_create_service);
2450 GOTO(out_create, rc = -EINVAL);
2452 ost->ost_io_service =
2453 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2454 OST_MAXREPSIZE, OST_IO_PORTAL,
2455 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2456 ost_handle, "ost_io",
2457 obd->obd_proc_entry, target_print_req,
2458 oss_min_threads, oss_max_threads,
2459 "ll_ost_io", LCT_DT_THREAD, ost_hpreq_handler);
2460 if (ost->ost_io_service == NULL) {
2461 CERROR("failed to start OST I/O service\n");
2462 GOTO(out_create, rc = -ENOMEM);
2465 ost->ost_io_service->srv_init = ost_thread_init;
2466 ost->ost_io_service->srv_done = ost_thread_done;
2467 ost->ost_io_service->srv_cpu_affinity = 1;
2468 rc = ptlrpc_start_threads(ost->ost_io_service);
2470 GOTO(out_io, rc = -EINVAL);
2472 ping_evictor_start();
2477 ptlrpc_unregister_service(ost->ost_io_service);
2478 ost->ost_io_service = NULL;
2480 ptlrpc_unregister_service(ost->ost_create_service);
2481 ost->ost_create_service = NULL;
2483 ptlrpc_unregister_service(ost->ost_service);
2484 ost->ost_service = NULL;
2486 lprocfs_obd_cleanup(obd);
2490 static int ost_cleanup(struct obd_device *obd)
2492 struct ost_obd *ost = &obd->u.ost;
2496 ping_evictor_stop();
2498 /* there is no recovery for OST OBD, all recovery is controlled by
2500 LASSERT(obd->obd_recovering == 0);
2501 cfs_down(&ost->ost_health_sem);
2502 ptlrpc_unregister_service(ost->ost_service);
2503 ptlrpc_unregister_service(ost->ost_create_service);
2504 ptlrpc_unregister_service(ost->ost_io_service);
2505 ost->ost_service = NULL;
2506 ost->ost_create_service = NULL;
2507 cfs_up(&ost->ost_health_sem);
2509 lprocfs_obd_cleanup(obd);
2514 static int ost_health_check(struct obd_device *obd)
2516 struct ost_obd *ost = &obd->u.ost;
2519 cfs_down(&ost->ost_health_sem);
2520 rc |= ptlrpc_service_health_check(ost->ost_service);
2521 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2522 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2523 cfs_up(&ost->ost_health_sem);
2526 * health_check to return 0 on healthy
2527 * and 1 on unhealthy.
2535 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2537 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2540 /* use obd ops to offer management infrastructure */
2541 static struct obd_ops ost_obd_ops = {
2542 .o_owner = THIS_MODULE,
2543 .o_setup = ost_setup,
2544 .o_cleanup = ost_cleanup,
2545 .o_health_check = ost_health_check,
2549 static int __init ost_init(void)
2551 struct lprocfs_static_vars lvars;
2555 lprocfs_ost_init_vars(&lvars);
2556 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2557 LUSTRE_OSS_NAME, NULL);
2559 if (ost_num_threads != 0 && oss_num_threads == 0) {
2560 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2561 "use oss_num_threads instead or unset both for "
2562 "dynamic thread startup\n");
2563 oss_num_threads = ost_num_threads;
2569 static void /*__exit*/ ost_exit(void)
2571 class_unregister_type(LUSTRE_OSS_NAME);
2574 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2575 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2576 MODULE_LICENSE("GPL");
2578 module_init(ost_init);
2579 module_exit(ost_exit);