Skip to content

Commit

Permalink
Version 8.3.0.72
Browse files Browse the repository at this point in the history
- Improved vdoformat error handling.
- Added clang support.
- General code clean up and simplification.

Signed-off-by: Matthew Sakai <[email protected]>
  • Loading branch information
lorelei-sakai committed Oct 15, 2024
1 parent bfd434b commit 64786b7
Show file tree
Hide file tree
Showing 17 changed files with 167 additions and 91 deletions.
49 changes: 32 additions & 17 deletions utils/uds/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,45 @@
# 02110-1301, USA.
#

BUILD_VERSION = 8.3.0.71
BUILD_VERSION = 8.3.0.72

DEPDIR = .deps

ifdef LLVM
export CC := clang
export LD := ld.ldd
endif

ifeq ($(origin CC), default)
CC=gcc
CC := gcc
endif

ifeq ($(findstring clang, $(CC)),clang)
# Ignore additional warnings for clang
WARNS = -Wno-compare-distinct-pointer-types \
-Wno-gnu-statement-expression \
-Wno-gnu-zero-variadic-macro-arguments \
-Wno-implicit-const-int-float-conversion \
-Wno-language-extension-token
else
WARNS = -Wcast-align \
-Wcast-qual \
-Wformat=2 \
-Wlogical-op
endif

WARNS = -Wall \
-Wcast-align \
-Werror \
-Wextra \
-Winit-self \
-Wlogical-op \
-Wmissing-include-dirs \
-Wpointer-arith \
-Wredundant-decls \
-Wunused \
-Wwrite-strings

C_WARNS = -Wbad-function-cast \
-Wcast-qual \
WARNS += -Wall \
-Werror \
-Wextra \
-Winit-self \
-Wmissing-include-dirs \
-Wpointer-arith \
-Wredundant-decls \
-Wunused \
-Wwrite-strings

C_WARNS = -Wbad-function-cast \
-Wfloat-equal \
-Wformat=2 \
-Wmissing-declarations \
-Wmissing-format-attribute \
-Wmissing-prototypes \
Expand Down
51 changes: 32 additions & 19 deletions utils/uds/asm/unaligned.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,48 @@
#include <asm/byteorder.h>
#include <linux/types.h>

/* Type safe comparison macros, similar to the ones in linux/kernel.h. */
/* Type safe comparison macros, similar to the ones in linux/minmax.h. */

/*
* If pointers to types are comparable (without dereferencing them and
* potentially causing side effects) then types are the same.
*/
#define TYPECHECK(x, y) (!!(sizeof((typeof(x) *) 1 == (typeof(y) *) 1)))
#define CONSTCHECK(x, y) (__builtin_constant_p(x) && __builtin_constant_p(y))
#define __typecheck(x, y) \
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))

/*
* Hack for VDO to replace use of the kernel's __is_constexpr() in __cmp_ macros.
* VDO cannot use __is_constexpr() due to it relying on a GCC extension to allow sizeof(void).
*/
#define __constcheck(x, y) \
(__builtin_constant_p(x) && __builtin_constant_p(y))

/* It takes two levels of macro expansion to compose the unique temp names. */
#define CONCAT_(a, b) a##b
#define CONCAT(a, b) CONCAT_(a, b)
#define UNIQUE_ID(a) CONCAT(_UNIQUE_, CONCAT(a, __COUNTER__))

