2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2022-11-01 20:26:26 +00:00
|
|
|
* Copyright (C) 2018 Intel Corporation.
|
2018-05-08 11:30:29 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SPDK_BDEV_RAID_INTERNAL_H
|
|
|
|
#define SPDK_BDEV_RAID_INTERNAL_H
|
|
|
|
|
|
|
|
#include "spdk/bdev_module.h"
|
|
|
|
|
2019-10-09 11:46:46 +00:00
|
|
|
enum raid_level {
|
|
|
|
INVALID_RAID_LEVEL = -1,
|
|
|
|
RAID0 = 0,
|
2022-04-27 09:18:05 +00:00
|
|
|
RAID5F = 95, /* 0x5f */
|
2022-02-01 06:46:20 +00:00
|
|
|
CONCAT = 99,
|
2019-10-09 11:46:46 +00:00
|
|
|
};
|
2019-09-27 14:35:37 +00:00
|
|
|
|
2018-05-08 11:30:29 +00:00
|
|
|
/*
|
|
|
|
* Raid state describes the state of the raid. This raid bdev can be either in
|
|
|
|
* configured list or configuring list
|
|
|
|
*/
|
|
|
|
enum raid_bdev_state {
|
|
|
|
/* raid bdev is ready and is seen by upper layers */
|
|
|
|
RAID_BDEV_STATE_ONLINE,
|
|
|
|
|
2018-10-08 04:04:34 +00:00
|
|
|
/*
|
|
|
|
* raid bdev is configuring, not all underlying bdevs are present.
|
|
|
|
* And can't be seen by upper layers.
|
|
|
|
*/
|
2018-05-08 11:30:29 +00:00
|
|
|
RAID_BDEV_STATE_CONFIGURING,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In offline state, raid bdev layer will complete all incoming commands without
|
|
|
|
* submitting to underlying base nvme bdevs
|
|
|
|
*/
|
|
|
|
RAID_BDEV_STATE_OFFLINE,
|
|
|
|
|
2022-11-03 13:25:30 +00:00
|
|
|
/* raid bdev state max, new states should be added before this */
|
|
|
|
RAID_BDEV_STATE_MAX
|
2018-05-08 11:30:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* raid_base_bdev_info contains information for the base bdevs which are part of some
|
|
|
|
* raid. This structure contains the per base bdev information. Whatever is
|
|
|
|
* required per base device for raid bdev will be kept here
|
|
|
|
*/
|
|
|
|
struct raid_base_bdev_info {
|
2022-08-26 11:02:27 +00:00
|
|
|
/* name of the bdev */
|
|
|
|
char *name;
|
|
|
|
|
2018-05-08 11:30:29 +00:00
|
|
|
/* pointer to base spdk bdev */
|
2018-08-20 23:01:56 +00:00
|
|
|
struct spdk_bdev *bdev;
|
2018-05-08 11:30:29 +00:00
|
|
|
|
|
|
|
/* pointer to base bdev descriptor opened by raid bdev */
|
2018-08-20 23:01:56 +00:00
|
|
|
struct spdk_bdev_desc *desc;
|
2018-05-08 11:30:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* When underlying base device calls the hot plug function on drive removal,
|
|
|
|
* this flag will be set and later after doing some processing, base device
|
|
|
|
* descriptor will be closed
|
|
|
|
*/
|
2018-08-20 23:01:56 +00:00
|
|
|
bool remove_scheduled;
|
2020-02-24 21:00:09 +00:00
|
|
|
|
|
|
|
/* thread where base device is opened */
|
|
|
|
struct spdk_thread *thread;
|
2018-05-08 11:30:29 +00:00
|
|
|
};
|
|
|
|
|
2019-09-05 22:39:10 +00:00
|
|
|
/*
|
|
|
|
* raid_bdev_io is the context part of bdev_io. It contains the information
|
|
|
|
* related to bdev_io for a raid bdev
|
|
|
|
*/
|
|
|
|
struct raid_bdev_io {
|
2019-10-10 10:07:02 +00:00
|
|
|
/* The raid bdev associated with this IO */
|
|
|
|
struct raid_bdev *raid_bdev;
|
|
|
|
|
2019-09-05 22:39:10 +00:00
|
|
|
/* WaitQ entry, used only in waitq logic */
|
|
|
|
struct spdk_bdev_io_wait_entry waitq_entry;
|
|
|
|
|
2019-10-10 09:23:01 +00:00
|
|
|
/* Context of the original channel for this IO */
|
|
|
|
struct raid_bdev_io_channel *raid_ch;
|
2019-09-05 22:39:10 +00:00
|
|
|
|
|
|
|
/* Used for tracking progress on io requests sent to member disks. */
|
2019-11-15 14:07:32 +00:00
|
|
|
uint64_t base_bdev_io_remaining;
|
2019-09-05 22:39:10 +00:00
|
|
|
uint8_t base_bdev_io_submitted;
|
|
|
|
uint8_t base_bdev_io_status;
|
2021-04-30 14:11:43 +00:00
|
|
|
|
|
|
|
/* Private data for the raid module */
|
|
|
|
void *module_private;
|
2019-09-05 22:39:10 +00:00
|
|
|
};
|
|
|
|
|
2018-05-08 11:30:29 +00:00
|
|
|
/*
|
2018-07-31 00:14:18 +00:00
|
|
|
* raid_bdev is the single entity structure which contains SPDK block device
|
|
|
|
* and the information related to any raid bdev either configured or
|
|
|
|
* in configuring list. io device is created on this.
|
2018-05-08 11:30:29 +00:00
|
|
|
*/
|
|
|
|
struct raid_bdev {
|
2018-07-31 00:14:18 +00:00
|
|
|
/* raid bdev device, this will get registered in bdev layer */
|
2019-08-07 01:53:53 +00:00
|
|
|
struct spdk_bdev bdev;
|
2018-07-31 00:14:18 +00:00
|
|
|
|
2018-05-08 11:30:29 +00:00
|
|
|
/* link of raid bdev to link it to global raid bdev list */
|
2019-08-07 01:53:53 +00:00
|
|
|
TAILQ_ENTRY(raid_bdev) global_link;
|
2018-05-08 11:30:29 +00:00
|
|
|
|
|
|
|
/* array of base bdev info */
|
2019-08-07 01:53:53 +00:00
|
|
|
struct raid_base_bdev_info *base_bdev_info;
|
2018-05-08 11:30:29 +00:00
|
|
|
|
|
|
|
/* strip size of raid bdev in blocks */
|
2019-08-07 01:53:53 +00:00
|
|
|
uint32_t strip_size;
|
2018-05-08 11:30:29 +00:00
|
|
|
|
2018-12-19 18:04:18 +00:00
|
|
|
/* strip size of raid bdev in KB */
|
2019-08-07 01:53:53 +00:00
|
|
|
uint32_t strip_size_kb;
|
2018-12-19 18:04:18 +00:00
|
|
|
|
2018-05-08 11:30:29 +00:00
|
|
|
/* strip size bit shift for optimized calculation */
|
2019-08-07 01:53:53 +00:00
|
|
|
uint32_t strip_size_shift;
|
2018-05-08 11:30:29 +00:00
|
|
|
|
|
|
|
/* block length bit shift for optimized calculation */
|
2019-08-07 01:53:53 +00:00
|
|
|
uint32_t blocklen_shift;
|
2018-05-08 11:30:29 +00:00
|
|
|
|
|
|
|
/* state of raid bdev */
|
2019-08-07 01:53:53 +00:00
|
|
|
enum raid_bdev_state state;
|
2018-05-08 11:30:29 +00:00
|
|
|
|
|
|
|
/* number of base bdevs comprising raid bdev */
|
2019-08-07 01:53:53 +00:00
|
|
|
uint8_t num_base_bdevs;
|
2018-05-08 11:30:29 +00:00
|
|
|
|
|
|
|
/* number of base bdevs discovered */
|
2019-08-07 01:53:53 +00:00
|
|
|
uint8_t num_base_bdevs_discovered;
|
2018-05-08 11:30:29 +00:00
|
|
|
|
|
|
|
/* Raid Level of this raid bdev */
|
2019-10-09 11:46:46 +00:00
|
|
|
enum raid_level level;
|
2018-05-08 11:30:29 +00:00
|
|
|
|
2019-04-11 02:56:30 +00:00
|
|
|
/* Set to true if destroy of this raid bdev is started. */
|
2019-08-07 01:53:53 +00:00
|
|
|
bool destroy_started;
|
2019-10-09 09:22:41 +00:00
|
|
|
|
|
|
|
/* Module for RAID-level specific operations */
|
|
|
|
struct raid_bdev_module *module;
|
2019-11-04 11:35:50 +00:00
|
|
|
|
|
|
|
/* Private data for the raid module */
|
|
|
|
void *module_private;
|
2018-05-08 11:30:29 +00:00
|
|
|
};
|
|
|
|
|
2019-11-05 09:32:18 +00:00
|
|
|
#define RAID_FOR_EACH_BASE_BDEV(r, i) \
|
|
|
|
for (i = r->base_bdev_info; i < r->base_bdev_info + r->num_base_bdevs; i++)
|
|
|
|
|
2018-05-08 11:30:29 +00:00
|
|
|
/*
|
|
|
|
* raid_bdev_io_channel is the context of spdk_io_channel for raid bdev device. It
|
|
|
|
* contains the relationship of raid bdev io channel with base bdev io channels.
|
|
|
|
*/
|
|
|
|
struct raid_bdev_io_channel {
|
|
|
|
/* Array of IO channels of base bdevs */
|
2019-08-06 23:53:26 +00:00
|
|
|
struct spdk_io_channel **base_channel;
|
|
|
|
|
|
|
|
/* Number of IO channels */
|
|
|
|
uint8_t num_channels;
|
2019-12-09 14:44:08 +00:00
|
|
|
|
|
|
|
/* Private raid module IO channel */
|
|
|
|
struct spdk_io_channel *module_channel;
|
2018-05-08 11:30:29 +00:00
|
|
|
};
|
|
|
|
|
2022-08-23 10:52:55 +00:00
|
|
|
/* TAIL head for raid bdev list */
|
2019-04-08 06:57:04 +00:00
|
|
|
TAILQ_HEAD(raid_all_tailq, raid_bdev);
|
|
|
|
|
|
|
|
extern struct raid_all_tailq g_raid_bdev_list;
|
2018-05-08 11:30:29 +00:00
|
|
|
|
2019-04-09 00:40:54 +00:00
|
|
|
typedef void (*raid_bdev_destruct_cb)(void *cb_ctx, int rc);
|
|
|
|
|
2022-08-26 11:02:27 +00:00
|
|
|
int raid_bdev_create(const char *name, uint32_t strip_size, uint8_t num_base_bdevs,
|
|
|
|
enum raid_level level, struct raid_bdev **raid_bdev_out);
|
|
|
|
void raid_bdev_delete(struct raid_bdev *raid_bdev, raid_bdev_destruct_cb cb_fn, void *cb_ctx);
|
|
|
|
int raid_bdev_add_base_device(struct raid_bdev *raid_bdev, const char *name, uint8_t slot);
|
|
|
|
struct raid_bdev *raid_bdev_find_by_name(const char *name);
|
2022-11-03 13:25:30 +00:00
|
|
|
enum raid_level raid_bdev_str_to_level(const char *str);
|
2019-10-09 11:46:46 +00:00
|
|
|
const char *raid_bdev_level_to_str(enum raid_level level);
|
2022-11-03 13:25:30 +00:00
|
|
|
enum raid_bdev_state raid_bdev_str_to_state(const char *str);
|
|
|
|
const char *raid_bdev_state_to_str(enum raid_bdev_state state);
|
2018-05-08 11:30:29 +00:00
|
|
|
|
2019-10-09 09:22:41 +00:00
|
|
|
/*
|
|
|
|
* RAID module descriptor
|
|
|
|
*/
|
|
|
|
struct raid_bdev_module {
|
|
|
|
/* RAID level implemented by this module */
|
|
|
|
enum raid_level level;
|
|
|
|
|
2019-11-07 08:19:19 +00:00
|
|
|
/* Minimum required number of base bdevs. Must be > 0. */
|
|
|
|
uint8_t base_bdevs_min;
|
|
|
|
|
2019-11-04 11:35:50 +00:00
|
|
|
/*
|
|
|
|
* Maximum number of base bdevs that can be removed without failing
|
|
|
|
* the array.
|
|
|
|
*/
|
|
|
|
uint8_t base_bdevs_max_degraded;
|
|
|
|
|
2019-10-29 13:31:51 +00:00
|
|
|
/*
|
|
|
|
* Called when the raid is starting, right before changing the state to
|
|
|
|
* online and registering the bdev. Parameters of the bdev like blockcnt
|
|
|
|
* should be set here.
|
|
|
|
*
|
|
|
|
* Non-zero return value will abort the startup process.
|
|
|
|
*/
|
|
|
|
int (*start)(struct raid_bdev *raid_bdev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when the raid is stopping, right before changing the state to
|
|
|
|
* offline and unregistering the bdev. Optional.
|
2022-09-27 14:08:08 +00:00
|
|
|
*
|
|
|
|
* The function should return false if it is asynchronous. Then, after
|
|
|
|
* the async operation has completed and the module is fully stopped
|
|
|
|
* raid_bdev_module_stop_done() must be called.
|
2019-10-29 13:31:51 +00:00
|
|
|
*/
|
2022-09-27 14:08:08 +00:00
|
|
|
bool (*stop)(struct raid_bdev *raid_bdev);
|
2019-10-29 13:31:51 +00:00
|
|
|
|
2019-10-10 12:24:07 +00:00
|
|
|
/* Handler for R/W requests */
|
|
|
|
void (*submit_rw_request)(struct raid_bdev_io *raid_io);
|
|
|
|
|
2020-01-28 11:15:10 +00:00
|
|
|
/* Handler for requests without payload (flush, unmap). Optional. */
|
2019-10-10 12:24:07 +00:00
|
|
|
void (*submit_null_payload_request)(struct raid_bdev_io *raid_io);
|
|
|
|
|
2019-12-09 14:44:08 +00:00
|
|
|
/*
|
|
|
|
* Called when the bdev's IO channel is created to get the module's private IO channel.
|
|
|
|
* Optional.
|
|
|
|
*/
|
|
|
|
struct spdk_io_channel *(*get_io_channel)(struct raid_bdev *raid_bdev);
|
|
|
|
|
2019-10-09 09:22:41 +00:00
|
|
|
TAILQ_ENTRY(raid_bdev_module) link;
|
|
|
|
};
|
|
|
|
|
|
|
|
void raid_bdev_module_list_add(struct raid_bdev_module *raid_module);
|
|
|
|
|
|
|
|
#define __RAID_MODULE_REGISTER(line) __RAID_MODULE_REGISTER_(line)
|
|
|
|
#define __RAID_MODULE_REGISTER_(line) raid_module_register_##line
|
|
|
|
|
|
|
|
#define RAID_MODULE_REGISTER(_module) \
|
|
|
|
__attribute__((constructor)) static void \
|
|
|
|
__RAID_MODULE_REGISTER(__LINE__)(void) \
|
|
|
|
{ \
|
|
|
|
raid_bdev_module_list_add(_module); \
|
|
|
|
}
|
|
|
|
|
2022-06-22 21:35:04 +00:00
|
|
|
bool raid_bdev_io_complete_part(struct raid_bdev_io *raid_io, uint64_t completed,
|
|
|
|
enum spdk_bdev_io_status status);
|
|
|
|
void raid_bdev_queue_io_wait(struct raid_bdev_io *raid_io, struct spdk_bdev *bdev,
|
|
|
|
struct spdk_io_channel *ch, spdk_bdev_io_wait_cb cb_fn);
|
|
|
|
void raid_bdev_io_complete(struct raid_bdev_io *raid_io, enum spdk_bdev_io_status status);
|
2022-09-27 14:08:08 +00:00
|
|
|
void raid_bdev_module_stop_done(struct raid_bdev *raid_bdev);
|
2019-10-08 10:33:15 +00:00
|
|
|
|
2018-10-29 02:45:42 +00:00
|
|
|
#endif /* SPDK_BDEV_RAID_INTERNAL_H */
|