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 __u64 versions[PTLRPC_NUM_VERSIONS] = { 0 };
94 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
95 versions[0] = oti->oti_pre_version;
96 lustre_msg_set_versions(req->rq_repmsg, versions);
98 req->rq_transno = oti->oti_transno;
100 /* XXX 4 == entries in oti_ack_locks??? */
101 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
104 /* XXX not even calling target_send_reply in some cases... */
105 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode, 0);
109 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
110 struct obd_trans_info *oti)
112 struct ost_body *body, *repbody;
113 struct lustre_capa *capa = NULL;
117 /* Get the request body */
118 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
122 if (body->oa.o_id == 0)
125 /* If there's a DLM request, cancel the locks mentioned in it*/
126 if (req_capsule_field_present(&req->rq_pill, &RMF_DLM_REQ, RCL_CLIENT)) {
127 struct ldlm_request *dlm;
129 dlm = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
132 ldlm_request_cancel(req, dlm, 0);
135 /* If there's a capability, get it */
136 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
137 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
139 CERROR("Missing capability for OST DESTROY");
144 /* Prepare the reply */
145 rc = req_capsule_server_pack(&req->rq_pill);
149 /* Get the log cancellation cookie */
150 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
151 oti->oti_logcookies = &body->oa.o_lcookie;
153 /* Finish the reply */
154 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
155 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
157 /* Do the destroy and set the reply status accordingly */
158 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL, capa);
163 * Helper function for getting server side [start, start+count] DLM lock
164 * if asked by client.
166 static int ost_lock_get(struct obd_export *exp, struct obdo *oa,
167 __u64 start, __u64 count, struct lustre_handle *lh,
170 struct ldlm_res_id res_id = { .name = { oa->o_id, 0, oa->o_gr, 0} };
171 ldlm_policy_data_t policy;
172 __u64 end = start + count;
176 LASSERT(!lustre_handle_is_used(lh));
177 /* o_id and o_gr are used for localizing resource, if client miss to set
178 * them, do not trigger ASSERTION. */
179 if (unlikely((oa->o_valid & (OBD_MD_FLID | OBD_MD_FLGROUP)) !=
180 (OBD_MD_FLID | OBD_MD_FLGROUP)))
183 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
184 !(oa->o_flags & OBD_FL_SRVLOCK))
187 CDEBUG(D_INODE, "OST-side extent lock.\n");
189 policy.l_extent.start = start & CFS_PAGE_MASK;
191 /* If ->o_blocks is EOF it means "lock till the end of the
192 * file". Otherwise, it's size of a hole being punched (in bytes) */
193 if (count == OBD_OBJECT_EOF || end < start)
194 policy.l_extent.end = OBD_OBJECT_EOF;
196 policy.l_extent.end = end | ~CFS_PAGE_MASK;
198 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
199 LDLM_EXTENT, &policy, mode, &flags,
200 ldlm_blocking_ast, ldlm_completion_ast,
201 ldlm_glimpse_ast, NULL, 0, NULL, lh));
204 /* Helper function: release lock, if any. */
205 static void ost_lock_put(struct obd_export *exp,
206 struct lustre_handle *lh, int mode)
209 if (lustre_handle_is_used(lh))
210 ldlm_lock_decref(lh, mode);
214 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
216 struct ost_body *body, *repbody;
217 struct obd_info oinfo = { { { 0 } } };
218 struct lustre_handle lh = { 0 };
222 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
226 rc = req_capsule_server_pack(&req->rq_pill);
230 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
231 repbody->oa = body->oa;
233 rc = ost_lock_get(exp, &body->oa, 0, OBD_OBJECT_EOF, &lh, LCK_PR, 0);
237 oinfo.oi_oa = &repbody->oa;
238 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA) {
239 oinfo.oi_capa = req_capsule_client_get(&req->rq_pill,
241 if (oinfo.oi_capa == NULL) {
242 CERROR("Missing capability for OST GETATTR");
247 req->rq_status = obd_getattr(exp, &oinfo);
248 ost_lock_put(exp, &lh, LCK_PR);
250 ost_drop_id(exp, &repbody->oa);
254 static int ost_statfs(struct ptlrpc_request *req)
256 struct obd_statfs *osfs;
260 rc = req_capsule_server_pack(&req->rq_pill);
264 osfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
266 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
267 cfs_time_current_64() - CFS_HZ, 0);
268 if (req->rq_status != 0)
269 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
274 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
275 struct obd_trans_info *oti)
277 struct ost_body *body, *repbody;
281 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
285 rc = req_capsule_server_pack(&req->rq_pill);
289 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
290 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
291 oti->oti_logcookies = &repbody->oa.o_lcookie;
293 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
294 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
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 /* standard truncate optimization: if file body is completely
327 * destroyed, don't send data back to the server. */
328 if (oinfo.oi_oa->o_size == 0)
329 flags |= LDLM_AST_DISCARD_DATA;
331 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
332 rc = ost_lock_get(exp, oinfo.oi_oa, oinfo.oi_oa->o_size,
333 oinfo.oi_oa->o_blocks, &lh, LCK_PW, flags);
335 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
336 oinfo.oi_oa->o_flags == OBD_FL_SRVLOCK)
338 * If OBD_FL_SRVLOCK is the only bit set in
339 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
340 * through filter_setattr() to filter_iocontrol().
342 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
344 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA) {
345 oinfo.oi_capa = req_capsule_client_get(&req->rq_pill,
347 if (oinfo.oi_capa == NULL) {
348 CERROR("Missing capability for OST PUNCH");
352 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
353 ost_lock_put(exp, &lh, LCK_PW);
355 repbody->oa = *oinfo.oi_oa;
356 ost_drop_id(exp, &repbody->oa);
360 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
362 struct ost_body *body, *repbody;
363 struct lustre_capa *capa = NULL;
367 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
371 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
372 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
374 CERROR("Missing capability for OST SYNC");
379 rc = req_capsule_server_pack(&req->rq_pill);
383 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
384 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
385 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
386 repbody->oa.o_blocks, capa);
387 ost_drop_id(exp, &repbody->oa);
391 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
392 struct obd_trans_info *oti)
394 struct ost_body *body, *repbody;
396 struct obd_info oinfo = { { { 0 } } };
399 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
403 rc = req_capsule_server_pack(&req->rq_pill);
407 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
408 repbody->oa = body->oa;
410 oinfo.oi_oa = &repbody->oa;
411 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA) {
412 oinfo.oi_capa = req_capsule_client_get(&req->rq_pill,
414 if (oinfo.oi_capa == NULL) {
415 CERROR("Missing capability for OST SETATTR");
419 req->rq_status = obd_setattr(exp, &oinfo, oti);
420 ost_drop_id(exp, &repbody->oa);
424 static int ost_bulk_timeout(void *data)
427 /* We don't fail the connection here, because having the export
428 * killed makes the (vital) call to commitrw very sad.
433 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
434 cksum_type_t cksum_type)
439 cksum = init_checksum(cksum_type);
440 for (i = 0; i < desc->bd_iov_count; i++) {
441 struct page *page = desc->bd_iov[i].kiov_page;
442 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
443 char *ptr = kmap(page) + off;
444 int len = desc->bd_iov[i].kiov_len;
446 /* corrupt the data before we compute the checksum, to
447 * simulate a client->OST data error */
448 if (i == 0 && opc == OST_WRITE &&
449 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
450 memcpy(ptr, "bad3", min(4, len));
451 cksum = compute_checksum(cksum, ptr, len, cksum_type);
452 /* corrupt the data after we compute the checksum, to
453 * simulate an OST->client data error */
454 if (i == 0 && opc == OST_READ &&
455 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
456 memcpy(ptr, "bad4", min(4, len));
457 /* nobody should use corrupted page again */
458 ClearPageUptodate(page);
466 static int ost_brw_lock_get(int mode, struct obd_export *exp,
467 struct obd_ioobj *obj, struct niobuf_remote *nb,
468 struct lustre_handle *lh)
471 int nrbufs = obj->ioo_bufcnt;
472 struct ldlm_res_id res_id;
473 ldlm_policy_data_t policy;
477 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
478 LASSERT(mode == LCK_PR || mode == LCK_PW);
479 LASSERT(!lustre_handle_is_used(lh));
481 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
484 for (i = 1; i < nrbufs; i ++)
485 if ((nb[0].flags & OBD_BRW_SRVLOCK) !=
486 (nb[i].flags & OBD_BRW_SRVLOCK))
489 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
490 policy.l_extent.end = (nb[nrbufs - 1].offset +
491 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
493 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
494 LDLM_EXTENT, &policy, mode, &flags,
495 ldlm_blocking_ast, ldlm_completion_ast,
496 ldlm_glimpse_ast, NULL, 0, NULL, lh));
499 static void ost_brw_lock_put(int mode,
500 struct obd_ioobj *obj, struct niobuf_remote *niob,
501 struct lustre_handle *lh)
504 LASSERT(mode == LCK_PR || mode == LCK_PW);
505 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
506 lustre_handle_is_used(lh));
507 if (lustre_handle_is_used(lh))
508 ldlm_lock_decref(lh, mode);
512 struct ost_prolong_data {
513 struct obd_export *opd_exp;
514 ldlm_policy_data_t opd_policy;
516 ldlm_mode_t opd_mode;
521 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
523 struct ost_prolong_data *opd = data;
525 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
527 if (lock->l_req_mode != lock->l_granted_mode) {
528 /* scan granted locks only */
529 return LDLM_ITER_STOP;
532 if (lock->l_export != opd->opd_exp) {
533 /* prolong locks only for given client */
534 return LDLM_ITER_CONTINUE;
537 if (!(lock->l_granted_mode & opd->opd_mode)) {
538 /* we aren't interesting in all type of locks */
539 return LDLM_ITER_CONTINUE;
542 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
543 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
544 /* the request doesn't cross the lock, skip it */
545 return LDLM_ITER_CONTINUE;
548 /* Fill the obdo with the matched lock handle.
549 * XXX: it is possible in some cases the IO RPC is covered by several
550 * locks, even for the write case, so it may need to be a lock list. */
551 if (opd->opd_oa && !(opd->opd_oa->o_valid & OBD_MD_FLHANDLE)) {
552 opd->opd_oa->o_handle.cookie = lock->l_handle.h_cookie;
553 opd->opd_oa->o_valid |= OBD_MD_FLHANDLE;
556 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
557 /* ignore locks not being cancelled */
558 return LDLM_ITER_CONTINUE;
561 CDEBUG(D_DLMTRACE,"refresh lock: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
562 lock->l_resource->lr_name.name[0],
563 lock->l_resource->lr_name.name[1],
564 opd->opd_policy.l_extent.start, opd->opd_policy.l_extent.end);
565 /* OK. this is a possible lock the user holds doing I/O
566 * let's refresh eviction timer for it */
567 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
568 opd->opd_lock_match = 1;
570 return LDLM_ITER_CONTINUE;
573 static int ost_rw_prolong_locks(struct ptlrpc_request *req, struct obd_ioobj *obj,
574 struct niobuf_remote *nb, struct obdo *oa,
577 struct ldlm_res_id res_id;
578 int nrbufs = obj->ioo_bufcnt;
579 struct ost_prolong_data opd = { 0 };
582 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
585 opd.opd_exp = req->rq_export;
586 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
587 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
588 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
590 /* prolong locks for the current service time of the corresponding
591 * portal (= OST_IO_PORTAL) */
592 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
593 max(at_est2timeout(at_get(&req->rq_rqbd->
594 rqbd_service->srv_at_estimate)), ldlm_timeout);
596 CDEBUG(D_INFO,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
597 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
598 opd.opd_policy.l_extent.end);
600 if (oa->o_valid & OBD_MD_FLHANDLE) {
601 struct ldlm_lock *lock;
603 lock = ldlm_handle2lock(&oa->o_handle);
605 ost_prolong_locks_iter(lock, &opd);
606 if (opd.opd_lock_match) {
611 /* Check if the lock covers the whole IO region,
612 * otherwise iterate through the resource. */
613 if (lock->l_policy_data.l_extent.end >=
614 opd.opd_policy.l_extent.end &&
615 lock->l_policy_data.l_extent.start <=
616 opd.opd_policy.l_extent.start) {
625 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
626 ost_prolong_locks_iter, &opd);
627 RETURN(opd.opd_lock_match);
630 /* Allocate thread local buffers if needed */
631 static struct ost_thread_local_cache *ost_tls_get(struct ptlrpc_request *r)
633 struct ost_thread_local_cache *tls =
634 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
636 /* In normal mode of operation an I/O request is serviced only
637 * by ll_ost_io threads each of them has own tls buffers allocated by
639 * During recovery, an I/O request may be queued until any of the ost
640 * service threads process it. Not necessary it should be one of
641 * ll_ost_io threads. In that case we dynamically allocating tls
642 * buffers for the request service time. */
643 if (unlikely(tls == NULL)) {
644 LASSERT(r->rq_export->exp_in_recovery);
648 r->rq_svc_thread->t_data = tls;
654 /* Free thread local buffers if they were allocated only for servicing
655 * this one request */
656 static void ost_tls_put(struct ptlrpc_request *r)
658 struct ost_thread_local_cache *tls =
659 (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
661 if (unlikely(tls->temporary)) {
663 r->rq_svc_thread->t_data = NULL;
667 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
669 struct ptlrpc_bulk_desc *desc = NULL;
670 struct obd_export *exp = req->rq_export;
671 struct niobuf_remote *remote_nb;
672 struct niobuf_local *local_nb;
673 struct obd_ioobj *ioo;
674 struct ost_body *body, *repbody;
675 struct lustre_capa *capa = NULL;
676 struct l_wait_info lwi;
677 struct lustre_handle lockh = { 0 };
678 int niocount, npages, nob = 0, rc, i;
680 struct ost_thread_local_cache *tls;
683 req->rq_bulk_read = 1;
685 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
686 GOTO(out, rc = -EIO);
688 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
690 /* Check if there is eviction in progress, and if so, wait for it to
692 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
693 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
694 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
695 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
699 GOTO(out, rc = -ENOTCONN);
701 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
702 * ost_rw_hpreq_check(). */
703 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
705 GOTO(out, rc = -EFAULT);
708 * A req_capsule_X_get_array(pill, field, ptr_to_element_count) function
709 * would be useful here and wherever we get &RMF_OBD_IOOBJ and
710 * &RMF_NIOBUF_REMOTE.
712 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
714 GOTO(out, rc = -EFAULT);
716 niocount = ioo->ioo_bufcnt;
717 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
718 if (remote_nb == NULL)
719 GOTO(out, rc = -EFAULT);
721 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
722 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
724 CERROR("Missing capability for OST BRW READ");
725 GOTO(out, rc = -EFAULT);
729 rc = req_capsule_server_pack(&req->rq_pill);
733 tls = ost_tls_get(req);
735 GOTO(out_bulk, rc = -ENOMEM);
736 local_nb = tls->local;
738 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
743 * If getting the lock took more time than
744 * client was willing to wait, drop it. b=11330
746 if (cfs_time_current_sec() > req->rq_deadline ||
747 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
749 CERROR("Dropping timed-out read from %s because locking"
750 "object "LPX64" took %ld seconds (limit was %ld).\n",
751 libcfs_id2str(req->rq_peer), ioo->ioo_id,
752 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
753 req->rq_deadline - req->rq_arrival_time.tv_sec);
754 GOTO(out_lock, rc = -ETIMEDOUT);
757 npages = OST_THREAD_POOL_SIZE;
758 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
759 remote_nb, &npages, local_nb, oti, capa);
763 desc = ptlrpc_prep_bulk_exp(req, npages,
764 BULK_PUT_SOURCE, OST_BULK_PORTAL);
766 GOTO(out_lock, rc = -ENOMEM);
768 if (!lustre_handle_is_used(&lockh))
769 /* no needs to try to prolong lock if server is asked
770 * to handle locking (= OBD_BRW_SRVLOCK) */
771 ost_rw_prolong_locks(req, ioo, remote_nb, &body->oa,
775 for (i = 0; i < npages; i++) {
776 int page_rc = local_nb[i].rc;
778 if (page_rc < 0) { /* error */
784 if (page_rc != 0) { /* some data! */
785 LASSERT (local_nb[i].page != NULL);
786 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
787 local_nb[i].offset & ~CFS_PAGE_MASK,
791 if (page_rc != local_nb[i].len) { /* short read */
792 /* All subsequent pages should be 0 */
794 LASSERT(local_nb[i].rc == 0);
799 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
800 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
802 if (body->oa.o_valid & OBD_MD_FLFLAGS)
803 cksum_type = cksum_type_unpack(body->oa.o_flags);
804 body->oa.o_flags = cksum_type_pack(cksum_type);
805 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
806 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
807 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
809 body->oa.o_valid = 0;
811 /* We're finishing using body->oa as an input variable */
813 /* Check if client was evicted while we were doing i/o before touching
816 /* Check if there is eviction in progress, and if so, wait for
818 if (unlikely(cfs_atomic_read(&exp->exp_obd->
819 obd_evict_inprogress))) {
820 lwi = LWI_INTR(NULL, NULL);
821 rc = l_wait_event(exp->exp_obd->
822 obd_evict_inprogress_waitq,
823 !cfs_atomic_read(&exp->exp_obd->
824 obd_evict_inprogress),
827 /* Check if client was evicted or tried to reconnect already */
828 if (exp->exp_failed || exp->exp_abort_active_req)
831 rc = sptlrpc_svc_wrap_bulk(req, desc);
833 rc = ptlrpc_start_bulk_transfer(desc);
837 time_t start = cfs_time_current_sec();
839 long timeoutl = req->rq_deadline -
840 cfs_time_current_sec();
841 cfs_duration_t timeout = timeoutl <= 0 ?
842 CFS_TICK : cfs_time_seconds(timeoutl);
843 lwi = LWI_TIMEOUT_INTERVAL(timeout,
847 rc = l_wait_event(desc->bd_waitq,
848 !ptlrpc_server_bulk_active(desc) ||
850 exp->exp_abort_active_req,
852 LASSERT(rc == 0 || rc == -ETIMEDOUT);
853 /* Wait again if we changed deadline */
854 } while ((rc == -ETIMEDOUT) &&
855 (req->rq_deadline > cfs_time_current_sec()));
857 if (rc == -ETIMEDOUT) {
858 DEBUG_REQ(D_ERROR, req,
859 "timeout on bulk PUT after %ld%+lds",
860 req->rq_deadline - start,
861 cfs_time_current_sec() -
863 ptlrpc_abort_bulk(desc);
864 } else if (exp->exp_failed) {
865 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
867 ptlrpc_abort_bulk(desc);
868 } else if (exp->exp_abort_active_req) {
869 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk PUT");
870 /* we don't reply anyway */
872 ptlrpc_abort_bulk(desc);
873 } else if (!desc->bd_success ||
874 desc->bd_nob_transferred != desc->bd_nob) {
875 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
877 "truncated" : "network error on",
878 desc->bd_nob_transferred,
880 /* XXX should this be a different errno? */
884 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
889 /* Must commit after prep above in all cases */
890 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
891 remote_nb, npages, local_nb, oti, rc);
894 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
895 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
896 ost_drop_id(exp, &repbody->oa);
900 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
905 ptlrpc_free_bulk(desc);
909 req->rq_status = nob;
910 ptlrpc_lprocfs_brw(req, nob);
911 target_committed_to_req(req);
913 } else if (!no_reply) {
914 /* Only reply if there was no comms problem with bulk */
915 target_committed_to_req(req);
919 /* reply out callback would free */
920 ptlrpc_req_drop_rs(req);
921 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
922 "client will retry\n",
923 exp->exp_obd->obd_name,
924 exp->exp_client_uuid.uuid,
925 exp->exp_connection->c_remote_uuid.uuid,
926 libcfs_id2str(req->rq_peer));
932 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
934 struct ptlrpc_bulk_desc *desc = NULL;
935 struct obd_export *exp = req->rq_export;
936 struct niobuf_remote *remote_nb;
937 struct niobuf_local *local_nb;
938 struct obd_ioobj *ioo;
939 struct ost_body *body, *repbody;
940 struct l_wait_info lwi;
941 struct lustre_handle lockh = {0};
942 struct lustre_capa *capa = NULL;
944 int objcount, niocount, npages;
946 obd_count client_cksum = 0, server_cksum = 0;
947 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
949 __u32 o_uid = 0, o_gid = 0;
950 struct ost_thread_local_cache *tls;
953 req->rq_bulk_write = 1;
955 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
956 GOTO(out, rc = -EIO);
957 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
958 GOTO(out, rc = -EFAULT);
960 /* pause before transaction has been started */
961 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
963 /* Check if there is eviction in progress, and if so, wait for it to
965 if (unlikely(cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
966 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
967 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
968 !cfs_atomic_read(&exp->exp_obd->obd_evict_inprogress),
972 GOTO(out, rc = -ENOTCONN);
974 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
975 * ost_rw_hpreq_check(). */
976 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
978 GOTO(out, rc = -EFAULT);
980 if ((body->oa.o_flags & OBD_BRW_MEMALLOC) &&
981 (exp->exp_connection->c_peer.nid == exp->exp_connection->c_self))
982 libcfs_memory_pressure_set();
984 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
985 RCL_CLIENT) / sizeof(*ioo);
986 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
988 GOTO(out, rc = -EFAULT);
989 for (niocount = i = 0; i < objcount; i++)
990 niocount += ioo[i].ioo_bufcnt;
993 * It'd be nice to have a capsule function to indicate how many elements
994 * there were in a buffer for an RMF that's declared to be an array.
995 * It's easy enough to compute the number of elements here though.
997 remote_nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
998 if (remote_nb == NULL || niocount != (req_capsule_get_size(&req->rq_pill,
999 &RMF_NIOBUF_REMOTE, RCL_CLIENT) / sizeof(*remote_nb)))
1000 GOTO(out, rc = -EFAULT);
1002 if (body->oa.o_valid & OBD_MD_FLOSSCAPA) {
1003 capa = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
1005 CERROR("Missing capability for OST BRW WRITE");
1006 GOTO(out, rc = -EFAULT);
1010 req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER,
1011 niocount * sizeof(*rcs));
1012 rc = req_capsule_server_pack(&req->rq_pill);
1015 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, obd_fail_val);
1016 rcs = req_capsule_server_get(&req->rq_pill, &RMF_RCS);
1018 tls = ost_tls_get(req);
1020 GOTO(out_bulk, rc = -ENOMEM);
1021 local_nb = tls->local;
1023 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
1028 * If getting the lock took more time than
1029 * client was willing to wait, drop it. b=11330
1031 if (cfs_time_current_sec() > req->rq_deadline ||
1032 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
1034 CERROR("Dropping timed-out write from %s because locking "
1035 "object "LPX64" took %ld seconds (limit was %ld).\n",
1036 libcfs_id2str(req->rq_peer), ioo->ioo_id,
1037 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
1038 req->rq_deadline - req->rq_arrival_time.tv_sec);
1039 GOTO(out_lock, rc = -ETIMEDOUT);
1042 if (!lustre_handle_is_used(&lockh))
1043 /* no needs to try to prolong lock if server is asked
1044 * to handle locking (= OBD_BRW_SRVLOCK) */
1045 ost_rw_prolong_locks(req, ioo, remote_nb,&body->oa, LCK_PW);
1047 /* obd_preprw clobbers oa->valid, so save what we need */
1048 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
1049 client_cksum = body->oa.o_cksum;
1050 if (body->oa.o_valid & OBD_MD_FLFLAGS)
1051 cksum_type = cksum_type_unpack(body->oa.o_flags);
1054 /* Because we already sync grant info with client when reconnect,
1055 * grant info will be cleared for resent req, then fed_grant and
1056 * total_grant will not be modified in following preprw_write */
1057 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1058 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1059 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1062 if (exp_connect_rmtclient(exp)) {
1063 o_uid = body->oa.o_uid;
1064 o_gid = body->oa.o_gid;
1066 npages = OST_THREAD_POOL_SIZE;
1067 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
1068 ioo, remote_nb, &npages, local_nb, oti, capa);
1072 desc = ptlrpc_prep_bulk_exp(req, npages,
1073 BULK_GET_SINK, OST_BULK_PORTAL);
1075 GOTO(out_lock, rc = -ENOMEM);
1077 /* NB Having prepped, we must commit... */
1079 for (i = 0; i < npages; i++)
1080 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1081 local_nb[i].offset & ~CFS_PAGE_MASK,
1084 rc = sptlrpc_svc_prep_bulk(req, desc);
1088 /* Check if client was evicted or tried to reconnect while we
1089 * were doing i/o before touching network */
1090 if (desc->bd_export->exp_failed ||
1091 desc->bd_export->exp_abort_active_req)
1094 rc = ptlrpc_start_bulk_transfer(desc);
1096 time_t start = cfs_time_current_sec();
1098 long timeoutl = req->rq_deadline -
1099 cfs_time_current_sec();
1100 cfs_duration_t timeout = timeoutl <= 0 ?
1101 CFS_TICK : cfs_time_seconds(timeoutl);
1102 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
1103 ost_bulk_timeout, desc);
1104 rc = l_wait_event(desc->bd_waitq,
1105 !ptlrpc_server_bulk_active(desc) ||
1106 desc->bd_export->exp_failed ||
1107 desc->bd_export->exp_abort_active_req,
1109 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1110 /* Wait again if we changed deadline */
1111 } while ((rc == -ETIMEDOUT) &&
1112 (req->rq_deadline > cfs_time_current_sec()));
1114 if (rc == -ETIMEDOUT) {
1115 DEBUG_REQ(D_ERROR, req,
1116 "timeout on bulk GET after %ld%+lds",
1117 req->rq_deadline - start,
1118 cfs_time_current_sec() -
1120 ptlrpc_abort_bulk(desc);
1121 } else if (desc->bd_export->exp_failed) {
1122 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1124 ptlrpc_abort_bulk(desc);
1125 } else if (desc->bd_export->exp_abort_active_req) {
1126 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk GET");
1127 /* we don't reply anyway */
1129 ptlrpc_abort_bulk(desc);
1130 } else if (!desc->bd_success) {
1131 DEBUG_REQ(D_ERROR, req, "network error on bulk GET");
1132 /* XXX should this be a different errno? */
1135 rc = sptlrpc_svc_unwrap_bulk(req, desc);
1138 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1142 repbody = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
1143 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1145 if (unlikely(client_cksum != 0 && rc == 0)) {
1146 static int cksum_counter;
1147 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1148 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1149 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1150 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1151 repbody->oa.o_cksum = server_cksum;
1153 if (unlikely(client_cksum != server_cksum)) {
1154 CERROR("client csum %x, server csum %x\n",
1155 client_cksum, server_cksum);
1157 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1158 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1159 cksum_counter, libcfs_id2str(req->rq_peer),
1164 /* Must commit after prep above in all cases */
1165 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1166 remote_nb, npages, local_nb, oti, rc);
1167 if (rc == -ENOTCONN)
1168 /* quota acquire process has been given up because
1169 * either the client has been evicted or the client
1170 * has timed out the request already */
1173 if (exp_connect_rmtclient(exp)) {
1174 repbody->oa.o_uid = o_uid;
1175 repbody->oa.o_gid = o_gid;
1179 * Disable sending mtime back to the client. If the client locked the
1180 * whole object, then it has already updated the mtime on its side,
1181 * otherwise it will have to glimpse anyway (see bug 21489, comment 32)
1183 repbody->oa.o_valid &= ~(OBD_MD_FLMTIME | OBD_MD_FLATIME);
1185 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1186 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1191 if (new_cksum == server_cksum)
1192 msg = "changed in transit before arrival at OST";
1193 else if (new_cksum == client_cksum)
1194 msg = "initial checksum before message complete";
1196 msg = "changed in transit AND after initial checksum";
1198 if (req->rq_peer.nid == desc->bd_sender) {
1202 router = libcfs_nid2str(desc->bd_sender);
1205 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1206 "%s%s%s inum "LPU64"/"LPU64" object "
1207 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1208 exp->exp_obd->obd_name, msg,
1209 libcfs_id2str(req->rq_peer),
1211 body->oa.o_valid & OBD_MD_FLFID ?
1212 body->oa.o_fid : (__u64)0,
1213 body->oa.o_valid & OBD_MD_FLFID ?
1214 body->oa.o_generation :(__u64)0,
1216 body->oa.o_valid & OBD_MD_FLGROUP ?
1217 body->oa.o_gr : (__u64)0,
1219 local_nb[npages-1].offset +
1220 local_nb[npages-1].len - 1 );
1221 CERROR("client csum %x, original server csum %x, "
1222 "server csum now %x\n",
1223 client_cksum, server_cksum, new_cksum);
1229 /* set per-requested niobuf return codes */
1230 for (i = j = 0; i < niocount; i++) {
1231 int len = remote_nb[i].len;
1236 LASSERT(j < npages);
1237 if (local_nb[j].rc < 0)
1238 rcs[i] = local_nb[j].rc;
1239 len -= local_nb[j].len;
1244 LASSERT(j == npages);
1245 ptlrpc_lprocfs_brw(req, nob);
1249 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1254 ptlrpc_free_bulk(desc);
1256 /* XXX: don't send reply if obd rdonly mode, this can cause data loss
1257 * on client, see bug 22190. Remove this when async bulk will be done.
1258 * Meanwhile, if this is umount then don't reply anything. */
1259 if (req->rq_export->exp_obd->obd_no_transno) {
1260 no_reply = req->rq_export->exp_obd->obd_stopping;
1265 oti_to_request(oti, req);
1266 target_committed_to_req(req);
1267 rc = ptlrpc_reply(req);
1268 } else if (!no_reply) {
1269 /* Only reply if there was no comms problem with bulk */
1270 target_committed_to_req(req);
1271 req->rq_status = rc;
1274 /* reply out callback would free */
1275 ptlrpc_req_drop_rs(req);
1276 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1277 "client will retry\n",
1278 exp->exp_obd->obd_name,
1279 exp->exp_client_uuid.uuid,
1280 exp->exp_connection->c_remote_uuid.uuid,
1281 libcfs_id2str(req->rq_peer));
1283 libcfs_memory_pressure_clr();
1288 * Implementation of OST_SET_INFO.
1290 * OST_SET_INFO is like ioctl(): heavily overloaded. Specifically, it takes a
1291 * "key" and a value RPC buffers as arguments, with the value's contents
1292 * interpreted according to the key.
1294 * Value types that need swabbing have swabbing done explicitly, either here or
1295 * in functions called from here. This should be corrected: all swabbing should
1296 * be done in the capsule abstraction, as that will then allow us to move
1297 * swabbing exclusively to the client without having to modify server code
1298 * outside the capsule abstraction's implementation itself. To correct this
1299 * will require minor changes to the capsule abstraction; see the comments for
1300 * req_capsule_extend() in layout.c.
1302 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1304 struct ost_body *body = NULL, *repbody;
1305 char *key, *val = NULL;
1306 int keylen, vallen, rc = 0;
1307 int is_grant_shrink = 0;
1310 key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1312 DEBUG_REQ(D_HA, req, "no set_info key");
1315 keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY,
1318 vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL,
1321 if ((is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK)))
1322 /* In this case the value is actually an RMF_OST_BODY, so we
1323 * transmutate the type of this PTLRPC */
1324 req_capsule_extend(&req->rq_pill, &RQF_OST_SET_GRANT_INFO);
1326 rc = req_capsule_server_pack(&req->rq_pill);
1331 if (is_grant_shrink) {
1332 body = req_capsule_client_get(&req->rq_pill,
1337 repbody = req_capsule_server_get(&req->rq_pill,
1339 memcpy(repbody, body, sizeof(*body));
1340 val = (char*)repbody;
1342 val = req_capsule_client_get(&req->rq_pill,
1347 if (KEY_IS(KEY_EVICT_BY_NID)) {
1349 obd_export_evict_by_nid(exp->exp_obd, val);
1351 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1352 if (vallen < sizeof(__u32))
1354 __swab32s((__u32 *)val);
1357 /* OBD will also check if KEY_IS(KEY_GRANT_SHRINK), and will cast val to
1358 * a struct ost_body * value */
1359 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1361 lustre_msg_set_status(req->rq_repmsg, 0);
1365 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1368 int keylen, replylen, rc = 0;
1369 struct req_capsule *pill = &req->rq_pill;
1372 /* this common part for get_info rpc */
1373 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1375 DEBUG_REQ(D_HA, req, "no get_info key");
1378 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1380 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1384 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1385 RCL_SERVER, replylen);
1387 rc = req_capsule_server_pack(pill);
1391 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1395 /* call again to fill in the reply buffer */
1396 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1398 lustre_msg_set_status(req->rq_repmsg, 0);
1402 #ifdef HAVE_QUOTA_SUPPORT
1403 static int ost_handle_quotactl(struct ptlrpc_request *req)
1405 struct obd_quotactl *oqctl, *repoqc;
1409 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1411 GOTO(out, rc = -EPROTO);
1413 rc = req_capsule_server_pack(&req->rq_pill);
1417 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1418 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1425 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1427 struct obd_quotactl *oqctl;
1431 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1435 rc = req_capsule_server_pack(&req->rq_pill);
1439 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1443 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1445 struct quota_adjust_qunit *oqaq, *repoqa;
1446 struct lustre_quota_ctxt *qctxt;
1450 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1451 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1453 GOTO(out, rc = -EPROTO);
1455 rc = req_capsule_server_pack(&req->rq_pill);
1459 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1460 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt);
1468 static int ost_llog_handle_connect(struct obd_export *exp,
1469 struct ptlrpc_request *req)
1471 struct llogd_conn_body *body;
1475 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
1476 rc = obd_llog_connect(exp, body);
1480 #define ost_init_sec_none(reply, exp) \
1482 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1483 OBD_CONNECT_RMT_CLIENT_FORCE | \
1484 OBD_CONNECT_OSS_CAPA); \
1485 cfs_spin_lock(&exp->exp_lock); \
1486 exp->exp_connect_flags = reply->ocd_connect_flags; \
1487 cfs_spin_unlock(&exp->exp_lock); \
1490 static int ost_init_sec_level(struct ptlrpc_request *req)
1492 struct obd_export *exp = req->rq_export;
1493 struct req_capsule *pill = &req->rq_pill;
1494 struct obd_device *obd = exp->exp_obd;
1495 struct filter_obd *filter = &obd->u.filter;
1496 char *client = libcfs_nid2str(req->rq_peer.nid);
1497 struct obd_connect_data *data, *reply;
1501 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1502 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1503 if (data == NULL || reply == NULL)
1506 /* connection from MDT is always trusted */
1507 if (req->rq_auth_usr_mdt) {
1508 ost_init_sec_none(reply, exp);
1512 /* no GSS support case */
1513 if (!req->rq_auth_gss) {
1514 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1515 CWARN("client %s -> target %s does not user GSS, "
1516 "can not run under security level %d.\n",
1517 client, obd->obd_name, filter->fo_sec_level);
1520 ost_init_sec_none(reply, exp);
1525 /* old version case */
1526 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1527 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1528 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1529 CWARN("client %s -> target %s uses old version, "
1530 "can not run under security level %d.\n",
1531 client, obd->obd_name, filter->fo_sec_level);
1534 CWARN("client %s -> target %s uses old version, "
1535 "run under security level %d.\n",
1536 client, obd->obd_name, filter->fo_sec_level);
1537 ost_init_sec_none(reply, exp);
1542 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1544 if (!req->rq_auth_remote)
1545 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1546 "asked to be remote.\n", client, obd->obd_name);
1547 } else if (req->rq_auth_remote) {
1549 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1550 "as remote by default.\n", client, obd->obd_name);
1554 if (!filter->fo_fl_oss_capa) {
1555 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1556 " but OSS capabilities are not enabled: %d.\n",
1557 client, obd->obd_name, filter->fo_fl_oss_capa);
1562 switch (filter->fo_sec_level) {
1563 case LUSTRE_SEC_NONE:
1565 ost_init_sec_none(reply, exp);
1568 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1569 "can not run under security level %d.\n",
1570 client, obd->obd_name, filter->fo_sec_level);
1573 case LUSTRE_SEC_REMOTE:
1575 ost_init_sec_none(reply, exp);
1577 case LUSTRE_SEC_ALL:
1579 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1580 OBD_CONNECT_RMT_CLIENT_FORCE);
1581 if (!filter->fo_fl_oss_capa)
1582 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1584 cfs_spin_lock(&exp->exp_lock);
1585 exp->exp_connect_flags = reply->ocd_connect_flags;
1586 cfs_spin_unlock(&exp->exp_lock);
1598 * this should be done in filter_connect()/filter_reconnect(), but
1599 * we can't obtain information like NID, which stored in incoming
1600 * request, thus can't decide what flavor to use. so we do it here.
1602 * This hack should be removed after the OST stack be rewritten, just
1603 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1605 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1607 struct obd_export *exp = req->rq_export;
1608 struct filter_obd *filter = &exp->exp_obd->u.filter;
1609 struct sptlrpc_flavor flvr;
1612 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1613 LUSTRE_ECHO_NAME) == 0)) {
1614 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1618 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1619 cfs_read_lock(&filter->fo_sptlrpc_lock);
1620 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1624 cfs_read_unlock(&filter->fo_sptlrpc_lock);
1626 cfs_spin_lock(&exp->exp_lock);
1628 exp->exp_sp_peer = req->rq_sp_from;
1629 exp->exp_flvr = flvr;
1631 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1632 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1633 CERROR("unauthorized rpc flavor %x from %s, "
1634 "expect %x\n", req->rq_flvr.sf_rpc,
1635 libcfs_nid2str(req->rq_peer.nid),
1636 exp->exp_flvr.sf_rpc);
1640 cfs_spin_unlock(&exp->exp_lock);
1642 if (exp->exp_sp_peer != req->rq_sp_from) {
1643 CERROR("RPC source %s doesn't match %s\n",
1644 sptlrpc_part2name(req->rq_sp_from),
1645 sptlrpc_part2name(exp->exp_sp_peer));
1648 rc = sptlrpc_target_export_check(exp, req);
1655 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1656 struct obd_device *obd, int *process)
1658 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1659 case OST_CONNECT: /* This will never get here, but for completeness. */
1660 case OST_DISCONNECT:
1671 case OBD_LOG_CANCEL:
1673 *process = target_queue_recovery_request(req, obd);
1677 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1683 int ost_msg_check_version(struct lustre_msg *msg)
1687 switch(lustre_msg_get_opc(msg)) {
1689 case OST_DISCONNECT:
1692 case SEC_CTX_INIT_CONT:
1694 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1696 CERROR("bad opc %u version %08x, expecting %08x\n",
1697 lustre_msg_get_opc(msg),
1698 lustre_msg_get_version(msg),
1699 LUSTRE_OBD_VERSION);
1712 #ifdef HAVE_QUOTA_SUPPORT
1713 case OST_QUOTACHECK:
1715 case OST_QUOTA_ADJUST_QUNIT:
1717 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1719 CERROR("bad opc %u version %08x, expecting %08x\n",
1720 lustre_msg_get_opc(msg),
1721 lustre_msg_get_version(msg),
1722 LUSTRE_OST_VERSION);
1727 case LDLM_BL_CALLBACK:
1728 case LDLM_CP_CALLBACK:
1729 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1731 CERROR("bad opc %u version %08x, expecting %08x\n",
1732 lustre_msg_get_opc(msg),
1733 lustre_msg_get_version(msg),
1734 LUSTRE_DLM_VERSION);
1736 case LLOG_ORIGIN_CONNECT:
1737 case OBD_LOG_CANCEL:
1738 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1740 CERROR("bad opc %u version %08x, expecting %08x\n",
1741 lustre_msg_get_opc(msg),
1742 lustre_msg_get_version(msg),
1743 LUSTRE_LOG_VERSION);
1746 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1753 * Returns 1 if the given PTLRPC matches the given LDLM locks, or 0 if it does
1756 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1757 struct ldlm_lock *lock)
1759 struct niobuf_remote *nb;
1760 struct obd_ioobj *ioo;
1761 struct ost_body *body;
1762 int objcount, niocount;
1767 opc = lustre_msg_get_opc(req->rq_reqmsg);
1768 LASSERT(opc == OST_READ || opc == OST_WRITE);
1770 /* As the request may be covered by several locks, do not look at
1771 * o_handle, look at the RPC IO region. */
1772 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1776 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1777 RCL_CLIENT) / sizeof(*ioo);
1778 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1782 for (niocount = i = 0; i < objcount; i++)
1783 niocount += ioo[i].ioo_bufcnt;
1785 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1787 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
1788 RCL_CLIENT) / sizeof(*nb)))
1792 if (opc == OST_READ)
1795 start = nb[0].offset & CFS_PAGE_MASK;
1796 end = (nb[ioo->ioo_bufcnt - 1].offset +
1797 nb[ioo->ioo_bufcnt - 1].len - 1) | ~CFS_PAGE_MASK;
1799 LASSERT(lock->l_resource != NULL);
1800 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_gr,
1801 &lock->l_resource->lr_name))
1804 if (!(lock->l_granted_mode & mode))
1807 if (lock->l_policy_data.l_extent.end < start ||
1808 lock->l_policy_data.l_extent.start > end)
1815 * High-priority queue request check for whether the given PTLRPC request (\a
1816 * req) is blocking an LDLM lock cancel.
1818 * Returns 1 if the given given PTLRPC request (\a req) is blocking an LDLM lock
1819 * cancel, 0 if it is not, and -EFAULT if the request is malformed.
1821 * Only OST_READs, OST_WRITEs and OST_PUNCHes go on the h-p RPC queue. This
1822 * function looks only at OST_READs and OST_WRITEs.
1824 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1826 struct niobuf_remote *nb;
1827 struct obd_ioobj *ioo;
1828 struct ost_body *body;
1829 int objcount, niocount;
1833 opc = lustre_msg_get_opc(req->rq_reqmsg);
1834 LASSERT(opc == OST_READ || opc == OST_WRITE);
1836 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1840 objcount = req_capsule_get_size(&req->rq_pill, &RMF_OBD_IOOBJ,
1841 RCL_CLIENT) / sizeof(*ioo);
1842 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
1846 for (niocount = i = 0; i < objcount; i++)
1847 niocount += ioo[i].ioo_bufcnt;
1848 nb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
1850 niocount != (req_capsule_get_size(&req->rq_pill, &RMF_NIOBUF_REMOTE,
1851 RCL_CLIENT) / sizeof(*nb)))
1853 if (niocount != 0 && (nb[0].flags & OBD_BRW_SRVLOCK))
1857 if (opc == OST_READ)
1859 RETURN(ost_rw_prolong_locks(req, ioo, nb, &body->oa, mode));
1862 static int ost_punch_prolong_locks(struct ptlrpc_request *req, struct obdo *oa)
1864 struct ldlm_res_id res_id = { .name = { oa->o_id } };
1865 struct ost_prolong_data opd = { 0 };
1870 end = start + oa->o_blocks;
1872 opd.opd_mode = LCK_PW;
1873 opd.opd_exp = req->rq_export;
1874 opd.opd_policy.l_extent.start = start & CFS_PAGE_MASK;
1875 if (oa->o_blocks == OBD_OBJECT_EOF || end < start)
1876 opd.opd_policy.l_extent.end = OBD_OBJECT_EOF;
1878 opd.opd_policy.l_extent.end = end | ~CFS_PAGE_MASK;
1880 /* prolong locks for the current service time of the corresponding
1881 * portal (= OST_IO_PORTAL) */
1882 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
1883 max(at_est2timeout(at_get(&req->rq_rqbd->
1884 rqbd_service->srv_at_estimate)), ldlm_timeout);
1886 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1887 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
1888 opd.opd_policy.l_extent.end);
1891 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
1892 ost_prolong_locks_iter, &opd);
1893 RETURN(opd.opd_lock_match);
1897 * Like ost_rw_hpreq_lock_match(), but for OST_PUNCH RPCs.
1899 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1900 struct ldlm_lock *lock)
1902 struct ost_body *body;
1905 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1907 RETURN(0); /* can't return -EFAULT here */
1909 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1910 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1916 * Like ost_rw_hpreq_check(), but for OST_PUNCH RPCs.
1918 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1920 struct ost_body *body;
1922 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
1926 LASSERT(!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1927 !(body->oa.o_flags & OBD_FL_SRVLOCK));
1929 RETURN(ost_punch_prolong_locks(req, &body->oa));
1932 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
1933 .hpreq_lock_match = ost_rw_hpreq_lock_match,
1934 .hpreq_check = ost_rw_hpreq_check,
1937 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
1938 .hpreq_lock_match = ost_punch_hpreq_lock_match,
1939 .hpreq_check = ost_punch_hpreq_check,
1942 /** Assign high priority operations to the request if needed. */
1943 static int ost_hpreq_handler(struct ptlrpc_request *req)
1946 if (req->rq_export) {
1947 int opc = lustre_msg_get_opc(req->rq_reqmsg);
1948 struct ost_body *body;
1950 if (opc == OST_READ || opc == OST_WRITE) {
1951 struct niobuf_remote *nb;
1952 struct obd_ioobj *ioo;
1953 int objcount, niocount;
1956 /* RPCs on the H-P queue can be inspected before
1957 * ost_handler() initializes their pills, so we
1958 * initialize that here. Capsule initialization is
1959 * idempotent, as is setting the pill's format (provided
1960 * it doesn't change).
1962 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1963 if (opc == OST_READ)
1964 req_capsule_set(&req->rq_pill,
1967 req_capsule_set(&req->rq_pill,
1968 &RQF_OST_BRW_WRITE);
1970 body = req_capsule_client_get(&req->rq_pill,
1973 CERROR("Missing/short ost_body\n");
1976 objcount = req_capsule_get_size(&req->rq_pill,
1980 if (objcount == 0) {
1981 CERROR("Missing/short ioobj\n");
1985 CERROR("too many ioobjs (%d)\n", objcount);
1989 ioo = req_capsule_client_get(&req->rq_pill,
1992 CERROR("Missing/short ioobj\n");
1996 for (niocount = i = 0; i < objcount; i++) {
1997 if (ioo[i].ioo_bufcnt == 0) {
1998 CERROR("ioo[%d] has zero bufcnt\n", i);
2001 niocount += ioo[i].ioo_bufcnt;
2003 if (niocount > PTLRPC_MAX_BRW_PAGES) {
2004 DEBUG_REQ(D_RPCTRACE, req,
2005 "bulk has too many pages (%d)",
2010 nb = req_capsule_client_get(&req->rq_pill,
2011 &RMF_NIOBUF_REMOTE);
2013 CERROR("Missing/short niobuf\n");
2017 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
2018 req->rq_ops = &ost_hpreq_rw;
2019 } else if (opc == OST_PUNCH) {
2020 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2021 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2023 body = req_capsule_client_get(&req->rq_pill,
2026 CERROR("Missing/short ost_body\n");
2030 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
2031 !(body->oa.o_flags & OBD_FL_SRVLOCK))
2032 req->rq_ops = &ost_hpreq_punch;
2038 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
2039 int ost_handle(struct ptlrpc_request *req)
2041 struct obd_trans_info trans_info = { 0, };
2042 struct obd_trans_info *oti = &trans_info;
2043 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
2044 struct obd_device *obd = NULL;
2047 LASSERT(current->journal_info == NULL);
2049 /* primordial rpcs don't affect server recovery */
2050 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2052 case SEC_CTX_INIT_CONT:
2057 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2059 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
2060 if (!class_connected_export(req->rq_export)) {
2061 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
2062 lustre_msg_get_opc(req->rq_reqmsg),
2063 libcfs_id2str(req->rq_peer));
2064 req->rq_status = -ENOTCONN;
2065 GOTO(out, rc = -ENOTCONN);
2068 obd = req->rq_export->exp_obd;
2070 /* Check for aborted recovery. */
2071 if (obd->obd_recovering) {
2072 rc = ost_filter_recovery_request(req, obd,
2074 if (rc || !should_process)
2076 else if (should_process < 0) {
2077 req->rq_status = should_process;
2078 rc = ptlrpc_error(req);
2086 rc = ost_msg_check_version(req->rq_reqmsg);
2090 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2092 CDEBUG(D_INODE, "connect\n");
2093 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
2094 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
2096 rc = target_handle_connect(req);
2097 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
2100 rc = ost_init_sec_level(req);
2102 rc = ost_connect_check_sptlrpc(req);
2106 case OST_DISCONNECT:
2107 CDEBUG(D_INODE, "disconnect\n");
2108 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
2109 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
2111 rc = target_handle_disconnect(req);
2114 CDEBUG(D_INODE, "create\n");
2115 req_capsule_set(&req->rq_pill, &RQF_OST_CREATE);
2116 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
2118 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2119 GOTO(out, rc = -EROFS);
2120 rc = ost_create(req->rq_export, req, oti);
2123 CDEBUG(D_INODE, "destroy\n");
2124 req_capsule_set(&req->rq_pill, &RQF_OST_DESTROY);
2125 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
2127 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2128 GOTO(out, rc = -EROFS);
2129 rc = ost_destroy(req->rq_export, req, oti);
2132 CDEBUG(D_INODE, "getattr\n");
2133 req_capsule_set(&req->rq_pill, &RQF_OST_GETATTR);
2134 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
2136 rc = ost_getattr(req->rq_export, req);
2139 CDEBUG(D_INODE, "setattr\n");
2140 req_capsule_set(&req->rq_pill, &RQF_OST_SETATTR);
2141 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
2143 rc = ost_setattr(req->rq_export, req, oti);
2146 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_WRITE);
2147 CDEBUG(D_INODE, "write\n");
2148 /* req->rq_request_portal would be nice, if it was set */
2149 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2150 CERROR("%s: deny write request from %s to portal %u\n",
2151 req->rq_export->exp_obd->obd_name,
2152 obd_export_nid2str(req->rq_export),
2153 req->rq_rqbd->rqbd_service->srv_req_portal);
2154 GOTO(out, rc = -EPROTO);
2156 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2158 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
2159 GOTO(out, rc = -ENOSPC);
2160 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2161 GOTO(out, rc = -EROFS);
2162 rc = ost_brw_write(req, oti);
2163 LASSERT(current->journal_info == NULL);
2164 /* ost_brw_write sends its own replies */
2167 req_capsule_set(&req->rq_pill, &RQF_OST_BRW_READ);
2168 CDEBUG(D_INODE, "read\n");
2169 /* req->rq_request_portal would be nice, if it was set */
2170 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2171 CERROR("%s: deny read request from %s to portal %u\n",
2172 req->rq_export->exp_obd->obd_name,
2173 obd_export_nid2str(req->rq_export),
2174 req->rq_rqbd->rqbd_service->srv_req_portal);
2175 GOTO(out, rc = -EPROTO);
2177 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2179 rc = ost_brw_read(req, oti);
2180 LASSERT(current->journal_info == NULL);
2181 /* ost_brw_read sends its own replies */
2184 CDEBUG(D_INODE, "punch\n");
2185 req_capsule_set(&req->rq_pill, &RQF_OST_PUNCH);
2186 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2188 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2189 GOTO(out, rc = -EROFS);
2190 rc = ost_punch(req->rq_export, req, oti);
2193 CDEBUG(D_INODE, "statfs\n");
2194 req_capsule_set(&req->rq_pill, &RQF_OST_STATFS);
2195 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2197 rc = ost_statfs(req);
2200 CDEBUG(D_INODE, "sync\n");
2201 req_capsule_set(&req->rq_pill, &RQF_OST_SYNC);
2202 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2204 rc = ost_sync(req->rq_export, req);
2207 DEBUG_REQ(D_INODE, req, "set_info");
2208 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
2209 rc = ost_set_info(req->rq_export, req);
2212 DEBUG_REQ(D_INODE, req, "get_info");
2213 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
2214 rc = ost_get_info(req->rq_export, req);
2216 #ifdef HAVE_QUOTA_SUPPORT
2217 case OST_QUOTACHECK:
2218 CDEBUG(D_INODE, "quotacheck\n");
2219 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2220 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2222 rc = ost_handle_quotacheck(req);
2225 CDEBUG(D_INODE, "quotactl\n");
2226 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2227 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2229 rc = ost_handle_quotactl(req);
2231 case OST_QUOTA_ADJUST_QUNIT:
2232 CDEBUG(D_INODE, "quota_adjust_qunit\n");
2233 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
2234 rc = ost_handle_quota_adjust_qunit(req);
2238 DEBUG_REQ(D_INODE, req, "ping");
2239 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2240 rc = target_handle_ping(req);
2242 /* FIXME - just reply status */
2243 case LLOG_ORIGIN_CONNECT:
2244 DEBUG_REQ(D_INODE, req, "log connect");
2245 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2246 rc = ost_llog_handle_connect(req->rq_export, req);
2247 req->rq_status = rc;
2248 rc = req_capsule_server_pack(&req->rq_pill);
2251 RETURN(ptlrpc_reply(req));
2252 case OBD_LOG_CANCEL:
2253 CDEBUG(D_INODE, "log cancel\n");
2254 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2255 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2257 rc = llog_origin_handle_cancel(req);
2258 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2260 req->rq_status = rc;
2261 rc = req_capsule_server_pack(&req->rq_pill);
2264 RETURN(ptlrpc_reply(req));
2266 CDEBUG(D_INODE, "enqueue\n");
2267 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2268 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2270 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2271 ldlm_server_blocking_ast,
2272 ldlm_server_glimpse_ast);
2273 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2276 CDEBUG(D_INODE, "convert\n");
2277 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2278 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2280 rc = ldlm_handle_convert(req);
2283 CDEBUG(D_INODE, "cancel\n");
2284 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2285 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2287 rc = ldlm_handle_cancel(req);
2289 case LDLM_BL_CALLBACK:
2290 case LDLM_CP_CALLBACK:
2291 CDEBUG(D_INODE, "callback\n");
2292 CERROR("callbacks should not happen on OST\n");
2295 CERROR("Unexpected opcode %d\n",
2296 lustre_msg_get_opc(req->rq_reqmsg));
2297 req->rq_status = -ENOTSUPP;
2298 rc = ptlrpc_error(req);
2302 LASSERT(current->journal_info == NULL);
2305 /* If we're DISCONNECTing, the export_data is already freed */
2306 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2307 target_committed_to_req(req);
2311 oti_to_request(oti, req);
2313 target_send_reply(req, rc, fail);
2316 EXPORT_SYMBOL(ost_handle);
2318 * free per-thread pool created by ost_thread_init().
2320 static void ost_thread_done(struct ptlrpc_thread *thread)
2322 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2327 LASSERT(thread != NULL);
2330 * be prepared to handle partially-initialized pools (because this is
2331 * called from ost_thread_init() for cleanup.
2333 tls = thread->t_data;
2336 thread->t_data = NULL;
2342 * initialize per-thread page pool (bug 5137).
2344 static int ost_thread_init(struct ptlrpc_thread *thread)
2346 struct ost_thread_local_cache *tls;
2350 LASSERT(thread != NULL);
2351 LASSERT(thread->t_data == NULL);
2352 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
2357 thread->t_data = tls;
2361 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2363 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2364 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2366 struct ost_obd *ost = &obd->u.ost;
2367 struct lprocfs_static_vars lvars;
2368 int oss_min_threads;
2369 int oss_max_threads;
2370 int oss_min_create_threads;
2371 int oss_max_create_threads;
2375 rc = cfs_cleanup_group_info();
2379 lprocfs_ost_init_vars(&lvars);
2380 lprocfs_obd_setup(obd, lvars.obd_vars);
2382 cfs_sema_init(&ost->ost_health_sem, 1);
2384 if (oss_num_threads) {
2385 /* If oss_num_threads is set, it is the min and the max. */
2386 if (oss_num_threads > OSS_THREADS_MAX)
2387 oss_num_threads = OSS_THREADS_MAX;
2388 if (oss_num_threads < OSS_THREADS_MIN)
2389 oss_num_threads = OSS_THREADS_MIN;
2390 oss_max_threads = oss_min_threads = oss_num_threads;
2392 /* Base min threads on memory and cpus */
2394 cfs_num_possible_cpus() * CFS_NUM_CACHEPAGES >>
2395 (27 - CFS_PAGE_SHIFT);
2396 if (oss_min_threads < OSS_THREADS_MIN)
2397 oss_min_threads = OSS_THREADS_MIN;
2398 /* Insure a 4x range for dynamic threads */
2399 if (oss_min_threads > OSS_THREADS_MAX / 4)
2400 oss_min_threads = OSS_THREADS_MAX / 4;
2401 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
2405 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2406 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
2407 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2408 ost_handle, LUSTRE_OSS_NAME,
2409 obd->obd_proc_entry, target_print_req,
2410 oss_min_threads, oss_max_threads,
2411 "ll_ost", LCT_DT_THREAD, NULL);
2412 if (ost->ost_service == NULL) {
2413 CERROR("failed to start service\n");
2414 GOTO(out_lprocfs, rc = -ENOMEM);
2417 rc = ptlrpc_start_threads(obd, ost->ost_service);
2419 GOTO(out_service, rc = -EINVAL);
2421 if (oss_num_create_threads) {
2422 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
2423 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
2424 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
2425 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
2426 oss_min_create_threads = oss_max_create_threads =
2427 oss_num_create_threads;
2429 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
2430 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
2433 ost->ost_create_service =
2434 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2435 OST_MAXREPSIZE, OST_CREATE_PORTAL,
2436 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2437 ost_handle, "ost_create",
2438 obd->obd_proc_entry, target_print_req,
2439 oss_min_create_threads, oss_max_create_threads,
2440 "ll_ost_creat", LCT_DT_THREAD, NULL);
2441 if (ost->ost_create_service == NULL) {
2442 CERROR("failed to start OST create service\n");
2443 GOTO(out_service, rc = -ENOMEM);
2446 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
2448 GOTO(out_create, rc = -EINVAL);
2450 ost->ost_io_service =
2451 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2452 OST_MAXREPSIZE, OST_IO_PORTAL,
2453 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2454 ost_handle, "ost_io",
2455 obd->obd_proc_entry, target_print_req,
2456 oss_min_threads, oss_max_threads,
2457 "ll_ost_io", LCT_DT_THREAD, ost_hpreq_handler);
2458 if (ost->ost_io_service == NULL) {
2459 CERROR("failed to start OST I/O service\n");
2460 GOTO(out_create, rc = -ENOMEM);
2463 ost->ost_io_service->srv_init = ost_thread_init;
2464 ost->ost_io_service->srv_done = ost_thread_done;
2465 ost->ost_io_service->srv_cpu_affinity = 1;
2466 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
2468 GOTO(out_io, rc = -EINVAL);
2470 ping_evictor_start();
2475 ptlrpc_unregister_service(ost->ost_io_service);
2476 ost->ost_io_service = NULL;
2478 ptlrpc_unregister_service(ost->ost_create_service);
2479 ost->ost_create_service = NULL;
2481 ptlrpc_unregister_service(ost->ost_service);
2482 ost->ost_service = NULL;
2484 lprocfs_obd_cleanup(obd);
2488 static int ost_cleanup(struct obd_device *obd)
2490 struct ost_obd *ost = &obd->u.ost;
2494 ping_evictor_stop();
2496 cfs_spin_lock_bh(&obd->obd_processing_task_lock);
2497 if (obd->obd_recovering) {
2498 target_cancel_recovery_timer(obd);
2499 obd->obd_recovering = 0;
2501 cfs_spin_unlock_bh(&obd->obd_processing_task_lock);
2503 cfs_down(&ost->ost_health_sem);
2504 ptlrpc_unregister_service(ost->ost_service);
2505 ptlrpc_unregister_service(ost->ost_create_service);
2506 ptlrpc_unregister_service(ost->ost_io_service);
2507 ost->ost_service = NULL;
2508 ost->ost_create_service = NULL;
2509 cfs_up(&ost->ost_health_sem);
2511 lprocfs_obd_cleanup(obd);
2516 static int ost_health_check(struct obd_device *obd)
2518 struct ost_obd *ost = &obd->u.ost;
2521 cfs_down(&ost->ost_health_sem);
2522 rc |= ptlrpc_service_health_check(ost->ost_service);
2523 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2524 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2525 cfs_up(&ost->ost_health_sem);
2528 * health_check to return 0 on healthy
2529 * and 1 on unhealthy.
2537 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2539 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2542 /* use obd ops to offer management infrastructure */
2543 static struct obd_ops ost_obd_ops = {
2544 .o_owner = THIS_MODULE,
2545 .o_setup = ost_setup,
2546 .o_cleanup = ost_cleanup,
2547 .o_health_check = ost_health_check,
2551 static int __init ost_init(void)
2553 struct lprocfs_static_vars lvars;
2557 lprocfs_ost_init_vars(&lvars);
2558 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2559 LUSTRE_OSS_NAME, NULL);
2561 if (ost_num_threads != 0 && oss_num_threads == 0) {
2562 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2563 "use oss_num_threads instead or unset both for "
2564 "dynamic thread startup\n");
2565 oss_num_threads = ost_num_threads;
2571 static void /*__exit*/ ost_exit(void)
2573 class_unregister_type(LUSTRE_OSS_NAME);
2576 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2577 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2578 MODULE_LICENSE("GPL");
2580 module_init(ost_init);
2581 module_exit(ost_exit);