LCOV - code coverage report
Current view: top level - spdk/lib/blob - zeroes.c (source / functions) Hit Total Coverage
Test: Combined Lines: 31 52 59.6 %
Date: 2024-12-15 14:56:52 Functions: 8 13 61.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 37 230 16.1 %

           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                 :       3541 : zeroes_destroy(struct spdk_bs_dev *bs_dev)
      15                 :            : {
      16                 :       3541 :         return;
      17                 :            : }
      18                 :            : 
      19                 :            : static void
      20                 :        432 : 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   [ +  +  +  -  :        432 :         memset(payload, 0, dev->blocklen * lba_count);
                   +  - ]
      24   [ +  -  +  -  :        432 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0);
          -  +  +  -  +  
          -  +  -  +  -  
                   +  - ]
      25                 :        432 : }
      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                 :         96 : 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                 :         16 :         int i;
      42                 :            : 
      43   [ +  +  +  - ]:        288 :         for (i = 0; i < iovcnt; i++) {
      44   [ +  +  +  -  :        192 :                 memset(iov[i].iov_base, 0, iov[i].iov_len);
          +  -  +  -  +  
             -  +  -  +  
                      - ]
      45                 :         32 :         }
      46                 :            : 
      47   [ +  -  +  -  :         96 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0);
          -  +  +  -  +  
          -  +  -  +  -  
                   +  - ]
      48                 :         96 : }
      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                 :     724169 : _read_memory_domain_memzero_done(void *ctx, int rc)
      62                 :            : {
      63                 :     724169 :         struct spdk_bs_dev_cb_args *cb_args = (struct spdk_bs_dev_cb_args *)ctx;
      64                 :            : 
      65   [ #  #  #  #  :     724169 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, rc);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
      66                 :     724169 : }
      67                 :            : 
      68                 :            : static void
      69                 :     805429 : 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                 :          0 :         int i, rc;
      75                 :            : 
      76   [ +  +  #  #  :     805429 :         if (ext_io_opts->memory_domain) {
                   #  # ]
      77   [ #  #  #  #  :     724169 :                 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         [ -  + ]:     724169 :                 if (rc) {
      80   [ #  #  #  #  :          0 :                         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, rc);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
      81                 :          0 :                 }
      82                 :     724169 :                 return;
      83                 :            :         }
      84                 :            : 
      85   [ +  +  #  # ]:     250444 :         for (i = 0; i < iovcnt; i++) {
      86   [ -  +  #  #  :     169184 :                 memset(iov[i].iov_base, 0, iov[i].iov_len);
          #  #  #  #  #  
             #  #  #  #  
                      # ]
      87                 :          0 :         }
      88                 :            : 
      89   [ #  #  #  #  :      81260 :         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                 :      36651 : zeroes_is_zeroes(struct spdk_bs_dev *dev, uint64_t lba, uint64_t lba_count)
     123                 :            : {
     124                 :      36651 :         return true;
     125                 :            : }
     126                 :            : 
     127                 :            : static bool
     128                 :       2283 : zeroes_translate_lba(struct spdk_bs_dev *dev, uint64_t lba, uint64_t *base_lba)
     129                 :            : {
     130                 :       2283 :         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                 :       3541 : bs_create_zeroes_dev(void)
     153                 :            : {
     154                 :       3541 :         return &g_zeroes_bs_dev;
     155                 :            : }

Generated by: LCOV version 1.14