source: mainline/uspace/lib/device/include/hr.h@ d082801

Last change on this file since d082801 was d082801, checked in by Miroslav Cimerman <mc@…>, 4 months ago

hr: refactor manual assembly

  • Property mode set to 100644
File size: 4.0 KB
Line 
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
49typedef 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
69typedef enum hr_vol_status {
70 HR_VOL_NONE = 0, /* Unknown/None */
71 HR_VOL_ONLINE, /* optimal */
72 HR_VOL_FAULTY, /* unusable */
73 HR_VOL_DEGRADED, /* not optimal */
74 HR_VOL_REBUILD /* rebuild in progress */
75} hr_vol_status_t;
76
77typedef enum hr_ext_status {
78 HR_EXT_NONE = 0, /* unknown/none status */
79 HR_EXT_INVALID, /* working but not consistent */
80 HR_EXT_ONLINE, /* ok */
81 HR_EXT_MISSING, /* offline */
82 HR_EXT_FAILED,
83 HR_EXT_REBUILD,
84 HR_EXT_HOTSPARE
85} hr_ext_status_t;
86
87typedef struct hr {
88 async_sess_t *sess;
89} hr_t;
90
91typedef struct hr_config {
92 char devname[HR_DEVNAME_LEN];
93 service_id_t devs[HR_MAX_EXTENTS];
94 size_t dev_no;
95 hr_level_t level;
96} hr_config_t;
97
98typedef struct hr_extent {
99 service_id_t svc_id;
100 hr_ext_status_t status;
101} hr_extent_t;
102
103typedef struct hr_vol_info {
104 hr_extent_t extents[HR_MAX_EXTENTS];
105 hr_extent_t hotspares[HR_MAX_HOTSPARES];
106 size_t extent_no;
107 size_t hotspare_no;
108 service_id_t svc_id;
109 hr_level_t level;
110 uint64_t nblocks;
111 uint32_t strip_size;
112 size_t bsize;
113 hr_vol_status_t status;
114 uint8_t layout;
115} hr_vol_info_t;
116
117extern errno_t hr_sess_init(hr_t **);
118extern void hr_sess_destroy(hr_t *);
119extern errno_t hr_create(hr_t *, hr_config_t *);
120extern errno_t hr_assemble(hr_t *, hr_config_t *, size_t *);
121extern errno_t hr_auto_assemble(size_t *);
122extern errno_t hr_stop(const char *, long);
123extern errno_t hr_add_hotspare(service_id_t, service_id_t);
124extern errno_t hr_print_status(void);
125extern const char *hr_get_vol_status_msg(hr_vol_status_t);
126extern const char *hr_get_ext_status_msg(hr_ext_status_t);
127extern const char *hr_get_layout_str(hr_level_t, uint8_t);
128
129#endif
130
131/** @}
132 */
Note: See TracBrowser for help on using the repository browser.