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 ost_num_threads;
55 CFS_MODULE_PARM(ost_num_threads, "i", int, 0444,
56 "number of OST service threads to start");
58 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
60 struct oti_req_ack_lock *ack_lock;
67 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
68 req->rq_transno = oti->oti_transno;
70 /* XXX 4 == entries in oti_ack_locks??? */
71 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
74 /* XXX not even calling target_send_reply in some cases... */
75 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode);
79 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
80 struct obd_trans_info *oti)
82 struct ost_body *body, *repbody;
83 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
86 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
87 lustre_swab_ost_body);
91 rc = lustre_pack_reply(req, 2, size, NULL);
95 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
96 oti->oti_logcookies = obdo_logcookie(&body->oa);
97 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
99 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
100 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL);
104 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
106 struct ost_body *body, *repbody;
107 struct obd_info oinfo = { { { 0 } } };
108 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
111 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
112 lustre_swab_ost_body);
116 rc = lustre_pack_reply(req, 2, size, NULL);
120 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
122 repbody->oa = body->oa;
124 oinfo.oi_oa = &repbody->oa;
125 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
126 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
128 req->rq_status = obd_getattr(exp, &oinfo);
132 static int ost_statfs(struct ptlrpc_request *req)
134 struct obd_statfs *osfs;
135 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*osfs) };
138 rc = lustre_pack_reply(req, 2, size, NULL);
142 osfs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*osfs));
144 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
145 cfs_time_current_64() - HZ);
146 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
147 osfs->os_bfree = osfs->os_bavail = 64;
148 if (req->rq_status != 0)
149 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
154 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
155 struct obd_trans_info *oti)
157 struct ost_body *body, *repbody;
158 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
161 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
162 lustre_swab_ost_body);
166 rc = lustre_pack_reply(req, 2, size, NULL);
170 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
172 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
173 oti->oti_logcookies = obdo_logcookie(&repbody->oa);
174 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
175 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
180 * Helper function for ost_punch(): if asked by client, acquire [size, EOF]
181 * lock on the file being truncated.
183 static int ost_punch_lock_get(struct obd_export *exp, struct obdo *oa,
184 struct lustre_handle *lh)
187 struct ldlm_res_id res_id = { .name = { oa->o_id, 0, oa->o_gr, 0} };
188 ldlm_policy_data_t policy;
194 LASSERT(!lustre_handle_is_used(lh));
196 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
197 !(oa->o_flags & OBD_FL_TRUNCLOCK))
200 CDEBUG(D_INODE, "OST-side truncate lock.\n");
203 finis = start + oa->o_blocks;
206 * standard truncate optimization: if file body is completely
207 * destroyed, don't send data back to the server.
209 flags = (start == 0) ? LDLM_AST_DISCARD_DATA : 0;
211 policy.l_extent.start = start & CFS_PAGE_MASK;
214 * If ->o_blocks is EOF it means "lock till the end of the
215 * file". Otherwise, it's size of a hole being punched (in bytes)
217 if (oa->o_blocks == OBD_OBJECT_EOF || finis < start)
218 policy.l_extent.end = OBD_OBJECT_EOF;
220 policy.l_extent.end = finis | ~CFS_PAGE_MASK;
222 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
223 LDLM_EXTENT, &policy, LCK_PW, &flags,
224 ldlm_blocking_ast, ldlm_completion_ast,
225 ldlm_glimpse_ast, NULL, 0, NULL, lh));
229 * Helper function for ost_punch(): release lock acquired by
230 * ost_punch_lock_get(), if any.
232 static void ost_punch_lock_put(struct obd_export *exp, struct obdo *oa,
233 struct lustre_handle *lh)
236 if (lustre_handle_is_used(lh))
237 ldlm_lock_decref(lh, LCK_PW);
241 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
242 struct obd_trans_info *oti)
244 struct obd_info oinfo = { { { 0 } } };
245 struct ost_body *body, *repbody;
246 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
247 struct lustre_handle lh = {0,};
250 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
251 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
253 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
254 lustre_swab_ost_body);
258 oinfo.oi_oa = &body->oa;
259 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
260 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
262 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
263 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
266 rc = lustre_pack_reply(req, 2, size, NULL);
270 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
272 repbody->oa = *oinfo.oi_oa;
273 rc = ost_punch_lock_get(exp, oinfo.oi_oa, &lh);
275 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
276 oinfo.oi_oa->o_flags == OBD_FL_TRUNCLOCK)
278 * If OBD_FL_TRUNCLOCK is the only bit set in
279 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
280 * through filter_setattr() to filter_iocontrol().
282 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
284 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
285 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
287 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
288 ost_punch_lock_put(exp, oinfo.oi_oa, &lh);
293 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
295 struct ost_body *body, *repbody;
296 struct lustre_capa *capa = NULL;
297 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
300 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
301 lustre_swab_ost_body);
305 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
306 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 1);
308 rc = lustre_pack_reply(req, 2, size, NULL);
312 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
314 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
315 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
316 repbody->oa.o_blocks, capa);
320 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
321 struct obd_trans_info *oti)
323 struct ost_body *body, *repbody;
324 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
325 struct obd_info oinfo = { { { 0 } } };
328 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
329 lustre_swab_ost_body);
333 rc = lustre_pack_reply(req, 2, size, NULL);
337 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
339 repbody->oa = body->oa;
341 oinfo.oi_oa = &repbody->oa;
342 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
343 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
345 req->rq_status = obd_setattr(exp, &oinfo, oti);
349 static int ost_bulk_timeout(void *data)
352 /* We don't fail the connection here, because having the export
353 * killed makes the (vital) call to commitrw very sad.
358 static int get_per_page_niobufs(struct obd_ioobj *ioo, int nioo,
359 struct niobuf_remote *rnb, int nrnb,
360 struct niobuf_remote **pp_rnbp)
362 /* Copy a remote niobuf, splitting it into page-sized chunks
363 * and setting ioo[i].ioo_bufcnt accordingly */
364 struct niobuf_remote *pp_rnb;
372 * array of sufficient size already preallocated by caller
374 LASSERT(pp_rnbp != NULL);
375 LASSERT(*pp_rnbp != NULL);
377 /* first count and check the number of pages required */
378 for (i = 0; i < nioo; i++)
379 for (j = 0; j < ioo->ioo_bufcnt; j++, rnbidx++) {
380 obd_off offset = rnb[rnbidx].offset;
381 obd_off p0 = offset >> PAGE_SHIFT;
382 obd_off pn = (offset + rnb[rnbidx].len - 1)>>PAGE_SHIFT;
384 LASSERT(rnbidx < nrnb);
386 npages += (pn + 1 - p0);
388 if (rnb[rnbidx].len == 0) {
389 CERROR("zero len BRW: obj %d objid "LPX64
390 " buf %u\n", i, ioo[i].ioo_id, j);
394 rnb[rnbidx].offset <= rnb[rnbidx-1].offset) {
395 CERROR("unordered BRW: obj %d objid "LPX64
396 " buf %u offset "LPX64" <= "LPX64"\n",
397 i, ioo[i].ioo_id, j, rnb[rnbidx].offset,
403 LASSERT(rnbidx == nrnb);
405 if (npages == nrnb) { /* all niobufs are for single pages */
412 /* now do the actual split */
414 for (i = 0; i < nioo; i++) {
417 for (j = 0; j < ioo[i].ioo_bufcnt; j++, rnbidx++) {
418 obd_off off = rnb[rnbidx].offset;
419 int nob = rnb[rnbidx].len;
421 LASSERT(rnbidx < nrnb);
423 obd_off poff = off & (PAGE_SIZE - 1);
424 int pnob = (poff + nob > PAGE_SIZE) ?
425 PAGE_SIZE - poff : nob;
427 LASSERT(page < npages);
428 pp_rnb[page].len = pnob;
429 pp_rnb[page].offset = off;
430 pp_rnb[page].flags = rnb[rnbidx].flags;
432 CDEBUG(0, " obj %d id "LPX64
433 "page %d(%d) "LPX64" for %d, flg %x\n",
434 i, ioo[i].ioo_id, obj_pages, page,
435 pp_rnb[page].offset, pp_rnb[page].len,
445 ioo[i].ioo_bufcnt = obj_pages;
447 LASSERT(page == npages);
452 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc)
457 for (i = 0; i < desc->bd_iov_count; i++) {
458 struct page *page = desc->bd_iov[i].kiov_page;
459 int off = desc->bd_iov[i].kiov_offset & ~PAGE_MASK;
460 char *ptr = kmap(page) + off;
461 int len = desc->bd_iov[i].kiov_len;
463 cksum = crc32_le(cksum, ptr, len);
470 * populate @nio by @nrpages pages from per-thread page pool
472 static void ost_nio_pages_get(struct ptlrpc_request *req,
473 struct niobuf_local *nio, int nrpages)
476 struct ost_thread_local_cache *tls;
480 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
481 LASSERT(req != NULL);
482 LASSERT(req->rq_svc_thread != NULL);
485 LASSERT(tls != NULL);
487 memset(nio, 0, nrpages * sizeof *nio);
488 for (i = 0; i < nrpages; ++ i) {
492 LASSERT(page != NULL);
493 POISON_PAGE(page, 0xf1);
495 LL_CDEBUG_PAGE(D_INFO, page, "%d\n", i);
501 * Dual for ost_nio_pages_get(). Poison pages in pool for debugging
503 static void ost_nio_pages_put(struct ptlrpc_request *req,
504 struct niobuf_local *nio, int nrpages)
510 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
512 for (i = 0; i < nrpages; ++ i)
513 POISON_PAGE(nio[i].page, 0xf2);
517 static int ost_brw_lock_get(int mode, struct obd_export *exp,
518 struct obd_ioobj *obj, struct niobuf_remote *nb,
519 struct lustre_handle *lh)
522 int nrbufs = obj->ioo_bufcnt;
523 struct ldlm_res_id res_id = { .name = { obj->ioo_id, 0,
525 ldlm_policy_data_t policy;
530 LASSERT(mode == LCK_PR || mode == LCK_PW);
531 LASSERT(!lustre_handle_is_used(lh));
533 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
536 /* EXPENSIVE ASSERTION */
537 for (i = 1; i < nrbufs; i ++)
538 LASSERT((nb[0].flags & OBD_BRW_SRVLOCK) ==
539 (nb[i].flags & OBD_BRW_SRVLOCK));
541 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
542 policy.l_extent.end = (nb[nrbufs - 1].offset +
543 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
545 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
546 LDLM_EXTENT, &policy, mode, &flags,
547 ldlm_blocking_ast, ldlm_completion_ast,
548 ldlm_glimpse_ast, NULL, 0, NULL, lh));
551 static void ost_brw_lock_put(int mode,
552 struct obd_ioobj *obj, struct niobuf_remote *niob,
553 struct lustre_handle *lh)
556 LASSERT(mode == LCK_PR || mode == LCK_PW);
557 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
558 lustre_handle_is_used(lh));
559 if (lustre_handle_is_used(lh))
560 ldlm_lock_decref(lh, mode);
564 struct ost_prolong_data {
565 struct obd_export *opd_exp;
566 ldlm_policy_data_t opd_policy;
567 ldlm_mode_t opd_mode;
570 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
572 struct ost_prolong_data *opd = data;
574 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
576 if (lock->l_req_mode != lock->l_granted_mode) {
577 /* scan granted locks only */
578 return LDLM_ITER_STOP;
581 if (lock->l_export != opd->opd_exp) {
582 /* prolong locks only for given client */
583 return LDLM_ITER_CONTINUE;
586 if (!(lock->l_granted_mode & opd->opd_mode)) {
587 /* we aren't interesting in all type of locks */
588 return LDLM_ITER_CONTINUE;
591 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
592 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
593 /* the request doesn't cross the lock, skip it */
594 return LDLM_ITER_CONTINUE;
597 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
598 /* ignore locks not being cancelled */
599 return LDLM_ITER_CONTINUE;
602 /* OK. this is a possible lock the user holds doing I/O
603 * let's refresh eviction timer for it */
604 ldlm_refresh_waiting_lock(lock);
606 return LDLM_ITER_CONTINUE;
609 static void ost_prolong_locks(struct obd_export *exp, struct obd_ioobj *obj,
610 struct niobuf_remote *nb, ldlm_mode_t mode)
612 struct ldlm_res_id res_id = { .name = { obj->ioo_id, 0,
614 int nrbufs = obj->ioo_bufcnt;
615 struct ost_prolong_data opd;
621 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
622 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
623 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
625 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
626 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
627 opd.opd_policy.l_extent.end);
628 ldlm_resource_iterate(exp->exp_obd->obd_namespace, &res_id,
629 ost_prolong_locks_iter, &opd);
632 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
634 struct ptlrpc_bulk_desc *desc;
635 struct niobuf_remote *remote_nb;
636 struct niobuf_remote *pp_rnb = NULL;
637 struct niobuf_local *local_nb;
638 struct obd_ioobj *ioo;
639 struct ost_body *body, *repbody;
640 struct lustre_capa *capa = NULL;
641 struct l_wait_info lwi;
642 struct lustre_handle lockh = { 0 };
643 int size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
644 int comms_error = 0, niocount, npages, nob = 0, rc, i, do_checksum;
647 req->rq_bulk_read = 1;
649 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
650 GOTO(out, rc = -EIO);
652 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
653 (obd_timeout + 1) / 4);
655 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
656 lustre_swab_ost_body);
658 CERROR("Missing/short ost_body\n");
659 GOTO(out, rc = -EFAULT);
662 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*ioo),
663 lustre_swab_obd_ioobj);
665 CERROR("Missing/short ioobj\n");
666 GOTO(out, rc = -EFAULT);
669 niocount = ioo->ioo_bufcnt;
670 if (niocount > PTLRPC_MAX_BRW_PAGES) {
671 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)\n",
673 GOTO(out, rc = -EFAULT);
676 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
677 niocount * sizeof(*remote_nb),
678 lustre_swab_niobuf_remote);
679 if (remote_nb == NULL) {
680 CERROR("Missing/short niobuf\n");
681 GOTO(out, rc = -EFAULT);
683 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
684 for (i = 1; i < niocount; i++)
685 lustre_swab_niobuf_remote (&remote_nb[i]);
688 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
689 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
691 rc = lustre_pack_reply(req, 2, size, NULL);
696 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
699 local_nb = ost_tls(req)->local;
700 pp_rnb = ost_tls(req)->remote;
702 /* FIXME all niobuf splitting should be done in obdfilter if needed */
703 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
704 npages = get_per_page_niobufs(ioo, 1, remote_nb, niocount, &pp_rnb);
706 GOTO(out, rc = npages);
708 LASSERT(npages <= OST_THREAD_POOL_SIZE);
710 ost_nio_pages_get(req, local_nb, npages);
712 desc = ptlrpc_prep_bulk_exp(req, npages,
713 BULK_PUT_SOURCE, OST_BULK_PORTAL);
715 GOTO(out, rc = -ENOMEM);
717 rc = ost_brw_lock_get(LCK_PR, req->rq_export, ioo, pp_rnb, &lockh);
721 rc = obd_preprw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
722 ioo, npages, pp_rnb, local_nb, oti, capa);
726 ost_prolong_locks(req->rq_export, ioo, pp_rnb, LCK_PW | LCK_PR);
728 /* We're finishing using body->oa as an input variable */
729 do_checksum = (body->oa.o_valid & OBD_MD_FLCKSUM);
730 body->oa.o_valid = 0;
733 for (i = 0; i < npages; i++) {
734 int page_rc = local_nb[i].rc;
736 if (page_rc < 0) { /* error */
741 LASSERTF(page_rc <= pp_rnb[i].len, "page_rc (%d) > "
742 "pp_rnb[%d].len (%d)\n", page_rc, i, pp_rnb[i].len);
744 if (page_rc != 0) { /* some data! */
745 LASSERT (local_nb[i].page != NULL);
746 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
747 pp_rnb[i].offset & (PAGE_SIZE-1),
751 if (page_rc != pp_rnb[i].len) { /* short read */
752 /* All subsequent pages should be 0 */
754 LASSERT(local_nb[i].rc == 0);
759 /* Check if client was evicted while we were doing i/o before touching
762 if (desc->bd_export->exp_failed)
765 sptlrpc_svc_wrap_bulk(req, desc);
767 rc = ptlrpc_start_bulk_transfer(desc);
771 lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 4, HZ,
772 ost_bulk_timeout, desc);
773 rc = l_wait_event(desc->bd_waitq,
774 !ptlrpc_bulk_active(desc) ||
775 desc->bd_export->exp_failed, &lwi);
776 LASSERT(rc == 0 || rc == -ETIMEDOUT);
777 if (rc == -ETIMEDOUT) {
778 DEBUG_REQ(D_ERROR, req, "timeout on bulk PUT");
779 ptlrpc_abort_bulk(desc);
780 } else if (desc->bd_export->exp_failed) {
781 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
783 ptlrpc_abort_bulk(desc);
784 } else if (!desc->bd_success ||
785 desc->bd_nob_transferred != desc->bd_nob) {
786 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
788 "truncated" : "network error on",
789 desc->bd_nob_transferred,
791 /* XXX should this be a different errno? */
795 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d\n", rc);
797 comms_error = rc != 0;
800 /* Must commit after prep above in all cases */
801 rc = obd_commitrw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
802 ioo, npages, local_nb, oti, rc);
804 ost_nio_pages_put(req, local_nb, npages);
807 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
809 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
811 if (unlikely(do_checksum)) {
812 repbody->oa.o_cksum = ost_checksum_bulk(desc);
813 repbody->oa.o_valid |= OBD_MD_FLCKSUM;
814 CDEBUG(D_PAGE, "checksum at read origin: %x\n",
815 repbody->oa.o_cksum);
820 ost_brw_lock_put(LCK_PR, ioo, pp_rnb, &lockh);
822 ptlrpc_free_bulk(desc);
826 req->rq_status = nob;
827 target_committed_to_req(req);
829 } else if (!comms_error) {
830 /* Only reply if there was no comms problem with bulk */
831 target_committed_to_req(req);
835 if (req->rq_reply_state != NULL) {
836 /* reply out callback would free */
837 ptlrpc_rs_decref(req->rq_reply_state);
838 req->rq_reply_state = NULL;
840 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
841 "client will retry\n",
842 req->rq_export->exp_obd->obd_name,
843 req->rq_export->exp_client_uuid.uuid,
844 req->rq_export->exp_connection->c_remote_uuid.uuid,
845 libcfs_id2str(req->rq_peer));
851 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
853 struct ptlrpc_bulk_desc *desc;
854 struct niobuf_remote *remote_nb;
855 struct niobuf_remote *pp_rnb;
856 struct niobuf_local *local_nb;
857 struct obd_ioobj *ioo;
858 struct ost_body *body, *repbody;
859 struct l_wait_info lwi;
860 struct lustre_handle lockh = {0};
861 struct lustre_capa *capa = NULL;
863 int size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
864 int objcount, niocount, npages, comms_error = 0;
865 int rc, swab, i, j, do_checksum;
868 req->rq_bulk_write = 1;
870 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
871 GOTO(out, rc = -EIO);
873 /* pause before transaction has been started */
874 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
875 (obd_timeout + 1) / 4);
877 swab = lustre_msg_swabbed(req->rq_reqmsg);
878 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
879 lustre_swab_ost_body);
881 CERROR("Missing/short ost_body\n");
882 GOTO(out, rc = -EFAULT);
885 LASSERT_REQSWAB(req, REQ_REC_OFF + 1);
886 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
889 CERROR("Missing/short ioobj\n");
890 GOTO(out, rc = -EFAULT);
893 CERROR("too many ioobjs (%d)\n", objcount);
894 GOTO(out, rc = -EFAULT);
897 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
898 objcount * sizeof(*ioo));
899 LASSERT (ioo != NULL);
900 for (niocount = i = 0; i < objcount; i++) {
902 lustre_swab_obd_ioobj(&ioo[i]);
903 if (ioo[i].ioo_bufcnt == 0) {
904 CERROR("ioo[%d] has zero bufcnt\n", i);
905 GOTO(out, rc = -EFAULT);
907 niocount += ioo[i].ioo_bufcnt;
910 if (niocount > PTLRPC_MAX_BRW_PAGES) {
911 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)\n",
913 GOTO(out, rc = -EFAULT);
916 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
917 niocount * sizeof(*remote_nb),
918 lustre_swab_niobuf_remote);
919 if (remote_nb == NULL) {
920 CERROR("Missing/short niobuf\n");
921 GOTO(out, rc = -EFAULT);
923 if (swab) { /* swab the remaining niobufs */
924 for (i = 1; i < niocount; i++)
925 lustre_swab_niobuf_remote (&remote_nb[i]);
928 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
929 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
931 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
932 rc = lustre_pack_reply(req, 3, size, NULL);
935 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
936 niocount * sizeof(*rcs));
939 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
942 local_nb = ost_tls(req)->local;
943 pp_rnb = ost_tls(req)->remote;
945 /* FIXME all niobuf splitting should be done in obdfilter if needed */
946 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
947 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
949 GOTO(out, rc = npages);
951 LASSERT(npages <= OST_THREAD_POOL_SIZE);
953 ost_nio_pages_get(req, local_nb, npages);
955 desc = ptlrpc_prep_bulk_exp(req, npages,
956 BULK_GET_SINK, OST_BULK_PORTAL);
958 GOTO(out, rc = -ENOMEM);
960 rc = ost_brw_lock_get(LCK_PW, req->rq_export, ioo, pp_rnb, &lockh);
964 ost_prolong_locks(req->rq_export, ioo, pp_rnb, LCK_PW);
966 /* obd_preprw clobbers oa->valid, so save what we need */
967 do_checksum = (body->oa.o_valid & OBD_MD_FLCKSUM);
969 rc = obd_preprw(OBD_BRW_WRITE, req->rq_export, &body->oa, objcount,
970 ioo, npages, pp_rnb, local_nb, oti, capa);
974 /* NB Having prepped, we must commit... */
976 for (i = 0; i < npages; i++)
977 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
978 pp_rnb[i].offset & (PAGE_SIZE - 1),
981 /* Check if client was evicted while we were doing i/o before touching
983 if (desc->bd_export->exp_failed)
986 rc = ptlrpc_start_bulk_transfer (desc);
988 lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 4, HZ,
989 ost_bulk_timeout, desc);
990 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
991 desc->bd_export->exp_failed, &lwi);
992 LASSERT(rc == 0 || rc == -ETIMEDOUT);
993 if (rc == -ETIMEDOUT) {
994 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
995 ptlrpc_abort_bulk(desc);
996 } else if (desc->bd_export->exp_failed) {
997 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
999 ptlrpc_abort_bulk(desc);
1000 } else if (!desc->bd_success ||
1001 desc->bd_nob_transferred != desc->bd_nob) {
1002 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1004 "truncated" : "network error on",
1005 desc->bd_nob_transferred, desc->bd_nob);
1006 /* XXX should this be a different errno? */
1010 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d\n", rc);
1012 comms_error = rc != 0;
1014 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1016 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1018 if (unlikely(do_checksum && rc == 0)) {
1019 static int cksum_counter;
1020 obd_count client_cksum = body->oa.o_cksum;
1021 obd_count cksum = ost_checksum_bulk(desc);
1024 if (client_cksum != cksum) {
1025 CERROR("Bad checksum: client %x, server %x id %s\n",
1026 client_cksum, cksum,
1027 libcfs_id2str(req->rq_peer));
1029 repbody->oa.o_cksum = cksum;
1030 repbody->oa.o_valid |= OBD_MD_FLCKSUM;
1031 } else if ((cksum_counter & (-cksum_counter)) ==
1033 CWARN("Checksum %u from %s: %x OK\n", cksum_counter,
1034 libcfs_id2str(req->rq_peer), cksum);
1037 if ((cksum_counter & (-cksum_counter)) == cksum_counter)
1038 CWARN("Checksum %u from %s: %x OK\n",
1040 libcfs_id2str(req->rq_peer), cksum);
1044 sptlrpc_svc_unwrap_bulk(req, desc);
1046 /* Must commit after prep above in all cases */
1047 rc = obd_commitrw(OBD_BRW_WRITE, req->rq_export, &repbody->oa,
1048 objcount, ioo, npages, local_nb, oti, rc);
1050 ost_nio_pages_put(req, local_nb, npages);
1053 /* set per-requested niobuf return codes */
1054 for (i = j = 0; i < niocount; i++) {
1055 int nob = remote_nb[i].len;
1059 LASSERT(j < npages);
1060 if (local_nb[j].rc < 0)
1061 rcs[i] = local_nb[j].rc;
1062 nob -= pp_rnb[j].len;
1067 LASSERT(j == npages);
1071 ost_brw_lock_put(LCK_PW, ioo, pp_rnb, &lockh);
1073 ptlrpc_free_bulk(desc);
1076 oti_to_request(oti, req);
1077 target_committed_to_req(req);
1078 rc = ptlrpc_reply(req);
1079 } else if (!comms_error) {
1080 /* Only reply if there was no comms problem with bulk */
1081 target_committed_to_req(req);
1082 req->rq_status = rc;
1085 if (req->rq_reply_state != NULL) {
1086 /* reply out callback would free */
1087 ptlrpc_rs_decref(req->rq_reply_state);
1088 req->rq_reply_state = NULL;
1090 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1091 "client will retry\n",
1092 req->rq_export->exp_obd->obd_name,
1093 req->rq_export->exp_client_uuid.uuid,
1094 req->rq_export->exp_connection->c_remote_uuid.uuid,
1095 libcfs_id2str(req->rq_peer));
1100 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1102 char *key, *val = NULL;
1103 int keylen, vallen, rc = 0;
1106 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1108 DEBUG_REQ(D_HA, req, "no set_info key");
1111 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1113 rc = lustre_pack_reply(req, 1, NULL, NULL);
1117 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1119 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
1121 if (KEY_IS("evict_by_nid")) {
1123 obd_export_evict_by_nid(exp->exp_obd, val);
1128 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1130 lustre_msg_set_status(req->rq_repmsg, 0);
1134 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1138 int size[2] = { sizeof(struct ptlrpc_body), sizeof(obd_id) };
1142 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1144 DEBUG_REQ(D_HA, req, "no get_info key");
1147 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1149 if (keylen < strlen("last_id") || memcmp(key, "last_id", 7) != 0)
1152 rc = lustre_pack_reply(req, 2, size, NULL);
1156 reply = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*reply));
1157 rc = obd_get_info(exp, keylen, key, size, reply);
1158 lustre_msg_set_status(req->rq_repmsg, 0);
1162 static int ost_handle_quotactl(struct ptlrpc_request *req)
1164 struct obd_quotactl *oqctl, *repoqc;
1165 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) };
1168 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1169 lustre_swab_obd_quotactl);
1171 GOTO(out, rc = -EPROTO);
1173 rc = lustre_pack_reply(req, 2, size, NULL);
1177 repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc));
1179 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1185 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1187 struct obd_quotactl *oqctl;
1191 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1192 lustre_swab_obd_quotactl);
1196 rc = lustre_pack_reply(req, 1, NULL, NULL);
1198 CERROR("ost: out of memory while packing quotacheck reply\n");
1202 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1206 static int ost_llog_handle_connect(struct obd_export *exp,
1207 struct ptlrpc_request *req)
1209 struct llogd_conn_body *body;
1213 body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body));
1214 rc = obd_llog_connect(exp, body);
1219 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1220 struct obd_device *obd, int *process)
1222 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1223 case OST_CONNECT: /* This will never get here, but for completeness. */
1224 case OST_DISCONNECT:
1235 case OBD_LOG_CANCEL:
1237 *process = target_queue_recovery_request(req, obd);
1241 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1243 /* XXX what should we set rq_status to here? */
1244 req->rq_status = -EAGAIN;
1245 RETURN(ptlrpc_error(req));
1249 int ost_msg_check_version(struct lustre_msg *msg)
1253 switch(lustre_msg_get_opc(msg)) {
1255 case OST_DISCONNECT:
1258 case SEC_CTX_INIT_CONT:
1260 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1262 CERROR("bad opc %u version %08x, expecting %08x\n",
1263 lustre_msg_get_opc(msg),
1264 lustre_msg_get_version(msg),
1265 LUSTRE_OBD_VERSION);
1278 case OST_QUOTACHECK:
1280 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1282 CERROR("bad opc %u version %08x, expecting %08x\n",
1283 lustre_msg_get_opc(msg),
1284 lustre_msg_get_version(msg),
1285 LUSTRE_OST_VERSION);
1290 case LDLM_BL_CALLBACK:
1291 case LDLM_CP_CALLBACK:
1292 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1294 CERROR("bad opc %u version %08x, expecting %08x\n",
1295 lustre_msg_get_opc(msg),
1296 lustre_msg_get_version(msg),
1297 LUSTRE_DLM_VERSION);
1299 case LLOG_ORIGIN_CONNECT:
1300 case OBD_LOG_CANCEL:
1301 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1303 CERROR("bad opc %u version %08x, expecting %08x\n",
1304 lustre_msg_get_opc(msg),
1305 lustre_msg_get_version(msg),
1306 LUSTRE_LOG_VERSION);
1309 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1315 int ost_handle(struct ptlrpc_request *req)
1317 struct obd_trans_info trans_info = { 0, };
1318 struct obd_trans_info *oti = &trans_info;
1319 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1320 struct obd_device *obd = NULL;
1323 LASSERT(current->journal_info == NULL);
1325 /* primordial rpcs don't affect server recovery */
1326 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1328 case SEC_CTX_INIT_CONT:
1333 /* XXX identical to MDS */
1334 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1337 if (req->rq_export == NULL) {
1338 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1339 lustre_msg_get_opc(req->rq_reqmsg),
1340 libcfs_id2str(req->rq_peer));
1341 req->rq_status = -ENOTCONN;
1342 GOTO(out, rc = -ENOTCONN);
1345 obd = req->rq_export->exp_obd;
1347 /* Check for aborted recovery. */
1348 spin_lock_bh(&obd->obd_processing_task_lock);
1349 recovering = obd->obd_recovering;
1350 spin_unlock_bh(&obd->obd_processing_task_lock);
1352 rc = ost_filter_recovery_request(req, obd,
1354 if (rc || !should_process)
1356 else if (should_process < 0) {
1357 req->rq_status = should_process;
1358 rc = ptlrpc_error(req);
1365 rc = ost_msg_check_version(req->rq_reqmsg);
1369 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1371 CDEBUG(D_INODE, "connect\n");
1372 OBD_FAIL_RETURN(OBD_FAIL_OST_CONNECT_NET, 0);
1373 rc = target_handle_connect(req);
1375 obd = req->rq_export->exp_obd;
1378 case OST_DISCONNECT:
1379 CDEBUG(D_INODE, "disconnect\n");
1380 OBD_FAIL_RETURN(OBD_FAIL_OST_DISCONNECT_NET, 0);
1381 rc = target_handle_disconnect(req);
1384 CDEBUG(D_INODE, "create\n");
1385 OBD_FAIL_RETURN(OBD_FAIL_OST_CREATE_NET, 0);
1386 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
1387 GOTO(out, rc = -ENOSPC);
1388 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1389 GOTO(out, rc = -EROFS);
1390 rc = ost_create(req->rq_export, req, oti);
1393 CDEBUG(D_INODE, "destroy\n");
1394 OBD_FAIL_RETURN(OBD_FAIL_OST_DESTROY_NET, 0);
1395 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1396 GOTO(out, rc = -EROFS);
1397 rc = ost_destroy(req->rq_export, req, oti);
1400 CDEBUG(D_INODE, "getattr\n");
1401 OBD_FAIL_RETURN(OBD_FAIL_OST_GETATTR_NET, 0);
1402 rc = ost_getattr(req->rq_export, req);
1405 CDEBUG(D_INODE, "setattr\n");
1406 OBD_FAIL_RETURN(OBD_FAIL_OST_SETATTR_NET, 0);
1407 rc = ost_setattr(req->rq_export, req, oti);
1410 CDEBUG(D_INODE, "write\n");
1411 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1412 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
1413 GOTO(out, rc = -ENOSPC);
1414 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1415 GOTO(out, rc = -EROFS);
1416 rc = ost_brw_write(req, oti);
1417 LASSERT(current->journal_info == NULL);
1418 /* ost_brw_write sends its own replies */
1421 CDEBUG(D_INODE, "read\n");
1422 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1423 rc = ost_brw_read(req, oti);
1424 LASSERT(current->journal_info == NULL);
1425 /* ost_brw_read sends its own replies */
1428 CDEBUG(D_INODE, "punch\n");
1429 OBD_FAIL_RETURN(OBD_FAIL_OST_PUNCH_NET, 0);
1430 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1431 GOTO(out, rc = -EROFS);
1432 rc = ost_punch(req->rq_export, req, oti);
1435 CDEBUG(D_INODE, "statfs\n");
1436 OBD_FAIL_RETURN(OBD_FAIL_OST_STATFS_NET, 0);
1437 rc = ost_statfs(req);
1440 CDEBUG(D_INODE, "sync\n");
1441 OBD_FAIL_RETURN(OBD_FAIL_OST_SYNC_NET, 0);
1442 rc = ost_sync(req->rq_export, req);
1445 DEBUG_REQ(D_INODE, req, "set_info");
1446 rc = ost_set_info(req->rq_export, req);
1449 DEBUG_REQ(D_INODE, req, "get_info");
1450 rc = ost_get_info(req->rq_export, req);
1452 case OST_QUOTACHECK:
1453 CDEBUG(D_INODE, "quotacheck\n");
1454 OBD_FAIL_RETURN(OBD_FAIL_OST_QUOTACHECK_NET, 0);
1455 rc = ost_handle_quotacheck(req);
1458 CDEBUG(D_INODE, "quotactl\n");
1459 OBD_FAIL_RETURN(OBD_FAIL_OST_QUOTACTL_NET, 0);
1460 rc = ost_handle_quotactl(req);
1463 DEBUG_REQ(D_INODE, req, "ping");
1464 rc = target_handle_ping(req);
1466 /* FIXME - just reply status */
1467 case LLOG_ORIGIN_CONNECT:
1468 DEBUG_REQ(D_INODE, req, "log connect\n");
1469 rc = ost_llog_handle_connect(req->rq_export, req);
1470 req->rq_status = rc;
1471 rc = lustre_pack_reply(req, 1, NULL, NULL);
1474 RETURN(ptlrpc_reply(req));
1475 case OBD_LOG_CANCEL:
1476 CDEBUG(D_INODE, "log cancel\n");
1477 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
1478 rc = llog_origin_handle_cancel(req);
1479 req->rq_status = rc;
1480 rc = lustre_pack_reply(req, 1, NULL, NULL);
1483 RETURN(ptlrpc_reply(req));
1485 CDEBUG(D_INODE, "enqueue\n");
1486 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
1487 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1488 ldlm_server_blocking_ast,
1489 ldlm_server_glimpse_ast);
1490 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1493 CDEBUG(D_INODE, "convert\n");
1494 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
1495 rc = ldlm_handle_convert(req);
1498 CDEBUG(D_INODE, "cancel\n");
1499 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CANCEL, 0);
1500 rc = ldlm_handle_cancel(req);
1502 case LDLM_BL_CALLBACK:
1503 case LDLM_CP_CALLBACK:
1504 CDEBUG(D_INODE, "callback\n");
1505 CERROR("callbacks should not happen on OST\n");
1508 CERROR("Unexpected opcode %d\n",
1509 lustre_msg_get_opc(req->rq_reqmsg));
1510 req->rq_status = -ENOTSUPP;
1511 rc = ptlrpc_error(req);
1515 LASSERT(current->journal_info == NULL);
1518 /* If we're DISCONNECTing, the export_data is already freed */
1519 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
1520 target_committed_to_req(req);
1524 oti_to_request(oti, req);
1526 target_send_reply(req, rc, fail);
1529 EXPORT_SYMBOL(ost_handle);
1531 * free per-thread pool created by ost_thread_init().
1533 static void ost_thread_done(struct ptlrpc_thread *thread)
1536 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
1541 LASSERT(thread != NULL);
1544 * be prepared to handle partially-initialized pools (because this is
1545 * called from ost_thread_init() for cleanup.
1547 tls = thread->t_data;
1549 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1550 if (tls->page[i] != NULL)
1551 __free_page(tls->page[i]);
1554 thread->t_data = NULL;
1560 * initialize per-thread page pool (bug 5137).
1562 static int ost_thread_init(struct ptlrpc_thread *thread)
1566 struct ost_thread_local_cache *tls;
1570 LASSERT(thread != NULL);
1571 LASSERT(thread->t_data == NULL);
1572 LASSERT(thread->t_id < OST_MAX_THREADS);
1577 thread->t_data = tls;
1581 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1582 tls->page[i] = alloc_page(OST_THREAD_POOL_GFP);
1583 if (tls->page[i] == NULL) {
1584 ost_thread_done(thread);
1594 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
1596 struct ost_obd *ost = &obd->u.ost;
1597 struct lprocfs_static_vars lvars;
1601 rc = cleanup_group_info();
1605 rc = llog_start_commit_thread();
1609 lprocfs_init_vars(ost, &lvars);
1610 lprocfs_obd_setup(obd, lvars.obd_vars);
1612 sema_init(&ost->ost_health_sem, 1);
1614 if (ost_num_threads < 2)
1615 ost_num_threads = OST_DEF_THREADS;
1616 if (ost_num_threads > OST_MAX_THREADS)
1617 ost_num_threads = OST_MAX_THREADS;
1620 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1621 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
1623 obd_timeout * 1000, ost_handle, LUSTRE_OSS_NAME,
1624 obd->obd_proc_entry, ost_print_req,
1625 ost_num_threads, LCT_DT_THREAD);
1626 if (ost->ost_service == NULL) {
1627 CERROR("failed to start service\n");
1628 GOTO(out_lprocfs, rc = -ENOMEM);
1631 rc = ptlrpc_start_threads(obd, ost->ost_service, "ll_ost");
1633 GOTO(out_service, rc = -EINVAL);
1635 ost->ost_create_service =
1636 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1637 OST_MAXREPSIZE, OST_CREATE_PORTAL,
1639 obd_timeout * 1000, ost_handle, "ost_create",
1640 obd->obd_proc_entry, ost_print_req, 1,
1642 if (ost->ost_create_service == NULL) {
1643 CERROR("failed to start OST create service\n");
1644 GOTO(out_service, rc = -ENOMEM);
1647 rc = ptlrpc_start_threads(obd, ost->ost_create_service,
1650 GOTO(out_create, rc = -EINVAL);
1652 ost->ost_io_service =
1653 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1654 OST_MAXREPSIZE, OST_IO_PORTAL,
1656 obd_timeout * 1000, ost_handle, "ost_io",
1657 obd->obd_proc_entry, ost_print_req,
1658 ost_num_threads, LCT_DT_THREAD);
1659 if (ost->ost_io_service == NULL) {
1660 CERROR("failed to start OST I/O service\n");
1661 GOTO(out_create, rc = -ENOMEM);
1664 ost->ost_io_service->srv_init = ost_thread_init;
1665 ost->ost_io_service->srv_done = ost_thread_done;
1666 ost->ost_io_service->srv_cpu_affinity = 1;
1667 rc = ptlrpc_start_threads(obd, ost->ost_io_service,
1670 GOTO(out_io, rc = -EINVAL);
1672 ping_evictor_start();
1677 ptlrpc_unregister_service(ost->ost_io_service);
1678 ost->ost_io_service = NULL;
1680 ptlrpc_unregister_service(ost->ost_create_service);
1681 ost->ost_create_service = NULL;
1683 ptlrpc_unregister_service(ost->ost_service);
1684 ost->ost_service = NULL;
1686 lprocfs_obd_cleanup(obd);
1690 static int ost_cleanup(struct obd_device *obd)
1692 struct ost_obd *ost = &obd->u.ost;
1696 ping_evictor_stop();
1698 spin_lock_bh(&obd->obd_processing_task_lock);
1699 if (obd->obd_recovering) {
1700 target_cancel_recovery_timer(obd);
1701 obd->obd_recovering = 0;
1703 spin_unlock_bh(&obd->obd_processing_task_lock);
1705 down(&ost->ost_health_sem);
1706 ptlrpc_unregister_service(ost->ost_service);
1707 ptlrpc_unregister_service(ost->ost_create_service);
1708 ptlrpc_unregister_service(ost->ost_io_service);
1709 ost->ost_service = NULL;
1710 ost->ost_create_service = NULL;
1711 up(&ost->ost_health_sem);
1713 lprocfs_obd_cleanup(obd);
1718 static int ost_health_check(struct obd_device *obd)
1720 struct ost_obd *ost = &obd->u.ost;
1723 down(&ost->ost_health_sem);
1724 rc |= ptlrpc_service_health_check(ost->ost_service);
1725 rc |= ptlrpc_service_health_check(ost->ost_create_service);
1726 rc |= ptlrpc_service_health_check(ost->ost_io_service);
1727 up(&ost->ost_health_sem);
1730 * health_check to return 0 on healthy
1731 * and 1 on unhealthy.
1739 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
1741 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
1744 /* use obd ops to offer management infrastructure */
1745 static struct obd_ops ost_obd_ops = {
1746 .o_owner = THIS_MODULE,
1747 .o_setup = ost_setup,
1748 .o_cleanup = ost_cleanup,
1749 .o_health_check = ost_health_check,
1753 static int __init ost_init(void)
1755 struct lprocfs_static_vars lvars;
1759 lprocfs_init_vars(ost, &lvars);
1760 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
1761 LUSTRE_OSS_NAME, NULL);
1765 static void /*__exit*/ ost_exit(void)
1767 class_unregister_type(LUSTRE_OSS_NAME);
1770 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1771 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
1772 MODULE_LICENSE("GPL");
1774 module_init(ost_init);
1775 module_exit(ost_exit);