Commit b46d79bd authored by Matthew Sakai's avatar Matthew Sakai Committed by Mike Snitzer

dm vdo: add deduplication index storage interface

This patch adds infrastructure for managing reads and writes to the
underlying storage layer for the deduplication index. The deduplication
index uses dm-bufio for all of its reads and writes, so part of this
infrastructure is managing the various dm-bufio clients required. It also
adds the buffered reader and buffered writer abstractions, which simplify
reading and writing metadata structures that span several blocks.

This patch also includes structures and utilities for encoding and decoding
all of the deduplication index metadata, collectively called the index
layout.
Co-developed-by: default avatarJ. corwin Coburn <corwin@hurlbutnet.net>
Signed-off-by: default avatarJ. corwin Coburn <corwin@hurlbutnet.net>
Co-developed-by: default avatarMichael Sclafani <dm-devel@lists.linux.dev>
Signed-off-by: default avatarMichael Sclafani <dm-devel@lists.linux.dev>
Co-developed-by: default avatarThomas Jaskiewicz <tom@jaskiewicz.us>
Signed-off-by: default avatarThomas Jaskiewicz <tom@jaskiewicz.us>
Co-developed-by: default avatarJohn Wiele <jwiele@redhat.com>
Signed-off-by: default avatarJohn Wiele <jwiele@redhat.com>
Signed-off-by: default avatarMatthew Sakai <msakai@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
parent 4390aa13
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright 2023 Red Hat
*/
#ifndef UDS_INDEX_LAYOUT_H
#define UDS_INDEX_LAYOUT_H
#include "config.h"
#include "io-factory.h"
#include "uds.h"
/*
* The index layout describes the format of the index on the underlying storage, and is responsible
* for creating those structures when the index is first created. It also validates the index data
* when loading a saved index, and updates it when saving the index.
*/
struct index_layout;
int __must_check uds_make_index_layout(struct configuration *config, bool new_layout,
struct index_layout **layout_ptr);
void uds_free_index_layout(struct index_layout *layout);
int __must_check uds_replace_index_layout_storage(struct index_layout *layout,
struct block_device *bdev);
int __must_check uds_load_index_state(struct index_layout *layout,
struct uds_index *index);
int __must_check uds_save_index_state(struct index_layout *layout,
struct uds_index *index);
int __must_check uds_discard_open_chapter(struct index_layout *layout);
u64 __must_check uds_get_volume_nonce(struct index_layout *layout);
int __must_check uds_open_volume_bufio(struct index_layout *layout, size_t block_size,
unsigned int reserved_buffers,
struct dm_bufio_client **client_ptr);
#endif /* UDS_INDEX_LAYOUT_H */
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright 2023 Red Hat
*/
#ifndef UDS_IO_FACTORY_H
#define UDS_IO_FACTORY_H
#include <linux/dm-bufio.h>
/*
* The I/O factory manages all low-level I/O operations to the underlying storage device. Its main
* clients are the index layout and the volume. The buffered reader and buffered writer interfaces
* are helpers for accessing data in a contiguous range of storage blocks.
*/
struct buffered_reader;
struct buffered_writer;
struct io_factory;
enum {
UDS_BLOCK_SIZE = 4096,
SECTORS_PER_BLOCK = UDS_BLOCK_SIZE >> SECTOR_SHIFT,
};
int __must_check uds_make_io_factory(struct block_device *bdev,
struct io_factory **factory_ptr);
int __must_check uds_replace_storage(struct io_factory *factory,
struct block_device *bdev);
void uds_put_io_factory(struct io_factory *factory);
size_t __must_check uds_get_writable_size(struct io_factory *factory);
int __must_check uds_make_bufio(struct io_factory *factory, off_t block_offset,
size_t block_size, unsigned int reserved_buffers,
struct dm_bufio_client **client_ptr);
int __must_check uds_make_buffered_reader(struct io_factory *factory, off_t offset,
u64 block_count,
struct buffered_reader **reader_ptr);
void uds_free_buffered_reader(struct buffered_reader *reader);
int __must_check uds_read_from_buffered_reader(struct buffered_reader *reader, u8 *data,
size_t length);
int __must_check uds_verify_buffered_data(struct buffered_reader *reader, const u8 *value,
size_t length);
int __must_check uds_make_buffered_writer(struct io_factory *factory, off_t offset,
u64 block_count,
struct buffered_writer **writer_ptr);
void uds_free_buffered_writer(struct buffered_writer *buffer);
int __must_check uds_write_to_buffered_writer(struct buffered_writer *writer,
const u8 *data, size_t length);
int __must_check uds_flush_buffered_writer(struct buffered_writer *writer);
#endif /* UDS_IO_FACTORY_H */
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright 2023 Red Hat
*/
#ifndef UDS_NUMERIC_H
#define UDS_NUMERIC_H
#include <asm/unaligned.h>
#include <linux/kernel.h>
#include <linux/types.h>
/*
* These utilities encode or decode a number from an offset in a larger data buffer and then
* advance the offset pointer to the next field in the buffer.
*/
static inline void decode_s64_le(const u8 *buffer, size_t *offset, s64 *decoded)
{
*decoded = get_unaligned_le64(buffer + *offset);
*offset += sizeof(s64);
}
static inline void encode_s64_le(u8 *data, size_t *offset, s64 to_encode)
{
put_unaligned_le64(to_encode, data + *offset);
*offset += sizeof(s64);
}
static inline void decode_u64_le(const u8 *buffer, size_t *offset, u64 *decoded)
{
*decoded = get_unaligned_le64(buffer + *offset);
*offset += sizeof(u64);
}
static inline void encode_u64_le(u8 *data, size_t *offset, u64 to_encode)
{
put_unaligned_le64(to_encode, data + *offset);
*offset += sizeof(u64);
}
static inline void decode_s32_le(const u8 *buffer, size_t *offset, s32 *decoded)
{
*decoded = get_unaligned_le32(buffer + *offset);
*offset += sizeof(s32);
}
static inline void encode_s32_le(u8 *data, size_t *offset, s32 to_encode)
{
put_unaligned_le32(to_encode, data + *offset);
*offset += sizeof(s32);
}
static inline void decode_u32_le(const u8 *buffer, size_t *offset, u32 *decoded)
{
*decoded = get_unaligned_le32(buffer + *offset);
*offset += sizeof(u32);
}
static inline void encode_u32_le(u8 *data, size_t *offset, u32 to_encode)
{
put_unaligned_le32(to_encode, data + *offset);
*offset += sizeof(u32);
}
static inline void decode_u16_le(const u8 *buffer, size_t *offset, u16 *decoded)
{
*decoded = get_unaligned_le16(buffer + *offset);
*offset += sizeof(u16);
}
static inline void encode_u16_le(u8 *data, size_t *offset, u16 to_encode)
{
put_unaligned_le16(to_encode, data + *offset);
*offset += sizeof(u16);
}
#endif /* UDS_NUMERIC_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment