LCOV - code coverage report
Current view: top level - spdk/lib/blob - blob_bs_dev.c (source / functions) Hit Total Coverage
Test: Combined Lines: 78 97 80.4 %
Date: 2024-12-13 14:26:56 Functions: 10 15 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 129 346 37.3 %

           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/log.h"
      10                 :            : #include "blobstore.h"
      11                 :            : 
      12                 :            : static void
      13                 :          0 : blob_bs_dev_write(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, void *payload,
      14                 :            :                   uint64_t lba, uint32_t lba_count,
      15                 :            :                   struct spdk_bs_dev_cb_args *cb_args)
      16                 :            : {
      17   [ #  #  #  #  :          0 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
      18         [ #  # ]:          0 :         assert(false);
      19                 :            : }
      20                 :            : 
      21                 :            : static void
      22                 :          0 : blob_bs_dev_writev(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
      23                 :            :                    struct iovec *iov, int iovcnt,
      24                 :            :                    uint64_t lba, uint32_t lba_count,
      25                 :            :                    struct spdk_bs_dev_cb_args *cb_args)
      26                 :            : {
      27   [ #  #  #  #  :          0 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
      28         [ #  # ]:          0 :         assert(false);
      29                 :            : }
      30                 :            : 
      31                 :            : static void
      32                 :          0 : blob_bs_dev_writev_ext(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
      33                 :            :                        struct iovec *iov, int iovcnt,
      34                 :            :                        uint64_t lba, uint32_t lba_count,
      35                 :            :                        struct spdk_bs_dev_cb_args *cb_args,
      36                 :            :                        struct spdk_blob_ext_io_opts *ext_opts)
      37                 :            : {
      38   [ #  #  #  #  :          0 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
      39         [ #  # ]:          0 :         assert(false);
      40                 :            : }
      41                 :            : 
      42                 :            : static void
      43                 :          0 : blob_bs_dev_write_zeroes(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
      44                 :            :                          uint64_t lba, uint64_t lba_count,
      45                 :            :                          struct spdk_bs_dev_cb_args *cb_args)
      46                 :            : {
      47   [ #  #  #  #  :          0 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
      48         [ #  # ]:          0 :         assert(false);
      49                 :            : }
      50                 :            : 
      51                 :            : static void
      52                 :          0 : blob_bs_dev_unmap(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
      53                 :            :                   uint64_t lba, uint64_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                 :      25061 : blob_bs_dev_read_cpl(void *cb_arg, int bserrno)
      62                 :            : {
      63                 :      25061 :         struct spdk_bs_dev_cb_args *cb_args = (struct spdk_bs_dev_cb_args *)cb_arg;
      64                 :            : 
      65   [ +  -  +  -  :      25061 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, bserrno);
          -  +  +  -  +  
          -  +  -  +  -  
                   +  - ]
      66                 :      25061 : }
      67                 :            : 
      68                 :            : static inline void
      69                 :       1685 : blob_bs_dev_read(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, void *payload,
      70                 :            :                  uint64_t lba, uint32_t lba_count, struct spdk_bs_dev_cb_args *cb_args)
      71                 :            : {
      72                 :       1685 :         struct spdk_blob_bs_dev *b = (struct spdk_blob_bs_dev *)dev;
      73                 :            : 
      74   [ +  -  +  - ]:       1685 :         spdk_blob_io_read(b->blob, channel, payload, lba, lba_count,
      75                 :        272 :                           blob_bs_dev_read_cpl, cb_args);
      76                 :       1685 : }
      77                 :            : 
      78                 :            : static inline void
      79                 :        480 : blob_bs_dev_readv(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
      80                 :            :                   struct iovec *iov, int iovcnt,
      81                 :            :                   uint64_t lba, uint32_t lba_count, struct spdk_bs_dev_cb_args *cb_args)
      82                 :            : {
      83                 :        480 :         struct spdk_blob_bs_dev *b = (struct spdk_blob_bs_dev *)dev;
      84                 :            : 
      85   [ +  -  +  - ]:        480 :         spdk_blob_io_readv(b->blob, channel, iov, iovcnt, lba, lba_count,
      86                 :         80 :                            blob_bs_dev_read_cpl, cb_args);
      87                 :        480 : }
      88                 :            : 
      89                 :            : static inline void
      90                 :      22896 : blob_bs_dev_readv_ext(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
      91                 :            :                       struct iovec *iov, int iovcnt,
      92                 :            :                       uint64_t lba, uint32_t lba_count, struct spdk_bs_dev_cb_args *cb_args,
      93                 :            :                       struct spdk_blob_ext_io_opts *ext_opts)
      94                 :            : {
      95                 :      22896 :         struct spdk_blob_bs_dev *b = (struct spdk_blob_bs_dev *)dev;
      96                 :            : 
      97   [ +  -  +  - ]:      22896 :         spdk_blob_io_readv_ext(b->blob, channel, iov, iovcnt, lba, lba_count,
      98                 :         72 :                                blob_bs_dev_read_cpl, cb_args, ext_opts);
      99                 :      22896 : }
     100                 :            : 
     101                 :            : static void
     102                 :       3710 : blob_bs_dev_destroy_cpl(void *cb_arg, int bserrno)
     103                 :            : {
     104         [ -  + ]:       3710 :         if (bserrno != 0) {
     105                 :          0 :                 SPDK_ERRLOG("Error on blob_bs_dev destroy: %d", bserrno);
     106                 :          0 :         }
     107                 :            : 
     108                 :            :         /* Free blob_bs_dev */
     109                 :       3710 :         free(cb_arg);
     110                 :       3710 : }
     111                 :            : 
     112                 :            : static void
     113                 :       3710 : blob_bs_dev_destroy(struct spdk_bs_dev *bs_dev)
     114                 :            : {
     115                 :       3710 :         struct spdk_blob_bs_dev *b = (struct spdk_blob_bs_dev *)bs_dev;
     116                 :            : 
     117   [ +  -  +  - ]:       3710 :         spdk_blob_close(b->blob, blob_bs_dev_destroy_cpl, b);
     118                 :       3710 : }
     119                 :            : 
     120                 :            : static bool
     121                 :       2265 : blob_bs_is_zeroes(struct spdk_bs_dev *dev, uint64_t lba, uint64_t lba_count)
     122                 :            : {
     123                 :       2265 :         struct spdk_blob_bs_dev *b = (struct spdk_blob_bs_dev *)dev;
     124   [ +  -  +  - ]:       2265 :         struct spdk_blob *blob = b->blob;
     125                 :            : 
     126   [ +  +  +  -  :       2265 :         assert(lba == bs_cluster_to_lba(blob->bs, bs_lba_to_cluster(blob->bs, lba)));
          +  -  +  -  +  
                -  #  # ]
     127   [ +  +  +  -  :       2265 :         assert(lba_count == bs_dev_byte_to_lba(dev, blob->bs->cluster_sz));
          +  -  +  -  +  
                -  #  # ]
     128                 :            : 
     129         [ +  + ]:       2265 :         if (bs_io_unit_is_allocated(blob, lba)) {
     130                 :       1397 :                 return false;
     131                 :            :         }
     132                 :            : 
     133   [ +  +  +  -  :        868 :         assert(blob->back_bs_dev != NULL);
             +  -  #  # ]
     134   [ +  -  +  -  :        868 :         return blob->back_bs_dev->is_zeroes(blob->back_bs_dev,
          +  -  +  -  -  
          +  +  -  +  -  
                   +  - ]
     135                 :        144 :                                             bs_io_unit_to_back_dev_lba(blob, lba),
     136                 :        144 :                                             bs_io_unit_to_back_dev_lba(blob, lba_count));
     137                 :        360 : }
     138                 :            : 
     139                 :            : static bool
     140                 :       1132 : blob_bs_translate_lba(struct spdk_bs_dev *dev, uint64_t lba, uint64_t *base_lba)
     141                 :            : {
     142                 :       1132 :         struct spdk_blob_bs_dev *b = (struct spdk_blob_bs_dev *)dev;
     143   [ +  -  +  - ]:       1132 :         struct spdk_blob *blob = b->blob;
     144                 :            : 
     145   [ +  +  #  # ]:       1132 :         assert(base_lba != NULL);
     146         [ +  + ]:       1132 :         if (bs_io_unit_is_allocated(blob, lba)) {
     147         [ +  - ]:        696 :                 *base_lba = bs_blob_io_unit_to_lba(blob, lba);
     148                 :        696 :                 return true;
     149                 :            :         }
     150                 :            : 
     151   [ +  +  +  -  :        436 :         assert(blob->back_bs_dev != NULL);
             +  -  #  # ]
     152   [ +  -  +  -  :        436 :         return blob->back_bs_dev->translate_lba(blob->back_bs_dev,
          +  -  +  -  -  
          +  +  -  +  -  
                   +  - ]
     153                 :         72 :                                                 bs_io_unit_to_back_dev_lba(blob, lba),
     154                 :         72 :                                                 base_lba);
     155                 :        180 : }
     156                 :            : 
     157                 :            : static bool
     158                 :         89 : blob_bs_is_degraded(struct spdk_bs_dev *dev)
     159                 :            : {
     160                 :         89 :         struct spdk_blob_bs_dev *b = (struct spdk_blob_bs_dev *)dev;
     161                 :            : 
     162   [ #  #  #  # ]:         89 :         return spdk_blob_is_degraded(b->blob);
     163                 :          0 : }
     164                 :            : 
     165                 :            : struct spdk_bs_dev *
     166                 :       3710 : bs_create_blob_bs_dev(struct spdk_blob *blob)
     167                 :            : {
     168                 :        592 :         struct spdk_blob_bs_dev  *b;
     169                 :            : 
     170                 :       3710 :         b = calloc(1, sizeof(*b));
     171         [ +  + ]:       3710 :         if (b == NULL) {
     172                 :          0 :                 return NULL;
     173                 :            :         }
     174                 :            :         /* snapshot blob */
     175   [ +  -  +  -  :       8012 :         b->bs_dev.blockcnt = blob->active.num_clusters *
          +  -  +  -  +  
                -  +  - ]
     176   [ +  -  +  -  :       3710 :                              blob->bs->pages_per_cluster * bs_io_unit_per_page(blob->bs);
          +  -  +  -  +  
             -  +  -  +  
                      - ]
     177   [ +  -  +  -  :       3710 :         b->bs_dev.blocklen = spdk_bs_get_io_unit_size(blob->bs);
          +  -  +  -  +  
                      - ]
     178   [ +  -  +  -  :       3710 :         b->bs_dev.create_channel = NULL;
                   +  - ]
     179   [ +  -  +  -  :       3710 :         b->bs_dev.destroy_channel = NULL;
                   +  - ]
     180   [ +  -  +  -  :       3710 :         b->bs_dev.destroy = blob_bs_dev_destroy;
                   +  - ]
     181   [ +  -  +  -  :       3710 :         b->bs_dev.write = blob_bs_dev_write;
                   +  - ]
     182   [ +  -  +  -  :       3710 :         b->bs_dev.writev = blob_bs_dev_writev;
                   +  - ]
     183   [ +  -  +  -  :       3710 :         b->bs_dev.writev_ext = blob_bs_dev_writev_ext;
                   +  - ]
     184   [ +  -  +  -  :       3710 :         b->bs_dev.read = blob_bs_dev_read;
                   +  - ]
     185   [ +  -  +  -  :       3710 :         b->bs_dev.readv = blob_bs_dev_readv;
                   +  - ]
     186   [ +  -  +  -  :       3710 :         b->bs_dev.readv_ext = blob_bs_dev_readv_ext;
                   +  - ]
     187   [ +  -  +  -  :       3710 :         b->bs_dev.write_zeroes = blob_bs_dev_write_zeroes;
                   +  - ]
     188   [ +  -  +  -  :       3710 :         b->bs_dev.unmap = blob_bs_dev_unmap;
                   +  - ]
     189   [ +  -  +  -  :       3710 :         b->bs_dev.is_zeroes = blob_bs_is_zeroes;
                   +  - ]
     190   [ +  -  +  -  :       3710 :         b->bs_dev.translate_lba = blob_bs_translate_lba;
                   +  - ]
     191   [ +  -  +  -  :       3710 :         b->bs_dev.is_degraded = blob_bs_is_degraded;
                   +  - ]
     192   [ +  -  +  - ]:       3710 :         b->blob = blob;
     193                 :            : 
     194         [ +  - ]:       3710 :         return &b->bs_dev;
     195                 :        592 : }

Generated by: LCOV version 1.15