Whamcloud - gitweb
LU-6245 lnet: remove kernel defines in userland headers
[fs/lustre-release.git] / lnet / selftest / selftest.h
index 7a36231..da2f63a 100644 (file)
@@ -27,6 +27,8 @@
 /*
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 
 #define LNET_ONLY
 
-#ifndef __KERNEL__
-
-/* XXX workaround XXX */
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#endif
 #include <libcfs/libcfs.h>
-#include <lnet/lnet.h>
+#include <lnet/api.h>
 #include <lnet/lib-lnet.h>
 #include <lnet/lib-types.h>
 #include <lnet/lnetst.h>
@@ -165,21 +159,16 @@ typedef struct {
         lnet_handle_md_t bk_mdh;
         int              bk_sink; /* sink/source */
         int              bk_niov; /* # iov in bk_iovs */
-#ifdef __KERNEL__
         lnet_kiov_t      bk_iovs[0];
-#else
-        cfs_page_t     **bk_pages;
-        lnet_md_iovec_t  bk_iovs[0];
-#endif
 } srpc_bulk_t; /* bulk descriptor */
 
 /* message buffer descriptor */
 typedef struct srpc_buffer {
-        cfs_list_t           buf_list; /* chain on srpc_service::*_msgq */
-        srpc_msg_t           buf_msg;
-        lnet_handle_md_t     buf_mdh;
-        lnet_nid_t           buf_self;
-        lnet_process_id_t    buf_peer;
+       struct list_head        buf_list; /* chain on srpc_service::*_msgq */
+       srpc_msg_t              buf_msg;
+       lnet_handle_md_t        buf_mdh;
+       lnet_nid_t              buf_self;
+       lnet_process_id_t       buf_peer;
 } srpc_buffer_t;
 
 struct swi_workitem;
