4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/selftest/brw_test.c
38 * Author: Isaac Huang <isaac@clusterfs.com>
43 static int brw_srv_workitems = SFW_TEST_WI_MAX;
44 module_param(brw_srv_workitems, int, 0644);
45 MODULE_PARM_DESC(brw_srv_workitems, "# BRW server workitems");
47 static int brw_inject_errors;
48 module_param(brw_inject_errors, int, 0644);
49 MODULE_PARM_DESC(brw_inject_errors, "# data errors to inject randomly, zero by default");
52 brw_client_fini(struct sfw_test_instance *tsi)
54 struct srpc_bulk *bulk;
55 struct sfw_test_unit *tsu;
57 LASSERT(tsi->tsi_is_client);
59 list_for_each_entry(tsu, &tsi->tsi_units, tsu_list) {
60 bulk = tsu->tsu_private;
65 tsu->tsu_private = NULL;
70 brw_client_init(struct sfw_test_instance *tsi)
72 struct sfw_session *sn = tsi->tsi_batch->bat_session;
77 struct srpc_bulk *bulk;
78 struct sfw_test_unit *tsu;
81 LASSERT(tsi->tsi_is_client);
83 if (!(sn->sn_features & LST_FEAT_BULK_LEN)) {
84 struct test_bulk_req *breq = &tsi->tsi_u.bulk_v0;
87 flags = breq->blk_flags;
90 * NB: this is not going to work for variable page size,
91 * but we have to keep it for compatibility
93 len = npg * PAGE_SIZE;
95 struct test_bulk_req_v1 *breq = &tsi->tsi_u.bulk_v1;
98 * I should never get this step if it's unknown feature
99 * because make_session will reject unknown feature
101 LASSERT(!(sn->sn_features & ~LST_FEATS_MASK));
104 flags = breq->blk_flags;
106 npg = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
109 if (npg > LNET_MAX_IOV || npg <= 0)
112 if (opc != LST_BRW_READ && opc != LST_BRW_WRITE)
115 if (flags != LST_BRW_CHECK_NONE &&
116 flags != LST_BRW_CHECK_FULL && flags != LST_BRW_CHECK_SIMPLE)
119 list_for_each_entry(tsu, &tsi->tsi_units, tsu_list) {
120 bulk = srpc_alloc_bulk(lnet_cpt_of_nid(tsu->tsu_dest.nid),
121 npg, len, opc == LST_BRW_READ);
123 brw_client_fini(tsi);
127 tsu->tsu_private = bulk;
133 #define BRW_POISON 0xbeefbeefbeefbeefULL
134 #define BRW_MAGIC 0xeeb0eeb1eeb2eeb3ULL
135 #define BRW_MSIZE sizeof(__u64)
138 brw_inject_one_error(void)
140 struct timespec64 ts;
142 if (brw_inject_errors <= 0)
147 if (!((ts.tv_nsec / NSEC_PER_USEC) & 1))
150 return brw_inject_errors--;
154 brw_fill_page(struct page *pg, int pattern, __u64 magic)
156 char *addr = page_address(pg);
161 if (pattern == LST_BRW_CHECK_NONE)
164 if (magic == BRW_MAGIC)
165 magic += brw_inject_one_error();
167 if (pattern == LST_BRW_CHECK_SIMPLE) {
168 memcpy(addr, &magic, BRW_MSIZE);
169 addr += PAGE_SIZE - BRW_MSIZE;
170 memcpy(addr, &magic, BRW_MSIZE);
174 if (pattern == LST_BRW_CHECK_FULL) {
175 for (i = 0; i < PAGE_SIZE / BRW_MSIZE; i++)
176 memcpy(addr + i * BRW_MSIZE, &magic, BRW_MSIZE);
184 brw_check_page(struct page *pg, int pattern, __u64 magic)
186 char *addr = page_address(pg);
187 __u64 data = 0; /* make compiler happy */
192 if (pattern == LST_BRW_CHECK_NONE)
195 if (pattern == LST_BRW_CHECK_SIMPLE) {
196 data = *((__u64 *)addr);
200 addr += PAGE_SIZE - BRW_MSIZE;
201 data = *((__u64 *)addr);
208 if (pattern == LST_BRW_CHECK_FULL) {
209 for (i = 0; i < PAGE_SIZE / BRW_MSIZE; i++) {
210 data = *(((__u64 *)addr) + i);
221 CERROR("Bad data in page %p: %#llx, %#llx expected\n",
227 brw_fill_bulk(struct srpc_bulk *bk, int pattern, __u64 magic)
232 for (i = 0; i < bk->bk_niov; i++) {
233 pg = bk->bk_iovs[i].kiov_page;
234 brw_fill_page(pg, pattern, magic);
239 brw_check_bulk(struct srpc_bulk *bk, int pattern, __u64 magic)
244 for (i = 0; i < bk->bk_niov; i++) {
245 pg = bk->bk_iovs[i].kiov_page;
246 if (brw_check_page(pg, pattern, magic)) {
247 CERROR("Bulk page %p (%d/%d) is corrupted!\n",
257 brw_client_prep_rpc(struct sfw_test_unit *tsu,
258 lnet_process_id_t dest, struct srpc_client_rpc **rpcpp)
260 struct srpc_bulk *bulk = tsu->tsu_private;
261 struct sfw_test_instance *tsi = tsu->tsu_instance;
262 struct sfw_session *sn = tsi->tsi_batch->bat_session;
263 struct srpc_client_rpc *rpc;
264 struct srpc_brw_reqst *req;
274 if (!(sn->sn_features & LST_FEAT_BULK_LEN)) {
275 struct test_bulk_req *breq = &tsi->tsi_u.bulk_v0;
278 flags = breq->blk_flags;
280 len = npg * PAGE_SIZE;
282 struct test_bulk_req_v1 *breq = &tsi->tsi_u.bulk_v1;
285 * I should never get this step if it's unknown feature
286 * because make_session will reject unknown feature
288 LASSERT(!(sn->sn_features & ~LST_FEATS_MASK));
291 flags = breq->blk_flags;
293 npg = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
296 rc = sfw_create_test_rpc(tsu, dest, sn->sn_features, npg, len, &rpc);
300 memcpy(&rpc->crpc_bulk, bulk, offsetof(struct srpc_bulk, bk_iovs[npg]));
301 if (opc == LST_BRW_WRITE)
302 brw_fill_bulk(&rpc->crpc_bulk, flags, BRW_MAGIC);
304 brw_fill_bulk(&rpc->crpc_bulk, flags, BRW_POISON);
306 req = &rpc->crpc_reqstmsg.msg_body.brw_reqst;
307 req->brw_flags = flags;
316 brw_client_done_rpc(struct sfw_test_unit *tsu, struct srpc_client_rpc *rpc)
318 __u64 magic = BRW_MAGIC;
319 struct sfw_test_instance *tsi = tsu->tsu_instance;
320 struct sfw_session *sn = tsi->tsi_batch->bat_session;
321 struct srpc_msg *msg = &rpc->crpc_replymsg;
322 struct srpc_brw_reply *reply = &msg->msg_body.brw_reply;
323 struct srpc_brw_reqst *reqst = &rpc->crpc_reqstmsg.msg_body.brw_reqst;
327 if (rpc->crpc_status) {
328 CERROR("BRW RPC to %s failed with %d\n",
329 libcfs_id2str(rpc->crpc_dest), rpc->crpc_status);
330 if (!tsi->tsi_stopping) /* rpc could have been aborted */
331 atomic_inc(&sn->sn_brw_errors);
335 if (msg->msg_magic != SRPC_MSG_MAGIC) {
337 __swab32s(&reply->brw_status);
340 CDEBUG(reply->brw_status ? D_WARNING : D_NET,
341 "BRW RPC to %s finished with brw_status: %d\n",
342 libcfs_id2str(rpc->crpc_dest), reply->brw_status);
344 if (reply->brw_status) {
345 atomic_inc(&sn->sn_brw_errors);
346 rpc->crpc_status = -(int)reply->brw_status;
350 if (reqst->brw_rw == LST_BRW_WRITE)
353 if (brw_check_bulk(&rpc->crpc_bulk, reqst->brw_flags, magic)) {
354 CERROR("Bulk data from %s is corrupted!\n",
355 libcfs_id2str(rpc->crpc_dest));
356 atomic_inc(&sn->sn_brw_errors);
357 rpc->crpc_status = -EBADMSG;
362 brw_server_rpc_done(struct srpc_server_rpc *rpc)
364 struct srpc_bulk *blk = rpc->srpc_bulk;
369 if (rpc->srpc_status)
370 CERROR("Bulk transfer %s %s has failed: %d\n",
371 blk->bk_sink ? "from" : "to",
372 libcfs_id2str(rpc->srpc_peer), rpc->srpc_status);
374 CDEBUG(D_NET, "Transferred %d pages bulk data %s %s\n",
375 blk->bk_niov, blk->bk_sink ? "from" : "to",
376 libcfs_id2str(rpc->srpc_peer));
382 brw_bulk_ready(struct srpc_server_rpc *rpc, int status)
384 __u64 magic = BRW_MAGIC;
385 struct srpc_brw_reply *reply = &rpc->srpc_replymsg.msg_body.brw_reply;
386 struct srpc_brw_reqst *reqst;
387 struct srpc_msg *reqstmsg;
389 LASSERT(rpc->srpc_bulk);
390 LASSERT(rpc->srpc_reqstbuf);
392 reqstmsg = &rpc->srpc_reqstbuf->buf_msg;
393 reqst = &reqstmsg->msg_body.brw_reqst;
396 CERROR("BRW bulk %s failed for RPC from %s: %d\n",
397 reqst->brw_rw == LST_BRW_READ ? "READ" : "WRITE",
398 libcfs_id2str(rpc->srpc_peer), status);
402 if (reqst->brw_rw == LST_BRW_READ)
405 if (reqstmsg->msg_magic != SRPC_MSG_MAGIC)
408 if (brw_check_bulk(rpc->srpc_bulk, reqst->brw_flags, magic)) {
409 CERROR("Bulk data from %s is corrupted!\n",
410 libcfs_id2str(rpc->srpc_peer));
411 reply->brw_status = EBADMSG;
418 brw_server_handle(struct srpc_server_rpc *rpc)
420 struct srpc_service *sv = rpc->srpc_scd->scd_svc;
421 struct srpc_msg *replymsg = &rpc->srpc_replymsg;
422 struct srpc_msg *reqstmsg = &rpc->srpc_reqstbuf->buf_msg;
423 struct srpc_brw_reply *reply = &replymsg->msg_body.brw_reply;
424 struct srpc_brw_reqst *reqst = &reqstmsg->msg_body.brw_reqst;
428 LASSERT(sv->sv_id == SRPC_SERVICE_BRW);
430 if (reqstmsg->msg_magic != SRPC_MSG_MAGIC) {
431 LASSERT(reqstmsg->msg_magic == __swab32(SRPC_MSG_MAGIC));
433 __swab32s(&reqst->brw_rw);
434 __swab32s(&reqst->brw_len);
435 __swab32s(&reqst->brw_flags);
436 __swab64s(&reqst->brw_rpyid);
437 __swab64s(&reqst->brw_bulkid);
439 LASSERT(reqstmsg->msg_type == (__u32)srpc_service2request(sv->sv_id));
441 reply->brw_status = 0;
442 rpc->srpc_done = brw_server_rpc_done;
444 if ((reqst->brw_rw != LST_BRW_READ && reqst->brw_rw != LST_BRW_WRITE) ||
445 (reqst->brw_flags != LST_BRW_CHECK_NONE &&
446 reqst->brw_flags != LST_BRW_CHECK_FULL &&
447 reqst->brw_flags != LST_BRW_CHECK_SIMPLE)) {
448 reply->brw_status = EINVAL;
452 if (reqstmsg->msg_ses_feats & ~LST_FEATS_MASK) {
453 replymsg->msg_ses_feats = LST_FEATS_MASK;
454 reply->brw_status = EPROTO;
458 if (!(reqstmsg->msg_ses_feats & LST_FEAT_BULK_LEN)) {
459 /* compat with old version */
460 if (reqst->brw_len & ~PAGE_MASK) {
461 reply->brw_status = EINVAL;
464 npg = reqst->brw_len >> PAGE_SHIFT;
467 npg = (reqst->brw_len + PAGE_SIZE - 1) >> PAGE_SHIFT;
470 replymsg->msg_ses_feats = reqstmsg->msg_ses_feats;
472 if (!reqst->brw_len || npg > LNET_MAX_IOV) {
473 reply->brw_status = EINVAL;
477 rc = sfw_alloc_pages(rpc, rpc->srpc_scd->scd_cpt, npg,
479 reqst->brw_rw == LST_BRW_WRITE);
483 if (reqst->brw_rw == LST_BRW_READ)
484 brw_fill_bulk(rpc->srpc_bulk, reqst->brw_flags, BRW_MAGIC);
486 brw_fill_bulk(rpc->srpc_bulk, reqst->brw_flags, BRW_POISON);
491 struct sfw_test_client_ops brw_test_client;
493 void brw_init_test_client(void)
495 brw_test_client.tso_init = brw_client_init;
496 brw_test_client.tso_fini = brw_client_fini;
497 brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
498 brw_test_client.tso_done_rpc = brw_client_done_rpc;
501 struct srpc_service brw_test_service;
503 void brw_init_test_service(void)
505 brw_test_service.sv_id = SRPC_SERVICE_BRW;
506 brw_test_service.sv_name = "brw_test";
507 brw_test_service.sv_handler = brw_server_handle;
508 brw_test_service.sv_bulk_ready = brw_bulk_ready;
509 brw_test_service.sv_wi_total = brw_srv_workitems;