diff --git a/lib/ftl/Makefile b/lib/ftl/Makefile index 12c16dc61..3eb7d81cf 100644 --- a/lib/ftl/Makefile +++ b/lib/ftl/Makefile @@ -11,6 +11,8 @@ SO_MINOR := 0 CFLAGS += -I. +FTL_SUBDIRS := utils + C_SRCS = ftl_core.c SPDK_MAP_FILE = $(abspath $(CURDIR)/spdk_ftl.map) @@ -18,3 +20,14 @@ SPDK_MAP_FILE = $(abspath $(CURDIR)/spdk_ftl.map) LIBNAME = ftl include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk + +# TODO: This should be handled by spdk.subdirs.mk +CLEAN_FTL_SUBDIRS = $(addprefix clean_ftl_, $(FTL_SUBDIRS)) + +clean: $(CLEAN_FTL_SUBDIRS) + +.PHONY: $(CLEAN_FTL_SUBDIRS) +$(CLEAN_FTL_SUBDIRS): _Q := $(Q) +$(CLEAN_FTL_SUBDIRS): Q := +$(CLEAN_FTL_SUBDIRS): clean_ftl_%:% + $(_Q)cd $< && $(CLEAN_C) diff --git a/lib/ftl/ftl_core.c b/lib/ftl/ftl_core.c index 99d168540..53d20abfc 100644 --- a/lib/ftl/ftl_core.c +++ b/lib/ftl/ftl_core.c @@ -13,5 +13,6 @@ #include "spdk/crc32.h" #include "ftl_core.h" +#include "ftl_internal.h" SPDK_LOG_REGISTER_COMPONENT(ftl_core) diff --git a/lib/ftl/ftl_core.h b/lib/ftl/ftl_core.h index 70f32fb12..922887168 100644 --- a/lib/ftl/ftl_core.h +++ b/lib/ftl/ftl_core.h @@ -15,7 +15,9 @@ #include "spdk/ftl.h" #include "spdk/bdev.h" #include "spdk/bdev_zone.h" -#include "spdk/log.h" + +#include "ftl_internal.h" +#include "utils/ftl_log.h" struct spdk_ftl_dev { /* Device instance */ diff --git a/lib/ftl/ftl_internal.h b/lib/ftl/ftl_internal.h new file mode 100644 index 000000000..534444e0f --- /dev/null +++ b/lib/ftl/ftl_internal.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) Intel Corporation. + * All rights reserved. + */ + +#ifndef FTL_INTERNAL_H +#define FTL_INTERNAL_H + +#include "spdk/stdinc.h" +#include "spdk/crc32.h" +#include "spdk/util.h" +#include "spdk/uuid.h" + +/* Marks address as invalid */ +#define FTL_ADDR_INVALID ((ftl_addr)-1) + +/* + * This type represents address in the ftl address space. Values from 0 to based bdev size are + * mapped directly to base device lbas. Values above that represent nv cache lbas. + */ +typedef uint64_t ftl_addr; + +#endif /* FTL_INTERNAL_H */ diff --git a/lib/ftl/ftl_utils.h b/lib/ftl/ftl_utils.h new file mode 100644 index 000000000..24cb94bca --- /dev/null +++ b/lib/ftl/ftl_utils.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) Intel Corporation. + * All rights reserved. + */ + +#ifndef FTL_FTL_UTILS_H +#define FTL_FTL_UTILS_H + +#include "utils/ftl_defs.h" + +#endif /* FTL_FTL_UTILS_H */ diff --git a/lib/ftl/utils/ftl_defs.h b/lib/ftl/utils/ftl_defs.h new file mode 100644 index 000000000..0e62ea9b7 --- /dev/null +++ b/lib/ftl/utils/ftl_defs.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) Intel Corporation. + * All rights reserved. + */ + +#ifndef FTL_DEFS_H +#define FTL_DEFS_H + +#include "spdk/stdinc.h" + +#ifndef KiB +#define KiB (1ULL << 10) +#endif + +#ifndef MiB +#define MiB (1ULL << 20) +#endif + +#ifndef GiB +#define GiB (1ULL << 30) +#endif + +#ifndef TiB +#define TiB (1ULL << 40) +#endif + +#define ftl_abort() \ + do { \ + assert(false); \ + abort(); \ + } while (0) + +#define ftl_bug(cond) \ + do { \ + if (spdk_unlikely((cond))) { \ + ftl_abort(); \ + } \ + } while (0) + +#endif /* FTL_DEFS_H */ diff --git a/lib/ftl/utils/ftl_log.h b/lib/ftl/utils/ftl_log.h new file mode 100644 index 000000000..ab0f5df10 --- /dev/null +++ b/lib/ftl/utils/ftl_log.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) Intel Corporation. + * All rights reserved. + */ + +#ifndef FTL_LOG_H +#define FTL_LOG_H + +#include "spdk/stdinc.h" +#include "spdk/log.h" + +#define FTL_LOG_COMMON(type, dev, format, ...) \ + if ((dev) == NULL) \ + { \ + spdk_log(SPDK_LOG_##type, __FILE__, __LINE__, __func__, "[FTL] "format, ## __VA_ARGS__); \ + } else { \ + spdk_log(SPDK_LOG_##type, __FILE__, __LINE__, __func__, "[FTL][%s] "format, (dev)->name, ## __VA_ARGS__); \ + } \ + +#define FTL_ERRLOG(dev, format, ...) \ + FTL_LOG_COMMON(ERROR, dev, format, ## __VA_ARGS__) + +#define FTL_WARNLOG(dev, format, ...) \ + FTL_LOG_COMMON(WARN, dev, format, ## __VA_ARGS__) + +#define FTL_NOTICELOG(dev, format, ...) \ + FTL_LOG_COMMON(NOTICE, dev, format, ## __VA_ARGS__) + +#define FTL_INFOLOG(dev, format, ...) \ + FTL_LOG_COMMON(INFO, dev, format, ## __VA_ARGS__) + +#define FTL_DEBUGLOG(dev, format, ...) \ + FTL_LOG_COMMON(DEBUG, dev, format, ## __VA_ARGS__) + +#endif /* FTL_LOG_H */