linux/drivers/md/dm-vdo/indexer/io-factory.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright 2023 Red Hat
 */

#include "io-factory.h"

#include <linux/atomic.h>
#include <linux/blkdev.h>
#include <linux/err.h>
#include <linux/mount.h>

#include "logger.h"
#include "memory-alloc.h"
#include "numeric.h"

/*
 * The I/O factory object manages access to index storage, which is a contiguous range of blocks on
 * a block device.
 *
 * The factory holds the open device and is responsible for closing it. The factory has methods to
 * make helper structures that can be used to access sections of the index.
 */
struct io_factory {};

/* The buffered reader allows efficient I/O by reading page-sized segments into a buffer. */
struct buffered_reader {};

#define MAX_READ_AHEAD_BLOCKS

/*
 * The buffered writer allows efficient I/O by buffering writes and committing page-sized segments
 * to storage.
 */
struct buffered_writer {};

static void uds_get_io_factory(struct io_factory *factory)
{}

int uds_make_io_factory(struct block_device *bdev, struct io_factory **factory_ptr)
{}

int uds_replace_storage(struct io_factory *factory, struct block_device *bdev)
{}

/* Free an I/O factory once all references have been released. */
void uds_put_io_factory(struct io_factory *factory)
{}

size_t uds_get_writable_size(struct io_factory *factory)
{}

/* Create a struct dm_bufio_client for an index region starting at offset. */
int 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)
{}

static void read_ahead(struct buffered_reader *reader, sector_t block_number)
{}

void uds_free_buffered_reader(struct buffered_reader *reader)
{}

/* Create a buffered reader for an index region starting at offset. */
int uds_make_buffered_reader(struct io_factory *factory, off_t offset, u64 block_count,
			     struct buffered_reader **reader_ptr)
{}

static int position_reader(struct buffered_reader *reader, sector_t block_number,
			   off_t offset)
{}

static size_t bytes_remaining_in_read_buffer(struct buffered_reader *reader)
{}

static int reset_reader(struct buffered_reader *reader)
{}

int uds_read_from_buffered_reader(struct buffered_reader *reader, u8 *data,
				  size_t length)
{}

/*
 * Verify that the next data on the reader matches the required value. If the value matches, the
 * matching contents are consumed. If the value does not match, the reader state is unchanged.
 */
int uds_verify_buffered_data(struct buffered_reader *reader, const u8 *value,
			     size_t length)
{}

/* Create a buffered writer for an index region starting at offset. */
int uds_make_buffered_writer(struct io_factory *factory, off_t offset, u64 block_count,
			     struct buffered_writer **writer_ptr)
{}

static size_t get_remaining_write_space(struct buffered_writer *writer)
{}

static int __must_check prepare_next_buffer(struct buffered_writer *writer)
{}

static int flush_previous_buffer(struct buffered_writer *writer)
{}

void uds_free_buffered_writer(struct buffered_writer *writer)
{}

/*
 * Append data to the buffer, writing as needed. If no data is provided, zeros are written instead.
 * If a write error occurs, it is recorded and returned on every subsequent write attempt.
 */
int uds_write_to_buffered_writer(struct buffered_writer *writer, const u8 *data,
				 size_t length)
{}

int uds_flush_buffered_writer(struct buffered_writer *writer)
{}