History

virtio-blk: add support for zoned block devices

This patch adds support for Zoned Block Devices (ZBDs) to the kernel virtio-blk driver. The patch accompanies the virtio-blk ZBD support draft that is now being proposed for standardization. The latest version of the draft is linked at https://github.com/oasis-tcs/virtio-spec/issues/143 . The QEMU zoned device code that implements these protocol extensions has been developed by Sam Li and it is currently in review at the QEMU mailing list. A number of virtblk request structure changes has been introduced to accommodate the functionality that is specific to zoned block devices and, most importantly, make room for carrying the Zoned Append sector value from the device back to the driver along with the request status. The zone-specific code in the patch is heavily influenced by NVMe ZNS code in drivers/nvme/host/zns.c, but it is simpler because the proposed virtio ZBD draft only covers the zoned device features that are relevant to the zoned functionality provided by Linux block layer. includes the following fixup: virtio-blk: fix probe without CONFIG_BLK_DEV_ZONED When building without CONFIG_BLK_DEV_ZONED, VIRTIO_BLK_F_ZONED is excluded from array of driver features. As a result virtio_has_feature panics in virtio_check_driver_offered_feature since that by design verifies that a feature we are checking for is listed in the feature array. To fix, replace the call to virtio_has_feature with a stub.

Dmitry Fomichev committed 4 years ago

Commit 95bfec41 parent d16c0cd2 files · +474 −18Browse files

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

Unified · Split

include/uapi/linux/virtio_blk.h+105−0
@@ -41,6 +41,7 @@ · 40 unmodified lines
4141 #define VIRTIO_BLK_F_DISCARD 13 /* DISCARD is supported */
4242 #define VIRTIO_BLK_F_WRITE_ZEROES 14 /* WRITE ZEROES is supported */
4343 #define VIRTIO_BLK_F_SECURE_ERASE 16 /* Secure Erase is supported */
44+#define VIRTIO_BLK_F_ZONED 17 /* Zoned block device */
4445
4546 /* Legacy feature bits */
4647 #ifndef VIRTIO_BLK_NO_LEGACY
@@ -137,6 +138,16 @@ struct virtio_blk_config { · 90 unmodified lines
137138 /* Secure erase commands must be aligned to this number of sectors. */
138139 __virtio32 secure_erase_sector_alignment;
139140
141+ /* Zoned block device characteristics (if VIRTIO_BLK_F_ZONED) */
142+ struct virtio_blk_zoned_characteristics {
143+ __virtio32 zone_sectors;
144+ __virtio32 max_open_zones;
145+ __virtio32 max_active_zones;
146+ __virtio32 max_append_sectors;
147+ __virtio32 write_granularity;
148+ __u8 model;
149+ __u8 unused2[3];
150+ } zoned;
140151 } __attribute__((packed));
141152
142153 /*
@@ -174,6 +185,27 @@ struct virtio_blk_config { · 31 unmodified lines
174185 /* Secure erase command */
175186 #define VIRTIO_BLK_T_SECURE_ERASE 14
176187
188+/* Zone append command */
189+#define VIRTIO_BLK_T_ZONE_APPEND 15
190+
191+/* Report zones command */
192+#define VIRTIO_BLK_T_ZONE_REPORT 16
193+
194+/* Open zone command */
195+#define VIRTIO_BLK_T_ZONE_OPEN 18
196+
197+/* Close zone command */
198+#define VIRTIO_BLK_T_ZONE_CLOSE 20
199+
200+/* Finish zone command */
201+#define VIRTIO_BLK_T_ZONE_FINISH 22
202+
203+/* Reset zone command */
204+#define VIRTIO_BLK_T_ZONE_RESET 24
205+
206+/* Reset All zones command */
207+#define VIRTIO_BLK_T_ZONE_RESET_ALL 26
208+
177209 #ifndef VIRTIO_BLK_NO_LEGACY
178210 /* Barrier before this op. */
179211 #define VIRTIO_BLK_T_BARRIER 0x80000000
@@ -193,6 +225,72 @@ struct virtio_blk_outhdr { · 13 unmodified lines
193225 __virtio64 sector;
194226 };
195227
228+/*
229+ * Supported zoned device models.
230+ */
231+
232+/* Regular block device */
233+#define VIRTIO_BLK_Z_NONE 0
234+/* Host-managed zoned device */
235+#define VIRTIO_BLK_Z_HM 1
236+/* Host-aware zoned device */
237+#define VIRTIO_BLK_Z_HA 2
238+
239+/*
240+ * Zone descriptor. A part of VIRTIO_BLK_T_ZONE_REPORT command reply.
241+ */
242+struct virtio_blk_zone_descriptor {
243+ /* Zone capacity */
244+ __virtio64 z_cap;
245+ /* The starting sector of the zone */
246+ __virtio64 z_start;
247+ /* Zone write pointer position in sectors */
248+ __virtio64 z_wp;
249+ /* Zone type */
250+ __u8 z_type;
251+ /* Zone state */
252+ __u8 z_state;
253+ __u8 reserved[38];
254+};
255+
256+struct virtio_blk_zone_report {
257+ __virtio64 nr_zones;
258+ __u8 reserved[56];
259+ struct virtio_blk_zone_descriptor zones[];
260+};
261+
262+/*
263+ * Supported zone types.
264+ */
265+
266+/* Conventional zone */
267+#define VIRTIO_BLK_ZT_CONV 1
268+/* Sequential Write Required zone */
269+#define VIRTIO_BLK_ZT_SWR 2
270+/* Sequential Write Preferred zone */
271+#define VIRTIO_BLK_ZT_SWP 3
272+
273+/*
274+ * Zone states that are available for zones of all types.
275+ */
276+
277+/* Not a write pointer (conventional zones only) */
278+#define VIRTIO_BLK_ZS_NOT_WP 0
279+/* Empty */
280+#define VIRTIO_BLK_ZS_EMPTY 1
281+/* Implicitly Open */
282+#define VIRTIO_BLK_ZS_IOPEN 2
283+/* Explicitly Open */
284+#define VIRTIO_BLK_ZS_EOPEN 3
285+/* Closed */
286+#define VIRTIO_BLK_ZS_CLOSED 4
287+/* Read-Only */
288+#define VIRTIO_BLK_ZS_RDONLY 13
289+/* Full */
290+#define VIRTIO_BLK_ZS_FULL 14
291+/* Offline */
292+#define VIRTIO_BLK_ZS_OFFLINE 15
293+
196294 /* Unmap this range (only valid for write zeroes command) */
197295 #define VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP 0x00000001
198296
@@ -219,4 +317,11 @@ struct virtio_scsi_inhdr { · 20 unmodified lines
219317 #define VIRTIO_BLK_S_OK 0
220318 #define VIRTIO_BLK_S_IOERR 1
221319 #define VIRTIO_BLK_S_UNSUPP 2
320+
321+/* Error codes that are specific to zoned block devices */
322+#define VIRTIO_BLK_S_ZONE_INVALID_CMD 3
323+#define VIRTIO_BLK_S_ZONE_UNALIGNED_WP 4
324+#define VIRTIO_BLK_S_ZONE_OPEN_RESOURCE 5
325+#define VIRTIO_BLK_S_ZONE_ACTIVE_RESOURCE 6
326+
222327 #endif /* _LINUX_VIRTIO_BLK_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t