Whamcloud - gitweb
LU-1031: add grouplock test to sanity.sh
[fs/lustre-release.git] / lnet / selftest / brw_test.c
index ee2d024..59c6e60 100644 (file)
@@ -1,18 +1,45 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
+/*
+ * GPL HEADER START
  *
- * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
- *   Author: Isaac Huang <isaac@clusterfs.com>
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lnet/selftest/brw_test.c
+ *
+ * Author: Isaac Huang <isaac@clusterfs.com>
  */
 
-#include <libcfs/kp30.h>
 #include "selftest.h"
 
 
-static int brw_inject_errors = 0;
-CFS_MODULE_PARM(brw_inject_errors, "i", int, 0644,
-                "# data errors to inject randomly");
+extern int brw_inject_errors;
 
 static void
 brw_client_fini (sfw_test_instance_t *tsi)
@@ -20,7 +47,10 @@ brw_client_fini (sfw_test_instance_t *tsi)
         srpc_bulk_t     *bulk;
         sfw_test_unit_t *tsu;
 
-        list_for_each_entry (tsu, &tsi->tsi_units, tsu_list) {
+        LASSERT (tsi->tsi_is_client);
+
+        cfs_list_for_each_entry_typed (tsu, &tsi->tsi_units,
+                                       sfw_test_unit_t, tsu_list) {
                 bulk = tsu->tsu_private;
                 if (bulk == NULL) continue;
 
@@ -38,6 +68,8 @@ brw_client_init (sfw_test_instance_t *tsi)
         srpc_bulk_t      *bulk;
         sfw_test_unit_t  *tsu;
 
+        LASSERT (tsi->tsi_is_client);
+
         if (npg > LNET_MAX_IOV || npg <= 0)
                 return -EINVAL;
 
@@ -48,7 +80,8 @@ brw_client_init (sfw_test_instance_t *tsi)
             flags != LST_BRW_CHECK_FULL && flags != LST_BRW_CHECK_SIMPLE)
                 return -EINVAL;
 
-        list_for_each_entry (tsu, &tsi->tsi_units, tsu_list) {
+        cfs_list_for_each_entry_typed (tsu, &tsi->tsi_units,
+                                       sfw_test_unit_t, tsu_list) {
                 bulk = srpc_alloc_bulk(npg, breq->blk_opc == LST_BRW_READ);
                 if (bulk == NULL) {
                         brw_client_fini(tsi);
@@ -75,7 +108,7 @@ brw_inject_one_error (void)
 #ifndef __KERNEL__
         gettimeofday(&tv, NULL);
 #else
-        do_gettimeofday(&tv);
+        cfs_gettimeofday(&tv);
 #endif
 
         if ((tv.tv_usec & 1) == 0) return 0;
@@ -91,8 +124,7 @@ brw_fill_page (cfs_page_t *pg, int pattern, __u64 magic)
 
         LASSERT (addr != NULL);
 
-        if (pattern == LST_BRW_CHECK_NONE)
-                return;
+        if (pattern == LST_BRW_CHECK_NONE) return;
 
         if (magic == BRW_MAGIC)
                 magic += brw_inject_one_error();
@@ -118,7 +150,7 @@ int
 brw_check_page (cfs_page_t *pg, int pattern, __u64 magic)
 {
         char  *addr = cfs_page_address(pg);
-        __u64  data;
+        __u64  data = 0; /* make compiler happy */
         int    i;
 
         LASSERT (addr != NULL);
@@ -149,7 +181,7 @@ brw_check_page (cfs_page_t *pg, int pattern, __u64 magic)
         LBUG ();
 
 bad_data:
-        CERROR ("Bad data in page %p: "LPU64", "LPU64" expected\n",
+        CERROR ("Bad data in page %p: "LPX64", "LPX64" expected\n",
                 pg, data, magic);
         return 1;
 }
@@ -164,6 +196,7 @@ brw_fill_bulk (srpc_bulk_t *bk, int pattern, __u64 magic)
 #ifdef __KERNEL__
                 pg = bk->bk_iovs[i].kiov_page;
 #else
+                LASSERT (bk->bk_pages != NULL);
                 pg = bk->bk_pages[i];
 #endif
                 brw_fill_page(pg, pattern, magic);
@@ -180,6 +213,7 @@ brw_check_bulk (srpc_bulk_t *bk, int pattern, __u64 magic)
 #ifdef __KERNEL__
                 pg = bk->bk_iovs[i].kiov_page;
 #else
+                LASSERT (bk->bk_pages != NULL);
                 pg = bk->bk_pages[i];
 #endif
                 if (brw_check_page(pg, pattern, magic) != 0) {
@@ -219,7 +253,7 @@ brw_client_prep_rpc (sfw_test_unit_t *tsu,
 
         req = &rpc->crpc_reqstmsg.msg_body.brw_reqst;
         req->brw_flags = flags;
-        req->brw_rw    = breq->blk_opc; 
+        req->brw_rw    = breq->blk_opc;
         req->brw_len   = npg * CFS_PAGE_SIZE;
 
         *rpcpp = rpc;
@@ -229,22 +263,21 @@ brw_client_prep_rpc (sfw_test_unit_t *tsu,
 static void
 brw_client_done_rpc (sfw_test_unit_t *tsu, srpc_client_rpc_t *rpc)
 {
-        __u64             magic = BRW_MAGIC;
-        srpc_msg_t       *msg = &rpc->crpc_replymsg;
-        srpc_brw_reply_t *reply = &msg->msg_body.brw_reply;
-        srpc_brw_reqst_t *reqst = &rpc->crpc_reqstmsg.msg_body.brw_reqst;
-        sfw_session_t    *sn = tsu->tsu_instance->tsi_batch->bat_session;
+        __u64                magic = BRW_MAGIC;
+        sfw_test_instance_t *tsi = tsu->tsu_instance;
+        sfw_session_t       *sn = tsi->tsi_batch->bat_session;
+        srpc_msg_t          *msg = &rpc->crpc_replymsg;
+        srpc_brw_reply_t    *reply = &msg->msg_body.brw_reply;
+        srpc_brw_reqst_t    *reqst = &rpc->crpc_reqstmsg.msg_body.brw_reqst;
 
         LASSERT (sn != NULL);
 
-#ifndef __KERNEL__
-        rpc->crpc_bulk.bk_pages = NULL;
-#endif
-
         if (rpc->crpc_status != 0) {
                 CERROR ("BRW RPC to %s failed with %d\n",
                         libcfs_id2str(rpc->crpc_dest), rpc->crpc_status);
-                return;
+                if (!tsi->tsi_stopping) /* rpc could have been aborted */
+                        cfs_atomic_inc(&sn->sn_brw_errors);
+                goto out;
         }
 
         if (msg->msg_magic != SRPC_MSG_MAGIC) {
@@ -252,27 +285,29 @@ brw_client_done_rpc (sfw_test_unit_t *tsu, srpc_client_rpc_t *rpc)
                 __swab32s(&reply->brw_status);
         }
 
-        if (tsu->tsu_error == 0)
-                tsu->tsu_error = -reply->brw_status;
-
         CDEBUG (reply->brw_status ? D_WARNING : D_NET,
                 "BRW RPC to %s finished with brw_status: %d\n",
                 libcfs_id2str(rpc->crpc_dest), reply->brw_status);
 
         if (reply->brw_status != 0) {
-                atomic_inc(&sn->sn_brw_errors);
-                return;
+                cfs_atomic_inc(&sn->sn_brw_errors);
+                rpc->crpc_status = -(int)reply->brw_status;
+                goto out;
         }
 
-        if (reqst->brw_rw == LST_BRW_WRITE) return;
+        if (reqst->brw_rw == LST_BRW_WRITE) goto out;
 
         if (brw_check_bulk(&rpc->crpc_bulk, reqst->brw_flags, magic) != 0) {
                 CERROR ("Bulk data from %s is corrupted!\n",
                         libcfs_id2str(rpc->crpc_dest));
-                tsu->tsu_error = -EBADMSG;
-                atomic_inc(&sn->sn_brw_errors);
+                cfs_atomic_inc(&sn->sn_brw_errors);
+                rpc->crpc_status = -EBADMSG;
         }
 
+out:
+#ifndef __KERNEL__
+        rpc->crpc_bulk.bk_pages = NULL;
+#endif
         return;
 }
 
@@ -353,7 +388,7 @@ brw_server_handle (srpc_server_rpc_t *rpc)
                 __swab64s(&reqst->brw_rpyid);
                 __swab64s(&reqst->brw_bulkid);
         }
-        LASSERT (reqstmsg->msg_type == srpc_service2request(sv->sv_id));
+        LASSERT (reqstmsg->msg_type == (__u32)srpc_service2request(sv->sv_id));
 
         rpc->srpc_done = brw_server_rpc_done;
 
@@ -366,7 +401,7 @@ brw_server_handle (srpc_server_rpc_t *rpc)
                 reply->brw_status = EINVAL;
                 return 0;
         }
-        
+
         reply->brw_status = 0;
         rc = sfw_alloc_pages(rpc, reqst->brw_len / CFS_PAGE_SIZE,
                              reqst->brw_rw == LST_BRW_WRITE);
@@ -380,18 +415,20 @@ brw_server_handle (srpc_server_rpc_t *rpc)
         return 0;
 }
 
-sfw_test_client_ops_t brw_test_client =
+sfw_test_client_ops_t brw_test_client;
+void brw_init_test_client(void)
 {
-        .tso_init      = brw_client_init,
-        .tso_fini      = brw_client_fini,
-        .tso_prep_rpc  = brw_client_prep_rpc,
-        .tso_done_rpc  = brw_client_done_rpc,
+        brw_test_client.tso_init       = brw_client_init;
+        brw_test_client.tso_fini       = brw_client_fini;
+        brw_test_client.tso_prep_rpc   = brw_client_prep_rpc;
+        brw_test_client.tso_done_rpc   = brw_client_done_rpc;
 };
 
-srpc_service_t brw_test_service =
+srpc_service_t brw_test_service;
+void brw_init_test_service(void)
 {
-        .sv_name       = "brw test",
-        .sv_handler    = brw_server_handle,
-        .sv_bulk_ready = brw_bulk_ready,
-        .sv_id         = SRPC_SERVICE_BRW,
-};
+        brw_test_service.sv_id         = SRPC_SERVICE_BRW;
+        brw_test_service.sv_name       = "brw_test";
+        brw_test_service.sv_handler    = brw_server_handle;
+        brw_test_service.sv_bulk_ready = brw_bulk_ready;
+}