#define SAFE_COMPARE(x, y, unique_x, unique_y, op) \
__extension__({ \
typeof(x) unique_x = (x); \
typeof(y) unique_y = (y); \
unique_x op unique_y ? unique_x : unique_y; \
#define ___PASTE(a,b) a##b
#define __PASTE(a,b) ___PASTE(a,b)
#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)

/* Defined in linux/minmax.h */
#define __cmp_op_min <
#define __cmp_op_max >

#define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y))

#define __cmp_once(op, x, y, unique_x, unique_y) \
__extension__({ \
typeof(x) unique_x = (x); \
typeof(y) unique_y = (y); \
__cmp(op, unique_x, unique_y); \
})

#define COMPARE(x, y, op) \
__builtin_choose_expr( \
(TYPECHECK(x, y) && CONSTCHECK(x, y)), \
(((x) op(y)) ? (x) : (y)), \
SAFE_COMPARE(x, y, UNIQUE_ID(x_), UNIQUE_ID(y_), op))
#define __careful_cmp(op, x, y) \
__builtin_choose_expr( \
(__typecheck(x, y) && __constcheck(x, y)), \
__cmp(op, x, y), \
__cmp_once(op, x, y, __UNIQUE_ID(x_), __UNIQUE_ID(y_)))

#define min(x, y) COMPARE(x, y, <)
#define max(x, y) COMPARE(x, y, >)
#define min(x, y) __careful_cmp(min, x, y)
#define max(x, y) __careful_cmp(max, x, y)

/* Defined in linux/minmax.h */
#define swap(a, b) \
Expand Down
2 changes: 1 addition & 1 deletion utils/uds/chapter-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ int uds_pack_open_chapter_index_page(struct open_chapter_index *chapter_index,
if (list_number < 0)
return UDS_OVERFLOW;

next_list = first_list + list_number--,
next_list = first_list + list_number--;
result = uds_start_delta_index_search(delta_index, next_list, 0,
&entry);
if (result != UDS_SUCCESS)
Expand Down
47 changes: 40 additions & 7 deletions utils/uds/linux/blkdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#ifndef LINUX_BLKDEV_H
#define LINUX_BLKDEV_H

#include <linux/compiler_attributes.h>
#include <linux/compiler.h>
#include <linux/types.h>
#include <errno.h>
#include <stdio.h>

#define SECTOR_SHIFT 9
Expand All @@ -24,9 +25,17 @@
sprintf(buffer, "%u:%u", MAJOR(dev), MINOR(dev))

/* Defined in linux/blk_types.h */
typedef unsigned int blk_opf_t;
typedef uint32_t blk_status_t;
typedef unsigned int blk_qc_t;
typedef u32 __bitwise blk_opf_t;
typedef unsigned int blk_qc_t;

typedef u8 __bitwise blk_status_t;
#define BLK_STS_OK 0
#define BLK_STS_NOSPC ((blk_status_t)3)
#define BLK_STS_RESOURCE ((blk_status_t)9)
#define BLK_STS_IOERR ((blk_status_t)10)

/* hack for vdo, don't use elsewhere */
#define BLK_STS_VDO_INJECTED ((blk_status_t)31)

struct bio;

Expand All @@ -38,20 +47,44 @@ struct block_device {
loff_t size;
};

/* Defined in linux/blk-core.c */
static const struct {
int error;
const char *name;
} blk_errors[] = {
[BLK_STS_OK] = { 0, "" },
[BLK_STS_NOSPC] = { -ENOSPC, "critical space allocation" },
[BLK_STS_RESOURCE] = { -ENOMEM, "kernel resource" },

/* error specifically for VDO unit tests */
[BLK_STS_VDO_INJECTED] = { 31, "vdo injected error" },
/* everything else not covered above: */
[BLK_STS_IOERR] = { -EIO, "I/O" },
};

/**********************************************************************/
static inline int blk_status_to_errno(blk_status_t status)
{
return (int) status;
int idx = (int) status;

return blk_errors[idx].error;
}

/**********************************************************************/
static inline blk_status_t errno_to_blk_status(int error)
{
return (blk_status_t) error;
unsigned int i;

for (i = 0; i < ARRAY_SIZE(blk_errors); i++) {
if (blk_errors[i].error == error)
return (blk_status_t)i;
}

return BLK_STS_IOERR;
}

/**********************************************************************/
blk_qc_t submit_bio_noacct(struct bio *bio);
void submit_bio_noacct(struct bio *bio);

/**********************************************************************/
static inline loff_t bdev_nr_bytes(struct block_device *bdev)
Expand Down
9 changes: 5 additions & 4 deletions utils/uds/minisyslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void mini_syslog(int priority, const char *format, ...)
}

/**********************************************************************/
static bool __must_check write_msg(int fd, const char *msg)
static bool write_msg(int fd, const char *msg)
{
size_t bytes_to_write = strlen(msg);
ssize_t bytes_written = write(fd, msg, bytes_to_write);
Expand Down Expand Up @@ -180,9 +180,10 @@ static void log_it(int priority,
}
if (failure && (log_option & LOG_CONS)) {
int console = open(_PATH_CONSOLE, O_WRONLY);
failure |= (console == -1) || write_msg(console, stderr_msg);
if (console != -1)
failure |= (close(console) != 0);
if (console != -1) {
write_msg(console, stderr_msg);
close(console);
}
}
}

Expand Down
7 changes: 2 additions & 5 deletions utils/uds/murmurhash3.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,11 @@ void murmurhash3_128(const void *key, const int len, const u32 seed, void *out)
u64 *hash_out = out;

/* body */

const u64 *blocks = (const u64 *)(data);

int i;

for (i = 0; i < nblocks; i++) {
u64 k1 = get_unaligned_le64(&blocks[i * 2]);
u64 k2 = get_unaligned_le64(&blocks[i * 2 + 1]);
u64 k1 = get_unaligned_le64(&data[i * 16]);
u64 k2 = get_unaligned_le64(&data[i * 16 + 8]);

k1 *= c1;
k1 = ROTL64(k1, 31);
Expand Down
30 changes: 24 additions & 6 deletions utils/vdo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,38 @@
# 02110-1301, USA.
#

VDO_VERSION = 8.3.0.71
VDO_VERSION = 8.3.0.72

UDS_DIR = ../uds

ifdef LLVM
export CC := clang
export LD := ld.ldd
endif

ifeq ($(origin CC), default)
CC := gcc
endif

ifeq ($(findstring clang, $(CC)),clang)
# Ignore additional warnings for clang
WARNS = -Wno-compare-distinct-pointer-types \
-Wno-gnu-statement-expression \
-Wno-gnu-zero-variadic-macro-arguments \
-Wno-implicit-const-int-float-conversion \
-Wno-language-extension-token
else
WARNS = -Wcast-align \
-Wcast-qual \
-Wformat=2 \
-Wlogical-op
endif

WARNS = \
WARNS += \
-Wall \
-Wcast-align \
-Werror \
-Wextra \
-Winit-self \
-Wlogical-op \
-Wmissing-include-dirs \
-Wpointer-arith \
-Wredundant-decls \
Expand All @@ -37,9 +57,7 @@ WARNS = \

C_WARNS = \
-Wbad-function-cast \
-Wcast-qual \
-Wfloat-equal \
-Wformat=2 \
-Wmissing-declarations \
-Wmissing-format-attribute \
-Wmissing-prototypes \
Expand Down
2 changes: 0 additions & 2 deletions utils/vdo/adaptlvm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ LVM_EXTRA_ARGS=${EXTRA_LVM_ARGS:-}

BACKINGTABLE=
DEV_VG_LV=
DM_VPOOL=
LV=
LVMVDO=
OPERATION=
Expand Down Expand Up @@ -101,7 +100,6 @@ setRW() {
fi

VPOOL_NAME=$(lvdisplay ${LVMVDO} | awk '/LV VDO Pool name/ {print $NF}')
DM_VPOOL="${VG}-${VPOOL_NAME}"
DM_VDATA="${VG}-${VPOOL_NAME}_vdata"

# Look in the list of dm devices and find the appropriate backing device
Expand Down
2 changes: 1 addition & 1 deletion utils/vdo/encodings.c
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ static int __must_check make_partition(struct layout *layout, enum partition_id
/**
* vdo_initialize_layout() - Lay out the partitions of a vdo.
* @size: The entire size of the vdo.
* @origin: The start of the layout on the underlying storage in blocks.
* @offset: The start of the layout on the underlying storage in blocks.
* @block_map_blocks: The size of the block map partition.
* @journal_blocks: The size of the journal partition.
* @summary_blocks: The size of the slab summary partition.
Expand Down
3 changes: 1 addition & 2 deletions utils/vdo/fileLayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ static int fileWriter(PhysicalLayer *header,
return result;
}

bool wasAligned = (alignedBuffer == buffer);
if (!wasAligned) {
if (alignedBuffer != buffer) {
memcpy(alignedBuffer, buffer, bytes);
}

Expand Down
2 changes: 1 addition & 1 deletion utils/vdo/status-codes.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const struct error_info vdo_status_list[] = {
{ "VDO_LOCK_ERROR", "A lock is held incorrectly" },
{ "VDO_READ_ONLY", "The device is in read-only mode" },
{ "VDO_SHUTTING_DOWN", "The device is shutting down" },
{ "VDO_CORRUPT_JOURNAL", "Recovery journal entries corrupted" },
{ "VDO_CORRUPT_JOURNAL", "Recovery journal corrupted" },
{ "VDO_TOO_MANY_SLABS", "Exceeds maximum number of slabs supported" },
{ "VDO_INVALID_FRAGMENT", "Compressed block fragment is invalid" },
{ "VDO_RETRY_AFTER_REBUILD", "Retry operation after rebuilding finishes" },
Expand Down
2 changes: 1 addition & 1 deletion utils/vdo/status-codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ enum vdo_status_codes {
VDO_READ_ONLY,
/* the VDO is shutting down */
VDO_SHUTTING_DOWN,
/* the recovery journal has corrupt entries */
/* the recovery journal has corrupt entries or corrupt metadata */
VDO_CORRUPT_JOURNAL,
/* exceeds maximum number of slabs supported */
VDO_TOO_MANY_SLABS,
Expand Down
4 changes: 0 additions & 4 deletions utils/vdo/vdoConfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ static int __must_check configureVDO(UserVDO *vdo)

const struct partition *partition =
getPartition(vdo, VDO_SLAB_DEPOT_PARTITION, "no allocator partition");
if (result != VDO_SUCCESS) {
return result;
}

result = vdo_configure_slab_depot(partition, slabConfig, 0, &vdo->states.slab_depot);
if (result != VDO_SUCCESS) {
return result;
Expand Down
6 changes: 3 additions & 3 deletions utils/vdo/vdoStatsWriter.c
Original file line number Diff line number Diff line change
Expand Up @@ -917,12 +917,12 @@ static int write_vdo_statistics(char *prefix,
u64 one_k_blocks = stats->physical_blocks * stats->block_size / 1024;
u64 one_k_blocks_used = (stats->data_blocks_used + stats->overhead_blocks_used) * stats->block_size / 1024;
u64 one_k_blocks_available = (stats->physical_blocks - stats->data_blocks_used - stats->overhead_blocks_used) * stats->block_size / 1024;
u8 used_percent = (int) (100 * (stats->data_blocks_used + stats->overhead_blocks_used) / stats->physical_blocks) + 0.5;
s32 savings = (stats->logical_blocks_used > 0) ? (int) (100 * (s64) (stats->logical_blocks_used - stats->data_blocks_used) / (u64) stats->logical_blocks_used) : -1;
u8 used_percent = (int) (100 * ((double) (stats->data_blocks_used + stats->overhead_blocks_used) / stats->physical_blocks) + 0.5);
s32 savings = (stats->logical_blocks_used > 0) ? (int) (100 * (s64) (stats->logical_blocks_used - stats->data_blocks_used) / (u64) stats->logical_blocks_used) : 0;
u8 saving_percent = savings;
char five_twelve_byte_emulation[4] = "";
sprintf(five_twelve_byte_emulation, "%s", (stats->logical_block_size == 512) ? "on" : "off");
double write_amplification_ratio = (stats->bios_in.write > 0) ? roundf((stats->bios_meta.write + stats->bios_out.write) / (stats->bios_in.write)) : 0.00;
double write_amplification_ratio = (stats->bios_in.write > 0) ? roundf((double) (stats->bios_meta.write + stats->bios_out.write) / stats->bios_in.write) : 0.00;

if (asprintf(&joined, "%s version", prefix) == -1) {
return VDO_UNEXPECTED_EOF;
Expand Down
Loading

0 comments on commit 64786b7

Please sign in to comment.