]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/blkmapd/device-discovery.h
Merge branch 'sid'
[nfs-utils.git] / utils / blkmapd / device-discovery.h
1 /*
2  * bl-device-discovery.h
3  *
4  * Copyright (c) 2010 EMC Corporation, Haiying Tang <Tang_Haiying@emc.com>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 #ifndef BL_DEVICE_DISCOVERY_H
28 #define BL_DEVICE_DISCOVERY_H
29
30 #include <stdint.h>
31
32 enum blk_vol_type {
33         BLOCK_VOLUME_SIMPLE = 0,        /* maps to a single LU */
34         BLOCK_VOLUME_SLICE = 1,         /* slice of another volume */
35         BLOCK_VOLUME_CONCAT = 2,        /* concatenation of multiple volumes */
36         BLOCK_VOLUME_STRIPE = 3,        /* striped across multiple volumes */
37         BLOCK_VOLUME_PSEUDO = 4,
38 };
39
40 /* All disk offset/lengths are stored in 512-byte sectors */
41 struct bl_volume {
42         uint32_t bv_type;
43         off_t bv_size;
44         struct bl_volume **bv_vols;
45         int bv_vol_n;
46         union {
47                 dev_t bv_dev;           /* for BLOCK_VOLUME_SIMPLE(PSEUDO) */
48                 off_t bv_stripe_unit;   /* for BLOCK_VOLUME_STRIPE(CONCAT) */
49                 off_t bv_offset;        /* for BLOCK_VOLUME_SLICE */
50         } param;
51 };
52
53 struct bl_sig_comp {
54         int64_t bs_offset;              /* In bytes */
55         uint32_t bs_length;             /* In bytes */
56         char *bs_string;
57 };
58
59 /* Maximum number of signatures components in a simple volume */
60 # define BLOCK_MAX_SIG_COMP 16
61
62 struct bl_sig {
63         int si_num_comps;
64         struct bl_sig_comp si_comps[BLOCK_MAX_SIG_COMP];
65 };
66
67 /*
68  * Multipath support: ACTIVE or PSEUDO device is valid,
69  *                    PASSIVE is a standby for ACTIVE.
70  */
71 enum bl_path_state_e {
72         BL_PATH_STATE_PASSIVE = 1,
73         BL_PATH_STATE_ACTIVE = 2,
74         BL_PATH_STATE_PSEUDO = 3,
75 };
76
77 struct bl_serial {
78         int len;
79         char *data;
80 };
81
82 struct bl_disk_path {
83         struct bl_disk_path *next;
84         char *full_path;
85         enum bl_path_state_e state;
86 };
87
88 struct bl_disk {
89         struct bl_disk *next;
90         struct bl_serial *serial;
91         dev_t dev;
92         off_t size;                     /* in 512-byte sectors */
93         struct bl_disk_path *valid_path;
94         struct bl_disk_path *paths;
95 };
96
97 struct bl_dev_id {
98         unsigned char type;
99         unsigned char ids;
100         unsigned char reserve;
101         unsigned char len;
102         char data[0];
103 };
104
105 struct bl_dev_msg {
106         int status;
107         uint32_t major, minor;
108 };
109
110 struct bl_pipemsg_hdr {
111         uint8_t type;
112         uint16_t totallen;              /* length of message excluding hdr */
113 };
114
115 #define BL_DEVICE_UMOUNT                0x0     /* Umount--delete devices */
116 #define BL_DEVICE_MOUNT                 0x1     /* Mount--create devices */
117 #define BL_DEVICE_REQUEST_INIT          0x0     /* Start request */
118 #define BL_DEVICE_REQUEST_PROC          0x1     /* User process succeeds */
119 #define BL_DEVICE_REQUEST_ERR           0x2     /* User process fails */
120
121 uint32_t *blk_overflow(uint32_t * p, uint32_t * end, size_t nbytes);
122
123 #define BLK_READBUF(p, e, nbytes)  do { \
124         p = blk_overflow(p, e, nbytes); \
125         if (!p) {\
126                 goto out_err;\
127         } \
128 } while (0)
129
130 #define READ32(x)         (x) = ntohl(*p++)
131
132 #define READ64(x)         do {                  \
133         (x) = (uint64_t)ntohl(*p++) << 32;           \
134         (x) |= ntohl(*p++);                     \
135 } while (0)
136
137 #define READ_SECTOR(x)     do { \
138         READ64(tmp); \
139         if (tmp & 0x1ff) { \
140                 goto out_err; \
141         } \
142         (x) = tmp >> 9; \
143 } while (0)
144
145 extern struct bl_disk *visible_disk_list;
146 uint64_t dm_device_create(struct bl_volume *vols, int num_vols);
147 int dm_device_remove_all(uint64_t *dev);
148 uint64_t process_deviceinfo(const char *dev_addr_buf,
149                             unsigned int dev_addr_len,
150                             uint32_t *major, uint32_t *minor);
151
152 extern ssize_t atomicio(ssize_t(*f) (int, void *, size_t),
153                         int fd, void *_s, size_t n);
154 extern struct bl_serial *bldev_read_serial(int fd, const char *filename);
155 extern enum bl_path_state_e bldev_read_ap_state(int fd);
156 extern int bl_discover_devices(void);
157
158 #define BL_LOG_INFO(fmt...)             syslog(LOG_INFO, fmt)
159 #define BL_LOG_WARNING(fmt...)          syslog(LOG_WARNING, fmt)
160 #define BL_LOG_ERR(fmt...)              syslog(LOG_ERR, fmt)
161 #define BL_LOG_DEBUG(fmt...)            syslog(LOG_DEBUG, fmt)
162 #endif