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 rc = 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 rc = sptlrpc_svc_prep_bulk(req, desc);
985 /* Check if client was evicted while we were doing i/o before touching
987 if (desc->bd_export->exp_failed)
990 rc = ptlrpc_start_bulk_transfer(desc);
992 time_t start = cfs_time_current_sec();
994 long timeoutl = req->rq_deadline -
995 cfs_time_current_sec();
996 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
997 CFS_TICK : cfs_time_seconds(timeoutl);
998 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
999 ost_bulk_timeout, desc);
1000 rc = l_wait_event(desc->bd_waitq,
1001 !ptlrpc_server_bulk_active(desc) ||
1002 desc->bd_export->exp_failed, &lwi);
1003 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1004 /* Wait again if we changed deadline */
1005 } while ((rc == -ETIMEDOUT) &&
1006 (req->rq_deadline > cfs_time_current_sec()));
1008 if (rc == -ETIMEDOUT) {
1009 DEBUG_REQ(D_ERROR, req,
1010 "timeout on bulk GET after %ld%+lds",
1011 req->rq_deadline - start,
1012 cfs_time_current_sec() -
1014 ptlrpc_abort_bulk(desc);
1015 } else if (desc->bd_export->exp_failed) {
1016 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1018 ptlrpc_abort_bulk(desc);
1019 } else if (!desc->bd_success) {
1020 DEBUG_REQ(D_ERROR, req, "network error on bulk GET");
1021 /* XXX should this be a different errno? */
1024 rc = sptlrpc_svc_unwrap_bulk(req, desc);
1027 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1031 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1033 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1035 if (unlikely(client_cksum != 0 && rc == 0)) {
1036 static int cksum_counter;
1037 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1038 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1039 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1040 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1041 repbody->oa.o_cksum = server_cksum;
1043 if (unlikely(client_cksum != server_cksum)) {
1044 CERROR("client csum %x, server csum %x\n",
1045 client_cksum, server_cksum);
1047 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1048 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1049 cksum_counter, libcfs_id2str(req->rq_peer),
1054 /* Must commit after prep above in all cases */
1055 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1056 remote_nb, npages, local_nb, oti, rc);
1057 if (exp_connect_rmtclient(exp)) {
1058 repbody->oa.o_uid = o_uid;
1059 repbody->oa.o_gid = o_gid;
1062 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1063 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1068 if (new_cksum == server_cksum)
1069 msg = "changed in transit before arrival at OST";
1070 else if (new_cksum == client_cksum)
1071 msg = "initial checksum before message complete";
1073 msg = "changed in transit AND after initial checksum";
1075 if (req->rq_peer.nid == desc->bd_sender) {
1079 router = libcfs_nid2str(desc->bd_sender);
1082 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1083 "%s%s%s inum "LPU64"/"LPU64" object "
1084 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1085 exp->exp_obd->obd_name, msg,
1086 libcfs_id2str(req->rq_peer),
1088 body->oa.o_valid & OBD_MD_FLFID ?
1089 body->oa.o_fid : (__u64)0,
1090 body->oa.o_valid & OBD_MD_FLFID ?
1091 body->oa.o_generation :(__u64)0,
1093 body->oa.o_valid & OBD_MD_FLGROUP ?
1094 body->oa.o_gr : (__u64)0,
1096 local_nb[npages-1].offset +
1097 local_nb[npages-1].len - 1 );
1098 CERROR("client csum %x, original server csum %x, "
1099 "server csum now %x\n",
1100 client_cksum, server_cksum, new_cksum);
1106 /* set per-requested niobuf return codes */
1107 for (i = j = 0; i < niocount; i++) {
1108 int len = remote_nb[i].len;
1113 LASSERT(j < npages);
1114 if (local_nb[j].rc < 0)
1115 rcs[i] = local_nb[j].rc;
1116 len -= local_nb[j].len;
1121 LASSERT(j == npages);
1122 ptlrpc_lprocfs_brw(req, nob);
1126 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1129 ptlrpc_free_bulk(desc);
1132 oti_to_request(oti, req);
1133 target_committed_to_req(req);
1134 rc = ptlrpc_reply(req);
1135 } else if (!no_reply) {
1136 /* Only reply if there was no comms problem with bulk */
1137 target_committed_to_req(req);
1138 req->rq_status = rc;
1141 /* reply out callback would free */
1142 ptlrpc_req_drop_rs(req);
1143 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1144 "client will retry\n",
1145 exp->exp_obd->obd_name,
1146 exp->exp_client_uuid.uuid,
1147 exp->exp_connection->c_remote_uuid.uuid,
1148 libcfs_id2str(req->rq_peer));
1153 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1155 struct ost_body *body = NULL, *repbody;
1156 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
1157 char *key, *val = NULL;
1158 int keylen, vallen, rc = 0;
1161 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1163 DEBUG_REQ(D_HA, req, "no set_info key");
1166 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1168 if (KEY_IS(KEY_GRANT_SHRINK)) {
1169 rc = lustre_pack_reply(req, 2, size, NULL);
1173 rc = lustre_pack_reply(req, 1, NULL, NULL);
1178 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1180 if (KEY_IS(KEY_GRANT_SHRINK)) {
1181 body = lustre_swab_reqbuf(req, REQ_REC_OFF + 1,
1183 lustre_swab_ost_body);
1187 repbody = lustre_msg_buf(req->rq_repmsg,
1190 memcpy(repbody, body, sizeof(*body));
1191 val = (char*)repbody;
1193 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,0);
1196 if (KEY_IS(KEY_EVICT_BY_NID)) {
1198 obd_export_evict_by_nid(exp->exp_obd, val);
1203 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1205 lustre_msg_set_status(req->rq_repmsg, 0);
1209 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1212 int keylen, replylen, rc = 0;
1213 struct req_capsule *pill = &req->rq_pill;
1216 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
1218 /* this common part for get_info rpc */
1219 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1221 DEBUG_REQ(D_HA, req, "no get_info key");
1224 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1226 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1230 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1231 RCL_SERVER, replylen);
1233 rc = req_capsule_server_pack(pill);
1237 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1241 /* call again to fill in the reply buffer */
1242 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1244 lustre_msg_set_status(req->rq_repmsg, 0);
1248 #ifdef HAVE_QUOTA_SUPPORT
1249 static int ost_handle_quotactl(struct ptlrpc_request *req)
1251 struct obd_quotactl *oqctl, *repoqc;
1255 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1257 GOTO(out, rc = -EPROTO);
1259 rc = req_capsule_server_pack(&req->rq_pill);
1263 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1264 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1271 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1273 struct obd_quotactl *oqctl;
1277 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1281 rc = req_capsule_server_pack(&req->rq_pill);
1285 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1289 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1291 struct quota_adjust_qunit *oqaq, *repoqa;
1292 struct lustre_quota_ctxt *qctxt;
1296 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1297 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1299 GOTO(out, rc = -EPROTO);
1301 rc = req_capsule_server_pack(&req->rq_pill);
1305 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1306 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt);
1314 static int ost_llog_handle_connect(struct obd_export *exp,
1315 struct ptlrpc_request *req)
1317 struct llogd_conn_body *body;
1321 body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body));
1322 rc = obd_llog_connect(exp, body);
1326 #define ost_init_sec_none(reply, exp) \
1328 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1329 OBD_CONNECT_RMT_CLIENT_FORCE | \
1330 OBD_CONNECT_OSS_CAPA); \
1331 spin_lock(&exp->exp_lock); \
1332 exp->exp_connect_flags = reply->ocd_connect_flags; \
1333 spin_unlock(&exp->exp_lock); \
1336 static int ost_init_sec_level(struct ptlrpc_request *req)
1338 struct obd_export *exp = req->rq_export;
1339 struct req_capsule *pill = &req->rq_pill;
1340 struct obd_device *obd = exp->exp_obd;
1341 struct filter_obd *filter = &obd->u.filter;
1342 char *client = libcfs_nid2str(req->rq_peer.nid);
1343 struct obd_connect_data *data, *reply;
1347 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1348 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1349 if (data == NULL || reply == NULL)
1352 /* connection from MDT is always trusted */
1353 if (req->rq_auth_usr_mdt) {
1354 ost_init_sec_none(reply, exp);
1358 /* no GSS support case */
1359 if (!req->rq_auth_gss) {
1360 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1361 CWARN("client %s -> target %s does not user GSS, "
1362 "can not run under security level %d.\n",
1363 client, obd->obd_name, filter->fo_sec_level);
1366 ost_init_sec_none(reply, exp);
1371 /* old version case */
1372 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1373 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1374 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1375 CWARN("client %s -> target %s uses old version, "
1376 "can not run under security level %d.\n",
1377 client, obd->obd_name, filter->fo_sec_level);
1380 CWARN("client %s -> target %s uses old version, "
1381 "run under security level %d.\n",
1382 client, obd->obd_name, filter->fo_sec_level);
1383 ost_init_sec_none(reply, exp);
1388 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1390 if (!req->rq_auth_remote)
1391 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1392 "asked to be remote.\n", client, obd->obd_name);
1393 } else if (req->rq_auth_remote) {
1395 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1396 "as remote by default.\n", client, obd->obd_name);
1400 if (!filter->fo_fl_oss_capa) {
1401 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1402 " but OSS capabilities are not enabled: %d.\n",
1403 client, obd->obd_name, filter->fo_fl_oss_capa);
1408 switch (filter->fo_sec_level) {
1409 case LUSTRE_SEC_NONE:
1411 ost_init_sec_none(reply, exp);
1414 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1415 "can not run under security level %d.\n",
1416 client, obd->obd_name, filter->fo_sec_level);
1419 case LUSTRE_SEC_REMOTE:
1421 ost_init_sec_none(reply, exp);
1423 case LUSTRE_SEC_ALL:
1425 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1426 OBD_CONNECT_RMT_CLIENT_FORCE);
1427 if (!filter->fo_fl_oss_capa)
1428 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1430 spin_lock(&exp->exp_lock);
1431 exp->exp_connect_flags = reply->ocd_connect_flags;
1432 spin_unlock(&exp->exp_lock);
1444 * this should be done in filter_connect()/filter_reconnect(), but
1445 * we can't obtain information like NID, which stored in incoming
1446 * request, thus can't decide what flavor to use. so we do it here.
1448 * This hack should be removed after the OST stack be rewritten, just
1449 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1451 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1453 struct obd_export *exp = req->rq_export;
1454 struct filter_obd *filter = &exp->exp_obd->u.filter;
1455 struct sptlrpc_flavor flvr;
1458 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1459 read_lock(&filter->fo_sptlrpc_lock);
1460 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1464 read_unlock(&filter->fo_sptlrpc_lock);
1466 spin_lock(&exp->exp_lock);
1468 exp->exp_sp_peer = req->rq_sp_from;
1469 exp->exp_flvr = flvr;
1471 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1472 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1473 CERROR("unauthorized rpc flavor %x from %s, "
1474 "expect %x\n", req->rq_flvr.sf_rpc,
1475 libcfs_nid2str(req->rq_peer.nid),
1476 exp->exp_flvr.sf_rpc);
1480 spin_unlock(&exp->exp_lock);
1482 if (exp->exp_sp_peer != req->rq_sp_from) {
1483 CERROR("RPC source %s doesn't match %s\n",
1484 sptlrpc_part2name(req->rq_sp_from),
1485 sptlrpc_part2name(exp->exp_sp_peer));
1488 rc = sptlrpc_target_export_check(exp, req);
1495 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1496 struct obd_device *obd, int *process)
1498 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1499 case OST_CONNECT: /* This will never get here, but for completeness. */
1500 case OST_DISCONNECT:
1511 case OBD_LOG_CANCEL:
1513 *process = target_queue_recovery_request(req, obd);
1517 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1523 int ost_msg_check_version(struct lustre_msg *msg)
1527 switch(lustre_msg_get_opc(msg)) {
1529 case OST_DISCONNECT:
1532 case SEC_CTX_INIT_CONT:
1534 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1536 CERROR("bad opc %u version %08x, expecting %08x\n",
1537 lustre_msg_get_opc(msg),
1538 lustre_msg_get_version(msg),
1539 LUSTRE_OBD_VERSION);
1552 #ifdef HAVE_QUOTA_SUPPORT
1553 case OST_QUOTACHECK:
1555 case OST_QUOTA_ADJUST_QUNIT:
1557 rc = lustre_msg_check_version(msg, LUSTRE_OST_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_OST_VERSION);
1567 case LDLM_BL_CALLBACK:
1568 case LDLM_CP_CALLBACK:
1569 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1571 CERROR("bad opc %u version %08x, expecting %08x\n",
1572 lustre_msg_get_opc(msg),
1573 lustre_msg_get_version(msg),
1574 LUSTRE_DLM_VERSION);
1576 case LLOG_ORIGIN_CONNECT:
1577 case OBD_LOG_CANCEL:
1578 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1580 CERROR("bad opc %u version %08x, expecting %08x\n",
1581 lustre_msg_get_opc(msg),
1582 lustre_msg_get_version(msg),
1583 LUSTRE_LOG_VERSION);
1586 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1592 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1593 struct ldlm_lock *lock)
1595 struct niobuf_remote *nb;
1596 struct obd_ioobj *ioo;
1597 struct ost_body *body;
1598 int objcount, niocount;
1603 opc = lustre_msg_get_opc(req->rq_reqmsg);
1604 LASSERT(opc == OST_READ || opc == OST_WRITE);
1606 /* As the request may be covered by several locks, do not look at
1607 * o_handle, look at the RPC IO region. */
1608 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
1610 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
1612 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
1613 objcount * sizeof(*ioo));
1614 LASSERT(ioo != NULL);
1615 for (niocount = i = 0; i < objcount; i++)
1616 niocount += ioo[i].ioo_bufcnt;
1618 nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
1619 niocount * sizeof(*nb));
1620 LASSERT(nb != NULL);
1623 if (opc == OST_READ)
1626 start = nb[0].offset & CFS_PAGE_MASK;
1627 end = (nb[ioo->ioo_bufcnt - 1].offset +
1628 nb[ioo->ioo_bufcnt - 1].len - 1) | ~CFS_PAGE_MASK;
1630 LASSERT(lock->l_resource != NULL);
1631 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_gr,
1632 &lock->l_resource->lr_name))
1635 if (!(lock->l_granted_mode & mode))
1638 if (lock->l_policy_data.l_extent.end < start ||
1639 lock->l_policy_data.l_extent.start > end)
1646 * Swab buffers needed to call ost_rw_prolong_locks() and call it.
1647 * Return the value from ost_rw_prolong_locks() which is non-zero if
1648 * there is a cancelled lock which is waiting for this IO request.
1650 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1652 struct niobuf_remote *nb;
1653 struct obd_ioobj *ioo;
1654 struct ost_body *body;
1655 int objcount, niocount;
1659 opc = lustre_msg_get_opc(req->rq_reqmsg);
1660 LASSERT(opc == OST_READ || opc == OST_WRITE);
1662 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
1663 LASSERT(body != NULL);
1665 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
1667 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
1668 objcount * sizeof(*ioo));
1669 LASSERT(ioo != NULL);
1671 for (niocount = i = 0; i < objcount; i++)
1672 niocount += ioo[i].ioo_bufcnt;
1673 nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
1674 niocount * sizeof(*nb));
1675 LASSERT(nb != NULL);
1676 LASSERT(niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK));
1679 if (opc == OST_READ)
1681 RETURN(ost_rw_prolong_locks(req, ioo, nb, &body->oa, mode));
1684 static int ost_punch_prolong_locks(struct ptlrpc_request *req, struct obdo *oa)
1686 struct ldlm_res_id res_id = { .name = { oa->o_id } };
1687 struct ost_prolong_data opd = { 0 };
1692 end = start + oa->o_blocks;
1694 opd.opd_mode = LCK_PW;
1695 opd.opd_exp = req->rq_export;
1696 opd.opd_policy.l_extent.start = start & CFS_PAGE_MASK;
1697 if (oa->o_blocks == OBD_OBJECT_EOF || end < start)
1698 opd.opd_policy.l_extent.end = OBD_OBJECT_EOF;
1700 opd.opd_policy.l_extent.end = end | ~CFS_PAGE_MASK;
1702 /* prolong locks for the current service time of the corresponding
1703 * portal (= OST_IO_PORTAL) */
1704 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
1705 max(at_est2timeout(at_get(&req->rq_rqbd->
1706 rqbd_service->srv_at_estimate)), ldlm_timeout);
1708 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1709 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
1710 opd.opd_policy.l_extent.end);
1713 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
1714 ost_prolong_locks_iter, &opd);
1715 RETURN(opd.opd_lock_match);
1718 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1719 struct ldlm_lock *lock)
1721 struct ost_body *body;
1724 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
1726 LASSERT(body != NULL);
1728 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1729 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1734 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1736 struct ost_body *body = lustre_msg_buf(req->rq_reqmsg,
1737 REQ_REC_OFF, sizeof(*body));
1738 LASSERT(body != NULL);
1739 LASSERT(!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1740 !(body->oa.o_flags & OBD_FL_TRUNCLOCK));
1742 RETURN(ost_punch_prolong_locks(req, &body->oa));
1745 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
1746 .hpreq_lock_match = ost_rw_hpreq_lock_match,
1747 .hpreq_check = ost_rw_hpreq_check,
1750 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
1751 .hpreq_lock_match = ost_punch_hpreq_lock_match,
1752 .hpreq_check = ost_punch_hpreq_check,
1755 /** Assign high priority operations to the request if needed. */
1756 static int ost_hpreq_handler(struct ptlrpc_request *req)
1759 if (req->rq_export) {
1760 int opc = lustre_msg_get_opc(req->rq_reqmsg);
1761 struct ost_body *body;
1763 if (opc == OST_READ || opc == OST_WRITE) {
1764 struct niobuf_remote *nb;
1765 struct obd_ioobj *ioo;
1766 int objcount, niocount;
1769 body = lustre_swab_reqbuf(req, REQ_REC_OFF,
1773 CERROR("Missing/short ost_body\n");
1776 objcount = lustre_msg_buflen(req->rq_reqmsg,
1779 if (objcount == 0) {
1780 CERROR("Missing/short ioobj\n");
1784 CERROR("too many ioobjs (%d)\n", objcount);
1788 swab = !lustre_req_swabbed(req, REQ_REC_OFF + 1) &&
1789 lustre_msg_swabbed(req->rq_reqmsg);
1790 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1,
1791 objcount * sizeof(*ioo),
1792 lustre_swab_obd_ioobj);
1794 CERROR("Missing/short ioobj\n");
1797 for (niocount = i = 0; i < objcount; i++) {
1799 lustre_swab_obd_ioobj(&ioo[i]);
1800 if (ioo[i].ioo_bufcnt == 0) {
1801 CERROR("ioo[%d] has zero bufcnt\n", i);
1804 niocount += ioo[i].ioo_bufcnt;
1806 if (niocount > PTLRPC_MAX_BRW_PAGES) {
1807 DEBUG_REQ(D_ERROR, req, "bulk has too many "
1808 "pages (%d)", niocount);
1812 swab = !lustre_req_swabbed(req, REQ_REC_OFF + 2) &&
1813 lustre_msg_swabbed(req->rq_reqmsg);
1814 nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
1815 niocount * sizeof(*nb),
1816 lustre_swab_niobuf_remote);
1818 CERROR("Missing/short niobuf\n");
1823 /* swab remaining niobufs */
1824 for (i = 1; i < niocount; i++)
1825 lustre_swab_niobuf_remote(&nb[i]);
1828 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
1829 req->rq_ops = &ost_hpreq_rw;
1830 } else if (opc == OST_PUNCH) {
1831 body = lustre_swab_reqbuf(req, REQ_REC_OFF,
1835 CERROR("Missing/short ost_body\n");
1839 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1840 !(body->oa.o_flags & OBD_FL_TRUNCLOCK))
1841 req->rq_ops = &ost_hpreq_punch;
1847 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1848 int ost_handle(struct ptlrpc_request *req)
1850 struct obd_trans_info trans_info = { 0, };
1851 struct obd_trans_info *oti = &trans_info;
1852 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1853 struct obd_device *obd = NULL;
1856 LASSERT(current->journal_info == NULL);
1858 /* primordial rpcs don't affect server recovery */
1859 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1861 case SEC_CTX_INIT_CONT:
1866 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1868 /* XXX identical to MDS */
1869 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1872 if (req->rq_export == NULL) {
1873 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1874 lustre_msg_get_opc(req->rq_reqmsg),
1875 libcfs_id2str(req->rq_peer));
1876 req->rq_status = -ENOTCONN;
1877 GOTO(out, rc = -ENOTCONN);
1880 obd = req->rq_export->exp_obd;
1882 /* Check for aborted recovery. */
1883 spin_lock_bh(&obd->obd_processing_task_lock);
1884 recovering = obd->obd_recovering;
1885 spin_unlock_bh(&obd->obd_processing_task_lock);
1887 rc = ost_filter_recovery_request(req, obd,
1889 if (rc || !should_process)
1891 else if (should_process < 0) {
1892 req->rq_status = should_process;
1893 rc = ptlrpc_error(req);
1901 rc = ost_msg_check_version(req->rq_reqmsg);
1905 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1907 CDEBUG(D_INODE, "connect\n");
1908 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
1909 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
1911 rc = target_handle_connect(req);
1912 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
1915 rc = ost_init_sec_level(req);
1917 rc = ost_connect_check_sptlrpc(req);
1921 case OST_DISCONNECT:
1922 CDEBUG(D_INODE, "disconnect\n");
1923 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
1924 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
1926 rc = target_handle_disconnect(req);
1929 CDEBUG(D_INODE, "create\n");
1930 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
1932 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1933 GOTO(out, rc = -ENOSPC);
1934 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1935 GOTO(out, rc = -EROFS);
1936 rc = ost_create(req->rq_export, req, oti);
1939 CDEBUG(D_INODE, "destroy\n");
1940 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
1942 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1943 GOTO(out, rc = -EROFS);
1944 rc = ost_destroy(req->rq_export, req, oti);
1947 CDEBUG(D_INODE, "getattr\n");
1948 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
1950 rc = ost_getattr(req->rq_export, req);
1953 CDEBUG(D_INODE, "setattr\n");
1954 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
1956 rc = ost_setattr(req->rq_export, req, oti);
1959 CDEBUG(D_INODE, "write\n");
1960 /* req->rq_request_portal would be nice, if it was set */
1961 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1962 CERROR("%s: deny write request from %s to portal %u\n",
1963 req->rq_export->exp_obd->obd_name,
1964 obd_export_nid2str(req->rq_export),
1965 req->rq_rqbd->rqbd_service->srv_req_portal);
1966 GOTO(out, rc = -EPROTO);
1968 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1970 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1971 GOTO(out, rc = -ENOSPC);
1972 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1973 GOTO(out, rc = -EROFS);
1974 rc = ost_brw_write(req, oti);
1975 LASSERT(current->journal_info == NULL);
1976 /* ost_brw_write sends its own replies */
1979 CDEBUG(D_INODE, "read\n");
1980 /* req->rq_request_portal would be nice, if it was set */
1981 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1982 CERROR("%s: deny read request from %s to portal %u\n",
1983 req->rq_export->exp_obd->obd_name,
1984 obd_export_nid2str(req->rq_export),
1985 req->rq_rqbd->rqbd_service->srv_req_portal);
1986 GOTO(out, rc = -EPROTO);
1988 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1990 rc = ost_brw_read(req, oti);
1991 LASSERT(current->journal_info == NULL);
1992 /* ost_brw_read sends its own replies */
1995 CDEBUG(D_INODE, "punch\n");
1996 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
1998 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1999 GOTO(out, rc = -EROFS);
2000 rc = ost_punch(req->rq_export, req, oti);
2003 CDEBUG(D_INODE, "statfs\n");
2004 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2006 rc = ost_statfs(req);
2009 CDEBUG(D_INODE, "sync\n");
2010 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2012 rc = ost_sync(req->rq_export, req);
2015 DEBUG_REQ(D_INODE, req, "set_info");
2016 req_capsule_set(&req->rq_pill, &RQF_OST_SET_INFO);
2017 rc = ost_set_info(req->rq_export, req);
2020 DEBUG_REQ(D_INODE, req, "get_info");
2021 rc = ost_get_info(req->rq_export, req);
2023 #ifdef HAVE_QUOTA_SUPPORT
2024 case OST_QUOTACHECK:
2025 CDEBUG(D_INODE, "quotacheck\n");
2026 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2027 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2029 rc = ost_handle_quotacheck(req);
2032 CDEBUG(D_INODE, "quotactl\n");
2033 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2034 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2036 rc = ost_handle_quotactl(req);
2038 case OST_QUOTA_ADJUST_QUNIT:
2039 CDEBUG(D_INODE, "quota_adjust_qunit\n");
2040 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
2041 rc = ost_handle_quota_adjust_qunit(req);
2045 DEBUG_REQ(D_INODE, req, "ping");
2046 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2047 rc = target_handle_ping(req);
2049 /* FIXME - just reply status */
2050 case LLOG_ORIGIN_CONNECT:
2051 DEBUG_REQ(D_INODE, req, "log connect");
2052 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2053 rc = ost_llog_handle_connect(req->rq_export, req);
2054 req->rq_status = rc;
2055 rc = req_capsule_server_pack(&req->rq_pill);
2058 RETURN(ptlrpc_reply(req));
2059 case OBD_LOG_CANCEL:
2060 CDEBUG(D_INODE, "log cancel\n");
2061 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2062 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2064 rc = llog_origin_handle_cancel(req);
2065 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2067 req->rq_status = rc;
2068 rc = req_capsule_server_pack(&req->rq_pill);
2071 RETURN(ptlrpc_reply(req));
2073 CDEBUG(D_INODE, "enqueue\n");
2074 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2075 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2077 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2078 ldlm_server_blocking_ast,
2079 ldlm_server_glimpse_ast);
2080 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2083 CDEBUG(D_INODE, "convert\n");
2084 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2085 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2087 rc = ldlm_handle_convert(req);
2090 CDEBUG(D_INODE, "cancel\n");
2091 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2092 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2094 rc = ldlm_handle_cancel(req);
2096 case LDLM_BL_CALLBACK:
2097 case LDLM_CP_CALLBACK:
2098 CDEBUG(D_INODE, "callback\n");
2099 CERROR("callbacks should not happen on OST\n");
2102 CERROR("Unexpected opcode %d\n",
2103 lustre_msg_get_opc(req->rq_reqmsg));
2104 req->rq_status = -ENOTSUPP;
2105 rc = ptlrpc_error(req);
2109 LASSERT(current->journal_info == NULL);
2112 /* If we're DISCONNECTing, the export_data is already freed */
2113 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2114 target_committed_to_req(req);
2118 oti_to_request(oti, req);
2120 target_send_reply(req, rc, fail);
2123 EXPORT_SYMBOL(ost_handle);
2125 * free per-thread pool created by ost_thread_init().
2127 static void ost_thread_done(struct ptlrpc_thread *thread)
2129 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2134 LASSERT(thread != NULL);
2137 * be prepared to handle partially-initialized pools (because this is
2138 * called from ost_thread_init() for cleanup.
2140 tls = thread->t_data;
2143 thread->t_data = NULL;
2149 * initialize per-thread page pool (bug 5137).
2151 static int ost_thread_init(struct ptlrpc_thread *thread)
2153 struct ost_thread_local_cache *tls;
2157 LASSERT(thread != NULL);
2158 LASSERT(thread->t_data == NULL);
2159 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
2164 thread->t_data = tls;
2168 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2170 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2171 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2173 struct ost_obd *ost = &obd->u.ost;
2174 struct lprocfs_static_vars lvars;
2175 int oss_min_threads;
2176 int oss_max_threads;
2177 int oss_min_create_threads;
2178 int oss_max_create_threads;
2182 rc = cleanup_group_info();
2186 lprocfs_ost_init_vars(&lvars);
2187 lprocfs_obd_setup(obd, lvars.obd_vars);
2189 sema_init(&ost->ost_health_sem, 1);
2191 if (oss_num_threads) {
2192 /* If oss_num_threads is set, it is the min and the max. */
2193 if (oss_num_threads > OSS_THREADS_MAX)
2194 oss_num_threads = OSS_THREADS_MAX;
2195 if (oss_num_threads < OSS_THREADS_MIN)
2196 oss_num_threads = OSS_THREADS_MIN;
2197 oss_max_threads = oss_min_threads = oss_num_threads;
2199 /* Base min threads on memory and cpus */
2200 oss_min_threads = num_possible_cpus() * num_physpages >>
2201 (27 - CFS_PAGE_SHIFT);
2202 if (oss_min_threads < OSS_THREADS_MIN)
2203 oss_min_threads = OSS_THREADS_MIN;
2204 /* Insure a 4x range for dynamic threads */
2205 if (oss_min_threads > OSS_THREADS_MAX / 4)
2206 oss_min_threads = OSS_THREADS_MAX / 4;
2207 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
2211 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2212 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
2213 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2214 ost_handle, LUSTRE_OSS_NAME,
2215 obd->obd_proc_entry, target_print_req,
2216 oss_min_threads, oss_max_threads,
2217 "ll_ost", LCT_DT_THREAD, NULL);
2218 if (ost->ost_service == NULL) {
2219 CERROR("failed to start service\n");
2220 GOTO(out_lprocfs, rc = -ENOMEM);
2223 rc = ptlrpc_start_threads(obd, ost->ost_service);
2225 GOTO(out_service, rc = -EINVAL);
2227 if (oss_num_create_threads) {
2228 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
2229 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
2230 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
2231 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
2232 oss_min_create_threads = oss_max_create_threads =
2233 oss_num_create_threads;
2235 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
2236 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
2239 ost->ost_create_service =
2240 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2241 OST_MAXREPSIZE, OST_CREATE_PORTAL,
2242 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2243 ost_handle, "ost_create",
2244 obd->obd_proc_entry, target_print_req,
2245 oss_min_create_threads, oss_max_create_threads,
2246 "ll_ost_creat", LCT_DT_THREAD, NULL);
2247 if (ost->ost_create_service == NULL) {
2248 CERROR("failed to start OST create service\n");
2249 GOTO(out_service, rc = -ENOMEM);
2252 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
2254 GOTO(out_create, rc = -EINVAL);
2256 ost->ost_io_service =
2257 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2258 OST_MAXREPSIZE, OST_IO_PORTAL,
2259 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2260 ost_handle, "ost_io",
2261 obd->obd_proc_entry, target_print_req,
2262 oss_min_threads, oss_max_threads,
2263 "ll_ost_io", LCT_DT_THREAD, ost_hpreq_handler);
2264 if (ost->ost_io_service == NULL) {
2265 CERROR("failed to start OST I/O service\n");
2266 GOTO(out_create, rc = -ENOMEM);
2269 ost->ost_io_service->srv_init = ost_thread_init;
2270 ost->ost_io_service->srv_done = ost_thread_done;
2271 ost->ost_io_service->srv_cpu_affinity = 1;
2272 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
2274 GOTO(out_io, rc = -EINVAL);
2276 ping_evictor_start();
2281 ptlrpc_unregister_service(ost->ost_io_service);
2282 ost->ost_io_service = NULL;
2284 ptlrpc_unregister_service(ost->ost_create_service);
2285 ost->ost_create_service = NULL;
2287 ptlrpc_unregister_service(ost->ost_service);
2288 ost->ost_service = NULL;
2290 lprocfs_obd_cleanup(obd);
2294 static int ost_cleanup(struct obd_device *obd)
2296 struct ost_obd *ost = &obd->u.ost;
2300 ping_evictor_stop();
2302 spin_lock_bh(&obd->obd_processing_task_lock);
2303 if (obd->obd_recovering) {
2304 target_cancel_recovery_timer(obd);
2305 obd->obd_recovering = 0;
2307 spin_unlock_bh(&obd->obd_processing_task_lock);
2309 down(&ost->ost_health_sem);
2310 ptlrpc_unregister_service(ost->ost_service);
2311 ptlrpc_unregister_service(ost->ost_create_service);
2312 ptlrpc_unregister_service(ost->ost_io_service);
2313 ost->ost_service = NULL;
2314 ost->ost_create_service = NULL;
2315 up(&ost->ost_health_sem);
2317 lprocfs_obd_cleanup(obd);
2322 static int ost_health_check(struct obd_device *obd)
2324 struct ost_obd *ost = &obd->u.ost;
2327 down(&ost->ost_health_sem);
2328 rc |= ptlrpc_service_health_check(ost->ost_service);
2329 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2330 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2331 up(&ost->ost_health_sem);
2334 * health_check to return 0 on healthy
2335 * and 1 on unhealthy.
2343 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2345 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2348 /* use obd ops to offer management infrastructure */
2349 static struct obd_ops ost_obd_ops = {
2350 .o_owner = THIS_MODULE,
2351 .o_setup = ost_setup,
2352 .o_cleanup = ost_cleanup,
2353 .o_health_check = ost_health_check,
2357 static int __init ost_init(void)
2359 struct lprocfs_static_vars lvars;
2363 lprocfs_ost_init_vars(&lvars);
2364 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2365 LUSTRE_OSS_NAME, NULL);
2367 if (ost_num_threads != 0 && oss_num_threads == 0) {
2368 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2369 "use oss_num_threads instead or unset both for "
2370 "dynamic thread startup\n");
2371 oss_num_threads = ost_num_threads;
2377 static void /*__exit*/ ost_exit(void)
2379 class_unregister_type(LUSTRE_OSS_NAME);
2382 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2383 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2384 MODULE_LICENSE("GPL");
2386 module_init(ost_init);
2387 module_exit(ost_exit);