1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
5 * Author: Peter J. Braam <braam@clusterfs.com>
6 * Author: Phil Schwan <phil@clusterfs.com>
8 * This file is part of the Lustre file system, http://www.lustre.org
9 * Lustre is a trademark of Cluster File Systems, Inc.
11 * You may have signed or agreed to another license before downloading
12 * this software. If so, you are bound by the terms and conditions
13 * of that agreement, and the following does not apply to you. See the
14 * LICENSE file included with this distribution for more information.
16 * If you did not agree to a different license, then this copy of Lustre
17 * is open source software; you can redistribute it and/or modify it
18 * under the terms of version 2 of the GNU General Public License as
19 * published by the Free Software Foundation.
21 * In either case, Lustre is distributed in the hope that it will be
22 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
23 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * license text for more details.
26 * Storage Target Handling functions
27 * Lustre Object Server Module (OST)
29 * This server is single threaded at present (but can easily be multi
30 * threaded). For testing and management it is treated as an
31 * obd_device, although it does not export a full OBD method table
32 * (the requests are coming in over the wire, so object target
33 * modules do not have a full method table.)
37 # define EXPORT_SYMTAB
39 #define DEBUG_SUBSYSTEM S_OST
41 #include <linux/module.h>
42 #include <obd_cksum.h>
44 #include <lustre_net.h>
45 #include <lustre_dlm.h>
46 #include <lustre_export.h>
47 #include <lustre_debug.h>
48 #include <linux/init.h>
49 #include <lprocfs_status.h>
50 #include <lustre_commit_confd.h>
51 #include <libcfs/list.h>
52 #include <lustre_quota.h>
53 #include "ost_internal.h"
55 static int oss_num_threads;
56 CFS_MODULE_PARM(oss_num_threads, "i", int, 0444,
57 "number of OSS service threads to start");
59 static int ost_num_threads;
60 CFS_MODULE_PARM(ost_num_threads, "i", int, 0444,
61 "number of OST service threads to start (deprecated)");
63 static int oss_num_create_threads;
64 CFS_MODULE_PARM(oss_num_create_threads, "i", int, 0444,
65 "number of OSS create threads to start");
67 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
69 struct oti_req_ack_lock *ack_lock;
76 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
77 req->rq_transno = oti->oti_transno;
79 /* XXX 4 == entries in oti_ack_locks??? */
80 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
83 /* XXX not even calling target_send_reply in some cases... */
84 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode);
88 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
89 struct obd_trans_info *oti)
91 struct ost_body *body, *repbody;
92 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
96 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
97 lustre_swab_ost_body);
101 if (body->oa.o_id == 0)
104 if (lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1)) {
105 struct ldlm_request *dlm;
106 dlm = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*dlm),
107 lustre_swab_ldlm_request);
110 ldlm_request_cancel(req, dlm, 0);
113 rc = lustre_pack_reply(req, 2, size, NULL);
117 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
118 oti->oti_logcookies = obdo_logcookie(&body->oa);
119 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
121 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
122 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL);
126 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
128 struct ost_body *body, *repbody;
129 struct obd_info oinfo = { { { 0 } } };
130 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
134 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
135 lustre_swab_ost_body);
139 rc = lustre_pack_reply(req, 2, size, NULL);
143 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
145 repbody->oa = body->oa;
147 oinfo.oi_oa = &repbody->oa;
148 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
149 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
151 req->rq_status = obd_getattr(exp, &oinfo);
155 static int ost_statfs(struct ptlrpc_request *req)
157 struct obd_statfs *osfs;
158 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*osfs) };
162 rc = lustre_pack_reply(req, 2, size, NULL);
166 osfs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*osfs));
168 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
169 cfs_time_current_64() - HZ, 0);
170 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
171 osfs->os_bfree = osfs->os_bavail = 64;
172 if (req->rq_status != 0)
173 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
178 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
179 struct obd_trans_info *oti)
181 struct ost_body *body, *repbody;
182 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
186 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
187 lustre_swab_ost_body);
191 rc = lustre_pack_reply(req, 2, size, NULL);
195 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
197 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
198 oti->oti_logcookies = obdo_logcookie(&repbody->oa);
199 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
200 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
205 * Helper function for ost_punch(): if asked by client, acquire [size, EOF]
206 * lock on the file being truncated.
208 static int ost_punch_lock_get(struct obd_export *exp, struct obdo *oa,
209 struct lustre_handle *lh)
212 struct ldlm_res_id res_id = { .name = { oa->o_id, 0, oa->o_gr, 0} };
213 ldlm_policy_data_t policy;
219 LASSERT(!lustre_handle_is_used(lh));
221 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
222 !(oa->o_flags & OBD_FL_TRUNCLOCK))
225 CDEBUG(D_INODE, "OST-side truncate lock.\n");
228 finis = start + oa->o_blocks;
231 * standard truncate optimization: if file body is completely
232 * destroyed, don't send data back to the server.
234 flags = (start == 0) ? LDLM_AST_DISCARD_DATA : 0;
236 policy.l_extent.start = start & CFS_PAGE_MASK;
239 * If ->o_blocks is EOF it means "lock till the end of the
240 * file". Otherwise, it's size of a hole being punched (in bytes)
242 if (oa->o_blocks == OBD_OBJECT_EOF || finis < start)
243 policy.l_extent.end = OBD_OBJECT_EOF;
245 policy.l_extent.end = finis | ~CFS_PAGE_MASK;
247 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
248 LDLM_EXTENT, &policy, LCK_PW, &flags,
249 ldlm_blocking_ast, ldlm_completion_ast,
250 ldlm_glimpse_ast, NULL, 0, NULL, lh));
254 * Helper function for ost_punch(): release lock acquired by
255 * ost_punch_lock_get(), if any.
257 static void ost_punch_lock_put(struct obd_export *exp, struct obdo *oa,
258 struct lustre_handle *lh)
261 if (lustre_handle_is_used(lh))
262 ldlm_lock_decref(lh, LCK_PW);
266 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
267 struct obd_trans_info *oti)
269 struct obd_info oinfo = { { { 0 } } };
270 struct ost_body *body, *repbody;
271 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
273 struct lustre_handle lh = {0,};
276 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
277 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
279 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
280 lustre_swab_ost_body);
284 oinfo.oi_oa = &body->oa;
285 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
286 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
288 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
289 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
292 rc = lustre_pack_reply(req, 2, size, NULL);
296 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
298 rc = ost_punch_lock_get(exp, oinfo.oi_oa, &lh);
300 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
301 oinfo.oi_oa->o_flags == OBD_FL_TRUNCLOCK)
303 * If OBD_FL_TRUNCLOCK is the only bit set in
304 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
305 * through filter_setattr() to filter_iocontrol().
307 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
309 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
310 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
312 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
313 ost_punch_lock_put(exp, oinfo.oi_oa, &lh);
315 repbody->oa = *oinfo.oi_oa;
319 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
321 struct ost_body *body, *repbody;
322 struct lustre_capa *capa = NULL;
323 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
327 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
328 lustre_swab_ost_body);
332 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
333 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 1);
335 rc = lustre_pack_reply(req, 2, size, NULL);
339 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
341 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
342 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
343 repbody->oa.o_blocks, capa);
347 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
348 struct obd_trans_info *oti)
350 struct ost_body *body, *repbody;
351 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
353 struct obd_info oinfo = { { { 0 } } };
356 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
357 lustre_swab_ost_body);
361 rc = lustre_pack_reply(req, 2, size, NULL);
365 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
367 repbody->oa = body->oa;
369 oinfo.oi_oa = &repbody->oa;
370 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
371 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
373 req->rq_status = obd_setattr(exp, &oinfo, oti);
377 static int ost_bulk_timeout(void *data)
380 /* We don't fail the connection here, because having the export
381 * killed makes the (vital) call to commitrw very sad.
386 static int get_per_page_niobufs(struct obd_ioobj *ioo, int nioo,
387 struct niobuf_remote *rnb, int nrnb,
388 struct niobuf_remote **pp_rnbp)
390 /* Copy a remote niobuf, splitting it into page-sized chunks
391 * and setting ioo[i].ioo_bufcnt accordingly */
392 struct niobuf_remote *pp_rnb;
400 * array of sufficient size already preallocated by caller
402 LASSERT(pp_rnbp != NULL);
403 LASSERT(*pp_rnbp != NULL);
405 /* first count and check the number of pages required */
406 for (i = 0; i < nioo; i++)
407 for (j = 0; j < ioo->ioo_bufcnt; j++, rnbidx++) {
408 obd_off offset = rnb[rnbidx].offset;
409 obd_off p0 = offset >> CFS_PAGE_SHIFT;
410 obd_off pn = (offset + rnb[rnbidx].len - 1) >>
413 LASSERT(rnbidx < nrnb);
415 npages += (pn + 1 - p0);
417 if (rnb[rnbidx].len == 0) {
418 CERROR("zero len BRW: obj %d objid "LPX64
419 " buf %u\n", i, ioo[i].ioo_id, j);
423 rnb[rnbidx].offset <= rnb[rnbidx-1].offset) {
424 CERROR("unordered BRW: obj %d objid "LPX64
425 " buf %u offset "LPX64" <= "LPX64"\n",
426 i, ioo[i].ioo_id, j, rnb[rnbidx].offset,
432 LASSERT(rnbidx == nrnb);
434 if (npages == nrnb) { /* all niobufs are for single pages */
441 /* now do the actual split */
443 for (i = 0; i < nioo; i++) {
446 for (j = 0; j < ioo[i].ioo_bufcnt; j++, rnbidx++) {
447 obd_off off = rnb[rnbidx].offset;
448 int nob = rnb[rnbidx].len;
450 LASSERT(rnbidx < nrnb);
452 obd_off poff = off & ~CFS_PAGE_MASK;
453 int pnob = (poff + nob > CFS_PAGE_SIZE) ?
454 CFS_PAGE_SIZE - poff : nob;
456 LASSERT(page < npages);
457 pp_rnb[page].len = pnob;
458 pp_rnb[page].offset = off;
459 pp_rnb[page].flags = rnb[rnbidx].flags;
461 CDEBUG(0, " obj %d id "LPX64
462 "page %d(%d) "LPX64" for %d, flg %x\n",
463 i, ioo[i].ioo_id, obj_pages, page,
464 pp_rnb[page].offset, pp_rnb[page].len,
474 ioo[i].ioo_bufcnt = obj_pages;
476 LASSERT(page == npages);
481 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
482 cksum_type_t cksum_type)
487 cksum = init_checksum(cksum_type);
488 for (i = 0; i < desc->bd_iov_count; i++) {
489 struct page *page = desc->bd_iov[i].kiov_page;
490 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
491 char *ptr = kmap(page) + off;
492 int len = desc->bd_iov[i].kiov_len;
494 /* corrupt the data before we compute the checksum, to
495 * simulate a client->OST data error */
496 if (i == 0 && opc == OST_WRITE &&
497 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
498 memcpy(ptr, "bad3", min(4, len));
499 cksum = compute_checksum(cksum, ptr, len, cksum_type);
500 /* corrupt the data after we compute the checksum, to
501 * simulate an OST->client data error */
502 if (i == 0 && opc == OST_READ &&
503 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND))
504 memcpy(ptr, "bad4", min(4, len));
512 * populate @nio by @nrpages pages from per-thread page pool
514 static void ost_nio_pages_get(struct ptlrpc_request *req,
515 struct niobuf_local *nio, int nrpages)
518 struct ost_thread_local_cache *tls;
522 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
523 LASSERT(req != NULL);
524 LASSERT(req->rq_svc_thread != NULL);
527 LASSERT(tls != NULL);
529 memset(nio, 0, nrpages * sizeof *nio);
530 for (i = 0; i < nrpages; ++ i) {
534 LASSERT(page != NULL);
535 POISON_PAGE(page, 0xf1);
537 LL_CDEBUG_PAGE(D_INFO, page, "%d\n", i);
543 * Dual for ost_nio_pages_get(). Poison pages in pool for debugging
545 static void ost_nio_pages_put(struct ptlrpc_request *req,
546 struct niobuf_local *nio, int nrpages)
552 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
554 for (i = 0; i < nrpages; ++ i)
555 POISON_PAGE(nio[i].page, 0xf2);
559 static int ost_brw_lock_get(int mode, struct obd_export *exp,
560 struct obd_ioobj *obj, struct niobuf_remote *nb,
561 struct lustre_handle *lh)
564 int nrbufs = obj->ioo_bufcnt;
565 struct ldlm_res_id res_id = { .name = { obj->ioo_id, 0,
567 ldlm_policy_data_t policy;
572 LASSERT(mode == LCK_PR || mode == LCK_PW);
573 LASSERT(!lustre_handle_is_used(lh));
575 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
578 /* EXPENSIVE ASSERTION */
579 for (i = 1; i < nrbufs; i ++)
580 LASSERT((nb[0].flags & OBD_BRW_SRVLOCK) ==
581 (nb[i].flags & OBD_BRW_SRVLOCK));
583 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
584 policy.l_extent.end = (nb[nrbufs - 1].offset +
585 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
587 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
588 LDLM_EXTENT, &policy, mode, &flags,
589 ldlm_blocking_ast, ldlm_completion_ast,
590 ldlm_glimpse_ast, NULL, 0, NULL, lh));
593 static void ost_brw_lock_put(int mode,
594 struct obd_ioobj *obj, struct niobuf_remote *niob,
595 struct lustre_handle *lh)
598 LASSERT(mode == LCK_PR || mode == LCK_PW);
599 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
600 lustre_handle_is_used(lh));
601 if (lustre_handle_is_used(lh))
602 ldlm_lock_decref(lh, mode);
606 struct ost_prolong_data {
607 struct obd_export *opd_exp;
608 ldlm_policy_data_t opd_policy;
609 ldlm_mode_t opd_mode;
612 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
614 struct ost_prolong_data *opd = data;
616 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
618 if (lock->l_req_mode != lock->l_granted_mode) {
619 /* scan granted locks only */
620 return LDLM_ITER_STOP;
623 if (lock->l_export != opd->opd_exp) {
624 /* prolong locks only for given client */
625 return LDLM_ITER_CONTINUE;
628 if (!(lock->l_granted_mode & opd->opd_mode)) {
629 /* we aren't interesting in all type of locks */
630 return LDLM_ITER_CONTINUE;
633 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
634 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
635 /* the request doesn't cross the lock, skip it */
636 return LDLM_ITER_CONTINUE;
639 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
640 /* ignore locks not being cancelled */
641 return LDLM_ITER_CONTINUE;
644 /* OK. this is a possible lock the user holds doing I/O
645 * let's refresh eviction timer for it */
646 ldlm_refresh_waiting_lock(lock);
648 return LDLM_ITER_CONTINUE;
651 static void ost_prolong_locks(struct obd_export *exp, struct obd_ioobj *obj,
652 struct niobuf_remote *nb, ldlm_mode_t mode)
654 struct ldlm_res_id res_id = { .name = { obj->ioo_id, 0,
656 int nrbufs = obj->ioo_bufcnt;
657 struct ost_prolong_data opd;
663 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
664 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
665 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
667 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
668 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
669 opd.opd_policy.l_extent.end);
670 ldlm_resource_iterate(exp->exp_obd->obd_namespace, &res_id,
671 ost_prolong_locks_iter, &opd);
674 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
676 struct ptlrpc_bulk_desc *desc;
677 struct obd_export *exp = req->rq_export;
678 struct niobuf_remote *remote_nb;
679 struct niobuf_remote *pp_rnb = NULL;
680 struct niobuf_local *local_nb;
681 struct obd_ioobj *ioo;
682 struct ost_body *body, *repbody;
683 struct lustre_capa *capa = NULL;
684 struct l_wait_info lwi;
685 struct lustre_handle lockh = { 0 };
686 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
687 int niocount, npages, nob = 0, rc, i;
691 req->rq_bulk_read = 1;
693 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
694 GOTO(out, rc = -EIO);
696 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
698 /* Check if there is eviction in progress, and if so, wait for it to
700 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
701 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
702 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
703 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
707 GOTO(out, rc = -ENOTCONN);
709 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
710 lustre_swab_ost_body);
712 CERROR("Missing/short ost_body\n");
713 GOTO(out, rc = -EFAULT);
716 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*ioo),
717 lustre_swab_obd_ioobj);
719 CERROR("Missing/short ioobj\n");
720 GOTO(out, rc = -EFAULT);
723 niocount = ioo->ioo_bufcnt;
724 if (niocount > PTLRPC_MAX_BRW_PAGES) {
725 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
727 GOTO(out, rc = -EFAULT);
730 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
731 niocount * sizeof(*remote_nb),
732 lustre_swab_niobuf_remote);
733 if (remote_nb == NULL) {
734 CERROR("Missing/short niobuf\n");
735 GOTO(out, rc = -EFAULT);
737 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
738 for (i = 1; i < niocount; i++)
739 lustre_swab_niobuf_remote (&remote_nb[i]);
742 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
743 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
745 rc = lustre_pack_reply(req, 2, size, NULL);
750 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
753 local_nb = ost_tls(req)->local;
754 pp_rnb = ost_tls(req)->remote;
756 /* FIXME all niobuf splitting should be done in obdfilter if needed */
757 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
758 npages = get_per_page_niobufs(ioo, 1, remote_nb, niocount, &pp_rnb);
760 GOTO(out, rc = npages);
762 LASSERT(npages <= OST_THREAD_POOL_SIZE);
764 ost_nio_pages_get(req, local_nb, npages);
766 desc = ptlrpc_prep_bulk_exp(req, npages,
767 BULK_PUT_SOURCE, OST_BULK_PORTAL);
769 GOTO(out, rc = -ENOMEM);
771 rc = ost_brw_lock_get(LCK_PR, exp, ioo, pp_rnb, &lockh);
776 * If getting the lock took more time than
777 * client was willing to wait, drop it. b=11330
779 if (cfs_time_current_sec() > req->rq_deadline ||
780 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
782 CERROR("Dropping timed-out read from %s because locking"
783 "object "LPX64" took %ld seconds (limit was %ld).\n",
784 libcfs_id2str(req->rq_peer), ioo->ioo_id,
785 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
786 req->rq_deadline - req->rq_arrival_time.tv_sec);
787 GOTO(out_lock, rc = -ETIMEDOUT);
790 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1,
791 ioo, npages, pp_rnb, local_nb, oti, capa);
795 ost_prolong_locks(exp, ioo, pp_rnb, LCK_PW | LCK_PR);
798 for (i = 0; i < npages; i++) {
799 int page_rc = local_nb[i].rc;
801 if (page_rc < 0) { /* error */
806 LASSERTF(page_rc <= pp_rnb[i].len, "page_rc (%d) > "
807 "pp_rnb[%d].len (%d)\n", page_rc, i, pp_rnb[i].len);
809 if (page_rc != 0) { /* some data! */
810 LASSERT (local_nb[i].page != NULL);
811 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
812 pp_rnb[i].offset & ~CFS_PAGE_MASK,
816 if (page_rc != pp_rnb[i].len) { /* short read */
817 /* All subsequent pages should be 0 */
819 LASSERT(local_nb[i].rc == 0);
824 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
825 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
827 if (body->oa.o_valid & OBD_MD_FLFLAGS)
828 cksum_type = cksum_type_unpack(body->oa.o_flags);
829 body->oa.o_flags = cksum_type_pack(cksum_type);
830 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
831 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
832 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
834 body->oa.o_valid = 0;
836 /* We're finishing using body->oa as an input variable */
838 /* Check if client was evicted while we were doing i/o before touching
841 /* Check if there is eviction in progress, and if so, wait for
843 if (unlikely(atomic_read(&exp->exp_obd->
844 obd_evict_inprogress))) {
845 lwi = LWI_INTR(NULL, NULL);
846 rc = l_wait_event(exp->exp_obd->
847 obd_evict_inprogress_waitq,
848 !atomic_read(&exp->exp_obd->
849 obd_evict_inprogress),
855 sptlrpc_svc_wrap_bulk(req, desc);
857 rc = ptlrpc_start_bulk_transfer(desc);
861 time_t start = cfs_time_current_sec();
863 long timeoutl = req->rq_deadline -
864 cfs_time_current_sec();
865 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
866 CFS_TICK : cfs_time_seconds(timeoutl);
867 lwi = LWI_TIMEOUT_INTERVAL(timeout,
871 rc = l_wait_event(desc->bd_waitq,
872 !ptlrpc_bulk_active(desc) ||
873 exp->exp_failed, &lwi);
874 LASSERT(rc == 0 || rc == -ETIMEDOUT);
875 /* Wait again if we changed deadline */
876 } while ((rc == -ETIMEDOUT) &&
877 (req->rq_deadline > cfs_time_current_sec()));
879 if (rc == -ETIMEDOUT) {
880 DEBUG_REQ(D_ERROR, req,
881 "timeout on bulk PUT after %ld%+lds",
882 req->rq_deadline - start,
883 cfs_time_current_sec() -
885 ptlrpc_abort_bulk(desc);
886 } else if (exp->exp_failed) {
887 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
889 ptlrpc_abort_bulk(desc);
890 } else if (!desc->bd_success ||
891 desc->bd_nob_transferred != desc->bd_nob) {
892 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
894 "truncated" : "network error on",
895 desc->bd_nob_transferred,
897 /* XXX should this be a different errno? */
901 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
906 /* Must commit after prep above in all cases */
907 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1,
908 ioo, npages, local_nb, oti, rc);
910 ost_nio_pages_put(req, local_nb, npages);
913 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
915 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
919 ost_brw_lock_put(LCK_PR, ioo, pp_rnb, &lockh);
921 ptlrpc_free_bulk(desc);
925 req->rq_status = nob;
926 target_committed_to_req(req);
928 } else if (!no_reply) {
929 /* Only reply if there was no comms problem with bulk */
930 target_committed_to_req(req);
934 /* reply out callback would free */
935 ptlrpc_req_drop_rs(req);
936 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
937 "client will retry\n",
938 exp->exp_obd->obd_name,
939 exp->exp_client_uuid.uuid,
940 exp->exp_connection->c_remote_uuid.uuid,
941 libcfs_id2str(req->rq_peer));
947 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
949 struct ptlrpc_bulk_desc *desc;
950 struct obd_export *exp = req->rq_export;
951 struct niobuf_remote *remote_nb;
952 struct niobuf_remote *pp_rnb;
953 struct niobuf_local *local_nb;
954 struct obd_ioobj *ioo;
955 struct ost_body *body, *repbody;
956 struct l_wait_info lwi;
957 struct lustre_handle lockh = {0};
958 struct lustre_capa *capa = NULL;
960 __u32 size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
961 int objcount, niocount, npages;
963 obd_count client_cksum = 0, server_cksum = 0;
964 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
968 req->rq_bulk_write = 1;
970 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
971 GOTO(out, rc = -EIO);
972 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
973 GOTO(out, rc = -EFAULT);
975 /* pause before transaction has been started */
976 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
978 /* Check if there is eviction in progress, and if so, wait for it to
980 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
981 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
982 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
983 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
987 GOTO(out, rc = -ENOTCONN);
989 swab = lustre_msg_swabbed(req->rq_reqmsg);
990 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
991 lustre_swab_ost_body);
993 CERROR("Missing/short ost_body\n");
994 GOTO(out, rc = -EFAULT);
997 lustre_set_req_swabbed(req, REQ_REC_OFF + 1);
998 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
1000 if (objcount == 0) {
1001 CERROR("Missing/short ioobj\n");
1002 GOTO(out, rc = -EFAULT);
1005 CERROR("too many ioobjs (%d)\n", objcount);
1006 GOTO(out, rc = -EFAULT);
1009 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
1010 objcount * sizeof(*ioo));
1011 LASSERT (ioo != NULL);
1012 for (niocount = i = 0; i < objcount; i++) {
1014 lustre_swab_obd_ioobj(&ioo[i]);
1015 if (ioo[i].ioo_bufcnt == 0) {
1016 CERROR("ioo[%d] has zero bufcnt\n", i);
1017 GOTO(out, rc = -EFAULT);
1019 niocount += ioo[i].ioo_bufcnt;
1022 if (niocount > PTLRPC_MAX_BRW_PAGES) {
1023 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
1025 GOTO(out, rc = -EFAULT);
1028 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
1029 niocount * sizeof(*remote_nb),
1030 lustre_swab_niobuf_remote);
1031 if (remote_nb == NULL) {
1032 CERROR("Missing/short niobuf\n");
1033 GOTO(out, rc = -EFAULT);
1035 if (swab) { /* swab the remaining niobufs */
1036 for (i = 1; i < niocount; i++)
1037 lustre_swab_niobuf_remote (&remote_nb[i]);
1040 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
1041 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
1043 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
1044 rc = lustre_pack_reply(req, 3, size, NULL);
1047 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, obd_fail_val);
1048 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
1049 niocount * sizeof(*rcs));
1052 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
1053 * ost_thread_init().
1055 local_nb = ost_tls(req)->local;
1056 pp_rnb = ost_tls(req)->remote;
1058 /* FIXME all niobuf splitting should be done in obdfilter if needed */
1059 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
1060 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
1062 GOTO(out, rc = npages);
1064 LASSERT(npages <= OST_THREAD_POOL_SIZE);
1066 ost_nio_pages_get(req, local_nb, npages);
1068 desc = ptlrpc_prep_bulk_exp(req, npages,
1069 BULK_GET_SINK, OST_BULK_PORTAL);
1071 GOTO(out, rc = -ENOMEM);
1073 rc = ost_brw_lock_get(LCK_PW, exp, ioo, pp_rnb, &lockh);
1078 * If getting the lock took more time than
1079 * client was willing to wait, drop it. b=11330
1081 if (cfs_time_current_sec() > req->rq_deadline ||
1082 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
1084 CERROR("Dropping timed-out write from %s because locking "
1085 "object "LPX64" took %ld seconds (limit was %ld).\n",
1086 libcfs_id2str(req->rq_peer), ioo->ioo_id,
1087 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
1088 req->rq_deadline - req->rq_arrival_time.tv_sec);
1089 GOTO(out_lock, rc = -ETIMEDOUT);
1092 ost_prolong_locks(exp, ioo, pp_rnb, LCK_PW);
1094 /* obd_preprw clobbers oa->valid, so save what we need */
1095 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
1096 client_cksum = body->oa.o_cksum;
1097 if (body->oa.o_valid & OBD_MD_FLFLAGS)
1098 cksum_type = cksum_type_unpack(body->oa.o_flags);
1101 /* Because we already sync grant info with client when reconnect,
1102 * grant info will be cleared for resent req, then fed_grant and
1103 * total_grant will not be modified in following preprw_write */
1104 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
1105 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
1106 body->oa.o_valid &= ~OBD_MD_FLGRANT;
1109 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
1110 ioo, npages, pp_rnb, local_nb, oti, capa);
1114 /* NB Having prepped, we must commit... */
1116 for (i = 0; i < npages; i++)
1117 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1118 pp_rnb[i].offset & ~CFS_PAGE_MASK,
1121 /* Check if client was evicted while we were doing i/o before touching
1123 if (desc->bd_export->exp_failed)
1126 rc = ptlrpc_start_bulk_transfer (desc);
1128 time_t start = cfs_time_current_sec();
1130 long timeoutl = req->rq_deadline -
1131 cfs_time_current_sec();
1132 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
1133 CFS_TICK : cfs_time_seconds(timeoutl);
1134 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
1135 ost_bulk_timeout, desc);
1136 rc = l_wait_event(desc->bd_waitq,
1137 !ptlrpc_bulk_active(desc) ||
1138 desc->bd_export->exp_failed, &lwi);
1139 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1140 /* Wait again if we changed deadline */
1141 } while ((rc == -ETIMEDOUT) &&
1142 (req->rq_deadline > cfs_time_current_sec()));
1144 if (rc == -ETIMEDOUT) {
1145 DEBUG_REQ(D_ERROR, req,
1146 "timeout on bulk GET after %ld%+lds",
1147 req->rq_deadline - start,
1148 cfs_time_current_sec() -
1150 ptlrpc_abort_bulk(desc);
1151 } else if (desc->bd_export->exp_failed) {
1152 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1154 ptlrpc_abort_bulk(desc);
1155 } else if (!desc->bd_success ||
1156 desc->bd_nob_transferred != desc->bd_nob) {
1157 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1159 "truncated" : "network error on",
1160 desc->bd_nob_transferred, desc->bd_nob);
1161 /* XXX should this be a different errno? */
1165 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1170 sptlrpc_svc_unwrap_bulk(req, desc);
1172 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1174 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1176 if (unlikely(client_cksum != 0 && rc == 0)) {
1177 static int cksum_counter;
1178 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1179 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1180 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1181 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1182 repbody->oa.o_cksum = server_cksum;
1184 if (unlikely(client_cksum != server_cksum)) {
1185 CERROR("client csum %x, server csum %x\n",
1186 client_cksum, server_cksum);
1188 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1189 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1190 cksum_counter, libcfs_id2str(req->rq_peer),
1195 /* Must commit after prep above in all cases */
1196 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa,
1197 objcount, ioo, npages, local_nb, oti, rc);
1199 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1200 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1205 if (new_cksum == server_cksum)
1206 msg = "changed in transit before arrival at OST";
1207 else if (new_cksum == client_cksum)
1208 msg = "initial checksum before message complete";
1210 msg = "changed in transit AND after initial checksum";
1212 if (req->rq_peer.nid == desc->bd_sender) {
1216 router = libcfs_nid2str(desc->bd_sender);
1219 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1220 "%s%s%s inum "LPU64"/"LPU64" object "
1221 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1222 exp->exp_obd->obd_name, msg,
1223 libcfs_id2str(req->rq_peer),
1225 body->oa.o_valid & OBD_MD_FLFID ?
1226 body->oa.o_fid : (__u64)0,
1227 body->oa.o_valid & OBD_MD_FLFID ?
1228 body->oa.o_generation :(__u64)0,
1230 body->oa.o_valid & OBD_MD_FLGROUP ?
1231 body->oa.o_gr : (__u64)0,
1233 pp_rnb[npages-1].offset+pp_rnb[npages-1].len
1235 CERROR("client csum %x, original server csum %x, "
1236 "server csum now %x\n",
1237 client_cksum, server_cksum, new_cksum);
1240 ost_nio_pages_put(req, local_nb, npages);
1243 /* set per-requested niobuf return codes */
1244 for (i = j = 0; i < niocount; i++) {
1245 int nob = remote_nb[i].len;
1249 LASSERT(j < npages);
1250 if (local_nb[j].rc < 0)
1251 rcs[i] = local_nb[j].rc;
1252 nob -= pp_rnb[j].len;
1257 LASSERT(j == npages);
1261 ost_brw_lock_put(LCK_PW, ioo, pp_rnb, &lockh);
1263 ptlrpc_free_bulk(desc);
1266 oti_to_request(oti, req);
1267 target_committed_to_req(req);
1268 rc = ptlrpc_reply(req);
1269 } else if (!no_reply) {
1270 /* Only reply if there was no comms problem with bulk */
1271 target_committed_to_req(req);
1272 req->rq_status = rc;
1275 /* reply out callback would free */
1276 ptlrpc_req_drop_rs(req);
1277 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1278 "client will retry\n",
1279 exp->exp_obd->obd_name,
1280 exp->exp_client_uuid.uuid,
1281 exp->exp_connection->c_remote_uuid.uuid,
1282 libcfs_id2str(req->rq_peer));
1287 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1289 char *key, *val = NULL;
1290 int keylen, vallen, rc = 0;
1293 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1295 DEBUG_REQ(D_HA, req, "no set_info key");
1298 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1300 rc = lustre_pack_reply(req, 1, NULL, NULL);
1304 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1306 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
1308 if (KEY_IS(KEY_EVICT_BY_NID)) {
1310 obd_export_evict_by_nid(exp->exp_obd, val);
1315 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1317 lustre_msg_set_status(req->rq_repmsg, 0);
1321 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1324 int keylen, replylen, rc = 0;
1325 struct req_capsule *pill = &req->rq_pill;
1328 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
1330 /* this common part for get_info rpc */
1331 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1333 DEBUG_REQ(D_HA, req, "no get_info key");
1336 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1338 rc = obd_get_info(exp, keylen, key, &replylen, NULL);
1342 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1343 RCL_SERVER, replylen);
1345 rc = req_capsule_server_pack(pill);
1349 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1353 /* call again to fill in the reply buffer */
1354 rc = obd_get_info(exp, keylen, key, &replylen, reply);
1356 lustre_msg_set_status(req->rq_repmsg, 0);
1360 static int ost_handle_quotactl(struct ptlrpc_request *req)
1362 struct obd_quotactl *oqctl, *repoqc;
1363 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) };
1367 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1368 lustre_swab_obd_quotactl);
1370 GOTO(out, rc = -EPROTO);
1372 rc = lustre_pack_reply(req, 2, size, NULL);
1376 repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc));
1378 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1384 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1386 struct obd_quotactl *oqctl;
1390 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1394 rc = req_capsule_server_pack(&req->rq_pill);
1396 CERROR("ost: out of memory while packing quotacheck reply\n");
1400 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1404 static int ost_llog_handle_connect(struct obd_export *exp,
1405 struct ptlrpc_request *req)
1407 struct llogd_conn_body *body;
1411 body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body));
1412 rc = obd_llog_connect(exp, body);
1416 static int filter_export_check_flavor(struct filter_obd *filter,
1417 struct obd_export *exp,
1418 struct ptlrpc_request *req)
1423 * this should be done in filter_connect()/filter_reconnect(), but
1424 * we can't obtain information like NID, which stored in incoming
1425 * request, thus can't decide what flavor to use. so we do it here.
1427 * This hack should be removed after the OST stack be rewritten, just
1428 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1430 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_INVALID)
1433 CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from));
1434 spin_lock(&exp->exp_lock);
1435 exp->exp_sp_peer = req->rq_sp_from;
1437 read_lock(&filter->fo_sptlrpc_lock);
1438 sptlrpc_rule_set_choose(&filter->fo_sptlrpc_rset, exp->exp_sp_peer,
1439 req->rq_peer.nid, &exp->exp_flvr);
1440 read_unlock(&filter->fo_sptlrpc_lock);
1442 if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1443 CERROR("invalid rpc flavor %x, expect %x, from %s\n",
1444 req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
1445 libcfs_nid2str(req->rq_peer.nid));
1446 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID;
1450 spin_unlock(&exp->exp_lock);
1455 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1456 struct obd_device *obd, int *process)
1458 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1459 case OST_CONNECT: /* This will never get here, but for completeness. */
1460 case OST_DISCONNECT:
1471 case OBD_LOG_CANCEL:
1473 *process = target_queue_recovery_request(req, obd);
1477 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1483 int ost_msg_check_version(struct lustre_msg *msg)
1487 switch(lustre_msg_get_opc(msg)) {
1489 case OST_DISCONNECT:
1492 case SEC_CTX_INIT_CONT:
1494 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1496 CERROR("bad opc %u version %08x, expecting %08x\n",
1497 lustre_msg_get_opc(msg),
1498 lustre_msg_get_version(msg),
1499 LUSTRE_OBD_VERSION);
1512 case OST_QUOTACHECK:
1514 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1516 CERROR("bad opc %u version %08x, expecting %08x\n",
1517 lustre_msg_get_opc(msg),
1518 lustre_msg_get_version(msg),
1519 LUSTRE_OST_VERSION);
1524 case LDLM_BL_CALLBACK:
1525 case LDLM_CP_CALLBACK:
1526 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1528 CERROR("bad opc %u version %08x, expecting %08x\n",
1529 lustre_msg_get_opc(msg),
1530 lustre_msg_get_version(msg),
1531 LUSTRE_DLM_VERSION);
1533 case LLOG_ORIGIN_CONNECT:
1534 case OBD_LOG_CANCEL:
1535 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1537 CERROR("bad opc %u version %08x, expecting %08x\n",
1538 lustre_msg_get_opc(msg),
1539 lustre_msg_get_version(msg),
1540 LUSTRE_LOG_VERSION);
1543 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1549 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1550 int ost_handle(struct ptlrpc_request *req)
1552 struct obd_trans_info trans_info = { 0, };
1553 struct obd_trans_info *oti = &trans_info;
1554 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1555 struct obd_device *obd = NULL;
1558 LASSERT(current->journal_info == NULL);
1560 /* primordial rpcs don't affect server recovery */
1561 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1563 case SEC_CTX_INIT_CONT:
1568 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1570 /* XXX identical to MDS */
1571 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1574 if (req->rq_export == NULL) {
1575 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1576 lustre_msg_get_opc(req->rq_reqmsg),
1577 libcfs_id2str(req->rq_peer));
1578 req->rq_status = -ENOTCONN;
1579 GOTO(out, rc = -ENOTCONN);
1582 obd = req->rq_export->exp_obd;
1584 /* Check for aborted recovery. */
1585 spin_lock_bh(&obd->obd_processing_task_lock);
1586 recovering = obd->obd_recovering;
1587 spin_unlock_bh(&obd->obd_processing_task_lock);
1589 rc = ost_filter_recovery_request(req, obd,
1591 if (rc || !should_process)
1593 else if (should_process < 0) {
1594 req->rq_status = should_process;
1595 rc = ptlrpc_error(req);
1603 rc = ost_msg_check_version(req->rq_reqmsg);
1607 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1609 CDEBUG(D_INODE, "connect\n");
1610 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
1611 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
1613 rc = target_handle_connect(req);
1614 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
1617 struct obd_export *exp = req->rq_export;
1621 rc = filter_export_check_flavor(&obd->u.filter,
1626 case OST_DISCONNECT:
1627 CDEBUG(D_INODE, "disconnect\n");
1628 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
1629 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
1631 rc = target_handle_disconnect(req);
1634 CDEBUG(D_INODE, "create\n");
1635 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
1637 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1638 GOTO(out, rc = -ENOSPC);
1639 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1640 GOTO(out, rc = -EROFS);
1641 rc = ost_create(req->rq_export, req, oti);
1644 CDEBUG(D_INODE, "destroy\n");
1645 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
1647 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1648 GOTO(out, rc = -EROFS);
1649 rc = ost_destroy(req->rq_export, req, oti);
1652 CDEBUG(D_INODE, "getattr\n");
1653 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
1655 rc = ost_getattr(req->rq_export, req);
1658 CDEBUG(D_INODE, "setattr\n");
1659 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
1661 rc = ost_setattr(req->rq_export, req, oti);
1664 CDEBUG(D_INODE, "write\n");
1665 /* req->rq_request_portal would be nice, if it was set */
1666 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1667 CERROR("%s: deny write request from %s to portal %u\n",
1668 req->rq_export->exp_obd->obd_name,
1669 obd_export_nid2str(req->rq_export),
1670 req->rq_rqbd->rqbd_service->srv_req_portal);
1671 GOTO(out, rc = -EPROTO);
1673 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1675 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1676 GOTO(out, rc = -ENOSPC);
1677 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1678 GOTO(out, rc = -EROFS);
1679 rc = ost_brw_write(req, oti);
1680 LASSERT(current->journal_info == NULL);
1681 /* ost_brw_write sends its own replies */
1684 CDEBUG(D_INODE, "read\n");
1685 /* req->rq_request_portal would be nice, if it was set */
1686 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1687 CERROR("%s: deny read request from %s to portal %u\n",
1688 req->rq_export->exp_obd->obd_name,
1689 obd_export_nid2str(req->rq_export),
1690 req->rq_rqbd->rqbd_service->srv_req_portal);
1691 GOTO(out, rc = -EPROTO);
1693 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1695 rc = ost_brw_read(req, oti);
1696 LASSERT(current->journal_info == NULL);
1697 /* ost_brw_read sends its own replies */
1700 CDEBUG(D_INODE, "punch\n");
1701 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
1703 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1704 GOTO(out, rc = -EROFS);
1705 rc = ost_punch(req->rq_export, req, oti);
1708 CDEBUG(D_INODE, "statfs\n");
1709 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
1711 rc = ost_statfs(req);
1714 CDEBUG(D_INODE, "sync\n");
1715 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
1717 rc = ost_sync(req->rq_export, req);
1720 DEBUG_REQ(D_INODE, req, "set_info");
1721 req_capsule_set(&req->rq_pill, &RQF_OST_SET_INFO);
1722 rc = ost_set_info(req->rq_export, req);
1725 DEBUG_REQ(D_INODE, req, "get_info");
1726 rc = ost_get_info(req->rq_export, req);
1728 case OST_QUOTACHECK:
1729 CDEBUG(D_INODE, "quotacheck\n");
1730 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
1731 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
1733 rc = ost_handle_quotacheck(req);
1736 CDEBUG(D_INODE, "quotactl\n");
1737 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
1738 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
1740 rc = ost_handle_quotactl(req);
1743 DEBUG_REQ(D_INODE, req, "ping");
1744 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
1745 rc = target_handle_ping(req);
1747 /* FIXME - just reply status */
1748 case LLOG_ORIGIN_CONNECT:
1749 DEBUG_REQ(D_INODE, req, "log connect");
1750 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
1751 rc = ost_llog_handle_connect(req->rq_export, req);
1752 req->rq_status = rc;
1753 rc = req_capsule_server_pack(&req->rq_pill);
1756 RETURN(ptlrpc_reply(req));
1757 case OBD_LOG_CANCEL:
1758 CDEBUG(D_INODE, "log cancel\n");
1759 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
1760 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
1762 rc = llog_origin_handle_cancel(req);
1763 req->rq_status = rc;
1764 rc = req_capsule_server_pack(&req->rq_pill);
1767 RETURN(ptlrpc_reply(req));
1769 CDEBUG(D_INODE, "enqueue\n");
1770 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
1771 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
1773 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1774 ldlm_server_blocking_ast,
1775 ldlm_server_glimpse_ast);
1776 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1779 CDEBUG(D_INODE, "convert\n");
1780 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
1781 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
1783 rc = ldlm_handle_convert(req);
1786 CDEBUG(D_INODE, "cancel\n");
1787 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
1788 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
1790 rc = ldlm_handle_cancel(req);
1792 case LDLM_BL_CALLBACK:
1793 case LDLM_CP_CALLBACK:
1794 CDEBUG(D_INODE, "callback\n");
1795 CERROR("callbacks should not happen on OST\n");
1798 CERROR("Unexpected opcode %d\n",
1799 lustre_msg_get_opc(req->rq_reqmsg));
1800 req->rq_status = -ENOTSUPP;
1801 rc = ptlrpc_error(req);
1805 LASSERT(current->journal_info == NULL);
1808 /* If we're DISCONNECTing, the export_data is already freed */
1809 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
1810 target_committed_to_req(req);
1814 oti_to_request(oti, req);
1816 target_send_reply(req, rc, fail);
1819 EXPORT_SYMBOL(ost_handle);
1821 * free per-thread pool created by ost_thread_init().
1823 static void ost_thread_done(struct ptlrpc_thread *thread)
1826 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
1831 LASSERT(thread != NULL);
1834 * be prepared to handle partially-initialized pools (because this is
1835 * called from ost_thread_init() for cleanup.
1837 tls = thread->t_data;
1839 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1840 if (tls->page[i] != NULL)
1841 OBD_PAGE_FREE(tls->page[i]);
1844 thread->t_data = NULL;
1850 * initialize per-thread page pool (bug 5137).
1852 static int ost_thread_init(struct ptlrpc_thread *thread)
1856 struct ost_thread_local_cache *tls;
1860 LASSERT(thread != NULL);
1861 LASSERT(thread->t_data == NULL);
1862 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
1867 thread->t_data = tls;
1871 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1872 OBD_PAGE_ALLOC(tls->page[i], OST_THREAD_POOL_GFP);
1873 if (tls->page[i] == NULL) {
1874 ost_thread_done(thread);
1884 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
1886 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
1887 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
1889 struct ost_obd *ost = &obd->u.ost;
1890 struct lprocfs_static_vars lvars;
1891 int oss_min_threads;
1892 int oss_max_threads;
1893 int oss_min_create_threads;
1894 int oss_max_create_threads;
1898 rc = cleanup_group_info();
1902 lprocfs_ost_init_vars(&lvars);
1903 lprocfs_obd_setup(obd, lvars.obd_vars);
1905 sema_init(&ost->ost_health_sem, 1);
1907 if (oss_num_threads) {
1908 /* If oss_num_threads is set, it is the min and the max. */
1909 if (oss_num_threads > OSS_THREADS_MAX)
1910 oss_num_threads = OSS_THREADS_MAX;
1911 if (oss_num_threads < OSS_THREADS_MIN)
1912 oss_num_threads = OSS_THREADS_MIN;
1913 oss_max_threads = oss_min_threads = oss_num_threads;
1915 /* Base min threads on memory and cpus */
1916 oss_min_threads = num_possible_cpus() * num_physpages >>
1917 (27 - CFS_PAGE_SHIFT);
1918 if (oss_min_threads < OSS_THREADS_MIN)
1919 oss_min_threads = OSS_THREADS_MIN;
1920 /* Insure a 4x range for dynamic threads */
1921 if (oss_min_threads > OSS_THREADS_MAX / 4)
1922 oss_min_threads = OSS_THREADS_MAX / 4;
1923 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4);
1927 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1928 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
1929 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1930 ost_handle, LUSTRE_OSS_NAME,
1931 obd->obd_proc_entry, target_print_req,
1932 oss_min_threads, oss_max_threads,
1933 "ll_ost", LCT_DT_THREAD);
1934 if (ost->ost_service == NULL) {
1935 CERROR("failed to start service\n");
1936 GOTO(out_lprocfs, rc = -ENOMEM);
1939 rc = ptlrpc_start_threads(obd, ost->ost_service);
1941 GOTO(out_service, rc = -EINVAL);
1943 if (oss_num_create_threads) {
1944 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
1945 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
1946 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
1947 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
1948 oss_min_create_threads = oss_max_create_threads =
1949 oss_num_create_threads;
1951 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
1952 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
1955 ost->ost_create_service =
1956 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1957 OST_MAXREPSIZE, OST_CREATE_PORTAL,
1958 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1959 ost_handle, "ost_create",
1960 obd->obd_proc_entry, target_print_req,
1961 oss_min_create_threads, oss_max_create_threads,
1962 "ll_ost_creat", LCT_DT_THREAD);
1963 if (ost->ost_create_service == NULL) {
1964 CERROR("failed to start OST create service\n");
1965 GOTO(out_service, rc = -ENOMEM);
1968 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
1970 GOTO(out_create, rc = -EINVAL);
1972 ost->ost_io_service =
1973 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1974 OST_MAXREPSIZE, OST_IO_PORTAL,
1975 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1976 ost_handle, "ost_io",
1977 obd->obd_proc_entry, target_print_req,
1978 oss_min_threads, oss_max_threads,
1979 "ll_ost_io", LCT_DT_THREAD);
1980 if (ost->ost_io_service == NULL) {
1981 CERROR("failed to start OST I/O service\n");
1982 GOTO(out_create, rc = -ENOMEM);
1985 ost->ost_io_service->srv_init = ost_thread_init;
1986 ost->ost_io_service->srv_done = ost_thread_done;
1987 ost->ost_io_service->srv_cpu_affinity = 1;
1988 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
1990 GOTO(out_io, rc = -EINVAL);
1992 ping_evictor_start();
1997 ptlrpc_unregister_service(ost->ost_io_service);
1998 ost->ost_io_service = NULL;
2000 ptlrpc_unregister_service(ost->ost_create_service);
2001 ost->ost_create_service = NULL;
2003 ptlrpc_unregister_service(ost->ost_service);
2004 ost->ost_service = NULL;
2006 lprocfs_obd_cleanup(obd);
2010 static int ost_cleanup(struct obd_device *obd)
2012 struct ost_obd *ost = &obd->u.ost;
2016 ping_evictor_stop();
2018 spin_lock_bh(&obd->obd_processing_task_lock);
2019 if (obd->obd_recovering) {
2020 target_cancel_recovery_timer(obd);
2021 obd->obd_recovering = 0;
2023 spin_unlock_bh(&obd->obd_processing_task_lock);
2025 down(&ost->ost_health_sem);
2026 ptlrpc_unregister_service(ost->ost_service);
2027 ptlrpc_unregister_service(ost->ost_create_service);
2028 ptlrpc_unregister_service(ost->ost_io_service);
2029 ost->ost_service = NULL;
2030 ost->ost_create_service = NULL;
2031 up(&ost->ost_health_sem);
2033 lprocfs_obd_cleanup(obd);
2038 static int ost_health_check(struct obd_device *obd)
2040 struct ost_obd *ost = &obd->u.ost;
2043 down(&ost->ost_health_sem);
2044 rc |= ptlrpc_service_health_check(ost->ost_service);
2045 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2046 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2047 up(&ost->ost_health_sem);
2050 * health_check to return 0 on healthy
2051 * and 1 on unhealthy.
2059 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2061 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2064 /* use obd ops to offer management infrastructure */
2065 static struct obd_ops ost_obd_ops = {
2066 .o_owner = THIS_MODULE,
2067 .o_setup = ost_setup,
2068 .o_cleanup = ost_cleanup,
2069 .o_health_check = ost_health_check,
2073 static int __init ost_init(void)
2075 struct lprocfs_static_vars lvars;
2079 lprocfs_ost_init_vars(&lvars);
2080 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2081 LUSTRE_OSS_NAME, NULL);
2083 if (ost_num_threads != 0 && oss_num_threads == 0) {
2084 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2085 "use oss_num_threads instead or unset both for "
2086 "dynamic thread startup\n");
2087 oss_num_threads = ost_num_threads;
2093 static void /*__exit*/ ost_exit(void)
2095 class_unregister_type(LUSTRE_OSS_NAME);
2098 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2099 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2100 MODULE_LICENSE("GPL");
2102 module_init(ost_init);
2103 module_exit(ost_exit);