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 2008 Sun Microsystems, Inc. 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);
84 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
86 struct oti_req_ack_lock *ack_lock;
93 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
94 req->rq_transno = oti->oti_transno;
96 /* XXX 4 == entries in oti_ack_locks??? */
97 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
100 /* XXX not even calling target_send_reply in some cases... */
101 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode, 0);
105 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
106 struct obd_trans_info *oti)
108 struct ost_body *body, *repbody;
109 struct lustre_capa *capa = NULL;
113 /* Get the request body */
114 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
118 if (body->oa.o_id == 0)
121 /* If there's a DLM request, cancel the locks mentioned in it*/
122 if (req_capsule_field_present(&req->rq_pill, &RMF_DLM_REQ, RCL_CLIENT)) {
123 struct ldlm_request *dlm;
125 dlm = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
128 ldlm_request_cancel(req, dlm, 0);
131 /* If there's a capability, get it */
132 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
133 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
135 CERROR("Missing capability for OST DESTROY");
140 /* Prepare the reply */
141 rc = req_capsule_server_pack(&req->rq_pill);
145 /* Get the log cancellation cookie */
146 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
147 oti->oti_logcookies = &body->oa.o_lcookie;
149 /* Finish the reply */
150 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
151 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
153 /* Do the destroy and set the reply status accordingly */
154 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL, capa);
158 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
160 struct ost_body *body, *repbody;
161 struct obd_info oinfo = { { { 0 } } };
165 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
169 rc = req_capsule_server_pack(&req->rq_pill);
173 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
174 repbody->oa = body->oa;
176 oinfo.oi_oa = &repbody->oa;
177 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA) {
178 oinfo.oi_capa = req_capsule_client_get(&req->rq_pill,
180 if (oinfo.oi_capa == NULL) {
181 CERROR("Missing capability for OST GETATTR");
186 req->rq_status = obd_getattr(exp, &oinfo);
187 ost_drop_id(exp, &repbody->oa);
191 static int ost_statfs(struct ptlrpc_request *req)
193 struct obd_statfs *osfs;
197 rc = req_capsule_server_pack(&req->rq_pill);
201 osfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
203 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
204 cfs_time_current_64() - HZ, 0);
205 if (req->rq_status != 0)
206 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
211 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
212 struct obd_trans_info *oti)
214 struct ost_body *body, *repbody;
218 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
222 rc = req_capsule_server_pack(&req->rq_pill);
226 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
227 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
228 oti->oti_logcookies = &repbody->oa.o_lcookie;
230 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
231 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
236 * Helper function for ost_punch(): if asked by client, acquire [size, EOF]
237 * lock on the file being truncated.
239 static int ost_punch_lock_get(struct obd_export *exp, struct obdo *oa,
240 struct lustre_handle *lh)
243 struct ldlm_res_id res_id;
244 ldlm_policy_data_t policy;
250 osc_build_res_name(oa->o_id, oa->o_gr, &res_id);
251 LASSERT(!lustre_handle_is_used(lh));
253 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
254 !(oa->o_flags & OBD_FL_TRUNCLOCK))
257 CDEBUG(D_INODE, "OST-side truncate lock.\n");
260 finis = start + oa->o_blocks;
263 * standard truncate optimization: if file body is completely
264 * destroyed, don't send data back to the server.
266 flags = (start == 0) ? LDLM_AST_DISCARD_DATA : 0;
268 policy.l_extent.start = start & CFS_PAGE_MASK;
271 * If ->o_blocks is EOF it means "lock till the end of the
272 * file". Otherwise, it's size of a hole being punched (in bytes)
274 if (oa->o_blocks == OBD_OBJECT_EOF || finis < start)
275 policy.l_extent.end = OBD_OBJECT_EOF;
277 policy.l_extent.end = finis | ~CFS_PAGE_MASK;
279 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
280 LDLM_EXTENT, &policy, LCK_PW, &flags,
281 ldlm_blocking_ast, ldlm_completion_ast,
282 ldlm_glimpse_ast, NULL, 0, NULL, lh));
286 * Helper function for ost_punch(): release lock acquired by
287 * ost_punch_lock_get(), if any.
289 static void ost_punch_lock_put(struct obd_export *exp, struct obdo *oa,
290 struct lustre_handle *lh)
293 if (lustre_handle_is_used(lh))
294 ldlm_lock_decref(lh, LCK_PW);
298 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
299 struct obd_trans_info *oti)
301 struct obd_info oinfo = { { { 0 } } };
302 struct ost_body *body, *repbody;
304 struct lustre_handle lh = {0,};
307 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
308 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
310 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
314 oinfo.oi_oa = &body->oa;
315 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
316 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
318 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
319 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
322 rc = req_capsule_server_pack(&req->rq_pill);
326 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
327 rc = ost_punch_lock_get(exp, oinfo.oi_oa, &lh);
329 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
330 oinfo.oi_oa->o_flags == OBD_FL_TRUNCLOCK)
332 * If OBD_FL_TRUNCLOCK is the only bit set in
333 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
334 * through filter_setattr() to filter_iocontrol().
336 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
338 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA) {
339 oinfo.oi_capa = req_capsule_client_get(&req->rq_pill,
341 if (oinfo.oi_capa == NULL) {
342 CERROR("Missing capability for OST PUNCH");
346 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
347 ost_punch_lock_put(exp, oinfo.oi_oa, &lh);
349 repbody->oa = *oinfo.oi_oa;
350 ost_drop_id(exp, &repbody->oa);
354 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
356 struct ost_body *body, *repbody;
357 struct lustre_capa *capa = NULL;
361 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
365 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
366 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
368 CERROR("Missing capability for OST SYNC");
373 rc = req_capsule_server_pack(&req->rq_pill);
377 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
378 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
379 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
380 repbody->oa.o_blocks, capa);
381 ost_drop_id(exp, &repbody->oa);
385 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
386 struct obd_trans_info *oti)
388 struct ost_body *body, *repbody;
390 struct obd_info oinfo = { { { 0 } } };
393 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
397 rc = req_capsule_server_pack(&req->rq_pill);
401 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
402 repbody->oa = body->oa;
404 oinfo.oi_oa = &repbody->oa;
405 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA) {
406 oinfo.oi_capa = req_capsule_client_get(&req->rq_pill,
408 if (oinfo.oi_capa == NULL) {
409 CERROR("Missing capability for OST SETATTR");
413 req->rq_status = obd_setattr(exp, &oinfo, oti);
414 ost_drop_id(exp, &repbody->oa);
418 static int ost_bulk_timeout(void *data)
421 /* We don't fail the connection here, because having the export
422 * killed makes the (vital) call to commitrw very sad.
427 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
428 cksum_type_t cksum_type)
433 cksum = init_checksum(cksum_type);
434 for (i = 0; i < desc->bd_iov_count; i++) {
435 struct page *page = desc->bd_iov[i].kiov_page;
436 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
437 char *ptr = kmap(page) + off;
438 int len = desc->bd_iov[i].kiov_len;
440 /* corrupt the data before we compute the checksum, to
441 * simulate a client->OST data error */
442 if (i == 0 && opc == OST_WRITE &&
443 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
444 memcpy(ptr, "bad3", min(4, len));
445 cksum = compute_checksum(cksum, ptr, len, cksum_type);
446 /* corrupt the data after we compute the checksum, to
447 * simulate an OST->client data error */
448 if (i == 0 && opc == OST_READ &&
449 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
450 memcpy(ptr, "bad4", min(4, len));
451 /* nobody should use corrupted page again */
452 ClearPageUptodate(page);
460 static int ost_brw_lock_get(int mode, struct obd_export *exp,
461 struct obd_ioobj *obj, struct niobuf_remote *nb,
462 struct lustre_handle *lh)
465 int nrbufs = obj->ioo_bufcnt;
466 struct ldlm_res_id res_id;
467 ldlm_policy_data_t policy;
471 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
472 LASSERT(mode == LCK_PR || mode == LCK_PW);
473 LASSERT(!lustre_handle_is_used(lh));
475 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
478 for (i = 1; i < nrbufs; i ++)
479 if ((nb[0].flags & OBD_BRW_SRVLOCK) !=
480 (nb[i].flags & OBD_BRW_SRVLOCK))
483 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
484 policy.l_extent.end = (nb[nrbufs - 1].offset +
485 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
487 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
488 LDLM_EXTENT, &policy, mode, &flags,
489 ldlm_blocking_ast, ldlm_completion_ast,
490 ldlm_glimpse_ast, NULL, 0, NULL, lh));
493 static void ost_brw_lock_put(int mode,
494 struct obd_ioobj *obj, struct niobuf_remote *niob,
495 struct lustre_handle *lh)
498 LASSERT(mode == LCK_PR || mode == LCK_PW);
499 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
500 lustre_handle_is_used(lh));
501 if (lustre_handle_is_used(lh))
502 ldlm_lock_decref(lh, mode);
506 struct ost_prolong_data {
507 struct obd_export *opd_exp;
508 ldlm_policy_data_t opd_policy;
510 ldlm_mode_t opd_mode;
515 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
517 struct ost_prolong_data *opd = data;
519 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
521 if (lock->l_req_mode != lock->l_granted_mode) {
522 /* scan granted locks only */
523 return LDLM_ITER_STOP;
526 if (lock->l_export != opd->opd_exp) {
527 /* prolong locks only for given client */
528 return LDLM_ITER_CONTINUE;
531 if (!(lock->l_granted_mode & opd->opd_mode)) {
532 /* we aren't interesting in all type of locks */
533 return LDLM_ITER_CONTINUE;
536 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
537 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
538 /* the request doesn't cross the lock, skip it */
539 return LDLM_ITER_CONTINUE;
542 /* Fill the obdo with the matched lock handle.
543 * XXX: it is possible in some cases the IO RPC is covered by several
544 * locks, even for the write case, so it may need to be a lock list. */
545 if (opd->opd_oa && !(opd->opd_oa->o_valid & OBD_MD_FLHANDLE)) {
546 opd->opd_oa->o_handle.cookie = lock->l_handle.h_cookie;
547 opd->opd_oa->o_valid |= OBD_MD_FLHANDLE;
550 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
551 /* ignore locks not being cancelled */
552 return LDLM_ITER_CONTINUE;
555 CDEBUG(D_DLMTRACE,"refresh lock: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
556 lock->l_resource->lr_name.name[0],
557 lock->l_resource->lr_name.name[1],
558 opd->opd_policy.l_extent.start, opd->opd_policy.l_extent.end);
559 /* OK. this is a possible lock the user holds doing I/O
560 * let's refresh eviction timer for it */
561 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
562 opd->opd_lock_match = 1;
564 return LDLM_ITER_CONTINUE;
567 static int ost_rw_prolong_locks(struct ptlrpc_request *req, struct obd_ioobj *obj,
568 struct niobuf_remote *nb, struct obdo *oa,
571 struct ldlm_res_id res_id;
572 int nrbufs = obj->ioo_bufcnt;
573 struct ost_prolong_data opd = { 0 };
576 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
579 opd.opd_exp = req->rq_export;
580 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
581 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
582 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
584 /* prolong locks for the current service time of the corresponding
585 * portal (= OST_IO_PORTAL) */
586 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
587 max(at_est2timeout(at_get(&req->rq_rqbd->
588 rqbd_service->srv_at_estimate)), ldlm_timeout);
590 CDEBUG(D_INFO,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
591 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
592 opd.opd_policy.l_extent.end);
594 if (oa->o_valid & OBD_MD_FLHANDLE) {
595 struct ldlm_lock *lock;
597 lock = ldlm_handle2lock(&oa->o_handle);
599 ost_prolong_locks_iter(lock, &opd);
600 if (opd.opd_lock_match) {
605 /* Check if the lock covers the whole IO region,
606 * otherwise iterate through the resource. */
607 if (lock->l_policy_data.l_extent.end >=
608 opd.opd_policy.l_extent.end &&
609 lock->l_policy_data.l_extent.start <=
610 opd.opd_policy.l_extent.start) {
619 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
620 ost_prolong_locks_iter, &opd);
621 RETURN(opd.opd_lock_match);
624 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
626 struct ptlrpc_bulk_desc *desc = NULL;
627 struct obd_export *exp = req->rq_export;
628 struct niobuf_remote *remote_nb;
629 struct niobuf_local *local_nb;
630 struct obd_ioobj *ioo;
631 struct ost_body *body, *repbody;
632 struct lustre_capa *capa = NULL;
633 struct l_wait_info lwi;
634 struct lustre_handle lockh = { 0 };
635 int niocount, npages, nob = 0, rc, i;
639 req->rq_bulk_read = 1;
641 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
642 GOTO(out, rc = -EIO);
644 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
646 /* Check if there is eviction in progress, and if so, wait for it to
648 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
649 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
650 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
651 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
655 GOTO(out, rc = -ENOTCONN);
657 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
658 * ost_rw_hpreq_check(). */
659 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
661 GOTO(out, rc = -EFAULT);
664 * A req_capsule_X_get_array(pill, field, ptr_to_element_count) function
665 * would be useful here and wherever we get &RMF_OBD_IOOBJ and
666 * &RMF_NIOBUF_REMOTE.
668 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
670 GOTO(out, rc = -EFAULT);
672 niocount = ioo->ioo_bufcnt;
673 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
674 if (remote_nb == NULL)
675 GOTO(out, rc = -EFAULT);
677 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
678 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
680 CERROR("Missing capability for OST BRW READ");
681 GOTO(out, rc = -EFAULT);
685 req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER, 0);
686 rc = req_capsule_server_pack(&req->rq_pill);
691 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
694 local_nb = ost_tls(req)->local;
696 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
701 * If getting the lock took more time than
702 * client was willing to wait, drop it. b=11330
704 if (cfs_time_current_sec() > req->rq_deadline ||
705 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
707 CERROR("Dropping timed-out read from %s because locking"
708 "object "LPX64" took %ld seconds (limit was %ld).\n",
709 libcfs_id2str(req->rq_peer), ioo->ioo_id,
710 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
711 req->rq_deadline - req->rq_arrival_time.tv_sec);
712 GOTO(out_lock, rc = -ETIMEDOUT);
715 npages = OST_THREAD_POOL_SIZE;
716 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
717 remote_nb, &npages, local_nb, oti, capa);
721 desc = ptlrpc_prep_bulk_exp(req, npages,
722 BULK_PUT_SOURCE, OST_BULK_PORTAL);
724 GOTO(out_lock, rc = -ENOMEM);
726 if (!lustre_handle_is_used(&lockh))
727 /* no needs to try to prolong lock if server is asked
728 * to handle locking (= OBD_BRW_SRVLOCK) */
729 ost_rw_prolong_locks(req, ioo, remote_nb, &body->oa,
733 for (i = 0; i < npages; i++) {
734 int page_rc = local_nb[i].rc;
736 if (page_rc < 0) { /* error */
742 if (page_rc != 0) { /* some data! */
743 LASSERT (local_nb[i].page != NULL);
744 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
745 local_nb[i].offset & ~CFS_PAGE_MASK,
749 if (page_rc != local_nb[i].len) { /* short read */
750 /* All subsequent pages should be 0 */
752 LASSERT(local_nb[i].rc == 0);
757 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
758 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
760 if (body->oa.o_valid & OBD_MD_FLFLAGS)
761 cksum_type = cksum_type_unpack(body->oa.o_flags);
762 body->oa.o_flags = cksum_type_pack(cksum_type);
763 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
764 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
765 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
767 body->oa.o_valid = 0;
769 /* We're finishing using body->oa as an input variable */
771 /* Check if client was evicted while we were doing i/o before touching
774 /* Check if there is eviction in progress, and if so, wait for
776 if (unlikely(atomic_read(&exp->exp_obd->
777 obd_evict_inprogress))) {
778 lwi = LWI_INTR(NULL, NULL);
779 rc = l_wait_event(exp->exp_obd->
780 obd_evict_inprogress_waitq,
781 !atomic_read(&exp->exp_obd->
782 obd_evict_inprogress),
785 /* Check if client was evicted or tried to reconnect already */
786 if (exp->exp_failed || exp->exp_abort_active_req)
789 rc = sptlrpc_svc_wrap_bulk(req, desc);
791 rc = ptlrpc_start_bulk_transfer(desc);
795 time_t start = cfs_time_current_sec();
797 long timeoutl = req->rq_deadline -
798 cfs_time_current_sec();
799 cfs_duration_t timeout = timeoutl <= 0 ?
800 CFS_TICK : cfs_time_seconds(timeoutl);
801 lwi = LWI_TIMEOUT_INTERVAL(timeout,
805 rc = l_wait_event(desc->bd_waitq,
806 !ptlrpc_server_bulk_active(desc) ||
808 exp->exp_abort_active_req,
810 LASSERT(rc == 0 || rc == -ETIMEDOUT);
811 /* Wait again if we changed deadline */
812 } while ((rc == -ETIMEDOUT) &&
813 (req->rq_deadline > cfs_time_current_sec()));
815 if (rc == -ETIMEDOUT) {
816 DEBUG_REQ(D_ERROR, req,
817 "timeout on bulk PUT after %ld%+lds",
818 req->rq_deadline - start,
819 cfs_time_current_sec() -
821 ptlrpc_abort_bulk(desc);
822 } else if (exp->exp_failed) {
823 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
825 ptlrpc_abort_bulk(desc);
826 } else if (exp->exp_abort_active_req) {
827 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk PUT");
828 /* we don't reply anyway */
830 ptlrpc_abort_bulk(desc);
831 } else if (!desc->bd_success ||
832 desc->bd_nob_transferred != desc->bd_nob) {
833 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
835 "truncated" : "network error on",
836 desc->bd_nob_transferred,
838 /* XXX should this be a different errno? */
842 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
847 /* Must commit after prep above in all cases */
848 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
849 remote_nb, npages, local_nb, oti, rc);
852 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
853 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
854 ost_drop_id(exp, &repbody->oa);
858 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
861 ptlrpc_free_bulk(desc);
865 req->rq_status = nob;
866 ptlrpc_lprocfs_brw(req, nob);
867 target_committed_to_req(req);
869 } else if (!no_reply) {
870 /* Only reply if there was no comms problem with bulk */
871 target_committed_to_req(req);
875 /* reply out callback would free */
876 ptlrpc_req_drop_rs(req);
877 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
878 "client will retry\n",
879 exp->exp_obd->obd_name,
880 exp->exp_client_uuid.uuid,
881 exp->exp_connection->c_remote_uuid.uuid,
882 libcfs_id2str(req->rq_peer));
888 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
890 struct ptlrpc_bulk_desc *desc = NULL;
891 struct obd_export *exp = req->rq_export;
892 struct niobuf_remote *remote_nb;
893 struct niobuf_local *local_nb;
894 struct obd_ioobj *ioo;
895 struct ost_body *body, *repbody;
896 struct l_wait_info lwi;
897 struct lustre_handle lockh = {0};
898 struct lustre_capa *capa = NULL;
900 int objcount, niocount, npages;
902 obd_count client_cksum = 0, server_cksum = 0;
903 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
905 __u32 o_uid = 0, o_gid = 0;
908 req->rq_bulk_write = 1;
910 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
911 GOTO(out, rc = -EIO);
912 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
913 GOTO(out, rc = -EFAULT);
915 /* pause before transaction has been started */
916 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
918 /* Check if there is eviction in progress, and if so, wait for it to
920 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
921 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
922 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
923 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
927 GOTO(out, rc = -ENOTCONN);
929 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
930 * ost_rw_hpreq_check(). */
931 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
933 GOTO(out, rc = -EFAULT);
935 if ((body->oa.o_flags & OBD_BRW_MEMALLOC) &&
936 (exp->exp_connection->c_peer.nid == exp->exp_connection->c_self))
937 libcfs_memory_pressure_set();
939 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
940 RCL_CLIENT) / sizeof(*ioo);
941 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
943 GOTO(out, rc = -EFAULT);
944 for (niocount = i = 0; i < objcount; i++)
945 niocount += ioo[i].ioo_bufcnt;
948 * It'd be nice to have a capsule function to indicate how many elements
949 * there were in a buffer for an RMF that's declared to be an array.
950 * It's easy enough to compute the number of elements here though.
952 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
953 if (remote_nb == NULL || niocount != (req_capsule_get_size(&req->rq_pill,
954 &RMF_NIOBUF_REMOTE, RCL_CLIENT) / sizeof(*remote_nb)))
955 GOTO(out, rc = -EFAULT);
957 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
958 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
960 CERROR("Missing capability for OST BRW WRITE");
961 GOTO(out, rc = -EFAULT);
965 req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER,
966 niocount * sizeof(*rcs));
967 rc = req_capsule_server_pack(&req->rq_pill);
970 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, obd_fail_val);
971 rcs = req_capsule_server_get(&req->rq_pill, &RMF_RCS);
974 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
977 local_nb = ost_tls(req)->local;
979 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
984 * If getting the lock took more time than
985 * client was willing to wait, drop it. b=11330
987 if (cfs_time_current_sec() > req->rq_deadline ||
988 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
990 CERROR("Dropping timed-out write from %s because locking "
991 "object "LPX64" took %ld seconds (limit was %ld).\n",
992 libcfs_id2str(req->rq_peer), ioo->ioo_id,
993 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
994 req->rq_deadline - req->rq_arrival_time.tv_sec);
995 GOTO(out_lock, rc = -ETIMEDOUT);
998 if (!lustre_handle_is_used(&lockh))
999 /* no needs to try to prolong lock if server is asked
1000 * to handle locking (= OBD_BRW_SRVLOCK) */
1001 ost_rw_prolong_locks(req, ioo, remote_nb,&body->oa, LCK_PW);
1003 /* obd_preprw clobbers oa->valid, so save what we need */
1004 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
1005 client_cksum = body->oa.o_cksum;
1006 if (body->oa.o_valid & OBD_MD_FLFLAGS)
1007 cksum_type = cksum_type_unpack(body->oa.o_flags);
1010 /* Because we already sync grant info with client when reconnect,
1011 * grant info will be cleared for resent req, then fed_grant and
1012 * total_grant will not be modified in following preprw_write */
1013 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1014 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1015 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1018 if (exp_connect_rmtclient(exp)) {
1019 o_uid = body->oa.o_uid;
1020 o_gid = body->oa.o_gid;
1022 npages = OST_THREAD_POOL_SIZE;
1023 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
1024 ioo, remote_nb, &npages, local_nb, oti, capa);
1028 desc = ptlrpc_prep_bulk_exp(req, npages,
1029 BULK_GET_SINK, OST_BULK_PORTAL);
1031 GOTO(out_lock, rc = -ENOMEM);
1033 /* NB Having prepped, we must commit... */
1035 for (i = 0; i < npages; i++)
1036 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1037 local_nb[i].offset & ~CFS_PAGE_MASK,
1040 rc = sptlrpc_svc_prep_bulk(req, desc);
1044 /* Check if client was evicted or tried to reconnect while we
1045 * were doing i/o before touching network */
1046 if (desc->bd_export->exp_failed ||
1047 desc->bd_export->exp_abort_active_req)
1050 rc = ptlrpc_start_bulk_transfer(desc);
1052 time_t start = cfs_time_current_sec();
1054 long timeoutl = req->rq_deadline -
1055 cfs_time_current_sec();
1056 cfs_duration_t timeout = timeoutl <= 0 ?
1057 CFS_TICK : cfs_time_seconds(timeoutl);
1058 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
1059 ost_bulk_timeout, desc);
1060 rc = l_wait_event(desc->bd_waitq,
1061 !ptlrpc_server_bulk_active(desc) ||
1062 desc->bd_export->exp_failed ||
1063 desc->bd_export->exp_abort_active_req,
1065 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1066 /* Wait again if we changed deadline */
1067 } while ((rc == -ETIMEDOUT) &&
1068 (req->rq_deadline > cfs_time_current_sec()));
1070 if (rc == -ETIMEDOUT) {
1071 DEBUG_REQ(D_ERROR, req,
1072 "timeout on bulk GET after %ld%+lds",
1073 req->rq_deadline - start,
1074 cfs_time_current_sec() -
1076 ptlrpc_abort_bulk(desc);
1077 } else if (desc->bd_export->exp_failed) {
1078 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1080 ptlrpc_abort_bulk(desc);
1081 } else if (desc->bd_export->exp_abort_active_req) {
1082 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk GET");
1083 /* we don't reply anyway */
1085 ptlrpc_abort_bulk(desc);
1086 } else if (!desc->bd_success) {
1087 DEBUG_REQ(D_ERROR, req, "network error on bulk GET");
1088 /* XXX should this be a different errno? */
1091 rc = sptlrpc_svc_unwrap_bulk(req, desc);
1094 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1098 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
1099 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1101 if (unlikely(client_cksum != 0 && rc == 0)) {
1102 static int cksum_counter;
1103 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1104 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1105 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1106 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1107 repbody->oa.o_cksum = server_cksum;
1109 if (unlikely(client_cksum != server_cksum)) {
1110 CERROR("client csum %x, server csum %x\n",
1111 client_cksum, server_cksum);
1113 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1114 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1115 cksum_counter, libcfs_id2str(req->rq_peer),
1120 /* Must commit after prep above in all cases */
1121 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1122 remote_nb, npages, local_nb, oti, rc);
1123 if (rc == -ENOTCONN)
1124 /* quota acquire process has been given up because
1125 * either the client has been evicted or the client
1126 * has timed out the request already */
1129 if (exp_connect_rmtclient(exp)) {
1130 repbody->oa.o_uid = o_uid;
1131 repbody->oa.o_gid = o_gid;
1134 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1135 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1140 if (new_cksum == server_cksum)
1141 msg = "changed in transit before arrival at OST";
1142 else if (new_cksum == client_cksum)
1143 msg = "initial checksum before message complete";
1145 msg = "changed in transit AND after initial checksum";
1147 if (req->rq_peer.nid == desc->bd_sender) {
1151 router = libcfs_nid2str(desc->bd_sender);
1154 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1155 "%s%s%s inum "LPU64"/"LPU64" object "
1156 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1157 exp->exp_obd->obd_name, msg,
1158 libcfs_id2str(req->rq_peer),
1160 body->oa.o_valid & OBD_MD_FLFID ?
1161 body->oa.o_fid : (__u64)0,
1162 body->oa.o_valid & OBD_MD_FLFID ?
1163 body->oa.o_generation :(__u64)0,
1165 body->oa.o_valid & OBD_MD_FLGROUP ?
1166 body->oa.o_gr : (__u64)0,
1168 local_nb[npages-1].offset +
1169 local_nb[npages-1].len - 1 );
1170 CERROR("client csum %x, original server csum %x, "
1171 "server csum now %x\n",
1172 client_cksum, server_cksum, new_cksum);
1178 /* set per-requested niobuf return codes */
1179 for (i = j = 0; i < niocount; i++) {
1180 int len = remote_nb[i].len;
1185 LASSERT(j < npages);
1186 if (local_nb[j].rc < 0)
1187 rcs[i] = local_nb[j].rc;
1188 len -= local_nb[j].len;
1193 LASSERT(j == npages);
1194 ptlrpc_lprocfs_brw(req, nob);
1198 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1201 ptlrpc_free_bulk(desc);
1204 oti_to_request(oti, req);
1205 target_committed_to_req(req);
1206 rc = ptlrpc_reply(req);
1207 } else if (!no_reply) {
1208 /* Only reply if there was no comms problem with bulk */
1209 target_committed_to_req(req);
1210 req->rq_status = rc;
1213 /* reply out callback would free */
1214 ptlrpc_req_drop_rs(req);
1215 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1216 "client will retry\n",
1217 exp->exp_obd->obd_name,
1218 exp->exp_client_uuid.uuid,
1219 exp->exp_connection->c_remote_uuid.uuid,
1220 libcfs_id2str(req->rq_peer));
1222 libcfs_memory_pressure_clr();
1227 * Implementation of OST_SET_INFO.
1229 * OST_SET_INFO is like ioctl(): heavily overloaded. Specifically, it takes a
1230 * "key" and a value RPC buffers as arguments, with the value's contents
1231 * interpreted according to the key.
1233 * Value types that need swabbing have swabbing done explicitly, either here or
1234 * in functions called from here. This should be corrected: all swabbing should
1235 * be done in the capsule abstraction, as that will then allow us to move
1236 * swabbing exclusively to the client without having to modify server code
1237 * outside the capsule abstraction's implementation itself. To correct this
1238 * will require minor changes to the capsule abstraction; see the comments for
1239 * req_capsule_extend() in layout.c.
1241 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1243 struct ost_body *body = NULL, *repbody;
1244 char *key, *val = NULL;
1245 int keylen, vallen, rc = 0;
1246 int is_grant_shrink = 0;
1249 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1251 DEBUG_REQ(D_HA, req, "no set_info key");
1254 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1257 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1260 if ((is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK)))
1261 /* In this case the value is actually an RMF_OST_BODY, so we
1262 * transmutate the type of this PTLRPC */
1263 req_capsule_extend(&req->rq_pill, &RQF_OST_SET_GRANT_INFO);
1265 rc = req_capsule_server_pack(&req->rq_pill);
1270 if (is_grant_shrink) {
1271 body = req_capsule_client_get(&req->rq_pill,
1276 repbody = req_capsule_server_get(&req->rq_pill,
1278 memcpy(repbody, body, sizeof(*body));
1279 val = (char*)repbody;
1281 val = req_capsule_client_get(&req->rq_pill,
1286 if (KEY_IS(KEY_EVICT_BY_NID)) {
1288 obd_export_evict_by_nid(exp->exp_obd, val);
1290 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1291 if (vallen < sizeof(__u32))
1293 __swab32s((__u32 *)val);
1296 /* OBD will also check if KEY_IS(KEY_GRANT_SHRINK), and will cast val to
1297 * a struct ost_body * value */
1298 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1300 lustre_msg_set_status(req->rq_repmsg, 0);
1304 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1307 int keylen, replylen, rc = 0;
1308 struct req_capsule *pill = &req->rq_pill;
1311 /* this common part for get_info rpc */
1312 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1314 DEBUG_REQ(D_HA, req, "no get_info key");
1317 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1319 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1323 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1324 RCL_SERVER, replylen);
1326 rc = req_capsule_server_pack(pill);
1330 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1334 /* call again to fill in the reply buffer */
1335 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1337 lustre_msg_set_status(req->rq_repmsg, 0);
1341 #ifdef HAVE_QUOTA_SUPPORT
1342 static int ost_handle_quotactl(struct ptlrpc_request *req)
1344 struct obd_quotactl *oqctl, *repoqc;
1348 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1350 GOTO(out, rc = -EPROTO);
1352 rc = req_capsule_server_pack(&req->rq_pill);
1356 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1357 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1364 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1366 struct obd_quotactl *oqctl;
1370 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1374 rc = req_capsule_server_pack(&req->rq_pill);
1378 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1382 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1384 struct quota_adjust_qunit *oqaq, *repoqa;
1385 struct lustre_quota_ctxt *qctxt;
1389 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1390 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1392 GOTO(out, rc = -EPROTO);
1394 rc = req_capsule_server_pack(&req->rq_pill);
1398 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1399 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt);
1407 static int ost_llog_handle_connect(struct obd_export *exp,
1408 struct ptlrpc_request *req)
1410 struct llogd_conn_body *body;
1414 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
1415 rc = obd_llog_connect(exp, body);
1419 #define ost_init_sec_none(reply, exp) \
1421 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1422 OBD_CONNECT_RMT_CLIENT_FORCE | \
1423 OBD_CONNECT_OSS_CAPA); \
1424 spin_lock(&exp->exp_lock); \
1425 exp->exp_connect_flags = reply->ocd_connect_flags; \
1426 spin_unlock(&exp->exp_lock); \
1429 static int ost_init_sec_level(struct ptlrpc_request *req)
1431 struct obd_export *exp = req->rq_export;
1432 struct req_capsule *pill = &req->rq_pill;
1433 struct obd_device *obd = exp->exp_obd;
1434 struct filter_obd *filter = &obd->u.filter;
1435 char *client = libcfs_nid2str(req->rq_peer.nid);
1436 struct obd_connect_data *data, *reply;
1440 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1441 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1442 if (data == NULL || reply == NULL)
1445 /* connection from MDT is always trusted */
1446 if (req->rq_auth_usr_mdt) {
1447 ost_init_sec_none(reply, exp);
1451 /* no GSS support case */
1452 if (!req->rq_auth_gss) {
1453 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1454 CWARN("client %s -> target %s does not user GSS, "
1455 "can not run under security level %d.\n",
1456 client, obd->obd_name, filter->fo_sec_level);
1459 ost_init_sec_none(reply, exp);
1464 /* old version case */
1465 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1466 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1467 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1468 CWARN("client %s -> target %s uses old version, "
1469 "can not run under security level %d.\n",
1470 client, obd->obd_name, filter->fo_sec_level);
1473 CWARN("client %s -> target %s uses old version, "
1474 "run under security level %d.\n",
1475 client, obd->obd_name, filter->fo_sec_level);
1476 ost_init_sec_none(reply, exp);
1481 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1483 if (!req->rq_auth_remote)
1484 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1485 "asked to be remote.\n", client, obd->obd_name);
1486 } else if (req->rq_auth_remote) {
1488 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1489 "as remote by default.\n", client, obd->obd_name);
1493 if (!filter->fo_fl_oss_capa) {
1494 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1495 " but OSS capabilities are not enabled: %d.\n",
1496 client, obd->obd_name, filter->fo_fl_oss_capa);
1501 switch (filter->fo_sec_level) {
1502 case LUSTRE_SEC_NONE:
1504 ost_init_sec_none(reply, exp);
1507 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1508 "can not run under security level %d.\n",
1509 client, obd->obd_name, filter->fo_sec_level);
1512 case LUSTRE_SEC_REMOTE:
1514 ost_init_sec_none(reply, exp);
1516 case LUSTRE_SEC_ALL:
1518 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1519 OBD_CONNECT_RMT_CLIENT_FORCE);
1520 if (!filter->fo_fl_oss_capa)
1521 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1523 spin_lock(&exp->exp_lock);
1524 exp->exp_connect_flags = reply->ocd_connect_flags;
1525 spin_unlock(&exp->exp_lock);
1537 * this should be done in filter_connect()/filter_reconnect(), but
1538 * we can't obtain information like NID, which stored in incoming
1539 * request, thus can't decide what flavor to use. so we do it here.
1541 * This hack should be removed after the OST stack be rewritten, just
1542 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1544 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1546 struct obd_export *exp = req->rq_export;
1547 struct filter_obd *filter = &exp->exp_obd->u.filter;
1548 struct sptlrpc_flavor flvr;
1551 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1552 LUSTRE_ECHO_NAME) == 0)) {
1553 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1557 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1558 read_lock(&filter->fo_sptlrpc_lock);
1559 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1563 read_unlock(&filter->fo_sptlrpc_lock);
1565 spin_lock(&exp->exp_lock);
1567 exp->exp_sp_peer = req->rq_sp_from;
1568 exp->exp_flvr = flvr;
1570 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1571 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1572 CERROR("unauthorized rpc flavor %x from %s, "
1573 "expect %x\n", req->rq_flvr.sf_rpc,
1574 libcfs_nid2str(req->rq_peer.nid),
1575 exp->exp_flvr.sf_rpc);
1579 spin_unlock(&exp->exp_lock);
1581 if (exp->exp_sp_peer != req->rq_sp_from) {
1582 CERROR("RPC source %s doesn't match %s\n",
1583 sptlrpc_part2name(req->rq_sp_from),
1584 sptlrpc_part2name(exp->exp_sp_peer));
1587 rc = sptlrpc_target_export_check(exp, req);
1594 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1595 struct obd_device *obd, int *process)
1597 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1598 case OST_CONNECT: /* This will never get here, but for completeness. */
1599 case OST_DISCONNECT:
1610 case OBD_LOG_CANCEL:
1612 *process = target_queue_recovery_request(req, obd);
1616 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1622 int ost_msg_check_version(struct lustre_msg *msg)
1626 switch(lustre_msg_get_opc(msg)) {
1628 case OST_DISCONNECT:
1631 case SEC_CTX_INIT_CONT:
1633 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1635 CERROR("bad opc %u version %08x, expecting %08x\n",
1636 lustre_msg_get_opc(msg),
1637 lustre_msg_get_version(msg),
1638 LUSTRE_OBD_VERSION);
1651 #ifdef HAVE_QUOTA_SUPPORT
1652 case OST_QUOTACHECK:
1654 case OST_QUOTA_ADJUST_QUNIT:
1656 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1658 CERROR("bad opc %u version %08x, expecting %08x\n",
1659 lustre_msg_get_opc(msg),
1660 lustre_msg_get_version(msg),
1661 LUSTRE_OST_VERSION);
1666 case LDLM_BL_CALLBACK:
1667 case LDLM_CP_CALLBACK:
1668 rc = lustre_msg_check_version(msg, LUSTRE_DLM_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_DLM_VERSION);
1675 case LLOG_ORIGIN_CONNECT:
1676 case OBD_LOG_CANCEL:
1677 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1679 CERROR("bad opc %u version %08x, expecting %08x\n",
1680 lustre_msg_get_opc(msg),
1681 lustre_msg_get_version(msg),
1682 LUSTRE_LOG_VERSION);
1685 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1692 * Returns 1 if the given PTLRPC matches the given LDLM locks, or 0 if it does
1695 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1696 struct ldlm_lock *lock)
1698 struct niobuf_remote *nb;
1699 struct obd_ioobj *ioo;
1700 struct ost_body *body;
1701 int objcount, niocount;
1706 opc = lustre_msg_get_opc(req->rq_reqmsg);
1707 LASSERT(opc == OST_READ || opc == OST_WRITE);
1709 /* As the request may be covered by several locks, do not look at
1710 * o_handle, look at the RPC IO region. */
1711 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1715 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1716 RCL_CLIENT) / sizeof(*ioo);
1717 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1721 for (niocount = i = 0; i < objcount; i++)
1722 niocount += ioo[i].ioo_bufcnt;
1724 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1726 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
1727 RCL_CLIENT) / sizeof(*nb)))
1731 if (opc == OST_READ)
1734 start = nb[0].offset & CFS_PAGE_MASK;
1735 end = (nb[ioo->ioo_bufcnt - 1].offset +
1736 nb[ioo->ioo_bufcnt - 1].len - 1) | ~CFS_PAGE_MASK;
1738 LASSERT(lock->l_resource != NULL);
1739 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_gr,
1740 &lock->l_resource->lr_name))
1743 if (!(lock->l_granted_mode & mode))
1746 if (lock->l_policy_data.l_extent.end < start ||
1747 lock->l_policy_data.l_extent.start > end)
1754 * High-priority queue request check for whether the given PTLRPC request (\a
1755 * req) is blocking an LDLM lock cancel.
1757 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1758 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1760 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1761 * function looks only at OST_READs and OST_WRITEs.
1763 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1765 struct niobuf_remote *nb;
1766 struct obd_ioobj *ioo;
1767 struct ost_body *body;
1768 int objcount, niocount;
1772 opc = lustre_msg_get_opc(req->rq_reqmsg);
1773 LASSERT(opc == OST_READ || opc == OST_WRITE);
1775 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1779 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1780 RCL_CLIENT) / sizeof(*ioo);
1781 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1785 for (niocount = i = 0; i < objcount; i++)
1786 niocount += ioo[i].ioo_bufcnt;
1787 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1789 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
1790 RCL_CLIENT) / sizeof(*nb)))
1792 if (niocount != 0 && (nb[0].flags & OBD_BRW_SRVLOCK))
1796 if (opc == OST_READ)
1798 RETURN(ost_rw_prolong_locks(req, ioo, nb, &body->oa, mode));
1801 static int ost_punch_prolong_locks(struct ptlrpc_request *req, struct obdo *oa)
1803 struct ldlm_res_id res_id = { .name = { oa->o_id } };
1804 struct ost_prolong_data opd = { 0 };
1809 end = start + oa->o_blocks;
1811 opd.opd_mode = LCK_PW;
1812 opd.opd_exp = req->rq_export;
1813 opd.opd_policy.l_extent.start = start & CFS_PAGE_MASK;
1814 if (oa->o_blocks == OBD_OBJECT_EOF || end < start)
1815 opd.opd_policy.l_extent.end = OBD_OBJECT_EOF;
1817 opd.opd_policy.l_extent.end = end | ~CFS_PAGE_MASK;
1819 /* prolong locks for the current service time of the corresponding
1820 * portal (= OST_IO_PORTAL) */
1821 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
1822 max(at_est2timeout(at_get(&req->rq_rqbd->
1823 rqbd_service->srv_at_estimate)), ldlm_timeout);
1825 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1826 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
1827 opd.opd_policy.l_extent.end);
1830 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
1831 ost_prolong_locks_iter, &opd);
1832 RETURN(opd.opd_lock_match);
1836 * Like ost_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
1838 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1839 struct ldlm_lock *lock)
1841 struct ost_body *body;
1844 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1846 RETURN(0); /* can't return -EFAULT here */
1848 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1849 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1855 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
1857 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1859 struct ost_body *body;
1861 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1865 LASSERT(!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1866 !(body->oa.o_flags & OBD_FL_TRUNCLOCK));
1868 RETURN(ost_punch_prolong_locks(req, &body->oa));
1871 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
1872 .hpreq_lock_match = ost_rw_hpreq_lock_match,
1873 .hpreq_check = ost_rw_hpreq_check,
1876 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
1877 .hpreq_lock_match = ost_punch_hpreq_lock_match,
1878 .hpreq_check = ost_punch_hpreq_check,
1881 /** Assign high priority operations to the request if needed. */
1882 static int ost_hpreq_handler(struct ptlrpc_request *req)
1885 if (req->rq_export) {
1886 int opc = lustre_msg_get_opc(req->rq_reqmsg);
1887 struct ost_body *body;
1889 if (opc == OST_READ || opc == OST_WRITE) {
1890 struct niobuf_remote *nb;
1891 struct obd_ioobj *ioo;
1892 int objcount, niocount;
1895 /* RPCs on the H-P queue can be inspected before
1896 * ost_handler() initializes their pills, so we
1897 * initialize that here. Capsule initialization is
1898 * idempotent, as is setting the pill's format (provided
1899 * it doesn't change).
1901 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1902 req_capsule_set(&req->rq_pill, &RQF_OST_BRW);
1904 body = req_capsule_client_get(&req->rq_pill,
1907 CERROR("Missing/short ost_body\n");
1910 objcount = req_capsule_get_size(&req->rq_pill,
1914 if (objcount == 0) {
1915 CERROR("Missing/short ioobj\n");
1919 CERROR("too many ioobjs (%d)\n", objcount);
1923 ioo = req_capsule_client_get(&req->rq_pill,
1926 CERROR("Missing/short ioobj\n");
1930 for (niocount = i = 0; i < objcount; i++) {
1931 if (ioo[i].ioo_bufcnt == 0) {
1932 CERROR("ioo[%d] has zero bufcnt\n", i);
1935 niocount += ioo[i].ioo_bufcnt;
1937 if (niocount > PTLRPC_MAX_BRW_PAGES) {
1938 DEBUG_REQ(D_RPCTRACE, req,
1939 "bulk has too many pages (%d)",
1944 nb = req_capsule_client_get(&req->rq_pill,
1945 &RMF_NIOBUF_REMOTE);
1947 CERROR("Missing/short niobuf\n");
1951 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
1952 req->rq_ops = &ost_hpreq_rw;
1953 } else if (opc == OST_PUNCH) {
1954 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1955 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
1957 body = req_capsule_client_get(&req->rq_pill,
1960 CERROR("Missing/short ost_body\n");
1964 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1965 !(body->oa.o_flags & OBD_FL_TRUNCLOCK))
1966 req->rq_ops = &ost_hpreq_punch;
1972 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1973 int ost_handle(struct ptlrpc_request *req)
1975 struct obd_trans_info trans_info = { 0, };
1976 struct obd_trans_info *oti = &trans_info;
1977 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1978 struct obd_device *obd = NULL;
1981 LASSERT(current->journal_info == NULL);
1983 /* primordial rpcs don't affect server recovery */
1984 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1986 case SEC_CTX_INIT_CONT:
1991 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1993 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1996 if (!class_connected_export(req->rq_export)) {
1997 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1998 lustre_msg_get_opc(req->rq_reqmsg),
1999 libcfs_id2str(req->rq_peer));
2000 req->rq_status = -ENOTCONN;
2001 GOTO(out, rc = -ENOTCONN);
2004 obd = req->rq_export->exp_obd;
2006 /* Check for aborted recovery. */
2007 spin_lock_bh(&obd->obd_processing_task_lock);
2008 recovering = obd->obd_recovering;
2009 spin_unlock_bh(&obd->obd_processing_task_lock);
2011 rc = ost_filter_recovery_request(req, obd,
2013 if (rc || !should_process)
2015 else if (should_process < 0) {
2016 req->rq_status = should_process;
2017 rc = ptlrpc_error(req);
2025 rc = ost_msg_check_version(req->rq_reqmsg);
2029 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2031 CDEBUG(D_INODE, "connect\n");
2032 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
2033 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
2035 rc = target_handle_connect(req);
2036 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
2039 rc = ost_init_sec_level(req);
2041 rc = ost_connect_check_sptlrpc(req);
2045 case OST_DISCONNECT:
2046 CDEBUG(D_INODE, "disconnect\n");
2047 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
2048 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
2050 rc = target_handle_disconnect(req);
2053 CDEBUG(D_INODE, "create\n");
2054 req_capsule_set(&req->rq_pill, &RQF_OST_CREATE);
2055 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
2057 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2058 GOTO(out, rc = -EROFS);
2059 rc = ost_create(req->rq_export, req, oti);
2062 CDEBUG(D_INODE, "destroy\n");
2063 req_capsule_set(&req->rq_pill, &RQF_OST_DESTROY);
2064 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
2066 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2067 GOTO(out, rc = -EROFS);
2068 rc = ost_destroy(req->rq_export, req, oti);
2071 CDEBUG(D_INODE, "getattr\n");
2072 req_capsule_set(&req->rq_pill, &RQF_OST_GETATTR);
2073 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
2075 rc = ost_getattr(req->rq_export, req);
2078 CDEBUG(D_INODE, "setattr\n");
2079 req_capsule_set(&req->rq_pill, &RQF_OST_SETATTR);
2080 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
2082 rc = ost_setattr(req->rq_export, req, oti);
2085 req_capsule_set(&req->rq_pill, &RQF_OST_BRW);
2086 CDEBUG(D_INODE, "write\n");
2087 /* req->rq_request_portal would be nice, if it was set */
2088 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2089 CERROR("%s: deny write request from %s to portal %u\n",
2090 req->rq_export->exp_obd->obd_name,
2091 obd_export_nid2str(req->rq_export),
2092 req->rq_rqbd->rqbd_service->srv_req_portal);
2093 GOTO(out, rc = -EPROTO);
2095 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2097 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
2098 GOTO(out, rc = -ENOSPC);
2099 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2100 GOTO(out, rc = -EROFS);
2101 rc = ost_brw_write(req, oti);
2102 LASSERT(current->journal_info == NULL);
2103 /* ost_brw_write sends its own replies */
2106 req_capsule_set(&req->rq_pill, &RQF_OST_BRW);
2107 CDEBUG(D_INODE, "read\n");
2108 /* req->rq_request_portal would be nice, if it was set */
2109 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2110 CERROR("%s: deny read request from %s to portal %u\n",
2111 req->rq_export->exp_obd->obd_name,
2112 obd_export_nid2str(req->rq_export),
2113 req->rq_rqbd->rqbd_service->srv_req_portal);
2114 GOTO(out, rc = -EPROTO);
2116 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2118 rc = ost_brw_read(req, oti);
2119 LASSERT(current->journal_info == NULL);
2120 /* ost_brw_read sends its own replies */
2123 CDEBUG(D_INODE, "punch\n");
2124 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2125 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2127 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2128 GOTO(out, rc = -EROFS);
2129 rc = ost_punch(req->rq_export, req, oti);
2132 CDEBUG(D_INODE, "statfs\n");
2133 req_capsule_set(&req->rq_pill, &RQF_OST_STATFS);
2134 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2136 rc = ost_statfs(req);
2139 CDEBUG(D_INODE, "sync\n");
2140 req_capsule_set(&req->rq_pill, &RQF_OST_SYNC);
2141 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2143 rc = ost_sync(req->rq_export, req);
2146 DEBUG_REQ(D_INODE, req, "set_info");
2147 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
2148 rc = ost_set_info(req->rq_export, req);
2151 DEBUG_REQ(D_INODE, req, "get_info");
2152 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
2153 rc = ost_get_info(req->rq_export, req);
2155 #ifdef HAVE_QUOTA_SUPPORT
2156 case OST_QUOTACHECK:
2157 CDEBUG(D_INODE, "quotacheck\n");
2158 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2159 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2161 rc = ost_handle_quotacheck(req);
2164 CDEBUG(D_INODE, "quotactl\n");
2165 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2166 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2168 rc = ost_handle_quotactl(req);
2170 case OST_QUOTA_ADJUST_QUNIT:
2171 CDEBUG(D_INODE, "quota_adjust_qunit\n");
2172 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
2173 rc = ost_handle_quota_adjust_qunit(req);
2177 DEBUG_REQ(D_INODE, req, "ping");
2178 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2179 rc = target_handle_ping(req);
2181 /* FIXME - just reply status */
2182 case LLOG_ORIGIN_CONNECT:
2183 DEBUG_REQ(D_INODE, req, "log connect");
2184 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2185 rc = ost_llog_handle_connect(req->rq_export, req);
2186 req->rq_status = rc;
2187 rc = req_capsule_server_pack(&req->rq_pill);
2190 RETURN(ptlrpc_reply(req));
2191 case OBD_LOG_CANCEL:
2192 CDEBUG(D_INODE, "log cancel\n");
2193 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2194 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2196 rc = llog_origin_handle_cancel(req);
2197 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2199 req->rq_status = rc;
2200 rc = req_capsule_server_pack(&req->rq_pill);
2203 RETURN(ptlrpc_reply(req));
2205 CDEBUG(D_INODE, "enqueue\n");
2206 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2207 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2209 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2210 ldlm_server_blocking_ast,
2211 ldlm_server_glimpse_ast);
2212 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2215 CDEBUG(D_INODE, "convert\n");
2216 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2217 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2219 rc = ldlm_handle_convert(req);
2222 CDEBUG(D_INODE, "cancel\n");
2223 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2224 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2226 rc = ldlm_handle_cancel(req);
2228 case LDLM_BL_CALLBACK:
2229 case LDLM_CP_CALLBACK:
2230 CDEBUG(D_INODE, "callback\n");
2231 CERROR("callbacks should not happen on OST\n");
2234 CERROR("Unexpected opcode %d\n",
2235 lustre_msg_get_opc(req->rq_reqmsg));
2236 req->rq_status = -ENOTSUPP;
2237 rc = ptlrpc_error(req);
2241 LASSERT(current->journal_info == NULL);
2244 /* If we're DISCONNECTing, the export_data is already freed */
2245 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2246 target_committed_to_req(req);
2250 oti_to_request(oti, req);
2252 target_send_reply(req, rc, fail);
2255 EXPORT_SYMBOL(ost_handle);
2257 * free per-thread pool created by ost_thread_init().
2259 static void ost_thread_done(struct ptlrpc_thread *thread)
2261 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2266 LASSERT(thread != NULL);
2269 * be prepared to handle partially-initialized pools (because this is
2270 * called from ost_thread_init() for cleanup.
2272 tls = thread->t_data;
2275 thread->t_data = NULL;
2281 * initialize per-thread page pool (bug 5137).
2283 static int ost_thread_init(struct ptlrpc_thread *thread)
2285 struct ost_thread_local_cache *tls;
2289 LASSERT(thread != NULL);
2290 LASSERT(thread->t_data == NULL);
2291 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
2296 thread->t_data = tls;
2300 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2302 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2303 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2305 struct ost_obd *ost = &obd->u.ost;
2306 struct lprocfs_static_vars lvars;
2307 int oss_min_threads;
2308 int oss_max_threads;
2309 int oss_min_create_threads;
2310 int oss_max_create_threads;
2314 rc = cleanup_group_info();
2318 lprocfs_ost_init_vars(&lvars);
2319 lprocfs_obd_setup(obd, lvars.obd_vars);
2321 sema_init(&ost->ost_health_sem, 1);
2323 if (oss_num_threads) {
2324 /* If oss_num_threads is set, it is the min and the max. */
2325 if (oss_num_threads > OSS_THREADS_MAX)
2326 oss_num_threads = OSS_THREADS_MAX;
2327 if (oss_num_threads < OSS_THREADS_MIN)
2328 oss_num_threads = OSS_THREADS_MIN;
2329 oss_max_threads = oss_min_threads = oss_num_threads;
2331 /* Base min threads on memory and cpus */
2332 oss_min_threads = num_possible_cpus() * CFS_NUM_CACHEPAGES >>
2333 (27 - CFS_PAGE_SHIFT);
2334 if (oss_min_threads < OSS_THREADS_MIN)
2335 oss_min_threads = OSS_THREADS_MIN;
2336 /* Insure a 4x range for dynamic threads */
2337 if (oss_min_threads > OSS_THREADS_MAX / 4)
2338 oss_min_threads = OSS_THREADS_MAX / 4;
2339 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
2343 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2344 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
2345 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2346 ost_handle, LUSTRE_OSS_NAME,
2347 obd->obd_proc_entry, target_print_req,
2348 oss_min_threads, oss_max_threads,
2349 "ll_ost", LCT_DT_THREAD, NULL);
2350 if (ost->ost_service == NULL) {
2351 CERROR("failed to start service\n");
2352 GOTO(out_lprocfs, rc = -ENOMEM);
2355 rc = ptlrpc_start_threads(obd, ost->ost_service);
2357 GOTO(out_service, rc = -EINVAL);
2359 if (oss_num_create_threads) {
2360 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
2361 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
2362 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
2363 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
2364 oss_min_create_threads = oss_max_create_threads =
2365 oss_num_create_threads;
2367 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
2368 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
2371 ost->ost_create_service =
2372 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2373 OST_MAXREPSIZE, OST_CREATE_PORTAL,
2374 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2375 ost_handle, "ost_create",
2376 obd->obd_proc_entry, target_print_req,
2377 oss_min_create_threads, oss_max_create_threads,
2378 "ll_ost_creat", LCT_DT_THREAD, NULL);
2379 if (ost->ost_create_service == NULL) {
2380 CERROR("failed to start OST create service\n");
2381 GOTO(out_service, rc = -ENOMEM);
2384 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
2386 GOTO(out_create, rc = -EINVAL);
2388 ost->ost_io_service =
2389 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2390 OST_MAXREPSIZE, OST_IO_PORTAL,
2391 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2392 ost_handle, "ost_io",
2393 obd->obd_proc_entry, target_print_req,
2394 oss_min_threads, oss_max_threads,
2395 "ll_ost_io", LCT_DT_THREAD, ost_hpreq_handler);
2396 if (ost->ost_io_service == NULL) {
2397 CERROR("failed to start OST I/O service\n");
2398 GOTO(out_create, rc = -ENOMEM);
2401 ost->ost_io_service->srv_init = ost_thread_init;
2402 ost->ost_io_service->srv_done = ost_thread_done;
2403 ost->ost_io_service->srv_cpu_affinity = 1;
2404 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
2406 GOTO(out_io, rc = -EINVAL);
2408 ping_evictor_start();
2413 ptlrpc_unregister_service(ost->ost_io_service);
2414 ost->ost_io_service = NULL;
2416 ptlrpc_unregister_service(ost->ost_create_service);
2417 ost->ost_create_service = NULL;
2419 ptlrpc_unregister_service(ost->ost_service);
2420 ost->ost_service = NULL;
2422 lprocfs_obd_cleanup(obd);
2426 static int ost_cleanup(struct obd_device *obd)
2428 struct ost_obd *ost = &obd->u.ost;
2432 ping_evictor_stop();
2434 spin_lock_bh(&obd->obd_processing_task_lock);
2435 if (obd->obd_recovering) {
2436 target_cancel_recovery_timer(obd);
2437 obd->obd_recovering = 0;
2439 spin_unlock_bh(&obd->obd_processing_task_lock);
2441 down(&ost->ost_health_sem);
2442 ptlrpc_unregister_service(ost->ost_service);
2443 ptlrpc_unregister_service(ost->ost_create_service);
2444 ptlrpc_unregister_service(ost->ost_io_service);
2445 ost->ost_service = NULL;
2446 ost->ost_create_service = NULL;
2447 up(&ost->ost_health_sem);
2449 lprocfs_obd_cleanup(obd);
2454 static int ost_health_check(struct obd_device *obd)
2456 struct ost_obd *ost = &obd->u.ost;
2459 down(&ost->ost_health_sem);
2460 rc |= ptlrpc_service_health_check(ost->ost_service);
2461 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2462 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2463 up(&ost->ost_health_sem);
2466 * health_check to return 0 on healthy
2467 * and 1 on unhealthy.
2475 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2477 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2480 /* use obd ops to offer management infrastructure */
2481 static struct obd_ops ost_obd_ops = {
2482 .o_owner = THIS_MODULE,
2483 .o_setup = ost_setup,
2484 .o_cleanup = ost_cleanup,
2485 .o_health_check = ost_health_check,
2489 static int __init ost_init(void)
2491 struct lprocfs_static_vars lvars;
2495 lprocfs_ost_init_vars(&lvars);
2496 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2497 LUSTRE_OSS_NAME, NULL);
2499 if (ost_num_threads != 0 && oss_num_threads == 0) {
2500 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2501 "use oss_num_threads instead or unset both for "
2502 "dynamic thread startup\n");
2503 oss_num_threads = ost_num_threads;
2509 static void /*__exit*/ ost_exit(void)
2511 class_unregister_type(LUSTRE_OSS_NAME);
2514 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2515 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2516 MODULE_LICENSE("GPL");
2518 module_init(ost_init);
2519 module_exit(ost_exit);