History

ublk_drv: add SET_PARAMS/GET_PARAMS control command

Add two commands to set/get parameters generically. One important goal of ublk is to provide generic framework for making block device by userspace flexibly. As one generic block device, there are still lots of block parameters, such as max_sectors, write_cache/fua, discard related limits, zoned parameters, ...., so this patch starts to add generic mechanism for set/get device parameters. Both generic block parameters(all kinds of queue settings) and ublk feature parameters can be covered with this way, then it becomes quite easy to extend in future. Add two parameter types are used so far: basic(covers basic queue setting and misc settings which can't be grouped easily) and discard, basic type must be set, and discard type becomes optional now This way provides mechanism to simulate any kind of generic block device from userspace easily, from both block queue setting viewpoint or ublk feature viewpoint. The style of putting all parameters together is suggested by Christoph.

Ming Lei committed 4 years ago

Commit 0aa73171 parent 93d71ec2 files · +234 −18Browse files

Showing the changes to include/uapi (1 of 2 files). Show all

Unified · Split

include/uapi/linux/ublk_cmd.h+47−0
@@ -15,6 +15,8 @@ · 14 unmodified lines
15#define UBLK_CMD_DEL_DEV 0x0515#define UBLK_CMD_DEL_DEV 0x05
16#define UBLK_CMD_START_DEV 0x0616#define UBLK_CMD_START_DEV 0x06
17#define UBLK_CMD_STOP_DEV 0x0717#define UBLK_CMD_STOP_DEV 0x07
18#define UBLK_CMD_SET_PARAMS 0x08
19#define UBLK_CMD_GET_PARAMS 0x09
18 20
19/*21/*
20 * IO commands, issued by ublk server, and handled by ublk driver.22 * IO commands, issued by ublk server, and handled by ublk driver.
@@ -158,4 +160,49 @@ struct ublksrv_io_cmd { · 137 unmodified lines
158 __u64 addr;160 __u64 addr;
159};161};
160 162
163struct ublk_param_basic {
164#define UBLK_ATTR_READ_ONLY (1 << 0)
165#define UBLK_ATTR_ROTATIONAL (1 << 1)
166#define UBLK_ATTR_VOLATILE_CACHE (1 << 2)
167#define UBLK_ATTR_FUA (1 << 3)
168 __u32 attrs;
169 __u8 logical_bs_shift;
170 __u8 physical_bs_shift;
171 __u8 io_opt_shift;
172 __u8 io_min_shift;
173
174 __u32 max_sectors;
175 __u32 chunk_sectors;
176
177 __u64 dev_sectors;
178 __u64 virt_boundary_mask;
179};
180
181struct ublk_param_discard {
182 __u32 discard_alignment;
183
184 __u32 discard_granularity;
185 __u32 max_discard_sectors;
186
187 __u32 max_write_zeroes_sectors;
188 __u16 max_discard_segments;
189 __u16 reserved0;
190};
191
192struct ublk_params {
193 /*
194 * Total length of parameters, userspace has to set 'len' for both
195 * SET_PARAMS and GET_PARAMS command, and driver may update len
196 * if two sides use different version of 'ublk_params', same with
197 * 'types' fields.
198 */
199 __u32 len;
200#define UBLK_PARAM_TYPE_BASIC (1 << 0)
201#define UBLK_PARAM_TYPE_DISCARD (1 << 1)
202 __u32 types; /* types of parameter included */
203
204 struct ublk_param_basic basic;
205 struct ublk_param_discard discard;
206};
207
161#endif208#endif