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 (rc == -ENOTCONN)
1090 /* quota acquire process has been given up because
1091 * either the client has been evicted or the client
1092 * has timed out the request already */
1095 if (exp_connect_rmtclient(exp)) {
1096 repbody->oa.o_uid = o_uid;
1097 repbody->oa.o_gid = o_gid;
1100 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1101 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1106 if (new_cksum == server_cksum)
1107 msg = "changed in transit before arrival at OST";
1108 else if (new_cksum == client_cksum)
1109 msg = "initial checksum before message complete";
1111 msg = "changed in transit AND after initial checksum";
1113 if (req->rq_peer.nid == desc->bd_sender) {
1117 router = libcfs_nid2str(desc->bd_sender);
1120 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1121 "%s%s%s inum "LPU64"/"LPU64" object "
1122 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1123 exp->exp_obd->obd_name, msg,
1124 libcfs_id2str(req->rq_peer),
1126 body->oa.o_valid & OBD_MD_FLFID ?
1127 body->oa.o_fid : (__u64)0,
1128 body->oa.o_valid & OBD_MD_FLFID ?
1129 body->oa.o_generation :(__u64)0,
1131 body->oa.o_valid & OBD_MD_FLGROUP ?
1132 body->oa.o_gr : (__u64)0,
1134 local_nb[npages-1].offset +
1135 local_nb[npages-1].len - 1 );
1136 CERROR("client csum %x, original server csum %x, "
1137 "server csum now %x\n",
1138 client_cksum, server_cksum, new_cksum);
1144 /* set per-requested niobuf return codes */
1145 for (i = j = 0; i < niocount; i++) {
1146 int len = remote_nb[i].len;
1151 LASSERT(j < npages);
1152 if (local_nb[j].rc < 0)
1153 rcs[i] = local_nb[j].rc;
1154 len -= local_nb[j].len;
1159 LASSERT(j == npages);
1160 ptlrpc_lprocfs_brw(req, nob);
1164 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1167 ptlrpc_free_bulk(desc);
1170 oti_to_request(oti, req);
1171 target_committed_to_req(req);
1172 rc = ptlrpc_reply(req);
1173 } else if (!no_reply) {
1174 /* Only reply if there was no comms problem with bulk */
1175 target_committed_to_req(req);
1176 req->rq_status = rc;
1179 /* reply out callback would free */
1180 ptlrpc_req_drop_rs(req);
1181 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1182 "client will retry\n",
1183 exp->exp_obd->obd_name,
1184 exp->exp_client_uuid.uuid,
1185 exp->exp_connection->c_remote_uuid.uuid,
1186 libcfs_id2str(req->rq_peer));
1188 libcfs_memory_pressure_clr();
1192 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1194 struct ost_body *body = NULL, *repbody;
1195 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
1196 char *key, *val = NULL;
1197 int keylen, vallen, rc = 0;
1200 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1202 DEBUG_REQ(D_HA, req, "no set_info key");
1205 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1207 if (KEY_IS(KEY_GRANT_SHRINK)) {
1208 rc = lustre_pack_reply(req, 2, size, NULL);
1212 rc = lustre_pack_reply(req, 1, NULL, NULL);
1217 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1219 if (KEY_IS(KEY_GRANT_SHRINK)) {
1220 body = lustre_swab_reqbuf(req, REQ_REC_OFF + 1,
1222 lustre_swab_ost_body);
1226 repbody = lustre_msg_buf(req->rq_repmsg,
1229 memcpy(repbody, body, sizeof(*body));
1230 val = (char*)repbody;
1232 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,0);
1235 if (KEY_IS(KEY_EVICT_BY_NID)) {
1237 obd_export_evict_by_nid(exp->exp_obd, val);
1239 } else if (KEY_IS(KEY_MDS_CONN) && ptlrpc_req_need_swab(req)) {
1240 /* Val's are not swabbed automatically */
1241 __swab32s((__u32 *)val);
1244 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1246 lustre_msg_set_status(req->rq_repmsg, 0);
1250 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1253 int keylen, replylen, rc = 0;
1254 struct req_capsule *pill = &req->rq_pill;
1257 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
1259 /* this common part for get_info rpc */
1260 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1262 DEBUG_REQ(D_HA, req, "no get_info key");
1265 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1267 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1271 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1272 RCL_SERVER, replylen);
1274 rc = req_capsule_server_pack(pill);
1278 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1282 /* call again to fill in the reply buffer */
1283 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1285 lustre_msg_set_status(req->rq_repmsg, 0);
1289 #ifdef HAVE_QUOTA_SUPPORT
1290 static int ost_handle_quotactl(struct ptlrpc_request *req)
1292 struct obd_quotactl *oqctl, *repoqc;
1296 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1298 GOTO(out, rc = -EPROTO);
1300 rc = req_capsule_server_pack(&req->rq_pill);
1304 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1305 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1312 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1314 struct obd_quotactl *oqctl;
1318 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1322 rc = req_capsule_server_pack(&req->rq_pill);
1326 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1330 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1332 struct quota_adjust_qunit *oqaq, *repoqa;
1333 struct lustre_quota_ctxt *qctxt;
1337 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1338 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1340 GOTO(out, rc = -EPROTO);
1342 rc = req_capsule_server_pack(&req->rq_pill);
1346 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1347 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt);
1355 static int ost_llog_handle_connect(struct obd_export *exp,
1356 struct ptlrpc_request *req)
1358 struct llogd_conn_body *body;
1362 body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body));
1363 rc = obd_llog_connect(exp, body);
1367 #define ost_init_sec_none(reply, exp) \
1369 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1370 OBD_CONNECT_RMT_CLIENT_FORCE | \
1371 OBD_CONNECT_OSS_CAPA); \
1372 spin_lock(&exp->exp_lock); \
1373 exp->exp_connect_flags = reply->ocd_connect_flags; \
1374 spin_unlock(&exp->exp_lock); \
1377 static int ost_init_sec_level(struct ptlrpc_request *req)
1379 struct obd_export *exp = req->rq_export;
1380 struct req_capsule *pill = &req->rq_pill;
1381 struct obd_device *obd = exp->exp_obd;
1382 struct filter_obd *filter = &obd->u.filter;
1383 char *client = libcfs_nid2str(req->rq_peer.nid);
1384 struct obd_connect_data *data, *reply;
1388 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1389 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1390 if (data == NULL || reply == NULL)
1393 /* connection from MDT is always trusted */
1394 if (req->rq_auth_usr_mdt) {
1395 ost_init_sec_none(reply, exp);
1399 /* no GSS support case */
1400 if (!req->rq_auth_gss) {
1401 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1402 CWARN("client %s -> target %s does not user GSS, "
1403 "can not run under security level %d.\n",
1404 client, obd->obd_name, filter->fo_sec_level);
1407 ost_init_sec_none(reply, exp);
1412 /* old version case */
1413 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1414 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1415 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1416 CWARN("client %s -> target %s uses old version, "
1417 "can not run under security level %d.\n",
1418 client, obd->obd_name, filter->fo_sec_level);
1421 CWARN("client %s -> target %s uses old version, "
1422 "run under security level %d.\n",
1423 client, obd->obd_name, filter->fo_sec_level);
1424 ost_init_sec_none(reply, exp);
1429 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1431 if (!req->rq_auth_remote)
1432 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1433 "asked to be remote.\n", client, obd->obd_name);
1434 } else if (req->rq_auth_remote) {
1436 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1437 "as remote by default.\n", client, obd->obd_name);
1441 if (!filter->fo_fl_oss_capa) {
1442 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1443 " but OSS capabilities are not enabled: %d.\n",
1444 client, obd->obd_name, filter->fo_fl_oss_capa);
1449 switch (filter->fo_sec_level) {
1450 case LUSTRE_SEC_NONE:
1452 ost_init_sec_none(reply, exp);
1455 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1456 "can not run under security level %d.\n",
1457 client, obd->obd_name, filter->fo_sec_level);
1460 case LUSTRE_SEC_REMOTE:
1462 ost_init_sec_none(reply, exp);
1464 case LUSTRE_SEC_ALL:
1466 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1467 OBD_CONNECT_RMT_CLIENT_FORCE);
1468 if (!filter->fo_fl_oss_capa)
1469 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1471 spin_lock(&exp->exp_lock);
1472 exp->exp_connect_flags = reply->ocd_connect_flags;
1473 spin_unlock(&exp->exp_lock);
1485 * this should be done in filter_connect()/filter_reconnect(), but
1486 * we can't obtain information like NID, which stored in incoming
1487 * request, thus can't decide what flavor to use. so we do it here.
1489 * This hack should be removed after the OST stack be rewritten, just
1490 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1492 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1494 struct obd_export *exp = req->rq_export;
1495 struct filter_obd *filter = &exp->exp_obd->u.filter;
1496 struct sptlrpc_flavor flvr;
1499 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1500 LUSTRE_ECHO_NAME) == 0)) {
1501 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1505 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1506 read_lock(&filter->fo_sptlrpc_lock);
1507 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1511 read_unlock(&filter->fo_sptlrpc_lock);
1513 spin_lock(&exp->exp_lock);
1515 exp->exp_sp_peer = req->rq_sp_from;
1516 exp->exp_flvr = flvr;
1518 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1519 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1520 CERROR("unauthorized rpc flavor %x from %s, "
1521 "expect %x\n", req->rq_flvr.sf_rpc,
1522 libcfs_nid2str(req->rq_peer.nid),
1523 exp->exp_flvr.sf_rpc);
1527 spin_unlock(&exp->exp_lock);
1529 if (exp->exp_sp_peer != req->rq_sp_from) {
1530 CERROR("RPC source %s doesn't match %s\n",
1531 sptlrpc_part2name(req->rq_sp_from),
1532 sptlrpc_part2name(exp->exp_sp_peer));
1535 rc = sptlrpc_target_export_check(exp, req);
1542 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1543 struct obd_device *obd, int *process)
1545 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1546 case OST_CONNECT: /* This will never get here, but for completeness. */
1547 case OST_DISCONNECT:
1558 case OBD_LOG_CANCEL:
1560 *process = target_queue_recovery_request(req, obd);
1564 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1570 int ost_msg_check_version(struct lustre_msg *msg)
1574 switch(lustre_msg_get_opc(msg)) {
1576 case OST_DISCONNECT:
1579 case SEC_CTX_INIT_CONT:
1581 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1583 CERROR("bad opc %u version %08x, expecting %08x\n",
1584 lustre_msg_get_opc(msg),
1585 lustre_msg_get_version(msg),
1586 LUSTRE_OBD_VERSION);
1599 #ifdef HAVE_QUOTA_SUPPORT
1600 case OST_QUOTACHECK:
1602 case OST_QUOTA_ADJUST_QUNIT:
1604 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1606 CERROR("bad opc %u version %08x, expecting %08x\n",
1607 lustre_msg_get_opc(msg),
1608 lustre_msg_get_version(msg),
1609 LUSTRE_OST_VERSION);
1614 case LDLM_BL_CALLBACK:
1615 case LDLM_CP_CALLBACK:
1616 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1618 CERROR("bad opc %u version %08x, expecting %08x\n",
1619 lustre_msg_get_opc(msg),
1620 lustre_msg_get_version(msg),
1621 LUSTRE_DLM_VERSION);
1623 case LLOG_ORIGIN_CONNECT:
1624 case OBD_LOG_CANCEL:
1625 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1627 CERROR("bad opc %u version %08x, expecting %08x\n",
1628 lustre_msg_get_opc(msg),
1629 lustre_msg_get_version(msg),
1630 LUSTRE_LOG_VERSION);
1633 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1639 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1640 struct ldlm_lock *lock)
1642 struct niobuf_remote *nb;
1643 struct obd_ioobj *ioo;
1644 struct ost_body *body;
1645 int objcount, niocount;
1650 opc = lustre_msg_get_opc(req->rq_reqmsg);
1651 LASSERT(opc == OST_READ || opc == OST_WRITE);
1653 /* As the request may be covered by several locks, do not look at
1654 * o_handle, look at the RPC IO region. */
1655 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
1657 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
1659 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
1660 objcount * sizeof(*ioo));
1661 LASSERT(ioo != NULL);
1662 for (niocount = i = 0; i < objcount; i++)
1663 niocount += ioo[i].ioo_bufcnt;
1665 nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
1666 niocount * sizeof(*nb));
1667 LASSERT(nb != NULL);
1670 if (opc == OST_READ)
1673 start = nb[0].offset & CFS_PAGE_MASK;
1674 end = (nb[ioo->ioo_bufcnt - 1].offset +
1675 nb[ioo->ioo_bufcnt - 1].len - 1) | ~CFS_PAGE_MASK;
1677 LASSERT(lock->l_resource != NULL);
1678 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_gr,
1679 &lock->l_resource->lr_name))
1682 if (!(lock->l_granted_mode & mode))
1685 if (lock->l_policy_data.l_extent.end < start ||
1686 lock->l_policy_data.l_extent.start > end)
1693 * Swab buffers needed to call ost_rw_prolong_locks() and call it.
1694 * Return the value from ost_rw_prolong_locks() which is non-zero if
1695 * there is a cancelled lock which is waiting for this IO request.
1697 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1699 struct niobuf_remote *nb;
1700 struct obd_ioobj *ioo;
1701 struct ost_body *body;
1702 int objcount, niocount;
1706 opc = lustre_msg_get_opc(req->rq_reqmsg);
1707 LASSERT(opc == OST_READ || opc == OST_WRITE);
1709 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
1710 LASSERT(body != NULL);
1712 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
1714 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
1715 objcount * sizeof(*ioo));
1716 LASSERT(ioo != NULL);
1718 for (niocount = i = 0; i < objcount; i++)
1719 niocount += ioo[i].ioo_bufcnt;
1720 nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
1721 niocount * sizeof(*nb));
1722 LASSERT(nb != NULL);
1723 LASSERT(niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK));
1726 if (opc == OST_READ)
1728 RETURN(ost_rw_prolong_locks(req, ioo, nb, &body->oa, mode));
1731 static int ost_punch_prolong_locks(struct ptlrpc_request *req, struct obdo *oa)
1733 struct ldlm_res_id res_id = { .name = { oa->o_id } };
1734 struct ost_prolong_data opd = { 0 };
1739 end = start + oa->o_blocks;
1741 opd.opd_mode = LCK_PW;
1742 opd.opd_exp = req->rq_export;
1743 opd.opd_policy.l_extent.start = start & CFS_PAGE_MASK;
1744 if (oa->o_blocks == OBD_OBJECT_EOF || end < start)
1745 opd.opd_policy.l_extent.end = OBD_OBJECT_EOF;
1747 opd.opd_policy.l_extent.end = end | ~CFS_PAGE_MASK;
1749 /* prolong locks for the current service time of the corresponding
1750 * portal (= OST_IO_PORTAL) */
1751 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
1752 max(at_est2timeout(at_get(&req->rq_rqbd->
1753 rqbd_service->srv_at_estimate)), ldlm_timeout);
1755 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1756 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
1757 opd.opd_policy.l_extent.end);
1760 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
1761 ost_prolong_locks_iter, &opd);
1762 RETURN(opd.opd_lock_match);
1765 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1766 struct ldlm_lock *lock)
1768 struct ost_body *body;
1771 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
1773 LASSERT(body != NULL);
1775 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1776 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1781 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1783 struct ost_body *body = lustre_msg_buf(req->rq_reqmsg,
1784 REQ_REC_OFF, sizeof(*body));
1785 LASSERT(body != NULL);
1786 LASSERT(!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1787 !(body->oa.o_flags & OBD_FL_TRUNCLOCK));
1789 RETURN(ost_punch_prolong_locks(req, &body->oa));
1792 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
1793 .hpreq_lock_match = ost_rw_hpreq_lock_match,
1794 .hpreq_check = ost_rw_hpreq_check,
1797 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
1798 .hpreq_lock_match = ost_punch_hpreq_lock_match,
1799 .hpreq_check = ost_punch_hpreq_check,
1802 /** Assign high priority operations to the request if needed. */
1803 static int ost_hpreq_handler(struct ptlrpc_request *req)
1806 if (req->rq_export) {
1807 int opc = lustre_msg_get_opc(req->rq_reqmsg);
1808 struct ost_body *body;
1810 if (opc == OST_READ || opc == OST_WRITE) {
1811 struct niobuf_remote *nb;
1812 struct obd_ioobj *ioo;
1813 int objcount, niocount;
1816 body = lustre_swab_reqbuf(req, REQ_REC_OFF,
1820 CERROR("Missing/short ost_body\n");
1823 objcount = lustre_msg_buflen(req->rq_reqmsg,
1826 if (objcount == 0) {
1827 CERROR("Missing/short ioobj\n");
1831 CERROR("too many ioobjs (%d)\n", objcount);
1835 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1,
1836 objcount * sizeof(*ioo),
1837 lustre_swab_obd_ioobj);
1839 CERROR("Missing/short ioobj\n");
1843 swab = ptlrpc_req_need_swab(req);
1844 for (niocount = i = 0; i < objcount; i++) {
1846 lustre_swab_obd_ioobj(&ioo[i]);
1847 if (ioo[i].ioo_bufcnt == 0) {
1848 CERROR("ioo[%d] has zero bufcnt\n", i);
1851 niocount += ioo[i].ioo_bufcnt;
1853 if (niocount > PTLRPC_MAX_BRW_PAGES) {
1854 DEBUG_REQ(D_ERROR, req, "bulk has too many "
1855 "pages (%d)", niocount);
1859 nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
1860 niocount * sizeof(*nb),
1861 lustre_swab_niobuf_remote);
1863 CERROR("Missing/short niobuf\n");
1867 swab = ptlrpc_req_need_swab(req);
1869 /* swab remaining niobufs */
1870 for (i = 1; i < niocount; i++)
1871 lustre_swab_niobuf_remote(&nb[i]);
1874 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
1875 req->rq_ops = &ost_hpreq_rw;
1876 } else if (opc == OST_PUNCH) {
1877 body = lustre_swab_reqbuf(req, REQ_REC_OFF,
1881 CERROR("Missing/short ost_body\n");
1885 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1886 !(body->oa.o_flags & OBD_FL_TRUNCLOCK))
1887 req->rq_ops = &ost_hpreq_punch;
1893 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1894 int ost_handle(struct ptlrpc_request *req)
1896 struct obd_trans_info trans_info = { 0, };
1897 struct obd_trans_info *oti = &trans_info;
1898 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1899 struct obd_device *obd = NULL;
1902 LASSERT(current->journal_info == NULL);
1904 /* primordial rpcs don't affect server recovery */
1905 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1907 case SEC_CTX_INIT_CONT:
1912 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1914 /* XXX identical to MDS */
1915 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1918 if (req->rq_export == NULL) {
1919 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1920 lustre_msg_get_opc(req->rq_reqmsg),
1921 libcfs_id2str(req->rq_peer));
1922 req->rq_status = -ENOTCONN;
1923 GOTO(out, rc = -ENOTCONN);
1926 obd = req->rq_export->exp_obd;
1928 /* Check for aborted recovery. */
1929 spin_lock_bh(&obd->obd_processing_task_lock);
1930 recovering = obd->obd_recovering;
1931 spin_unlock_bh(&obd->obd_processing_task_lock);
1933 rc = ost_filter_recovery_request(req, obd,
1935 if (rc || !should_process)
1937 else if (should_process < 0) {
1938 req->rq_status = should_process;
1939 rc = ptlrpc_error(req);
1947 rc = ost_msg_check_version(req->rq_reqmsg);
1951 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1953 CDEBUG(D_INODE, "connect\n");
1954 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
1955 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
1957 rc = target_handle_connect(req);
1958 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
1961 rc = ost_init_sec_level(req);
1963 rc = ost_connect_check_sptlrpc(req);
1967 case OST_DISCONNECT:
1968 CDEBUG(D_INODE, "disconnect\n");
1969 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
1970 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
1972 rc = target_handle_disconnect(req);
1975 CDEBUG(D_INODE, "create\n");
1976 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
1978 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1979 GOTO(out, rc = -ENOSPC);
1980 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1981 GOTO(out, rc = -EROFS);
1982 rc = ost_create(req->rq_export, req, oti);
1985 CDEBUG(D_INODE, "destroy\n");
1986 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
1988 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1989 GOTO(out, rc = -EROFS);
1990 rc = ost_destroy(req->rq_export, req, oti);
1993 CDEBUG(D_INODE, "getattr\n");
1994 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
1996 rc = ost_getattr(req->rq_export, req);
1999 CDEBUG(D_INODE, "setattr\n");
2000 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
2002 rc = ost_setattr(req->rq_export, req, oti);
2005 CDEBUG(D_INODE, "write\n");
2006 /* req->rq_request_portal would be nice, if it was set */
2007 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2008 CERROR("%s: deny write request from %s to portal %u\n",
2009 req->rq_export->exp_obd->obd_name,
2010 obd_export_nid2str(req->rq_export),
2011 req->rq_rqbd->rqbd_service->srv_req_portal);
2012 GOTO(out, rc = -EPROTO);
2014 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2016 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
2017 GOTO(out, rc = -ENOSPC);
2018 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2019 GOTO(out, rc = -EROFS);
2020 rc = ost_brw_write(req, oti);
2021 LASSERT(current->journal_info == NULL);
2022 /* ost_brw_write sends its own replies */
2025 CDEBUG(D_INODE, "read\n");
2026 /* req->rq_request_portal would be nice, if it was set */
2027 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2028 CERROR("%s: deny read request from %s to portal %u\n",
2029 req->rq_export->exp_obd->obd_name,
2030 obd_export_nid2str(req->rq_export),
2031 req->rq_rqbd->rqbd_service->srv_req_portal);
2032 GOTO(out, rc = -EPROTO);
2034 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2036 rc = ost_brw_read(req, oti);
2037 LASSERT(current->journal_info == NULL);
2038 /* ost_brw_read sends its own replies */
2041 CDEBUG(D_INODE, "punch\n");
2042 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2044 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2045 GOTO(out, rc = -EROFS);
2046 rc = ost_punch(req->rq_export, req, oti);
2049 CDEBUG(D_INODE, "statfs\n");
2050 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2052 rc = ost_statfs(req);
2055 CDEBUG(D_INODE, "sync\n");
2056 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2058 rc = ost_sync(req->rq_export, req);
2061 DEBUG_REQ(D_INODE, req, "set_info");
2062 req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO);
2063 rc = ost_set_info(req->rq_export, req);
2066 DEBUG_REQ(D_INODE, req, "get_info");
2067 rc = ost_get_info(req->rq_export, req);
2069 #ifdef HAVE_QUOTA_SUPPORT
2070 case OST_QUOTACHECK:
2071 CDEBUG(D_INODE, "quotacheck\n");
2072 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2073 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2075 rc = ost_handle_quotacheck(req);
2078 CDEBUG(D_INODE, "quotactl\n");
2079 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2080 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2082 rc = ost_handle_quotactl(req);
2084 case OST_QUOTA_ADJUST_QUNIT:
2085 CDEBUG(D_INODE, "quota_adjust_qunit\n");
2086 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
2087 rc = ost_handle_quota_adjust_qunit(req);
2091 DEBUG_REQ(D_INODE, req, "ping");
2092 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2093 rc = target_handle_ping(req);
2095 /* FIXME - just reply status */
2096 case LLOG_ORIGIN_CONNECT:
2097 DEBUG_REQ(D_INODE, req, "log connect");
2098 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2099 rc = ost_llog_handle_connect(req->rq_export, req);
2100 req->rq_status = rc;
2101 rc = req_capsule_server_pack(&req->rq_pill);
2104 RETURN(ptlrpc_reply(req));
2105 case OBD_LOG_CANCEL:
2106 CDEBUG(D_INODE, "log cancel\n");
2107 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2108 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2110 rc = llog_origin_handle_cancel(req);
2111 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2113 req->rq_status = rc;
2114 rc = req_capsule_server_pack(&req->rq_pill);
2117 RETURN(ptlrpc_reply(req));
2119 CDEBUG(D_INODE, "enqueue\n");
2120 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2121 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2123 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2124 ldlm_server_blocking_ast,
2125 ldlm_server_glimpse_ast);
2126 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2129 CDEBUG(D_INODE, "convert\n");
2130 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2131 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2133 rc = ldlm_handle_convert(req);
2136 CDEBUG(D_INODE, "cancel\n");
2137 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2138 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2140 rc = ldlm_handle_cancel(req);
2142 case LDLM_BL_CALLBACK:
2143 case LDLM_CP_CALLBACK:
2144 CDEBUG(D_INODE, "callback\n");
2145 CERROR("callbacks should not happen on OST\n");
2148 CERROR("Unexpected opcode %d\n",
2149 lustre_msg_get_opc(req->rq_reqmsg));
2150 req->rq_status = -ENOTSUPP;
2151 rc = ptlrpc_error(req);
2155 LASSERT(current->journal_info == NULL);
2158 /* If we're DISCONNECTing, the export_data is already freed */
2159 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2160 target_committed_to_req(req);
2164 oti_to_request(oti, req);
2166 target_send_reply(req, rc, fail);
2169 EXPORT_SYMBOL(ost_handle);
2171 * free per-thread pool created by ost_thread_init().
2173 static void ost_thread_done(struct ptlrpc_thread *thread)
2175 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2180 LASSERT(thread != NULL);
2183 * be prepared to handle partially-initialized pools (because this is
2184 * called from ost_thread_init() for cleanup.
2186 tls = thread->t_data;
2189 thread->t_data = NULL;
2195 * initialize per-thread page pool (bug 5137).
2197 static int ost_thread_init(struct ptlrpc_thread *thread)
2199 struct ost_thread_local_cache *tls;
2203 LASSERT(thread != NULL);
2204 LASSERT(thread->t_data == NULL);
2205 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
2210 thread->t_data = tls;
2214 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2216 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2217 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2219 struct ost_obd *ost = &obd->u.ost;
2220 struct lprocfs_static_vars lvars;
2221 int oss_min_threads;
2222 int oss_max_threads;
2223 int oss_min_create_threads;
2224 int oss_max_create_threads;
2228 rc = cleanup_group_info();
2232 lprocfs_ost_init_vars(&lvars);
2233 lprocfs_obd_setup(obd, lvars.obd_vars);
2235 sema_init(&ost->ost_health_sem, 1);
2237 if (oss_num_threads) {
2238 /* If oss_num_threads is set, it is the min and the max. */
2239 if (oss_num_threads > OSS_THREADS_MAX)
2240 oss_num_threads = OSS_THREADS_MAX;
2241 if (oss_num_threads < OSS_THREADS_MIN)
2242 oss_num_threads = OSS_THREADS_MIN;
2243 oss_max_threads = oss_min_threads = oss_num_threads;
2245 /* Base min threads on memory and cpus */
2246 oss_min_threads = num_possible_cpus() * CFS_NUM_CACHEPAGES >>
2247 (27 - CFS_PAGE_SHIFT);
2248 if (oss_min_threads < OSS_THREADS_MIN)
2249 oss_min_threads = OSS_THREADS_MIN;
2250 /* Insure a 4x range for dynamic threads */
2251 if (oss_min_threads > OSS_THREADS_MAX / 4)
2252 oss_min_threads = OSS_THREADS_MAX / 4;
2253 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
2257 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2258 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
2259 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2260 ost_handle, LUSTRE_OSS_NAME,
2261 obd->obd_proc_entry, target_print_req,
2262 oss_min_threads, oss_max_threads,
2263 "ll_ost", LCT_DT_THREAD, NULL);
2264 if (ost->ost_service == NULL) {
2265 CERROR("failed to start service\n");
2266 GOTO(out_lprocfs, rc = -ENOMEM);
2269 rc = ptlrpc_start_threads(obd, ost->ost_service);
2271 GOTO(out_service, rc = -EINVAL);
2273 if (oss_num_create_threads) {
2274 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
2275 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
2276 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
2277 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
2278 oss_min_create_threads = oss_max_create_threads =
2279 oss_num_create_threads;
2281 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
2282 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
2285 ost->ost_create_service =
2286 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2287 OST_MAXREPSIZE, OST_CREATE_PORTAL,
2288 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2289 ost_handle, "ost_create",
2290 obd->obd_proc_entry, target_print_req,
2291 oss_min_create_threads, oss_max_create_threads,
2292 "ll_ost_creat", LCT_DT_THREAD, NULL);
2293 if (ost->ost_create_service == NULL) {
2294 CERROR("failed to start OST create service\n");
2295 GOTO(out_service, rc = -ENOMEM);
2298 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
2300 GOTO(out_create, rc = -EINVAL);
2302 ost->ost_io_service =
2303 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2304 OST_MAXREPSIZE, OST_IO_PORTAL,
2305 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2306 ost_handle, "ost_io",
2307 obd->obd_proc_entry, target_print_req,
2308 oss_min_threads, oss_max_threads,
2309 "ll_ost_io", LCT_DT_THREAD, ost_hpreq_handler);
2310 if (ost->ost_io_service == NULL) {
2311 CERROR("failed to start OST I/O service\n");
2312 GOTO(out_create, rc = -ENOMEM);
2315 ost->ost_io_service->srv_init = ost_thread_init;
2316 ost->ost_io_service->srv_done = ost_thread_done;
2317 ost->ost_io_service->srv_cpu_affinity = 1;
2318 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
2320 GOTO(out_io, rc = -EINVAL);
2322 ping_evictor_start();
2327 ptlrpc_unregister_service(ost->ost_io_service);
2328 ost->ost_io_service = NULL;
2330 ptlrpc_unregister_service(ost->ost_create_service);
2331 ost->ost_create_service = NULL;
2333 ptlrpc_unregister_service(ost->ost_service);
2334 ost->ost_service = NULL;
2336 lprocfs_obd_cleanup(obd);
2340 static int ost_cleanup(struct obd_device *obd)
2342 struct ost_obd *ost = &obd->u.ost;
2346 ping_evictor_stop();
2348 spin_lock_bh(&obd->obd_processing_task_lock);
2349 if (obd->obd_recovering) {
2350 target_cancel_recovery_timer(obd);
2351 obd->obd_recovering = 0;
2353 spin_unlock_bh(&obd->obd_processing_task_lock);
2355 down(&ost->ost_health_sem);
2356 ptlrpc_unregister_service(ost->ost_service);
2357 ptlrpc_unregister_service(ost->ost_create_service);
2358 ptlrpc_unregister_service(ost->ost_io_service);
2359 ost->ost_service = NULL;
2360 ost->ost_create_service = NULL;
2361 up(&ost->ost_health_sem);
2363 lprocfs_obd_cleanup(obd);
2368 static int ost_health_check(struct obd_device *obd)
2370 struct ost_obd *ost = &obd->u.ost;
2373 down(&ost->ost_health_sem);
2374 rc |= ptlrpc_service_health_check(ost->ost_service);
2375 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2376 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2377 up(&ost->ost_health_sem);
2380 * health_check to return 0 on healthy
2381 * and 1 on unhealthy.
2389 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2391 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2394 /* use obd ops to offer management infrastructure */
2395 static struct obd_ops ost_obd_ops = {
2396 .o_owner = THIS_MODULE,
2397 .o_setup = ost_setup,
2398 .o_cleanup = ost_cleanup,
2399 .o_health_check = ost_health_check,
2403 static int __init ost_init(void)
2405 struct lprocfs_static_vars lvars;
2409 lprocfs_ost_init_vars(&lvars);
2410 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2411 LUSTRE_OSS_NAME, NULL);
2413 if (ost_num_threads != 0 && oss_num_threads == 0) {
2414 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2415 "use oss_num_threads instead or unset both for "
2416 "dynamic thread startup\n");
2417 oss_num_threads = ost_num_threads;
2423 static void /*__exit*/ ost_exit(void)
2425 class_unregister_type(LUSTRE_OSS_NAME);
2428 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2429 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2430 MODULE_LICENSE("GPL");
2432 module_init(ost_init);
2433 module_exit(ost_exit);