LCOV - code coverage report
Current view: top level - spdk/test/unit/lib/bdev/raid/raid0.c - raid0_ut.c (source / functions) Hit Total Coverage
Test: Combined Lines: 413 426 96.9 %
Date: 2024-07-15 14:20:07 Functions: 36 42 85.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 147 236 62.3 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2024 Intel Corporation.
       3                 :            :  *   All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "spdk/stdinc.h"
       7                 :            : #include "spdk_internal/cunit.h"
       8                 :            : #include "spdk/env.h"
       9                 :            : 
      10                 :            : #include "common/lib/ut_multithread.c"
      11                 :            : 
      12                 :            : #include "bdev/raid/raid0.c"
      13                 :            : #include "../common.c"
      14                 :            : 
      15                 :            : #define MAX_BASE_DRIVES 32
      16                 :            : #define MAX_TEST_IO_RANGE (3 * 3 * 3 * (MAX_BASE_DRIVES + 5))
      17                 :            : #define BLOCK_CNT (1024ul * 1024ul * 1024ul * 1024ul)
      18                 :            : 
      19                 :            : /* Data structure to capture the output of IO for verification */
      20                 :            : struct io_output {
      21                 :            :         struct spdk_bdev_desc       *desc;
      22                 :            :         struct spdk_io_channel      *ch;
      23                 :            :         uint64_t                    offset_blocks;
      24                 :            :         uint64_t                    num_blocks;
      25                 :            :         spdk_bdev_io_completion_cb  cb;
      26                 :            :         void                        *cb_arg;
      27                 :            :         enum spdk_bdev_io_type      iotype;
      28                 :            :         struct iovec                *iovs;
      29                 :            :         int                         iovcnt;
      30                 :            :         void                        *md_buf;
      31                 :            : };
      32                 :            : 
      33                 :            : struct raid_io_ranges {
      34                 :            :         uint64_t lba;
      35                 :            :         uint64_t nblocks;
      36                 :            : };
      37                 :            : 
      38                 :            : /* Globals */
      39                 :            : struct io_output *g_io_output = NULL;
      40                 :            : uint32_t g_io_output_index;
      41                 :            : uint32_t g_io_comp_status;
      42                 :            : bool g_child_io_status_flag;
      43                 :            : TAILQ_HEAD(bdev, spdk_bdev);
      44                 :            : uint32_t g_block_len;
      45                 :            : uint32_t g_strip_size;
      46                 :            : uint32_t g_max_io_size;
      47                 :            : uint8_t g_max_base_drives;
      48                 :            : struct raid_io_ranges g_io_ranges[MAX_TEST_IO_RANGE];
      49                 :            : uint32_t g_io_range_idx;
      50                 :            : bool g_enable_dif;
      51                 :            : 
      52                 :          4 : DEFINE_STUB_V(raid_bdev_module_list_add, (struct raid_bdev_module *raid_module));
      53                 :          0 : DEFINE_STUB_V(raid_bdev_queue_io_wait, (struct raid_bdev_io *raid_io, struct spdk_bdev *bdev,
      54                 :            :                                         struct spdk_io_channel *ch, spdk_bdev_io_wait_cb cb_fn));
      55         [ #  # ]:          0 : DEFINE_STUB(spdk_bdev_flush_blocks, int, (struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
      56                 :            :                 uint64_t offset_blocks, uint64_t num_blocks, spdk_bdev_io_completion_cb cb,
      57                 :            :                 void *cb_arg), 0);
      58   [ -  +  -  + ]:         72 : DEFINE_STUB(spdk_bdev_is_dif_head_of_md, bool, (const struct spdk_bdev *bdev), false);
      59         [ #  # ]:          0 : DEFINE_STUB(spdk_bdev_notify_blockcnt_change, int, (struct spdk_bdev *bdev, uint64_t size), 0);
      60                 :            : 
      61                 :            : bool
      62                 :        112 : spdk_bdev_is_md_interleaved(const struct spdk_bdev *bdev)
      63                 :            : {
      64   [ +  +  -  +  :        112 :         return (bdev->md_len != 0) && bdev->md_interleave;
                   -  + ]
      65                 :            : }
      66                 :            : 
      67                 :            : bool
      68                 :         40 : spdk_bdev_is_md_separate(const struct spdk_bdev *bdev)
      69                 :            : {
      70   [ +  +  +  +  :         40 :         return (bdev->md_len != 0) && !bdev->md_interleave;
                   +  - ]
      71                 :            : }
      72                 :            : 
      73                 :            : uint32_t
      74                 :        164 : spdk_bdev_get_md_size(const struct spdk_bdev *bdev)
      75                 :            : {
      76                 :        164 :         return bdev->md_len;
      77                 :            : }
      78                 :            : 
      79                 :            : uint32_t
      80                 :         72 : spdk_bdev_get_block_size(const struct spdk_bdev *bdev)
      81                 :            : {
      82                 :         72 :         return bdev->blocklen;
      83                 :            : }
      84                 :            : 
      85                 :            : static int
      86                 :          8 : set_test_opts(void)
      87                 :            : {
      88                 :          8 :         g_max_base_drives = MAX_BASE_DRIVES;
      89                 :          8 :         g_block_len = 4096;
      90                 :          8 :         g_strip_size = 64;
      91                 :          8 :         g_max_io_size = 1024;
      92                 :          8 :         g_enable_dif = false;
      93                 :            : 
      94                 :          8 :         return 0;
      95                 :            : }
      96                 :            : 
      97                 :            : static int
      98                 :          4 : set_test_opts_dif(void)
      99                 :            : {
     100                 :          4 :         set_test_opts();
     101                 :          4 :         g_enable_dif = true;
     102                 :            : 
     103                 :          4 :         return 0;
     104                 :            : }
     105                 :            : 
     106                 :            : /* Set globals before every test run */
     107                 :            : static void
     108                 :         32 : set_globals(void)
     109                 :            : {
     110                 :            :         uint32_t max_splits;
     111                 :            : 
     112         [ -  + ]:         32 :         if (g_max_io_size < g_strip_size) {
     113                 :          0 :                 max_splits = 2;
     114                 :            :         } else {
     115         [ -  + ]:         32 :                 max_splits = (g_max_io_size / g_strip_size) + 1;
     116                 :            :         }
     117         [ +  - ]:         32 :         if (max_splits < g_max_base_drives) {
     118                 :         32 :                 max_splits = g_max_base_drives;
     119                 :            :         }
     120                 :            : 
     121                 :         32 :         g_io_output = calloc(max_splits, sizeof(struct io_output));
     122         [ -  + ]:         32 :         SPDK_CU_ASSERT_FATAL(g_io_output != NULL);
     123                 :         32 :         g_io_output_index = 0;
     124                 :         32 :         g_io_comp_status = 0;
     125                 :         32 :         g_child_io_status_flag = true;
     126                 :         32 : }
     127                 :            : 
     128                 :            : /* Reset globals */
     129                 :            : static void
     130                 :         32 : reset_globals(void)
     131                 :            : {
     132         [ +  - ]:         32 :         if (g_io_output) {
     133                 :         32 :                 free(g_io_output);
     134                 :         32 :                 g_io_output = NULL;
     135                 :            :         }
     136                 :         32 : }
     137                 :            : 
     138                 :            : static void
     139                 :         40 : generate_dif(struct iovec *iovs, int iovcnt, void *md_buf,
     140                 :            :              uint64_t offset_blocks, uint32_t num_blocks, struct spdk_bdev *bdev)
     141                 :            : {
     142                 :         40 :         struct spdk_dif_ctx dif_ctx;
     143                 :            :         int rc;
     144                 :         40 :         struct spdk_dif_ctx_init_ext_opts dif_opts;
     145                 :            :         spdk_dif_type_t dif_type;
     146                 :            :         bool md_interleaved;
     147                 :         40 :         struct iovec md_iov;
     148                 :            : 
     149                 :         40 :         dif_type = spdk_bdev_get_dif_type(bdev);
     150                 :         40 :         md_interleaved = spdk_bdev_is_md_interleaved(bdev);
     151                 :            : 
     152         [ +  + ]:         40 :         if (dif_type == SPDK_DIF_DISABLE) {
     153                 :         20 :                 return;
     154                 :            :         }
     155                 :            : 
     156                 :         20 :         dif_opts.size = SPDK_SIZEOF(&dif_opts, dif_pi_format);
     157                 :         20 :         dif_opts.dif_pi_format = SPDK_DIF_PI_FORMAT_16;
     158                 :         30 :         rc = spdk_dif_ctx_init(&dif_ctx,
     159                 :            :                                spdk_bdev_get_block_size(bdev),
     160                 :            :                                spdk_bdev_get_md_size(bdev),
     161                 :            :                                md_interleaved,
     162                 :         20 :                                spdk_bdev_is_dif_head_of_md(bdev),
     163                 :            :                                dif_type,
     164                 :            :                                bdev->dif_check_flags,
     165                 :            :                                offset_blocks,
     166                 :            :                                0xFFFF, 0x123, 0, 0, &dif_opts);
     167         [ -  + ]:         20 :         SPDK_CU_ASSERT_FATAL(rc == 0);
     168                 :            : 
     169         [ +  - ]:         20 :         if (!md_interleaved) {
     170                 :         20 :                 md_iov.iov_base = md_buf;
     171                 :         20 :                 md_iov.iov_len  = spdk_bdev_get_md_size(bdev) * num_blocks;
     172                 :            : 
     173                 :         20 :                 rc = spdk_dix_generate(iovs, iovcnt, &md_iov, num_blocks, &dif_ctx);
     174         [ -  + ]:         20 :                 SPDK_CU_ASSERT_FATAL(rc == 0);
     175                 :            :         }
     176                 :            : }
     177                 :            : 
     178                 :            : static void
     179                 :         60 : verify_dif(struct iovec *iovs, int iovcnt, void *md_buf,
     180                 :            :            uint64_t offset_blocks, uint32_t num_blocks, struct spdk_bdev *bdev)
     181                 :            : {
     182                 :         60 :         struct spdk_dif_ctx dif_ctx;
     183                 :            :         int rc;
     184                 :         60 :         struct spdk_dif_ctx_init_ext_opts dif_opts;
     185                 :         60 :         struct spdk_dif_error errblk;
     186                 :            :         spdk_dif_type_t dif_type;
     187                 :            :         bool md_interleaved;
     188                 :         60 :         struct iovec md_iov;
     189                 :            : 
     190                 :         60 :         dif_type = spdk_bdev_get_dif_type(bdev);
     191                 :         60 :         md_interleaved = spdk_bdev_is_md_interleaved(bdev);
     192                 :            : 
     193         [ +  + ]:         60 :         if (dif_type == SPDK_DIF_DISABLE) {
     194                 :         20 :                 return;
     195                 :            :         }
     196                 :            : 
     197                 :         40 :         dif_opts.size = SPDK_SIZEOF(&dif_opts, dif_pi_format);
     198                 :         40 :         dif_opts.dif_pi_format = SPDK_DIF_PI_FORMAT_16;
     199                 :         60 :         rc = spdk_dif_ctx_init(&dif_ctx,
     200                 :            :                                spdk_bdev_get_block_size(bdev),
     201                 :            :                                spdk_bdev_get_md_size(bdev),
     202                 :            :                                md_interleaved,
     203                 :         40 :                                spdk_bdev_is_dif_head_of_md(bdev),
     204                 :            :                                dif_type,
     205                 :            :                                bdev->dif_check_flags,
     206                 :            :                                offset_blocks,
     207                 :            :                                0xFFFF, 0x123, 0, 0, &dif_opts);
     208         [ -  + ]:         40 :         SPDK_CU_ASSERT_FATAL(rc == 0);
     209                 :            : 
     210         [ +  - ]:         40 :         if (!md_interleaved) {
     211                 :         40 :                 md_iov.iov_base = md_buf;
     212                 :         40 :                 md_iov.iov_len  = spdk_bdev_get_md_size(bdev) * num_blocks;
     213                 :            : 
     214                 :         40 :                 rc = spdk_dix_verify(iovs, iovcnt,
     215                 :            :                                      &md_iov, num_blocks, &dif_ctx, &errblk);
     216         [ -  + ]:         40 :                 SPDK_CU_ASSERT_FATAL(rc == 0);
     217                 :            :         }
     218                 :            : }
     219                 :            : 
     220                 :            : static void
     221                 :         12 : remap_dif(void *md_buf, uint64_t num_blocks, struct spdk_bdev *bdev, uint32_t remapped_offset)
     222                 :            : {
     223                 :         12 :         struct spdk_dif_ctx dif_ctx;
     224                 :            :         int rc;
     225                 :         12 :         struct spdk_dif_ctx_init_ext_opts dif_opts;
     226                 :         12 :         struct spdk_dif_error errblk;
     227                 :            :         spdk_dif_type_t dif_type;
     228                 :            :         bool md_interleaved;
     229                 :         12 :         struct iovec md_iov;
     230                 :            : 
     231                 :         12 :         dif_type = spdk_bdev_get_dif_type(bdev);
     232                 :         12 :         md_interleaved = spdk_bdev_is_md_interleaved(bdev);
     233                 :            : 
     234         [ -  + ]:         12 :         if (dif_type == SPDK_DIF_DISABLE) {
     235                 :          0 :                 return;
     236                 :            :         }
     237                 :            : 
     238                 :         12 :         dif_opts.size = SPDK_SIZEOF(&dif_opts, dif_pi_format);
     239                 :         12 :         dif_opts.dif_pi_format = SPDK_DIF_PI_FORMAT_16;
     240                 :         18 :         rc = spdk_dif_ctx_init(&dif_ctx,
     241                 :            :                                spdk_bdev_get_block_size(bdev),
     242                 :            :                                spdk_bdev_get_md_size(bdev),
     243                 :            :                                md_interleaved,
     244                 :         12 :                                spdk_bdev_is_dif_head_of_md(bdev),
     245                 :            :                                dif_type,
     246                 :            :                                bdev->dif_check_flags,
     247                 :            :                                0,
     248                 :            :                                0xFFFF, 0x123, 0, 0, &dif_opts);
     249         [ -  + ]:         12 :         SPDK_CU_ASSERT_FATAL(rc == 0);
     250                 :            : 
     251         [ +  - ]:         12 :         if (!md_interleaved) {
     252                 :         12 :                 md_iov.iov_base = md_buf;
     253                 :         12 :                 md_iov.iov_len  = spdk_bdev_get_md_size(bdev) * num_blocks;
     254                 :            : 
     255                 :         12 :                 spdk_dif_ctx_set_remapped_init_ref_tag(&dif_ctx, remapped_offset);
     256                 :            : 
     257                 :         12 :                 rc = spdk_dix_remap_ref_tag(&md_iov, num_blocks, &dif_ctx, &errblk, false);
     258         [ -  + ]:         12 :                 SPDK_CU_ASSERT_FATAL(rc == 0);
     259                 :            :         }
     260                 :            : }
     261                 :            : 
     262                 :            : /* Store the IO completion status in global variable to verify by various tests */
     263                 :            : void
     264                 :       7744 : raid_test_bdev_io_complete(struct raid_bdev_io *raid_io, enum spdk_bdev_io_status status)
     265                 :            : {
     266                 :       7744 :         g_io_comp_status = ((status == SPDK_BDEV_IO_STATUS_SUCCESS) ? true : false);
     267                 :       7744 : }
     268                 :            : 
     269                 :            : int
     270                 :         12 : raid_bdev_remap_dix_reftag(void *md_buf, uint64_t num_blocks,
     271                 :            :                            struct spdk_bdev *bdev, uint32_t remapped_offset)
     272                 :            : {
     273                 :         12 :         remap_dif(md_buf, num_blocks, bdev, remapped_offset);
     274                 :            : 
     275                 :         12 :         return 0;
     276                 :            : }
     277                 :            : 
     278                 :            : int
     279                 :         20 : raid_bdev_verify_dix_reftag(struct iovec *iovs, int iovcnt, void *md_buf,
     280                 :            :                             uint64_t num_blocks, struct spdk_bdev *bdev, uint32_t offset_blocks)
     281                 :            : {
     282                 :         20 :         verify_dif(iovs, iovcnt, md_buf, offset_blocks, num_blocks, bdev);
     283                 :            : 
     284                 :         20 :         return 0;
     285                 :            : }
     286                 :            : 
     287                 :            : static void
     288                 :     141664 : set_io_output(struct io_output *output,
     289                 :            :               struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
     290                 :            :               uint64_t offset_blocks, uint64_t num_blocks,
     291                 :            :               spdk_bdev_io_completion_cb cb, void *cb_arg,
     292                 :            :               enum spdk_bdev_io_type iotype, struct iovec *iovs,
     293                 :            :               int iovcnt, void *md)
     294                 :            : {
     295                 :     141664 :         output->desc = desc;
     296                 :     141664 :         output->ch = ch;
     297                 :     141664 :         output->offset_blocks = offset_blocks;
     298                 :     141664 :         output->num_blocks = num_blocks;
     299                 :     141664 :         output->cb = cb;
     300                 :     141664 :         output->cb_arg = cb_arg;
     301                 :     141664 :         output->iotype = iotype;
     302                 :     141664 :         output->iovs = iovs;
     303                 :     141664 :         output->iovcnt = iovcnt;
     304                 :     141664 :         output->md_buf = md;
     305                 :     141664 : }
     306                 :            : 
     307                 :            : static struct spdk_bdev_io *
     308                 :     141664 : get_child_io(struct io_output *output)
     309                 :            : {
     310                 :            :         struct spdk_bdev_io *bdev_io;
     311                 :            : 
     312                 :     141664 :         bdev_io = calloc(1, sizeof(*bdev_io));
     313         [ -  + ]:     141664 :         SPDK_CU_ASSERT_FATAL(bdev_io != NULL);
     314                 :            : 
     315                 :     141664 :         bdev_io->bdev = spdk_bdev_desc_get_bdev(output->desc);
     316                 :     141664 :         bdev_io->type = output->iotype;
     317                 :     141664 :         bdev_io->u.bdev.offset_blocks = output->offset_blocks;
     318                 :     141664 :         bdev_io->u.bdev.num_blocks = output->num_blocks;
     319                 :     141664 :         bdev_io->u.bdev.iovs = output->iovs;
     320                 :     141664 :         bdev_io->u.bdev.iovcnt = output->iovcnt;
     321                 :     141664 :         bdev_io->u.bdev.md_buf = output->md_buf;
     322                 :            : 
     323                 :     141664 :         return bdev_io;
     324                 :            : }
     325                 :            : 
     326                 :            : static void
     327                 :     141664 : child_io_complete(struct spdk_bdev_io *bdev_io, spdk_bdev_io_completion_cb cb, void *cb_arg)
     328                 :            : {
     329   [ +  +  +  +  :     141664 :         if (g_child_io_status_flag && bdev_io->type == SPDK_BDEV_IO_TYPE_READ) {
                   +  + ]
     330                 :         24 :                 verify_dif(bdev_io->u.bdev.iovs, bdev_io->u.bdev.iovcnt, bdev_io->u.bdev.md_buf,
     331                 :         16 :                            bdev_io->u.bdev.offset_blocks, bdev_io->u.bdev.num_blocks, bdev_io->bdev);
     332                 :            :         }
     333                 :            : 
     334         [ -  + ]:     141664 :         cb(bdev_io, g_child_io_status_flag, cb_arg);
     335                 :     141664 : }
     336                 :            : 
     337                 :            : int
     338                 :         24 : spdk_bdev_writev_blocks_ext(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
     339                 :            :                             struct iovec *iov, int iovcnt,
     340                 :            :                             uint64_t offset_blocks, uint64_t num_blocks,
     341                 :            :                             spdk_bdev_io_completion_cb cb, void *cb_arg,
     342                 :            :                             struct spdk_bdev_ext_io_opts *opts)
     343                 :            : {
     344                 :         24 :         struct io_output *output = &g_io_output[g_io_output_index];
     345                 :            :         struct spdk_bdev_io *child_io;
     346                 :            : 
     347         [ -  + ]:         24 :         if (g_max_io_size < g_strip_size) {
     348         [ #  # ]:          0 :                 SPDK_CU_ASSERT_FATAL(g_io_output_index < 2);
     349                 :            :         } else {
     350   [ -  +  -  + ]:         24 :                 SPDK_CU_ASSERT_FATAL(g_io_output_index < (g_max_io_size / g_strip_size) + 1);
     351                 :            :         }
     352                 :         24 :         set_io_output(output, desc, ch, offset_blocks, num_blocks, cb, cb_arg,
     353                 :            :                       SPDK_BDEV_IO_TYPE_WRITE, iov, iovcnt, opts->metadata);
     354                 :         24 :         g_io_output_index++;
     355                 :            : 
     356                 :         24 :         child_io = get_child_io(output);
     357                 :         24 :         child_io_complete(child_io, cb, cb_arg);
     358                 :            : 
     359                 :         24 :         return 0;
     360                 :            : }
     361                 :            : 
     362                 :            : int
     363                 :     141624 : spdk_bdev_unmap_blocks(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
     364                 :            :                        uint64_t offset_blocks, uint64_t num_blocks,
     365                 :            :                        spdk_bdev_io_completion_cb cb, void *cb_arg)
     366                 :            : {
     367                 :     141624 :         struct io_output *output = &g_io_output[g_io_output_index];
     368                 :            :         struct spdk_bdev_io *child_io;
     369                 :            : 
     370                 :     141624 :         set_io_output(output, desc, ch, offset_blocks, num_blocks, cb, cb_arg,
     371                 :            :                       SPDK_BDEV_IO_TYPE_UNMAP, NULL, 0, NULL);
     372                 :     141624 :         g_io_output_index++;
     373                 :            : 
     374                 :     141624 :         child_io = get_child_io(output);
     375                 :     141624 :         child_io_complete(child_io, cb, cb_arg);
     376                 :            : 
     377                 :     141624 :         return 0;
     378                 :            : }
     379                 :            : 
     380                 :            : void
     381                 :     141664 : spdk_bdev_free_io(struct spdk_bdev_io *bdev_io)
     382                 :            : {
     383         [ +  - ]:     141664 :         if (bdev_io) {
     384                 :     141664 :                 free(bdev_io);
     385                 :            :         }
     386                 :     141664 : }
     387                 :            : 
     388                 :            : int
     389                 :         16 : spdk_bdev_readv_blocks_ext(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
     390                 :            :                            struct iovec *iov, int iovcnt,
     391                 :            :                            uint64_t offset_blocks, uint64_t num_blocks,
     392                 :            :                            spdk_bdev_io_completion_cb cb, void *cb_arg,
     393                 :            :                            struct spdk_bdev_ext_io_opts *opts)
     394                 :            : {
     395                 :         16 :         struct io_output *output = &g_io_output[g_io_output_index];
     396                 :            :         struct spdk_bdev_io *child_io;
     397                 :            : 
     398   [ -  +  -  + ]:         16 :         SPDK_CU_ASSERT_FATAL(g_io_output_index <= (g_max_io_size / g_strip_size) + 1);
     399                 :         16 :         set_io_output(output, desc, ch, offset_blocks, num_blocks, cb, cb_arg,
     400                 :            :                       SPDK_BDEV_IO_TYPE_READ, iov, iovcnt, opts->metadata);
     401                 :         16 :         generate_dif(iov, iovcnt, opts->metadata, offset_blocks, num_blocks,
     402                 :            :                      spdk_bdev_desc_get_bdev(desc));
     403                 :         16 :         g_io_output_index++;
     404                 :            : 
     405                 :         16 :         child_io = get_child_io(output);
     406                 :         16 :         child_io_complete(child_io, cb, cb_arg);
     407                 :            : 
     408                 :         16 :         return 0;
     409                 :            : }
     410                 :            : 
     411                 :            : static void
     412                 :       7744 : raid_io_cleanup(struct raid_bdev_io *raid_io)
     413                 :            : {
     414         [ +  + ]:       7744 :         if (raid_io->iovs) {
     415                 :            :                 int i;
     416                 :            : 
     417         [ +  + ]:         80 :                 for (i = 0; i < raid_io->iovcnt; i++) {
     418                 :         40 :                         free(raid_io->iovs[i].iov_base);
     419                 :            :                 }
     420                 :         40 :                 free(raid_io->iovs);
     421                 :            :         }
     422                 :            : 
     423                 :       7744 :         free(raid_io->md_buf);
     424                 :       7744 :         free(raid_io);
     425                 :       7744 : }
     426                 :            : 
     427                 :            : static void
     428                 :       7744 : raid_io_initialize(struct raid_bdev_io *raid_io, struct raid_bdev_io_channel *raid_ch,
     429                 :            :                    struct raid_bdev *raid_bdev, uint64_t lba, uint64_t blocks, int16_t iotype)
     430                 :            : {
     431                 :       7744 :         struct iovec *iovs = NULL;
     432                 :       7744 :         int iovcnt = 0;
     433                 :       7744 :         void *md_buf = NULL;
     434                 :            : 
     435   [ +  +  +  - ]:       7744 :         if (iotype != SPDK_BDEV_IO_TYPE_UNMAP && iotype != SPDK_BDEV_IO_TYPE_FLUSH) {
     436                 :         40 :                 iovcnt = 1;
     437                 :         40 :                 iovs = calloc(iovcnt, sizeof(struct iovec));
     438         [ -  + ]:         40 :                 SPDK_CU_ASSERT_FATAL(iovs != NULL);
     439                 :         40 :                 iovs->iov_len = blocks * g_block_len;
     440                 :         40 :                 iovs->iov_base = calloc(1, iovs->iov_len);
     441         [ -  + ]:         40 :                 SPDK_CU_ASSERT_FATAL(iovs->iov_base != NULL);
     442                 :            : 
     443         [ +  + ]:         40 :                 if (spdk_bdev_is_md_separate(&raid_bdev->bdev)) {
     444                 :         20 :                         md_buf = calloc(1, blocks * spdk_bdev_get_md_size(&raid_bdev->bdev));
     445         [ -  + ]:         20 :                         SPDK_CU_ASSERT_FATAL(md_buf != NULL);
     446                 :            :                 }
     447                 :            :         }
     448                 :            : 
     449                 :       7744 :         raid_test_bdev_io_init(raid_io, raid_bdev, raid_ch, iotype, lba, blocks, iovs, iovcnt, md_buf);
     450                 :       7744 : }
     451                 :            : 
     452                 :            : static void
     453                 :         40 : verify_io(struct raid_bdev_io *raid_io, uint32_t io_status)
     454                 :            : {
     455                 :         40 :         struct raid_bdev *raid_bdev = raid_io->raid_bdev;
     456                 :         40 :         uint8_t num_base_drives = raid_bdev->num_base_bdevs;
     457                 :         40 :         uint32_t strip_shift = spdk_u32log2(g_strip_size);
     458         [ -  + ]:         40 :         uint64_t start_strip = raid_io->offset_blocks >> strip_shift;
     459         [ -  + ]:         40 :         uint64_t end_strip = (raid_io->offset_blocks + raid_io->num_blocks - 1) >>
     460                 :            :                              strip_shift;
     461                 :         40 :         uint32_t splits_reqd = (end_strip - start_strip + 1);
     462                 :            :         uint32_t strip;
     463                 :            :         uint64_t pd_strip;
     464                 :            :         uint8_t pd_idx;
     465                 :            :         uint32_t offset_in_strip;
     466                 :            :         uint64_t pd_lba;
     467                 :            :         uint64_t pd_blocks;
     468                 :         40 :         uint32_t index = 0;
     469                 :            :         struct io_output *output;
     470                 :            : 
     471         [ -  + ]:         40 :         SPDK_CU_ASSERT_FATAL(raid_bdev != NULL);
     472         [ -  + ]:         40 :         SPDK_CU_ASSERT_FATAL(num_base_drives != 0);
     473                 :            : 
     474                 :         40 :         CU_ASSERT(splits_reqd == g_io_output_index);
     475         [ +  + ]:         80 :         for (strip = start_strip; strip <= end_strip; strip++, index++) {
     476         [ -  + ]:         40 :                 pd_strip = strip / num_base_drives;
     477         [ -  + ]:         40 :                 pd_idx = strip % num_base_drives;
     478         [ +  - ]:         40 :                 if (strip == start_strip) {
     479                 :         40 :                         offset_in_strip = raid_io->offset_blocks & (g_strip_size - 1);
     480         [ -  + ]:         40 :                         pd_lba = (pd_strip << strip_shift) + offset_in_strip;
     481         [ +  - ]:         40 :                         if (strip == end_strip) {
     482                 :         40 :                                 pd_blocks = raid_io->num_blocks;
     483                 :            :                         } else {
     484                 :          0 :                                 pd_blocks = g_strip_size - offset_in_strip;
     485                 :            :                         }
     486         [ #  # ]:          0 :                 } else if (strip == end_strip) {
     487         [ #  # ]:          0 :                         pd_lba = pd_strip << strip_shift;
     488                 :          0 :                         pd_blocks = ((raid_io->offset_blocks + raid_io->num_blocks - 1) &
     489                 :          0 :                                      (g_strip_size - 1)) + 1;
     490                 :            :                 } else {
     491         [ #  # ]:          0 :                         pd_lba = pd_strip << raid_bdev->strip_size_shift;
     492                 :          0 :                         pd_blocks = raid_bdev->strip_size;
     493                 :            :                 }
     494                 :         40 :                 output = &g_io_output[index];
     495                 :         40 :                 CU_ASSERT(pd_lba == output->offset_blocks);
     496                 :         40 :                 CU_ASSERT(pd_blocks == output->num_blocks);
     497                 :         40 :                 CU_ASSERT(raid_bdev_channel_get_base_channel(raid_io->raid_ch, pd_idx) == output->ch);
     498                 :         40 :                 CU_ASSERT(raid_bdev->base_bdev_info[pd_idx].desc == output->desc);
     499                 :         40 :                 CU_ASSERT(raid_io->type == output->iotype);
     500         [ +  + ]:         40 :                 if (raid_io->type == SPDK_BDEV_IO_TYPE_WRITE) {
     501                 :         48 :                         verify_dif(output->iovs, output->iovcnt, output->md_buf,
     502                 :         24 :                                    output->offset_blocks, output->num_blocks,
     503                 :         24 :                                    spdk_bdev_desc_get_bdev(raid_bdev->base_bdev_info[pd_idx].desc));
     504                 :            :                 }
     505                 :            :         }
     506                 :         40 :         CU_ASSERT(g_io_comp_status == io_status);
     507                 :         40 : }
     508                 :            : 
     509                 :            : static void
     510                 :       7704 : verify_io_without_payload(struct raid_bdev_io *raid_io, uint32_t io_status)
     511                 :            : {
     512                 :       7704 :         struct raid_bdev *raid_bdev = raid_io->raid_bdev;
     513                 :       7704 :         uint8_t num_base_drives = raid_bdev->num_base_bdevs;
     514                 :       7704 :         uint32_t strip_shift = spdk_u32log2(g_strip_size);
     515         [ -  + ]:       7704 :         uint64_t start_offset_in_strip = raid_io->offset_blocks % g_strip_size;
     516         [ -  + ]:       7704 :         uint64_t end_offset_in_strip = (raid_io->offset_blocks + raid_io->num_blocks - 1) %
     517                 :            :                                        g_strip_size;
     518         [ -  + ]:       7704 :         uint64_t start_strip = raid_io->offset_blocks >> strip_shift;
     519         [ -  + ]:       7704 :         uint64_t end_strip = (raid_io->offset_blocks + raid_io->num_blocks - 1) >>
     520                 :            :                              strip_shift;
     521                 :            :         uint8_t n_disks_involved;
     522                 :            :         uint64_t start_strip_disk_idx;
     523                 :            :         uint64_t end_strip_disk_idx;
     524                 :            :         uint64_t nblocks_in_start_disk;
     525                 :            :         uint64_t offset_in_start_disk;
     526                 :            :         uint8_t disk_idx;
     527                 :            :         uint64_t base_io_idx;
     528                 :       7704 :         uint64_t sum_nblocks = 0;
     529                 :            :         struct io_output *output;
     530                 :            : 
     531         [ -  + ]:       7704 :         SPDK_CU_ASSERT_FATAL(raid_bdev != NULL);
     532         [ -  + ]:       7704 :         SPDK_CU_ASSERT_FATAL(num_base_drives != 0);
     533         [ -  + ]:       7704 :         SPDK_CU_ASSERT_FATAL(raid_io->type != SPDK_BDEV_IO_TYPE_READ);
     534         [ -  + ]:       7704 :         SPDK_CU_ASSERT_FATAL(raid_io->type != SPDK_BDEV_IO_TYPE_WRITE);
     535                 :            : 
     536                 :       7704 :         n_disks_involved = spdk_min(end_strip - start_strip + 1, num_base_drives);
     537                 :       7704 :         CU_ASSERT(n_disks_involved == g_io_output_index);
     538                 :            : 
     539         [ -  + ]:       7704 :         start_strip_disk_idx = start_strip % num_base_drives;
     540         [ -  + ]:       7704 :         end_strip_disk_idx = end_strip % num_base_drives;
     541                 :            : 
     542                 :       7704 :         offset_in_start_disk = g_io_output[0].offset_blocks;
     543                 :       7704 :         nblocks_in_start_disk = g_io_output[0].num_blocks;
     544                 :            : 
     545         [ +  + ]:     149328 :         for (base_io_idx = 0, disk_idx = start_strip_disk_idx; base_io_idx < n_disks_involved;
     546                 :     141624 :              base_io_idx++, disk_idx++) {
     547                 :            :                 uint64_t start_offset_in_disk;
     548                 :            :                 uint64_t end_offset_in_disk;
     549                 :            : 
     550                 :     141624 :                 output = &g_io_output[base_io_idx];
     551                 :            : 
     552                 :            :                 /* round disk_idx */
     553         [ +  + ]:     141624 :                 if (disk_idx >= num_base_drives) {
     554         [ -  + ]:       3960 :                         disk_idx %= num_base_drives;
     555                 :            :                 }
     556                 :            : 
     557                 :            :                 /* start_offset_in_disk aligned in strip check:
     558                 :            :                  * The first base io has a same start_offset_in_strip with the whole raid io.
     559                 :            :                  * Other base io should have aligned start_offset_in_strip which is 0.
     560                 :            :                  */
     561                 :     141624 :                 start_offset_in_disk = output->offset_blocks;
     562         [ +  + ]:     141624 :                 if (base_io_idx == 0) {
     563         [ -  + ]:       7704 :                         CU_ASSERT(start_offset_in_disk % g_strip_size == start_offset_in_strip);
     564                 :            :                 } else {
     565         [ -  + ]:     133920 :                         CU_ASSERT(start_offset_in_disk % g_strip_size == 0);
     566                 :            :                 }
     567                 :            : 
     568                 :            :                 /* end_offset_in_disk aligned in strip check:
     569                 :            :                  * Base io on disk at which end_strip is located, has a same end_offset_in_strip
     570                 :            :                  * with the whole raid io.
     571                 :            :                  * Other base io should have aligned end_offset_in_strip.
     572                 :            :                  */
     573                 :     141624 :                 end_offset_in_disk = output->offset_blocks + output->num_blocks - 1;
     574         [ +  + ]:     141624 :                 if (disk_idx == end_strip_disk_idx) {
     575         [ -  + ]:       7704 :                         CU_ASSERT(end_offset_in_disk % g_strip_size == end_offset_in_strip);
     576                 :            :                 } else {
     577         [ -  + ]:     133920 :                         CU_ASSERT(end_offset_in_disk % g_strip_size == g_strip_size - 1);
     578                 :            :                 }
     579                 :            : 
     580                 :            :                 /* start_offset_in_disk compared with start_disk.
     581                 :            :                  * 1. For disk_idx which is larger than start_strip_disk_idx: Its start_offset_in_disk
     582                 :            :                  *    mustn't be larger than the start offset of start_offset_in_disk; And the gap
     583                 :            :                  *    must be less than strip size.
     584                 :            :                  * 2. For disk_idx which is less than start_strip_disk_idx, Its start_offset_in_disk
     585                 :            :                  *    must be larger than the start offset of start_offset_in_disk; And the gap mustn't
     586                 :            :                  *    be less than strip size.
     587                 :            :                  */
     588         [ +  + ]:     141624 :                 if (disk_idx > start_strip_disk_idx) {
     589                 :      74880 :                         CU_ASSERT(start_offset_in_disk <= offset_in_start_disk);
     590                 :      74880 :                         CU_ASSERT(offset_in_start_disk - start_offset_in_disk < g_strip_size);
     591         [ +  + ]:      66744 :                 } else if (disk_idx < start_strip_disk_idx) {
     592                 :      59040 :                         CU_ASSERT(start_offset_in_disk > offset_in_start_disk);
     593                 :      59040 :                         CU_ASSERT(output->offset_blocks - offset_in_start_disk <= g_strip_size);
     594                 :            :                 }
     595                 :            : 
     596                 :            :                 /* nblocks compared with start_disk:
     597                 :            :                  * The gap between them must be within a strip size.
     598                 :            :                  */
     599         [ +  + ]:     141624 :                 if (output->num_blocks <= nblocks_in_start_disk) {
     600                 :      56352 :                         CU_ASSERT(nblocks_in_start_disk - output->num_blocks <= g_strip_size);
     601                 :            :                 } else {
     602                 :      85272 :                         CU_ASSERT(output->num_blocks - nblocks_in_start_disk < g_strip_size);
     603                 :            :                 }
     604                 :            : 
     605                 :     141624 :                 sum_nblocks += output->num_blocks;
     606                 :            : 
     607                 :     141624 :                 CU_ASSERT(raid_bdev_channel_get_base_channel(raid_io->raid_ch, disk_idx) == output->ch);
     608                 :     141624 :                 CU_ASSERT(raid_bdev->base_bdev_info[disk_idx].desc == output->desc);
     609                 :     141624 :                 CU_ASSERT(raid_io->type == output->iotype);
     610                 :            :         }
     611                 :            : 
     612                 :            :         /* Sum of each nblocks should be same with raid bdev_io */
     613                 :       7704 :         CU_ASSERT(raid_io->num_blocks == sum_nblocks);
     614                 :            : 
     615                 :       7704 :         CU_ASSERT(g_io_comp_status == io_status);
     616                 :       7704 : }
     617                 :            : 
     618                 :            : static struct raid_bdev *
     619                 :         32 : create_raid0(void)
     620                 :            : {
     621                 :            :         struct raid_bdev *raid_bdev;
     622                 :            :         struct raid_base_bdev_info *base_info;
     623                 :         32 :         struct raid_params params = {
     624                 :            :                 .num_base_bdevs = g_max_base_drives,
     625                 :            :                 .base_bdev_blockcnt = BLOCK_CNT,
     626                 :            :                 .base_bdev_blocklen = g_block_len,
     627                 :            :                 .strip_size = g_strip_size,
     628         [ -  + ]:         32 :                 .md_type = g_enable_dif ? RAID_PARAMS_MD_SEPARATE : RAID_PARAMS_MD_NONE,
     629                 :            :         };
     630                 :            : 
     631                 :         32 :         raid_bdev = raid_test_create_raid_bdev(&params, &g_raid0_module);
     632                 :            : 
     633         [ -  + ]:         32 :         SPDK_CU_ASSERT_FATAL(raid0_start(raid_bdev) == 0);
     634                 :            : 
     635   [ +  +  +  + ]:         32 :         if (g_enable_dif) {
     636                 :         16 :                 raid_bdev->bdev.dif_type = SPDK_DIF_TYPE1;
     637                 :         16 :                 raid_bdev->bdev.dif_check_flags =
     638                 :            :                         SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_REFTAG_CHECK |
     639                 :            :                         SPDK_DIF_FLAGS_APPTAG_CHECK;
     640                 :            : 
     641         [ +  + ]:        528 :                 RAID_FOR_EACH_BASE_BDEV(raid_bdev, base_info) {
     642                 :        512 :                         struct spdk_bdev *bdev = spdk_bdev_desc_get_bdev(base_info->desc);
     643                 :            : 
     644                 :        512 :                         bdev->dif_type = raid_bdev->bdev.dif_type;
     645                 :        512 :                         bdev->dif_check_flags = raid_bdev->bdev.dif_check_flags;
     646                 :            :                 }
     647                 :            :         }
     648                 :            : 
     649                 :         32 :         return raid_bdev;
     650                 :            : }
     651                 :            : 
     652                 :            : static void
     653                 :         32 : delete_raid0(struct raid_bdev *raid_bdev)
     654                 :            : {
     655                 :         32 :         raid_test_delete_raid_bdev(raid_bdev);
     656                 :         32 : }
     657                 :            : 
     658                 :            : static void
     659                 :          8 : test_write_io(void)
     660                 :            : {
     661                 :            :         struct raid_bdev *raid_bdev;
     662                 :            :         uint8_t i;
     663                 :            :         uint64_t io_len;
     664                 :          8 :         uint64_t lba = 0;
     665                 :            :         struct raid_bdev_io *raid_io;
     666                 :            :         struct raid_bdev_io_channel *raid_ch;
     667                 :            : 
     668                 :          8 :         set_globals();
     669                 :            : 
     670                 :          8 :         raid_bdev = create_raid0();
     671                 :          8 :         raid_ch = raid_test_create_io_channel(raid_bdev);
     672                 :            : 
     673                 :            :         /* test 2 IO sizes based on global strip size set earlier */
     674         [ +  + ]:         24 :         for (i = 0; i < 2; i++) {
     675                 :         16 :                 raid_io = calloc(1, sizeof(*raid_io));
     676         [ -  + ]:         16 :                 SPDK_CU_ASSERT_FATAL(raid_io != NULL);
     677         [ -  + ]:         16 :                 io_len = (g_strip_size / 2) << i;
     678                 :         16 :                 raid_io_initialize(raid_io, raid_ch, raid_bdev, lba, io_len, SPDK_BDEV_IO_TYPE_WRITE);
     679                 :         16 :                 lba += g_strip_size;
     680   [ -  +  -  + ]:         16 :                 memset(g_io_output, 0, ((g_max_io_size / g_strip_size) + 1) * sizeof(struct io_output));
     681                 :         16 :                 g_io_output_index = 0;
     682                 :         24 :                 generate_dif(raid_io->iovs, raid_io->iovcnt, raid_io->md_buf,
     683                 :         16 :                              raid_io->offset_blocks, raid_io->num_blocks, &raid_bdev->bdev);
     684                 :         16 :                 raid0_submit_rw_request(raid_io);
     685         [ -  + ]:         16 :                 verify_io(raid_io, g_child_io_status_flag);
     686                 :         16 :                 raid_io_cleanup(raid_io);
     687                 :            :         }
     688                 :            : 
     689                 :          8 :         raid_test_destroy_io_channel(raid_ch);
     690                 :          8 :         delete_raid0(raid_bdev);
     691                 :            : 
     692                 :          8 :         reset_globals();
     693                 :          8 : }
     694                 :            : 
     695                 :            : static void
     696                 :          8 : test_read_io(void)
     697                 :            : {
     698                 :            :         struct raid_bdev *raid_bdev;
     699                 :            :         uint8_t i;
     700                 :            :         uint64_t io_len;
     701                 :          8 :         uint64_t lba = 0;
     702                 :            :         struct raid_bdev_io *raid_io;
     703                 :            :         struct raid_bdev_io_channel *raid_ch;
     704                 :            : 
     705                 :          8 :         set_globals();
     706                 :            : 
     707                 :          8 :         raid_bdev = create_raid0();
     708                 :          8 :         raid_ch = raid_test_create_io_channel(raid_bdev);
     709                 :            : 
     710                 :            :         /* test 2 IO sizes based on global strip size set earlier */
     711                 :          8 :         lba = 0;
     712         [ +  + ]:         24 :         for (i = 0; i < 2; i++) {
     713                 :         16 :                 raid_io = calloc(1, sizeof(*raid_io));
     714         [ -  + ]:         16 :                 SPDK_CU_ASSERT_FATAL(raid_io != NULL);
     715         [ -  + ]:         16 :                 io_len = (g_strip_size / 2) << i;
     716                 :         16 :                 raid_io_initialize(raid_io, raid_ch, raid_bdev, lba, io_len, SPDK_BDEV_IO_TYPE_READ);
     717                 :         16 :                 lba += g_strip_size;
     718   [ -  +  -  + ]:         16 :                 memset(g_io_output, 0, ((g_max_io_size / g_strip_size) + 1) * sizeof(struct io_output));
     719                 :         16 :                 g_io_output_index = 0;
     720                 :         16 :                 raid0_submit_rw_request(raid_io);
     721         [ -  + ]:         16 :                 verify_io(raid_io, g_child_io_status_flag);
     722                 :         16 :                 raid_io_cleanup(raid_io);
     723                 :            :         }
     724                 :            : 
     725                 :          8 :         raid_test_destroy_io_channel(raid_ch);
     726                 :          8 :         delete_raid0(raid_bdev);
     727                 :            : 
     728                 :          8 :         reset_globals();
     729                 :          8 : }
     730                 :            : 
     731                 :            : static void
     732                 :        288 : raid_bdev_io_generate_by_strips(uint64_t n_strips)
     733                 :            : {
     734                 :            :         uint64_t lba;
     735                 :            :         uint64_t nblocks;
     736                 :            :         uint64_t start_offset;
     737                 :            :         uint64_t end_offset;
     738                 :        288 :         uint64_t offsets_in_strip[3];
     739                 :            :         uint64_t start_bdev_idx;
     740                 :            :         uint64_t start_bdev_offset;
     741                 :        288 :         uint64_t start_bdev_idxs[3];
     742                 :            :         int i, j, l;
     743                 :            : 
     744                 :            :         /* 3 different situations of offset in strip */
     745                 :        288 :         offsets_in_strip[0] = 0;
     746                 :        288 :         offsets_in_strip[1] = g_strip_size >> 1;
     747                 :        288 :         offsets_in_strip[2] = g_strip_size - 1;
     748                 :            : 
     749                 :            :         /* 3 different situations of start_bdev_idx */
     750                 :        288 :         start_bdev_idxs[0] = 0;
     751                 :        288 :         start_bdev_idxs[1] = g_max_base_drives >> 1;
     752                 :        288 :         start_bdev_idxs[2] = g_max_base_drives - 1;
     753                 :            : 
     754                 :            :         /* consider different offset in strip */
     755         [ +  + ]:       1152 :         for (i = 0; i < 3; i++) {
     756                 :        864 :                 start_offset = offsets_in_strip[i];
     757         [ +  + ]:       3456 :                 for (j = 0; j < 3; j++) {
     758                 :       2592 :                         end_offset = offsets_in_strip[j];
     759   [ +  +  +  + ]:       2592 :                         if (n_strips == 1 && start_offset > end_offset) {
     760                 :         24 :                                 continue;
     761                 :            :                         }
     762                 :            : 
     763                 :            :                         /* consider at which base_bdev lba is started. */
     764         [ +  + ]:      10272 :                         for (l = 0; l < 3; l++) {
     765                 :       7704 :                                 start_bdev_idx = start_bdev_idxs[l];
     766                 :       7704 :                                 start_bdev_offset = start_bdev_idx * g_strip_size;
     767                 :       7704 :                                 lba = start_bdev_offset + start_offset;
     768                 :       7704 :                                 nblocks = (n_strips - 1) * g_strip_size + end_offset - start_offset + 1;
     769                 :            : 
     770                 :       7704 :                                 g_io_ranges[g_io_range_idx].lba = lba;
     771                 :       7704 :                                 g_io_ranges[g_io_range_idx].nblocks = nblocks;
     772                 :            : 
     773         [ -  + ]:       7704 :                                 SPDK_CU_ASSERT_FATAL(g_io_range_idx < MAX_TEST_IO_RANGE);
     774                 :       7704 :                                 g_io_range_idx++;
     775                 :            :                         }
     776                 :            :                 }
     777                 :            :         }
     778                 :        288 : }
     779                 :            : 
     780                 :            : static void
     781                 :          8 : raid_bdev_io_generate(void)
     782                 :            : {
     783                 :            :         uint64_t n_strips;
     784                 :          8 :         uint64_t n_strips_span = g_max_base_drives;
     785                 :          8 :         uint64_t n_strips_times[5] = {g_max_base_drives + 1, g_max_base_drives * 2 - 1,
     786                 :          8 :                                       g_max_base_drives * 2, g_max_base_drives * 3,
     787                 :          8 :                                       g_max_base_drives * 4
     788                 :            :                                      };
     789                 :            :         uint32_t i;
     790                 :            : 
     791                 :          8 :         g_io_range_idx = 0;
     792                 :            : 
     793                 :            :         /* consider different number of strips from 1 to strips spanned base bdevs,
     794                 :            :          * and even to times of strips spanned base bdevs
     795                 :            :          */
     796         [ +  + ]:        256 :         for (n_strips = 1; n_strips < n_strips_span; n_strips++) {
     797                 :        248 :                 raid_bdev_io_generate_by_strips(n_strips);
     798                 :            :         }
     799                 :            : 
     800         [ +  + ]:         48 :         for (i = 0; i < SPDK_COUNTOF(n_strips_times); i++) {
     801                 :         40 :                 n_strips = n_strips_times[i];
     802                 :         40 :                 raid_bdev_io_generate_by_strips(n_strips);
     803                 :            :         }
     804                 :          8 : }
     805                 :            : 
     806                 :            : static void
     807                 :          8 : test_unmap_io(void)
     808                 :            : {
     809                 :            :         struct raid_bdev *raid_bdev;
     810                 :            :         uint32_t count;
     811                 :            :         uint64_t io_len;
     812                 :            :         uint64_t lba;
     813                 :            :         struct raid_bdev_io *raid_io;
     814                 :            :         struct raid_bdev_io_channel *raid_ch;
     815                 :            : 
     816                 :          8 :         set_globals();
     817                 :            : 
     818                 :          8 :         raid_bdev = create_raid0();
     819                 :          8 :         raid_ch = raid_test_create_io_channel(raid_bdev);
     820                 :            : 
     821                 :          8 :         raid_bdev_io_generate();
     822         [ +  + ]:       7712 :         for (count = 0; count < g_io_range_idx; count++) {
     823                 :       7704 :                 raid_io = calloc(1, sizeof(*raid_io));
     824         [ -  + ]:       7704 :                 SPDK_CU_ASSERT_FATAL(raid_io != NULL);
     825                 :       7704 :                 io_len = g_io_ranges[count].nblocks;
     826                 :       7704 :                 lba = g_io_ranges[count].lba;
     827                 :       7704 :                 raid_io_initialize(raid_io, raid_ch, raid_bdev, lba, io_len, SPDK_BDEV_IO_TYPE_UNMAP);
     828         [ -  + ]:       7704 :                 memset(g_io_output, 0, g_max_base_drives * sizeof(struct io_output));
     829                 :       7704 :                 g_io_output_index = 0;
     830                 :       7704 :                 raid0_submit_null_payload_request(raid_io);
     831         [ -  + ]:       7704 :                 verify_io_without_payload(raid_io, g_child_io_status_flag);
     832                 :       7704 :                 raid_io_cleanup(raid_io);
     833                 :            :         }
     834                 :            : 
     835                 :          8 :         raid_test_destroy_io_channel(raid_ch);
     836                 :          8 :         delete_raid0(raid_bdev);
     837                 :            : 
     838                 :          8 :         reset_globals();
     839                 :          8 : }
     840                 :            : 
     841                 :            : /* Test IO failures */
     842                 :            : static void
     843                 :          8 : test_io_failure(void)
     844                 :            : {
     845                 :            :         struct raid_bdev *raid_bdev;
     846                 :            :         uint32_t count;
     847                 :            :         uint64_t io_len;
     848                 :            :         uint64_t lba;
     849                 :            :         struct raid_bdev_io *raid_io;
     850                 :            :         struct raid_bdev_io_channel *raid_ch;
     851                 :            : 
     852                 :          8 :         set_globals();
     853                 :            : 
     854                 :          8 :         raid_bdev = create_raid0();
     855                 :          8 :         raid_ch = raid_test_create_io_channel(raid_bdev);
     856                 :            : 
     857                 :          8 :         lba = 0;
     858                 :          8 :         g_child_io_status_flag = false;
     859         [ +  + ]:         16 :         for (count = 0; count < 1; count++) {
     860                 :          8 :                 raid_io = calloc(1, sizeof(*raid_io));
     861         [ -  + ]:          8 :                 SPDK_CU_ASSERT_FATAL(raid_io != NULL);
     862         [ -  + ]:          8 :                 io_len = (g_strip_size / 2) << count;
     863                 :          8 :                 raid_io_initialize(raid_io, raid_ch, raid_bdev, lba, io_len, SPDK_BDEV_IO_TYPE_WRITE);
     864                 :          8 :                 lba += g_strip_size;
     865   [ -  +  -  + ]:          8 :                 memset(g_io_output, 0, ((g_max_io_size / g_strip_size) + 1) * sizeof(struct io_output));
     866                 :          8 :                 g_io_output_index = 0;
     867                 :         12 :                 generate_dif(raid_io->iovs, raid_io->iovcnt, raid_io->md_buf,
     868                 :          8 :                              raid_io->offset_blocks, raid_io->num_blocks, &raid_bdev->bdev);
     869                 :          8 :                 raid0_submit_rw_request(raid_io);
     870         [ -  + ]:          8 :                 verify_io(raid_io, g_child_io_status_flag);
     871                 :          8 :                 raid_io_cleanup(raid_io);
     872                 :            :         }
     873                 :            : 
     874                 :          8 :         raid_test_destroy_io_channel(raid_ch);
     875                 :          8 :         delete_raid0(raid_bdev);
     876                 :            : 
     877                 :          8 :         reset_globals();
     878                 :          8 : }
     879                 :            : 
     880                 :            : int
     881                 :          4 : main(int argc, char **argv)
     882                 :            : {
     883                 :            :         unsigned int    num_failures;
     884                 :            : 
     885                 :          4 :         CU_TestInfo tests[] = {
     886                 :            :                 { "test_write_io", test_write_io },
     887                 :            :                 { "test_read_io", test_read_io },
     888                 :            :                 { "test_unmap_io", test_unmap_io },
     889                 :            :                 { "test_io_failure", test_io_failure },
     890                 :            :                 CU_TEST_INFO_NULL,
     891                 :            :         };
     892                 :          4 :         CU_SuiteInfo suites[] = {
     893                 :            :                 { "raid0", set_test_opts, NULL, NULL, NULL, tests },
     894                 :            :                 { "raid0_dif", set_test_opts_dif, NULL, NULL, NULL, tests },
     895                 :            :                 CU_SUITE_INFO_NULL,
     896                 :            :         };
     897                 :            : 
     898                 :          4 :         CU_initialize_registry();
     899                 :          4 :         CU_register_suites(suites);
     900                 :            : 
     901                 :          4 :         allocate_threads(1);
     902                 :          4 :         set_thread(0);
     903                 :            : 
     904                 :          4 :         num_failures = spdk_ut_run_tests(argc, argv, NULL);
     905                 :          4 :         CU_cleanup_registry();
     906                 :            : 
     907                 :          4 :         free_threads();
     908                 :            : 
     909                 :          4 :         return num_failures;
     910                 :            : }

Generated by: LCOV version 1.14