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: J. corwin Coburn <corwin@hurlbutnet.net> Signed-off-by: J. corwin Coburn <corwin@hurlbutnet.net> Co-developed-by: Michael Sclafani <dm-devel@lists.linux.dev> Signed-off-by: Michael Sclafani <dm-devel@lists.linux.dev> Co-developed-by: Thomas Jaskiewicz <tom@jaskiewicz.us> Signed-off-by: Thomas Jaskiewicz <tom@jaskiewicz.us> Co-developed-by: John Wiele <jwiele@redhat.com> Signed-off-by: John Wiele <jwiele@redhat.com> Signed-off-by: Matthew Sakai <msakai@redhat.com> Signed-off-by: Mike Snitzer <snitzer@kernel.org>
This commit is contained in:
parent
4390aa138b
commit
b46d79bdb8
5 changed files with 2368 additions and 0 deletions
1768
drivers/md/dm-vdo/index-layout.c
Normal file
1768
drivers/md/dm-vdo/index-layout.c
Normal file
File diff suppressed because it is too large
Load diff
43
drivers/md/dm-vdo/index-layout.h
Normal file
43
drivers/md/dm-vdo/index-layout.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/* 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 */
|
415
drivers/md/dm-vdo/io-factory.c
Normal file
415
drivers/md/dm-vdo/io-factory.c
Normal file
|
@ -0,0 +1,415 @@
|
|||
// 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 {
|
||||
struct block_device *bdev;
|
||||
atomic_t ref_count;
|
||||
};
|
||||
|
||||
/* The buffered reader allows efficient I/O by reading page-sized segments into a buffer. */
|
||||
struct buffered_reader {
|
||||
struct io_factory *factory;
|
||||
struct dm_bufio_client *client;
|
||||
struct dm_buffer *buffer;
|
||||
sector_t limit;
|
||||
sector_t block_number;
|
||||
u8 *start;
|
||||
u8 *end;
|
||||
};
|
||||
|
||||
enum { MAX_READ_AHEAD_BLOCKS = 4 };
|
||||
|
||||
/*
|
||||
* The buffered writer allows efficient I/O by buffering writes and committing page-sized segments
|
||||
* to storage.
|
||||
*/
|
||||
struct buffered_writer {
|
||||
struct io_factory *factory;
|
||||
struct dm_bufio_client *client;
|
||||
struct dm_buffer *buffer;
|
||||
sector_t limit;
|
||||
sector_t block_number;
|
||||
u8 *start;
|
||||
u8 *end;
|
||||
int error;
|
||||
};
|
||||
|
||||
static void uds_get_io_factory(struct io_factory *factory)
|
||||
{
|
||||
atomic_inc(&factory->ref_count);
|
||||
}
|
||||
|
||||
int uds_make_io_factory(struct block_device *bdev, struct io_factory **factory_ptr)
|
||||
{
|
||||
int result;
|
||||
struct io_factory *factory;
|
||||
|
||||
result = uds_allocate(1, struct io_factory, __func__, &factory);
|
||||
if (result != UDS_SUCCESS)
|
||||
return result;
|
||||
|
||||
factory->bdev = bdev;
|
||||
atomic_set_release(&factory->ref_count, 1);
|
||||
|
||||
*factory_ptr = factory;
|
||||
return UDS_SUCCESS;
|
||||
}
|
||||
|
||||
int uds_replace_storage(struct io_factory *factory, struct block_device *bdev)
|
||||
{
|
||||
factory->bdev = bdev;
|
||||
return UDS_SUCCESS;
|
||||
}
|
||||
|
||||
/* Free an I/O factory once all references have been released. */
|
||||
void uds_put_io_factory(struct io_factory *factory)
|
||||
{
|
||||
if (atomic_add_return(-1, &factory->ref_count) <= 0)
|
||||
uds_free(factory);
|
||||
}
|
||||
|
||||
size_t uds_get_writable_size(struct io_factory *factory)
|
||||
{
|
||||
return i_size_read(factory->bdev->bd_inode);
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
struct dm_bufio_client *client;
|
||||
|
||||
client = dm_bufio_client_create(factory->bdev, block_size, reserved_buffers, 0,
|
||||
NULL, NULL, 0);
|
||||
if (IS_ERR(client))
|
||||
return -PTR_ERR(client);
|
||||
|
||||
dm_bufio_set_sector_offset(client, block_offset * SECTORS_PER_BLOCK);
|
||||
*client_ptr = client;
|
||||
return UDS_SUCCESS;
|
||||
}
|
||||
|
||||
static void read_ahead(struct buffered_reader *reader, sector_t block_number)
|
||||
{
|
||||
if (block_number < reader->limit) {
|
||||
sector_t read_ahead = min((sector_t) MAX_READ_AHEAD_BLOCKS,
|
||||
reader->limit - block_number);
|
||||
|
||||
dm_bufio_prefetch(reader->client, block_number, read_ahead);
|
||||
}
|
||||
}
|
||||
|
||||
void uds_free_buffered_reader(struct buffered_reader *reader)
|
||||
{
|
||||
if (reader == NULL)
|
||||
return;
|
||||
|
||||
if (reader->buffer != NULL)
|
||||
dm_bufio_release(reader->buffer);
|
||||
|
||||
dm_bufio_client_destroy(reader->client);
|
||||
uds_put_io_factory(reader->factory);
|
||||
uds_free(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)
|
||||
{
|
||||
int result;
|
||||
struct dm_bufio_client *client = NULL;
|
||||
struct buffered_reader *reader = NULL;
|
||||
|
||||
result = uds_make_bufio(factory, offset, UDS_BLOCK_SIZE, 1, &client);
|
||||
if (result != UDS_SUCCESS)
|
||||
return result;
|
||||
|
||||
result = uds_allocate(1, struct buffered_reader, "buffered reader", &reader);
|
||||
if (result != UDS_SUCCESS) {
|
||||
dm_bufio_client_destroy(client);
|
||||
return result;
|
||||
}
|
||||
|
||||
*reader = (struct buffered_reader) {
|
||||
.factory = factory,
|
||||
.client = client,
|
||||
.buffer = NULL,
|
||||
.limit = block_count,
|
||||
.block_number = 0,
|
||||
.start = NULL,
|
||||
.end = NULL,
|
||||
};
|
||||
|
||||
read_ahead(reader, 0);
|
||||
uds_get_io_factory(factory);
|
||||
*reader_ptr = reader;
|
||||
return UDS_SUCCESS;
|
||||
}
|
||||
|
||||
static int position_reader(struct buffered_reader *reader, sector_t block_number,
|
||||
off_t offset)
|
||||
{
|
||||
struct dm_buffer *buffer = NULL;
|
||||
void *data;
|
||||
|
||||
if ((reader->end == NULL) || (block_number != reader->block_number)) {
|
||||
if (block_number >= reader->limit)
|
||||
return UDS_OUT_OF_RANGE;
|
||||
|
||||
if (reader->buffer != NULL)
|
||||
dm_bufio_release(uds_forget(reader->buffer));
|
||||
|
||||
data = dm_bufio_read(reader->client, block_number, &buffer);
|
||||
if (IS_ERR(data))
|
||||
return -PTR_ERR(data);
|
||||
|
||||
reader->buffer = buffer;
|
||||
reader->start = data;
|
||||
if (block_number == reader->block_number + 1)
|
||||
read_ahead(reader, block_number + 1);
|
||||
}
|
||||
|
||||
reader->block_number = block_number;
|
||||
reader->end = reader->start + offset;
|
||||
return UDS_SUCCESS;
|
||||
}
|
||||
|
||||
static size_t bytes_remaining_in_read_buffer(struct buffered_reader *reader)
|
||||
{
|
||||
return (reader->end == NULL) ? 0 : reader->start + UDS_BLOCK_SIZE - reader->end;
|
||||
}
|
||||
|
||||
static int reset_reader(struct buffered_reader *reader)
|
||||
{
|
||||
sector_t block_number;
|
||||
|
||||
if (bytes_remaining_in_read_buffer(reader) > 0)
|
||||
return UDS_SUCCESS;
|
||||
|
||||
block_number = reader->block_number;
|
||||
if (reader->end != NULL)
|
||||
block_number++;
|
||||
|
||||
return position_reader(reader, block_number, 0);
|
||||
}
|
||||
|
||||
int uds_read_from_buffered_reader(struct buffered_reader *reader, u8 *data,
|
||||
size_t length)
|
||||
{
|
||||
int result = UDS_SUCCESS;
|
||||
size_t chunk_size;
|
||||
|
||||
while (length > 0) {
|
||||
result = reset_reader(reader);
|
||||
if (result != UDS_SUCCESS)
|
||||
return result;
|
||||
|
||||
chunk_size = min(length, bytes_remaining_in_read_buffer(reader));
|
||||
memcpy(data, reader->end, chunk_size);
|
||||
length -= chunk_size;
|
||||
data += chunk_size;
|
||||
reader->end += chunk_size;
|
||||
}
|
||||
|
||||
return UDS_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
int result = UDS_SUCCESS;
|
||||
size_t chunk_size;
|
||||
sector_t start_block_number = reader->block_number;
|
||||
int start_offset = reader->end - reader->start;
|
||||
|
||||
while (length > 0) {
|
||||
result = reset_reader(reader);
|
||||
if (result != UDS_SUCCESS) {
|
||||
result = UDS_CORRUPT_DATA;
|
||||
break;
|
||||
}
|
||||
|
||||
chunk_size = min(length, bytes_remaining_in_read_buffer(reader));
|
||||
if (memcmp(value, reader->end, chunk_size) != 0) {
|
||||
result = UDS_CORRUPT_DATA;
|
||||
break;
|
||||
}
|
||||
|
||||
length -= chunk_size;
|
||||
value += chunk_size;
|
||||
reader->end += chunk_size;
|
||||
}
|
||||
|
||||
if (result != UDS_SUCCESS)
|
||||
position_reader(reader, start_block_number, start_offset);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
int result;
|
||||
struct dm_bufio_client *client = NULL;
|
||||
struct buffered_writer *writer;
|
||||
|
||||
result = uds_make_bufio(factory, offset, UDS_BLOCK_SIZE, 1, &client);
|
||||
if (result != UDS_SUCCESS)
|
||||
return result;
|
||||
|
||||
result = uds_allocate(1, struct buffered_writer, "buffered writer", &writer);
|
||||
if (result != UDS_SUCCESS) {
|
||||
dm_bufio_client_destroy(client);
|
||||
return result;
|
||||
}
|
||||
|
||||
*writer = (struct buffered_writer) {
|
||||
.factory = factory,
|
||||
.client = client,
|
||||
.buffer = NULL,
|
||||
.limit = block_count,
|
||||
.start = NULL,
|
||||
.end = NULL,
|
||||
.block_number = 0,
|
||||
.error = UDS_SUCCESS,
|
||||
};
|
||||
|
||||
uds_get_io_factory(factory);
|
||||
*writer_ptr = writer;
|
||||
return UDS_SUCCESS;
|
||||
}
|
||||
|
||||
static size_t get_remaining_write_space(struct buffered_writer *writer)
|
||||
{
|
||||
return writer->start + UDS_BLOCK_SIZE - writer->end;
|
||||
}
|
||||
|
||||
static int __must_check prepare_next_buffer(struct buffered_writer *writer)
|
||||
{
|
||||
struct dm_buffer *buffer = NULL;
|
||||
void *data;
|
||||
|
||||
if (writer->block_number >= writer->limit) {
|
||||
writer->error = UDS_OUT_OF_RANGE;
|
||||
return UDS_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
data = dm_bufio_new(writer->client, writer->block_number, &buffer);
|
||||
if (IS_ERR(data)) {
|
||||
writer->error = -PTR_ERR(data);
|
||||
return writer->error;
|
||||
}
|
||||
|
||||
writer->buffer = buffer;
|
||||
writer->start = data;
|
||||
writer->end = data;
|
||||
return UDS_SUCCESS;
|
||||
}
|
||||
|
||||
static int flush_previous_buffer(struct buffered_writer *writer)
|
||||
{
|
||||
size_t available;
|
||||
|
||||
if (writer->buffer == NULL)
|
||||
return writer->error;
|
||||
|
||||
if (writer->error == UDS_SUCCESS) {
|
||||
available = get_remaining_write_space(writer);
|
||||
|
||||
if (available > 0)
|
||||
memset(writer->end, 0, available);
|
||||
|
||||
dm_bufio_mark_buffer_dirty(writer->buffer);
|
||||
}
|
||||
|
||||
dm_bufio_release(writer->buffer);
|
||||
writer->buffer = NULL;
|
||||
writer->start = NULL;
|
||||
writer->end = NULL;
|
||||
writer->block_number++;
|
||||
return writer->error;
|
||||
}
|
||||
|
||||
void uds_free_buffered_writer(struct buffered_writer *writer)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (writer == NULL)
|
||||
return;
|
||||
|
||||
flush_previous_buffer(writer);
|
||||
result = -dm_bufio_write_dirty_buffers(writer->client);
|
||||
if (result != UDS_SUCCESS)
|
||||
uds_log_warning_strerror(result, "%s: failed to sync storage", __func__);
|
||||
|
||||
dm_bufio_client_destroy(writer->client);
|
||||
uds_put_io_factory(writer->factory);
|
||||
uds_free(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 result = writer->error;
|
||||
size_t chunk_size;
|
||||
|
||||
while ((length > 0) && (result == UDS_SUCCESS)) {
|
||||
if (writer->buffer == NULL) {
|
||||
result = prepare_next_buffer(writer);
|
||||
continue;
|
||||
}
|
||||
|
||||
chunk_size = min(length, get_remaining_write_space(writer));
|
||||
if (data == NULL) {
|
||||
memset(writer->end, 0, chunk_size);
|
||||
} else {
|
||||
memcpy(writer->end, data, chunk_size);
|
||||
data += chunk_size;
|
||||
}
|
||||
|
||||
length -= chunk_size;
|
||||
writer->end += chunk_size;
|
||||
|
||||
if (get_remaining_write_space(writer) == 0)
|
||||
result = uds_flush_buffered_writer(writer);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int uds_flush_buffered_writer(struct buffered_writer *writer)
|
||||
{
|
||||
if (writer->error != UDS_SUCCESS)
|
||||
return writer->error;
|
||||
|
||||
return flush_previous_buffer(writer);
|
||||
}
|
64
drivers/md/dm-vdo/io-factory.h
Normal file
64
drivers/md/dm-vdo/io-factory.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
/* 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 */
|
78
drivers/md/dm-vdo/numeric.h
Normal file
78
drivers/md/dm-vdo/numeric.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/* 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 */
|
Loading…
Add table
Reference in a new issue