LCOV - code coverage report
Current view: top level - spdk/lib/blob - zeroes.c (source / functions) Hit Total Coverage
Test: Combined Lines: 29 50 58.0 %
Date: 2024-11-18 19:48:35 Functions: 8 13 61.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 228 4.4 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2018 Intel Corporation.
       3                 :            :  *   All rights reserved.
       4                 :            :  *   Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
       5                 :            :  */
       6                 :            : 
       7                 :            : #include "spdk/stdinc.h"
       8                 :            : #include "spdk/blob.h"
       9                 :            : #include "spdk/dma.h"
      10                 :            : 
      11                 :            : #include "blobstore.h"
      12                 :            : 
      13                 :            : static void
      14                 :       1873 : zeroes_destroy(struct spdk_bs_dev *bs_dev)
      15                 :            : {
      16                 :       1873 :         return;
      17                 :            : }
      18                 :            : 
      19                 :            : static void
      20                 :        216 : zeroes_read(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, void *payload,
      21                 :            :             uint64_t lba, uint32_t lba_count, struct spdk_bs_dev_cb_args *cb_args)
      22                 :            : {
      23   [ -  +  #  #  :        216 :         memset(payload, 0, dev->blocklen * lba_count);
                   #  # ]
      24   [ #  #  #  #  :        216 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
      25                 :        216 : }
      26                 :            : 
      27                 :            : static void
      28                 :          0 : zeroes_write(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, void *payload,
      29                 :            :              uint64_t lba, uint32_t lba_count,
      30                 :            :              struct spdk_bs_dev_cb_args *cb_args)
      31                 :            : {
      32   [ #  #  #  #  :          0 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
      33         [ #  # ]:          0 :         assert(false);
      34                 :            : }
      35                 :            : 
      36                 :            : static void
      37                 :         48 : zeroes_readv(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
      38                 :            :              struct iovec *iov, int iovcnt,
      39                 :            :              uint64_t lba, uint32_t lba_count, struct spdk_bs_dev_cb_args *cb_args)
      40                 :            : {
      41                 :            :         int i;
      42                 :            : 
      43   [ +  +  #  # ]:        144 :         for (i = 0; i < iovcnt; i++) {
      44   [ -  +  #  #  :         96 :                 memset(iov[i].iov_base, 0, iov[i].iov_len);
          #  #  #  #  #  
             #  #  #  #  
                      # ]
      45                 :          0 :         }
      46                 :            : 
      47   [ #  #  #  #  :         48 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
      48                 :         48 : }
      49                 :            : 
      50                 :            : static void
      51                 :          0 : zeroes_writev(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
      52                 :            :               struct iovec *iov, int iovcnt,
      53                 :            :               uint64_t lba, uint32_t lba_count,
      54                 :            :               struct spdk_bs_dev_cb_args *cb_args)
      55                 :            : {
      56   [ #  #  #  #  :          0 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
      57         [ #  # ]:          0 :         assert(false);
      58                 :            : }
      59                 :            : 
      60                 :            : static void
      61                 :     722636 : _read_memory_domain_memzero_done(void *ctx, int rc)
      62                 :            : {
      63                 :     722636 :         struct spdk_bs_dev_cb_args *cb_args = (struct spdk_bs_dev_cb_args *)ctx;
      64                 :            : 
      65   [ #  #  #  #  :     722636 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, rc);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
      66                 :     722636 : }
      67                 :            : 
      68                 :            : static void
      69                 :     791189 : zeroes_readv_ext(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
      70                 :            :                  struct iovec *iov, int iovcnt,
      71                 :            :                  uint64_t lba, uint32_t lba_count, struct spdk_bs_dev_cb_args *cb_args,
      72                 :            :                  struct spdk_blob_ext_io_opts *ext_io_opts)
      73                 :            : {
      74                 :            :         int i, rc;
      75                 :            : 
      76   [ +  +  #  #  :     791189 :         if (ext_io_opts->memory_domain) {
                   #  # ]
      77   [ #  #  #  #  :     722636 :                 rc = spdk_memory_domain_memzero(ext_io_opts->memory_domain, ext_io_opts->memory_domain_ctx, iov,
             #  #  #  # ]
      78                 :          0 :                                                 iovcnt, _read_memory_domain_memzero_done, cb_args);
      79         [ -  + ]:     722636 :                 if (rc) {
      80   [ #  #  #  #  :          0 :                         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, rc);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
      81                 :          0 :                 }
      82                 :     722636 :                 return;
      83                 :            :         }
      84                 :            : 
      85   [ +  +  #  # ]:     548901 :         for (i = 0; i < iovcnt; i++) {
      86   [ -  +  #  #  :     480348 :                 memset(iov[i].iov_base, 0, iov[i].iov_len);
          #  #  #  #  #  
             #  #  #  #  
                      # ]
      87                 :          0 :         }
      88                 :            : 
      89   [ #  #  #  #  :      68553 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
      90                 :          0 : }
      91                 :            : 
      92                 :            : static void
      93                 :          0 : zeroes_writev_ext(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
      94                 :            :                   struct iovec *iov, int iovcnt,
      95                 :            :                   uint64_t lba, uint32_t lba_count,
      96                 :            :                   struct spdk_bs_dev_cb_args *cb_args,
      97                 :            :                   struct spdk_blob_ext_io_opts *ext_io_opts)
      98                 :            : {
      99   [ #  #  #  #  :          0 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     100         [ #  # ]:          0 :         assert(false);
     101                 :            : }
     102                 :            : 
     103                 :            : static void
     104                 :          0 : zeroes_write_zeroes(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
     105                 :            :                     uint64_t lba, uint64_t lba_count,
     106                 :            :                     struct spdk_bs_dev_cb_args *cb_args)
     107                 :            : {
     108   [ #  #  #  #  :          0 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     109         [ #  # ]:          0 :         assert(false);
     110                 :            : }
     111                 :            : 
     112                 :            : static void
     113                 :          0 : zeroes_unmap(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
     114                 :            :              uint64_t lba, uint64_t lba_count,
     115                 :            :              struct spdk_bs_dev_cb_args *cb_args)
     116                 :            : {
     117   [ #  #  #  #  :          0 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     118         [ #  # ]:          0 :         assert(false);
     119                 :            : }
     120                 :            : 
     121                 :            : static bool
     122                 :      22005 : zeroes_is_zeroes(struct spdk_bs_dev *dev, uint64_t lba, uint64_t lba_count)
     123                 :            : {
     124                 :      22005 :         return true;
     125                 :            : }
     126                 :            : 
     127                 :            : static bool
     128                 :       1815 : zeroes_translate_lba(struct spdk_bs_dev *dev, uint64_t lba, uint64_t *base_lba)
     129                 :            : {
     130                 :       1815 :         return false;
     131                 :            : }
     132                 :            : 
     133                 :            : static struct spdk_bs_dev g_zeroes_bs_dev = {
     134                 :            :         .blockcnt = UINT64_MAX,
     135                 :            :         .blocklen = 512,
     136                 :            :         .create_channel = NULL,
     137                 :            :         .destroy_channel = NULL,
     138                 :            :         .destroy = zeroes_destroy,
     139                 :            :         .read = zeroes_read,
     140                 :            :         .write = zeroes_write,
     141                 :            :         .readv = zeroes_readv,
     142                 :            :         .writev = zeroes_writev,
     143                 :            :         .readv_ext = zeroes_readv_ext,
     144                 :            :         .writev_ext = zeroes_writev_ext,
     145                 :            :         .write_zeroes = zeroes_write_zeroes,
     146                 :            :         .unmap = zeroes_unmap,
     147                 :            :         .is_zeroes = zeroes_is_zeroes,
     148                 :            :         .translate_lba = zeroes_translate_lba,
     149                 :            : };
     150                 :            : 
     151                 :            : struct spdk_bs_dev *
     152                 :       1873 : bs_create_zeroes_dev(void)
     153                 :            : {
     154                 :       1873 :         return &g_zeroes_bs_dev;
     155                 :            : }

Generated by: LCOV version 1.15