1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
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>
43 # define EXPORT_SYMTAB
45 #define DEBUG_SUBSYSTEM S_OST
47 #include <linux/module.h>
48 #include <obd_cksum.h>
50 #include <lustre_net.h>
51 #include <lustre_dlm.h>
52 #include <lustre_export.h>
53 #include <lustre_debug.h>
54 #include <linux/init.h>
55 #include <lprocfs_status.h>
56 #include <libcfs/list.h>
57 #include <lustre_quota.h>
58 #include "ost_internal.h"
60 static int oss_num_threads;
61 CFS_MODULE_PARM(oss_num_threads, "i", int, 0444,
62 "number of OSS service threads to start");
64 static int ost_num_threads;
65 CFS_MODULE_PARM(ost_num_threads, "i", int, 0444,
66 "number of OST service threads to start (deprecated)");
68 static int oss_num_create_threads;
69 CFS_MODULE_PARM(oss_num_create_threads, "i", int, 0444,
70 "number of OSS create threads to start");
73 * Do not return server-side uid/gid to remote client
75 static void ost_drop_id(struct obd_export *exp, struct obdo *oa)
77 if (exp_connect_rmtclient(exp)) {
80 oa->o_valid &= ~(OBD_MD_FLUID | OBD_MD_FLGID);
85 * Validate oa from client.
86 * If the request comes from 2.0 clients, currently only RSVD seq and IDIF
88 * a. for single MDS seq = FID_SEQ_OST_MDT0,
89 * b. for CMD, seq = FID_SEQ_OST_MDT0, FID_SEQ_OST_MDT1 - FID_SEQ_OST_MAX
91 static int ost_validate_obdo(struct obd_export *exp, struct obdo *oa,
92 struct obd_ioobj *ioobj)
94 if (oa != NULL && !(oa->o_valid & OBD_MD_FLGROUP)) {
95 oa->o_seq = FID_SEQ_OST_MDT0;
97 ioobj->ioo_seq = FID_SEQ_OST_MDT0;
98 /* remove fid_seq_is_rsvd() after FID-on-OST allows SEQ > 9 */
99 } else if (oa == NULL ||
100 !(fid_seq_is_rsvd(oa->o_seq) || fid_seq_is_idif(oa->o_seq))) {
101 CERROR("%s: client %s sent invalid object "POSTID"\n",
102 exp->exp_obd->obd_name, obd_export_nid2str(exp),
103 oa ? oa->o_id : -1, oa ? oa->o_seq : -1);
106 obdo_from_ostid(oa, &oa->o_oi);
108 ioobj_from_obdo(ioobj, oa);
112 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
114 struct oti_req_ack_lock *ack_lock;
120 if (req->rq_repmsg) {
121 __u64 versions[PTLRPC_NUM_VERSIONS] = { 0 };
122 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
123 versions[0] = oti->oti_pre_version;
124 lustre_msg_set_versions(req->rq_repmsg, versions);
126 req->rq_transno = oti->oti_transno;
128 /* XXX 4 == entries in oti_ack_locks??? */
129 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
132 /* XXX not even calling target_send_reply in some cases... */
133 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode, 0);
137 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
138 struct obd_trans_info *oti)
140 struct ost_body *body, *repbody;
141 struct lustre_capa *capa = NULL;
145 /* Get the request body */
146 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
150 if (body->oa.o_id == 0)
153 rc = ost_validate_obdo(exp, &body->oa, NULL);
157 /* If there's a DLM request, cancel the locks mentioned in it*/
158 if (req_capsule_field_present(&req->rq_pill, &RMF_DLM_REQ, RCL_CLIENT)) {
159 struct ldlm_request *dlm;
161 dlm = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
164 ldlm_request_cancel(req, dlm, 0);
167 /* If there's a capability, get it */
168 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
169 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
171 CERROR("Missing capability for OST DESTROY");
176 /* Prepare the reply */
177 rc = req_capsule_server_pack(&req->rq_pill);
181 /* Get the log cancellation cookie */
182 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
183 oti->oti_logcookies = &body->oa.o_lcookie;
185 /* Finish the reply */
186 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
187 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
189 /* Do the destroy and set the reply status accordingly */
190 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL, capa);
195 * Helper function for getting server side [start, start+count] DLM lock
196 * if asked by client.
198 static int ost_lock_get(struct obd_export *exp, struct obdo *oa,
199 __u64 start, __u64 count, struct lustre_handle *lh,
202 struct ldlm_res_id res_id;
203 ldlm_policy_data_t policy;
204 __u64 end = start + count;
208 LASSERT(!lustre_handle_is_used(lh));
209 /* o_id and o_gr are used for localizing resource, if client miss to set
210 * them, do not trigger ASSERTION. */
211 if (unlikely((oa->o_valid & (OBD_MD_FLID | OBD_MD_FLGROUP)) !=
212 (OBD_MD_FLID | OBD_MD_FLGROUP)))
215 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
216 !(oa->o_flags & OBD_FL_SRVLOCK))
219 osc_build_res_name(oa->o_id, oa->o_seq, &res_id);
220 CDEBUG(D_INODE, "OST-side extent lock.\n");
222 policy.l_extent.start = start & CFS_PAGE_MASK;
224 /* If ->o_blocks is EOF it means "lock till the end of the
225 * file". Otherwise, it's size of a hole being punched (in bytes) */
226 if (count == OBD_OBJECT_EOF || end < start)
227 policy.l_extent.end = OBD_OBJECT_EOF;
229 policy.l_extent.end = end | ~CFS_PAGE_MASK;
231 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
232 LDLM_EXTENT, &policy, mode, &flags,
233 ldlm_blocking_ast, ldlm_completion_ast,
234 ldlm_glimpse_ast, NULL, 0, NULL, lh));
237 /* Helper function: release lock, if any. */
238 static void ost_lock_put(struct obd_export *exp,
239 struct lustre_handle *lh, int mode)
242 if (lustre_handle_is_used(lh))
243 ldlm_lock_decref(lh, mode);
247 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
249 struct ost_body *body, *repbody;
250 struct obd_info *oinfo;
251 struct lustre_handle lh = { 0 };
252 struct lustre_capa *capa = NULL;
256 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
260 rc = ost_validate_obdo(exp, &body->oa, NULL);
264 rc = req_capsule_server_pack(&req->rq_pill);
268 rc = ost_lock_get(exp, &body->oa, 0, OBD_OBJECT_EOF, &lh, LCK_PR, 0);
272 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
273 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
275 CERROR("Missing capability for OST GETATTR");
276 GOTO(unlock, rc = -EFAULT);
280 OBD_ALLOC_PTR(oinfo);
282 GOTO(unlock, rc = -ENOMEM);
283 oinfo->oi_oa = &body->oa;
284 oinfo->oi_capa = capa;
286 req->rq_status = obd_getattr(exp, oinfo);
290 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
291 repbody->oa = body->oa;
292 ost_drop_id(exp, &repbody->oa);
295 ost_lock_put(exp, &lh, LCK_PR);
300 static int ost_statfs(struct ptlrpc_request *req)
302 struct obd_statfs *osfs;
306 rc = req_capsule_server_pack(&req->rq_pill);
310 osfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
312 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
313 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
315 if (req->rq_status != 0)
316 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
321 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
322 struct obd_trans_info *oti)
324 struct ost_body *body, *repbody;
328 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
332 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
336 rc = req_capsule_server_pack(&req->rq_pill);
340 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
341 repbody->oa = body->oa;
342 oti->oti_logcookies = &body->oa.o_lcookie;
344 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
345 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
349 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
350 struct obd_trans_info *oti)
352 struct ost_body *body, *repbody;
354 struct lustre_handle lh = {0,};
357 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
358 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
360 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
364 rc = ost_validate_obdo(exp, &body->oa, NULL);
368 if ((body->oa.o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
369 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
372 rc = req_capsule_server_pack(&req->rq_pill);
376 /* standard truncate optimization: if file body is completely
377 * destroyed, don't send data back to the server. */
378 if (body->oa.o_size == 0)
379 flags |= LDLM_AST_DISCARD_DATA;
381 rc = ost_lock_get(exp, &body->oa, body->oa.o_size, body->oa.o_blocks,
384 struct obd_info *oinfo;
385 struct lustre_capa *capa = NULL;
387 if (body->oa.o_valid & OBD_MD_FLFLAGS &&
388 body->oa.o_flags == OBD_FL_SRVLOCK)
390 * If OBD_FL_SRVLOCK is the only bit set in
391 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
392 * through filter_setattr() to filter_iocontrol().
394 body->oa.o_valid &= ~OBD_MD_FLFLAGS;
396 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
397 capa = req_capsule_client_get(&req->rq_pill,
400 CERROR("Missing capability for OST PUNCH");
401 GOTO(unlock, rc = -EFAULT);
405 OBD_ALLOC_PTR(oinfo);
407 GOTO(unlock, rc = -ENOMEM);
408 oinfo->oi_oa = &body->oa;
409 oinfo->oi_policy.l_extent.start = oinfo->oi_oa->o_size;
410 oinfo->oi_policy.l_extent.end = oinfo->oi_oa->o_blocks;
411 oinfo->oi_capa = capa;
413 req->rq_status = obd_punch(exp, oinfo, oti, NULL);
416 ost_lock_put(exp, &lh, LCK_PW);
419 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
420 repbody->oa = body->oa;
421 ost_drop_id(exp, &repbody->oa);
425 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
427 struct ost_body *body, *repbody;
428 struct obd_info *oinfo;
429 struct lustre_capa *capa = NULL;
433 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
437 rc = ost_validate_obdo(exp, &body->oa, NULL);
441 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
442 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
444 CERROR("Missing capability for OST SYNC");
449 rc = req_capsule_server_pack(&req->rq_pill);
453 OBD_ALLOC_PTR(oinfo);
457 oinfo->oi_oa = &body->oa;
458 oinfo->oi_capa = capa;
459 req->rq_status = obd_sync(exp, oinfo, body->oa.o_size,
460 body->oa.o_blocks, NULL);
463 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
464 repbody->oa = body->oa;
465 ost_drop_id(exp, &repbody->oa);
469 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
470 struct obd_trans_info *oti)
472 struct ost_body *body, *repbody;
473 struct obd_info *oinfo;
474 struct lustre_capa *capa = NULL;
478 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
482 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
486 rc = req_capsule_server_pack(&req->rq_pill);
490 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
491 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
493 CERROR("Missing capability for OST SETATTR");
498 OBD_ALLOC_PTR(oinfo);
501 oinfo->oi_oa = &body->oa;
502 oinfo->oi_capa = capa;
504 req->rq_status = obd_setattr(exp, oinfo, oti);
508 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
509 repbody->oa = body->oa;
510 ost_drop_id(exp, &repbody->oa);
514 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
515 cksum_type_t cksum_type)
520 cksum = init_checksum(cksum_type);
521 for (i = 0; i < desc->bd_iov_count; i++) {
522 struct page *page = desc->bd_iov[i].kiov_page;
523 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
524 char *ptr = kmap(page) + off;
525 int len = desc->bd_iov[i].kiov_len;
527 /* corrupt the data before we compute the checksum, to
528 * simulate a client->OST data error */
529 if (i == 0 && opc == OST_WRITE &&
530 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
531 memcpy(ptr, "bad3", min(4, len));
532 cksum = compute_checksum(cksum, ptr, len, cksum_type);
533 /* corrupt the data after we compute the checksum, to
534 * simulate an OST->client data error */
535 if (i == 0 && opc == OST_READ &&
536 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
537 memcpy(ptr, "bad4", min(4, len));
538 /* nobody should use corrupted page again */
539 ClearPageUptodate(page);
547 static int ost_brw_lock_get(int mode, struct obd_export *exp,
548 struct obd_ioobj *obj, struct niobuf_remote *nb,
549 struct lustre_handle *lh)
552 int nrbufs = obj->ioo_bufcnt;
553 struct ldlm_res_id res_id;
554 ldlm_policy_data_t policy;
558 osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id);
559 LASSERT(mode == LCK_PR || mode == LCK_PW);
560 LASSERT(!lustre_handle_is_used(lh));
562 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
565 for (i = 1; i < nrbufs; i ++)
566 if ((nb[0].flags & OBD_BRW_SRVLOCK) !=
567 (nb[i].flags & OBD_BRW_SRVLOCK))
570 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
571 policy.l_extent.end = (nb[nrbufs - 1].offset +
572 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
574 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
575 LDLM_EXTENT, &policy, mode, &flags,
576 ldlm_blocking_ast, ldlm_completion_ast,
577 ldlm_glimpse_ast, NULL, 0, NULL, lh));
580 static void ost_brw_lock_put(int mode,
581 struct obd_ioobj *obj, struct niobuf_remote *niob,
582 struct lustre_handle *lh)
585 LASSERT(mode == LCK_PR || mode == LCK_PW);
586 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
587 lustre_handle_is_used(lh));
588 if (lustre_handle_is_used(lh))
589 ldlm_lock_decref(lh, mode);
593 struct ost_prolong_data {
594 struct obd_export *opd_exp;
595 ldlm_policy_data_t opd_policy;
597 ldlm_mode_t opd_mode;
602 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
604 struct ost_prolong_data *opd = data;
606 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
608 if (lock->l_req_mode != lock->l_granted_mode) {
609 /* scan granted locks only */
610 return LDLM_ITER_STOP;
613 if (lock->l_export != opd->opd_exp) {
614 /* prolong locks only for given client */
615 return LDLM_ITER_CONTINUE;
618 if (!(lock->l_granted_mode & opd->opd_mode)) {
619 /* we aren't interesting in all type of locks */
620 return LDLM_ITER_CONTINUE;
623 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
624 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
625 /* the request doesn't cross the lock, skip it */
626 return LDLM_ITER_CONTINUE;
629 /* Fill the obdo with the matched lock handle.
630 * XXX: it is possible in some cases the IO RPC is covered by several
631 * locks, even for the write case, so it may need to be a lock list. */
632 if (opd->opd_oa && !(opd->opd_oa->o_valid & OBD_MD_FLHANDLE)) {
633 opd->opd_oa->o_handle.cookie = lock->l_handle.h_cookie;
634 opd->opd_oa->o_valid |= OBD_MD_FLHANDLE;
637 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
638 /* ignore locks not being cancelled */
639 return LDLM_ITER_CONTINUE;
642 CDEBUG(D_DLMTRACE,"refresh lock: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
643 lock->l_resource->lr_name.name[0],
644 lock->l_resource->lr_name.name[1],
645 opd->opd_policy.l_extent.start, opd->opd_policy.l_extent.end);
646 /* OK. this is a possible lock the user holds doing I/O
647 * let's refresh eviction timer for it */
648 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
649 opd->opd_lock_match = 1;
651 return LDLM_ITER_CONTINUE;
654 static int ost_rw_prolong_locks(struct ptlrpc_request *req, struct obd_ioobj *obj,
655 struct niobuf_remote *nb, struct obdo *oa,
658 struct ldlm_res_id res_id;
659 int nrbufs = obj->ioo_bufcnt;
660 struct ost_prolong_data opd = { 0 };
663 osc_build_res_name(obj->ioo_id, obj->ioo_seq, &res_id);
666 opd.opd_exp = req->rq_export;
667 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
668 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
669 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
671 /* prolong locks for the current service time of the corresponding
672 * portal (= OST_IO_PORTAL) */
673 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
674 max(at_est2timeout(at_get(&req->rq_rqbd->
675 rqbd_service->srv_at_estimate)), ldlm_timeout);
677 CDEBUG(D_INFO,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
678 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
679 opd.opd_policy.l_extent.end);
681 if (oa->o_valid & OBD_MD_FLHANDLE) {
682 struct ldlm_lock *lock;
684 lock = ldlm_handle2lock(&oa->o_handle);
686 ost_prolong_locks_iter(lock, &opd);
687 if (opd.opd_lock_match) {
692 /* Check if the lock covers the whole IO region,
693 * otherwise iterate through the resource. */
694 if (lock->l_policy_data.l_extent.end >=
695 opd.opd_policy.l_extent.end &&
696 lock->l_policy_data.l_extent.start <=
697 opd.opd_policy.l_extent.start) {
706 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
707 ost_prolong_locks_iter, &opd);
708 RETURN(opd.opd_lock_match);
711 /* Allocate thread local buffers if needed */
712 static struct ost_thread_local_cache *ost_tls_get(struct ptlrpc_request *r)
714 struct ost_thread_local_cache *tls =
715 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
717 /* In normal mode of operation an I/O request is serviced only
718 * by ll_ost_io threads each of them has own tls buffers allocated by
720 * During recovery, an I/O request may be queued until any of the ost
721 * service threads process it. Not necessary it should be one of
722 * ll_ost_io threads. In that case we dynamically allocating tls
723 * buffers for the request service time. */
724 if (unlikely(tls == NULL)) {
725 LASSERT(r->rq_export->exp_in_recovery);
729 r->rq_svc_thread->t_data = tls;
735 /* Free thread local buffers if they were allocated only for servicing
736 * this one request */
737 static void ost_tls_put(struct ptlrpc_request *r)
739 struct ost_thread_local_cache *tls =
740 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
742 if (unlikely(tls->temporary)) {
744 r->rq_svc_thread->t_data = NULL;
748 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
750 struct ptlrpc_bulk_desc *desc = NULL;
751 struct obd_export *exp = req->rq_export;
752 struct niobuf_remote *remote_nb;
753 struct niobuf_local *local_nb;
754 struct obd_ioobj *ioo;
755 struct ost_body *body, *repbody;
756 struct lustre_capa *capa = NULL;
757 struct l_wait_info lwi;
758 struct lustre_handle lockh = { 0 };
759 int niocount, npages, nob = 0, rc, i;
761 struct ost_thread_local_cache *tls;
764 req->rq_bulk_read = 1;
766 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
767 GOTO(out, rc = -EIO);
769 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
771 /* Check if there is eviction in progress, and if so, wait for it to
773 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
774 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
775 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
776 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
780 GOTO(out, rc = -ENOTCONN);
782 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
783 * ost_rw_hpreq_check(). */
784 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
786 GOTO(out, rc = -EFAULT);
789 * A req_capsule_X_get_array(pill, field, ptr_to_element_count) function
790 * would be useful here and wherever we get &RMF_OBD_IOOBJ and
791 * &RMF_NIOBUF_REMOTE.
793 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
795 GOTO(out, rc = -EFAULT);
797 rc = ost_validate_obdo(exp, &body->oa, ioo);
801 niocount = ioo->ioo_bufcnt;
802 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
803 if (remote_nb == NULL)
804 GOTO(out, rc = -EFAULT);
806 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
807 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
809 CERROR("Missing capability for OST BRW READ");
810 GOTO(out, rc = -EFAULT);
814 rc = req_capsule_server_pack(&req->rq_pill);
818 tls = ost_tls_get(req);
820 GOTO(out_bulk, rc = -ENOMEM);
821 local_nb = tls->local;
823 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
828 * If getting the lock took more time than
829 * client was willing to wait, drop it. b=11330
831 if (cfs_time_current_sec() > req->rq_deadline ||
832 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
834 CERROR("Dropping timed-out read from %s because locking"
835 "object "LPX64" took %ld seconds (limit was %ld).\n",
836 libcfs_id2str(req->rq_peer), ioo->ioo_id,
837 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
838 req->rq_deadline - req->rq_arrival_time.tv_sec);
839 GOTO(out_lock, rc = -ETIMEDOUT);
842 npages = OST_THREAD_POOL_SIZE;
843 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
844 remote_nb, &npages, local_nb, oti, capa);
848 desc = ptlrpc_prep_bulk_exp(req, npages,
849 BULK_PUT_SOURCE, OST_BULK_PORTAL);
851 GOTO(out_commitrw, rc = -ENOMEM);
853 if (!lustre_handle_is_used(&lockh))
854 /* no needs to try to prolong lock if server is asked
855 * to handle locking (= OBD_BRW_SRVLOCK) */
856 ost_rw_prolong_locks(req, ioo, remote_nb, &body->oa,
860 for (i = 0; i < npages; i++) {
861 int page_rc = local_nb[i].rc;
863 if (page_rc < 0) { /* error */
869 if (page_rc != 0) { /* some data! */
870 LASSERT (local_nb[i].page != NULL);
871 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
872 local_nb[i].offset & ~CFS_PAGE_MASK,
876 if (page_rc != local_nb[i].len) { /* short read */
877 /* All subsequent pages should be 0 */
879 LASSERT(local_nb[i].rc == 0);
884 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
885 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
887 if (body->oa.o_valid & OBD_MD_FLFLAGS)
888 cksum_type = cksum_type_unpack(body->oa.o_flags);
889 body->oa.o_flags = cksum_type_pack(cksum_type);
890 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
891 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
892 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
894 body->oa.o_valid = 0;
896 /* We're finishing using body->oa as an input variable */
898 /* Check if client was evicted while we were doing i/o before touching
901 rc = target_bulk_io(exp, desc, &lwi);
906 /* Must commit after prep above in all cases */
907 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
908 remote_nb, npages, local_nb, oti, rc);
911 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
912 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
913 ost_drop_id(exp, &repbody->oa);
917 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
922 ptlrpc_free_bulk(desc);
926 req->rq_status = nob;
927 ptlrpc_lprocfs_brw(req, nob);
928 target_committed_to_req(req);
930 } else if (!no_reply) {
931 /* Only reply if there was no comms problem with bulk */
932 target_committed_to_req(req);
936 /* reply out callback would free */
937 ptlrpc_req_drop_rs(req);
938 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
939 "client will retry\n",
940 exp->exp_obd->obd_name,
941 exp->exp_client_uuid.uuid,
942 exp->exp_connection->c_remote_uuid.uuid,
943 libcfs_id2str(req->rq_peer));
949 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
951 struct ptlrpc_bulk_desc *desc = NULL;
952 struct obd_export *exp = req->rq_export;
953 struct niobuf_remote *remote_nb;
954 struct niobuf_local *local_nb;
955 struct obd_ioobj *ioo;
956 struct ost_body *body, *repbody;
957 struct l_wait_info lwi;
958 struct lustre_handle lockh = {0};
959 struct lustre_capa *capa = NULL;
961 int objcount, niocount, npages;
963 obd_count client_cksum = 0, server_cksum = 0;
964 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
965 int no_reply = 0, mmap = 0;
966 __u32 o_uid = 0, o_gid = 0;
967 struct ost_thread_local_cache *tls;
970 req->rq_bulk_write = 1;
972 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
973 GOTO(out, rc = -EIO);
974 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
975 GOTO(out, rc = -EFAULT);
977 /* pause before transaction has been started */
978 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
980 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
981 * ost_rw_hpreq_check(). */
982 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
984 GOTO(out, rc = -EFAULT);
986 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
987 RCL_CLIENT) / sizeof(*ioo);
988 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
990 GOTO(out, rc = -EFAULT);
992 rc = ost_validate_obdo(exp, &body->oa, ioo);
996 for (niocount = i = 0; i < objcount; i++)
997 niocount += ioo[i].ioo_bufcnt;
1000 * It'd be nice to have a capsule function to indicate how many elements
1001 * there were in a buffer for an RMF that's declared to be an array.
1002 * It's easy enough to compute the number of elements here though.
1004 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1005 if (remote_nb == NULL || niocount != (req_capsule_get_size(&req->rq_pill,
1006 &RMF_NIOBUF_REMOTE, RCL_CLIENT) / sizeof(*remote_nb)))
1007 GOTO(out, rc = -EFAULT);
1009 if ((remote_nb[0].flags & OBD_BRW_MEMALLOC) &&
1010 (exp->exp_connection->c_peer.nid == exp->exp_connection->c_self))
1011 cfs_memory_pressure_set();
1013 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
1014 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
1016 CERROR("Missing capability for OST BRW WRITE");
1017 GOTO(out, rc = -EFAULT);
1021 req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER,
1022 niocount * sizeof(*rcs));
1023 rc = req_capsule_server_pack(&req->rq_pill);
1026 CFS_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, cfs_fail_val);
1027 rcs = req_capsule_server_get(&req->rq_pill, &RMF_RCS);
1029 tls = ost_tls_get(req);
1031 GOTO(out_bulk, rc = -ENOMEM);
1032 local_nb = tls->local;
1034 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
1039 * If getting the lock took more time than
1040 * client was willing to wait, drop it. b=11330
1042 if (cfs_time_current_sec() > req->rq_deadline ||
1043 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
1045 CERROR("Dropping timed-out write from %s because locking "
1046 "object "LPX64" took %ld seconds (limit was %ld).\n",
1047 libcfs_id2str(req->rq_peer), ioo->ioo_id,
1048 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
1049 req->rq_deadline - req->rq_arrival_time.tv_sec);
1050 GOTO(out_lock, rc = -ETIMEDOUT);
1053 if (!lustre_handle_is_used(&lockh))
1054 /* no needs to try to prolong lock if server is asked
1055 * to handle locking (= OBD_BRW_SRVLOCK) */
1056 ost_rw_prolong_locks(req, ioo, remote_nb,&body->oa, LCK_PW);
1058 /* obd_preprw clobbers oa->valid, so save what we need */
1059 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
1060 client_cksum = body->oa.o_cksum;
1061 if (body->oa.o_valid & OBD_MD_FLFLAGS)
1062 cksum_type = cksum_type_unpack(body->oa.o_flags);
1064 if (body->oa.o_valid & OBD_MD_FLFLAGS && body->oa.o_flags & OBD_FL_MMAP)
1067 /* Because we already sync grant info with client when reconnect,
1068 * grant info will be cleared for resent req, then fed_grant and
1069 * total_grant will not be modified in following preprw_write */
1070 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1071 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1072 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1075 if (exp_connect_rmtclient(exp)) {
1076 o_uid = body->oa.o_uid;
1077 o_gid = body->oa.o_gid;
1079 npages = OST_THREAD_POOL_SIZE;
1080 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
1081 ioo, remote_nb, &npages, local_nb, oti, capa);
1085 desc = ptlrpc_prep_bulk_exp(req, npages,
1086 BULK_GET_SINK, OST_BULK_PORTAL);
1088 GOTO(skip_transfer, rc = -ENOMEM);
1090 /* NB Having prepped, we must commit... */
1092 for (i = 0; i < npages; i++)
1093 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1094 local_nb[i].offset & ~CFS_PAGE_MASK,
1097 rc = sptlrpc_svc_prep_bulk(req, desc);
1101 rc = target_bulk_io(exp, desc, &lwi);
1105 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
1106 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1108 if (unlikely(client_cksum != 0 && rc == 0)) {
1109 static int cksum_counter;
1110 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1111 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1112 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1113 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1114 repbody->oa.o_cksum = server_cksum;
1116 if (unlikely(client_cksum != server_cksum)) {
1117 CDEBUG_LIMIT(mmap ? D_INFO : D_ERROR,
1118 "client csum %x, server csum %x\n",
1119 client_cksum, server_cksum);
1121 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1122 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1123 cksum_counter, libcfs_id2str(req->rq_peer),
1128 /* Must commit after prep above in all cases */
1129 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1130 remote_nb, npages, local_nb, oti, rc);
1131 if (rc == -ENOTCONN)
1132 /* quota acquire process has been given up because
1133 * either the client has been evicted or the client
1134 * has timed out the request already */
1137 if (exp_connect_rmtclient(exp)) {
1138 repbody->oa.o_uid = o_uid;
1139 repbody->oa.o_gid = o_gid;
1143 * Disable sending mtime back to the client. If the client locked the
1144 * whole object, then it has already updated the mtime on its side,
1145 * otherwise it will have to glimpse anyway (see bug 21489, comment 32)
1147 repbody->oa.o_valid &= ~(OBD_MD_FLMTIME | OBD_MD_FLATIME);
1149 if (unlikely(client_cksum != server_cksum && rc == 0 && !mmap)) {
1150 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1155 if (new_cksum == server_cksum)
1156 msg = "changed in transit before arrival at OST";
1157 else if (new_cksum == client_cksum)
1158 msg = "initial checksum before message complete";
1160 msg = "changed in transit AND after initial checksum";
1162 if (req->rq_peer.nid == desc->bd_sender) {
1166 router = libcfs_nid2str(desc->bd_sender);
1169 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1170 "%s%s%s inode "DFID" object "
1171 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1172 exp->exp_obd->obd_name, msg,
1173 libcfs_id2str(req->rq_peer),
1175 body->oa.o_valid & OBD_MD_FLFID ?
1176 body->oa.o_parent_seq : (__u64)0,
1177 body->oa.o_valid & OBD_MD_FLFID ?
1178 body->oa.o_parent_oid : 0,
1179 body->oa.o_valid & OBD_MD_FLFID ?
1180 body->oa.o_parent_ver : 0,
1182 body->oa.o_valid & OBD_MD_FLGROUP ?
1183 body->oa.o_seq : (__u64)0,
1185 local_nb[npages-1].offset +
1186 local_nb[npages-1].len - 1 );
1187 CERROR("client csum %x, original server csum %x, "
1188 "server csum now %x\n",
1189 client_cksum, server_cksum, new_cksum);
1195 /* set per-requested niobuf return codes */
1196 for (i = j = 0; i < niocount; i++) {
1197 int len = remote_nb[i].len;
1202 LASSERT(j < npages);
1203 if (local_nb[j].rc < 0)
1204 rcs[i] = local_nb[j].rc;
1205 len -= local_nb[j].len;
1210 LASSERT(j == npages);
1211 ptlrpc_lprocfs_brw(req, nob);
1215 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1220 ptlrpc_free_bulk(desc);
1223 oti_to_request(oti, req);
1224 target_committed_to_req(req);
1225 rc = ptlrpc_reply(req);
1226 } else if (!no_reply) {
1227 /* Only reply if there was no comms problem with bulk */
1228 target_committed_to_req(req);
1229 req->rq_status = rc;
1232 /* reply out callback would free */
1233 ptlrpc_req_drop_rs(req);
1234 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1235 "client will retry\n",
1236 exp->exp_obd->obd_name,
1237 exp->exp_client_uuid.uuid,
1238 exp->exp_connection->c_remote_uuid.uuid,
1239 libcfs_id2str(req->rq_peer));
1241 cfs_memory_pressure_clr();
1246 * Implementation of OST_SET_INFO.
1248 * OST_SET_INFO is like ioctl(): heavily overloaded. Specifically, it takes a
1249 * "key" and a value RPC buffers as arguments, with the value's contents
1250 * interpreted according to the key.
1252 * Value types that need swabbing have swabbing done explicitly, either here or
1253 * in functions called from here. This should be corrected: all swabbing should
1254 * be done in the capsule abstraction, as that will then allow us to move
1255 * swabbing exclusively to the client without having to modify server code
1256 * outside the capsule abstraction's implementation itself. To correct this
1257 * will require minor changes to the capsule abstraction; see the comments for
1258 * req_capsule_extend() in layout.c.
1260 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1262 struct ost_body *body = NULL, *repbody;
1263 char *key, *val = NULL;
1264 int keylen, vallen, rc = 0;
1265 int is_grant_shrink = 0;
1268 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1270 DEBUG_REQ(D_HA, req, "no set_info key");
1273 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1276 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1279 if ((is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK)))
1280 /* In this case the value is actually an RMF_OST_BODY, so we
1281 * transmutate the type of this PTLRPC */
1282 req_capsule_extend(&req->rq_pill, &RQF_OST_SET_GRANT_INFO);
1284 rc = req_capsule_server_pack(&req->rq_pill);
1289 if (is_grant_shrink) {
1290 body = req_capsule_client_get(&req->rq_pill,
1295 repbody = req_capsule_server_get(&req->rq_pill,
1297 memcpy(repbody, body, sizeof(*body));
1298 val = (char*)repbody;
1300 val = req_capsule_client_get(&req->rq_pill,
1305 if (KEY_IS(KEY_EVICT_BY_NID)) {
1307 obd_export_evict_by_nid(exp->exp_obd, val);
1309 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1310 if (vallen < sizeof(__u32))
1312 __swab32s((__u32 *)val);
1315 /* OBD will also check if KEY_IS(KEY_GRANT_SHRINK), and will cast val to
1316 * a struct ost_body * value */
1317 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1319 lustre_msg_set_status(req->rq_repmsg, 0);
1323 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1326 int keylen, replylen, rc = 0;
1327 struct req_capsule *pill = &req->rq_pill;
1330 /* this common part for get_info rpc */
1331 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1333 DEBUG_REQ(D_HA, req, "no get_info key");
1336 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1338 if (KEY_IS(KEY_FIEMAP)) {
1339 struct ll_fiemap_info_key *fm_key = key;
1342 rc = ost_validate_obdo(exp, &fm_key->oa, NULL);
1347 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1351 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1352 RCL_SERVER, replylen);
1354 rc = req_capsule_server_pack(pill);
1358 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1362 /* call again to fill in the reply buffer */
1363 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1365 lustre_msg_set_status(req->rq_repmsg, 0);
1369 #ifdef HAVE_QUOTA_SUPPORT
1370 static int ost_handle_quotactl(struct ptlrpc_request *req)
1372 struct obd_quotactl *oqctl, *repoqc;
1376 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1378 GOTO(out, rc = -EPROTO);
1380 rc = req_capsule_server_pack(&req->rq_pill);
1384 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1385 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1392 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1394 struct obd_quotactl *oqctl;
1398 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1402 rc = req_capsule_server_pack(&req->rq_pill);
1406 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1410 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1412 struct quota_adjust_qunit *oqaq, *repoqa;
1413 struct lustre_quota_ctxt *qctxt;
1417 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1418 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1420 GOTO(out, rc = -EPROTO);
1422 rc = req_capsule_server_pack(&req->rq_pill);
1426 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1427 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt, NULL);
1435 static int ost_llog_handle_connect(struct obd_export *exp,
1436 struct ptlrpc_request *req)
1438 struct llogd_conn_body *body;
1442 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
1443 rc = obd_llog_connect(exp, body);
1447 #define ost_init_sec_none(reply, exp) \
1449 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1450 OBD_CONNECT_RMT_CLIENT_FORCE | \
1451 OBD_CONNECT_OSS_CAPA); \
1452 cfs_spin_lock(&exp->exp_lock); \
1453 exp->exp_connect_flags = reply->ocd_connect_flags; \
1454 cfs_spin_unlock(&exp->exp_lock); \
1457 static int ost_init_sec_level(struct ptlrpc_request *req)
1459 struct obd_export *exp = req->rq_export;
1460 struct req_capsule *pill = &req->rq_pill;
1461 struct obd_device *obd = exp->exp_obd;
1462 struct filter_obd *filter = &obd->u.filter;
1463 char *client = libcfs_nid2str(req->rq_peer.nid);
1464 struct obd_connect_data *data, *reply;
1468 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1469 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1470 if (data == NULL || reply == NULL)
1473 /* connection from MDT is always trusted */
1474 if (req->rq_auth_usr_mdt) {
1475 ost_init_sec_none(reply, exp);
1479 /* no GSS support case */
1480 if (!req->rq_auth_gss) {
1481 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1482 CWARN("client %s -> target %s does not user GSS, "
1483 "can not run under security level %d.\n",
1484 client, obd->obd_name, filter->fo_sec_level);
1487 ost_init_sec_none(reply, exp);
1492 /* old version case */
1493 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1494 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1495 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1496 CWARN("client %s -> target %s uses old version, "
1497 "can not run under security level %d.\n",
1498 client, obd->obd_name, filter->fo_sec_level);
1501 CWARN("client %s -> target %s uses old version, "
1502 "run under security level %d.\n",
1503 client, obd->obd_name, filter->fo_sec_level);
1504 ost_init_sec_none(reply, exp);
1509 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1511 if (!req->rq_auth_remote)
1512 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1513 "asked to be remote.\n", client, obd->obd_name);
1514 } else if (req->rq_auth_remote) {
1516 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1517 "as remote by default.\n", client, obd->obd_name);
1521 if (!filter->fo_fl_oss_capa) {
1522 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1523 " but OSS capabilities are not enabled: %d.\n",
1524 client, obd->obd_name, filter->fo_fl_oss_capa);
1529 switch (filter->fo_sec_level) {
1530 case LUSTRE_SEC_NONE:
1532 ost_init_sec_none(reply, exp);
1535 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1536 "can not run under security level %d.\n",
1537 client, obd->obd_name, filter->fo_sec_level);
1540 case LUSTRE_SEC_REMOTE:
1542 ost_init_sec_none(reply, exp);
1544 case LUSTRE_SEC_ALL:
1546 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1547 OBD_CONNECT_RMT_CLIENT_FORCE);
1548 if (!filter->fo_fl_oss_capa)
1549 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1551 cfs_spin_lock(&exp->exp_lock);
1552 exp->exp_connect_flags = reply->ocd_connect_flags;
1553 cfs_spin_unlock(&exp->exp_lock);
1565 * this should be done in filter_connect()/filter_reconnect(), but
1566 * we can't obtain information like NID, which stored in incoming
1567 * request, thus can't decide what flavor to use. so we do it here.
1569 * This hack should be removed after the OST stack be rewritten, just
1570 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1572 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1574 struct obd_export *exp = req->rq_export;
1575 struct filter_obd *filter = &exp->exp_obd->u.filter;
1576 struct sptlrpc_flavor flvr;
1579 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1580 LUSTRE_ECHO_NAME) == 0)) {
1581 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1585 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1586 cfs_read_lock(&filter->fo_sptlrpc_lock);
1587 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1591 cfs_read_unlock(&filter->fo_sptlrpc_lock);
1593 cfs_spin_lock(&exp->exp_lock);
1595 exp->exp_sp_peer = req->rq_sp_from;
1596 exp->exp_flvr = flvr;
1598 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1599 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1600 CERROR("unauthorized rpc flavor %x from %s, "
1601 "expect %x\n", req->rq_flvr.sf_rpc,
1602 libcfs_nid2str(req->rq_peer.nid),
1603 exp->exp_flvr.sf_rpc);
1607 cfs_spin_unlock(&exp->exp_lock);
1609 if (exp->exp_sp_peer != req->rq_sp_from) {
1610 CERROR("RPC source %s doesn't match %s\n",
1611 sptlrpc_part2name(req->rq_sp_from),
1612 sptlrpc_part2name(exp->exp_sp_peer));
1615 rc = sptlrpc_target_export_check(exp, req);
1622 /* Ensure that data and metadata are synced to the disk when lock is cancelled
1624 int ost_blocking_ast(struct ldlm_lock *lock,
1625 struct ldlm_lock_desc *desc,
1626 void *data, int flag)
1628 __u32 sync_lock_cancel = 0;
1629 __u32 len = sizeof(sync_lock_cancel);
1633 rc = obd_get_info(lock->l_export, sizeof(KEY_SYNC_LOCK_CANCEL),
1634 KEY_SYNC_LOCK_CANCEL, &len, &sync_lock_cancel, NULL);
1636 if (!rc && flag == LDLM_CB_CANCELING &&
1637 (lock->l_granted_mode & (LCK_PW|LCK_GROUP)) &&
1638 (sync_lock_cancel == ALWAYS_SYNC_ON_CANCEL ||
1639 (sync_lock_cancel == BLOCKING_SYNC_ON_CANCEL &&
1640 lock->l_flags & LDLM_FL_CBPENDING))) {
1641 struct obd_info *oinfo;
1645 OBD_ALLOC_PTR(oinfo);
1650 OBD_FREE_PTR(oinfo);
1653 oa->o_id = lock->l_resource->lr_name.name[0];
1654 oa->o_seq = lock->l_resource->lr_name.name[1];
1655 oa->o_valid = OBD_MD_FLID|OBD_MD_FLGROUP;
1658 rc = obd_sync(lock->l_export, oinfo,
1659 lock->l_policy_data.l_extent.start,
1660 lock->l_policy_data.l_extent.end, NULL);
1662 CERROR("Error %d syncing data on lock cancel\n", rc);
1665 OBD_FREE_PTR(oinfo);
1668 rc = ldlm_server_blocking_ast(lock, desc, data, flag);
1672 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1673 struct obd_device *obd, int *process)
1675 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1676 case OST_CONNECT: /* This will never get here, but for completeness. */
1677 case OST_DISCONNECT:
1688 case OBD_LOG_CANCEL:
1690 *process = target_queue_recovery_request(req, obd);
1694 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1700 int ost_msg_check_version(struct lustre_msg *msg)
1704 switch(lustre_msg_get_opc(msg)) {
1706 case OST_DISCONNECT:
1709 case SEC_CTX_INIT_CONT:
1711 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1713 CERROR("bad opc %u version %08x, expecting %08x\n",
1714 lustre_msg_get_opc(msg),
1715 lustre_msg_get_version(msg),
1716 LUSTRE_OBD_VERSION);
1729 #ifdef HAVE_QUOTA_SUPPORT
1730 case OST_QUOTACHECK:
1732 case OST_QUOTA_ADJUST_QUNIT:
1734 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1736 CERROR("bad opc %u version %08x, expecting %08x\n",
1737 lustre_msg_get_opc(msg),
1738 lustre_msg_get_version(msg),
1739 LUSTRE_OST_VERSION);
1744 case LDLM_BL_CALLBACK:
1745 case LDLM_CP_CALLBACK:
1746 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1748 CERROR("bad opc %u version %08x, expecting %08x\n",
1749 lustre_msg_get_opc(msg),
1750 lustre_msg_get_version(msg),
1751 LUSTRE_DLM_VERSION);
1753 case LLOG_ORIGIN_CONNECT:
1754 case OBD_LOG_CANCEL:
1755 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1757 CERROR("bad opc %u version %08x, expecting %08x\n",
1758 lustre_msg_get_opc(msg),
1759 lustre_msg_get_version(msg),
1760 LUSTRE_LOG_VERSION);
1763 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1770 * Returns 1 if the given PTLRPC matches the given LDLM locks, or 0 if it does
1773 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1774 struct ldlm_lock *lock)
1776 struct niobuf_remote *nb;
1777 struct obd_ioobj *ioo;
1778 struct ost_body *body;
1779 int objcount, niocount;
1780 int mode, opc, i, rc;
1784 opc = lustre_msg_get_opc(req->rq_reqmsg);
1785 LASSERT(opc == OST_READ || opc == OST_WRITE);
1787 /* As the request may be covered by several locks, do not look at
1788 * o_handle, look at the RPC IO region. */
1789 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1793 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1794 RCL_CLIENT) / sizeof(*ioo);
1795 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1799 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
1803 for (niocount = i = 0; i < objcount; i++)
1804 niocount += ioo[i].ioo_bufcnt;
1806 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1808 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
1809 RCL_CLIENT) / sizeof(*nb)))
1813 if (opc == OST_READ)
1816 start = nb[0].offset & CFS_PAGE_MASK;
1817 end = (nb[ioo->ioo_bufcnt - 1].offset +
1818 nb[ioo->ioo_bufcnt - 1].len - 1) | ~CFS_PAGE_MASK;
1820 LASSERT(lock->l_resource != NULL);
1821 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_seq,
1822 &lock->l_resource->lr_name))
1825 if (!(lock->l_granted_mode & mode))
1828 if (lock->l_policy_data.l_extent.end < start ||
1829 lock->l_policy_data.l_extent.start > end)
1836 * High-priority queue request check for whether the given PTLRPC request (\a
1837 * req) is blocking an LDLM lock cancel.
1839 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1840 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1842 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1843 * function looks only at OST_READs and OST_WRITEs.
1845 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1847 struct niobuf_remote *nb;
1848 struct obd_ioobj *ioo;
1849 struct ost_body *body;
1850 int objcount, niocount;
1851 int mode, opc, i, rc;
1854 opc = lustre_msg_get_opc(req->rq_reqmsg);
1855 LASSERT(opc == OST_READ || opc == OST_WRITE);
1857 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1861 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1862 RCL_CLIENT) / sizeof(*ioo);
1863 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1867 rc = ost_validate_obdo(req->rq_export, &body->oa, ioo);
1871 for (niocount = i = 0; i < objcount; i++)
1872 niocount += ioo[i].ioo_bufcnt;
1873 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1875 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
1876 RCL_CLIENT) / sizeof(*nb)))
1878 if (niocount != 0 && (nb[0].flags & OBD_BRW_SRVLOCK))
1882 if (opc == OST_READ)
1884 RETURN(ost_rw_prolong_locks(req, ioo, nb, &body->oa, mode));
1887 static int ost_punch_prolong_locks(struct ptlrpc_request *req, struct obdo *oa)
1889 struct ldlm_res_id res_id = { .name = { oa->o_id } };
1890 struct ost_prolong_data opd = { 0 };
1895 end = start + oa->o_blocks;
1897 opd.opd_mode = LCK_PW;
1898 opd.opd_exp = req->rq_export;
1899 opd.opd_policy.l_extent.start = start & CFS_PAGE_MASK;
1900 if (oa->o_blocks == OBD_OBJECT_EOF || end < start)
1901 opd.opd_policy.l_extent.end = OBD_OBJECT_EOF;
1903 opd.opd_policy.l_extent.end = end | ~CFS_PAGE_MASK;
1905 /* prolong locks for the current service time of the corresponding
1906 * portal (= OST_IO_PORTAL) */
1907 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
1908 max(at_est2timeout(at_get(&req->rq_rqbd->
1909 rqbd_service->srv_at_estimate)), ldlm_timeout);
1911 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1912 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
1913 opd.opd_policy.l_extent.end);
1916 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
1917 ost_prolong_locks_iter, &opd);
1918 RETURN(opd.opd_lock_match);
1922 * Like ost_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
1924 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1925 struct ldlm_lock *lock)
1927 struct ost_body *body;
1931 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1933 RETURN(0); /* can't return -EFAULT here */
1935 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
1939 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1940 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1946 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
1948 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1950 struct ost_body *body;
1953 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1957 rc = ost_validate_obdo(req->rq_export, &body->oa, NULL);
1961 LASSERT(!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1962 !(body->oa.o_flags & OBD_FL_SRVLOCK));
1964 RETURN(ost_punch_prolong_locks(req, &body->oa));
1967 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
1968 .hpreq_lock_match = ost_rw_hpreq_lock_match,
1969 .hpreq_check = ost_rw_hpreq_check,
1972 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
1973 .hpreq_lock_match = ost_punch_hpreq_lock_match,
1974 .hpreq_check = ost_punch_hpreq_check,
1977 /** Assign high priority operations to the request if needed. */
1978 static int ost_hpreq_handler(struct ptlrpc_request *req)
1981 if (req->rq_export) {
1982 int opc = lustre_msg_get_opc(req->rq_reqmsg);
1983 struct ost_body *body;
1985 if (opc == OST_READ || opc == OST_WRITE) {
1986 struct niobuf_remote *nb;
1987 struct obd_ioobj *ioo;
1988 int objcount, niocount;
1991 /* RPCs on the H-P queue can be inspected before
1992 * ost_handler() initializes their pills, so we
1993 * initialize that here. Capsule initialization is
1994 * idempotent, as is setting the pill's format (provided
1995 * it doesn't change).
1997 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1998 if (opc == OST_READ)
1999 req_capsule_set(&req->rq_pill,
2002 req_capsule_set(&req->rq_pill,
2003 &RQF_OST_BRW_WRITE);
2005 body = req_capsule_client_get(&req->rq_pill,
2008 CERROR("Missing/short ost_body\n");
2012 objcount = req_capsule_get_size(&req->rq_pill,
2016 if (objcount == 0) {
2017 CERROR("Missing/short ioobj\n");
2021 CERROR("too many ioobjs (%d)\n", objcount);
2025 ioo = req_capsule_client_get(&req->rq_pill,
2028 CERROR("Missing/short ioobj\n");
2032 for (niocount = i = 0; i < objcount; i++) {
2033 if (ioo[i].ioo_bufcnt == 0) {
2034 CERROR("ioo[%d] has zero bufcnt\n", i);
2037 niocount += ioo[i].ioo_bufcnt;
2039 if (niocount > PTLRPC_MAX_BRW_PAGES) {
2040 DEBUG_REQ(D_RPCTRACE, req,
2041 "bulk has too many pages (%d)",
2046 nb = req_capsule_client_get(&req->rq_pill,
2047 &RMF_NIOBUF_REMOTE);
2049 CERROR("Missing/short niobuf\n");
2053 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
2054 req->rq_ops = &ost_hpreq_rw;
2055 } else if (opc == OST_PUNCH) {
2056 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2057 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2059 body = req_capsule_client_get(&req->rq_pill,
2062 CERROR("Missing/short ost_body\n");
2066 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
2067 !(body->oa.o_flags & OBD_FL_SRVLOCK))
2068 req->rq_ops = &ost_hpreq_punch;
2074 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
2075 int ost_handle(struct ptlrpc_request *req)
2077 struct obd_trans_info trans_info = { 0, };
2078 struct obd_trans_info *oti = &trans_info;
2079 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
2080 struct obd_device *obd = NULL;
2083 LASSERT(current->journal_info == NULL);
2085 /* primordial rpcs don't affect server recovery */
2086 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2088 case SEC_CTX_INIT_CONT:
2093 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2095 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
2096 if (!class_connected_export(req->rq_export)) {
2097 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
2098 lustre_msg_get_opc(req->rq_reqmsg),
2099 libcfs_id2str(req->rq_peer));
2100 req->rq_status = -ENOTCONN;
2101 GOTO(out, rc = -ENOTCONN);
2104 obd = req->rq_export->exp_obd;
2106 /* Check for aborted recovery. */
2107 if (obd->obd_recovering) {
2108 rc = ost_filter_recovery_request(req, obd,
2110 if (rc || !should_process)
2112 else if (should_process < 0) {
2113 req->rq_status = should_process;
2114 rc = ptlrpc_error(req);
2122 rc = ost_msg_check_version(req->rq_reqmsg);
2126 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2128 CDEBUG(D_INODE, "connect\n");
2129 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
2130 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
2132 rc = target_handle_connect(req);
2133 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
2136 rc = ost_init_sec_level(req);
2138 rc = ost_connect_check_sptlrpc(req);
2142 case OST_DISCONNECT:
2143 CDEBUG(D_INODE, "disconnect\n");
2144 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
2145 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
2147 rc = target_handle_disconnect(req);
2150 CDEBUG(D_INODE, "create\n");
2151 req_capsule_set(&req->rq_pill, &RQF_OST_CREATE);
2152 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
2154 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2155 GOTO(out, rc = -EROFS);
2156 rc = ost_create(req->rq_export, req, oti);
2159 CDEBUG(D_INODE, "destroy\n");
2160 req_capsule_set(&req->rq_pill, &RQF_OST_DESTROY);
2161 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
2163 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2164 GOTO(out, rc = -EROFS);
2165 rc = ost_destroy(req->rq_export, req, oti);
2168 CDEBUG(D_INODE, "getattr\n");
2169 req_capsule_set(&req->rq_pill, &RQF_OST_GETATTR);
2170 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
2172 rc = ost_getattr(req->rq_export, req);
2175 CDEBUG(D_INODE, "setattr\n");
2176 req_capsule_set(&req->rq_pill, &RQF_OST_SETATTR);
2177 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
2179 rc = ost_setattr(req->rq_export, req, oti);
2182 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_WRITE);
2183 CDEBUG(D_INODE, "write\n");
2184 /* req->rq_request_portal would be nice, if it was set */
2185 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2186 CERROR("%s: deny write request from %s to portal %u\n",
2187 req->rq_export->exp_obd->obd_name,
2188 obd_export_nid2str(req->rq_export),
2189 req->rq_rqbd->rqbd_service->srv_req_portal);
2190 GOTO(out, rc = -EPROTO);
2192 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2194 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
2195 GOTO(out, rc = -ENOSPC);
2196 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2197 GOTO(out, rc = -EROFS);
2198 rc = ost_brw_write(req, oti);
2199 LASSERT(current->journal_info == NULL);
2200 /* ost_brw_write sends its own replies */
2203 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_READ);
2204 CDEBUG(D_INODE, "read\n");
2205 /* req->rq_request_portal would be nice, if it was set */
2206 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2207 CERROR("%s: deny read request from %s to portal %u\n",
2208 req->rq_export->exp_obd->obd_name,
2209 obd_export_nid2str(req->rq_export),
2210 req->rq_rqbd->rqbd_service->srv_req_portal);
2211 GOTO(out, rc = -EPROTO);
2213 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2215 rc = ost_brw_read(req, oti);
2216 LASSERT(current->journal_info == NULL);
2217 /* ost_brw_read sends its own replies */
2220 CDEBUG(D_INODE, "punch\n");
2221 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2222 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2224 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2225 GOTO(out, rc = -EROFS);
2226 rc = ost_punch(req->rq_export, req, oti);
2229 CDEBUG(D_INODE, "statfs\n");
2230 req_capsule_set(&req->rq_pill, &RQF_OST_STATFS);
2231 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2233 rc = ost_statfs(req);
2236 CDEBUG(D_INODE, "sync\n");
2237 req_capsule_set(&req->rq_pill, &RQF_OST_SYNC);
2238 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2240 rc = ost_sync(req->rq_export, req);
2243 DEBUG_REQ(D_INODE, req, "set_info");
2244 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
2245 rc = ost_set_info(req->rq_export, req);
2248 DEBUG_REQ(D_INODE, req, "get_info");
2249 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
2250 rc = ost_get_info(req->rq_export, req);
2252 #ifdef HAVE_QUOTA_SUPPORT
2253 case OST_QUOTACHECK:
2254 CDEBUG(D_INODE, "quotacheck\n");
2255 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2256 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2258 rc = ost_handle_quotacheck(req);
2261 CDEBUG(D_INODE, "quotactl\n");
2262 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2263 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2265 rc = ost_handle_quotactl(req);
2267 case OST_QUOTA_ADJUST_QUNIT:
2268 CDEBUG(D_INODE, "quota_adjust_qunit\n");
2269 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
2270 rc = ost_handle_quota_adjust_qunit(req);
2274 DEBUG_REQ(D_INODE, req, "ping");
2275 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2276 rc = target_handle_ping(req);
2278 /* FIXME - just reply status */
2279 case LLOG_ORIGIN_CONNECT:
2280 DEBUG_REQ(D_INODE, req, "log connect");
2281 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2282 rc = ost_llog_handle_connect(req->rq_export, req);
2283 req->rq_status = rc;
2284 rc = req_capsule_server_pack(&req->rq_pill);
2287 RETURN(ptlrpc_reply(req));
2288 case OBD_LOG_CANCEL:
2289 CDEBUG(D_INODE, "log cancel\n");
2290 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2291 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2293 rc = llog_origin_handle_cancel(req);
2294 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2296 req->rq_status = rc;
2297 rc = req_capsule_server_pack(&req->rq_pill);
2300 RETURN(ptlrpc_reply(req));
2302 CDEBUG(D_INODE, "enqueue\n");
2303 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2304 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2306 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2308 ldlm_server_glimpse_ast);
2309 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2312 CDEBUG(D_INODE, "convert\n");
2313 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2314 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2316 rc = ldlm_handle_convert(req);
2319 CDEBUG(D_INODE, "cancel\n");
2320 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2321 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2323 rc = ldlm_handle_cancel(req);
2325 case LDLM_BL_CALLBACK:
2326 case LDLM_CP_CALLBACK:
2327 CDEBUG(D_INODE, "callback\n");
2328 CERROR("callbacks should not happen on OST\n");
2331 CERROR("Unexpected opcode %d\n",
2332 lustre_msg_get_opc(req->rq_reqmsg));
2333 req->rq_status = -ENOTSUPP;
2334 rc = ptlrpc_error(req);
2338 LASSERT(current->journal_info == NULL);
2341 /* If we're DISCONNECTing, the export_data is already freed */
2342 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2343 target_committed_to_req(req);
2347 oti_to_request(oti, req);
2349 target_send_reply(req, rc, fail);
2352 EXPORT_SYMBOL(ost_handle);
2354 * free per-thread pool created by ost_thread_init().
2356 static void ost_thread_done(struct ptlrpc_thread *thread)
2358 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2363 LASSERT(thread != NULL);
2366 * be prepared to handle partially-initialized pools (because this is
2367 * called from ost_thread_init() for cleanup.
2369 tls = thread->t_data;
2372 thread->t_data = NULL;
2378 * initialize per-thread page pool (bug 5137).
2380 static int ost_thread_init(struct ptlrpc_thread *thread)
2382 struct ost_thread_local_cache *tls;
2386 LASSERT(thread != NULL);
2387 LASSERT(thread->t_data == NULL);
2388 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
2393 thread->t_data = tls;
2397 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2399 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2400 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2402 struct ost_obd *ost = &obd->u.ost;
2403 struct lprocfs_static_vars lvars;
2404 int oss_min_threads;
2405 int oss_max_threads;
2406 int oss_min_create_threads;
2407 int oss_max_create_threads;
2411 rc = cfs_cleanup_group_info();
2415 lprocfs_ost_init_vars(&lvars);
2416 lprocfs_obd_setup(obd, lvars.obd_vars);
2418 cfs_sema_init(&ost->ost_health_sem, 1);
2420 if (oss_num_threads) {
2421 /* If oss_num_threads is set, it is the min and the max. */
2422 if (oss_num_threads > OSS_THREADS_MAX)
2423 oss_num_threads = OSS_THREADS_MAX;
2424 if (oss_num_threads < OSS_THREADS_MIN)
2425 oss_num_threads = OSS_THREADS_MIN;
2426 oss_max_threads = oss_min_threads = oss_num_threads;
2428 /* Base min threads on memory and cpus */
2430 cfs_num_possible_cpus() * CFS_NUM_CACHEPAGES >>
2431 (27 - CFS_PAGE_SHIFT);
2432 if (oss_min_threads < OSS_THREADS_MIN)
2433 oss_min_threads = OSS_THREADS_MIN;
2434 /* Insure a 4x range for dynamic threads */
2435 if (oss_min_threads > OSS_THREADS_MAX / 4)
2436 oss_min_threads = OSS_THREADS_MAX / 4;
2437 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
2441 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2442 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
2443 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2444 ost_handle, LUSTRE_OSS_NAME,
2445 obd->obd_proc_entry, target_print_req,
2446 oss_min_threads, oss_max_threads,
2447 "ll_ost", LCT_DT_THREAD, NULL);
2448 if (ost->ost_service == NULL) {
2449 CERROR("failed to start service\n");
2450 GOTO(out_lprocfs, rc = -ENOMEM);
2453 rc = ptlrpc_start_threads(ost->ost_service);
2455 GOTO(out_service, rc = -EINVAL);
2457 if (oss_num_create_threads) {
2458 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
2459 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
2460 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
2461 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
2462 oss_min_create_threads = oss_max_create_threads =
2463 oss_num_create_threads;
2465 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
2466 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
2469 ost->ost_create_service =
2470 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2471 OST_MAXREPSIZE, OST_CREATE_PORTAL,
2472 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2473 ost_handle, "ost_create",
2474 obd->obd_proc_entry, target_print_req,
2475 oss_min_create_threads, oss_max_create_threads,
2476 "ll_ost_creat", LCT_DT_THREAD, NULL);
2477 if (ost->ost_create_service == NULL) {
2478 CERROR("failed to start OST create service\n");
2479 GOTO(out_service, rc = -ENOMEM);
2482 rc = ptlrpc_start_threads(ost->ost_create_service);
2484 GOTO(out_create, rc = -EINVAL);
2486 ost->ost_io_service =
2487 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2488 OST_MAXREPSIZE, OST_IO_PORTAL,
2489 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2490 ost_handle, "ost_io",
2491 obd->obd_proc_entry, target_print_req,
2492 oss_min_threads, oss_max_threads,
2493 "ll_ost_io", LCT_DT_THREAD, ost_hpreq_handler);
2494 if (ost->ost_io_service == NULL) {
2495 CERROR("failed to start OST I/O service\n");
2496 GOTO(out_create, rc = -ENOMEM);
2499 ost->ost_io_service->srv_init = ost_thread_init;
2500 ost->ost_io_service->srv_done = ost_thread_done;
2501 ost->ost_io_service->srv_cpu_affinity = 1;
2502 rc = ptlrpc_start_threads(ost->ost_io_service);
2504 GOTO(out_io, rc = -EINVAL);
2506 ping_evictor_start();
2511 ptlrpc_unregister_service(ost->ost_io_service);
2512 ost->ost_io_service = NULL;
2514 ptlrpc_unregister_service(ost->ost_create_service);
2515 ost->ost_create_service = NULL;
2517 ptlrpc_unregister_service(ost->ost_service);
2518 ost->ost_service = NULL;
2520 lprocfs_obd_cleanup(obd);
2524 static int ost_cleanup(struct obd_device *obd)
2526 struct ost_obd *ost = &obd->u.ost;
2530 ping_evictor_stop();
2532 /* there is no recovery for OST OBD, all recovery is controlled by
2534 LASSERT(obd->obd_recovering == 0);
2535 cfs_down(&ost->ost_health_sem);
2536 ptlrpc_unregister_service(ost->ost_service);
2537 ptlrpc_unregister_service(ost->ost_create_service);
2538 ptlrpc_unregister_service(ost->ost_io_service);
2539 ost->ost_service = NULL;
2540 ost->ost_create_service = NULL;
2541 cfs_up(&ost->ost_health_sem);
2543 lprocfs_obd_cleanup(obd);
2548 static int ost_health_check(struct obd_device *obd)
2550 struct ost_obd *ost = &obd->u.ost;
2553 cfs_down(&ost->ost_health_sem);
2554 rc |= ptlrpc_service_health_check(ost->ost_service);
2555 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2556 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2557 cfs_up(&ost->ost_health_sem);
2560 * health_check to return 0 on healthy
2561 * and 1 on unhealthy.
2569 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2571 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2574 /* use obd ops to offer management infrastructure */
2575 static struct obd_ops ost_obd_ops = {
2576 .o_owner = THIS_MODULE,
2577 .o_setup = ost_setup,
2578 .o_cleanup = ost_cleanup,
2579 .o_health_check = ost_health_check,
2583 static int __init ost_init(void)
2585 struct lprocfs_static_vars lvars;
2589 lprocfs_ost_init_vars(&lvars);
2590 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2591 LUSTRE_OSS_NAME, NULL);
2593 if (ost_num_threads != 0 && oss_num_threads == 0) {
2594 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2595 "use oss_num_threads instead or unset both for "
2596 "dynamic thread startup\n");
2597 oss_num_threads = ost_num_threads;
2603 static void /*__exit*/ ost_exit(void)
2605 class_unregister_type(LUSTRE_OSS_NAME);
2608 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2609 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2610 MODULE_LICENSE("GPL");
2612 module_init(ost_init);
2613 module_exit(ost_exit);