@@ -195,32 +184,33 @@ typedef struct swi_workitem {
 /* server-side state of a RPC */
 typedef struct srpc_server_rpc {
        /* chain on srpc_service::*_rpcq */
-       cfs_list_t              srpc_list;
+       struct list_head        srpc_list;
        struct srpc_service_cd *srpc_scd;
-        swi_workitem_t       srpc_wi;
-        srpc_event_t         srpc_ev;      /* bulk/reply event */
-        lnet_nid_t           srpc_self;
-        lnet_process_id_t    srpc_peer;
-        srpc_msg_t           srpc_replymsg;
-        lnet_handle_md_t     srpc_replymdh;
-        srpc_buffer_t       *srpc_reqstbuf;
-        srpc_bulk_t         *srpc_bulk;
-
-        unsigned int         srpc_aborted; /* being given up */
-        int                  srpc_status;
-        void               (*srpc_done)(struct srpc_server_rpc *);
+       swi_workitem_t          srpc_wi;
+       srpc_event_t            srpc_ev;        /* bulk/reply event */
+       lnet_nid_t              srpc_self;
+       lnet_process_id_t       srpc_peer;
+       srpc_msg_t              srpc_replymsg;
+       lnet_handle_md_t        srpc_replymdh;
+       srpc_buffer_t           *srpc_reqstbuf;
+       srpc_bulk_t             *srpc_bulk;
+
+       unsigned int    srpc_aborted; /* being given up */
+       int             srpc_status;
+       void            (*srpc_done)(struct srpc_server_rpc *);
 } srpc_server_rpc_t;
 
 /* client-side state of a RPC */
 typedef struct srpc_client_rpc {
-       cfs_list_t              crpc_list;      /* chain on user's lists */
+       struct list_head        crpc_list;      /* chain on user's lists */
        spinlock_t              crpc_lock;      /* serialize */
-        int                  crpc_service;
-        cfs_atomic_t         crpc_refcount;
-        int                  crpc_timeout; /* # seconds to wait for reply */
-        stt_timer_t          crpc_timer;
-        swi_workitem_t       crpc_wi;
-        lnet_process_id_t    crpc_dest;
+       int                     crpc_service;
+       atomic_t                crpc_refcount;
+       /* # seconds to wait for reply */
+       int                     crpc_timeout;
+       stt_timer_t             crpc_timer;
+       swi_workitem_t          crpc_wi;
+       lnet_process_id_t       crpc_dest;
 
         void               (*crpc_done)(struct srpc_client_rpc *);
         void               (*crpc_fini)(struct srpc_client_rpc *);
@@ -251,18 +241,18 @@ offsetof(srpc_client_rpc_t, crpc_bulk.bk_iovs[(rpc)->crpc_bulk.bk_niov])
 do {                                                                    \
         CDEBUG(D_NET, "RPC[%p] -> %s (%d)++\n",                         \
                (rpc), libcfs_id2str((rpc)->crpc_dest),                  \
-               cfs_atomic_read(&(rpc)->crpc_refcount));                 \
-        LASSERT(cfs_atomic_read(&(rpc)->crpc_refcount) > 0);            \
-        cfs_atomic_inc(&(rpc)->crpc_refcount);                          \
+              atomic_read(&(rpc)->crpc_refcount));                 \
+       LASSERT(atomic_read(&(rpc)->crpc_refcount) > 0);            \
+       atomic_inc(&(rpc)->crpc_refcount);                          \
 } while (0)
 
 #define srpc_client_rpc_decref(rpc)                                     \
 do {                                                                    \
         CDEBUG(D_NET, "RPC[%p] -> %s (%d)--\n",                         \
                (rpc), libcfs_id2str((rpc)->crpc_dest),                  \
-               cfs_atomic_read(&(rpc)->crpc_refcount));                 \
-        LASSERT(cfs_atomic_read(&(rpc)->crpc_refcount) > 0);            \
-        if (cfs_atomic_dec_and_test(&(rpc)->crpc_refcount))             \
+              atomic_read(&(rpc)->crpc_refcount));                 \
+       LASSERT(atomic_read(&(rpc)->crpc_refcount) > 0);            \
+       if (atomic_dec_and_test(&(rpc)->crpc_refcount))             \
                 srpc_destroy_client_rpc(rpc);                           \
 } while (0)
 
