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;
500 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
502 struct ost_prolong_data *opd = data;
504 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
506 if (lock->l_req_mode != lock->l_granted_mode) {
507 /* scan granted locks only */
508 return LDLM_ITER_STOP;
511 if (lock->l_export != opd->opd_exp) {
512 /* prolong locks only for given client */
513 return LDLM_ITER_CONTINUE;
516 if (!(lock->l_granted_mode & opd->opd_mode)) {
517 /* we aren't interesting in all type of locks */
518 return LDLM_ITER_CONTINUE;
521 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
522 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
523 /* the request doesn't cross the lock, skip it */
524 return LDLM_ITER_CONTINUE;
527 /* Fill the obdo with the matched lock handle.
528 * XXX: it is possible in some cases the IO RPC is covered by several
529 * locks, even for the write case, so it may need to be a lock list. */
530 if (opd->opd_oa && !(opd->opd_oa->o_valid & OBD_MD_FLHANDLE)) {
531 opd->opd_oa->o_handle.cookie = lock->l_handle.h_cookie;
532 opd->opd_oa->o_valid |= OBD_MD_FLHANDLE;
535 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
536 /* ignore locks not being cancelled */
537 return LDLM_ITER_CONTINUE;
540 /* OK. this is a possible lock the user holds doing I/O
541 * let's refresh eviction timer for it */
542 ldlm_refresh_waiting_lock(lock);
543 opd->opd_lock_match = 1;
545 return LDLM_ITER_CONTINUE;
548 static int ost_rw_prolong_locks(struct obd_export *exp, struct obd_ioobj *obj,
549 struct niobuf_remote *nb, struct obdo *oa,
552 struct ldlm_res_id res_id;
553 int nrbufs = obj->ioo_bufcnt;
554 struct ost_prolong_data opd = { 0 };
557 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
561 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
562 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
563 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
565 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
566 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
567 opd.opd_policy.l_extent.end);
569 if (oa->o_valid & OBD_MD_FLHANDLE) {
570 struct ldlm_lock *lock;
572 lock = ldlm_handle2lock(&oa->o_handle);
574 ost_prolong_locks_iter(lock, &opd);
575 if (opd.opd_lock_match) {
580 /* Check if the lock covers the whole IO region,
581 * otherwise iterate through the resource. */
582 if (lock->l_policy_data.l_extent.end >=
583 opd.opd_policy.l_extent.end &&
584 lock->l_policy_data.l_extent.start <=
585 opd.opd_policy.l_extent.start) {
594 ldlm_resource_iterate(exp->exp_obd->obd_namespace, &res_id,
595 ost_prolong_locks_iter, &opd);
596 RETURN(opd.opd_lock_match);
599 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
601 struct ptlrpc_bulk_desc *desc = NULL;
602 struct obd_export *exp = req->rq_export;
603 struct niobuf_remote *remote_nb;
604 struct niobuf_local *local_nb;
605 struct obd_ioobj *ioo;
606 struct ost_body *body, *repbody;
607 struct lustre_capa *capa = NULL;
608 struct l_wait_info lwi;
609 struct lustre_handle lockh = { 0 };
610 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
611 int niocount, npages, nob = 0, rc, i;
615 req->rq_bulk_read = 1;
617 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
618 GOTO(out, rc = -EIO);
620 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
622 /* Check if there is eviction in progress, and if so, wait for it to
624 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
625 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
626 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
627 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
631 GOTO(out, rc = -ENOTCONN);
633 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
634 * ost_rw_hpreq_check(). */
635 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
636 LASSERT(body != NULL);
638 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, sizeof(*ioo));
639 LASSERT(ioo != NULL);
641 niocount = ioo->ioo_bufcnt;
642 remote_nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
643 niocount * sizeof(*remote_nb));
644 LASSERT(remote_nb != NULL);
646 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
647 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
649 rc = lustre_pack_reply(req, 2, size, NULL);
654 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
657 local_nb = ost_tls(req)->local;
659 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
664 * If getting the lock took more time than
665 * client was willing to wait, drop it. b=11330
667 if (cfs_time_current_sec() > req->rq_deadline ||
668 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
670 CERROR("Dropping timed-out read from %s because locking"
671 "object "LPX64" took %ld seconds (limit was %ld).\n",
672 libcfs_id2str(req->rq_peer), ioo->ioo_id,
673 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
674 req->rq_deadline - req->rq_arrival_time.tv_sec);
675 GOTO(out_lock, rc = -ETIMEDOUT);
678 npages = OST_THREAD_POOL_SIZE;
679 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
680 remote_nb, &npages, local_nb, oti, capa);
684 desc = ptlrpc_prep_bulk_exp(req, npages,
685 BULK_PUT_SOURCE, OST_BULK_PORTAL);
686 if (desc == NULL) /* XXX: check all cleanup stuff */
687 GOTO(out, rc = -ENOMEM);
689 ost_rw_prolong_locks(exp, ioo, remote_nb, &body->oa, LCK_PW | LCK_PR);
692 for (i = 0; i < npages; i++) {
693 int page_rc = local_nb[i].rc;
695 if (page_rc < 0) { /* error */
701 if (page_rc != 0) { /* some data! */
702 LASSERT (local_nb[i].page != NULL);
703 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
704 local_nb[i].offset & ~CFS_PAGE_MASK,
708 if (page_rc != local_nb[i].len) { /* short read */
709 /* All subsequent pages should be 0 */
711 LASSERT(local_nb[i].rc == 0);
716 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
717 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
719 if (body->oa.o_valid & OBD_MD_FLFLAGS)
720 cksum_type = cksum_type_unpack(body->oa.o_flags);
721 body->oa.o_flags = cksum_type_pack(cksum_type);
722 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
723 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
724 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
726 body->oa.o_valid = 0;
728 /* We're finishing using body->oa as an input variable */
730 /* Check if client was evicted while we were doing i/o before touching
733 /* Check if there is eviction in progress, and if so, wait for
735 if (unlikely(atomic_read(&exp->exp_obd->
736 obd_evict_inprogress))) {
737 lwi = LWI_INTR(NULL, NULL);
738 rc = l_wait_event(exp->exp_obd->
739 obd_evict_inprogress_waitq,
740 !atomic_read(&exp->exp_obd->
741 obd_evict_inprogress),
747 sptlrpc_svc_wrap_bulk(req, desc);
749 rc = ptlrpc_start_bulk_transfer(desc);
753 time_t start = cfs_time_current_sec();
755 long timeoutl = req->rq_deadline -
756 cfs_time_current_sec();
757 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
758 CFS_TICK : cfs_time_seconds(timeoutl);
759 lwi = LWI_TIMEOUT_INTERVAL(timeout,
763 rc = l_wait_event(desc->bd_waitq,
764 !ptlrpc_server_bulk_active(desc) ||
765 exp->exp_failed, &lwi);
766 LASSERT(rc == 0 || rc == -ETIMEDOUT);
767 /* Wait again if we changed deadline */
768 } while ((rc == -ETIMEDOUT) &&
769 (req->rq_deadline > cfs_time_current_sec()));
771 if (rc == -ETIMEDOUT) {
772 DEBUG_REQ(D_ERROR, req,
773 "timeout on bulk PUT after %ld%+lds",
774 req->rq_deadline - start,
775 cfs_time_current_sec() -
777 ptlrpc_abort_bulk(desc);
778 } else if (exp->exp_failed) {
779 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
781 ptlrpc_abort_bulk(desc);
782 } else if (!desc->bd_success ||
783 desc->bd_nob_transferred != desc->bd_nob) {
784 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
786 "truncated" : "network error on",
787 desc->bd_nob_transferred,
789 /* XXX should this be a different errno? */
793 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
798 /* Must commit after prep above in all cases */
799 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
800 remote_nb, npages, local_nb, oti, rc);
803 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
805 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
806 ost_drop_id(exp, &repbody->oa);
810 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
813 ptlrpc_free_bulk(desc);
817 req->rq_status = nob;
818 ptlrpc_lprocfs_brw(req, nob);
819 target_committed_to_req(req);
821 } else if (!no_reply) {
822 /* Only reply if there was no comms problem with bulk */
823 target_committed_to_req(req);
827 /* reply out callback would free */
828 ptlrpc_req_drop_rs(req);
829 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
830 "client will retry\n",
831 exp->exp_obd->obd_name,
832 exp->exp_client_uuid.uuid,
833 exp->exp_connection->c_remote_uuid.uuid,
834 libcfs_id2str(req->rq_peer));
840 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
842 struct ptlrpc_bulk_desc *desc = NULL;
843 struct obd_export *exp = req->rq_export;
844 struct niobuf_remote *remote_nb;
845 struct niobuf_local *local_nb;
846 struct obd_ioobj *ioo;
847 struct ost_body *body, *repbody;
848 struct l_wait_info lwi;
849 struct lustre_handle lockh = {0};
850 struct lustre_capa *capa = NULL;
852 __u32 size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
853 int objcount, niocount, npages;
855 obd_count client_cksum = 0, server_cksum = 0;
856 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
858 __u32 o_uid = 0, o_gid = 0;
861 req->rq_bulk_write = 1;
863 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
864 GOTO(out, rc = -EIO);
865 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
866 GOTO(out, rc = -EFAULT);
868 /* pause before transaction has been started */
869 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
871 /* Check if there is eviction in progress, and if so, wait for it to
873 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
874 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
875 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
876 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
880 GOTO(out, rc = -ENOTCONN);
882 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
883 * ost_rw_hpreq_check(). */
884 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
885 LASSERT(body != NULL);
887 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
889 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
890 objcount * sizeof(*ioo));
891 LASSERT(ioo != NULL);
892 for (niocount = i = 0; i < objcount; i++)
893 niocount += ioo[i].ioo_bufcnt;
895 remote_nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
896 niocount * sizeof(*remote_nb));
897 LASSERT(remote_nb != NULL);
899 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
900 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
902 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
903 rc = lustre_pack_reply(req, 3, size, NULL);
906 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, obd_fail_val);
907 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
908 niocount * sizeof(*rcs));
911 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
914 local_nb = ost_tls(req)->local;
916 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
921 * If getting the lock took more time than
922 * client was willing to wait, drop it. b=11330
924 if (cfs_time_current_sec() > req->rq_deadline ||
925 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
927 CERROR("Dropping timed-out write from %s because locking "
928 "object "LPX64" took %ld seconds (limit was %ld).\n",
929 libcfs_id2str(req->rq_peer), ioo->ioo_id,
930 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
931 req->rq_deadline - req->rq_arrival_time.tv_sec);
932 GOTO(out_lock, rc = -ETIMEDOUT);
935 ost_rw_prolong_locks(exp, ioo, remote_nb,&body->oa, LCK_PW);
937 /* obd_preprw clobbers oa->valid, so save what we need */
938 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
939 client_cksum = body->oa.o_cksum;
940 if (body->oa.o_valid & OBD_MD_FLFLAGS)
941 cksum_type = cksum_type_unpack(body->oa.o_flags);
944 /* Because we already sync grant info with client when reconnect,
945 * grant info will be cleared for resent req, then fed_grant and
946 * total_grant will not be modified in following preprw_write */
947 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
948 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
949 body->oa.o_valid &= ~OBD_MD_FLGRANT;
952 if (exp_connect_rmtclient(exp)) {
953 o_uid = body->oa.o_uid;
954 o_gid = body->oa.o_gid;
956 npages = OST_THREAD_POOL_SIZE;
957 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
958 ioo, remote_nb, &npages, local_nb, oti, capa);
962 desc = ptlrpc_prep_bulk_exp(req, npages,
963 BULK_GET_SINK, OST_BULK_PORTAL);
965 GOTO(out, rc = -ENOMEM);
967 /* NB Having prepped, we must commit... */
969 for (i = 0; i < npages; i++)
970 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
971 local_nb[i].offset & ~CFS_PAGE_MASK,
974 /* Check if client was evicted while we were doing i/o before touching
976 if (desc->bd_export->exp_failed)
979 rc = ptlrpc_start_bulk_transfer(desc);
981 time_t start = cfs_time_current_sec();
983 long timeoutl = req->rq_deadline -
984 cfs_time_current_sec();
985 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
986 CFS_TICK : cfs_time_seconds(timeoutl);
987 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
988 ost_bulk_timeout, desc);
989 rc = l_wait_event(desc->bd_waitq,
990 !ptlrpc_server_bulk_active(desc) ||
991 desc->bd_export->exp_failed, &lwi);
992 LASSERT(rc == 0 || rc == -ETIMEDOUT);
993 /* Wait again if we changed deadline */
994 } while ((rc == -ETIMEDOUT) &&
995 (req->rq_deadline > cfs_time_current_sec()));
997 if (rc == -ETIMEDOUT) {
998 DEBUG_REQ(D_ERROR, req,
999 "timeout on bulk GET after %ld%+lds",
1000 req->rq_deadline - start,
1001 cfs_time_current_sec() -
1003 ptlrpc_abort_bulk(desc);
1004 } else if (desc->bd_export->exp_failed) {
1005 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1007 ptlrpc_abort_bulk(desc);
1008 } else if (!desc->bd_success ||
1009 desc->bd_nob_transferred != desc->bd_nob) {
1010 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1012 "truncated" : "network error on",
1013 desc->bd_nob_transferred, desc->bd_nob);
1014 /* XXX should this be a different errno? */
1018 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1023 sptlrpc_svc_unwrap_bulk(req, desc);
1025 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1027 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1029 if (unlikely(client_cksum != 0 && rc == 0)) {
1030 static int cksum_counter;
1031 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1032 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1033 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1034 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1035 repbody->oa.o_cksum = server_cksum;
1037 if (unlikely(client_cksum != server_cksum)) {
1038 CERROR("client csum %x, server csum %x\n",
1039 client_cksum, server_cksum);
1041 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1042 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1043 cksum_counter, libcfs_id2str(req->rq_peer),
1048 /* Must commit after prep above in all cases */
1049 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1050 remote_nb, npages, local_nb, oti, rc);
1051 if (exp_connect_rmtclient(exp)) {
1052 repbody->oa.o_uid = o_uid;
1053 repbody->oa.o_gid = o_gid;
1056 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1057 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1062 if (new_cksum == server_cksum)
1063 msg = "changed in transit before arrival at OST";
1064 else if (new_cksum == client_cksum)
1065 msg = "initial checksum before message complete";
1067 msg = "changed in transit AND after initial checksum";
1069 if (req->rq_peer.nid == desc->bd_sender) {
1073 router = libcfs_nid2str(desc->bd_sender);
1076 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1077 "%s%s%s inum "LPU64"/"LPU64" object "
1078 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1079 exp->exp_obd->obd_name, msg,
1080 libcfs_id2str(req->rq_peer),
1082 body->oa.o_valid & OBD_MD_FLFID ?
1083 body->oa.o_fid : (__u64)0,
1084 body->oa.o_valid & OBD_MD_FLFID ?
1085 body->oa.o_generation :(__u64)0,
1087 body->oa.o_valid & OBD_MD_FLGROUP ?
1088 body->oa.o_gr : (__u64)0,
1090 local_nb[npages-1].offset +
1091 local_nb[npages-1].len - 1 );
1092 CERROR("client csum %x, original server csum %x, "
1093 "server csum now %x\n",
1094 client_cksum, server_cksum, new_cksum);
1100 /* set per-requested niobuf return codes */
1101 for (i = j = 0; i < niocount; i++) {
1102 int len = remote_nb[i].len;
1107 LASSERT(j < npages);
1108 if (local_nb[j].rc < 0)
1109 rcs[i] = local_nb[j].rc;
1110 len -= local_nb[j].len;
1115 LASSERT(j == npages);
1116 ptlrpc_lprocfs_brw(req, nob);
1120 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1123 ptlrpc_free_bulk(desc);
1126 oti_to_request(oti, req);
1127 target_committed_to_req(req);
1128 rc = ptlrpc_reply(req);
1129 } else if (!no_reply) {
1130 /* Only reply if there was no comms problem with bulk */
1131 target_committed_to_req(req);
1132 req->rq_status = rc;
1135 /* reply out callback would free */
1136 ptlrpc_req_drop_rs(req);
1137 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1138 "client will retry\n",
1139 exp->exp_obd->obd_name,
1140 exp->exp_client_uuid.uuid,
1141 exp->exp_connection->c_remote_uuid.uuid,
1142 libcfs_id2str(req->rq_peer));
1147 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1149 char *key, *val = NULL;
1150 int keylen, vallen, rc = 0;
1153 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1155 DEBUG_REQ(D_HA, req, "no set_info key");
1158 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1160 rc = lustre_pack_reply(req, 1, NULL, NULL);
1164 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1166 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
1168 if (KEY_IS(KEY_EVICT_BY_NID)) {
1170 obd_export_evict_by_nid(exp->exp_obd, val);
1175 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1177 lustre_msg_set_status(req->rq_repmsg, 0);
1181 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1184 int keylen, replylen, rc = 0;
1185 struct req_capsule *pill = &req->rq_pill;
1188 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
1190 /* this common part for get_info rpc */
1191 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1193 DEBUG_REQ(D_HA, req, "no get_info key");
1196 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1198 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1202 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1203 RCL_SERVER, replylen);
1205 rc = req_capsule_server_pack(pill);
1209 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1213 /* call again to fill in the reply buffer */
1214 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1216 lustre_msg_set_status(req->rq_repmsg, 0);
1220 #ifdef HAVE_QUOTA_SUPPORT
1221 static int ost_handle_quotactl(struct ptlrpc_request *req)
1223 struct obd_quotactl *oqctl, *repoqc;
1227 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1229 GOTO(out, rc = -EPROTO);
1231 rc = req_capsule_server_pack(&req->rq_pill);
1235 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1236 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1243 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1245 struct obd_quotactl *oqctl;
1249 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1253 rc = req_capsule_server_pack(&req->rq_pill);
1257 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1261 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1263 struct quota_adjust_qunit *oqaq, *repoqa;
1264 struct lustre_quota_ctxt *qctxt;
1268 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1269 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1271 GOTO(out, rc = -EPROTO);
1273 rc = req_capsule_server_pack(&req->rq_pill);
1277 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1278 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt);
1286 static int ost_llog_handle_connect(struct obd_export *exp,
1287 struct ptlrpc_request *req)
1289 struct llogd_conn_body *body;
1293 body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body));
1294 rc = obd_llog_connect(exp, body);
1298 #define ost_init_sec_none(reply, exp) \
1300 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1301 OBD_CONNECT_RMT_CLIENT_FORCE | \
1302 OBD_CONNECT_OSS_CAPA); \
1303 spin_lock(&exp->exp_lock); \
1304 exp->exp_connect_flags = reply->ocd_connect_flags; \
1305 spin_unlock(&exp->exp_lock); \
1308 static int ost_init_sec_level(struct ptlrpc_request *req)
1310 struct obd_export *exp = req->rq_export;
1311 struct req_capsule *pill = &req->rq_pill;
1312 struct obd_device *obd = exp->exp_obd;
1313 struct filter_obd *filter = &obd->u.filter;
1314 char *client = libcfs_nid2str(req->rq_peer.nid);
1315 struct obd_connect_data *data, *reply;
1319 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1320 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1321 if (data == NULL || reply == NULL)
1324 /* connection from MDT is always trusted */
1325 if (req->rq_auth_usr_mdt) {
1326 ost_init_sec_none(reply, exp);
1330 /* no GSS support case */
1331 if (!req->rq_auth_gss) {
1332 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1333 CWARN("client %s -> target %s does not user GSS, "
1334 "can not run under security level %d.\n",
1335 client, obd->obd_name, filter->fo_sec_level);
1338 ost_init_sec_none(reply, exp);
1343 /* old version case */
1344 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1345 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1346 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1347 CWARN("client %s -> target %s uses old version, "
1348 "can not run under security level %d.\n",
1349 client, obd->obd_name, filter->fo_sec_level);
1352 CWARN("client %s -> target %s uses old version, "
1353 "run under security level %d.\n",
1354 client, obd->obd_name, filter->fo_sec_level);
1355 ost_init_sec_none(reply, exp);
1360 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1362 if (!req->rq_auth_remote)
1363 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1364 "asked to be remote.\n", client, obd->obd_name);
1365 } else if (req->rq_auth_remote) {
1367 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1368 "as remote by default.\n", client, obd->obd_name);
1372 if (!filter->fo_fl_oss_capa) {
1373 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1374 " but OSS capabilities are not enabled: %d.\n",
1375 client, obd->obd_name, filter->fo_fl_oss_capa);
1380 switch (filter->fo_sec_level) {
1381 case LUSTRE_SEC_NONE:
1383 ost_init_sec_none(reply, exp);
1386 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1387 "can not run under security level %d.\n",
1388 client, obd->obd_name, filter->fo_sec_level);
1391 case LUSTRE_SEC_REMOTE:
1393 ost_init_sec_none(reply, exp);
1395 case LUSTRE_SEC_ALL:
1397 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1398 OBD_CONNECT_RMT_CLIENT_FORCE);
1399 if (!filter->fo_fl_oss_capa)
1400 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1402 spin_lock(&exp->exp_lock);
1403 exp->exp_connect_flags = reply->ocd_connect_flags;
1404 spin_unlock(&exp->exp_lock);
1416 * this should be done in filter_connect()/filter_reconnect(), but
1417 * we can't obtain information like NID, which stored in incoming
1418 * request, thus can't decide what flavor to use. so we do it here.
1420 * This hack should be removed after the OST stack be rewritten, just
1421 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1423 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1425 struct obd_export *exp = req->rq_export;
1426 struct filter_obd *filter = &exp->exp_obd->u.filter;
1427 struct sptlrpc_flavor flvr;
1430 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1431 read_lock(&filter->fo_sptlrpc_lock);
1432 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1436 read_unlock(&filter->fo_sptlrpc_lock);
1438 spin_lock(&exp->exp_lock);
1440 exp->exp_sp_peer = req->rq_sp_from;
1441 exp->exp_flvr = flvr;
1443 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1444 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1445 CERROR("unauthorized rpc flavor %x from %s, "
1446 "expect %x\n", req->rq_flvr.sf_rpc,
1447 libcfs_nid2str(req->rq_peer.nid),
1448 exp->exp_flvr.sf_rpc);
1452 spin_unlock(&exp->exp_lock);
1454 if (exp->exp_sp_peer != req->rq_sp_from) {
1455 CERROR("RPC source %s doesn't match %s\n",
1456 sptlrpc_part2name(req->rq_sp_from),
1457 sptlrpc_part2name(exp->exp_sp_peer));
1460 rc = sptlrpc_target_export_check(exp, req);
1467 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1468 struct obd_device *obd, int *process)
1470 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1471 case OST_CONNECT: /* This will never get here, but for completeness. */
1472 case OST_DISCONNECT:
1483 case OBD_LOG_CANCEL:
1485 *process = target_queue_recovery_request(req, obd);
1489 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1495 int ost_msg_check_version(struct lustre_msg *msg)
1499 switch(lustre_msg_get_opc(msg)) {
1501 case OST_DISCONNECT:
1504 case SEC_CTX_INIT_CONT:
1506 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1508 CERROR("bad opc %u version %08x, expecting %08x\n",
1509 lustre_msg_get_opc(msg),
1510 lustre_msg_get_version(msg),
1511 LUSTRE_OBD_VERSION);
1524 #ifdef HAVE_QUOTA_SUPPORT
1525 case OST_QUOTACHECK:
1527 case OST_QUOTA_ADJUST_QUNIT:
1529 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1531 CERROR("bad opc %u version %08x, expecting %08x\n",
1532 lustre_msg_get_opc(msg),
1533 lustre_msg_get_version(msg),
1534 LUSTRE_OST_VERSION);
1539 case LDLM_BL_CALLBACK:
1540 case LDLM_CP_CALLBACK:
1541 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1543 CERROR("bad opc %u version %08x, expecting %08x\n",
1544 lustre_msg_get_opc(msg),
1545 lustre_msg_get_version(msg),
1546 LUSTRE_DLM_VERSION);
1548 case LLOG_ORIGIN_CONNECT:
1549 case OBD_LOG_CANCEL:
1550 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1552 CERROR("bad opc %u version %08x, expecting %08x\n",
1553 lustre_msg_get_opc(msg),
1554 lustre_msg_get_version(msg),
1555 LUSTRE_LOG_VERSION);
1558 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1564 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1565 struct ldlm_lock *lock)
1567 struct niobuf_remote *nb;
1568 struct obd_ioobj *ioo;
1569 struct ost_body *body;
1570 int objcount, niocount;
1575 opc = lustre_msg_get_opc(req->rq_reqmsg);
1576 LASSERT(opc == OST_READ || opc == OST_WRITE);
1578 /* As the request may be covered by several locks, do not look at
1579 * o_handle, look at the RPC IO region. */
1580 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
1582 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
1584 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
1585 objcount * sizeof(*ioo));
1586 LASSERT(ioo != NULL);
1587 for (niocount = i = 0; i < objcount; i++)
1588 niocount += ioo[i].ioo_bufcnt;
1590 nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
1591 niocount * sizeof(*nb));
1592 LASSERT(nb != NULL);
1595 if (opc == OST_READ)
1598 start = nb[0].offset & CFS_PAGE_MASK;
1599 end = (nb[ioo->ioo_bufcnt - 1].offset +
1600 nb[ioo->ioo_bufcnt - 1].len - 1) | ~CFS_PAGE_MASK;
1602 if (!(lock->l_granted_mode & mode))
1605 if (lock->l_policy_data.l_extent.end < start ||
1606 lock->l_policy_data.l_extent.start > end)
1613 * Swab buffers needed to call ost_rw_prolong_locks() and call it.
1614 * Return the value from ost_rw_prolong_locks() which is non-zero if
1615 * there is a cancelled lock which is waiting for this IO request.
1617 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1619 struct niobuf_remote *nb;
1620 struct obd_ioobj *ioo;
1621 struct ost_body *body;
1622 int objcount, niocount;
1626 opc = lustre_msg_get_opc(req->rq_reqmsg);
1627 LASSERT(opc == OST_READ || opc == OST_WRITE);
1629 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
1630 LASSERT(body != NULL);
1632 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
1634 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
1635 objcount * sizeof(*ioo));
1636 LASSERT(ioo != NULL);
1638 for (niocount = i = 0; i < objcount; i++)
1639 niocount += ioo[i].ioo_bufcnt;
1640 nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
1641 niocount * sizeof(*nb));
1642 LASSERT(nb != NULL);
1643 LASSERT(niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK));
1646 if (opc == OST_READ)
1648 RETURN(ost_rw_prolong_locks(req->rq_export, ioo, nb, &body->oa, mode));
1651 static int ost_punch_prolong_locks(struct obd_export *exp, struct obdo *oa)
1653 struct ldlm_res_id res_id = { .name = { oa->o_id } };
1654 struct ost_prolong_data opd = { 0 };
1659 end = start + oa->o_blocks;
1661 opd.opd_mode = LCK_PW;
1663 opd.opd_policy.l_extent.start = start & CFS_PAGE_MASK;
1664 if (oa->o_blocks == OBD_OBJECT_EOF || end < start)
1665 opd.opd_policy.l_extent.end = OBD_OBJECT_EOF;
1667 opd.opd_policy.l_extent.end = end | ~CFS_PAGE_MASK;
1669 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1670 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
1671 opd.opd_policy.l_extent.end);
1674 ldlm_resource_iterate(exp->exp_obd->obd_namespace, &res_id,
1675 ost_prolong_locks_iter, &opd);
1676 RETURN(opd.opd_lock_match);
1679 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1680 struct ldlm_lock *lock)
1682 struct ost_body *body;
1685 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
1687 LASSERT(body != NULL);
1689 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1690 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1695 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1697 struct ost_body *body = lustre_msg_buf(req->rq_reqmsg,
1698 REQ_REC_OFF, sizeof(*body));
1699 LASSERT(body != NULL);
1700 LASSERT(!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1701 !(body->oa.o_flags & OBD_FL_TRUNCLOCK));
1703 RETURN(ost_punch_prolong_locks(req->rq_export, &body->oa));
1706 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
1707 .hpreq_lock_match = ost_rw_hpreq_lock_match,
1708 .hpreq_check = ost_rw_hpreq_check,
1711 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
1712 .hpreq_lock_match = ost_punch_hpreq_lock_match,
1713 .hpreq_check = ost_punch_hpreq_check,
1716 /** Assign high priority operations to the request if needed. */
1717 static int ost_hpreq_handler(struct ptlrpc_request *req)
1720 if (req->rq_export) {
1721 int opc = lustre_msg_get_opc(req->rq_reqmsg);
1722 struct ost_body *body;
1724 if (opc == OST_READ || opc == OST_WRITE) {
1725 struct niobuf_remote *nb;
1726 struct obd_ioobj *ioo;
1727 int objcount, niocount;
1730 body = lustre_swab_reqbuf(req, REQ_REC_OFF,
1734 CERROR("Missing/short ost_body\n");
1737 objcount = lustre_msg_buflen(req->rq_reqmsg,
1740 if (objcount == 0) {
1741 CERROR("Missing/short ioobj\n");
1745 CERROR("too many ioobjs (%d)\n", objcount);
1749 swab = !lustre_req_swabbed(req, REQ_REC_OFF + 1) &&
1750 lustre_msg_swabbed(req->rq_reqmsg);
1751 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1,
1752 objcount * sizeof(*ioo),
1753 lustre_swab_obd_ioobj);
1755 CERROR("Missing/short ioobj\n");
1758 for (niocount = i = 0; i < objcount; i++) {
1760 lustre_swab_obd_ioobj(&ioo[i]);
1761 if (ioo[i].ioo_bufcnt == 0) {
1762 CERROR("ioo[%d] has zero bufcnt\n", i);
1765 niocount += ioo[i].ioo_bufcnt;
1767 if (niocount > PTLRPC_MAX_BRW_PAGES) {
1768 DEBUG_REQ(D_ERROR, req, "bulk has too many "
1769 "pages (%d)", niocount);
1773 swab = !lustre_req_swabbed(req, REQ_REC_OFF + 2) &&
1774 lustre_msg_swabbed(req->rq_reqmsg);
1775 nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
1776 niocount * sizeof(*nb),
1777 lustre_swab_niobuf_remote);
1779 CERROR("Missing/short niobuf\n");
1784 /* swab remaining niobufs */
1785 for (i = 1; i < niocount; i++)
1786 lustre_swab_niobuf_remote(&nb[i]);
1789 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
1790 req->rq_ops = &ost_hpreq_rw;
1791 } else if (opc == OST_PUNCH) {
1792 body = lustre_swab_reqbuf(req, REQ_REC_OFF,
1796 CERROR("Missing/short ost_body\n");
1800 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1801 !(body->oa.o_flags & OBD_FL_TRUNCLOCK))
1802 req->rq_ops = &ost_hpreq_punch;
1808 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1809 int ost_handle(struct ptlrpc_request *req)
1811 struct obd_trans_info trans_info = { 0, };
1812 struct obd_trans_info *oti = &trans_info;
1813 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1814 struct obd_device *obd = NULL;
1817 LASSERT(current->journal_info == NULL);
1819 /* primordial rpcs don't affect server recovery */
1820 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1822 case SEC_CTX_INIT_CONT:
1827 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1829 /* XXX identical to MDS */
1830 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1833 if (req->rq_export == NULL) {
1834 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1835 lustre_msg_get_opc(req->rq_reqmsg),
1836 libcfs_id2str(req->rq_peer));
1837 req->rq_status = -ENOTCONN;
1838 GOTO(out, rc = -ENOTCONN);
1841 obd = req->rq_export->exp_obd;
1843 /* Check for aborted recovery. */
1844 spin_lock_bh(&obd->obd_processing_task_lock);
1845 recovering = obd->obd_recovering;
1846 spin_unlock_bh(&obd->obd_processing_task_lock);
1848 rc = ost_filter_recovery_request(req, obd,
1850 if (rc || !should_process)
1852 else if (should_process < 0) {
1853 req->rq_status = should_process;
1854 rc = ptlrpc_error(req);
1862 rc = ost_msg_check_version(req->rq_reqmsg);
1866 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1868 CDEBUG(D_INODE, "connect\n");
1869 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
1870 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
1872 rc = target_handle_connect(req);
1873 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
1876 rc = ost_init_sec_level(req);
1878 rc = ost_connect_check_sptlrpc(req);
1882 case OST_DISCONNECT:
1883 CDEBUG(D_INODE, "disconnect\n");
1884 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
1885 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
1887 rc = target_handle_disconnect(req);
1890 CDEBUG(D_INODE, "create\n");
1891 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
1893 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1894 GOTO(out, rc = -ENOSPC);
1895 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1896 GOTO(out, rc = -EROFS);
1897 rc = ost_create(req->rq_export, req, oti);
1900 CDEBUG(D_INODE, "destroy\n");
1901 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
1903 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1904 GOTO(out, rc = -EROFS);
1905 rc = ost_destroy(req->rq_export, req, oti);
1908 CDEBUG(D_INODE, "getattr\n");
1909 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
1911 rc = ost_getattr(req->rq_export, req);
1914 CDEBUG(D_INODE, "setattr\n");
1915 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
1917 rc = ost_setattr(req->rq_export, req, oti);
1920 CDEBUG(D_INODE, "write\n");
1921 /* req->rq_request_portal would be nice, if it was set */
1922 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1923 CERROR("%s: deny write request from %s to portal %u\n",
1924 req->rq_export->exp_obd->obd_name,
1925 obd_export_nid2str(req->rq_export),
1926 req->rq_rqbd->rqbd_service->srv_req_portal);
1927 GOTO(out, rc = -EPROTO);
1929 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1931 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1932 GOTO(out, rc = -ENOSPC);
1933 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1934 GOTO(out, rc = -EROFS);
1935 rc = ost_brw_write(req, oti);
1936 LASSERT(current->journal_info == NULL);
1937 /* ost_brw_write sends its own replies */
1940 CDEBUG(D_INODE, "read\n");
1941 /* req->rq_request_portal would be nice, if it was set */
1942 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1943 CERROR("%s: deny read request from %s to portal %u\n",
1944 req->rq_export->exp_obd->obd_name,
1945 obd_export_nid2str(req->rq_export),
1946 req->rq_rqbd->rqbd_service->srv_req_portal);
1947 GOTO(out, rc = -EPROTO);
1949 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1951 rc = ost_brw_read(req, oti);
1952 LASSERT(current->journal_info == NULL);
1953 /* ost_brw_read sends its own replies */
1956 CDEBUG(D_INODE, "punch\n");
1957 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
1959 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1960 GOTO(out, rc = -EROFS);
1961 rc = ost_punch(req->rq_export, req, oti);
1964 CDEBUG(D_INODE, "statfs\n");
1965 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
1967 rc = ost_statfs(req);
1970 CDEBUG(D_INODE, "sync\n");
1971 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
1973 rc = ost_sync(req->rq_export, req);
1976 DEBUG_REQ(D_INODE, req, "set_info");
1977 req_capsule_set(&req->rq_pill, &RQF_OST_SET_INFO);
1978 rc = ost_set_info(req->rq_export, req);
1981 DEBUG_REQ(D_INODE, req, "get_info");
1982 rc = ost_get_info(req->rq_export, req);
1984 #ifdef HAVE_QUOTA_SUPPORT
1985 case OST_QUOTACHECK:
1986 CDEBUG(D_INODE, "quotacheck\n");
1987 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
1988 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
1990 rc = ost_handle_quotacheck(req);
1993 CDEBUG(D_INODE, "quotactl\n");
1994 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
1995 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
1997 rc = ost_handle_quotactl(req);
1999 case OST_QUOTA_ADJUST_QUNIT:
2000 CDEBUG(D_INODE, "quota_adjust_qunit\n");
2001 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
2002 rc = ost_handle_quota_adjust_qunit(req);
2006 DEBUG_REQ(D_INODE, req, "ping");
2007 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2008 rc = target_handle_ping(req);
2010 /* FIXME - just reply status */
2011 case LLOG_ORIGIN_CONNECT:
2012 DEBUG_REQ(D_INODE, req, "log connect");
2013 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2014 rc = ost_llog_handle_connect(req->rq_export, req);
2015 req->rq_status = rc;
2016 rc = req_capsule_server_pack(&req->rq_pill);
2019 RETURN(ptlrpc_reply(req));
2020 case OBD_LOG_CANCEL:
2021 CDEBUG(D_INODE, "log cancel\n");
2022 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2023 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2025 rc = llog_origin_handle_cancel(req);
2026 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2028 req->rq_status = rc;
2029 rc = req_capsule_server_pack(&req->rq_pill);
2032 RETURN(ptlrpc_reply(req));
2034 CDEBUG(D_INODE, "enqueue\n");
2035 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2036 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2038 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2039 ldlm_server_blocking_ast,
2040 ldlm_server_glimpse_ast);
2041 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2044 CDEBUG(D_INODE, "convert\n");
2045 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2046 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2048 rc = ldlm_handle_convert(req);
2051 CDEBUG(D_INODE, "cancel\n");
2052 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2053 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2055 rc = ldlm_handle_cancel(req);
2057 case LDLM_BL_CALLBACK:
2058 case LDLM_CP_CALLBACK:
2059 CDEBUG(D_INODE, "callback\n");
2060 CERROR("callbacks should not happen on OST\n");
2063 CERROR("Unexpected opcode %d\n",
2064 lustre_msg_get_opc(req->rq_reqmsg));
2065 req->rq_status = -ENOTSUPP;
2066 rc = ptlrpc_error(req);
2070 LASSERT(current->journal_info == NULL);
2073 /* If we're DISCONNECTing, the export_data is already freed */
2074 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2075 target_committed_to_req(req);
2079 oti_to_request(oti, req);
2081 target_send_reply(req, rc, fail);
2084 EXPORT_SYMBOL(ost_handle);
2086 * free per-thread pool created by ost_thread_init().
2088 static void ost_thread_done(struct ptlrpc_thread *thread)
2090 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2095 LASSERT(thread != NULL);
2098 * be prepared to handle partially-initialized pools (because this is
2099 * called from ost_thread_init() for cleanup.
2101 tls = thread->t_data;
2104 thread->t_data = NULL;
2110 * initialize per-thread page pool (bug 5137).
2112 static int ost_thread_init(struct ptlrpc_thread *thread)
2114 struct ost_thread_local_cache *tls;
2118 LASSERT(thread != NULL);
2119 LASSERT(thread->t_data == NULL);
2120 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
2125 thread->t_data = tls;
2129 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2131 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2132 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2134 struct ost_obd *ost = &obd->u.ost;
2135 struct lprocfs_static_vars lvars;
2136 int oss_min_threads;
2137 int oss_max_threads;
2138 int oss_min_create_threads;
2139 int oss_max_create_threads;
2143 rc = cleanup_group_info();
2147 lprocfs_ost_init_vars(&lvars);
2148 lprocfs_obd_setup(obd, lvars.obd_vars);
2150 sema_init(&ost->ost_health_sem, 1);
2152 if (oss_num_threads) {
2153 /* If oss_num_threads is set, it is the min and the max. */
2154 if (oss_num_threads > OSS_THREADS_MAX)
2155 oss_num_threads = OSS_THREADS_MAX;
2156 if (oss_num_threads < OSS_THREADS_MIN)
2157 oss_num_threads = OSS_THREADS_MIN;
2158 oss_max_threads = oss_min_threads = oss_num_threads;
2160 /* Base min threads on memory and cpus */
2161 oss_min_threads = num_possible_cpus() * num_physpages >>
2162 (27 - CFS_PAGE_SHIFT);
2163 if (oss_min_threads < OSS_THREADS_MIN)
2164 oss_min_threads = OSS_THREADS_MIN;
2165 /* Insure a 4x range for dynamic threads */
2166 if (oss_min_threads > OSS_THREADS_MAX / 4)
2167 oss_min_threads = OSS_THREADS_MAX / 4;
2168 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
2172 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2173 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
2174 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2175 ost_handle, LUSTRE_OSS_NAME,
2176 obd->obd_proc_entry, target_print_req,
2177 oss_min_threads, oss_max_threads,
2178 "ll_ost", LCT_DT_THREAD, NULL);
2179 if (ost->ost_service == NULL) {
2180 CERROR("failed to start service\n");
2181 GOTO(out_lprocfs, rc = -ENOMEM);
2184 rc = ptlrpc_start_threads(obd, ost->ost_service);
2186 GOTO(out_service, rc = -EINVAL);
2188 if (oss_num_create_threads) {
2189 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
2190 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
2191 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
2192 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
2193 oss_min_create_threads = oss_max_create_threads =
2194 oss_num_create_threads;
2196 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
2197 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
2200 ost->ost_create_service =
2201 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2202 OST_MAXREPSIZE, OST_CREATE_PORTAL,
2203 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2204 ost_handle, "ost_create",
2205 obd->obd_proc_entry, target_print_req,
2206 oss_min_create_threads, oss_max_create_threads,
2207 "ll_ost_creat", LCT_DT_THREAD, NULL);
2208 if (ost->ost_create_service == NULL) {
2209 CERROR("failed to start OST create service\n");
2210 GOTO(out_service, rc = -ENOMEM);
2213 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
2215 GOTO(out_create, rc = -EINVAL);
2217 ost->ost_io_service =
2218 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2219 OST_MAXREPSIZE, OST_IO_PORTAL,
2220 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2221 ost_handle, "ost_io",
2222 obd->obd_proc_entry, target_print_req,
2223 oss_min_threads, oss_max_threads,
2224 "ll_ost_io", LCT_DT_THREAD, ost_hpreq_handler);
2225 if (ost->ost_io_service == NULL) {
2226 CERROR("failed to start OST I/O service\n");
2227 GOTO(out_create, rc = -ENOMEM);
2230 ost->ost_io_service->srv_init = ost_thread_init;
2231 ost->ost_io_service->srv_done = ost_thread_done;
2232 ost->ost_io_service->srv_cpu_affinity = 1;
2233 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
2235 GOTO(out_io, rc = -EINVAL);
2237 ping_evictor_start();
2242 ptlrpc_unregister_service(ost->ost_io_service);
2243 ost->ost_io_service = NULL;
2245 ptlrpc_unregister_service(ost->ost_create_service);
2246 ost->ost_create_service = NULL;
2248 ptlrpc_unregister_service(ost->ost_service);
2249 ost->ost_service = NULL;
2251 lprocfs_obd_cleanup(obd);
2255 static int ost_cleanup(struct obd_device *obd)
2257 struct ost_obd *ost = &obd->u.ost;
2261 ping_evictor_stop();
2263 spin_lock_bh(&obd->obd_processing_task_lock);
2264 if (obd->obd_recovering) {
2265 target_cancel_recovery_timer(obd);
2266 obd->obd_recovering = 0;
2268 spin_unlock_bh(&obd->obd_processing_task_lock);
2270 down(&ost->ost_health_sem);
2271 ptlrpc_unregister_service(ost->ost_service);
2272 ptlrpc_unregister_service(ost->ost_create_service);
2273 ptlrpc_unregister_service(ost->ost_io_service);
2274 ost->ost_service = NULL;
2275 ost->ost_create_service = NULL;
2276 up(&ost->ost_health_sem);
2278 lprocfs_obd_cleanup(obd);
2283 static int ost_health_check(struct obd_device *obd)
2285 struct ost_obd *ost = &obd->u.ost;
2288 down(&ost->ost_health_sem);
2289 rc |= ptlrpc_service_health_check(ost->ost_service);
2290 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2291 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2292 up(&ost->ost_health_sem);
2295 * health_check to return 0 on healthy
2296 * and 1 on unhealthy.
2304 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2306 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2309 /* use obd ops to offer management infrastructure */
2310 static struct obd_ops ost_obd_ops = {
2311 .o_owner = THIS_MODULE,
2312 .o_setup = ost_setup,
2313 .o_cleanup = ost_cleanup,
2314 .o_health_check = ost_health_check,
2318 static int __init ost_init(void)
2320 struct lprocfs_static_vars lvars;
2324 lprocfs_ost_init_vars(&lvars);
2325 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2326 LUSTRE_OSS_NAME, NULL);
2328 if (ost_num_threads != 0 && oss_num_threads == 0) {
2329 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2330 "use oss_num_threads instead or unset both for "
2331 "dynamic thread startup\n");
2332 oss_num_threads = ost_num_threads;
2338 static void /*__exit*/ ost_exit(void)
2340 class_unregister_type(LUSTRE_OSS_NAME);
2343 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2344 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2345 MODULE_LICENSE("GPL");
2347 module_init(ost_init);
2348 module_exit(ost_exit);