Spdk/include/spdk/ftl.h
Jim Harris 488570ebd4 Replace most BSD 3-clause license text with SPDX identifier.
Many open source projects have moved to using SPDX identifiers
to specify license information, reducing the amount of
boilerplate code in every source file.  This patch replaces
the bulk of SPDK .c, .cpp and Makefiles with the BSD-3-Clause
identifier.

Almost all of these files share the exact same license text,
and this patch only modifies the files that contain the
most common license text.  There can be slight variations
because the third clause contains company names - most say
"Intel Corporation", but there are instances for Nvidia,
Samsung, Eideticom and even "the copyright holder".

Used a bash script to automate replacement of the license text
with SPDX identifier which is checked into scripts/spdx.sh.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Iaa88ab5e92ea471691dc298cfe41ebfb5d169780
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12904
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Dong Yi <dongx.yi@intel.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: <qun.wan@intel.com>
2022-06-09 07:35:12 +00:00

224 lines
5.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) Intel Corporation.
* All rights reserved.
*/
#ifndef SPDK_FTL_H
#define SPDK_FTL_H
#include "spdk/stdinc.h"
#include "spdk/uuid.h"
#include "spdk/thread.h"
#include "spdk/bdev.h"
#ifdef __cplusplus
extern "C" {
#endif
struct spdk_ftl_dev;
/* Limit thresholds */
enum {
SPDK_FTL_LIMIT_CRIT,
SPDK_FTL_LIMIT_HIGH,
SPDK_FTL_LIMIT_LOW,
SPDK_FTL_LIMIT_START,
SPDK_FTL_LIMIT_MAX
};
struct spdk_ftl_limit {
/* Threshold from which the limiting starts */
size_t thld;
/* Limit percentage */
size_t limit;
};
struct spdk_ftl_conf {
/* Number of reserved addresses not exposed to the user */
size_t lba_rsvd;
/* Size of the per-io_channel write buffer */
size_t write_buffer_size;
/* Threshold for opening new band */
size_t band_thld;
/* Maximum IO depth per band relocate */
size_t max_reloc_qdepth;
/* Maximum active band relocates */
size_t max_active_relocs;
/* IO pool size per user thread */
size_t user_io_pool_size;
/* Lowest percentage of invalid blocks for a band to be defragged */
size_t invalid_thld;
/* User writes limits */
struct spdk_ftl_limit limits[SPDK_FTL_LIMIT_MAX];
/* Allow for partial recovery from open bands instead of returning error */
bool allow_open_bands;
/* Use append instead of write */
bool use_append;
/* Maximum supported number of IO channels */
uint32_t max_io_channels;
struct {
/* Maximum number of concurrent requests */
size_t max_request_cnt;
/* Maximum number of blocks per one request */
size_t max_request_size;
} nv_cache;
/* Create l2p table on l2p_path persistent memory file or device instead of in DRAM */
const char *l2p_path;
};
enum spdk_ftl_mode {
/* Create new device */
SPDK_FTL_MODE_CREATE = (1 << 0),
};
struct spdk_ftl_dev_init_opts {
/* Underlying device */
const char *base_bdev;
/* Write buffer cache */
const char *cache_bdev;
/* Thread responsible for core tasks execution */
struct spdk_thread *core_thread;
/* Device's config */
const struct spdk_ftl_conf *conf;
/* Device's name */
const char *name;
/* Mode flags */
unsigned int mode;
/* Device UUID (valid when restoring device from disk) */
struct spdk_uuid uuid;
};
struct spdk_ftl_attrs {
/* Device's UUID */
struct spdk_uuid uuid;
/* Number of logical blocks */
uint64_t num_blocks;
/* Logical block size */
size_t block_size;
/* Underlying device */
const char *base_bdev;
/* Write buffer cache */
const char *cache_bdev;
/* Number of zones per parallel unit in the underlying device (including any offline ones) */
size_t num_zones;
/* Number of logical blocks per zone */
size_t zone_size;
/* Device specific configuration */
struct spdk_ftl_conf conf;
};
typedef void (*spdk_ftl_fn)(void *, int);
typedef void (*spdk_ftl_init_fn)(struct spdk_ftl_dev *, void *, int);
/**
* Initialize the FTL on given NVMe device and parallel unit range.
*
* Covers the following:
* - retrieve zone device information,
* - allocate buffers and resources,
* - initialize internal structures,
* - initialize internal thread(s),
* - restore or create L2P table.
*
* \param opts configuration for new device
* \param cb callback function to call when the device is created
* \param cb_arg callback's argument
*
* \return 0 if initialization was started successfully, negative errno otherwise.
*/
int spdk_ftl_dev_init(const struct spdk_ftl_dev_init_opts *opts, spdk_ftl_init_fn cb, void *cb_arg);
/**
* Deinitialize and free given device.
*
* \param dev device
* \param cb callback function to call when the device is freed
* \param cb_arg callback's argument
*
* \return 0 if successfully scheduled free, negative errno otherwise.
*/
int spdk_ftl_dev_free(struct spdk_ftl_dev *dev, spdk_ftl_init_fn cb, void *cb_arg);
/**
* Initialize FTL configuration structure with default values.
*
* \param conf FTL configuration to initialize
*/
void spdk_ftl_conf_init_defaults(struct spdk_ftl_conf *conf);
/**
* Retrieve devices attributes.
*
* \param dev device
* \param attr Attribute structure to fill
*/
void spdk_ftl_dev_get_attrs(const struct spdk_ftl_dev *dev, struct spdk_ftl_attrs *attr);
/**
* Submits a read to the specified device.
*
* \param dev Device
* \param ch I/O channel
* \param lba Starting LBA to read the data
* \param lba_cnt Number of sectors to read
* \param iov Single IO vector or pointer to IO vector table
* \param iov_cnt Number of IO vectors
* \param cb_fn Callback function to invoke when the I/O is completed
* \param cb_arg Argument to pass to the callback function
*
* \return 0 if successfully submitted, negative errno otherwise.
*/
int spdk_ftl_read(struct spdk_ftl_dev *dev, struct spdk_io_channel *ch, uint64_t lba,
size_t lba_cnt,
struct iovec *iov, size_t iov_cnt, spdk_ftl_fn cb_fn, void *cb_arg);
/**
* Submits a write to the specified device.
*
* \param dev Device
* \param ch I/O channel
* \param lba Starting LBA to write the data
* \param lba_cnt Number of sectors to write
* \param iov Single IO vector or pointer to IO vector table
* \param iov_cnt Number of IO vectors
* \param cb_fn Callback function to invoke when the I/O is completed
* \param cb_arg Argument to pass to the callback function
*
* \return 0 if successfully submitted, negative errno otherwise.
*/
int spdk_ftl_write(struct spdk_ftl_dev *dev, struct spdk_io_channel *ch, uint64_t lba,
size_t lba_cnt,
struct iovec *iov, size_t iov_cnt, spdk_ftl_fn cb_fn, void *cb_arg);
/**
* Submits a flush request to the specified device.
*
* \param dev device
* \param cb_fn Callback function to invoke when all prior IOs have been completed
* \param cb_arg Argument to pass to the callback function
*
* \return 0 if successfully submitted, negative errno otherwise.
*/
int spdk_ftl_flush(struct spdk_ftl_dev *dev, spdk_ftl_fn cb_fn, void *cb_arg);
#ifdef __cplusplus
}
#endif
#endif /* SPDK_FTL_H */