@@ -279,9 +269,9 @@ struct srpc_service_cd {
        /** event buffer */
        srpc_event_t            scd_ev;
        /** free RPC descriptors */
-       cfs_list_t              scd_rpc_free;
+       struct list_head        scd_rpc_free;
        /** in-flight RPCs */
-       cfs_list_t              scd_rpc_active;
+       struct list_head        scd_rpc_active;
        /** workitem for posting buffer */
        swi_workitem_t          scd_buf_wi;
        /** CPT id */
@@ -301,9 +291,9 @@ struct srpc_service_cd {
        /** increase/decrease some buffers */
        int                     scd_buf_adjust;
        /** posted message buffers */
-       cfs_list_t              scd_buf_posted;
+       struct list_head        scd_buf_posted;
        /** blocked for RPC descriptor */
-       cfs_list_t              scd_buf_blocked;
+       struct list_head        scd_buf_blocked;
 };
 
 /* number of server workitems (mini-thread) for testing service */
@@ -334,30 +324,32 @@ typedef struct srpc_service {
 } srpc_service_t;
 
 typedef struct {
-        cfs_list_t        sn_list;    /* chain on fw_zombie_sessions */
-        lst_sid_t         sn_id;      /* unique identifier */
-        unsigned int      sn_timeout; /* # seconds' inactivity to expire */
-        int               sn_timer_active;
-       unsigned int      sn_features;
-        stt_timer_t       sn_timer;
-        cfs_list_t        sn_batches; /* list of batches */
-        char              sn_name[LST_NAME_SIZE];
-        cfs_atomic_t      sn_refcount;
-        cfs_atomic_t      sn_brw_errors;
-        cfs_atomic_t      sn_ping_errors;
-        cfs_time_t        sn_started;
+       /* chain on fw_zombie_sessions */
+       struct list_head        sn_list;
+       lst_sid_t               sn_id;          /* unique identifier */
+       /* # seconds' inactivity to expire */
+       unsigned int            sn_timeout;
+       int                     sn_timer_active;
+       unsigned int            sn_features;
+       stt_timer_t             sn_timer;
+       struct list_head        sn_batches;     /* list of batches */
+       char                    sn_name[LST_NAME_SIZE];
+       atomic_t                sn_refcount;
+       atomic_t                sn_brw_errors;
+       atomic_t                sn_ping_errors;
+       cfs_time_t              sn_started;
 } sfw_session_t;
 
 #define sfw_sid_equal(sid0, sid1)     ((sid0).ses_nid == (sid1).ses_nid && \
                                        (sid0).ses_stamp == (sid1).ses_stamp)
 
 typedef struct {
-        cfs_list_t        bat_list;      /* chain on sn_batches */
-        lst_bid_t         bat_id;        /* batch id */
-        int               bat_error;     /* error code of batch */
-        sfw_session_t    *bat_session;   /* batch's session */
-        cfs_atomic_t      bat_nactive;   /* # of active tests */
-        cfs_list_t        bat_tests;     /* test instances */
+       struct list_head        bat_list;       /* chain on sn_batches */
+       lst_bid_t               bat_id;         /* batch id */
+       int                     bat_error;      /* error code of batch */
+       sfw_session_t           *bat_session;   /* batch's session */
+       atomic_t                bat_nactive;    /* # of active tests */
+       struct list_head        bat_tests;      /* test instances */
 } sfw_batch_t;
 
 typedef struct {
@@ -371,24 +363,24 @@ typedef struct {
 } sfw_test_client_ops_t;
 
 typedef struct sfw_test_instance {
-        cfs_list_t              tsi_list;         /* chain on batch */
-        int                     tsi_service;      /* test type */
-        sfw_batch_t            *tsi_batch;        /* batch */
-        sfw_test_client_ops_t  *tsi_ops;          /* test client operations */
-
-        /* public parameter for all test units */
-        int                     tsi_is_client:1;     /* is test client */
-        int                     tsi_stoptsu_onerr:1; /* stop tsu on error */
+       struct list_head        tsi_list;       /* chain on batch */
+       int                     tsi_service;    /* test type */
+       sfw_batch_t             *tsi_batch;     /* batch */
+       sfw_test_client_ops_t   *tsi_ops;       /* test client operations */
+
+       /* public parameter for all test units */
+       unsigned int            tsi_is_client:1;     /* is test client */
+       unsigned int            tsi_stoptsu_onerr:1; /* stop tsu on error */
         int                     tsi_concur;          /* concurrency */
         int                     tsi_loop;            /* loop count */
 
        /* status of test instance */
-       spinlock_t              tsi_lock;         /* serialize */
-        int                     tsi_stopping:1;   /* test is stopping */
-        cfs_atomic_t            tsi_nactive;      /* # of active test unit */
-        cfs_list_t              tsi_units;        /* test units */
-        cfs_list_t              tsi_free_rpcs;    /* free rpcs */
-        cfs_list_t              tsi_active_rpcs;  /* active rpcs */
+       spinlock_t              tsi_lock;       /* serialize */
+       unsigned int            tsi_stopping:1; /* test is stopping */
+       atomic_t                tsi_nactive;    /* # of active test unit */
+       struct list_head        tsi_units;      /* test units */
+       struct list_head        tsi_free_rpcs;  /* free rpcs */
+       struct list_head        tsi_active_rpcs;/* active rpcs */
 
        union {
                test_ping_req_t         ping;     /* ping parameter */
@@ -397,26 +389,26 @@ typedef struct sfw_test_instance {
        } tsi_u;
 } sfw_test_instance_t;
 
-/* XXX: trailing (CFS_PAGE_SIZE % sizeof(lnet_process_id_t)) bytes at
+/* XXX: trailing (PAGE_CACHE_SIZE % sizeof(lnet_process_id_t)) bytes at
  * the end of pages are not used */
 #define SFW_MAX_CONCUR     LST_MAX_CONCUR
-#define SFW_ID_PER_PAGE    (CFS_PAGE_SIZE / sizeof(lnet_process_id_packed_t))
+#define SFW_ID_PER_PAGE    (PAGE_CACHE_SIZE / sizeof(lnet_process_id_packed_t))
 #define SFW_MAX_NDESTS     (LNET_MAX_IOV * SFW_ID_PER_PAGE)
 #define sfw_id_pages(n)    (((n) + SFW_ID_PER_PAGE - 1) / SFW_ID_PER_PAGE)
 
 typedef struct sfw_test_unit {
-        cfs_list_t            tsu_list;         /* chain on lst_test_instance */
-        lnet_process_id_t     tsu_dest;         /* id of dest node */
-        int                   tsu_loop;         /* loop count of the test */
-        sfw_test_instance_t  *tsu_instance;     /* pointer to test instance */
-        void                 *tsu_private;      /* private data */
-        swi_workitem_t        tsu_worker;       /* workitem of the test unit */
+       struct list_head        tsu_list;       /* chain on lst_test_instance */
+       lnet_process_id_t       tsu_dest;       /* id of dest node */
+       int                     tsu_loop;       /* loop count of the test */
+       sfw_test_instance_t     *tsu_instance;  /* pointer to test instance */
+       void                    *tsu_private;   /* private data */
+       swi_workitem_t          tsu_worker;     /* workitem of the test unit */
 } sfw_test_unit_t;
 
 typedef struct sfw_test_case {
-        cfs_list_t              tsc_list;         /* chain on fw_tests */
-        srpc_service_t         *tsc_srv_service;  /* test service */
-        sfw_test_client_ops_t  *tsc_cli_ops;      /* ops of test client */
+       struct list_head        tsc_list;               /* chain on fw_tests */
+       srpc_service_t          *tsc_srv_service;       /* test service */
+       sfw_test_client_ops_t   *tsc_cli_ops;           /* ops of test client */
 } sfw_test_case_t;
 
 srpc_client_rpc_t *
@@ -431,7 +423,7 @@ void sfw_post_rpc(srpc_client_rpc_t *rpc);
 void sfw_client_rpc_done(srpc_client_rpc_t *rpc);
 void sfw_unpack_message(srpc_msg_t *msg);
 void sfw_free_pages(srpc_server_rpc_t *rpc);
-void sfw_add_bulk_page(srpc_bulk_t *bk, cfs_page_t *pg, int i);
+void sfw_add_bulk_page(srpc_bulk_t *bk, struct page *pg, int i);
 int sfw_alloc_pages(srpc_server_rpc_t *rpc, int cpt, int npages, int len,
                    int sink);
 int sfw_make_session (srpc_mksn_reqst_t *request, srpc_mksn_reply_t *reply);
@@ -503,14 +495,6 @@ swi_deschedule_workitem(swi_workitem_t *swi)
        return cfs_wi_deschedule(swi->swi_sched, &swi->swi_workitem);
 }
 
-#ifndef __KERNEL__
-static inline int
-swi_check_events(void)
-{
-        return cfs_wi_check_events();
-}
-#endif
-
 int sfw_startup(void);
 int srpc_startup(void);
 void sfw_shutdown(void);
@@ -519,41 +503,38 @@ void srpc_shutdown(void);
 static inline void
 srpc_destroy_client_rpc (srpc_client_rpc_t *rpc)
 {
-        LASSERT (rpc != NULL);
-        LASSERT (!srpc_event_pending(rpc));
-        LASSERT (cfs_atomic_read(&rpc->crpc_refcount) == 0);
-#ifndef __KERNEL__
-        LASSERT (rpc->crpc_bulk.bk_pages == NULL);
-#endif
+       LASSERT (rpc != NULL);
+       LASSERT (!srpc_event_pending(rpc));
+       LASSERT (atomic_read(&rpc->crpc_refcount) == 0);
 
-        if (rpc->crpc_fini == NULL) {
-                LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc));
-        } else {
-                (*rpc->crpc_fini) (rpc);
-        }
+       if (rpc->crpc_fini == NULL) {
+               LIBCFS_FREE(rpc, srpc_client_rpc_size(rpc));
+       } else {
+               (*rpc->crpc_fini) (rpc);
+       }
 
