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 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
110 struct lustre_capa *capa = NULL;
114 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
115 lustre_swab_ost_body);
119 if (body->oa.o_id == 0)
122 if (lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1)) {
123 struct ldlm_request *dlm;
124 dlm = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*dlm),
125 lustre_swab_ldlm_request);
128 ldlm_request_cancel(req, dlm, 0);
131 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
132 capa = lustre_unpack_incoming_capa(req, REQ_REC_OFF + 2);
134 rc = lustre_pack_reply(req, 2, size, NULL);
138 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
139 oti->oti_logcookies = &body->oa.o_lcookie;
140 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
142 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
143 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL, capa);
147 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
149 struct ost_body *body, *repbody;
150 struct obd_info oinfo = { { { 0 } } };
151 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
155 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
156 lustre_swab_ost_body);
160 rc = lustre_pack_reply(req, 2, size, NULL);
164 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
166 repbody->oa = body->oa;
168 oinfo.oi_oa = &repbody->oa;
169 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
170 oinfo.oi_capa = lustre_unpack_incoming_capa(req,
172 req->rq_status = obd_getattr(exp, &oinfo);
173 ost_drop_id(exp, &repbody->oa);
177 static int ost_statfs(struct ptlrpc_request *req)
179 struct obd_statfs *osfs;
180 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*osfs) };
184 rc = lustre_pack_reply(req, 2, size, NULL);
188 osfs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*osfs));
190 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
191 cfs_time_current_64() - HZ, 0);
192 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
193 osfs->os_bfree = osfs->os_bavail = 64;
194 if (req->rq_status != 0)
195 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
200 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
201 struct obd_trans_info *oti)
203 struct ost_body *body, *repbody;
204 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
208 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
209 lustre_swab_ost_body);
213 rc = lustre_pack_reply(req, 2, size, NULL);
217 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
219 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
220 oti->oti_logcookies = &repbody->oa.o_lcookie;
222 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
223 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
228 * Helper function for ost_punch(): if asked by client, acquire [size, EOF]
229 * lock on the file being truncated.
231 static int ost_punch_lock_get(struct obd_export *exp, struct obdo *oa,
232 struct lustre_handle *lh)
235 struct ldlm_res_id res_id;
236 ldlm_policy_data_t policy;
242 osc_build_res_name(oa->o_id, oa->o_gr, &res_id);
243 LASSERT(!lustre_handle_is_used(lh));
245 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
246 !(oa->o_flags & OBD_FL_TRUNCLOCK))
249 CDEBUG(D_INODE, "OST-side truncate lock.\n");
252 finis = start + oa->o_blocks;
255 * standard truncate optimization: if file body is completely
256 * destroyed, don't send data back to the server.
258 flags = (start == 0) ? LDLM_AST_DISCARD_DATA : 0;
260 policy.l_extent.start = start & CFS_PAGE_MASK;
263 * If ->o_blocks is EOF it means "lock till the end of the
264 * file". Otherwise, it's size of a hole being punched (in bytes)
266 if (oa->o_blocks == OBD_OBJECT_EOF || finis < start)
267 policy.l_extent.end = OBD_OBJECT_EOF;
269 policy.l_extent.end = finis | ~CFS_PAGE_MASK;
271 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
272 LDLM_EXTENT, &policy, LCK_PW, &flags,
273 ldlm_blocking_ast, ldlm_completion_ast,
274 ldlm_glimpse_ast, NULL, 0, NULL,
279 * Helper function for ost_punch(): release lock acquired by
280 * ost_punch_lock_get(), if any.
282 static void ost_punch_lock_put(struct obd_export *exp, struct obdo *oa,
283 struct lustre_handle *lh)
286 if (lustre_handle_is_used(lh))
287 ldlm_lock_decref(lh, LCK_PW);
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;
296 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
298 struct lustre_handle lh = {0,};
301 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
302 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
304 /* ost_body is varified and swabbed in ost_hpreq_handler() */
305 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
306 LASSERT(body != NULL);
308 oinfo.oi_oa = &body->oa;
309 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
310 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
312 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
313 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
316 rc = lustre_pack_reply(req, 2, size, NULL);
320 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
322 rc = ost_punch_lock_get(exp, oinfo.oi_oa, &lh);
324 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
325 oinfo.oi_oa->o_flags == OBD_FL_TRUNCLOCK)
327 * If OBD_FL_TRUNCLOCK is the only bit set in
328 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
329 * through filter_setattr() to filter_iocontrol().
331 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
333 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
334 oinfo.oi_capa = lustre_unpack_incoming_capa(req,
336 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
337 ost_punch_lock_put(exp, oinfo.oi_oa, &lh);
339 repbody->oa = *oinfo.oi_oa;
340 ost_drop_id(exp, &repbody->oa);
344 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
346 struct ost_body *body, *repbody;
347 struct lustre_capa *capa = NULL;
348 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
352 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
353 lustre_swab_ost_body);
357 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
358 capa = lustre_unpack_incoming_capa(req, REQ_REC_OFF + 1);
360 rc = lustre_pack_reply(req, 2, size, NULL);
364 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
366 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
367 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
368 repbody->oa.o_blocks, capa);
369 ost_drop_id(exp, &repbody->oa);
373 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
374 struct obd_trans_info *oti)
376 struct ost_body *body, *repbody;
377 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
379 struct obd_info oinfo = { { { 0 } } };
382 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
383 lustre_swab_ost_body);
387 rc = lustre_pack_reply(req, 2, size, NULL);
391 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
393 repbody->oa = body->oa;
395 oinfo.oi_oa = &repbody->oa;
396 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
397 oinfo.oi_capa = lustre_unpack_incoming_capa(req,
399 req->rq_status = obd_setattr(exp, &oinfo, oti);
400 ost_drop_id(exp, &repbody->oa);
404 static int ost_bulk_timeout(void *data)
407 /* We don't fail the connection here, because having the export
408 * killed makes the (vital) call to commitrw very sad.
413 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
414 cksum_type_t cksum_type)
419 cksum = init_checksum(cksum_type);
420 for (i = 0; i < desc->bd_iov_count; i++) {
421 struct page *page = desc->bd_iov[i].kiov_page;
422 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
423 char *ptr = kmap(page) + off;
424 int len = desc->bd_iov[i].kiov_len;
426 /* corrupt the data before we compute the checksum, to
427 * simulate a client->OST data error */
428 if (i == 0 && opc == OST_WRITE &&
429 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
430 memcpy(ptr, "bad3", min(4, len));
431 cksum = compute_checksum(cksum, ptr, len, cksum_type);
432 /* corrupt the data after we compute the checksum, to
433 * simulate an OST->client data error */
434 if (i == 0 && opc == OST_READ &&
435 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
436 memcpy(ptr, "bad4", min(4, len));
437 /* nobody should use corrupted page again */
438 ClearPageUptodate(page);
446 static int ost_brw_lock_get(int mode, struct obd_export *exp,
447 struct obd_ioobj *obj, struct niobuf_remote *nb,
448 struct lustre_handle *lh)
451 int nrbufs = obj->ioo_bufcnt;
452 struct ldlm_res_id res_id;
453 ldlm_policy_data_t policy;
457 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
458 LASSERT(mode == LCK_PR || mode == LCK_PW);
459 LASSERT(!lustre_handle_is_used(lh));
461 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
464 /* EXPENSIVE ASSERTION */
465 for (i = 1; i < nrbufs; i ++)
466 LASSERT((nb[0].flags & OBD_BRW_SRVLOCK) ==
467 (nb[i].flags & OBD_BRW_SRVLOCK));
469 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
470 policy.l_extent.end = (nb[nrbufs - 1].offset +
471 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
473 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
474 LDLM_EXTENT, &policy, mode, &flags,
475 ldlm_blocking_ast, ldlm_completion_ast,
476 ldlm_glimpse_ast, NULL, 0, NULL,
480 static void ost_brw_lock_put(int mode,
481 struct obd_ioobj *obj, struct niobuf_remote *niob,
482 struct lustre_handle *lh)
485 LASSERT(mode == LCK_PR || mode == LCK_PW);
486 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
487 lustre_handle_is_used(lh));
488 if (lustre_handle_is_used(lh))
489 ldlm_lock_decref(lh, mode);
493 struct ost_prolong_data {
494 struct obd_export *opd_exp;
495 ldlm_policy_data_t opd_policy;
497 ldlm_mode_t opd_mode;
502 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
504 struct ost_prolong_data *opd = data;
506 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
508 if (lock->l_req_mode != lock->l_granted_mode) {
509 /* scan granted locks only */
510 return LDLM_ITER_STOP;
513 if (lock->l_export != opd->opd_exp) {
514 /* prolong locks only for given client */
515 return LDLM_ITER_CONTINUE;
518 if (!(lock->l_granted_mode & opd->opd_mode)) {
519 /* we aren't interesting in all type of locks */
520 return LDLM_ITER_CONTINUE;
523 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
524 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
525 /* the request doesn't cross the lock, skip it */
526 return LDLM_ITER_CONTINUE;
529 /* Fill the obdo with the matched lock handle.
530 * XXX: it is possible in some cases the IO RPC is covered by several
531 * locks, even for the write case, so it may need to be a lock list. */
532 if (opd->opd_oa && !(opd->opd_oa->o_valid & OBD_MD_FLHANDLE)) {
533 opd->opd_oa->o_handle.cookie = lock->l_handle.h_cookie;
534 opd->opd_oa->o_valid |= OBD_MD_FLHANDLE;
537 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
538 /* ignore locks not being cancelled */
539 return LDLM_ITER_CONTINUE;
542 CDEBUG(D_DLMTRACE,"refresh lock: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
543 lock->l_resource->lr_name.name[0],
544 lock->l_resource->lr_name.name[1],
545 opd->opd_policy.l_extent.start, opd->opd_policy.l_extent.end);
546 /* OK. this is a possible lock the user holds doing I/O
547 * let's refresh eviction timer for it */
548 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
549 opd->opd_lock_match = 1;
551 return LDLM_ITER_CONTINUE;
554 static int ost_rw_prolong_locks(struct ptlrpc_request *req, struct obd_ioobj *obj,
555 struct niobuf_remote *nb, struct obdo *oa,
558 struct ldlm_res_id res_id;
559 int nrbufs = obj->ioo_bufcnt;
560 struct ost_prolong_data opd = { 0 };
563 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
566 opd.opd_exp = req->rq_export;
567 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
568 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
569 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
571 /* prolong locks for the current service time of the corresponding
572 * portal (= OST_IO_PORTAL) */
573 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
574 max(at_est2timeout(at_get(&req->rq_rqbd->
575 rqbd_service->srv_at_estimate)), ldlm_timeout);
577 CDEBUG(D_INFO,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
578 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
579 opd.opd_policy.l_extent.end);
581 if (oa->o_valid & OBD_MD_FLHANDLE) {
582 struct ldlm_lock *lock;
584 lock = ldlm_handle2lock(&oa->o_handle);
586 ost_prolong_locks_iter(lock, &opd);
587 if (opd.opd_lock_match) {
592 /* Check if the lock covers the whole IO region,
593 * otherwise iterate through the resource. */
594 if (lock->l_policy_data.l_extent.end >=
595 opd.opd_policy.l_extent.end &&
596 lock->l_policy_data.l_extent.start <=
597 opd.opd_policy.l_extent.start) {
606 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
607 ost_prolong_locks_iter, &opd);
608 RETURN(opd.opd_lock_match);
611 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
613 struct ptlrpc_bulk_desc *desc = NULL;
614 struct obd_export *exp = req->rq_export;
615 struct niobuf_remote *remote_nb;
616 struct niobuf_local *local_nb;
617 struct obd_ioobj *ioo;
618 struct ost_body *body, *repbody;
619 struct lustre_capa *capa = NULL;
620 struct l_wait_info lwi;
621 struct lustre_handle lockh = { 0 };
622 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
623 int niocount, npages, nob = 0, rc, i;
627 req->rq_bulk_read = 1;
629 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
630 GOTO(out, rc = -EIO);
632 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
634 /* Check if there is eviction in progress, and if so, wait for it to
636 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
637 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
638 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
639 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
643 GOTO(out, rc = -ENOTCONN);
645 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
646 * ost_rw_hpreq_check(). */
647 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
648 LASSERT(body != NULL);
650 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, sizeof(*ioo));
651 LASSERT(ioo != NULL);
653 niocount = ioo->ioo_bufcnt;
654 remote_nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
655 niocount * sizeof(*remote_nb));
656 LASSERT(remote_nb != NULL);
658 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
659 capa = lustre_unpack_incoming_capa(req, REQ_REC_OFF + 3);
661 rc = lustre_pack_reply(req, 2, size, NULL);
666 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
669 local_nb = ost_tls(req)->local;
671 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
676 * If getting the lock took more time than
677 * client was willing to wait, drop it. b=11330
679 if (cfs_time_current_sec() > req->rq_deadline ||
680 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
682 CERROR("Dropping timed-out read from %s because locking"
683 "object "LPX64" took %ld seconds (limit was %ld).\n",
684 libcfs_id2str(req->rq_peer), ioo->ioo_id,
685 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
686 req->rq_deadline - req->rq_arrival_time.tv_sec);
687 GOTO(out_lock, rc = -ETIMEDOUT);
690 npages = OST_THREAD_POOL_SIZE;
691 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
692 remote_nb, &npages, local_nb, oti, capa);
696 desc = ptlrpc_prep_bulk_exp(req, npages,
697 BULK_PUT_SOURCE, OST_BULK_PORTAL);
699 GOTO(out_lock, rc = -ENOMEM);
701 if (!lustre_handle_is_used(&lockh))
702 /* no needs to try to prolong lock if server is asked
703 * to handle locking (= OBD_BRW_SRVLOCK) */
704 ost_rw_prolong_locks(req, ioo, remote_nb, &body->oa,
708 for (i = 0; i < npages; i++) {
709 int page_rc = local_nb[i].rc;
711 if (page_rc < 0) { /* error */
717 if (page_rc != 0) { /* some data! */
718 LASSERT (local_nb[i].page != NULL);
719 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
720 local_nb[i].offset & ~CFS_PAGE_MASK,
724 if (page_rc != local_nb[i].len) { /* short read */
725 /* All subsequent pages should be 0 */
727 LASSERT(local_nb[i].rc == 0);
732 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
733 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
735 if (body->oa.o_valid & OBD_MD_FLFLAGS)
736 cksum_type = cksum_type_unpack(body->oa.o_flags);
737 body->oa.o_flags = cksum_type_pack(cksum_type);
738 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
739 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
740 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
742 body->oa.o_valid = 0;
744 /* We're finishing using body->oa as an input variable */
746 /* Check if client was evicted while we were doing i/o before touching
749 /* Check if there is eviction in progress, and if so, wait for
751 if (unlikely(atomic_read(&exp->exp_obd->
752 obd_evict_inprogress))) {
753 lwi = LWI_INTR(NULL, NULL);
754 rc = l_wait_event(exp->exp_obd->
755 obd_evict_inprogress_waitq,
756 !atomic_read(&exp->exp_obd->
757 obd_evict_inprogress),
760 /* Check if client was evicted or tried to reconnect already */
761 if (exp->exp_failed || exp->exp_abort_active_req)
764 rc = sptlrpc_svc_wrap_bulk(req, desc);
766 rc = ptlrpc_start_bulk_transfer(desc);
770 time_t start = cfs_time_current_sec();
772 long timeoutl = req->rq_deadline -
773 cfs_time_current_sec();
774 cfs_duration_t timeout = timeoutl <= 0 ?
775 CFS_TICK : cfs_time_seconds(timeoutl);
776 lwi = LWI_TIMEOUT_INTERVAL(timeout,
780 rc = l_wait_event(desc->bd_waitq,
781 !ptlrpc_server_bulk_active(desc) ||
783 exp->exp_abort_active_req,
785 LASSERT(rc == 0 || rc == -ETIMEDOUT);
786 /* Wait again if we changed deadline */
787 } while ((rc == -ETIMEDOUT) &&
788 (req->rq_deadline > cfs_time_current_sec()));
790 if (rc == -ETIMEDOUT) {
791 DEBUG_REQ(D_ERROR, req,
792 "timeout on bulk PUT after %ld%+lds",
793 req->rq_deadline - start,
794 cfs_time_current_sec() -
796 ptlrpc_abort_bulk(desc);
797 } else if (exp->exp_failed) {
798 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
800 ptlrpc_abort_bulk(desc);
801 } else if (exp->exp_abort_active_req) {
802 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk PUT");
803 /* we don't reply anyway */
805 ptlrpc_abort_bulk(desc);
806 } else if (!desc->bd_success ||
807 desc->bd_nob_transferred != desc->bd_nob) {
808 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
810 "truncated" : "network error on",
811 desc->bd_nob_transferred,
813 /* XXX should this be a different errno? */
817 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
822 /* Must commit after prep above in all cases */
823 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
824 remote_nb, npages, local_nb, oti, rc);
827 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
829 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
830 ost_drop_id(exp, &repbody->oa);
834 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
837 ptlrpc_free_bulk(desc);
841 req->rq_status = nob;
842 ptlrpc_lprocfs_brw(req, nob);
843 target_committed_to_req(req);
845 } else if (!no_reply) {
846 /* Only reply if there was no comms problem with bulk */
847 target_committed_to_req(req);
851 /* reply out callback would free */
852 ptlrpc_req_drop_rs(req);
853 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
854 "client will retry\n",
855 exp->exp_obd->obd_name,
856 exp->exp_client_uuid.uuid,
857 exp->exp_connection->c_remote_uuid.uuid,
858 libcfs_id2str(req->rq_peer));
864 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
866 struct ptlrpc_bulk_desc *desc = NULL;
867 struct obd_export *exp = req->rq_export;
868 struct niobuf_remote *remote_nb;
869 struct niobuf_local *local_nb;
870 struct obd_ioobj *ioo;
871 struct ost_body *body, *repbody;
872 struct l_wait_info lwi;
873 struct lustre_handle lockh = {0};
874 struct lustre_capa *capa = NULL;
876 __u32 size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
877 int objcount, niocount, npages;
879 obd_count client_cksum = 0, server_cksum = 0;
880 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
882 __u32 o_uid = 0, o_gid = 0;
885 req->rq_bulk_write = 1;
887 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
888 GOTO(out, rc = -EIO);
889 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
890 GOTO(out, rc = -EFAULT);
892 /* pause before transaction has been started */
893 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
895 /* Check if there is eviction in progress, and if so, wait for it to
897 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
898 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
899 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
900 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
904 GOTO(out, rc = -ENOTCONN);
906 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
907 * ost_rw_hpreq_check(). */
908 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
909 LASSERT(body != NULL);
911 if ((body->oa.o_flags & OBD_BRW_MEMALLOC) &&
912 (exp->exp_connection->c_peer.nid == exp->exp_connection->c_self))
913 libcfs_memory_pressure_set();
915 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
917 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
918 objcount * sizeof(*ioo));
919 LASSERT(ioo != NULL);
920 for (niocount = i = 0; i < objcount; i++)
921 niocount += ioo[i].ioo_bufcnt;
923 remote_nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
924 niocount * sizeof(*remote_nb));
925 LASSERT(remote_nb != NULL);
927 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
928 capa = lustre_unpack_incoming_capa(req, REQ_REC_OFF + 3);
930 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
931 rc = lustre_pack_reply(req, 3, size, NULL);
934 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, obd_fail_val);
935 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
936 niocount * sizeof(*rcs));
939 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
942 local_nb = ost_tls(req)->local;
944 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
949 * If getting the lock took more time than
950 * client was willing to wait, drop it. b=11330
952 if (cfs_time_current_sec() > req->rq_deadline ||
953 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
955 CERROR("Dropping timed-out write from %s because locking "
956 "object "LPX64" took %ld seconds (limit was %ld).\n",
957 libcfs_id2str(req->rq_peer), ioo->ioo_id,
958 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
959 req->rq_deadline - req->rq_arrival_time.tv_sec);
960 GOTO(out_lock, rc = -ETIMEDOUT);
963 if (!lustre_handle_is_used(&lockh))
964 /* no needs to try to prolong lock if server is asked
965 * to handle locking (= OBD_BRW_SRVLOCK) */
966 ost_rw_prolong_locks(req, ioo, remote_nb,&body->oa, LCK_PW);
968 /* obd_preprw clobbers oa->valid, so save what we need */
969 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
970 client_cksum = body->oa.o_cksum;
971 if (body->oa.o_valid & OBD_MD_FLFLAGS)
972 cksum_type = cksum_type_unpack(body->oa.o_flags);
975 /* Because we already sync grant info with client when reconnect,
976 * grant info will be cleared for resent req, then fed_grant and
977 * total_grant will not be modified in following preprw_write */
978 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
979 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
980 body->oa.o_valid &= ~OBD_MD_FLGRANT;
983 if (exp_connect_rmtclient(exp)) {
984 o_uid = body->oa.o_uid;
985 o_gid = body->oa.o_gid;
987 npages = OST_THREAD_POOL_SIZE;
988 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
989 ioo, remote_nb, &npages, local_nb, oti, capa);
993 desc = ptlrpc_prep_bulk_exp(req, npages,
994 BULK_GET_SINK, OST_BULK_PORTAL);
996 GOTO(out_lock, rc = -ENOMEM);
998 /* NB Having prepped, we must commit... */
1000 for (i = 0; i < npages; i++)
1001 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1002 local_nb[i].offset & ~CFS_PAGE_MASK,
1005 rc = sptlrpc_svc_prep_bulk(req, desc);
1009 /* Check if client was evicted or tried to reconnect while we
1010 * were doing i/o before touching network */
1011 if (desc->bd_export->exp_failed ||
1012 desc->bd_export->exp_abort_active_req)
1015 rc = ptlrpc_start_bulk_transfer(desc);
1017 time_t start = cfs_time_current_sec();
1019 long timeoutl = req->rq_deadline -
1020 cfs_time_current_sec();
1021 cfs_duration_t timeout = timeoutl <= 0 ?
1022 CFS_TICK : cfs_time_seconds(timeoutl);
1023 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
1024 ost_bulk_timeout, desc);
1025 rc = l_wait_event(desc->bd_waitq,
1026 !ptlrpc_server_bulk_active(desc) ||
1027 desc->bd_export->exp_failed ||
1028 desc->bd_export->exp_abort_active_req,
1030 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1031 /* Wait again if we changed deadline */
1032 } while ((rc == -ETIMEDOUT) &&
1033 (req->rq_deadline > cfs_time_current_sec()));
1035 if (rc == -ETIMEDOUT) {
1036 DEBUG_REQ(D_ERROR, req,
1037 "timeout on bulk GET after %ld%+lds",
1038 req->rq_deadline - start,
1039 cfs_time_current_sec() -
1041 ptlrpc_abort_bulk(desc);
1042 } else if (desc->bd_export->exp_failed) {
1043 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1045 ptlrpc_abort_bulk(desc);
1046 } else if (desc->bd_export->exp_abort_active_req) {
1047 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk GET");
1048 /* we don't reply anyway */
1050 ptlrpc_abort_bulk(desc);
1051 } else if (!desc->bd_success) {
1052 DEBUG_REQ(D_ERROR, req, "network error on bulk GET");
1053 /* XXX should this be a different errno? */
1056 rc = sptlrpc_svc_unwrap_bulk(req, desc);
1059 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1063 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1065 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1067 if (unlikely(client_cksum != 0 && rc == 0)) {
1068 static int cksum_counter;
1069 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1070 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1071 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1072 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1073 repbody->oa.o_cksum = server_cksum;
1075 if (unlikely(client_cksum != server_cksum)) {
1076 CERROR("client csum %x, server csum %x\n",
1077 client_cksum, server_cksum);
1079 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1080 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1081 cksum_counter, libcfs_id2str(req->rq_peer),
1086 /* Must commit after prep above in all cases */
1087 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1088 remote_nb, npages, local_nb, oti, rc);
1089 if (exp_connect_rmtclient(exp)) {
1090 repbody->oa.o_uid = o_uid;
1091 repbody->oa.o_gid = o_gid;
1094 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1095 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1100 if (new_cksum == server_cksum)
1101 msg = "changed in transit before arrival at OST";
1102 else if (new_cksum == client_cksum)
1103 msg = "initial checksum before message complete";
1105 msg = "changed in transit AND after initial checksum";
1107 if (req->rq_peer.nid == desc->bd_sender) {
1111 router = libcfs_nid2str(desc->bd_sender);
1114 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1115 "%s%s%s inum "LPU64"/"LPU64" object "
1116 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1117 exp->exp_obd->obd_name, msg,
1118 libcfs_id2str(req->rq_peer),
1120 body->oa.o_valid & OBD_MD_FLFID ?
1121 body->oa.o_fid : (__u64)0,
1122 body->oa.o_valid & OBD_MD_FLFID ?
1123 body->oa.o_generation :(__u64)0,
1125 body->oa.o_valid & OBD_MD_FLGROUP ?
1126 body->oa.o_gr : (__u64)0,
1128 local_nb[npages-1].offset +
1129 local_nb[npages-1].len - 1 );
1130 CERROR("client csum %x, original server csum %x, "
1131 "server csum now %x\n",
1132 client_cksum, server_cksum, new_cksum);
1138 /* set per-requested niobuf return codes */
1139 for (i = j = 0; i < niocount; i++) {
1140 int len = remote_nb[i].len;
1145 LASSERT(j < npages);
1146 if (local_nb[j].rc < 0)
1147 rcs[i] = local_nb[j].rc;
1148 len -= local_nb[j].len;
1153 LASSERT(j == npages);
1154 ptlrpc_lprocfs_brw(req, nob);
1158 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1161 ptlrpc_free_bulk(desc);
1164 oti_to_request(oti, req);
1165 target_committed_to_req(req);
1166 rc = ptlrpc_reply(req);
1167 } else if (!no_reply) {
1168 /* Only reply if there was no comms problem with bulk */
1169 target_committed_to_req(req);
1170 req->rq_status = rc;
1173 /* reply out callback would free */
1174 ptlrpc_req_drop_rs(req);
1175 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1176 "client will retry\n",
1177 exp->exp_obd->obd_name,
1178 exp->exp_client_uuid.uuid,
1179 exp->exp_connection->c_remote_uuid.uuid,
1180 libcfs_id2str(req->rq_peer));
1182 libcfs_memory_pressure_clr();
1186 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1188 struct ost_body *body = NULL, *repbody;
1189 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
1190 char *key, *val = NULL;
1191 int keylen, vallen, rc = 0;
1194 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1196 DEBUG_REQ(D_HA, req, "no set_info key");
1199 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1201 if (KEY_IS(KEY_GRANT_SHRINK)) {
1202 rc = lustre_pack_reply(req, 2, size, NULL);
1206 rc = lustre_pack_reply(req, 1, NULL, NULL);
1211 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1213 if (KEY_IS(KEY_GRANT_SHRINK)) {
1214 body = lustre_swab_reqbuf(req, REQ_REC_OFF + 1,
1216 lustre_swab_ost_body);
1220 repbody = lustre_msg_buf(req->rq_repmsg,
1223 memcpy(repbody, body, sizeof(*body));
1224 val = (char*)repbody;
1226 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,0);
1229 if (KEY_IS(KEY_EVICT_BY_NID)) {
1231 obd_export_evict_by_nid(exp->exp_obd, val);
1233 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1234 /* Val's are not swabbed automatically */
1235 __swab32s((__u32 *)val);
1238 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1240 lustre_msg_set_status(req->rq_repmsg, 0);
1244 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1247 int keylen, replylen, rc = 0;
1248 struct req_capsule *pill = &req->rq_pill;
1251 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
1253 /* this common part for get_info rpc */
1254 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1256 DEBUG_REQ(D_HA, req, "no get_info key");
1259 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1261 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1265 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1266 RCL_SERVER, replylen);
1268 rc = req_capsule_server_pack(pill);
1272 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1276 /* call again to fill in the reply buffer */
1277 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1279 lustre_msg_set_status(req->rq_repmsg, 0);
1283 #ifdef HAVE_QUOTA_SUPPORT
1284 static int ost_handle_quotactl(struct ptlrpc_request *req)
1286 struct obd_quotactl *oqctl, *repoqc;
1290 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1292 GOTO(out, rc = -EPROTO);
1294 rc = req_capsule_server_pack(&req->rq_pill);
1298 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1299 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1306 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1308 struct obd_quotactl *oqctl;
1312 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1316 rc = req_capsule_server_pack(&req->rq_pill);
1320 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1324 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1326 struct quota_adjust_qunit *oqaq, *repoqa;
1327 struct lustre_quota_ctxt *qctxt;
1331 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1332 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1334 GOTO(out, rc = -EPROTO);
1336 rc = req_capsule_server_pack(&req->rq_pill);
1340 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1341 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt);
1349 static int ost_llog_handle_connect(struct obd_export *exp,
1350 struct ptlrpc_request *req)
1352 struct llogd_conn_body *body;
1356 body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body));
1357 rc = obd_llog_connect(exp, body);
1361 #define ost_init_sec_none(reply, exp) \
1363 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1364 OBD_CONNECT_RMT_CLIENT_FORCE | \
1365 OBD_CONNECT_OSS_CAPA); \
1366 spin_lock(&exp->exp_lock); \
1367 exp->exp_connect_flags = reply->ocd_connect_flags; \
1368 spin_unlock(&exp->exp_lock); \
1371 static int ost_init_sec_level(struct ptlrpc_request *req)
1373 struct obd_export *exp = req->rq_export;
1374 struct req_capsule *pill = &req->rq_pill;
1375 struct obd_device *obd = exp->exp_obd;
1376 struct filter_obd *filter = &obd->u.filter;
1377 char *client = libcfs_nid2str(req->rq_peer.nid);
1378 struct obd_connect_data *data, *reply;
1382 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1383 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1384 if (data == NULL || reply == NULL)
1387 /* connection from MDT is always trusted */
1388 if (req->rq_auth_usr_mdt) {
1389 ost_init_sec_none(reply, exp);
1393 /* no GSS support case */
1394 if (!req->rq_auth_gss) {
1395 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1396 CWARN("client %s -> target %s does not user GSS, "
1397 "can not run under security level %d.\n",
1398 client, obd->obd_name, filter->fo_sec_level);
1401 ost_init_sec_none(reply, exp);
1406 /* old version case */
1407 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1408 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1409 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1410 CWARN("client %s -> target %s uses old version, "
1411 "can not run under security level %d.\n",
1412 client, obd->obd_name, filter->fo_sec_level);
1415 CWARN("client %s -> target %s uses old version, "
1416 "run under security level %d.\n",
1417 client, obd->obd_name, filter->fo_sec_level);
1418 ost_init_sec_none(reply, exp);
1423 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1425 if (!req->rq_auth_remote)
1426 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1427 "asked to be remote.\n", client, obd->obd_name);
1428 } else if (req->rq_auth_remote) {
1430 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1431 "as remote by default.\n", client, obd->obd_name);
1435 if (!filter->fo_fl_oss_capa) {
1436 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1437 " but OSS capabilities are not enabled: %d.\n",
1438 client, obd->obd_name, filter->fo_fl_oss_capa);
1443 switch (filter->fo_sec_level) {
1444 case LUSTRE_SEC_NONE:
1446 ost_init_sec_none(reply, exp);
1449 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1450 "can not run under security level %d.\n",
1451 client, obd->obd_name, filter->fo_sec_level);
1454 case LUSTRE_SEC_REMOTE:
1456 ost_init_sec_none(reply, exp);
1458 case LUSTRE_SEC_ALL:
1460 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1461 OBD_CONNECT_RMT_CLIENT_FORCE);
1462 if (!filter->fo_fl_oss_capa)
1463 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1465 spin_lock(&exp->exp_lock);
1466 exp->exp_connect_flags = reply->ocd_connect_flags;
1467 spin_unlock(&exp->exp_lock);
1479 * this should be done in filter_connect()/filter_reconnect(), but
1480 * we can't obtain information like NID, which stored in incoming
1481 * request, thus can't decide what flavor to use. so we do it here.
1483 * This hack should be removed after the OST stack be rewritten, just
1484 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1486 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1488 struct obd_export *exp = req->rq_export;
1489 struct filter_obd *filter = &exp->exp_obd->u.filter;
1490 struct sptlrpc_flavor flvr;
1493 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1494 LUSTRE_ECHO_NAME) == 0)) {
1495 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1499 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1500 read_lock(&filter->fo_sptlrpc_lock);
1501 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1505 read_unlock(&filter->fo_sptlrpc_lock);
1507 spin_lock(&exp->exp_lock);
1509 exp->exp_sp_peer = req->rq_sp_from;
1510 exp->exp_flvr = flvr;
1512 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1513 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1514 CERROR("unauthorized rpc flavor %x from %s, "
1515 "expect %x\n", req->rq_flvr.sf_rpc,
1516 libcfs_nid2str(req->rq_peer.nid),
1517 exp->exp_flvr.sf_rpc);
1521 spin_unlock(&exp->exp_lock);
1523 if (exp->exp_sp_peer != req->rq_sp_from) {
1524 CERROR("RPC source %s doesn't match %s\n",
1525 sptlrpc_part2name(req->rq_sp_from),
1526 sptlrpc_part2name(exp->exp_sp_peer));
1529 rc = sptlrpc_target_export_check(exp, req);
1536 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1537 struct obd_device *obd, int *process)
1539 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1540 case OST_CONNECT: /* This will never get here, but for completeness. */
1541 case OST_DISCONNECT:
1552 case OBD_LOG_CANCEL:
1554 *process = target_queue_recovery_request(req, obd);
1558 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1564 int ost_msg_check_version(struct lustre_msg *msg)
1568 switch(lustre_msg_get_opc(msg)) {
1570 case OST_DISCONNECT:
1573 case SEC_CTX_INIT_CONT:
1575 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1577 CERROR("bad opc %u version %08x, expecting %08x\n",
1578 lustre_msg_get_opc(msg),
1579 lustre_msg_get_version(msg),
1580 LUSTRE_OBD_VERSION);
1593 #ifdef HAVE_QUOTA_SUPPORT
1594 case OST_QUOTACHECK:
1596 case OST_QUOTA_ADJUST_QUNIT:
1598 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1600 CERROR("bad opc %u version %08x, expecting %08x\n",
1601 lustre_msg_get_opc(msg),
1602 lustre_msg_get_version(msg),
1603 LUSTRE_OST_VERSION);
1608 case LDLM_BL_CALLBACK:
1609 case LDLM_CP_CALLBACK:
1610 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1612 CERROR("bad opc %u version %08x, expecting %08x\n",
1613 lustre_msg_get_opc(msg),
1614 lustre_msg_get_version(msg),
1615 LUSTRE_DLM_VERSION);
1617 case LLOG_ORIGIN_CONNECT:
1618 case OBD_LOG_CANCEL:
1619 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1621 CERROR("bad opc %u version %08x, expecting %08x\n",
1622 lustre_msg_get_opc(msg),
1623 lustre_msg_get_version(msg),
1624 LUSTRE_LOG_VERSION);
1627 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1633 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1634 struct ldlm_lock *lock)
1636 struct niobuf_remote *nb;
1637 struct obd_ioobj *ioo;
1638 struct ost_body *body;
1639 int objcount, niocount;
1644 opc = lustre_msg_get_opc(req->rq_reqmsg);
1645 LASSERT(opc == OST_READ || opc == OST_WRITE);
1647 /* As the request may be covered by several locks, do not look at
1648 * o_handle, look at the RPC IO region. */
1649 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
1651 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
1653 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
1654 objcount * sizeof(*ioo));
1655 LASSERT(ioo != NULL);
1656 for (niocount = i = 0; i < objcount; i++)
1657 niocount += ioo[i].ioo_bufcnt;
1659 nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
1660 niocount * sizeof(*nb));
1661 LASSERT(nb != NULL);
1664 if (opc == OST_READ)
1667 start = nb[0].offset & CFS_PAGE_MASK;
1668 end = (nb[ioo->ioo_bufcnt - 1].offset +
1669 nb[ioo->ioo_bufcnt - 1].len - 1) | ~CFS_PAGE_MASK;
1671 LASSERT(lock->l_resource != NULL);
1672 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_gr,
1673 &lock->l_resource->lr_name))
1676 if (!(lock->l_granted_mode & mode))
1679 if (lock->l_policy_data.l_extent.end < start ||
1680 lock->l_policy_data.l_extent.start > end)
1687 * Swab buffers needed to call ost_rw_prolong_locks() and call it.
1688 * Return the value from ost_rw_prolong_locks() which is non-zero if
1689 * there is a cancelled lock which is waiting for this IO request.
1691 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1693 struct niobuf_remote *nb;
1694 struct obd_ioobj *ioo;
1695 struct ost_body *body;
1696 int objcount, niocount;
1700 opc = lustre_msg_get_opc(req->rq_reqmsg);
1701 LASSERT(opc == OST_READ || opc == OST_WRITE);
1703 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
1704 LASSERT(body != NULL);
1706 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
1708 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
1709 objcount * sizeof(*ioo));
1710 LASSERT(ioo != NULL);
1712 for (niocount = i = 0; i < objcount; i++)
1713 niocount += ioo[i].ioo_bufcnt;
1714 nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
1715 niocount * sizeof(*nb));
1716 LASSERT(nb != NULL);
1717 LASSERT(niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK));
1720 if (opc == OST_READ)
1722 RETURN(ost_rw_prolong_locks(req, ioo, nb, &body->oa, mode));
1725 static int ost_punch_prolong_locks(struct ptlrpc_request *req, struct obdo *oa)
1727 struct ldlm_res_id res_id = { .name = { oa->o_id } };
1728 struct ost_prolong_data opd = { 0 };
1733 end = start + oa->o_blocks;
1735 opd.opd_mode = LCK_PW;
1736 opd.opd_exp = req->rq_export;
1737 opd.opd_policy.l_extent.start = start & CFS_PAGE_MASK;
1738 if (oa->o_blocks == OBD_OBJECT_EOF || end < start)
1739 opd.opd_policy.l_extent.end = OBD_OBJECT_EOF;
1741 opd.opd_policy.l_extent.end = end | ~CFS_PAGE_MASK;
1743 /* prolong locks for the current service time of the corresponding
1744 * portal (= OST_IO_PORTAL) */
1745 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
1746 max(at_est2timeout(at_get(&req->rq_rqbd->
1747 rqbd_service->srv_at_estimate)), ldlm_timeout);
1749 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1750 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
1751 opd.opd_policy.l_extent.end);
1754 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
1755 ost_prolong_locks_iter, &opd);
1756 RETURN(opd.opd_lock_match);
1759 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1760 struct ldlm_lock *lock)
1762 struct ost_body *body;
1765 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
1767 LASSERT(body != NULL);
1769 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1770 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1775 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1777 struct ost_body *body = lustre_msg_buf(req->rq_reqmsg,
1778 REQ_REC_OFF, sizeof(*body));
1779 LASSERT(body != NULL);
1780 LASSERT(!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1781 !(body->oa.o_flags & OBD_FL_TRUNCLOCK));
1783 RETURN(ost_punch_prolong_locks(req, &body->oa));
1786 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
1787 .hpreq_lock_match = ost_rw_hpreq_lock_match,
1788 .hpreq_check = ost_rw_hpreq_check,
1791 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
1792 .hpreq_lock_match = ost_punch_hpreq_lock_match,
1793 .hpreq_check = ost_punch_hpreq_check,
1796 /** Assign high priority operations to the request if needed. */
1797 static int ost_hpreq_handler(struct ptlrpc_request *req)
1800 if (req->rq_export) {
1801 int opc = lustre_msg_get_opc(req->rq_reqmsg);
1802 struct ost_body *body;
1804 if (opc == OST_READ || opc == OST_WRITE) {
1805 struct niobuf_remote *nb;
1806 struct obd_ioobj *ioo;
1807 int objcount, niocount;
1810 body = lustre_swab_reqbuf(req, REQ_REC_OFF,
1814 CERROR("Missing/short ost_body\n");
1817 objcount = lustre_msg_buflen(req->rq_reqmsg,
1820 if (objcount == 0) {
1821 CERROR("Missing/short ioobj\n");
1825 CERROR("too many ioobjs (%d)\n", objcount);
1829 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1,
1830 objcount * sizeof(*ioo),
1831 lustre_swab_obd_ioobj);
1833 CERROR("Missing/short ioobj\n");
1837 swab = ptlrpc_req_need_swab(req);
1838 for (niocount = i = 0; i < objcount; i++) {
1840 lustre_swab_obd_ioobj(&ioo[i]);
1841 if (ioo[i].ioo_bufcnt == 0) {
1842 CERROR("ioo[%d] has zero bufcnt\n", i);
1845 niocount += ioo[i].ioo_bufcnt;
1847 if (niocount > PTLRPC_MAX_BRW_PAGES) {
1848 DEBUG_REQ(D_ERROR, req, "bulk has too many "
1849 "pages (%d)", niocount);
1853 nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
1854 niocount * sizeof(*nb),
1855 lustre_swab_niobuf_remote);
1857 CERROR("Missing/short niobuf\n");
1861 swab = ptlrpc_req_need_swab(req);
1863 /* swab remaining niobufs */
1864 for (i = 1; i < niocount; i++)
1865 lustre_swab_niobuf_remote(&nb[i]);
1868 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
1869 req->rq_ops = &ost_hpreq_rw;
1870 } else if (opc == OST_PUNCH) {
1871 body = lustre_swab_reqbuf(req, REQ_REC_OFF,
1875 CERROR("Missing/short ost_body\n");
1879 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1880 !(body->oa.o_flags & OBD_FL_TRUNCLOCK))
1881 req->rq_ops = &ost_hpreq_punch;
1887 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1888 int ost_handle(struct ptlrpc_request *req)
1890 struct obd_trans_info trans_info = { 0, };
1891 struct obd_trans_info *oti = &trans_info;
1892 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1893 struct obd_device *obd = NULL;
1896 LASSERT(current->journal_info == NULL);
1898 /* primordial rpcs don't affect server recovery */
1899 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1901 case SEC_CTX_INIT_CONT:
1906 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1908 /* XXX identical to MDS */
1909 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1912 if (req->rq_export == NULL) {
1913 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1914 lustre_msg_get_opc(req->rq_reqmsg),
1915 libcfs_id2str(req->rq_peer));
1916 req->rq_status = -ENOTCONN;
1917 GOTO(out, rc = -ENOTCONN);
1920 obd = req->rq_export->exp_obd;
1922 /* Check for aborted recovery. */
1923 spin_lock_bh(&obd->obd_processing_task_lock);
1924 recovering = obd->obd_recovering;
1925 spin_unlock_bh(&obd->obd_processing_task_lock);
1927 rc = ost_filter_recovery_request(req, obd,
1929 if (rc || !should_process)
1931 else if (should_process < 0) {
1932 req->rq_status = should_process;
1933 rc = ptlrpc_error(req);
1941 rc = ost_msg_check_version(req->rq_reqmsg);
1945 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1947 CDEBUG(D_INODE, "connect\n");
1948 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
1949 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
1951 rc = target_handle_connect(req);
1952 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
1955 rc = ost_init_sec_level(req);
1957 rc = ost_connect_check_sptlrpc(req);
1961 case OST_DISCONNECT:
1962 CDEBUG(D_INODE, "disconnect\n");
1963 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
1964 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
1966 rc = target_handle_disconnect(req);
1969 CDEBUG(D_INODE, "create\n");
1970 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
1972 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1973 GOTO(out, rc = -ENOSPC);
1974 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1975 GOTO(out, rc = -EROFS);
1976 rc = ost_create(req->rq_export, req, oti);
1979 CDEBUG(D_INODE, "destroy\n");
1980 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
1982 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1983 GOTO(out, rc = -EROFS);
1984 rc = ost_destroy(req->rq_export, req, oti);
1987 CDEBUG(D_INODE, "getattr\n");
1988 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
1990 rc = ost_getattr(req->rq_export, req);
1993 CDEBUG(D_INODE, "setattr\n");
1994 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
1996 rc = ost_setattr(req->rq_export, req, oti);
1999 CDEBUG(D_INODE, "write\n");
2000 /* req->rq_request_portal would be nice, if it was set */
2001 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2002 CERROR("%s: deny write request from %s to portal %u\n",
2003 req->rq_export->exp_obd->obd_name,
2004 obd_export_nid2str(req->rq_export),
2005 req->rq_rqbd->rqbd_service->srv_req_portal);
2006 GOTO(out, rc = -EPROTO);
2008 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2010 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
2011 GOTO(out, rc = -ENOSPC);
2012 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2013 GOTO(out, rc = -EROFS);
2014 rc = ost_brw_write(req, oti);
2015 LASSERT(current->journal_info == NULL);
2016 /* ost_brw_write sends its own replies */
2019 CDEBUG(D_INODE, "read\n");
2020 /* req->rq_request_portal would be nice, if it was set */
2021 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2022 CERROR("%s: deny read request from %s to portal %u\n",
2023 req->rq_export->exp_obd->obd_name,
2024 obd_export_nid2str(req->rq_export),
2025 req->rq_rqbd->rqbd_service->srv_req_portal);
2026 GOTO(out, rc = -EPROTO);
2028 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2030 rc = ost_brw_read(req, oti);
2031 LASSERT(current->journal_info == NULL);
2032 /* ost_brw_read sends its own replies */
2035 CDEBUG(D_INODE, "punch\n");
2036 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2038 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2039 GOTO(out, rc = -EROFS);
2040 rc = ost_punch(req->rq_export, req, oti);
2043 CDEBUG(D_INODE, "statfs\n");
2044 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2046 rc = ost_statfs(req);
2049 CDEBUG(D_INODE, "sync\n");
2050 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2052 rc = ost_sync(req->rq_export, req);
2055 DEBUG_REQ(D_INODE, req, "set_info");
2056 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
2057 rc = ost_set_info(req->rq_export, req);
2060 DEBUG_REQ(D_INODE, req, "get_info");
2061 rc = ost_get_info(req->rq_export, req);
2063 #ifdef HAVE_QUOTA_SUPPORT
2064 case OST_QUOTACHECK:
2065 CDEBUG(D_INODE, "quotacheck\n");
2066 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2067 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2069 rc = ost_handle_quotacheck(req);
2072 CDEBUG(D_INODE, "quotactl\n");
2073 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2074 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2076 rc = ost_handle_quotactl(req);
2078 case OST_QUOTA_ADJUST_QUNIT:
2079 CDEBUG(D_INODE, "quota_adjust_qunit\n");
2080 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
2081 rc = ost_handle_quota_adjust_qunit(req);
2085 DEBUG_REQ(D_INODE, req, "ping");
2086 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2087 rc = target_handle_ping(req);
2089 /* FIXME - just reply status */
2090 case LLOG_ORIGIN_CONNECT:
2091 DEBUG_REQ(D_INODE, req, "log connect");
2092 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2093 rc = ost_llog_handle_connect(req->rq_export, req);
2094 req->rq_status = rc;
2095 rc = req_capsule_server_pack(&req->rq_pill);
2098 RETURN(ptlrpc_reply(req));
2099 case OBD_LOG_CANCEL:
2100 CDEBUG(D_INODE, "log cancel\n");
2101 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2102 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2104 rc = llog_origin_handle_cancel(req);
2105 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2107 req->rq_status = rc;
2108 rc = req_capsule_server_pack(&req->rq_pill);
2111 RETURN(ptlrpc_reply(req));
2113 CDEBUG(D_INODE, "enqueue\n");
2114 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2115 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2117 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2118 ldlm_server_blocking_ast,
2119 ldlm_server_glimpse_ast);
2120 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2123 CDEBUG(D_INODE, "convert\n");
2124 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2125 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2127 rc = ldlm_handle_convert(req);
2130 CDEBUG(D_INODE, "cancel\n");
2131 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2132 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2134 rc = ldlm_handle_cancel(req);
2136 case LDLM_BL_CALLBACK:
2137 case LDLM_CP_CALLBACK:
2138 CDEBUG(D_INODE, "callback\n");
2139 CERROR("callbacks should not happen on OST\n");
2142 CERROR("Unexpected opcode %d\n",
2143 lustre_msg_get_opc(req->rq_reqmsg));
2144 req->rq_status = -ENOTSUPP;
2145 rc = ptlrpc_error(req);
2149 LASSERT(current->journal_info == NULL);
2152 /* If we're DISCONNECTing, the export_data is already freed */
2153 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2154 target_committed_to_req(req);
2158 oti_to_request(oti, req);
2160 target_send_reply(req, rc, fail);
2163 EXPORT_SYMBOL(ost_handle);
2165 * free per-thread pool created by ost_thread_init().
2167 static void ost_thread_done(struct ptlrpc_thread *thread)
2169 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2174 LASSERT(thread != NULL);
2177 * be prepared to handle partially-initialized pools (because this is
2178 * called from ost_thread_init() for cleanup.
2180 tls = thread->t_data;
2183 thread->t_data = NULL;
2189 * initialize per-thread page pool (bug 5137).
2191 static int ost_thread_init(struct ptlrpc_thread *thread)
2193 struct ost_thread_local_cache *tls;
2197 LASSERT(thread != NULL);
2198 LASSERT(thread->t_data == NULL);
2199 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
2204 thread->t_data = tls;
2208 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2210 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2211 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2213 struct ost_obd *ost = &obd->u.ost;
2214 struct lprocfs_static_vars lvars;
2215 int oss_min_threads;
2216 int oss_max_threads;
2217 int oss_min_create_threads;
2218 int oss_max_create_threads;
2222 rc = cleanup_group_info();
2226 lprocfs_ost_init_vars(&lvars);
2227 lprocfs_obd_setup(obd, lvars.obd_vars);
2229 sema_init(&ost->ost_health_sem, 1);
2231 if (oss_num_threads) {
2232 /* If oss_num_threads is set, it is the min and the max. */
2233 if (oss_num_threads > OSS_THREADS_MAX)
2234 oss_num_threads = OSS_THREADS_MAX;
2235 if (oss_num_threads < OSS_THREADS_MIN)
2236 oss_num_threads = OSS_THREADS_MIN;
2237 oss_max_threads = oss_min_threads = oss_num_threads;
2239 /* Base min threads on memory and cpus */
2240 oss_min_threads = num_possible_cpus() * CFS_NUM_CACHEPAGES >>
2241 (27 - CFS_PAGE_SHIFT);
2242 if (oss_min_threads < OSS_THREADS_MIN)
2243 oss_min_threads = OSS_THREADS_MIN;
2244 /* Insure a 4x range for dynamic threads */
2245 if (oss_min_threads > OSS_THREADS_MAX / 4)
2246 oss_min_threads = OSS_THREADS_MAX / 4;
2247 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
2251 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2252 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
2253 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2254 ost_handle, LUSTRE_OSS_NAME,
2255 obd->obd_proc_entry, target_print_req,
2256 oss_min_threads, oss_max_threads,
2257 "ll_ost", LCT_DT_THREAD, NULL);
2258 if (ost->ost_service == NULL) {
2259 CERROR("failed to start service\n");
2260 GOTO(out_lprocfs, rc = -ENOMEM);
2263 rc = ptlrpc_start_threads(obd, ost->ost_service);
2265 GOTO(out_service, rc = -EINVAL);
2267 if (oss_num_create_threads) {
2268 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
2269 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
2270 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
2271 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
2272 oss_min_create_threads = oss_max_create_threads =
2273 oss_num_create_threads;
2275 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
2276 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
2279 ost->ost_create_service =
2280 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2281 OST_MAXREPSIZE, OST_CREATE_PORTAL,
2282 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2283 ost_handle, "ost_create",
2284 obd->obd_proc_entry, target_print_req,
2285 oss_min_create_threads, oss_max_create_threads,
2286 "ll_ost_creat", LCT_DT_THREAD, NULL);
2287 if (ost->ost_create_service == NULL) {
2288 CERROR("failed to start OST create service\n");
2289 GOTO(out_service, rc = -ENOMEM);
2292 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
2294 GOTO(out_create, rc = -EINVAL);
2296 ost->ost_io_service =
2297 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2298 OST_MAXREPSIZE, OST_IO_PORTAL,
2299 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2300 ost_handle, "ost_io",
2301 obd->obd_proc_entry, target_print_req,
2302 oss_min_threads, oss_max_threads,
2303 "ll_ost_io", LCT_DT_THREAD, ost_hpreq_handler);
2304 if (ost->ost_io_service == NULL) {
2305 CERROR("failed to start OST I/O service\n");
2306 GOTO(out_create, rc = -ENOMEM);
2309 ost->ost_io_service->srv_init = ost_thread_init;
2310 ost->ost_io_service->srv_done = ost_thread_done;
2311 ost->ost_io_service->srv_cpu_affinity = 1;
2312 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
2314 GOTO(out_io, rc = -EINVAL);
2316 ping_evictor_start();
2321 ptlrpc_unregister_service(ost->ost_io_service);
2322 ost->ost_io_service = NULL;
2324 ptlrpc_unregister_service(ost->ost_create_service);
2325 ost->ost_create_service = NULL;
2327 ptlrpc_unregister_service(ost->ost_service);
2328 ost->ost_service = NULL;
2330 lprocfs_obd_cleanup(obd);
2334 static int ost_cleanup(struct obd_device *obd)
2336 struct ost_obd *ost = &obd->u.ost;
2340 ping_evictor_stop();
2342 spin_lock_bh(&obd->obd_processing_task_lock);
2343 if (obd->obd_recovering) {
2344 target_cancel_recovery_timer(obd);
2345 obd->obd_recovering = 0;
2347 spin_unlock_bh(&obd->obd_processing_task_lock);
2349 down(&ost->ost_health_sem);
2350 ptlrpc_unregister_service(ost->ost_service);
2351 ptlrpc_unregister_service(ost->ost_create_service);
2352 ptlrpc_unregister_service(ost->ost_io_service);
2353 ost->ost_service = NULL;
2354 ost->ost_create_service = NULL;
2355 up(&ost->ost_health_sem);
2357 lprocfs_obd_cleanup(obd);
2362 static int ost_health_check(struct obd_device *obd)
2364 struct ost_obd *ost = &obd->u.ost;
2367 down(&ost->ost_health_sem);
2368 rc |= ptlrpc_service_health_check(ost->ost_service);
2369 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2370 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2371 up(&ost->ost_health_sem);
2374 * health_check to return 0 on healthy
2375 * and 1 on unhealthy.
2383 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2385 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2388 /* use obd ops to offer management infrastructure */
2389 static struct obd_ops ost_obd_ops = {
2390 .o_owner = THIS_MODULE,
2391 .o_setup = ost_setup,
2392 .o_cleanup = ost_cleanup,
2393 .o_health_check = ost_health_check,
2397 static int __init ost_init(void)
2399 struct lprocfs_static_vars lvars;
2403 lprocfs_ost_init_vars(&lvars);
2404 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2405 LUSTRE_OSS_NAME, NULL);
2407 if (ost_num_threads != 0 && oss_num_threads == 0) {
2408 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2409 "use oss_num_threads instead or unset both for "
2410 "dynamic thread startup\n");
2411 oss_num_threads = ost_num_threads;
2417 static void /*__exit*/ ost_exit(void)
2419 class_unregister_type(LUSTRE_OSS_NAME);
2422 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2423 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2424 MODULE_LICENSE("GPL");
2426 module_init(ost_init);
2427 module_exit(ost_exit);