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 CDEBUG(D_DLMTRACE,"refresh lock: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
542 lock->l_resource->lr_name.name[0],
543 lock->l_resource->lr_name.name[1],
544 opd->opd_policy.l_extent.start, opd->opd_policy.l_extent.end);
545 /* OK. this is a possible lock the user holds doing I/O
546 * let's refresh eviction timer for it */
547 ldlm_refresh_waiting_lock(lock, opd->opd_timeout);
548 opd->opd_lock_match = 1;
550 return LDLM_ITER_CONTINUE;
553 static int ost_rw_prolong_locks(struct ptlrpc_request *req, struct obd_ioobj *obj,
554 struct niobuf_remote *nb, struct obdo *oa,
557 struct ldlm_res_id res_id;
558 int nrbufs = obj->ioo_bufcnt;
559 struct ost_prolong_data opd = { 0 };
562 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
565 opd.opd_exp = req->rq_export;
566 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
567 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
568 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
570 /* prolong locks for the current service time of the corresponding
571 * portal (= OST_IO_PORTAL) */
572 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
573 max(at_est2timeout(at_get(&req->rq_rqbd->
574 rqbd_service->srv_at_estimate)), ldlm_timeout);
576 CDEBUG(D_INFO,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
577 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
578 opd.opd_policy.l_extent.end);
580 if (oa->o_valid & OBD_MD_FLHANDLE) {
581 struct ldlm_lock *lock;
583 lock = ldlm_handle2lock(&oa->o_handle);
585 ost_prolong_locks_iter(lock, &opd);
586 if (opd.opd_lock_match) {
591 /* Check if the lock covers the whole IO region,
592 * otherwise iterate through the resource. */
593 if (lock->l_policy_data.l_extent.end >=
594 opd.opd_policy.l_extent.end &&
595 lock->l_policy_data.l_extent.start <=
596 opd.opd_policy.l_extent.start) {
605 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
606 ost_prolong_locks_iter, &opd);
607 RETURN(opd.opd_lock_match);
610 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
612 struct ptlrpc_bulk_desc *desc = NULL;
613 struct obd_export *exp = req->rq_export;
614 struct niobuf_remote *remote_nb;
615 struct niobuf_local *local_nb;
616 struct obd_ioobj *ioo;
617 struct ost_body *body, *repbody;
618 struct lustre_capa *capa = NULL;
619 struct l_wait_info lwi;
620 struct lustre_handle lockh = { 0 };
621 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
622 int niocount, npages, nob = 0, rc, i;
626 req->rq_bulk_read = 1;
628 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
629 GOTO(out, rc = -EIO);
631 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
633 /* Check if there is eviction in progress, and if so, wait for it to
635 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
636 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
637 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
638 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
642 GOTO(out, rc = -ENOTCONN);
644 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
645 * ost_rw_hpreq_check(). */
646 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
647 LASSERT(body != NULL);
649 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, sizeof(*ioo));
650 LASSERT(ioo != NULL);
652 niocount = ioo->ioo_bufcnt;
653 remote_nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
654 niocount * sizeof(*remote_nb));
655 LASSERT(remote_nb != NULL);
657 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
658 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
660 rc = lustre_pack_reply(req, 2, size, NULL);
665 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
668 local_nb = ost_tls(req)->local;
670 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
675 * If getting the lock took more time than
676 * client was willing to wait, drop it. b=11330
678 if (cfs_time_current_sec() > req->rq_deadline ||
679 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
681 CERROR("Dropping timed-out read from %s because locking"
682 "object "LPX64" took %ld seconds (limit was %ld).\n",
683 libcfs_id2str(req->rq_peer), ioo->ioo_id,
684 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
685 req->rq_deadline - req->rq_arrival_time.tv_sec);
686 GOTO(out_lock, rc = -ETIMEDOUT);
689 npages = OST_THREAD_POOL_SIZE;
690 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
691 remote_nb, &npages, local_nb, oti, capa);
695 desc = ptlrpc_prep_bulk_exp(req, npages,
696 BULK_PUT_SOURCE, OST_BULK_PORTAL);
697 if (desc == NULL) /* XXX: check all cleanup stuff */
698 GOTO(out, rc = -ENOMEM);
700 ost_rw_prolong_locks(req, ioo, remote_nb, &body->oa, LCK_PW | LCK_PR);
703 for (i = 0; i < npages; i++) {
704 int page_rc = local_nb[i].rc;
706 if (page_rc < 0) { /* error */
712 if (page_rc != 0) { /* some data! */
713 LASSERT (local_nb[i].page != NULL);
714 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
715 local_nb[i].offset & ~CFS_PAGE_MASK,
719 if (page_rc != local_nb[i].len) { /* short read */
720 /* All subsequent pages should be 0 */
722 LASSERT(local_nb[i].rc == 0);
727 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
728 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
730 if (body->oa.o_valid & OBD_MD_FLFLAGS)
731 cksum_type = cksum_type_unpack(body->oa.o_flags);
732 body->oa.o_flags = cksum_type_pack(cksum_type);
733 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
734 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
735 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
737 body->oa.o_valid = 0;
739 /* We're finishing using body->oa as an input variable */
741 /* Check if client was evicted while we were doing i/o before touching
744 /* Check if there is eviction in progress, and if so, wait for
746 if (unlikely(atomic_read(&exp->exp_obd->
747 obd_evict_inprogress))) {
748 lwi = LWI_INTR(NULL, NULL);
749 rc = l_wait_event(exp->exp_obd->
750 obd_evict_inprogress_waitq,
751 !atomic_read(&exp->exp_obd->
752 obd_evict_inprogress),
758 rc = sptlrpc_svc_wrap_bulk(req, desc);
760 rc = ptlrpc_start_bulk_transfer(desc);
764 time_t start = cfs_time_current_sec();
766 long timeoutl = req->rq_deadline -
767 cfs_time_current_sec();
768 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
769 CFS_TICK : cfs_time_seconds(timeoutl);
770 lwi = LWI_TIMEOUT_INTERVAL(timeout,
774 rc = l_wait_event(desc->bd_waitq,
775 !ptlrpc_server_bulk_active(desc) ||
777 exp->exp_abort_active_req,
779 LASSERT(rc == 0 || rc == -ETIMEDOUT);
780 /* Wait again if we changed deadline */
781 } while ((rc == -ETIMEDOUT) &&
782 (req->rq_deadline > cfs_time_current_sec()));
784 if (rc == -ETIMEDOUT) {
785 DEBUG_REQ(D_ERROR, req,
786 "timeout on bulk PUT after %ld%+lds",
787 req->rq_deadline - start,
788 cfs_time_current_sec() -
790 ptlrpc_abort_bulk(desc);
791 } else if (exp->exp_failed) {
792 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
794 ptlrpc_abort_bulk(desc);
795 } else if (exp->exp_abort_active_req) {
796 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk PUT");
797 /* we don't reply anyway */
799 ptlrpc_abort_bulk(desc);
800 } else if (!desc->bd_success ||
801 desc->bd_nob_transferred != desc->bd_nob) {
802 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
804 "truncated" : "network error on",
805 desc->bd_nob_transferred,
807 /* XXX should this be a different errno? */
811 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
816 /* Must commit after prep above in all cases */
817 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
818 remote_nb, npages, local_nb, oti, rc);
821 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
823 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
824 ost_drop_id(exp, &repbody->oa);
828 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
831 ptlrpc_free_bulk(desc);
835 req->rq_status = nob;
836 ptlrpc_lprocfs_brw(req, nob);
837 target_committed_to_req(req);
839 } else if (!no_reply) {
840 /* Only reply if there was no comms problem with bulk */
841 target_committed_to_req(req);
845 /* reply out callback would free */
846 ptlrpc_req_drop_rs(req);
847 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
848 "client will retry\n",
849 exp->exp_obd->obd_name,
850 exp->exp_client_uuid.uuid,
851 exp->exp_connection->c_remote_uuid.uuid,
852 libcfs_id2str(req->rq_peer));
858 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
860 struct ptlrpc_bulk_desc *desc = NULL;
861 struct obd_export *exp = req->rq_export;
862 struct niobuf_remote *remote_nb;
863 struct niobuf_local *local_nb;
864 struct obd_ioobj *ioo;
865 struct ost_body *body, *repbody;
866 struct l_wait_info lwi;
867 struct lustre_handle lockh = {0};
868 struct lustre_capa *capa = NULL;
870 __u32 size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
871 int objcount, niocount, npages;
873 obd_count client_cksum = 0, server_cksum = 0;
874 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
876 __u32 o_uid = 0, o_gid = 0;
879 req->rq_bulk_write = 1;
881 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
882 GOTO(out, rc = -EIO);
883 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
884 GOTO(out, rc = -EFAULT);
886 /* pause before transaction has been started */
887 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
889 /* Check if there is eviction in progress, and if so, wait for it to
891 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
892 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
893 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
894 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
898 GOTO(out, rc = -ENOTCONN);
900 /* ost_body, ioobj & noibuf_remote are verified and swabbed in
901 * ost_rw_hpreq_check(). */
902 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
903 LASSERT(body != NULL);
905 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
907 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
908 objcount * sizeof(*ioo));
909 LASSERT(ioo != NULL);
910 for (niocount = i = 0; i < objcount; i++)
911 niocount += ioo[i].ioo_bufcnt;
913 remote_nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
914 niocount * sizeof(*remote_nb));
915 LASSERT(remote_nb != NULL);
917 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
918 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
920 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
921 rc = lustre_pack_reply(req, 3, size, NULL);
924 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, obd_fail_val);
925 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
926 niocount * sizeof(*rcs));
929 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
932 local_nb = ost_tls(req)->local;
934 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
939 * If getting the lock took more time than
940 * client was willing to wait, drop it. b=11330
942 if (cfs_time_current_sec() > req->rq_deadline ||
943 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
945 CERROR("Dropping timed-out write from %s because locking "
946 "object "LPX64" took %ld seconds (limit was %ld).\n",
947 libcfs_id2str(req->rq_peer), ioo->ioo_id,
948 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
949 req->rq_deadline - req->rq_arrival_time.tv_sec);
950 GOTO(out_lock, rc = -ETIMEDOUT);
953 ost_rw_prolong_locks(req, ioo, remote_nb,&body->oa, LCK_PW);
955 /* obd_preprw clobbers oa->valid, so save what we need */
956 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
957 client_cksum = body->oa.o_cksum;
958 if (body->oa.o_valid & OBD_MD_FLFLAGS)
959 cksum_type = cksum_type_unpack(body->oa.o_flags);
962 /* Because we already sync grant info with client when reconnect,
963 * grant info will be cleared for resent req, then fed_grant and
964 * total_grant will not be modified in following preprw_write */
965 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
966 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
967 body->oa.o_valid &= ~OBD_MD_FLGRANT;
970 if (exp_connect_rmtclient(exp)) {
971 o_uid = body->oa.o_uid;
972 o_gid = body->oa.o_gid;
974 npages = OST_THREAD_POOL_SIZE;
975 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
976 ioo, remote_nb, &npages, local_nb, oti, capa);
980 desc = ptlrpc_prep_bulk_exp(req, npages,
981 BULK_GET_SINK, OST_BULK_PORTAL);
983 GOTO(out, rc = -ENOMEM);
985 /* NB Having prepped, we must commit... */
987 for (i = 0; i < npages; i++)
988 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
989 local_nb[i].offset & ~CFS_PAGE_MASK,
992 rc = sptlrpc_svc_prep_bulk(req, desc);
996 /* Check if client was evicted while we were doing i/o before touching
998 if (desc->bd_export->exp_failed)
1001 rc = ptlrpc_start_bulk_transfer(desc);
1003 time_t start = cfs_time_current_sec();
1005 long timeoutl = req->rq_deadline -
1006 cfs_time_current_sec();
1007 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
1008 CFS_TICK : cfs_time_seconds(timeoutl);
1009 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
1010 ost_bulk_timeout, desc);
1011 rc = l_wait_event(desc->bd_waitq,
1012 !ptlrpc_server_bulk_active(desc) ||
1013 desc->bd_export->exp_failed ||
1014 desc->bd_export->exp_abort_active_req,
1016 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1017 /* Wait again if we changed deadline */
1018 } while ((rc == -ETIMEDOUT) &&
1019 (req->rq_deadline > cfs_time_current_sec()));
1021 if (rc == -ETIMEDOUT) {
1022 DEBUG_REQ(D_ERROR, req,
1023 "timeout on bulk GET after %ld%+lds",
1024 req->rq_deadline - start,
1025 cfs_time_current_sec() -
1027 ptlrpc_abort_bulk(desc);
1028 } else if (desc->bd_export->exp_failed) {
1029 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1031 ptlrpc_abort_bulk(desc);
1032 } else if (desc->bd_export->exp_abort_active_req) {
1033 DEBUG_REQ(D_ERROR, req, "Reconnect on bulk GET");
1034 /* we don't reply anyway */
1036 ptlrpc_abort_bulk(desc);
1037 } else if (!desc->bd_success) {
1038 DEBUG_REQ(D_ERROR, req, "network error on bulk GET");
1039 /* XXX should this be a different errno? */
1042 rc = sptlrpc_svc_unwrap_bulk(req, desc);
1045 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1049 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1051 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1053 if (unlikely(client_cksum != 0 && rc == 0)) {
1054 static int cksum_counter;
1055 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1056 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1057 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1058 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1059 repbody->oa.o_cksum = server_cksum;
1061 if (unlikely(client_cksum != server_cksum)) {
1062 CERROR("client csum %x, server csum %x\n",
1063 client_cksum, server_cksum);
1065 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1066 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1067 cksum_counter, libcfs_id2str(req->rq_peer),
1072 /* Must commit after prep above in all cases */
1073 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1074 remote_nb, npages, local_nb, oti, rc);
1075 if (exp_connect_rmtclient(exp)) {
1076 repbody->oa.o_uid = o_uid;
1077 repbody->oa.o_gid = o_gid;
1080 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1081 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1086 if (new_cksum == server_cksum)
1087 msg = "changed in transit before arrival at OST";
1088 else if (new_cksum == client_cksum)
1089 msg = "initial checksum before message complete";
1091 msg = "changed in transit AND after initial checksum";
1093 if (req->rq_peer.nid == desc->bd_sender) {
1097 router = libcfs_nid2str(desc->bd_sender);
1100 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1101 "%s%s%s inum "LPU64"/"LPU64" object "
1102 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1103 exp->exp_obd->obd_name, msg,
1104 libcfs_id2str(req->rq_peer),
1106 body->oa.o_valid & OBD_MD_FLFID ?
1107 body->oa.o_fid : (__u64)0,
1108 body->oa.o_valid & OBD_MD_FLFID ?
1109 body->oa.o_generation :(__u64)0,
1111 body->oa.o_valid & OBD_MD_FLGROUP ?
1112 body->oa.o_gr : (__u64)0,
1114 local_nb[npages-1].offset +
1115 local_nb[npages-1].len - 1 );
1116 CERROR("client csum %x, original server csum %x, "
1117 "server csum now %x\n",
1118 client_cksum, server_cksum, new_cksum);
1124 /* set per-requested niobuf return codes */
1125 for (i = j = 0; i < niocount; i++) {
1126 int len = remote_nb[i].len;
1131 LASSERT(j < npages);
1132 if (local_nb[j].rc < 0)
1133 rcs[i] = local_nb[j].rc;
1134 len -= local_nb[j].len;
1139 LASSERT(j == npages);
1140 ptlrpc_lprocfs_brw(req, nob);
1144 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1147 ptlrpc_free_bulk(desc);
1150 oti_to_request(oti, req);
1151 target_committed_to_req(req);
1152 rc = ptlrpc_reply(req);
1153 } else if (!no_reply) {
1154 /* Only reply if there was no comms problem with bulk */
1155 target_committed_to_req(req);
1156 req->rq_status = rc;
1159 /* reply out callback would free */
1160 ptlrpc_req_drop_rs(req);
1161 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1162 "client will retry\n",
1163 exp->exp_obd->obd_name,
1164 exp->exp_client_uuid.uuid,
1165 exp->exp_connection->c_remote_uuid.uuid,
1166 libcfs_id2str(req->rq_peer));
1171 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1173 struct ost_body *body = NULL, *repbody;
1174 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
1175 char *key, *val = NULL;
1176 int keylen, vallen, rc = 0;
1179 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1181 DEBUG_REQ(D_HA, req, "no set_info key");
1184 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1186 if (KEY_IS(KEY_GRANT_SHRINK)) {
1187 rc = lustre_pack_reply(req, 2, size, NULL);
1191 rc = lustre_pack_reply(req, 1, NULL, NULL);
1196 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1198 if (KEY_IS(KEY_GRANT_SHRINK)) {
1199 body = lustre_swab_reqbuf(req, REQ_REC_OFF + 1,
1201 lustre_swab_ost_body);
1205 repbody = lustre_msg_buf(req->rq_repmsg,
1208 memcpy(repbody, body, sizeof(*body));
1209 val = (char*)repbody;
1211 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,0);
1214 if (KEY_IS(KEY_EVICT_BY_NID)) {
1216 obd_export_evict_by_nid(exp->exp_obd, val);
1218 } else if (KEY_IS(KEY_MDS_CONN) && lustre_msg_swabbed(req->rq_reqmsg)) {
1219 /* Val's are not swabbed automatically */
1220 __swab32s((__u32 *)val);
1223 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1225 lustre_msg_set_status(req->rq_repmsg, 0);
1229 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1232 int keylen, replylen, rc = 0;
1233 struct req_capsule *pill = &req->rq_pill;
1236 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
1238 /* this common part for get_info rpc */
1239 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1241 DEBUG_REQ(D_HA, req, "no get_info key");
1244 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1246 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1250 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1251 RCL_SERVER, replylen);
1253 rc = req_capsule_server_pack(pill);
1257 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1261 /* call again to fill in the reply buffer */
1262 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1264 lustre_msg_set_status(req->rq_repmsg, 0);
1268 #ifdef HAVE_QUOTA_SUPPORT
1269 static int ost_handle_quotactl(struct ptlrpc_request *req)
1271 struct obd_quotactl *oqctl, *repoqc;
1275 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1277 GOTO(out, rc = -EPROTO);
1279 rc = req_capsule_server_pack(&req->rq_pill);
1283 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1284 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1291 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1293 struct obd_quotactl *oqctl;
1297 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1301 rc = req_capsule_server_pack(&req->rq_pill);
1305 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1309 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1311 struct quota_adjust_qunit *oqaq, *repoqa;
1312 struct lustre_quota_ctxt *qctxt;
1316 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1317 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1319 GOTO(out, rc = -EPROTO);
1321 rc = req_capsule_server_pack(&req->rq_pill);
1325 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1326 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt);
1334 static int ost_llog_handle_connect(struct obd_export *exp,
1335 struct ptlrpc_request *req)
1337 struct llogd_conn_body *body;
1341 body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body));
1342 rc = obd_llog_connect(exp, body);
1346 #define ost_init_sec_none(reply, exp) \
1348 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1349 OBD_CONNECT_RMT_CLIENT_FORCE | \
1350 OBD_CONNECT_OSS_CAPA); \
1351 spin_lock(&exp->exp_lock); \
1352 exp->exp_connect_flags = reply->ocd_connect_flags; \
1353 spin_unlock(&exp->exp_lock); \
1356 static int ost_init_sec_level(struct ptlrpc_request *req)
1358 struct obd_export *exp = req->rq_export;
1359 struct req_capsule *pill = &req->rq_pill;
1360 struct obd_device *obd = exp->exp_obd;
1361 struct filter_obd *filter = &obd->u.filter;
1362 char *client = libcfs_nid2str(req->rq_peer.nid);
1363 struct obd_connect_data *data, *reply;
1367 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1368 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1369 if (data == NULL || reply == NULL)
1372 /* connection from MDT is always trusted */
1373 if (req->rq_auth_usr_mdt) {
1374 ost_init_sec_none(reply, exp);
1378 /* no GSS support case */
1379 if (!req->rq_auth_gss) {
1380 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1381 CWARN("client %s -> target %s does not user GSS, "
1382 "can not run under security level %d.\n",
1383 client, obd->obd_name, filter->fo_sec_level);
1386 ost_init_sec_none(reply, exp);
1391 /* old version case */
1392 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1393 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1394 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1395 CWARN("client %s -> target %s uses old version, "
1396 "can not run under security level %d.\n",
1397 client, obd->obd_name, filter->fo_sec_level);
1400 CWARN("client %s -> target %s uses old version, "
1401 "run under security level %d.\n",
1402 client, obd->obd_name, filter->fo_sec_level);
1403 ost_init_sec_none(reply, exp);
1408 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1410 if (!req->rq_auth_remote)
1411 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1412 "asked to be remote.\n", client, obd->obd_name);
1413 } else if (req->rq_auth_remote) {
1415 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1416 "as remote by default.\n", client, obd->obd_name);
1420 if (!filter->fo_fl_oss_capa) {
1421 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1422 " but OSS capabilities are not enabled: %d.\n",
1423 client, obd->obd_name, filter->fo_fl_oss_capa);
1428 switch (filter->fo_sec_level) {
1429 case LUSTRE_SEC_NONE:
1431 ost_init_sec_none(reply, exp);
1434 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1435 "can not run under security level %d.\n",
1436 client, obd->obd_name, filter->fo_sec_level);
1439 case LUSTRE_SEC_REMOTE:
1441 ost_init_sec_none(reply, exp);
1443 case LUSTRE_SEC_ALL:
1445 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1446 OBD_CONNECT_RMT_CLIENT_FORCE);
1447 if (!filter->fo_fl_oss_capa)
1448 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1450 spin_lock(&exp->exp_lock);
1451 exp->exp_connect_flags = reply->ocd_connect_flags;
1452 spin_unlock(&exp->exp_lock);
1464 * this should be done in filter_connect()/filter_reconnect(), but
1465 * we can't obtain information like NID, which stored in incoming
1466 * request, thus can't decide what flavor to use. so we do it here.
1468 * This hack should be removed after the OST stack be rewritten, just
1469 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1471 static int ost_connect_check_sptlrpc(struct ptlrpc_request *req)
1473 struct obd_export *exp = req->rq_export;
1474 struct filter_obd *filter = &exp->exp_obd->u.filter;
1475 struct sptlrpc_flavor flvr;
1478 if (unlikely(strcmp(exp->exp_obd->obd_type->typ_name,
1479 LUSTRE_ECHO_NAME) == 0)) {
1480 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY;
1484 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
1485 read_lock(&filter->fo_sptlrpc_lock);
1486 sptlrpc_target_choose_flavor(&filter->fo_sptlrpc_rset,
1490 read_unlock(&filter->fo_sptlrpc_lock);
1492 spin_lock(&exp->exp_lock);
1494 exp->exp_sp_peer = req->rq_sp_from;
1495 exp->exp_flvr = flvr;
1497 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
1498 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1499 CERROR("unauthorized rpc flavor %x from %s, "
1500 "expect %x\n", req->rq_flvr.sf_rpc,
1501 libcfs_nid2str(req->rq_peer.nid),
1502 exp->exp_flvr.sf_rpc);
1506 spin_unlock(&exp->exp_lock);
1508 if (exp->exp_sp_peer != req->rq_sp_from) {
1509 CERROR("RPC source %s doesn't match %s\n",
1510 sptlrpc_part2name(req->rq_sp_from),
1511 sptlrpc_part2name(exp->exp_sp_peer));
1514 rc = sptlrpc_target_export_check(exp, req);
1521 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1522 struct obd_device *obd, int *process)
1524 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1525 case OST_CONNECT: /* This will never get here, but for completeness. */
1526 case OST_DISCONNECT:
1537 case OBD_LOG_CANCEL:
1539 *process = target_queue_recovery_request(req, obd);
1543 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1549 int ost_msg_check_version(struct lustre_msg *msg)
1553 switch(lustre_msg_get_opc(msg)) {
1555 case OST_DISCONNECT:
1558 case SEC_CTX_INIT_CONT:
1560 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1562 CERROR("bad opc %u version %08x, expecting %08x\n",
1563 lustre_msg_get_opc(msg),
1564 lustre_msg_get_version(msg),
1565 LUSTRE_OBD_VERSION);
1578 #ifdef HAVE_QUOTA_SUPPORT
1579 case OST_QUOTACHECK:
1581 case OST_QUOTA_ADJUST_QUNIT:
1583 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1585 CERROR("bad opc %u version %08x, expecting %08x\n",
1586 lustre_msg_get_opc(msg),
1587 lustre_msg_get_version(msg),
1588 LUSTRE_OST_VERSION);
1593 case LDLM_BL_CALLBACK:
1594 case LDLM_CP_CALLBACK:
1595 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1597 CERROR("bad opc %u version %08x, expecting %08x\n",
1598 lustre_msg_get_opc(msg),
1599 lustre_msg_get_version(msg),
1600 LUSTRE_DLM_VERSION);
1602 case LLOG_ORIGIN_CONNECT:
1603 case OBD_LOG_CANCEL:
1604 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1606 CERROR("bad opc %u version %08x, expecting %08x\n",
1607 lustre_msg_get_opc(msg),
1608 lustre_msg_get_version(msg),
1609 LUSTRE_LOG_VERSION);
1612 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1618 static int ost_rw_hpreq_lock_match(struct ptlrpc_request *req,
1619 struct ldlm_lock *lock)
1621 struct niobuf_remote *nb;
1622 struct obd_ioobj *ioo;
1623 struct ost_body *body;
1624 int objcount, niocount;
1629 opc = lustre_msg_get_opc(req->rq_reqmsg);
1630 LASSERT(opc == OST_READ || opc == OST_WRITE);
1632 /* As the request may be covered by several locks, do not look at
1633 * o_handle, look at the RPC IO region. */
1634 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
1636 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
1638 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
1639 objcount * sizeof(*ioo));
1640 LASSERT(ioo != NULL);
1641 for (niocount = i = 0; i < objcount; i++)
1642 niocount += ioo[i].ioo_bufcnt;
1644 nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
1645 niocount * sizeof(*nb));
1646 LASSERT(nb != NULL);
1649 if (opc == OST_READ)
1652 start = nb[0].offset & CFS_PAGE_MASK;
1653 end = (nb[ioo->ioo_bufcnt - 1].offset +
1654 nb[ioo->ioo_bufcnt - 1].len - 1) | ~CFS_PAGE_MASK;
1656 LASSERT(lock->l_resource != NULL);
1657 if (!osc_res_name_eq(ioo->ioo_id, ioo->ioo_gr,
1658 &lock->l_resource->lr_name))
1661 if (!(lock->l_granted_mode & mode))
1664 if (lock->l_policy_data.l_extent.end < start ||
1665 lock->l_policy_data.l_extent.start > end)
1672 * Swab buffers needed to call ost_rw_prolong_locks() and call it.
1673 * Return the value from ost_rw_prolong_locks() which is non-zero if
1674 * there is a cancelled lock which is waiting for this IO request.
1676 static int ost_rw_hpreq_check(struct ptlrpc_request *req)
1678 struct niobuf_remote *nb;
1679 struct obd_ioobj *ioo;
1680 struct ost_body *body;
1681 int objcount, niocount;
1685 opc = lustre_msg_get_opc(req->rq_reqmsg);
1686 LASSERT(opc == OST_READ || opc == OST_WRITE);
1688 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
1689 LASSERT(body != NULL);
1691 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
1693 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
1694 objcount * sizeof(*ioo));
1695 LASSERT(ioo != NULL);
1697 for (niocount = i = 0; i < objcount; i++)
1698 niocount += ioo[i].ioo_bufcnt;
1699 nb = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2,
1700 niocount * sizeof(*nb));
1701 LASSERT(nb != NULL);
1702 LASSERT(niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK));
1705 if (opc == OST_READ)
1707 RETURN(ost_rw_prolong_locks(req, ioo, nb, &body->oa, mode));
1710 static int ost_punch_prolong_locks(struct ptlrpc_request *req, struct obdo *oa)
1712 struct ldlm_res_id res_id = { .name = { oa->o_id } };
1713 struct ost_prolong_data opd = { 0 };
1718 end = start + oa->o_blocks;
1720 opd.opd_mode = LCK_PW;
1721 opd.opd_exp = req->rq_export;
1722 opd.opd_policy.l_extent.start = start & CFS_PAGE_MASK;
1723 if (oa->o_blocks == OBD_OBJECT_EOF || end < start)
1724 opd.opd_policy.l_extent.end = OBD_OBJECT_EOF;
1726 opd.opd_policy.l_extent.end = end | ~CFS_PAGE_MASK;
1728 /* prolong locks for the current service time of the corresponding
1729 * portal (= OST_IO_PORTAL) */
1730 opd.opd_timeout = AT_OFF ? obd_timeout / 2:
1731 max(at_est2timeout(at_get(&req->rq_rqbd->
1732 rqbd_service->srv_at_estimate)), ldlm_timeout);
1734 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
1735 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
1736 opd.opd_policy.l_extent.end);
1739 ldlm_resource_iterate(req->rq_export->exp_obd->obd_namespace, &res_id,
1740 ost_prolong_locks_iter, &opd);
1741 RETURN(opd.opd_lock_match);
1744 static int ost_punch_hpreq_lock_match(struct ptlrpc_request *req,
1745 struct ldlm_lock *lock)
1747 struct ost_body *body;
1750 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
1752 LASSERT(body != NULL);
1754 if (body->oa.o_valid & OBD_MD_FLHANDLE &&
1755 body->oa.o_handle.cookie == lock->l_handle.h_cookie)
1760 static int ost_punch_hpreq_check(struct ptlrpc_request *req)
1762 struct ost_body *body = lustre_msg_buf(req->rq_reqmsg,
1763 REQ_REC_OFF, sizeof(*body));
1764 LASSERT(body != NULL);
1765 LASSERT(!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1766 !(body->oa.o_flags & OBD_FL_TRUNCLOCK));
1768 RETURN(ost_punch_prolong_locks(req, &body->oa));
1771 struct ptlrpc_hpreq_ops ost_hpreq_rw = {
1772 .hpreq_lock_match = ost_rw_hpreq_lock_match,
1773 .hpreq_check = ost_rw_hpreq_check,
1776 struct ptlrpc_hpreq_ops ost_hpreq_punch = {
1777 .hpreq_lock_match = ost_punch_hpreq_lock_match,
1778 .hpreq_check = ost_punch_hpreq_check,
1781 /** Assign high priority operations to the request if needed. */
1782 static int ost_hpreq_handler(struct ptlrpc_request *req)
1785 if (req->rq_export) {
1786 int opc = lustre_msg_get_opc(req->rq_reqmsg);
1787 struct ost_body *body;
1789 if (opc == OST_READ || opc == OST_WRITE) {
1790 struct niobuf_remote *nb;
1791 struct obd_ioobj *ioo;
1792 int objcount, niocount;
1795 body = lustre_swab_reqbuf(req, REQ_REC_OFF,
1799 CERROR("Missing/short ost_body\n");
1802 objcount = lustre_msg_buflen(req->rq_reqmsg,
1805 if (objcount == 0) {
1806 CERROR("Missing/short ioobj\n");
1810 CERROR("too many ioobjs (%d)\n", objcount);
1814 swab = !lustre_req_swabbed(req, REQ_REC_OFF + 1) &&
1815 lustre_msg_swabbed(req->rq_reqmsg);
1816 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1,
1817 objcount * sizeof(*ioo),
1818 lustre_swab_obd_ioobj);
1820 CERROR("Missing/short ioobj\n");
1823 for (niocount = i = 0; i < objcount; i++) {
1825 lustre_swab_obd_ioobj(&ioo[i]);
1826 if (ioo[i].ioo_bufcnt == 0) {
1827 CERROR("ioo[%d] has zero bufcnt\n", i);
1830 niocount += ioo[i].ioo_bufcnt;
1832 if (niocount > PTLRPC_MAX_BRW_PAGES) {
1833 DEBUG_REQ(D_ERROR, req, "bulk has too many "
1834 "pages (%d)", niocount);
1838 swab = !lustre_req_swabbed(req, REQ_REC_OFF + 2) &&
1839 lustre_msg_swabbed(req->rq_reqmsg);
1840 nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
1841 niocount * sizeof(*nb),
1842 lustre_swab_niobuf_remote);
1844 CERROR("Missing/short niobuf\n");
1849 /* swab remaining niobufs */
1850 for (i = 1; i < niocount; i++)
1851 lustre_swab_niobuf_remote(&nb[i]);
1854 if (niocount == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
1855 req->rq_ops = &ost_hpreq_rw;
1856 } else if (opc == OST_PUNCH) {
1857 body = lustre_swab_reqbuf(req, REQ_REC_OFF,
1861 CERROR("Missing/short ost_body\n");
1865 if (!(body->oa.o_valid & OBD_MD_FLFLAGS) ||
1866 !(body->oa.o_flags & OBD_FL_TRUNCLOCK))
1867 req->rq_ops = &ost_hpreq_punch;
1873 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1874 int ost_handle(struct ptlrpc_request *req)
1876 struct obd_trans_info trans_info = { 0, };
1877 struct obd_trans_info *oti = &trans_info;
1878 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1879 struct obd_device *obd = NULL;
1882 LASSERT(current->journal_info == NULL);
1884 /* primordial rpcs don't affect server recovery */
1885 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1887 case SEC_CTX_INIT_CONT:
1892 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1894 /* XXX identical to MDS */
1895 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1898 if (req->rq_export == NULL) {
1899 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1900 lustre_msg_get_opc(req->rq_reqmsg),
1901 libcfs_id2str(req->rq_peer));
1902 req->rq_status = -ENOTCONN;
1903 GOTO(out, rc = -ENOTCONN);
1906 obd = req->rq_export->exp_obd;
1908 /* Check for aborted recovery. */
1909 spin_lock_bh(&obd->obd_processing_task_lock);
1910 recovering = obd->obd_recovering;
1911 spin_unlock_bh(&obd->obd_processing_task_lock);
1913 rc = ost_filter_recovery_request(req, obd,
1915 if (rc || !should_process)
1917 else if (should_process < 0) {
1918 req->rq_status = should_process;
1919 rc = ptlrpc_error(req);
1927 rc = ost_msg_check_version(req->rq_reqmsg);
1931 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1933 CDEBUG(D_INODE, "connect\n");
1934 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
1935 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
1937 rc = target_handle_connect(req);
1938 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
1941 rc = ost_init_sec_level(req);
1943 rc = ost_connect_check_sptlrpc(req);
1947 case OST_DISCONNECT:
1948 CDEBUG(D_INODE, "disconnect\n");
1949 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
1950 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
1952 rc = target_handle_disconnect(req);
1955 CDEBUG(D_INODE, "create\n");
1956 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
1958 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1959 GOTO(out, rc = -ENOSPC);
1960 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1961 GOTO(out, rc = -EROFS);
1962 rc = ost_create(req->rq_export, req, oti);
1965 CDEBUG(D_INODE, "destroy\n");
1966 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
1968 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1969 GOTO(out, rc = -EROFS);
1970 rc = ost_destroy(req->rq_export, req, oti);
1973 CDEBUG(D_INODE, "getattr\n");
1974 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
1976 rc = ost_getattr(req->rq_export, req);
1979 CDEBUG(D_INODE, "setattr\n");
1980 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
1982 rc = ost_setattr(req->rq_export, req, oti);
1985 CDEBUG(D_INODE, "write\n");
1986 /* req->rq_request_portal would be nice, if it was set */
1987 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1988 CERROR("%s: deny write request from %s to portal %u\n",
1989 req->rq_export->exp_obd->obd_name,
1990 obd_export_nid2str(req->rq_export),
1991 req->rq_rqbd->rqbd_service->srv_req_portal);
1992 GOTO(out, rc = -EPROTO);
1994 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1996 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1997 GOTO(out, rc = -ENOSPC);
1998 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1999 GOTO(out, rc = -EROFS);
2000 rc = ost_brw_write(req, oti);
2001 LASSERT(current->journal_info == NULL);
2002 /* ost_brw_write sends its own replies */
2005 CDEBUG(D_INODE, "read\n");
2006 /* req->rq_request_portal would be nice, if it was set */
2007 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
2008 CERROR("%s: deny read request from %s to portal %u\n",
2009 req->rq_export->exp_obd->obd_name,
2010 obd_export_nid2str(req->rq_export),
2011 req->rq_rqbd->rqbd_service->srv_req_portal);
2012 GOTO(out, rc = -EPROTO);
2014 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
2016 rc = ost_brw_read(req, oti);
2017 LASSERT(current->journal_info == NULL);
2018 /* ost_brw_read sends its own replies */
2021 CDEBUG(D_INODE, "punch\n");
2022 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
2024 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
2025 GOTO(out, rc = -EROFS);
2026 rc = ost_punch(req->rq_export, req, oti);
2029 CDEBUG(D_INODE, "statfs\n");
2030 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
2032 rc = ost_statfs(req);
2035 CDEBUG(D_INODE, "sync\n");
2036 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
2038 rc = ost_sync(req->rq_export, req);
2041 DEBUG_REQ(D_INODE, req, "set_info");
2042 req_capsule_set(&req->rq_pill, &RQF_OST_SET_INFO);
2043 rc = ost_set_info(req->rq_export, req);
2046 DEBUG_REQ(D_INODE, req, "get_info");
2047 rc = ost_get_info(req->rq_export, req);
2049 #ifdef HAVE_QUOTA_SUPPORT
2050 case OST_QUOTACHECK:
2051 CDEBUG(D_INODE, "quotacheck\n");
2052 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
2053 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
2055 rc = ost_handle_quotacheck(req);
2058 CDEBUG(D_INODE, "quotactl\n");
2059 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
2060 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
2062 rc = ost_handle_quotactl(req);
2064 case OST_QUOTA_ADJUST_QUNIT:
2065 CDEBUG(D_INODE, "quota_adjust_qunit\n");
2066 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
2067 rc = ost_handle_quota_adjust_qunit(req);
2071 DEBUG_REQ(D_INODE, req, "ping");
2072 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
2073 rc = target_handle_ping(req);
2075 /* FIXME - just reply status */
2076 case LLOG_ORIGIN_CONNECT:
2077 DEBUG_REQ(D_INODE, req, "log connect");
2078 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
2079 rc = ost_llog_handle_connect(req->rq_export, req);
2080 req->rq_status = rc;
2081 rc = req_capsule_server_pack(&req->rq_pill);
2084 RETURN(ptlrpc_reply(req));
2085 case OBD_LOG_CANCEL:
2086 CDEBUG(D_INODE, "log cancel\n");
2087 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
2088 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
2090 rc = llog_origin_handle_cancel(req);
2091 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
2093 req->rq_status = rc;
2094 rc = req_capsule_server_pack(&req->rq_pill);
2097 RETURN(ptlrpc_reply(req));
2099 CDEBUG(D_INODE, "enqueue\n");
2100 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
2101 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
2103 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2104 ldlm_server_blocking_ast,
2105 ldlm_server_glimpse_ast);
2106 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
2109 CDEBUG(D_INODE, "convert\n");
2110 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
2111 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
2113 rc = ldlm_handle_convert(req);
2116 CDEBUG(D_INODE, "cancel\n");
2117 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
2118 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
2120 rc = ldlm_handle_cancel(req);
2122 case LDLM_BL_CALLBACK:
2123 case LDLM_CP_CALLBACK:
2124 CDEBUG(D_INODE, "callback\n");
2125 CERROR("callbacks should not happen on OST\n");
2128 CERROR("Unexpected opcode %d\n",
2129 lustre_msg_get_opc(req->rq_reqmsg));
2130 req->rq_status = -ENOTSUPP;
2131 rc = ptlrpc_error(req);
2135 LASSERT(current->journal_info == NULL);
2138 /* If we're DISCONNECTing, the export_data is already freed */
2139 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
2140 target_committed_to_req(req);
2144 oti_to_request(oti, req);
2146 target_send_reply(req, rc, fail);
2149 EXPORT_SYMBOL(ost_handle);
2151 * free per-thread pool created by ost_thread_init().
2153 static void ost_thread_done(struct ptlrpc_thread *thread)
2155 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
2160 LASSERT(thread != NULL);
2163 * be prepared to handle partially-initialized pools (because this is
2164 * called from ost_thread_init() for cleanup.
2166 tls = thread->t_data;
2169 thread->t_data = NULL;
2175 * initialize per-thread page pool (bug 5137).
2177 static int ost_thread_init(struct ptlrpc_thread *thread)
2179 struct ost_thread_local_cache *tls;
2183 LASSERT(thread != NULL);
2184 LASSERT(thread->t_data == NULL);
2185 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
2190 thread->t_data = tls;
2194 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
2196 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
2197 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
2199 struct ost_obd *ost = &obd->u.ost;
2200 struct lprocfs_static_vars lvars;
2201 int oss_min_threads;
2202 int oss_max_threads;
2203 int oss_min_create_threads;
2204 int oss_max_create_threads;
2208 rc = cleanup_group_info();
2212 lprocfs_ost_init_vars(&lvars);
2213 lprocfs_obd_setup(obd, lvars.obd_vars);
2215 sema_init(&ost->ost_health_sem, 1);
2217 if (oss_num_threads) {
2218 /* If oss_num_threads is set, it is the min and the max. */
2219 if (oss_num_threads > OSS_THREADS_MAX)
2220 oss_num_threads = OSS_THREADS_MAX;
2221 if (oss_num_threads < OSS_THREADS_MIN)
2222 oss_num_threads = OSS_THREADS_MIN;
2223 oss_max_threads = oss_min_threads = oss_num_threads;
2225 /* Base min threads on memory and cpus */
2226 oss_min_threads = num_possible_cpus() * num_physpages >>
2227 (27 - CFS_PAGE_SHIFT);
2228 if (oss_min_threads < OSS_THREADS_MIN)
2229 oss_min_threads = OSS_THREADS_MIN;
2230 /* Insure a 4x range for dynamic threads */
2231 if (oss_min_threads > OSS_THREADS_MAX / 4)
2232 oss_min_threads = OSS_THREADS_MAX / 4;
2233 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4 + 1);
2237 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2238 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
2239 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2240 ost_handle, LUSTRE_OSS_NAME,
2241 obd->obd_proc_entry, target_print_req,
2242 oss_min_threads, oss_max_threads,
2243 "ll_ost", LCT_DT_THREAD, NULL);
2244 if (ost->ost_service == NULL) {
2245 CERROR("failed to start service\n");
2246 GOTO(out_lprocfs, rc = -ENOMEM);
2249 rc = ptlrpc_start_threads(obd, ost->ost_service);
2251 GOTO(out_service, rc = -EINVAL);
2253 if (oss_num_create_threads) {
2254 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
2255 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
2256 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
2257 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
2258 oss_min_create_threads = oss_max_create_threads =
2259 oss_num_create_threads;
2261 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
2262 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
2265 ost->ost_create_service =
2266 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2267 OST_MAXREPSIZE, OST_CREATE_PORTAL,
2268 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2269 ost_handle, "ost_create",
2270 obd->obd_proc_entry, target_print_req,
2271 oss_min_create_threads, oss_max_create_threads,
2272 "ll_ost_creat", LCT_DT_THREAD, NULL);
2273 if (ost->ost_create_service == NULL) {
2274 CERROR("failed to start OST create service\n");
2275 GOTO(out_service, rc = -ENOMEM);
2278 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
2280 GOTO(out_create, rc = -EINVAL);
2282 ost->ost_io_service =
2283 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2284 OST_MAXREPSIZE, OST_IO_PORTAL,
2285 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2286 ost_handle, "ost_io",
2287 obd->obd_proc_entry, target_print_req,
2288 oss_min_threads, oss_max_threads,
2289 "ll_ost_io", LCT_DT_THREAD, ost_hpreq_handler);
2290 if (ost->ost_io_service == NULL) {
2291 CERROR("failed to start OST I/O service\n");
2292 GOTO(out_create, rc = -ENOMEM);
2295 ost->ost_io_service->srv_init = ost_thread_init;
2296 ost->ost_io_service->srv_done = ost_thread_done;
2297 ost->ost_io_service->srv_cpu_affinity = 1;
2298 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
2300 GOTO(out_io, rc = -EINVAL);
2302 ping_evictor_start();
2307 ptlrpc_unregister_service(ost->ost_io_service);
2308 ost->ost_io_service = NULL;
2310 ptlrpc_unregister_service(ost->ost_create_service);
2311 ost->ost_create_service = NULL;
2313 ptlrpc_unregister_service(ost->ost_service);
2314 ost->ost_service = NULL;
2316 lprocfs_obd_cleanup(obd);
2320 static int ost_cleanup(struct obd_device *obd)
2322 struct ost_obd *ost = &obd->u.ost;
2326 ping_evictor_stop();
2328 spin_lock_bh(&obd->obd_processing_task_lock);
2329 if (obd->obd_recovering) {
2330 target_cancel_recovery_timer(obd);
2331 obd->obd_recovering = 0;
2333 spin_unlock_bh(&obd->obd_processing_task_lock);
2335 down(&ost->ost_health_sem);
2336 ptlrpc_unregister_service(ost->ost_service);
2337 ptlrpc_unregister_service(ost->ost_create_service);
2338 ptlrpc_unregister_service(ost->ost_io_service);
2339 ost->ost_service = NULL;
2340 ost->ost_create_service = NULL;
2341 up(&ost->ost_health_sem);
2343 lprocfs_obd_cleanup(obd);
2348 static int ost_health_check(struct obd_device *obd)
2350 struct ost_obd *ost = &obd->u.ost;
2353 down(&ost->ost_health_sem);
2354 rc |= ptlrpc_service_health_check(ost->ost_service);
2355 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2356 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2357 up(&ost->ost_health_sem);
2360 * health_check to return 0 on healthy
2361 * and 1 on unhealthy.
2369 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2371 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2374 /* use obd ops to offer management infrastructure */
2375 static struct obd_ops ost_obd_ops = {
2376 .o_owner = THIS_MODULE,
2377 .o_setup = ost_setup,
2378 .o_cleanup = ost_cleanup,
2379 .o_health_check = ost_health_check,
2383 static int __init ost_init(void)
2385 struct lprocfs_static_vars lvars;
2389 lprocfs_ost_init_vars(&lvars);
2390 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2391 LUSTRE_OSS_NAME, NULL);
2393 if (ost_num_threads != 0 && oss_num_threads == 0) {
2394 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2395 "use oss_num_threads instead or unset both for "
2396 "dynamic thread startup\n");
2397 oss_num_threads = ost_num_threads;
2403 static void /*__exit*/ ost_exit(void)
2405 class_unregister_type(LUSTRE_OSS_NAME);
2408 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2409 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2410 MODULE_LICENSE("GPL");
2412 module_init(ost_init);
2413 module_exit(ost_exit);