| 1 | /*
|
|---|
| 2 | * Copyright (c) 2024 Miroslav Cimerman
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup libdevice
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /**
|
|---|
| 33 | * @file
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #ifndef LIBDEVICE_HR_H
|
|---|
| 37 | #define LIBDEVICE_HR_H
|
|---|
| 38 |
|
|---|
| 39 | #include <async.h>
|
|---|
| 40 | #include <errno.h>
|
|---|
| 41 | #include <loc.h>
|
|---|
| 42 |
|
|---|
| 43 | /* for now */
|
|---|
| 44 | #define HR_MAX_EXTENTS 4
|
|---|
| 45 | #define HR_MAX_HOTSPARES HR_MAX_EXTENTS
|
|---|
| 46 |
|
|---|
| 47 | #define HR_DEVNAME_LEN 32
|
|---|
| 48 |
|
|---|
| 49 | typedef enum hr_level {
|
|---|
| 50 | HR_LVL_0 = 0x00, /* striping, no redundancy */
|
|---|
| 51 | HR_LVL_1 = 0x01, /* n-way mirroring */
|
|---|
| 52 | HR_LVL_4 = 0x04, /* dedicated parity */
|
|---|
| 53 | HR_LVL_5 = 0x05, /* distributed parity */
|
|---|
| 54 | HR_LVL_UNKNOWN = 0xFF
|
|---|
| 55 | } hr_level_t;
|
|---|
| 56 |
|
|---|
| 57 | /*
|
|---|
| 58 | * SNIA
|
|---|
| 59 | * Common RAID Disk Data Format
|
|---|
| 60 | * Specification
|
|---|
| 61 | * Version 2.0 Revision 19
|
|---|
| 62 | */
|
|---|
| 63 | #define HR_RLQ_RAID4_0 0x00 /* RAID-4 Non-Rotating Parity 0 */
|
|---|
| 64 | #define HR_RLQ_RAID4_N 0x01 /* RAID-4 Non-Rotating Parity N */
|
|---|
| 65 | #define HR_RLQ_RAID5_0R 0x00 /* RAID-5 Rotating Parity 0 with Data Restart */
|
|---|
| 66 | #define HR_RLQ_RAID5_NR 0x02 /* RAID-5 Rotating Parity N with Data Restart */
|
|---|
| 67 | #define HR_RLQ_RAID5_NC 0x03 /* RAID-5 Rotating Parity N with Data Continuation */
|
|---|
| 68 |
|
|---|
| 69 | typedef enum hr_vol_status {
|
|---|
| 70 | HR_VOL_INVALID,
|
|---|
| 71 | HR_VOL_ONLINE, /* OPTIMAL */
|
|---|
| 72 | HR_VOL_FAULTY,
|
|---|
| 73 | HR_VOL_DEGRADED, /* also used for partial, but usable mirror */
|
|---|
| 74 | HR_VOL_REBUILD
|
|---|
| 75 | } hr_vol_status_t;
|
|---|
| 76 |
|
|---|
| 77 | typedef enum hr_ext_status {
|
|---|
| 78 | HR_EXT_INVALID,
|
|---|
| 79 | HR_EXT_ONLINE, /* OK */
|
|---|
| 80 | HR_EXT_MISSING,
|
|---|
| 81 | HR_EXT_FAILED,
|
|---|
| 82 | HR_EXT_REBUILD,
|
|---|
| 83 | HR_EXT_HOTSPARE
|
|---|
| 84 | } hr_ext_status_t;
|
|---|
| 85 |
|
|---|
| 86 | typedef struct hr {
|
|---|
| 87 | async_sess_t *sess;
|
|---|
| 88 | } hr_t;
|
|---|
| 89 |
|
|---|
| 90 | typedef struct hr_config {
|
|---|
| 91 | char devname[HR_DEVNAME_LEN];
|
|---|
| 92 | service_id_t devs[HR_MAX_EXTENTS];
|
|---|
| 93 | size_t dev_no;
|
|---|
| 94 | hr_level_t level;
|
|---|
| 95 | } hr_config_t;
|
|---|
| 96 |
|
|---|
| 97 | typedef struct hr_extent {
|
|---|
| 98 | service_id_t svc_id;
|
|---|
| 99 | hr_ext_status_t status;
|
|---|
| 100 | } hr_extent_t;
|
|---|
| 101 |
|
|---|
| 102 | typedef struct hr_vol_info {
|
|---|
| 103 | hr_extent_t extents[HR_MAX_EXTENTS];
|
|---|
| 104 | hr_extent_t hotspares[HR_MAX_HOTSPARES];
|
|---|
| 105 | size_t extent_no;
|
|---|
| 106 | size_t hotspare_no;
|
|---|
| 107 | service_id_t svc_id;
|
|---|
| 108 | hr_level_t level;
|
|---|
| 109 | uint64_t nblocks;
|
|---|
| 110 | uint32_t strip_size;
|
|---|
| 111 | size_t bsize;
|
|---|
| 112 | hr_vol_status_t status;
|
|---|
| 113 | uint8_t layout;
|
|---|
| 114 | } hr_vol_info_t;
|
|---|
| 115 |
|
|---|
| 116 | extern errno_t hr_sess_init(hr_t **);
|
|---|
| 117 | extern void hr_sess_destroy(hr_t *);
|
|---|
| 118 |
|
|---|
| 119 | extern errno_t hr_create(hr_t *, hr_config_t *, bool);
|
|---|
| 120 | extern errno_t hr_stop(const char *, long);
|
|---|
| 121 | extern errno_t hr_add_hotspare(service_id_t, service_id_t);
|
|---|
| 122 | extern errno_t hr_print_status(void);
|
|---|
| 123 |
|
|---|
| 124 | extern const char *hr_get_vol_status_msg(hr_vol_status_t);
|
|---|
| 125 | extern const char *hr_get_ext_status_msg(hr_ext_status_t);
|
|---|
| 126 | extern const char *hr_get_layout_str(hr_level_t, uint8_t);
|
|---|
| 127 |
|
|---|
| 128 | #endif
|
|---|
| 129 |
|
|---|
| 130 | /** @}
|
|---|
| 131 | */
|
|---|