2018-10-29 11:29:03 +00:00
|
|
|
|
/*-
|
|
|
|
|
* BSD LICENSE
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
|
* distribution.
|
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef SPDK_FTL_H
|
|
|
|
|
#define SPDK_FTL_H
|
|
|
|
|
|
2019-01-24 18:47:12 +00:00
|
|
|
|
#include "spdk/stdinc.h"
|
|
|
|
|
#include "spdk/uuid.h"
|
|
|
|
|
#include "spdk/thread.h"
|
2019-03-15 16:37:44 +00:00
|
|
|
|
#include "spdk/bdev.h"
|
2018-10-29 11:29:03 +00:00
|
|
|
|
|
2019-07-05 11:35:13 +00:00
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-10-29 11:29:03 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2020-02-13 14:50:58 +00:00
|
|
|
|
/* Size of the per-io_channel write buffer */
|
|
|
|
|
size_t write_buffer_size;
|
2018-10-29 11:29:03 +00:00
|
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
2019-10-24 14:36:42 +00:00
|
|
|
|
/* Lowest percentage of invalid blocks for a band to be defragged */
|
2019-07-04 12:41:08 +00:00
|
|
|
|
size_t invalid_thld;
|
2018-10-29 11:29:03 +00:00
|
|
|
|
|
2019-07-04 12:41:08 +00:00
|
|
|
|
/* User writes limits */
|
|
|
|
|
struct spdk_ftl_limit limits[SPDK_FTL_LIMIT_MAX];
|
2019-04-10 17:37:52 +00:00
|
|
|
|
|
2019-05-23 13:43:21 +00:00
|
|
|
|
/* Allow for partial recovery from open bands instead of returning error */
|
|
|
|
|
bool allow_open_bands;
|
2019-05-29 07:22:34 +00:00
|
|
|
|
|
2019-10-17 13:40:50 +00:00
|
|
|
|
/* Use append instead of write */
|
|
|
|
|
bool use_append;
|
|
|
|
|
|
2020-01-24 11:02:21 +00:00
|
|
|
|
/* Maximum supported number of IO channels */
|
|
|
|
|
uint32_t max_io_channels;
|
|
|
|
|
|
2019-05-29 07:22:34 +00:00
|
|
|
|
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;
|
2020-02-06 11:58:20 +00:00
|
|
|
|
|
|
|
|
|
/* Create l2p table on l2p_path persistent memory file or device instead of in DRAM */
|
|
|
|
|
const char *l2p_path;
|
2018-10-29 11:29:03 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum spdk_ftl_mode {
|
|
|
|
|
/* Create new device */
|
|
|
|
|
SPDK_FTL_MODE_CREATE = (1 << 0),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct spdk_ftl_dev_init_opts {
|
2020-01-08 15:13:00 +00:00
|
|
|
|
/* Underlying device */
|
2020-01-13 13:52:47 +00:00
|
|
|
|
const char *base_bdev;
|
2019-03-15 16:37:44 +00:00
|
|
|
|
/* Write buffer cache */
|
2020-01-13 13:52:47 +00:00
|
|
|
|
const char *cache_bdev;
|
2018-10-29 11:29:03 +00:00
|
|
|
|
|
|
|
|
|
/* Thread responsible for core tasks execution */
|
|
|
|
|
struct spdk_thread *core_thread;
|
|
|
|
|
|
|
|
|
|
/* Device's config */
|
2019-04-19 08:40:12 +00:00
|
|
|
|
const struct spdk_ftl_conf *conf;
|
2018-10-29 11:29:03 +00:00
|
|
|
|
/* 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 */
|
2019-10-24 14:36:42 +00:00
|
|
|
|
uint64_t num_blocks;
|
2018-10-29 11:29:03 +00:00
|
|
|
|
/* Logical block size */
|
2019-10-24 14:36:42 +00:00
|
|
|
|
size_t block_size;
|
2020-01-13 13:52:47 +00:00
|
|
|
|
/* Underlying device */
|
|
|
|
|
const char *base_bdev;
|
2019-03-15 16:37:44 +00:00
|
|
|
|
/* Write buffer cache */
|
2020-01-13 13:52:47 +00:00
|
|
|
|
const char *cache_bdev;
|
2019-09-04 13:44:28 +00:00
|
|
|
|
/* 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;
|
2019-07-04 12:51:10 +00:00
|
|
|
|
/* Device specific configuration */
|
|
|
|
|
struct spdk_ftl_conf conf;
|
2018-10-29 11:29:03 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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:
|
2020-01-08 15:13:00 +00:00
|
|
|
|
* - retrieve zone device information,
|
2018-10-29 11:29:03 +00:00
|
|
|
|
* - 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.
|
|
|
|
|
*/
|
2019-06-24 13:46:26 +00:00
|
|
|
|
int spdk_ftl_dev_free(struct spdk_ftl_dev *dev, spdk_ftl_init_fn cb, void *cb_arg);
|
2018-10-29 11:29:03 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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 device’s attributes.
|
|
|
|
|
*
|
|
|
|
|
* \param dev device
|
|
|
|
|
* \param attr Attribute structure to fill
|
|
|
|
|
*/
|
2019-06-04 09:34:02 +00:00
|
|
|
|
void spdk_ftl_dev_get_attrs(const struct spdk_ftl_dev *dev, struct spdk_ftl_attrs *attr);
|
2018-10-29 11:29:03 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*
|
2019-02-05 11:37:26 +00:00
|
|
|
|
* \return 0 if successfully submitted, negative errno otherwise.
|
2018-10-29 11:29:03 +00:00
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
*
|
2019-02-05 11:37:26 +00:00
|
|
|
|
* \return 0 if successfully submitted, negative errno otherwise.
|
2018-10-29 11:29:03 +00:00
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
*
|
2019-02-05 11:37:26 +00:00
|
|
|
|
* \return 0 if successfully submitted, negative errno otherwise.
|
2018-10-29 11:29:03 +00:00
|
|
|
|
*/
|
|
|
|
|
int spdk_ftl_flush(struct spdk_ftl_dev *dev, spdk_ftl_fn cb_fn, void *cb_arg);
|
|
|
|
|
|
2019-07-05 11:35:13 +00:00
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-10-29 11:29:03 +00:00
|
|
|
|
#endif /* SPDK_FTL_H */
|