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 <linux/obd_ost.h>
43 #include <linux/lustre_net.h>
44 #include <linux/lustre_dlm.h>
45 #include <linux/lustre_export.h>
46 #include <linux/lustre_debug.h>
47 #include <linux/init.h>
48 #include <linux/lprocfs_status.h>
49 #include <linux/lustre_commit_confd.h>
50 #include <libcfs/list.h>
51 #include <linux/lustre_quota.h>
52 #include "ost_internal.h"
54 void oti_init(struct obd_trans_info *oti, struct ptlrpc_request *req)
58 memset(oti, 0, sizeof *oti);
60 if (req->rq_repmsg && req->rq_reqmsg != 0)
61 oti->oti_transno = req->rq_repmsg->transno;
62 oti->oti_thread = req->rq_svc_thread;
65 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
67 struct oti_req_ack_lock *ack_lock;
74 req->rq_repmsg->transno = oti->oti_transno;
76 /* XXX 4 == entries in oti_ack_locks??? */
77 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
80 /* XXX not even calling target_send_reply in some cases... */
81 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode);
85 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
86 struct obd_trans_info *oti)
88 struct ost_body *body, *repbody;
89 int rc, size = sizeof(*body);
92 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
96 rc = lustre_pack_reply(req, 1, &size, NULL);
100 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
101 oti->oti_logcookies = obdo_logcookie(&body->oa);
102 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
103 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
104 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti);
108 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
110 struct ost_body *body, *repbody;
111 int rc, size = sizeof(*body);
114 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
118 rc = lustre_pack_reply(req, 1, &size, NULL);
122 repbody = lustre_msg_buf (req->rq_repmsg, 0, sizeof(*repbody));
123 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
124 req->rq_status = obd_getattr(exp, &repbody->oa, NULL);
128 static int ost_statfs(struct ptlrpc_request *req)
130 struct obd_statfs *osfs;
131 int rc, size = sizeof(*osfs);
134 rc = lustre_pack_reply(req, 1, &size, NULL);
138 osfs = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*osfs));
140 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs, jiffies-HZ);
141 if (req->rq_status != 0)
142 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
147 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
148 struct obd_trans_info *oti)
150 struct ost_body *body, *repbody;
151 int rc, size = sizeof(*repbody);
154 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
158 rc = lustre_pack_reply(req, 1, &size, NULL);
162 repbody = lustre_msg_buf (req->rq_repmsg, 0, sizeof(*repbody));
163 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
164 oti->oti_logcookies = obdo_logcookie(&repbody->oa);
165 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
166 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
171 * Helper function for ost_punch(): if asked by client, acquire [size, EOF]
172 * lock on the file being truncated.
174 static int ost_punch_lock_get(struct obd_export *exp, struct obdo *oa,
175 struct lustre_handle *lh)
178 struct ldlm_res_id res_id = { .name = { oa->o_id } };
179 ldlm_policy_data_t policy;
185 LASSERT(!lustre_handle_is_used(lh));
187 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
188 !(oa->o_flags & OBD_FL_TRUNCLOCK))
191 CDEBUG(D_INODE, "OST-side truncate lock.\n");
194 finis = start + oa->o_blocks;
197 * standard truncate optimization: if file body is completely
198 * destroyed, don't send data back to the server.
200 flags = (start == 0) ? LDLM_AST_DISCARD_DATA : 0;
202 policy.l_extent.start = start & CFS_PAGE_MASK;
205 * If ->o_blocks is EOF it means "lock till the end of the
206 * file". Otherwise, it's size of a hole being punched (in bytes)
208 if (oa->o_blocks == OBD_OBJECT_EOF || finis < start)
209 policy.l_extent.end = OBD_OBJECT_EOF;
211 policy.l_extent.end = finis | ~CFS_PAGE_MASK;
213 RETURN(ldlm_cli_enqueue(NULL, NULL, exp->exp_obd->obd_namespace,
214 res_id, LDLM_EXTENT, &policy, LCK_PW, &flags,
215 ldlm_blocking_ast, ldlm_completion_ast,
217 NULL, NULL, 0, NULL, lh));
221 * Helper function for ost_punch(): release lock acquired by
222 * ost_punch_lock_get(), if any.
224 static void ost_punch_lock_put(struct obd_export *exp, struct obdo *oa,
225 struct lustre_handle *lh)
228 if (lustre_handle_is_used(lh))
229 ldlm_lock_decref(lh, LCK_PW);
233 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
234 struct obd_trans_info *oti)
237 struct ost_body *body, *repbody;
238 struct lustre_handle lh = {0,};
240 int rc, size = sizeof(*repbody);
245 * check that we do support OBD_CONNECT_TRUNCLOCK.
247 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
249 body = lustre_swab_reqbuf(req, 0, sizeof *body, lustre_swab_ost_body);
254 if ((oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
255 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
258 rc = lustre_pack_reply(req, 1, &size, NULL);
262 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
264 rc = ost_punch_lock_get(exp, oa, &lh);
266 if (oa->o_valid & OBD_MD_FLFLAGS &&
267 oa->o_flags == OBD_FL_TRUNCLOCK)
269 * If OBD_FL_TRUNCLOCK is the only bit set in
270 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
271 * through filter_setattr() to filter_iocontrol().
273 oa->o_valid &= ~OBD_MD_FLFLAGS;
275 req->rq_status = obd_punch(exp, oa, NULL,
276 oa->o_size, oa->o_blocks, oti);
277 ost_punch_lock_put(exp, oa, &lh);
282 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
284 struct ost_body *body, *repbody;
285 int rc, size = sizeof(*repbody);
288 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
292 rc = lustre_pack_reply(req, 1, &size, NULL);
296 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
297 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
298 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
299 repbody->oa.o_blocks);
303 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
304 struct obd_trans_info *oti)
306 struct ost_body *body, *repbody;
307 int rc, size = sizeof(*repbody);
310 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
314 rc = lustre_pack_reply(req, 1, &size, NULL);
318 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
319 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
321 req->rq_status = obd_setattr(exp, &repbody->oa, NULL, oti);
325 static int ost_bulk_timeout(void *data)
328 /* We don't fail the connection here, because having the export
329 * killed makes the (vital) call to commitrw very sad.
334 static int get_per_page_niobufs(struct obd_ioobj *ioo, int nioo,
335 struct niobuf_remote *rnb, int nrnb,
336 struct niobuf_remote **pp_rnbp)
338 /* Copy a remote niobuf, splitting it into page-sized chunks
339 * and setting ioo[i].ioo_bufcnt accordingly */
340 struct niobuf_remote *pp_rnb;
348 * array of sufficient size already preallocated by caller
350 LASSERT(pp_rnbp != NULL);
351 LASSERT(*pp_rnbp != NULL);
353 /* first count and check the number of pages required */
354 for (i = 0; i < nioo; i++)
355 for (j = 0; j < ioo->ioo_bufcnt; j++, rnbidx++) {
356 obd_off offset = rnb[rnbidx].offset;
357 obd_off p0 = offset >> PAGE_SHIFT;
358 obd_off pn = (offset + rnb[rnbidx].len - 1)>>PAGE_SHIFT;
360 LASSERT(rnbidx < nrnb);
362 npages += (pn + 1 - p0);
364 if (rnb[rnbidx].len == 0) {
365 CERROR("zero len BRW: obj %d objid "LPX64
366 " buf %u\n", i, ioo[i].ioo_id, j);
370 rnb[rnbidx].offset <= rnb[rnbidx-1].offset) {
371 CERROR("unordered BRW: obj %d objid "LPX64
372 " buf %u offset "LPX64" <= "LPX64"\n",
373 i, ioo[i].ioo_id, j, rnb[rnbidx].offset,
379 LASSERT(rnbidx == nrnb);
381 if (npages == nrnb) { /* all niobufs are for single pages */
388 /* now do the actual split */
390 for (i = 0; i < nioo; i++) {
393 for (j = 0; j < ioo[i].ioo_bufcnt; j++, rnbidx++) {
394 obd_off off = rnb[rnbidx].offset;
395 int nob = rnb[rnbidx].len;
397 LASSERT(rnbidx < nrnb);
399 obd_off poff = off & (PAGE_SIZE - 1);
400 int pnob = (poff + nob > PAGE_SIZE) ?
401 PAGE_SIZE - poff : nob;
403 LASSERT(page < npages);
404 pp_rnb[page].len = pnob;
405 pp_rnb[page].offset = off;
406 pp_rnb[page].flags = rnb[rnbidx].flags;
408 CDEBUG(0, " obj %d id "LPX64
409 "page %d(%d) "LPX64" for %d, flg %x\n",
410 i, ioo[i].ioo_id, obj_pages, page,
411 pp_rnb[page].offset, pp_rnb[page].len,
421 ioo[i].ioo_bufcnt = obj_pages;
423 LASSERT(page == npages);
428 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc)
433 for (i = 0; i < desc->bd_iov_count; i++) {
434 struct page *page = desc->bd_iov[i].kiov_page;
435 int off = desc->bd_iov[i].kiov_offset & ~PAGE_MASK;
436 char *ptr = kmap(page) + off;
437 int len = desc->bd_iov[i].kiov_len;
439 cksum = crc32_le(cksum, ptr, len);
446 * populate @nio by @nrpages pages from per-thread page pool
448 static void ost_nio_pages_get(struct ptlrpc_request *req,
449 struct niobuf_local *nio, int nrpages)
452 struct ost_thread_local_cache *tls;
456 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
457 LASSERT(req != NULL);
458 LASSERT(req->rq_svc_thread != NULL);
461 LASSERT(tls != NULL);
463 memset(nio, 0, nrpages * sizeof *nio);
464 for (i = 0; i < nrpages; ++ i) {
468 LASSERT(page != NULL);
469 POISON_PAGE(page, 0xf1);
471 LL_CDEBUG_PAGE(D_INFO, page, "%d\n", i);
477 * Dual for ost_nio_pages_get(). Poison pages in pool for debugging
479 static void ost_nio_pages_put(struct ptlrpc_request *req,
480 struct niobuf_local *nio, int nrpages)
486 LASSERT(nrpages <= OST_THREAD_POOL_SIZE);
488 for (i = 0; i < nrpages; ++ i)
489 POISON_PAGE(nio[i].page, 0xf2);
493 /* cut-n-paste of mds_blocking_ast() */
494 static int ost_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
495 void *data, int flag)
500 if (flag == LDLM_CB_CANCELING) {
501 /* Don't need to do anything here. */
505 /* XXX layering violation! -phil */
506 l_lock(&lock->l_resource->lr_namespace->ns_lock);
507 /* Get this: if mds_blocking_ast is racing with mds_intent_policy,
508 * such that mds_blocking_ast is called just before l_i_p takes the
509 * ns_lock, then by the time we get the lock, we might not be the
510 * correct blocking function anymore. So check, and return early, if
512 if (lock->l_blocking_ast != ost_blocking_ast) {
513 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
517 lock->l_flags |= LDLM_FL_CBPENDING;
518 do_ast = (!lock->l_readers && !lock->l_writers);
519 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
522 struct lustre_handle lockh;
525 LDLM_DEBUG(lock, "already unused, calling ldlm_cli_cancel");
526 ldlm_lock2handle(lock, &lockh);
527 rc = ldlm_cli_cancel(&lockh);
529 CERROR("ldlm_cli_cancel: %d\n", rc);
531 LDLM_DEBUG(lock, "Lock still has references, will be "
537 static int ost_brw_lock_get(int mode, struct obd_export *exp,
538 struct obd_ioobj *obj, struct niobuf_remote *nb,
539 struct lustre_handle *lh)
542 int nrbufs = obj->ioo_bufcnt;
543 struct ldlm_res_id res_id = { .name = { obj->ioo_id } };
544 ldlm_policy_data_t policy;
549 LASSERT(mode == LCK_PR || mode == LCK_PW);
550 LASSERT(!lustre_handle_is_used(lh));
552 /* EXPENSIVE ASSERTION */
553 for (i = 1; i < nrbufs; i ++)
554 LASSERT((nb[0].flags & OBD_BRW_SRVLOCK) ==
555 (nb[i].flags & OBD_BRW_SRVLOCK));
557 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
560 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
561 policy.l_extent.end = (nb[nrbufs - 1].offset +
562 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
564 RETURN(ldlm_cli_enqueue(NULL, NULL, exp->exp_obd->obd_namespace,
565 res_id, LDLM_EXTENT, &policy, mode, &flags,
566 ldlm_blocking_ast, ldlm_completion_ast,
568 NULL, NULL, 0, NULL, lh));
571 static void ost_brw_lock_put(int mode,
572 struct obd_ioobj *obj, struct niobuf_remote *niob,
573 struct lustre_handle *lh)
576 LASSERT(mode == LCK_PR || mode == LCK_PW);
577 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
578 lustre_handle_is_used(lh));
579 if (lustre_handle_is_used(lh))
580 ldlm_lock_decref(lh, mode);
584 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
586 struct ptlrpc_bulk_desc *desc;
587 struct niobuf_remote *remote_nb;
588 struct niobuf_remote *pp_rnb = NULL;
589 struct niobuf_local *local_nb;
590 struct obd_ioobj *ioo;
591 struct ost_body *body, *repbody;
592 struct l_wait_info lwi;
593 struct lustre_handle lockh = {0};
594 int size[1] = { sizeof(*body) };
603 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
604 GOTO(out, rc = -EIO);
606 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
607 (obd_timeout + 1) / 4);
609 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
611 CERROR("Missing/short ost_body\n");
612 GOTO(out, rc = -EFAULT);
615 ioo = lustre_swab_reqbuf(req, 1, sizeof(*ioo), lustre_swab_obd_ioobj);
617 CERROR("Missing/short ioobj\n");
618 GOTO(out, rc = -EFAULT);
621 niocount = ioo->ioo_bufcnt;
622 if (niocount > PTLRPC_MAX_BRW_PAGES) {
623 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)\n",
625 GOTO(out, rc = -EFAULT);
628 remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb),
629 lustre_swab_niobuf_remote);
630 if (remote_nb == NULL) {
631 CERROR("Missing/short niobuf\n");
632 GOTO(out, rc = -EFAULT);
634 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
635 for (i = 1; i < niocount; i++)
636 lustre_swab_niobuf_remote (&remote_nb[i]);
639 rc = lustre_pack_reply(req, 1, size, NULL);
644 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
647 local_nb = ost_tls(req)->local;
648 pp_rnb = ost_tls(req)->remote;
650 /* FIXME all niobuf splitting should be done in obdfilter if needed */
651 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
652 npages = get_per_page_niobufs(ioo, 1, remote_nb, niocount, &pp_rnb);
654 GOTO(out, rc = npages);
656 LASSERT(npages <= OST_THREAD_POOL_SIZE);
658 ost_nio_pages_get(req, local_nb, npages);
660 desc = ptlrpc_prep_bulk_exp(req, npages,
661 BULK_PUT_SOURCE, OST_BULK_PORTAL);
663 GOTO(out, rc = -ENOMEM);
665 rc = ost_brw_lock_get(LCK_PR, req->rq_export, ioo, pp_rnb, &lockh);
669 rc = obd_preprw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
670 ioo, npages, pp_rnb, local_nb, oti);
674 /* We're finishing using body->oa as an input variable */
675 do_checksum = (body->oa.o_valid & OBD_MD_FLCKSUM);
676 body->oa.o_valid = 0;
679 for (i = 0; i < npages; i++) {
680 int page_rc = local_nb[i].rc;
682 if (page_rc < 0) { /* error */
687 LASSERTF(page_rc <= pp_rnb[i].len, "page_rc (%d) > "
688 "pp_rnb[%d].len (%d)\n", page_rc, i, pp_rnb[i].len);
690 if (page_rc != 0) { /* some data! */
691 LASSERT (local_nb[i].page != NULL);
692 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
693 pp_rnb[i].offset & (PAGE_SIZE-1),
697 if (page_rc != pp_rnb[i].len) { /* short read */
698 /* All subsequent pages should be 0 */
700 LASSERT(local_nb[i].rc == 0);
706 rc = ptlrpc_start_bulk_transfer(desc);
708 lwi = LWI_TIMEOUT(obd_timeout * HZ / 4,
709 ost_bulk_timeout, desc);
710 rc = l_wait_event(desc->bd_waitq,
711 !ptlrpc_bulk_active(desc), &lwi);
712 LASSERT(rc == 0 || rc == -ETIMEDOUT);
713 if (rc == -ETIMEDOUT) {
714 DEBUG_REQ(D_ERROR, req, "timeout on bulk PUT");
715 ptlrpc_abort_bulk(desc);
716 } else if (!desc->bd_success ||
717 desc->bd_nob_transferred != desc->bd_nob) {
718 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
720 "truncated" : "network error on",
721 desc->bd_nob_transferred,
723 /* XXX should this be a different errno? */
727 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d\n", rc);
729 comms_error = rc != 0;
732 /* Must commit after prep above in all cases */
733 rc = obd_commitrw(OBD_BRW_READ, req->rq_export, &body->oa, 1,
734 ioo, npages, local_nb, oti, rc);
736 ost_nio_pages_put(req, local_nb, npages);
739 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
740 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
742 if (unlikely(do_checksum)) {
743 repbody->oa.o_cksum = ost_checksum_bulk(desc);
744 repbody->oa.o_valid |= OBD_MD_FLCKSUM;
745 CDEBUG(D_PAGE, "checksum at read origin: %x\n",
746 repbody->oa.o_cksum);
751 ost_brw_lock_put(LCK_PR, ioo, pp_rnb, &lockh);
753 ptlrpc_free_bulk(desc);
757 req->rq_status = nob;
758 target_committed_to_req(req);
760 } else if (!comms_error) {
761 /* only reply if comms OK */
762 target_committed_to_req(req);
766 if (req->rq_reply_state != NULL) {
767 /* reply out callback would free */
768 ptlrpc_rs_decref(req->rq_reply_state);
769 req->rq_reply_state = NULL;
771 if (req->rq_reqmsg->conn_cnt == req->rq_export->exp_conn_cnt) {
772 CERROR("bulk IO comms error: "
773 "evicting %s@%s id %s\n",
774 req->rq_export->exp_client_uuid.uuid,
775 req->rq_export->exp_connection->c_remote_uuid.uuid,
776 libcfs_id2str(req->rq_peer));
777 class_fail_export(req->rq_export);
779 CERROR("ignoring bulk IO comms error: "
780 "client reconnected %s@%s id %s\n",
781 req->rq_export->exp_client_uuid.uuid,
782 req->rq_export->exp_connection->c_remote_uuid.uuid,
783 libcfs_id2str(req->rq_peer));
790 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
792 struct ptlrpc_bulk_desc *desc;
793 struct niobuf_remote *remote_nb;
794 struct niobuf_remote *pp_rnb;
795 struct niobuf_local *local_nb;
796 struct obd_ioobj *ioo;
797 struct ost_body *body, *repbody;
798 struct l_wait_info lwi;
799 struct lustre_handle lockh = {0};
801 int size[2] = { sizeof(*body) };
802 int objcount, niocount, npages;
804 int rc, swab, i, j, do_checksum;
807 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
808 GOTO(out, rc = -EIO);
810 /* pause before transaction has been started */
811 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK | OBD_FAIL_ONCE,
812 (obd_timeout + 1) / 4);
814 swab = lustre_msg_swabbed(req->rq_reqmsg);
815 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
817 CERROR("Missing/short ost_body\n");
818 GOTO(out, rc = -EFAULT);
821 LASSERT_REQSWAB(req, 1);
822 objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
824 CERROR("Missing/short ioobj\n");
825 GOTO(out, rc = -EFAULT);
828 CERROR("too many ioobjs (%d)\n", objcount);
829 GOTO(out, rc = -EFAULT);
832 ioo = lustre_msg_buf (req->rq_reqmsg, 1, objcount * sizeof(*ioo));
833 LASSERT (ioo != NULL);
834 for (niocount = i = 0; i < objcount; i++) {
836 lustre_swab_obd_ioobj (&ioo[i]);
837 if (ioo[i].ioo_bufcnt == 0) {
838 CERROR("ioo[%d] has zero bufcnt\n", i);
839 GOTO(out, rc = -EFAULT);
841 niocount += ioo[i].ioo_bufcnt;
844 if (niocount > PTLRPC_MAX_BRW_PAGES) {
845 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)\n",
847 GOTO(out, rc = -EFAULT);
850 remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb),
851 lustre_swab_niobuf_remote);
852 if (remote_nb == NULL) {
853 CERROR("Missing/short niobuf\n");
854 GOTO(out, rc = -EFAULT);
856 if (swab) { /* swab the remaining niobufs */
857 for (i = 1; i < niocount; i++)
858 lustre_swab_niobuf_remote (&remote_nb[i]);
861 size[1] = niocount * sizeof(*rcs);
862 rc = lustre_pack_reply(req, 2, size, NULL);
865 rcs = lustre_msg_buf(req->rq_repmsg, 1, niocount * sizeof(*rcs));
868 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
871 local_nb = ost_tls(req)->local;
872 pp_rnb = ost_tls(req)->remote;
874 /* FIXME all niobuf splitting should be done in obdfilter if needed */
875 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
876 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
878 GOTO(out, rc = npages);
880 LASSERT(npages <= OST_THREAD_POOL_SIZE);
882 ost_nio_pages_get(req, local_nb, npages);
884 desc = ptlrpc_prep_bulk_exp(req, npages,
885 BULK_GET_SINK, OST_BULK_PORTAL);
887 GOTO(out, rc = -ENOMEM);
889 rc = ost_brw_lock_get(LCK_PW, req->rq_export, ioo, pp_rnb, &lockh);
893 /* obd_preprw clobbers oa->valid, so save what we need */
894 do_checksum = (body->oa.o_valid & OBD_MD_FLCKSUM);
896 rc = obd_preprw(OBD_BRW_WRITE, req->rq_export, &body->oa, objcount,
897 ioo, npages, pp_rnb, local_nb, oti);
901 /* NB Having prepped, we must commit... */
903 for (i = 0; i < npages; i++)
904 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
905 pp_rnb[i].offset & (PAGE_SIZE - 1),
908 rc = ptlrpc_start_bulk_transfer (desc);
910 lwi = LWI_TIMEOUT(obd_timeout * HZ / 4,
911 ost_bulk_timeout, desc);
912 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc),
914 LASSERT(rc == 0 || rc == -ETIMEDOUT);
915 if (rc == -ETIMEDOUT) {
916 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
917 ptlrpc_abort_bulk(desc);
918 } else if (!desc->bd_success ||
919 desc->bd_nob_transferred != desc->bd_nob) {
920 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
922 "truncated" : "network error on",
923 desc->bd_nob_transferred, desc->bd_nob);
924 /* XXX should this be a different errno? */
928 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d\n", rc);
930 comms_error = rc != 0;
932 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
933 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
935 if (unlikely(do_checksum && rc == 0)) {
936 static int cksum_counter;
937 obd_count client_cksum = body->oa.o_cksum;
938 obd_count cksum = ost_checksum_bulk(desc);
941 if (client_cksum != cksum) {
942 CERROR("Bad checksum: client %x, server %x id %s\n",
944 libcfs_id2str(req->rq_peer));
946 repbody->oa.o_cksum = cksum;
947 repbody->oa.o_valid |= OBD_MD_FLCKSUM;
948 } else if ((cksum_counter & (-cksum_counter)) ==
950 CWARN("Checksum %u from %s: %x OK\n", cksum_counter,
951 libcfs_id2str(req->rq_peer), cksum);
954 if ((cksum_counter & (-cksum_counter)) == cksum_counter)
955 CWARN("Checksum %u from %s: %x OK\n",
957 libcfs_id2str(req->rq_peer), cksum);
961 /* Must commit after prep above in all cases */
962 rc = obd_commitrw(OBD_BRW_WRITE, req->rq_export, &repbody->oa,
963 objcount, ioo, npages, local_nb, oti, rc);
965 ost_nio_pages_put(req, local_nb, npages);
968 /* set per-requested niobuf return codes */
969 for (i = j = 0; i < niocount; i++) {
970 int nob = remote_nb[i].len;
975 if (local_nb[j].rc < 0)
976 rcs[i] = local_nb[j].rc;
977 nob -= pp_rnb[j].len;
982 LASSERT(j == npages);
986 ost_brw_lock_put(LCK_PW, ioo, pp_rnb, &lockh);
988 ptlrpc_free_bulk(desc);
991 oti_to_request(oti, req);
992 target_committed_to_req(req);
993 rc = ptlrpc_reply(req);
994 } else if (!comms_error) {
995 /* Only reply if there was no comms problem with bulk */
996 target_committed_to_req(req);
1000 if (req->rq_reply_state != NULL) {
1001 /* reply out callback would free */
1002 ptlrpc_rs_decref(req->rq_reply_state);
1003 req->rq_reply_state = NULL;
1005 if (req->rq_reqmsg->conn_cnt == req->rq_export->exp_conn_cnt) {
1006 CERROR("%s: bulk IO comm error evicting %s@%s id %s\n",
1007 req->rq_export->exp_obd->obd_name,
1008 req->rq_export->exp_client_uuid.uuid,
1009 req->rq_export->exp_connection->c_remote_uuid.uuid,
1010 libcfs_id2str(req->rq_peer));
1011 class_fail_export(req->rq_export);
1013 CERROR("ignoring bulk IO comms error: "
1014 "client reconnected %s@%s id %s\n",
1015 req->rq_export->exp_client_uuid.uuid,
1016 req->rq_export->exp_connection->c_remote_uuid.uuid,
1017 libcfs_id2str(req->rq_peer));
1023 static int ost_san_brw(struct ptlrpc_request *req, int cmd)
1025 struct niobuf_remote *remote_nb, *res_nb, *pp_rnb = NULL;
1026 struct obd_ioobj *ioo;
1027 struct ost_body *body, *repbody;
1028 int rc, i, objcount, niocount, size[2] = {sizeof(*body)}, npages;
1032 /* XXX not set to use latest protocol */
1034 swab = lustre_msg_swabbed(req->rq_reqmsg);
1035 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
1037 CERROR("Missing/short ost_body\n");
1038 GOTO(out, rc = -EFAULT);
1041 ioo = lustre_swab_reqbuf(req, 1, sizeof(*ioo), lustre_swab_obd_ioobj);
1043 CERROR("Missing/short ioobj\n");
1044 GOTO(out, rc = -EFAULT);
1046 objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
1047 niocount = ioo[0].ioo_bufcnt;
1048 for (i = 1; i < objcount; i++) {
1050 lustre_swab_obd_ioobj (&ioo[i]);
1051 niocount += ioo[i].ioo_bufcnt;
1054 remote_nb = lustre_swab_reqbuf(req, 2, niocount * sizeof(*remote_nb),
1055 lustre_swab_niobuf_remote);
1056 if (remote_nb == NULL) {
1057 CERROR("Missing/short niobuf\n");
1058 GOTO(out, rc = -EFAULT);
1060 if (swab) { /* swab the remaining niobufs */
1061 for (i = 1; i < niocount; i++)
1062 lustre_swab_niobuf_remote (&remote_nb[i]);
1066 * Per-thread array of struct niobuf_remote's was allocated by
1067 * ost_thread_init().
1069 pp_rnb = ost_tls(req)->remote;
1071 /* CAVEAT EMPTOR this sets ioo->ioo_bufcnt to # pages */
1072 npages = get_per_page_niobufs(ioo, objcount,remote_nb,niocount,&pp_rnb);
1074 GOTO (out, rc = npages);
1076 size[1] = npages * sizeof(*pp_rnb);
1077 rc = lustre_pack_reply(req, 2, size, NULL);
1081 req->rq_status = obd_san_preprw(cmd, req->rq_export, &body->oa,
1082 objcount, ioo, npages, pp_rnb);
1087 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
1088 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
1090 res_nb = lustre_msg_buf(req->rq_repmsg, 1, size[1]);
1091 memcpy(res_nb, remote_nb, size[1]);
1094 target_committed_to_req(req);
1096 req->rq_status = rc;
1106 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1108 char *key, *val = NULL;
1109 int keylen, vallen, rc = 0;
1112 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
1114 DEBUG_REQ(D_HA, req, "no set_info key");
1117 keylen = lustre_msg_buflen(req->rq_reqmsg,0);
1119 rc = lustre_pack_reply(req, 0, NULL, NULL);
1123 vallen = lustre_msg_buflen(req->rq_reqmsg, 1);
1125 val = lustre_msg_buf(req->rq_reqmsg, 1, 0);
1127 if (KEY_IS("evict_by_nid")) {
1129 obd_export_evict_by_nid(exp->exp_obd, val);
1134 rc = obd_set_info(exp, keylen, key, vallen, val);
1136 req->rq_repmsg->status = 0;
1140 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1143 int keylen, rc = 0, size = sizeof(obd_id);
1147 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
1149 DEBUG_REQ(D_HA, req, "no get_info key");
1152 keylen = req->rq_reqmsg->buflens[0];
1154 if (keylen < strlen("last_id") || memcmp(key, "last_id", 7) != 0)
1157 rc = lustre_pack_reply(req, 1, &size, NULL);
1161 reply = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*reply));
1162 rc = obd_get_info(exp, keylen, key, &size, reply);
1163 req->rq_repmsg->status = 0;
1167 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1168 struct obd_device *obd, int *process)
1170 switch (req->rq_reqmsg->opc) {
1171 case OST_CONNECT: /* This will never get here, but for completeness. */
1172 case OST_DISCONNECT:
1183 case OBD_LOG_CANCEL:
1185 *process = target_queue_recovery_request(req, obd);
1189 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1191 /* XXX what should we set rq_status to here? */
1192 req->rq_status = -EAGAIN;
1193 RETURN(ptlrpc_error(req));
1197 static int ost_handle(struct ptlrpc_request *req)
1199 struct obd_trans_info trans_info = { 0, };
1200 struct obd_trans_info *oti = &trans_info;
1201 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1202 struct obd_device *obd = NULL;
1205 LASSERT(current->journal_info == NULL);
1206 /* XXX identical to MDS */
1207 if (req->rq_reqmsg->opc != OST_CONNECT) {
1208 int abort_recovery, recovering;
1210 if (req->rq_export == NULL) {
1211 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1212 req->rq_reqmsg->opc, libcfs_id2str(req->rq_peer));
1213 req->rq_status = -ENOTCONN;
1214 GOTO(out, rc = -ENOTCONN);
1217 obd = req->rq_export->exp_obd;
1219 /* Check for aborted recovery. */
1220 spin_lock_bh(&obd->obd_processing_task_lock);
1221 abort_recovery = obd->obd_abort_recovery;
1222 recovering = obd->obd_recovering;
1223 spin_unlock_bh(&obd->obd_processing_task_lock);
1224 if (abort_recovery) {
1225 target_abort_recovery(obd);
1226 } else if (recovering) {
1227 rc = ost_filter_recovery_request(req, obd,
1229 if (rc || !should_process)
1236 switch (req->rq_reqmsg->opc) {
1238 CDEBUG(D_INODE, "connect\n");
1239 OBD_FAIL_RETURN(OBD_FAIL_OST_CONNECT_NET, 0);
1240 rc = target_handle_connect(req, ost_handle);
1242 obd = req->rq_export->exp_obd;
1245 case OST_DISCONNECT:
1246 CDEBUG(D_INODE, "disconnect\n");
1247 OBD_FAIL_RETURN(OBD_FAIL_OST_DISCONNECT_NET, 0);
1248 rc = target_handle_disconnect(req);
1251 CDEBUG(D_INODE, "create\n");
1252 OBD_FAIL_RETURN(OBD_FAIL_OST_CREATE_NET, 0);
1253 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
1254 GOTO(out, rc = -ENOSPC);
1255 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1256 GOTO(out, rc = -EROFS);
1257 rc = ost_create(req->rq_export, req, oti);
1260 CDEBUG(D_INODE, "destroy\n");
1261 OBD_FAIL_RETURN(OBD_FAIL_OST_DESTROY_NET, 0);
1262 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1263 GOTO(out, rc = -EROFS);
1264 rc = ost_destroy(req->rq_export, req, oti);
1267 CDEBUG(D_INODE, "getattr\n");
1268 OBD_FAIL_RETURN(OBD_FAIL_OST_GETATTR_NET, 0);
1269 rc = ost_getattr(req->rq_export, req);
1272 CDEBUG(D_INODE, "setattr\n");
1273 OBD_FAIL_RETURN(OBD_FAIL_OST_SETATTR_NET, 0);
1274 rc = ost_setattr(req->rq_export, req, oti);
1277 CDEBUG(D_INODE, "write\n");
1278 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1279 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_ENOSPC))
1280 GOTO(out, rc = -ENOSPC);
1281 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1282 GOTO(out, rc = -EROFS);
1283 rc = ost_brw_write(req, oti);
1284 LASSERT(current->journal_info == NULL);
1285 /* ost_brw_write sends its own replies */
1288 CDEBUG(D_INODE, "read\n");
1289 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1290 rc = ost_brw_read(req, oti);
1291 LASSERT(current->journal_info == NULL);
1292 /* ost_brw_read sends its own replies */
1295 CDEBUG(D_INODE, "san read\n");
1296 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1297 rc = ost_san_brw(req, OBD_BRW_READ);
1298 /* ost_san_brw sends its own replies */
1301 CDEBUG(D_INODE, "san write\n");
1302 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1303 rc = ost_san_brw(req, OBD_BRW_WRITE);
1304 /* ost_san_brw sends its own replies */
1307 CDEBUG(D_INODE, "punch\n");
1308 OBD_FAIL_RETURN(OBD_FAIL_OST_PUNCH_NET, 0);
1309 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_OST_EROFS))
1310 GOTO(out, rc = -EROFS);
1311 rc = ost_punch(req->rq_export, req, oti);
1314 CDEBUG(D_INODE, "statfs\n");
1315 OBD_FAIL_RETURN(OBD_FAIL_OST_STATFS_NET, 0);
1316 rc = ost_statfs(req);
1319 CDEBUG(D_INODE, "sync\n");
1320 OBD_FAIL_RETURN(OBD_FAIL_OST_SYNC_NET, 0);
1321 rc = ost_sync(req->rq_export, req);
1324 DEBUG_REQ(D_INODE, req, "set_info");
1325 rc = ost_set_info(req->rq_export, req);
1328 DEBUG_REQ(D_INODE, req, "get_info");
1329 rc = ost_get_info(req->rq_export, req);
1331 case OST_QUOTACHECK:
1332 CDEBUG(D_INODE, "quotacheck\n");
1333 OBD_FAIL_RETURN(OBD_FAIL_OST_QUOTACHECK_NET, 0);
1334 rc = ost_quotacheck(req);
1337 CDEBUG(D_INODE, "quotactl\n");
1338 OBD_FAIL_RETURN(OBD_FAIL_OST_QUOTACTL_NET, 0);
1339 rc = ost_quotactl(req);
1342 DEBUG_REQ(D_INODE, req, "ping");
1343 rc = target_handle_ping(req);
1345 /* FIXME - just reply status */
1346 case LLOG_ORIGIN_CONNECT:
1347 DEBUG_REQ(D_INODE, req, "log connect\n");
1348 rc = llog_handle_connect(req);
1349 req->rq_status = rc;
1350 rc = lustre_pack_reply(req, 0, NULL, NULL);
1353 RETURN(ptlrpc_reply(req));
1354 case OBD_LOG_CANCEL:
1355 CDEBUG(D_INODE, "log cancel\n");
1356 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
1357 rc = llog_origin_handle_cancel(req);
1358 req->rq_status = rc;
1359 rc = lustre_pack_reply(req, 0, NULL, NULL);
1362 RETURN(ptlrpc_reply(req));
1364 CDEBUG(D_INODE, "enqueue\n");
1365 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
1366 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1367 ldlm_server_blocking_ast,
1368 ldlm_server_glimpse_ast);
1369 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1372 CDEBUG(D_INODE, "convert\n");
1373 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
1374 rc = ldlm_handle_convert(req);
1377 CDEBUG(D_INODE, "cancel\n");
1378 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CANCEL, 0);
1379 rc = ldlm_handle_cancel(req);
1381 case LDLM_BL_CALLBACK:
1382 case LDLM_CP_CALLBACK:
1383 CDEBUG(D_INODE, "callback\n");
1384 CERROR("callbacks should not happen on OST\n");
1387 CERROR("Unexpected opcode %d\n", req->rq_reqmsg->opc);
1388 req->rq_status = -ENOTSUPP;
1389 rc = ptlrpc_error(req);
1393 LASSERT(current->journal_info == NULL);
1396 /* If we're DISCONNECTing, the export_data is already freed */
1397 if (!rc && req->rq_reqmsg->opc != OST_DISCONNECT)
1398 target_committed_to_req(req);
1401 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LAST_REPLAY) {
1402 if (obd && obd->obd_recovering) {
1403 DEBUG_REQ(D_HA, req, "LAST_REPLAY, queuing reply");
1404 return target_queue_final_reply(req, rc);
1406 /* Lost a race with recovery; let the error path DTRT. */
1407 rc = req->rq_status = -ENOTCONN;
1411 oti_to_request(oti, req);
1413 target_send_reply(req, rc, fail);
1418 * free per-thread pool created by ost_thread_init().
1420 static void ost_thread_done(struct ptlrpc_thread *thread)
1423 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
1428 LASSERT(thread != NULL);
1429 LASSERT(thread->t_data != NULL);
1432 * be prepared to handle partially-initialized pools (because this is
1433 * called from ost_thread_init() for cleanup.
1435 tls = thread->t_data;
1437 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1438 if (tls->page[i] != NULL)
1439 __free_page(tls->page[i]);
1442 thread->t_data = NULL;
1448 * initialize per-thread page pool (bug 5137).
1450 static int ost_thread_init(struct ptlrpc_thread *thread)
1454 struct ost_thread_local_cache *tls;
1458 LASSERT(thread != NULL);
1459 LASSERT(thread->t_data == NULL);
1460 LASSERT(thread->t_id < OST_NUM_THREADS);
1465 thread->t_data = tls;
1469 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
1470 tls->page[i] = alloc_page(OST_THREAD_POOL_GFP);
1471 if (tls->page[i] == NULL) {
1472 ost_thread_done(thread);
1482 static int ost_setup(struct obd_device *obd, obd_count len, void *buf)
1484 struct ost_obd *ost = &obd->u.ost;
1485 struct lprocfs_static_vars lvars;
1489 rc = cleanup_group_info();
1493 rc = llog_start_commit_thread();
1497 lprocfs_init_vars(ost, &lvars);
1498 lprocfs_obd_setup(obd, lvars.obd_vars);
1500 sema_init(&ost->ost_health_sem, 1);
1503 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1504 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
1506 obd_timeout * 1000, ost_handle, LUSTRE_OST_NAME,
1507 obd->obd_proc_entry, ost_print_req,
1509 if (ost->ost_service == NULL) {
1510 CERROR("failed to start service\n");
1511 GOTO(out_lprocfs, rc = -ENOMEM);
1514 rc = ptlrpc_start_threads(obd, ost->ost_service, "ll_ost");
1516 GOTO(out_service, rc = -EINVAL);
1518 ost->ost_create_service =
1519 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1520 OST_MAXREPSIZE, OST_CREATE_PORTAL,
1522 obd_timeout * 1000, ost_handle, "ost_create",
1523 obd->obd_proc_entry, ost_print_req, 1);
1524 if (ost->ost_create_service == NULL) {
1525 CERROR("failed to start OST create service\n");
1526 GOTO(out_service, rc = -ENOMEM);
1529 rc = ptlrpc_start_threads(obd, ost->ost_create_service,
1532 GOTO(out_create, rc = -EINVAL);
1534 ost->ost_io_service =
1535 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1536 OST_MAXREPSIZE, OST_IO_PORTAL,
1538 obd_timeout * 1000, ost_handle, "ost_io",
1539 obd->obd_proc_entry, ost_print_req,
1541 if (ost->ost_io_service == NULL) {
1542 CERROR("failed to start OST I/O service\n");
1543 GOTO(out_create, rc = -ENOMEM);
1546 ost->ost_io_service->srv_init = ost_thread_init;
1547 ost->ost_io_service->srv_done = ost_thread_done;
1548 ost->ost_io_service->srv_cpu_affinity = 1;
1549 rc = ptlrpc_start_threads(obd, ost->ost_io_service,
1552 GOTO(out_io, rc = -EINVAL);
1557 ptlrpc_unregister_service(ost->ost_io_service);
1558 ost->ost_io_service = NULL;
1560 ptlrpc_unregister_service(ost->ost_create_service);
1561 ost->ost_create_service = NULL;
1563 ptlrpc_unregister_service(ost->ost_service);
1564 ost->ost_service = NULL;
1566 lprocfs_obd_cleanup(obd);
1570 static int ost_cleanup(struct obd_device *obd)
1572 struct ost_obd *ost = &obd->u.ost;
1576 spin_lock_bh(&obd->obd_processing_task_lock);
1577 if (obd->obd_recovering) {
1578 target_cancel_recovery_timer(obd);
1579 obd->obd_recovering = 0;
1581 spin_unlock_bh(&obd->obd_processing_task_lock);
1583 down(&ost->ost_health_sem);
1584 ptlrpc_unregister_service(ost->ost_service);
1585 ptlrpc_unregister_service(ost->ost_create_service);
1586 ptlrpc_unregister_service(ost->ost_io_service);
1587 ost->ost_service = NULL;
1588 ost->ost_create_service = NULL;
1589 up(&ost->ost_health_sem);
1591 lprocfs_obd_cleanup(obd);
1596 static int ost_health_check(struct obd_device *obd)
1598 struct ost_obd *ost = &obd->u.ost;
1601 down(&ost->ost_health_sem);
1602 rc |= ptlrpc_service_health_check(ost->ost_service);
1603 rc |= ptlrpc_service_health_check(ost->ost_create_service);
1604 rc |= ptlrpc_service_health_check(ost->ost_io_service);
1605 up(&ost->ost_health_sem);
1608 * health_check to return 0 on healthy
1609 * and 1 on unhealthy.
1617 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
1619 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
1622 /* use obd ops to offer management infrastructure */
1623 static struct obd_ops ost_obd_ops = {
1624 .o_owner = THIS_MODULE,
1625 .o_setup = ost_setup,
1626 .o_cleanup = ost_cleanup,
1627 .o_health_check = ost_health_check,
1630 static int __init ost_init(void)
1632 struct lprocfs_static_vars lvars;
1635 lprocfs_init_vars(ost,&lvars);
1636 RETURN(class_register_type(&ost_obd_ops, lvars.module_vars,
1640 static void /*__exit*/ ost_exit(void)
1642 class_unregister_type(LUSTRE_OST_NAME);
1645 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1646 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
1647 MODULE_LICENSE("GPL");
1649 module_init(ost_init);
1650 module_exit(ost_exit);