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, Whamcloud, Inc.
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 <lustre_quota.h>
55 #include "ost_internal.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 * Do not return server-side uid/gid to remote client
80 static void ost_drop_id(struct obd_export *exp, struct obdo *oa)
82 if (exp_connect_rmtclient(exp)) {
85 oa->o_valid &= ~(OBD_MD_FLUID | OBD_MD_FLGID);
90 * Validate oa from client.
91 * If the request comes from 2.0 clients, currently only RSVD seq and IDIF
93 * a. for single MDS seq = FID_SEQ_OST_MDT0,
94 * b. for CMD, seq = FID_SEQ_OST_MDT0, FID_SEQ_OST_MDT1 - FID_SEQ_OST_MAX
96 static int ost_validate_obdo(struct obd_export *exp, struct obdo *oa,
97 struct obd_ioobj *ioobj)
99 if (oa != NULL && !(oa->o_valid & OBD_MD_FLGROUP)) {
100 oa->o_seq = FID_SEQ_OST_MDT0;
102 ioobj->ioo_seq = FID_SEQ_OST_MDT0;
103 /* remove fid_seq_is_rsvd() after FID-on-OST allows SEQ > 9 */
104 } else if (oa == NULL || !(fid_seq_is_rsvd(oa->o_seq) ||
105 fid_seq_is_mdt0(oa->o_seq))) {
106 CERROR("%s: client %s sent invalid object "POSTID"\n",
107 exp->exp_obd->obd_name, obd_export_nid2str(exp),
108 oa ? oa->o_id : -1, oa ? oa->o_seq : -1);
111 obdo_from_ostid(oa, &oa->o_oi);
113 ioobj_from_obdo(ioobj, oa);
117 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
119 struct oti_req_ack_lock *ack_lock;
125 if (req->rq_repmsg) {
126 __u64 versions[PTLRPC_NUM_VERSIONS] = { 0 };
127 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
128 versions[0] = oti->oti_pre_version;
129 lustre_msg_set_versions(req->rq_repmsg, versions);
131 req->rq_transno = oti->oti_transno;
133 /* XXX 4 == entries in oti_ack_locks??? */
134 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
137 /* XXX not even calling target_send_reply in some cases... */
138 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode, 0);
142 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
143 struct obd_trans_info *oti)
145 struct ost_body *body, *repbody;
146 struct lustre_capa *capa = NULL;
150 /* Get the request body */
151 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
155 if (body->oa.o_id == 0)
158 rc = ost_validate_obdo(exp, &body->oa, NULL);
162 /* If there's a DLM request, cancel the locks mentioned in it*/
163 if (req_capsule_field_present(&req->rq_pill, &RMF_DLM_REQ, RCL_CLIENT)) {
164 struct ldlm_request *dlm;
166 dlm = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
169 ldlm_request_cancel(req, dlm, 0);
172 /* If there's a capability, get it */
173 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
174 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
176 CERROR("Missing capability for OST DESTROY");
181 /* Prepare the reply */
182 rc = req_capsule_server_pack(&req->rq_pill);
186 /* Get the log cancellation cookie */
187 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
188 oti->oti_logcookies = &body->oa.o_lcookie;
190 /* Finish the reply */
191 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
192 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
194 /* Do the destroy and set the reply status accordingly */
195 req->rq_status = obd_destroy(req->rq_svc_thread->t_env, exp,
196 &repbody->oa, NULL, oti, NULL, capa);
201 * Helper function for getting server side [start, start+count] DLM lock
202 * if asked by client.
204 static int ost_lock_get(struct obd_export *exp, struct obdo *oa,
205 __u64 start, __u64 count, struct lustre_handle *lh,
208 struct ldlm_res_id res_id;
209 ldlm_policy_data_t policy;
210 __u64 end = start + count;
214 LASSERT(!lustre_handle_is_used(lh));
215 /* o_id and o_gr are used for localizing resource, if client miss to set
216 * them, do not trigger ASSERTION. */
217 if (unlikely((oa->o_valid & (OBD_MD_FLID | OBD_MD_FLGROUP)) !=
218 (OBD_MD_FLID | OBD_MD_FLGROUP)))
221 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
222 !(oa->o_flags & OBD_FL_SRVLOCK))
225 osc_build_res_name(oa->o_id, oa->o_seq, &res_id);
226 CDEBUG(D_INODE, "OST-side extent lock.\n");
228 policy.l_extent.start = start & CFS_PAGE_MASK;
230 /* If ->o_blocks is EOF it means "lock till the end of the
231 * file". Otherwise, it's size of a hole being punched (in bytes) */
232 if (count == OBD_OBJECT_EOF || end < start)
233 policy.l_extent.end = OBD_OBJECT_EOF;
235 policy.l_extent.end = end | ~CFS_PAGE_MASK;
237 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
238 LDLM_EXTENT, &policy, mode, &flags,
239 ldlm_blocking_ast, ldlm_completion_ast,
240 ldlm_glimpse_ast, NULL, 0, NULL, lh));
243 /* Helper function: release lock, if any. */
244 static void ost_lock_put(struct obd_export *exp,
245 struct lustre_handle *lh, int mode)
248 if (lustre_handle_is_used(lh))
249 ldlm_lock_decref(lh, mode);
253 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
255 struct ost_body *body, *repbody;
256 struct obd_info *oinfo;
257 struct lustre_handle lh = { 0 };
258 struct lustre_capa *capa = NULL;
262 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
266 rc = ost_validate_obdo(exp, &body->oa, NULL);
270 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
271 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
273 CERROR("Missing capability for OST GETATTR");
278 rc = req_capsule_server_pack(&req->rq_pill);
282 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
283 repbody->oa = body->oa;
285 rc = ost_lock_get(exp, &repbody->oa, 0, OBD_OBJECT_EOF, &lh, LCK_PR, 0);
289 OBD_ALLOC_PTR(oinfo);
291 GOTO(unlock, rc = -ENOMEM);
292 oinfo->oi_oa = &repbody->oa;
293 oinfo->oi_capa = capa;
295 req->rq_status = obd_getattr(req->rq_svc_thread->t_env, exp, oinfo);
299 ost_drop_id(exp, &repbody->oa);
302 ost_lock_put(exp, &lh, LCK_PR);
306 static int ost_statfs(struct ptlrpc_request *req)
308 struct obd_statfs *osfs;
312 rc = req_capsule_server_pack(&req->rq_pill);
316 osfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
318 req->rq_status = obd_statfs(req->rq_svc_thread->t_env, req->rq_export,
320 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
322 if (req->rq_status != 0)
323 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
325 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_EINPROGRESS))
326 req->rq_status = -EINPROGRESS;
331 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
332 struct obd_trans_info *oti)
334 struct ost_body *body, *repbody;
338 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
342 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
346 rc = req_capsule_server_pack(&req->rq_pill);
350 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
351 repbody->oa = body->oa;
352 oti->oti_logcookies = &body->oa.o_lcookie;
354 req->rq_status = obd_create(req->rq_svc_thread->t_env, exp,
355 &repbody->oa, NULL, oti);
356 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
360 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
361 struct obd_trans_info *oti)
363 struct ost_body *body, *repbody;
365 struct lustre_handle lh = {0,};
368 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
369 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
371 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
375 rc = ost_validate_obdo(exp, &body->oa, NULL);
379 if ((body->oa.o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
380 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
383 rc = req_capsule_server_pack(&req->rq_pill);
387 /* standard truncate optimization: if file body is completely
388 * destroyed, don't send data back to the server. */
389 if (body->oa.o_size == 0)
390 flags |= LDLM_AST_DISCARD_DATA;
392 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
393 repbody->oa = body->oa;
395 rc = ost_lock_get(exp, &repbody->oa, repbody->oa.o_size,
396 repbody->oa.o_blocks, &lh, LCK_PW, flags);
398 struct obd_info *oinfo;
399 struct lustre_capa *capa = NULL;
401 if (repbody->oa.o_valid & OBD_MD_FLFLAGS &&
402 repbody->oa.o_flags == OBD_FL_SRVLOCK)
404 * If OBD_FL_SRVLOCK is the only bit set in
405 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
406 * through filter_setattr() to filter_iocontrol().
408 repbody->oa.o_valid &= ~OBD_MD_FLFLAGS;
410 if (repbody->oa.o_valid & OBD_MD_FLOSSCAPA) {
411 capa = req_capsule_client_get(&req->rq_pill,
414 CERROR("Missing capability for OST PUNCH");
415 GOTO(unlock, rc = -EFAULT);
419 OBD_ALLOC_PTR(oinfo);
421 GOTO(unlock, rc = -ENOMEM);
422 oinfo->oi_oa = &repbody->oa;
423 oinfo->oi_policy.l_extent.start = oinfo->oi_oa->o_size;
424 oinfo->oi_policy.l_extent.end = oinfo->oi_oa->o_blocks;
425 oinfo->oi_capa = capa;
426 oinfo->oi_flags = OBD_FL_PUNCH;
428 req->rq_status = obd_punch(req->rq_svc_thread->t_env, exp,
432 ost_lock_put(exp, &lh, LCK_PW);
435 ost_drop_id(exp, &repbody->oa);
439 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req,
440 struct obd_trans_info *oti)
442 struct ost_body *body, *repbody;
443 struct obd_info *oinfo;
444 struct lustre_capa *capa = NULL;
448 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
452 rc = ost_validate_obdo(exp, &body->oa, NULL);
456 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
457 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
459 CERROR("Missing capability for OST SYNC");
464 rc = req_capsule_server_pack(&req->rq_pill);
468 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
469 repbody->oa = body->oa;
471 OBD_ALLOC_PTR(oinfo);
475 oinfo->oi_oa = &repbody->oa;
476 oinfo->oi_capa = capa;
477 oinfo->oi_jobid = oti->oti_jobid;
478 req->rq_status = obd_sync(req->rq_svc_thread->t_env, exp, oinfo,
479 repbody->oa.o_size, repbody->oa.o_blocks,
483 ost_drop_id(exp, &repbody->oa);
487 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
488 struct obd_trans_info *oti)
490 struct ost_body *body, *repbody;
491 struct obd_info *oinfo;
492 struct lustre_capa *capa = NULL;
496 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
500 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
504 rc = req_capsule_server_pack(&req->rq_pill);
508 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
509 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
511 CERROR("Missing capability for OST SETATTR");
516 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
517 repbody->oa = body->oa;
519 OBD_ALLOC_PTR(oinfo);
522 oinfo->oi_oa = &repbody->oa;
523 oinfo->oi_capa = capa;
525 req->rq_status = obd_setattr(req->rq_svc_thread->t_env, exp, oinfo,
530 ost_drop_id(exp, &repbody->oa);
534 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
535 cksum_type_t cksum_type)
537 struct cfs_crypto_hash_desc *hdesc;
538 unsigned int bufsize;
540 unsigned char cfs_alg = cksum_obd2cfs(cksum_type);
543 hdesc = cfs_crypto_hash_init(cfs_alg, NULL, 0);
545 CERROR("Unable to initialize checksum hash %s\n",
546 cfs_crypto_hash_name(cfs_alg));
547 return PTR_ERR(hdesc);
549 CDEBUG(D_INFO, "Checksum for algo %s\n", cfs_crypto_hash_name(cfs_alg));
550 for (i = 0; i < desc->bd_iov_count; i++) {
552 /* corrupt the data before we compute the checksum, to
553 * simulate a client->OST data error */
554 if (i == 0 && opc == OST_WRITE &&
555 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE)) {
556 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
557 int len = desc->bd_iov[i].kiov_len;
558 char *ptr = kmap(desc->bd_iov[i].kiov_page) + off;
559 memcpy(ptr, "bad3", min(4, len));
560 kunmap(desc->bd_iov[i].kiov_page);
562 cfs_crypto_hash_update_page(hdesc, desc->bd_iov[i].kiov_page,
563 desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK,
564 desc->bd_iov[i].kiov_len);
566 /* corrupt the data after we compute the checksum, to
567 * simulate an OST->client data error */
568 if (i == 0 && opc == OST_READ &&
569 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
570 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
571 int len = desc->bd_iov[i].kiov_len;
572 char *ptr = kmap(desc->bd_iov[i].kiov_page) + off;
573 memcpy(ptr, "bad4", min(4, len));
574 kunmap(desc->bd_iov[i].kiov_page);
575 /* nobody should use corrupted page again */
576 ClearPageUptodate(desc->bd_iov[i].kiov_page);
581 err = cfs_crypto_hash_final(hdesc, (unsigned char *)&cksum, &bufsize);
583 cfs_crypto_hash_final(hdesc, NULL, NULL);
588 static int ost_brw_lock_get(int mode, struct obd_export *exp,
589 struct obd_ioobj *obj, struct niobuf_remote *nb,
590 struct lustre_handle *lh)
593 int nrbufs = obj->ioo_bufcnt;
594 struct ldlm_res_id res_id;
595 ldlm_policy_data_t policy;
599 osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id);
600 LASSERT(mode == LCK_PR || mode == LCK_PW);
601 LASSERT(!lustre_handle_is_used(lh));
603 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
606 for (i = 1; i < nrbufs; i ++)
607 if ((nb[0].flags & OBD_BRW_SRVLOCK) !=
608 (nb[i].flags & OBD_BRW_SRVLOCK))
611 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
612 policy.l_extent.end = (nb[nrbufs - 1].offset +
613 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
615 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
616 LDLM_EXTENT, &policy, mode, &flags,
617 ldlm_blocking_ast, ldlm_completion_ast,
618 ldlm_glimpse_ast, NULL, 0, NULL, lh));
621 static void ost_brw_lock_put(int mode,
622 struct obd_ioobj *obj, struct niobuf_remote *niob,
623 struct lustre_handle *lh)
626 LASSERT(mode == LCK_PR || mode == LCK_PW);
627 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
628 lustre_handle_is_used(lh));
629 if (lustre_handle_is_used(lh))
630 ldlm_lock_decref(lh, mode);
634 /* Allocate thread local buffers if needed */
635 static struct ost_thread_local_cache *ost_tls_get(struct ptlrpc_request *r)
637 struct ost_thread_local_cache *tls =
638 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
640 /* In normal mode of operation an I/O request is serviced only
641 * by ll_ost_io threads each of them has own tls buffers allocated by
643 * During recovery, an I/O request may be queued until any of the ost
644 * service threads process it. Not necessary it should be one of
645 * ll_ost_io threads. In that case we dynamically allocating tls
646 * buffers for the request service time. */
647 if (unlikely(tls == NULL)) {
648 LASSERT(r->rq_export->exp_in_recovery);
652 r->rq_svc_thread->t_data = tls;
658 /* Free thread local buffers if they were allocated only for servicing
659 * this one request */
660 static void ost_tls_put(struct ptlrpc_request *r)
662 struct ost_thread_local_cache *tls =
663 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
665 if (unlikely(tls->temporary)) {
667 r->rq_svc_thread->t_data = NULL;
671 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
673 struct ptlrpc_bulk_desc *desc = NULL;
674 struct obd_export *exp = req->rq_export;
675 struct niobuf_remote *remote_nb;
676 struct niobuf_local *local_nb;
677 struct obd_ioobj *ioo;
678 struct ost_body *body, *repbody;
679 struct lustre_capa *capa = NULL;
680 struct l_wait_info lwi;
681 struct lustre_handle lockh = { 0 };
682 int niocount, npages, nob = 0, rc, i;
684 struct ost_thread_local_cache *tls;
687 req->rq_bulk_read = 1;
689 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
690 GOTO(out, rc = -EIO);
692 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
694 /* Check if there is eviction in progress, and if so, wait for it to
696 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
697 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
698 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
699 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
703 GOTO(out, rc = -ENOTCONN);
705 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
706 * ost_rw_hpreq_check(). */
707 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
709 GOTO(out, rc = -EFAULT);
712 * A req_capsule_X_get_array(pill, field, ptr_to_element_count) function
713 * would be useful here and wherever we get &RMF_OBD_IOOBJ and
714 * &RMF_NIOBUF_REMOTE.
716 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
718 GOTO(out, rc = -EFAULT);
720 rc = ost_validate_obdo(exp, &body->oa, ioo);
724 niocount = ioo->ioo_bufcnt;
725 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
726 if (remote_nb == NULL)
727 GOTO(out, rc = -EFAULT);
729 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
730 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
732 CERROR("Missing capability for OST BRW READ");
733 GOTO(out, rc = -EFAULT);
737 rc = req_capsule_server_pack(&req->rq_pill);
741 tls = ost_tls_get(req);
743 GOTO(out_bulk, rc = -ENOMEM);
744 local_nb = tls->local;
746 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
751 * If getting the lock took more time than
752 * client was willing to wait, drop it. b=11330
754 if (cfs_time_current_sec() > req->rq_deadline ||
755 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
757 CERROR("Dropping timed-out read from %s because locking"
758 "object "LPX64" took %ld seconds (limit was %ld).\n",
759 libcfs_id2str(req->rq_peer), ioo->ioo_id,
760 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
761 req->rq_deadline - req->rq_arrival_time.tv_sec);
762 GOTO(out_lock, rc = -ETIMEDOUT);
765 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
766 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
768 npages = OST_THREAD_POOL_SIZE;
769 rc = obd_preprw(req->rq_svc_thread->t_env, OBD_BRW_READ, exp,
770 &repbody->oa, 1, ioo, remote_nb, &npages, local_nb,
775 desc = ptlrpc_prep_bulk_exp(req, npages,
776 BULK_PUT_SOURCE, OST_BULK_PORTAL);
778 GOTO(out_commitrw, rc = -ENOMEM);
781 for (i = 0; i < npages; i++) {
782 int page_rc = local_nb[i].rc;
784 if (page_rc < 0) { /* error */
790 if (page_rc != 0) { /* some data! */
791 LASSERT (local_nb[i].page != NULL);
792 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
793 local_nb[i].lnb_page_offset,
797 if (page_rc != local_nb[i].len) { /* short read */
798 /* All subsequent pages should be 0 */
800 LASSERT(local_nb[i].rc == 0);
805 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
806 cksum_type_t cksum_type =
807 cksum_type_unpack(repbody->oa.o_valid & OBD_MD_FLFLAGS ?
808 repbody->oa.o_flags : 0);
809 repbody->oa.o_flags = cksum_type_pack(cksum_type);
810 repbody->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
811 repbody->oa.o_cksum = ost_checksum_bulk(desc, OST_READ,cksum_type);
812 CDEBUG(D_PAGE, "checksum at read origin: %x\n",
813 repbody->oa.o_cksum);
815 repbody->oa.o_valid = 0;
817 /* We're finishing using body->oa as an input variable */
819 /* Check if client was evicted while we were doing i/o before touching
822 if (likely(!CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2)))
823 rc = target_bulk_io(exp, desc, &lwi);
828 /* Must commit after prep above in all cases */
829 rc = obd_commitrw(req->rq_svc_thread->t_env, OBD_BRW_READ, exp,
830 &repbody->oa, 1, ioo, remote_nb, npages, local_nb,
834 ost_drop_id(exp, &repbody->oa);
837 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
841 if (desc && !CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2))
842 ptlrpc_free_bulk(desc);
846 req->rq_status = nob;
847 ptlrpc_lprocfs_brw(req, nob);
848 target_committed_to_req(req);
850 } else if (!no_reply) {
851 /* Only reply if there was no comms problem with bulk */
852 target_committed_to_req(req);
856 /* reply out callback would free */
857 ptlrpc_req_drop_rs(req);
858 LCONSOLE_WARN("%s: Bulk IO read error with %s (at %s), "
859 "client will retry: rc %d\n",
860 exp->exp_obd->obd_name,
861 obd_uuid2str(&exp->exp_client_uuid),
862 obd_export_nid2str(exp), rc);
864 /* send a bulk after reply to simulate a network delay or reordering
866 if (unlikely(CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CLIENT_BULK_CB2))) {
868 struct l_wait_info lwi1;
870 CDEBUG(D_INFO, "reorder BULK\n");
871 cfs_waitq_init(&waitq);
873 lwi1 = LWI_TIMEOUT_INTR(cfs_time_seconds(3), NULL, NULL, NULL);
874 l_wait_event(waitq, 0, &lwi1);
875 rc = target_bulk_io(exp, desc, &lwi);
876 ptlrpc_free_bulk(desc);
882 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
884 struct ptlrpc_bulk_desc *desc = NULL;
885 struct obd_export *exp = req->rq_export;
886 struct niobuf_remote *remote_nb;
887 struct niobuf_local *local_nb;
888 struct obd_ioobj *ioo;
889 struct ost_body *body, *repbody;
890 struct l_wait_info lwi;
891 struct lustre_handle lockh = {0};
892 struct lustre_capa *capa = NULL;
894 int objcount, niocount, npages;
896 obd_count client_cksum = 0, server_cksum = 0;
897 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
898 int no_reply = 0, mmap = 0;
899 __u32 o_uid = 0, o_gid = 0;
900 struct ost_thread_local_cache *tls;
903 req->rq_bulk_write = 1;
905 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
906 GOTO(out, rc = -EIO);
907 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
908 GOTO(out, rc = -EFAULT);
910 /* pause before transaction has been started */
911 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
913 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
914 * ost_rw_hpreq_check(). */
915 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
917 GOTO(out, rc = -EFAULT);
919 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
920 RCL_CLIENT) / sizeof(*ioo);
921 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
923 GOTO(out, rc = -EFAULT);
925 rc = ost_validate_obdo(exp, &body->oa, ioo);
929 for (niocount = i = 0; i < objcount; i++)
930 niocount += ioo[i].ioo_bufcnt;
933 * It'd be nice to have a capsule function to indicate how many elements
934 * there were in a buffer for an RMF that's declared to be an array.
935 * It's easy enough to compute the number of elements here though.
937 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
938 if (remote_nb == NULL || niocount != (req_capsule_get_size(&req->rq_pill,
939 &RMF_NIOBUF_REMOTE, RCL_CLIENT) / sizeof(*remote_nb)))
940 GOTO(out, rc = -EFAULT);
942 if ((remote_nb[0].flags & OBD_BRW_MEMALLOC) &&
943 (exp->exp_connection->c_peer.nid == exp->exp_connection->c_self))
944 cfs_memory_pressure_set();
946 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
947 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
949 CERROR("Missing capability for OST BRW WRITE");
950 GOTO(out, rc = -EFAULT);
954 req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER,
955 niocount * sizeof(*rcs));
956 rc = req_capsule_server_pack(&req->rq_pill);
959 CFS_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, cfs_fail_val);
960 rcs = req_capsule_server_get(&req->rq_pill, &RMF_RCS);
962 tls = ost_tls_get(req);
964 GOTO(out_bulk, rc = -ENOMEM);
965 local_nb = tls->local;
967 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
972 * If getting the lock took more time than
973 * client was willing to wait, drop it. b=11330
975 if (cfs_time_current_sec() > req->rq_deadline ||
976 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
978 CERROR("Dropping timed-out write from %s because locking "
979 "object "LPX64" took %ld seconds (limit was %ld).\n",
980 libcfs_id2str(req->rq_peer), ioo->ioo_id,
981 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
982 req->rq_deadline - req->rq_arrival_time.tv_sec);
983 GOTO(out_lock, rc = -ETIMEDOUT);
986 /* obd_preprw clobbers oa->valid, so save what we need */
987 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
988 client_cksum = body->oa.o_cksum;
989 if (body->oa.o_valid & OBD_MD_FLFLAGS)
990 cksum_type = cksum_type_unpack(body->oa.o_flags);
992 if (body->oa.o_valid & OBD_MD_FLFLAGS && body->oa.o_flags & OBD_FL_MMAP)
995 /* Because we already sync grant info with client when reconnect,
996 * grant info will be cleared for resent req, then fed_grant and
997 * total_grant will not be modified in following preprw_write */
998 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
999 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1000 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1003 if (exp_connect_rmtclient(exp)) {
1004 o_uid = body->oa.o_uid;
1005 o_gid = body->oa.o_gid;
1008 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
1009 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1011 npages = OST_THREAD_POOL_SIZE;
1012 rc = obd_preprw(req->rq_svc_thread->t_env, OBD_BRW_WRITE, exp,
1013 &repbody->oa, objcount, ioo, remote_nb, &npages,
1014 local_nb, oti, capa);
1018 desc = ptlrpc_prep_bulk_exp(req, npages,
1019 BULK_GET_SINK, OST_BULK_PORTAL);
1021 GOTO(skip_transfer, rc = -ENOMEM);
1023 /* NB Having prepped, we must commit... */
1025 for (i = 0; i < npages; i++)
1026 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1027 local_nb[i].lnb_page_offset,
1030 rc = sptlrpc_svc_prep_bulk(req, desc);
1034 rc = target_bulk_io(exp, desc, &lwi);
1038 if (client_cksum != 0 && rc == 0) {
1039 static int cksum_counter;
1040 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1041 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1042 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1043 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1044 repbody->oa.o_cksum = server_cksum;
1046 if (unlikely(client_cksum != server_cksum)) {
1047 CDEBUG_LIMIT(mmap ? D_INFO : D_ERROR,
1048 "client csum %x, server csum %x\n",
1049 client_cksum, server_cksum);
1051 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1052 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1053 cksum_counter, libcfs_id2str(req->rq_peer),
1058 /* Must commit after prep above in all cases */
1059 rc = obd_commitrw(req->rq_svc_thread->t_env, OBD_BRW_WRITE, exp,
1060 &repbody->oa, objcount, ioo, remote_nb, npages,
1062 if (rc == -ENOTCONN)
1063 /* quota acquire process has been given up because
1064 * either the client has been evicted or the client
1065 * has timed out the request already */
1068 if (exp_connect_rmtclient(exp)) {
1069 repbody->oa.o_uid = o_uid;
1070 repbody->oa.o_gid = o_gid;
1074 * Disable sending mtime back to the client. If the client locked the
1075 * whole object, then it has already updated the mtime on its side,
1076 * otherwise it will have to glimpse anyway (see bug 21489, comment 32)
1078 repbody->oa.o_valid &= ~(OBD_MD_FLMTIME | OBD_MD_FLATIME);
1080 if (unlikely(client_cksum != server_cksum && rc == 0 && !mmap)) {
1081 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1086 if (new_cksum == server_cksum)
1087 msg = "changed in transit before arrival at OST";
1088 else if (new_cksum == client_cksum)
1089 msg = "initial checksum before message complete";
1091 msg = "changed in transit AND after initial checksum";
1093 if (req->rq_peer.nid == desc->bd_sender) {
1097 router = libcfs_nid2str(desc->bd_sender);
1100 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1101 "%s%s%s inode "DFID" object "
1102 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1103 exp->exp_obd->obd_name, msg,
1104 libcfs_id2str(req->rq_peer),
1106 body->oa.o_valid & OBD_MD_FLFID ?
1107 body->oa.o_parent_seq : (__u64)0,
1108 body->oa.o_valid & OBD_MD_FLFID ?
1109 body->oa.o_parent_oid : 0,
1110 body->oa.o_valid & OBD_MD_FLFID ?
1111 body->oa.o_parent_ver : 0,
1113 body->oa.o_valid & OBD_MD_FLGROUP ?
1114 body->oa.o_seq : (__u64)0,
1115 local_nb[0].lnb_file_offset,
1116 local_nb[npages-1].lnb_file_offset +
1117 local_nb[npages-1].len - 1 );
1118 CERROR("client csum %x, original server csum %x, "
1119 "server csum now %x\n",
1120 client_cksum, server_cksum, new_cksum);
1126 /* set per-requested niobuf return codes */
1127 for (i = j = 0; i < niocount; i++) {
1128 int len = remote_nb[i].len;
1133 LASSERT(j < npages);
1134 if (local_nb[j].rc < 0)
1135 rcs[i] = local_nb[j].rc;
1136 len -= local_nb[j].len;
1141 LASSERT(j == npages);
1142 ptlrpc_lprocfs_brw(req, nob);
1146 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1151 ptlrpc_free_bulk(desc);
1154 oti_to_request(oti, req);
1155 target_committed_to_req(req);
1156 rc = ptlrpc_reply(req);
1157 } else if (!no_reply) {
1158 /* Only reply if there was no comms problem with bulk */
1159 target_committed_to_req(req);
1160 req->rq_status = rc;
1163 /* reply out callback would free */
1164 ptlrpc_req_drop_rs(req);
1165 LCONSOLE_WARN("%s: Bulk IO write error with %s (at %s), "
1166 "client will retry: rc %d\n",
1167 exp->exp_obd->obd_name,
1168 obd_uuid2str(&exp->exp_client_uuid),
1169 obd_export_nid2str(exp), rc);
1171 cfs_memory_pressure_clr();
1176 * Implementation of OST_SET_INFO.
1178 * OST_SET_INFO is like ioctl(): heavily overloaded. Specifically, it takes a
1179 * "key" and a value RPC buffers as arguments, with the value's contents
1180 * interpreted according to the key.
1182 * Value types that need swabbing have swabbing done explicitly, either here or
1183 * in functions called from here. This should be corrected: all swabbing should
1184 * be done in the capsule abstraction, as that will then allow us to move
1185 * swabbing exclusively to the client without having to modify server code
1186 * outside the capsule abstraction's implementation itself. To correct this
1187 * will require minor changes to the capsule abstraction; see the comments for
1188 * req_capsule_extend() in layout.c.
1190 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1192 struct ost_body *body = NULL, *repbody;
1193 char *key, *val = NULL;
1194 int keylen, vallen, rc = 0;
1195 int is_grant_shrink = 0;
1198 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1200 DEBUG_REQ(D_HA, req, "no set_info key");
1203 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1206 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1209 if ((is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK)))
1210 /* In this case the value is actually an RMF_OST_BODY, so we
1211 * transmutate the type of this PTLRPC */
1212 req_capsule_extend(&req->rq_pill, &RQF_OST_SET_GRANT_INFO);
1214 rc = req_capsule_server_pack(&req->rq_pill);
1219 if (is_grant_shrink) {
1220 body = req_capsule_client_get(&req->rq_pill,
1225 repbody = req_capsule_server_get(&req->rq_pill,
1227 memcpy(repbody, body, sizeof(*body));
1228 val = (char*)repbody;
1230 val = req_capsule_client_get(&req->rq_pill,
1235 if (KEY_IS(KEY_EVICT_BY_NID)) {
1237 obd_export_evict_by_nid(exp->exp_obd, val);
1239 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1240 if (vallen < sizeof(__u32))
1242 __swab32s((__u32 *)val);
1245 /* OBD will also check if KEY_IS(KEY_GRANT_SHRINK), and will cast val to
1246 * a struct ost_body * value */
1247 rc = obd_set_info_async(req->rq_svc_thread->t_env, exp, keylen,
1248 key, vallen, val, NULL);
1250 lustre_msg_set_status(req->rq_repmsg, 0);
1254 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1257 int keylen, replylen, rc = 0;
1258 struct req_capsule *pill = &req->rq_pill;
1261 /* this common part for get_info rpc */
1262 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1264 DEBUG_REQ(D_HA, req, "no get_info key");
1267 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1269 if (KEY_IS(KEY_FIEMAP)) {
1270 struct ll_fiemap_info_key *fm_key = key;
1273 rc = ost_validate_obdo(exp, &fm_key->oa, NULL);
1278 rc = obd_get_info(req->rq_svc_thread->t_env, exp, keylen, key,
1279 &replylen, NULL, NULL);
1283 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1284 RCL_SERVER, replylen);
1286 rc = req_capsule_server_pack(pill);
1290 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1294 /* call again to fill in the reply buffer */
1295 rc = obd_get_info(req->rq_svc_thread->t_env, exp, keylen, key,
1296 &replylen, reply, NULL);
1298 lustre_msg_set_status(req->rq_repmsg, 0);
1302 static int ost_handle_quotactl(struct ptlrpc_request *req)
1304 struct obd_quotactl *oqctl, *repoqc;
1308 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1310 GOTO(out, rc = -EPROTO);
1312 rc = req_capsule_server_pack(&req->rq_pill);
1316 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1317 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1324 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1326 struct obd_quotactl *oqctl;
1330 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1334 rc = req_capsule_server_pack(&req->rq_pill);
1338 /* deprecated, not used any more */
1339 req->rq_status = -EOPNOTSUPP;
1340 RETURN(-EOPNOTSUPP);
1343 static int ost_llog_handle_connect(struct obd_export *exp,
1344 struct ptlrpc_request *req)
1346 struct llogd_conn_body *body;
1350 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
1351 rc = obd_llog_connect(exp, body);
1355 #define ost_init_sec_none(reply, exp) \
1357 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1358 OBD_CONNECT_RMT_CLIENT_FORCE | \
1359 OBD_CONNECT_OSS_CAPA); \
1360 cfs_spin_lock(&exp->exp_lock); \
1361 exp->exp_connect_flags = reply->ocd_connect_flags; \
1362 cfs_spin_unlock(&exp->exp_lock); \
1365 static int ost_init_sec_level(struct ptlrpc_request *req)
1367 struct obd_export *exp = req->rq_export;
1368 struct req_capsule *pill = &req->rq_pill;
1369 struct obd_device *obd = exp->exp_obd;
1370 struct filter_obd *filter = &obd->u.filter;
1371 char *client = libcfs_nid2str(req->rq_peer.nid);
1372 struct obd_connect_data *data, *reply;
1376 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1377 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1378 if (data == NULL || reply == NULL)
1381 /* connection from MDT is always trusted */
1382 if (req->rq_auth_usr_mdt) {
1383 ost_init_sec_none(reply, exp);
1387 /* no GSS support case */
1388 if (!req->rq_auth_gss) {
1389 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1390 CWARN("client %s -> target %s does not user GSS, "
1391 "can not run under security level %d.\n",
1392 client, obd->obd_name, filter->fo_sec_level);
1395 ost_init_sec_none(reply, exp);
1400 /* old version case */
1401 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1402 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1403 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1404 CWARN("client %s -> target %s uses old version, "
1405 "can not run under security level %d.\n",
1406 client, obd->obd_name, filter->fo_sec_level);
1409 CWARN("client %s -> target %s uses old version, "
1410 "run under security level %d.\n",
1411 client, obd->obd_name, filter->fo_sec_level);
1412 ost_init_sec_none(reply, exp);
1417 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1419 if (!req->rq_auth_remote)
1420 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1421 "asked to be remote.\n", client, obd->obd_name);
1422 } else if (req->rq_auth_remote) {
1424 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1425 "as remote by default.\n", client, obd->obd_name);
1429 if (!filter->fo_fl_oss_capa) {
1430 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1431 " but OSS capabilities are not enabled: %d.\n",
1432 client, obd->obd_name, filter->fo_fl_oss_capa);
1437 switch (filter->fo_sec_level) {
1438 case LUSTRE_SEC_NONE:
1440 ost_init_sec_none(reply, exp);
1443 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1444 "can not run under security level %d.\n",
1445 client, obd->obd_name, filter->fo_sec_level);
1448 case LUSTRE_SEC_REMOTE:
1450 ost_init_sec_none(reply, exp);
1452 case LUSTRE_SEC_ALL:
1454 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1455 OBD_CONNECT_RMT_CLIENT_FORCE);
1456 if (!filter->fo_fl_oss_capa)
1457 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1459 cfs_spin_lock(&exp->exp_lock);
1460 exp->exp_connect_flags = reply->ocd_connect_flags;
1461 cfs_spin_unlock(&exp->exp_lock);
1473 * this should be done in filter_connect()/filter_reconnect(), but
1474 * we can't obtain information like NID, which stored in incoming
1475 * request, thus can't decide what flavor to use. so we do it here.
1477 * This hack should be removed after the OST stack be rewritten, just
1478 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1480 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1482 struct obd_export *exp = req->rq_export;
1483 struct filter_obd *filter = &exp->exp_obd->u.filter;
1484 struct sptlrpc_flavor flvr;
1487 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1488 LUSTRE_ECHO_NAME) == 0)) {
1489 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1493 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1494 cfs_read_lock(&filter->fo_sptlrpc_lock);
1495 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1499 cfs_read_unlock(&filter->fo_sptlrpc_lock);
1501 cfs_spin_lock(&exp->exp_lock);
1503 exp->exp_sp_peer = req->rq_sp_from;
1504 exp->exp_flvr = flvr;
1506 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1507 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1508 CERROR("unauthorized rpc flavor %x from %s, "
1509 "expect %x\n", req->rq_flvr.sf_rpc,
1510 libcfs_nid2str(req->rq_peer.nid),
1511 exp->exp_flvr.sf_rpc);
1515 cfs_spin_unlock(&exp->exp_lock);
1517 if (exp->exp_sp_peer != req->rq_sp_from) {
1518 CERROR("RPC source %s doesn't match %s\n",
1519 sptlrpc_part2name(req->rq_sp_from),
1520 sptlrpc_part2name(exp->exp_sp_peer));
1523 rc = sptlrpc_target_export_check(exp, req);
1530 /* Ensure that data and metadata are synced to the disk when lock is cancelled
1532 int ost_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
1533 void *data, int flag)
1536 __u32 sync_lock_cancel = 0;
1537 __u32 len = sizeof(sync_lock_cancel);
1542 rc = lu_env_init(&env, LCT_DT_THREAD);
1543 if (unlikely(rc != 0))
1546 rc = obd_get_info(&env, lock->l_export, sizeof(KEY_SYNC_LOCK_CANCEL),
1547 KEY_SYNC_LOCK_CANCEL, &len, &sync_lock_cancel, NULL);
1548 if (rc == 0 && flag == LDLM_CB_CANCELING &&
1549 (lock->l_granted_mode & (LCK_PW|LCK_GROUP)) &&
1550 (sync_lock_cancel == ALWAYS_SYNC_ON_CANCEL ||
1551 (sync_lock_cancel == BLOCKING_SYNC_ON_CANCEL &&
1552 lock->l_flags & LDLM_FL_CBPENDING))) {
1553 struct obd_info *oinfo;
1557 OBD_ALLOC_PTR(oinfo);
1559 GOTO(out_env, rc = -ENOMEM);
1562 OBD_FREE_PTR(oinfo);
1563 GOTO(out_env, rc = -ENOMEM);
1565 oa->o_id = lock->l_resource->lr_name.name[0];
1566 oa->o_seq = lock->l_resource->lr_name.name[1];
1567 oa->o_valid = OBD_MD_FLID|OBD_MD_FLGROUP;
1569 oinfo->oi_capa = BYPASS_CAPA;
1571 rc = obd_sync(&env, lock->l_export, oinfo,
1572 lock->l_policy_data.l_extent.start,
1573 lock->l_policy_data.l_extent.end, NULL);
1575 CERROR("Error %d syncing data on lock cancel\n", rc);
1578 OBD_FREE_PTR(oinfo);
1581 rc = ldlm_server_blocking_ast(lock, desc, data, flag);
1587 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1588 struct obd_device *obd, int *process)
1590 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1591 case OST_CONNECT: /* This will never get here, but for completeness. */
1592 case OST_DISCONNECT:
1603 case OBD_LOG_CANCEL:
1605 *process = target_queue_recovery_request(req, obd);
1609 DEBUG_REQ(D_WARNING, req, "not permitted during recovery");
1615 int ost_msg_check_version(struct lustre_msg *msg)
1619 switch(lustre_msg_get_opc(msg)) {
1621 case OST_DISCONNECT:
1624 case SEC_CTX_INIT_CONT:
1626 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1628 CERROR("bad opc %u version %08x, expecting %08x\n",
1629 lustre_msg_get_opc(msg),
1630 lustre_msg_get_version(msg),
1631 LUSTRE_OBD_VERSION);
1644 case OST_QUOTACHECK:
1646 case OST_QUOTA_ADJUST_QUNIT:
1647 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1649 CERROR("bad opc %u version %08x, expecting %08x\n",
1650 lustre_msg_get_opc(msg),
1651 lustre_msg_get_version(msg),
1652 LUSTRE_OST_VERSION);
1657 case LDLM_BL_CALLBACK:
1658 case LDLM_CP_CALLBACK:
1659 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1661 CERROR("bad opc %u version %08x, expecting %08x\n",
1662 lustre_msg_get_opc(msg),
1663 lustre_msg_get_version(msg),
1664 LUSTRE_DLM_VERSION);
1666 case LLOG_ORIGIN_CONNECT:
1667 case OBD_LOG_CANCEL:
1668 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1670 CERROR("bad opc %u version %08x, expecting %08x\n",
1671 lustre_msg_get_opc(msg),
1672 lustre_msg_get_version(msg),
1673 LUSTRE_LOG_VERSION);
1676 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1682 struct ost_prolong_data {
1683 struct ptlrpc_request *opd_req;
1684 struct obd_export *opd_exp;
1685 struct obdo *opd_oa;
1686 struct ldlm_res_id opd_resid;
1687 struct ldlm_extent opd_extent;
1688 ldlm_mode_t opd_mode;
1689 unsigned int opd_locks;
1693 /* prolong locks for the current service time of the corresponding
1694 * portal (= OST_IO_PORTAL)
1696 static inline int prolong_timeout(struct ptlrpc_request *req)
1698 struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
1701 return obd_timeout / 2;
1703 return max(at_est2timeout(at_get(&svcpt->scp_at_estimate)),
1707 static void ost_prolong_lock_one(struct ost_prolong_data *opd,
1708 struct ldlm_lock *lock)
1710 LASSERT(lock->l_export == opd->opd_exp);
1712 if (lock->l_destroyed) /* lock already cancelled */
1715 /* XXX: never try to grab resource lock here because we're inside
1716 * exp_bl_list_lock; in ldlm_lockd.c to handle waiting list we take
1717 * res lock and then exp_bl_list_lock. */
1719 if (!(lock->l_flags & LDLM_FL_AST_SENT))
1720 /* ignore locks not being cancelled */
1724 "refreshed for req x"LPU64" ext("LPU64"->"LPU64") to %ds.\n",
1725 opd->opd_req->rq_xid, opd->opd_extent.start,
1726 opd->opd_extent.end, opd->opd_timeout);
1728 /* OK. this is a possible lock the user holds doing I/O
1729 * let's refresh eviction timer for it */
1730 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
1734 static void ost_prolong_locks(struct ost_prolong_data *data)
1736 struct obd_export *exp = data->opd_exp;
1737 struct obdo *oa = data->opd_oa;
1738 struct ldlm_lock *lock;
1741 if (oa->o_valid & OBD_MD_FLHANDLE) {
1742 /* mostly a request should be covered by only one lock, try
1744 lock = ldlm_handle2lock(&oa->o_handle);
1746 /* Fast path to check if the lock covers the whole IO
1747 * region exclusively. */
1748 if (lock->l_granted_mode == LCK_PW &&
1749 ldlm_extent_contain(&lock->l_policy_data.l_extent,
1750 &data->opd_extent)) {
1752 ost_prolong_lock_one(data, lock);
1753 LDLM_LOCK_PUT(lock);
1756 LDLM_LOCK_PUT(lock);
1761 cfs_spin_lock_bh(&exp->exp_bl_list_lock);
1762 cfs_list_for_each_entry(lock, &exp->exp_bl_list, l_exp_list) {
1763 LASSERT(lock->l_flags & LDLM_FL_AST_SENT);
1764 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
1766 if (!ldlm_res_eq(&data->opd_resid, &lock->l_resource->lr_name))
1769 if (!ldlm_extent_overlap(&lock->l_policy_data.l_extent,
1773 ost_prolong_lock_one(data, lock);
1775 cfs_spin_unlock_bh(&exp->exp_bl_list_lock);
1781 * Returns 1 if the given PTLRPC matches the given LDLM locks, or 0 if it does
1784 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1785 struct ldlm_lock *lock)
1787 struct niobuf_remote *nb;
1788 struct obd_ioobj *ioo;
1790 struct ldlm_extent ext;
1793 opc = lustre_msg_get_opc(req->rq_reqmsg);
1794 LASSERT(opc == OST_READ || opc == OST_WRITE);
1796 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1797 LASSERT(ioo != NULL);
1799 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1800 LASSERT(nb != NULL);
1802 ext.start = nb->offset;
1803 nb += ioo->ioo_bufcnt - 1;
1804 ext.end = nb->offset + nb->len - 1;
1806 LASSERT(lock->l_resource != NULL);
1807 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_seq,
1808 &lock->l_resource->lr_name))
1812 if (opc == OST_READ)
1814 if (!(lock->l_granted_mode & mode))
1817 RETURN(ldlm_extent_overlap(&lock->l_policy_data.l_extent, &ext));
1821 * High-priority queue request check for whether the given PTLRPC request (\a
1822 * req) is blocking an LDLM lock cancel.
1824 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1825 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1827 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1828 * function looks only at OST_READs and OST_WRITEs.
1830 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1832 struct obd_device *obd = req->rq_export->exp_obd;
1833 struct ost_body *body;
1834 struct obd_ioobj *ioo;
1835 struct niobuf_remote *nb;
1836 struct ost_prolong_data opd = { 0 };
1841 * Use LASSERT to do sanity check because malformed RPCs should have
1842 * been filtered out in ost_hpreq_handler().
1844 opc = lustre_msg_get_opc(req->rq_reqmsg);
1845 LASSERT(opc == OST_READ || opc == OST_WRITE);
1847 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1848 LASSERT(body != NULL);
1850 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1851 LASSERT(ioo != NULL);
1853 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1854 LASSERT(nb != NULL);
1855 LASSERT(!(nb->flags & OBD_BRW_SRVLOCK));
1857 osc_build_res_name(ioo->ioo_id, ioo->ioo_seq, &opd.opd_resid);
1861 if (opc == OST_READ)
1863 opd.opd_mode = mode;
1864 opd.opd_exp = req->rq_export;
1865 opd.opd_oa = &body->oa;
1866 opd.opd_extent.start = nb->offset;
1867 nb += ioo->ioo_bufcnt - 1;
1868 opd.opd_extent.end = nb->offset + nb->len - 1;
1869 opd.opd_timeout = prolong_timeout(req);
1871 DEBUG_REQ(D_RPCTRACE, req,
1872 "%s %s: refresh rw locks: " LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1873 obd->obd_name, cfs_current()->comm,
1874 opd.opd_resid.name[0], opd.opd_resid.name[1],
1875 opd.opd_extent.start, opd.opd_extent.end);
1877 ost_prolong_locks(&opd);
1879 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
1880 obd->obd_name, opd.opd_locks, req);
1882 RETURN(opd.opd_locks);
1885 static void ost_rw_hpreq_fini(struct ptlrpc_request *req)
1887 (void)ost_rw_hpreq_check(req);
1891 * Like ost_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
1893 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1894 struct ldlm_lock *lock)
1896 struct ost_body *body;
1899 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1900 LASSERT(body != NULL);
1902 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1903 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1910 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
1912 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1914 struct obd_device *obd = req->rq_export->exp_obd;
1915 struct ost_body *body;
1917 struct ost_prolong_data opd = { 0 };
1921 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1922 LASSERT(body != NULL);
1925 LASSERT(!(oa->o_valid & OBD_MD_FLFLAGS) ||
1926 !(oa->o_flags & OBD_FL_SRVLOCK));
1929 end = start + oa->o_blocks;
1932 opd.opd_mode = LCK_PW;
1933 opd.opd_exp = req->rq_export;
1935 opd.opd_extent.start = start;
1936 opd.opd_extent.end = end;
1937 if (oa->o_blocks == OBD_OBJECT_EOF)
1938 opd.opd_extent.end = OBD_OBJECT_EOF;
1939 opd.opd_timeout = prolong_timeout(req);
1941 osc_build_res_name(oa->o_id, oa->o_seq, &opd.opd_resid);
1944 "%s: refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1946 opd.opd_resid.name[0], opd.opd_resid.name[1],
1947 opd.opd_extent.start, opd.opd_extent.end);
1949 ost_prolong_locks(&opd);
1951 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
1952 obd->obd_name, opd.opd_locks, req);
1954 RETURN(opd.opd_locks > 0);
1957 static void ost_punch_hpreq_fini(struct ptlrpc_request *req)
1959 (void)ost_punch_hpreq_check(req);
1962 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
1963 .hpreq_lock_match = ost_rw_hpreq_lock_match,
1964 .hpreq_check = ost_rw_hpreq_check,
1965 .hpreq_fini = ost_rw_hpreq_fini
1968 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
1969 .hpreq_lock_match = ost_punch_hpreq_lock_match,
1970 .hpreq_check = ost_punch_hpreq_check,
1971 .hpreq_fini = ost_punch_hpreq_fini
1974 /** Assign high priority operations to the request if needed. */
1975 static int ost_hpreq_handler(struct ptlrpc_request *req)
1978 if (req->rq_export) {
1979 int opc = lustre_msg_get_opc(req->rq_reqmsg);
1980 struct ost_body *body;
1982 if (opc == OST_READ || opc == OST_WRITE) {
1983 struct niobuf_remote *nb;
1984 struct obd_ioobj *ioo;
1985 int objcount, niocount;
1989 /* RPCs on the H-P queue can be inspected before
1990 * ost_handler() initializes their pills, so we
1991 * initialize that here. Capsule initialization is
1992 * idempotent, as is setting the pill's format (provided
1993 * it doesn't change).
1995 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1996 if (opc == OST_READ)
1997 req_capsule_set(&req->rq_pill,
2000 req_capsule_set(&req->rq_pill,
2001 &RQF_OST_BRW_WRITE);
2003 body = req_capsule_client_get(&req->rq_pill,
2006 CERROR("Missing/short ost_body\n");
2010 objcount = req_capsule_get_size(&req->rq_pill,
2014 if (objcount == 0) {
2015 CERROR("Missing/short ioobj\n");
2019 CERROR("too many ioobjs (%d)\n", objcount);
2023 ioo = req_capsule_client_get(&req->rq_pill,
2026 CERROR("Missing/short ioobj\n");
2030 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
2032 CERROR("invalid object ids\n");
2036 for (niocount = i = 0; i < objcount; i++) {
2037 if (ioo[i].ioo_bufcnt == 0) {
2038 CERROR("ioo[%d] has zero bufcnt\n", i);
2041 niocount += ioo[i].ioo_bufcnt;
2043 if (niocount > PTLRPC_MAX_BRW_PAGES) {
2044 DEBUG_REQ(D_RPCTRACE, req,
2045 "bulk has too many pages (%d)",
2050 nb = req_capsule_client_get(&req->rq_pill,
2051 &RMF_NIOBUF_REMOTE);
2053 CERROR("Missing/short niobuf\n");
2057 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
2058 req->rq_ops = &ost_hpreq_rw;
2059 } else if (opc == OST_PUNCH) {
2060 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2061 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2063 body = req_capsule_client_get(&req->rq_pill,
2066 CERROR("Missing/short ost_body\n");
2070 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
2071 !(body->oa.o_flags & OBD_FL_SRVLOCK))
2072 req->rq_ops = &ost_hpreq_punch;
2078 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
2079 int ost_handle(struct ptlrpc_request *req)
2081 struct obd_trans_info trans_info = { 0, };
2082 struct obd_trans_info *oti = &trans_info;
2083 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
2084 struct obd_device *obd = NULL;
2087 /* OST module is kept between remounts, but the last reference
2088 * to specific module (say, osd or ofd) kills all related keys
2089 * from the environment. so we have to refill it until the root
2090 * cause is fixed properly */
2091 lu_env_refill(req->rq_svc_thread->t_env);
2093 LASSERT(current->journal_info == NULL);
2095 /* primordial rpcs don't affect server recovery */
2096 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2098 case SEC_CTX_INIT_CONT:
2103 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2105 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
2106 if (!class_connected_export(req->rq_export)) {
2107 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
2108 lustre_msg_get_opc(req->rq_reqmsg),
2109 libcfs_id2str(req->rq_peer));
2110 req->rq_status = -ENOTCONN;
2111 GOTO(out, rc = -ENOTCONN);
2114 obd = req->rq_export->exp_obd;
2116 /* Check for aborted recovery. */
2117 if (obd->obd_recovering) {
2118 rc = ost_filter_recovery_request(req, obd,
2120 if (rc || !should_process)
2122 else if (should_process < 0) {
2123 req->rq_status = should_process;
2124 rc = ptlrpc_error(req);
2132 rc = ost_msg_check_version(req->rq_reqmsg);
2136 if (req && req->rq_reqmsg && req->rq_export &&
2137 (req->rq_export->exp_connect_flags & OBD_CONNECT_JOBSTATS))
2138 oti->oti_jobid = lustre_msg_get_jobid(req->rq_reqmsg);
2140 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2142 CDEBUG(D_INODE, "connect\n");
2143 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
2144 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
2146 rc = target_handle_connect(req);
2147 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
2150 rc = ost_init_sec_level(req);
2152 rc = ost_connect_check_sptlrpc(req);
2156 case OST_DISCONNECT:
2157 CDEBUG(D_INODE, "disconnect\n");
2158 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
2159 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
2161 rc = target_handle_disconnect(req);
2164 CDEBUG(D_INODE, "create\n");
2165 req_capsule_set(&req->rq_pill, &RQF_OST_CREATE);
2166 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
2168 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2169 GOTO(out, rc = -EROFS);
2170 rc = ost_create(req->rq_export, req, oti);
2173 CDEBUG(D_INODE, "destroy\n");
2174 req_capsule_set(&req->rq_pill, &RQF_OST_DESTROY);
2175 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
2177 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2178 GOTO(out, rc = -EROFS);
2179 rc = ost_destroy(req->rq_export, req, oti);
2182 CDEBUG(D_INODE, "getattr\n");
2183 req_capsule_set(&req->rq_pill, &RQF_OST_GETATTR);
2184 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
2186 rc = ost_getattr(req->rq_export, req);
2189 CDEBUG(D_INODE, "setattr\n");
2190 req_capsule_set(&req->rq_pill, &RQF_OST_SETATTR);
2191 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
2193 rc = ost_setattr(req->rq_export, req, oti);
2196 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_WRITE);
2197 CDEBUG(D_INODE, "write\n");
2198 /* req->rq_request_portal would be nice, if it was set */
2199 if (ptlrpc_req2svc(req)->srv_req_portal != OST_IO_PORTAL) {
2200 CERROR("%s: deny write request from %s to portal %u\n",
2201 req->rq_export->exp_obd->obd_name,
2202 obd_export_nid2str(req->rq_export),
2203 ptlrpc_req2svc(req)->srv_req_portal);
2204 GOTO(out, rc = -EPROTO);
2206 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2208 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
2209 GOTO(out, rc = -ENOSPC);
2210 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2211 GOTO(out, rc = -EROFS);
2212 rc = ost_brw_write(req, oti);
2213 LASSERT(current->journal_info == NULL);
2214 /* ost_brw_write sends its own replies */
2217 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_READ);
2218 CDEBUG(D_INODE, "read\n");
2219 /* req->rq_request_portal would be nice, if it was set */
2220 if (ptlrpc_req2svc(req)->srv_req_portal != OST_IO_PORTAL) {
2221 CERROR("%s: deny read request from %s to portal %u\n",
2222 req->rq_export->exp_obd->obd_name,
2223 obd_export_nid2str(req->rq_export),
2224 ptlrpc_req2svc(req)->srv_req_portal);
2225 GOTO(out, rc = -EPROTO);
2227 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2229 rc = ost_brw_read(req, oti);
2230 LASSERT(current->journal_info == NULL);
2231 /* ost_brw_read sends its own replies */
2234 CDEBUG(D_INODE, "punch\n");
2235 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2236 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2238 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2239 GOTO(out, rc = -EROFS);
2240 rc = ost_punch(req->rq_export, req, oti);
2243 CDEBUG(D_INODE, "statfs\n");
2244 req_capsule_set(&req->rq_pill, &RQF_OST_STATFS);
2245 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2247 rc = ost_statfs(req);
2250 CDEBUG(D_INODE, "sync\n");
2251 req_capsule_set(&req->rq_pill, &RQF_OST_SYNC);
2252 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2254 rc = ost_sync(req->rq_export, req, oti);
2257 DEBUG_REQ(D_INODE, req, "set_info");
2258 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
2259 rc = ost_set_info(req->rq_export, req);
2262 DEBUG_REQ(D_INODE, req, "get_info");
2263 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
2264 rc = ost_get_info(req->rq_export, req);
2266 case OST_QUOTACHECK:
2267 CDEBUG(D_INODE, "quotacheck\n");
2268 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2269 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2271 rc = ost_handle_quotacheck(req);
2274 CDEBUG(D_INODE, "quotactl\n");
2275 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2276 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2278 rc = ost_handle_quotactl(req);
2281 DEBUG_REQ(D_INODE, req, "ping");
2282 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2283 rc = target_handle_ping(req);
2285 /* FIXME - just reply status */
2286 case LLOG_ORIGIN_CONNECT:
2287 DEBUG_REQ(D_INODE, req, "log connect");
2288 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2289 rc = ost_llog_handle_connect(req->rq_export, req);
2290 req->rq_status = rc;
2291 rc = req_capsule_server_pack(&req->rq_pill);
2294 RETURN(ptlrpc_reply(req));
2295 case OBD_LOG_CANCEL:
2296 CDEBUG(D_INODE, "log cancel\n");
2297 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2298 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2300 rc = llog_origin_handle_cancel(req);
2301 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2303 req->rq_status = rc;
2304 rc = req_capsule_server_pack(&req->rq_pill);
2307 RETURN(ptlrpc_reply(req));
2309 CDEBUG(D_INODE, "enqueue\n");
2310 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2311 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2313 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2315 ldlm_server_glimpse_ast);
2316 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2319 CDEBUG(D_INODE, "convert\n");
2320 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2321 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2323 rc = ldlm_handle_convert(req);
2326 CDEBUG(D_INODE, "cancel\n");
2327 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2328 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2330 rc = ldlm_handle_cancel(req);
2332 case LDLM_BL_CALLBACK:
2333 case LDLM_CP_CALLBACK:
2334 CDEBUG(D_INODE, "callback\n");
2335 CERROR("callbacks should not happen on OST\n");
2338 CERROR("Unexpected opcode %d\n",
2339 lustre_msg_get_opc(req->rq_reqmsg));
2340 req->rq_status = -ENOTSUPP;
2341 rc = ptlrpc_error(req);
2345 LASSERT(current->journal_info == NULL);
2348 /* If we're DISCONNECTing, the export_data is already freed */
2349 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2350 target_committed_to_req(req);
2354 oti_to_request(oti, req);
2356 target_send_reply(req, rc, fail);
2359 EXPORT_SYMBOL(ost_handle);
2361 * free per-thread pool created by ost_thread_init().
2363 static void ost_thread_done(struct ptlrpc_thread *thread)
2365 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2370 LASSERT(thread != NULL);
2373 * be prepared to handle partially-initialized pools (because this is
2374 * called from ost_thread_init() for cleanup.
2376 tls = thread->t_data;
2379 thread->t_data = NULL;
2385 * initialize per-thread page pool (bug 5137).
2387 static int ost_thread_init(struct ptlrpc_thread *thread)
2389 struct ost_thread_local_cache *tls;
2393 LASSERT(thread != NULL);
2394 LASSERT(thread->t_data == NULL);
2399 thread->t_data = tls;
2403 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2405 static struct cfs_cpt_table *ost_io_cptable;
2407 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2408 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2410 static struct ptlrpc_service_conf svc_conf;
2411 struct ost_obd *ost = &obd->u.ost;
2412 struct lprocfs_static_vars lvars;
2417 rc = cfs_cleanup_group_info();
2421 lprocfs_ost_init_vars(&lvars);
2422 lprocfs_obd_setup(obd, lvars.obd_vars);
2424 cfs_mutex_init(&ost->ost_health_mutex);
2426 svc_conf = (typeof(svc_conf)) {
2427 .psc_name = LUSTRE_OSS_NAME,
2428 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
2430 .bc_nbufs = OST_NBUFS,
2431 .bc_buf_size = OST_BUFSIZE,
2432 .bc_req_max_size = OST_MAXREQSIZE,
2433 .bc_rep_max_size = OST_MAXREPSIZE,
2434 .bc_req_portal = OST_REQUEST_PORTAL,
2435 .bc_rep_portal = OSC_REPLY_PORTAL,
2438 .tc_thr_name = "ll_ost",
2439 .tc_thr_factor = OSS_THR_FACTOR,
2440 .tc_nthrs_init = OSS_NTHRS_INIT,
2441 .tc_nthrs_base = OSS_NTHRS_BASE,
2442 .tc_nthrs_max = OSS_NTHRS_MAX,
2443 .tc_nthrs_user = oss_num_threads,
2444 .tc_cpu_affinity = 1,
2445 .tc_ctx_tags = LCT_DT_THREAD,
2448 .cc_pattern = oss_cpts,
2451 .so_req_handler = ost_handle,
2452 .so_req_printer = target_print_req,
2453 .so_hpreq_handler = ptlrpc_hpreq_handler,
2456 ost->ost_service = ptlrpc_register_service(&svc_conf,
2457 obd->obd_proc_entry);
2458 if (IS_ERR(ost->ost_service)) {
2459 rc = PTR_ERR(ost->ost_service);
2460 CERROR("failed to start service: %d\n", rc);
2461 GOTO(out_lprocfs, rc);
2464 memset(&svc_conf, 0, sizeof(svc_conf));
2465 svc_conf = (typeof(svc_conf)) {
2466 .psc_name = "ost_create",
2467 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
2469 .bc_nbufs = OST_NBUFS,
2470 .bc_buf_size = OST_BUFSIZE,
2471 .bc_req_max_size = OST_MAXREQSIZE,
2472 .bc_rep_max_size = OST_MAXREPSIZE,
2473 .bc_req_portal = OST_CREATE_PORTAL,
2474 .bc_rep_portal = OSC_REPLY_PORTAL,
2477 .tc_thr_name = "ll_ost_create",
2478 .tc_thr_factor = OSS_CR_THR_FACTOR,
2479 .tc_nthrs_init = OSS_CR_NTHRS_INIT,
2480 .tc_nthrs_base = OSS_CR_NTHRS_BASE,
2481 .tc_nthrs_max = OSS_CR_NTHRS_MAX,
2482 .tc_nthrs_user = oss_num_create_threads,
2483 .tc_cpu_affinity = 1,
2484 .tc_ctx_tags = LCT_DT_THREAD,
2487 .cc_pattern = oss_cpts,
2490 .so_req_handler = ost_handle,
2491 .so_req_printer = target_print_req,
2492 .so_hpreq_handler = NULL,
2495 ost->ost_create_service = ptlrpc_register_service(&svc_conf,
2496 obd->obd_proc_entry);
2497 if (IS_ERR(ost->ost_create_service)) {
2498 rc = PTR_ERR(ost->ost_create_service);
2499 CERROR("failed to start OST create service: %d\n", rc);
2500 GOTO(out_service, rc);
2503 mask = cfs_cpt_table->ctb_nodemask;
2504 /* event CPT feature is disabled in libcfs level by set partition
2505 * number to 1, we still want to set node affinity for io service */
2506 if (cfs_cpt_number(cfs_cpt_table) == 1 && nodes_weight(*mask) > 1) {
2510 ost_io_cptable = cfs_cpt_table_alloc(nodes_weight(*mask));
2511 for_each_node_mask(i, *mask) {
2512 if (ost_io_cptable == NULL) {
2513 CWARN("OSS failed to create CPT table\n");
2517 rc = cfs_cpt_set_node(ost_io_cptable, cpt++, i);
2519 CWARN("OSS Failed to set node %d for"
2520 "IO CPT table\n", i);
2521 cfs_cpt_table_free(ost_io_cptable);
2522 ost_io_cptable = NULL;
2528 memset(&svc_conf, 0, sizeof(svc_conf));
2529 svc_conf = (typeof(svc_conf)) {
2530 .psc_name = "ost_io",
2531 .psc_watchdog_factor = OSS_SERVICE_WATCHDOG_FACTOR,
2533 .bc_nbufs = OST_NBUFS,
2534 .bc_buf_size = OST_BUFSIZE,
2535 .bc_req_max_size = OST_MAXREQSIZE,
2536 .bc_rep_max_size = OST_MAXREPSIZE,
2537 .bc_req_portal = OST_IO_PORTAL,
2538 .bc_rep_portal = OSC_REPLY_PORTAL,
2541 .tc_thr_name = "ll_ost_io",
2542 .tc_thr_factor = OSS_THR_FACTOR,
2543 .tc_nthrs_init = OSS_NTHRS_INIT,
2544 .tc_nthrs_base = OSS_NTHRS_BASE,
2545 .tc_nthrs_max = OSS_NTHRS_MAX,
2546 .tc_nthrs_user = oss_num_threads,
2547 .tc_cpu_affinity = 1,
2548 .tc_ctx_tags = LCT_DT_THREAD,
2551 .cc_cptable = ost_io_cptable,
2552 .cc_pattern = ost_io_cptable == NULL ?
2556 .so_thr_init = ost_thread_init,
2557 .so_thr_done = ost_thread_done,
2558 .so_req_handler = ost_handle,
2559 .so_hpreq_handler = ost_hpreq_handler,
2560 .so_req_printer = target_print_req,
2561 .so_hpreq_handler = NULL,
2564 ost->ost_io_service = ptlrpc_register_service(&svc_conf,
2565 obd->obd_proc_entry);
2566 if (IS_ERR(ost->ost_io_service)) {
2567 rc = PTR_ERR(ost->ost_io_service);
2568 CERROR("failed to start OST I/O service: %d\n", rc);
2569 ost->ost_io_service = NULL;
2570 GOTO(out_create, rc);
2573 ping_evictor_start();
2578 ptlrpc_unregister_service(ost->ost_create_service);
2579 ost->ost_create_service = NULL;
2581 ptlrpc_unregister_service(ost->ost_service);
2582 ost->ost_service = NULL;
2584 lprocfs_obd_cleanup(obd);
2588 static int ost_cleanup(struct obd_device *obd)
2590 struct ost_obd *ost = &obd->u.ost;
2594 ping_evictor_stop();
2596 /* there is no recovery for OST OBD, all recovery is controlled by
2598 LASSERT(obd->obd_recovering == 0);
2599 cfs_mutex_lock(&ost->ost_health_mutex);
2600 ptlrpc_unregister_service(ost->ost_service);
2601 ptlrpc_unregister_service(ost->ost_create_service);
2602 ptlrpc_unregister_service(ost->ost_io_service);
2603 ost->ost_service = NULL;
2604 ost->ost_create_service = NULL;
2605 ost->ost_io_service = NULL;
2607 cfs_mutex_unlock(&ost->ost_health_mutex);
2609 lprocfs_obd_cleanup(obd);
2611 if (ost_io_cptable != NULL) {
2612 cfs_cpt_table_free(ost_io_cptable);
2613 ost_io_cptable = NULL;
2619 static int ost_health_check(const struct lu_env *env, struct obd_device *obd)
2621 struct ost_obd *ost = &obd->u.ost;
2624 cfs_mutex_lock(&ost->ost_health_mutex);
2625 rc |= ptlrpc_service_health_check(ost->ost_service);
2626 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2627 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2628 cfs_mutex_unlock(&ost->ost_health_mutex);
2631 * health_check to return 0 on healthy
2632 * and 1 on unhealthy.
2640 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2642 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2645 /* use obd ops to offer management infrastructure */
2646 static struct obd_ops ost_obd_ops = {
2647 .o_owner = THIS_MODULE,
2648 .o_setup = ost_setup,
2649 .o_cleanup = ost_cleanup,
2650 .o_health_check = ost_health_check,
2654 static int __init ost_init(void)
2656 struct lprocfs_static_vars lvars;
2660 lprocfs_ost_init_vars(&lvars);
2661 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2662 LUSTRE_OSS_NAME, NULL);
2664 if (ost_num_threads != 0 && oss_num_threads == 0) {
2665 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2666 "use oss_num_threads instead or unset both for "
2667 "dynamic thread startup\n");
2668 oss_num_threads = ost_num_threads;
2674 static void /*__exit*/ ost_exit(void)
2676 class_unregister_type(LUSTRE_OSS_NAME);
2679 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2680 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2681 MODULE_LICENSE("GPL");
2683 module_init(ost_init);
2684 module_exit(ost_exit);