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 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
64 struct oti_req_ack_lock *ack_lock;
71 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
72 req->rq_transno = oti->oti_transno;
74 /* XXX 4 == entries in oti_ack_locks??? */
75 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
78 /* XXX not even calling target_send_reply in some cases... */
79 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode);
83 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
84 struct obd_trans_info *oti)
86 struct ost_body *body, *repbody;
87 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
90 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
91 lustre_swab_ost_body);
95 if (lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1)) {
96 struct ldlm_request *dlm;
97 dlm = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*dlm),
98 lustre_swab_ldlm_request);
101 ldlm_request_cancel(req, dlm, 0);
104 rc = lustre_pack_reply(req, 2, size, NULL);
108 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
109 oti->oti_logcookies = obdo_logcookie(&body->oa);
110 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
112 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
113 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL);
117 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
119 struct ost_body *body, *repbody;
120 struct obd_info oinfo = { { { 0 } } };
121 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
124 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
125 lustre_swab_ost_body);
129 rc = lustre_pack_reply(req, 2, size, NULL);
133 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
135 repbody->oa = body->oa;
137 oinfo.oi_oa = &repbody->oa;
138 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
139 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
141 req->rq_status = obd_getattr(exp, &oinfo);
145 static int ost_statfs(struct ptlrpc_request *req)
147 struct obd_statfs *osfs;
148 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*osfs) };
151 rc = lustre_pack_reply(req, 2, size, NULL);
155 osfs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*osfs));
157 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
158 cfs_time_current_64() - HZ);
159 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
160 osfs->os_bfree = osfs->os_bavail = 64;
161 if (req->rq_status != 0)
162 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
167 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
168 struct obd_trans_info *oti)
170 struct ost_body *body, *repbody;
171 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
174 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
175 lustre_swab_ost_body);
179 rc = lustre_pack_reply(req, 2, size, NULL);
183 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
185 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
186 oti->oti_logcookies = obdo_logcookie(&repbody->oa);
187 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
188 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
193 * Helper function for ost_punch(): if asked by client, acquire [size, EOF]
194 * lock on the file being truncated.
196 static int ost_punch_lock_get(struct obd_export *exp, struct obdo *oa,
197 struct lustre_handle *lh)
200 struct ldlm_res_id res_id = { .name = { oa->o_id, 0, oa->o_gr, 0} };
201 ldlm_policy_data_t policy;
207 LASSERT(!lustre_handle_is_used(lh));
209 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
210 !(oa->o_flags & OBD_FL_TRUNCLOCK))
213 CDEBUG(D_INODE, "OST-side truncate lock.\n");
216 finis = start + oa->o_blocks;
219 * standard truncate optimization: if file body is completely
220 * destroyed, don't send data back to the server.
222 flags = (start == 0) ? LDLM_AST_DISCARD_DATA : 0;
224 policy.l_extent.start = start & CFS_PAGE_MASK;
227 * If ->o_blocks is EOF it means "lock till the end of the
228 * file". Otherwise, it's size of a hole being punched (in bytes)
230 if (oa->o_blocks == OBD_OBJECT_EOF || finis < start)
231 policy.l_extent.end = OBD_OBJECT_EOF;
233 policy.l_extent.end = finis | ~CFS_PAGE_MASK;
235 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
236 LDLM_EXTENT, &policy, LCK_PW, &flags,
237 ldlm_blocking_ast, ldlm_completion_ast,
238 ldlm_glimpse_ast, NULL, 0, NULL, lh));
242 * Helper function for ost_punch(): release lock acquired by
243 * ost_punch_lock_get(), if any.
245 static void ost_punch_lock_put(struct obd_export *exp, struct obdo *oa,
246 struct lustre_handle *lh)
249 if (lustre_handle_is_used(lh))
250 ldlm_lock_decref(lh, LCK_PW);
254 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
255 struct obd_trans_info *oti)
257 struct obd_info oinfo = { { { 0 } } };
258 struct ost_body *body, *repbody;
259 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
260 struct lustre_handle lh = {0,};
263 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
264 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
266 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
267 lustre_swab_ost_body);
271 oinfo.oi_oa = &body->oa;
272 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
273 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
275 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
276 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
279 rc = lustre_pack_reply(req, 2, size, NULL);
283 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
285 rc = ost_punch_lock_get(exp, oinfo.oi_oa, &lh);
287 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
288 oinfo.oi_oa->o_flags == OBD_FL_TRUNCLOCK)
290 * If OBD_FL_TRUNCLOCK is the only bit set in
291 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
292 * through filter_setattr() to filter_iocontrol().
294 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
296 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
297 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
299 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
300 ost_punch_lock_put(exp, oinfo.oi_oa, &lh);
302 repbody->oa = *oinfo.oi_oa;
306 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
308 struct ost_body *body, *repbody;
309 struct lustre_capa *capa = NULL;
310 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
313 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
314 lustre_swab_ost_body);
318 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
319 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 1);
321 rc = lustre_pack_reply(req, 2, size, NULL);
325 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
327 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
328 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
329 repbody->oa.o_blocks, capa);
333 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
334 struct obd_trans_info *oti)
336 struct ost_body *body, *repbody;
337 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
338 struct obd_info oinfo = { { { 0 } } };
341 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
342 lustre_swab_ost_body);
346 rc = lustre_pack_reply(req, 2, size, NULL);
350 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
352 repbody->oa = body->oa;
354 oinfo.oi_oa = &repbody->oa;
355 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
356 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
358 req->rq_status = obd_setattr(exp, &oinfo, oti);
362 static int ost_bulk_timeout(void *data)
365 /* We don't fail the connection here, because having the export
366 * killed makes the (vital) call to commitrw very sad.
371 static int get_per_page_niobufs(struct obd_ioobj *ioo, int nioo,
372 struct niobuf_remote *rnb, int nrnb,
373 struct niobuf_remote **pp_rnbp)
375 /* Copy a remote niobuf, splitting it into page-sized chunks
376 * and setting ioo[i].ioo_bufcnt accordingly */
377 struct niobuf_remote *pp_rnb;
385 * array of sufficient size already preallocated by caller
387 LASSERT(pp_rnbp != NULL);
388 LASSERT(*pp_rnbp != NULL);
390 /* first count and check the number of pages required */
391 for (i = 0; i < nioo; i++)
392 for (j = 0; j < ioo->ioo_bufcnt; j++, rnbidx++) {
393 obd_off offset = rnb[rnbidx].offset;
394 obd_off p0 = offset >> CFS_PAGE_SHIFT;
395 obd_off pn = (offset + rnb[rnbidx].len - 1) >>
398 LASSERT(rnbidx < nrnb);
400 npages += (pn + 1 - p0);
402 if (rnb[rnbidx].len == 0) {
403 CERROR("zero len BRW: obj %d objid "LPX64
404 " buf %u\n", i, ioo[i].ioo_id, j);
408 rnb[rnbidx].offset <= rnb[rnbidx-1].offset) {
409 CERROR("unordered BRW: obj %d objid "LPX64
410 " buf %u offset "LPX64" <= "LPX64"\n",
411 i, ioo[i].ioo_id, j, rnb[rnbidx].offset,
417 LASSERT(rnbidx == nrnb);
419 if (npages == nrnb) { /* all niobufs are for single pages */
426 /* now do the actual split */
428 for (i = 0; i < nioo; i++) {
431 for (j = 0; j < ioo[i].ioo_bufcnt; j++, rnbidx++) {
432 obd_off off = rnb[rnbidx].offset;
433 int nob = rnb[rnbidx].len;
435 LASSERT(rnbidx < nrnb);
437 obd_off poff = off & ~CFS_PAGE_MASK;
438 int pnob = (poff + nob > CFS_PAGE_SIZE) ?
439 PAGE_SIZE - poff : nob;
441 LASSERT(page < npages);
442 pp_rnb[page].len = pnob;
443 pp_rnb[page].offset = off;
444 pp_rnb[page].flags = rnb[rnbidx].flags;
446 CDEBUG(0, " obj %d id "LPX64
447 "page %d(%d) "LPX64" for %d, flg %x\n",
448 i, ioo[i].ioo_id, obj_pages, page,
449 pp_rnb[page].offset, pp_rnb[page].len,
459 ioo[i].ioo_bufcnt = obj_pages;
461 LASSERT(page == npages);
466 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc)
471 for (i = 0; i < desc->bd_iov_count; i++) {
472 struct page *page = desc->bd_iov[i].kiov_page;
473 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
474 char *ptr = kmap(page) + off;
475 int len = desc->bd_iov[i].kiov_len;
477 /* corrupt the data before we compute the checksum, to
478 * simulate a client->OST data error */
480 OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_CHECKSUM_RECEIVE))
481 memcpy(ptr, "bad3", min(4, len));
482 cksum = crc32_le(cksum, ptr, len);
483 /* corrupt the data after we compute the checksum, to
484 * simulate an OST->client data error */
485 if (i == 0 && OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_CHECKSUM_SEND))
486 memcpy(ptr, "bad4", min(4, len));
494 * populate @nio by @nrpages pages from per-thread page pool
496 static void ost_nio_pages_get(struct ptlrpc_request *req,
497 struct niobuf_local *nio, int nrpages)
500 struct ost_thread_local_cache *tls;
504 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
505 LASSERT(req != NULL);
506 LASSERT(req->rq_svc_thread != NULL);
509 LASSERT(tls != NULL);
511 memset(nio, 0, nrpages * sizeof *nio);
512 for (i = 0; i < nrpages; ++ i) {
516 LASSERT(page != NULL);
517 POISON_PAGE(page, 0xf1);
519 LL_CDEBUG_PAGE(D_INFO, page, "%d\n", i);
525 * Dual for ost_nio_pages_get(). Poison pages in pool for debugging
527 static void ost_nio_pages_put(struct ptlrpc_request *req,
528 struct niobuf_local *nio, int nrpages)
534 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
536 for (i = 0; i < nrpages; ++ i)
537 POISON_PAGE(nio[i].page, 0xf2);
541 static int ost_brw_lock_get(int mode, struct obd_export *exp,
542 struct obd_ioobj *obj, struct niobuf_remote *nb,
543 struct lustre_handle *lh)
546 int nrbufs = obj->ioo_bufcnt;
547 struct ldlm_res_id res_id = { .name = { obj->ioo_id, 0,
549 ldlm_policy_data_t policy;
554 LASSERT(mode == LCK_PR || mode == LCK_PW);
555 LASSERT(!lustre_handle_is_used(lh));
557 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
560 /* EXPENSIVE ASSERTION */
561 for (i = 1; i < nrbufs; i ++)
562 LASSERT((nb[0].flags & OBD_BRW_SRVLOCK) ==
563 (nb[i].flags & OBD_BRW_SRVLOCK));
565 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
566 policy.l_extent.end = (nb[nrbufs - 1].offset +
567 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
569 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
570 LDLM_EXTENT, &policy, mode, &flags,
571 ldlm_blocking_ast, ldlm_completion_ast,
572 ldlm_glimpse_ast, NULL, 0, NULL, lh));
575 static void ost_brw_lock_put(int mode,
576 struct obd_ioobj *obj, struct niobuf_remote *niob,
577 struct lustre_handle *lh)
580 LASSERT(mode == LCK_PR || mode == LCK_PW);
581 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
582 lustre_handle_is_used(lh));
583 if (lustre_handle_is_used(lh))
584 ldlm_lock_decref(lh, mode);
588 struct ost_prolong_data {
589 struct obd_export *opd_exp;
590 ldlm_policy_data_t opd_policy;
591 ldlm_mode_t opd_mode;
594 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
596 struct ost_prolong_data *opd = data;
598 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
600 if (lock->l_req_mode != lock->l_granted_mode) {
601 /* scan granted locks only */
602 return LDLM_ITER_STOP;
605 if (lock->l_export != opd->opd_exp) {
606 /* prolong locks only for given client */
607 return LDLM_ITER_CONTINUE;
610 if (!(lock->l_granted_mode & opd->opd_mode)) {
611 /* we aren't interesting in all type of locks */
612 return LDLM_ITER_CONTINUE;
615 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
616 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
617 /* the request doesn't cross the lock, skip it */
618 return LDLM_ITER_CONTINUE;
621 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
622 /* ignore locks not being cancelled */
623 return LDLM_ITER_CONTINUE;
626 /* OK. this is a possible lock the user holds doing I/O
627 * let's refresh eviction timer for it */
628 ldlm_refresh_waiting_lock(lock);
630 return LDLM_ITER_CONTINUE;
633 static void ost_prolong_locks(struct obd_export *exp, struct obd_ioobj *obj,
634 struct niobuf_remote *nb, ldlm_mode_t mode)
636 struct ldlm_res_id res_id = { .name = { obj->ioo_id, 0,
638 int nrbufs = obj->ioo_bufcnt;
639 struct ost_prolong_data opd;
645 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
646 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
647 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
649 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
650 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
651 opd.opd_policy.l_extent.end);
652 ldlm_resource_iterate(exp->exp_obd->obd_namespace, &res_id,
653 ost_prolong_locks_iter, &opd);
656 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
658 struct ptlrpc_bulk_desc *desc;
659 struct niobuf_remote *remote_nb;
660 struct niobuf_remote *pp_rnb = NULL;
661 struct niobuf_local *local_nb;
662 struct obd_ioobj *ioo;
663 struct ost_body *body, *repbody;
664 struct lustre_capa *capa = NULL;
665 struct l_wait_info lwi;
666 struct lustre_handle lockh = { 0 };
667 int size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
668 int comms_error = 0, niocount, npages, nob = 0, rc, i;
672 req->rq_bulk_read = 1;
674 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
675 GOTO(out, rc = -EIO);
677 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
678 (obd_timeout + 1) / 4);
680 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
681 lustre_swab_ost_body);
683 CERROR("Missing/short ost_body\n");
684 GOTO(out, rc = -EFAULT);
687 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*ioo),
688 lustre_swab_obd_ioobj);
690 CERROR("Missing/short ioobj\n");
691 GOTO(out, rc = -EFAULT);
694 niocount = ioo->ioo_bufcnt;
695 if (niocount > PTLRPC_MAX_BRW_PAGES) {
696 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
698 GOTO(out, rc = -EFAULT);
701 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
702 niocount * sizeof(*remote_nb),
703 lustre_swab_niobuf_remote);
704 if (remote_nb == NULL) {
705 CERROR("Missing/short niobuf\n");
706 GOTO(out, rc = -EFAULT);
708 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
709 for (i = 1; i < niocount; i++)
710 lustre_swab_niobuf_remote (&remote_nb[i]);
713 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
714 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
716 rc = lustre_pack_reply(req, 2, size, NULL);
721 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
724 local_nb = ost_tls(req)->local;
725 pp_rnb = ost_tls(req)->remote;
727 /* FIXME all niobuf splitting should be done in obdfilter if needed */
728 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
729 npages = get_per_page_niobufs(ioo, 1, remote_nb, niocount, &pp_rnb);
731 GOTO(out, rc = npages);
733 LASSERT(npages <= OST_THREAD_POOL_SIZE);
735 ost_nio_pages_get(req, local_nb, npages);
737 desc = ptlrpc_prep_bulk_exp(req, npages,
738 BULK_PUT_SOURCE, OST_BULK_PORTAL);
740 GOTO(out, rc = -ENOMEM);
742 rc = ost_brw_lock_get(LCK_PR, req->rq_export, ioo, pp_rnb, &lockh);
747 * If getting the lock took more time than
748 * client was willing to wait, drop it. b=11330
750 if (cfs_time_current_sec() > req->rq_arrival_time.tv_sec + obd_timeout ||
751 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
753 CERROR("Dropping timed-out read from %s because locking"
754 "object "LPX64" took %ld seconds.\n",
755 libcfs_id2str(req->rq_peer), ioo->ioo_id,
756 cfs_time_current_sec() - req->rq_arrival_time.tv_sec);
760 rc = obd_preprw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
761 ioo, npages, pp_rnb, local_nb, oti, capa);
765 ost_prolong_locks(req->rq_export, ioo, pp_rnb, LCK_PW | LCK_PR);
768 for (i = 0; i < npages; i++) {
769 int page_rc = local_nb[i].rc;
771 if (page_rc < 0) { /* error */
776 LASSERTF(page_rc <= pp_rnb[i].len, "page_rc (%d) > "
777 "pp_rnb[%d].len (%d)\n", page_rc, i, pp_rnb[i].len);
779 if (page_rc != 0) { /* some data! */
780 LASSERT (local_nb[i].page != NULL);
781 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
782 pp_rnb[i].offset & ~CFS_PAGE_MASK,
786 if (page_rc != pp_rnb[i].len) { /* short read */
787 /* All subsequent pages should be 0 */
789 LASSERT(local_nb[i].rc == 0);
794 if (unlikely(body->oa.o_valid & OBD_MD_FLCKSUM)) {
795 body->oa.o_cksum = ost_checksum_bulk(desc);
796 body->oa.o_valid = OBD_MD_FLCKSUM;
797 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
799 body->oa.o_valid = 0;
801 /* We're finishing using body->oa as an input variable */
803 /* Check if client was evicted while we were doing i/o before touching
806 if (desc->bd_export->exp_failed)
809 sptlrpc_svc_wrap_bulk(req, desc);
811 rc = ptlrpc_start_bulk_transfer(desc);
815 lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 4, HZ,
816 ost_bulk_timeout, desc);
817 rc = l_wait_event(desc->bd_waitq,
818 !ptlrpc_bulk_active(desc) ||
819 desc->bd_export->exp_failed, &lwi);
820 LASSERT(rc == 0 || rc == -ETIMEDOUT);
821 if (rc == -ETIMEDOUT) {
822 DEBUG_REQ(D_ERROR, req, "timeout on bulk PUT");
823 ptlrpc_abort_bulk(desc);
824 } else if (desc->bd_export->exp_failed) {
825 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
827 ptlrpc_abort_bulk(desc);
828 } else if (!desc->bd_success ||
829 desc->bd_nob_transferred != desc->bd_nob) {
830 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
832 "truncated" : "network error on",
833 desc->bd_nob_transferred,
835 /* XXX should this be a different errno? */
839 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
841 comms_error = rc != 0;
844 /* Must commit after prep above in all cases */
845 rc = obd_commitrw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
846 ioo, npages, local_nb, oti, rc);
848 ost_nio_pages_put(req, local_nb, npages);
851 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
853 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
857 ost_brw_lock_put(LCK_PR, ioo, pp_rnb, &lockh);
859 ptlrpc_free_bulk(desc);
865 req->rq_status = nob;
866 target_committed_to_req(req);
868 } else if (!comms_error) {
869 /* Only reply if there was no comms problem with bulk */
870 target_committed_to_req(req);
874 if (req->rq_reply_state != NULL) {
875 /* reply out callback would free */
876 ptlrpc_rs_decref(req->rq_reply_state);
877 req->rq_reply_state = NULL;
879 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
880 "client will retry\n",
881 req->rq_export->exp_obd->obd_name,
882 req->rq_export->exp_client_uuid.uuid,
883 req->rq_export->exp_connection->c_remote_uuid.uuid,
884 libcfs_id2str(req->rq_peer));
890 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
892 struct ptlrpc_bulk_desc *desc;
893 struct niobuf_remote *remote_nb;
894 struct niobuf_remote *pp_rnb;
895 struct niobuf_local *local_nb;
896 struct obd_ioobj *ioo;
897 struct ost_body *body, *repbody;
898 struct l_wait_info lwi;
899 struct lustre_handle lockh = {0};
900 struct lustre_capa *capa = NULL;
902 int size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
903 int objcount, niocount, npages, comms_error = 0;
905 obd_count client_cksum, server_cksum = 0;
909 req->rq_bulk_write = 1;
911 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
912 GOTO(out, rc = -EIO);
914 /* pause before transaction has been started */
915 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
916 (obd_timeout + 1) / 4);
918 swab = lustre_msg_swabbed(req->rq_reqmsg);
919 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
920 lustre_swab_ost_body);
922 CERROR("Missing/short ost_body\n");
923 GOTO(out, rc = -EFAULT);
926 LASSERT_REQSWAB(req, REQ_REC_OFF + 1);
927 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
930 CERROR("Missing/short ioobj\n");
931 GOTO(out, rc = -EFAULT);
934 CERROR("too many ioobjs (%d)\n", objcount);
935 GOTO(out, rc = -EFAULT);
938 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
939 objcount * sizeof(*ioo));
940 LASSERT (ioo != NULL);
941 for (niocount = i = 0; i < objcount; i++) {
943 lustre_swab_obd_ioobj(&ioo[i]);
944 if (ioo[i].ioo_bufcnt == 0) {
945 CERROR("ioo[%d] has zero bufcnt\n", i);
946 GOTO(out, rc = -EFAULT);
948 niocount += ioo[i].ioo_bufcnt;
951 if (niocount > PTLRPC_MAX_BRW_PAGES) {
952 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
954 GOTO(out, rc = -EFAULT);
957 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
958 niocount * sizeof(*remote_nb),
959 lustre_swab_niobuf_remote);
960 if (remote_nb == NULL) {
961 CERROR("Missing/short niobuf\n");
962 GOTO(out, rc = -EFAULT);
964 if (swab) { /* swab the remaining niobufs */
965 for (i = 1; i < niocount; i++)
966 lustre_swab_niobuf_remote (&remote_nb[i]);
969 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
970 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
972 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
973 rc = lustre_pack_reply(req, 3, size, NULL);
976 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
977 niocount * sizeof(*rcs));
980 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
983 local_nb = ost_tls(req)->local;
984 pp_rnb = ost_tls(req)->remote;
986 /* FIXME all niobuf splitting should be done in obdfilter if needed */
987 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
988 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
990 GOTO(out, rc = npages);
992 LASSERT(npages <= OST_THREAD_POOL_SIZE);
994 ost_nio_pages_get(req, local_nb, npages);
996 desc = ptlrpc_prep_bulk_exp(req, npages,
997 BULK_GET_SINK, OST_BULK_PORTAL);
999 GOTO(out, rc = -ENOMEM);
1001 rc = ost_brw_lock_get(LCK_PW, req->rq_export, ioo, pp_rnb, &lockh);
1006 * If getting the lock took more time than
1007 * client was willing to wait, drop it. b=11330
1009 if (cfs_time_current_sec() > req->rq_arrival_time.tv_sec + obd_timeout ||
1010 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
1012 CERROR("Dropping timed-out write from %s because locking"
1013 "object "LPX64" took %ld seconds.\n",
1014 libcfs_id2str(req->rq_peer), ioo->ioo_id,
1015 cfs_time_current_sec() - req->rq_arrival_time.tv_sec);
1019 ost_prolong_locks(req->rq_export, ioo, pp_rnb, LCK_PW);
1021 /* obd_preprw clobbers oa->valid, so save what we need */
1022 client_cksum = body->oa.o_valid & OBD_MD_FLCKSUM ? body->oa.o_cksum : 0;
1024 /* Because we already sync grant info with client when reconnect,
1025 * grant info will be cleared for resent req, then fed_grant and
1026 * total_grant will not be modified in following preprw_write */
1027 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1028 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info\n");
1029 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1032 rc = obd_preprw(OBD_BRW_WRITE, req->rq_export, &body->oa, objcount,
1033 ioo, npages, pp_rnb, local_nb, oti, capa);
1037 /* NB Having prepped, we must commit... */
1039 for (i = 0; i < npages; i++)
1040 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1041 pp_rnb[i].offset & ~CFS_PAGE_MASK,
1044 /* Check if client was evicted while we were doing i/o before touching
1046 if (desc->bd_export->exp_failed)
1049 rc = ptlrpc_start_bulk_transfer (desc);
1051 lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 2, HZ,
1052 ost_bulk_timeout, desc);
1053 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1054 desc->bd_export->exp_failed, &lwi);
1055 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1056 if (rc == -ETIMEDOUT) {
1057 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1058 ptlrpc_abort_bulk(desc);
1059 } else if (desc->bd_export->exp_failed) {
1060 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1062 ptlrpc_abort_bulk(desc);
1063 } else if (!desc->bd_success ||
1064 desc->bd_nob_transferred != desc->bd_nob) {
1065 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1067 "truncated" : "network error on",
1068 desc->bd_nob_transferred, desc->bd_nob);
1069 /* XXX should this be a different errno? */
1073 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1075 comms_error = rc != 0;
1077 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1079 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1081 if (unlikely(client_cksum != 0 && rc == 0)) {
1082 static int cksum_counter;
1083 server_cksum = ost_checksum_bulk(desc);
1084 repbody->oa.o_valid |= OBD_MD_FLCKSUM;
1085 repbody->oa.o_cksum = server_cksum;
1087 if (unlikely(client_cksum != server_cksum)) {
1088 CERROR("client csum %x, server csum %x\n",
1089 client_cksum, server_cksum);
1091 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1092 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1093 cksum_counter, libcfs_id2str(req->rq_peer),
1098 sptlrpc_svc_unwrap_bulk(req, desc);
1100 /* Must commit after prep above in all cases */
1101 rc = obd_commitrw(OBD_BRW_WRITE, req->rq_export, &repbody->oa,
1102 objcount, ioo, npages, local_nb, oti, rc);
1104 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1105 int new_cksum = ost_checksum_bulk(desc);
1110 if (new_cksum == server_cksum)
1111 msg = "changed in transit before arrival at OST";
1112 else if (new_cksum == client_cksum)
1113 msg = "initial checksum before message complete";
1115 msg = "changed in transit AND after initial checksum";
1117 if (req->rq_peer.nid == desc->bd_sender) {
1121 router = libcfs_nid2str(desc->bd_sender);
1124 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1125 "%s%s%s inum "LPU64"/"LPU64" object "
1126 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1127 req->rq_export->exp_obd->obd_name, msg,
1128 libcfs_id2str(req->rq_peer),
1130 body->oa.o_valid & OBD_MD_FLFID ?
1131 body->oa.o_fid : (__u64)0,
1132 body->oa.o_valid & OBD_MD_FLFID ?
1133 body->oa.o_generation :(__u64)0,
1135 body->oa.o_valid & OBD_MD_FLGROUP ?
1136 body->oa.o_gr : (__u64)0,
1138 pp_rnb[npages-1].offset+pp_rnb[npages-1].len
1140 CERROR("client csum %x, original server csum %x, "
1141 "server csum now %x\n",
1142 client_cksum, server_cksum, new_cksum);
1145 ost_nio_pages_put(req, local_nb, npages);
1148 /* set per-requested niobuf return codes */
1149 for (i = j = 0; i < niocount; i++) {
1150 int nob = remote_nb[i].len;
1154 LASSERT(j < npages);
1155 if (local_nb[j].rc < 0)
1156 rcs[i] = local_nb[j].rc;
1157 nob -= pp_rnb[j].len;
1162 LASSERT(j == npages);
1166 ost_brw_lock_put(LCK_PW, ioo, pp_rnb, &lockh);
1168 ptlrpc_free_bulk(desc);
1173 oti_to_request(oti, req);
1174 target_committed_to_req(req);
1175 rc = ptlrpc_reply(req);
1176 } else if (!comms_error) {
1177 /* Only reply if there was no comms problem with bulk */
1178 target_committed_to_req(req);
1179 req->rq_status = rc;
1182 if (req->rq_reply_state != NULL) {
1183 /* reply out callback would free */
1184 ptlrpc_rs_decref(req->rq_reply_state);
1185 req->rq_reply_state = NULL;
1187 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1188 "client will retry\n",
1189 req->rq_export->exp_obd->obd_name,
1190 req->rq_export->exp_client_uuid.uuid,
1191 req->rq_export->exp_connection->c_remote_uuid.uuid,
1192 libcfs_id2str(req->rq_peer));
1197 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1199 char *key, *val = NULL;
1200 int keylen, vallen, rc = 0;
1203 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1205 DEBUG_REQ(D_HA, req, "no set_info key");
1208 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1210 rc = lustre_pack_reply(req, 1, NULL, NULL);
1214 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1216 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
1218 if (KEY_IS("evict_by_nid")) {
1220 obd_export_evict_by_nid(exp->exp_obd, val);
1225 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1227 lustre_msg_set_status(req->rq_repmsg, 0);
1231 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1235 int size[2] = { sizeof(struct ptlrpc_body), sizeof(obd_id) };
1239 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1241 DEBUG_REQ(D_HA, req, "no get_info key");
1244 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1246 if (keylen < strlen("last_id") || memcmp(key, "last_id", 7) != 0)
1249 rc = lustre_pack_reply(req, 2, size, NULL);
1253 reply = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*reply));
1254 rc = obd_get_info(exp, keylen, key, size, reply);
1255 lustre_msg_set_status(req->rq_repmsg, 0);
1259 static int ost_handle_quotactl(struct ptlrpc_request *req)
1261 struct obd_quotactl *oqctl, *repoqc;
1262 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) };
1265 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1266 lustre_swab_obd_quotactl);
1268 GOTO(out, rc = -EPROTO);
1270 rc = lustre_pack_reply(req, 2, size, NULL);
1274 repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc));
1276 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1282 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1284 struct obd_quotactl *oqctl;
1288 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1289 lustre_swab_obd_quotactl);
1293 rc = lustre_pack_reply(req, 1, NULL, NULL);
1295 CERROR("ost: out of memory while packing quotacheck reply\n");
1299 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1303 static int ost_llog_handle_connect(struct obd_export *exp,
1304 struct ptlrpc_request *req)
1306 struct llogd_conn_body *body;
1310 body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body));
1311 rc = obd_llog_connect(exp, body);
1316 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1317 struct obd_device *obd, int *process)
1319 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1320 case OST_CONNECT: /* This will never get here, but for completeness. */
1321 case OST_DISCONNECT:
1332 case OBD_LOG_CANCEL:
1334 *process = target_queue_recovery_request(req, obd);
1338 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1344 int ost_msg_check_version(struct lustre_msg *msg)
1348 switch(lustre_msg_get_opc(msg)) {
1350 case OST_DISCONNECT:
1353 case SEC_CTX_INIT_CONT:
1355 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1357 CERROR("bad opc %u version %08x, expecting %08x\n",
1358 lustre_msg_get_opc(msg),
1359 lustre_msg_get_version(msg),
1360 LUSTRE_OBD_VERSION);
1373 case OST_QUOTACHECK:
1375 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1377 CERROR("bad opc %u version %08x, expecting %08x\n",
1378 lustre_msg_get_opc(msg),
1379 lustre_msg_get_version(msg),
1380 LUSTRE_OST_VERSION);
1385 case LDLM_BL_CALLBACK:
1386 case LDLM_CP_CALLBACK:
1387 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1389 CERROR("bad opc %u version %08x, expecting %08x\n",
1390 lustre_msg_get_opc(msg),
1391 lustre_msg_get_version(msg),
1392 LUSTRE_DLM_VERSION);
1394 case LLOG_ORIGIN_CONNECT:
1395 case OBD_LOG_CANCEL:
1396 rc = lustre_msg_check_version(msg, LUSTRE_LOG_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_LOG_VERSION);
1404 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1410 int ost_handle(struct ptlrpc_request *req)
1412 struct obd_trans_info trans_info = { 0, };
1413 struct obd_trans_info *oti = &trans_info;
1414 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1415 struct obd_device *obd = NULL;
1418 LASSERT(current->journal_info == NULL);
1420 /* primordial rpcs don't affect server recovery */
1421 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1423 case SEC_CTX_INIT_CONT:
1428 /* XXX identical to MDS */
1429 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1432 if (req->rq_export == NULL) {
1433 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1434 lustre_msg_get_opc(req->rq_reqmsg),
1435 libcfs_id2str(req->rq_peer));
1436 req->rq_status = -ENOTCONN;
1437 GOTO(out, rc = -ENOTCONN);
1440 obd = req->rq_export->exp_obd;
1442 /* Check for aborted recovery. */
1443 spin_lock_bh(&obd->obd_processing_task_lock);
1444 recovering = obd->obd_recovering;
1445 spin_unlock_bh(&obd->obd_processing_task_lock);
1447 rc = ost_filter_recovery_request(req, obd,
1449 if (rc || !should_process)
1451 else if (should_process < 0) {
1452 req->rq_status = should_process;
1453 rc = ptlrpc_error(req);
1461 rc = ost_msg_check_version(req->rq_reqmsg);
1465 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1467 CDEBUG(D_INODE, "connect\n");
1468 OBD_FAIL_RETURN(OBD_FAIL_OST_CONNECT_NET, 0);
1469 rc = target_handle_connect(req);
1471 obd = req->rq_export->exp_obd;
1474 case OST_DISCONNECT:
1475 CDEBUG(D_INODE, "disconnect\n");
1476 OBD_FAIL_RETURN(OBD_FAIL_OST_DISCONNECT_NET, 0);
1477 rc = target_handle_disconnect(req);
1480 CDEBUG(D_INODE, "create\n");
1481 OBD_FAIL_RETURN(OBD_FAIL_OST_CREATE_NET, 0);
1482 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
1483 GOTO(out, rc = -ENOSPC);
1484 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1485 GOTO(out, rc = -EROFS);
1486 rc = ost_create(req->rq_export, req, oti);
1489 CDEBUG(D_INODE, "destroy\n");
1490 OBD_FAIL_RETURN(OBD_FAIL_OST_DESTROY_NET, 0);
1491 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1492 GOTO(out, rc = -EROFS);
1493 rc = ost_destroy(req->rq_export, req, oti);
1496 CDEBUG(D_INODE, "getattr\n");
1497 OBD_FAIL_RETURN(OBD_FAIL_OST_GETATTR_NET, 0);
1498 rc = ost_getattr(req->rq_export, req);
1501 CDEBUG(D_INODE, "setattr\n");
1502 OBD_FAIL_RETURN(OBD_FAIL_OST_SETATTR_NET, 0);
1503 rc = ost_setattr(req->rq_export, req, oti);
1506 CDEBUG(D_INODE, "write\n");
1507 /* req->rq_request_portal would be nice, if it was set */
1508 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1509 CERROR("%s: deny write request from %s to portal %u\n",
1510 req->rq_export->exp_obd->obd_name,
1511 obd_export_nid2str(req->rq_export),
1512 req->rq_rqbd->rqbd_service->srv_req_portal);
1513 GOTO(out, rc = -EPROTO);
1515 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1516 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
1517 GOTO(out, rc = -ENOSPC);
1518 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1519 GOTO(out, rc = -EROFS);
1520 rc = ost_brw_write(req, oti);
1521 LASSERT(current->journal_info == NULL);
1522 /* ost_brw_write sends its own replies */
1525 CDEBUG(D_INODE, "read\n");
1526 /* req->rq_request_portal would be nice, if it was set */
1527 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1528 CERROR("%s: deny read request from %s to portal %u\n",
1529 req->rq_export->exp_obd->obd_name,
1530 obd_export_nid2str(req->rq_export),
1531 req->rq_rqbd->rqbd_service->srv_req_portal);
1532 GOTO(out, rc = -EPROTO);
1534 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1535 rc = ost_brw_read(req, oti);
1536 LASSERT(current->journal_info == NULL);
1537 /* ost_brw_read sends its own replies */
1540 CDEBUG(D_INODE, "punch\n");
1541 OBD_FAIL_RETURN(OBD_FAIL_OST_PUNCH_NET, 0);
1542 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1543 GOTO(out, rc = -EROFS);
1544 rc = ost_punch(req->rq_export, req, oti);
1547 CDEBUG(D_INODE, "statfs\n");
1548 OBD_FAIL_RETURN(OBD_FAIL_OST_STATFS_NET, 0);
1549 rc = ost_statfs(req);
1552 CDEBUG(D_INODE, "sync\n");
1553 OBD_FAIL_RETURN(OBD_FAIL_OST_SYNC_NET, 0);
1554 rc = ost_sync(req->rq_export, req);
1557 DEBUG_REQ(D_INODE, req, "set_info");
1558 rc = ost_set_info(req->rq_export, req);
1561 DEBUG_REQ(D_INODE, req, "get_info");
1562 rc = ost_get_info(req->rq_export, req);
1564 case OST_QUOTACHECK:
1565 CDEBUG(D_INODE, "quotacheck\n");
1566 OBD_FAIL_RETURN(OBD_FAIL_OST_QUOTACHECK_NET, 0);
1567 rc = ost_handle_quotacheck(req);
1570 CDEBUG(D_INODE, "quotactl\n");
1571 OBD_FAIL_RETURN(OBD_FAIL_OST_QUOTACTL_NET, 0);
1572 rc = ost_handle_quotactl(req);
1575 DEBUG_REQ(D_INODE, req, "ping");
1576 rc = target_handle_ping(req);
1578 /* FIXME - just reply status */
1579 case LLOG_ORIGIN_CONNECT:
1580 DEBUG_REQ(D_INODE, req, "log connect");
1581 rc = ost_llog_handle_connect(req->rq_export, req);
1582 req->rq_status = rc;
1583 rc = lustre_pack_reply(req, 1, NULL, NULL);
1586 RETURN(ptlrpc_reply(req));
1587 case OBD_LOG_CANCEL:
1588 CDEBUG(D_INODE, "log cancel\n");
1589 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
1590 rc = llog_origin_handle_cancel(req);
1591 req->rq_status = rc;
1592 rc = lustre_pack_reply(req, 1, NULL, NULL);
1595 RETURN(ptlrpc_reply(req));
1597 CDEBUG(D_INODE, "enqueue\n");
1598 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
1599 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1600 ldlm_server_blocking_ast,
1601 ldlm_server_glimpse_ast);
1602 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1605 CDEBUG(D_INODE, "convert\n");
1606 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
1607 rc = ldlm_handle_convert(req);
1610 CDEBUG(D_INODE, "cancel\n");
1611 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CANCEL, 0);
1612 rc = ldlm_handle_cancel(req);
1614 case LDLM_BL_CALLBACK:
1615 case LDLM_CP_CALLBACK:
1616 CDEBUG(D_INODE, "callback\n");
1617 CERROR("callbacks should not happen on OST\n");
1620 CERROR("Unexpected opcode %d\n",
1621 lustre_msg_get_opc(req->rq_reqmsg));
1622 req->rq_status = -ENOTSUPP;
1623 rc = ptlrpc_error(req);
1627 LASSERT(current->journal_info == NULL);
1630 /* If we're DISCONNECTing, the export_data is already freed */
1631 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
1632 target_committed_to_req(req);
1636 oti_to_request(oti, req);
1638 target_send_reply(req, rc, fail);
1641 EXPORT_SYMBOL(ost_handle);
1643 * free per-thread pool created by ost_thread_init().
1645 static void ost_thread_done(struct ptlrpc_thread *thread)
1648 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
1653 LASSERT(thread != NULL);
1656 * be prepared to handle partially-initialized pools (because this is
1657 * called from ost_thread_init() for cleanup.
1659 tls = thread->t_data;
1661 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1662 if (tls->page[i] != NULL)
1663 __cfs_free_page(tls->page[i]);
1666 thread->t_data = NULL;
1672 * initialize per-thread page pool (bug 5137).
1674 static int ost_thread_init(struct ptlrpc_thread *thread)
1678 struct ost_thread_local_cache *tls;
1682 LASSERT(thread != NULL);
1683 LASSERT(thread->t_data == NULL);
1684 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
1689 thread->t_data = tls;
1693 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1694 tls->page[i] = cfs_alloc_page(OST_THREAD_POOL_GFP);
1695 if (tls->page[i] == NULL) {
1696 ost_thread_done(thread);
1706 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
1708 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
1709 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
1711 struct ost_obd *ost = &obd->u.ost;
1712 struct lprocfs_static_vars lvars;
1713 int oss_min_threads;
1714 int oss_max_threads;
1718 rc = cleanup_group_info();
1722 rc = llog_start_commit_thread();
1726 lprocfs_init_vars(ost, &lvars);
1727 lprocfs_obd_setup(obd, lvars.obd_vars);
1729 sema_init(&ost->ost_health_sem, 1);
1731 if (oss_num_threads) {
1732 /* If oss_num_threads is set, it is the min and the max. */
1733 if (oss_num_threads > OSS_THREADS_MAX)
1734 oss_num_threads = OSS_THREADS_MAX;
1735 if (oss_num_threads < OSS_THREADS_MIN)
1736 oss_num_threads = OSS_THREADS_MIN;
1737 oss_max_threads = oss_min_threads = oss_num_threads;
1739 /* Base min threads on memory and cpus */
1740 oss_min_threads = smp_num_cpus * num_physpages >>
1741 (27 - CFS_PAGE_SHIFT);
1742 if (oss_min_threads < OSS_THREADS_MIN)
1743 oss_min_threads = OSS_THREADS_MIN;
1744 /* Insure a 4x range for dynamic threads */
1745 if (oss_min_threads > OSS_THREADS_MAX / 4)
1746 oss_min_threads = OSS_THREADS_MAX / 4;
1747 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4);
1751 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1752 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
1754 OST_WATCHDOG_TIMEOUT, ost_handle,
1755 LUSTRE_OSS_NAME, obd->obd_proc_entry,
1756 ost_print_req, oss_min_threads,
1757 oss_max_threads, "ll_ost",
1759 if (ost->ost_service == NULL) {
1760 CERROR("failed to start service\n");
1761 GOTO(out_lprocfs, rc = -ENOMEM);
1764 rc = ptlrpc_start_threads(obd, ost->ost_service);
1766 GOTO(out_service, rc = -EINVAL);
1768 ost->ost_create_service =
1769 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1770 OST_MAXREPSIZE, OST_CREATE_PORTAL,
1772 OST_WATCHDOG_TIMEOUT, ost_handle, "ost_create",
1773 obd->obd_proc_entry, ost_print_req, 1, 1,
1774 "ll_ost_creat", LCT_DT_THREAD);
1775 if (ost->ost_create_service == NULL) {
1776 CERROR("failed to start OST create service\n");
1777 GOTO(out_service, rc = -ENOMEM);
1780 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
1782 GOTO(out_create, rc = -EINVAL);
1784 ost->ost_io_service =
1785 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1786 OST_MAXREPSIZE, OST_IO_PORTAL,
1788 OST_WATCHDOG_TIMEOUT, ost_handle, "ost_io",
1789 obd->obd_proc_entry, ost_print_req,
1790 oss_min_threads, oss_max_threads,
1791 "ll_ost_io", LCT_DT_THREAD);
1792 if (ost->ost_io_service == NULL) {
1793 CERROR("failed to start OST I/O service\n");
1794 GOTO(out_create, rc = -ENOMEM);
1797 ost->ost_io_service->srv_init = ost_thread_init;
1798 ost->ost_io_service->srv_done = ost_thread_done;
1799 ost->ost_io_service->srv_cpu_affinity = 1;
1800 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
1802 GOTO(out_io, rc = -EINVAL);
1804 ping_evictor_start();
1809 ptlrpc_unregister_service(ost->ost_io_service);
1810 ost->ost_io_service = NULL;
1812 ptlrpc_unregister_service(ost->ost_create_service);
1813 ost->ost_create_service = NULL;
1815 ptlrpc_unregister_service(ost->ost_service);
1816 ost->ost_service = NULL;
1818 lprocfs_obd_cleanup(obd);
1822 static int ost_cleanup(struct obd_device *obd)
1824 struct ost_obd *ost = &obd->u.ost;
1828 ping_evictor_stop();
1830 spin_lock_bh(&obd->obd_processing_task_lock);
1831 if (obd->obd_recovering) {
1832 target_cancel_recovery_timer(obd);
1833 obd->obd_recovering = 0;
1835 spin_unlock_bh(&obd->obd_processing_task_lock);
1837 down(&ost->ost_health_sem);
1838 ptlrpc_unregister_service(ost->ost_service);
1839 ptlrpc_unregister_service(ost->ost_create_service);
1840 ptlrpc_unregister_service(ost->ost_io_service);
1841 ost->ost_service = NULL;
1842 ost->ost_create_service = NULL;
1843 up(&ost->ost_health_sem);
1845 lprocfs_obd_cleanup(obd);
1850 static int ost_health_check(struct obd_device *obd)
1852 struct ost_obd *ost = &obd->u.ost;
1855 down(&ost->ost_health_sem);
1856 rc |= ptlrpc_service_health_check(ost->ost_service);
1857 rc |= ptlrpc_service_health_check(ost->ost_create_service);
1858 rc |= ptlrpc_service_health_check(ost->ost_io_service);
1859 up(&ost->ost_health_sem);
1862 * health_check to return 0 on healthy
1863 * and 1 on unhealthy.
1871 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
1873 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
1876 /* use obd ops to offer management infrastructure */
1877 static struct obd_ops ost_obd_ops = {
1878 .o_owner = THIS_MODULE,
1879 .o_setup = ost_setup,
1880 .o_cleanup = ost_cleanup,
1881 .o_health_check = ost_health_check,
1885 static int __init ost_init(void)
1887 struct lprocfs_static_vars lvars;
1891 lprocfs_init_vars(ost, &lvars);
1892 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
1893 LUSTRE_OSS_NAME, NULL);
1895 if (ost_num_threads != 0 && oss_num_threads == 0) {
1896 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
1897 "use oss_num_threads instead or unset both for "
1898 "dynamic thread startup\n");
1899 oss_num_threads = ost_num_threads;
1905 static void /*__exit*/ ost_exit(void)
1907 class_unregister_type(LUSTRE_OSS_NAME);
1910 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1911 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
1912 MODULE_LICENSE("GPL");
1914 module_init(ost_init);
1915 module_exit(ost_exit);