Skip to content

Commit

Permalink
Sprinkle in some const (#589)
Browse files Browse the repository at this point in the history
Signed-off-by: Tristan Partin <[email protected]>
  • Loading branch information
tristan957 authored Jan 19, 2023
1 parent 9f4baf2 commit 156c6f9
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 37 deletions.
28 changes: 14 additions & 14 deletions lib/cn/kvset.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 */
/*
* Copyright (C) 2015-2022 Micron Technology, Inc. All rights reserved.
* Copyright (C) 2015-2023 Micron Technology, Inc. All rights reserved.
*/

#include <stdint.h>
Expand Down Expand Up @@ -115,27 +115,27 @@ static struct kmem_cache *kvset_iter_cache HSE_READ_MOSTLY;
* from a logical vblock index.
*/
static HSE_ALWAYS_INLINE struct mbset *
lvx2mbs(struct kvset *ks, uint i)
lvx2mbs(const struct kvset *ks, uint i)
{
return ks->ks_vblk2mbs[i].mbs;
}

static HSE_ALWAYS_INLINE uint
lvx2mbs_bnum(struct kvset *ks, uint i)
lvx2mbs_bnum(const struct kvset *ks, uint i)
{
return ks->ks_vblk2mbs[i].idx;
}

/* Map logical vblock index (as stored in KMD) to an mblock ID */
static HSE_ALWAYS_INLINE uint64_t
lvx2mbid(struct kvset *ks, uint i)
lvx2mbid(const struct kvset *ks, uint i)
{
return mbset_get_mbid(lvx2mbs(ks, i), lvx2mbs_bnum(ks, i));
}

/* Map logical vblock index (as stored in KMD) to a vblock descriptor */
static HSE_ALWAYS_INLINE struct vblock_desc *
lvx2vbd(struct kvset *ks, uint i)
lvx2vbd(const struct kvset *ks, uint i)
{
return mbset_get_udata(lvx2mbs(ks, i), lvx2mbs_bnum(ks, i));
}
Expand All @@ -161,7 +161,7 @@ kvset_put_ref_final(struct kvset *ks)
*/
for (tries = 0; tries < maxtries; ++tries) {
for (i = 0; i < ks->ks_st.kst_vblks; ++i) {
struct vblock_desc *vbd = lvx2vbd(ks, i);
const struct vblock_desc *vbd = lvx2vbd(ks, i);

if (atomic_read(&vbd->vbd_refcnt) > 0)
break;
Expand Down Expand Up @@ -1233,7 +1233,7 @@ extern const size_t tls_vbufsz;
static merr_t
kvset_lookup_val_direct(
struct kvset * ks,
struct vblock_desc *vbd,
const struct vblock_desc *vbd,
uint16_t vbidx,
uint32_t vboff,
void * vbuf,
Expand Down Expand Up @@ -1299,7 +1299,7 @@ kvset_lookup_val_direct(
static merr_t
kvset_lookup_val_direct_decompress(
struct kvset *ks,
struct vblock_desc *vbd,
const struct vblock_desc *vbd,
uint16_t vbidx,
uint32_t vboff,
void *vbuf,
Expand Down Expand Up @@ -1350,7 +1350,7 @@ static
merr_t
kvset_lookup_val(struct kvset *ks, struct kvs_vtuple_ref *vref, struct kvs_buf *vbuf)
{
struct vblock_desc *vbd;
const struct vblock_desc *vbd;
merr_t err;
void *src, *dst;
uint omlen, copylen;
Expand Down Expand Up @@ -1775,23 +1775,23 @@ kvset_get_nth_vblock_id(struct kvset *ks, uint32_t index)
}

uint32_t
kvset_get_nth_vblock_alen(struct kvset *ks, uint32_t index)
kvset_get_nth_vblock_alen(const struct kvset *ks, uint32_t index)
{
const struct vblock_desc *vbd = lvx2vbd(ks, index);

return vbd ? vbd->vbd_alen : 0;
}

uint32_t
kvset_get_nth_vblock_wlen(struct kvset *ks, uint32_t index)
kvset_get_nth_vblock_wlen(const struct kvset *ks, uint32_t index)
{
const struct vblock_desc *vbd = lvx2vbd(ks, index);

return vbd ? vbd->vbd_wlen : 0;
}

struct vblock_desc *
kvset_get_nth_vblock_desc(struct kvset *ks, uint32_t index)
kvset_get_nth_vblock_desc(const struct kvset *ks, uint32_t index)
{
return lvx2vbd(ks, index);
}
Expand Down Expand Up @@ -3288,7 +3288,7 @@ kvset_iter_get_valptr_read(
const void ** vdata)
{
merr_t err;
struct vblock_desc * vbd;
const struct vblock_desc *vbd;
struct vblk_reader * vr;
struct vr_buf * active;
struct cn_merge_stats *ms = iter->stats;
Expand Down Expand Up @@ -3374,7 +3374,7 @@ kvset_iter_get_valptr_read(
off = active->off + active->len;

if (off >= vr->vr_mblk_dlen) {
struct vblock_desc *ra_vbd;
const struct vblock_desc *ra_vbd;

off = 0;
vbidx++;
Expand Down
8 changes: 4 additions & 4 deletions lib/cn/kvset.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 */
/*
* Copyright (C) 2015-2022 Micron Technology, Inc. All rights reserved.
* Copyright (C) 2015-2023 Micron Technology, Inc. All rights reserved.
*/

#ifndef HSE_KVS_CN_KVSET_H
Expand Down Expand Up @@ -355,14 +355,14 @@ kvset_set_rule(struct kvset *ks, enum cn_rule rule);
*/
/* MTF_MOCK */
uint32_t
kvset_get_nth_vblock_alen(struct kvset *km, uint32_t index);
kvset_get_nth_vblock_alen(const struct kvset *km, uint32_t index);

/**
* Get written length of useful data in nth vblock
*/
/* MTF_MOCK */
uint32_t
kvset_get_nth_vblock_wlen(struct kvset *km, uint32_t index);
kvset_get_nth_vblock_wlen(const struct kvset *km, uint32_t index);

/* MTF_MOCK */
void
Expand Down Expand Up @@ -403,7 +403,7 @@ struct cn_tree *
kvset_get_tree(struct kvset *kvset);

struct vblock_desc *
kvset_get_nth_vblock_desc(struct kvset *ks, uint32_t index);
kvset_get_nth_vblock_desc(const struct kvset *ks, uint32_t index);

/* MTF_MOCK */
void
Expand Down
6 changes: 3 additions & 3 deletions lib/cn/kvset_split.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 */
/*
* Copyright (C) 2022 Micron Technology, Inc. All rights reserved.
* Copyright (C) 2022-2023 Micron Technology, Inc. All rights reserved.
*/

#include <sys/mman.h>
Expand Down Expand Up @@ -428,7 +428,7 @@ get_vblk_split_index(

for (v = start; v <= end; v++) {
struct key_obj min_key = { 0 };
struct vblock_desc *vbd = kvset_get_nth_vblock_desc(ks, v);
const struct vblock_desc *vbd = kvset_get_nth_vblock_desc(ks, v);

key2kobj(&min_key, vbd->vbd_mblkdesc->map_base + vbd->vbd_min_koff, vbd->vbd_min_klen);

Expand All @@ -438,7 +438,7 @@ get_vblk_split_index(

if (v > start) {
struct key_obj max_key = { 0 };
struct vblock_desc *vbd = kvset_get_nth_vblock_desc(ks, v - 1);
const struct vblock_desc *vbd = kvset_get_nth_vblock_desc(ks, v - 1);

key2kobj(&max_key, vbd->vbd_mblkdesc->map_base + vbd->vbd_max_koff, vbd->vbd_max_klen);

Expand Down
14 changes: 7 additions & 7 deletions lib/cn/mbset.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 */
/*
* Copyright (C) 2015-2022 Micron Technology, Inc. All rights reserved.
* Copyright (C) 2015-2023 Micron Technology, Inc. All rights reserved.
*/

#ifndef HSE_KVDB_CN_MBSET_H
Expand Down Expand Up @@ -74,25 +74,25 @@ void
mbset_set_delete_flag(struct mbset *self);

static HSE_ALWAYS_INLINE struct mpool *
mbset_get_mp(struct mbset *self)
mbset_get_mp(const struct mbset *self)
{
return self->mbs_mp;
}

static HSE_ALWAYS_INLINE uint64_t
mbset_get_wlen(struct mbset *self)
mbset_get_wlen(const struct mbset *self)
{
return self->mbs_wlen;
}

static HSE_ALWAYS_INLINE uint64_t
mbset_get_alen(struct mbset *self)
mbset_get_alen(const struct mbset *self)
{
return self->mbs_alen;
}

static HSE_ALWAYS_INLINE uint64_t
mbset_get_mbid(struct mbset *self, uint blk_num)
mbset_get_mbid(const struct mbset *self, uint blk_num)
{
bool valid = blk_num < self->mbs_mblkc;

Expand All @@ -101,13 +101,13 @@ mbset_get_mbid(struct mbset *self, uint blk_num)
}

static HSE_ALWAYS_INLINE uint
mbset_get_blkc(struct mbset *self)
mbset_get_blkc(const struct mbset *self)
{
return self->mbs_mblkc;
}

static HSE_ALWAYS_INLINE void *
mbset_get_udata(struct mbset *self, uint blk_num)
mbset_get_udata(const struct mbset *self, uint blk_num)
{
bool valid = blk_num < self->mbs_mblkc;

Expand Down
8 changes: 4 additions & 4 deletions lib/cn/vblock_reader.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 */
/*
* Copyright (C) 2015-2022 Micron Technology, Inc. All rights reserved.
* Copyright (C) 2015-2023 Micron Technology, Inc. All rights reserved.
*/

#include <stdint.h>
Expand Down Expand Up @@ -195,7 +195,7 @@ vbr_madvise_async_cb(struct work_struct *work)

bool
vbr_madvise_async(
struct vblock_desc * vbd,
struct vblock_desc *vbd,
uint off,
uint len,
int advice,
Expand All @@ -222,14 +222,14 @@ vbr_madvise_async(
}

void
vbr_madvise(struct vblock_desc *vbd, uint off, uint len, int advice)
vbr_madvise(const struct vblock_desc *vbd, uint off, uint len, int advice)
{
mblk_madvise_pages(vbd->vbd_mblkdesc, off / PAGE_SIZE, len / PAGE_SIZE, advice);
}

/* off, len version */
void *
vbr_value(struct vblock_desc *vbd, uint vboff, uint vlen)
vbr_value(const struct vblock_desc *vbd, uint vboff, uint vlen)
{
assert(vbd->vbd_mblkdesc->map_base);
assert(vboff + vlen <= vbd->vbd_wlen);
Expand Down
6 changes: 3 additions & 3 deletions lib/cn/vblock_reader.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 */
/*
* Copyright (C) 2015-2022 Micron Technology, Inc. All rights reserved.
* Copyright (C) 2015-2023 Micron Technology, Inc. All rights reserved.
*/

#ifndef HSE_KVS_CN_VBLOCK_READER_H
Expand Down Expand Up @@ -113,7 +113,7 @@ vbr_readahead(
* @vbd: vblock descriptor
*/
void
vbr_madvise(struct vblock_desc *vbd, uint off, uint len, int advice);
vbr_madvise(const struct vblock_desc *vbd, uint off, uint len, int advice);

/**
* vbr_value() - Get ptr to a value stored in a vblock
Expand All @@ -122,6 +122,6 @@ vbr_madvise(struct vblock_desc *vbd, uint off, uint len, int advice);
* @vlen: length of value
*/
void *
vbr_value(struct vblock_desc *vbd, uint vboff, uint vlen);
vbr_value(const struct vblock_desc *vbd, uint vboff, uint vlen);

#endif
4 changes: 2 additions & 2 deletions tests/mocks/repository/lib/mock_kvset.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ _kvset_get_nth_vblock_id(struct kvset *kvset, uint32_t index)
}

static uint32_t
_kvset_get_nth_vblock_alen(struct kvset *kvset, uint32_t index)
_kvset_get_nth_vblock_alen(const struct kvset *kvset, uint32_t index)
{
/* In the event mpool_mblock_punch() or mpool_mblock_clone() gets mocked,
* this should more than likely change since those seem to be the only 2
Expand All @@ -377,7 +377,7 @@ _kvset_get_nth_vblock_alen(struct kvset *kvset, uint32_t index)
}

static uint32_t
_kvset_get_nth_vblock_wlen(struct kvset *kvset, uint32_t index)
_kvset_get_nth_vblock_wlen(const struct kvset *kvset, uint32_t index)
{
struct mock_kvset *mk = (void *)kvset;
struct kvdata * iterv = mk->iter_data;
Expand Down

0 comments on commit 156c6f9

Please sign in to comment.