FreeBSD/Linux Kernel Cross Reference
sys/geom/gate/g_gate.h
1 /*-
2 * Copyright (c) 2004-2009 Pawel Jakub Dawidek <pjd@FreeBSD.org>
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 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28
29 #ifndef _G_GATE_H_
30 #define _G_GATE_H_
31
32 #include <sys/param.h>
33 #include <sys/lock.h>
34 #include <sys/mutex.h>
35 #include <sys/queue.h>
36
37 #include <geom/geom.h>
38
39 #define G_GATE_CLASS_NAME "GATE"
40 #define G_GATE_PROVIDER_NAME "ggate"
41 #define G_GATE_MOD_NAME "ggate"
42 #define G_GATE_CTL_NAME "ggctl"
43
44 #define G_GATE_VERSION 3
45
46 /*
47 * Maximum number of request that can be stored in
48 * the queue when there are no workers.
49 */
50 #define G_GATE_MAX_QUEUE_SIZE 4096
51
52 #define G_GATE_FLAG_READONLY 0x0001
53 #define G_GATE_FLAG_WRITEONLY 0x0002
54 #define G_GATE_FLAG_DESTROY 0x1000
55 #define G_GATE_USERFLAGS (G_GATE_FLAG_READONLY | G_GATE_FLAG_WRITEONLY)
56
57 /*
58 * Pick unit number automatically in /dev/ggate<unit>.
59 */
60 #define G_GATE_UNIT_AUTO (-1)
61 /*
62 * Full provider name is given, so don't use ggate<unit>.
63 */
64 #define G_GATE_NAME_GIVEN (-2)
65
66 #define G_GATE_CMD_CREATE _IOWR('m', 0, struct g_gate_ctl_create)
67 #define G_GATE_CMD_MODIFY _IOWR('m', 1, struct g_gate_ctl_modify)
68 #define G_GATE_CMD_DESTROY _IOWR('m', 2, struct g_gate_ctl_destroy)
69 #define G_GATE_CMD_CANCEL _IOWR('m', 3, struct g_gate_ctl_cancel)
70 #define G_GATE_CMD_START _IOWR('m', 4, struct g_gate_ctl_io)
71 #define G_GATE_CMD_DONE _IOWR('m', 5, struct g_gate_ctl_io)
72
73 #define G_GATE_INFOSIZE 2048
74
75 #ifdef _KERNEL
76 /*
77 * 'P:' means 'Protected by'.
78 */
79 struct g_gate_softc {
80 char *sc_name; /* P: (read-only) */
81 int sc_unit; /* P: (read-only) */
82 int sc_ref; /* P: g_gate_list_mtx */
83 struct g_provider *sc_provider; /* P: (read-only) */
84 uint32_t sc_flags; /* P: sc_queue_mtx */
85
86 struct bio_queue_head sc_inqueue; /* P: sc_queue_mtx */
87 struct bio_queue_head sc_outqueue; /* P: sc_queue_mtx */
88 struct mtx sc_queue_mtx;
89 uint32_t sc_queue_count; /* P: sc_queue_mtx */
90 uint32_t sc_queue_size; /* P: (read-only) */
91 u_int sc_timeout; /* P: (read-only) */
92 struct g_consumer *sc_readcons; /* P: sc_read_mtx */
93 off_t sc_readoffset; /* P: sc_read_mtx */
94 struct callout sc_callout; /* P: (modified only
95 from callout
96 thread) */
97 uintptr_t sc_seq; /* P: sc_queue_mtx */
98 LIST_ENTRY(g_gate_softc) sc_next; /* P: g_gate_list_mtx */
99 char sc_info[G_GATE_INFOSIZE]; /* P: (read-only) */
100 struct mtx sc_read_mtx;
101 };
102
103 #define G_GATE_DEBUG(lvl, ...) do { \
104 if (g_gate_debug >= (lvl)) { \
105 printf("GEOM_GATE"); \
106 if (g_gate_debug > 0) \
107 printf("[%u]", lvl); \
108 printf(": "); \
109 printf(__VA_ARGS__); \
110 printf("\n"); \
111 } \
112 } while (0)
113 #define G_GATE_LOGREQ(lvl, bp, ...) do { \
114 if (g_gate_debug >= (lvl)) { \
115 printf("GEOM_GATE"); \
116 if (g_gate_debug > 0) \
117 printf("[%u]", lvl); \
118 printf(": "); \
119 printf(__VA_ARGS__); \
120 printf(" "); \
121 g_print_bio(bp); \
122 printf("\n"); \
123 } \
124 } while (0)
125 #endif /* !_KERNEL */
126
127 struct g_gate_ctl_create {
128 u_int gctl_version;
129 off_t gctl_mediasize;
130 u_int gctl_sectorsize;
131 u_int gctl_flags;
132 u_int gctl_maxcount;
133 u_int gctl_timeout;
134 char gctl_name[NAME_MAX];
135 char gctl_info[G_GATE_INFOSIZE];
136 char gctl_readprov[NAME_MAX];
137 off_t gctl_readoffset;
138 int gctl_unit; /* in/out */
139 };
140
141 #define GG_MODIFY_MEDIASIZE 0x01
142 #define GG_MODIFY_INFO 0x02
143 #define GG_MODIFY_READPROV 0x04
144 #define GG_MODIFY_READOFFSET 0x08
145 struct g_gate_ctl_modify {
146 u_int gctl_version;
147 int gctl_unit;
148 uint32_t gctl_modify;
149 off_t gctl_mediasize;
150 char gctl_info[G_GATE_INFOSIZE];
151 char gctl_readprov[NAME_MAX];
152 off_t gctl_readoffset;
153 };
154
155 struct g_gate_ctl_destroy {
156 u_int gctl_version;
157 int gctl_unit;
158 int gctl_force;
159 char gctl_name[NAME_MAX];
160 };
161
162 struct g_gate_ctl_cancel {
163 u_int gctl_version;
164 int gctl_unit;
165 uintptr_t gctl_seq;
166 char gctl_name[NAME_MAX];
167 };
168
169 struct g_gate_ctl_io {
170 u_int gctl_version;
171 int gctl_unit;
172 uintptr_t gctl_seq;
173 u_int gctl_cmd;
174 off_t gctl_offset;
175 off_t gctl_length;
176 void *gctl_data;
177 int gctl_error;
178 };
179 #endif /* !_G_GATE_H_ */
Cache object: 0fdea23d87f80afeaf23bb3a971c9be2
|