1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
5 * Author: Peter J. Braam <braam@clusterfs.com>
6 * Author: Phil Schwan <phil@clusterfs.com>
8 * This file is part of the Lustre file system, http://www.lustre.org
9 * Lustre is a trademark of Cluster File Systems, Inc.
11 * You may have signed or agreed to another license before downloading
12 * this software. If so, you are bound by the terms and conditions
13 * of that agreement, and the following does not apply to you. See the
14 * LICENSE file included with this distribution for more information.
16 * If you did not agree to a different license, then this copy of Lustre
17 * is open source software; you can redistribute it and/or modify it
18 * under the terms of version 2 of the GNU General Public License as
19 * published by the Free Software Foundation.
21 * In either case, Lustre is distributed in the hope that it will be
22 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
23 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * license text for more details.
26 * Storage Target Handling functions
27 * Lustre Object Server Module (OST)
29 * This server is single threaded at present (but can easily be multi
30 * threaded). For testing and management it is treated as an
31 * obd_device, although it does not export a full OBD method table
32 * (the requests are coming in over the wire, so object target
33 * modules do not have a full method table.)
37 # define EXPORT_SYMTAB
39 #define DEBUG_SUBSYSTEM S_OST
41 #include <linux/module.h>
42 #include <obd_cksum.h>
44 #include <lustre_net.h>
45 #include <lustre_dlm.h>
46 #include <lustre_export.h>
47 #include <lustre_debug.h>
48 #include <linux/init.h>
49 #include <lprocfs_status.h>
50 #include <lustre_commit_confd.h>
51 #include <libcfs/list.h>
52 #include <lustre_quota.h>
53 #include "ost_internal.h"
55 static int oss_num_threads;
56 CFS_MODULE_PARM(oss_num_threads, "i", int, 0444,
57 "number of OSS service threads to start");
59 static int ost_num_threads;
60 CFS_MODULE_PARM(ost_num_threads, "i", int, 0444,
61 "number of OST service threads to start (deprecated)");
63 static int oss_num_create_threads;
64 CFS_MODULE_PARM(oss_num_create_threads, "i", int, 0444,
65 "number of OSS create threads to start");
67 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
69 struct oti_req_ack_lock *ack_lock;
76 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
77 req->rq_transno = oti->oti_transno;
79 /* XXX 4 == entries in oti_ack_locks??? */
80 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
83 /* XXX not even calling target_send_reply in some cases... */
84 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode);
88 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
89 struct obd_trans_info *oti)
91 struct ost_body *body, *repbody;
92 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
95 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
96 lustre_swab_ost_body);
100 if (body->oa.o_id == 0)
103 if (lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1)) {
104 struct ldlm_request *dlm;
105 dlm = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*dlm),
106 lustre_swab_ldlm_request);
109 ldlm_request_cancel(req, dlm, 0);
112 rc = lustre_pack_reply(req, 2, size, NULL);
116 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
117 oti->oti_logcookies = obdo_logcookie(&body->oa);
118 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
120 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
121 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL);
125 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
127 struct ost_body *body, *repbody;
128 struct obd_info oinfo = { { { 0 } } };
129 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
132 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
133 lustre_swab_ost_body);
137 rc = lustre_pack_reply(req, 2, size, NULL);
141 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
143 repbody->oa = body->oa;
145 oinfo.oi_oa = &repbody->oa;
146 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
147 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
149 req->rq_status = obd_getattr(exp, &oinfo);
153 static int ost_statfs(struct ptlrpc_request *req)
155 struct obd_statfs *osfs;
156 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*osfs) };
159 rc = lustre_pack_reply(req, 2, size, NULL);
163 osfs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*osfs));
165 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
166 cfs_time_current_64() - HZ, 0);
167 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
168 osfs->os_bfree = osfs->os_bavail = 64;
169 if (req->rq_status != 0)
170 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
175 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
176 struct obd_trans_info *oti)
178 struct ost_body *body, *repbody;
179 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
182 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
183 lustre_swab_ost_body);
187 rc = lustre_pack_reply(req, 2, size, NULL);
191 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
193 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
194 oti->oti_logcookies = obdo_logcookie(&repbody->oa);
195 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
196 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
201 * Helper function for ost_punch(): if asked by client, acquire [size, EOF]
202 * lock on the file being truncated.
204 static int ost_punch_lock_get(struct obd_export *exp, struct obdo *oa,
205 struct lustre_handle *lh)
208 struct ldlm_res_id res_id = { .name = { oa->o_id, 0, oa->o_gr, 0} };
209 ldlm_policy_data_t policy;
215 LASSERT(!lustre_handle_is_used(lh));
217 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
218 !(oa->o_flags & OBD_FL_TRUNCLOCK))
221 CDEBUG(D_INODE, "OST-side truncate lock.\n");
224 finis = start + oa->o_blocks;
227 * standard truncate optimization: if file body is completely
228 * destroyed, don't send data back to the server.
230 flags = (start == 0) ? LDLM_AST_DISCARD_DATA : 0;
232 policy.l_extent.start = start & CFS_PAGE_MASK;
235 * If ->o_blocks is EOF it means "lock till the end of the
236 * file". Otherwise, it's size of a hole being punched (in bytes)
238 if (oa->o_blocks == OBD_OBJECT_EOF || finis < start)
239 policy.l_extent.end = OBD_OBJECT_EOF;
241 policy.l_extent.end = finis | ~CFS_PAGE_MASK;
243 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
244 LDLM_EXTENT, &policy, LCK_PW, &flags,
245 ldlm_blocking_ast, ldlm_completion_ast,
246 ldlm_glimpse_ast, NULL, 0, NULL, lh));
250 * Helper function for ost_punch(): release lock acquired by
251 * ost_punch_lock_get(), if any.
253 static void ost_punch_lock_put(struct obd_export *exp, struct obdo *oa,
254 struct lustre_handle *lh)
257 if (lustre_handle_is_used(lh))
258 ldlm_lock_decref(lh, LCK_PW);
262 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
263 struct obd_trans_info *oti)
265 struct obd_info oinfo = { { { 0 } } };
266 struct ost_body *body, *repbody;
267 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
268 struct lustre_handle lh = {0,};
271 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
272 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
274 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
275 lustre_swab_ost_body);
279 oinfo.oi_oa = &body->oa;
280 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
281 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
283 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
284 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
287 rc = lustre_pack_reply(req, 2, size, NULL);
291 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
293 rc = ost_punch_lock_get(exp, oinfo.oi_oa, &lh);
295 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
296 oinfo.oi_oa->o_flags == OBD_FL_TRUNCLOCK)
298 * If OBD_FL_TRUNCLOCK is the only bit set in
299 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
300 * through filter_setattr() to filter_iocontrol().
302 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
304 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
305 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
307 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
308 ost_punch_lock_put(exp, oinfo.oi_oa, &lh);
310 repbody->oa = *oinfo.oi_oa;
314 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
316 struct ost_body *body, *repbody;
317 struct lustre_capa *capa = NULL;
318 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
321 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
322 lustre_swab_ost_body);
326 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
327 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 1);
329 rc = lustre_pack_reply(req, 2, size, NULL);
333 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
335 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
336 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
337 repbody->oa.o_blocks, capa);
341 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
342 struct obd_trans_info *oti)
344 struct ost_body *body, *repbody;
345 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
346 struct obd_info oinfo = { { { 0 } } };
349 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
350 lustre_swab_ost_body);
354 rc = lustre_pack_reply(req, 2, size, NULL);
358 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
360 repbody->oa = body->oa;
362 oinfo.oi_oa = &repbody->oa;
363 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
364 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
366 req->rq_status = obd_setattr(exp, &oinfo, oti);
370 static int ost_bulk_timeout(void *data)
373 /* We don't fail the connection here, because having the export
374 * killed makes the (vital) call to commitrw very sad.
379 static int get_per_page_niobufs(struct obd_ioobj *ioo, int nioo,
380 struct niobuf_remote *rnb, int nrnb,
381 struct niobuf_remote **pp_rnbp)
383 /* Copy a remote niobuf, splitting it into page-sized chunks
384 * and setting ioo[i].ioo_bufcnt accordingly */
385 struct niobuf_remote *pp_rnb;
393 * array of sufficient size already preallocated by caller
395 LASSERT(pp_rnbp != NULL);
396 LASSERT(*pp_rnbp != NULL);
398 /* first count and check the number of pages required */
399 for (i = 0; i < nioo; i++)
400 for (j = 0; j < ioo->ioo_bufcnt; j++, rnbidx++) {
401 obd_off offset = rnb[rnbidx].offset;
402 obd_off p0 = offset >> CFS_PAGE_SHIFT;
403 obd_off pn = (offset + rnb[rnbidx].len - 1) >>
406 LASSERT(rnbidx < nrnb);
408 npages += (pn + 1 - p0);
410 if (rnb[rnbidx].len == 0) {
411 CERROR("zero len BRW: obj %d objid "LPX64
412 " buf %u\n", i, ioo[i].ioo_id, j);
416 rnb[rnbidx].offset <= rnb[rnbidx-1].offset) {
417 CERROR("unordered BRW: obj %d objid "LPX64
418 " buf %u offset "LPX64" <= "LPX64"\n",
419 i, ioo[i].ioo_id, j, rnb[rnbidx].offset,
425 LASSERT(rnbidx == nrnb);
427 if (npages == nrnb) { /* all niobufs are for single pages */
434 /* now do the actual split */
436 for (i = 0; i < nioo; i++) {
439 for (j = 0; j < ioo[i].ioo_bufcnt; j++, rnbidx++) {
440 obd_off off = rnb[rnbidx].offset;
441 int nob = rnb[rnbidx].len;
443 LASSERT(rnbidx < nrnb);
445 obd_off poff = off & ~CFS_PAGE_MASK;
446 int pnob = (poff + nob > CFS_PAGE_SIZE) ?
447 PAGE_SIZE - poff : nob;
449 LASSERT(page < npages);
450 pp_rnb[page].len = pnob;
451 pp_rnb[page].offset = off;
452 pp_rnb[page].flags = rnb[rnbidx].flags;
454 CDEBUG(0, " obj %d id "LPX64
455 "page %d(%d) "LPX64" for %d, flg %x\n",
456 i, ioo[i].ioo_id, obj_pages, page,
457 pp_rnb[page].offset, pp_rnb[page].len,
467 ioo[i].ioo_bufcnt = obj_pages;
469 LASSERT(page == npages);
474 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
475 cksum_type_t cksum_type)
480 cksum = init_checksum(cksum_type);
481 for (i = 0; i < desc->bd_iov_count; i++) {
482 struct page *page = desc->bd_iov[i].kiov_page;
483 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
484 char *ptr = kmap(page) + off;
485 int len = desc->bd_iov[i].kiov_len;
487 /* corrupt the data before we compute the checksum, to
488 * simulate a client->OST data error */
489 if (i == 0 && opc == OST_WRITE &&
490 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
491 memcpy(ptr, "bad3", min(4, len));
492 cksum = compute_checksum(cksum, ptr, len, cksum_type);
493 /* corrupt the data after we compute the checksum, to
494 * simulate an OST->client data error */
495 if (i == 0 && opc == OST_READ &&
496 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND))
497 memcpy(ptr, "bad4", min(4, len));
505 * populate @nio by @nrpages pages from per-thread page pool
507 static void ost_nio_pages_get(struct ptlrpc_request *req,
508 struct niobuf_local *nio, int nrpages)
511 struct ost_thread_local_cache *tls;
515 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
516 LASSERT(req != NULL);
517 LASSERT(req->rq_svc_thread != NULL);
520 LASSERT(tls != NULL);
522 memset(nio, 0, nrpages * sizeof *nio);
523 for (i = 0; i < nrpages; ++ i) {
527 LASSERT(page != NULL);
528 POISON_PAGE(page, 0xf1);
530 LL_CDEBUG_PAGE(D_INFO, page, "%d\n", i);
536 * Dual for ost_nio_pages_get(). Poison pages in pool for debugging
538 static void ost_nio_pages_put(struct ptlrpc_request *req,
539 struct niobuf_local *nio, int nrpages)
545 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
547 for (i = 0; i < nrpages; ++ i)
548 POISON_PAGE(nio[i].page, 0xf2);
552 static int ost_brw_lock_get(int mode, struct obd_export *exp,
553 struct obd_ioobj *obj, struct niobuf_remote *nb,
554 struct lustre_handle *lh)
557 int nrbufs = obj->ioo_bufcnt;
558 struct ldlm_res_id res_id = { .name = { obj->ioo_id, 0,
560 ldlm_policy_data_t policy;
565 LASSERT(mode == LCK_PR || mode == LCK_PW);
566 LASSERT(!lustre_handle_is_used(lh));
568 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
571 /* EXPENSIVE ASSERTION */
572 for (i = 1; i < nrbufs; i ++)
573 LASSERT((nb[0].flags & OBD_BRW_SRVLOCK) ==
574 (nb[i].flags & OBD_BRW_SRVLOCK));
576 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
577 policy.l_extent.end = (nb[nrbufs - 1].offset +
578 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
580 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
581 LDLM_EXTENT, &policy, mode, &flags,
582 ldlm_blocking_ast, ldlm_completion_ast,
583 ldlm_glimpse_ast, NULL, 0, NULL, lh));
586 static void ost_brw_lock_put(int mode,
587 struct obd_ioobj *obj, struct niobuf_remote *niob,
588 struct lustre_handle *lh)
591 LASSERT(mode == LCK_PR || mode == LCK_PW);
592 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
593 lustre_handle_is_used(lh));
594 if (lustre_handle_is_used(lh))
595 ldlm_lock_decref(lh, mode);
599 struct ost_prolong_data {
600 struct obd_export *opd_exp;
601 ldlm_policy_data_t opd_policy;
602 ldlm_mode_t opd_mode;
605 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
607 struct ost_prolong_data *opd = data;
609 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
611 if (lock->l_req_mode != lock->l_granted_mode) {
612 /* scan granted locks only */
613 return LDLM_ITER_STOP;
616 if (lock->l_export != opd->opd_exp) {
617 /* prolong locks only for given client */
618 return LDLM_ITER_CONTINUE;
621 if (!(lock->l_granted_mode & opd->opd_mode)) {
622 /* we aren't interesting in all type of locks */
623 return LDLM_ITER_CONTINUE;
626 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
627 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
628 /* the request doesn't cross the lock, skip it */
629 return LDLM_ITER_CONTINUE;
632 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
633 /* ignore locks not being cancelled */
634 return LDLM_ITER_CONTINUE;
637 /* OK. this is a possible lock the user holds doing I/O
638 * let's refresh eviction timer for it */
639 ldlm_refresh_waiting_lock(lock);
641 return LDLM_ITER_CONTINUE;
644 static void ost_prolong_locks(struct obd_export *exp, struct obd_ioobj *obj,
645 struct niobuf_remote *nb, ldlm_mode_t mode)
647 struct ldlm_res_id res_id = { .name = { obj->ioo_id, 0,
649 int nrbufs = obj->ioo_bufcnt;
650 struct ost_prolong_data opd;
656 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
657 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
658 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
660 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
661 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
662 opd.opd_policy.l_extent.end);
663 ldlm_resource_iterate(exp->exp_obd->obd_namespace, &res_id,
664 ost_prolong_locks_iter, &opd);
667 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
669 struct ptlrpc_bulk_desc *desc;
670 struct obd_export *exp = req->rq_export;
671 struct niobuf_remote *remote_nb;
672 struct niobuf_remote *pp_rnb = NULL;
673 struct niobuf_local *local_nb;
674 struct obd_ioobj *ioo;
675 struct ost_body *body, *repbody;
676 struct lustre_capa *capa = NULL;
677 struct l_wait_info lwi;
678 struct lustre_handle lockh = { 0 };
679 int size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
680 int niocount, npages, nob = 0, rc, i;
684 req->rq_bulk_read = 1;
686 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
687 GOTO(out, rc = -EIO);
689 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
691 /* Check if there is eviction in progress, and if so, wait for it to
693 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
694 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
695 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
696 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
700 GOTO(out, rc = -ENOTCONN);
702 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
703 lustre_swab_ost_body);
705 CERROR("Missing/short ost_body\n");
706 GOTO(out, rc = -EFAULT);
709 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*ioo),
710 lustre_swab_obd_ioobj);
712 CERROR("Missing/short ioobj\n");
713 GOTO(out, rc = -EFAULT);
716 niocount = ioo->ioo_bufcnt;
717 if (niocount > PTLRPC_MAX_BRW_PAGES) {
718 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
720 GOTO(out, rc = -EFAULT);
723 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
724 niocount * sizeof(*remote_nb),
725 lustre_swab_niobuf_remote);
726 if (remote_nb == NULL) {
727 CERROR("Missing/short niobuf\n");
728 GOTO(out, rc = -EFAULT);
730 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
731 for (i = 1; i < niocount; i++)
732 lustre_swab_niobuf_remote (&remote_nb[i]);
735 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
736 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
738 rc = lustre_pack_reply(req, 2, size, NULL);
743 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
746 local_nb = ost_tls(req)->local;
747 pp_rnb = ost_tls(req)->remote;
749 /* FIXME all niobuf splitting should be done in obdfilter if needed */
750 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
751 npages = get_per_page_niobufs(ioo, 1, remote_nb, niocount, &pp_rnb);
753 GOTO(out, rc = npages);
755 LASSERT(npages <= OST_THREAD_POOL_SIZE);
757 ost_nio_pages_get(req, local_nb, npages);
759 desc = ptlrpc_prep_bulk_exp(req, npages,
760 BULK_PUT_SOURCE, OST_BULK_PORTAL);
762 GOTO(out, rc = -ENOMEM);
764 rc = ost_brw_lock_get(LCK_PR, exp, ioo, pp_rnb, &lockh);
769 * If getting the lock took more time than
770 * client was willing to wait, drop it. b=11330
772 if (cfs_time_current_sec() > req->rq_arrival_time.tv_sec + obd_timeout ||
773 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
775 CERROR("Dropping timed-out read from %s because locking"
776 "object "LPX64" took %ld seconds.\n",
777 libcfs_id2str(req->rq_peer), ioo->ioo_id,
778 cfs_time_current_sec() - req->rq_arrival_time.tv_sec);
779 GOTO(out_lock, rc = -ETIMEDOUT);
782 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1,
783 ioo, npages, pp_rnb, local_nb, oti, capa);
787 ost_prolong_locks(exp, ioo, pp_rnb, LCK_PW | LCK_PR);
790 for (i = 0; i < npages; i++) {
791 int page_rc = local_nb[i].rc;
793 if (page_rc < 0) { /* error */
798 LASSERTF(page_rc <= pp_rnb[i].len, "page_rc (%d) > "
799 "pp_rnb[%d].len (%d)\n", page_rc, i, pp_rnb[i].len);
801 if (page_rc != 0) { /* some data! */
802 LASSERT (local_nb[i].page != NULL);
803 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
804 pp_rnb[i].offset & ~CFS_PAGE_MASK,
808 if (page_rc != pp_rnb[i].len) { /* short read */
809 /* All subsequent pages should be 0 */
811 LASSERT(local_nb[i].rc == 0);
816 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
817 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
819 if (body->oa.o_valid & OBD_MD_FLFLAGS)
820 cksum_type = cksum_type_unpack(body->oa.o_flags);
821 body->oa.o_flags = cksum_type_pack(cksum_type);
822 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
823 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
824 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
826 body->oa.o_valid = 0;
828 /* We're finishing using body->oa as an input variable */
830 /* Check if client was evicted while we were doing i/o before touching
833 /* Check if there is eviction in progress, and if so, wait for
835 if (unlikely(atomic_read(&exp->exp_obd->
836 obd_evict_inprogress))) {
837 lwi = LWI_INTR(NULL, NULL);
838 rc = l_wait_event(exp->exp_obd->
839 obd_evict_inprogress_waitq,
840 !atomic_read(&exp->exp_obd->
841 obd_evict_inprogress),
847 sptlrpc_svc_wrap_bulk(req, desc);
849 rc = ptlrpc_start_bulk_transfer(desc);
853 lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 4, HZ,
854 ost_bulk_timeout, desc);
855 rc = l_wait_event(desc->bd_waitq,
856 !ptlrpc_bulk_active(desc) ||
857 exp->exp_failed, &lwi);
858 LASSERT(rc == 0 || rc == -ETIMEDOUT);
859 if (rc == -ETIMEDOUT) {
860 DEBUG_REQ(D_ERROR, req, "timeout on bulk PUT");
861 ptlrpc_abort_bulk(desc);
862 } else if (exp->exp_failed) {
863 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
865 ptlrpc_abort_bulk(desc);
866 } else if (!desc->bd_success ||
867 desc->bd_nob_transferred != desc->bd_nob) {
868 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
870 "truncated" : "network error on",
871 desc->bd_nob_transferred,
873 /* XXX should this be a different errno? */
877 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
882 /* Must commit after prep above in all cases */
883 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1,
884 ioo, npages, local_nb, oti, rc);
886 ost_nio_pages_put(req, local_nb, npages);
889 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
891 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
895 ost_brw_lock_put(LCK_PR, ioo, pp_rnb, &lockh);
897 ptlrpc_free_bulk(desc);
901 req->rq_status = nob;
902 target_committed_to_req(req);
904 } else if (!no_reply) {
905 /* Only reply if there was no comms problem with bulk */
906 target_committed_to_req(req);
910 if (req->rq_reply_state != NULL) {
911 /* reply out callback would free */
912 ptlrpc_rs_decref(req->rq_reply_state);
913 req->rq_reply_state = NULL;
915 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
916 "client will retry\n",
917 exp->exp_obd->obd_name,
918 exp->exp_client_uuid.uuid,
919 exp->exp_connection->c_remote_uuid.uuid,
920 libcfs_id2str(req->rq_peer));
926 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
928 struct ptlrpc_bulk_desc *desc;
929 struct obd_export *exp = req->rq_export;
930 struct niobuf_remote *remote_nb;
931 struct niobuf_remote *pp_rnb;
932 struct niobuf_local *local_nb;
933 struct obd_ioobj *ioo;
934 struct ost_body *body, *repbody;
935 struct l_wait_info lwi;
936 struct lustre_handle lockh = {0};
937 struct lustre_capa *capa = NULL;
939 int size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
940 int objcount, niocount, npages;
942 obd_count client_cksum = 0, server_cksum = 0;
943 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
947 req->rq_bulk_write = 1;
949 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
950 GOTO(out, rc = -EIO);
951 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
952 GOTO(out, rc = -EFAULT);
954 /* pause before transaction has been started */
955 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
957 /* Check if there is eviction in progress, and if so, wait for it to
959 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
960 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
961 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
962 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
966 GOTO(out, rc = -ENOTCONN);
968 swab = lustre_msg_swabbed(req->rq_reqmsg);
969 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
970 lustre_swab_ost_body);
972 CERROR("Missing/short ost_body\n");
973 GOTO(out, rc = -EFAULT);
976 lustre_set_req_swabbed(req, REQ_REC_OFF + 1);
977 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
980 CERROR("Missing/short ioobj\n");
981 GOTO(out, rc = -EFAULT);
984 CERROR("too many ioobjs (%d)\n", objcount);
985 GOTO(out, rc = -EFAULT);
988 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
989 objcount * sizeof(*ioo));
990 LASSERT (ioo != NULL);
991 for (niocount = i = 0; i < objcount; i++) {
993 lustre_swab_obd_ioobj(&ioo[i]);
994 if (ioo[i].ioo_bufcnt == 0) {
995 CERROR("ioo[%d] has zero bufcnt\n", i);
996 GOTO(out, rc = -EFAULT);
998 niocount += ioo[i].ioo_bufcnt;
1001 if (niocount > PTLRPC_MAX_BRW_PAGES) {
1002 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
1004 GOTO(out, rc = -EFAULT);
1007 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
1008 niocount * sizeof(*remote_nb),
1009 lustre_swab_niobuf_remote);
1010 if (remote_nb == NULL) {
1011 CERROR("Missing/short niobuf\n");
1012 GOTO(out, rc = -EFAULT);
1014 if (swab) { /* swab the remaining niobufs */
1015 for (i = 1; i < niocount; i++)
1016 lustre_swab_niobuf_remote (&remote_nb[i]);
1019 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
1020 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
1022 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
1023 rc = lustre_pack_reply(req, 3, size, NULL);
1026 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
1027 niocount * sizeof(*rcs));
1030 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
1031 * ost_thread_init().
1033 local_nb = ost_tls(req)->local;
1034 pp_rnb = ost_tls(req)->remote;
1036 /* FIXME all niobuf splitting should be done in obdfilter if needed */
1037 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
1038 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
1040 GOTO(out, rc = npages);
1042 LASSERT(npages <= OST_THREAD_POOL_SIZE);
1044 ost_nio_pages_get(req, local_nb, npages);
1046 desc = ptlrpc_prep_bulk_exp(req, npages,
1047 BULK_GET_SINK, OST_BULK_PORTAL);
1049 GOTO(out, rc = -ENOMEM);
1051 rc = ost_brw_lock_get(LCK_PW, exp, ioo, pp_rnb, &lockh);
1056 * If getting the lock took more time than
1057 * client was willing to wait, drop it. b=11330
1059 if (cfs_time_current_sec() > req->rq_arrival_time.tv_sec + obd_timeout ||
1060 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
1062 CERROR("Dropping timed-out write from %s because locking"
1063 "object "LPX64" took %ld seconds.\n",
1064 libcfs_id2str(req->rq_peer), ioo->ioo_id,
1065 cfs_time_current_sec() - req->rq_arrival_time.tv_sec);
1066 GOTO(out_lock, rc = -ETIMEDOUT);
1069 ost_prolong_locks(exp, ioo, pp_rnb, LCK_PW);
1071 /* obd_preprw clobbers oa->valid, so save what we need */
1072 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
1073 client_cksum = body->oa.o_cksum;
1074 if (body->oa.o_valid & OBD_MD_FLFLAGS)
1075 cksum_type = cksum_type_unpack(body->oa.o_flags);
1078 /* Because we already sync grant info with client when reconnect,
1079 * grant info will be cleared for resent req, then fed_grant and
1080 * total_grant will not be modified in following preprw_write */
1081 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1082 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1083 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1086 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
1087 ioo, npages, pp_rnb, local_nb, oti, capa);
1091 /* NB Having prepped, we must commit... */
1093 for (i = 0; i < npages; i++)
1094 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1095 pp_rnb[i].offset & ~CFS_PAGE_MASK,
1098 /* Check if client was evicted while we were doing i/o before touching
1100 if (desc->bd_export->exp_failed)
1103 rc = ptlrpc_start_bulk_transfer (desc);
1105 lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 2, HZ,
1106 ost_bulk_timeout, desc);
1107 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1108 desc->bd_export->exp_failed, &lwi);
1109 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1110 if (rc == -ETIMEDOUT) {
1111 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1112 ptlrpc_abort_bulk(desc);
1113 } else if (desc->bd_export->exp_failed) {
1114 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1116 ptlrpc_abort_bulk(desc);
1117 } else if (!desc->bd_success ||
1118 desc->bd_nob_transferred != desc->bd_nob) {
1119 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1121 "truncated" : "network error on",
1122 desc->bd_nob_transferred, desc->bd_nob);
1123 /* XXX should this be a different errno? */
1127 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1132 sptlrpc_svc_unwrap_bulk(req, desc);
1134 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1136 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1138 if (unlikely(client_cksum != 0 && rc == 0)) {
1139 static int cksum_counter;
1140 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1141 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1142 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1143 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1144 repbody->oa.o_cksum = server_cksum;
1146 if (unlikely(client_cksum != server_cksum)) {
1147 CERROR("client csum %x, server csum %x\n",
1148 client_cksum, server_cksum);
1150 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1151 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1152 cksum_counter, libcfs_id2str(req->rq_peer),
1157 /* Must commit after prep above in all cases */
1158 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa,
1159 objcount, ioo, npages, local_nb, oti, rc);
1161 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1162 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1167 if (new_cksum == server_cksum)
1168 msg = "changed in transit before arrival at OST";
1169 else if (new_cksum == client_cksum)
1170 msg = "initial checksum before message complete";
1172 msg = "changed in transit AND after initial checksum";
1174 if (req->rq_peer.nid == desc->bd_sender) {
1178 router = libcfs_nid2str(desc->bd_sender);
1181 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1182 "%s%s%s inum "LPU64"/"LPU64" object "
1183 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1184 exp->exp_obd->obd_name, msg,
1185 libcfs_id2str(req->rq_peer),
1187 body->oa.o_valid & OBD_MD_FLFID ?
1188 body->oa.o_fid : (__u64)0,
1189 body->oa.o_valid & OBD_MD_FLFID ?
1190 body->oa.o_generation :(__u64)0,
1192 body->oa.o_valid & OBD_MD_FLGROUP ?
1193 body->oa.o_gr : (__u64)0,
1195 pp_rnb[npages-1].offset+pp_rnb[npages-1].len
1197 CERROR("client csum %x, original server csum %x, "
1198 "server csum now %x\n",
1199 client_cksum, server_cksum, new_cksum);
1202 ost_nio_pages_put(req, local_nb, npages);
1205 /* set per-requested niobuf return codes */
1206 for (i = j = 0; i < niocount; i++) {
1207 int nob = remote_nb[i].len;
1211 LASSERT(j < npages);
1212 if (local_nb[j].rc < 0)
1213 rcs[i] = local_nb[j].rc;
1214 nob -= pp_rnb[j].len;
1219 LASSERT(j == npages);
1223 ost_brw_lock_put(LCK_PW, ioo, pp_rnb, &lockh);
1225 ptlrpc_free_bulk(desc);
1228 oti_to_request(oti, req);
1229 target_committed_to_req(req);
1230 rc = ptlrpc_reply(req);
1231 } else if (!no_reply) {
1232 /* Only reply if there was no comms problem with bulk */
1233 target_committed_to_req(req);
1234 req->rq_status = rc;
1237 if (req->rq_reply_state != NULL) {
1238 /* reply out callback would free */
1239 ptlrpc_rs_decref(req->rq_reply_state);
1240 req->rq_reply_state = NULL;
1242 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1243 "client will retry\n",
1244 exp->exp_obd->obd_name,
1245 exp->exp_client_uuid.uuid,
1246 exp->exp_connection->c_remote_uuid.uuid,
1247 libcfs_id2str(req->rq_peer));
1252 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1254 char *key, *val = NULL;
1255 int keylen, vallen, rc = 0;
1258 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1260 DEBUG_REQ(D_HA, req, "no set_info key");
1263 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1265 rc = lustre_pack_reply(req, 1, NULL, NULL);
1269 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1271 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
1273 if (KEY_IS("evict_by_nid")) {
1275 obd_export_evict_by_nid(exp->exp_obd, val);
1280 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1282 lustre_msg_set_status(req->rq_repmsg, 0);
1286 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1289 int keylen, replylen, rc = 0;
1290 struct req_capsule *pill = &req->rq_pill;
1293 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
1295 /* this common part for get_info rpc */
1296 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1298 DEBUG_REQ(D_HA, req, "no get_info key");
1301 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1303 rc = obd_get_info(exp, keylen, key, &replylen, NULL);
1307 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1308 RCL_SERVER, replylen);
1310 rc = req_capsule_server_pack(pill);
1314 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1318 /* call again to fill in the reply buffer */
1319 rc = obd_get_info(exp, keylen, key, &replylen, reply);
1321 lustre_msg_set_status(req->rq_repmsg, 0);
1325 static int ost_handle_quotactl(struct ptlrpc_request *req)
1327 struct obd_quotactl *oqctl, *repoqc;
1328 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) };
1331 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1332 lustre_swab_obd_quotactl);
1334 GOTO(out, rc = -EPROTO);
1336 rc = lustre_pack_reply(req, 2, size, NULL);
1340 repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc));
1342 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1348 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1350 struct obd_quotactl *oqctl;
1354 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1358 rc = req_capsule_server_pack(&req->rq_pill);
1360 CERROR("ost: out of memory while packing quotacheck reply\n");
1364 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1368 static int ost_llog_handle_connect(struct obd_export *exp,
1369 struct ptlrpc_request *req)
1371 struct llogd_conn_body *body;
1375 body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body));
1376 rc = obd_llog_connect(exp, body);
1380 static int filter_export_check_flavor(struct filter_obd *filter,
1381 struct obd_export *exp,
1382 struct ptlrpc_request *req)
1387 * this should be done in filter_connect()/filter_reconnect(), but
1388 * we can't obtain information like NID, which stored in incoming
1389 * request, thus can't decide what flavor to use. so we do it here.
1391 * This hack should be removed after the OST stack be rewritten, just
1392 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1394 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_INVALID)
1397 CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from));
1398 spin_lock(&exp->exp_lock);
1399 exp->exp_sp_peer = req->rq_sp_from;
1401 read_lock(&filter->fo_sptlrpc_lock);
1402 sptlrpc_rule_set_choose(&filter->fo_sptlrpc_rset, exp->exp_sp_peer,
1403 req->rq_peer.nid, &exp->exp_flvr);
1404 read_unlock(&filter->fo_sptlrpc_lock);
1406 if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1407 CERROR("invalid rpc flavor %x, expect %x, from %s\n",
1408 req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
1409 libcfs_nid2str(req->rq_peer.nid));
1410 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID;
1414 spin_unlock(&exp->exp_lock);
1419 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1420 struct obd_device *obd, int *process)
1422 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1423 case OST_CONNECT: /* This will never get here, but for completeness. */
1424 case OST_DISCONNECT:
1435 case OBD_LOG_CANCEL:
1437 *process = target_queue_recovery_request(req, obd);
1441 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1447 int ost_msg_check_version(struct lustre_msg *msg)
1451 switch(lustre_msg_get_opc(msg)) {
1453 case OST_DISCONNECT:
1456 case SEC_CTX_INIT_CONT:
1458 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1460 CERROR("bad opc %u version %08x, expecting %08x\n",
1461 lustre_msg_get_opc(msg),
1462 lustre_msg_get_version(msg),
1463 LUSTRE_OBD_VERSION);
1476 case OST_QUOTACHECK:
1478 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1480 CERROR("bad opc %u version %08x, expecting %08x\n",
1481 lustre_msg_get_opc(msg),
1482 lustre_msg_get_version(msg),
1483 LUSTRE_OST_VERSION);
1488 case LDLM_BL_CALLBACK:
1489 case LDLM_CP_CALLBACK:
1490 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1492 CERROR("bad opc %u version %08x, expecting %08x\n",
1493 lustre_msg_get_opc(msg),
1494 lustre_msg_get_version(msg),
1495 LUSTRE_DLM_VERSION);
1497 case LLOG_ORIGIN_CONNECT:
1498 case OBD_LOG_CANCEL:
1499 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1501 CERROR("bad opc %u version %08x, expecting %08x\n",
1502 lustre_msg_get_opc(msg),
1503 lustre_msg_get_version(msg),
1504 LUSTRE_LOG_VERSION);
1507 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1513 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1514 int ost_handle(struct ptlrpc_request *req)
1516 struct obd_trans_info trans_info = { 0, };
1517 struct obd_trans_info *oti = &trans_info;
1518 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1519 struct obd_device *obd = NULL;
1522 LASSERT(current->journal_info == NULL);
1524 /* primordial rpcs don't affect server recovery */
1525 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1527 case SEC_CTX_INIT_CONT:
1532 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1534 /* XXX identical to MDS */
1535 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1538 if (req->rq_export == NULL) {
1539 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1540 lustre_msg_get_opc(req->rq_reqmsg),
1541 libcfs_id2str(req->rq_peer));
1542 req->rq_status = -ENOTCONN;
1543 GOTO(out, rc = -ENOTCONN);
1546 obd = req->rq_export->exp_obd;
1548 /* Check for aborted recovery. */
1549 spin_lock_bh(&obd->obd_processing_task_lock);
1550 recovering = obd->obd_recovering;
1551 spin_unlock_bh(&obd->obd_processing_task_lock);
1553 rc = ost_filter_recovery_request(req, obd,
1555 if (rc || !should_process)
1557 else if (should_process < 0) {
1558 req->rq_status = should_process;
1559 rc = ptlrpc_error(req);
1567 rc = ost_msg_check_version(req->rq_reqmsg);
1571 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1573 CDEBUG(D_INODE, "connect\n");
1574 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
1575 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
1577 rc = target_handle_connect(req);
1578 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
1581 struct obd_export *exp = req->rq_export;
1585 rc = filter_export_check_flavor(&obd->u.filter,
1590 case OST_DISCONNECT:
1591 CDEBUG(D_INODE, "disconnect\n");
1592 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
1593 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
1595 rc = target_handle_disconnect(req);
1598 CDEBUG(D_INODE, "create\n");
1599 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
1601 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1602 GOTO(out, rc = -ENOSPC);
1603 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1604 GOTO(out, rc = -EROFS);
1605 rc = ost_create(req->rq_export, req, oti);
1608 CDEBUG(D_INODE, "destroy\n");
1609 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
1611 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1612 GOTO(out, rc = -EROFS);
1613 rc = ost_destroy(req->rq_export, req, oti);
1616 CDEBUG(D_INODE, "getattr\n");
1617 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
1619 rc = ost_getattr(req->rq_export, req);
1622 CDEBUG(D_INODE, "setattr\n");
1623 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
1625 rc = ost_setattr(req->rq_export, req, oti);
1628 CDEBUG(D_INODE, "write\n");
1629 /* req->rq_request_portal would be nice, if it was set */
1630 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1631 CERROR("%s: deny write request from %s to portal %u\n",
1632 req->rq_export->exp_obd->obd_name,
1633 obd_export_nid2str(req->rq_export),
1634 req->rq_rqbd->rqbd_service->srv_req_portal);
1635 GOTO(out, rc = -EPROTO);
1637 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1639 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1640 GOTO(out, rc = -ENOSPC);
1641 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1642 GOTO(out, rc = -EROFS);
1643 rc = ost_brw_write(req, oti);
1644 LASSERT(current->journal_info == NULL);
1645 /* ost_brw_write sends its own replies */
1648 CDEBUG(D_INODE, "read\n");
1649 /* req->rq_request_portal would be nice, if it was set */
1650 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1651 CERROR("%s: deny read request from %s to portal %u\n",
1652 req->rq_export->exp_obd->obd_name,
1653 obd_export_nid2str(req->rq_export),
1654 req->rq_rqbd->rqbd_service->srv_req_portal);
1655 GOTO(out, rc = -EPROTO);
1657 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1659 rc = ost_brw_read(req, oti);
1660 LASSERT(current->journal_info == NULL);
1661 /* ost_brw_read sends its own replies */
1664 CDEBUG(D_INODE, "punch\n");
1665 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
1667 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1668 GOTO(out, rc = -EROFS);
1669 rc = ost_punch(req->rq_export, req, oti);
1672 CDEBUG(D_INODE, "statfs\n");
1673 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
1675 rc = ost_statfs(req);
1678 CDEBUG(D_INODE, "sync\n");
1679 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
1681 rc = ost_sync(req->rq_export, req);
1684 DEBUG_REQ(D_INODE, req, "set_info");
1685 req_capsule_set(&req->rq_pill, &RQF_OST_SET_INFO);
1686 rc = ost_set_info(req->rq_export, req);
1689 DEBUG_REQ(D_INODE, req, "get_info");
1690 rc = ost_get_info(req->rq_export, req);
1692 case OST_QUOTACHECK:
1693 CDEBUG(D_INODE, "quotacheck\n");
1694 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
1695 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
1697 rc = ost_handle_quotacheck(req);
1700 CDEBUG(D_INODE, "quotactl\n");
1701 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
1702 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
1704 rc = ost_handle_quotactl(req);
1707 DEBUG_REQ(D_INODE, req, "ping");
1708 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
1709 rc = target_handle_ping(req);
1711 /* FIXME - just reply status */
1712 case LLOG_ORIGIN_CONNECT:
1713 DEBUG_REQ(D_INODE, req, "log connect");
1714 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
1715 rc = ost_llog_handle_connect(req->rq_export, req);
1716 req->rq_status = rc;
1717 rc = req_capsule_server_pack(&req->rq_pill);
1720 RETURN(ptlrpc_reply(req));
1721 case OBD_LOG_CANCEL:
1722 CDEBUG(D_INODE, "log cancel\n");
1723 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
1724 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
1726 rc = llog_origin_handle_cancel(req);
1727 req->rq_status = rc;
1728 rc = req_capsule_server_pack(&req->rq_pill);
1731 RETURN(ptlrpc_reply(req));
1733 CDEBUG(D_INODE, "enqueue\n");
1734 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
1735 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
1737 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1738 ldlm_server_blocking_ast,
1739 ldlm_server_glimpse_ast);
1740 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1743 CDEBUG(D_INODE, "convert\n");
1744 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
1745 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
1747 rc = ldlm_handle_convert(req);
1750 CDEBUG(D_INODE, "cancel\n");
1751 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
1752 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
1754 rc = ldlm_handle_cancel(req);
1756 case LDLM_BL_CALLBACK:
1757 case LDLM_CP_CALLBACK:
1758 CDEBUG(D_INODE, "callback\n");
1759 CERROR("callbacks should not happen on OST\n");
1762 CERROR("Unexpected opcode %d\n",
1763 lustre_msg_get_opc(req->rq_reqmsg));
1764 req->rq_status = -ENOTSUPP;
1765 rc = ptlrpc_error(req);
1769 LASSERT(current->journal_info == NULL);
1772 /* If we're DISCONNECTing, the export_data is already freed */
1773 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
1774 target_committed_to_req(req);
1778 oti_to_request(oti, req);
1780 target_send_reply(req, rc, fail);
1783 EXPORT_SYMBOL(ost_handle);
1785 * free per-thread pool created by ost_thread_init().
1787 static void ost_thread_done(struct ptlrpc_thread *thread)
1790 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
1795 LASSERT(thread != NULL);
1798 * be prepared to handle partially-initialized pools (because this is
1799 * called from ost_thread_init() for cleanup.
1801 tls = thread->t_data;
1803 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1804 if (tls->page[i] != NULL)
1805 OBD_PAGE_FREE(tls->page[i]);
1808 thread->t_data = NULL;
1814 * initialize per-thread page pool (bug 5137).
1816 static int ost_thread_init(struct ptlrpc_thread *thread)
1820 struct ost_thread_local_cache *tls;
1824 LASSERT(thread != NULL);
1825 LASSERT(thread->t_data == NULL);
1826 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
1831 thread->t_data = tls;
1835 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1836 OBD_PAGE_ALLOC(tls->page[i], OST_THREAD_POOL_GFP);
1837 if (tls->page[i] == NULL) {
1838 ost_thread_done(thread);
1848 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
1850 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
1851 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
1853 struct ost_obd *ost = &obd->u.ost;
1854 struct lprocfs_static_vars lvars;
1855 int oss_min_threads;
1856 int oss_max_threads;
1857 int oss_min_create_threads;
1858 int oss_max_create_threads;
1862 rc = cleanup_group_info();
1866 lprocfs_ost_init_vars(&lvars);
1867 lprocfs_obd_setup(obd, lvars.obd_vars);
1869 sema_init(&ost->ost_health_sem, 1);
1871 if (oss_num_threads) {
1872 /* If oss_num_threads is set, it is the min and the max. */
1873 if (oss_num_threads > OSS_THREADS_MAX)
1874 oss_num_threads = OSS_THREADS_MAX;
1875 if (oss_num_threads < OSS_THREADS_MIN)
1876 oss_num_threads = OSS_THREADS_MIN;
1877 oss_max_threads = oss_min_threads = oss_num_threads;
1879 /* Base min threads on memory and cpus */
1880 oss_min_threads = num_possible_cpus() * num_physpages >>
1881 (27 - CFS_PAGE_SHIFT);
1882 if (oss_min_threads < OSS_THREADS_MIN)
1883 oss_min_threads = OSS_THREADS_MIN;
1884 /* Insure a 4x range for dynamic threads */
1885 if (oss_min_threads > OSS_THREADS_MAX / 4)
1886 oss_min_threads = OSS_THREADS_MAX / 4;
1887 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4);
1891 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1892 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
1894 OST_WATCHDOG_TIMEOUT, ost_handle,
1895 LUSTRE_OSS_NAME, obd->obd_proc_entry,
1896 ost_print_req, oss_min_threads,
1897 oss_max_threads, "ll_ost",
1899 if (ost->ost_service == NULL) {
1900 CERROR("failed to start service\n");
1901 GOTO(out_lprocfs, rc = -ENOMEM);
1904 rc = ptlrpc_start_threads(obd, ost->ost_service);
1906 GOTO(out_service, rc = -EINVAL);
1908 if (oss_num_create_threads) {
1909 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
1910 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
1911 if (oss_num_create_threads < OSS_DEF_CREATE_THREADS)
1912 oss_num_create_threads = OSS_DEF_CREATE_THREADS;
1913 oss_min_create_threads = oss_max_create_threads =
1914 oss_num_create_threads;
1916 oss_min_create_threads = OSS_DEF_CREATE_THREADS;
1917 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
1920 ost->ost_create_service =
1921 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1922 OST_MAXREPSIZE, OST_CREATE_PORTAL,
1924 OST_WATCHDOG_TIMEOUT, ost_handle, "ost_create",
1925 obd->obd_proc_entry, ost_print_req,
1926 oss_min_create_threads,
1927 oss_max_create_threads,
1928 "ll_ost_creat", LCT_DT_THREAD);
1929 if (ost->ost_create_service == NULL) {
1930 CERROR("failed to start OST create service\n");
1931 GOTO(out_service, rc = -ENOMEM);
1934 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
1936 GOTO(out_create, rc = -EINVAL);
1938 ost->ost_io_service =
1939 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1940 OST_MAXREPSIZE, OST_IO_PORTAL,
1942 OST_WATCHDOG_TIMEOUT, ost_handle, "ost_io",
1943 obd->obd_proc_entry, ost_print_req,
1944 oss_min_threads, oss_max_threads,
1945 "ll_ost_io", LCT_DT_THREAD);
1946 if (ost->ost_io_service == NULL) {
1947 CERROR("failed to start OST I/O service\n");
1948 GOTO(out_create, rc = -ENOMEM);
1951 ost->ost_io_service->srv_init = ost_thread_init;
1952 ost->ost_io_service->srv_done = ost_thread_done;
1953 ost->ost_io_service->srv_cpu_affinity = 1;
1954 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
1956 GOTO(out_io, rc = -EINVAL);
1958 ping_evictor_start();
1963 ptlrpc_unregister_service(ost->ost_io_service);
1964 ost->ost_io_service = NULL;
1966 ptlrpc_unregister_service(ost->ost_create_service);
1967 ost->ost_create_service = NULL;
1969 ptlrpc_unregister_service(ost->ost_service);
1970 ost->ost_service = NULL;
1972 lprocfs_obd_cleanup(obd);
1976 static int ost_cleanup(struct obd_device *obd)
1978 struct ost_obd *ost = &obd->u.ost;
1982 ping_evictor_stop();
1984 spin_lock_bh(&obd->obd_processing_task_lock);
1985 if (obd->obd_recovering) {
1986 target_cancel_recovery_timer(obd);
1987 obd->obd_recovering = 0;
1989 spin_unlock_bh(&obd->obd_processing_task_lock);
1991 down(&ost->ost_health_sem);
1992 ptlrpc_unregister_service(ost->ost_service);
1993 ptlrpc_unregister_service(ost->ost_create_service);
1994 ptlrpc_unregister_service(ost->ost_io_service);
1995 ost->ost_service = NULL;
1996 ost->ost_create_service = NULL;
1997 up(&ost->ost_health_sem);
1999 lprocfs_obd_cleanup(obd);
2004 static int ost_health_check(struct obd_device *obd)
2006 struct ost_obd *ost = &obd->u.ost;
2009 down(&ost->ost_health_sem);
2010 rc |= ptlrpc_service_health_check(ost->ost_service);
2011 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2012 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2013 up(&ost->ost_health_sem);
2016 * health_check to return 0 on healthy
2017 * and 1 on unhealthy.
2025 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2027 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2030 /* use obd ops to offer management infrastructure */
2031 static struct obd_ops ost_obd_ops = {
2032 .o_owner = THIS_MODULE,
2033 .o_setup = ost_setup,
2034 .o_cleanup = ost_cleanup,
2035 .o_health_check = ost_health_check,
2039 static int __init ost_init(void)
2041 struct lprocfs_static_vars lvars;
2045 lprocfs_ost_init_vars(&lvars);
2046 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2047 LUSTRE_OSS_NAME, NULL);
2049 if (ost_num_threads != 0 && oss_num_threads == 0) {
2050 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2051 "use oss_num_threads instead or unset both for "
2052 "dynamic thread startup\n");
2053 oss_num_threads = ost_num_threads;
2059 static void /*__exit*/ ost_exit(void)
2061 class_unregister_type(LUSTRE_OSS_NAME);
2064 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2065 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2066 MODULE_LICENSE("GPL");
2068 module_init(ost_init);
2069 module_exit(ost_exit);