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 <linux/init.h>
52 #include <lprocfs_status.h>
53 #include <libcfs/list.h>
54 #include "ost_internal.h"
55 #include <lustre_fid.h>
57 static int oss_num_threads;
58 CFS_MODULE_PARM(oss_num_threads, "i", int, 0444,
59 "number of OSS service threads to start");
61 static int ost_num_threads;
62 CFS_MODULE_PARM(ost_num_threads, "i", int, 0444,
63 "number of OST service threads to start (deprecated)");
65 static int oss_num_create_threads;
66 CFS_MODULE_PARM(oss_num_create_threads, "i", int, 0444,
67 "number of OSS create threads to start");
69 static char *oss_cpts;
70 CFS_MODULE_PARM(oss_cpts, "s", charp, 0444,
71 "CPU partitions OSS threads should run on");
73 static char *oss_io_cpts;
74 CFS_MODULE_PARM(oss_io_cpts, "s", charp, 0444,
75 "CPU partitions OSS IO threads should run on");
78 * this page is allocated statically when module is initializing
79 * it is used to simulate data corruptions, see ost_checksum_bulk()
80 * for details. as the original pages provided by the layers below
81 * can be remain in the internal cache, we do not want to modify
84 static struct page *ost_page_to_corrupt = NULL;
87 * Do not return server-side uid/gid to remote client
89 static void ost_drop_id(struct obd_export *exp, struct obdo *oa)
91 if (exp_connect_rmtclient(exp)) {
94 oa->o_valid &= ~(OBD_MD_FLUID | OBD_MD_FLGID);
99 * Validate oa from client.
100 * If the request comes from 2.0 clients, currently only RSVD seq and IDIF
102 * a. for single MDS seq = FID_SEQ_OST_MDT0,
103 * b. for CMD, seq = FID_SEQ_OST_MDT0, FID_SEQ_OST_MDT1 - FID_SEQ_OST_MAX
105 static int ost_validate_obdo(struct obd_export *exp, struct obdo *oa,
106 struct obd_ioobj *ioobj)
108 if (oa != NULL && !(oa->o_valid & OBD_MD_FLGROUP)) {
109 oa->o_seq = FID_SEQ_OST_MDT0;
111 ioobj->ioo_seq = FID_SEQ_OST_MDT0;
112 /* remove fid_seq_is_rsvd() after FID-on-OST allows SEQ > 9 */
113 } else if (oa == NULL || !(fid_seq_is_rsvd(oa->o_seq) ||
114 fid_seq_is_mdt0(oa->o_seq))) {
115 CERROR("%s: client %s sent invalid object "POSTID"\n",
116 exp->exp_obd->obd_name, obd_export_nid2str(exp),
117 oa ? oa->o_id : -1, oa ? oa->o_seq : -1);
120 obdo_from_ostid(oa, &oa->o_oi);
122 ioobj_from_obdo(ioobj, oa);
126 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
128 struct oti_req_ack_lock *ack_lock;
134 if (req->rq_repmsg) {
135 __u64 versions[PTLRPC_NUM_VERSIONS] = { 0 };
136 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
137 versions[0] = oti->oti_pre_version;
138 lustre_msg_set_versions(req->rq_repmsg, versions);
140 req->rq_transno = oti->oti_transno;
142 /* XXX 4 == entries in oti_ack_locks??? */
143 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
146 /* XXX not even calling target_send_reply in some cases... */
147 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode, 0);
151 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
152 struct obd_trans_info *oti)
154 struct ost_body *body, *repbody;
155 struct lustre_capa *capa = NULL;
159 /* Get the request body */
160 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
164 if (body->oa.o_id == 0)
167 rc = ost_validate_obdo(exp, &body->oa, NULL);
171 /* If there's a DLM request, cancel the locks mentioned in it*/
172 if (req_capsule_field_present(&req->rq_pill, &RMF_DLM_REQ, RCL_CLIENT)) {
173 struct ldlm_request *dlm;
175 dlm = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
178 ldlm_request_cancel(req, dlm, 0);
181 /* If there's a capability, get it */
182 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
183 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
185 CERROR("Missing capability for OST DESTROY");
190 /* Prepare the reply */
191 rc = req_capsule_server_pack(&req->rq_pill);
195 /* Get the log cancellation cookie */
196 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
197 oti->oti_logcookies = &body->oa.o_lcookie;
199 /* Finish the reply */
200 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
201 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
203 /* Do the destroy and set the reply status accordingly */
204 req->rq_status = obd_destroy(req->rq_svc_thread->t_env, exp,
205 &repbody->oa, NULL, oti, NULL, capa);
210 * Helper function for getting server side [start, start+count] DLM lock
211 * if asked by client.
213 static int ost_lock_get(struct obd_export *exp, struct obdo *oa,
214 __u64 start, __u64 count, struct lustre_handle *lh,
215 int mode, __u64 flags)
217 struct ldlm_res_id res_id;
218 ldlm_policy_data_t policy;
219 __u64 end = start + count;
223 LASSERT(!lustre_handle_is_used(lh));
224 /* o_id and o_gr are used for localizing resource, if client miss to set
225 * them, do not trigger ASSERTION. */
226 if (unlikely((oa->o_valid & (OBD_MD_FLID | OBD_MD_FLGROUP)) !=
227 (OBD_MD_FLID | OBD_MD_FLGROUP)))
230 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
231 !(oa->o_flags & OBD_FL_SRVLOCK))
234 osc_build_res_name(oa->o_id, oa->o_seq, &res_id);
235 CDEBUG(D_INODE, "OST-side extent lock.\n");
237 policy.l_extent.start = start & CFS_PAGE_MASK;
239 /* If ->o_blocks is EOF it means "lock till the end of the
240 * file". Otherwise, it's size of a hole being punched (in bytes) */
241 if (count == OBD_OBJECT_EOF || end < start)
242 policy.l_extent.end = OBD_OBJECT_EOF;
244 policy.l_extent.end = end | ~CFS_PAGE_MASK;
246 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
247 LDLM_EXTENT, &policy, mode, &flags,
248 ldlm_blocking_ast, ldlm_completion_ast,
249 ldlm_glimpse_ast, NULL, 0, LVB_T_NONE,
253 /* Helper function: release lock, if any. */
254 static void ost_lock_put(struct obd_export *exp,
255 struct lustre_handle *lh, int mode)
258 if (lustre_handle_is_used(lh))
259 ldlm_lock_decref(lh, mode);
263 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
265 struct ost_body *body, *repbody;
266 struct obd_info *oinfo;
267 struct lustre_handle lh = { 0 };
268 struct lustre_capa *capa = NULL;
272 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
276 rc = ost_validate_obdo(exp, &body->oa, NULL);
280 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
281 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
283 CERROR("Missing capability for OST GETATTR");
288 rc = req_capsule_server_pack(&req->rq_pill);
292 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
293 repbody->oa = body->oa;
295 rc = ost_lock_get(exp, &repbody->oa, 0, OBD_OBJECT_EOF, &lh, LCK_PR, 0);
299 OBD_ALLOC_PTR(oinfo);
301 GOTO(unlock, rc = -ENOMEM);
302 oinfo->oi_oa = &repbody->oa;
303 oinfo->oi_capa = capa;
305 req->rq_status = obd_getattr(req->rq_svc_thread->t_env, exp, oinfo);
309 ost_drop_id(exp, &repbody->oa);
312 ost_lock_put(exp, &lh, LCK_PR);
316 static int ost_statfs(struct ptlrpc_request *req)
318 struct obd_statfs *osfs;
322 rc = req_capsule_server_pack(&req->rq_pill);
326 osfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
328 req->rq_status = obd_statfs(req->rq_svc_thread->t_env, req->rq_export,
330 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
332 if (req->rq_status != 0)
333 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
335 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_EINPROGRESS))
336 req->rq_status = -EINPROGRESS;
341 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
342 struct obd_trans_info *oti)
344 struct ost_body *body, *repbody;
348 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
352 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
356 rc = req_capsule_server_pack(&req->rq_pill);
360 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
361 repbody->oa = body->oa;
362 oti->oti_logcookies = &body->oa.o_lcookie;
364 req->rq_status = obd_create(req->rq_svc_thread->t_env, exp,
365 &repbody->oa, NULL, oti);
366 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
370 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
371 struct obd_trans_info *oti)
373 struct ost_body *body, *repbody;
375 struct lustre_handle lh = {0,};
379 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
380 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
382 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
386 rc = ost_validate_obdo(exp, &body->oa, NULL);
390 if ((body->oa.o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
391 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
394 rc = req_capsule_server_pack(&req->rq_pill);
398 /* standard truncate optimization: if file body is completely
399 * destroyed, don't send data back to the server. */
400 if (body->oa.o_size == 0)
401 flags |= LDLM_AST_DISCARD_DATA;
403 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
404 repbody->oa = body->oa;
406 rc = ost_lock_get(exp, &repbody->oa, repbody->oa.o_size,
407 repbody->oa.o_blocks, &lh, LCK_PW, flags);
409 struct obd_info *oinfo;
410 struct lustre_capa *capa = NULL;
412 if (repbody->oa.o_valid & OBD_MD_FLFLAGS &&
413 repbody->oa.o_flags == OBD_FL_SRVLOCK)
415 * If OBD_FL_SRVLOCK is the only bit set in
416 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
417 * through filter_setattr() to filter_iocontrol().
419 repbody->oa.o_valid &= ~OBD_MD_FLFLAGS;
421 if (repbody->oa.o_valid & OBD_MD_FLOSSCAPA) {
422 capa = req_capsule_client_get(&req->rq_pill,
425 CERROR("Missing capability for OST PUNCH");
426 GOTO(unlock, rc = -EFAULT);
430 OBD_ALLOC_PTR(oinfo);
432 GOTO(unlock, rc = -ENOMEM);
433 oinfo->oi_oa = &repbody->oa;
434 oinfo->oi_policy.l_extent.start = oinfo->oi_oa->o_size;
435 oinfo->oi_policy.l_extent.end = oinfo->oi_oa->o_blocks;
436 oinfo->oi_capa = capa;
437 oinfo->oi_flags = OBD_FL_PUNCH;
439 req->rq_status = obd_punch(req->rq_svc_thread->t_env, exp,
443 ost_lock_put(exp, &lh, LCK_PW);
446 ost_drop_id(exp, &repbody->oa);
450 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req,
451 struct obd_trans_info *oti)
453 struct ost_body *body, *repbody;
454 struct obd_info *oinfo;
455 struct lustre_capa *capa = NULL;
459 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
463 rc = ost_validate_obdo(exp, &body->oa, NULL);
467 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
468 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
470 CERROR("Missing capability for OST SYNC");
475 rc = req_capsule_server_pack(&req->rq_pill);
479 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
480 repbody->oa = body->oa;
482 OBD_ALLOC_PTR(oinfo);
486 oinfo->oi_oa = &repbody->oa;
487 oinfo->oi_capa = capa;
488 oinfo->oi_jobid = oti->oti_jobid;
489 req->rq_status = obd_sync(req->rq_svc_thread->t_env, exp, oinfo,
490 repbody->oa.o_size, repbody->oa.o_blocks,
494 ost_drop_id(exp, &repbody->oa);
498 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
499 struct obd_trans_info *oti)
501 struct ost_body *body, *repbody;
502 struct obd_info *oinfo;
503 struct lustre_capa *capa = NULL;
507 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
511 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
515 rc = req_capsule_server_pack(&req->rq_pill);
519 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
520 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
522 CERROR("Missing capability for OST SETATTR");
527 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
528 repbody->oa = body->oa;
530 OBD_ALLOC_PTR(oinfo);
533 oinfo->oi_oa = &repbody->oa;
534 oinfo->oi_capa = capa;
536 req->rq_status = obd_setattr(req->rq_svc_thread->t_env, exp, oinfo,
541 ost_drop_id(exp, &repbody->oa);
545 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
546 cksum_type_t cksum_type)
548 struct cfs_crypto_hash_desc *hdesc;
549 unsigned int bufsize;
551 unsigned char cfs_alg = cksum_obd2cfs(cksum_type);
554 hdesc = cfs_crypto_hash_init(cfs_alg, NULL, 0);
556 CERROR("Unable to initialize checksum hash %s\n",
557 cfs_crypto_hash_name(cfs_alg));
558 return PTR_ERR(hdesc);
560 CDEBUG(D_INFO, "Checksum for algo %s\n", cfs_crypto_hash_name(cfs_alg));
561 for (i = 0; i < desc->bd_iov_count; i++) {
563 /* corrupt the data before we compute the checksum, to
564 * simulate a client->OST data error */
565 if (i == 0 && opc == OST_WRITE &&
566 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE)) {
567 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
568 int len = desc->bd_iov[i].kiov_len;
569 struct page *np = ost_page_to_corrupt;
570 char *ptr = kmap(desc->bd_iov[i].kiov_page) + off;
573 char *ptr2 = kmap(np) + off;
575 memcpy(ptr2, ptr, len);
576 memcpy(ptr2, "bad3", min(4, len));
578 desc->bd_iov[i].kiov_page = np;
580 CERROR("can't alloc page for corruption\n");
583 cfs_crypto_hash_update_page(hdesc, desc->bd_iov[i].kiov_page,
584 desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK,
585 desc->bd_iov[i].kiov_len);
587 /* corrupt the data after we compute the checksum, to
588 * simulate an OST->client data error */
589 if (i == 0 && opc == OST_READ &&
590 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
591 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
592 int len = desc->bd_iov[i].kiov_len;
593 struct page *np = ost_page_to_corrupt;
594 char *ptr = kmap(desc->bd_iov[i].kiov_page) + off;
597 char *ptr2 = kmap(np) + off;
599 memcpy(ptr2, ptr, len);
600 memcpy(ptr2, "bad4", min(4, len));
602 desc->bd_iov[i].kiov_page = np;
604 CERROR("can't alloc page for corruption\n");
610 err = cfs_crypto_hash_final(hdesc, (unsigned char *)&cksum, &bufsize);
612 cfs_crypto_hash_final(hdesc, NULL, NULL);
617 static int ost_brw_lock_get(int mode, struct obd_export *exp,
618 struct obd_ioobj *obj, struct niobuf_remote *nb,
619 struct lustre_handle *lh)
622 int nrbufs = obj->ioo_bufcnt;
623 struct ldlm_res_id res_id;
624 ldlm_policy_data_t policy;
628 osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id);
629 LASSERT(mode == LCK_PR || mode == LCK_PW);
630 LASSERT(!lustre_handle_is_used(lh));
632 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
635 for (i = 1; i < nrbufs; i ++)
636 if ((nb[0].flags & OBD_BRW_SRVLOCK) !=
637 (nb[i].flags & OBD_BRW_SRVLOCK))
640 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
641 policy.l_extent.end = (nb[nrbufs - 1].offset +
642 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
644 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
645 LDLM_EXTENT, &policy, mode, &flags,
646 ldlm_blocking_ast, ldlm_completion_ast,
647 ldlm_glimpse_ast, NULL, 0, LVB_T_NONE,
651 static void ost_brw_lock_put(int mode,
652 struct obd_ioobj *obj, struct niobuf_remote *niob,
653 struct lustre_handle *lh)
656 LASSERT(mode == LCK_PR || mode == LCK_PW);
657 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
658 lustre_handle_is_used(lh));
659 if (lustre_handle_is_used(lh))
660 ldlm_lock_decref(lh, mode);
664 /* Allocate thread local buffers if needed */
665 static struct ost_thread_local_cache *ost_tls_get(struct ptlrpc_request *r)
667 struct ost_thread_local_cache *tls =
668 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
670 /* In normal mode of operation an I/O request is serviced only
671 * by ll_ost_io threads each of them has own tls buffers allocated by
672 * ost_io_thread_init().
673 * During recovery, an I/O request may be queued until any of the ost
674 * service threads process it. Not necessary it should be one of
675 * ll_ost_io threads. In that case we dynamically allocating tls
676 * buffers for the request service time. */
677 if (unlikely(tls == NULL)) {
678 LASSERT(r->rq_export->exp_in_recovery);
682 r->rq_svc_thread->t_data = tls;
688 /* Free thread local buffers if they were allocated only for servicing
689 * this one request */
690 static void ost_tls_put(struct ptlrpc_request *r)
692 struct ost_thread_local_cache *tls =
693 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
695 if (unlikely(tls->temporary)) {
697 r->rq_svc_thread->t_data = NULL;
701 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
703 struct ptlrpc_bulk_desc *desc = NULL;
704 struct obd_export *exp = req->rq_export;
705 struct niobuf_remote *remote_nb;
706 struct niobuf_local *local_nb;
707 struct obd_ioobj *ioo;
708 struct ost_body *body, *repbody;
709 struct lustre_capa *capa = NULL;
710 struct l_wait_info lwi;
711 struct lustre_handle lockh = { 0 };
712 int niocount, npages, nob = 0, rc, i;
714 struct ost_thread_local_cache *tls;
717 req->rq_bulk_read = 1;
719 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
720 GOTO(out, rc = -EIO);
722 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
724 /* Check if there is eviction in progress, and if so, wait for it to
726 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
727 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
728 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
729 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
733 GOTO(out, rc = -ENOTCONN);
735 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
736 * ost_rw_hpreq_check(). */
737 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
739 GOTO(out, rc = -EFAULT);
742 * A req_capsule_X_get_array(pill, field, ptr_to_element_count) function
743 * would be useful here and wherever we get &RMF_OBD_IOOBJ and
744 * &RMF_NIOBUF_REMOTE.
746 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
748 GOTO(out, rc = -EFAULT);
750 rc = ost_validate_obdo(exp, &body->oa, ioo);
754 niocount = ioo->ioo_bufcnt;
755 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
756 if (remote_nb == NULL)
757 GOTO(out, rc = -EFAULT);
759 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
760 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
762 CERROR("Missing capability for OST BRW READ");
763 GOTO(out, rc = -EFAULT);
767 rc = req_capsule_server_pack(&req->rq_pill);
771 tls = ost_tls_get(req);
773 GOTO(out_bulk, rc = -ENOMEM);
774 local_nb = tls->local;
776 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
781 * If getting the lock took more time than
782 * client was willing to wait, drop it. b=11330
784 if (cfs_time_current_sec() > req->rq_deadline ||
785 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
787 CERROR("Dropping timed-out read from %s because locking"
788 "object "LPX64" took %ld seconds (limit was %ld).\n",
789 libcfs_id2str(req->rq_peer), ioo->ioo_id,
790 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
791 req->rq_deadline - req->rq_arrival_time.tv_sec);
792 GOTO(out_lock, rc = -ETIMEDOUT);
795 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
796 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
798 npages = OST_THREAD_POOL_SIZE;
799 rc = obd_preprw(req->rq_svc_thread->t_env, OBD_BRW_READ, exp,
800 &repbody->oa, 1, ioo, remote_nb, &npages, local_nb,
805 desc = ptlrpc_prep_bulk_exp(req, npages,
806 BULK_PUT_SOURCE, OST_BULK_PORTAL);
808 GOTO(out_commitrw, rc = -ENOMEM);
811 for (i = 0; i < npages; i++) {
812 int page_rc = local_nb[i].rc;
814 if (page_rc < 0) { /* error */
820 if (page_rc != 0) { /* some data! */
821 LASSERT (local_nb[i].page != NULL);
822 ptlrpc_prep_bulk_page_nopin(desc, local_nb[i].page,
823 local_nb[i].lnb_page_offset,
827 if (page_rc != local_nb[i].len) { /* short read */
828 /* All subsequent pages should be 0 */
830 LASSERT(local_nb[i].rc == 0);
835 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
836 cksum_type_t cksum_type =
837 cksum_type_unpack(repbody->oa.o_valid & OBD_MD_FLFLAGS ?
838 repbody->oa.o_flags : 0);
839 repbody->oa.o_flags = cksum_type_pack(cksum_type);
840 repbody->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
841 repbody->oa.o_cksum = ost_checksum_bulk(desc, OST_READ,cksum_type);
842 CDEBUG(D_PAGE, "checksum at read origin: %x\n",
843 repbody->oa.o_cksum);
845 repbody->oa.o_valid = 0;
847 /* We're finishing using body->oa as an input variable */
849 /* Check if client was evicted while we were doing i/o before touching
852 if (likely(!CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2)))
853 rc = target_bulk_io(exp, desc, &lwi);
858 /* Must commit after prep above in all cases */
859 rc = obd_commitrw(req->rq_svc_thread->t_env, OBD_BRW_READ, exp,
860 &repbody->oa, 1, ioo, remote_nb, npages, local_nb,
864 ost_drop_id(exp, &repbody->oa);
867 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
871 if (desc && !CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2))
872 ptlrpc_free_bulk_nopin(desc);
876 req->rq_status = nob;
877 ptlrpc_lprocfs_brw(req, nob);
878 target_committed_to_req(req);
880 } else if (!no_reply) {
881 /* Only reply if there was no comms problem with bulk */
882 target_committed_to_req(req);
886 /* reply out callback would free */
887 ptlrpc_req_drop_rs(req);
888 LCONSOLE_WARN("%s: Bulk IO read error with %s (at %s), "
889 "client will retry: rc %d\n",
890 exp->exp_obd->obd_name,
891 obd_uuid2str(&exp->exp_client_uuid),
892 obd_export_nid2str(exp), rc);
894 /* send a bulk after reply to simulate a network delay or reordering
896 if (unlikely(CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2))) {
898 struct l_wait_info lwi1;
900 CDEBUG(D_INFO, "reorder BULK\n");
901 cfs_waitq_init(&waitq);
903 lwi1 = LWI_TIMEOUT_INTR(cfs_time_seconds(3), NULL, NULL, NULL);
904 l_wait_event(waitq, 0, &lwi1);
905 rc = target_bulk_io(exp, desc, &lwi);
906 ptlrpc_free_bulk_nopin(desc);
912 static void ost_warn_on_cksum(struct ptlrpc_request *req,
913 struct ptlrpc_bulk_desc *desc,
914 struct niobuf_local *local_nb, int npages,
915 obd_count client_cksum, obd_count server_cksum,
918 struct obd_export *exp = req->rq_export;
919 struct ost_body *body;
923 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
924 LASSERT (body != NULL);
926 if (req->rq_peer.nid == desc->bd_sender) {
930 router = libcfs_nid2str(desc->bd_sender);
934 CDEBUG_LIMIT(D_INFO, "client csum %x, server csum %x\n",
935 client_cksum, server_cksum);
939 LCONSOLE_ERROR_MSG(0x168, "BAD WRITE CHECKSUM: %s from %s%s%s inode "
940 DFID" object "LPU64"/"LPU64" extent ["LPU64"-"LPU64
941 "]: client csum %x, server csum %x\n",
942 exp->exp_obd->obd_name, libcfs_id2str(req->rq_peer),
944 body->oa.o_valid & OBD_MD_FLFID ?
945 body->oa.o_parent_seq : (__u64)0,
946 body->oa.o_valid & OBD_MD_FLFID ?
947 body->oa.o_parent_oid : 0,
948 body->oa.o_valid & OBD_MD_FLFID ?
949 body->oa.o_parent_ver : 0,
951 body->oa.o_valid & OBD_MD_FLGROUP ?
952 body->oa.o_seq : (__u64)0,
953 local_nb[0].lnb_file_offset,
954 local_nb[npages-1].lnb_file_offset +
955 local_nb[npages-1].len - 1,
956 client_cksum, server_cksum);
959 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
961 struct ptlrpc_bulk_desc *desc = NULL;
962 struct obd_export *exp = req->rq_export;
963 struct niobuf_remote *remote_nb;
964 struct niobuf_local *local_nb;
965 struct obd_ioobj *ioo;
966 struct ost_body *body, *repbody;
967 struct l_wait_info lwi;
968 struct lustre_handle lockh = {0};
969 struct lustre_capa *capa = NULL;
971 int objcount, niocount, npages;
973 obd_count client_cksum = 0, server_cksum = 0;
974 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
975 int no_reply = 0, mmap = 0;
976 __u32 o_uid = 0, o_gid = 0;
977 struct ost_thread_local_cache *tls;
980 req->rq_bulk_write = 1;
982 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
983 GOTO(out, rc = -EIO);
984 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
985 GOTO(out, rc = -EFAULT);
987 /* pause before transaction has been started */
988 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
990 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
991 * ost_rw_hpreq_check(). */
992 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
994 GOTO(out, rc = -EFAULT);
996 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
997 RCL_CLIENT) / sizeof(*ioo);
998 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1000 GOTO(out, rc = -EFAULT);
1002 rc = ost_validate_obdo(exp, &body->oa, ioo);
1006 for (niocount = i = 0; i < objcount; i++)
1007 niocount += ioo[i].ioo_bufcnt;
1010 * It'd be nice to have a capsule function to indicate how many elements
1011 * there were in a buffer for an RMF that's declared to be an array.
1012 * It's easy enough to compute the number of elements here though.
1014 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1015 if (remote_nb == NULL || niocount != (req_capsule_get_size(&req->rq_pill,
1016 &RMF_NIOBUF_REMOTE, RCL_CLIENT) / sizeof(*remote_nb)))
1017 GOTO(out, rc = -EFAULT);
1019 if ((remote_nb[0].flags & OBD_BRW_MEMALLOC) &&
1020 (exp->exp_connection->c_peer.nid == exp->exp_connection->c_self))
1021 cfs_memory_pressure_set();
1023 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
1024 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
1026 CERROR("Missing capability for OST BRW WRITE");
1027 GOTO(out, rc = -EFAULT);
1031 req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER,
1032 niocount * sizeof(*rcs));
1033 rc = req_capsule_server_pack(&req->rq_pill);
1036 CFS_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, cfs_fail_val);
1037 rcs = req_capsule_server_get(&req->rq_pill, &RMF_RCS);
1039 tls = ost_tls_get(req);
1041 GOTO(out_bulk, rc = -ENOMEM);
1042 local_nb = tls->local;
1044 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
1049 * If getting the lock took more time than
1050 * client was willing to wait, drop it. b=11330
1052 if (cfs_time_current_sec() > req->rq_deadline ||
1053 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
1055 CERROR("Dropping timed-out write from %s because locking "
1056 "object "LPX64" took %ld seconds (limit was %ld).\n",
1057 libcfs_id2str(req->rq_peer), ioo->ioo_id,
1058 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
1059 req->rq_deadline - req->rq_arrival_time.tv_sec);
1060 GOTO(out_lock, rc = -ETIMEDOUT);
1063 /* obd_preprw clobbers oa->valid, so save what we need */
1064 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
1065 client_cksum = body->oa.o_cksum;
1066 if (body->oa.o_valid & OBD_MD_FLFLAGS)
1067 cksum_type = cksum_type_unpack(body->oa.o_flags);
1069 if (body->oa.o_valid & OBD_MD_FLFLAGS && body->oa.o_flags & OBD_FL_MMAP)
1072 /* Because we already sync grant info with client when reconnect,
1073 * grant info will be cleared for resent req, then fed_grant and
1074 * total_grant will not be modified in following preprw_write */
1075 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1076 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1077 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1080 if (exp_connect_rmtclient(exp)) {
1081 o_uid = body->oa.o_uid;
1082 o_gid = body->oa.o_gid;
1085 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
1086 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1088 npages = OST_THREAD_POOL_SIZE;
1089 rc = obd_preprw(req->rq_svc_thread->t_env, OBD_BRW_WRITE, exp,
1090 &repbody->oa, objcount, ioo, remote_nb, &npages,
1091 local_nb, oti, capa);
1095 desc = ptlrpc_prep_bulk_exp(req, npages,
1096 BULK_GET_SINK, OST_BULK_PORTAL);
1098 GOTO(skip_transfer, rc = -ENOMEM);
1100 /* NB Having prepped, we must commit... */
1102 for (i = 0; i < npages; i++)
1103 ptlrpc_prep_bulk_page_nopin(desc, local_nb[i].page,
1104 local_nb[i].lnb_page_offset,
1107 rc = sptlrpc_svc_prep_bulk(req, desc);
1111 rc = target_bulk_io(exp, desc, &lwi);
1115 if (client_cksum != 0 && rc == 0) {
1116 static int cksum_counter;
1117 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1118 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1119 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1120 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1121 repbody->oa.o_cksum = server_cksum;
1123 if (unlikely(client_cksum != server_cksum)) {
1124 ost_warn_on_cksum(req, desc, local_nb, npages,
1125 client_cksum, server_cksum, mmap);
1128 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1129 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1130 cksum_counter, libcfs_id2str(req->rq_peer),
1135 /* Must commit after prep above in all cases */
1136 rc = obd_commitrw(req->rq_svc_thread->t_env, OBD_BRW_WRITE, exp,
1137 &repbody->oa, objcount, ioo, remote_nb, npages,
1139 if (rc == -ENOTCONN)
1140 /* quota acquire process has been given up because
1141 * either the client has been evicted or the client
1142 * has timed out the request already */
1145 if (exp_connect_rmtclient(exp)) {
1146 repbody->oa.o_uid = o_uid;
1147 repbody->oa.o_gid = o_gid;
1151 * Disable sending mtime back to the client. If the client locked the
1152 * whole object, then it has already updated the mtime on its side,
1153 * otherwise it will have to glimpse anyway (see bug 21489, comment 32)
1155 repbody->oa.o_valid &= ~(OBD_MD_FLMTIME | OBD_MD_FLATIME);
1160 /* set per-requested niobuf return codes */
1161 for (i = j = 0; i < niocount; i++) {
1162 int len = remote_nb[i].len;
1167 LASSERT(j < npages);
1168 if (local_nb[j].rc < 0)
1169 rcs[i] = local_nb[j].rc;
1170 len -= local_nb[j].len;
1175 LASSERT(j == npages);
1176 ptlrpc_lprocfs_brw(req, nob);
1180 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1185 ptlrpc_free_bulk_nopin(desc);
1188 oti_to_request(oti, req);
1189 target_committed_to_req(req);
1190 rc = ptlrpc_reply(req);
1191 } else if (!no_reply) {
1192 /* Only reply if there was no comms problem with bulk */
1193 target_committed_to_req(req);
1194 req->rq_status = rc;
1197 /* reply out callback would free */
1198 ptlrpc_req_drop_rs(req);
1199 LCONSOLE_WARN("%s: Bulk IO write error with %s (at %s), "
1200 "client will retry: rc %d\n",
1201 exp->exp_obd->obd_name,
1202 obd_uuid2str(&exp->exp_client_uuid),
1203 obd_export_nid2str(exp), rc);
1205 cfs_memory_pressure_clr();
1210 * Implementation of OST_SET_INFO.
1212 * OST_SET_INFO is like ioctl(): heavily overloaded. Specifically, it takes a
1213 * "key" and a value RPC buffers as arguments, with the value's contents
1214 * interpreted according to the key.
1216 * Value types that need swabbing have swabbing done explicitly, either here or
1217 * in functions called from here. This should be corrected: all swabbing should
1218 * be done in the capsule abstraction, as that will then allow us to move
1219 * swabbing exclusively to the client without having to modify server code
1220 * outside the capsule abstraction's implementation itself. To correct this
1221 * will require minor changes to the capsule abstraction; see the comments for
1222 * req_capsule_extend() in layout.c.
1224 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1226 struct ost_body *body = NULL, *repbody;
1227 char *key, *val = NULL;
1228 int keylen, vallen, rc = 0;
1229 int is_grant_shrink = 0;
1232 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1234 DEBUG_REQ(D_HA, req, "no set_info key");
1237 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1240 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1243 if ((is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK)))
1244 /* In this case the value is actually an RMF_OST_BODY, so we
1245 * transmutate the type of this PTLRPC */
1246 req_capsule_extend(&req->rq_pill, &RQF_OST_SET_GRANT_INFO);
1248 rc = req_capsule_server_pack(&req->rq_pill);
1253 if (is_grant_shrink) {
1254 body = req_capsule_client_get(&req->rq_pill,
1259 repbody = req_capsule_server_get(&req->rq_pill,
1261 memcpy(repbody, body, sizeof(*body));
1262 val = (char*)repbody;
1264 val = req_capsule_client_get(&req->rq_pill,
1269 if (KEY_IS(KEY_EVICT_BY_NID)) {
1271 obd_export_evict_by_nid(exp->exp_obd, val);
1273 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1274 if (vallen < sizeof(__u32))
1276 __swab32s((__u32 *)val);
1279 /* OBD will also check if KEY_IS(KEY_GRANT_SHRINK), and will cast val to
1280 * a struct ost_body * value */
1281 rc = obd_set_info_async(req->rq_svc_thread->t_env, exp, keylen,
1282 key, vallen, val, NULL);
1284 lustre_msg_set_status(req->rq_repmsg, 0);
1288 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1291 int keylen, replylen, rc = 0;
1292 struct req_capsule *pill = &req->rq_pill;
1295 /* this common part for get_info rpc */
1296 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1298 DEBUG_REQ(D_HA, req, "no get_info key");
1301 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1303 if (KEY_IS(KEY_FIEMAP)) {
1304 struct ll_fiemap_info_key *fm_key = key;
1307 rc = ost_validate_obdo(exp, &fm_key->oa, NULL);
1312 rc = obd_get_info(req->rq_svc_thread->t_env, exp, keylen, key,
1313 &replylen, NULL, NULL);
1317 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1318 RCL_SERVER, replylen);
1320 rc = req_capsule_server_pack(pill);
1324 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1328 /* call again to fill in the reply buffer */
1329 rc = obd_get_info(req->rq_svc_thread->t_env, exp, keylen, key,
1330 &replylen, reply, NULL);
1332 lustre_msg_set_status(req->rq_repmsg, 0);
1336 static int ost_handle_quotactl(struct ptlrpc_request *req)
1338 struct obd_quotactl *oqctl, *repoqc;
1342 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1344 GOTO(out, rc = -EPROTO);
1346 rc = req_capsule_server_pack(&req->rq_pill);
1350 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1351 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1358 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1360 struct obd_quotactl *oqctl;
1364 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1368 rc = req_capsule_server_pack(&req->rq_pill);
1372 /* deprecated, not used any more */
1373 req->rq_status = -EOPNOTSUPP;
1374 RETURN(-EOPNOTSUPP);
1377 static int ost_llog_handle_connect(struct obd_export *exp,
1378 struct ptlrpc_request *req)
1380 struct llogd_conn_body *body;
1384 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
1385 rc = obd_llog_connect(exp, body);
1389 #define ost_init_sec_none(reply, exp) \
1391 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1392 OBD_CONNECT_RMT_CLIENT_FORCE | \
1393 OBD_CONNECT_OSS_CAPA); \
1394 spin_lock(&exp->exp_lock); \
1395 exp->exp_connect_flags = reply->ocd_connect_flags; \
1396 spin_unlock(&exp->exp_lock); \
1399 static int ost_init_sec_level(struct ptlrpc_request *req)
1401 struct obd_export *exp = req->rq_export;
1402 struct req_capsule *pill = &req->rq_pill;
1403 struct obd_device *obd = exp->exp_obd;
1404 struct filter_obd *filter = &obd->u.filter;
1405 char *client = libcfs_nid2str(req->rq_peer.nid);
1406 struct obd_connect_data *data, *reply;
1410 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1411 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1412 if (data == NULL || reply == NULL)
1415 /* connection from MDT is always trusted */
1416 if (req->rq_auth_usr_mdt) {
1417 ost_init_sec_none(reply, exp);
1421 /* no GSS support case */
1422 if (!req->rq_auth_gss) {
1423 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1424 CWARN("client %s -> target %s does not user GSS, "
1425 "can not run under security level %d.\n",
1426 client, obd->obd_name, filter->fo_sec_level);
1429 ost_init_sec_none(reply, exp);
1434 /* old version case */
1435 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1436 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1437 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1438 CWARN("client %s -> target %s uses old version, "
1439 "can not run under security level %d.\n",
1440 client, obd->obd_name, filter->fo_sec_level);
1443 CWARN("client %s -> target %s uses old version, "
1444 "run under security level %d.\n",
1445 client, obd->obd_name, filter->fo_sec_level);
1446 ost_init_sec_none(reply, exp);
1451 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1453 if (!req->rq_auth_remote)
1454 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1455 "asked to be remote.\n", client, obd->obd_name);
1456 } else if (req->rq_auth_remote) {
1458 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1459 "as remote by default.\n", client, obd->obd_name);
1463 if (!filter->fo_fl_oss_capa) {
1464 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1465 " but OSS capabilities are not enabled: %d.\n",
1466 client, obd->obd_name, filter->fo_fl_oss_capa);
1471 switch (filter->fo_sec_level) {
1472 case LUSTRE_SEC_NONE:
1474 ost_init_sec_none(reply, exp);
1477 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1478 "can not run under security level %d.\n",
1479 client, obd->obd_name, filter->fo_sec_level);
1482 case LUSTRE_SEC_REMOTE:
1484 ost_init_sec_none(reply, exp);
1486 case LUSTRE_SEC_ALL:
1488 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1489 OBD_CONNECT_RMT_CLIENT_FORCE);
1490 if (!filter->fo_fl_oss_capa)
1491 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1493 spin_lock(&exp->exp_lock);
1494 exp->exp_connect_flags = reply->ocd_connect_flags;
1495 spin_unlock(&exp->exp_lock);
1507 * this should be done in filter_connect()/filter_reconnect(), but
1508 * we can't obtain information like NID, which stored in incoming
1509 * request, thus can't decide what flavor to use. so we do it here.
1511 * This hack should be removed after the OST stack be rewritten, just
1512 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1514 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1516 struct obd_export *exp = req->rq_export;
1517 struct filter_obd *filter = &exp->exp_obd->u.filter;
1518 struct sptlrpc_flavor flvr;
1521 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1522 LUSTRE_ECHO_NAME) == 0)) {
1523 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1527 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1528 read_lock(&filter->fo_sptlrpc_lock);
1529 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1533 read_unlock(&filter->fo_sptlrpc_lock);
1535 spin_lock(&exp->exp_lock);
1537 exp->exp_sp_peer = req->rq_sp_from;
1538 exp->exp_flvr = flvr;
1540 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1541 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1542 CERROR("unauthorized rpc flavor %x from %s, "
1543 "expect %x\n", req->rq_flvr.sf_rpc,
1544 libcfs_nid2str(req->rq_peer.nid),
1545 exp->exp_flvr.sf_rpc);
1549 spin_unlock(&exp->exp_lock);
1551 if (exp->exp_sp_peer != req->rq_sp_from) {
1552 CERROR("RPC source %s doesn't match %s\n",
1553 sptlrpc_part2name(req->rq_sp_from),
1554 sptlrpc_part2name(exp->exp_sp_peer));
1557 rc = sptlrpc_target_export_check(exp, req);
1564 /* Ensure that data and metadata are synced to the disk when lock is cancelled
1566 int ost_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
1567 void *data, int flag)
1570 __u32 sync_lock_cancel = 0;
1571 __u32 len = sizeof(sync_lock_cancel);
1576 rc = lu_env_init(&env, LCT_DT_THREAD);
1577 if (unlikely(rc != 0))
1580 rc = obd_get_info(&env, lock->l_export, sizeof(KEY_SYNC_LOCK_CANCEL),
1581 KEY_SYNC_LOCK_CANCEL, &len, &sync_lock_cancel, NULL);
1582 if (rc == 0 && flag == LDLM_CB_CANCELING &&
1583 (lock->l_granted_mode & (LCK_PW|LCK_GROUP)) &&
1584 (sync_lock_cancel == ALWAYS_SYNC_ON_CANCEL ||
1585 (sync_lock_cancel == BLOCKING_SYNC_ON_CANCEL &&
1586 lock->l_flags & LDLM_FL_CBPENDING))) {
1587 struct obd_info *oinfo;
1591 OBD_ALLOC_PTR(oinfo);
1593 GOTO(out_env, rc = -ENOMEM);
1596 OBD_FREE_PTR(oinfo);
1597 GOTO(out_env, rc = -ENOMEM);
1599 oa->o_id = lock->l_resource->lr_name.name[0];
1600 oa->o_seq = lock->l_resource->lr_name.name[1];
1601 oa->o_valid = OBD_MD_FLID|OBD_MD_FLGROUP;
1603 oinfo->oi_capa = BYPASS_CAPA;
1605 rc = obd_sync(&env, lock->l_export, oinfo,
1606 lock->l_policy_data.l_extent.start,
1607 lock->l_policy_data.l_extent.end, NULL);
1609 CERROR("Error %d syncing data on lock cancel\n", rc);
1612 OBD_FREE_PTR(oinfo);
1615 rc = ldlm_server_blocking_ast(lock, desc, data, flag);
1621 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1622 struct obd_device *obd, int *process)
1624 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1625 case OST_CONNECT: /* This will never get here, but for completeness. */
1626 case OST_DISCONNECT:
1637 case OBD_LOG_CANCEL:
1639 *process = target_queue_recovery_request(req, obd);
1643 DEBUG_REQ(D_WARNING, req, "not permitted during recovery");
1649 int ost_msg_check_version(struct lustre_msg *msg)
1653 switch(lustre_msg_get_opc(msg)) {
1655 case OST_DISCONNECT:
1658 case SEC_CTX_INIT_CONT:
1660 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1662 CERROR("bad opc %u version %08x, expecting %08x\n",
1663 lustre_msg_get_opc(msg),
1664 lustre_msg_get_version(msg),
1665 LUSTRE_OBD_VERSION);
1668 /* Note: client always use MDS_VERSION for FID request */
1669 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
1671 CERROR("bad opc %u version %08x, expecting %08x\n",
1672 lustre_msg_get_opc(msg),
1673 lustre_msg_get_version(msg),
1674 LUSTRE_MDS_VERSION);
1687 case OST_QUOTACHECK:
1689 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1691 CERROR("bad opc %u version %08x, expecting %08x\n",
1692 lustre_msg_get_opc(msg),
1693 lustre_msg_get_version(msg),
1694 LUSTRE_OST_VERSION);
1699 case LDLM_BL_CALLBACK:
1700 case LDLM_CP_CALLBACK:
1701 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1703 CERROR("bad opc %u version %08x, expecting %08x\n",
1704 lustre_msg_get_opc(msg),
1705 lustre_msg_get_version(msg),
1706 LUSTRE_DLM_VERSION);
1708 case LLOG_ORIGIN_CONNECT:
1709 case OBD_LOG_CANCEL:
1710 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1712 CERROR("bad opc %u version %08x, expecting %08x\n",
1713 lustre_msg_get_opc(msg),
1714 lustre_msg_get_version(msg),
1715 LUSTRE_LOG_VERSION);
1717 case OST_QUOTA_ADJUST_QUNIT:
1719 CERROR("Quota adjust is deprecated as of 2.4.0\n");
1722 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1728 struct ost_prolong_data {
1729 struct ptlrpc_request *opd_req;
1730 struct obd_export *opd_exp;
1731 struct obdo *opd_oa;
1732 struct ldlm_res_id opd_resid;
1733 struct ldlm_extent opd_extent;
1734 ldlm_mode_t opd_mode;
1735 unsigned int opd_locks;
1739 /* prolong locks for the current service time of the corresponding
1740 * portal (= OST_IO_PORTAL)
1742 static inline int prolong_timeout(struct ptlrpc_request *req)
1744 struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
1747 return obd_timeout / 2;
1749 return max(at_est2timeout(at_get(&svcpt->scp_at_estimate)),
1753 static void ost_prolong_lock_one(struct ost_prolong_data *opd,
1754 struct ldlm_lock *lock)
1756 LASSERT(lock->l_export == opd->opd_exp);
1758 if (lock->l_destroyed) /* lock already cancelled */
1761 /* XXX: never try to grab resource lock here because we're inside
1762 * exp_bl_list_lock; in ldlm_lockd.c to handle waiting list we take
1763 * res lock and then exp_bl_list_lock. */
1765 if (!(lock->l_flags & LDLM_FL_AST_SENT))
1766 /* ignore locks not being cancelled */
1770 "refreshed for req x"LPU64" ext("LPU64"->"LPU64") to %ds.\n",
1771 opd->opd_req->rq_xid, opd->opd_extent.start,
1772 opd->opd_extent.end, opd->opd_timeout);
1774 /* OK. this is a possible lock the user holds doing I/O
1775 * let's refresh eviction timer for it */
1776 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
1780 static void ost_prolong_locks(struct ost_prolong_data *data)
1782 struct obd_export *exp = data->opd_exp;
1783 struct obdo *oa = data->opd_oa;
1784 struct ldlm_lock *lock;
1787 if (oa->o_valid & OBD_MD_FLHANDLE) {
1788 /* mostly a request should be covered by only one lock, try
1790 lock = ldlm_handle2lock(&oa->o_handle);
1792 /* Fast path to check if the lock covers the whole IO
1793 * region exclusively. */
1794 if (lock->l_granted_mode == LCK_PW &&
1795 ldlm_extent_contain(&lock->l_policy_data.l_extent,
1796 &data->opd_extent)) {
1798 ost_prolong_lock_one(data, lock);
1799 LDLM_LOCK_PUT(lock);
1802 LDLM_LOCK_PUT(lock);
1807 spin_lock_bh(&exp->exp_bl_list_lock);
1808 cfs_list_for_each_entry(lock, &exp->exp_bl_list, l_exp_list) {
1809 LASSERT(lock->l_flags & LDLM_FL_AST_SENT);
1810 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
1812 if (!ldlm_res_eq(&data->opd_resid, &lock->l_resource->lr_name))
1815 if (!ldlm_extent_overlap(&lock->l_policy_data.l_extent,
1819 ost_prolong_lock_one(data, lock);
1821 spin_unlock_bh(&exp->exp_bl_list_lock);
1827 * Returns 1 if the given PTLRPC matches the given LDLM locks, or 0 if it does
1830 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1831 struct ldlm_lock *lock)
1833 struct niobuf_remote *nb;
1834 struct obd_ioobj *ioo;
1836 struct ldlm_extent ext;
1839 opc = lustre_msg_get_opc(req->rq_reqmsg);
1840 LASSERT(opc == OST_READ || opc == OST_WRITE);
1842 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1843 LASSERT(ioo != NULL);
1845 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1846 LASSERT(nb != NULL);
1848 ext.start = nb->offset;
1849 nb += ioo->ioo_bufcnt - 1;
1850 ext.end = nb->offset + nb->len - 1;
1852 LASSERT(lock->l_resource != NULL);
1853 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_seq,
1854 &lock->l_resource->lr_name))
1858 if (opc == OST_READ)
1860 if (!(lock->l_granted_mode & mode))
1863 RETURN(ldlm_extent_overlap(&lock->l_policy_data.l_extent, &ext));
1867 * High-priority queue request check for whether the given PTLRPC request (\a
1868 * req) is blocking an LDLM lock cancel.
1870 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1871 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1873 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1874 * function looks only at OST_READs and OST_WRITEs.
1876 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1878 struct obd_device *obd = req->rq_export->exp_obd;
1879 struct ost_body *body;
1880 struct obd_ioobj *ioo;
1881 struct niobuf_remote *nb;
1882 struct ost_prolong_data opd = { 0 };
1887 * Use LASSERT to do sanity check because malformed RPCs should have
1888 * been filtered out in ost_hpreq_handler().
1890 opc = lustre_msg_get_opc(req->rq_reqmsg);
1891 LASSERT(opc == OST_READ || opc == OST_WRITE);
1893 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1894 LASSERT(body != NULL);
1896 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1897 LASSERT(ioo != NULL);
1899 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1900 LASSERT(nb != NULL);
1901 LASSERT(!(nb->flags & OBD_BRW_SRVLOCK));
1903 osc_build_res_name(ioo->ioo_id, ioo->ioo_seq, &opd.opd_resid);
1907 if (opc == OST_READ)
1909 opd.opd_mode = mode;
1910 opd.opd_exp = req->rq_export;
1911 opd.opd_oa = &body->oa;
1912 opd.opd_extent.start = nb->offset;
1913 nb += ioo->ioo_bufcnt - 1;
1914 opd.opd_extent.end = nb->offset + nb->len - 1;
1915 opd.opd_timeout = prolong_timeout(req);
1917 DEBUG_REQ(D_RPCTRACE, req,
1918 "%s %s: refresh rw locks: " LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1919 obd->obd_name, cfs_current()->comm,
1920 opd.opd_resid.name[0], opd.opd_resid.name[1],
1921 opd.opd_extent.start, opd.opd_extent.end);
1923 ost_prolong_locks(&opd);
1925 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
1926 obd->obd_name, opd.opd_locks, req);
1928 RETURN(opd.opd_locks);
1931 static void ost_rw_hpreq_fini(struct ptlrpc_request *req)
1933 (void)ost_rw_hpreq_check(req);
1937 * Like ost_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
1939 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1940 struct ldlm_lock *lock)
1942 struct ost_body *body;
1945 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1946 LASSERT(body != NULL);
1948 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1949 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1956 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
1958 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1960 struct obd_device *obd = req->rq_export->exp_obd;
1961 struct ost_body *body;
1963 struct ost_prolong_data opd = { 0 };
1967 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1968 LASSERT(body != NULL);
1971 LASSERT(!(oa->o_valid & OBD_MD_FLFLAGS) ||
1972 !(oa->o_flags & OBD_FL_SRVLOCK));
1975 end = start + oa->o_blocks;
1978 opd.opd_mode = LCK_PW;
1979 opd.opd_exp = req->rq_export;
1981 opd.opd_extent.start = start;
1982 opd.opd_extent.end = end;
1983 if (oa->o_blocks == OBD_OBJECT_EOF)
1984 opd.opd_extent.end = OBD_OBJECT_EOF;
1985 opd.opd_timeout = prolong_timeout(req);
1987 osc_build_res_name(oa->o_id, oa->o_seq, &opd.opd_resid);
1990 "%s: refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1992 opd.opd_resid.name[0], opd.opd_resid.name[1],
1993 opd.opd_extent.start, opd.opd_extent.end);
1995 ost_prolong_locks(&opd);
1997 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
1998 obd->obd_name, opd.opd_locks, req);
2000 RETURN(opd.opd_locks > 0);
2003 static void ost_punch_hpreq_fini(struct ptlrpc_request *req)
2005 (void)ost_punch_hpreq_check(req);
2008 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
2009 .hpreq_lock_match = ost_rw_hpreq_lock_match,
2010 .hpreq_check = ost_rw_hpreq_check,
2011 .hpreq_fini = ost_rw_hpreq_fini
2014 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
2015 .hpreq_lock_match = ost_punch_hpreq_lock_match,
2016 .hpreq_check = ost_punch_hpreq_check,
2017 .hpreq_fini = ost_punch_hpreq_fini
2020 /** Assign high priority operations to the request if needed. */
2021 static int ost_io_hpreq_handler(struct ptlrpc_request *req)
2024 if (req->rq_export) {
2025 int opc = lustre_msg_get_opc(req->rq_reqmsg);
2026 struct ost_body *body;
2028 if (opc == OST_READ || opc == OST_WRITE) {
2029 struct niobuf_remote *nb;
2030 struct obd_ioobj *ioo;
2031 int objcount, niocount;
2035 /* RPCs on the H-P queue can be inspected before
2036 * ost_handler() initializes their pills, so we
2037 * initialize that here. Capsule initialization is
2038 * idempotent, as is setting the pill's format (provided
2039 * it doesn't change).
2041 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2042 if (opc == OST_READ)
2043 req_capsule_set(&req->rq_pill,
2046 req_capsule_set(&req->rq_pill,
2047 &RQF_OST_BRW_WRITE);
2049 body = req_capsule_client_get(&req->rq_pill,
2052 CERROR("Missing/short ost_body\n");
2056 objcount = req_capsule_get_size(&req->rq_pill,
2060 if (objcount == 0) {
2061 CERROR("Missing/short ioobj\n");
2065 CERROR("too many ioobjs (%d)\n", objcount);
2069 ioo = req_capsule_client_get(&req->rq_pill,
2072 CERROR("Missing/short ioobj\n");
2076 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
2078 CERROR("invalid object ids\n");
2082 for (niocount = i = 0; i < objcount; i++) {
2083 if (ioo[i].ioo_bufcnt == 0) {
2084 CERROR("ioo[%d] has zero bufcnt\n", i);
2087 niocount += ioo[i].ioo_bufcnt;
2089 if (niocount > PTLRPC_MAX_BRW_PAGES) {
2090 DEBUG_REQ(D_RPCTRACE, req,
2091 "bulk has too many pages (%d)",
2096 nb = req_capsule_client_get(&req->rq_pill,
2097 &RMF_NIOBUF_REMOTE);
2099 CERROR("Missing/short niobuf\n");
2103 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
2104 req->rq_ops = &ost_hpreq_rw;
2105 } else if (opc == OST_PUNCH) {
2106 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2107 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2109 body = req_capsule_client_get(&req->rq_pill,
2112 CERROR("Missing/short ost_body\n");
2116 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
2117 !(body->oa.o_flags & OBD_FL_SRVLOCK))
2118 req->rq_ops = &ost_hpreq_punch;
2124 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
2125 int ost_handle(struct ptlrpc_request *req)
2127 struct obd_trans_info trans_info = { 0, };
2128 struct obd_trans_info *oti = &trans_info;
2129 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
2130 struct obd_device *obd = NULL;
2133 /* OST module is kept between remounts, but the last reference
2134 * to specific module (say, osd or ofd) kills all related keys
2135 * from the environment. so we have to refill it until the root
2136 * cause is fixed properly */
2137 lu_env_refill(req->rq_svc_thread->t_env);
2139 LASSERT(current->journal_info == NULL);
2141 /* primordial rpcs don't affect server recovery */
2142 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2144 case SEC_CTX_INIT_CONT:
2149 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2151 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
2152 if (!class_connected_export(req->rq_export)) {
2153 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
2154 lustre_msg_get_opc(req->rq_reqmsg),
2155 libcfs_id2str(req->rq_peer));
2156 req->rq_status = -ENOTCONN;
2157 GOTO(out, rc = -ENOTCONN);
2160 obd = req->rq_export->exp_obd;
2162 /* Check for aborted recovery. */
2163 if (obd->obd_recovering) {
2164 rc = ost_filter_recovery_request(req, obd,
2166 if (rc || !should_process)
2168 else if (should_process < 0) {
2169 req->rq_status = should_process;
2170 rc = ptlrpc_error(req);
2178 rc = ost_msg_check_version(req->rq_reqmsg);
2182 if (req && req->rq_reqmsg && req->rq_export &&
2183 (req->rq_export->exp_connect_flags & OBD_CONNECT_JOBSTATS))
2184 oti->oti_jobid = lustre_msg_get_jobid(req->rq_reqmsg);
2186 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2188 CDEBUG(D_INODE, "connect\n");
2189 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
2190 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
2192 rc = target_handle_connect(req);
2193 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
2196 rc = ost_init_sec_level(req);
2198 rc = ost_connect_check_sptlrpc(req);
2202 case OST_DISCONNECT:
2203 CDEBUG(D_INODE, "disconnect\n");
2204 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
2205 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
2207 rc = target_handle_disconnect(req);
2210 CDEBUG(D_INODE, "create\n");
2211 req_capsule_set(&req->rq_pill, &RQF_OST_CREATE);
2212 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
2214 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2215 GOTO(out, rc = -EROFS);
2216 rc = ost_create(req->rq_export, req, oti);
2219 CDEBUG(D_INODE, "destroy\n");
2220 req_capsule_set(&req->rq_pill, &RQF_OST_DESTROY);
2221 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
2223 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2224 GOTO(out, rc = -EROFS);
2225 rc = ost_destroy(req->rq_export, req, oti);
2228 CDEBUG(D_INODE, "getattr\n");
2229 req_capsule_set(&req->rq_pill, &RQF_OST_GETATTR);
2230 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
2232 rc = ost_getattr(req->rq_export, req);
2235 CDEBUG(D_INODE, "setattr\n");
2236 req_capsule_set(&req->rq_pill, &RQF_OST_SETATTR);
2237 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
2239 rc = ost_setattr(req->rq_export, req, oti);
2242 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_WRITE);
2243 CDEBUG(D_INODE, "write\n");
2244 /* req->rq_request_portal would be nice, if it was set */
2245 if (ptlrpc_req2svc(req)->srv_req_portal != OST_IO_PORTAL) {
2246 CERROR("%s: deny write request from %s to portal %u\n",
2247 req->rq_export->exp_obd->obd_name,
2248 obd_export_nid2str(req->rq_export),
2249 ptlrpc_req2svc(req)->srv_req_portal);
2250 GOTO(out, rc = -EPROTO);
2252 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2254 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
2255 GOTO(out, rc = -ENOSPC);
2256 if (OBD_FAIL_TIMEOUT(OBD_FAIL_OST_EROFS, 1))
2257 GOTO(out, rc = -EROFS);
2258 rc = ost_brw_write(req, oti);
2259 LASSERT(current->journal_info == NULL);
2260 /* ost_brw_write sends its own replies */
2263 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_READ);
2264 CDEBUG(D_INODE, "read\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 read 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 rc = ost_brw_read(req, oti);
2276 LASSERT(current->journal_info == NULL);
2277 /* ost_brw_read sends its own replies */
2280 CDEBUG(D_INODE, "punch\n");
2281 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2282 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2284 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2285 GOTO(out, rc = -EROFS);
2286 rc = ost_punch(req->rq_export, req, oti);
2289 CDEBUG(D_INODE, "statfs\n");
2290 req_capsule_set(&req->rq_pill, &RQF_OST_STATFS);
2291 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2293 rc = ost_statfs(req);
2296 CDEBUG(D_INODE, "sync\n");
2297 req_capsule_set(&req->rq_pill, &RQF_OST_SYNC);
2298 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2300 rc = ost_sync(req->rq_export, req, oti);
2303 DEBUG_REQ(D_INODE, req, "set_info");
2304 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
2305 rc = ost_set_info(req->rq_export, req);
2308 DEBUG_REQ(D_INODE, req, "get_info");
2309 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
2310 rc = ost_get_info(req->rq_export, req);
2313 CDEBUG(D_INODE, "seq\n");
2314 rc = seq_handle(req);
2316 case OST_QUOTACHECK:
2317 CDEBUG(D_INODE, "quotacheck\n");
2318 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2319 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2321 rc = ost_handle_quotacheck(req);
2324 CDEBUG(D_INODE, "quotactl\n");
2325 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2326 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2328 rc = ost_handle_quotactl(req);
2331 DEBUG_REQ(D_INODE, req, "ping");
2332 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2333 rc = target_handle_ping(req);
2335 /* FIXME - just reply status */
2336 case LLOG_ORIGIN_CONNECT:
2337 DEBUG_REQ(D_INODE, req, "log connect");
2338 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2339 rc = ost_llog_handle_connect(req->rq_export, req);
2340 req->rq_status = rc;
2341 rc = req_capsule_server_pack(&req->rq_pill);
2344 RETURN(ptlrpc_reply(req));
2345 case OBD_LOG_CANCEL:
2346 CDEBUG(D_INODE, "log cancel\n");
2347 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2348 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2350 rc = llog_origin_handle_cancel(req);
2351 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2353 req->rq_status = rc;
2354 rc = req_capsule_server_pack(&req->rq_pill);
2357 RETURN(ptlrpc_reply(req));
2359 CDEBUG(D_INODE, "enqueue\n");
2360 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2361 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE_NET))
2363 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2365 ldlm_server_glimpse_ast);
2366 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2369 CDEBUG(D_INODE, "convert\n");
2370 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2371 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT_NET))
2373 rc = ldlm_handle_convert(req);
2376 CDEBUG(D_INODE, "cancel\n");
2377 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2378 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL_NET))
2380 rc = ldlm_handle_cancel(req);
2382 case LDLM_BL_CALLBACK:
2383 case LDLM_CP_CALLBACK:
2384 CDEBUG(D_INODE, "callback\n");
2385 CERROR("callbacks should not happen on OST\n");
2388 CERROR("Unexpected opcode %d\n",
2389 lustre_msg_get_opc(req->rq_reqmsg));
2390 req->rq_status = -ENOTSUPP;
2391 rc = ptlrpc_error(req);
2395 LASSERT(current->journal_info == NULL);
2398 /* If we're DISCONNECTing, the export_data is already freed */
2399 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2400 target_committed_to_req(req);
2404 oti_to_request(oti, req);
2406 target_send_reply(req, rc, fail);
2409 EXPORT_SYMBOL(ost_handle);
2412 * free per-thread pool created by ost_io_thread_init().
2414 static void ost_io_thread_done(struct ptlrpc_thread *thread)
2416 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2421 LASSERT(thread != NULL);
2424 * be prepared to handle partially-initialized pools (because this is
2425 * called from ost_io_thread_init() for cleanup.
2427 tls = thread->t_data;
2430 thread->t_data = NULL;
2436 * initialize per-thread page pool (bug 5137).
2438 static int ost_io_thread_init(struct ptlrpc_thread *thread)
2440 struct ost_thread_local_cache *tls;
2444 LASSERT(thread != NULL);
2445 LASSERT(thread->t_data == NULL);
2450 thread->t_data = tls;
2454 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2456 static struct cfs_cpt_table *ost_io_cptable;
2458 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2459 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2461 static struct ptlrpc_service_conf svc_conf;
2462 struct ost_obd *ost = &obd->u.ost;
2463 struct lprocfs_static_vars lvars;
2468 rc = cfs_cleanup_group_info();
2472 lprocfs_ost_init_vars(&lvars);
2473 lprocfs_obd_setup(obd, lvars.obd_vars);
2475 mutex_init(&ost->ost_health_mutex);
2477 svc_conf = (typeof(svc_conf)) {
2478 .psc_name = LUSTRE_OSS_NAME,
2479 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
2481 .bc_nbufs = OST_NBUFS,
2482 .bc_buf_size = OST_BUFSIZE,
2483 .bc_req_max_size = OST_MAXREQSIZE,
2484 .bc_rep_max_size = OST_MAXREPSIZE,
2485 .bc_req_portal = OST_REQUEST_PORTAL,
2486 .bc_rep_portal = OSC_REPLY_PORTAL,
2489 .tc_thr_name = "ll_ost",
2490 .tc_thr_factor = OSS_THR_FACTOR,
2491 .tc_nthrs_init = OSS_NTHRS_INIT,
2492 .tc_nthrs_base = OSS_NTHRS_BASE,
2493 .tc_nthrs_max = OSS_NTHRS_MAX,
2494 .tc_nthrs_user = oss_num_threads,
2495 .tc_cpu_affinity = 1,
2496 .tc_ctx_tags = LCT_DT_THREAD,
2499 .cc_pattern = oss_cpts,
2502 .so_req_handler = ost_handle,
2503 .so_req_printer = target_print_req,
2504 .so_hpreq_handler = ptlrpc_hpreq_handler,
2507 ost->ost_service = ptlrpc_register_service(&svc_conf,
2508 obd->obd_proc_entry);
2509 if (IS_ERR(ost->ost_service)) {
2510 rc = PTR_ERR(ost->ost_service);
2511 CERROR("failed to start service: %d\n", rc);
2512 GOTO(out_lprocfs, rc);
2515 memset(&svc_conf, 0, sizeof(svc_conf));
2516 svc_conf = (typeof(svc_conf)) {
2517 .psc_name = "ost_create",
2518 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
2520 .bc_nbufs = OST_NBUFS,
2521 .bc_buf_size = OST_BUFSIZE,
2522 .bc_req_max_size = OST_MAXREQSIZE,
2523 .bc_rep_max_size = OST_MAXREPSIZE,
2524 .bc_req_portal = OST_CREATE_PORTAL,
2525 .bc_rep_portal = OSC_REPLY_PORTAL,
2528 .tc_thr_name = "ll_ost_create",
2529 .tc_thr_factor = OSS_CR_THR_FACTOR,
2530 .tc_nthrs_init = OSS_CR_NTHRS_INIT,
2531 .tc_nthrs_base = OSS_CR_NTHRS_BASE,
2532 .tc_nthrs_max = OSS_CR_NTHRS_MAX,
2533 .tc_nthrs_user = oss_num_create_threads,
2534 .tc_cpu_affinity = 1,
2535 .tc_ctx_tags = LCT_DT_THREAD,
2538 .cc_pattern = oss_cpts,
2541 .so_req_handler = ost_handle,
2542 .so_req_printer = target_print_req,
2545 ost->ost_create_service = ptlrpc_register_service(&svc_conf,
2546 obd->obd_proc_entry);
2547 if (IS_ERR(ost->ost_create_service)) {
2548 rc = PTR_ERR(ost->ost_create_service);
2549 CERROR("failed to start OST create service: %d\n", rc);
2550 GOTO(out_service, rc);
2553 mask = cfs_cpt_table->ctb_nodemask;
2554 /* event CPT feature is disabled in libcfs level by set partition
2555 * number to 1, we still want to set node affinity for io service */
2556 if (cfs_cpt_number(cfs_cpt_table) == 1 && nodes_weight(*mask) > 1) {
2560 ost_io_cptable = cfs_cpt_table_alloc(nodes_weight(*mask));
2561 for_each_node_mask(i, *mask) {
2562 if (ost_io_cptable == NULL) {
2563 CWARN("OSS failed to create CPT table\n");
2567 rc = cfs_cpt_set_node(ost_io_cptable, cpt++, i);
2569 CWARN("OSS Failed to set node %d for"
2570 "IO CPT table\n", i);
2571 cfs_cpt_table_free(ost_io_cptable);
2572 ost_io_cptable = NULL;
2578 memset(&svc_conf, 0, sizeof(svc_conf));
2579 svc_conf = (typeof(svc_conf)) {
2580 .psc_name = "ost_io",
2581 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
2583 .bc_nbufs = OST_NBUFS,
2584 .bc_buf_size = OST_BUFSIZE,
2585 .bc_req_max_size = OST_MAXREQSIZE,
2586 .bc_rep_max_size = OST_MAXREPSIZE,
2587 .bc_req_portal = OST_IO_PORTAL,
2588 .bc_rep_portal = OSC_REPLY_PORTAL,
2591 .tc_thr_name = "ll_ost_io",
2592 .tc_thr_factor = OSS_THR_FACTOR,
2593 .tc_nthrs_init = OSS_NTHRS_INIT,
2594 .tc_nthrs_base = OSS_NTHRS_BASE,
2595 .tc_nthrs_max = OSS_NTHRS_MAX,
2596 .tc_nthrs_user = oss_num_threads,
2597 .tc_cpu_affinity = 1,
2598 .tc_ctx_tags = LCT_DT_THREAD,
2601 .cc_cptable = ost_io_cptable,
2602 .cc_pattern = ost_io_cptable == NULL ?
2606 .so_thr_init = ost_io_thread_init,
2607 .so_thr_done = ost_io_thread_done,
2608 .so_req_handler = ost_handle,
2609 .so_hpreq_handler = ost_io_hpreq_handler,
2610 .so_req_printer = target_print_req,
2613 ost->ost_io_service = ptlrpc_register_service(&svc_conf,
2614 obd->obd_proc_entry);
2615 if (IS_ERR(ost->ost_io_service)) {
2616 rc = PTR_ERR(ost->ost_io_service);
2617 CERROR("failed to start OST I/O service: %d\n", rc);
2618 ost->ost_io_service = NULL;
2619 GOTO(out_create, rc);
2622 memset(&svc_conf, 0, sizeof(svc_conf));
2623 svc_conf = (typeof(svc_conf)) {
2624 .psc_name = "ost_seq",
2625 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
2627 .bc_nbufs = OST_NBUFS,
2628 .bc_buf_size = OST_BUFSIZE,
2629 .bc_req_max_size = OST_MAXREQSIZE,
2630 .bc_rep_max_size = OST_MAXREPSIZE,
2631 .bc_req_portal = SEQ_DATA_PORTAL,
2632 .bc_rep_portal = OSC_REPLY_PORTAL,
2635 .tc_thr_name = "ll_ost_seq",
2636 .tc_thr_factor = OSS_CR_THR_FACTOR,
2637 .tc_nthrs_init = OSS_CR_NTHRS_INIT,
2638 .tc_nthrs_base = OSS_CR_NTHRS_BASE,
2639 .tc_nthrs_max = OSS_CR_NTHRS_MAX,
2640 .tc_nthrs_user = oss_num_create_threads,
2641 .tc_cpu_affinity = 1,
2642 .tc_ctx_tags = LCT_DT_THREAD,
2646 .cc_pattern = oss_cpts,
2649 .so_req_handler = ost_handle,
2650 .so_req_printer = target_print_req,
2651 .so_hpreq_handler = NULL,
2654 ost->ost_seq_service = ptlrpc_register_service(&svc_conf,
2655 obd->obd_proc_entry);
2656 if (IS_ERR(ost->ost_seq_service)) {
2657 rc = PTR_ERR(ost->ost_seq_service);
2658 CERROR("failed to start OST seq service: %d\n", rc);
2659 ost->ost_seq_service = NULL;
2663 ping_evictor_start();
2667 ptlrpc_unregister_service(ost->ost_io_service);
2668 ost->ost_io_service = NULL;
2670 ptlrpc_unregister_service(ost->ost_create_service);
2671 ost->ost_create_service = NULL;
2673 ptlrpc_unregister_service(ost->ost_service);
2674 ost->ost_service = NULL;
2676 lprocfs_obd_cleanup(obd);
2680 static int ost_cleanup(struct obd_device *obd)
2682 struct ost_obd *ost = &obd->u.ost;
2686 ping_evictor_stop();
2688 /* there is no recovery for OST OBD, all recovery is controlled by
2690 LASSERT(obd->obd_recovering == 0);
2691 mutex_lock(&ost->ost_health_mutex);
2692 ptlrpc_unregister_service(ost->ost_service);
2693 ptlrpc_unregister_service(ost->ost_create_service);
2694 ptlrpc_unregister_service(ost->ost_io_service);
2695 ptlrpc_unregister_service(ost->ost_seq_service);
2696 ost->ost_service = NULL;
2697 ost->ost_create_service = NULL;
2698 ost->ost_io_service = NULL;
2699 ost->ost_seq_service = NULL;
2701 mutex_unlock(&ost->ost_health_mutex);
2703 lprocfs_obd_cleanup(obd);
2705 if (ost_io_cptable != NULL) {
2706 cfs_cpt_table_free(ost_io_cptable);
2707 ost_io_cptable = NULL;
2713 static int ost_health_check(const struct lu_env *env, struct obd_device *obd)
2715 struct ost_obd *ost = &obd->u.ost;
2718 mutex_lock(&ost->ost_health_mutex);
2719 rc |= ptlrpc_service_health_check(ost->ost_service);
2720 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2721 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2722 mutex_unlock(&ost->ost_health_mutex);
2725 * health_check to return 0 on healthy
2726 * and 1 on unhealthy.
2734 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2736 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2739 /* use obd ops to offer management infrastructure */
2740 static struct obd_ops ost_obd_ops = {
2741 .o_owner = THIS_MODULE,
2742 .o_setup = ost_setup,
2743 .o_cleanup = ost_cleanup,
2744 .o_health_check = ost_health_check,
2748 static int __init ost_init(void)
2750 struct lprocfs_static_vars lvars;
2754 ost_page_to_corrupt = cfs_alloc_page(CFS_ALLOC_STD);
2756 lprocfs_ost_init_vars(&lvars);
2757 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2758 LUSTRE_OSS_NAME, NULL);
2760 if (ost_num_threads != 0 && oss_num_threads == 0) {
2761 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2762 "use oss_num_threads instead or unset both for "
2763 "dynamic thread startup\n");
2764 oss_num_threads = ost_num_threads;
2770 static void /*__exit*/ ost_exit(void)
2772 if (ost_page_to_corrupt)
2773 page_cache_release(ost_page_to_corrupt);
2775 class_unregister_type(LUSTRE_OSS_NAME);
2778 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2779 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2780 MODULE_LICENSE("GPL");
2782 module_init(ost_init);
2783 module_exit(ost_exit);