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 (unlikely(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 } else if (unlikely(oa == NULL || !(fid_seq_is_idif(oa->o_seq) ||
117 fid_seq_is_mdt(oa->o_seq) ||
118 fid_seq_is_echo(oa->o_seq)))) {
119 CERROR("%s: client %s sent bad object "DOSTID": rc = -EPROTO\n",
120 exp->exp_obd->obd_name, obd_export_nid2str(exp),
121 oa ? oa->o_id : -1, oa ? oa->o_seq : -1);
125 obdo_from_ostid(oa, &oa->o_oi);
127 unsigned max_brw = ioobj_max_brw_get(ioobj);
129 if (unlikely((max_brw & (max_brw - 1)) != 0)) {
130 CERROR("%s: client %s sent bad ioobj max %u for "DOSTID
131 ": rc = -EPROTO\n", exp->exp_obd->obd_name,
132 obd_export_nid2str(exp), max_brw,
136 ioobj_from_obdo(ioobj, oa);
141 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
143 struct oti_req_ack_lock *ack_lock;
149 if (req->rq_repmsg) {
150 __u64 versions[PTLRPC_NUM_VERSIONS] = { 0 };
151 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
152 versions[0] = oti->oti_pre_version;
153 lustre_msg_set_versions(req->rq_repmsg, versions);
155 req->rq_transno = oti->oti_transno;
157 /* XXX 4 == entries in oti_ack_locks??? */
158 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
161 /* XXX not even calling target_send_reply in some cases... */
162 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode, 0);
166 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
167 struct obd_trans_info *oti)
169 struct ost_body *body, *repbody;
170 struct lustre_capa *capa = NULL;
174 /* Get the request body */
175 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
179 if (body->oa.o_id == 0)
182 rc = ost_validate_obdo(exp, &body->oa, NULL);
186 /* If there's a DLM request, cancel the locks mentioned in it*/
187 if (req_capsule_field_present(&req->rq_pill, &RMF_DLM_REQ, RCL_CLIENT)) {
188 struct ldlm_request *dlm;
190 dlm = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
193 ldlm_request_cancel(req, dlm, 0);
196 /* If there's a capability, get it */
197 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
198 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
200 CERROR("Missing capability for OST DESTROY");
205 /* Prepare the reply */
206 rc = req_capsule_server_pack(&req->rq_pill);
210 /* Get the log cancellation cookie */
211 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
212 oti->oti_logcookies = &body->oa.o_lcookie;
214 /* Finish the reply */
215 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
216 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
218 /* Do the destroy and set the reply status accordingly */
219 req->rq_status = obd_destroy(req->rq_svc_thread->t_env, exp,
220 &repbody->oa, NULL, oti, NULL, capa);
225 * Helper function for getting server side [start, start+count] DLM lock
226 * if asked by client.
228 static int ost_lock_get(struct obd_export *exp, struct obdo *oa,
229 __u64 start, __u64 count, struct lustre_handle *lh,
230 int mode, __u64 flags)
232 struct ldlm_res_id res_id;
233 ldlm_policy_data_t policy;
234 __u64 end = start + count;
238 LASSERT(!lustre_handle_is_used(lh));
239 /* o_id and o_gr are used for localizing resource, if client miss to set
240 * them, do not trigger ASSERTION. */
241 if (unlikely((oa->o_valid & (OBD_MD_FLID | OBD_MD_FLGROUP)) !=
242 (OBD_MD_FLID | OBD_MD_FLGROUP)))
245 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
246 !(oa->o_flags & OBD_FL_SRVLOCK))
249 ostid_build_res_name(&oa->o_oi, &res_id);
250 CDEBUG(D_INODE, "OST-side extent lock.\n");
252 policy.l_extent.start = start & CFS_PAGE_MASK;
254 /* If ->o_blocks is EOF it means "lock till the end of the
255 * file". Otherwise, it's size of a hole being punched (in bytes) */
256 if (count == OBD_OBJECT_EOF || end < start)
257 policy.l_extent.end = OBD_OBJECT_EOF;
259 policy.l_extent.end = end | ~CFS_PAGE_MASK;
261 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
262 LDLM_EXTENT, &policy, mode, &flags,
263 ldlm_blocking_ast, ldlm_completion_ast,
264 ldlm_glimpse_ast, NULL, 0, LVB_T_NONE,
268 /* Helper function: release lock, if any. */
269 static void ost_lock_put(struct obd_export *exp,
270 struct lustre_handle *lh, int mode)
273 if (lustre_handle_is_used(lh))
274 ldlm_lock_decref(lh, mode);
278 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
280 struct ost_body *body, *repbody;
281 struct obd_info *oinfo;
282 struct lustre_handle lh = { 0 };
283 struct lustre_capa *capa = NULL;
287 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
291 rc = ost_validate_obdo(exp, &body->oa, NULL);
295 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
296 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
298 CERROR("Missing capability for OST GETATTR");
303 rc = req_capsule_server_pack(&req->rq_pill);
307 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
308 repbody->oa = body->oa;
310 rc = ost_lock_get(exp, &repbody->oa, 0, OBD_OBJECT_EOF, &lh, LCK_PR, 0);
314 OBD_ALLOC_PTR(oinfo);
316 GOTO(unlock, rc = -ENOMEM);
317 oinfo->oi_oa = &repbody->oa;
318 oinfo->oi_capa = capa;
320 req->rq_status = obd_getattr(req->rq_svc_thread->t_env, exp, oinfo);
324 ost_drop_id(exp, &repbody->oa);
327 ost_lock_put(exp, &lh, LCK_PR);
331 static int ost_statfs(struct ptlrpc_request *req)
333 struct obd_statfs *osfs;
337 rc = req_capsule_server_pack(&req->rq_pill);
341 osfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
343 req->rq_status = obd_statfs(req->rq_svc_thread->t_env, req->rq_export,
345 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
347 if (req->rq_status != 0)
348 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
350 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_EINPROGRESS))
351 req->rq_status = -EINPROGRESS;
356 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
357 struct obd_trans_info *oti)
359 struct ost_body *body, *repbody;
363 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
367 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
371 rc = req_capsule_server_pack(&req->rq_pill);
375 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
376 repbody->oa = body->oa;
377 oti->oti_logcookies = &body->oa.o_lcookie;
379 req->rq_status = obd_create(req->rq_svc_thread->t_env, exp,
380 &repbody->oa, NULL, oti);
381 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
385 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
386 struct obd_trans_info *oti)
388 struct ost_body *body, *repbody;
390 struct lustre_handle lh = {0,};
394 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
395 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
397 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
401 rc = ost_validate_obdo(exp, &body->oa, NULL);
405 if ((body->oa.o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
406 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
409 rc = req_capsule_server_pack(&req->rq_pill);
413 /* standard truncate optimization: if file body is completely
414 * destroyed, don't send data back to the server. */
415 if (body->oa.o_size == 0)
416 flags |= LDLM_AST_DISCARD_DATA;
418 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
419 repbody->oa = body->oa;
421 rc = ost_lock_get(exp, &repbody->oa, repbody->oa.o_size,
422 repbody->oa.o_blocks, &lh, LCK_PW, flags);
424 struct obd_info *oinfo;
425 struct lustre_capa *capa = NULL;
427 if (repbody->oa.o_valid & OBD_MD_FLFLAGS &&
428 repbody->oa.o_flags == OBD_FL_SRVLOCK)
430 * If OBD_FL_SRVLOCK is the only bit set in
431 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
432 * through filter_setattr() to filter_iocontrol().
434 repbody->oa.o_valid &= ~OBD_MD_FLFLAGS;
436 if (repbody->oa.o_valid & OBD_MD_FLOSSCAPA) {
437 capa = req_capsule_client_get(&req->rq_pill,
440 CERROR("Missing capability for OST PUNCH");
441 GOTO(unlock, rc = -EFAULT);
445 OBD_ALLOC_PTR(oinfo);
447 GOTO(unlock, rc = -ENOMEM);
448 oinfo->oi_oa = &repbody->oa;
449 oinfo->oi_policy.l_extent.start = oinfo->oi_oa->o_size;
450 oinfo->oi_policy.l_extent.end = oinfo->oi_oa->o_blocks;
451 oinfo->oi_capa = capa;
452 oinfo->oi_flags = OBD_FL_PUNCH;
454 req->rq_status = obd_punch(req->rq_svc_thread->t_env, exp,
458 ost_lock_put(exp, &lh, LCK_PW);
461 ost_drop_id(exp, &repbody->oa);
465 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req,
466 struct obd_trans_info *oti)
468 struct ost_body *body, *repbody;
469 struct obd_info *oinfo;
470 struct lustre_capa *capa = NULL;
474 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
478 rc = ost_validate_obdo(exp, &body->oa, NULL);
482 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
483 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
485 CERROR("Missing capability for OST SYNC");
490 rc = req_capsule_server_pack(&req->rq_pill);
494 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
495 repbody->oa = body->oa;
497 OBD_ALLOC_PTR(oinfo);
501 oinfo->oi_oa = &repbody->oa;
502 oinfo->oi_capa = capa;
503 oinfo->oi_jobid = oti->oti_jobid;
504 req->rq_status = obd_sync(req->rq_svc_thread->t_env, exp, oinfo,
505 repbody->oa.o_size, repbody->oa.o_blocks,
509 ost_drop_id(exp, &repbody->oa);
513 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
514 struct obd_trans_info *oti)
516 struct ost_body *body, *repbody;
517 struct obd_info *oinfo;
518 struct lustre_capa *capa = NULL;
522 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
526 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
530 rc = req_capsule_server_pack(&req->rq_pill);
534 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
535 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
537 CERROR("Missing capability for OST SETATTR");
542 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
543 repbody->oa = body->oa;
545 OBD_ALLOC_PTR(oinfo);
548 oinfo->oi_oa = &repbody->oa;
549 oinfo->oi_capa = capa;
551 req->rq_status = obd_setattr(req->rq_svc_thread->t_env, exp, oinfo,
556 ost_drop_id(exp, &repbody->oa);
560 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
561 cksum_type_t cksum_type)
563 struct cfs_crypto_hash_desc *hdesc;
564 unsigned int bufsize;
566 unsigned char cfs_alg = cksum_obd2cfs(cksum_type);
569 hdesc = cfs_crypto_hash_init(cfs_alg, NULL, 0);
571 CERROR("Unable to initialize checksum hash %s\n",
572 cfs_crypto_hash_name(cfs_alg));
573 return PTR_ERR(hdesc);
575 CDEBUG(D_INFO, "Checksum for algo %s\n", cfs_crypto_hash_name(cfs_alg));
576 for (i = 0; i < desc->bd_iov_count; i++) {
578 /* corrupt the data before we compute the checksum, to
579 * simulate a client->OST data error */
580 if (i == 0 && opc == OST_WRITE &&
581 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE)) {
582 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
583 int len = desc->bd_iov[i].kiov_len;
584 struct page *np = ost_page_to_corrupt;
585 char *ptr = kmap(desc->bd_iov[i].kiov_page) + off;
588 char *ptr2 = kmap(np) + off;
590 memcpy(ptr2, ptr, len);
591 memcpy(ptr2, "bad3", min(4, len));
593 desc->bd_iov[i].kiov_page = np;
595 CERROR("can't alloc page for corruption\n");
598 cfs_crypto_hash_update_page(hdesc, desc->bd_iov[i].kiov_page,
599 desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK,
600 desc->bd_iov[i].kiov_len);
602 /* corrupt the data after we compute the checksum, to
603 * simulate an OST->client data error */
604 if (i == 0 && opc == OST_READ &&
605 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
606 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
607 int len = desc->bd_iov[i].kiov_len;
608 struct page *np = ost_page_to_corrupt;
609 char *ptr = kmap(desc->bd_iov[i].kiov_page) + off;
612 char *ptr2 = kmap(np) + off;
614 memcpy(ptr2, ptr, len);
615 memcpy(ptr2, "bad4", min(4, len));
617 desc->bd_iov[i].kiov_page = np;
619 CERROR("can't alloc page for corruption\n");
625 err = cfs_crypto_hash_final(hdesc, (unsigned char *)&cksum, &bufsize);
627 cfs_crypto_hash_final(hdesc, NULL, NULL);
632 static int ost_brw_lock_get(int mode, struct obd_export *exp,
633 struct obd_ioobj *obj, struct niobuf_remote *nb,
634 struct lustre_handle *lh)
637 int nrbufs = obj->ioo_bufcnt;
638 struct ldlm_res_id res_id;
639 ldlm_policy_data_t policy;
643 ostid_build_res_name(&obj->ioo_oid, &res_id);
644 LASSERT(mode == LCK_PR || mode == LCK_PW);
645 LASSERT(!lustre_handle_is_used(lh));
647 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
650 for (i = 1; i < nrbufs; i ++)
651 if ((nb[0].flags & OBD_BRW_SRVLOCK) !=
652 (nb[i].flags & OBD_BRW_SRVLOCK))
655 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
656 policy.l_extent.end = (nb[nrbufs - 1].offset +
657 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
659 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
660 LDLM_EXTENT, &policy, mode, &flags,
661 ldlm_blocking_ast, ldlm_completion_ast,
662 ldlm_glimpse_ast, NULL, 0, LVB_T_NONE,
666 static void ost_brw_lock_put(int mode,
667 struct obd_ioobj *obj, struct niobuf_remote *niob,
668 struct lustre_handle *lh)
671 LASSERT(mode == LCK_PR || mode == LCK_PW);
672 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
673 lustre_handle_is_used(lh));
674 if (lustre_handle_is_used(lh))
675 ldlm_lock_decref(lh, mode);
679 /* Allocate thread local buffers if needed */
680 static struct ost_thread_local_cache *ost_tls_get(struct ptlrpc_request *r)
682 struct ost_thread_local_cache *tls =
683 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
685 /* In normal mode of operation an I/O request is serviced only
686 * by ll_ost_io threads each of them has own tls buffers allocated by
687 * ost_io_thread_init().
688 * During recovery, an I/O request may be queued until any of the ost
689 * service threads process it. Not necessary it should be one of
690 * ll_ost_io threads. In that case we dynamically allocating tls
691 * buffers for the request service time. */
692 if (unlikely(tls == NULL)) {
693 LASSERT(r->rq_export->exp_in_recovery);
697 r->rq_svc_thread->t_data = tls;
703 /* Free thread local buffers if they were allocated only for servicing
704 * this one request */
705 static void ost_tls_put(struct ptlrpc_request *r)
707 struct ost_thread_local_cache *tls =
708 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
710 if (unlikely(tls->temporary)) {
712 r->rq_svc_thread->t_data = NULL;
716 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
718 struct ptlrpc_bulk_desc *desc = NULL;
719 struct obd_export *exp = req->rq_export;
720 struct niobuf_remote *remote_nb;
721 struct niobuf_local *local_nb;
722 struct obd_ioobj *ioo;
723 struct ost_body *body, *repbody;
724 struct lustre_capa *capa = NULL;
725 struct l_wait_info lwi;
726 struct lustre_handle lockh = { 0 };
727 int niocount, npages, nob = 0, rc, i;
729 struct ost_thread_local_cache *tls;
732 req->rq_bulk_read = 1;
734 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
735 GOTO(out, rc = -EIO);
737 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
739 /* Check if there is eviction in progress, and if so, wait for it to
741 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
742 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
743 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
744 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
748 GOTO(out, rc = -ENOTCONN);
750 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
751 * ost_rw_hpreq_check(). */
752 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
754 GOTO(out, rc = -EFAULT);
757 * A req_capsule_X_get_array(pill, field, ptr_to_element_count) function
758 * would be useful here and wherever we get &RMF_OBD_IOOBJ and
759 * &RMF_NIOBUF_REMOTE.
761 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
763 GOTO(out, rc = -EFAULT);
765 rc = ost_validate_obdo(exp, &body->oa, ioo);
769 niocount = ioo->ioo_bufcnt;
770 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
771 if (remote_nb == NULL)
772 GOTO(out, rc = -EFAULT);
774 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
775 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
777 CERROR("Missing capability for OST BRW READ");
778 GOTO(out, rc = -EFAULT);
782 rc = req_capsule_server_pack(&req->rq_pill);
786 tls = ost_tls_get(req);
788 GOTO(out_bulk, rc = -ENOMEM);
789 local_nb = tls->local;
791 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
796 * If getting the lock took more time than
797 * client was willing to wait, drop it. b=11330
799 if (cfs_time_current_sec() > req->rq_deadline ||
800 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
802 CERROR("Dropping timed-out read from %s because locking"
803 "object "LPX64" took %ld seconds (limit was %ld).\n",
804 libcfs_id2str(req->rq_peer), ioo->ioo_id,
805 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
806 req->rq_deadline - req->rq_arrival_time.tv_sec);
807 GOTO(out_lock, rc = -ETIMEDOUT);
810 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
811 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
813 npages = OST_THREAD_POOL_SIZE;
814 rc = obd_preprw(req->rq_svc_thread->t_env, OBD_BRW_READ, exp,
815 &repbody->oa, 1, ioo, remote_nb, &npages, local_nb,
820 desc = ptlrpc_prep_bulk_exp(req, npages, ioobj_max_brw_get(ioo),
821 BULK_PUT_SOURCE, OST_BULK_PORTAL);
823 GOTO(out_commitrw, rc = -ENOMEM);
826 for (i = 0; i < npages; i++) {
827 int page_rc = local_nb[i].rc;
829 if (page_rc < 0) { /* error */
835 if (page_rc != 0) { /* some data! */
836 LASSERT (local_nb[i].page != NULL);
837 ptlrpc_prep_bulk_page_nopin(desc, local_nb[i].page,
838 local_nb[i].lnb_page_offset,
842 if (page_rc != local_nb[i].len) { /* short read */
843 /* All subsequent pages should be 0 */
845 LASSERT(local_nb[i].rc == 0);
850 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
851 cksum_type_t cksum_type =
852 cksum_type_unpack(repbody->oa.o_valid & OBD_MD_FLFLAGS ?
853 repbody->oa.o_flags : 0);
854 repbody->oa.o_flags = cksum_type_pack(cksum_type);
855 repbody->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
856 repbody->oa.o_cksum = ost_checksum_bulk(desc, OST_READ,cksum_type);
857 CDEBUG(D_PAGE, "checksum at read origin: %x\n",
858 repbody->oa.o_cksum);
860 repbody->oa.o_valid = 0;
862 /* We're finishing using body->oa as an input variable */
864 /* Check if client was evicted while we were doing i/o before touching
867 if (likely(!CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2)))
868 rc = target_bulk_io(exp, desc, &lwi);
873 /* Must commit after prep above in all cases */
874 rc = obd_commitrw(req->rq_svc_thread->t_env, OBD_BRW_READ, exp,
875 &repbody->oa, 1, ioo, remote_nb, npages, local_nb,
879 ost_drop_id(exp, &repbody->oa);
882 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
886 if (desc && !CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2))
887 ptlrpc_free_bulk_nopin(desc);
891 req->rq_status = nob;
892 ptlrpc_lprocfs_brw(req, nob);
893 target_committed_to_req(req);
895 } else if (!no_reply) {
896 /* Only reply if there was no comms problem with bulk */
897 target_committed_to_req(req);
901 /* reply out callback would free */
902 ptlrpc_req_drop_rs(req);
903 LCONSOLE_WARN("%s: Bulk IO read error with %s (at %s), "
904 "client will retry: rc %d\n",
905 exp->exp_obd->obd_name,
906 obd_uuid2str(&exp->exp_client_uuid),
907 obd_export_nid2str(exp), rc);
909 /* send a bulk after reply to simulate a network delay or reordering
911 if (unlikely(CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2))) {
913 struct l_wait_info lwi1;
915 CDEBUG(D_INFO, "reorder BULK\n");
916 cfs_waitq_init(&waitq);
918 lwi1 = LWI_TIMEOUT_INTR(cfs_time_seconds(3), NULL, NULL, NULL);
919 l_wait_event(waitq, 0, &lwi1);
920 rc = target_bulk_io(exp, desc, &lwi);
921 ptlrpc_free_bulk_nopin(desc);
927 static void ost_warn_on_cksum(struct ptlrpc_request *req,
928 struct ptlrpc_bulk_desc *desc,
929 struct niobuf_local *local_nb, int npages,
930 obd_count client_cksum, obd_count server_cksum,
933 struct obd_export *exp = req->rq_export;
934 struct ost_body *body;
938 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
939 LASSERT (body != NULL);
941 if (req->rq_peer.nid == desc->bd_sender) {
945 router = libcfs_nid2str(desc->bd_sender);
949 CDEBUG_LIMIT(D_INFO, "client csum %x, server csum %x\n",
950 client_cksum, server_cksum);
954 LCONSOLE_ERROR_MSG(0x168, "BAD WRITE CHECKSUM: %s from %s%s%s inode "
955 DFID" object "LPU64"/"LPU64" extent ["LPU64"-"LPU64
956 "]: client csum %x, server csum %x\n",
957 exp->exp_obd->obd_name, libcfs_id2str(req->rq_peer),
959 body->oa.o_valid & OBD_MD_FLFID ?
960 body->oa.o_parent_seq : (__u64)0,
961 body->oa.o_valid & OBD_MD_FLFID ?
962 body->oa.o_parent_oid : 0,
963 body->oa.o_valid & OBD_MD_FLFID ?
964 body->oa.o_parent_ver : 0,
966 body->oa.o_valid & OBD_MD_FLGROUP ?
967 body->oa.o_seq : (__u64)0,
968 local_nb[0].lnb_file_offset,
969 local_nb[npages-1].lnb_file_offset +
970 local_nb[npages-1].len - 1,
971 client_cksum, server_cksum);
974 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
976 struct ptlrpc_bulk_desc *desc = NULL;
977 struct obd_export *exp = req->rq_export;
978 struct niobuf_remote *remote_nb;
979 struct niobuf_local *local_nb;
980 struct obd_ioobj *ioo;
981 struct ost_body *body, *repbody;
982 struct l_wait_info lwi;
983 struct lustre_handle lockh = {0};
984 struct lustre_capa *capa = NULL;
986 int objcount, niocount, npages;
988 obd_count client_cksum = 0, server_cksum = 0;
989 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
990 int no_reply = 0, mmap = 0;
991 __u32 o_uid = 0, o_gid = 0;
992 struct ost_thread_local_cache *tls;
995 req->rq_bulk_write = 1;
997 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
998 GOTO(out, rc = -EIO);
999 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
1000 GOTO(out, rc = -EFAULT);
1002 /* pause before transaction has been started */
1003 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
1005 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
1006 * ost_rw_hpreq_check(). */
1007 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1009 GOTO(out, rc = -EFAULT);
1011 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1012 RCL_CLIENT) / sizeof(*ioo);
1013 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1015 GOTO(out, rc = -EFAULT);
1017 rc = ost_validate_obdo(exp, &body->oa, ioo);
1021 for (niocount = i = 0; i < objcount; i++)
1022 niocount += ioo[i].ioo_bufcnt;
1025 * It'd be nice to have a capsule function to indicate how many elements
1026 * there were in a buffer for an RMF that's declared to be an array.
1027 * It's easy enough to compute the number of elements here though.
1029 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1030 if (remote_nb == NULL || niocount != (req_capsule_get_size(&req->rq_pill,
1031 &RMF_NIOBUF_REMOTE, RCL_CLIENT) / sizeof(*remote_nb)))
1032 GOTO(out, rc = -EFAULT);
1034 if ((remote_nb[0].flags & OBD_BRW_MEMALLOC) &&
1035 (exp->exp_connection->c_peer.nid == exp->exp_connection->c_self))
1036 cfs_memory_pressure_set();
1038 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
1039 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
1041 CERROR("Missing capability for OST BRW WRITE");
1042 GOTO(out, rc = -EFAULT);
1046 req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER,
1047 niocount * sizeof(*rcs));
1048 rc = req_capsule_server_pack(&req->rq_pill);
1051 CFS_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, cfs_fail_val);
1052 rcs = req_capsule_server_get(&req->rq_pill, &RMF_RCS);
1054 tls = ost_tls_get(req);
1056 GOTO(out_bulk, rc = -ENOMEM);
1057 local_nb = tls->local;
1059 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
1064 * If getting the lock took more time than
1065 * client was willing to wait, drop it. b=11330
1067 if (cfs_time_current_sec() > req->rq_deadline ||
1068 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
1070 CERROR("Dropping timed-out write from %s because locking "
1071 "object "LPX64" took %ld seconds (limit was %ld).\n",
1072 libcfs_id2str(req->rq_peer), ioo->ioo_id,
1073 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
1074 req->rq_deadline - req->rq_arrival_time.tv_sec);
1075 GOTO(out_lock, rc = -ETIMEDOUT);
1078 /* obd_preprw clobbers oa->valid, so save what we need */
1079 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
1080 client_cksum = body->oa.o_cksum;
1081 if (body->oa.o_valid & OBD_MD_FLFLAGS)
1082 cksum_type = cksum_type_unpack(body->oa.o_flags);
1084 if (body->oa.o_valid & OBD_MD_FLFLAGS && body->oa.o_flags & OBD_FL_MMAP)
1087 /* Because we already sync grant info with client when reconnect,
1088 * grant info will be cleared for resent req, then fed_grant and
1089 * total_grant will not be modified in following preprw_write */
1090 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1091 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1092 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1095 if (exp_connect_rmtclient(exp)) {
1096 o_uid = body->oa.o_uid;
1097 o_gid = body->oa.o_gid;
1100 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
1101 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1103 npages = OST_THREAD_POOL_SIZE;
1104 rc = obd_preprw(req->rq_svc_thread->t_env, OBD_BRW_WRITE, exp,
1105 &repbody->oa, objcount, ioo, remote_nb, &npages,
1106 local_nb, oti, capa);
1110 desc = ptlrpc_prep_bulk_exp(req, npages, ioobj_max_brw_get(ioo),
1111 BULK_GET_SINK, OST_BULK_PORTAL);
1113 GOTO(skip_transfer, rc = -ENOMEM);
1115 /* NB Having prepped, we must commit... */
1116 for (i = 0; i < npages; i++)
1117 ptlrpc_prep_bulk_page_nopin(desc, local_nb[i].page,
1118 local_nb[i].lnb_page_offset,
1121 rc = sptlrpc_svc_prep_bulk(req, desc);
1125 rc = target_bulk_io(exp, desc, &lwi);
1129 if (client_cksum != 0 && rc == 0) {
1130 static int cksum_counter;
1131 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1132 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1133 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1134 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1135 repbody->oa.o_cksum = server_cksum;
1137 if (unlikely(client_cksum != server_cksum)) {
1138 ost_warn_on_cksum(req, desc, local_nb, npages,
1139 client_cksum, server_cksum, mmap);
1142 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1143 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1144 cksum_counter, libcfs_id2str(req->rq_peer),
1149 /* Must commit after prep above in all cases */
1150 rc = obd_commitrw(req->rq_svc_thread->t_env, OBD_BRW_WRITE, exp,
1151 &repbody->oa, objcount, ioo, remote_nb, npages,
1153 if (rc == -ENOTCONN)
1154 /* quota acquire process has been given up because
1155 * either the client has been evicted or the client
1156 * has timed out the request already */
1159 if (exp_connect_rmtclient(exp)) {
1160 repbody->oa.o_uid = o_uid;
1161 repbody->oa.o_gid = o_gid;
1165 * Disable sending mtime back to the client. If the client locked the
1166 * whole object, then it has already updated the mtime on its side,
1167 * otherwise it will have to glimpse anyway (see bug 21489, comment 32)
1169 repbody->oa.o_valid &= ~(OBD_MD_FLMTIME | OBD_MD_FLATIME);
1174 /* set per-requested niobuf return codes */
1175 for (i = j = 0; i < niocount; i++) {
1176 int len = remote_nb[i].len;
1181 LASSERT(j < npages);
1182 if (local_nb[j].rc < 0)
1183 rcs[i] = local_nb[j].rc;
1184 len -= local_nb[j].len;
1189 LASSERT(j == npages);
1190 ptlrpc_lprocfs_brw(req, nob);
1194 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1199 ptlrpc_free_bulk_nopin(desc);
1202 oti_to_request(oti, req);
1203 target_committed_to_req(req);
1204 rc = ptlrpc_reply(req);
1205 } else if (!no_reply) {
1206 /* Only reply if there was no comms problem with bulk */
1207 target_committed_to_req(req);
1208 req->rq_status = rc;
1211 /* reply out callback would free */
1212 ptlrpc_req_drop_rs(req);
1213 LCONSOLE_WARN("%s: Bulk IO write error with %s (at %s), "
1214 "client will retry: rc %d\n",
1215 exp->exp_obd->obd_name,
1216 obd_uuid2str(&exp->exp_client_uuid),
1217 obd_export_nid2str(exp), rc);
1219 cfs_memory_pressure_clr();
1224 * Implementation of OST_SET_INFO.
1226 * OST_SET_INFO is like ioctl(): heavily overloaded. Specifically, it takes a
1227 * "key" and a value RPC buffers as arguments, with the value's contents
1228 * interpreted according to the key.
1230 * Value types that need swabbing have swabbing done explicitly, either here or
1231 * in functions called from here. This should be corrected: all swabbing should
1232 * be done in the capsule abstraction, as that will then allow us to move
1233 * swabbing exclusively to the client without having to modify server code
1234 * outside the capsule abstraction's implementation itself. To correct this
1235 * will require minor changes to the capsule abstraction; see the comments for
1236 * req_capsule_extend() in layout.c.
1238 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1240 struct ost_body *body = NULL, *repbody;
1241 char *key, *val = NULL;
1242 int keylen, vallen, rc = 0;
1243 int is_grant_shrink = 0;
1246 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1248 DEBUG_REQ(D_HA, req, "no set_info key");
1251 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1254 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1257 if ((is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK)))
1258 /* In this case the value is actually an RMF_OST_BODY, so we
1259 * transmutate the type of this PTLRPC */
1260 req_capsule_extend(&req->rq_pill, &RQF_OST_SET_GRANT_INFO);
1262 rc = req_capsule_server_pack(&req->rq_pill);
1267 if (is_grant_shrink) {
1268 body = req_capsule_client_get(&req->rq_pill,
1273 repbody = req_capsule_server_get(&req->rq_pill,
1275 memcpy(repbody, body, sizeof(*body));
1276 val = (char*)repbody;
1278 val = req_capsule_client_get(&req->rq_pill,
1283 if (KEY_IS(KEY_EVICT_BY_NID)) {
1285 obd_export_evict_by_nid(exp->exp_obd, val);
1287 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1288 if (vallen < sizeof(__u32))
1290 __swab32s((__u32 *)val);
1293 /* OBD will also check if KEY_IS(KEY_GRANT_SHRINK), and will cast val to
1294 * a struct ost_body * value */
1295 rc = obd_set_info_async(req->rq_svc_thread->t_env, exp, keylen,
1296 key, vallen, val, NULL);
1298 lustre_msg_set_status(req->rq_repmsg, 0);
1302 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1305 int keylen, replylen, rc = 0;
1306 struct req_capsule *pill = &req->rq_pill;
1309 /* this common part for get_info rpc */
1310 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1312 DEBUG_REQ(D_HA, req, "no get_info key");
1315 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1317 if (KEY_IS(KEY_FIEMAP)) {
1318 struct ll_fiemap_info_key *fm_key = key;
1321 rc = ost_validate_obdo(exp, &fm_key->oa, NULL);
1326 rc = obd_get_info(req->rq_svc_thread->t_env, exp, keylen, key,
1327 &replylen, NULL, NULL);
1331 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1332 RCL_SERVER, replylen);
1334 rc = req_capsule_server_pack(pill);
1338 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1342 if (KEY_IS(KEY_LAST_FID)) {
1346 req_capsule_extend(pill, &RQF_OST_GET_INFO_LAST_FID);
1347 val = req_capsule_client_get(pill, &RMF_SETINFO_VAL);
1348 vallen = req_capsule_get_size(pill, &RMF_SETINFO_VAL,
1350 if (val != NULL && vallen > 0 && replylen >= vallen) {
1351 memcpy(reply, val, vallen);
1353 CERROR("%s: invalid req val %p vallen %d replylen %d\n",
1354 exp->exp_obd->obd_name, val, vallen, replylen);
1355 GOTO(out, rc = -EINVAL);
1359 /* call again to fill in the reply buffer */
1360 rc = obd_get_info(req->rq_svc_thread->t_env, exp, keylen, key,
1361 &replylen, reply, NULL);
1363 lustre_msg_set_status(req->rq_repmsg, 0);
1367 static int ost_handle_quotactl(struct ptlrpc_request *req)
1369 struct obd_quotactl *oqctl, *repoqc;
1373 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1375 GOTO(out, rc = -EPROTO);
1377 rc = req_capsule_server_pack(&req->rq_pill);
1381 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1382 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1389 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1391 struct obd_quotactl *oqctl;
1395 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1399 rc = req_capsule_server_pack(&req->rq_pill);
1403 /* deprecated, not used any more */
1404 req->rq_status = -EOPNOTSUPP;
1405 RETURN(-EOPNOTSUPP);
1408 static int ost_llog_handle_connect(struct obd_export *exp,
1409 struct ptlrpc_request *req)
1411 struct llogd_conn_body *body;
1415 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
1416 rc = obd_llog_connect(exp, body);
1420 #define ost_init_sec_none(reply, exp) \
1422 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1423 OBD_CONNECT_RMT_CLIENT_FORCE | \
1424 OBD_CONNECT_OSS_CAPA); \
1425 spin_lock(&exp->exp_lock); \
1426 *exp_connect_flags_ptr(exp) = reply->ocd_connect_flags; \
1427 spin_unlock(&exp->exp_lock); \
1430 static int ost_init_sec_level(struct ptlrpc_request *req)
1432 struct obd_export *exp = req->rq_export;
1433 struct req_capsule *pill = &req->rq_pill;
1434 struct obd_device *obd = exp->exp_obd;
1435 struct filter_obd *filter = &obd->u.filter;
1436 char *client = libcfs_nid2str(req->rq_peer.nid);
1437 struct obd_connect_data *data, *reply;
1441 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1442 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1443 if (data == NULL || reply == NULL)
1446 /* connection from MDT is always trusted */
1447 if (req->rq_auth_usr_mdt) {
1448 ost_init_sec_none(reply, exp);
1452 /* no GSS support case */
1453 if (!req->rq_auth_gss) {
1454 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1455 CWARN("client %s -> target %s does not user GSS, "
1456 "can not run under security level %d.\n",
1457 client, obd->obd_name, filter->fo_sec_level);
1460 ost_init_sec_none(reply, exp);
1465 /* old version case */
1466 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1467 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1468 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1469 CWARN("client %s -> target %s uses old version, "
1470 "can not run under security level %d.\n",
1471 client, obd->obd_name, filter->fo_sec_level);
1474 CWARN("client %s -> target %s uses old version, "
1475 "run under security level %d.\n",
1476 client, obd->obd_name, filter->fo_sec_level);
1477 ost_init_sec_none(reply, exp);
1482 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1484 if (!req->rq_auth_remote)
1485 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1486 "asked to be remote.\n", client, obd->obd_name);
1487 } else if (req->rq_auth_remote) {
1489 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1490 "as remote by default.\n", client, obd->obd_name);
1494 if (!filter->fo_fl_oss_capa) {
1495 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1496 " but OSS capabilities are not enabled: %d.\n",
1497 client, obd->obd_name, filter->fo_fl_oss_capa);
1502 switch (filter->fo_sec_level) {
1503 case LUSTRE_SEC_NONE:
1505 ost_init_sec_none(reply, exp);
1508 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1509 "can not run under security level %d.\n",
1510 client, obd->obd_name, filter->fo_sec_level);
1513 case LUSTRE_SEC_REMOTE:
1515 ost_init_sec_none(reply, exp);
1517 case LUSTRE_SEC_ALL:
1519 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1520 OBD_CONNECT_RMT_CLIENT_FORCE);
1521 if (!filter->fo_fl_oss_capa)
1522 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1524 spin_lock(&exp->exp_lock);
1525 *exp_connect_flags_ptr(exp) = reply->ocd_connect_flags;
1526 spin_unlock(&exp->exp_lock);
1538 * this should be done in filter_connect()/filter_reconnect(), but
1539 * we can't obtain information like NID, which stored in incoming
1540 * request, thus can't decide what flavor to use. so we do it here.
1542 * This hack should be removed after the OST stack be rewritten, just
1543 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1545 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1547 struct obd_export *exp = req->rq_export;
1548 struct filter_obd *filter = &exp->exp_obd->u.filter;
1549 struct sptlrpc_flavor flvr;
1552 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1553 LUSTRE_ECHO_NAME) == 0)) {
1554 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1558 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1559 read_lock(&filter->fo_sptlrpc_lock);
1560 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1564 read_unlock(&filter->fo_sptlrpc_lock);
1566 spin_lock(&exp->exp_lock);
1568 exp->exp_sp_peer = req->rq_sp_from;
1569 exp->exp_flvr = flvr;
1571 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1572 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1573 CERROR("unauthorized rpc flavor %x from %s, "
1574 "expect %x\n", req->rq_flvr.sf_rpc,
1575 libcfs_nid2str(req->rq_peer.nid),
1576 exp->exp_flvr.sf_rpc);
1580 spin_unlock(&exp->exp_lock);
1582 if (exp->exp_sp_peer != req->rq_sp_from) {
1583 CERROR("RPC source %s doesn't match %s\n",
1584 sptlrpc_part2name(req->rq_sp_from),
1585 sptlrpc_part2name(exp->exp_sp_peer));
1588 rc = sptlrpc_target_export_check(exp, req);
1595 /* Ensure that data and metadata are synced to the disk when lock is cancelled
1597 int ost_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
1598 void *data, int flag)
1601 __u32 sync_lock_cancel = 0;
1602 __u32 len = sizeof(sync_lock_cancel);
1607 rc = lu_env_init(&env, LCT_DT_THREAD);
1608 if (unlikely(rc != 0))
1611 rc = obd_get_info(&env, lock->l_export, sizeof(KEY_SYNC_LOCK_CANCEL),
1612 KEY_SYNC_LOCK_CANCEL, &len, &sync_lock_cancel, NULL);
1613 if (rc == 0 && flag == LDLM_CB_CANCELING &&
1614 (lock->l_granted_mode & (LCK_PW|LCK_GROUP)) &&
1615 (sync_lock_cancel == ALWAYS_SYNC_ON_CANCEL ||
1616 (sync_lock_cancel == BLOCKING_SYNC_ON_CANCEL &&
1617 lock->l_flags & LDLM_FL_CBPENDING))) {
1618 struct obd_info *oinfo;
1622 OBD_ALLOC_PTR(oinfo);
1624 GOTO(out_env, rc = -ENOMEM);
1627 OBD_FREE_PTR(oinfo);
1628 GOTO(out_env, rc = -ENOMEM);
1631 ostid_res_name_to_id(&oa->o_oi, &lock->l_resource->lr_name);
1632 oa->o_valid = OBD_MD_FLID|OBD_MD_FLGROUP;
1634 oinfo->oi_capa = BYPASS_CAPA;
1636 rc = obd_sync(&env, lock->l_export, oinfo,
1637 lock->l_policy_data.l_extent.start,
1638 lock->l_policy_data.l_extent.end, NULL);
1640 CERROR("Error %d syncing data on lock cancel\n", rc);
1643 OBD_FREE_PTR(oinfo);
1646 rc = ldlm_server_blocking_ast(lock, desc, data, flag);
1652 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1653 struct obd_device *obd, int *process)
1655 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1656 case OST_CONNECT: /* This will never get here, but for completeness. */
1657 case OST_DISCONNECT:
1668 case OBD_LOG_CANCEL:
1670 *process = target_queue_recovery_request(req, obd);
1674 DEBUG_REQ(D_WARNING, req, "not permitted during recovery");
1680 int ost_msg_check_version(struct lustre_msg *msg)
1684 switch(lustre_msg_get_opc(msg)) {
1686 case OST_DISCONNECT:
1689 case SEC_CTX_INIT_CONT:
1691 rc = lustre_msg_check_version(msg, LUSTRE_OBD_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_OBD_VERSION);
1699 /* Note: client always use MDS_VERSION for FID request */
1700 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
1702 CERROR("bad opc %u version %08x, expecting %08x\n",
1703 lustre_msg_get_opc(msg),
1704 lustre_msg_get_version(msg),
1705 LUSTRE_MDS_VERSION);
1718 case OST_QUOTACHECK:
1720 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1722 CERROR("bad opc %u version %08x, expecting %08x\n",
1723 lustre_msg_get_opc(msg),
1724 lustre_msg_get_version(msg),
1725 LUSTRE_OST_VERSION);
1730 case LDLM_BL_CALLBACK:
1731 case LDLM_CP_CALLBACK:
1732 rc = lustre_msg_check_version(msg, LUSTRE_DLM_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_DLM_VERSION);
1739 case LLOG_ORIGIN_CONNECT:
1740 case OBD_LOG_CANCEL:
1741 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1743 CERROR("bad opc %u version %08x, expecting %08x\n",
1744 lustre_msg_get_opc(msg),
1745 lustre_msg_get_version(msg),
1746 LUSTRE_LOG_VERSION);
1748 case OST_QUOTA_ADJUST_QUNIT:
1750 CERROR("Quota adjust is deprecated as of 2.4.0\n");
1753 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1759 struct ost_prolong_data {
1760 struct ptlrpc_request *opd_req;
1761 struct obd_export *opd_exp;
1762 struct obdo *opd_oa;
1763 struct ldlm_res_id opd_resid;
1764 struct ldlm_extent opd_extent;
1765 ldlm_mode_t opd_mode;
1766 unsigned int opd_locks;
1770 /* prolong locks for the current service time of the corresponding
1771 * portal (= OST_IO_PORTAL)
1773 static inline int prolong_timeout(struct ptlrpc_request *req)
1775 struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
1778 return obd_timeout / 2;
1780 return max(at_est2timeout(at_get(&svcpt->scp_at_estimate)),
1784 static void ost_prolong_lock_one(struct ost_prolong_data *opd,
1785 struct ldlm_lock *lock)
1787 LASSERT(lock->l_export == opd->opd_exp);
1789 if (lock->l_destroyed) /* lock already cancelled */
1792 /* XXX: never try to grab resource lock here because we're inside
1793 * exp_bl_list_lock; in ldlm_lockd.c to handle waiting list we take
1794 * res lock and then exp_bl_list_lock. */
1796 if (!(lock->l_flags & LDLM_FL_AST_SENT))
1797 /* ignore locks not being cancelled */
1801 "refreshed for req x"LPU64" ext("LPU64"->"LPU64") to %ds.\n",
1802 opd->opd_req->rq_xid, opd->opd_extent.start,
1803 opd->opd_extent.end, opd->opd_timeout);
1805 /* OK. this is a possible lock the user holds doing I/O
1806 * let's refresh eviction timer for it */
1807 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
1811 static void ost_prolong_locks(struct ost_prolong_data *data)
1813 struct obd_export *exp = data->opd_exp;
1814 struct obdo *oa = data->opd_oa;
1815 struct ldlm_lock *lock;
1818 if (oa->o_valid & OBD_MD_FLHANDLE) {
1819 /* mostly a request should be covered by only one lock, try
1821 lock = ldlm_handle2lock(&oa->o_handle);
1823 /* Fast path to check if the lock covers the whole IO
1824 * region exclusively. */
1825 if (lock->l_granted_mode == LCK_PW &&
1826 ldlm_extent_contain(&lock->l_policy_data.l_extent,
1827 &data->opd_extent)) {
1829 ost_prolong_lock_one(data, lock);
1830 LDLM_LOCK_PUT(lock);
1833 LDLM_LOCK_PUT(lock);
1838 spin_lock_bh(&exp->exp_bl_list_lock);
1839 cfs_list_for_each_entry(lock, &exp->exp_bl_list, l_exp_list) {
1840 LASSERT(lock->l_flags & LDLM_FL_AST_SENT);
1841 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
1843 if (!ldlm_res_eq(&data->opd_resid, &lock->l_resource->lr_name))
1846 if (!ldlm_extent_overlap(&lock->l_policy_data.l_extent,
1850 ost_prolong_lock_one(data, lock);
1852 spin_unlock_bh(&exp->exp_bl_list_lock);
1858 * Returns 1 if the given PTLRPC matches the given LDLM locks, or 0 if it does
1861 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1862 struct ldlm_lock *lock)
1864 struct niobuf_remote *nb;
1865 struct obd_ioobj *ioo;
1867 struct ldlm_extent ext;
1870 opc = lustre_msg_get_opc(req->rq_reqmsg);
1871 LASSERT(opc == OST_READ || opc == OST_WRITE);
1873 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1874 LASSERT(ioo != NULL);
1876 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1877 LASSERT(nb != NULL);
1879 ext.start = nb->offset;
1880 nb += ioo->ioo_bufcnt - 1;
1881 ext.end = nb->offset + nb->len - 1;
1883 LASSERT(lock->l_resource != NULL);
1884 if (!ostid_res_name_eq(&ioo->ioo_oid, &lock->l_resource->lr_name))
1888 if (opc == OST_READ)
1890 if (!(lock->l_granted_mode & mode))
1893 RETURN(ldlm_extent_overlap(&lock->l_policy_data.l_extent, &ext));
1897 * High-priority queue request check for whether the given PTLRPC request (\a
1898 * req) is blocking an LDLM lock cancel.
1900 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1901 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1903 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1904 * function looks only at OST_READs and OST_WRITEs.
1906 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1908 struct obd_device *obd = req->rq_export->exp_obd;
1909 struct ost_body *body;
1910 struct obd_ioobj *ioo;
1911 struct niobuf_remote *nb;
1912 struct ost_prolong_data opd = { 0 };
1917 * Use LASSERT to do sanity check because malformed RPCs should have
1918 * been filtered out in ost_hpreq_handler().
1920 opc = lustre_msg_get_opc(req->rq_reqmsg);
1921 LASSERT(opc == OST_READ || opc == OST_WRITE);
1923 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1924 LASSERT(body != NULL);
1926 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1927 LASSERT(ioo != NULL);
1929 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1930 LASSERT(nb != NULL);
1931 LASSERT(!(nb->flags & OBD_BRW_SRVLOCK));
1933 ostid_build_res_name(&ioo->ioo_oid, &opd.opd_resid);
1937 if (opc == OST_READ)
1939 opd.opd_mode = mode;
1940 opd.opd_exp = req->rq_export;
1941 opd.opd_oa = &body->oa;
1942 opd.opd_extent.start = nb->offset;
1943 nb += ioo->ioo_bufcnt - 1;
1944 opd.opd_extent.end = nb->offset + nb->len - 1;
1945 opd.opd_timeout = prolong_timeout(req);
1947 DEBUG_REQ(D_RPCTRACE, req,
1948 "%s %s: refresh rw locks: " LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1949 obd->obd_name, cfs_current()->comm,
1950 opd.opd_resid.name[0], opd.opd_resid.name[1],
1951 opd.opd_extent.start, opd.opd_extent.end);
1953 ost_prolong_locks(&opd);
1955 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
1956 obd->obd_name, opd.opd_locks, req);
1958 RETURN(opd.opd_locks > 0);
1961 static void ost_rw_hpreq_fini(struct ptlrpc_request *req)
1963 (void)ost_rw_hpreq_check(req);
1967 * Like ost_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
1969 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1970 struct ldlm_lock *lock)
1972 struct ost_body *body;
1975 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1976 LASSERT(body != NULL);
1978 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1979 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1986 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
1988 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1990 struct obd_device *obd = req->rq_export->exp_obd;
1991 struct ost_body *body;
1993 struct ost_prolong_data opd = { 0 };
1997 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1998 LASSERT(body != NULL);
2001 LASSERT(!(oa->o_valid & OBD_MD_FLFLAGS) ||
2002 !(oa->o_flags & OBD_FL_SRVLOCK));
2005 end = start + oa->o_blocks;
2008 opd.opd_mode = LCK_PW;
2009 opd.opd_exp = req->rq_export;
2011 opd.opd_extent.start = start;
2012 opd.opd_extent.end = end;
2013 if (oa->o_blocks == OBD_OBJECT_EOF)
2014 opd.opd_extent.end = OBD_OBJECT_EOF;
2015 opd.opd_timeout = prolong_timeout(req);
2017 ostid_build_res_name(&oa->o_oi, &opd.opd_resid);
2020 "%s: refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
2022 opd.opd_resid.name[0], opd.opd_resid.name[1],
2023 opd.opd_extent.start, opd.opd_extent.end);
2025 ost_prolong_locks(&opd);
2027 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
2028 obd->obd_name, opd.opd_locks, req);
2030 RETURN(opd.opd_locks > 0);
2033 static void ost_punch_hpreq_fini(struct ptlrpc_request *req)
2035 (void)ost_punch_hpreq_check(req);
2038 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
2039 .hpreq_lock_match = ost_rw_hpreq_lock_match,
2040 .hpreq_check = ost_rw_hpreq_check,
2041 .hpreq_fini = ost_rw_hpreq_fini
2044 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
2045 .hpreq_lock_match = ost_punch_hpreq_lock_match,
2046 .hpreq_check = ost_punch_hpreq_check,
2047 .hpreq_fini = ost_punch_hpreq_fini
2050 /** Assign high priority operations to the request if needed. */
2051 static int ost_io_hpreq_handler(struct ptlrpc_request *req)
2054 if (req->rq_export) {
2055 int opc = lustre_msg_get_opc(req->rq_reqmsg);
2056 struct ost_body *body;
2058 if (opc == OST_READ || opc == OST_WRITE) {
2059 struct niobuf_remote *nb;
2060 struct obd_ioobj *ioo;
2061 int objcount, niocount;
2065 /* RPCs on the H-P queue can be inspected before
2066 * ost_handler() initializes their pills, so we
2067 * initialize that here. Capsule initialization is
2068 * idempotent, as is setting the pill's format (provided
2069 * it doesn't change).
2071 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2072 if (opc == OST_READ)
2073 req_capsule_set(&req->rq_pill,
2076 req_capsule_set(&req->rq_pill,
2077 &RQF_OST_BRW_WRITE);
2079 body = req_capsule_client_get(&req->rq_pill,
2082 CERROR("Missing/short ost_body\n");
2086 objcount = req_capsule_get_size(&req->rq_pill,
2090 if (objcount == 0) {
2091 CERROR("Missing/short ioobj\n");
2095 CERROR("too many ioobjs (%d)\n", objcount);
2099 ioo = req_capsule_client_get(&req->rq_pill,
2102 CERROR("Missing/short ioobj\n");
2106 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
2108 CERROR("invalid object ids\n");
2112 for (niocount = i = 0; i < objcount; i++) {
2113 if (ioo[i].ioo_bufcnt == 0) {
2114 CERROR("ioo[%d] has zero bufcnt\n", i);
2117 niocount += ioo[i].ioo_bufcnt;
2119 if (niocount > PTLRPC_MAX_BRW_PAGES) {
2120 DEBUG_REQ(D_RPCTRACE, req,
2121 "bulk has too many pages (%d)",
2126 nb = req_capsule_client_get(&req->rq_pill,
2127 &RMF_NIOBUF_REMOTE);
2129 CERROR("Missing/short niobuf\n");
2133 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
2134 req->rq_ops = &ost_hpreq_rw;
2135 } else if (opc == OST_PUNCH) {
2136 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2137 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2139 body = req_capsule_client_get(&req->rq_pill,
2142 CERROR("Missing/short ost_body\n");
2146 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
2147 !(body->oa.o_flags & OBD_FL_SRVLOCK))
2148 req->rq_ops = &ost_hpreq_punch;
2154 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
2155 int ost_handle(struct ptlrpc_request *req)
2157 struct obd_trans_info trans_info = { 0, };
2158 struct obd_trans_info *oti = &trans_info;
2159 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
2160 struct obd_device *obd = NULL;
2163 /* OST module is kept between remounts, but the last reference
2164 * to specific module (say, osd or ofd) kills all related keys
2165 * from the environment. so we have to refill it until the root
2166 * cause is fixed properly */
2167 lu_env_refill(req->rq_svc_thread->t_env);
2169 LASSERT(current->journal_info == NULL);
2171 /* primordial rpcs don't affect server recovery */
2172 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2174 case SEC_CTX_INIT_CONT:
2179 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2181 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
2182 if (!class_connected_export(req->rq_export)) {
2183 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
2184 lustre_msg_get_opc(req->rq_reqmsg),
2185 libcfs_id2str(req->rq_peer));
2186 req->rq_status = -ENOTCONN;
2187 GOTO(out, rc = -ENOTCONN);
2190 obd = req->rq_export->exp_obd;
2192 /* Check for aborted recovery. */
2193 if (obd->obd_recovering) {
2194 rc = ost_filter_recovery_request(req, obd,
2196 if (rc || !should_process)
2198 else if (should_process < 0) {
2199 req->rq_status = should_process;
2200 rc = ptlrpc_error(req);
2208 rc = ost_msg_check_version(req->rq_reqmsg);
2212 if (req && req->rq_reqmsg && req->rq_export &&
2213 (exp_connect_flags(req->rq_export) & OBD_CONNECT_JOBSTATS))
2214 oti->oti_jobid = lustre_msg_get_jobid(req->rq_reqmsg);
2216 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2218 CDEBUG(D_INODE, "connect\n");
2219 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
2220 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
2222 rc = target_handle_connect(req);
2223 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
2226 rc = ost_init_sec_level(req);
2228 rc = ost_connect_check_sptlrpc(req);
2232 case OST_DISCONNECT:
2233 CDEBUG(D_INODE, "disconnect\n");
2234 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
2235 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
2237 rc = target_handle_disconnect(req);
2240 CDEBUG(D_INODE, "create\n");
2241 req_capsule_set(&req->rq_pill, &RQF_OST_CREATE);
2242 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
2244 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2245 GOTO(out, rc = -EROFS);
2246 rc = ost_create(req->rq_export, req, oti);
2249 CDEBUG(D_INODE, "destroy\n");
2250 req_capsule_set(&req->rq_pill, &RQF_OST_DESTROY);
2251 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
2253 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2254 GOTO(out, rc = -EROFS);
2255 rc = ost_destroy(req->rq_export, req, oti);
2258 CDEBUG(D_INODE, "getattr\n");
2259 req_capsule_set(&req->rq_pill, &RQF_OST_GETATTR);
2260 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
2262 rc = ost_getattr(req->rq_export, req);
2265 CDEBUG(D_INODE, "setattr\n");
2266 req_capsule_set(&req->rq_pill, &RQF_OST_SETATTR);
2267 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
2269 rc = ost_setattr(req->rq_export, req, oti);
2272 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_WRITE);
2273 CDEBUG(D_INODE, "write\n");
2274 /* req->rq_request_portal would be nice, if it was set */
2275 if (ptlrpc_req2svc(req)->srv_req_portal != OST_IO_PORTAL) {
2276 CERROR("%s: deny write request from %s to portal %u\n",
2277 req->rq_export->exp_obd->obd_name,
2278 obd_export_nid2str(req->rq_export),
2279 ptlrpc_req2svc(req)->srv_req_portal);
2280 GOTO(out, rc = -EPROTO);
2282 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2284 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
2285 GOTO(out, rc = -ENOSPC);
2286 if (OBD_FAIL_TIMEOUT(OBD_FAIL_OST_EROFS, 1))
2287 GOTO(out, rc = -EROFS);
2288 rc = ost_brw_write(req, oti);
2289 LASSERT(current->journal_info == NULL);
2290 /* ost_brw_write sends its own replies */
2293 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_READ);
2294 CDEBUG(D_INODE, "read\n");
2295 /* req->rq_request_portal would be nice, if it was set */
2296 if (ptlrpc_req2svc(req)->srv_req_portal != OST_IO_PORTAL) {
2297 CERROR("%s: deny read request from %s to portal %u\n",
2298 req->rq_export->exp_obd->obd_name,
2299 obd_export_nid2str(req->rq_export),
2300 ptlrpc_req2svc(req)->srv_req_portal);
2301 GOTO(out, rc = -EPROTO);
2303 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2305 rc = ost_brw_read(req, oti);
2306 LASSERT(current->journal_info == NULL);
2307 /* ost_brw_read sends its own replies */
2310 CDEBUG(D_INODE, "punch\n");
2311 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2312 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2314 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2315 GOTO(out, rc = -EROFS);
2316 rc = ost_punch(req->rq_export, req, oti);
2319 CDEBUG(D_INODE, "statfs\n");
2320 req_capsule_set(&req->rq_pill, &RQF_OST_STATFS);
2321 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2323 rc = ost_statfs(req);
2326 CDEBUG(D_INODE, "sync\n");
2327 req_capsule_set(&req->rq_pill, &RQF_OST_SYNC);
2328 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2330 rc = ost_sync(req->rq_export, req, oti);
2333 DEBUG_REQ(D_INODE, req, "set_info");
2334 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
2335 rc = ost_set_info(req->rq_export, req);
2338 DEBUG_REQ(D_INODE, req, "get_info");
2339 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
2340 rc = ost_get_info(req->rq_export, req);
2343 CDEBUG(D_INODE, "seq\n");
2344 rc = seq_handle(req);
2346 case OST_QUOTACHECK:
2347 CDEBUG(D_INODE, "quotacheck\n");
2348 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2349 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2351 rc = ost_handle_quotacheck(req);
2354 CDEBUG(D_INODE, "quotactl\n");
2355 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2356 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2358 rc = ost_handle_quotactl(req);
2361 DEBUG_REQ(D_INODE, req, "ping");
2362 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2363 rc = target_handle_ping(req);
2365 /* FIXME - just reply status */
2366 case LLOG_ORIGIN_CONNECT:
2367 DEBUG_REQ(D_INODE, req, "log connect");
2368 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2369 rc = ost_llog_handle_connect(req->rq_export, req);
2370 req->rq_status = rc;
2371 rc = req_capsule_server_pack(&req->rq_pill);
2374 RETURN(ptlrpc_reply(req));
2375 case OBD_LOG_CANCEL:
2376 CDEBUG(D_INODE, "log cancel\n");
2377 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2378 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2380 rc = llog_origin_handle_cancel(req);
2381 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2383 req->rq_status = rc;
2384 rc = req_capsule_server_pack(&req->rq_pill);
2387 RETURN(ptlrpc_reply(req));
2389 CDEBUG(D_INODE, "enqueue\n");
2390 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2391 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE_NET))
2393 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2395 ldlm_server_glimpse_ast);
2396 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2399 CDEBUG(D_INODE, "convert\n");
2400 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2401 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT_NET))
2403 rc = ldlm_handle_convert(req);
2406 CDEBUG(D_INODE, "cancel\n");
2407 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2408 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL_NET))
2410 rc = ldlm_handle_cancel(req);
2412 case LDLM_BL_CALLBACK:
2413 case LDLM_CP_CALLBACK:
2414 CDEBUG(D_INODE, "callback\n");
2415 CERROR("callbacks should not happen on OST\n");
2418 CERROR("Unexpected opcode %d\n",
2419 lustre_msg_get_opc(req->rq_reqmsg));
2420 req->rq_status = -ENOTSUPP;
2421 rc = ptlrpc_error(req);
2425 LASSERT(current->journal_info == NULL);
2428 /* If we're DISCONNECTing, the export_data is already freed */
2429 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2430 target_committed_to_req(req);
2434 oti_to_request(oti, req);
2436 target_send_reply(req, rc, fail);
2439 EXPORT_SYMBOL(ost_handle);
2442 * free per-thread pool created by ost_io_thread_init().
2444 static void ost_io_thread_done(struct ptlrpc_thread *thread)
2446 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2451 LASSERT(thread != NULL);
2454 * be prepared to handle partially-initialized pools (because this is
2455 * called from ost_io_thread_init() for cleanup.
2457 tls = thread->t_data;
2460 thread->t_data = NULL;
2466 * initialize per-thread page pool (bug 5137).
2468 static int ost_io_thread_init(struct ptlrpc_thread *thread)
2470 struct ost_thread_local_cache *tls;
2474 LASSERT(thread != NULL);
2475 LASSERT(thread->t_data == NULL);
2480 thread->t_data = tls;
2484 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2486 static struct cfs_cpt_table *ost_io_cptable;
2488 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2489 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2491 static struct ptlrpc_service_conf svc_conf;
2492 struct ost_obd *ost = &obd->u.ost;
2493 struct lprocfs_static_vars lvars;
2498 rc = cfs_cleanup_group_info();
2502 lprocfs_ost_init_vars(&lvars);
2503 lprocfs_obd_setup(obd, lvars.obd_vars);
2505 mutex_init(&ost->ost_health_mutex);
2507 svc_conf = (typeof(svc_conf)) {
2508 .psc_name = LUSTRE_OSS_NAME,
2509 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
2511 .bc_nbufs = OST_NBUFS,
2512 .bc_buf_size = OST_BUFSIZE,
2513 .bc_req_max_size = OST_MAXREQSIZE,
2514 .bc_rep_max_size = OST_MAXREPSIZE,
2515 .bc_req_portal = OST_REQUEST_PORTAL,
2516 .bc_rep_portal = OSC_REPLY_PORTAL,
2519 .tc_thr_name = "ll_ost",
2520 .tc_thr_factor = OSS_THR_FACTOR,
2521 .tc_nthrs_init = OSS_NTHRS_INIT,
2522 .tc_nthrs_base = OSS_NTHRS_BASE,
2523 .tc_nthrs_max = OSS_NTHRS_MAX,
2524 .tc_nthrs_user = oss_num_threads,
2525 .tc_cpu_affinity = 1,
2526 .tc_ctx_tags = LCT_DT_THREAD,
2529 .cc_pattern = oss_cpts,
2532 .so_req_handler = ost_handle,
2533 .so_req_printer = target_print_req,
2534 .so_hpreq_handler = ptlrpc_hpreq_handler,
2537 ost->ost_service = ptlrpc_register_service(&svc_conf,
2538 obd->obd_proc_entry);
2539 if (IS_ERR(ost->ost_service)) {
2540 rc = PTR_ERR(ost->ost_service);
2541 CERROR("failed to start service: %d\n", rc);
2542 GOTO(out_lprocfs, rc);
2545 memset(&svc_conf, 0, sizeof(svc_conf));
2546 svc_conf = (typeof(svc_conf)) {
2547 .psc_name = "ost_create",
2548 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
2550 .bc_nbufs = OST_NBUFS,
2551 .bc_buf_size = OST_BUFSIZE,
2552 .bc_req_max_size = OST_MAXREQSIZE,
2553 .bc_rep_max_size = OST_MAXREPSIZE,
2554 .bc_req_portal = OST_CREATE_PORTAL,
2555 .bc_rep_portal = OSC_REPLY_PORTAL,
2558 .tc_thr_name = "ll_ost_create",
2559 .tc_thr_factor = OSS_CR_THR_FACTOR,
2560 .tc_nthrs_init = OSS_CR_NTHRS_INIT,
2561 .tc_nthrs_base = OSS_CR_NTHRS_BASE,
2562 .tc_nthrs_max = OSS_CR_NTHRS_MAX,
2563 .tc_nthrs_user = oss_num_create_threads,
2564 .tc_cpu_affinity = 1,
2565 .tc_ctx_tags = LCT_DT_THREAD,
2568 .cc_pattern = oss_cpts,
2571 .so_req_handler = ost_handle,
2572 .so_req_printer = target_print_req,
2575 ost->ost_create_service = ptlrpc_register_service(&svc_conf,
2576 obd->obd_proc_entry);
2577 if (IS_ERR(ost->ost_create_service)) {
2578 rc = PTR_ERR(ost->ost_create_service);
2579 CERROR("failed to start OST create service: %d\n", rc);
2580 GOTO(out_service, rc);
2583 mask = cfs_cpt_table->ctb_nodemask;
2584 /* event CPT feature is disabled in libcfs level by set partition
2585 * number to 1, we still want to set node affinity for io service */
2586 if (cfs_cpt_number(cfs_cpt_table) == 1 && nodes_weight(*mask) > 1) {
2590 ost_io_cptable = cfs_cpt_table_alloc(nodes_weight(*mask));
2591 for_each_node_mask(i, *mask) {
2592 if (ost_io_cptable == NULL) {
2593 CWARN("OSS failed to create CPT table\n");
2597 rc = cfs_cpt_set_node(ost_io_cptable, cpt++, i);
2599 CWARN("OSS Failed to set node %d for"
2600 "IO CPT table\n", i);
2601 cfs_cpt_table_free(ost_io_cptable);
2602 ost_io_cptable = NULL;
2608 memset(&svc_conf, 0, sizeof(svc_conf));
2609 svc_conf = (typeof(svc_conf)) {
2610 .psc_name = "ost_io",
2611 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
2613 .bc_nbufs = OST_NBUFS,
2614 .bc_buf_size = OST_IO_BUFSIZE,
2615 .bc_req_max_size = OST_IO_MAXREQSIZE,
2616 .bc_rep_max_size = OST_IO_MAXREPSIZE,
2617 .bc_req_portal = OST_IO_PORTAL,
2618 .bc_rep_portal = OSC_REPLY_PORTAL,
2621 .tc_thr_name = "ll_ost_io",
2622 .tc_thr_factor = OSS_THR_FACTOR,
2623 .tc_nthrs_init = OSS_NTHRS_INIT,
2624 .tc_nthrs_base = OSS_NTHRS_BASE,
2625 .tc_nthrs_max = OSS_NTHRS_MAX,
2626 .tc_nthrs_user = oss_num_threads,
2627 .tc_cpu_affinity = 1,
2628 .tc_ctx_tags = LCT_DT_THREAD,
2631 .cc_cptable = ost_io_cptable,
2632 .cc_pattern = ost_io_cptable == NULL ?
2636 .so_thr_init = ost_io_thread_init,
2637 .so_thr_done = ost_io_thread_done,
2638 .so_req_handler = ost_handle,
2639 .so_hpreq_handler = ost_io_hpreq_handler,
2640 .so_req_printer = target_print_req,
2643 ost->ost_io_service = ptlrpc_register_service(&svc_conf,
2644 obd->obd_proc_entry);
2645 if (IS_ERR(ost->ost_io_service)) {
2646 rc = PTR_ERR(ost->ost_io_service);
2647 CERROR("failed to start OST I/O service: %d\n", rc);
2648 ost->ost_io_service = NULL;
2649 GOTO(out_create, rc);
2652 memset(&svc_conf, 0, sizeof(svc_conf));
2653 svc_conf = (typeof(svc_conf)) {
2654 .psc_name = "ost_seq",
2655 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
2657 .bc_nbufs = OST_NBUFS,
2658 .bc_buf_size = OST_BUFSIZE,
2659 .bc_req_max_size = OST_MAXREQSIZE,
2660 .bc_rep_max_size = OST_MAXREPSIZE,
2661 .bc_req_portal = SEQ_DATA_PORTAL,
2662 .bc_rep_portal = OSC_REPLY_PORTAL,
2665 .tc_thr_name = "ll_ost_seq",
2666 .tc_thr_factor = OSS_CR_THR_FACTOR,
2667 .tc_nthrs_init = OSS_CR_NTHRS_INIT,
2668 .tc_nthrs_base = OSS_CR_NTHRS_BASE,
2669 .tc_nthrs_max = OSS_CR_NTHRS_MAX,
2670 .tc_nthrs_user = oss_num_create_threads,
2671 .tc_cpu_affinity = 1,
2672 .tc_ctx_tags = LCT_DT_THREAD,
2676 .cc_pattern = oss_cpts,
2679 .so_req_handler = ost_handle,
2680 .so_req_printer = target_print_req,
2681 .so_hpreq_handler = NULL,
2684 ost->ost_seq_service = ptlrpc_register_service(&svc_conf,
2685 obd->obd_proc_entry);
2686 if (IS_ERR(ost->ost_seq_service)) {
2687 rc = PTR_ERR(ost->ost_seq_service);
2688 CERROR("failed to start OST seq service: %d\n", rc);
2689 ost->ost_seq_service = NULL;
2693 ping_evictor_start();
2697 ptlrpc_unregister_service(ost->ost_io_service);
2698 ost->ost_io_service = NULL;
2700 ptlrpc_unregister_service(ost->ost_create_service);
2701 ost->ost_create_service = NULL;
2703 ptlrpc_unregister_service(ost->ost_service);
2704 ost->ost_service = NULL;
2706 lprocfs_obd_cleanup(obd);
2710 static int ost_cleanup(struct obd_device *obd)
2712 struct ost_obd *ost = &obd->u.ost;
2716 ping_evictor_stop();
2718 /* there is no recovery for OST OBD, all recovery is controlled by
2720 LASSERT(obd->obd_recovering == 0);
2721 mutex_lock(&ost->ost_health_mutex);
2722 ptlrpc_unregister_service(ost->ost_service);
2723 ptlrpc_unregister_service(ost->ost_create_service);
2724 ptlrpc_unregister_service(ost->ost_io_service);
2725 ptlrpc_unregister_service(ost->ost_seq_service);
2726 ost->ost_service = NULL;
2727 ost->ost_create_service = NULL;
2728 ost->ost_io_service = NULL;
2729 ost->ost_seq_service = NULL;
2731 mutex_unlock(&ost->ost_health_mutex);
2733 lprocfs_obd_cleanup(obd);
2735 if (ost_io_cptable != NULL) {
2736 cfs_cpt_table_free(ost_io_cptable);
2737 ost_io_cptable = NULL;
2743 static int ost_health_check(const struct lu_env *env, struct obd_device *obd)
2745 struct ost_obd *ost = &obd->u.ost;
2748 mutex_lock(&ost->ost_health_mutex);
2749 rc |= ptlrpc_service_health_check(ost->ost_service);
2750 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2751 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2752 mutex_unlock(&ost->ost_health_mutex);
2755 * health_check to return 0 on healthy
2756 * and 1 on unhealthy.
2764 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2766 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2769 /* use obd ops to offer management infrastructure */
2770 static struct obd_ops ost_obd_ops = {
2771 .o_owner = THIS_MODULE,
2772 .o_setup = ost_setup,
2773 .o_cleanup = ost_cleanup,
2774 .o_health_check = ost_health_check,
2778 static int __init ost_init(void)
2780 struct lprocfs_static_vars lvars;
2784 ost_page_to_corrupt = cfs_alloc_page(CFS_ALLOC_STD);
2786 lprocfs_ost_init_vars(&lvars);
2787 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2788 LUSTRE_OSS_NAME, NULL);
2790 if (ost_num_threads != 0 && oss_num_threads == 0) {
2791 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2792 "use oss_num_threads instead or unset both for "
2793 "dynamic thread startup\n");
2794 oss_num_threads = ost_num_threads;
2800 static void /*__exit*/ ost_exit(void)
2802 if (ost_page_to_corrupt)
2803 page_cache_release(ost_page_to_corrupt);
2805 class_unregister_type(LUSTRE_OSS_NAME);
2808 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2809 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2810 MODULE_LICENSE("GPL");
2812 module_init(ost_init);
2813 module_exit(ost_exit);