4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ost/ost_handler.c
38 * Author: Peter J. Braam <braam@clusterfs.com>
39 * Author: Phil Schwan <phil@clusterfs.com>
42 #define DEBUG_SUBSYSTEM S_OST
44 #include <linux/module.h>
45 #include <obd_cksum.h>
47 #include <lustre_net.h>
48 #include <lustre_dlm.h>
49 #include <lustre_export.h>
50 #include <lustre_debug.h>
51 #include <lustre_fid.h>
52 #include <lustre_fld.h>
53 #include <linux/init.h>
54 #include <lprocfs_status.h>
55 #include <libcfs/list.h>
56 #include <lustre_quota.h>
57 #include <lustre_fid.h>
58 #include "ost_internal.h"
59 #include <lustre_fid.h>
61 static int oss_num_threads;
62 CFS_MODULE_PARM(oss_num_threads, "i", int, 0444,
63 "number of OSS service threads to start");
65 static int ost_num_threads;
66 CFS_MODULE_PARM(ost_num_threads, "i", int, 0444,
67 "number of OST service threads to start (deprecated)");
69 static int oss_num_create_threads;
70 CFS_MODULE_PARM(oss_num_create_threads, "i", int, 0444,
71 "number of OSS create threads to start");
73 static char *oss_cpts;
74 CFS_MODULE_PARM(oss_cpts, "s", charp, 0444,
75 "CPU partitions OSS threads should run on");
77 static char *oss_io_cpts;
78 CFS_MODULE_PARM(oss_io_cpts, "s", charp, 0444,
79 "CPU partitions OSS IO threads should run on");
82 * this page is allocated statically when module is initializing
83 * it is used to simulate data corruptions, see ost_checksum_bulk()
84 * for details. as the original pages provided by the layers below
85 * can be remain in the internal cache, we do not want to modify
88 static struct page *ost_page_to_corrupt = NULL;
91 * Do not return server-side uid/gid to remote client
93 static void ost_drop_id(struct obd_export *exp, struct obdo *oa)
95 if (exp_connect_rmtclient(exp)) {
98 oa->o_valid &= ~(OBD_MD_FLUID | OBD_MD_FLGID);
103 * Validate oa from client.
104 * If the request comes from 2.0 clients, currently only RSVD seq and IDIF
106 * a. for single MDS seq = FID_SEQ_OST_MDT0,
107 * b. for CMD, seq = FID_SEQ_OST_MDT0, FID_SEQ_OST_MDT1 - FID_SEQ_OST_MAX
109 static int ost_validate_obdo(struct obd_export *exp, struct obdo *oa,
110 struct obd_ioobj *ioobj)
112 if (oa != NULL && !(oa->o_valid & OBD_MD_FLGROUP)) {
113 oa->o_seq = FID_SEQ_OST_MDT0;
115 ioobj->ioo_seq = FID_SEQ_OST_MDT0;
116 /* remove fid_seq_is_rsvd() after FID-on-OST allows SEQ > 9 */
117 } else if (oa == NULL ||
118 !(fid_seq_is_norm(oa->o_seq) || fid_seq_is_mdt(oa->o_seq) ||
119 fid_seq_is_echo(oa->o_seq))) {
120 CERROR("%s: client %s sent invalid object "POSTID"\n",
121 exp->exp_obd->obd_name, obd_export_nid2str(exp),
122 oa ? oa->o_id : -1, oa ? oa->o_seq : -1);
125 obdo_from_ostid(oa, &oa->o_oi);
127 ioobj_from_obdo(ioobj, oa);
131 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
133 struct oti_req_ack_lock *ack_lock;
139 if (req->rq_repmsg) {
140 __u64 versions[PTLRPC_NUM_VERSIONS] = { 0 };
141 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
142 versions[0] = oti->oti_pre_version;
143 lustre_msg_set_versions(req->rq_repmsg, versions);
145 req->rq_transno = oti->oti_transno;
147 /* XXX 4 == entries in oti_ack_locks??? */
148 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
151 /* XXX not even calling target_send_reply in some cases... */
152 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode, 0);
156 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
157 struct obd_trans_info *oti)
159 struct ost_body *body, *repbody;
160 struct lustre_capa *capa = NULL;
164 /* Get the request body */
165 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
169 if (body->oa.o_id == 0)
172 rc = ost_validate_obdo(exp, &body->oa, NULL);
176 /* If there's a DLM request, cancel the locks mentioned in it*/
177 if (req_capsule_field_present(&req->rq_pill, &RMF_DLM_REQ, RCL_CLIENT)) {
178 struct ldlm_request *dlm;
180 dlm = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
183 ldlm_request_cancel(req, dlm, 0);
186 /* If there's a capability, get it */
187 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
188 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
190 CERROR("Missing capability for OST DESTROY");
195 /* Prepare the reply */
196 rc = req_capsule_server_pack(&req->rq_pill);
200 /* Get the log cancellation cookie */
201 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
202 oti->oti_logcookies = &body->oa.o_lcookie;
204 /* Finish the reply */
205 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
206 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
208 /* Do the destroy and set the reply status accordingly */
209 req->rq_status = obd_destroy(req->rq_svc_thread->t_env, exp,
210 &repbody->oa, NULL, oti, NULL, capa);
215 * Helper function for getting server side [start, start+count] DLM lock
216 * if asked by client.
218 static int ost_lock_get(struct obd_export *exp, struct obdo *oa,
219 __u64 start, __u64 count, struct lustre_handle *lh,
220 int mode, __u64 flags)
222 struct ldlm_res_id res_id;
223 ldlm_policy_data_t policy;
224 __u64 end = start + count;
228 LASSERT(!lustre_handle_is_used(lh));
229 /* o_id and o_gr are used for localizing resource, if client miss to set
230 * them, do not trigger ASSERTION. */
231 if (unlikely((oa->o_valid & (OBD_MD_FLID | OBD_MD_FLGROUP)) !=
232 (OBD_MD_FLID | OBD_MD_FLGROUP)))
235 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
236 !(oa->o_flags & OBD_FL_SRVLOCK))
239 ostid_build_res_name(&oa->o_oi, &res_id);
240 CDEBUG(D_INODE, "OST-side extent lock.\n");
242 policy.l_extent.start = start & CFS_PAGE_MASK;
244 /* If ->o_blocks is EOF it means "lock till the end of the
245 * file". Otherwise, it's size of a hole being punched (in bytes) */
246 if (count == OBD_OBJECT_EOF || end < start)
247 policy.l_extent.end = OBD_OBJECT_EOF;
249 policy.l_extent.end = end | ~CFS_PAGE_MASK;
251 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
252 LDLM_EXTENT, &policy, mode, &flags,
253 ldlm_blocking_ast, ldlm_completion_ast,
254 ldlm_glimpse_ast, NULL, 0, LVB_T_NONE,
258 /* Helper function: release lock, if any. */
259 static void ost_lock_put(struct obd_export *exp,
260 struct lustre_handle *lh, int mode)
263 if (lustre_handle_is_used(lh))
264 ldlm_lock_decref(lh, mode);
268 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
270 struct ost_body *body, *repbody;
271 struct obd_info *oinfo;
272 struct lustre_handle lh = { 0 };
273 struct lustre_capa *capa = NULL;
277 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
281 rc = ost_validate_obdo(exp, &body->oa, NULL);
285 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
286 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
288 CERROR("Missing capability for OST GETATTR");
293 rc = req_capsule_server_pack(&req->rq_pill);
297 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
298 repbody->oa = body->oa;
300 rc = ost_lock_get(exp, &repbody->oa, 0, OBD_OBJECT_EOF, &lh, LCK_PR, 0);
304 OBD_ALLOC_PTR(oinfo);
306 GOTO(unlock, rc = -ENOMEM);
307 oinfo->oi_oa = &repbody->oa;
308 oinfo->oi_capa = capa;
310 req->rq_status = obd_getattr(req->rq_svc_thread->t_env, exp, oinfo);
314 ost_drop_id(exp, &repbody->oa);
317 ost_lock_put(exp, &lh, LCK_PR);
321 static int ost_statfs(struct ptlrpc_request *req)
323 struct obd_statfs *osfs;
327 rc = req_capsule_server_pack(&req->rq_pill);
331 osfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
333 req->rq_status = obd_statfs(req->rq_svc_thread->t_env, req->rq_export,
335 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
337 if (req->rq_status != 0)
338 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
340 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_EINPROGRESS))
341 req->rq_status = -EINPROGRESS;
346 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
347 struct obd_trans_info *oti)
349 struct ost_body *body, *repbody;
353 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
357 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
361 rc = req_capsule_server_pack(&req->rq_pill);
365 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
366 repbody->oa = body->oa;
367 oti->oti_logcookies = &body->oa.o_lcookie;
369 req->rq_status = obd_create(req->rq_svc_thread->t_env, exp,
370 &repbody->oa, NULL, oti);
371 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
375 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
376 struct obd_trans_info *oti)
378 struct ost_body *body, *repbody;
380 struct lustre_handle lh = {0,};
384 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
385 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
387 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
391 rc = ost_validate_obdo(exp, &body->oa, NULL);
395 if ((body->oa.o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
396 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
399 rc = req_capsule_server_pack(&req->rq_pill);
403 /* standard truncate optimization: if file body is completely
404 * destroyed, don't send data back to the server. */
405 if (body->oa.o_size == 0)
406 flags |= LDLM_AST_DISCARD_DATA;
408 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
409 repbody->oa = body->oa;
411 rc = ost_lock_get(exp, &repbody->oa, repbody->oa.o_size,
412 repbody->oa.o_blocks, &lh, LCK_PW, flags);
414 struct obd_info *oinfo;
415 struct lustre_capa *capa = NULL;
417 if (repbody->oa.o_valid & OBD_MD_FLFLAGS &&
418 repbody->oa.o_flags == OBD_FL_SRVLOCK)
420 * If OBD_FL_SRVLOCK is the only bit set in
421 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
422 * through filter_setattr() to filter_iocontrol().
424 repbody->oa.o_valid &= ~OBD_MD_FLFLAGS;
426 if (repbody->oa.o_valid & OBD_MD_FLOSSCAPA) {
427 capa = req_capsule_client_get(&req->rq_pill,
430 CERROR("Missing capability for OST PUNCH");
431 GOTO(unlock, rc = -EFAULT);
435 OBD_ALLOC_PTR(oinfo);
437 GOTO(unlock, rc = -ENOMEM);
438 oinfo->oi_oa = &repbody->oa;
439 oinfo->oi_policy.l_extent.start = oinfo->oi_oa->o_size;
440 oinfo->oi_policy.l_extent.end = oinfo->oi_oa->o_blocks;
441 oinfo->oi_capa = capa;
442 oinfo->oi_flags = OBD_FL_PUNCH;
444 req->rq_status = obd_punch(req->rq_svc_thread->t_env, exp,
448 ost_lock_put(exp, &lh, LCK_PW);
451 ost_drop_id(exp, &repbody->oa);
455 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req,
456 struct obd_trans_info *oti)
458 struct ost_body *body, *repbody;
459 struct obd_info *oinfo;
460 struct lustre_capa *capa = NULL;
464 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
468 rc = ost_validate_obdo(exp, &body->oa, NULL);
472 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
473 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
475 CERROR("Missing capability for OST SYNC");
480 rc = req_capsule_server_pack(&req->rq_pill);
484 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
485 repbody->oa = body->oa;
487 OBD_ALLOC_PTR(oinfo);
491 oinfo->oi_oa = &repbody->oa;
492 oinfo->oi_capa = capa;
493 oinfo->oi_jobid = oti->oti_jobid;
494 req->rq_status = obd_sync(req->rq_svc_thread->t_env, exp, oinfo,
495 repbody->oa.o_size, repbody->oa.o_blocks,
499 ost_drop_id(exp, &repbody->oa);
503 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
504 struct obd_trans_info *oti)
506 struct ost_body *body, *repbody;
507 struct obd_info *oinfo;
508 struct lustre_capa *capa = NULL;
512 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
516 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
520 rc = req_capsule_server_pack(&req->rq_pill);
524 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
525 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
527 CERROR("Missing capability for OST SETATTR");
532 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
533 repbody->oa = body->oa;
535 OBD_ALLOC_PTR(oinfo);
538 oinfo->oi_oa = &repbody->oa;
539 oinfo->oi_capa = capa;
541 req->rq_status = obd_setattr(req->rq_svc_thread->t_env, exp, oinfo,
546 ost_drop_id(exp, &repbody->oa);
550 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
551 cksum_type_t cksum_type)
553 struct cfs_crypto_hash_desc *hdesc;
554 unsigned int bufsize;
556 unsigned char cfs_alg = cksum_obd2cfs(cksum_type);
559 hdesc = cfs_crypto_hash_init(cfs_alg, NULL, 0);
561 CERROR("Unable to initialize checksum hash %s\n",
562 cfs_crypto_hash_name(cfs_alg));
563 return PTR_ERR(hdesc);
565 CDEBUG(D_INFO, "Checksum for algo %s\n", cfs_crypto_hash_name(cfs_alg));
566 for (i = 0; i < desc->bd_iov_count; i++) {
568 /* corrupt the data before we compute the checksum, to
569 * simulate a client->OST data error */
570 if (i == 0 && opc == OST_WRITE &&
571 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE)) {
572 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
573 int len = desc->bd_iov[i].kiov_len;
574 struct page *np = ost_page_to_corrupt;
575 char *ptr = kmap(desc->bd_iov[i].kiov_page) + off;
578 char *ptr2 = kmap(np) + off;
580 memcpy(ptr2, ptr, len);
581 memcpy(ptr2, "bad3", min(4, len));
583 desc->bd_iov[i].kiov_page = np;
585 CERROR("can't alloc page for corruption\n");
588 cfs_crypto_hash_update_page(hdesc, desc->bd_iov[i].kiov_page,
589 desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK,
590 desc->bd_iov[i].kiov_len);
592 /* corrupt the data after we compute the checksum, to
593 * simulate an OST->client data error */
594 if (i == 0 && opc == OST_READ &&
595 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
596 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
597 int len = desc->bd_iov[i].kiov_len;
598 struct page *np = ost_page_to_corrupt;
599 char *ptr = kmap(desc->bd_iov[i].kiov_page) + off;
602 char *ptr2 = kmap(np) + off;
604 memcpy(ptr2, ptr, len);
605 memcpy(ptr2, "bad4", min(4, len));
607 desc->bd_iov[i].kiov_page = np;
609 CERROR("can't alloc page for corruption\n");
615 err = cfs_crypto_hash_final(hdesc, (unsigned char *)&cksum, &bufsize);
617 cfs_crypto_hash_final(hdesc, NULL, NULL);
622 static int ost_brw_lock_get(int mode, struct obd_export *exp,
623 struct obd_ioobj *obj, struct niobuf_remote *nb,
624 struct lustre_handle *lh)
627 int nrbufs = obj->ioo_bufcnt;
628 struct ldlm_res_id res_id;
629 ldlm_policy_data_t policy;
633 ostid_build_res_name(&obj->ioo_oid, &res_id);
634 LASSERT(mode == LCK_PR || mode == LCK_PW);
635 LASSERT(!lustre_handle_is_used(lh));
637 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
640 for (i = 1; i < nrbufs; i ++)
641 if ((nb[0].flags & OBD_BRW_SRVLOCK) !=
642 (nb[i].flags & OBD_BRW_SRVLOCK))
645 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
646 policy.l_extent.end = (nb[nrbufs - 1].offset +
647 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
649 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
650 LDLM_EXTENT, &policy, mode, &flags,
651 ldlm_blocking_ast, ldlm_completion_ast,
652 ldlm_glimpse_ast, NULL, 0, LVB_T_NONE,
656 static void ost_brw_lock_put(int mode,
657 struct obd_ioobj *obj, struct niobuf_remote *niob,
658 struct lustre_handle *lh)
661 LASSERT(mode == LCK_PR || mode == LCK_PW);
662 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
663 lustre_handle_is_used(lh));
664 if (lustre_handle_is_used(lh))
665 ldlm_lock_decref(lh, mode);
669 /* Allocate thread local buffers if needed */
670 static struct ost_thread_local_cache *ost_tls_get(struct ptlrpc_request *r)
672 struct ost_thread_local_cache *tls =
673 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
675 /* In normal mode of operation an I/O request is serviced only
676 * by ll_ost_io threads each of them has own tls buffers allocated by
677 * ost_io_thread_init().
678 * During recovery, an I/O request may be queued until any of the ost
679 * service threads process it. Not necessary it should be one of
680 * ll_ost_io threads. In that case we dynamically allocating tls
681 * buffers for the request service time. */
682 if (unlikely(tls == NULL)) {
683 LASSERT(r->rq_export->exp_in_recovery);
687 r->rq_svc_thread->t_data = tls;
693 /* Free thread local buffers if they were allocated only for servicing
694 * this one request */
695 static void ost_tls_put(struct ptlrpc_request *r)
697 struct ost_thread_local_cache *tls =
698 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
700 if (unlikely(tls->temporary)) {
702 r->rq_svc_thread->t_data = NULL;
706 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
708 struct ptlrpc_bulk_desc *desc = NULL;
709 struct obd_export *exp = req->rq_export;
710 struct niobuf_remote *remote_nb;
711 struct niobuf_local *local_nb;
712 struct obd_ioobj *ioo;
713 struct ost_body *body, *repbody;
714 struct lustre_capa *capa = NULL;
715 struct l_wait_info lwi;
716 struct lustre_handle lockh = { 0 };
717 int niocount, npages, nob = 0, rc, i;
719 struct ost_thread_local_cache *tls;
722 req->rq_bulk_read = 1;
724 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
725 GOTO(out, rc = -EIO);
727 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
729 /* Check if there is eviction in progress, and if so, wait for it to
731 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
732 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
733 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
734 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
738 GOTO(out, rc = -ENOTCONN);
740 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
741 * ost_rw_hpreq_check(). */
742 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
744 GOTO(out, rc = -EFAULT);
747 * A req_capsule_X_get_array(pill, field, ptr_to_element_count) function
748 * would be useful here and wherever we get &RMF_OBD_IOOBJ and
749 * &RMF_NIOBUF_REMOTE.
751 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
753 GOTO(out, rc = -EFAULT);
755 rc = ost_validate_obdo(exp, &body->oa, ioo);
759 niocount = ioo->ioo_bufcnt;
760 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
761 if (remote_nb == NULL)
762 GOTO(out, rc = -EFAULT);
764 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
765 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
767 CERROR("Missing capability for OST BRW READ");
768 GOTO(out, rc = -EFAULT);
772 rc = req_capsule_server_pack(&req->rq_pill);
776 tls = ost_tls_get(req);
778 GOTO(out_bulk, rc = -ENOMEM);
779 local_nb = tls->local;
781 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
786 * If getting the lock took more time than
787 * client was willing to wait, drop it. b=11330
789 if (cfs_time_current_sec() > req->rq_deadline ||
790 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
792 CERROR("Dropping timed-out read from %s because locking"
793 "object "LPX64" took %ld seconds (limit was %ld).\n",
794 libcfs_id2str(req->rq_peer), ioo->ioo_id,
795 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
796 req->rq_deadline - req->rq_arrival_time.tv_sec);
797 GOTO(out_lock, rc = -ETIMEDOUT);
800 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
801 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
803 npages = OST_THREAD_POOL_SIZE;
804 rc = obd_preprw(req->rq_svc_thread->t_env, OBD_BRW_READ, exp,
805 &repbody->oa, 1, ioo, remote_nb, &npages, local_nb,
810 desc = ptlrpc_prep_bulk_exp(req, npages,
811 BULK_PUT_SOURCE, OST_BULK_PORTAL);
813 GOTO(out_commitrw, rc = -ENOMEM);
816 for (i = 0; i < npages; i++) {
817 int page_rc = local_nb[i].rc;
819 if (page_rc < 0) { /* error */
825 if (page_rc != 0) { /* some data! */
826 LASSERT (local_nb[i].page != NULL);
827 ptlrpc_prep_bulk_page_nopin(desc, local_nb[i].page,
828 local_nb[i].lnb_page_offset,
832 if (page_rc != local_nb[i].len) { /* short read */
833 /* All subsequent pages should be 0 */
835 LASSERT(local_nb[i].rc == 0);
840 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
841 cksum_type_t cksum_type =
842 cksum_type_unpack(repbody->oa.o_valid & OBD_MD_FLFLAGS ?
843 repbody->oa.o_flags : 0);
844 repbody->oa.o_flags = cksum_type_pack(cksum_type);
845 repbody->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
846 repbody->oa.o_cksum = ost_checksum_bulk(desc, OST_READ,cksum_type);
847 CDEBUG(D_PAGE, "checksum at read origin: %x\n",
848 repbody->oa.o_cksum);
850 repbody->oa.o_valid = 0;
852 /* We're finishing using body->oa as an input variable */
854 /* Check if client was evicted while we were doing i/o before touching
857 if (likely(!CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2)))
858 rc = target_bulk_io(exp, desc, &lwi);
863 /* Must commit after prep above in all cases */
864 rc = obd_commitrw(req->rq_svc_thread->t_env, OBD_BRW_READ, exp,
865 &repbody->oa, 1, ioo, remote_nb, npages, local_nb,
869 ost_drop_id(exp, &repbody->oa);
872 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
876 if (desc && !CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2))
877 ptlrpc_free_bulk_nopin(desc);
881 req->rq_status = nob;
882 ptlrpc_lprocfs_brw(req, nob);
883 target_committed_to_req(req);
885 } else if (!no_reply) {
886 /* Only reply if there was no comms problem with bulk */
887 target_committed_to_req(req);
891 /* reply out callback would free */
892 ptlrpc_req_drop_rs(req);
893 LCONSOLE_WARN("%s: Bulk IO read error with %s (at %s), "
894 "client will retry: rc %d\n",
895 exp->exp_obd->obd_name,
896 obd_uuid2str(&exp->exp_client_uuid),
897 obd_export_nid2str(exp), rc);
899 /* send a bulk after reply to simulate a network delay or reordering
901 if (unlikely(CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2))) {
903 struct l_wait_info lwi1;
905 CDEBUG(D_INFO, "reorder BULK\n");
906 cfs_waitq_init(&waitq);
908 lwi1 = LWI_TIMEOUT_INTR(cfs_time_seconds(3), NULL, NULL, NULL);
909 l_wait_event(waitq, 0, &lwi1);
910 rc = target_bulk_io(exp, desc, &lwi);
911 ptlrpc_free_bulk_nopin(desc);
917 static void ost_warn_on_cksum(struct ptlrpc_request *req,
918 struct ptlrpc_bulk_desc *desc,
919 struct niobuf_local *local_nb, int npages,
920 obd_count client_cksum, obd_count server_cksum,
923 struct obd_export *exp = req->rq_export;
924 struct ost_body *body;
928 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
929 LASSERT (body != NULL);
931 if (req->rq_peer.nid == desc->bd_sender) {
935 router = libcfs_nid2str(desc->bd_sender);
939 CDEBUG_LIMIT(D_INFO, "client csum %x, server csum %x\n",
940 client_cksum, server_cksum);
944 LCONSOLE_ERROR_MSG(0x168, "BAD WRITE CHECKSUM: %s from %s%s%s inode "
945 DFID" object "LPU64"/"LPU64" extent ["LPU64"-"LPU64
946 "]: client csum %x, server csum %x\n",
947 exp->exp_obd->obd_name, libcfs_id2str(req->rq_peer),
949 body->oa.o_valid & OBD_MD_FLFID ?
950 body->oa.o_parent_seq : (__u64)0,
951 body->oa.o_valid & OBD_MD_FLFID ?
952 body->oa.o_parent_oid : 0,
953 body->oa.o_valid & OBD_MD_FLFID ?
954 body->oa.o_parent_ver : 0,
956 body->oa.o_valid & OBD_MD_FLGROUP ?
957 body->oa.o_seq : (__u64)0,
958 local_nb[0].lnb_file_offset,
959 local_nb[npages-1].lnb_file_offset +
960 local_nb[npages-1].len - 1,
961 client_cksum, server_cksum);
964 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
966 struct ptlrpc_bulk_desc *desc = NULL;
967 struct obd_export *exp = req->rq_export;
968 struct niobuf_remote *remote_nb;
969 struct niobuf_local *local_nb;
970 struct obd_ioobj *ioo;
971 struct ost_body *body, *repbody;
972 struct l_wait_info lwi;
973 struct lustre_handle lockh = {0};
974 struct lustre_capa *capa = NULL;
976 int objcount, niocount, npages;
978 obd_count client_cksum = 0, server_cksum = 0;
979 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
980 int no_reply = 0, mmap = 0;
981 __u32 o_uid = 0, o_gid = 0;
982 struct ost_thread_local_cache *tls;
985 req->rq_bulk_write = 1;
987 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
988 GOTO(out, rc = -EIO);
989 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
990 GOTO(out, rc = -EFAULT);
992 /* pause before transaction has been started */
993 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
995 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
996 * ost_rw_hpreq_check(). */
997 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
999 GOTO(out, rc = -EFAULT);
1001 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1002 RCL_CLIENT) / sizeof(*ioo);
1003 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1005 GOTO(out, rc = -EFAULT);
1007 rc = ost_validate_obdo(exp, &body->oa, ioo);
1011 for (niocount = i = 0; i < objcount; i++)
1012 niocount += ioo[i].ioo_bufcnt;
1015 * It'd be nice to have a capsule function to indicate how many elements
1016 * there were in a buffer for an RMF that's declared to be an array.
1017 * It's easy enough to compute the number of elements here though.
1019 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1020 if (remote_nb == NULL || niocount != (req_capsule_get_size(&req->rq_pill,
1021 &RMF_NIOBUF_REMOTE, RCL_CLIENT) / sizeof(*remote_nb)))
1022 GOTO(out, rc = -EFAULT);
1024 if ((remote_nb[0].flags & OBD_BRW_MEMALLOC) &&
1025 (exp->exp_connection->c_peer.nid == exp->exp_connection->c_self))
1026 cfs_memory_pressure_set();
1028 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
1029 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
1031 CERROR("Missing capability for OST BRW WRITE");
1032 GOTO(out, rc = -EFAULT);
1036 req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER,
1037 niocount * sizeof(*rcs));
1038 rc = req_capsule_server_pack(&req->rq_pill);
1041 CFS_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, cfs_fail_val);
1042 rcs = req_capsule_server_get(&req->rq_pill, &RMF_RCS);
1044 tls = ost_tls_get(req);
1046 GOTO(out_bulk, rc = -ENOMEM);
1047 local_nb = tls->local;
1049 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
1054 * If getting the lock took more time than
1055 * client was willing to wait, drop it. b=11330
1057 if (cfs_time_current_sec() > req->rq_deadline ||
1058 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
1060 CERROR("Dropping timed-out write from %s because locking "
1061 "object "LPX64" took %ld seconds (limit was %ld).\n",
1062 libcfs_id2str(req->rq_peer), ioo->ioo_id,
1063 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
1064 req->rq_deadline - req->rq_arrival_time.tv_sec);
1065 GOTO(out_lock, rc = -ETIMEDOUT);
1068 /* obd_preprw clobbers oa->valid, so save what we need */
1069 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
1070 client_cksum = body->oa.o_cksum;
1071 if (body->oa.o_valid & OBD_MD_FLFLAGS)
1072 cksum_type = cksum_type_unpack(body->oa.o_flags);
1074 if (body->oa.o_valid & OBD_MD_FLFLAGS && body->oa.o_flags & OBD_FL_MMAP)
1077 /* Because we already sync grant info with client when reconnect,
1078 * grant info will be cleared for resent req, then fed_grant and
1079 * total_grant will not be modified in following preprw_write */
1080 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1081 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1082 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1085 if (exp_connect_rmtclient(exp)) {
1086 o_uid = body->oa.o_uid;
1087 o_gid = body->oa.o_gid;
1090 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
1091 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1093 npages = OST_THREAD_POOL_SIZE;
1094 rc = obd_preprw(req->rq_svc_thread->t_env, OBD_BRW_WRITE, exp,
1095 &repbody->oa, objcount, ioo, remote_nb, &npages,
1096 local_nb, oti, capa);
1100 desc = ptlrpc_prep_bulk_exp(req, npages,
1101 BULK_GET_SINK, OST_BULK_PORTAL);
1103 GOTO(skip_transfer, rc = -ENOMEM);
1105 /* NB Having prepped, we must commit... */
1107 for (i = 0; i < npages; i++)
1108 ptlrpc_prep_bulk_page_nopin(desc, local_nb[i].page,
1109 local_nb[i].lnb_page_offset,
1112 rc = sptlrpc_svc_prep_bulk(req, desc);
1116 rc = target_bulk_io(exp, desc, &lwi);
1120 if (client_cksum != 0 && rc == 0) {
1121 static int cksum_counter;
1122 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1123 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1124 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1125 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1126 repbody->oa.o_cksum = server_cksum;
1128 if (unlikely(client_cksum != server_cksum)) {
1129 ost_warn_on_cksum(req, desc, local_nb, npages,
1130 client_cksum, server_cksum, mmap);
1133 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1134 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1135 cksum_counter, libcfs_id2str(req->rq_peer),
1140 /* Must commit after prep above in all cases */
1141 rc = obd_commitrw(req->rq_svc_thread->t_env, OBD_BRW_WRITE, exp,
1142 &repbody->oa, objcount, ioo, remote_nb, npages,
1144 if (rc == -ENOTCONN)
1145 /* quota acquire process has been given up because
1146 * either the client has been evicted or the client
1147 * has timed out the request already */
1150 if (exp_connect_rmtclient(exp)) {
1151 repbody->oa.o_uid = o_uid;
1152 repbody->oa.o_gid = o_gid;
1156 * Disable sending mtime back to the client. If the client locked the
1157 * whole object, then it has already updated the mtime on its side,
1158 * otherwise it will have to glimpse anyway (see bug 21489, comment 32)
1160 repbody->oa.o_valid &= ~(OBD_MD_FLMTIME | OBD_MD_FLATIME);
1165 /* set per-requested niobuf return codes */
1166 for (i = j = 0; i < niocount; i++) {
1167 int len = remote_nb[i].len;
1172 LASSERT(j < npages);
1173 if (local_nb[j].rc < 0)
1174 rcs[i] = local_nb[j].rc;
1175 len -= local_nb[j].len;
1180 LASSERT(j == npages);
1181 ptlrpc_lprocfs_brw(req, nob);
1185 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1190 ptlrpc_free_bulk_nopin(desc);
1193 oti_to_request(oti, req);
1194 target_committed_to_req(req);
1195 rc = ptlrpc_reply(req);
1196 } else if (!no_reply) {
1197 /* Only reply if there was no comms problem with bulk */
1198 target_committed_to_req(req);
1199 req->rq_status = rc;
1202 /* reply out callback would free */
1203 ptlrpc_req_drop_rs(req);
1204 LCONSOLE_WARN("%s: Bulk IO write error with %s (at %s), "
1205 "client will retry: rc %d\n",
1206 exp->exp_obd->obd_name,
1207 obd_uuid2str(&exp->exp_client_uuid),
1208 obd_export_nid2str(exp), rc);
1210 cfs_memory_pressure_clr();
1215 * Implementation of OST_SET_INFO.
1217 * OST_SET_INFO is like ioctl(): heavily overloaded. Specifically, it takes a
1218 * "key" and a value RPC buffers as arguments, with the value's contents
1219 * interpreted according to the key.
1221 * Value types that need swabbing have swabbing done explicitly, either here or
1222 * in functions called from here. This should be corrected: all swabbing should
1223 * be done in the capsule abstraction, as that will then allow us to move
1224 * swabbing exclusively to the client without having to modify server code
1225 * outside the capsule abstraction's implementation itself. To correct this
1226 * will require minor changes to the capsule abstraction; see the comments for
1227 * req_capsule_extend() in layout.c.
1229 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1231 struct ost_body *body = NULL, *repbody;
1232 char *key, *val = NULL;
1233 int keylen, vallen, rc = 0;
1234 int is_grant_shrink = 0;
1237 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1239 DEBUG_REQ(D_HA, req, "no set_info key");
1242 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1245 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1248 if ((is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK)))
1249 /* In this case the value is actually an RMF_OST_BODY, so we
1250 * transmutate the type of this PTLRPC */
1251 req_capsule_extend(&req->rq_pill, &RQF_OST_SET_GRANT_INFO);
1253 rc = req_capsule_server_pack(&req->rq_pill);
1258 if (is_grant_shrink) {
1259 body = req_capsule_client_get(&req->rq_pill,
1264 repbody = req_capsule_server_get(&req->rq_pill,
1266 memcpy(repbody, body, sizeof(*body));
1267 val = (char*)repbody;
1269 val = req_capsule_client_get(&req->rq_pill,
1274 if (KEY_IS(KEY_EVICT_BY_NID)) {
1276 obd_export_evict_by_nid(exp->exp_obd, val);
1278 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1279 if (vallen < sizeof(__u32))
1281 __swab32s((__u32 *)val);
1284 /* OBD will also check if KEY_IS(KEY_GRANT_SHRINK), and will cast val to
1285 * a struct ost_body * value */
1286 rc = obd_set_info_async(req->rq_svc_thread->t_env, exp, keylen,
1287 key, vallen, val, NULL);
1289 lustre_msg_set_status(req->rq_repmsg, 0);
1293 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1296 int keylen, replylen, rc = 0;
1297 struct req_capsule *pill = &req->rq_pill;
1300 /* this common part for get_info rpc */
1301 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1303 DEBUG_REQ(D_HA, req, "no get_info key");
1306 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1308 if (KEY_IS(KEY_FIEMAP)) {
1309 struct ll_fiemap_info_key *fm_key = key;
1312 rc = ost_validate_obdo(exp, &fm_key->oa, NULL);
1317 rc = obd_get_info(req->rq_svc_thread->t_env, exp, keylen, key,
1318 &replylen, NULL, NULL);
1322 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1323 RCL_SERVER, replylen);
1325 rc = req_capsule_server_pack(pill);
1329 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1333 if (KEY_IS(KEY_LAST_FID)) {
1337 req_capsule_extend(pill, &RQF_OST_GET_INFO_LAST_FID);
1338 val = req_capsule_client_get(pill, &RMF_SETINFO_VAL);
1339 vallen = req_capsule_get_size(pill, &RMF_SETINFO_VAL,
1341 if (val != NULL && vallen > 0 && replylen >= vallen) {
1342 memcpy(reply, val, vallen);
1344 CERROR("%s: invalid req val %p vallen %d replylen %d\n",
1345 exp->exp_obd->obd_name, val, vallen, replylen);
1346 GOTO(out, rc = -EINVAL);
1350 /* call again to fill in the reply buffer */
1351 rc = obd_get_info(req->rq_svc_thread->t_env, exp, keylen, key,
1352 &replylen, reply, NULL);
1354 lustre_msg_set_status(req->rq_repmsg, 0);
1358 static int ost_handle_quotactl(struct ptlrpc_request *req)
1360 struct obd_quotactl *oqctl, *repoqc;
1364 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1366 GOTO(out, rc = -EPROTO);
1368 rc = req_capsule_server_pack(&req->rq_pill);
1372 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1373 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1380 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1382 struct obd_quotactl *oqctl;
1386 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1390 rc = req_capsule_server_pack(&req->rq_pill);
1394 /* deprecated, not used any more */
1395 req->rq_status = -EOPNOTSUPP;
1396 RETURN(-EOPNOTSUPP);
1399 static int ost_llog_handle_connect(struct obd_export *exp,
1400 struct ptlrpc_request *req)
1402 struct llogd_conn_body *body;
1406 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
1407 rc = obd_llog_connect(exp, body);
1411 #define ost_init_sec_none(reply, exp) \
1413 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1414 OBD_CONNECT_RMT_CLIENT_FORCE | \
1415 OBD_CONNECT_OSS_CAPA); \
1416 spin_lock(&exp->exp_lock); \
1417 exp->exp_connect_flags = reply->ocd_connect_flags; \
1418 spin_unlock(&exp->exp_lock); \
1421 static int ost_init_sec_level(struct ptlrpc_request *req)
1423 struct obd_export *exp = req->rq_export;
1424 struct req_capsule *pill = &req->rq_pill;
1425 struct obd_device *obd = exp->exp_obd;
1426 struct filter_obd *filter = &obd->u.filter;
1427 char *client = libcfs_nid2str(req->rq_peer.nid);
1428 struct obd_connect_data *data, *reply;
1432 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1433 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1434 if (data == NULL || reply == NULL)
1437 /* connection from MDT is always trusted */
1438 if (req->rq_auth_usr_mdt) {
1439 ost_init_sec_none(reply, exp);
1443 /* no GSS support case */
1444 if (!req->rq_auth_gss) {
1445 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1446 CWARN("client %s -> target %s does not user GSS, "
1447 "can not run under security level %d.\n",
1448 client, obd->obd_name, filter->fo_sec_level);
1451 ost_init_sec_none(reply, exp);
1456 /* old version case */
1457 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1458 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1459 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1460 CWARN("client %s -> target %s uses old version, "
1461 "can not run under security level %d.\n",
1462 client, obd->obd_name, filter->fo_sec_level);
1465 CWARN("client %s -> target %s uses old version, "
1466 "run under security level %d.\n",
1467 client, obd->obd_name, filter->fo_sec_level);
1468 ost_init_sec_none(reply, exp);
1473 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1475 if (!req->rq_auth_remote)
1476 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1477 "asked to be remote.\n", client, obd->obd_name);
1478 } else if (req->rq_auth_remote) {
1480 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1481 "as remote by default.\n", client, obd->obd_name);
1485 if (!filter->fo_fl_oss_capa) {
1486 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1487 " but OSS capabilities are not enabled: %d.\n",
1488 client, obd->obd_name, filter->fo_fl_oss_capa);
1493 switch (filter->fo_sec_level) {
1494 case LUSTRE_SEC_NONE:
1496 ost_init_sec_none(reply, exp);
1499 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1500 "can not run under security level %d.\n",
1501 client, obd->obd_name, filter->fo_sec_level);
1504 case LUSTRE_SEC_REMOTE:
1506 ost_init_sec_none(reply, exp);
1508 case LUSTRE_SEC_ALL:
1510 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1511 OBD_CONNECT_RMT_CLIENT_FORCE);
1512 if (!filter->fo_fl_oss_capa)
1513 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1515 spin_lock(&exp->exp_lock);
1516 exp->exp_connect_flags = reply->ocd_connect_flags;
1517 spin_unlock(&exp->exp_lock);
1529 * this should be done in filter_connect()/filter_reconnect(), but
1530 * we can't obtain information like NID, which stored in incoming
1531 * request, thus can't decide what flavor to use. so we do it here.
1533 * This hack should be removed after the OST stack be rewritten, just
1534 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1536 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1538 struct obd_export *exp = req->rq_export;
1539 struct filter_obd *filter = &exp->exp_obd->u.filter;
1540 struct sptlrpc_flavor flvr;
1543 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1544 LUSTRE_ECHO_NAME) == 0)) {
1545 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1549 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1550 read_lock(&filter->fo_sptlrpc_lock);
1551 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1555 read_unlock(&filter->fo_sptlrpc_lock);
1557 spin_lock(&exp->exp_lock);
1559 exp->exp_sp_peer = req->rq_sp_from;
1560 exp->exp_flvr = flvr;
1562 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1563 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1564 CERROR("unauthorized rpc flavor %x from %s, "
1565 "expect %x\n", req->rq_flvr.sf_rpc,
1566 libcfs_nid2str(req->rq_peer.nid),
1567 exp->exp_flvr.sf_rpc);
1571 spin_unlock(&exp->exp_lock);
1573 if (exp->exp_sp_peer != req->rq_sp_from) {
1574 CERROR("RPC source %s doesn't match %s\n",
1575 sptlrpc_part2name(req->rq_sp_from),
1576 sptlrpc_part2name(exp->exp_sp_peer));
1579 rc = sptlrpc_target_export_check(exp, req);
1586 /* Ensure that data and metadata are synced to the disk when lock is cancelled
1588 int ost_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
1589 void *data, int flag)
1592 __u32 sync_lock_cancel = 0;
1593 __u32 len = sizeof(sync_lock_cancel);
1598 rc = lu_env_init(&env, LCT_DT_THREAD);
1599 if (unlikely(rc != 0))
1602 rc = obd_get_info(&env, lock->l_export, sizeof(KEY_SYNC_LOCK_CANCEL),
1603 KEY_SYNC_LOCK_CANCEL, &len, &sync_lock_cancel, NULL);
1604 if (rc == 0 && flag == LDLM_CB_CANCELING &&
1605 (lock->l_granted_mode & (LCK_PW|LCK_GROUP)) &&
1606 (sync_lock_cancel == ALWAYS_SYNC_ON_CANCEL ||
1607 (sync_lock_cancel == BLOCKING_SYNC_ON_CANCEL &&
1608 lock->l_flags & LDLM_FL_CBPENDING))) {
1609 struct obd_info *oinfo;
1613 OBD_ALLOC_PTR(oinfo);
1615 GOTO(out_env, rc = -ENOMEM);
1618 OBD_FREE_PTR(oinfo);
1619 GOTO(out_env, rc = -ENOMEM);
1622 ostid_res_name_to_id(&oa->o_oi, &lock->l_resource->lr_name);
1623 oa->o_valid = OBD_MD_FLID|OBD_MD_FLGROUP;
1625 oinfo->oi_capa = BYPASS_CAPA;
1627 rc = obd_sync(&env, lock->l_export, oinfo,
1628 lock->l_policy_data.l_extent.start,
1629 lock->l_policy_data.l_extent.end, NULL);
1631 CERROR("Error %d syncing data on lock cancel\n", rc);
1634 OBD_FREE_PTR(oinfo);
1637 rc = ldlm_server_blocking_ast(lock, desc, data, flag);
1643 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1644 struct obd_device *obd, int *process)
1646 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1647 case OST_CONNECT: /* This will never get here, but for completeness. */
1648 case OST_DISCONNECT:
1659 case OBD_LOG_CANCEL:
1661 *process = target_queue_recovery_request(req, obd);
1665 DEBUG_REQ(D_WARNING, req, "not permitted during recovery");
1671 int ost_msg_check_version(struct lustre_msg *msg)
1675 switch(lustre_msg_get_opc(msg)) {
1677 case OST_DISCONNECT:
1680 case SEC_CTX_INIT_CONT:
1682 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1684 CERROR("bad opc %u version %08x, expecting %08x\n",
1685 lustre_msg_get_opc(msg),
1686 lustre_msg_get_version(msg),
1687 LUSTRE_OBD_VERSION);
1690 /* Note: client always use MDS_VERSION for FID request */
1691 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
1693 CERROR("bad opc %u version %08x, expecting %08x\n",
1694 lustre_msg_get_opc(msg),
1695 lustre_msg_get_version(msg),
1696 LUSTRE_MDS_VERSION);
1709 case OST_QUOTACHECK:
1711 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1713 CERROR("bad opc %u version %08x, expecting %08x\n",
1714 lustre_msg_get_opc(msg),
1715 lustre_msg_get_version(msg),
1716 LUSTRE_OST_VERSION);
1721 case LDLM_BL_CALLBACK:
1722 case LDLM_CP_CALLBACK:
1723 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1725 CERROR("bad opc %u version %08x, expecting %08x\n",
1726 lustre_msg_get_opc(msg),
1727 lustre_msg_get_version(msg),
1728 LUSTRE_DLM_VERSION);
1730 case LLOG_ORIGIN_CONNECT:
1731 case OBD_LOG_CANCEL:
1732 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1734 CERROR("bad opc %u version %08x, expecting %08x\n",
1735 lustre_msg_get_opc(msg),
1736 lustre_msg_get_version(msg),
1737 LUSTRE_LOG_VERSION);
1739 case OST_QUOTA_ADJUST_QUNIT:
1741 CERROR("Quota adjust is deprecated as of 2.4.0\n");
1744 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1750 struct ost_prolong_data {
1751 struct ptlrpc_request *opd_req;
1752 struct obd_export *opd_exp;
1753 struct obdo *opd_oa;
1754 struct ldlm_res_id opd_resid;
1755 struct ldlm_extent opd_extent;
1756 ldlm_mode_t opd_mode;
1757 unsigned int opd_locks;
1761 /* prolong locks for the current service time of the corresponding
1762 * portal (= OST_IO_PORTAL)
1764 static inline int prolong_timeout(struct ptlrpc_request *req)
1766 struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
1769 return obd_timeout / 2;
1771 return max(at_est2timeout(at_get(&svcpt->scp_at_estimate)),
1775 static void ost_prolong_lock_one(struct ost_prolong_data *opd,
1776 struct ldlm_lock *lock)
1778 LASSERT(lock->l_export == opd->opd_exp);
1780 if (lock->l_destroyed) /* lock already cancelled */
1783 /* XXX: never try to grab resource lock here because we're inside
1784 * exp_bl_list_lock; in ldlm_lockd.c to handle waiting list we take
1785 * res lock and then exp_bl_list_lock. */
1787 if (!(lock->l_flags & LDLM_FL_AST_SENT))
1788 /* ignore locks not being cancelled */
1792 "refreshed for req x"LPU64" ext("LPU64"->"LPU64") to %ds.\n",
1793 opd->opd_req->rq_xid, opd->opd_extent.start,
1794 opd->opd_extent.end, opd->opd_timeout);
1796 /* OK. this is a possible lock the user holds doing I/O
1797 * let's refresh eviction timer for it */
1798 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
1802 static void ost_prolong_locks(struct ost_prolong_data *data)
1804 struct obd_export *exp = data->opd_exp;
1805 struct obdo *oa = data->opd_oa;
1806 struct ldlm_lock *lock;
1809 if (oa->o_valid & OBD_MD_FLHANDLE) {
1810 /* mostly a request should be covered by only one lock, try
1812 lock = ldlm_handle2lock(&oa->o_handle);
1814 /* Fast path to check if the lock covers the whole IO
1815 * region exclusively. */
1816 if (lock->l_granted_mode == LCK_PW &&
1817 ldlm_extent_contain(&lock->l_policy_data.l_extent,
1818 &data->opd_extent)) {
1820 ost_prolong_lock_one(data, lock);
1821 LDLM_LOCK_PUT(lock);
1824 LDLM_LOCK_PUT(lock);
1829 spin_lock_bh(&exp->exp_bl_list_lock);
1830 cfs_list_for_each_entry(lock, &exp->exp_bl_list, l_exp_list) {
1831 LASSERT(lock->l_flags & LDLM_FL_AST_SENT);
1832 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
1834 if (!ldlm_res_eq(&data->opd_resid, &lock->l_resource->lr_name))
1837 if (!ldlm_extent_overlap(&lock->l_policy_data.l_extent,
1841 ost_prolong_lock_one(data, lock);
1843 spin_unlock_bh(&exp->exp_bl_list_lock);
1849 * Returns 1 if the given PTLRPC matches the given LDLM locks, or 0 if it does
1852 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1853 struct ldlm_lock *lock)
1855 struct niobuf_remote *nb;
1856 struct obd_ioobj *ioo;
1858 struct ldlm_extent ext;
1861 opc = lustre_msg_get_opc(req->rq_reqmsg);
1862 LASSERT(opc == OST_READ || opc == OST_WRITE);
1864 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1865 LASSERT(ioo != NULL);
1867 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1868 LASSERT(nb != NULL);
1870 ext.start = nb->offset;
1871 nb += ioo->ioo_bufcnt - 1;
1872 ext.end = nb->offset + nb->len - 1;
1874 LASSERT(lock->l_resource != NULL);
1875 if (!ostid_res_name_eq(&ioo->ioo_oid, &lock->l_resource->lr_name))
1879 if (opc == OST_READ)
1881 if (!(lock->l_granted_mode & mode))
1884 RETURN(ldlm_extent_overlap(&lock->l_policy_data.l_extent, &ext));
1888 * High-priority queue request check for whether the given PTLRPC request (\a
1889 * req) is blocking an LDLM lock cancel.
1891 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1892 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1894 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1895 * function looks only at OST_READs and OST_WRITEs.
1897 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1899 struct obd_device *obd = req->rq_export->exp_obd;
1900 struct ost_body *body;
1901 struct obd_ioobj *ioo;
1902 struct niobuf_remote *nb;
1903 struct ost_prolong_data opd = { 0 };
1908 * Use LASSERT to do sanity check because malformed RPCs should have
1909 * been filtered out in ost_hpreq_handler().
1911 opc = lustre_msg_get_opc(req->rq_reqmsg);
1912 LASSERT(opc == OST_READ || opc == OST_WRITE);
1914 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1915 LASSERT(body != NULL);
1917 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1918 LASSERT(ioo != NULL);
1920 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1921 LASSERT(nb != NULL);
1922 LASSERT(!(nb->flags & OBD_BRW_SRVLOCK));
1924 ostid_build_res_name(&ioo->ioo_oid, &opd.opd_resid);
1928 if (opc == OST_READ)
1930 opd.opd_mode = mode;
1931 opd.opd_exp = req->rq_export;
1932 opd.opd_oa = &body->oa;
1933 opd.opd_extent.start = nb->offset;
1934 nb += ioo->ioo_bufcnt - 1;
1935 opd.opd_extent.end = nb->offset + nb->len - 1;
1936 opd.opd_timeout = prolong_timeout(req);
1938 DEBUG_REQ(D_RPCTRACE, req,
1939 "%s %s: refresh rw locks: " LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1940 obd->obd_name, cfs_current()->comm,
1941 opd.opd_resid.name[0], opd.opd_resid.name[1],
1942 opd.opd_extent.start, opd.opd_extent.end);
1944 ost_prolong_locks(&opd);
1946 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
1947 obd->obd_name, opd.opd_locks, req);
1949 RETURN(opd.opd_locks);
1952 static void ost_rw_hpreq_fini(struct ptlrpc_request *req)
1954 (void)ost_rw_hpreq_check(req);
1958 * Like ost_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
1960 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1961 struct ldlm_lock *lock)
1963 struct ost_body *body;
1966 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1967 LASSERT(body != NULL);
1969 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1970 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1977 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
1979 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1981 struct obd_device *obd = req->rq_export->exp_obd;
1982 struct ost_body *body;
1984 struct ost_prolong_data opd = { 0 };
1988 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1989 LASSERT(body != NULL);
1992 LASSERT(!(oa->o_valid & OBD_MD_FLFLAGS) ||
1993 !(oa->o_flags & OBD_FL_SRVLOCK));
1996 end = start + oa->o_blocks;
1999 opd.opd_mode = LCK_PW;
2000 opd.opd_exp = req->rq_export;
2002 opd.opd_extent.start = start;
2003 opd.opd_extent.end = end;
2004 if (oa->o_blocks == OBD_OBJECT_EOF)
2005 opd.opd_extent.end = OBD_OBJECT_EOF;
2006 opd.opd_timeout = prolong_timeout(req);
2008 ostid_build_res_name(&oa->o_oi, &opd.opd_resid);
2011 "%s: refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
2013 opd.opd_resid.name[0], opd.opd_resid.name[1],
2014 opd.opd_extent.start, opd.opd_extent.end);
2016 ost_prolong_locks(&opd);
2018 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
2019 obd->obd_name, opd.opd_locks, req);
2021 RETURN(opd.opd_locks > 0);
2024 static void ost_punch_hpreq_fini(struct ptlrpc_request *req)
2026 (void)ost_punch_hpreq_check(req);
2029 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
2030 .hpreq_lock_match = ost_rw_hpreq_lock_match,
2031 .hpreq_check = ost_rw_hpreq_check,
2032 .hpreq_fini = ost_rw_hpreq_fini
2035 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
2036 .hpreq_lock_match = ost_punch_hpreq_lock_match,
2037 .hpreq_check = ost_punch_hpreq_check,
2038 .hpreq_fini = ost_punch_hpreq_fini
2041 /** Assign high priority operations to the request if needed. */
2042 static int ost_io_hpreq_handler(struct ptlrpc_request *req)
2045 if (req->rq_export) {
2046 int opc = lustre_msg_get_opc(req->rq_reqmsg);
2047 struct ost_body *body;
2049 if (opc == OST_READ || opc == OST_WRITE) {
2050 struct niobuf_remote *nb;
2051 struct obd_ioobj *ioo;
2052 int objcount, niocount;
2056 /* RPCs on the H-P queue can be inspected before
2057 * ost_handler() initializes their pills, so we
2058 * initialize that here. Capsule initialization is
2059 * idempotent, as is setting the pill's format (provided
2060 * it doesn't change).
2062 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2063 if (opc == OST_READ)
2064 req_capsule_set(&req->rq_pill,
2067 req_capsule_set(&req->rq_pill,
2068 &RQF_OST_BRW_WRITE);
2070 body = req_capsule_client_get(&req->rq_pill,
2073 CERROR("Missing/short ost_body\n");
2077 objcount = req_capsule_get_size(&req->rq_pill,
2081 if (objcount == 0) {
2082 CERROR("Missing/short ioobj\n");
2086 CERROR("too many ioobjs (%d)\n", objcount);
2090 ioo = req_capsule_client_get(&req->rq_pill,
2093 CERROR("Missing/short ioobj\n");
2097 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
2099 CERROR("invalid object ids\n");
2103 for (niocount = i = 0; i < objcount; i++) {
2104 if (ioo[i].ioo_bufcnt == 0) {
2105 CERROR("ioo[%d] has zero bufcnt\n", i);
2108 niocount += ioo[i].ioo_bufcnt;
2110 if (niocount > PTLRPC_MAX_BRW_PAGES) {
2111 DEBUG_REQ(D_RPCTRACE, req,
2112 "bulk has too many pages (%d)",
2117 nb = req_capsule_client_get(&req->rq_pill,
2118 &RMF_NIOBUF_REMOTE);
2120 CERROR("Missing/short niobuf\n");
2124 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
2125 req->rq_ops = &ost_hpreq_rw;
2126 } else if (opc == OST_PUNCH) {
2127 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2128 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2130 body = req_capsule_client_get(&req->rq_pill,
2133 CERROR("Missing/short ost_body\n");
2137 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
2138 !(body->oa.o_flags & OBD_FL_SRVLOCK))
2139 req->rq_ops = &ost_hpreq_punch;
2145 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
2146 int ost_handle(struct ptlrpc_request *req)
2148 struct obd_trans_info trans_info = { 0, };
2149 struct obd_trans_info *oti = &trans_info;
2150 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
2151 struct obd_device *obd = NULL;
2154 /* OST module is kept between remounts, but the last reference
2155 * to specific module (say, osd or ofd) kills all related keys
2156 * from the environment. so we have to refill it until the root
2157 * cause is fixed properly */
2158 lu_env_refill(req->rq_svc_thread->t_env);
2160 LASSERT(current->journal_info == NULL);
2162 /* primordial rpcs don't affect server recovery */
2163 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2165 case SEC_CTX_INIT_CONT:
2170 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2172 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
2173 if (!class_connected_export(req->rq_export)) {
2174 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
2175 lustre_msg_get_opc(req->rq_reqmsg),
2176 libcfs_id2str(req->rq_peer));
2177 req->rq_status = -ENOTCONN;
2178 GOTO(out, rc = -ENOTCONN);
2181 obd = req->rq_export->exp_obd;
2183 /* Check for aborted recovery. */
2184 if (obd->obd_recovering) {
2185 rc = ost_filter_recovery_request(req, obd,
2187 if (rc || !should_process)
2189 else if (should_process < 0) {
2190 req->rq_status = should_process;
2191 rc = ptlrpc_error(req);
2199 rc = ost_msg_check_version(req->rq_reqmsg);
2203 if (req && req->rq_reqmsg && req->rq_export &&
2204 (req->rq_export->exp_connect_flags & OBD_CONNECT_JOBSTATS))
2205 oti->oti_jobid = lustre_msg_get_jobid(req->rq_reqmsg);
2207 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2209 CDEBUG(D_INODE, "connect\n");
2210 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
2211 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
2213 rc = target_handle_connect(req);
2214 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
2217 rc = ost_init_sec_level(req);
2219 rc = ost_connect_check_sptlrpc(req);
2223 case OST_DISCONNECT:
2224 CDEBUG(D_INODE, "disconnect\n");
2225 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
2226 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
2228 rc = target_handle_disconnect(req);
2231 CDEBUG(D_INODE, "create\n");
2232 req_capsule_set(&req->rq_pill, &RQF_OST_CREATE);
2233 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
2235 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2236 GOTO(out, rc = -EROFS);
2237 rc = ost_create(req->rq_export, req, oti);
2240 CDEBUG(D_INODE, "destroy\n");
2241 req_capsule_set(&req->rq_pill, &RQF_OST_DESTROY);
2242 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
2244 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2245 GOTO(out, rc = -EROFS);
2246 rc = ost_destroy(req->rq_export, req, oti);
2249 CDEBUG(D_INODE, "getattr\n");
2250 req_capsule_set(&req->rq_pill, &RQF_OST_GETATTR);
2251 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
2253 rc = ost_getattr(req->rq_export, req);
2256 CDEBUG(D_INODE, "setattr\n");
2257 req_capsule_set(&req->rq_pill, &RQF_OST_SETATTR);
2258 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
2260 rc = ost_setattr(req->rq_export, req, oti);
2263 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_WRITE);
2264 CDEBUG(D_INODE, "write\n");
2265 /* req->rq_request_portal would be nice, if it was set */
2266 if (ptlrpc_req2svc(req)->srv_req_portal != OST_IO_PORTAL) {
2267 CERROR("%s: deny write request from %s to portal %u\n",
2268 req->rq_export->exp_obd->obd_name,
2269 obd_export_nid2str(req->rq_export),
2270 ptlrpc_req2svc(req)->srv_req_portal);
2271 GOTO(out, rc = -EPROTO);
2273 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2275 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
2276 GOTO(out, rc = -ENOSPC);
2277 if (OBD_FAIL_TIMEOUT(OBD_FAIL_OST_EROFS, 1))
2278 GOTO(out, rc = -EROFS);
2279 rc = ost_brw_write(req, oti);
2280 LASSERT(current->journal_info == NULL);
2281 /* ost_brw_write sends its own replies */
2284 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_READ);
2285 CDEBUG(D_INODE, "read\n");
2286 /* req->rq_request_portal would be nice, if it was set */
2287 if (ptlrpc_req2svc(req)->srv_req_portal != OST_IO_PORTAL) {
2288 CERROR("%s: deny read request from %s to portal %u\n",
2289 req->rq_export->exp_obd->obd_name,
2290 obd_export_nid2str(req->rq_export),
2291 ptlrpc_req2svc(req)->srv_req_portal);
2292 GOTO(out, rc = -EPROTO);
2294 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2296 rc = ost_brw_read(req, oti);
2297 LASSERT(current->journal_info == NULL);
2298 /* ost_brw_read sends its own replies */
2301 CDEBUG(D_INODE, "punch\n");
2302 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2303 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2305 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2306 GOTO(out, rc = -EROFS);
2307 rc = ost_punch(req->rq_export, req, oti);
2310 CDEBUG(D_INODE, "statfs\n");
2311 req_capsule_set(&req->rq_pill, &RQF_OST_STATFS);
2312 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2314 rc = ost_statfs(req);
2317 CDEBUG(D_INODE, "sync\n");
2318 req_capsule_set(&req->rq_pill, &RQF_OST_SYNC);
2319 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2321 rc = ost_sync(req->rq_export, req, oti);
2324 DEBUG_REQ(D_INODE, req, "set_info");
2325 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
2326 rc = ost_set_info(req->rq_export, req);
2329 DEBUG_REQ(D_INODE, req, "get_info");
2330 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
2331 rc = ost_get_info(req->rq_export, req);
2334 CDEBUG(D_INODE, "seq\n");
2335 rc = seq_handle(req);
2337 case OST_QUOTACHECK:
2338 CDEBUG(D_INODE, "quotacheck\n");
2339 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2340 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2342 rc = ost_handle_quotacheck(req);
2345 CDEBUG(D_INODE, "quotactl\n");
2346 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2347 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2349 rc = ost_handle_quotactl(req);
2352 DEBUG_REQ(D_INODE, req, "ping");
2353 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2354 rc = target_handle_ping(req);
2356 /* FIXME - just reply status */
2357 case LLOG_ORIGIN_CONNECT:
2358 DEBUG_REQ(D_INODE, req, "log connect");
2359 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2360 rc = ost_llog_handle_connect(req->rq_export, req);
2361 req->rq_status = rc;
2362 rc = req_capsule_server_pack(&req->rq_pill);
2365 RETURN(ptlrpc_reply(req));
2366 case OBD_LOG_CANCEL:
2367 CDEBUG(D_INODE, "log cancel\n");
2368 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2369 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2371 rc = llog_origin_handle_cancel(req);
2372 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2374 req->rq_status = rc;
2375 rc = req_capsule_server_pack(&req->rq_pill);
2378 RETURN(ptlrpc_reply(req));
2380 CDEBUG(D_INODE, "enqueue\n");
2381 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2382 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE_NET))
2384 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2386 ldlm_server_glimpse_ast);
2387 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2390 CDEBUG(D_INODE, "convert\n");
2391 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2392 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT_NET))
2394 rc = ldlm_handle_convert(req);
2397 CDEBUG(D_INODE, "cancel\n");
2398 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2399 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL_NET))
2401 rc = ldlm_handle_cancel(req);
2403 case LDLM_BL_CALLBACK:
2404 case LDLM_CP_CALLBACK:
2405 CDEBUG(D_INODE, "callback\n");
2406 CERROR("callbacks should not happen on OST\n");
2409 CERROR("Unexpected opcode %d\n",
2410 lustre_msg_get_opc(req->rq_reqmsg));
2411 req->rq_status = -ENOTSUPP;
2412 rc = ptlrpc_error(req);
2416 LASSERT(current->journal_info == NULL);
2419 /* If we're DISCONNECTing, the export_data is already freed */
2420 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2421 target_committed_to_req(req);
2425 oti_to_request(oti, req);
2427 target_send_reply(req, rc, fail);
2430 EXPORT_SYMBOL(ost_handle);
2433 * free per-thread pool created by ost_io_thread_init().
2435 static void ost_io_thread_done(struct ptlrpc_thread *thread)
2437 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2442 LASSERT(thread != NULL);
2445 * be prepared to handle partially-initialized pools (because this is
2446 * called from ost_io_thread_init() for cleanup.
2448 tls = thread->t_data;
2451 thread->t_data = NULL;
2457 * initialize per-thread page pool (bug 5137).
2459 static int ost_io_thread_init(struct ptlrpc_thread *thread)
2461 struct ost_thread_local_cache *tls;
2465 LASSERT(thread != NULL);
2466 LASSERT(thread->t_data == NULL);
2471 thread->t_data = tls;
2475 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2477 static struct cfs_cpt_table *ost_io_cptable;
2479 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2480 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2482 static struct ptlrpc_service_conf svc_conf;
2483 struct ost_obd *ost = &obd->u.ost;
2484 struct lprocfs_static_vars lvars;
2489 rc = cfs_cleanup_group_info();
2493 lprocfs_ost_init_vars(&lvars);
2494 lprocfs_obd_setup(obd, lvars.obd_vars);
2496 mutex_init(&ost->ost_health_mutex);
2498 svc_conf = (typeof(svc_conf)) {
2499 .psc_name = LUSTRE_OSS_NAME,
2500 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
2502 .bc_nbufs = OST_NBUFS,
2503 .bc_buf_size = OST_BUFSIZE,
2504 .bc_req_max_size = OST_MAXREQSIZE,
2505 .bc_rep_max_size = OST_MAXREPSIZE,
2506 .bc_req_portal = OST_REQUEST_PORTAL,
2507 .bc_rep_portal = OSC_REPLY_PORTAL,
2510 .tc_thr_name = "ll_ost",
2511 .tc_thr_factor = OSS_THR_FACTOR,
2512 .tc_nthrs_init = OSS_NTHRS_INIT,
2513 .tc_nthrs_base = OSS_NTHRS_BASE,
2514 .tc_nthrs_max = OSS_NTHRS_MAX,
2515 .tc_nthrs_user = oss_num_threads,
2516 .tc_cpu_affinity = 1,
2517 .tc_ctx_tags = LCT_DT_THREAD,
2520 .cc_pattern = oss_cpts,
2523 .so_req_handler = ost_handle,
2524 .so_req_printer = target_print_req,
2525 .so_hpreq_handler = ptlrpc_hpreq_handler,
2528 ost->ost_service = ptlrpc_register_service(&svc_conf,
2529 obd->obd_proc_entry);
2530 if (IS_ERR(ost->ost_service)) {
2531 rc = PTR_ERR(ost->ost_service);
2532 CERROR("failed to start service: %d\n", rc);
2533 GOTO(out_lprocfs, rc);
2536 memset(&svc_conf, 0, sizeof(svc_conf));
2537 svc_conf = (typeof(svc_conf)) {
2538 .psc_name = "ost_create",
2539 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
2541 .bc_nbufs = OST_NBUFS,
2542 .bc_buf_size = OST_BUFSIZE,
2543 .bc_req_max_size = OST_MAXREQSIZE,
2544 .bc_rep_max_size = OST_MAXREPSIZE,
2545 .bc_req_portal = OST_CREATE_PORTAL,
2546 .bc_rep_portal = OSC_REPLY_PORTAL,
2549 .tc_thr_name = "ll_ost_create",
2550 .tc_thr_factor = OSS_CR_THR_FACTOR,
2551 .tc_nthrs_init = OSS_CR_NTHRS_INIT,
2552 .tc_nthrs_base = OSS_CR_NTHRS_BASE,
2553 .tc_nthrs_max = OSS_CR_NTHRS_MAX,
2554 .tc_nthrs_user = oss_num_create_threads,
2555 .tc_cpu_affinity = 1,
2556 .tc_ctx_tags = LCT_DT_THREAD,
2559 .cc_pattern = oss_cpts,
2562 .so_req_handler = ost_handle,
2563 .so_req_printer = target_print_req,
2566 ost->ost_create_service = ptlrpc_register_service(&svc_conf,
2567 obd->obd_proc_entry);
2568 if (IS_ERR(ost->ost_create_service)) {
2569 rc = PTR_ERR(ost->ost_create_service);
2570 CERROR("failed to start OST create service: %d\n", rc);
2571 GOTO(out_service, rc);
2574 mask = cfs_cpt_table->ctb_nodemask;
2575 /* event CPT feature is disabled in libcfs level by set partition
2576 * number to 1, we still want to set node affinity for io service */
2577 if (cfs_cpt_number(cfs_cpt_table) == 1 && nodes_weight(*mask) > 1) {
2581 ost_io_cptable = cfs_cpt_table_alloc(nodes_weight(*mask));
2582 for_each_node_mask(i, *mask) {
2583 if (ost_io_cptable == NULL) {
2584 CWARN("OSS failed to create CPT table\n");
2588 rc = cfs_cpt_set_node(ost_io_cptable, cpt++, i);
2590 CWARN("OSS Failed to set node %d for"
2591 "IO CPT table\n", i);
2592 cfs_cpt_table_free(ost_io_cptable);
2593 ost_io_cptable = NULL;
2599 memset(&svc_conf, 0, sizeof(svc_conf));
2600 svc_conf = (typeof(svc_conf)) {
2601 .psc_name = "ost_io",
2602 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
2604 .bc_nbufs = OST_NBUFS,
2605 .bc_buf_size = OST_BUFSIZE,
2606 .bc_req_max_size = OST_MAXREQSIZE,
2607 .bc_rep_max_size = OST_MAXREPSIZE,
2608 .bc_req_portal = OST_IO_PORTAL,
2609 .bc_rep_portal = OSC_REPLY_PORTAL,
2612 .tc_thr_name = "ll_ost_io",
2613 .tc_thr_factor = OSS_THR_FACTOR,
2614 .tc_nthrs_init = OSS_NTHRS_INIT,
2615 .tc_nthrs_base = OSS_NTHRS_BASE,
2616 .tc_nthrs_max = OSS_NTHRS_MAX,
2617 .tc_nthrs_user = oss_num_threads,
2618 .tc_cpu_affinity = 1,
2619 .tc_ctx_tags = LCT_DT_THREAD,
2622 .cc_cptable = ost_io_cptable,
2623 .cc_pattern = ost_io_cptable == NULL ?
2627 .so_thr_init = ost_io_thread_init,
2628 .so_thr_done = ost_io_thread_done,
2629 .so_req_handler = ost_handle,
2630 .so_hpreq_handler = ost_io_hpreq_handler,
2631 .so_req_printer = target_print_req,
2634 ost->ost_io_service = ptlrpc_register_service(&svc_conf,
2635 obd->obd_proc_entry);
2636 if (IS_ERR(ost->ost_io_service)) {
2637 rc = PTR_ERR(ost->ost_io_service);
2638 CERROR("failed to start OST I/O service: %d\n", rc);
2639 ost->ost_io_service = NULL;
2640 GOTO(out_create, rc);
2643 memset(&svc_conf, 0, sizeof(svc_conf));
2644 svc_conf = (typeof(svc_conf)) {
2645 .psc_name = "ost_seq",
2646 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
2648 .bc_nbufs = OST_NBUFS,
2649 .bc_buf_size = OST_BUFSIZE,
2650 .bc_req_max_size = OST_MAXREQSIZE,
2651 .bc_rep_max_size = OST_MAXREPSIZE,
2652 .bc_req_portal = SEQ_DATA_PORTAL,
2653 .bc_rep_portal = OSC_REPLY_PORTAL,
2656 .tc_thr_name = "ll_ost_seq",
2657 .tc_thr_factor = OSS_CR_THR_FACTOR,
2658 .tc_nthrs_init = OSS_CR_NTHRS_INIT,
2659 .tc_nthrs_base = OSS_CR_NTHRS_BASE,
2660 .tc_nthrs_max = OSS_CR_NTHRS_MAX,
2661 .tc_nthrs_user = oss_num_create_threads,
2662 .tc_cpu_affinity = 1,
2663 .tc_ctx_tags = LCT_DT_THREAD,
2667 .cc_pattern = oss_cpts,
2670 .so_req_handler = ost_handle,
2671 .so_req_printer = target_print_req,
2672 .so_hpreq_handler = NULL,
2675 ost->ost_seq_service = ptlrpc_register_service(&svc_conf,
2676 obd->obd_proc_entry);
2677 if (IS_ERR(ost->ost_seq_service)) {
2678 rc = PTR_ERR(ost->ost_seq_service);
2679 CERROR("failed to start OST seq service: %d\n", rc);
2680 ost->ost_seq_service = NULL;
2684 ping_evictor_start();
2688 ptlrpc_unregister_service(ost->ost_io_service);
2689 ost->ost_io_service = NULL;
2691 ptlrpc_unregister_service(ost->ost_create_service);
2692 ost->ost_create_service = NULL;
2694 ptlrpc_unregister_service(ost->ost_service);
2695 ost->ost_service = NULL;
2697 lprocfs_obd_cleanup(obd);
2701 static int ost_cleanup(struct obd_device *obd)
2703 struct ost_obd *ost = &obd->u.ost;
2707 ping_evictor_stop();
2709 /* there is no recovery for OST OBD, all recovery is controlled by
2711 LASSERT(obd->obd_recovering == 0);
2712 mutex_lock(&ost->ost_health_mutex);
2713 ptlrpc_unregister_service(ost->ost_service);
2714 ptlrpc_unregister_service(ost->ost_create_service);
2715 ptlrpc_unregister_service(ost->ost_io_service);
2716 ptlrpc_unregister_service(ost->ost_seq_service);
2717 ost->ost_service = NULL;
2718 ost->ost_create_service = NULL;
2719 ost->ost_io_service = NULL;
2720 ost->ost_seq_service = NULL;
2722 mutex_unlock(&ost->ost_health_mutex);
2724 lprocfs_obd_cleanup(obd);
2726 if (ost_io_cptable != NULL) {
2727 cfs_cpt_table_free(ost_io_cptable);
2728 ost_io_cptable = NULL;
2734 static int ost_health_check(const struct lu_env *env, struct obd_device *obd)
2736 struct ost_obd *ost = &obd->u.ost;
2739 mutex_lock(&ost->ost_health_mutex);
2740 rc |= ptlrpc_service_health_check(ost->ost_service);
2741 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2742 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2743 mutex_unlock(&ost->ost_health_mutex);
2746 * health_check to return 0 on healthy
2747 * and 1 on unhealthy.
2755 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2757 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2760 /* use obd ops to offer management infrastructure */
2761 static struct obd_ops ost_obd_ops = {
2762 .o_owner = THIS_MODULE,
2763 .o_setup = ost_setup,
2764 .o_cleanup = ost_cleanup,
2765 .o_health_check = ost_health_check,
2769 static int __init ost_init(void)
2771 struct lprocfs_static_vars lvars;
2775 ost_page_to_corrupt = cfs_alloc_page(CFS_ALLOC_STD);
2777 lprocfs_ost_init_vars(&lvars);
2778 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2779 LUSTRE_OSS_NAME, NULL);
2781 if (ost_num_threads != 0 && oss_num_threads == 0) {
2782 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2783 "use oss_num_threads instead or unset both for "
2784 "dynamic thread startup\n");
2785 oss_num_threads = ost_num_threads;
2791 static void /*__exit*/ ost_exit(void)
2793 if (ost_page_to_corrupt)
2794 page_cache_release(ost_page_to_corrupt);
2796 class_unregister_type(LUSTRE_OSS_NAME);
2799 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2800 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2801 MODULE_LICENSE("GPL");
2803 module_init(ost_init);
2804 module_exit(ost_exit);