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 (body->oa.o_id == 0)
102 if (lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1)) {
103 struct ldlm_request *dlm;
104 dlm = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*dlm),
105 lustre_swab_ldlm_request);
108 ldlm_request_cancel(req, dlm, 0);
111 rc = lustre_pack_reply(req, 2, size, NULL);
115 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
116 oti->oti_logcookies = obdo_logcookie(&body->oa);
117 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
119 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
120 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL);
124 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
126 struct ost_body *body, *repbody;
127 struct obd_info oinfo = { { { 0 } } };
128 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
131 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
132 lustre_swab_ost_body);
136 rc = lustre_pack_reply(req, 2, size, NULL);
140 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
142 repbody->oa = body->oa;
144 oinfo.oi_oa = &repbody->oa;
145 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
146 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
148 req->rq_status = obd_getattr(exp, &oinfo);
152 static int ost_statfs(struct ptlrpc_request *req)
154 struct obd_statfs *osfs;
155 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*osfs) };
158 rc = lustre_pack_reply(req, 2, size, NULL);
162 osfs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*osfs));
164 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
165 cfs_time_current_64() - HZ);
166 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
167 osfs->os_bfree = osfs->os_bavail = 64;
168 if (req->rq_status != 0)
169 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
174 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
175 struct obd_trans_info *oti)
177 struct ost_body *body, *repbody;
178 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
181 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
182 lustre_swab_ost_body);
186 rc = lustre_pack_reply(req, 2, size, NULL);
190 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
192 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
193 oti->oti_logcookies = obdo_logcookie(&repbody->oa);
194 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
195 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
200 * Helper function for ost_punch(): if asked by client, acquire [size, EOF]
201 * lock on the file being truncated.
203 static int ost_punch_lock_get(struct obd_export *exp, struct obdo *oa,
204 struct lustre_handle *lh)
207 struct ldlm_res_id res_id = { .name = { oa->o_id, 0, oa->o_gr, 0} };
208 ldlm_policy_data_t policy;
214 LASSERT(!lustre_handle_is_used(lh));
216 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
217 !(oa->o_flags & OBD_FL_TRUNCLOCK))
220 CDEBUG(D_INODE, "OST-side truncate lock.\n");
223 finis = start + oa->o_blocks;
226 * standard truncate optimization: if file body is completely
227 * destroyed, don't send data back to the server.
229 flags = (start == 0) ? LDLM_AST_DISCARD_DATA : 0;
231 policy.l_extent.start = start & CFS_PAGE_MASK;
234 * If ->o_blocks is EOF it means "lock till the end of the
235 * file". Otherwise, it's size of a hole being punched (in bytes)
237 if (oa->o_blocks == OBD_OBJECT_EOF || finis < start)
238 policy.l_extent.end = OBD_OBJECT_EOF;
240 policy.l_extent.end = finis | ~CFS_PAGE_MASK;
242 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
243 LDLM_EXTENT, &policy, LCK_PW, &flags,
244 ldlm_blocking_ast, ldlm_completion_ast,
245 ldlm_glimpse_ast, NULL, 0, NULL, lh));
249 * Helper function for ost_punch(): release lock acquired by
250 * ost_punch_lock_get(), if any.
252 static void ost_punch_lock_put(struct obd_export *exp, struct obdo *oa,
253 struct lustre_handle *lh)
256 if (lustre_handle_is_used(lh))
257 ldlm_lock_decref(lh, LCK_PW);
261 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
262 struct obd_trans_info *oti)
264 struct obd_info oinfo = { { { 0 } } };
265 struct ost_body *body, *repbody;
266 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
267 struct lustre_handle lh = {0,};
270 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
271 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
273 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
274 lustre_swab_ost_body);
278 oinfo.oi_oa = &body->oa;
279 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
280 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
282 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
283 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
286 rc = lustre_pack_reply(req, 2, size, NULL);
290 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
292 rc = ost_punch_lock_get(exp, oinfo.oi_oa, &lh);
294 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
295 oinfo.oi_oa->o_flags == OBD_FL_TRUNCLOCK)
297 * If OBD_FL_TRUNCLOCK is the only bit set in
298 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
299 * through filter_setattr() to filter_iocontrol().
301 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
303 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
304 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
306 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
307 ost_punch_lock_put(exp, oinfo.oi_oa, &lh);
309 repbody->oa = *oinfo.oi_oa;
313 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
315 struct ost_body *body, *repbody;
316 struct lustre_capa *capa = NULL;
317 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
320 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
321 lustre_swab_ost_body);
325 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
326 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 1);
328 rc = lustre_pack_reply(req, 2, size, NULL);
332 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
334 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
335 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
336 repbody->oa.o_blocks, capa);
340 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
341 struct obd_trans_info *oti)
343 struct ost_body *body, *repbody;
344 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
345 struct obd_info oinfo = { { { 0 } } };
348 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
349 lustre_swab_ost_body);
353 rc = lustre_pack_reply(req, 2, size, NULL);
357 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
359 repbody->oa = body->oa;
361 oinfo.oi_oa = &repbody->oa;
362 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
363 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
365 req->rq_status = obd_setattr(exp, &oinfo, oti);
369 static int ost_bulk_timeout(void *data)
372 /* We don't fail the connection here, because having the export
373 * killed makes the (vital) call to commitrw very sad.
378 static int get_per_page_niobufs(struct obd_ioobj *ioo, int nioo,
379 struct niobuf_remote *rnb, int nrnb,
380 struct niobuf_remote **pp_rnbp)
382 /* Copy a remote niobuf, splitting it into page-sized chunks
383 * and setting ioo[i].ioo_bufcnt accordingly */
384 struct niobuf_remote *pp_rnb;
392 * array of sufficient size already preallocated by caller
394 LASSERT(pp_rnbp != NULL);
395 LASSERT(*pp_rnbp != NULL);
397 /* first count and check the number of pages required */
398 for (i = 0; i < nioo; i++)
399 for (j = 0; j < ioo->ioo_bufcnt; j++, rnbidx++) {
400 obd_off offset = rnb[rnbidx].offset;
401 obd_off p0 = offset >> CFS_PAGE_SHIFT;
402 obd_off pn = (offset + rnb[rnbidx].len - 1) >>
405 LASSERT(rnbidx < nrnb);
407 npages += (pn + 1 - p0);
409 if (rnb[rnbidx].len == 0) {
410 CERROR("zero len BRW: obj %d objid "LPX64
411 " buf %u\n", i, ioo[i].ioo_id, j);
415 rnb[rnbidx].offset <= rnb[rnbidx-1].offset) {
416 CERROR("unordered BRW: obj %d objid "LPX64
417 " buf %u offset "LPX64" <= "LPX64"\n",
418 i, ioo[i].ioo_id, j, rnb[rnbidx].offset,
424 LASSERT(rnbidx == nrnb);
426 if (npages == nrnb) { /* all niobufs are for single pages */
433 /* now do the actual split */
435 for (i = 0; i < nioo; i++) {
438 for (j = 0; j < ioo[i].ioo_bufcnt; j++, rnbidx++) {
439 obd_off off = rnb[rnbidx].offset;
440 int nob = rnb[rnbidx].len;
442 LASSERT(rnbidx < nrnb);
444 obd_off poff = off & ~CFS_PAGE_MASK;
445 int pnob = (poff + nob > CFS_PAGE_SIZE) ?
446 PAGE_SIZE - poff : nob;
448 LASSERT(page < npages);
449 pp_rnb[page].len = pnob;
450 pp_rnb[page].offset = off;
451 pp_rnb[page].flags = rnb[rnbidx].flags;
453 CDEBUG(0, " obj %d id "LPX64
454 "page %d(%d) "LPX64" for %d, flg %x\n",
455 i, ioo[i].ioo_id, obj_pages, page,
456 pp_rnb[page].offset, pp_rnb[page].len,
466 ioo[i].ioo_bufcnt = obj_pages;
468 LASSERT(page == npages);
473 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc)
478 for (i = 0; i < desc->bd_iov_count; i++) {
479 struct page *page = desc->bd_iov[i].kiov_page;
480 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
481 char *ptr = kmap(page) + off;
482 int len = desc->bd_iov[i].kiov_len;
484 /* corrupt the data before we compute the checksum, to
485 * simulate a client->OST data error */
486 if (i == 0 && opc == OST_WRITE &&
487 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
488 memcpy(ptr, "bad3", min(4, len));
489 cksum = crc32_le(cksum, ptr, len);
490 /* corrupt the data after we compute the checksum, to
491 * simulate an OST->client data error */
492 if (i == 0 && opc == OST_READ &&
493 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND))
494 memcpy(ptr, "bad4", min(4, len));
502 * populate @nio by @nrpages pages from per-thread page pool
504 static void ost_nio_pages_get(struct ptlrpc_request *req,
505 struct niobuf_local *nio, int nrpages)
508 struct ost_thread_local_cache *tls;
512 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
513 LASSERT(req != NULL);
514 LASSERT(req->rq_svc_thread != NULL);
517 LASSERT(tls != NULL);
519 memset(nio, 0, nrpages * sizeof *nio);
520 for (i = 0; i < nrpages; ++ i) {
524 LASSERT(page != NULL);
525 POISON_PAGE(page, 0xf1);
527 LL_CDEBUG_PAGE(D_INFO, page, "%d\n", i);
533 * Dual for ost_nio_pages_get(). Poison pages in pool for debugging
535 static void ost_nio_pages_put(struct ptlrpc_request *req,
536 struct niobuf_local *nio, int nrpages)
542 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
544 for (i = 0; i < nrpages; ++ i)
545 POISON_PAGE(nio[i].page, 0xf2);
549 static int ost_brw_lock_get(int mode, struct obd_export *exp,
550 struct obd_ioobj *obj, struct niobuf_remote *nb,
551 struct lustre_handle *lh)
554 int nrbufs = obj->ioo_bufcnt;
555 struct ldlm_res_id res_id = { .name = { obj->ioo_id, 0,
557 ldlm_policy_data_t policy;
562 LASSERT(mode == LCK_PR || mode == LCK_PW);
563 LASSERT(!lustre_handle_is_used(lh));
565 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
568 /* EXPENSIVE ASSERTION */
569 for (i = 1; i < nrbufs; i ++)
570 LASSERT((nb[0].flags & OBD_BRW_SRVLOCK) ==
571 (nb[i].flags & OBD_BRW_SRVLOCK));
573 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
574 policy.l_extent.end = (nb[nrbufs - 1].offset +
575 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
577 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
578 LDLM_EXTENT, &policy, mode, &flags,
579 ldlm_blocking_ast, ldlm_completion_ast,
580 ldlm_glimpse_ast, NULL, 0, NULL, lh));
583 static void ost_brw_lock_put(int mode,
584 struct obd_ioobj *obj, struct niobuf_remote *niob,
585 struct lustre_handle *lh)
588 LASSERT(mode == LCK_PR || mode == LCK_PW);
589 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
590 lustre_handle_is_used(lh));
591 if (lustre_handle_is_used(lh))
592 ldlm_lock_decref(lh, mode);
596 struct ost_prolong_data {
597 struct obd_export *opd_exp;
598 ldlm_policy_data_t opd_policy;
599 ldlm_mode_t opd_mode;
602 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
604 struct ost_prolong_data *opd = data;
606 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
608 if (lock->l_req_mode != lock->l_granted_mode) {
609 /* scan granted locks only */
610 return LDLM_ITER_STOP;
613 if (lock->l_export != opd->opd_exp) {
614 /* prolong locks only for given client */
615 return LDLM_ITER_CONTINUE;
618 if (!(lock->l_granted_mode & opd->opd_mode)) {
619 /* we aren't interesting in all type of locks */
620 return LDLM_ITER_CONTINUE;
623 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
624 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
625 /* the request doesn't cross the lock, skip it */
626 return LDLM_ITER_CONTINUE;
629 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
630 /* ignore locks not being cancelled */
631 return LDLM_ITER_CONTINUE;
634 /* OK. this is a possible lock the user holds doing I/O
635 * let's refresh eviction timer for it */
636 ldlm_refresh_waiting_lock(lock);
638 return LDLM_ITER_CONTINUE;
641 static void ost_prolong_locks(struct obd_export *exp, struct obd_ioobj *obj,
642 struct niobuf_remote *nb, ldlm_mode_t mode)
644 struct ldlm_res_id res_id = { .name = { obj->ioo_id, 0,
646 int nrbufs = obj->ioo_bufcnt;
647 struct ost_prolong_data opd;
653 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
654 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
655 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
657 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
658 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
659 opd.opd_policy.l_extent.end);
660 ldlm_resource_iterate(exp->exp_obd->obd_namespace, &res_id,
661 ost_prolong_locks_iter, &opd);
664 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
666 struct ptlrpc_bulk_desc *desc;
667 struct obd_export *exp = req->rq_export;
668 struct niobuf_remote *remote_nb;
669 struct niobuf_remote *pp_rnb = NULL;
670 struct niobuf_local *local_nb;
671 struct obd_ioobj *ioo;
672 struct ost_body *body, *repbody;
673 struct lustre_capa *capa = NULL;
674 struct l_wait_info lwi;
675 struct lustre_handle lockh = { 0 };
676 int size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
677 int niocount, npages, nob = 0, rc, i;
681 req->rq_bulk_read = 1;
683 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
684 GOTO(out, rc = -EIO);
686 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
688 /* Check if there is eviction in progress, and if so, wait for it to
690 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
691 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
692 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
693 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
697 GOTO(out, rc = -ENOTCONN);
699 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
700 lustre_swab_ost_body);
702 CERROR("Missing/short ost_body\n");
703 GOTO(out, rc = -EFAULT);
706 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*ioo),
707 lustre_swab_obd_ioobj);
709 CERROR("Missing/short ioobj\n");
710 GOTO(out, rc = -EFAULT);
713 niocount = ioo->ioo_bufcnt;
714 if (niocount > PTLRPC_MAX_BRW_PAGES) {
715 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
717 GOTO(out, rc = -EFAULT);
720 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
721 niocount * sizeof(*remote_nb),
722 lustre_swab_niobuf_remote);
723 if (remote_nb == NULL) {
724 CERROR("Missing/short niobuf\n");
725 GOTO(out, rc = -EFAULT);
727 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
728 for (i = 1; i < niocount; i++)
729 lustre_swab_niobuf_remote (&remote_nb[i]);
732 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
733 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
735 rc = lustre_pack_reply(req, 2, size, NULL);
740 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
743 local_nb = ost_tls(req)->local;
744 pp_rnb = ost_tls(req)->remote;
746 /* FIXME all niobuf splitting should be done in obdfilter if needed */
747 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
748 npages = get_per_page_niobufs(ioo, 1, remote_nb, niocount, &pp_rnb);
750 GOTO(out, rc = npages);
752 LASSERT(npages <= OST_THREAD_POOL_SIZE);
754 ost_nio_pages_get(req, local_nb, npages);
756 desc = ptlrpc_prep_bulk_exp(req, npages,
757 BULK_PUT_SOURCE, OST_BULK_PORTAL);
759 GOTO(out, rc = -ENOMEM);
761 rc = ost_brw_lock_get(LCK_PR, exp, ioo, pp_rnb, &lockh);
766 * If getting the lock took more time than
767 * client was willing to wait, drop it. b=11330
769 if (cfs_time_current_sec() > req->rq_arrival_time.tv_sec + obd_timeout ||
770 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
772 CERROR("Dropping timed-out read from %s because locking"
773 "object "LPX64" took %ld seconds.\n",
774 libcfs_id2str(req->rq_peer), ioo->ioo_id,
775 cfs_time_current_sec() - req->rq_arrival_time.tv_sec);
776 GOTO(out_lock, rc = -ETIMEDOUT);
779 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1,
780 ioo, npages, pp_rnb, local_nb, oti, capa);
784 ost_prolong_locks(exp, ioo, pp_rnb, LCK_PW | LCK_PR);
787 for (i = 0; i < npages; i++) {
788 int page_rc = local_nb[i].rc;
790 if (page_rc < 0) { /* error */
795 LASSERTF(page_rc <= pp_rnb[i].len, "page_rc (%d) > "
796 "pp_rnb[%d].len (%d)\n", page_rc, i, pp_rnb[i].len);
798 if (page_rc != 0) { /* some data! */
799 LASSERT (local_nb[i].page != NULL);
800 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
801 pp_rnb[i].offset & ~CFS_PAGE_MASK,
805 if (page_rc != pp_rnb[i].len) { /* short read */
806 /* All subsequent pages should be 0 */
808 LASSERT(local_nb[i].rc == 0);
813 if (unlikely(body->oa.o_valid & OBD_MD_FLCKSUM)) {
814 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ);
815 body->oa.o_valid = OBD_MD_FLCKSUM;
816 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
818 body->oa.o_valid = 0;
820 /* We're finishing using body->oa as an input variable */
822 /* Check if client was evicted while we were doing i/o before touching
825 /* Check if there is eviction in progress, and if so, wait for
827 if (unlikely(atomic_read(&exp->exp_obd->
828 obd_evict_inprogress))) {
829 lwi = LWI_INTR(NULL, NULL);
830 rc = l_wait_event(exp->exp_obd->
831 obd_evict_inprogress_waitq,
832 !atomic_read(&exp->exp_obd->
833 obd_evict_inprogress),
839 sptlrpc_svc_wrap_bulk(req, desc);
841 rc = ptlrpc_start_bulk_transfer(desc);
845 lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 4, HZ,
846 ost_bulk_timeout, desc);
847 rc = l_wait_event(desc->bd_waitq,
848 !ptlrpc_bulk_active(desc) ||
849 exp->exp_failed, &lwi);
850 LASSERT(rc == 0 || rc == -ETIMEDOUT);
851 if (rc == -ETIMEDOUT) {
852 DEBUG_REQ(D_ERROR, req, "timeout on bulk PUT");
853 ptlrpc_abort_bulk(desc);
854 } else if (exp->exp_failed) {
855 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
857 ptlrpc_abort_bulk(desc);
858 } else if (!desc->bd_success ||
859 desc->bd_nob_transferred != desc->bd_nob) {
860 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
862 "truncated" : "network error on",
863 desc->bd_nob_transferred,
865 /* XXX should this be a different errno? */
869 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
874 /* Must commit after prep above in all cases */
875 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1,
876 ioo, npages, local_nb, oti, rc);
878 ost_nio_pages_put(req, local_nb, npages);
881 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
883 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
887 ost_brw_lock_put(LCK_PR, ioo, pp_rnb, &lockh);
889 ptlrpc_free_bulk(desc);
893 req->rq_status = nob;
894 target_committed_to_req(req);
896 } else if (!no_reply) {
897 /* Only reply if there was no comms problem with bulk */
898 target_committed_to_req(req);
902 if (req->rq_reply_state != NULL) {
903 /* reply out callback would free */
904 ptlrpc_rs_decref(req->rq_reply_state);
905 req->rq_reply_state = NULL;
907 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
908 "client will retry\n",
909 exp->exp_obd->obd_name,
910 exp->exp_client_uuid.uuid,
911 exp->exp_connection->c_remote_uuid.uuid,
912 libcfs_id2str(req->rq_peer));
918 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
920 struct ptlrpc_bulk_desc *desc;
921 struct obd_export *exp = req->rq_export;
922 struct niobuf_remote *remote_nb;
923 struct niobuf_remote *pp_rnb;
924 struct niobuf_local *local_nb;
925 struct obd_ioobj *ioo;
926 struct ost_body *body, *repbody;
927 struct l_wait_info lwi;
928 struct lustre_handle lockh = {0};
929 struct lustre_capa *capa = NULL;
931 int size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
932 int objcount, niocount, npages;
934 obd_count client_cksum, server_cksum = 0;
938 req->rq_bulk_write = 1;
940 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
941 GOTO(out, rc = -EIO);
942 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
943 GOTO(out, rc = -EFAULT);
945 /* pause before transaction has been started */
946 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
948 /* Check if there is eviction in progress, and if so, wait for it to
950 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
951 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
952 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
953 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
957 GOTO(out, rc = -ENOTCONN);
959 swab = lustre_msg_swabbed(req->rq_reqmsg);
960 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
961 lustre_swab_ost_body);
963 CERROR("Missing/short ost_body\n");
964 GOTO(out, rc = -EFAULT);
967 lustre_set_req_swabbed(req, REQ_REC_OFF + 1);
968 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
971 CERROR("Missing/short ioobj\n");
972 GOTO(out, rc = -EFAULT);
975 CERROR("too many ioobjs (%d)\n", objcount);
976 GOTO(out, rc = -EFAULT);
979 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
980 objcount * sizeof(*ioo));
981 LASSERT (ioo != NULL);
982 for (niocount = i = 0; i < objcount; i++) {
984 lustre_swab_obd_ioobj(&ioo[i]);
985 if (ioo[i].ioo_bufcnt == 0) {
986 CERROR("ioo[%d] has zero bufcnt\n", i);
987 GOTO(out, rc = -EFAULT);
989 niocount += ioo[i].ioo_bufcnt;
992 if (niocount > PTLRPC_MAX_BRW_PAGES) {
993 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
995 GOTO(out, rc = -EFAULT);
998 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
999 niocount * sizeof(*remote_nb),
1000 lustre_swab_niobuf_remote);
1001 if (remote_nb == NULL) {
1002 CERROR("Missing/short niobuf\n");
1003 GOTO(out, rc = -EFAULT);
1005 if (swab) { /* swab the remaining niobufs */
1006 for (i = 1; i < niocount; i++)
1007 lustre_swab_niobuf_remote (&remote_nb[i]);
1010 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
1011 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
1013 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
1014 rc = lustre_pack_reply(req, 3, size, NULL);
1017 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
1018 niocount * sizeof(*rcs));
1021 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
1022 * ost_thread_init().
1024 local_nb = ost_tls(req)->local;
1025 pp_rnb = ost_tls(req)->remote;
1027 /* FIXME all niobuf splitting should be done in obdfilter if needed */
1028 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
1029 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
1031 GOTO(out, rc = npages);
1033 LASSERT(npages <= OST_THREAD_POOL_SIZE);
1035 ost_nio_pages_get(req, local_nb, npages);
1037 desc = ptlrpc_prep_bulk_exp(req, npages,
1038 BULK_GET_SINK, OST_BULK_PORTAL);
1040 GOTO(out, rc = -ENOMEM);
1042 rc = ost_brw_lock_get(LCK_PW, exp, ioo, pp_rnb, &lockh);
1047 * If getting the lock took more time than
1048 * client was willing to wait, drop it. b=11330
1050 if (cfs_time_current_sec() > req->rq_arrival_time.tv_sec + obd_timeout ||
1051 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
1053 CERROR("Dropping timed-out write from %s because locking"
1054 "object "LPX64" took %ld seconds.\n",
1055 libcfs_id2str(req->rq_peer), ioo->ioo_id,
1056 cfs_time_current_sec() - req->rq_arrival_time.tv_sec);
1057 GOTO(out_lock, rc = -ETIMEDOUT);
1060 ost_prolong_locks(exp, ioo, pp_rnb, LCK_PW);
1062 /* obd_preprw clobbers oa->valid, so save what we need */
1063 client_cksum = body->oa.o_valid & OBD_MD_FLCKSUM ? body->oa.o_cksum : 0;
1065 /* Because we already sync grant info with client when reconnect,
1066 * grant info will be cleared for resent req, then fed_grant and
1067 * total_grant will not be modified in following preprw_write */
1068 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1069 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1070 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1073 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
1074 ioo, npages, pp_rnb, local_nb, oti, capa);
1078 /* NB Having prepped, we must commit... */
1080 for (i = 0; i < npages; i++)
1081 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1082 pp_rnb[i].offset & ~CFS_PAGE_MASK,
1085 /* Check if client was evicted while we were doing i/o before touching
1087 if (desc->bd_export->exp_failed)
1090 rc = ptlrpc_start_bulk_transfer (desc);
1092 lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 2, HZ,
1093 ost_bulk_timeout, desc);
1094 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1095 desc->bd_export->exp_failed, &lwi);
1096 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1097 if (rc == -ETIMEDOUT) {
1098 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1099 ptlrpc_abort_bulk(desc);
1100 } else if (desc->bd_export->exp_failed) {
1101 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1103 ptlrpc_abort_bulk(desc);
1104 } else if (!desc->bd_success ||
1105 desc->bd_nob_transferred != desc->bd_nob) {
1106 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1108 "truncated" : "network error on",
1109 desc->bd_nob_transferred, desc->bd_nob);
1110 /* XXX should this be a different errno? */
1114 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1119 sptlrpc_svc_unwrap_bulk(req, desc);
1121 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1123 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1125 if (unlikely(client_cksum != 0 && rc == 0)) {
1126 static int cksum_counter;
1127 server_cksum = ost_checksum_bulk(desc, OST_WRITE);
1128 repbody->oa.o_valid |= OBD_MD_FLCKSUM;
1129 repbody->oa.o_cksum = server_cksum;
1131 if (unlikely(client_cksum != server_cksum)) {
1132 CERROR("client csum %x, server csum %x\n",
1133 client_cksum, server_cksum);
1135 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1136 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1137 cksum_counter, libcfs_id2str(req->rq_peer),
1142 /* Must commit after prep above in all cases */
1143 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa,
1144 objcount, ioo, npages, local_nb, oti, rc);
1146 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1147 int new_cksum = ost_checksum_bulk(desc, OST_WRITE);
1152 if (new_cksum == server_cksum)
1153 msg = "changed in transit before arrival at OST";
1154 else if (new_cksum == client_cksum)
1155 msg = "initial checksum before message complete";
1157 msg = "changed in transit AND after initial checksum";
1159 if (req->rq_peer.nid == desc->bd_sender) {
1163 router = libcfs_nid2str(desc->bd_sender);
1166 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1167 "%s%s%s inum "LPU64"/"LPU64" object "
1168 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1169 exp->exp_obd->obd_name, msg,
1170 libcfs_id2str(req->rq_peer),
1172 body->oa.o_valid & OBD_MD_FLFID ?
1173 body->oa.o_fid : (__u64)0,
1174 body->oa.o_valid & OBD_MD_FLFID ?
1175 body->oa.o_generation :(__u64)0,
1177 body->oa.o_valid & OBD_MD_FLGROUP ?
1178 body->oa.o_gr : (__u64)0,
1180 pp_rnb[npages-1].offset+pp_rnb[npages-1].len
1182 CERROR("client csum %x, original server csum %x, "
1183 "server csum now %x\n",
1184 client_cksum, server_cksum, new_cksum);
1187 ost_nio_pages_put(req, local_nb, npages);
1190 /* set per-requested niobuf return codes */
1191 for (i = j = 0; i < niocount; i++) {
1192 int nob = remote_nb[i].len;
1196 LASSERT(j < npages);
1197 if (local_nb[j].rc < 0)
1198 rcs[i] = local_nb[j].rc;
1199 nob -= pp_rnb[j].len;
1204 LASSERT(j == npages);
1208 ost_brw_lock_put(LCK_PW, ioo, pp_rnb, &lockh);
1210 ptlrpc_free_bulk(desc);
1213 oti_to_request(oti, req);
1214 target_committed_to_req(req);
1215 rc = ptlrpc_reply(req);
1216 } else if (!no_reply) {
1217 /* Only reply if there was no comms problem with bulk */
1218 target_committed_to_req(req);
1219 req->rq_status = rc;
1222 if (req->rq_reply_state != NULL) {
1223 /* reply out callback would free */
1224 ptlrpc_rs_decref(req->rq_reply_state);
1225 req->rq_reply_state = NULL;
1227 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1228 "client will retry\n",
1229 exp->exp_obd->obd_name,
1230 exp->exp_client_uuid.uuid,
1231 exp->exp_connection->c_remote_uuid.uuid,
1232 libcfs_id2str(req->rq_peer));
1237 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1239 char *key, *val = NULL;
1240 int keylen, vallen, rc = 0;
1243 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1245 DEBUG_REQ(D_HA, req, "no set_info key");
1248 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1250 rc = lustre_pack_reply(req, 1, NULL, NULL);
1254 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1256 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
1258 if (KEY_IS("evict_by_nid")) {
1260 obd_export_evict_by_nid(exp->exp_obd, val);
1265 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1267 lustre_msg_set_status(req->rq_repmsg, 0);
1271 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1274 int keylen, replylen, rc = 0;
1275 struct req_capsule *pill = &req->rq_pill;
1278 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
1280 /* this common part for get_info rpc */
1281 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1283 DEBUG_REQ(D_HA, req, "no get_info key");
1286 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1288 rc = obd_get_info(exp, keylen, key, &replylen, NULL);
1292 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1293 RCL_SERVER, replylen);
1295 rc = req_capsule_server_pack(pill);
1299 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1303 /* call again to fill in the reply buffer */
1304 rc = obd_get_info(exp, keylen, key, &replylen, reply);
1306 lustre_msg_set_status(req->rq_repmsg, 0);
1310 static int ost_handle_quotactl(struct ptlrpc_request *req)
1312 struct obd_quotactl *oqctl, *repoqc;
1313 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) };
1316 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1317 lustre_swab_obd_quotactl);
1319 GOTO(out, rc = -EPROTO);
1321 rc = lustre_pack_reply(req, 2, size, NULL);
1325 repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc));
1327 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1333 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1335 struct obd_quotactl *oqctl;
1339 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1343 rc = req_capsule_server_pack(&req->rq_pill);
1345 CERROR("ost: out of memory while packing quotacheck reply\n");
1349 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1353 static int ost_llog_handle_connect(struct obd_export *exp,
1354 struct ptlrpc_request *req)
1356 struct llogd_conn_body *body;
1360 body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body));
1361 rc = obd_llog_connect(exp, body);
1365 static int filter_export_check_flavor(struct filter_obd *filter,
1366 struct obd_export *exp,
1367 struct ptlrpc_request *req)
1372 * this should be done in filter_connect()/filter_reconnect(), but
1373 * we can't obtain information like NID, which stored in incoming
1374 * request, thus can't decide what flavor to use. so we do it here.
1376 * This hack should be removed after the OST stack be rewritten, just
1377 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1379 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_INVALID)
1382 CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from));
1383 spin_lock(&exp->exp_lock);
1384 exp->exp_sp_peer = req->rq_sp_from;
1386 read_lock(&filter->fo_sptlrpc_lock);
1387 sptlrpc_rule_set_choose(&filter->fo_sptlrpc_rset, exp->exp_sp_peer,
1388 req->rq_peer.nid, &exp->exp_flvr);
1389 read_unlock(&filter->fo_sptlrpc_lock);
1391 if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1392 CERROR("invalid rpc flavor %x, expect %x, from %s\n",
1393 req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
1394 libcfs_nid2str(req->rq_peer.nid));
1395 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID;
1399 spin_unlock(&exp->exp_lock);
1404 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1405 struct obd_device *obd, int *process)
1407 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1408 case OST_CONNECT: /* This will never get here, but for completeness. */
1409 case OST_DISCONNECT:
1420 case OBD_LOG_CANCEL:
1422 *process = target_queue_recovery_request(req, obd);
1426 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1432 int ost_msg_check_version(struct lustre_msg *msg)
1436 switch(lustre_msg_get_opc(msg)) {
1438 case OST_DISCONNECT:
1441 case SEC_CTX_INIT_CONT:
1443 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1445 CERROR("bad opc %u version %08x, expecting %08x\n",
1446 lustre_msg_get_opc(msg),
1447 lustre_msg_get_version(msg),
1448 LUSTRE_OBD_VERSION);
1461 case OST_QUOTACHECK:
1463 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1465 CERROR("bad opc %u version %08x, expecting %08x\n",
1466 lustre_msg_get_opc(msg),
1467 lustre_msg_get_version(msg),
1468 LUSTRE_OST_VERSION);
1473 case LDLM_BL_CALLBACK:
1474 case LDLM_CP_CALLBACK:
1475 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1477 CERROR("bad opc %u version %08x, expecting %08x\n",
1478 lustre_msg_get_opc(msg),
1479 lustre_msg_get_version(msg),
1480 LUSTRE_DLM_VERSION);
1482 case LLOG_ORIGIN_CONNECT:
1483 case OBD_LOG_CANCEL:
1484 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1486 CERROR("bad opc %u version %08x, expecting %08x\n",
1487 lustre_msg_get_opc(msg),
1488 lustre_msg_get_version(msg),
1489 LUSTRE_LOG_VERSION);
1492 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1498 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1499 int ost_handle(struct ptlrpc_request *req)
1501 struct obd_trans_info trans_info = { 0, };
1502 struct obd_trans_info *oti = &trans_info;
1503 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1504 struct obd_device *obd = NULL;
1507 LASSERT(current->journal_info == NULL);
1509 /* primordial rpcs don't affect server recovery */
1510 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1512 case SEC_CTX_INIT_CONT:
1517 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1519 /* XXX identical to MDS */
1520 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1523 if (req->rq_export == NULL) {
1524 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1525 lustre_msg_get_opc(req->rq_reqmsg),
1526 libcfs_id2str(req->rq_peer));
1527 req->rq_status = -ENOTCONN;
1528 GOTO(out, rc = -ENOTCONN);
1531 obd = req->rq_export->exp_obd;
1533 /* Check for aborted recovery. */
1534 spin_lock_bh(&obd->obd_processing_task_lock);
1535 recovering = obd->obd_recovering;
1536 spin_unlock_bh(&obd->obd_processing_task_lock);
1538 rc = ost_filter_recovery_request(req, obd,
1540 if (rc || !should_process)
1542 else if (should_process < 0) {
1543 req->rq_status = should_process;
1544 rc = ptlrpc_error(req);
1552 rc = ost_msg_check_version(req->rq_reqmsg);
1556 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1558 CDEBUG(D_INODE, "connect\n");
1559 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
1560 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
1562 rc = target_handle_connect(req);
1563 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
1566 struct obd_export *exp = req->rq_export;
1570 rc = filter_export_check_flavor(&obd->u.filter,
1575 case OST_DISCONNECT:
1576 CDEBUG(D_INODE, "disconnect\n");
1577 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
1578 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
1580 rc = target_handle_disconnect(req);
1583 CDEBUG(D_INODE, "create\n");
1584 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
1586 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1587 GOTO(out, rc = -ENOSPC);
1588 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1589 GOTO(out, rc = -EROFS);
1590 rc = ost_create(req->rq_export, req, oti);
1593 CDEBUG(D_INODE, "destroy\n");
1594 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
1596 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1597 GOTO(out, rc = -EROFS);
1598 rc = ost_destroy(req->rq_export, req, oti);
1601 CDEBUG(D_INODE, "getattr\n");
1602 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
1604 rc = ost_getattr(req->rq_export, req);
1607 CDEBUG(D_INODE, "setattr\n");
1608 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
1610 rc = ost_setattr(req->rq_export, req, oti);
1613 CDEBUG(D_INODE, "write\n");
1614 /* req->rq_request_portal would be nice, if it was set */
1615 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1616 CERROR("%s: deny write request from %s to portal %u\n",
1617 req->rq_export->exp_obd->obd_name,
1618 obd_export_nid2str(req->rq_export),
1619 req->rq_rqbd->rqbd_service->srv_req_portal);
1620 GOTO(out, rc = -EPROTO);
1622 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1624 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1625 GOTO(out, rc = -ENOSPC);
1626 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1627 GOTO(out, rc = -EROFS);
1628 rc = ost_brw_write(req, oti);
1629 LASSERT(current->journal_info == NULL);
1630 /* ost_brw_write sends its own replies */
1633 CDEBUG(D_INODE, "read\n");
1634 /* req->rq_request_portal would be nice, if it was set */
1635 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1636 CERROR("%s: deny read request from %s to portal %u\n",
1637 req->rq_export->exp_obd->obd_name,
1638 obd_export_nid2str(req->rq_export),
1639 req->rq_rqbd->rqbd_service->srv_req_portal);
1640 GOTO(out, rc = -EPROTO);
1642 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1644 rc = ost_brw_read(req, oti);
1645 LASSERT(current->journal_info == NULL);
1646 /* ost_brw_read sends its own replies */
1649 CDEBUG(D_INODE, "punch\n");
1650 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
1652 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1653 GOTO(out, rc = -EROFS);
1654 rc = ost_punch(req->rq_export, req, oti);
1657 CDEBUG(D_INODE, "statfs\n");
1658 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
1660 rc = ost_statfs(req);
1663 CDEBUG(D_INODE, "sync\n");
1664 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
1666 rc = ost_sync(req->rq_export, req);
1669 DEBUG_REQ(D_INODE, req, "set_info");
1670 req_capsule_set(&req->rq_pill, &RQF_OST_SET_INFO);
1671 rc = ost_set_info(req->rq_export, req);
1674 DEBUG_REQ(D_INODE, req, "get_info");
1675 rc = ost_get_info(req->rq_export, req);
1677 case OST_QUOTACHECK:
1678 CDEBUG(D_INODE, "quotacheck\n");
1679 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
1680 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
1682 rc = ost_handle_quotacheck(req);
1685 CDEBUG(D_INODE, "quotactl\n");
1686 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
1687 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
1689 rc = ost_handle_quotactl(req);
1692 DEBUG_REQ(D_INODE, req, "ping");
1693 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
1694 rc = target_handle_ping(req);
1696 /* FIXME - just reply status */
1697 case LLOG_ORIGIN_CONNECT:
1698 DEBUG_REQ(D_INODE, req, "log connect");
1699 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
1700 rc = ost_llog_handle_connect(req->rq_export, req);
1701 req->rq_status = rc;
1702 rc = req_capsule_server_pack(&req->rq_pill);
1705 RETURN(ptlrpc_reply(req));
1706 case OBD_LOG_CANCEL:
1707 CDEBUG(D_INODE, "log cancel\n");
1708 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
1709 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
1711 rc = llog_origin_handle_cancel(req);
1712 req->rq_status = rc;
1713 rc = req_capsule_server_pack(&req->rq_pill);
1716 RETURN(ptlrpc_reply(req));
1718 CDEBUG(D_INODE, "enqueue\n");
1719 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
1720 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
1722 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1723 ldlm_server_blocking_ast,
1724 ldlm_server_glimpse_ast);
1725 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1728 CDEBUG(D_INODE, "convert\n");
1729 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
1730 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
1732 rc = ldlm_handle_convert(req);
1735 CDEBUG(D_INODE, "cancel\n");
1736 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
1737 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
1739 rc = ldlm_handle_cancel(req);
1741 case LDLM_BL_CALLBACK:
1742 case LDLM_CP_CALLBACK:
1743 CDEBUG(D_INODE, "callback\n");
1744 CERROR("callbacks should not happen on OST\n");
1747 CERROR("Unexpected opcode %d\n",
1748 lustre_msg_get_opc(req->rq_reqmsg));
1749 req->rq_status = -ENOTSUPP;
1750 rc = ptlrpc_error(req);
1754 LASSERT(current->journal_info == NULL);
1757 /* If we're DISCONNECTing, the export_data is already freed */
1758 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
1759 target_committed_to_req(req);
1763 oti_to_request(oti, req);
1765 target_send_reply(req, rc, fail);
1768 EXPORT_SYMBOL(ost_handle);
1770 * free per-thread pool created by ost_thread_init().
1772 static void ost_thread_done(struct ptlrpc_thread *thread)
1775 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
1780 LASSERT(thread != NULL);
1783 * be prepared to handle partially-initialized pools (because this is
1784 * called from ost_thread_init() for cleanup.
1786 tls = thread->t_data;
1788 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1789 if (tls->page[i] != NULL)
1790 OBD_PAGE_FREE(tls->page[i]);
1793 thread->t_data = NULL;
1799 * initialize per-thread page pool (bug 5137).
1801 static int ost_thread_init(struct ptlrpc_thread *thread)
1805 struct ost_thread_local_cache *tls;
1809 LASSERT(thread != NULL);
1810 LASSERT(thread->t_data == NULL);
1811 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
1816 thread->t_data = tls;
1820 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1821 OBD_PAGE_ALLOC(tls->page[i], OST_THREAD_POOL_GFP);
1822 if (tls->page[i] == NULL) {
1823 ost_thread_done(thread);
1833 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
1835 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
1836 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
1838 struct ost_obd *ost = &obd->u.ost;
1839 struct lprocfs_static_vars lvars;
1840 int oss_min_threads;
1841 int oss_max_threads;
1842 int oss_min_create_threads;
1843 int oss_max_create_threads;
1847 rc = cleanup_group_info();
1851 lprocfs_ost_init_vars(&lvars);
1852 lprocfs_obd_setup(obd, lvars.obd_vars);
1854 sema_init(&ost->ost_health_sem, 1);
1856 if (oss_num_threads) {
1857 /* If oss_num_threads is set, it is the min and the max. */
1858 if (oss_num_threads > OSS_THREADS_MAX)
1859 oss_num_threads = OSS_THREADS_MAX;
1860 if (oss_num_threads < OSS_THREADS_MIN)
1861 oss_num_threads = OSS_THREADS_MIN;
1862 oss_max_threads = oss_min_threads = oss_num_threads;
1864 /* Base min threads on memory and cpus */
1865 oss_min_threads = num_possible_cpus() * num_physpages >>
1866 (27 - CFS_PAGE_SHIFT);
1867 if (oss_min_threads < OSS_THREADS_MIN)
1868 oss_min_threads = OSS_THREADS_MIN;
1869 /* Insure a 4x range for dynamic threads */
1870 if (oss_min_threads > OSS_THREADS_MAX / 4)
1871 oss_min_threads = OSS_THREADS_MAX / 4;
1872 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4);
1876 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1877 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
1879 OST_WATCHDOG_TIMEOUT, ost_handle,
1880 LUSTRE_OSS_NAME, obd->obd_proc_entry,
1881 ost_print_req, oss_min_threads,
1882 oss_max_threads, "ll_ost",
1884 if (ost->ost_service == NULL) {
1885 CERROR("failed to start service\n");
1886 GOTO(out_lprocfs, rc = -ENOMEM);
1889 rc = ptlrpc_start_threads(obd, ost->ost_service);
1891 GOTO(out_service, rc = -EINVAL);
1893 if (oss_num_create_threads) {
1894 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
1895 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
1896 if (oss_num_create_threads < OSS_DEF_CREATE_THREADS)
1897 oss_num_create_threads = OSS_DEF_CREATE_THREADS;
1898 oss_min_create_threads = oss_max_create_threads =
1899 oss_num_create_threads;
1901 oss_min_create_threads = OSS_DEF_CREATE_THREADS;
1902 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
1905 ost->ost_create_service =
1906 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1907 OST_MAXREPSIZE, OST_CREATE_PORTAL,
1909 OST_WATCHDOG_TIMEOUT, ost_handle, "ost_create",
1910 obd->obd_proc_entry, ost_print_req,
1911 oss_min_create_threads,
1912 oss_max_create_threads,
1913 "ll_ost_creat", LCT_DT_THREAD);
1914 if (ost->ost_create_service == NULL) {
1915 CERROR("failed to start OST create service\n");
1916 GOTO(out_service, rc = -ENOMEM);
1919 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
1921 GOTO(out_create, rc = -EINVAL);
1923 ost->ost_io_service =
1924 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1925 OST_MAXREPSIZE, OST_IO_PORTAL,
1927 OST_WATCHDOG_TIMEOUT, ost_handle, "ost_io",
1928 obd->obd_proc_entry, ost_print_req,
1929 oss_min_threads, oss_max_threads,
1930 "ll_ost_io", LCT_DT_THREAD);
1931 if (ost->ost_io_service == NULL) {
1932 CERROR("failed to start OST I/O service\n");
1933 GOTO(out_create, rc = -ENOMEM);
1936 ost->ost_io_service->srv_init = ost_thread_init;
1937 ost->ost_io_service->srv_done = ost_thread_done;
1938 ost->ost_io_service->srv_cpu_affinity = 1;
1939 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
1941 GOTO(out_io, rc = -EINVAL);
1943 ping_evictor_start();
1948 ptlrpc_unregister_service(ost->ost_io_service);
1949 ost->ost_io_service = NULL;
1951 ptlrpc_unregister_service(ost->ost_create_service);
1952 ost->ost_create_service = NULL;
1954 ptlrpc_unregister_service(ost->ost_service);
1955 ost->ost_service = NULL;
1957 lprocfs_obd_cleanup(obd);
1961 static int ost_cleanup(struct obd_device *obd)
1963 struct ost_obd *ost = &obd->u.ost;
1967 ping_evictor_stop();
1969 spin_lock_bh(&obd->obd_processing_task_lock);
1970 if (obd->obd_recovering) {
1971 target_cancel_recovery_timer(obd);
1972 obd->obd_recovering = 0;
1974 spin_unlock_bh(&obd->obd_processing_task_lock);
1976 down(&ost->ost_health_sem);
1977 ptlrpc_unregister_service(ost->ost_service);
1978 ptlrpc_unregister_service(ost->ost_create_service);
1979 ptlrpc_unregister_service(ost->ost_io_service);
1980 ost->ost_service = NULL;
1981 ost->ost_create_service = NULL;
1982 up(&ost->ost_health_sem);
1984 lprocfs_obd_cleanup(obd);
1989 static int ost_health_check(struct obd_device *obd)
1991 struct ost_obd *ost = &obd->u.ost;
1994 down(&ost->ost_health_sem);
1995 rc |= ptlrpc_service_health_check(ost->ost_service);
1996 rc |= ptlrpc_service_health_check(ost->ost_create_service);
1997 rc |= ptlrpc_service_health_check(ost->ost_io_service);
1998 up(&ost->ost_health_sem);
2001 * health_check to return 0 on healthy
2002 * and 1 on unhealthy.
2010 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2012 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2015 /* use obd ops to offer management infrastructure */
2016 static struct obd_ops ost_obd_ops = {
2017 .o_owner = THIS_MODULE,
2018 .o_setup = ost_setup,
2019 .o_cleanup = ost_cleanup,
2020 .o_health_check = ost_health_check,
2024 static int __init ost_init(void)
2026 struct lprocfs_static_vars lvars;
2030 lprocfs_ost_init_vars(&lvars);
2031 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2032 LUSTRE_OSS_NAME, NULL);
2034 if (ost_num_threads != 0 && oss_num_threads == 0) {
2035 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2036 "use oss_num_threads instead or unset both for "
2037 "dynamic thread startup\n");
2038 oss_num_threads = ost_num_threads;
2044 static void /*__exit*/ ost_exit(void)
2046 class_unregister_type(LUSTRE_OSS_NAME);
2049 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2050 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2051 MODULE_LICENSE("GPL");
2053 module_init(ost_init);
2054 module_exit(ost_exit);