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>
43 #include <lustre_net.h>
44 #include <lustre_dlm.h>
45 #include <lustre_export.h>
46 #include <lustre_debug.h>
47 #include <linux/init.h>
48 #include <lprocfs_status.h>
49 #include <lustre_commit_confd.h>
50 #include <libcfs/list.h>
51 #include <lustre_quota.h>
52 #include "ost_internal.h"
54 static int oss_num_threads;
55 CFS_MODULE_PARM(oss_num_threads, "i", int, 0444,
56 "number of OSS service threads to start");
58 static int ost_num_threads;
59 CFS_MODULE_PARM(ost_num_threads, "i", int, 0444,
60 "number of OST service threads to start (deprecated)");
62 static int oss_num_create_threads;
63 CFS_MODULE_PARM(oss_num_create_threads, "i", int, 0444,
64 "number of OSS create threads to start");
66 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
68 struct oti_req_ack_lock *ack_lock;
75 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
76 req->rq_transno = oti->oti_transno;
78 /* XXX 4 == entries in oti_ack_locks??? */
79 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
82 /* XXX not even calling target_send_reply in some cases... */
83 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode);
87 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
88 struct obd_trans_info *oti)
90 struct ost_body *body, *repbody;
91 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
94 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
95 lustre_swab_ost_body);
99 if (lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1)) {
100 struct ldlm_request *dlm;
101 dlm = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*dlm),
102 lustre_swab_ldlm_request);
105 ldlm_request_cancel(req, dlm, 0);
108 rc = lustre_pack_reply(req, 2, size, NULL);
112 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
113 oti->oti_logcookies = obdo_logcookie(&body->oa);
114 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
116 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
117 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL);
121 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
123 struct ost_body *body, *repbody;
124 struct obd_info oinfo = { { { 0 } } };
125 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
128 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
129 lustre_swab_ost_body);
133 rc = lustre_pack_reply(req, 2, size, NULL);
137 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
139 repbody->oa = body->oa;
141 oinfo.oi_oa = &repbody->oa;
142 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
143 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
145 req->rq_status = obd_getattr(exp, &oinfo);
149 static int ost_statfs(struct ptlrpc_request *req)
151 struct obd_statfs *osfs;
152 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*osfs) };
155 rc = lustre_pack_reply(req, 2, size, NULL);
159 osfs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*osfs));
161 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
162 cfs_time_current_64() - HZ);
163 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
164 osfs->os_bfree = osfs->os_bavail = 64;
165 if (req->rq_status != 0)
166 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
171 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
172 struct obd_trans_info *oti)
174 struct ost_body *body, *repbody;
175 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
178 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
179 lustre_swab_ost_body);
183 rc = lustre_pack_reply(req, 2, size, NULL);
187 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
189 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
190 oti->oti_logcookies = obdo_logcookie(&repbody->oa);
191 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
192 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
197 * Helper function for ost_punch(): if asked by client, acquire [size, EOF]
198 * lock on the file being truncated.
200 static int ost_punch_lock_get(struct obd_export *exp, struct obdo *oa,
201 struct lustre_handle *lh)
204 struct ldlm_res_id res_id = { .name = { oa->o_id, 0, oa->o_gr, 0} };
205 ldlm_policy_data_t policy;
211 LASSERT(!lustre_handle_is_used(lh));
213 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
214 !(oa->o_flags & OBD_FL_TRUNCLOCK))
217 CDEBUG(D_INODE, "OST-side truncate lock.\n");
220 finis = start + oa->o_blocks;
223 * standard truncate optimization: if file body is completely
224 * destroyed, don't send data back to the server.
226 flags = (start == 0) ? LDLM_AST_DISCARD_DATA : 0;
228 policy.l_extent.start = start & CFS_PAGE_MASK;
231 * If ->o_blocks is EOF it means "lock till the end of the
232 * file". Otherwise, it's size of a hole being punched (in bytes)
234 if (oa->o_blocks == OBD_OBJECT_EOF || finis < start)
235 policy.l_extent.end = OBD_OBJECT_EOF;
237 policy.l_extent.end = finis | ~CFS_PAGE_MASK;
239 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
240 LDLM_EXTENT, &policy, LCK_PW, &flags,
241 ldlm_blocking_ast, ldlm_completion_ast,
242 ldlm_glimpse_ast, NULL, 0, NULL, lh));
246 * Helper function for ost_punch(): release lock acquired by
247 * ost_punch_lock_get(), if any.
249 static void ost_punch_lock_put(struct obd_export *exp, struct obdo *oa,
250 struct lustre_handle *lh)
253 if (lustre_handle_is_used(lh))
254 ldlm_lock_decref(lh, LCK_PW);
258 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
259 struct obd_trans_info *oti)
261 struct obd_info oinfo = { { { 0 } } };
262 struct ost_body *body, *repbody;
263 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
264 struct lustre_handle lh = {0,};
267 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
268 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
270 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
271 lustre_swab_ost_body);
275 oinfo.oi_oa = &body->oa;
276 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
277 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
279 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
280 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
283 rc = lustre_pack_reply(req, 2, size, NULL);
287 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
289 rc = ost_punch_lock_get(exp, oinfo.oi_oa, &lh);
291 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
292 oinfo.oi_oa->o_flags == OBD_FL_TRUNCLOCK)
294 * If OBD_FL_TRUNCLOCK is the only bit set in
295 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
296 * through filter_setattr() to filter_iocontrol().
298 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
300 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
301 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
303 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
304 ost_punch_lock_put(exp, oinfo.oi_oa, &lh);
306 repbody->oa = *oinfo.oi_oa;
310 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
312 struct ost_body *body, *repbody;
313 struct lustre_capa *capa = NULL;
314 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
317 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
318 lustre_swab_ost_body);
322 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
323 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 1);
325 rc = lustre_pack_reply(req, 2, size, NULL);
329 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
331 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
332 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
333 repbody->oa.o_blocks, capa);
337 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
338 struct obd_trans_info *oti)
340 struct ost_body *body, *repbody;
341 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
342 struct obd_info oinfo = { { { 0 } } };
345 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
346 lustre_swab_ost_body);
350 rc = lustre_pack_reply(req, 2, size, NULL);
354 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
356 repbody->oa = body->oa;
358 oinfo.oi_oa = &repbody->oa;
359 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
360 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
362 req->rq_status = obd_setattr(exp, &oinfo, oti);
366 static int ost_bulk_timeout(void *data)
369 /* We don't fail the connection here, because having the export
370 * killed makes the (vital) call to commitrw very sad.
375 static int get_per_page_niobufs(struct obd_ioobj *ioo, int nioo,
376 struct niobuf_remote *rnb, int nrnb,
377 struct niobuf_remote **pp_rnbp)
379 /* Copy a remote niobuf, splitting it into page-sized chunks
380 * and setting ioo[i].ioo_bufcnt accordingly */
381 struct niobuf_remote *pp_rnb;
389 * array of sufficient size already preallocated by caller
391 LASSERT(pp_rnbp != NULL);
392 LASSERT(*pp_rnbp != NULL);
394 /* first count and check the number of pages required */
395 for (i = 0; i < nioo; i++)
396 for (j = 0; j < ioo->ioo_bufcnt; j++, rnbidx++) {
397 obd_off offset = rnb[rnbidx].offset;
398 obd_off p0 = offset >> CFS_PAGE_SHIFT;
399 obd_off pn = (offset + rnb[rnbidx].len - 1) >>
402 LASSERT(rnbidx < nrnb);
404 npages += (pn + 1 - p0);
406 if (rnb[rnbidx].len == 0) {
407 CERROR("zero len BRW: obj %d objid "LPX64
408 " buf %u\n", i, ioo[i].ioo_id, j);
412 rnb[rnbidx].offset <= rnb[rnbidx-1].offset) {
413 CERROR("unordered BRW: obj %d objid "LPX64
414 " buf %u offset "LPX64" <= "LPX64"\n",
415 i, ioo[i].ioo_id, j, rnb[rnbidx].offset,
421 LASSERT(rnbidx == nrnb);
423 if (npages == nrnb) { /* all niobufs are for single pages */
430 /* now do the actual split */
432 for (i = 0; i < nioo; i++) {
435 for (j = 0; j < ioo[i].ioo_bufcnt; j++, rnbidx++) {
436 obd_off off = rnb[rnbidx].offset;
437 int nob = rnb[rnbidx].len;
439 LASSERT(rnbidx < nrnb);
441 obd_off poff = off & ~CFS_PAGE_MASK;
442 int pnob = (poff + nob > CFS_PAGE_SIZE) ?
443 PAGE_SIZE - poff : nob;
445 LASSERT(page < npages);
446 pp_rnb[page].len = pnob;
447 pp_rnb[page].offset = off;
448 pp_rnb[page].flags = rnb[rnbidx].flags;
450 CDEBUG(0, " obj %d id "LPX64
451 "page %d(%d) "LPX64" for %d, flg %x\n",
452 i, ioo[i].ioo_id, obj_pages, page,
453 pp_rnb[page].offset, pp_rnb[page].len,
463 ioo[i].ioo_bufcnt = obj_pages;
465 LASSERT(page == npages);
470 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc)
475 for (i = 0; i < desc->bd_iov_count; i++) {
476 struct page *page = desc->bd_iov[i].kiov_page;
477 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
478 char *ptr = kmap(page) + off;
479 int len = desc->bd_iov[i].kiov_len;
481 /* corrupt the data before we compute the checksum, to
482 * simulate a client->OST data error */
484 OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_CHECKSUM_RECEIVE))
485 memcpy(ptr, "bad3", min(4, len));
486 cksum = crc32_le(cksum, ptr, len);
487 /* corrupt the data after we compute the checksum, to
488 * simulate an OST->client data error */
489 if (i == 0 && OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_CHECKSUM_SEND))
490 memcpy(ptr, "bad4", min(4, len));
498 * populate @nio by @nrpages pages from per-thread page pool
500 static void ost_nio_pages_get(struct ptlrpc_request *req,
501 struct niobuf_local *nio, int nrpages)
504 struct ost_thread_local_cache *tls;
508 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
509 LASSERT(req != NULL);
510 LASSERT(req->rq_svc_thread != NULL);
513 LASSERT(tls != NULL);
515 memset(nio, 0, nrpages * sizeof *nio);
516 for (i = 0; i < nrpages; ++ i) {
520 LASSERT(page != NULL);
521 POISON_PAGE(page, 0xf1);
523 LL_CDEBUG_PAGE(D_INFO, page, "%d\n", i);
529 * Dual for ost_nio_pages_get(). Poison pages in pool for debugging
531 static void ost_nio_pages_put(struct ptlrpc_request *req,
532 struct niobuf_local *nio, int nrpages)
538 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
540 for (i = 0; i < nrpages; ++ i)
541 POISON_PAGE(nio[i].page, 0xf2);
545 static int ost_brw_lock_get(int mode, struct obd_export *exp,
546 struct obd_ioobj *obj, struct niobuf_remote *nb,
547 struct lustre_handle *lh)
550 int nrbufs = obj->ioo_bufcnt;
551 struct ldlm_res_id res_id = { .name = { obj->ioo_id, 0,
553 ldlm_policy_data_t policy;
558 LASSERT(mode == LCK_PR || mode == LCK_PW);
559 LASSERT(!lustre_handle_is_used(lh));
561 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
564 /* EXPENSIVE ASSERTION */
565 for (i = 1; i < nrbufs; i ++)
566 LASSERT((nb[0].flags & OBD_BRW_SRVLOCK) ==
567 (nb[i].flags & OBD_BRW_SRVLOCK));
569 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
570 policy.l_extent.end = (nb[nrbufs - 1].offset +
571 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
573 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
574 LDLM_EXTENT, &policy, mode, &flags,
575 ldlm_blocking_ast, ldlm_completion_ast,
576 ldlm_glimpse_ast, NULL, 0, NULL, lh));
579 static void ost_brw_lock_put(int mode,
580 struct obd_ioobj *obj, struct niobuf_remote *niob,
581 struct lustre_handle *lh)
584 LASSERT(mode == LCK_PR || mode == LCK_PW);
585 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
586 lustre_handle_is_used(lh));
587 if (lustre_handle_is_used(lh))
588 ldlm_lock_decref(lh, mode);
592 struct ost_prolong_data {
593 struct obd_export *opd_exp;
594 ldlm_policy_data_t opd_policy;
595 ldlm_mode_t opd_mode;
598 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
600 struct ost_prolong_data *opd = data;
602 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
604 if (lock->l_req_mode != lock->l_granted_mode) {
605 /* scan granted locks only */
606 return LDLM_ITER_STOP;
609 if (lock->l_export != opd->opd_exp) {
610 /* prolong locks only for given client */
611 return LDLM_ITER_CONTINUE;
614 if (!(lock->l_granted_mode & opd->opd_mode)) {
615 /* we aren't interesting in all type of locks */
616 return LDLM_ITER_CONTINUE;
619 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
620 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
621 /* the request doesn't cross the lock, skip it */
622 return LDLM_ITER_CONTINUE;
625 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
626 /* ignore locks not being cancelled */
627 return LDLM_ITER_CONTINUE;
630 /* OK. this is a possible lock the user holds doing I/O
631 * let's refresh eviction timer for it */
632 ldlm_refresh_waiting_lock(lock);
634 return LDLM_ITER_CONTINUE;
637 static void ost_prolong_locks(struct obd_export *exp, struct obd_ioobj *obj,
638 struct niobuf_remote *nb, ldlm_mode_t mode)
640 struct ldlm_res_id res_id = { .name = { obj->ioo_id, 0,
642 int nrbufs = obj->ioo_bufcnt;
643 struct ost_prolong_data opd;
649 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
650 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
651 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
653 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
654 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
655 opd.opd_policy.l_extent.end);
656 ldlm_resource_iterate(exp->exp_obd->obd_namespace, &res_id,
657 ost_prolong_locks_iter, &opd);
660 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
662 struct ptlrpc_bulk_desc *desc;
663 struct obd_export *exp = req->rq_export;
664 struct niobuf_remote *remote_nb;
665 struct niobuf_remote *pp_rnb = NULL;
666 struct niobuf_local *local_nb;
667 struct obd_ioobj *ioo;
668 struct ost_body *body, *repbody;
669 struct lustre_capa *capa = NULL;
670 struct l_wait_info lwi;
671 struct lustre_handle lockh = { 0 };
672 int size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
673 int niocount, npages, nob = 0, rc, i;
677 req->rq_bulk_read = 1;
679 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
680 GOTO(out, rc = -EIO);
682 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
684 /* Check if there is eviction in progress, and if so, wait for it to
686 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
687 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
688 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
689 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
693 GOTO(out, rc = -ENOTCONN);
695 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
696 lustre_swab_ost_body);
698 CERROR("Missing/short ost_body\n");
699 GOTO(out, rc = -EFAULT);
702 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*ioo),
703 lustre_swab_obd_ioobj);
705 CERROR("Missing/short ioobj\n");
706 GOTO(out, rc = -EFAULT);
709 niocount = ioo->ioo_bufcnt;
710 if (niocount > PTLRPC_MAX_BRW_PAGES) {
711 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
713 GOTO(out, rc = -EFAULT);
716 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
717 niocount * sizeof(*remote_nb),
718 lustre_swab_niobuf_remote);
719 if (remote_nb == NULL) {
720 CERROR("Missing/short niobuf\n");
721 GOTO(out, rc = -EFAULT);
723 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
724 for (i = 1; i < niocount; i++)
725 lustre_swab_niobuf_remote (&remote_nb[i]);
728 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
729 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
731 rc = lustre_pack_reply(req, 2, size, NULL);
736 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
739 local_nb = ost_tls(req)->local;
740 pp_rnb = ost_tls(req)->remote;
742 /* FIXME all niobuf splitting should be done in obdfilter if needed */
743 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
744 npages = get_per_page_niobufs(ioo, 1, remote_nb, niocount, &pp_rnb);
746 GOTO(out, rc = npages);
748 LASSERT(npages <= OST_THREAD_POOL_SIZE);
750 ost_nio_pages_get(req, local_nb, npages);
752 desc = ptlrpc_prep_bulk_exp(req, npages,
753 BULK_PUT_SOURCE, OST_BULK_PORTAL);
755 GOTO(out, rc = -ENOMEM);
757 rc = ost_brw_lock_get(LCK_PR, exp, ioo, pp_rnb, &lockh);
762 * If getting the lock took more time than
763 * client was willing to wait, drop it. b=11330
765 if (cfs_time_current_sec() > req->rq_arrival_time.tv_sec + obd_timeout ||
766 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
768 CERROR("Dropping timed-out read from %s because locking"
769 "object "LPX64" took %ld seconds.\n",
770 libcfs_id2str(req->rq_peer), ioo->ioo_id,
771 cfs_time_current_sec() - req->rq_arrival_time.tv_sec);
772 GOTO(out_lock, rc = -ETIMEDOUT);
775 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1,
776 ioo, npages, pp_rnb, local_nb, oti, capa);
780 ost_prolong_locks(exp, ioo, pp_rnb, LCK_PW | LCK_PR);
783 for (i = 0; i < npages; i++) {
784 int page_rc = local_nb[i].rc;
786 if (page_rc < 0) { /* error */
791 LASSERTF(page_rc <= pp_rnb[i].len, "page_rc (%d) > "
792 "pp_rnb[%d].len (%d)\n", page_rc, i, pp_rnb[i].len);
794 if (page_rc != 0) { /* some data! */
795 LASSERT (local_nb[i].page != NULL);
796 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
797 pp_rnb[i].offset & ~CFS_PAGE_MASK,
801 if (page_rc != pp_rnb[i].len) { /* short read */
802 /* All subsequent pages should be 0 */
804 LASSERT(local_nb[i].rc == 0);
809 if (unlikely(body->oa.o_valid & OBD_MD_FLCKSUM)) {
810 body->oa.o_cksum = ost_checksum_bulk(desc);
811 body->oa.o_valid = OBD_MD_FLCKSUM;
812 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
814 body->oa.o_valid = 0;
816 /* We're finishing using body->oa as an input variable */
818 /* Check if client was evicted while we were doing i/o before touching
821 /* Check if there is eviction in progress, and if so, wait for
823 if (unlikely(atomic_read(&exp->exp_obd->
824 obd_evict_inprogress))) {
825 lwi = LWI_INTR(NULL, NULL);
826 rc = l_wait_event(exp->exp_obd->
827 obd_evict_inprogress_waitq,
828 !atomic_read(&exp->exp_obd->
829 obd_evict_inprogress),
835 sptlrpc_svc_wrap_bulk(req, desc);
837 rc = ptlrpc_start_bulk_transfer(desc);
841 lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 4, HZ,
842 ost_bulk_timeout, desc);
843 rc = l_wait_event(desc->bd_waitq,
844 !ptlrpc_bulk_active(desc) ||
845 exp->exp_failed, &lwi);
846 LASSERT(rc == 0 || rc == -ETIMEDOUT);
847 if (rc == -ETIMEDOUT) {
848 DEBUG_REQ(D_ERROR, req, "timeout on bulk PUT");
849 ptlrpc_abort_bulk(desc);
850 } else if (exp->exp_failed) {
851 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
853 ptlrpc_abort_bulk(desc);
854 } else if (!desc->bd_success ||
855 desc->bd_nob_transferred != desc->bd_nob) {
856 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
858 "truncated" : "network error on",
859 desc->bd_nob_transferred,
861 /* XXX should this be a different errno? */
865 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
870 /* Must commit after prep above in all cases */
871 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1,
872 ioo, npages, local_nb, oti, rc);
874 ost_nio_pages_put(req, local_nb, npages);
877 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
879 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
883 ost_brw_lock_put(LCK_PR, ioo, pp_rnb, &lockh);
885 ptlrpc_free_bulk(desc);
889 req->rq_status = nob;
890 target_committed_to_req(req);
892 } else if (!no_reply) {
893 /* Only reply if there was no comms problem with bulk */
894 target_committed_to_req(req);
898 if (req->rq_reply_state != NULL) {
899 /* reply out callback would free */
900 ptlrpc_rs_decref(req->rq_reply_state);
901 req->rq_reply_state = NULL;
903 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
904 "client will retry\n",
905 exp->exp_obd->obd_name,
906 exp->exp_client_uuid.uuid,
907 exp->exp_connection->c_remote_uuid.uuid,
908 libcfs_id2str(req->rq_peer));
914 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
916 struct ptlrpc_bulk_desc *desc;
917 struct obd_export *exp = req->rq_export;
918 struct niobuf_remote *remote_nb;
919 struct niobuf_remote *pp_rnb;
920 struct niobuf_local *local_nb;
921 struct obd_ioobj *ioo;
922 struct ost_body *body, *repbody;
923 struct l_wait_info lwi;
924 struct lustre_handle lockh = {0};
925 struct lustre_capa *capa = NULL;
927 int size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
928 int objcount, niocount, npages;
930 obd_count client_cksum, server_cksum = 0;
934 req->rq_bulk_write = 1;
936 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
937 GOTO(out, rc = -EIO);
938 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
939 GOTO(out, rc = -EFAULT);
941 /* pause before transaction has been started */
942 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
944 /* Check if there is eviction in progress, and if so, wait for it to
946 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
947 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
948 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
949 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
953 GOTO(out, rc = -ENOTCONN);
955 swab = lustre_msg_swabbed(req->rq_reqmsg);
956 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
957 lustre_swab_ost_body);
959 CERROR("Missing/short ost_body\n");
960 GOTO(out, rc = -EFAULT);
963 lustre_set_req_swabbed(req, REQ_REC_OFF + 1);
964 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
967 CERROR("Missing/short ioobj\n");
968 GOTO(out, rc = -EFAULT);
971 CERROR("too many ioobjs (%d)\n", objcount);
972 GOTO(out, rc = -EFAULT);
975 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
976 objcount * sizeof(*ioo));
977 LASSERT (ioo != NULL);
978 for (niocount = i = 0; i < objcount; i++) {
980 lustre_swab_obd_ioobj(&ioo[i]);
981 if (ioo[i].ioo_bufcnt == 0) {
982 CERROR("ioo[%d] has zero bufcnt\n", i);
983 GOTO(out, rc = -EFAULT);
985 niocount += ioo[i].ioo_bufcnt;
988 if (niocount > PTLRPC_MAX_BRW_PAGES) {
989 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
991 GOTO(out, rc = -EFAULT);
994 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
995 niocount * sizeof(*remote_nb),
996 lustre_swab_niobuf_remote);
997 if (remote_nb == NULL) {
998 CERROR("Missing/short niobuf\n");
999 GOTO(out, rc = -EFAULT);
1001 if (swab) { /* swab the remaining niobufs */
1002 for (i = 1; i < niocount; i++)
1003 lustre_swab_niobuf_remote (&remote_nb[i]);
1006 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
1007 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
1009 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
1010 rc = lustre_pack_reply(req, 3, size, NULL);
1013 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
1014 niocount * sizeof(*rcs));
1017 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
1018 * ost_thread_init().
1020 local_nb = ost_tls(req)->local;
1021 pp_rnb = ost_tls(req)->remote;
1023 /* FIXME all niobuf splitting should be done in obdfilter if needed */
1024 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
1025 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
1027 GOTO(out, rc = npages);
1029 LASSERT(npages <= OST_THREAD_POOL_SIZE);
1031 ost_nio_pages_get(req, local_nb, npages);
1033 desc = ptlrpc_prep_bulk_exp(req, npages,
1034 BULK_GET_SINK, OST_BULK_PORTAL);
1036 GOTO(out, rc = -ENOMEM);
1038 rc = ost_brw_lock_get(LCK_PW, exp, ioo, pp_rnb, &lockh);
1043 * If getting the lock took more time than
1044 * client was willing to wait, drop it. b=11330
1046 if (cfs_time_current_sec() > req->rq_arrival_time.tv_sec + obd_timeout ||
1047 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
1049 CERROR("Dropping timed-out write from %s because locking"
1050 "object "LPX64" took %ld seconds.\n",
1051 libcfs_id2str(req->rq_peer), ioo->ioo_id,
1052 cfs_time_current_sec() - req->rq_arrival_time.tv_sec);
1053 GOTO(out_lock, rc = -ETIMEDOUT);
1056 ost_prolong_locks(exp, ioo, pp_rnb, LCK_PW);
1058 /* obd_preprw clobbers oa->valid, so save what we need */
1059 client_cksum = body->oa.o_valid & OBD_MD_FLCKSUM ? body->oa.o_cksum : 0;
1061 /* Because we already sync grant info with client when reconnect,
1062 * grant info will be cleared for resent req, then fed_grant and
1063 * total_grant will not be modified in following preprw_write */
1064 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1065 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1066 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1069 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
1070 ioo, npages, pp_rnb, local_nb, oti, capa);
1074 /* NB Having prepped, we must commit... */
1076 for (i = 0; i < npages; i++)
1077 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1078 pp_rnb[i].offset & ~CFS_PAGE_MASK,
1081 /* Check if client was evicted while we were doing i/o before touching
1083 if (desc->bd_export->exp_failed)
1086 rc = ptlrpc_start_bulk_transfer (desc);
1088 lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 2, HZ,
1089 ost_bulk_timeout, desc);
1090 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1091 desc->bd_export->exp_failed, &lwi);
1092 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1093 if (rc == -ETIMEDOUT) {
1094 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1095 ptlrpc_abort_bulk(desc);
1096 } else if (desc->bd_export->exp_failed) {
1097 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1099 ptlrpc_abort_bulk(desc);
1100 } else if (!desc->bd_success ||
1101 desc->bd_nob_transferred != desc->bd_nob) {
1102 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1104 "truncated" : "network error on",
1105 desc->bd_nob_transferred, desc->bd_nob);
1106 /* XXX should this be a different errno? */
1110 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1115 /* let client retry if unwrap failed */
1116 rc = sptlrpc_svc_unwrap_bulk(req, desc);
1119 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1121 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1123 if (unlikely(client_cksum != 0 && rc == 0)) {
1124 static int cksum_counter;
1125 server_cksum = ost_checksum_bulk(desc);
1126 repbody->oa.o_valid |= OBD_MD_FLCKSUM;
1127 repbody->oa.o_cksum = server_cksum;
1129 if (unlikely(client_cksum != server_cksum)) {
1130 CERROR("client csum %x, server csum %x\n",
1131 client_cksum, server_cksum);
1133 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1134 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1135 cksum_counter, libcfs_id2str(req->rq_peer),
1140 /* Must commit after prep above in all cases */
1141 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa,
1142 objcount, ioo, npages, local_nb, oti, rc);
1144 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1145 int new_cksum = ost_checksum_bulk(desc);
1150 if (new_cksum == server_cksum)
1151 msg = "changed in transit before arrival at OST";
1152 else if (new_cksum == client_cksum)
1153 msg = "initial checksum before message complete";
1155 msg = "changed in transit AND after initial checksum";
1157 if (req->rq_peer.nid == desc->bd_sender) {
1161 router = libcfs_nid2str(desc->bd_sender);
1164 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1165 "%s%s%s inum "LPU64"/"LPU64" object "
1166 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1167 exp->exp_obd->obd_name, msg,
1168 libcfs_id2str(req->rq_peer),
1170 body->oa.o_valid & OBD_MD_FLFID ?
1171 body->oa.o_fid : (__u64)0,
1172 body->oa.o_valid & OBD_MD_FLFID ?
1173 body->oa.o_generation :(__u64)0,
1175 body->oa.o_valid & OBD_MD_FLGROUP ?
1176 body->oa.o_gr : (__u64)0,
1178 pp_rnb[npages-1].offset+pp_rnb[npages-1].len
1180 CERROR("client csum %x, original server csum %x, "
1181 "server csum now %x\n",
1182 client_cksum, server_cksum, new_cksum);
1185 ost_nio_pages_put(req, local_nb, npages);
1188 /* set per-requested niobuf return codes */
1189 for (i = j = 0; i < niocount; i++) {
1190 int nob = remote_nb[i].len;
1194 LASSERT(j < npages);
1195 if (local_nb[j].rc < 0)
1196 rcs[i] = local_nb[j].rc;
1197 nob -= pp_rnb[j].len;
1202 LASSERT(j == npages);
1206 ost_brw_lock_put(LCK_PW, ioo, pp_rnb, &lockh);
1208 ptlrpc_free_bulk(desc);
1211 oti_to_request(oti, req);
1212 target_committed_to_req(req);
1213 rc = ptlrpc_reply(req);
1214 } else if (!no_reply) {
1215 /* Only reply if there was no comms problem with bulk */
1216 target_committed_to_req(req);
1217 req->rq_status = rc;
1220 if (req->rq_reply_state != NULL) {
1221 /* reply out callback would free */
1222 ptlrpc_rs_decref(req->rq_reply_state);
1223 req->rq_reply_state = NULL;
1225 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1226 "client will retry\n",
1227 exp->exp_obd->obd_name,
1228 exp->exp_client_uuid.uuid,
1229 exp->exp_connection->c_remote_uuid.uuid,
1230 libcfs_id2str(req->rq_peer));
1235 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1237 char *key, *val = NULL;
1238 int keylen, vallen, rc = 0;
1241 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1243 DEBUG_REQ(D_HA, req, "no set_info key");
1246 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1248 rc = lustre_pack_reply(req, 1, NULL, NULL);
1252 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1254 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
1256 if (KEY_IS("evict_by_nid")) {
1258 obd_export_evict_by_nid(exp->exp_obd, val);
1263 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1265 lustre_msg_set_status(req->rq_repmsg, 0);
1269 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1273 int size[2] = { sizeof(struct ptlrpc_body), 0 };
1276 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1278 DEBUG_REQ(D_HA, req, "no get_info key");
1281 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1283 /* call once to get the size to allocate the reply buffer */
1284 rc = obd_get_info(exp, keylen, key, &size[1], NULL);
1288 rc = lustre_pack_reply(req, 2, size, NULL);
1292 reply = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*reply));
1293 /* call again to fill in the reply buffer */
1294 rc = obd_get_info(exp, keylen, key, size, reply);
1295 lustre_msg_set_status(req->rq_repmsg, 0);
1300 static int ost_handle_quotactl(struct ptlrpc_request *req)
1302 struct obd_quotactl *oqctl, *repoqc;
1303 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) };
1306 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1307 lustre_swab_obd_quotactl);
1309 GOTO(out, rc = -EPROTO);
1311 rc = lustre_pack_reply(req, 2, size, NULL);
1315 repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc));
1317 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1323 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1325 struct obd_quotactl *oqctl;
1329 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1330 lustre_swab_obd_quotactl);
1334 rc = lustre_pack_reply(req, 1, NULL, NULL);
1336 CERROR("ost: out of memory while packing quotacheck reply\n");
1340 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1344 static int ost_llog_handle_connect(struct obd_export *exp,
1345 struct ptlrpc_request *req)
1347 struct llogd_conn_body *body;
1351 body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body));
1352 rc = obd_llog_connect(exp, body);
1357 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1358 struct obd_device *obd, int *process)
1360 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1361 case OST_CONNECT: /* This will never get here, but for completeness. */
1362 case OST_DISCONNECT:
1373 case OBD_LOG_CANCEL:
1375 *process = target_queue_recovery_request(req, obd);
1379 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1385 int ost_msg_check_version(struct lustre_msg *msg)
1389 switch(lustre_msg_get_opc(msg)) {
1391 case OST_DISCONNECT:
1394 case SEC_CTX_INIT_CONT:
1396 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1398 CERROR("bad opc %u version %08x, expecting %08x\n",
1399 lustre_msg_get_opc(msg),
1400 lustre_msg_get_version(msg),
1401 LUSTRE_OBD_VERSION);
1414 case OST_QUOTACHECK:
1416 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1418 CERROR("bad opc %u version %08x, expecting %08x\n",
1419 lustre_msg_get_opc(msg),
1420 lustre_msg_get_version(msg),
1421 LUSTRE_OST_VERSION);
1426 case LDLM_BL_CALLBACK:
1427 case LDLM_CP_CALLBACK:
1428 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1430 CERROR("bad opc %u version %08x, expecting %08x\n",
1431 lustre_msg_get_opc(msg),
1432 lustre_msg_get_version(msg),
1433 LUSTRE_DLM_VERSION);
1435 case LLOG_ORIGIN_CONNECT:
1436 case OBD_LOG_CANCEL:
1437 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1439 CERROR("bad opc %u version %08x, expecting %08x\n",
1440 lustre_msg_get_opc(msg),
1441 lustre_msg_get_version(msg),
1442 LUSTRE_LOG_VERSION);
1445 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1451 int ost_handle(struct ptlrpc_request *req)
1453 struct obd_trans_info trans_info = { 0, };
1454 struct obd_trans_info *oti = &trans_info;
1455 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1456 struct obd_device *obd = NULL;
1459 LASSERT(current->journal_info == NULL);
1461 /* primordial rpcs don't affect server recovery */
1462 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1464 case SEC_CTX_INIT_CONT:
1469 /* XXX identical to MDS */
1470 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1473 if (req->rq_export == NULL) {
1474 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1475 lustre_msg_get_opc(req->rq_reqmsg),
1476 libcfs_id2str(req->rq_peer));
1477 req->rq_status = -ENOTCONN;
1478 GOTO(out, rc = -ENOTCONN);
1481 obd = req->rq_export->exp_obd;
1483 /* Check for aborted recovery. */
1484 spin_lock_bh(&obd->obd_processing_task_lock);
1485 recovering = obd->obd_recovering;
1486 spin_unlock_bh(&obd->obd_processing_task_lock);
1488 rc = ost_filter_recovery_request(req, obd,
1490 if (rc || !should_process)
1492 else if (should_process < 0) {
1493 req->rq_status = should_process;
1494 rc = ptlrpc_error(req);
1502 rc = ost_msg_check_version(req->rq_reqmsg);
1506 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1508 CDEBUG(D_INODE, "connect\n");
1509 OBD_FAIL_RETURN(OBD_FAIL_OST_CONNECT_NET, 0);
1510 rc = target_handle_connect(req);
1512 obd = req->rq_export->exp_obd;
1515 case OST_DISCONNECT:
1516 CDEBUG(D_INODE, "disconnect\n");
1517 OBD_FAIL_RETURN(OBD_FAIL_OST_DISCONNECT_NET, 0);
1518 rc = target_handle_disconnect(req);
1521 CDEBUG(D_INODE, "create\n");
1522 OBD_FAIL_RETURN(OBD_FAIL_OST_CREATE_NET, 0);
1523 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
1524 GOTO(out, rc = -ENOSPC);
1525 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1526 GOTO(out, rc = -EROFS);
1527 rc = ost_create(req->rq_export, req, oti);
1530 CDEBUG(D_INODE, "destroy\n");
1531 OBD_FAIL_RETURN(OBD_FAIL_OST_DESTROY_NET, 0);
1532 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1533 GOTO(out, rc = -EROFS);
1534 rc = ost_destroy(req->rq_export, req, oti);
1537 CDEBUG(D_INODE, "getattr\n");
1538 OBD_FAIL_RETURN(OBD_FAIL_OST_GETATTR_NET, 0);
1539 rc = ost_getattr(req->rq_export, req);
1542 CDEBUG(D_INODE, "setattr\n");
1543 OBD_FAIL_RETURN(OBD_FAIL_OST_SETATTR_NET, 0);
1544 rc = ost_setattr(req->rq_export, req, oti);
1547 CDEBUG(D_INODE, "write\n");
1548 /* req->rq_request_portal would be nice, if it was set */
1549 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1550 CERROR("%s: deny write request from %s to portal %u\n",
1551 req->rq_export->exp_obd->obd_name,
1552 obd_export_nid2str(req->rq_export),
1553 req->rq_rqbd->rqbd_service->srv_req_portal);
1554 GOTO(out, rc = -EPROTO);
1556 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1557 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
1558 GOTO(out, rc = -ENOSPC);
1559 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1560 GOTO(out, rc = -EROFS);
1561 rc = ost_brw_write(req, oti);
1562 LASSERT(current->journal_info == NULL);
1563 /* ost_brw_write sends its own replies */
1566 CDEBUG(D_INODE, "read\n");
1567 /* req->rq_request_portal would be nice, if it was set */
1568 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1569 CERROR("%s: deny read request from %s to portal %u\n",
1570 req->rq_export->exp_obd->obd_name,
1571 obd_export_nid2str(req->rq_export),
1572 req->rq_rqbd->rqbd_service->srv_req_portal);
1573 GOTO(out, rc = -EPROTO);
1575 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1576 rc = ost_brw_read(req, oti);
1577 LASSERT(current->journal_info == NULL);
1578 /* ost_brw_read sends its own replies */
1581 CDEBUG(D_INODE, "punch\n");
1582 OBD_FAIL_RETURN(OBD_FAIL_OST_PUNCH_NET, 0);
1583 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1584 GOTO(out, rc = -EROFS);
1585 rc = ost_punch(req->rq_export, req, oti);
1588 CDEBUG(D_INODE, "statfs\n");
1589 OBD_FAIL_RETURN(OBD_FAIL_OST_STATFS_NET, 0);
1590 rc = ost_statfs(req);
1593 CDEBUG(D_INODE, "sync\n");
1594 OBD_FAIL_RETURN(OBD_FAIL_OST_SYNC_NET, 0);
1595 rc = ost_sync(req->rq_export, req);
1598 DEBUG_REQ(D_INODE, req, "set_info");
1599 rc = ost_set_info(req->rq_export, req);
1602 DEBUG_REQ(D_INODE, req, "get_info");
1603 rc = ost_get_info(req->rq_export, req);
1605 case OST_QUOTACHECK:
1606 CDEBUG(D_INODE, "quotacheck\n");
1607 OBD_FAIL_RETURN(OBD_FAIL_OST_QUOTACHECK_NET, 0);
1608 rc = ost_handle_quotacheck(req);
1611 CDEBUG(D_INODE, "quotactl\n");
1612 OBD_FAIL_RETURN(OBD_FAIL_OST_QUOTACTL_NET, 0);
1613 rc = ost_handle_quotactl(req);
1616 DEBUG_REQ(D_INODE, req, "ping");
1617 rc = target_handle_ping(req);
1619 /* FIXME - just reply status */
1620 case LLOG_ORIGIN_CONNECT:
1621 DEBUG_REQ(D_INODE, req, "log connect");
1622 rc = ost_llog_handle_connect(req->rq_export, req);
1623 req->rq_status = rc;
1624 rc = lustre_pack_reply(req, 1, NULL, NULL);
1627 RETURN(ptlrpc_reply(req));
1628 case OBD_LOG_CANCEL:
1629 CDEBUG(D_INODE, "log cancel\n");
1630 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
1631 rc = llog_origin_handle_cancel(req);
1632 req->rq_status = rc;
1633 rc = lustre_pack_reply(req, 1, NULL, NULL);
1636 RETURN(ptlrpc_reply(req));
1638 CDEBUG(D_INODE, "enqueue\n");
1639 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
1640 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1641 ldlm_server_blocking_ast,
1642 ldlm_server_glimpse_ast);
1643 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1646 CDEBUG(D_INODE, "convert\n");
1647 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
1648 rc = ldlm_handle_convert(req);
1651 CDEBUG(D_INODE, "cancel\n");
1652 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CANCEL, 0);
1653 rc = ldlm_handle_cancel(req);
1655 case LDLM_BL_CALLBACK:
1656 case LDLM_CP_CALLBACK:
1657 CDEBUG(D_INODE, "callback\n");
1658 CERROR("callbacks should not happen on OST\n");
1661 CERROR("Unexpected opcode %d\n",
1662 lustre_msg_get_opc(req->rq_reqmsg));
1663 req->rq_status = -ENOTSUPP;
1664 rc = ptlrpc_error(req);
1668 LASSERT(current->journal_info == NULL);
1671 /* If we're DISCONNECTing, the export_data is already freed */
1672 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
1673 target_committed_to_req(req);
1677 oti_to_request(oti, req);
1679 target_send_reply(req, rc, fail);
1682 EXPORT_SYMBOL(ost_handle);
1684 * free per-thread pool created by ost_thread_init().
1686 static void ost_thread_done(struct ptlrpc_thread *thread)
1689 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
1694 LASSERT(thread != NULL);
1697 * be prepared to handle partially-initialized pools (because this is
1698 * called from ost_thread_init() for cleanup.
1700 tls = thread->t_data;
1702 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1703 if (tls->page[i] != NULL)
1704 OBD_PAGE_FREE(tls->page[i]);
1707 thread->t_data = NULL;
1713 * initialize per-thread page pool (bug 5137).
1715 static int ost_thread_init(struct ptlrpc_thread *thread)
1719 struct ost_thread_local_cache *tls;
1723 LASSERT(thread != NULL);
1724 LASSERT(thread->t_data == NULL);
1725 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
1730 thread->t_data = tls;
1734 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1735 OBD_PAGE_ALLOC(tls->page[i], OST_THREAD_POOL_GFP);
1736 if (tls->page[i] == NULL) {
1737 ost_thread_done(thread);
1747 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
1749 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
1750 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
1752 struct ost_obd *ost = &obd->u.ost;
1753 struct lprocfs_static_vars lvars;
1754 int oss_min_threads;
1755 int oss_max_threads;
1756 int oss_min_create_threads;
1757 int oss_max_create_threads;
1761 rc = cleanup_group_info();
1765 rc = llog_start_commit_thread();
1769 lprocfs_init_vars(ost, &lvars);
1770 lprocfs_obd_setup(obd, lvars.obd_vars);
1772 sema_init(&ost->ost_health_sem, 1);
1774 if (oss_num_threads) {
1775 /* If oss_num_threads is set, it is the min and the max. */
1776 if (oss_num_threads > OSS_THREADS_MAX)
1777 oss_num_threads = OSS_THREADS_MAX;
1778 if (oss_num_threads < OSS_THREADS_MIN)
1779 oss_num_threads = OSS_THREADS_MIN;
1780 oss_max_threads = oss_min_threads = oss_num_threads;
1782 /* Base min threads on memory and cpus */
1783 oss_min_threads = num_possible_cpus() * num_physpages >>
1784 (27 - CFS_PAGE_SHIFT);
1785 if (oss_min_threads < OSS_THREADS_MIN)
1786 oss_min_threads = OSS_THREADS_MIN;
1787 /* Insure a 4x range for dynamic threads */
1788 if (oss_min_threads > OSS_THREADS_MAX / 4)
1789 oss_min_threads = OSS_THREADS_MAX / 4;
1790 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4);
1794 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1795 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
1797 OST_WATCHDOG_TIMEOUT, ost_handle,
1798 LUSTRE_OSS_NAME, obd->obd_proc_entry,
1799 ost_print_req, oss_min_threads,
1800 oss_max_threads, "ll_ost",
1802 if (ost->ost_service == NULL) {
1803 CERROR("failed to start service\n");
1804 GOTO(out_lprocfs, rc = -ENOMEM);
1807 rc = ptlrpc_start_threads(obd, ost->ost_service);
1809 GOTO(out_service, rc = -EINVAL);
1811 if (oss_num_create_threads) {
1812 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
1813 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
1814 if (oss_num_create_threads < OSS_DEF_CREATE_THREADS)
1815 oss_num_create_threads = OSS_DEF_CREATE_THREADS;
1816 oss_min_create_threads = oss_max_create_threads =
1817 oss_num_create_threads;
1819 oss_min_create_threads = OSS_DEF_CREATE_THREADS;
1820 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
1823 ost->ost_create_service =
1824 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1825 OST_MAXREPSIZE, OST_CREATE_PORTAL,
1827 OST_WATCHDOG_TIMEOUT, ost_handle, "ost_create",
1828 obd->obd_proc_entry, ost_print_req,
1829 oss_min_create_threads,
1830 oss_max_create_threads,
1831 "ll_ost_creat", LCT_DT_THREAD);
1832 if (ost->ost_create_service == NULL) {
1833 CERROR("failed to start OST create service\n");
1834 GOTO(out_service, rc = -ENOMEM);
1837 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
1839 GOTO(out_create, rc = -EINVAL);
1841 ost->ost_io_service =
1842 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1843 OST_MAXREPSIZE, OST_IO_PORTAL,
1845 OST_WATCHDOG_TIMEOUT, ost_handle, "ost_io",
1846 obd->obd_proc_entry, ost_print_req,
1847 oss_min_threads, oss_max_threads,
1848 "ll_ost_io", LCT_DT_THREAD);
1849 if (ost->ost_io_service == NULL) {
1850 CERROR("failed to start OST I/O service\n");
1851 GOTO(out_create, rc = -ENOMEM);
1854 ost->ost_io_service->srv_init = ost_thread_init;
1855 ost->ost_io_service->srv_done = ost_thread_done;
1856 ost->ost_io_service->srv_cpu_affinity = 1;
1857 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
1859 GOTO(out_io, rc = -EINVAL);
1861 ping_evictor_start();
1866 ptlrpc_unregister_service(ost->ost_io_service);
1867 ost->ost_io_service = NULL;
1869 ptlrpc_unregister_service(ost->ost_create_service);
1870 ost->ost_create_service = NULL;
1872 ptlrpc_unregister_service(ost->ost_service);
1873 ost->ost_service = NULL;
1875 lprocfs_obd_cleanup(obd);
1879 static int ost_cleanup(struct obd_device *obd)
1881 struct ost_obd *ost = &obd->u.ost;
1885 ping_evictor_stop();
1887 spin_lock_bh(&obd->obd_processing_task_lock);
1888 if (obd->obd_recovering) {
1889 target_cancel_recovery_timer(obd);
1890 obd->obd_recovering = 0;
1892 spin_unlock_bh(&obd->obd_processing_task_lock);
1894 down(&ost->ost_health_sem);
1895 ptlrpc_unregister_service(ost->ost_service);
1896 ptlrpc_unregister_service(ost->ost_create_service);
1897 ptlrpc_unregister_service(ost->ost_io_service);
1898 ost->ost_service = NULL;
1899 ost->ost_create_service = NULL;
1900 up(&ost->ost_health_sem);
1902 lprocfs_obd_cleanup(obd);
1907 static int ost_health_check(struct obd_device *obd)
1909 struct ost_obd *ost = &obd->u.ost;
1912 down(&ost->ost_health_sem);
1913 rc |= ptlrpc_service_health_check(ost->ost_service);
1914 rc |= ptlrpc_service_health_check(ost->ost_create_service);
1915 rc |= ptlrpc_service_health_check(ost->ost_io_service);
1916 up(&ost->ost_health_sem);
1919 * health_check to return 0 on healthy
1920 * and 1 on unhealthy.
1928 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
1930 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
1933 /* use obd ops to offer management infrastructure */
1934 static struct obd_ops ost_obd_ops = {
1935 .o_owner = THIS_MODULE,
1936 .o_setup = ost_setup,
1937 .o_cleanup = ost_cleanup,
1938 .o_health_check = ost_health_check,
1942 static int __init ost_init(void)
1944 struct lprocfs_static_vars lvars;
1948 lprocfs_init_vars(ost, &lvars);
1949 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
1950 LUSTRE_OSS_NAME, NULL);
1952 if (ost_num_threads != 0 && oss_num_threads == 0) {
1953 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
1954 "use oss_num_threads instead or unset both for "
1955 "dynamic thread startup\n");
1956 oss_num_threads = ost_num_threads;
1962 static void /*__exit*/ ost_exit(void)
1964 class_unregister_type(LUSTRE_OSS_NAME);
1967 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1968 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
1969 MODULE_LICENSE("GPL");
1971 module_init(ost_init);
1972 module_exit(ost_exit);