2 * bl-device-discovery.h
4 * Copyright (c) 2010 EMC Corporation, Haiying Tang <Tang_Haiying@emc.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
27 #ifndef BL_DEVICE_DISCOVERY_H
28 #define BL_DEVICE_DISCOVERY_H
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,
40 /* All disk offset/lengths are stored in 512-byte sectors */
44 struct bl_volume **bv_vols;
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 */
54 int64_t bs_offset; /* In bytes */
55 uint32_t bs_length; /* In bytes */
59 /* Maximum number of signatures components in a simple volume */
60 # define BLOCK_MAX_SIG_COMP 16
64 struct bl_sig_comp si_comps[BLOCK_MAX_SIG_COMP];
68 * Multipath support: ACTIVE or PSEUDO device is valid,
69 * PASSIVE is a standby for ACTIVE.
71 enum bl_path_state_e {
72 BL_PATH_STATE_PASSIVE = 1,
73 BL_PATH_STATE_ACTIVE = 2,
74 BL_PATH_STATE_PSEUDO = 3,
83 struct bl_disk_path *next;
85 enum bl_path_state_e state;
90 struct bl_serial *serial;
92 off_t size; /* in 512-byte sectors */
93 struct bl_disk_path *valid_path;
94 struct bl_disk_path *paths;
100 unsigned char reserve;
107 uint32_t major, minor;
110 struct bl_pipemsg_hdr {
112 uint16_t totallen; /* length of message excluding hdr */
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 */
121 uint32_t *blk_overflow(uint32_t * p, uint32_t * end, size_t nbytes);
123 #define BLK_READBUF(p, e, nbytes) do { \
124 p = blk_overflow(p, e, nbytes); \
130 #define READ32(x) (x) = ntohl(*p++)
132 #define READ64(x) do { \
133 (x) = (uint64_t)ntohl(*p++) << 32; \
134 (x) |= ntohl(*p++); \
137 #define READ_SECTOR(x) do { \
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);
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);
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)