1 | /*
|
---|
2 | * Copyright (c) 2025 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 | typedef enum hr_layout {
|
---|
58 | HR_RLQ_NONE = 0,
|
---|
59 | HR_RLQ_RAID4_0, /* RAID-4 Non-Rotating Parity 0 */
|
---|
60 | HR_RLQ_RAID4_N, /* RAID-4 Non-Rotating Parity N */
|
---|
61 | HR_RLQ_RAID5_0R, /* RAID-5 Rotating Parity 0 with Data Restart */
|
---|
62 | HR_RLQ_RAID5_NR, /* RAID-5 Rotating Parity N with Data Restart */
|
---|
63 | HR_RLQ_RAID5_NC /* RAID-5 Rotating Parity N with Data Continuation */
|
---|
64 | } hr_layout_t;
|
---|
65 |
|
---|
66 | typedef enum hr_vol_status {
|
---|
67 | HR_VOL_NONE = 0, /* Unknown/None */
|
---|
68 | HR_VOL_ONLINE, /* optimal */
|
---|
69 | HR_VOL_FAULTY, /* unusable */
|
---|
70 | HR_VOL_DEGRADED, /* not optimal */
|
---|
71 | HR_VOL_REBUILD /* rebuild in progress */
|
---|
72 | } hr_vol_status_t;
|
---|
73 |
|
---|
74 | typedef enum hr_ext_status {
|
---|
75 | HR_EXT_NONE = 0, /* unknown/none status */
|
---|
76 | HR_EXT_INVALID, /* working but not consistent */
|
---|
77 | HR_EXT_ONLINE, /* ok */
|
---|
78 | HR_EXT_MISSING, /* offline */
|
---|
79 | HR_EXT_FAILED,
|
---|
80 | HR_EXT_REBUILD,
|
---|
81 | HR_EXT_HOTSPARE
|
---|
82 | } hr_ext_status_t;
|
---|
83 |
|
---|
84 | typedef struct hr {
|
---|
85 | async_sess_t *sess;
|
---|
86 | } hr_t;
|
---|
87 |
|
---|
88 | typedef struct hr_config {
|
---|
89 | char devname[HR_DEVNAME_LEN];
|
---|
90 | service_id_t devs[HR_MAX_EXTENTS];
|
---|
91 | size_t dev_no;
|
---|
92 | hr_level_t level;
|
---|
93 | } hr_config_t;
|
---|
94 |
|
---|
95 | typedef struct hr_extent {
|
---|
96 | service_id_t svc_id;
|
---|
97 | hr_ext_status_t status;
|
---|
98 | } hr_extent_t;
|
---|
99 |
|
---|
100 | typedef struct hr_vol_info {
|
---|
101 | hr_extent_t extents[HR_MAX_EXTENTS];
|
---|
102 | hr_extent_t hotspares[HR_MAX_HOTSPARES];
|
---|
103 | size_t extent_no;
|
---|
104 | size_t hotspare_no;
|
---|
105 | service_id_t svc_id;
|
---|
106 | hr_level_t level;
|
---|
107 | uint64_t nblocks;
|
---|
108 | uint32_t strip_size;
|
---|
109 | size_t bsize;
|
---|
110 | hr_vol_status_t status;
|
---|
111 | uint8_t layout;
|
---|
112 | } hr_vol_info_t;
|
---|
113 |
|
---|
114 | typedef enum {
|
---|
115 | HR_METADATA_NATIVE = 0,
|
---|
116 | HR_METADATA_GEOM_MIRROR,
|
---|
117 | HR_METADATA_GEOM_STRIPE,
|
---|
118 | HR_METADATA_SOFTRAID,
|
---|
119 | HR_METADATA_LAST_DUMMY
|
---|
120 | } hr_metadata_type_t;
|
---|
121 |
|
---|
122 | extern errno_t hr_sess_init(hr_t **);
|
---|
123 | extern void hr_sess_destroy(hr_t *);
|
---|
124 | extern errno_t hr_create(hr_t *, hr_config_t *);
|
---|
125 | extern errno_t hr_assemble(hr_t *, hr_config_t *, size_t *);
|
---|
126 | extern errno_t hr_auto_assemble(hr_t *, size_t *);
|
---|
127 | extern errno_t hr_stop(hr_t *, const char *);
|
---|
128 | extern errno_t hr_stop_all(hr_t *);
|
---|
129 | extern errno_t hr_fail_extent(hr_t *, const char *, unsigned long);
|
---|
130 | extern errno_t hr_add_hotspare(hr_t *, const char *, const char *);
|
---|
131 | extern errno_t hr_print_status(hr_t *);
|
---|
132 | extern const char *hr_get_vol_status_msg(hr_vol_status_t);
|
---|
133 | extern const char *hr_get_ext_status_msg(hr_ext_status_t);
|
---|
134 | extern const char *hr_get_layout_str(hr_layout_t);
|
---|
135 | extern const char *hr_get_metadata_type_str(hr_metadata_type_t);
|
---|
136 |
|
---|
137 | #endif
|
---|
138 |
|
---|
139 | /** @}
|
---|
140 | */
|
---|