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_capa(req->rq_reqmsg, 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_capa(req->rq_reqmsg,
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;
221 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
222 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
227 * Helper function for ost_punch(): if asked by client, acquire [size, EOF]
228 * lock on the file being truncated.
230 static int ost_punch_lock_get(struct obd_export *exp, struct obdo *oa,
231 struct lustre_handle *lh)
234 struct ldlm_res_id res_id;
235 ldlm_policy_data_t policy;
241 osc_build_res_name(oa->o_id, oa->o_gr, &res_id);
242 LASSERT(!lustre_handle_is_used(lh));
244 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
245 !(oa->o_flags & OBD_FL_TRUNCLOCK))
248 CDEBUG(D_INODE, "OST-side truncate lock.\n");
251 finis = start + oa->o_blocks;
254 * standard truncate optimization: if file body is completely
255 * destroyed, don't send data back to the server.
257 flags = (start == 0) ? LDLM_AST_DISCARD_DATA : 0;
259 policy.l_extent.start = start & CFS_PAGE_MASK;
262 * If ->o_blocks is EOF it means "lock till the end of the
263 * file". Otherwise, it's size of a hole being punched (in bytes)
265 if (oa->o_blocks == OBD_OBJECT_EOF || finis < start)
266 policy.l_extent.end = OBD_OBJECT_EOF;
268 policy.l_extent.end = finis | ~CFS_PAGE_MASK;
270 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
271 LDLM_EXTENT, &policy, LCK_PW, &flags,
272 ldlm_blocking_ast, ldlm_completion_ast,
273 ldlm_glimpse_ast, NULL, 0, NULL,
278 * Helper function for ost_punch(): release lock acquired by
279 * ost_punch_lock_get(), if any.
281 static void ost_punch_lock_put(struct obd_export *exp, struct obdo *oa,
282 struct lustre_handle *lh)
285 if (lustre_handle_is_used(lh))
286 ldlm_lock_decref(lh, LCK_PW);
290 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
291 struct obd_trans_info *oti)
293 struct obd_info oinfo = { { { 0 } } };
294 struct ost_body *body, *repbody;
295 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
297 struct lustre_handle lh = {0,};
300 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
301 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
303 /* ost_body is varified and swabbed in ost_hpreq_handler() */
304 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
305 LASSERT(body != NULL);
307 oinfo.oi_oa = &body->oa;
308 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
309 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
311 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
312 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
315 rc = lustre_pack_reply(req, 2, size, NULL);
319 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
321 rc = ost_punch_lock_get(exp, oinfo.oi_oa, &lh);
323 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
324 oinfo.oi_oa->o_flags == OBD_FL_TRUNCLOCK)
326 * If OBD_FL_TRUNCLOCK is the only bit set in
327 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
328 * through filter_setattr() to filter_iocontrol().
330 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
332 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
333 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
335 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
336 ost_punch_lock_put(exp, oinfo.oi_oa, &lh);
338 repbody->oa = *oinfo.oi_oa;
339 ost_drop_id(exp, &repbody->oa);
343 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
345 struct ost_body *body, *repbody;
346 struct lustre_capa *capa = NULL;
347 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
351 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
352 lustre_swab_ost_body);
356 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
357 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 1);
359 rc = lustre_pack_reply(req, 2, size, NULL);
363 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
365 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
366 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
367 repbody->oa.o_blocks, capa);
368 ost_drop_id(exp, &repbody->oa);
372 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
373 struct obd_trans_info *oti)
375 struct ost_body *body, *repbody;
376 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
378 struct obd_info oinfo = { { { 0 } } };
381 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
382 lustre_swab_ost_body);
386 rc = lustre_pack_reply(req, 2, size, NULL);
390 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
392 repbody->oa = body->oa;
394 oinfo.oi_oa = &repbody->oa;
395 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
396 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
398 req->rq_status = obd_setattr(exp, &oinfo, oti);
399 ost_drop_id(exp, &repbody->oa);
403 static int ost_bulk_timeout(void *data)
406 /* We don't fail the connection here, because having the export
407 * killed makes the (vital) call to commitrw very sad.
412 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
413 cksum_type_t cksum_type)
418 cksum = init_checksum(cksum_type);
419 for (i = 0; i < desc->bd_iov_count; i++) {
420 struct page *page = desc->bd_iov[i].kiov_page;
421 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
422 char *ptr = kmap(page) + off;
423 int len = desc->bd_iov[i].kiov_len;
425 /* corrupt the data before we compute the checksum, to
426 * simulate a client->OST data error */
427 if (i == 0 && opc == OST_WRITE &&
428 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
429 memcpy(ptr, "bad3", min(4, len));
430 cksum = compute_checksum(cksum, ptr, len, cksum_type);
431 /* corrupt the data after we compute the checksum, to
432 * simulate an OST->client data error */
433 if (i == 0 && opc == OST_READ &&
434 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
435 memcpy(ptr, "bad4", min(4, len));
436 /* nobody should use corrupted page again */
437 ClearPageUptodate(page);
445 static int ost_brw_lock_get(int mode, struct obd_export *exp,
446 struct obd_ioobj *obj, struct niobuf_remote *nb,
447 struct lustre_handle *lh)
450 int nrbufs = obj->ioo_bufcnt;
451 struct ldlm_res_id res_id;
452 ldlm_policy_data_t policy;
456 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
457 LASSERT(mode == LCK_PR || mode == LCK_PW);
458 LASSERT(!lustre_handle_is_used(lh));
460 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
463 /* EXPENSIVE ASSERTION */
464 for (i = 1; i < nrbufs; i ++)
465 LASSERT((nb[0].flags & OBD_BRW_SRVLOCK) ==
466 (nb[i].flags & OBD_BRW_SRVLOCK));
468 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
469 policy.l_extent.end = (nb[nrbufs - 1].offset +
470 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
472 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
473 LDLM_EXTENT, &policy, mode, &flags,
474 ldlm_blocking_ast, ldlm_completion_ast,
475 ldlm_glimpse_ast, NULL, 0, NULL,
479 static void ost_brw_lock_put(int mode,
480 struct obd_ioobj *obj, struct niobuf_remote *niob,
481 struct lustre_handle *lh)
484 LASSERT(mode == LCK_PR || mode == LCK_PW);
485 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
486 lustre_handle_is_used(lh));
487 if (lustre_handle_is_used(lh))
488 ldlm_lock_decref(lh, mode);
492 struct ost_prolong_data {
493 struct obd_export *opd_exp;
494 ldlm_policy_data_t opd_policy;
496 ldlm_mode_t opd_mode;
501 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
503 struct ost_prolong_data *opd = data;
505 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
507 if (lock->l_req_mode != lock->l_granted_mode) {
508 /* scan granted locks only */
509 return LDLM_ITER_STOP;
512 if (lock->l_export != opd->opd_exp) {
513 /* prolong locks only for given client */
514 return LDLM_ITER_CONTINUE;
517 if (!(lock->l_granted_mode & opd->opd_mode)) {
518 /* we aren't interesting in all type of locks */
519 return LDLM_ITER_CONTINUE;
522 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
523 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
524 /* the request doesn't cross the lock, skip it */
525 return LDLM_ITER_CONTINUE;
528 /* Fill the obdo with the matched lock handle.
529 * XXX: it is possible in some cases the IO RPC is covered by several
530 * locks, even for the write case, so it may need to be a lock list. */
531 if (opd->opd_oa && !(opd->opd_oa->o_valid & OBD_MD_FLHANDLE)) {
532 opd->opd_oa->o_handle.cookie = lock->l_handle.h_cookie;
533 opd->opd_oa->o_valid |= OBD_MD_FLHANDLE;
536 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
537 /* ignore locks not being cancelled */
538 return LDLM_ITER_CONTINUE;
541 /* OK. this is a possible lock the user holds doing I/O
542 * let's refresh eviction timer for it */
543 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
544 opd->opd_lock_match = 1;
546 return LDLM_ITER_CONTINUE;
549 static int ost_rw_prolong_locks(struct ptlrpc_request *req, struct obd_ioobj *obj,
550 struct niobuf_remote *nb, struct obdo *oa,
553 struct ldlm_res_id res_id;
554 int nrbufs = obj->ioo_bufcnt;
555 struct ost_prolong_data opd = { 0 };
558 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
561 opd.opd_exp = req->rq_export;
562 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
563 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
564 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
566 /* prolong locks for the current service time of the corresponding
567 * portal (= OST_IO_PORTAL) */
568 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
569 max(at_est2timeout(at_get(&req->rq_rqbd->
570 rqbd_service->srv_at_estimate)), ldlm_timeout);
572 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
573 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
574 opd.opd_policy.l_extent.end);
576 if (oa->o_valid & OBD_MD_FLHANDLE) {
577 struct ldlm_lock *lock;
579 lock = ldlm_handle2lock(&oa->o_handle);
581 ost_prolong_locks_iter(lock, &opd);
582 if (opd.opd_lock_match) {
587 /* Check if the lock covers the whole IO region,
588 * otherwise iterate through the resource. */
589 if (lock->l_policy_data.l_extent.end >=
590 opd.opd_policy.l_extent.end &&
591 lock->l_policy_data.l_extent.start <=
592 opd.opd_policy.l_extent.start) {
601 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
602 ost_prolong_locks_iter, &opd);
603 RETURN(opd.opd_lock_match);
606 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
608 struct ptlrpc_bulk_desc *desc = NULL;
609 struct obd_export *exp = req->rq_export;
610 struct niobuf_remote *remote_nb;
611 struct niobuf_local *local_nb;
612 struct obd_ioobj *ioo;
613 struct ost_body *body, *repbody;
614 struct lustre_capa *capa = NULL;
615 struct l_wait_info lwi;
616 struct lustre_handle lockh = { 0 };
617 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
618 int niocount, npages, nob = 0, rc, i;
622 req->rq_bulk_read = 1;
624 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
625 GOTO(out, rc = -EIO);
627 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
629 /* Check if there is eviction in progress, and if so, wait for it to
631 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
632 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
633 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
634 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
638 GOTO(out, rc = -ENOTCONN);
640 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
641 * ost_rw_hpreq_check(). */
642 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
643 LASSERT(body != NULL);
645 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, sizeof(*ioo));
646 LASSERT(ioo != NULL);
648 niocount = ioo->ioo_bufcnt;
649 remote_nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
650 niocount * sizeof(*remote_nb));
651 LASSERT(remote_nb != NULL);
653 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
654 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
656 rc = lustre_pack_reply(req, 2, size, NULL);
661 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
664 local_nb = ost_tls(req)->local;
666 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
671 * If getting the lock took more time than
672 * client was willing to wait, drop it. b=11330
674 if (cfs_time_current_sec() > req->rq_deadline ||
675 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
677 CERROR("Dropping timed-out read from %s because locking"
678 "object "LPX64" took %ld seconds (limit was %ld).\n",
679 libcfs_id2str(req->rq_peer), ioo->ioo_id,
680 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
681 req->rq_deadline - req->rq_arrival_time.tv_sec);
682 GOTO(out_lock, rc = -ETIMEDOUT);
685 npages = OST_THREAD_POOL_SIZE;
686 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
687 remote_nb, &npages, local_nb, oti, capa);
691 desc = ptlrpc_prep_bulk_exp(req, npages,
692 BULK_PUT_SOURCE, OST_BULK_PORTAL);
693 if (desc == NULL) /* XXX: check all cleanup stuff */
694 GOTO(out, rc = -ENOMEM);
696 ost_rw_prolong_locks(req, ioo, remote_nb, &body->oa, LCK_PW | LCK_PR);
699 for (i = 0; i < npages; i++) {
700 int page_rc = local_nb[i].rc;
702 if (page_rc < 0) { /* error */
708 if (page_rc != 0) { /* some data! */
709 LASSERT (local_nb[i].page != NULL);
710 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
711 local_nb[i].offset & ~CFS_PAGE_MASK,
715 if (page_rc != local_nb[i].len) { /* short read */
716 /* All subsequent pages should be 0 */
718 LASSERT(local_nb[i].rc == 0);
723 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
724 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
726 if (body->oa.o_valid & OBD_MD_FLFLAGS)
727 cksum_type = cksum_type_unpack(body->oa.o_flags);
728 body->oa.o_flags = cksum_type_pack(cksum_type);
729 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
730 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
731 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
733 body->oa.o_valid = 0;
735 /* We're finishing using body->oa as an input variable */
737 /* Check if client was evicted while we were doing i/o before touching
740 /* Check if there is eviction in progress, and if so, wait for
742 if (unlikely(atomic_read(&exp->exp_obd->
743 obd_evict_inprogress))) {
744 lwi = LWI_INTR(NULL, NULL);
745 rc = l_wait_event(exp->exp_obd->
746 obd_evict_inprogress_waitq,
747 !atomic_read(&exp->exp_obd->
748 obd_evict_inprogress),
754 sptlrpc_svc_wrap_bulk(req, desc);
756 rc = ptlrpc_start_bulk_transfer(desc);
760 time_t start = cfs_time_current_sec();
762 long timeoutl = req->rq_deadline -
763 cfs_time_current_sec();
764 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
765 CFS_TICK : cfs_time_seconds(timeoutl);
766 lwi = LWI_TIMEOUT_INTERVAL(timeout,
770 rc = l_wait_event(desc->bd_waitq,
771 !ptlrpc_server_bulk_active(desc) ||
772 exp->exp_failed, &lwi);
773 LASSERT(rc == 0 || rc == -ETIMEDOUT);
774 /* Wait again if we changed deadline */
775 } while ((rc == -ETIMEDOUT) &&
776 (req->rq_deadline > cfs_time_current_sec()));
778 if (rc == -ETIMEDOUT) {
779 DEBUG_REQ(D_ERROR, req,
780 "timeout on bulk PUT after %ld%+lds",
781 req->rq_deadline - start,
782 cfs_time_current_sec() -
784 ptlrpc_abort_bulk(desc);
785 } else if (exp->exp_failed) {
786 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
788 ptlrpc_abort_bulk(desc);
789 } else if (!desc->bd_success ||
790 desc->bd_nob_transferred != desc->bd_nob) {
791 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
793 "truncated" : "network error on",
794 desc->bd_nob_transferred,
796 /* XXX should this be a different errno? */
800 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
805 /* Must commit after prep above in all cases */
806 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
807 remote_nb, npages, local_nb, oti, rc);
810 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
812 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
813 ost_drop_id(exp, &repbody->oa);
817 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
820 ptlrpc_free_bulk(desc);
824 req->rq_status = nob;
825 ptlrpc_lprocfs_brw(req, nob);
826 target_committed_to_req(req);
828 } else if (!no_reply) {
829 /* Only reply if there was no comms problem with bulk */
830 target_committed_to_req(req);
834 /* reply out callback would free */
835 ptlrpc_req_drop_rs(req);
836 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
837 "client will retry\n",
838 exp->exp_obd->obd_name,
839 exp->exp_client_uuid.uuid,
840 exp->exp_connection->c_remote_uuid.uuid,
841 libcfs_id2str(req->rq_peer));
847 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
849 struct ptlrpc_bulk_desc *desc = NULL;
850 struct obd_export *exp = req->rq_export;
851 struct niobuf_remote *remote_nb;
852 struct niobuf_local *local_nb;
853 struct obd_ioobj *ioo;
854 struct ost_body *body, *repbody;
855 struct l_wait_info lwi;
856 struct lustre_handle lockh = {0};
857 struct lustre_capa *capa = NULL;
859 __u32 size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
860 int objcount, niocount, npages;
862 obd_count client_cksum = 0, server_cksum = 0;
863 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
865 __u32 o_uid = 0, o_gid = 0;
868 req->rq_bulk_write = 1;
870 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
871 GOTO(out, rc = -EIO);
872 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
873 GOTO(out, rc = -EFAULT);
875 /* pause before transaction has been started */
876 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
878 /* Check if there is eviction in progress, and if so, wait for it to
880 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
881 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
882 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
883 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
887 GOTO(out, rc = -ENOTCONN);
889 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
890 * ost_rw_hpreq_check(). */
891 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
892 LASSERT(body != NULL);
894 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
896 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
897 objcount * sizeof(*ioo));
898 LASSERT(ioo != NULL);
899 for (niocount = i = 0; i < objcount; i++)
900 niocount += ioo[i].ioo_bufcnt;
902 remote_nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
903 niocount * sizeof(*remote_nb));
904 LASSERT(remote_nb != NULL);
906 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
907 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
909 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
910 rc = lustre_pack_reply(req, 3, size, NULL);
913 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, obd_fail_val);
914 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
915 niocount * sizeof(*rcs));
918 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
921 local_nb = ost_tls(req)->local;
923 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
928 * If getting the lock took more time than
929 * client was willing to wait, drop it. b=11330
931 if (cfs_time_current_sec() > req->rq_deadline ||
932 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
934 CERROR("Dropping timed-out write from %s because locking "
935 "object "LPX64" took %ld seconds (limit was %ld).\n",
936 libcfs_id2str(req->rq_peer), ioo->ioo_id,
937 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
938 req->rq_deadline - req->rq_arrival_time.tv_sec);
939 GOTO(out_lock, rc = -ETIMEDOUT);
942 ost_rw_prolong_locks(req, ioo, remote_nb,&body->oa, LCK_PW);
944 /* obd_preprw clobbers oa->valid, so save what we need */
945 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
946 client_cksum = body->oa.o_cksum;
947 if (body->oa.o_valid & OBD_MD_FLFLAGS)
948 cksum_type = cksum_type_unpack(body->oa.o_flags);
951 /* Because we already sync grant info with client when reconnect,
952 * grant info will be cleared for resent req, then fed_grant and
953 * total_grant will not be modified in following preprw_write */
954 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
955 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
956 body->oa.o_valid &= ~OBD_MD_FLGRANT;
959 if (exp_connect_rmtclient(exp)) {
960 o_uid = body->oa.o_uid;
961 o_gid = body->oa.o_gid;
963 npages = OST_THREAD_POOL_SIZE;
964 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
965 ioo, remote_nb, &npages, local_nb, oti, capa);
969 desc = ptlrpc_prep_bulk_exp(req, npages,
970 BULK_GET_SINK, OST_BULK_PORTAL);
972 GOTO(out, rc = -ENOMEM);
974 /* NB Having prepped, we must commit... */
976 for (i = 0; i < npages; i++)
977 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
978 local_nb[i].offset & ~CFS_PAGE_MASK,
981 /* Check if client was evicted while we were doing i/o before touching
983 if (desc->bd_export->exp_failed)
986 rc = ptlrpc_start_bulk_transfer(desc);
988 time_t start = cfs_time_current_sec();
990 long timeoutl = req->rq_deadline -
991 cfs_time_current_sec();
992 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
993 CFS_TICK : cfs_time_seconds(timeoutl);
994 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
995 ost_bulk_timeout, desc);
996 rc = l_wait_event(desc->bd_waitq,
997 !ptlrpc_server_bulk_active(desc) ||
998 desc->bd_export->exp_failed, &lwi);
999 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1000 /* Wait again if we changed deadline */
1001 } while ((rc == -ETIMEDOUT) &&
1002 (req->rq_deadline > cfs_time_current_sec()));
1004 if (rc == -ETIMEDOUT) {
1005 DEBUG_REQ(D_ERROR, req,
1006 "timeout on bulk GET after %ld%+lds",
1007 req->rq_deadline - start,
1008 cfs_time_current_sec() -
1010 ptlrpc_abort_bulk(desc);
1011 } else if (desc->bd_export->exp_failed) {
1012 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1014 ptlrpc_abort_bulk(desc);
1015 } else if (!desc->bd_success ||
1016 desc->bd_nob_transferred != desc->bd_nob) {
1017 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1019 "truncated" : "network error on",
1020 desc->bd_nob_transferred, desc->bd_nob);
1021 /* XXX should this be a different errno? */
1025 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1030 sptlrpc_svc_unwrap_bulk(req, desc);
1032 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1034 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1036 if (unlikely(client_cksum != 0 && rc == 0)) {
1037 static int cksum_counter;
1038 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1039 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1040 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1041 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1042 repbody->oa.o_cksum = server_cksum;
1044 if (unlikely(client_cksum != server_cksum)) {
1045 CERROR("client csum %x, server csum %x\n",
1046 client_cksum, server_cksum);
1048 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1049 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1050 cksum_counter, libcfs_id2str(req->rq_peer),
1055 /* Must commit after prep above in all cases */
1056 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1057 remote_nb, npages, local_nb, oti, rc);
1058 if (exp_connect_rmtclient(exp)) {
1059 repbody->oa.o_uid = o_uid;
1060 repbody->oa.o_gid = o_gid;
1063 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1064 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1069 if (new_cksum == server_cksum)
1070 msg = "changed in transit before arrival at OST";
1071 else if (new_cksum == client_cksum)
1072 msg = "initial checksum before message complete";
1074 msg = "changed in transit AND after initial checksum";
1076 if (req->rq_peer.nid == desc->bd_sender) {
1080 router = libcfs_nid2str(desc->bd_sender);
1083 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1084 "%s%s%s inum "LPU64"/"LPU64" object "
1085 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1086 exp->exp_obd->obd_name, msg,
1087 libcfs_id2str(req->rq_peer),
1089 body->oa.o_valid & OBD_MD_FLFID ?
1090 body->oa.o_fid : (__u64)0,
1091 body->oa.o_valid & OBD_MD_FLFID ?
1092 body->oa.o_generation :(__u64)0,
1094 body->oa.o_valid & OBD_MD_FLGROUP ?
1095 body->oa.o_gr : (__u64)0,
1097 local_nb[npages-1].offset +
1098 local_nb[npages-1].len - 1 );
1099 CERROR("client csum %x, original server csum %x, "
1100 "server csum now %x\n",
1101 client_cksum, server_cksum, new_cksum);
1107 /* set per-requested niobuf return codes */
1108 for (i = j = 0; i < niocount; i++) {
1109 int len = remote_nb[i].len;
1114 LASSERT(j < npages);
1115 if (local_nb[j].rc < 0)
1116 rcs[i] = local_nb[j].rc;
1117 len -= local_nb[j].len;
1122 LASSERT(j == npages);
1123 ptlrpc_lprocfs_brw(req, nob);
1127 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1130 ptlrpc_free_bulk(desc);
1133 oti_to_request(oti, req);
1134 target_committed_to_req(req);
1135 rc = ptlrpc_reply(req);
1136 } else if (!no_reply) {
1137 /* Only reply if there was no comms problem with bulk */
1138 target_committed_to_req(req);
1139 req->rq_status = rc;
1142 /* reply out callback would free */
1143 ptlrpc_req_drop_rs(req);
1144 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1145 "client will retry\n",
1146 exp->exp_obd->obd_name,
1147 exp->exp_client_uuid.uuid,
1148 exp->exp_connection->c_remote_uuid.uuid,
1149 libcfs_id2str(req->rq_peer));
1154 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1156 char *key, *val = NULL;
1157 int keylen, vallen, rc = 0;
1160 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1162 DEBUG_REQ(D_HA, req, "no set_info key");
1165 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1167 rc = lustre_pack_reply(req, 1, NULL, NULL);
1171 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1173 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
1175 if (KEY_IS(KEY_EVICT_BY_NID)) {
1177 obd_export_evict_by_nid(exp->exp_obd, val);
1182 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1184 lustre_msg_set_status(req->rq_repmsg, 0);
1188 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1191 int keylen, replylen, rc = 0;
1192 struct req_capsule *pill = &req->rq_pill;
1195 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
1197 /* this common part for get_info rpc */
1198 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1200 DEBUG_REQ(D_HA, req, "no get_info key");
1203 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1205 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1209 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1210 RCL_SERVER, replylen);
1212 rc = req_capsule_server_pack(pill);
1216 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1220 /* call again to fill in the reply buffer */
1221 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1223 lustre_msg_set_status(req->rq_repmsg, 0);
1227 #ifdef HAVE_QUOTA_SUPPORT
1228 static int ost_handle_quotactl(struct ptlrpc_request *req)
1230 struct obd_quotactl *oqctl, *repoqc;
1234 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1236 GOTO(out, rc = -EPROTO);
1238 rc = req_capsule_server_pack(&req->rq_pill);
1242 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1243 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1250 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1252 struct obd_quotactl *oqctl;
1256 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1260 rc = req_capsule_server_pack(&req->rq_pill);
1264 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1268 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1270 struct quota_adjust_qunit *oqaq, *repoqa;
1271 struct lustre_quota_ctxt *qctxt;
1275 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1276 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1278 GOTO(out, rc = -EPROTO);
1280 rc = req_capsule_server_pack(&req->rq_pill);
1284 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1285 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt);
1293 static int ost_llog_handle_connect(struct obd_export *exp,
1294 struct ptlrpc_request *req)
1296 struct llogd_conn_body *body;
1300 body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body));
1301 rc = obd_llog_connect(exp, body);
1305 #define ost_init_sec_none(reply, exp) \
1307 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1308 OBD_CONNECT_RMT_CLIENT_FORCE | \
1309 OBD_CONNECT_OSS_CAPA); \
1310 spin_lock(&exp->exp_lock); \
1311 exp->exp_connect_flags = reply->ocd_connect_flags; \
1312 spin_unlock(&exp->exp_lock); \
1315 static int ost_init_sec_level(struct ptlrpc_request *req)
1317 struct obd_export *exp = req->rq_export;
1318 struct req_capsule *pill = &req->rq_pill;
1319 struct obd_device *obd = exp->exp_obd;
1320 struct filter_obd *filter = &obd->u.filter;
1321 char *client = libcfs_nid2str(req->rq_peer.nid);
1322 struct obd_connect_data *data, *reply;
1326 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1327 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1328 if (data == NULL || reply == NULL)
1331 /* connection from MDT is always trusted */
1332 if (req->rq_auth_usr_mdt) {
1333 ost_init_sec_none(reply, exp);
1337 /* no GSS support case */
1338 if (!req->rq_auth_gss) {
1339 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1340 CWARN("client %s -> target %s does not user GSS, "
1341 "can not run under security level %d.\n",
1342 client, obd->obd_name, filter->fo_sec_level);
1345 ost_init_sec_none(reply, exp);
1350 /* old version case */
1351 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1352 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1353 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1354 CWARN("client %s -> target %s uses old version, "
1355 "can not run under security level %d.\n",
1356 client, obd->obd_name, filter->fo_sec_level);
1359 CWARN("client %s -> target %s uses old version, "
1360 "run under security level %d.\n",
1361 client, obd->obd_name, filter->fo_sec_level);
1362 ost_init_sec_none(reply, exp);
1367 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1369 if (!req->rq_auth_remote)
1370 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1371 "asked to be remote.\n", client, obd->obd_name);
1372 } else if (req->rq_auth_remote) {
1374 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1375 "as remote by default.\n", client, obd->obd_name);
1379 if (!filter->fo_fl_oss_capa) {
1380 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1381 " but OSS capabilities are not enabled: %d.\n",
1382 client, obd->obd_name, filter->fo_fl_oss_capa);
1387 switch (filter->fo_sec_level) {
1388 case LUSTRE_SEC_NONE:
1390 ost_init_sec_none(reply, exp);
1393 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1394 "can not run under security level %d.\n",
1395 client, obd->obd_name, filter->fo_sec_level);
1398 case LUSTRE_SEC_REMOTE:
1400 ost_init_sec_none(reply, exp);
1402 case LUSTRE_SEC_ALL:
1404 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1405 OBD_CONNECT_RMT_CLIENT_FORCE);
1406 if (!filter->fo_fl_oss_capa)
1407 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1409 spin_lock(&exp->exp_lock);
1410 exp->exp_connect_flags = reply->ocd_connect_flags;
1411 spin_unlock(&exp->exp_lock);
1423 * this should be done in filter_connect()/filter_reconnect(), but
1424 * we can't obtain information like NID, which stored in incoming
1425 * request, thus can't decide what flavor to use. so we do it here.
1427 * This hack should be removed after the OST stack be rewritten, just
1428 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1430 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1432 struct obd_export *exp = req->rq_export;
1433 struct filter_obd *filter = &exp->exp_obd->u.filter;
1434 struct sptlrpc_flavor flvr;
1437 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1438 read_lock(&filter->fo_sptlrpc_lock);
1439 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1443 read_unlock(&filter->fo_sptlrpc_lock);
1445 spin_lock(&exp->exp_lock);
1447 exp->exp_sp_peer = req->rq_sp_from;
1448 exp->exp_flvr = flvr;
1450 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1451 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1452 CERROR("unauthorized rpc flavor %x from %s, "
1453 "expect %x\n", req->rq_flvr.sf_rpc,
1454 libcfs_nid2str(req->rq_peer.nid),
1455 exp->exp_flvr.sf_rpc);
1459 spin_unlock(&exp->exp_lock);
1461 if (exp->exp_sp_peer != req->rq_sp_from) {
1462 CERROR("RPC source %s doesn't match %s\n",
1463 sptlrpc_part2name(req->rq_sp_from),
1464 sptlrpc_part2name(exp->exp_sp_peer));
1467 rc = sptlrpc_target_export_check(exp, req);
1474 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1475 struct obd_device *obd, int *process)
1477 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1478 case OST_CONNECT: /* This will never get here, but for completeness. */
1479 case OST_DISCONNECT:
1490 case OBD_LOG_CANCEL:
1492 *process = target_queue_recovery_request(req, obd);
1496 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1502 int ost_msg_check_version(struct lustre_msg *msg)
1506 switch(lustre_msg_get_opc(msg)) {
1508 case OST_DISCONNECT:
1511 case SEC_CTX_INIT_CONT:
1513 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1515 CERROR("bad opc %u version %08x, expecting %08x\n",
1516 lustre_msg_get_opc(msg),
1517 lustre_msg_get_version(msg),
1518 LUSTRE_OBD_VERSION);
1531 #ifdef HAVE_QUOTA_SUPPORT
1532 case OST_QUOTACHECK:
1534 case OST_QUOTA_ADJUST_QUNIT:
1536 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1538 CERROR("bad opc %u version %08x, expecting %08x\n",
1539 lustre_msg_get_opc(msg),
1540 lustre_msg_get_version(msg),
1541 LUSTRE_OST_VERSION);
1546 case LDLM_BL_CALLBACK:
1547 case LDLM_CP_CALLBACK:
1548 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1550 CERROR("bad opc %u version %08x, expecting %08x\n",
1551 lustre_msg_get_opc(msg),
1552 lustre_msg_get_version(msg),
1553 LUSTRE_DLM_VERSION);
1555 case LLOG_ORIGIN_CONNECT:
1556 case OBD_LOG_CANCEL:
1557 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1559 CERROR("bad opc %u version %08x, expecting %08x\n",
1560 lustre_msg_get_opc(msg),
1561 lustre_msg_get_version(msg),
1562 LUSTRE_LOG_VERSION);
1565 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1571 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1572 struct ldlm_lock *lock)
1574 struct niobuf_remote *nb;
1575 struct obd_ioobj *ioo;
1576 struct ost_body *body;
1577 int objcount, niocount;
1582 opc = lustre_msg_get_opc(req->rq_reqmsg);
1583 LASSERT(opc == OST_READ || opc == OST_WRITE);
1585 /* As the request may be covered by several locks, do not look at
1586 * o_handle, look at the RPC IO region. */
1587 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
1589 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
1591 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
1592 objcount * sizeof(*ioo));
1593 LASSERT(ioo != NULL);
1594 for (niocount = i = 0; i < objcount; i++)
1595 niocount += ioo[i].ioo_bufcnt;
1597 nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
1598 niocount * sizeof(*nb));
1599 LASSERT(nb != NULL);
1602 if (opc == OST_READ)
1605 start = nb[0].offset & CFS_PAGE_MASK;
1606 end = (nb[ioo->ioo_bufcnt - 1].offset +
1607 nb[ioo->ioo_bufcnt - 1].len - 1) | ~CFS_PAGE_MASK;
1609 if (!(lock->l_granted_mode & mode))
1612 if (lock->l_policy_data.l_extent.end < start ||
1613 lock->l_policy_data.l_extent.start > end)
1620 * Swab buffers needed to call ost_rw_prolong_locks() and call it.
1621 * Return the value from ost_rw_prolong_locks() which is non-zero if
1622 * there is a cancelled lock which is waiting for this IO request.
1624 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1626 struct niobuf_remote *nb;
1627 struct obd_ioobj *ioo;
1628 struct ost_body *body;
1629 int objcount, niocount;
1633 opc = lustre_msg_get_opc(req->rq_reqmsg);
1634 LASSERT(opc == OST_READ || opc == OST_WRITE);
1636 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
1637 LASSERT(body != NULL);
1639 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
1641 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
1642 objcount * sizeof(*ioo));
1643 LASSERT(ioo != NULL);
1645 for (niocount = i = 0; i < objcount; i++)
1646 niocount += ioo[i].ioo_bufcnt;
1647 nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
1648 niocount * sizeof(*nb));
1649 LASSERT(nb != NULL);
1650 LASSERT(niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK));
1653 if (opc == OST_READ)
1655 RETURN(ost_rw_prolong_locks(req, ioo, nb, &body->oa, mode));
1658 static int ost_punch_prolong_locks(struct ptlrpc_request *req, struct obdo *oa)
1660 struct ldlm_res_id res_id = { .name = { oa->o_id } };
1661 struct ost_prolong_data opd = { 0 };
1666 end = start + oa->o_blocks;
1668 opd.opd_mode = LCK_PW;
1669 opd.opd_exp = req->rq_export;
1670 opd.opd_policy.l_extent.start = start & CFS_PAGE_MASK;
1671 if (oa->o_blocks == OBD_OBJECT_EOF || end < start)
1672 opd.opd_policy.l_extent.end = OBD_OBJECT_EOF;
1674 opd.opd_policy.l_extent.end = end | ~CFS_PAGE_MASK;
1676 /* prolong locks for the current service time of the corresponding
1677 * portal (= OST_IO_PORTAL) */
1678 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
1679 max(at_est2timeout(at_get(&req->rq_rqbd->
1680 rqbd_service->srv_at_estimate)), ldlm_timeout);
1682 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1683 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
1684 opd.opd_policy.l_extent.end);
1687 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
1688 ost_prolong_locks_iter, &opd);
1689 RETURN(opd.opd_lock_match);
1692 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1693 struct ldlm_lock *lock)
1695 struct ost_body *body;
1698 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
1700 LASSERT(body != NULL);
1702 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1703 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1708 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1710 struct ost_body *body = lustre_msg_buf(req->rq_reqmsg,
1711 REQ_REC_OFF, sizeof(*body));
1712 LASSERT(body != NULL);
1713 LASSERT(!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1714 !(body->oa.o_flags & OBD_FL_TRUNCLOCK));
1716 RETURN(ost_punch_prolong_locks(req, &body->oa));
1719 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
1720 .hpreq_lock_match = ost_rw_hpreq_lock_match,
1721 .hpreq_check = ost_rw_hpreq_check,
1724 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
1725 .hpreq_lock_match = ost_punch_hpreq_lock_match,
1726 .hpreq_check = ost_punch_hpreq_check,
1729 /** Assign high priority operations to the request if needed. */
1730 static int ost_hpreq_handler(struct ptlrpc_request *req)
1733 if (req->rq_export) {
1734 int opc = lustre_msg_get_opc(req->rq_reqmsg);
1735 struct ost_body *body;
1737 if (opc == OST_READ || opc == OST_WRITE) {
1738 struct niobuf_remote *nb;
1739 struct obd_ioobj *ioo;
1740 int objcount, niocount;
1743 body = lustre_swab_reqbuf(req, REQ_REC_OFF,
1747 CERROR("Missing/short ost_body\n");
1750 objcount = lustre_msg_buflen(req->rq_reqmsg,
1753 if (objcount == 0) {
1754 CERROR("Missing/short ioobj\n");
1758 CERROR("too many ioobjs (%d)\n", objcount);
1762 swab = !lustre_req_swabbed(req, REQ_REC_OFF + 1) &&
1763 lustre_msg_swabbed(req->rq_reqmsg);
1764 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1,
1765 objcount * sizeof(*ioo),
1766 lustre_swab_obd_ioobj);
1768 CERROR("Missing/short ioobj\n");
1771 for (niocount = i = 0; i < objcount; i++) {
1773 lustre_swab_obd_ioobj(&ioo[i]);
1774 if (ioo[i].ioo_bufcnt == 0) {
1775 CERROR("ioo[%d] has zero bufcnt\n", i);
1778 niocount += ioo[i].ioo_bufcnt;
1780 if (niocount > PTLRPC_MAX_BRW_PAGES) {
1781 DEBUG_REQ(D_ERROR, req, "bulk has too many "
1782 "pages (%d)", niocount);
1786 swab = !lustre_req_swabbed(req, REQ_REC_OFF + 2) &&
1787 lustre_msg_swabbed(req->rq_reqmsg);
1788 nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
1789 niocount * sizeof(*nb),
1790 lustre_swab_niobuf_remote);
1792 CERROR("Missing/short niobuf\n");
1797 /* swab remaining niobufs */
1798 for (i = 1; i < niocount; i++)
1799 lustre_swab_niobuf_remote(&nb[i]);
1802 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
1803 req->rq_ops = &ost_hpreq_rw;
1804 } else if (opc == OST_PUNCH) {
1805 body = lustre_swab_reqbuf(req, REQ_REC_OFF,
1809 CERROR("Missing/short ost_body\n");
1813 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1814 !(body->oa.o_flags & OBD_FL_TRUNCLOCK))
1815 req->rq_ops = &ost_hpreq_punch;
1821 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1822 int ost_handle(struct ptlrpc_request *req)
1824 struct obd_trans_info trans_info = { 0, };
1825 struct obd_trans_info *oti = &trans_info;
1826 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1827 struct obd_device *obd = NULL;
1830 LASSERT(current->journal_info == NULL);
1832 /* primordial rpcs don't affect server recovery */
1833 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1835 case SEC_CTX_INIT_CONT:
1840 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1842 /* XXX identical to MDS */
1843 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1846 if (req->rq_export == NULL) {
1847 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1848 lustre_msg_get_opc(req->rq_reqmsg),
1849 libcfs_id2str(req->rq_peer));
1850 req->rq_status = -ENOTCONN;
1851 GOTO(out, rc = -ENOTCONN);
1854 obd = req->rq_export->exp_obd;
1856 /* Check for aborted recovery. */
1857 spin_lock_bh(&obd->obd_processing_task_lock);
1858 recovering = obd->obd_recovering;
1859 spin_unlock_bh(&obd->obd_processing_task_lock);
1861 rc = ost_filter_recovery_request(req, obd,
1863 if (rc || !should_process)
1865 else if (should_process < 0) {
1866 req->rq_status = should_process;
1867 rc = ptlrpc_error(req);
1875 rc = ost_msg_check_version(req->rq_reqmsg);
1879 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1881 CDEBUG(D_INODE, "connect\n");
1882 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
1883 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
1885 rc = target_handle_connect(req);
1886 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
1889 rc = ost_init_sec_level(req);
1891 rc = ost_connect_check_sptlrpc(req);
1895 case OST_DISCONNECT:
1896 CDEBUG(D_INODE, "disconnect\n");
1897 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
1898 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
1900 rc = target_handle_disconnect(req);
1903 CDEBUG(D_INODE, "create\n");
1904 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
1906 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1907 GOTO(out, rc = -ENOSPC);
1908 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1909 GOTO(out, rc = -EROFS);
1910 rc = ost_create(req->rq_export, req, oti);
1913 CDEBUG(D_INODE, "destroy\n");
1914 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
1916 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1917 GOTO(out, rc = -EROFS);
1918 rc = ost_destroy(req->rq_export, req, oti);
1921 CDEBUG(D_INODE, "getattr\n");
1922 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
1924 rc = ost_getattr(req->rq_export, req);
1927 CDEBUG(D_INODE, "setattr\n");
1928 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
1930 rc = ost_setattr(req->rq_export, req, oti);
1933 CDEBUG(D_INODE, "write\n");
1934 /* req->rq_request_portal would be nice, if it was set */
1935 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1936 CERROR("%s: deny write request from %s to portal %u\n",
1937 req->rq_export->exp_obd->obd_name,
1938 obd_export_nid2str(req->rq_export),
1939 req->rq_rqbd->rqbd_service->srv_req_portal);
1940 GOTO(out, rc = -EPROTO);
1942 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1944 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1945 GOTO(out, rc = -ENOSPC);
1946 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1947 GOTO(out, rc = -EROFS);
1948 rc = ost_brw_write(req, oti);
1949 LASSERT(current->journal_info == NULL);
1950 /* ost_brw_write sends its own replies */
1953 CDEBUG(D_INODE, "read\n");
1954 /* req->rq_request_portal would be nice, if it was set */
1955 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1956 CERROR("%s: deny read request from %s to portal %u\n",
1957 req->rq_export->exp_obd->obd_name,
1958 obd_export_nid2str(req->rq_export),
1959 req->rq_rqbd->rqbd_service->srv_req_portal);
1960 GOTO(out, rc = -EPROTO);
1962 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1964 rc = ost_brw_read(req, oti);
1965 LASSERT(current->journal_info == NULL);
1966 /* ost_brw_read sends its own replies */
1969 CDEBUG(D_INODE, "punch\n");
1970 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
1972 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1973 GOTO(out, rc = -EROFS);
1974 rc = ost_punch(req->rq_export, req, oti);
1977 CDEBUG(D_INODE, "statfs\n");
1978 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
1980 rc = ost_statfs(req);
1983 CDEBUG(D_INODE, "sync\n");
1984 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
1986 rc = ost_sync(req->rq_export, req);
1989 DEBUG_REQ(D_INODE, req, "set_info");
1990 req_capsule_set(&req->rq_pill, &RQF_OST_SET_INFO);
1991 rc = ost_set_info(req->rq_export, req);
1994 DEBUG_REQ(D_INODE, req, "get_info");
1995 rc = ost_get_info(req->rq_export, req);
1997 #ifdef HAVE_QUOTA_SUPPORT
1998 case OST_QUOTACHECK:
1999 CDEBUG(D_INODE, "quotacheck\n");
2000 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2001 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2003 rc = ost_handle_quotacheck(req);
2006 CDEBUG(D_INODE, "quotactl\n");
2007 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2008 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2010 rc = ost_handle_quotactl(req);
2012 case OST_QUOTA_ADJUST_QUNIT:
2013 CDEBUG(D_INODE, "quota_adjust_qunit\n");
2014 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
2015 rc = ost_handle_quota_adjust_qunit(req);
2019 DEBUG_REQ(D_INODE, req, "ping");
2020 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2021 rc = target_handle_ping(req);
2023 /* FIXME - just reply status */
2024 case LLOG_ORIGIN_CONNECT:
2025 DEBUG_REQ(D_INODE, req, "log connect");
2026 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2027 rc = ost_llog_handle_connect(req->rq_export, req);
2028 req->rq_status = rc;
2029 rc = req_capsule_server_pack(&req->rq_pill);
2032 RETURN(ptlrpc_reply(req));
2033 case OBD_LOG_CANCEL:
2034 CDEBUG(D_INODE, "log cancel\n");
2035 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2036 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2038 rc = llog_origin_handle_cancel(req);
2039 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2041 req->rq_status = rc;
2042 rc = req_capsule_server_pack(&req->rq_pill);
2045 RETURN(ptlrpc_reply(req));
2047 CDEBUG(D_INODE, "enqueue\n");
2048 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2049 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2051 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2052 ldlm_server_blocking_ast,
2053 ldlm_server_glimpse_ast);
2054 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2057 CDEBUG(D_INODE, "convert\n");
2058 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2059 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2061 rc = ldlm_handle_convert(req);
2064 CDEBUG(D_INODE, "cancel\n");
2065 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2066 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2068 rc = ldlm_handle_cancel(req);
2070 case LDLM_BL_CALLBACK:
2071 case LDLM_CP_CALLBACK:
2072 CDEBUG(D_INODE, "callback\n");
2073 CERROR("callbacks should not happen on OST\n");
2076 CERROR("Unexpected opcode %d\n",
2077 lustre_msg_get_opc(req->rq_reqmsg));
2078 req->rq_status = -ENOTSUPP;
2079 rc = ptlrpc_error(req);
2083 LASSERT(current->journal_info == NULL);
2086 /* If we're DISCONNECTing, the export_data is already freed */
2087 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2088 target_committed_to_req(req);
2092 oti_to_request(oti, req);
2094 target_send_reply(req, rc, fail);
2097 EXPORT_SYMBOL(ost_handle);
2099 * free per-thread pool created by ost_thread_init().
2101 static void ost_thread_done(struct ptlrpc_thread *thread)
2103 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2108 LASSERT(thread != NULL);
2111 * be prepared to handle partially-initialized pools (because this is
2112 * called from ost_thread_init() for cleanup.
2114 tls = thread->t_data;
2117 thread->t_data = NULL;
2123 * initialize per-thread page pool (bug 5137).
2125 static int ost_thread_init(struct ptlrpc_thread *thread)
2127 struct ost_thread_local_cache *tls;
2131 LASSERT(thread != NULL);
2132 LASSERT(thread->t_data == NULL);
2133 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
2138 thread->t_data = tls;
2142 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2144 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2145 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2147 struct ost_obd *ost = &obd->u.ost;
2148 struct lprocfs_static_vars lvars;
2149 int oss_min_threads;
2150 int oss_max_threads;
2151 int oss_min_create_threads;
2152 int oss_max_create_threads;
2156 rc = cleanup_group_info();
2160 lprocfs_ost_init_vars(&lvars);
2161 lprocfs_obd_setup(obd, lvars.obd_vars);
2163 sema_init(&ost->ost_health_sem, 1);
2165 if (oss_num_threads) {
2166 /* If oss_num_threads is set, it is the min and the max. */
2167 if (oss_num_threads > OSS_THREADS_MAX)
2168 oss_num_threads = OSS_THREADS_MAX;
2169 if (oss_num_threads < OSS_THREADS_MIN)
2170 oss_num_threads = OSS_THREADS_MIN;
2171 oss_max_threads = oss_min_threads = oss_num_threads;
2173 /* Base min threads on memory and cpus */
2174 oss_min_threads = num_possible_cpus() * num_physpages >>
2175 (27 - CFS_PAGE_SHIFT);
2176 if (oss_min_threads < OSS_THREADS_MIN)
2177 oss_min_threads = OSS_THREADS_MIN;
2178 /* Insure a 4x range for dynamic threads */
2179 if (oss_min_threads > OSS_THREADS_MAX / 4)
2180 oss_min_threads = OSS_THREADS_MAX / 4;
2181 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
2185 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2186 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
2187 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2188 ost_handle, LUSTRE_OSS_NAME,
2189 obd->obd_proc_entry, target_print_req,
2190 oss_min_threads, oss_max_threads,
2191 "ll_ost", LCT_DT_THREAD, NULL);
2192 if (ost->ost_service == NULL) {
2193 CERROR("failed to start service\n");
2194 GOTO(out_lprocfs, rc = -ENOMEM);
2197 rc = ptlrpc_start_threads(obd, ost->ost_service);
2199 GOTO(out_service, rc = -EINVAL);
2201 if (oss_num_create_threads) {
2202 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
2203 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
2204 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
2205 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
2206 oss_min_create_threads = oss_max_create_threads =
2207 oss_num_create_threads;
2209 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
2210 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
2213 ost->ost_create_service =
2214 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2215 OST_MAXREPSIZE, OST_CREATE_PORTAL,
2216 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2217 ost_handle, "ost_create",
2218 obd->obd_proc_entry, target_print_req,
2219 oss_min_create_threads, oss_max_create_threads,
2220 "ll_ost_creat", LCT_DT_THREAD, NULL);
2221 if (ost->ost_create_service == NULL) {
2222 CERROR("failed to start OST create service\n");
2223 GOTO(out_service, rc = -ENOMEM);
2226 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
2228 GOTO(out_create, rc = -EINVAL);
2230 ost->ost_io_service =
2231 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2232 OST_MAXREPSIZE, OST_IO_PORTAL,
2233 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2234 ost_handle, "ost_io",
2235 obd->obd_proc_entry, target_print_req,
2236 oss_min_threads, oss_max_threads,
2237 "ll_ost_io", LCT_DT_THREAD, ost_hpreq_handler);
2238 if (ost->ost_io_service == NULL) {
2239 CERROR("failed to start OST I/O service\n");
2240 GOTO(out_create, rc = -ENOMEM);
2243 ost->ost_io_service->srv_init = ost_thread_init;
2244 ost->ost_io_service->srv_done = ost_thread_done;
2245 ost->ost_io_service->srv_cpu_affinity = 1;
2246 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
2248 GOTO(out_io, rc = -EINVAL);
2250 ping_evictor_start();
2255 ptlrpc_unregister_service(ost->ost_io_service);
2256 ost->ost_io_service = NULL;
2258 ptlrpc_unregister_service(ost->ost_create_service);
2259 ost->ost_create_service = NULL;
2261 ptlrpc_unregister_service(ost->ost_service);
2262 ost->ost_service = NULL;
2264 lprocfs_obd_cleanup(obd);
2268 static int ost_cleanup(struct obd_device *obd)
2270 struct ost_obd *ost = &obd->u.ost;
2274 ping_evictor_stop();
2276 spin_lock_bh(&obd->obd_processing_task_lock);
2277 if (obd->obd_recovering) {
2278 target_cancel_recovery_timer(obd);
2279 obd->obd_recovering = 0;
2281 spin_unlock_bh(&obd->obd_processing_task_lock);
2283 down(&ost->ost_health_sem);
2284 ptlrpc_unregister_service(ost->ost_service);
2285 ptlrpc_unregister_service(ost->ost_create_service);
2286 ptlrpc_unregister_service(ost->ost_io_service);
2287 ost->ost_service = NULL;
2288 ost->ost_create_service = NULL;
2289 up(&ost->ost_health_sem);
2291 lprocfs_obd_cleanup(obd);
2296 static int ost_health_check(struct obd_device *obd)
2298 struct ost_obd *ost = &obd->u.ost;
2301 down(&ost->ost_health_sem);
2302 rc |= ptlrpc_service_health_check(ost->ost_service);
2303 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2304 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2305 up(&ost->ost_health_sem);
2308 * health_check to return 0 on healthy
2309 * and 1 on unhealthy.
2317 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2319 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2322 /* use obd ops to offer management infrastructure */
2323 static struct obd_ops ost_obd_ops = {
2324 .o_owner = THIS_MODULE,
2325 .o_setup = ost_setup,
2326 .o_cleanup = ost_cleanup,
2327 .o_health_check = ost_health_check,
2331 static int __init ost_init(void)
2333 struct lprocfs_static_vars lvars;
2337 lprocfs_ost_init_vars(&lvars);
2338 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2339 LUSTRE_OSS_NAME, NULL);
2341 if (ost_num_threads != 0 && oss_num_threads == 0) {
2342 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2343 "use oss_num_threads instead or unset both for "
2344 "dynamic thread startup\n");
2345 oss_num_threads = ost_num_threads;
2351 static void /*__exit*/ ost_exit(void)
2353 class_unregister_type(LUSTRE_OSS_NAME);
2356 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2357 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2358 MODULE_LICENSE("GPL");
2360 module_init(ost_init);
2361 module_exit(ost_exit);