Whamcloud - gitweb
LU-1031: add grouplock test to sanity.sh
[fs/lustre-release.git] / lnet / selftest / brw_test.c
index 8b0dd01..59c6e60 100644 (file)
@@ -1,9 +1,39 @@
-/* -*- 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 "selftest.h"
@@ -19,7 +49,8 @@ brw_client_fini (sfw_test_instance_t *tsi)
 
         LASSERT (tsi->tsi_is_client);
 
-        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 = tsu->tsu_private;
                 if (bulk == NULL) continue;
 
@@ -49,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);
@@ -76,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;
@@ -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;
 }
@@ -221,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;
@@ -244,7 +276,7 @@ brw_client_done_rpc (sfw_test_unit_t *tsu, srpc_client_rpc_t *rpc)
                 CERROR ("BRW RPC to %s failed with %d\n",
                         libcfs_id2str(rpc->crpc_dest), rpc->crpc_status);
                 if (!tsi->tsi_stopping) /* rpc could have been aborted */
-                        atomic_inc(&sn->sn_brw_errors);
+                        cfs_atomic_inc(&sn->sn_brw_errors);
                 goto out;
         }
 
@@ -258,8 +290,8 @@ brw_client_done_rpc (sfw_test_unit_t *tsu, srpc_client_rpc_t *rpc)
                 libcfs_id2str(rpc->crpc_dest), reply->brw_status);
 
         if (reply->brw_status != 0) {
-                atomic_inc(&sn->sn_brw_errors);
-                rpc->crpc_status = -reply->brw_status;
+                cfs_atomic_inc(&sn->sn_brw_errors);
+                rpc->crpc_status = -(int)reply->brw_status;
                 goto out;
         }
 
@@ -268,7 +300,7 @@ brw_client_done_rpc (sfw_test_unit_t *tsu, srpc_client_rpc_t *rpc)
         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));
-                atomic_inc(&sn->sn_brw_errors);
+                cfs_atomic_inc(&sn->sn_brw_errors);
                 rpc->crpc_status = -EBADMSG;
         }
 
@@ -356,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;
 
@@ -369,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);
@@ -383,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;
+}