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);
159 * Helper function for getting server side [start, start+count] DLM lock
160 * if asked by client.
162 static int ost_lock_get(struct obd_export *exp, struct obdo *oa,
163 __u64 start, __u64 count, struct lustre_handle *lh,
166 struct ldlm_res_id res_id = { .name = { oa->o_id, 0, oa->o_gr, 0} };
167 ldlm_policy_data_t policy;
168 __u64 end = start + count;
172 LASSERT(!lustre_handle_is_used(lh));
173 LASSERT((oa->o_valid & (OBD_MD_FLID | OBD_MD_FLGROUP)) ==
174 (OBD_MD_FLID | OBD_MD_FLGROUP));
176 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
177 !(oa->o_flags & OBD_FL_SRVLOCK))
180 CDEBUG(D_INODE, "OST-side extent lock.\n");
182 policy.l_extent.start = start & CFS_PAGE_MASK;
184 /* If ->o_blocks is EOF it means "lock till the end of the
185 * file". Otherwise, it's size of a hole being punched (in bytes) */
186 if (count == OBD_OBJECT_EOF || end < start)
187 policy.l_extent.end = OBD_OBJECT_EOF;
189 policy.l_extent.end = end | ~CFS_PAGE_MASK;
191 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
192 LDLM_EXTENT, &policy, mode, &flags,
193 ldlm_blocking_ast, ldlm_completion_ast,
194 ldlm_glimpse_ast, NULL, 0, NULL, lh));
197 /* Helper function: release lock, if any. */
198 static void ost_lock_put(struct obd_export *exp,
199 struct lustre_handle *lh, int mode)
202 if (lustre_handle_is_used(lh))
203 ldlm_lock_decref(lh, mode);
207 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
209 struct ost_body *body, *repbody;
210 struct obd_info oinfo = { { { 0 } } };
211 struct lustre_handle lh = { 0 };
215 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
219 rc = req_capsule_server_pack(&req->rq_pill);
223 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
224 repbody->oa = body->oa;
226 rc = ost_lock_get(exp, &body->oa, 0, OBD_OBJECT_EOF, &lh, LCK_PR, 0);
230 oinfo.oi_oa = &repbody->oa;
231 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA) {
232 oinfo.oi_capa = req_capsule_client_get(&req->rq_pill,
234 if (oinfo.oi_capa == NULL) {
235 CERROR("Missing capability for OST GETATTR");
240 req->rq_status = obd_getattr(exp, &oinfo);
241 ost_lock_put(exp, &lh, LCK_PR);
243 ost_drop_id(exp, &repbody->oa);
247 static int ost_statfs(struct ptlrpc_request *req)
249 struct obd_statfs *osfs;
253 rc = req_capsule_server_pack(&req->rq_pill);
257 osfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
259 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
260 cfs_time_current_64() - CFS_HZ, 0);
261 if (req->rq_status != 0)
262 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
267 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
268 struct obd_trans_info *oti)
270 struct ost_body *body, *repbody;
274 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
278 rc = req_capsule_server_pack(&req->rq_pill);
282 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
283 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
284 oti->oti_logcookies = &repbody->oa.o_lcookie;
286 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
287 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
291 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
292 struct obd_trans_info *oti)
294 struct obd_info oinfo = { { { 0 } } };
295 struct ost_body *body, *repbody;
297 struct lustre_handle lh = {0,};
300 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
301 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
303 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
307 oinfo.oi_oa = &body->oa;
308 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
309 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
311 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
312 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
315 rc = req_capsule_server_pack(&req->rq_pill);
319 /* standard truncate optimization: if file body is completely
320 * destroyed, don't send data back to the server. */
321 if (oinfo.oi_oa->o_size == 0)
322 flags |= LDLM_AST_DISCARD_DATA;
324 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
325 rc = ost_lock_get(exp, oinfo.oi_oa, oinfo.oi_oa->o_size,
326 oinfo.oi_oa->o_blocks, &lh, LCK_PW, flags);
328 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
329 oinfo.oi_oa->o_flags == OBD_FL_SRVLOCK)
331 * If OBD_FL_SRVLOCK is the only bit set in
332 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
333 * through filter_setattr() to filter_iocontrol().
335 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
337 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA) {
338 oinfo.oi_capa = req_capsule_client_get(&req->rq_pill,
340 if (oinfo.oi_capa == NULL) {
341 CERROR("Missing capability for OST PUNCH");
345 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
346 ost_lock_put(exp, &lh, LCK_PW);
348 repbody->oa = *oinfo.oi_oa;
349 ost_drop_id(exp, &repbody->oa);
353 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
355 struct ost_body *body, *repbody;
356 struct lustre_capa *capa = NULL;
360 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
364 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
365 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
367 CERROR("Missing capability for OST SYNC");
372 rc = req_capsule_server_pack(&req->rq_pill);
376 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
377 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
378 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
379 repbody->oa.o_blocks, capa);
380 ost_drop_id(exp, &repbody->oa);
384 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
385 struct obd_trans_info *oti)
387 struct ost_body *body, *repbody;
389 struct obd_info oinfo = { { { 0 } } };
392 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
396 rc = req_capsule_server_pack(&req->rq_pill);
400 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
401 repbody->oa = body->oa;
403 oinfo.oi_oa = &repbody->oa;
404 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA) {
405 oinfo.oi_capa = req_capsule_client_get(&req->rq_pill,
407 if (oinfo.oi_capa == NULL) {
408 CERROR("Missing capability for OST SETATTR");
412 req->rq_status = obd_setattr(exp, &oinfo, oti);
413 ost_drop_id(exp, &repbody->oa);
417 static int ost_bulk_timeout(void *data)
420 /* We don't fail the connection here, because having the export
421 * killed makes the (vital) call to commitrw very sad.
426 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
427 cksum_type_t cksum_type)
432 cksum = init_checksum(cksum_type);
433 for (i = 0; i < desc->bd_iov_count; i++) {
434 struct page *page = desc->bd_iov[i].kiov_page;
435 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
436 char *ptr = kmap(page) + off;
437 int len = desc->bd_iov[i].kiov_len;
439 /* corrupt the data before we compute the checksum, to
440 * simulate a client->OST data error */
441 if (i == 0 && opc == OST_WRITE &&
442 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
443 memcpy(ptr, "bad3", min(4, len));
444 cksum = compute_checksum(cksum, ptr, len, cksum_type);
445 /* corrupt the data after we compute the checksum, to
446 * simulate an OST->client data error */
447 if (i == 0 && opc == OST_READ &&
448 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
449 memcpy(ptr, "bad4", min(4, len));
450 /* nobody should use corrupted page again */
451 ClearPageUptodate(page);
459 static int ost_brw_lock_get(int mode, struct obd_export *exp,
460 struct obd_ioobj *obj, struct niobuf_remote *nb,
461 struct lustre_handle *lh)
464 int nrbufs = obj->ioo_bufcnt;
465 struct ldlm_res_id res_id;
466 ldlm_policy_data_t policy;
470 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
471 LASSERT(mode == LCK_PR || mode == LCK_PW);
472 LASSERT(!lustre_handle_is_used(lh));
474 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
477 for (i = 1; i < nrbufs; i ++)
478 if ((nb[0].flags & OBD_BRW_SRVLOCK) !=
479 (nb[i].flags & OBD_BRW_SRVLOCK))
482 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
483 policy.l_extent.end = (nb[nrbufs - 1].offset +
484 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
486 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
487 LDLM_EXTENT, &policy, mode, &flags,
488 ldlm_blocking_ast, ldlm_completion_ast,
489 ldlm_glimpse_ast, NULL, 0, NULL, lh));
492 static void ost_brw_lock_put(int mode,
493 struct obd_ioobj *obj, struct niobuf_remote *niob,
494 struct lustre_handle *lh)
497 LASSERT(mode == LCK_PR || mode == LCK_PW);
498 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
499 lustre_handle_is_used(lh));
500 if (lustre_handle_is_used(lh))
501 ldlm_lock_decref(lh, mode);
505 struct ost_prolong_data {
506 struct obd_export *opd_exp;
507 ldlm_policy_data_t opd_policy;
509 ldlm_mode_t opd_mode;
514 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
516 struct ost_prolong_data *opd = data;
518 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
520 if (lock->l_req_mode != lock->l_granted_mode) {
521 /* scan granted locks only */
522 return LDLM_ITER_STOP;
525 if (lock->l_export != opd->opd_exp) {
526 /* prolong locks only for given client */
527 return LDLM_ITER_CONTINUE;
530 if (!(lock->l_granted_mode & opd->opd_mode)) {
531 /* we aren't interesting in all type of locks */
532 return LDLM_ITER_CONTINUE;
535 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
536 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
537 /* the request doesn't cross the lock, skip it */
538 return LDLM_ITER_CONTINUE;
541 /* Fill the obdo with the matched lock handle.
542 * XXX: it is possible in some cases the IO RPC is covered by several
543 * locks, even for the write case, so it may need to be a lock list. */
544 if (opd->opd_oa && !(opd->opd_oa->o_valid & OBD_MD_FLHANDLE)) {
545 opd->opd_oa->o_handle.cookie = lock->l_handle.h_cookie;
546 opd->opd_oa->o_valid |= OBD_MD_FLHANDLE;
549 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
550 /* ignore locks not being cancelled */
551 return LDLM_ITER_CONTINUE;
554 CDEBUG(D_DLMTRACE,"refresh lock: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
555 lock->l_resource->lr_name.name[0],
556 lock->l_resource->lr_name.name[1],
557 opd->opd_policy.l_extent.start, opd->opd_policy.l_extent.end);
558 /* OK. this is a possible lock the user holds doing I/O
559 * let's refresh eviction timer for it */
560 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
561 opd->opd_lock_match = 1;
563 return LDLM_ITER_CONTINUE;
566 static int ost_rw_prolong_locks(struct ptlrpc_request *req, struct obd_ioobj *obj,
567 struct niobuf_remote *nb, struct obdo *oa,
570 struct ldlm_res_id res_id;
571 int nrbufs = obj->ioo_bufcnt;
572 struct ost_prolong_data opd = { 0 };
575 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
578 opd.opd_exp = req->rq_export;
579 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
580 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
581 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
583 /* prolong locks for the current service time of the corresponding
584 * portal (= OST_IO_PORTAL) */
585 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
586 max(at_est2timeout(at_get(&req->rq_rqbd->
587 rqbd_service->srv_at_estimate)), ldlm_timeout);
589 CDEBUG(D_INFO,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
590 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
591 opd.opd_policy.l_extent.end);
593 if (oa->o_valid & OBD_MD_FLHANDLE) {
594 struct ldlm_lock *lock;
596 lock = ldlm_handle2lock(&oa->o_handle);
598 ost_prolong_locks_iter(lock, &opd);
599 if (opd.opd_lock_match) {
604 /* Check if the lock covers the whole IO region,
605 * otherwise iterate through the resource. */
606 if (lock->l_policy_data.l_extent.end >=
607 opd.opd_policy.l_extent.end &&
608 lock->l_policy_data.l_extent.start <=
609 opd.opd_policy.l_extent.start) {
618 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
619 ost_prolong_locks_iter, &opd);
620 RETURN(opd.opd_lock_match);
623 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
625 struct ptlrpc_bulk_desc *desc = NULL;
626 struct obd_export *exp = req->rq_export;
627 struct niobuf_remote *remote_nb;
628 struct niobuf_local *local_nb;
629 struct obd_ioobj *ioo;
630 struct ost_body *body, *repbody;
631 struct lustre_capa *capa = NULL;
632 struct l_wait_info lwi;
633 struct lustre_handle lockh = { 0 };
634 int niocount, npages, nob = 0, rc, i;
638 req->rq_bulk_read = 1;
640 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
641 GOTO(out, rc = -EIO);
643 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
645 /* Check if there is eviction in progress, and if so, wait for it to
647 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
648 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
649 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
650 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
654 GOTO(out, rc = -ENOTCONN);
656 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
657 * ost_rw_hpreq_check(). */
658 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
660 GOTO(out, rc = -EFAULT);
663 * A req_capsule_X_get_array(pill, field, ptr_to_element_count) function
664 * would be useful here and wherever we get &RMF_OBD_IOOBJ and
665 * &RMF_NIOBUF_REMOTE.
667 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
669 GOTO(out, rc = -EFAULT);
671 niocount = ioo->ioo_bufcnt;
672 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
673 if (remote_nb == NULL)
674 GOTO(out, rc = -EFAULT);
676 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
677 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
679 CERROR("Missing capability for OST BRW READ");
680 GOTO(out, rc = -EFAULT);
684 rc = req_capsule_server_pack(&req->rq_pill);
689 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
692 local_nb = ost_tls(req)->local;
694 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
699 * If getting the lock took more time than
700 * client was willing to wait, drop it. b=11330
702 if (cfs_time_current_sec() > req->rq_deadline ||
703 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
705 CERROR("Dropping timed-out read from %s because locking"
706 "object "LPX64" took %ld seconds (limit was %ld).\n",
707 libcfs_id2str(req->rq_peer), ioo->ioo_id,
708 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
709 req->rq_deadline - req->rq_arrival_time.tv_sec);
710 GOTO(out_lock, rc = -ETIMEDOUT);
713 npages = OST_THREAD_POOL_SIZE;
714 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
715 remote_nb, &npages, local_nb, oti, capa);
719 desc = ptlrpc_prep_bulk_exp(req, npages,
720 BULK_PUT_SOURCE, OST_BULK_PORTAL);
722 GOTO(out_lock, rc = -ENOMEM);
724 if (!lustre_handle_is_used(&lockh))
725 /* no needs to try to prolong lock if server is asked
726 * to handle locking (= OBD_BRW_SRVLOCK) */
727 ost_rw_prolong_locks(req, ioo, remote_nb, &body->oa,
731 for (i = 0; i < npages; i++) {
732 int page_rc = local_nb[i].rc;
734 if (page_rc < 0) { /* error */
740 if (page_rc != 0) { /* some data! */
741 LASSERT (local_nb[i].page != NULL);
742 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
743 local_nb[i].offset & ~CFS_PAGE_MASK,
747 if (page_rc != local_nb[i].len) { /* short read */
748 /* All subsequent pages should be 0 */
750 LASSERT(local_nb[i].rc == 0);
755 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
756 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
758 if (body->oa.o_valid & OBD_MD_FLFLAGS)
759 cksum_type = cksum_type_unpack(body->oa.o_flags);
760 body->oa.o_flags = cksum_type_pack(cksum_type);
761 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
762 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
763 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
765 body->oa.o_valid = 0;
767 /* We're finishing using body->oa as an input variable */
769 /* Check if client was evicted while we were doing i/o before touching
772 /* Check if there is eviction in progress, and if so, wait for
774 if (unlikely(cfs_atomic_read(&exp->exp_obd->
775 obd_evict_inprogress))) {
776 lwi = LWI_INTR(NULL, NULL);
777 rc = l_wait_event(exp->exp_obd->
778 obd_evict_inprogress_waitq,
779 !cfs_atomic_read(&exp->exp_obd->
780 obd_evict_inprogress),
783 /* Check if client was evicted or tried to reconnect already */
784 if (exp->exp_failed || exp->exp_abort_active_req)
787 rc = sptlrpc_svc_wrap_bulk(req, desc);
789 rc = ptlrpc_start_bulk_transfer(desc);
793 time_t start = cfs_time_current_sec();
795 long timeoutl = req->rq_deadline -
796 cfs_time_current_sec();
797 cfs_duration_t timeout = timeoutl <= 0 ?
798 CFS_TICK : cfs_time_seconds(timeoutl);
799 lwi = LWI_TIMEOUT_INTERVAL(timeout,
803 rc = l_wait_event(desc->bd_waitq,
804 !ptlrpc_server_bulk_active(desc) ||
806 exp->exp_abort_active_req,
808 LASSERT(rc == 0 || rc == -ETIMEDOUT);
809 /* Wait again if we changed deadline */
810 } while ((rc == -ETIMEDOUT) &&
811 (req->rq_deadline > cfs_time_current_sec()));
813 if (rc == -ETIMEDOUT) {
814 DEBUG_REQ(D_ERROR, req,
815 "timeout on bulk PUT after %ld%+lds",
816 req->rq_deadline - start,
817 cfs_time_current_sec() -
819 ptlrpc_abort_bulk(desc);
820 } else if (exp->exp_failed) {
821 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
823 ptlrpc_abort_bulk(desc);
824 } else if (exp->exp_abort_active_req) {
825 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk PUT");
826 /* we don't reply anyway */
828 ptlrpc_abort_bulk(desc);
829 } else if (!desc->bd_success ||
830 desc->bd_nob_transferred != desc->bd_nob) {
831 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
833 "truncated" : "network error on",
834 desc->bd_nob_transferred,
836 /* XXX should this be a different errno? */
840 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
845 /* Must commit after prep above in all cases */
846 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
847 remote_nb, npages, local_nb, oti, rc);
850 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
851 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
852 ost_drop_id(exp, &repbody->oa);
856 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
859 ptlrpc_free_bulk(desc);
863 req->rq_status = nob;
864 ptlrpc_lprocfs_brw(req, nob);
865 target_committed_to_req(req);
867 } else if (!no_reply) {
868 /* Only reply if there was no comms problem with bulk */
869 target_committed_to_req(req);
873 /* reply out callback would free */
874 ptlrpc_req_drop_rs(req);
875 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
876 "client will retry\n",
877 exp->exp_obd->obd_name,
878 exp->exp_client_uuid.uuid,
879 exp->exp_connection->c_remote_uuid.uuid,
880 libcfs_id2str(req->rq_peer));
886 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
888 struct ptlrpc_bulk_desc *desc = NULL;
889 struct obd_export *exp = req->rq_export;
890 struct niobuf_remote *remote_nb;
891 struct niobuf_local *local_nb;
892 struct obd_ioobj *ioo;
893 struct ost_body *body, *repbody;
894 struct l_wait_info lwi;
895 struct lustre_handle lockh = {0};
896 struct lustre_capa *capa = NULL;
898 int objcount, niocount, npages;
900 obd_count client_cksum = 0, server_cksum = 0;
901 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
903 __u32 o_uid = 0, o_gid = 0;
906 req->rq_bulk_write = 1;
908 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
909 GOTO(out, rc = -EIO);
910 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
911 GOTO(out, rc = -EFAULT);
913 /* pause before transaction has been started */
914 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
916 /* Check if there is eviction in progress, and if so, wait for it to
918 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
919 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
920 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
921 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
925 GOTO(out, rc = -ENOTCONN);
927 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
928 * ost_rw_hpreq_check(). */
929 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
931 GOTO(out, rc = -EFAULT);
933 if ((body->oa.o_flags & OBD_BRW_MEMALLOC) &&
934 (exp->exp_connection->c_peer.nid == exp->exp_connection->c_self))
935 libcfs_memory_pressure_set();
937 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
938 RCL_CLIENT) / sizeof(*ioo);
939 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
941 GOTO(out, rc = -EFAULT);
942 for (niocount = i = 0; i < objcount; i++)
943 niocount += ioo[i].ioo_bufcnt;
946 * It'd be nice to have a capsule function to indicate how many elements
947 * there were in a buffer for an RMF that's declared to be an array.
948 * It's easy enough to compute the number of elements here though.
950 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
951 if (remote_nb == NULL || niocount != (req_capsule_get_size(&req->rq_pill,
952 &RMF_NIOBUF_REMOTE, RCL_CLIENT) / sizeof(*remote_nb)))
953 GOTO(out, rc = -EFAULT);
955 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
956 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
958 CERROR("Missing capability for OST BRW WRITE");
959 GOTO(out, rc = -EFAULT);
963 req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER,
964 niocount * sizeof(*rcs));
965 rc = req_capsule_server_pack(&req->rq_pill);
968 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, obd_fail_val);
969 rcs = req_capsule_server_get(&req->rq_pill, &RMF_RCS);
972 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
975 local_nb = ost_tls(req)->local;
977 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
982 * If getting the lock took more time than
983 * client was willing to wait, drop it. b=11330
985 if (cfs_time_current_sec() > req->rq_deadline ||
986 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
988 CERROR("Dropping timed-out write from %s because locking "
989 "object "LPX64" took %ld seconds (limit was %ld).\n",
990 libcfs_id2str(req->rq_peer), ioo->ioo_id,
991 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
992 req->rq_deadline - req->rq_arrival_time.tv_sec);
993 GOTO(out_lock, rc = -ETIMEDOUT);
996 if (!lustre_handle_is_used(&lockh))
997 /* no needs to try to prolong lock if server is asked
998 * to handle locking (= OBD_BRW_SRVLOCK) */
999 ost_rw_prolong_locks(req, ioo, remote_nb,&body->oa, LCK_PW);
1001 /* obd_preprw clobbers oa->valid, so save what we need */
1002 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
1003 client_cksum = body->oa.o_cksum;
1004 if (body->oa.o_valid & OBD_MD_FLFLAGS)
1005 cksum_type = cksum_type_unpack(body->oa.o_flags);
1008 /* Because we already sync grant info with client when reconnect,
1009 * grant info will be cleared for resent req, then fed_grant and
1010 * total_grant will not be modified in following preprw_write */
1011 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1012 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1013 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1016 if (exp_connect_rmtclient(exp)) {
1017 o_uid = body->oa.o_uid;
1018 o_gid = body->oa.o_gid;
1020 npages = OST_THREAD_POOL_SIZE;
1021 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
1022 ioo, remote_nb, &npages, local_nb, oti, capa);
1026 desc = ptlrpc_prep_bulk_exp(req, npages,
1027 BULK_GET_SINK, OST_BULK_PORTAL);
1029 GOTO(out_lock, rc = -ENOMEM);
1031 /* NB Having prepped, we must commit... */
1033 for (i = 0; i < npages; i++)
1034 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1035 local_nb[i].offset & ~CFS_PAGE_MASK,
1038 rc = sptlrpc_svc_prep_bulk(req, desc);
1042 /* Check if client was evicted or tried to reconnect while we
1043 * were doing i/o before touching network */
1044 if (desc->bd_export->exp_failed ||
1045 desc->bd_export->exp_abort_active_req)
1048 rc = ptlrpc_start_bulk_transfer(desc);
1050 time_t start = cfs_time_current_sec();
1052 long timeoutl = req->rq_deadline -
1053 cfs_time_current_sec();
1054 cfs_duration_t timeout = timeoutl <= 0 ?
1055 CFS_TICK : cfs_time_seconds(timeoutl);
1056 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
1057 ost_bulk_timeout, desc);
1058 rc = l_wait_event(desc->bd_waitq,
1059 !ptlrpc_server_bulk_active(desc) ||
1060 desc->bd_export->exp_failed ||
1061 desc->bd_export->exp_abort_active_req,
1063 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1064 /* Wait again if we changed deadline */
1065 } while ((rc == -ETIMEDOUT) &&
1066 (req->rq_deadline > cfs_time_current_sec()));
1068 if (rc == -ETIMEDOUT) {
1069 DEBUG_REQ(D_ERROR, req,
1070 "timeout on bulk GET after %ld%+lds",
1071 req->rq_deadline - start,
1072 cfs_time_current_sec() -
1074 ptlrpc_abort_bulk(desc);
1075 } else if (desc->bd_export->exp_failed) {
1076 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1078 ptlrpc_abort_bulk(desc);
1079 } else if (desc->bd_export->exp_abort_active_req) {
1080 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk GET");
1081 /* we don't reply anyway */
1083 ptlrpc_abort_bulk(desc);
1084 } else if (!desc->bd_success) {
1085 DEBUG_REQ(D_ERROR, req, "network error on bulk GET");
1086 /* XXX should this be a different errno? */
1089 rc = sptlrpc_svc_unwrap_bulk(req, desc);
1092 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1096 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
1097 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1099 if (unlikely(client_cksum != 0 && rc == 0)) {
1100 static int cksum_counter;
1101 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1102 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1103 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1104 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1105 repbody->oa.o_cksum = server_cksum;
1107 if (unlikely(client_cksum != server_cksum)) {
1108 CERROR("client csum %x, server csum %x\n",
1109 client_cksum, server_cksum);
1111 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1112 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1113 cksum_counter, libcfs_id2str(req->rq_peer),
1118 /* Must commit after prep above in all cases */
1119 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1120 remote_nb, npages, local_nb, oti, rc);
1121 if (rc == -ENOTCONN)
1122 /* quota acquire process has been given up because
1123 * either the client has been evicted or the client
1124 * has timed out the request already */
1127 if (exp_connect_rmtclient(exp)) {
1128 repbody->oa.o_uid = o_uid;
1129 repbody->oa.o_gid = o_gid;
1133 * Disable sending mtime back to the client. If the client locked the
1134 * whole object, then it has already updated the mtime on its side,
1135 * otherwise it will have to glimpse anyway (see bug 21489, comment 32)
1137 repbody->oa.o_valid &= ~(OBD_MD_FLMTIME | OBD_MD_FLATIME);
1139 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1140 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1145 if (new_cksum == server_cksum)
1146 msg = "changed in transit before arrival at OST";
1147 else if (new_cksum == client_cksum)
1148 msg = "initial checksum before message complete";
1150 msg = "changed in transit AND after initial checksum";
1152 if (req->rq_peer.nid == desc->bd_sender) {
1156 router = libcfs_nid2str(desc->bd_sender);
1159 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1160 "%s%s%s inum "LPU64"/"LPU64" object "
1161 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1162 exp->exp_obd->obd_name, msg,
1163 libcfs_id2str(req->rq_peer),
1165 body->oa.o_valid & OBD_MD_FLFID ?
1166 body->oa.o_fid : (__u64)0,
1167 body->oa.o_valid & OBD_MD_FLFID ?
1168 body->oa.o_generation :(__u64)0,
1170 body->oa.o_valid & OBD_MD_FLGROUP ?
1171 body->oa.o_gr : (__u64)0,
1173 local_nb[npages-1].offset +
1174 local_nb[npages-1].len - 1 );
1175 CERROR("client csum %x, original server csum %x, "
1176 "server csum now %x\n",
1177 client_cksum, server_cksum, new_cksum);
1183 /* set per-requested niobuf return codes */
1184 for (i = j = 0; i < niocount; i++) {
1185 int len = remote_nb[i].len;
1190 LASSERT(j < npages);
1191 if (local_nb[j].rc < 0)
1192 rcs[i] = local_nb[j].rc;
1193 len -= local_nb[j].len;
1198 LASSERT(j == npages);
1199 ptlrpc_lprocfs_brw(req, nob);
1203 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1206 ptlrpc_free_bulk(desc);
1209 oti_to_request(oti, req);
1210 target_committed_to_req(req);
1211 rc = ptlrpc_reply(req);
1212 } else if (!no_reply) {
1213 /* Only reply if there was no comms problem with bulk */
1214 target_committed_to_req(req);
1215 req->rq_status = rc;
1218 /* reply out callback would free */
1219 ptlrpc_req_drop_rs(req);
1220 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1221 "client will retry\n",
1222 exp->exp_obd->obd_name,
1223 exp->exp_client_uuid.uuid,
1224 exp->exp_connection->c_remote_uuid.uuid,
1225 libcfs_id2str(req->rq_peer));
1227 libcfs_memory_pressure_clr();
1232 * Implementation of OST_SET_INFO.
1234 * OST_SET_INFO is like ioctl(): heavily overloaded. Specifically, it takes a
1235 * "key" and a value RPC buffers as arguments, with the value's contents
1236 * interpreted according to the key.
1238 * Value types that need swabbing have swabbing done explicitly, either here or
1239 * in functions called from here. This should be corrected: all swabbing should
1240 * be done in the capsule abstraction, as that will then allow us to move
1241 * swabbing exclusively to the client without having to modify server code
1242 * outside the capsule abstraction's implementation itself. To correct this
1243 * will require minor changes to the capsule abstraction; see the comments for
1244 * req_capsule_extend() in layout.c.
1246 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1248 struct ost_body *body = NULL, *repbody;
1249 char *key, *val = NULL;
1250 int keylen, vallen, rc = 0;
1251 int is_grant_shrink = 0;
1254 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1256 DEBUG_REQ(D_HA, req, "no set_info key");
1259 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1262 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1265 if ((is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK)))
1266 /* In this case the value is actually an RMF_OST_BODY, so we
1267 * transmutate the type of this PTLRPC */
1268 req_capsule_extend(&req->rq_pill, &RQF_OST_SET_GRANT_INFO);
1270 rc = req_capsule_server_pack(&req->rq_pill);
1275 if (is_grant_shrink) {
1276 body = req_capsule_client_get(&req->rq_pill,
1281 repbody = req_capsule_server_get(&req->rq_pill,
1283 memcpy(repbody, body, sizeof(*body));
1284 val = (char*)repbody;
1286 val = req_capsule_client_get(&req->rq_pill,
1291 if (KEY_IS(KEY_EVICT_BY_NID)) {
1293 obd_export_evict_by_nid(exp->exp_obd, val);
1295 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1296 if (vallen < sizeof(__u32))
1298 __swab32s((__u32 *)val);
1301 /* OBD will also check if KEY_IS(KEY_GRANT_SHRINK), and will cast val to
1302 * a struct ost_body * value */
1303 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1305 lustre_msg_set_status(req->rq_repmsg, 0);
1309 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1312 int keylen, replylen, rc = 0;
1313 struct req_capsule *pill = &req->rq_pill;
1316 /* this common part for get_info rpc */
1317 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1319 DEBUG_REQ(D_HA, req, "no get_info key");
1322 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1324 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1328 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1329 RCL_SERVER, replylen);
1331 rc = req_capsule_server_pack(pill);
1335 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1339 /* call again to fill in the reply buffer */
1340 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1342 lustre_msg_set_status(req->rq_repmsg, 0);
1346 #ifdef HAVE_QUOTA_SUPPORT
1347 static int ost_handle_quotactl(struct ptlrpc_request *req)
1349 struct obd_quotactl *oqctl, *repoqc;
1353 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1355 GOTO(out, rc = -EPROTO);
1357 rc = req_capsule_server_pack(&req->rq_pill);
1361 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1362 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1369 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1371 struct obd_quotactl *oqctl;
1375 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1379 rc = req_capsule_server_pack(&req->rq_pill);
1383 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1387 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1389 struct quota_adjust_qunit *oqaq, *repoqa;
1390 struct lustre_quota_ctxt *qctxt;
1394 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1395 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1397 GOTO(out, rc = -EPROTO);
1399 rc = req_capsule_server_pack(&req->rq_pill);
1403 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1404 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt);
1412 static int ost_llog_handle_connect(struct obd_export *exp,
1413 struct ptlrpc_request *req)
1415 struct llogd_conn_body *body;
1419 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
1420 rc = obd_llog_connect(exp, body);
1424 #define ost_init_sec_none(reply, exp) \
1426 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1427 OBD_CONNECT_RMT_CLIENT_FORCE | \
1428 OBD_CONNECT_OSS_CAPA); \
1429 cfs_spin_lock(&exp->exp_lock); \
1430 exp->exp_connect_flags = reply->ocd_connect_flags; \
1431 cfs_spin_unlock(&exp->exp_lock); \
1434 static int ost_init_sec_level(struct ptlrpc_request *req)
1436 struct obd_export *exp = req->rq_export;
1437 struct req_capsule *pill = &req->rq_pill;
1438 struct obd_device *obd = exp->exp_obd;
1439 struct filter_obd *filter = &obd->u.filter;
1440 char *client = libcfs_nid2str(req->rq_peer.nid);
1441 struct obd_connect_data *data, *reply;
1445 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1446 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1447 if (data == NULL || reply == NULL)
1450 /* connection from MDT is always trusted */
1451 if (req->rq_auth_usr_mdt) {
1452 ost_init_sec_none(reply, exp);
1456 /* no GSS support case */
1457 if (!req->rq_auth_gss) {
1458 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1459 CWARN("client %s -> target %s does not user GSS, "
1460 "can not run under security level %d.\n",
1461 client, obd->obd_name, filter->fo_sec_level);
1464 ost_init_sec_none(reply, exp);
1469 /* old version case */
1470 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1471 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1472 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1473 CWARN("client %s -> target %s uses old version, "
1474 "can not run under security level %d.\n",
1475 client, obd->obd_name, filter->fo_sec_level);
1478 CWARN("client %s -> target %s uses old version, "
1479 "run under security level %d.\n",
1480 client, obd->obd_name, filter->fo_sec_level);
1481 ost_init_sec_none(reply, exp);
1486 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1488 if (!req->rq_auth_remote)
1489 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1490 "asked to be remote.\n", client, obd->obd_name);
1491 } else if (req->rq_auth_remote) {
1493 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1494 "as remote by default.\n", client, obd->obd_name);
1498 if (!filter->fo_fl_oss_capa) {
1499 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1500 " but OSS capabilities are not enabled: %d.\n",
1501 client, obd->obd_name, filter->fo_fl_oss_capa);
1506 switch (filter->fo_sec_level) {
1507 case LUSTRE_SEC_NONE:
1509 ost_init_sec_none(reply, exp);
1512 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1513 "can not run under security level %d.\n",
1514 client, obd->obd_name, filter->fo_sec_level);
1517 case LUSTRE_SEC_REMOTE:
1519 ost_init_sec_none(reply, exp);
1521 case LUSTRE_SEC_ALL:
1523 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1524 OBD_CONNECT_RMT_CLIENT_FORCE);
1525 if (!filter->fo_fl_oss_capa)
1526 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1528 cfs_spin_lock(&exp->exp_lock);
1529 exp->exp_connect_flags = reply->ocd_connect_flags;
1530 cfs_spin_unlock(&exp->exp_lock);
1542 * this should be done in filter_connect()/filter_reconnect(), but
1543 * we can't obtain information like NID, which stored in incoming
1544 * request, thus can't decide what flavor to use. so we do it here.
1546 * This hack should be removed after the OST stack be rewritten, just
1547 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1549 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1551 struct obd_export *exp = req->rq_export;
1552 struct filter_obd *filter = &exp->exp_obd->u.filter;
1553 struct sptlrpc_flavor flvr;
1556 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1557 LUSTRE_ECHO_NAME) == 0)) {
1558 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1562 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1563 cfs_read_lock(&filter->fo_sptlrpc_lock);
1564 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1568 cfs_read_unlock(&filter->fo_sptlrpc_lock);
1570 cfs_spin_lock(&exp->exp_lock);
1572 exp->exp_sp_peer = req->rq_sp_from;
1573 exp->exp_flvr = flvr;
1575 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1576 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1577 CERROR("unauthorized rpc flavor %x from %s, "
1578 "expect %x\n", req->rq_flvr.sf_rpc,
1579 libcfs_nid2str(req->rq_peer.nid),
1580 exp->exp_flvr.sf_rpc);
1584 cfs_spin_unlock(&exp->exp_lock);
1586 if (exp->exp_sp_peer != req->rq_sp_from) {
1587 CERROR("RPC source %s doesn't match %s\n",
1588 sptlrpc_part2name(req->rq_sp_from),
1589 sptlrpc_part2name(exp->exp_sp_peer));
1592 rc = sptlrpc_target_export_check(exp, req);
1599 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1600 struct obd_device *obd, int *process)
1602 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1603 case OST_CONNECT: /* This will never get here, but for completeness. */
1604 case OST_DISCONNECT:
1615 case OBD_LOG_CANCEL:
1617 *process = target_queue_recovery_request(req, obd);
1621 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1627 int ost_msg_check_version(struct lustre_msg *msg)
1631 switch(lustre_msg_get_opc(msg)) {
1633 case OST_DISCONNECT:
1636 case SEC_CTX_INIT_CONT:
1638 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1640 CERROR("bad opc %u version %08x, expecting %08x\n",
1641 lustre_msg_get_opc(msg),
1642 lustre_msg_get_version(msg),
1643 LUSTRE_OBD_VERSION);
1656 #ifdef HAVE_QUOTA_SUPPORT
1657 case OST_QUOTACHECK:
1659 case OST_QUOTA_ADJUST_QUNIT:
1661 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1663 CERROR("bad opc %u version %08x, expecting %08x\n",
1664 lustre_msg_get_opc(msg),
1665 lustre_msg_get_version(msg),
1666 LUSTRE_OST_VERSION);
1671 case LDLM_BL_CALLBACK:
1672 case LDLM_CP_CALLBACK:
1673 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1675 CERROR("bad opc %u version %08x, expecting %08x\n",
1676 lustre_msg_get_opc(msg),
1677 lustre_msg_get_version(msg),
1678 LUSTRE_DLM_VERSION);
1680 case LLOG_ORIGIN_CONNECT:
1681 case OBD_LOG_CANCEL:
1682 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1684 CERROR("bad opc %u version %08x, expecting %08x\n",
1685 lustre_msg_get_opc(msg),
1686 lustre_msg_get_version(msg),
1687 LUSTRE_LOG_VERSION);
1690 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1697 * Returns 1 if the given PTLRPC matches the given LDLM locks, or 0 if it does
1700 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1701 struct ldlm_lock *lock)
1703 struct niobuf_remote *nb;
1704 struct obd_ioobj *ioo;
1705 struct ost_body *body;
1706 int objcount, niocount;
1711 opc = lustre_msg_get_opc(req->rq_reqmsg);
1712 LASSERT(opc == OST_READ || opc == OST_WRITE);
1714 /* As the request may be covered by several locks, do not look at
1715 * o_handle, look at the RPC IO region. */
1716 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1720 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1721 RCL_CLIENT) / sizeof(*ioo);
1722 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1726 for (niocount = i = 0; i < objcount; i++)
1727 niocount += ioo[i].ioo_bufcnt;
1729 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1731 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
1732 RCL_CLIENT) / sizeof(*nb)))
1736 if (opc == OST_READ)
1739 start = nb[0].offset & CFS_PAGE_MASK;
1740 end = (nb[ioo->ioo_bufcnt - 1].offset +
1741 nb[ioo->ioo_bufcnt - 1].len - 1) | ~CFS_PAGE_MASK;
1743 LASSERT(lock->l_resource != NULL);
1744 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_gr,
1745 &lock->l_resource->lr_name))
1748 if (!(lock->l_granted_mode & mode))
1751 if (lock->l_policy_data.l_extent.end < start ||
1752 lock->l_policy_data.l_extent.start > end)
1759 * High-priority queue request check for whether the given PTLRPC request (\a
1760 * req) is blocking an LDLM lock cancel.
1762 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1763 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1765 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1766 * function looks only at OST_READs and OST_WRITEs.
1768 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1770 struct niobuf_remote *nb;
1771 struct obd_ioobj *ioo;
1772 struct ost_body *body;
1773 int objcount, niocount;
1777 opc = lustre_msg_get_opc(req->rq_reqmsg);
1778 LASSERT(opc == OST_READ || opc == OST_WRITE);
1780 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1784 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1785 RCL_CLIENT) / sizeof(*ioo);
1786 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1790 for (niocount = i = 0; i < objcount; i++)
1791 niocount += ioo[i].ioo_bufcnt;
1792 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1794 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
1795 RCL_CLIENT) / sizeof(*nb)))
1797 if (niocount != 0 && (nb[0].flags & OBD_BRW_SRVLOCK))
1801 if (opc == OST_READ)
1803 RETURN(ost_rw_prolong_locks(req, ioo, nb, &body->oa, mode));
1806 static int ost_punch_prolong_locks(struct ptlrpc_request *req, struct obdo *oa)
1808 struct ldlm_res_id res_id = { .name = { oa->o_id } };
1809 struct ost_prolong_data opd = { 0 };
1814 end = start + oa->o_blocks;
1816 opd.opd_mode = LCK_PW;
1817 opd.opd_exp = req->rq_export;
1818 opd.opd_policy.l_extent.start = start & CFS_PAGE_MASK;
1819 if (oa->o_blocks == OBD_OBJECT_EOF || end < start)
1820 opd.opd_policy.l_extent.end = OBD_OBJECT_EOF;
1822 opd.opd_policy.l_extent.end = end | ~CFS_PAGE_MASK;
1824 /* prolong locks for the current service time of the corresponding
1825 * portal (= OST_IO_PORTAL) */
1826 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
1827 max(at_est2timeout(at_get(&req->rq_rqbd->
1828 rqbd_service->srv_at_estimate)), ldlm_timeout);
1830 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1831 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
1832 opd.opd_policy.l_extent.end);
1835 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
1836 ost_prolong_locks_iter, &opd);
1837 RETURN(opd.opd_lock_match);
1841 * Like ost_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
1843 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1844 struct ldlm_lock *lock)
1846 struct ost_body *body;
1849 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1851 RETURN(0); /* can't return -EFAULT here */
1853 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1854 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1860 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
1862 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1864 struct ost_body *body;
1866 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1870 LASSERT(!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1871 !(body->oa.o_flags & OBD_FL_SRVLOCK));
1873 RETURN(ost_punch_prolong_locks(req, &body->oa));
1876 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
1877 .hpreq_lock_match = ost_rw_hpreq_lock_match,
1878 .hpreq_check = ost_rw_hpreq_check,
1881 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
1882 .hpreq_lock_match = ost_punch_hpreq_lock_match,
1883 .hpreq_check = ost_punch_hpreq_check,
1886 /** Assign high priority operations to the request if needed. */
1887 static int ost_hpreq_handler(struct ptlrpc_request *req)
1890 if (req->rq_export) {
1891 int opc = lustre_msg_get_opc(req->rq_reqmsg);
1892 struct ost_body *body;
1894 if (opc == OST_READ || opc == OST_WRITE) {
1895 struct niobuf_remote *nb;
1896 struct obd_ioobj *ioo;
1897 int objcount, niocount;
1900 /* RPCs on the H-P queue can be inspected before
1901 * ost_handler() initializes their pills, so we
1902 * initialize that here. Capsule initialization is
1903 * idempotent, as is setting the pill's format (provided
1904 * it doesn't change).
1906 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1907 if (opc == OST_READ)
1908 req_capsule_set(&req->rq_pill,
1911 req_capsule_set(&req->rq_pill,
1912 &RQF_OST_BRW_WRITE);
1914 body = req_capsule_client_get(&req->rq_pill,
1917 CERROR("Missing/short ost_body\n");
1920 objcount = req_capsule_get_size(&req->rq_pill,
1924 if (objcount == 0) {
1925 CERROR("Missing/short ioobj\n");
1929 CERROR("too many ioobjs (%d)\n", objcount);
1933 ioo = req_capsule_client_get(&req->rq_pill,
1936 CERROR("Missing/short ioobj\n");
1940 for (niocount = i = 0; i < objcount; i++) {
1941 if (ioo[i].ioo_bufcnt == 0) {
1942 CERROR("ioo[%d] has zero bufcnt\n", i);
1945 niocount += ioo[i].ioo_bufcnt;
1947 if (niocount > PTLRPC_MAX_BRW_PAGES) {
1948 DEBUG_REQ(D_RPCTRACE, req,
1949 "bulk has too many pages (%d)",
1954 nb = req_capsule_client_get(&req->rq_pill,
1955 &RMF_NIOBUF_REMOTE);
1957 CERROR("Missing/short niobuf\n");
1961 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
1962 req->rq_ops = &ost_hpreq_rw;
1963 } else if (opc == OST_PUNCH) {
1964 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1965 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
1967 body = req_capsule_client_get(&req->rq_pill,
1970 CERROR("Missing/short ost_body\n");
1974 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1975 !(body->oa.o_flags & OBD_FL_SRVLOCK))
1976 req->rq_ops = &ost_hpreq_punch;
1982 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1983 int ost_handle(struct ptlrpc_request *req)
1985 struct obd_trans_info trans_info = { 0, };
1986 struct obd_trans_info *oti = &trans_info;
1987 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1988 struct obd_device *obd = NULL;
1991 LASSERT(current->journal_info == NULL);
1993 /* primordial rpcs don't affect server recovery */
1994 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1996 case SEC_CTX_INIT_CONT:
2001 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2003 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
2006 if (!class_connected_export(req->rq_export)) {
2007 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
2008 lustre_msg_get_opc(req->rq_reqmsg),
2009 libcfs_id2str(req->rq_peer));
2010 req->rq_status = -ENOTCONN;
2011 GOTO(out, rc = -ENOTCONN);
2014 obd = req->rq_export->exp_obd;
2016 /* Check for aborted recovery. */
2017 cfs_spin_lock_bh(&obd->obd_processing_task_lock);
2018 recovering = obd->obd_recovering;
2019 cfs_spin_unlock_bh(&obd->obd_processing_task_lock);
2021 rc = ost_filter_recovery_request(req, obd,
2023 if (rc || !should_process)
2025 else if (should_process < 0) {
2026 req->rq_status = should_process;
2027 rc = ptlrpc_error(req);
2035 rc = ost_msg_check_version(req->rq_reqmsg);
2039 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2041 CDEBUG(D_INODE, "connect\n");
2042 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
2043 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
2045 rc = target_handle_connect(req);
2046 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
2049 rc = ost_init_sec_level(req);
2051 rc = ost_connect_check_sptlrpc(req);
2055 case OST_DISCONNECT:
2056 CDEBUG(D_INODE, "disconnect\n");
2057 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
2058 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
2060 rc = target_handle_disconnect(req);
2063 CDEBUG(D_INODE, "create\n");
2064 req_capsule_set(&req->rq_pill, &RQF_OST_CREATE);
2065 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
2067 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2068 GOTO(out, rc = -EROFS);
2069 rc = ost_create(req->rq_export, req, oti);
2072 CDEBUG(D_INODE, "destroy\n");
2073 req_capsule_set(&req->rq_pill, &RQF_OST_DESTROY);
2074 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
2076 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2077 GOTO(out, rc = -EROFS);
2078 rc = ost_destroy(req->rq_export, req, oti);
2081 CDEBUG(D_INODE, "getattr\n");
2082 req_capsule_set(&req->rq_pill, &RQF_OST_GETATTR);
2083 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
2085 rc = ost_getattr(req->rq_export, req);
2088 CDEBUG(D_INODE, "setattr\n");
2089 req_capsule_set(&req->rq_pill, &RQF_OST_SETATTR);
2090 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
2092 rc = ost_setattr(req->rq_export, req, oti);
2095 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_WRITE);
2096 CDEBUG(D_INODE, "write\n");
2097 /* req->rq_request_portal would be nice, if it was set */
2098 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2099 CERROR("%s: deny write request from %s to portal %u\n",
2100 req->rq_export->exp_obd->obd_name,
2101 obd_export_nid2str(req->rq_export),
2102 req->rq_rqbd->rqbd_service->srv_req_portal);
2103 GOTO(out, rc = -EPROTO);
2105 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2107 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
2108 GOTO(out, rc = -ENOSPC);
2109 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2110 GOTO(out, rc = -EROFS);
2111 rc = ost_brw_write(req, oti);
2112 LASSERT(current->journal_info == NULL);
2113 /* ost_brw_write sends its own replies */
2116 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_READ);
2117 CDEBUG(D_INODE, "read\n");
2118 /* req->rq_request_portal would be nice, if it was set */
2119 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2120 CERROR("%s: deny read request from %s to portal %u\n",
2121 req->rq_export->exp_obd->obd_name,
2122 obd_export_nid2str(req->rq_export),
2123 req->rq_rqbd->rqbd_service->srv_req_portal);
2124 GOTO(out, rc = -EPROTO);
2126 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2128 rc = ost_brw_read(req, oti);
2129 LASSERT(current->journal_info == NULL);
2130 /* ost_brw_read sends its own replies */
2133 CDEBUG(D_INODE, "punch\n");
2134 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2135 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2137 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2138 GOTO(out, rc = -EROFS);
2139 rc = ost_punch(req->rq_export, req, oti);
2142 CDEBUG(D_INODE, "statfs\n");
2143 req_capsule_set(&req->rq_pill, &RQF_OST_STATFS);
2144 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2146 rc = ost_statfs(req);
2149 CDEBUG(D_INODE, "sync\n");
2150 req_capsule_set(&req->rq_pill, &RQF_OST_SYNC);
2151 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2153 rc = ost_sync(req->rq_export, req);
2156 DEBUG_REQ(D_INODE, req, "set_info");
2157 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
2158 rc = ost_set_info(req->rq_export, req);
2161 DEBUG_REQ(D_INODE, req, "get_info");
2162 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
2163 rc = ost_get_info(req->rq_export, req);
2165 #ifdef HAVE_QUOTA_SUPPORT
2166 case OST_QUOTACHECK:
2167 CDEBUG(D_INODE, "quotacheck\n");
2168 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2169 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2171 rc = ost_handle_quotacheck(req);
2174 CDEBUG(D_INODE, "quotactl\n");
2175 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2176 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2178 rc = ost_handle_quotactl(req);
2180 case OST_QUOTA_ADJUST_QUNIT:
2181 CDEBUG(D_INODE, "quota_adjust_qunit\n");
2182 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
2183 rc = ost_handle_quota_adjust_qunit(req);
2187 DEBUG_REQ(D_INODE, req, "ping");
2188 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2189 rc = target_handle_ping(req);
2191 /* FIXME - just reply status */
2192 case LLOG_ORIGIN_CONNECT:
2193 DEBUG_REQ(D_INODE, req, "log connect");
2194 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2195 rc = ost_llog_handle_connect(req->rq_export, req);
2196 req->rq_status = rc;
2197 rc = req_capsule_server_pack(&req->rq_pill);
2200 RETURN(ptlrpc_reply(req));
2201 case OBD_LOG_CANCEL:
2202 CDEBUG(D_INODE, "log cancel\n");
2203 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2204 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2206 rc = llog_origin_handle_cancel(req);
2207 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2209 req->rq_status = rc;
2210 rc = req_capsule_server_pack(&req->rq_pill);
2213 RETURN(ptlrpc_reply(req));
2215 CDEBUG(D_INODE, "enqueue\n");
2216 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2217 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2219 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2220 ldlm_server_blocking_ast,
2221 ldlm_server_glimpse_ast);
2222 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2225 CDEBUG(D_INODE, "convert\n");
2226 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2227 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2229 rc = ldlm_handle_convert(req);
2232 CDEBUG(D_INODE, "cancel\n");
2233 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2234 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2236 rc = ldlm_handle_cancel(req);
2238 case LDLM_BL_CALLBACK:
2239 case LDLM_CP_CALLBACK:
2240 CDEBUG(D_INODE, "callback\n");
2241 CERROR("callbacks should not happen on OST\n");
2244 CERROR("Unexpected opcode %d\n",
2245 lustre_msg_get_opc(req->rq_reqmsg));
2246 req->rq_status = -ENOTSUPP;
2247 rc = ptlrpc_error(req);
2251 LASSERT(current->journal_info == NULL);
2254 /* If we're DISCONNECTing, the export_data is already freed */
2255 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2256 target_committed_to_req(req);
2260 oti_to_request(oti, req);
2262 target_send_reply(req, rc, fail);
2265 EXPORT_SYMBOL(ost_handle);
2267 * free per-thread pool created by ost_thread_init().
2269 static void ost_thread_done(struct ptlrpc_thread *thread)
2271 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2276 LASSERT(thread != NULL);
2279 * be prepared to handle partially-initialized pools (because this is
2280 * called from ost_thread_init() for cleanup.
2282 tls = thread->t_data;
2285 thread->t_data = NULL;
2291 * initialize per-thread page pool (bug 5137).
2293 static int ost_thread_init(struct ptlrpc_thread *thread)
2295 struct ost_thread_local_cache *tls;
2299 LASSERT(thread != NULL);
2300 LASSERT(thread->t_data == NULL);
2301 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
2306 thread->t_data = tls;
2310 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2312 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2313 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2315 struct ost_obd *ost = &obd->u.ost;
2316 struct lprocfs_static_vars lvars;
2317 int oss_min_threads;
2318 int oss_max_threads;
2319 int oss_min_create_threads;
2320 int oss_max_create_threads;
2324 rc = cfs_cleanup_group_info();
2328 lprocfs_ost_init_vars(&lvars);
2329 lprocfs_obd_setup(obd, lvars.obd_vars);
2331 cfs_sema_init(&ost->ost_health_sem, 1);
2333 if (oss_num_threads) {
2334 /* If oss_num_threads is set, it is the min and the max. */
2335 if (oss_num_threads > OSS_THREADS_MAX)
2336 oss_num_threads = OSS_THREADS_MAX;
2337 if (oss_num_threads < OSS_THREADS_MIN)
2338 oss_num_threads = OSS_THREADS_MIN;
2339 oss_max_threads = oss_min_threads = oss_num_threads;
2341 /* Base min threads on memory and cpus */
2343 cfs_num_possible_cpus() * CFS_NUM_CACHEPAGES >>
2344 (27 - CFS_PAGE_SHIFT);
2345 if (oss_min_threads < OSS_THREADS_MIN)
2346 oss_min_threads = OSS_THREADS_MIN;
2347 /* Insure a 4x range for dynamic threads */
2348 if (oss_min_threads > OSS_THREADS_MAX / 4)
2349 oss_min_threads = OSS_THREADS_MAX / 4;
2350 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
2354 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2355 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
2356 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2357 ost_handle, LUSTRE_OSS_NAME,
2358 obd->obd_proc_entry, target_print_req,
2359 oss_min_threads, oss_max_threads,
2360 "ll_ost", LCT_DT_THREAD, NULL);
2361 if (ost->ost_service == NULL) {
2362 CERROR("failed to start service\n");
2363 GOTO(out_lprocfs, rc = -ENOMEM);
2366 rc = ptlrpc_start_threads(obd, ost->ost_service);
2368 GOTO(out_service, rc = -EINVAL);
2370 if (oss_num_create_threads) {
2371 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
2372 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
2373 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
2374 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
2375 oss_min_create_threads = oss_max_create_threads =
2376 oss_num_create_threads;
2378 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
2379 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
2382 ost->ost_create_service =
2383 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2384 OST_MAXREPSIZE, OST_CREATE_PORTAL,
2385 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2386 ost_handle, "ost_create",
2387 obd->obd_proc_entry, target_print_req,
2388 oss_min_create_threads, oss_max_create_threads,
2389 "ll_ost_creat", LCT_DT_THREAD, NULL);
2390 if (ost->ost_create_service == NULL) {
2391 CERROR("failed to start OST create service\n");
2392 GOTO(out_service, rc = -ENOMEM);
2395 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
2397 GOTO(out_create, rc = -EINVAL);
2399 ost->ost_io_service =
2400 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2401 OST_MAXREPSIZE, OST_IO_PORTAL,
2402 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2403 ost_handle, "ost_io",
2404 obd->obd_proc_entry, target_print_req,
2405 oss_min_threads, oss_max_threads,
2406 "ll_ost_io", LCT_DT_THREAD, ost_hpreq_handler);
2407 if (ost->ost_io_service == NULL) {
2408 CERROR("failed to start OST I/O service\n");
2409 GOTO(out_create, rc = -ENOMEM);
2412 ost->ost_io_service->srv_init = ost_thread_init;
2413 ost->ost_io_service->srv_done = ost_thread_done;
2414 ost->ost_io_service->srv_cpu_affinity = 1;
2415 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
2417 GOTO(out_io, rc = -EINVAL);
2419 ping_evictor_start();
2424 ptlrpc_unregister_service(ost->ost_io_service);
2425 ost->ost_io_service = NULL;
2427 ptlrpc_unregister_service(ost->ost_create_service);
2428 ost->ost_create_service = NULL;
2430 ptlrpc_unregister_service(ost->ost_service);
2431 ost->ost_service = NULL;
2433 lprocfs_obd_cleanup(obd);
2437 static int ost_cleanup(struct obd_device *obd)
2439 struct ost_obd *ost = &obd->u.ost;
2443 ping_evictor_stop();
2445 cfs_spin_lock_bh(&obd->obd_processing_task_lock);
2446 if (obd->obd_recovering) {
2447 target_cancel_recovery_timer(obd);
2448 obd->obd_recovering = 0;
2450 cfs_spin_unlock_bh(&obd->obd_processing_task_lock);
2452 cfs_down(&ost->ost_health_sem);
2453 ptlrpc_unregister_service(ost->ost_service);
2454 ptlrpc_unregister_service(ost->ost_create_service);
2455 ptlrpc_unregister_service(ost->ost_io_service);
2456 ost->ost_service = NULL;
2457 ost->ost_create_service = NULL;
2458 cfs_up(&ost->ost_health_sem);
2460 lprocfs_obd_cleanup(obd);
2465 static int ost_health_check(struct obd_device *obd)
2467 struct ost_obd *ost = &obd->u.ost;
2470 cfs_down(&ost->ost_health_sem);
2471 rc |= ptlrpc_service_health_check(ost->ost_service);
2472 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2473 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2474 cfs_up(&ost->ost_health_sem);
2477 * health_check to return 0 on healthy
2478 * and 1 on unhealthy.
2486 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2488 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2491 /* use obd ops to offer management infrastructure */
2492 static struct obd_ops ost_obd_ops = {
2493 .o_owner = THIS_MODULE,
2494 .o_setup = ost_setup,
2495 .o_cleanup = ost_cleanup,
2496 .o_health_check = ost_health_check,
2500 static int __init ost_init(void)
2502 struct lprocfs_static_vars lvars;
2506 lprocfs_ost_init_vars(&lvars);
2507 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2508 LUSTRE_OSS_NAME, NULL);
2510 if (ost_num_threads != 0 && oss_num_threads == 0) {
2511 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2512 "use oss_num_threads instead or unset both for "
2513 "dynamic thread startup\n");
2514 oss_num_threads = ost_num_threads;
2520 static void /*__exit*/ ost_exit(void)
2522 class_unregister_type(LUSTRE_OSS_NAME);
2525 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2526 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2527 MODULE_LICENSE("GPL");
2529 module_init(ost_init);
2530 module_exit(ost_exit);