1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ost/ost_handler.c
38 * Author: Peter J. Braam <braam@clusterfs.com>
39 * Author: Phil Schwan <phil@clusterfs.com>
43 # define EXPORT_SYMTAB
45 #define DEBUG_SUBSYSTEM S_OST
47 #include <linux/module.h>
48 #include <obd_cksum.h>
50 #include <lustre_net.h>
51 #include <lustre_dlm.h>
52 #include <lustre_export.h>
53 #include <lustre_debug.h>
54 #include <linux/init.h>
55 #include <lprocfs_status.h>
56 #include <libcfs/list.h>
57 #include <lustre_quota.h>
58 #include "ost_internal.h"
60 static int oss_num_threads;
61 CFS_MODULE_PARM(oss_num_threads, "i", int, 0444,
62 "number of OSS service threads to start");
64 static int ost_num_threads;
65 CFS_MODULE_PARM(ost_num_threads, "i", int, 0444,
66 "number of OST service threads to start (deprecated)");
68 static int oss_num_create_threads;
69 CFS_MODULE_PARM(oss_num_create_threads, "i", int, 0444,
70 "number of OSS create threads to start");
73 * Do not return server-side uid/gid to remote client
75 static void ost_drop_id(struct obd_export *exp, struct obdo *oa)
77 if (exp_connect_rmtclient(exp)) {
80 oa->o_valid &= ~(OBD_MD_FLUID | OBD_MD_FLGID);
84 void oti_to_request(struct obd_trans_info *oti, struct ptlrpc_request *req)
86 struct oti_req_ack_lock *ack_lock;
93 lustre_msg_set_transno(req->rq_repmsg, oti->oti_transno);
94 req->rq_transno = oti->oti_transno;
96 /* XXX 4 == entries in oti_ack_locks??? */
97 for (ack_lock = oti->oti_ack_locks, i = 0; i < 4; i++, ack_lock++) {
100 /* XXX not even calling target_send_reply in some cases... */
101 ptlrpc_save_lock (req, &ack_lock->lock, ack_lock->mode, 0);
105 static int ost_destroy(struct obd_export *exp, struct ptlrpc_request *req,
106 struct obd_trans_info *oti)
108 struct ost_body *body, *repbody;
109 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
110 struct lustre_capa *capa = NULL;
114 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
115 lustre_swab_ost_body);
119 if (body->oa.o_id == 0)
122 if (lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1)) {
123 struct ldlm_request *dlm;
124 dlm = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*dlm),
125 lustre_swab_ldlm_request);
128 ldlm_request_cancel(req, dlm, 0);
131 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
132 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 2);
134 rc = lustre_pack_reply(req, 2, size, NULL);
138 if (body->oa.o_valid & OBD_MD_FLCOOKIE)
139 oti->oti_logcookies = &body->oa.o_lcookie;
140 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
142 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
143 req->rq_status = obd_destroy(exp, &body->oa, NULL, oti, NULL, capa);
147 static int ost_getattr(struct obd_export *exp, struct ptlrpc_request *req)
149 struct ost_body *body, *repbody;
150 struct obd_info oinfo = { { { 0 } } };
151 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
155 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
156 lustre_swab_ost_body);
160 rc = lustre_pack_reply(req, 2, size, NULL);
164 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
166 repbody->oa = body->oa;
168 oinfo.oi_oa = &repbody->oa;
169 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
170 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
172 req->rq_status = obd_getattr(exp, &oinfo);
173 ost_drop_id(exp, &repbody->oa);
177 static int ost_statfs(struct ptlrpc_request *req)
179 struct obd_statfs *osfs;
180 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*osfs) };
184 rc = lustre_pack_reply(req, 2, size, NULL);
188 osfs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*osfs));
190 req->rq_status = obd_statfs(req->rq_export->exp_obd, osfs,
191 cfs_time_current_64() - HZ, 0);
192 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
193 osfs->os_bfree = osfs->os_bavail = 64;
194 if (req->rq_status != 0)
195 CERROR("ost: statfs failed: rc %d\n", req->rq_status);
200 static int ost_create(struct obd_export *exp, struct ptlrpc_request *req,
201 struct obd_trans_info *oti)
203 struct ost_body *body, *repbody;
204 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
208 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
209 lustre_swab_ost_body);
213 rc = lustre_pack_reply(req, 2, size, NULL);
217 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
219 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
220 oti->oti_logcookies = &repbody->oa.o_lcookie;
221 req->rq_status = obd_create(exp, &repbody->oa, NULL, oti);
222 //obd_log_cancel(conn, NULL, 1, oti->oti_logcookies, 0);
227 * Helper function for ost_punch(): if asked by client, acquire [size, EOF]
228 * lock on the file being truncated.
230 static int ost_punch_lock_get(struct obd_export *exp, struct obdo *oa,
231 struct lustre_handle *lh)
234 struct ldlm_res_id res_id;
235 ldlm_policy_data_t policy;
241 osc_build_res_name(oa->o_id, oa->o_gr, &res_id);
242 LASSERT(!lustre_handle_is_used(lh));
244 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
245 !(oa->o_flags & OBD_FL_TRUNCLOCK))
248 CDEBUG(D_INODE, "OST-side truncate lock.\n");
251 finis = start + oa->o_blocks;
254 * standard truncate optimization: if file body is completely
255 * destroyed, don't send data back to the server.
257 flags = (start == 0) ? LDLM_AST_DISCARD_DATA : 0;
259 policy.l_extent.start = start & CFS_PAGE_MASK;
262 * If ->o_blocks is EOF it means "lock till the end of the
263 * file". Otherwise, it's size of a hole being punched (in bytes)
265 if (oa->o_blocks == OBD_OBJECT_EOF || finis < start)
266 policy.l_extent.end = OBD_OBJECT_EOF;
268 policy.l_extent.end = finis | ~CFS_PAGE_MASK;
270 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
271 LDLM_EXTENT, &policy, LCK_PW, &flags,
272 ldlm_blocking_ast, ldlm_completion_ast,
273 ldlm_glimpse_ast, NULL, 0, NULL,
278 * Helper function for ost_punch(): release lock acquired by
279 * ost_punch_lock_get(), if any.
281 static void ost_punch_lock_put(struct obd_export *exp, struct obdo *oa,
282 struct lustre_handle *lh)
285 if (lustre_handle_is_used(lh))
286 ldlm_lock_decref(lh, LCK_PW);
290 static int ost_punch(struct obd_export *exp, struct ptlrpc_request *req,
291 struct obd_trans_info *oti)
293 struct obd_info oinfo = { { { 0 } } };
294 struct ost_body *body, *repbody;
295 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
297 struct lustre_handle lh = {0,};
300 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
301 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
303 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
304 lustre_swab_ost_body);
308 oinfo.oi_oa = &body->oa;
309 oinfo.oi_policy.l_extent.start = oinfo.oi_oa->o_size;
310 oinfo.oi_policy.l_extent.end = oinfo.oi_oa->o_blocks;
312 if ((oinfo.oi_oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
313 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
316 rc = lustre_pack_reply(req, 2, size, NULL);
320 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
322 rc = ost_punch_lock_get(exp, oinfo.oi_oa, &lh);
324 if (oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
325 oinfo.oi_oa->o_flags == OBD_FL_TRUNCLOCK)
327 * If OBD_FL_TRUNCLOCK is the only bit set in
328 * ->o_flags, clear OBD_MD_FLFLAGS to avoid falling
329 * through filter_setattr() to filter_iocontrol().
331 oinfo.oi_oa->o_valid &= ~OBD_MD_FLFLAGS;
333 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
334 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
336 req->rq_status = obd_punch(exp, &oinfo, oti, NULL);
337 ost_punch_lock_put(exp, oinfo.oi_oa, &lh);
339 repbody->oa = *oinfo.oi_oa;
340 ost_drop_id(exp, &repbody->oa);
344 static int ost_sync(struct obd_export *exp, struct ptlrpc_request *req)
346 struct ost_body *body, *repbody;
347 struct lustre_capa *capa = NULL;
348 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
352 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
353 lustre_swab_ost_body);
357 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
358 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 1);
360 rc = lustre_pack_reply(req, 2, size, NULL);
364 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
366 memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
367 req->rq_status = obd_sync(exp, &repbody->oa, NULL, repbody->oa.o_size,
368 repbody->oa.o_blocks, capa);
369 ost_drop_id(exp, &repbody->oa);
373 static int ost_setattr(struct obd_export *exp, struct ptlrpc_request *req,
374 struct obd_trans_info *oti)
376 struct ost_body *body, *repbody;
377 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
379 struct obd_info oinfo = { { { 0 } } };
382 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
383 lustre_swab_ost_body);
387 rc = lustre_pack_reply(req, 2, size, NULL);
391 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
393 repbody->oa = body->oa;
395 oinfo.oi_oa = &repbody->oa;
396 if (oinfo.oi_oa->o_valid & OBD_MD_FLOSSCAPA)
397 oinfo.oi_capa = lustre_unpack_capa(req->rq_reqmsg,
399 req->rq_status = obd_setattr(exp, &oinfo, oti);
400 ost_drop_id(exp, &repbody->oa);
404 static int ost_bulk_timeout(void *data)
407 /* We don't fail the connection here, because having the export
408 * killed makes the (vital) call to commitrw very sad.
413 static __u32 ost_checksum_bulk(struct ptlrpc_bulk_desc *desc, int opc,
414 cksum_type_t cksum_type)
419 cksum = init_checksum(cksum_type);
420 for (i = 0; i < desc->bd_iov_count; i++) {
421 struct page *page = desc->bd_iov[i].kiov_page;
422 int off = desc->bd_iov[i].kiov_offset & ~CFS_PAGE_MASK;
423 char *ptr = kmap(page) + off;
424 int len = desc->bd_iov[i].kiov_len;
426 /* corrupt the data before we compute the checksum, to
427 * simulate a client->OST data error */
428 if (i == 0 && opc == OST_WRITE &&
429 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_RECEIVE))
430 memcpy(ptr, "bad3", min(4, len));
431 cksum = compute_checksum(cksum, ptr, len, cksum_type);
432 /* corrupt the data after we compute the checksum, to
433 * simulate an OST->client data error */
434 if (i == 0 && opc == OST_READ &&
435 OBD_FAIL_CHECK(OBD_FAIL_OST_CHECKSUM_SEND)) {
436 memcpy(ptr, "bad4", min(4, len));
437 /* nobody should use corrupted page again */
438 ClearPageUptodate(page);
446 static int ost_brw_lock_get(int mode, struct obd_export *exp,
447 struct obd_ioobj *obj, struct niobuf_remote *nb,
448 struct lustre_handle *lh)
451 int nrbufs = obj->ioo_bufcnt;
452 struct ldlm_res_id res_id;
453 ldlm_policy_data_t policy;
457 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
458 LASSERT(mode == LCK_PR || mode == LCK_PW);
459 LASSERT(!lustre_handle_is_used(lh));
461 if (nrbufs == 0 || !(nb[0].flags & OBD_BRW_SRVLOCK))
464 /* EXPENSIVE ASSERTION */
465 for (i = 1; i < nrbufs; i ++)
466 LASSERT((nb[0].flags & OBD_BRW_SRVLOCK) ==
467 (nb[i].flags & OBD_BRW_SRVLOCK));
469 policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
470 policy.l_extent.end = (nb[nrbufs - 1].offset +
471 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
473 RETURN(ldlm_cli_enqueue_local(exp->exp_obd->obd_namespace, &res_id,
474 LDLM_EXTENT, &policy, mode, &flags,
475 ldlm_blocking_ast, ldlm_completion_ast,
476 ldlm_glimpse_ast, NULL, 0, NULL,
480 static void ost_brw_lock_put(int mode,
481 struct obd_ioobj *obj, struct niobuf_remote *niob,
482 struct lustre_handle *lh)
485 LASSERT(mode == LCK_PR || mode == LCK_PW);
486 LASSERT((obj->ioo_bufcnt > 0 && (niob[0].flags & OBD_BRW_SRVLOCK)) ==
487 lustre_handle_is_used(lh));
488 if (lustre_handle_is_used(lh))
489 ldlm_lock_decref(lh, mode);
493 struct ost_prolong_data {
494 struct obd_export *opd_exp;
495 ldlm_policy_data_t opd_policy;
496 ldlm_mode_t opd_mode;
499 static int ost_prolong_locks_iter(struct ldlm_lock *lock, void *data)
501 struct ost_prolong_data *opd = data;
503 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
505 if (lock->l_req_mode != lock->l_granted_mode) {
506 /* scan granted locks only */
507 return LDLM_ITER_STOP;
510 if (lock->l_export != opd->opd_exp) {
511 /* prolong locks only for given client */
512 return LDLM_ITER_CONTINUE;
515 if (!(lock->l_granted_mode & opd->opd_mode)) {
516 /* we aren't interesting in all type of locks */
517 return LDLM_ITER_CONTINUE;
520 if (lock->l_policy_data.l_extent.end < opd->opd_policy.l_extent.start ||
521 lock->l_policy_data.l_extent.start > opd->opd_policy.l_extent.end) {
522 /* the request doesn't cross the lock, skip it */
523 return LDLM_ITER_CONTINUE;
526 if (!(lock->l_flags & LDLM_FL_AST_SENT)) {
527 /* ignore locks not being cancelled */
528 return LDLM_ITER_CONTINUE;
531 /* OK. this is a possible lock the user holds doing I/O
532 * let's refresh eviction timer for it */
533 ldlm_refresh_waiting_lock(lock);
535 return LDLM_ITER_CONTINUE;
538 static void ost_prolong_locks(struct obd_export *exp, struct obd_ioobj *obj,
539 struct niobuf_remote *nb, struct obdo *oa,
542 struct ldlm_res_id res_id;
543 int nrbufs = obj->ioo_bufcnt;
544 struct ost_prolong_data opd;
547 osc_build_res_name(obj->ioo_id, obj->ioo_gr, &res_id);
551 opd.opd_policy.l_extent.start = nb[0].offset & CFS_PAGE_MASK;
552 opd.opd_policy.l_extent.end = (nb[nrbufs - 1].offset +
553 nb[nrbufs - 1].len - 1) | ~CFS_PAGE_MASK;
555 CDEBUG(D_DLMTRACE,"refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
556 res_id.name[0], res_id.name[1], opd.opd_policy.l_extent.start,
557 opd.opd_policy.l_extent.end);
559 if (oa->o_valid & OBD_MD_FLHANDLE) {
560 struct ldlm_lock *lock;
562 lock = ldlm_handle2lock(&oa->o_handle);
564 ost_prolong_locks_iter(lock, &opd);
571 ldlm_resource_iterate(exp->exp_obd->obd_namespace, &res_id,
572 ost_prolong_locks_iter, &opd);
577 static int ost_brw_read(struct ptlrpc_request *req, struct obd_trans_info *oti)
579 struct ptlrpc_bulk_desc *desc = NULL;
580 struct obd_export *exp = req->rq_export;
581 struct niobuf_remote *remote_nb;
582 struct niobuf_local *local_nb;
583 struct obd_ioobj *ioo;
584 struct ost_body *body, *repbody;
585 struct lustre_capa *capa = NULL;
586 struct l_wait_info lwi;
587 struct lustre_handle lockh = { 0 };
588 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
589 int objcount, niocount, npages, nob = 0, rc, i;
593 req->rq_bulk_read = 1;
595 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_READ_BULK))
596 GOTO(out, rc = -EIO);
598 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
600 /* Check if there is eviction in progress, and if so, wait for it to
602 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
603 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
604 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
605 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
609 GOTO(out, rc = -ENOTCONN);
611 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
612 lustre_swab_ost_body);
614 CERROR("Missing/short ost_body\n");
615 GOTO(out, rc = -EFAULT);
618 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
621 CERROR("Missing/short ioobj\n");
622 GOTO(out, rc = -EFAULT);
625 CERROR("too many ioobjs (%d)\n", objcount);
626 GOTO(out, rc = -EFAULT);
629 ioo = lustre_swab_reqbuf(req, REQ_REC_OFF + 1, sizeof(*ioo),
630 lustre_swab_obd_ioobj);
632 CERROR("Missing/short ioobj\n");
633 GOTO(out, rc = -EFAULT);
636 niocount = ioo->ioo_bufcnt;
637 if (niocount > PTLRPC_MAX_BRW_PAGES) {
638 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
640 GOTO(out, rc = -EFAULT);
643 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
644 niocount * sizeof(*remote_nb),
645 lustre_swab_niobuf_remote);
646 if (remote_nb == NULL) {
647 CERROR("Missing/short niobuf\n");
648 GOTO(out, rc = -EFAULT);
650 if (lustre_msg_swabbed(req->rq_reqmsg)) { /* swab remaining niobufs */
651 for (i = 1; i < niocount; i++)
652 lustre_swab_niobuf_remote (&remote_nb[i]);
655 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
656 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
658 rc = lustre_pack_reply(req, 2, size, NULL);
663 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
666 local_nb = ost_tls(req)->local;
668 rc = ost_brw_lock_get(LCK_PR, exp, ioo, remote_nb, &lockh);
673 * If getting the lock took more time than
674 * client was willing to wait, drop it. b=11330
676 if (cfs_time_current_sec() > req->rq_deadline ||
677 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
679 CERROR("Dropping timed-out read from %s because locking"
680 "object "LPX64" took %ld seconds (limit was %ld).\n",
681 libcfs_id2str(req->rq_peer), ioo->ioo_id,
682 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
683 req->rq_deadline - req->rq_arrival_time.tv_sec);
684 GOTO(out_lock, rc = -ETIMEDOUT);
687 npages = OST_THREAD_POOL_SIZE;
688 rc = obd_preprw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
689 remote_nb, &npages, local_nb, oti, capa);
693 desc = ptlrpc_prep_bulk_exp(req, npages,
694 BULK_PUT_SOURCE, OST_BULK_PORTAL);
695 if (desc == NULL) /* XXX: check all cleanup stuff */
696 GOTO(out, rc = -ENOMEM);
698 ost_prolong_locks(exp, ioo, remote_nb, &body->oa, LCK_PW | LCK_PR);
701 for (i = 0; i < npages; i++) {
702 int page_rc = local_nb[i].rc;
704 if (page_rc < 0) { /* error */
710 if (page_rc != 0) { /* some data! */
711 LASSERT (local_nb[i].page != NULL);
712 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
713 local_nb[i].offset & ~CFS_PAGE_MASK,
717 if (page_rc != local_nb[i].len) { /* short read */
718 /* All subsequent pages should be 0 */
720 LASSERT(local_nb[i].rc == 0);
725 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
726 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
728 if (body->oa.o_valid & OBD_MD_FLFLAGS)
729 cksum_type = cksum_type_unpack(body->oa.o_flags);
730 body->oa.o_flags = cksum_type_pack(cksum_type);
731 body->oa.o_valid = OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
732 body->oa.o_cksum = ost_checksum_bulk(desc, OST_READ, cksum_type);
733 CDEBUG(D_PAGE,"checksum at read origin: %x\n",body->oa.o_cksum);
735 body->oa.o_valid = 0;
737 /* We're finishing using body->oa as an input variable */
739 /* Check if client was evicted while we were doing i/o before touching
742 /* Check if there is eviction in progress, and if so, wait for
744 if (unlikely(atomic_read(&exp->exp_obd->
745 obd_evict_inprogress))) {
746 lwi = LWI_INTR(NULL, NULL);
747 rc = l_wait_event(exp->exp_obd->
748 obd_evict_inprogress_waitq,
749 !atomic_read(&exp->exp_obd->
750 obd_evict_inprogress),
756 sptlrpc_svc_wrap_bulk(req, desc);
758 rc = ptlrpc_start_bulk_transfer(desc);
762 time_t start = cfs_time_current_sec();
764 long timeoutl = req->rq_deadline -
765 cfs_time_current_sec();
766 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
767 CFS_TICK : cfs_time_seconds(timeoutl);
768 lwi = LWI_TIMEOUT_INTERVAL(timeout,
772 rc = l_wait_event(desc->bd_waitq,
773 !ptlrpc_bulk_active(desc) ||
774 exp->exp_failed, &lwi);
775 LASSERT(rc == 0 || rc == -ETIMEDOUT);
776 /* Wait again if we changed deadline */
777 } while ((rc == -ETIMEDOUT) &&
778 (req->rq_deadline > cfs_time_current_sec()));
780 if (rc == -ETIMEDOUT) {
781 DEBUG_REQ(D_ERROR, req,
782 "timeout on bulk PUT after %ld%+lds",
783 req->rq_deadline - start,
784 cfs_time_current_sec() -
786 ptlrpc_abort_bulk(desc);
787 } else if (exp->exp_failed) {
788 DEBUG_REQ(D_ERROR, req, "Eviction on bulk PUT");
790 ptlrpc_abort_bulk(desc);
791 } else if (!desc->bd_success ||
792 desc->bd_nob_transferred != desc->bd_nob) {
793 DEBUG_REQ(D_ERROR, req, "%s bulk PUT %d(%d)",
795 "truncated" : "network error on",
796 desc->bd_nob_transferred,
798 /* XXX should this be a different errno? */
802 DEBUG_REQ(D_ERROR, req, "bulk PUT failed: rc %d", rc);
807 /* Must commit after prep above in all cases */
808 rc = obd_commitrw(OBD_BRW_READ, exp, &body->oa, 1, ioo,
809 remote_nb, npages, local_nb, oti, rc);
812 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
814 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
815 ost_drop_id(exp, &repbody->oa);
819 ost_brw_lock_put(LCK_PR, ioo, remote_nb, &lockh);
822 ptlrpc_free_bulk(desc);
826 req->rq_status = nob;
827 ptlrpc_lprocfs_brw(req, nob);
828 target_committed_to_req(req);
830 } else if (!no_reply) {
831 /* Only reply if there was no comms problem with bulk */
832 target_committed_to_req(req);
836 /* reply out callback would free */
837 ptlrpc_req_drop_rs(req);
838 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
839 "client will retry\n",
840 exp->exp_obd->obd_name,
841 exp->exp_client_uuid.uuid,
842 exp->exp_connection->c_remote_uuid.uuid,
843 libcfs_id2str(req->rq_peer));
849 static int ost_brw_write(struct ptlrpc_request *req, struct obd_trans_info *oti)
851 struct ptlrpc_bulk_desc *desc = NULL;
852 struct obd_export *exp = req->rq_export;
853 struct niobuf_remote *remote_nb;
854 struct niobuf_local *local_nb;
855 struct obd_ioobj *ioo;
856 struct ost_body *body, *repbody;
857 struct l_wait_info lwi;
858 struct lustre_handle lockh = {0};
859 struct lustre_capa *capa = NULL;
861 __u32 size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
862 int objcount, niocount, npages;
864 obd_count client_cksum = 0, server_cksum = 0;
865 cksum_type_t cksum_type = OBD_CKSUM_CRC32;
867 __u32 o_uid = 0, o_gid = 0;
870 req->rq_bulk_write = 1;
872 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK))
873 GOTO(out, rc = -EIO);
874 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_WRITE_BULK2))
875 GOTO(out, rc = -EFAULT);
877 /* pause before transaction has been started */
878 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_BULK, (obd_timeout + 1) / 4);
880 /* Check if there is eviction in progress, and if so, wait for it to
882 if (unlikely(atomic_read(&exp->exp_obd->obd_evict_inprogress))) {
883 lwi = LWI_INTR(NULL, NULL); // We do not care how long it takes
884 rc = l_wait_event(exp->exp_obd->obd_evict_inprogress_waitq,
885 !atomic_read(&exp->exp_obd->obd_evict_inprogress),
889 GOTO(out, rc = -ENOTCONN);
891 swab = lustre_msg_swabbed(req->rq_reqmsg);
892 body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
893 lustre_swab_ost_body);
895 CERROR("Missing/short ost_body\n");
896 GOTO(out, rc = -EFAULT);
899 lustre_set_req_swabbed(req, REQ_REC_OFF + 1);
900 objcount = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1) /
903 CERROR("Missing/short ioobj\n");
904 GOTO(out, rc = -EFAULT);
907 CERROR("too many ioobjs (%d)\n", objcount);
908 GOTO(out, rc = -EFAULT);
911 ioo = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1,
912 objcount * sizeof(*ioo));
913 LASSERT (ioo != NULL);
914 for (niocount = i = 0; i < objcount; i++) {
916 lustre_swab_obd_ioobj(&ioo[i]);
917 if (ioo[i].ioo_bufcnt == 0) {
918 CERROR("ioo[%d] has zero bufcnt\n", i);
919 GOTO(out, rc = -EFAULT);
921 niocount += ioo[i].ioo_bufcnt;
924 if (niocount > PTLRPC_MAX_BRW_PAGES) {
925 DEBUG_REQ(D_ERROR, req, "bulk has too many pages (%d)",
927 GOTO(out, rc = -EFAULT);
930 remote_nb = lustre_swab_reqbuf(req, REQ_REC_OFF + 2,
931 niocount * sizeof(*remote_nb),
932 lustre_swab_niobuf_remote);
933 if (remote_nb == NULL) {
934 CERROR("Missing/short niobuf\n");
935 GOTO(out, rc = -EFAULT);
937 if (swab) { /* swab the remaining niobufs */
938 for (i = 1; i < niocount; i++)
939 lustre_swab_niobuf_remote (&remote_nb[i]);
942 if (body->oa.o_valid & OBD_MD_FLOSSCAPA)
943 capa = lustre_unpack_capa(req->rq_reqmsg, REQ_REC_OFF + 3);
945 size[REPLY_REC_OFF + 1] = niocount * sizeof(*rcs);
946 rc = lustre_pack_reply(req, 3, size, NULL);
949 OBD_FAIL_TIMEOUT(OBD_FAIL_OST_BRW_PAUSE_PACK, obd_fail_val);
950 rcs = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
951 niocount * sizeof(*rcs));
954 * Per-thread array of struct niobuf_{local,remote}'s was allocated by
957 local_nb = ost_tls(req)->local;
959 rc = ost_brw_lock_get(LCK_PW, exp, ioo, remote_nb, &lockh);
964 * If getting the lock took more time than
965 * client was willing to wait, drop it. b=11330
967 if (cfs_time_current_sec() > req->rq_deadline ||
968 OBD_FAIL_CHECK(OBD_FAIL_OST_DROP_REQ)) {
970 CERROR("Dropping timed-out write from %s because locking "
971 "object "LPX64" took %ld seconds (limit was %ld).\n",
972 libcfs_id2str(req->rq_peer), ioo->ioo_id,
973 cfs_time_current_sec() - req->rq_arrival_time.tv_sec,
974 req->rq_deadline - req->rq_arrival_time.tv_sec);
975 GOTO(out_lock, rc = -ETIMEDOUT);
978 ost_prolong_locks(exp, ioo, remote_nb,&body->oa, LCK_PW);
980 /* obd_preprw clobbers oa->valid, so save what we need */
981 if (body->oa.o_valid & OBD_MD_FLCKSUM) {
982 client_cksum = body->oa.o_cksum;
983 if (body->oa.o_valid & OBD_MD_FLFLAGS)
984 cksum_type = cksum_type_unpack(body->oa.o_flags);
987 /* Because we already sync grant info with client when reconnect,
988 * grant info will be cleared for resent req, then fed_grant and
989 * total_grant will not be modified in following preprw_write */
990 if (lustre_msg_get_flags(req->rq_reqmsg) & (MSG_RESENT | MSG_REPLAY)) {
991 DEBUG_REQ(D_CACHE, req, "clear resent/replay req grant info");
992 body->oa.o_valid &= ~OBD_MD_FLGRANT;
995 if (exp_connect_rmtclient(exp)) {
996 o_uid = body->oa.o_uid;
997 o_gid = body->oa.o_gid;
999 npages = OST_THREAD_POOL_SIZE;
1000 rc = obd_preprw(OBD_BRW_WRITE, exp, &body->oa, objcount,
1001 ioo, remote_nb, &npages, local_nb, oti, capa);
1005 desc = ptlrpc_prep_bulk_exp(req, npages,
1006 BULK_GET_SINK, OST_BULK_PORTAL);
1008 GOTO(out, rc = -ENOMEM);
1010 /* NB Having prepped, we must commit... */
1012 for (i = 0; i < npages; i++)
1013 ptlrpc_prep_bulk_page(desc, local_nb[i].page,
1014 local_nb[i].offset & ~CFS_PAGE_MASK,
1017 /* Check if client was evicted while we were doing i/o before touching
1019 if (desc->bd_export->exp_failed)
1022 rc = ptlrpc_start_bulk_transfer (desc);
1024 time_t start = cfs_time_current_sec();
1026 long timeoutl = req->rq_deadline -
1027 cfs_time_current_sec();
1028 cfs_duration_t timeout = (timeoutl <= 0 || rc) ?
1029 CFS_TICK : cfs_time_seconds(timeoutl);
1030 lwi = LWI_TIMEOUT_INTERVAL(timeout, cfs_time_seconds(1),
1031 ost_bulk_timeout, desc);
1032 rc = l_wait_event(desc->bd_waitq,
1033 !ptlrpc_bulk_active(desc) ||
1034 desc->bd_export->exp_failed, &lwi);
1035 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1036 /* Wait again if we changed deadline */
1037 } while ((rc == -ETIMEDOUT) &&
1038 (req->rq_deadline > cfs_time_current_sec()));
1040 if (rc == -ETIMEDOUT) {
1041 DEBUG_REQ(D_ERROR, req,
1042 "timeout on bulk GET after %ld%+lds",
1043 req->rq_deadline - start,
1044 cfs_time_current_sec() -
1046 ptlrpc_abort_bulk(desc);
1047 } else if (desc->bd_export->exp_failed) {
1048 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1050 ptlrpc_abort_bulk(desc);
1051 } else if (!desc->bd_success ||
1052 desc->bd_nob_transferred != desc->bd_nob) {
1053 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1055 "truncated" : "network error on",
1056 desc->bd_nob_transferred, desc->bd_nob);
1057 /* XXX should this be a different errno? */
1061 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1066 sptlrpc_svc_unwrap_bulk(req, desc);
1068 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1070 memcpy(&repbody->oa, &body->oa, sizeof(repbody->oa));
1072 if (unlikely(client_cksum != 0 && rc == 0)) {
1073 static int cksum_counter;
1074 repbody->oa.o_valid |= OBD_MD_FLCKSUM | OBD_MD_FLFLAGS;
1075 repbody->oa.o_flags &= ~OBD_FL_CKSUM_ALL;
1076 repbody->oa.o_flags |= cksum_type_pack(cksum_type);
1077 server_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1078 repbody->oa.o_cksum = server_cksum;
1080 if (unlikely(client_cksum != server_cksum)) {
1081 CERROR("client csum %x, server csum %x\n",
1082 client_cksum, server_cksum);
1084 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
1085 CDEBUG(D_INFO, "Checksum %u from %s OK: %x\n",
1086 cksum_counter, libcfs_id2str(req->rq_peer),
1091 /* Must commit after prep above in all cases */
1092 rc = obd_commitrw(OBD_BRW_WRITE, exp, &repbody->oa, objcount, ioo,
1093 remote_nb, npages, local_nb, oti, rc);
1094 if (exp_connect_rmtclient(exp)) {
1095 repbody->oa.o_uid = o_uid;
1096 repbody->oa.o_gid = o_gid;
1099 if (unlikely(client_cksum != server_cksum && rc == 0)) {
1100 int new_cksum = ost_checksum_bulk(desc, OST_WRITE, cksum_type);
1105 if (new_cksum == server_cksum)
1106 msg = "changed in transit before arrival at OST";
1107 else if (new_cksum == client_cksum)
1108 msg = "initial checksum before message complete";
1110 msg = "changed in transit AND after initial checksum";
1112 if (req->rq_peer.nid == desc->bd_sender) {
1116 router = libcfs_nid2str(desc->bd_sender);
1119 LCONSOLE_ERROR_MSG(0x168, "%s: BAD WRITE CHECKSUM: %s from "
1120 "%s%s%s inum "LPU64"/"LPU64" object "
1121 LPU64"/"LPU64" extent ["LPU64"-"LPU64"]\n",
1122 exp->exp_obd->obd_name, msg,
1123 libcfs_id2str(req->rq_peer),
1125 body->oa.o_valid & OBD_MD_FLFID ?
1126 body->oa.o_fid : (__u64)0,
1127 body->oa.o_valid & OBD_MD_FLFID ?
1128 body->oa.o_generation :(__u64)0,
1130 body->oa.o_valid & OBD_MD_FLGROUP ?
1131 body->oa.o_gr : (__u64)0,
1133 local_nb[npages-1].offset +
1134 local_nb[npages-1].len - 1 );
1135 CERROR("client csum %x, original server csum %x, "
1136 "server csum now %x\n",
1137 client_cksum, server_cksum, new_cksum);
1143 /* set per-requested niobuf return codes */
1144 for (i = j = 0; i < niocount; i++) {
1145 int len = remote_nb[i].len;
1150 LASSERT(j < npages);
1151 if (local_nb[j].rc < 0)
1152 rcs[i] = local_nb[j].rc;
1153 len -= local_nb[j].len;
1158 LASSERT(j == npages);
1159 ptlrpc_lprocfs_brw(req, nob);
1163 ost_brw_lock_put(LCK_PW, ioo, remote_nb, &lockh);
1166 ptlrpc_free_bulk(desc);
1169 oti_to_request(oti, req);
1170 target_committed_to_req(req);
1171 rc = ptlrpc_reply(req);
1172 } else if (!no_reply) {
1173 /* Only reply if there was no comms problem with bulk */
1174 target_committed_to_req(req);
1175 req->rq_status = rc;
1178 /* reply out callback would free */
1179 ptlrpc_req_drop_rs(req);
1180 CWARN("%s: ignoring bulk IO comm error with %s@%s id %s - "
1181 "client will retry\n",
1182 exp->exp_obd->obd_name,
1183 exp->exp_client_uuid.uuid,
1184 exp->exp_connection->c_remote_uuid.uuid,
1185 libcfs_id2str(req->rq_peer));
1190 static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req)
1192 char *key, *val = NULL;
1193 int keylen, vallen, rc = 0;
1196 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1198 DEBUG_REQ(D_HA, req, "no set_info key");
1201 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1203 rc = lustre_pack_reply(req, 1, NULL, NULL);
1207 vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);
1209 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
1211 if (KEY_IS(KEY_EVICT_BY_NID)) {
1213 obd_export_evict_by_nid(exp->exp_obd, val);
1218 rc = obd_set_info_async(exp, keylen, key, vallen, val, NULL);
1220 lustre_msg_set_status(req->rq_repmsg, 0);
1224 static int ost_get_info(struct obd_export *exp, struct ptlrpc_request *req)
1227 int keylen, replylen, rc = 0;
1228 struct req_capsule *pill = &req->rq_pill;
1231 req_capsule_set(&req->rq_pill, &RQF_OST_GET_INFO_GENERIC);
1233 /* this common part for get_info rpc */
1234 key = req_capsule_client_get(pill, &RMF_SETINFO_KEY);
1236 DEBUG_REQ(D_HA, req, "no get_info key");
1239 keylen = req_capsule_get_size(pill, &RMF_SETINFO_KEY, RCL_CLIENT);
1241 rc = obd_get_info(exp, keylen, key, &replylen, NULL, NULL);
1245 req_capsule_set_size(pill, &RMF_GENERIC_DATA,
1246 RCL_SERVER, replylen);
1248 rc = req_capsule_server_pack(pill);
1252 reply = req_capsule_server_get(pill, &RMF_GENERIC_DATA);
1256 /* call again to fill in the reply buffer */
1257 rc = obd_get_info(exp, keylen, key, &replylen, reply, NULL);
1259 lustre_msg_set_status(req->rq_repmsg, 0);
1263 #ifdef HAVE_QUOTA_SUPPORT
1264 static int ost_handle_quotactl(struct ptlrpc_request *req)
1266 struct obd_quotactl *oqctl, *repoqc;
1270 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1272 GOTO(out, rc = -EPROTO);
1274 rc = req_capsule_server_pack(&req->rq_pill);
1278 repoqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1279 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1286 static int ost_handle_quotacheck(struct ptlrpc_request *req)
1288 struct obd_quotactl *oqctl;
1292 oqctl = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1296 rc = req_capsule_server_pack(&req->rq_pill);
1300 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1304 static int ost_handle_quota_adjust_qunit(struct ptlrpc_request *req)
1306 struct quota_adjust_qunit *oqaq, *repoqa;
1307 struct lustre_quota_ctxt *qctxt;
1311 qctxt = &req->rq_export->exp_obd->u.obt.obt_qctxt;
1312 oqaq = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1314 GOTO(out, rc = -EPROTO);
1316 rc = req_capsule_server_pack(&req->rq_pill);
1320 repoqa = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_ADJUST_QUNIT);
1321 req->rq_status = obd_quota_adjust_qunit(req->rq_export, oqaq, qctxt);
1329 static int ost_llog_handle_connect(struct obd_export *exp,
1330 struct ptlrpc_request *req)
1332 struct llogd_conn_body *body;
1336 body = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*body));
1337 rc = obd_llog_connect(exp, body);
1341 #define ost_init_sec_none(reply, exp) \
1343 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT | \
1344 OBD_CONNECT_RMT_CLIENT_FORCE | \
1345 OBD_CONNECT_OSS_CAPA); \
1346 spin_lock(&exp->exp_lock); \
1347 exp->exp_connect_flags = reply->ocd_connect_flags; \
1348 spin_unlock(&exp->exp_lock); \
1351 static int ost_init_sec_level(struct ptlrpc_request *req)
1353 struct obd_export *exp = req->rq_export;
1354 struct req_capsule *pill = &req->rq_pill;
1355 struct obd_device *obd = exp->exp_obd;
1356 struct filter_obd *filter = &obd->u.filter;
1357 char *client = libcfs_nid2str(req->rq_peer.nid);
1358 struct obd_connect_data *data, *reply;
1362 data = req_capsule_client_get(pill, &RMF_CONNECT_DATA);
1363 reply = req_capsule_server_get(pill, &RMF_CONNECT_DATA);
1364 if (data == NULL || reply == NULL)
1367 /* connection from MDT is always trusted */
1368 if (req->rq_auth_usr_mdt) {
1369 ost_init_sec_none(reply, exp);
1373 /* no GSS support case */
1374 if (!req->rq_auth_gss) {
1375 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1376 CWARN("client %s -> target %s does not user GSS, "
1377 "can not run under security level %d.\n",
1378 client, obd->obd_name, filter->fo_sec_level);
1381 ost_init_sec_none(reply, exp);
1386 /* old version case */
1387 if (unlikely(!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) ||
1388 !(data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA))) {
1389 if (filter->fo_sec_level > LUSTRE_SEC_NONE) {
1390 CWARN("client %s -> target %s uses old version, "
1391 "can not run under security level %d.\n",
1392 client, obd->obd_name, filter->fo_sec_level);
1395 CWARN("client %s -> target %s uses old version, "
1396 "run under security level %d.\n",
1397 client, obd->obd_name, filter->fo_sec_level);
1398 ost_init_sec_none(reply, exp);
1403 remote = data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT_FORCE;
1405 if (!req->rq_auth_remote)
1406 CDEBUG(D_SEC, "client (local realm) %s -> target %s "
1407 "asked to be remote.\n", client, obd->obd_name);
1408 } else if (req->rq_auth_remote) {
1410 CDEBUG(D_SEC, "client (remote realm) %s -> target %s is set "
1411 "as remote by default.\n", client, obd->obd_name);
1415 if (!filter->fo_fl_oss_capa) {
1416 CDEBUG(D_SEC, "client %s -> target %s is set as remote,"
1417 " but OSS capabilities are not enabled: %d.\n",
1418 client, obd->obd_name, filter->fo_fl_oss_capa);
1423 switch (filter->fo_sec_level) {
1424 case LUSTRE_SEC_NONE:
1426 ost_init_sec_none(reply, exp);
1429 CDEBUG(D_SEC, "client %s -> target %s is set as remote, "
1430 "can not run under security level %d.\n",
1431 client, obd->obd_name, filter->fo_sec_level);
1434 case LUSTRE_SEC_REMOTE:
1436 ost_init_sec_none(reply, exp);
1438 case LUSTRE_SEC_ALL:
1440 reply->ocd_connect_flags &= ~(OBD_CONNECT_RMT_CLIENT |
1441 OBD_CONNECT_RMT_CLIENT_FORCE);
1442 if (!filter->fo_fl_oss_capa)
1443 reply->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
1445 spin_lock(&exp->exp_lock);
1446 exp->exp_connect_flags = reply->ocd_connect_flags;
1447 spin_unlock(&exp->exp_lock);
1457 static int filter_export_check_flavor(struct filter_obd *filter,
1458 struct obd_export *exp,
1459 struct ptlrpc_request *req)
1464 * this should be done in filter_connect()/filter_reconnect(), but
1465 * we can't obtain information like NID, which stored in incoming
1466 * request, thus can't decide what flavor to use. so we do it here.
1468 * This hack should be removed after the OST stack be rewritten, just
1469 * like what we are doing in mdt_obd_connect()/mdt_obd_reconnect().
1471 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_INVALID)
1474 CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from));
1475 spin_lock(&exp->exp_lock);
1476 exp->exp_sp_peer = req->rq_sp_from;
1478 read_lock(&filter->fo_sptlrpc_lock);
1479 sptlrpc_rule_set_choose(&filter->fo_sptlrpc_rset, exp->exp_sp_peer,
1480 req->rq_peer.nid, &exp->exp_flvr);
1481 read_unlock(&filter->fo_sptlrpc_lock);
1483 if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
1484 CERROR("invalid rpc flavor %x, expect %x, from %s\n",
1485 req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
1486 libcfs_nid2str(req->rq_peer.nid));
1487 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID;
1491 spin_unlock(&exp->exp_lock);
1496 static int ost_filter_recovery_request(struct ptlrpc_request *req,
1497 struct obd_device *obd, int *process)
1499 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1500 case OST_CONNECT: /* This will never get here, but for completeness. */
1501 case OST_DISCONNECT:
1512 case OBD_LOG_CANCEL:
1514 *process = target_queue_recovery_request(req, obd);
1518 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1524 int ost_msg_check_version(struct lustre_msg *msg)
1528 switch(lustre_msg_get_opc(msg)) {
1530 case OST_DISCONNECT:
1533 case SEC_CTX_INIT_CONT:
1535 rc = lustre_msg_check_version(msg, LUSTRE_OBD_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_OBD_VERSION);
1553 #ifdef HAVE_QUOTA_SUPPORT
1554 case OST_QUOTACHECK:
1556 case OST_QUOTA_ADJUST_QUNIT:
1558 rc = lustre_msg_check_version(msg, LUSTRE_OST_VERSION);
1560 CERROR("bad opc %u version %08x, expecting %08x\n",
1561 lustre_msg_get_opc(msg),
1562 lustre_msg_get_version(msg),
1563 LUSTRE_OST_VERSION);
1568 case LDLM_BL_CALLBACK:
1569 case LDLM_CP_CALLBACK:
1570 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1572 CERROR("bad opc %u version %08x, expecting %08x\n",
1573 lustre_msg_get_opc(msg),
1574 lustre_msg_get_version(msg),
1575 LUSTRE_DLM_VERSION);
1577 case LLOG_ORIGIN_CONNECT:
1578 case OBD_LOG_CANCEL:
1579 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1581 CERROR("bad opc %u version %08x, expecting %08x\n",
1582 lustre_msg_get_opc(msg),
1583 lustre_msg_get_version(msg),
1584 LUSTRE_LOG_VERSION);
1587 CERROR("Unexpected opcode %d\n", lustre_msg_get_opc(msg));
1593 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
1594 int ost_handle(struct ptlrpc_request *req)
1596 struct obd_trans_info trans_info = { 0, };
1597 struct obd_trans_info *oti = &trans_info;
1598 int should_process, fail = OBD_FAIL_OST_ALL_REPLY_NET, rc = 0;
1599 struct obd_device *obd = NULL;
1602 LASSERT(current->journal_info == NULL);
1604 /* primordial rpcs don't affect server recovery */
1605 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1607 case SEC_CTX_INIT_CONT:
1612 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
1614 /* XXX identical to MDS */
1615 if (lustre_msg_get_opc(req->rq_reqmsg) != OST_CONNECT) {
1618 if (req->rq_export == NULL) {
1619 CDEBUG(D_HA,"operation %d on unconnected OST from %s\n",
1620 lustre_msg_get_opc(req->rq_reqmsg),
1621 libcfs_id2str(req->rq_peer));
1622 req->rq_status = -ENOTCONN;
1623 GOTO(out, rc = -ENOTCONN);
1626 obd = req->rq_export->exp_obd;
1628 /* Check for aborted recovery. */
1629 spin_lock_bh(&obd->obd_processing_task_lock);
1630 recovering = obd->obd_recovering;
1631 spin_unlock_bh(&obd->obd_processing_task_lock);
1633 rc = ost_filter_recovery_request(req, obd,
1635 if (rc || !should_process)
1637 else if (should_process < 0) {
1638 req->rq_status = should_process;
1639 rc = ptlrpc_error(req);
1647 rc = ost_msg_check_version(req->rq_reqmsg);
1651 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1653 CDEBUG(D_INODE, "connect\n");
1654 req_capsule_set(&req->rq_pill, &RQF_OST_CONNECT);
1655 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET))
1657 rc = target_handle_connect(req);
1658 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CONNECT_NET2))
1661 rc = ost_init_sec_level(req);
1663 struct obd_export *exp = req->rq_export;
1666 rc = filter_export_check_flavor(&obd->u.filter,
1672 case OST_DISCONNECT:
1673 CDEBUG(D_INODE, "disconnect\n");
1674 req_capsule_set(&req->rq_pill, &RQF_OST_DISCONNECT);
1675 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DISCONNECT_NET))
1677 rc = target_handle_disconnect(req);
1680 CDEBUG(D_INODE, "create\n");
1681 if (OBD_FAIL_CHECK(OBD_FAIL_OST_CREATE_NET))
1683 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1684 GOTO(out, rc = -ENOSPC);
1685 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1686 GOTO(out, rc = -EROFS);
1687 rc = ost_create(req->rq_export, req, oti);
1690 CDEBUG(D_INODE, "destroy\n");
1691 if (OBD_FAIL_CHECK(OBD_FAIL_OST_DESTROY_NET))
1693 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1694 GOTO(out, rc = -EROFS);
1695 rc = ost_destroy(req->rq_export, req, oti);
1698 CDEBUG(D_INODE, "getattr\n");
1699 if (OBD_FAIL_CHECK(OBD_FAIL_OST_GETATTR_NET))
1701 rc = ost_getattr(req->rq_export, req);
1704 CDEBUG(D_INODE, "setattr\n");
1705 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SETATTR_NET))
1707 rc = ost_setattr(req->rq_export, req, oti);
1710 CDEBUG(D_INODE, "write\n");
1711 /* req->rq_request_portal would be nice, if it was set */
1712 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1713 CERROR("%s: deny write request from %s to portal %u\n",
1714 req->rq_export->exp_obd->obd_name,
1715 obd_export_nid2str(req->rq_export),
1716 req->rq_rqbd->rqbd_service->srv_req_portal);
1717 GOTO(out, rc = -EPROTO);
1719 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1721 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOSPC))
1722 GOTO(out, rc = -ENOSPC);
1723 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1724 GOTO(out, rc = -EROFS);
1725 rc = ost_brw_write(req, oti);
1726 LASSERT(current->journal_info == NULL);
1727 /* ost_brw_write sends its own replies */
1730 CDEBUG(D_INODE, "read\n");
1731 /* req->rq_request_portal would be nice, if it was set */
1732 if (req->rq_rqbd->rqbd_service->srv_req_portal !=OST_IO_PORTAL){
1733 CERROR("%s: deny read request from %s to portal %u\n",
1734 req->rq_export->exp_obd->obd_name,
1735 obd_export_nid2str(req->rq_export),
1736 req->rq_rqbd->rqbd_service->srv_req_portal);
1737 GOTO(out, rc = -EPROTO);
1739 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_NET))
1741 rc = ost_brw_read(req, oti);
1742 LASSERT(current->journal_info == NULL);
1743 /* ost_brw_read sends its own replies */
1746 CDEBUG(D_INODE, "punch\n");
1747 if (OBD_FAIL_CHECK(OBD_FAIL_OST_PUNCH_NET))
1749 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1750 GOTO(out, rc = -EROFS);
1751 rc = ost_punch(req->rq_export, req, oti);
1754 CDEBUG(D_INODE, "statfs\n");
1755 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_NET))
1757 rc = ost_statfs(req);
1760 CDEBUG(D_INODE, "sync\n");
1761 if (OBD_FAIL_CHECK(OBD_FAIL_OST_SYNC_NET))
1763 rc = ost_sync(req->rq_export, req);
1766 DEBUG_REQ(D_INODE, req, "set_info");
1767 req_capsule_set(&req->rq_pill, &RQF_OST_SET_INFO);
1768 rc = ost_set_info(req->rq_export, req);
1771 DEBUG_REQ(D_INODE, req, "get_info");
1772 rc = ost_get_info(req->rq_export, req);
1774 #ifdef HAVE_QUOTA_SUPPORT
1775 case OST_QUOTACHECK:
1776 CDEBUG(D_INODE, "quotacheck\n");
1777 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACHECK);
1778 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACHECK_NET))
1780 rc = ost_handle_quotacheck(req);
1783 CDEBUG(D_INODE, "quotactl\n");
1784 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTACTL);
1785 if (OBD_FAIL_CHECK(OBD_FAIL_OST_QUOTACTL_NET))
1787 rc = ost_handle_quotactl(req);
1789 case OST_QUOTA_ADJUST_QUNIT:
1790 CDEBUG(D_INODE, "quota_adjust_qunit\n");
1791 req_capsule_set(&req->rq_pill, &RQF_OST_QUOTA_ADJUST_QUNIT);
1792 rc = ost_handle_quota_adjust_qunit(req);
1796 DEBUG_REQ(D_INODE, req, "ping");
1797 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
1798 rc = target_handle_ping(req);
1800 /* FIXME - just reply status */
1801 case LLOG_ORIGIN_CONNECT:
1802 DEBUG_REQ(D_INODE, req, "log connect");
1803 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_CONNECT);
1804 rc = ost_llog_handle_connect(req->rq_export, req);
1805 req->rq_status = rc;
1806 rc = req_capsule_server_pack(&req->rq_pill);
1809 RETURN(ptlrpc_reply(req));
1810 case OBD_LOG_CANCEL:
1811 CDEBUG(D_INODE, "log cancel\n");
1812 req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL);
1813 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET))
1815 rc = llog_origin_handle_cancel(req);
1816 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP))
1818 req->rq_status = rc;
1819 rc = req_capsule_server_pack(&req->rq_pill);
1822 RETURN(ptlrpc_reply(req));
1824 CDEBUG(D_INODE, "enqueue\n");
1825 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
1826 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE))
1828 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1829 ldlm_server_blocking_ast,
1830 ldlm_server_glimpse_ast);
1831 fail = OBD_FAIL_OST_LDLM_REPLY_NET;
1834 CDEBUG(D_INODE, "convert\n");
1835 req_capsule_set(&req->rq_pill, &RQF_LDLM_CONVERT);
1836 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CONVERT))
1838 rc = ldlm_handle_convert(req);
1841 CDEBUG(D_INODE, "cancel\n");
1842 req_capsule_set(&req->rq_pill, &RQF_LDLM_CANCEL);
1843 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL))
1845 rc = ldlm_handle_cancel(req);
1847 case LDLM_BL_CALLBACK:
1848 case LDLM_CP_CALLBACK:
1849 CDEBUG(D_INODE, "callback\n");
1850 CERROR("callbacks should not happen on OST\n");
1853 CERROR("Unexpected opcode %d\n",
1854 lustre_msg_get_opc(req->rq_reqmsg));
1855 req->rq_status = -ENOTSUPP;
1856 rc = ptlrpc_error(req);
1860 LASSERT(current->journal_info == NULL);
1863 /* If we're DISCONNECTing, the export_data is already freed */
1864 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != OST_DISCONNECT)
1865 target_committed_to_req(req);
1869 oti_to_request(oti, req);
1871 target_send_reply(req, rc, fail);
1874 EXPORT_SYMBOL(ost_handle);
1876 * free per-thread pool created by ost_thread_init().
1878 static void ost_thread_done(struct ptlrpc_thread *thread)
1880 struct ost_thread_local_cache *tls; /* TLS stands for Thread-Local
1885 LASSERT(thread != NULL);
1888 * be prepared to handle partially-initialized pools (because this is
1889 * called from ost_thread_init() for cleanup.
1891 tls = thread->t_data;
1894 thread->t_data = NULL;
1900 * initialize per-thread page pool (bug 5137).
1902 static int ost_thread_init(struct ptlrpc_thread *thread)
1904 struct ost_thread_local_cache *tls;
1908 LASSERT(thread != NULL);
1909 LASSERT(thread->t_data == NULL);
1910 LASSERTF(thread->t_id <= OSS_THREADS_MAX, "%u\n", thread->t_id);
1915 thread->t_data = tls;
1919 #define OST_WATCHDOG_TIMEOUT (obd_timeout * 1000)
1921 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
1922 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
1924 struct ost_obd *ost = &obd->u.ost;
1925 struct lprocfs_static_vars lvars;
1926 int oss_min_threads;
1927 int oss_max_threads;
1928 int oss_min_create_threads;
1929 int oss_max_create_threads;
1933 rc = cleanup_group_info();
1937 lprocfs_ost_init_vars(&lvars);
1938 lprocfs_obd_setup(obd, lvars.obd_vars);
1940 sema_init(&ost->ost_health_sem, 1);
1942 if (oss_num_threads) {
1943 /* If oss_num_threads is set, it is the min and the max. */
1944 if (oss_num_threads > OSS_THREADS_MAX)
1945 oss_num_threads = OSS_THREADS_MAX;
1946 if (oss_num_threads < OSS_THREADS_MIN)
1947 oss_num_threads = OSS_THREADS_MIN;
1948 oss_max_threads = oss_min_threads = oss_num_threads;
1950 /* Base min threads on memory and cpus */
1951 oss_min_threads = num_possible_cpus() * num_physpages >>
1952 (27 - CFS_PAGE_SHIFT);
1953 if (oss_min_threads < OSS_THREADS_MIN)
1954 oss_min_threads = OSS_THREADS_MIN;
1955 /* Insure a 4x range for dynamic threads */
1956 if (oss_min_threads > OSS_THREADS_MAX / 4)
1957 oss_min_threads = OSS_THREADS_MAX / 4;
1958 oss_max_threads = min(OSS_THREADS_MAX, oss_min_threads * 4);
1962 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1963 OST_MAXREPSIZE, OST_REQUEST_PORTAL,
1964 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1965 ost_handle, LUSTRE_OSS_NAME,
1966 obd->obd_proc_entry, target_print_req,
1967 oss_min_threads, oss_max_threads,
1968 "ll_ost", LCT_DT_THREAD);
1969 if (ost->ost_service == NULL) {
1970 CERROR("failed to start service\n");
1971 GOTO(out_lprocfs, rc = -ENOMEM);
1974 rc = ptlrpc_start_threads(obd, ost->ost_service);
1976 GOTO(out_service, rc = -EINVAL);
1978 if (oss_num_create_threads) {
1979 if (oss_num_create_threads > OSS_MAX_CREATE_THREADS)
1980 oss_num_create_threads = OSS_MAX_CREATE_THREADS;
1981 if (oss_num_create_threads < OSS_MIN_CREATE_THREADS)
1982 oss_num_create_threads = OSS_MIN_CREATE_THREADS;
1983 oss_min_create_threads = oss_max_create_threads =
1984 oss_num_create_threads;
1986 oss_min_create_threads = OSS_MIN_CREATE_THREADS;
1987 oss_max_create_threads = OSS_MAX_CREATE_THREADS;
1990 ost->ost_create_service =
1991 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
1992 OST_MAXREPSIZE, OST_CREATE_PORTAL,
1993 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
1994 ost_handle, "ost_create",
1995 obd->obd_proc_entry, target_print_req,
1996 oss_min_create_threads, oss_max_create_threads,
1997 "ll_ost_creat", LCT_DT_THREAD);
1998 if (ost->ost_create_service == NULL) {
1999 CERROR("failed to start OST create service\n");
2000 GOTO(out_service, rc = -ENOMEM);
2003 rc = ptlrpc_start_threads(obd, ost->ost_create_service);
2005 GOTO(out_create, rc = -EINVAL);
2007 ost->ost_io_service =
2008 ptlrpc_init_svc(OST_NBUFS, OST_BUFSIZE, OST_MAXREQSIZE,
2009 OST_MAXREPSIZE, OST_IO_PORTAL,
2010 OSC_REPLY_PORTAL, OSS_SERVICE_WATCHDOG_FACTOR,
2011 ost_handle, "ost_io",
2012 obd->obd_proc_entry, target_print_req,
2013 oss_min_threads, oss_max_threads,
2014 "ll_ost_io", LCT_DT_THREAD);
2015 if (ost->ost_io_service == NULL) {
2016 CERROR("failed to start OST I/O service\n");
2017 GOTO(out_create, rc = -ENOMEM);
2020 ost->ost_io_service->srv_init = ost_thread_init;
2021 ost->ost_io_service->srv_done = ost_thread_done;
2022 ost->ost_io_service->srv_cpu_affinity = 1;
2023 rc = ptlrpc_start_threads(obd, ost->ost_io_service);
2025 GOTO(out_io, rc = -EINVAL);
2027 ping_evictor_start();
2032 ptlrpc_unregister_service(ost->ost_io_service);
2033 ost->ost_io_service = NULL;
2035 ptlrpc_unregister_service(ost->ost_create_service);
2036 ost->ost_create_service = NULL;
2038 ptlrpc_unregister_service(ost->ost_service);
2039 ost->ost_service = NULL;
2041 lprocfs_obd_cleanup(obd);
2045 static int ost_cleanup(struct obd_device *obd)
2047 struct ost_obd *ost = &obd->u.ost;
2051 ping_evictor_stop();
2053 spin_lock_bh(&obd->obd_processing_task_lock);
2054 if (obd->obd_recovering) {
2055 target_cancel_recovery_timer(obd);
2056 obd->obd_recovering = 0;
2058 spin_unlock_bh(&obd->obd_processing_task_lock);
2060 down(&ost->ost_health_sem);
2061 ptlrpc_unregister_service(ost->ost_service);
2062 ptlrpc_unregister_service(ost->ost_create_service);
2063 ptlrpc_unregister_service(ost->ost_io_service);
2064 ost->ost_service = NULL;
2065 ost->ost_create_service = NULL;
2066 up(&ost->ost_health_sem);
2068 lprocfs_obd_cleanup(obd);
2073 static int ost_health_check(struct obd_device *obd)
2075 struct ost_obd *ost = &obd->u.ost;
2078 down(&ost->ost_health_sem);
2079 rc |= ptlrpc_service_health_check(ost->ost_service);
2080 rc |= ptlrpc_service_health_check(ost->ost_create_service);
2081 rc |= ptlrpc_service_health_check(ost->ost_io_service);
2082 up(&ost->ost_health_sem);
2085 * health_check to return 0 on healthy
2086 * and 1 on unhealthy.
2094 struct ost_thread_local_cache *ost_tls(struct ptlrpc_request *r)
2096 return (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
2099 /* use obd ops to offer management infrastructure */
2100 static struct obd_ops ost_obd_ops = {
2101 .o_owner = THIS_MODULE,
2102 .o_setup = ost_setup,
2103 .o_cleanup = ost_cleanup,
2104 .o_health_check = ost_health_check,
2108 static int __init ost_init(void)
2110 struct lprocfs_static_vars lvars;
2114 lprocfs_ost_init_vars(&lvars);
2115 rc = class_register_type(&ost_obd_ops, NULL, lvars.module_vars,
2116 LUSTRE_OSS_NAME, NULL);
2118 if (ost_num_threads != 0 && oss_num_threads == 0) {
2119 LCONSOLE_INFO("ost_num_threads module parameter is deprecated, "
2120 "use oss_num_threads instead or unset both for "
2121 "dynamic thread startup\n");
2122 oss_num_threads = ost_num_threads;
2128 static void /*__exit*/ ost_exit(void)
2130 class_unregister_type(LUSTRE_OSS_NAME);
2133 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2134 MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
2135 MODULE_LICENSE("GPL");
2137 module_init(ost_init);
2138 module_exit(ost_exit);