LCOV - code coverage report
Current view: top level - spdk/test/unit/lib/bdev/raid/raid1.c - raid1_ut.c (source / functions) Hit Total Coverage
Test: Combined Lines: 300 305 98.4 %
Date: 2024-07-15 22:46:19 Functions: 22 27 81.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 50 66 75.8 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2022 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/raid1.c"
      13                 :            : #include "../common.c"
      14                 :            : 
      15                 :            : static enum spdk_bdev_io_status g_io_status;
      16                 :            : static struct spdk_bdev_desc *g_last_io_desc;
      17                 :            : static spdk_bdev_io_completion_cb g_last_io_cb;
      18                 :            : 
      19                 :          3 : DEFINE_STUB_V(raid_bdev_module_list_add, (struct raid_bdev_module *raid_module));
      20                 :        144 : DEFINE_STUB_V(raid_bdev_module_stop_done, (struct raid_bdev *raid_bdev));
      21                 :        882 : DEFINE_STUB_V(spdk_bdev_free_io, (struct spdk_bdev_io *bdev_io));
      22                 :          0 : DEFINE_STUB_V(raid_bdev_queue_io_wait, (struct raid_bdev_io *raid_io, struct spdk_bdev *bdev,
      23                 :            :                                         struct spdk_io_channel *ch, spdk_bdev_io_wait_cb cb_fn));
      24                 :          0 : DEFINE_STUB_V(raid_bdev_process_request_complete, (struct raid_bdev_process_request *process_req,
      25                 :            :                 int status));
      26                 :          0 : DEFINE_STUB_V(raid_bdev_io_init, (struct raid_bdev_io *raid_io,
      27                 :            :                                   struct raid_bdev_io_channel *raid_ch,
      28                 :            :                                   enum spdk_bdev_io_type type, uint64_t offset_blocks,
      29                 :            :                                   uint64_t num_blocks, struct iovec *iovs, int iovcnt, void *md_buf,
      30                 :            :                                   struct spdk_memory_domain *memory_domain, void *memory_domain_ctx));
      31         [ #  # ]:          0 : DEFINE_STUB(raid_bdev_remap_dix_reftag, int, (void *md_buf, uint64_t num_blocks,
      32                 :            :                 struct spdk_bdev *bdev, uint32_t remapped_offset), -1);
      33                 :            : 
      34                 :            : int
      35                 :       4248 : spdk_bdev_readv_blocks_ext(struct spdk_bdev_desc *desc,
      36                 :            :                            struct spdk_io_channel *ch,
      37                 :            :                            struct iovec *iov, int iovcnt, uint64_t offset_blocks, uint64_t num_blocks,
      38                 :            :                            spdk_bdev_io_completion_cb cb, void *cb_arg, struct spdk_bdev_ext_io_opts *opts)
      39                 :            : {
      40                 :       4248 :         g_last_io_desc = desc;
      41                 :       4248 :         g_last_io_cb = cb;
      42                 :            : 
      43                 :       4248 :         return 0;
      44                 :            : }
      45                 :            : 
      46                 :            : int
      47                 :        432 : spdk_bdev_writev_blocks_ext(struct spdk_bdev_desc *desc,
      48                 :            :                             struct spdk_io_channel *ch,
      49                 :            :                             struct iovec *iov, int iovcnt, uint64_t offset_blocks, uint64_t num_blocks,
      50                 :            :                             spdk_bdev_io_completion_cb cb, void *cb_arg, struct spdk_bdev_ext_io_opts *opts)
      51                 :            : {
      52                 :        432 :         g_last_io_desc = desc;
      53                 :        432 :         g_last_io_cb = cb;
      54                 :            : 
      55                 :        432 :         return 0;
      56                 :            : }
      57                 :            : 
      58                 :            : void
      59                 :        270 : raid_bdev_fail_base_bdev(struct raid_base_bdev_info *base_info)
      60                 :            : {
      61                 :        270 :         base_info->is_failed = true;
      62                 :        270 : }
      63                 :            : 
      64                 :            : static int
      65                 :          3 : test_setup(void)
      66                 :            : {
      67                 :          3 :         uint8_t num_base_bdevs_values[] = { 2, 3 };
      68                 :          3 :         uint64_t base_bdev_blockcnt_values[] = { 1, 1024, 1024 * 1024 };
      69                 :          3 :         uint32_t base_bdev_blocklen_values[] = { 512, 4096 };
      70                 :            :         uint8_t *num_base_bdevs;
      71                 :            :         uint64_t *base_bdev_blockcnt;
      72                 :            :         uint32_t *base_bdev_blocklen;
      73                 :            :         uint64_t params_count;
      74                 :            :         int rc;
      75                 :            : 
      76                 :          3 :         params_count = SPDK_COUNTOF(num_base_bdevs_values) *
      77                 :            :                        SPDK_COUNTOF(base_bdev_blockcnt_values) *
      78                 :            :                        SPDK_COUNTOF(base_bdev_blocklen_values);
      79                 :          3 :         rc = raid_test_params_alloc(params_count);
      80         [ -  + ]:          3 :         if (rc) {
      81                 :          0 :                 return rc;
      82                 :            :         }
      83                 :            : 
      84         [ +  + ]:          9 :         ARRAY_FOR_EACH(num_base_bdevs_values, num_base_bdevs) {
      85         [ +  + ]:         24 :                 ARRAY_FOR_EACH(base_bdev_blockcnt_values, base_bdev_blockcnt) {
      86         [ +  + ]:         54 :                         ARRAY_FOR_EACH(base_bdev_blocklen_values, base_bdev_blocklen) {
      87                 :         36 :                                 struct raid_params params = {
      88                 :         36 :                                         .num_base_bdevs = *num_base_bdevs,
      89                 :         36 :                                         .base_bdev_blockcnt = *base_bdev_blockcnt,
      90                 :         36 :                                         .base_bdev_blocklen = *base_bdev_blocklen,
      91                 :            :                                 };
      92                 :         36 :                                 raid_test_params_add(&params);
      93                 :            :                         }
      94                 :            :                 }
      95                 :            :         }
      96                 :            : 
      97                 :          3 :         return 0;
      98                 :            : }
      99                 :            : 
     100                 :            : static int
     101                 :          3 : test_cleanup(void)
     102                 :            : {
     103                 :          3 :         raid_test_params_free();
     104                 :          3 :         return 0;
     105                 :            : }
     106                 :            : 
     107                 :            : static struct raid1_info *
     108                 :        144 : create_raid1(struct raid_params *params)
     109                 :            : {
     110                 :        144 :         struct raid_bdev *raid_bdev = raid_test_create_raid_bdev(params, &g_raid1_module);
     111                 :            : 
     112         [ -  + ]:        144 :         SPDK_CU_ASSERT_FATAL(raid1_start(raid_bdev) == 0);
     113                 :            : 
     114                 :        144 :         return raid_bdev->module_private;
     115                 :            : }
     116                 :            : 
     117                 :            : static void
     118                 :        144 : delete_raid1(struct raid1_info *r1_info)
     119                 :            : {
     120                 :        144 :         struct raid_bdev *raid_bdev = r1_info->raid_bdev;
     121                 :            : 
     122                 :        144 :         raid1_stop(raid_bdev);
     123                 :            : 
     124                 :        144 :         raid_test_delete_raid_bdev(raid_bdev);
     125                 :        144 : }
     126                 :            : 
     127                 :            : static void
     128                 :          3 : test_raid1_start(void)
     129                 :            : {
     130                 :            :         struct raid_params *params;
     131                 :            : 
     132         [ +  + ]:         39 :         RAID_PARAMS_FOR_EACH(params) {
     133                 :            :                 struct raid1_info *r1_info;
     134                 :            : 
     135                 :         36 :                 r1_info = create_raid1(params);
     136                 :            : 
     137         [ -  + ]:         36 :                 SPDK_CU_ASSERT_FATAL(r1_info != NULL);
     138                 :            : 
     139                 :         36 :                 CU_ASSERT_EQUAL(r1_info->raid_bdev->level, RAID1);
     140                 :         36 :                 CU_ASSERT_EQUAL(r1_info->raid_bdev->bdev.blockcnt, params->base_bdev_blockcnt);
     141                 :         36 :                 CU_ASSERT_PTR_EQUAL(r1_info->raid_bdev->module, &g_raid1_module);
     142                 :            : 
     143                 :         36 :                 delete_raid1(r1_info);
     144                 :            :         }
     145                 :          3 : }
     146                 :            : 
     147                 :            : static struct raid_bdev_io *
     148                 :       4122 : get_raid_io(struct raid1_info *r1_info, struct raid_bdev_io_channel *raid_ch,
     149                 :            :             enum spdk_bdev_io_type io_type, uint64_t num_blocks)
     150                 :            : {
     151                 :            :         struct raid_bdev_io *raid_io;
     152                 :            : 
     153                 :       4122 :         raid_io = calloc(1, sizeof(*raid_io));
     154         [ -  + ]:       4122 :         SPDK_CU_ASSERT_FATAL(raid_io != NULL);
     155                 :            : 
     156                 :       4122 :         raid_test_bdev_io_init(raid_io, r1_info->raid_bdev, raid_ch, io_type, 0, num_blocks, NULL, 0, NULL);
     157                 :            : 
     158                 :       4122 :         return raid_io;
     159                 :            : }
     160                 :            : 
     161                 :            : static void
     162                 :       4122 : put_raid_io(struct raid_bdev_io *raid_io)
     163                 :            : {
     164                 :       4122 :         free(raid_io);
     165                 :       4122 : }
     166                 :            : 
     167                 :            : void
     168                 :        324 : raid_test_bdev_io_complete(struct raid_bdev_io *raid_io, enum spdk_bdev_io_status status)
     169                 :            : {
     170                 :        324 :         g_io_status = status;
     171                 :            : 
     172                 :        324 :         put_raid_io(raid_io);
     173                 :        324 : }
     174                 :            : 
     175                 :            : static void
     176                 :          9 : run_for_each_raid1_config(void (*test_fn)(struct raid_bdev *raid_bdev,
     177                 :            :                           struct raid_bdev_io_channel *raid_ch))
     178                 :            : {
     179                 :            :         struct raid_params *params;
     180                 :            : 
     181         [ +  + ]:        117 :         RAID_PARAMS_FOR_EACH(params) {
     182                 :            :                 struct raid1_info *r1_info;
     183                 :            :                 struct raid_bdev_io_channel *raid_ch;
     184                 :            : 
     185                 :        108 :                 r1_info = create_raid1(params);
     186                 :        108 :                 raid_ch = raid_test_create_io_channel(r1_info->raid_bdev);
     187                 :            : 
     188                 :        108 :                 test_fn(r1_info->raid_bdev, raid_ch);
     189                 :            : 
     190                 :        108 :                 raid_test_destroy_io_channel(raid_ch);
     191                 :        108 :                 delete_raid1(r1_info);
     192                 :            :         }
     193                 :          9 : }
     194                 :            : 
     195                 :            : static void
     196                 :         36 : _test_raid1_read_balancing(struct raid_bdev *raid_bdev, struct raid_bdev_io_channel *raid_ch)
     197                 :            : {
     198                 :         36 :         struct raid1_info *r1_info = raid_bdev->module_private;
     199                 :         36 :         struct raid1_io_channel *raid1_ch = raid_bdev_channel_get_module_ctx(raid_ch);
     200                 :            :         uint8_t big_io_base_bdev_idx;
     201                 :         36 :         const uint64_t big_io_blocks = 256;
     202                 :         36 :         const uint64_t small_io_blocks = 4;
     203                 :            :         uint64_t blocks_remaining;
     204                 :            :         struct raid_bdev_io *raid_io;
     205                 :            :         uint8_t i;
     206                 :            :         int n;
     207                 :            : 
     208                 :            :         /* same sized IOs should be be spread evenly across all base bdevs */
     209         [ +  + ]:        144 :         for (n = 0; n < 3; n++) {
     210         [ +  + ]:        378 :                 for (i = 0; i < raid_bdev->num_base_bdevs; i++) {
     211                 :        270 :                         raid_io = get_raid_io(r1_info, raid_ch, SPDK_BDEV_IO_TYPE_READ, small_io_blocks);
     212                 :        270 :                         raid1_submit_read_request(raid_io);
     213                 :        270 :                         CU_ASSERT(raid_io->base_bdev_io_submitted == i);
     214                 :        270 :                         put_raid_io(raid_io);
     215                 :            :                 }
     216                 :            :         }
     217                 :            : 
     218         [ +  + ]:        126 :         for (i = 0; i < raid_bdev->num_base_bdevs; i++) {
     219                 :         90 :                 CU_ASSERT(raid1_ch->read_blocks_outstanding[i] == n * small_io_blocks);
     220                 :         90 :                 raid1_ch->read_blocks_outstanding[i] = 0;
     221                 :            :         }
     222                 :            : 
     223                 :            :         /*
     224                 :            :          * Submit one big and many small IOs. The small IOs should not land on the same base bdev
     225                 :            :          * as the big until the submitted block count is matched.
     226                 :            :          */
     227                 :         36 :         raid_io = get_raid_io(r1_info, raid_ch, SPDK_BDEV_IO_TYPE_READ, big_io_blocks);
     228                 :         36 :         raid1_submit_read_request(raid_io);
     229                 :         36 :         big_io_base_bdev_idx = raid_io->base_bdev_io_submitted;
     230                 :         36 :         put_raid_io(raid_io);
     231                 :            : 
     232                 :         36 :         blocks_remaining = big_io_blocks * (raid_bdev->num_base_bdevs - 1);
     233         [ +  + ]:       3492 :         while (blocks_remaining > 0) {
     234                 :       3456 :                 raid_io = get_raid_io(r1_info, raid_ch, SPDK_BDEV_IO_TYPE_READ, small_io_blocks);
     235                 :       3456 :                 raid1_submit_read_request(raid_io);
     236                 :       3456 :                 CU_ASSERT(raid_io->base_bdev_io_submitted != big_io_base_bdev_idx);
     237                 :       3456 :                 put_raid_io(raid_io);
     238                 :       3456 :                 blocks_remaining -= small_io_blocks;
     239                 :            :         }
     240                 :            : 
     241         [ +  + ]:        126 :         for (i = 0; i < raid_bdev->num_base_bdevs; i++) {
     242                 :         90 :                 CU_ASSERT(raid1_ch->read_blocks_outstanding[i] == big_io_blocks);
     243                 :            :         }
     244                 :            : 
     245                 :         36 :         raid_io = get_raid_io(r1_info, raid_ch, SPDK_BDEV_IO_TYPE_READ, small_io_blocks);
     246                 :         36 :         raid1_submit_read_request(raid_io);
     247                 :         36 :         CU_ASSERT(raid_io->base_bdev_io_submitted == big_io_base_bdev_idx);
     248                 :         36 :         put_raid_io(raid_io);
     249                 :         36 : }
     250                 :            : 
     251                 :            : static void
     252                 :          3 : test_raid1_read_balancing(void)
     253                 :            : {
     254                 :          3 :         run_for_each_raid1_config(_test_raid1_read_balancing);
     255                 :          3 : }
     256                 :            : 
     257                 :            : static void
     258                 :         36 : _test_raid1_write_error(struct raid_bdev *raid_bdev, struct raid_bdev_io_channel *raid_ch)
     259                 :            : {
     260                 :         36 :         struct raid1_info *r1_info = raid_bdev->module_private;
     261                 :            :         struct raid_bdev_io *raid_io;
     262                 :            :         struct raid_base_bdev_info *base_info;
     263                 :         36 :         struct spdk_bdev_io bdev_io = {};
     264                 :            :         bool bdev_io_success;
     265                 :            : 
     266                 :            :         /* first completion failed */
     267                 :         36 :         g_io_status = SPDK_BDEV_IO_STATUS_PENDING;
     268                 :         36 :         raid_io = get_raid_io(r1_info, raid_ch, SPDK_BDEV_IO_TYPE_WRITE, 64);
     269                 :         36 :         raid1_submit_write_request(raid_io);
     270                 :            : 
     271         [ +  + ]:        126 :         RAID_FOR_EACH_BASE_BDEV(raid_bdev, base_info) {
     272                 :         90 :                 base_info->is_failed = false;
     273         [ +  + ]:         90 :                 if (raid_bdev_base_bdev_slot(base_info) == 0) {
     274                 :         36 :                         bdev_io_success = false;
     275                 :            :                 } else {
     276                 :         54 :                         bdev_io_success = true;
     277                 :            :                 }
     278                 :         90 :                 bdev_io.bdev = base_info->desc->bdev;
     279                 :         90 :                 raid1_write_bdev_io_completion(&bdev_io, bdev_io_success, raid_io);
     280         [ -  + ]:         90 :                 CU_ASSERT(base_info->is_failed == !bdev_io_success);
     281                 :            :         }
     282                 :         36 :         CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_SUCCESS);
     283                 :            : 
     284                 :            :         /* all except first completion failed */
     285                 :         36 :         g_io_status = SPDK_BDEV_IO_STATUS_PENDING;
     286                 :         36 :         raid_io = get_raid_io(r1_info, raid_ch, SPDK_BDEV_IO_TYPE_WRITE, 64);
     287                 :         36 :         raid1_submit_write_request(raid_io);
     288                 :            : 
     289         [ +  + ]:        126 :         RAID_FOR_EACH_BASE_BDEV(raid_bdev, base_info) {
     290                 :         90 :                 base_info->is_failed = false;
     291         [ +  + ]:         90 :                 if (raid_bdev_base_bdev_slot(base_info) != 0) {
     292                 :         54 :                         bdev_io_success = false;
     293                 :            :                 } else {
     294                 :         36 :                         bdev_io_success = true;
     295                 :            :                 }
     296                 :         90 :                 bdev_io.bdev = base_info->desc->bdev;
     297                 :         90 :                 raid1_write_bdev_io_completion(&bdev_io, bdev_io_success, raid_io);
     298         [ -  + ]:         90 :                 CU_ASSERT(base_info->is_failed == !bdev_io_success);
     299                 :            :         }
     300                 :         36 :         CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_SUCCESS);
     301                 :            : 
     302                 :            :         /* all completions failed */
     303                 :         36 :         g_io_status = SPDK_BDEV_IO_STATUS_PENDING;
     304                 :         36 :         raid_io = get_raid_io(r1_info, raid_ch, SPDK_BDEV_IO_TYPE_WRITE, 64);
     305                 :         36 :         raid1_submit_write_request(raid_io);
     306                 :            : 
     307                 :         36 :         bdev_io_success = false;
     308         [ +  + ]:        126 :         RAID_FOR_EACH_BASE_BDEV(raid_bdev, base_info) {
     309                 :         90 :                 base_info->is_failed = false;
     310                 :         90 :                 bdev_io.bdev = base_info->desc->bdev;
     311                 :         90 :                 raid1_write_bdev_io_completion(&bdev_io, bdev_io_success, raid_io);
     312         [ -  + ]:         90 :                 CU_ASSERT(base_info->is_failed == !bdev_io_success);
     313                 :            :         }
     314                 :         36 :         CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_FAILED);
     315                 :         36 : }
     316                 :            : 
     317                 :            : static void
     318                 :          3 : test_raid1_write_error(void)
     319                 :            : {
     320                 :          3 :         run_for_each_raid1_config(_test_raid1_write_error);
     321                 :          3 : }
     322                 :            : 
     323                 :            : static void
     324                 :         36 : _test_raid1_read_error(struct raid_bdev *raid_bdev, struct raid_bdev_io_channel *raid_ch)
     325                 :            : {
     326                 :         36 :         struct raid1_info *r1_info = raid_bdev->module_private;
     327                 :         36 :         struct raid_base_bdev_info *base_info = &raid_bdev->base_bdev_info[0];
     328                 :         36 :         struct raid1_io_channel *raid1_ch = raid_bdev_channel_get_module_ctx(raid_ch);
     329                 :            :         struct raid_bdev_io *raid_io;
     330                 :         36 :         struct spdk_bdev_io bdev_io = {};
     331                 :            : 
     332                 :            :         /* first read fails, the second succeeds */
     333                 :         36 :         base_info->is_failed = false;
     334                 :         36 :         g_io_status = SPDK_BDEV_IO_STATUS_PENDING;
     335                 :         36 :         raid_io = get_raid_io(r1_info, raid_ch, SPDK_BDEV_IO_TYPE_READ, 64);
     336                 :         36 :         raid1_submit_read_request(raid_io);
     337                 :         36 :         CU_ASSERT(raid_io->base_bdev_io_submitted == 0);
     338                 :         36 :         CU_ASSERT(raid_io->base_bdev_io_remaining == 0);
     339                 :            : 
     340                 :         36 :         CU_ASSERT(g_last_io_desc == base_info->desc);
     341                 :         36 :         CU_ASSERT(g_last_io_cb == raid1_read_bdev_io_completion);
     342                 :         36 :         raid1_read_bdev_io_completion(&bdev_io, false, raid_io);
     343                 :         36 :         CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_PENDING);
     344                 :         36 :         CU_ASSERT((uint8_t)raid_io->base_bdev_io_remaining == (raid_bdev->num_base_bdevs - 1));
     345                 :            : 
     346                 :         36 :         CU_ASSERT(g_last_io_desc == raid_bdev->base_bdev_info[1].desc);
     347                 :         36 :         CU_ASSERT(g_last_io_cb == raid1_read_other_completion);
     348                 :         36 :         raid1_read_other_completion(&bdev_io, true, raid_io);
     349                 :         36 :         CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_PENDING);
     350                 :            : 
     351                 :         36 :         CU_ASSERT(g_last_io_desc == base_info->desc);
     352                 :         36 :         CU_ASSERT(g_last_io_cb == raid1_correct_read_error_completion);
     353                 :         36 :         raid1_correct_read_error_completion(&bdev_io, true, raid_io);
     354                 :         36 :         CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_SUCCESS);
     355         [ -  + ]:         36 :         CU_ASSERT(base_info->is_failed == false);
     356                 :            : 
     357                 :            :         /* rewrite fails */
     358                 :         36 :         base_info->is_failed = false;
     359                 :         36 :         g_io_status = SPDK_BDEV_IO_STATUS_PENDING;
     360                 :         36 :         raid_io = get_raid_io(r1_info, raid_ch, SPDK_BDEV_IO_TYPE_READ, 64);
     361                 :         36 :         raid1_submit_read_request(raid_io);
     362                 :         36 :         CU_ASSERT(raid_io->base_bdev_io_submitted == 0);
     363                 :         36 :         CU_ASSERT(raid_io->base_bdev_io_remaining == 0);
     364                 :            : 
     365                 :         36 :         CU_ASSERT(g_last_io_desc == base_info->desc);
     366                 :         36 :         CU_ASSERT(g_last_io_cb == raid1_read_bdev_io_completion);
     367                 :         36 :         raid1_read_bdev_io_completion(&bdev_io, false, raid_io);
     368                 :         36 :         CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_PENDING);
     369                 :         36 :         CU_ASSERT((uint8_t)raid_io->base_bdev_io_remaining == (raid_bdev->num_base_bdevs - 1));
     370                 :            : 
     371                 :         36 :         CU_ASSERT(g_last_io_desc == raid_bdev->base_bdev_info[1].desc);
     372                 :         36 :         CU_ASSERT(g_last_io_cb == raid1_read_other_completion);
     373                 :         36 :         raid1_read_other_completion(&bdev_io, true, raid_io);
     374                 :         36 :         CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_PENDING);
     375                 :            : 
     376                 :         36 :         CU_ASSERT(g_last_io_desc == base_info->desc);
     377                 :         36 :         CU_ASSERT(g_last_io_cb == raid1_correct_read_error_completion);
     378                 :         36 :         raid1_correct_read_error_completion(&bdev_io, false, raid_io);
     379                 :         36 :         CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_SUCCESS);
     380         [ -  + ]:         36 :         CU_ASSERT(base_info->is_failed == true);
     381                 :            : 
     382                 :            :         /* only the last read succeeds */
     383                 :         36 :         base_info->is_failed = false;
     384                 :         36 :         g_io_status = SPDK_BDEV_IO_STATUS_PENDING;
     385                 :         36 :         raid_io = get_raid_io(r1_info, raid_ch, SPDK_BDEV_IO_TYPE_READ, 64);
     386                 :         36 :         raid1_submit_read_request(raid_io);
     387                 :         36 :         CU_ASSERT(raid_io->base_bdev_io_submitted == 0);
     388                 :         36 :         CU_ASSERT(raid_io->base_bdev_io_remaining == 0);
     389                 :            : 
     390                 :         36 :         CU_ASSERT(g_last_io_desc == base_info->desc);
     391                 :         36 :         CU_ASSERT(g_last_io_cb == raid1_read_bdev_io_completion);
     392                 :         36 :         raid1_read_bdev_io_completion(&bdev_io, false, raid_io);
     393                 :         36 :         CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_PENDING);
     394                 :         36 :         CU_ASSERT((uint8_t)raid_io->base_bdev_io_remaining == (raid_bdev->num_base_bdevs - 1));
     395                 :            : 
     396         [ +  + ]:         54 :         while (raid_io->base_bdev_io_remaining > 1) {
     397                 :         18 :                 CU_ASSERT(g_last_io_cb == raid1_read_other_completion);
     398                 :         18 :                 raid1_read_other_completion(&bdev_io, false, raid_io);
     399                 :         18 :                 CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_PENDING);
     400                 :            :         }
     401                 :            : 
     402                 :         36 :         CU_ASSERT(g_last_io_desc == raid_bdev->base_bdev_info[raid_bdev->num_base_bdevs - 1].desc);
     403                 :         36 :         CU_ASSERT(g_last_io_cb == raid1_read_other_completion);
     404                 :         36 :         raid1_read_other_completion(&bdev_io, true, raid_io);
     405                 :         36 :         CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_PENDING);
     406                 :            : 
     407                 :         36 :         CU_ASSERT(g_last_io_desc == base_info->desc);
     408                 :         36 :         CU_ASSERT(g_last_io_cb == raid1_correct_read_error_completion);
     409                 :         36 :         raid1_correct_read_error_completion(&bdev_io, true, raid_io);
     410                 :         36 :         CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_SUCCESS);
     411         [ -  + ]:         36 :         CU_ASSERT(base_info->is_failed == false);
     412                 :            : 
     413                 :            :         /* all reads fail */
     414                 :         36 :         base_info->is_failed = false;
     415                 :         36 :         g_io_status = SPDK_BDEV_IO_STATUS_PENDING;
     416                 :         36 :         raid_io = get_raid_io(r1_info, raid_ch, SPDK_BDEV_IO_TYPE_READ, 64);
     417                 :         36 :         raid1_submit_read_request(raid_io);
     418                 :         36 :         CU_ASSERT(raid_io->base_bdev_io_submitted == 0);
     419                 :         36 :         CU_ASSERT(raid_io->base_bdev_io_remaining == 0);
     420                 :            : 
     421                 :         36 :         CU_ASSERT(g_last_io_desc == base_info->desc);
     422                 :         36 :         CU_ASSERT(g_last_io_cb == raid1_read_bdev_io_completion);
     423                 :         36 :         raid1_read_bdev_io_completion(&bdev_io, false, raid_io);
     424                 :         36 :         CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_PENDING);
     425                 :         36 :         CU_ASSERT((uint8_t)raid_io->base_bdev_io_remaining == (raid_bdev->num_base_bdevs - 1));
     426                 :            : 
     427         [ +  + ]:         54 :         while (raid_io->base_bdev_io_remaining > 1) {
     428                 :         18 :                 CU_ASSERT(g_last_io_cb == raid1_read_other_completion);
     429                 :         18 :                 raid1_read_other_completion(&bdev_io, false, raid_io);
     430                 :         18 :                 CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_PENDING);
     431                 :            :         }
     432                 :            : 
     433                 :         36 :         CU_ASSERT(g_last_io_desc == raid_bdev->base_bdev_info[raid_bdev->num_base_bdevs - 1].desc);
     434                 :         36 :         CU_ASSERT(g_last_io_cb == raid1_read_other_completion);
     435                 :         36 :         raid1_read_other_completion(&bdev_io, false, raid_io);
     436                 :         36 :         CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_FAILED);
     437         [ -  + ]:         36 :         CU_ASSERT(base_info->is_failed == true);
     438                 :            : 
     439                 :            :         /* read from base bdev #1 fails, read from #0 succeeds */
     440                 :         36 :         base_info->is_failed = false;
     441                 :         36 :         base_info = &raid_bdev->base_bdev_info[1];
     442                 :         36 :         raid1_ch->read_blocks_outstanding[0] = 123;
     443                 :         36 :         g_io_status = SPDK_BDEV_IO_STATUS_PENDING;
     444                 :         36 :         raid_io = get_raid_io(r1_info, raid_ch, SPDK_BDEV_IO_TYPE_READ, 64);
     445                 :         36 :         raid1_submit_read_request(raid_io);
     446                 :         36 :         CU_ASSERT(raid_io->base_bdev_io_submitted == 1);
     447                 :         36 :         CU_ASSERT(raid_io->base_bdev_io_remaining == 0);
     448                 :            : 
     449                 :         36 :         CU_ASSERT(g_last_io_desc == base_info->desc);
     450                 :         36 :         CU_ASSERT(g_last_io_cb == raid1_read_bdev_io_completion);
     451                 :         36 :         raid1_read_bdev_io_completion(&bdev_io, false, raid_io);
     452                 :         36 :         CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_PENDING);
     453                 :         36 :         CU_ASSERT((uint8_t)raid_io->base_bdev_io_remaining == raid_bdev->num_base_bdevs);
     454                 :            : 
     455                 :         36 :         CU_ASSERT(g_last_io_desc == raid_bdev->base_bdev_info[0].desc);
     456                 :         36 :         CU_ASSERT(g_last_io_cb == raid1_read_other_completion);
     457                 :         36 :         raid1_read_other_completion(&bdev_io, true, raid_io);
     458                 :         36 :         CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_PENDING);
     459                 :            : 
     460                 :         36 :         CU_ASSERT(g_last_io_desc == base_info->desc);
     461                 :         36 :         CU_ASSERT(g_last_io_cb == raid1_correct_read_error_completion);
     462                 :         36 :         raid1_correct_read_error_completion(&bdev_io, true, raid_io);
     463                 :         36 :         CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_SUCCESS);
     464         [ -  + ]:         36 :         CU_ASSERT(base_info->is_failed == false);
     465                 :            : 
     466                 :            :         /* base bdev #0 is failed, read from #1 fails, read from next succeeds if N > 2 */
     467                 :         36 :         base_info->is_failed = false;
     468                 :         36 :         raid_ch->_base_channels[0] = NULL;
     469                 :         36 :         g_io_status = SPDK_BDEV_IO_STATUS_PENDING;
     470                 :         36 :         raid_io = get_raid_io(r1_info, raid_ch, SPDK_BDEV_IO_TYPE_READ, 64);
     471                 :         36 :         raid1_submit_read_request(raid_io);
     472                 :         36 :         CU_ASSERT(raid_io->base_bdev_io_submitted == 1);
     473                 :         36 :         CU_ASSERT(raid_io->base_bdev_io_remaining == 0);
     474                 :            : 
     475                 :         36 :         CU_ASSERT(g_last_io_desc == base_info->desc);
     476                 :         36 :         CU_ASSERT(g_last_io_cb == raid1_read_bdev_io_completion);
     477                 :         36 :         raid1_read_bdev_io_completion(&bdev_io, false, raid_io);
     478         [ +  + ]:         36 :         if (raid_bdev->num_base_bdevs > 2) {
     479                 :         18 :                 CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_PENDING);
     480                 :         18 :                 CU_ASSERT((uint8_t)raid_io->base_bdev_io_remaining == (raid_bdev->num_base_bdevs - 2));
     481                 :            : 
     482                 :         18 :                 CU_ASSERT(g_last_io_desc == raid_bdev->base_bdev_info[2].desc);
     483                 :         18 :                 CU_ASSERT(g_last_io_cb == raid1_read_other_completion);
     484                 :         18 :                 raid1_read_other_completion(&bdev_io, true, raid_io);
     485                 :         18 :                 CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_PENDING);
     486                 :            : 
     487                 :         18 :                 CU_ASSERT(g_last_io_desc == base_info->desc);
     488                 :         18 :                 CU_ASSERT(g_last_io_cb == raid1_correct_read_error_completion);
     489                 :         18 :                 raid1_correct_read_error_completion(&bdev_io, true, raid_io);
     490                 :         18 :                 CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_SUCCESS);
     491         [ -  + ]:         18 :                 CU_ASSERT(base_info->is_failed == false);
     492                 :            :         } else {
     493                 :         18 :                 CU_ASSERT(g_io_status == SPDK_BDEV_IO_STATUS_FAILED);
     494         [ -  + ]:         18 :                 CU_ASSERT(base_info->is_failed == true);
     495                 :            :         }
     496                 :         36 : }
     497                 :            : 
     498                 :            : static void
     499                 :          3 : test_raid1_read_error(void)
     500                 :            : {
     501                 :          3 :         run_for_each_raid1_config(_test_raid1_read_error);
     502                 :          3 : }
     503                 :            : 
     504                 :            : int
     505                 :          3 : main(int argc, char **argv)
     506                 :            : {
     507                 :          3 :         CU_pSuite suite = NULL;
     508                 :            :         unsigned int num_failures;
     509                 :            : 
     510                 :          3 :         CU_initialize_registry();
     511                 :            : 
     512                 :          3 :         suite = CU_add_suite("raid1", test_setup, test_cleanup);
     513                 :          3 :         CU_ADD_TEST(suite, test_raid1_start);
     514                 :          3 :         CU_ADD_TEST(suite, test_raid1_read_balancing);
     515                 :          3 :         CU_ADD_TEST(suite, test_raid1_write_error);
     516                 :          3 :         CU_ADD_TEST(suite, test_raid1_read_error);
     517                 :            : 
     518                 :          3 :         allocate_threads(1);
     519                 :          3 :         set_thread(0);
     520                 :            : 
     521                 :          3 :         num_failures = spdk_ut_run_tests(argc, argv, NULL);
     522                 :          3 :         CU_cleanup_registry();
     523                 :            : 
     524                 :          3 :         free_threads();
     525                 :            : 
     526                 :          3 :         return num_failures;
     527                 :            : }

Generated by: LCOV version 1.14