-        return;
+       return;
 }
 
 static inline void
-srpc_init_client_rpc (srpc_client_rpc_t *rpc, lnet_process_id_t peer,
-                      int service, int nbulkiov, int bulklen,
-                      void (*rpc_done)(srpc_client_rpc_t *),
-                      void (*rpc_fini)(srpc_client_rpc_t *), void *priv)
+srpc_init_client_rpc(srpc_client_rpc_t *rpc, lnet_process_id_t peer,
+                    int service, int nbulkiov, int bulklen,
+                    void (*rpc_done)(srpc_client_rpc_t *),
+                    void (*rpc_fini)(srpc_client_rpc_t *), void *priv)
 {
-        LASSERT (nbulkiov <= LNET_MAX_IOV);
+       LASSERT(nbulkiov <= LNET_MAX_IOV);
 
-        memset(rpc, 0, offsetof(srpc_client_rpc_t,
-                                crpc_bulk.bk_iovs[nbulkiov]));
+       memset(rpc, 0, offsetof(srpc_client_rpc_t,
+                               crpc_bulk.bk_iovs[nbulkiov]));
 
-        CFS_INIT_LIST_HEAD(&rpc->crpc_list);
+       INIT_LIST_HEAD(&rpc->crpc_list);
        swi_init_workitem(&rpc->crpc_wi, rpc, srpc_send_rpc,
                          lst_sched_test[lnet_cpt_of_nid(peer.nid)]);
        spin_lock_init(&rpc->crpc_lock);
-        cfs_atomic_set(&rpc->crpc_refcount, 1); /* 1 ref for caller */
+       atomic_set(&rpc->crpc_refcount, 1); /* 1 ref for caller */
 
-        rpc->crpc_dest         = peer;
-        rpc->crpc_priv         = priv;
+       rpc->crpc_dest         = peer;
+       rpc->crpc_priv         = priv;
         rpc->crpc_service      = service;
         rpc->crpc_bulk.bk_len  = bulklen;
         rpc->crpc_bulk.bk_niov = nbulkiov;
@@ -593,26 +574,8 @@ swi_state2str (int state)
 #undef STATE2STR
 }
 
-#define UNUSED(x)       ( (void)(x) )
-
-#ifndef __KERNEL__
-
-int stt_poll_interval(void);
-int sfw_session_removed(void);
-
-int stt_check_events(void);
-int srpc_check_event(int timeout);
-
-int lnet_selftest_init(void);
-void lnet_selftest_fini(void);
-int selftest_wait_events(void);
-
-#else
-
 #define selftest_wait_events() cfs_pause(cfs_time_seconds(1) / 10)
 
-#endif
-
 #define lst_wait_until(cond, lock, fmt, ...)                           \
 do {                                                                   \
        int __I = 2;                                                    \
@@ -643,4 +606,14 @@ srpc_wait_service_shutdown(srpc_service_t *sv)
         }
 }
 
+extern sfw_test_client_ops_t ping_test_client;
+extern srpc_service_t        ping_test_service;
+void ping_init_test_client(void);
+void ping_init_test_service(void);
+
+extern sfw_test_client_ops_t brw_test_client;
+extern srpc_service_t        brw_test_service;
+void brw_init_test_client(void);
+void brw_init_test_service(void);
+
 #endif /* __SELFTEST_SELFTEST_H__ */