hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/include/uapi/linux/virtio_blk.h
....@@ -38,6 +38,8 @@
3838 #define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/
3939 #define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */
4040 #define VIRTIO_BLK_F_MQ 12 /* support more than one vq */
41
+#define VIRTIO_BLK_F_DISCARD 13 /* DISCARD is supported */
42
+#define VIRTIO_BLK_F_WRITE_ZEROES 14 /* WRITE ZEROES is supported */
4143
4244 /* Legacy feature bits */
4345 #ifndef VIRTIO_BLK_NO_LEGACY
....@@ -55,20 +57,20 @@
5557
5658 struct virtio_blk_config {
5759 /* The capacity (in 512-byte sectors). */
58
- __u64 capacity;
60
+ __virtio64 capacity;
5961 /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */
60
- __u32 size_max;
62
+ __virtio32 size_max;
6163 /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
62
- __u32 seg_max;
64
+ __virtio32 seg_max;
6365 /* geometry of the device (if VIRTIO_BLK_F_GEOMETRY) */
6466 struct virtio_blk_geometry {
65
- __u16 cylinders;
67
+ __virtio16 cylinders;
6668 __u8 heads;
6769 __u8 sectors;
6870 } geometry;
6971
7072 /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */
71
- __u32 blk_size;
73
+ __virtio32 blk_size;
7274
7375 /* the next 4 entries are guarded by VIRTIO_BLK_F_TOPOLOGY */
7476 /* exponent for physical block per logical block. */
....@@ -76,16 +78,49 @@
7678 /* alignment offset in logical blocks. */
7779 __u8 alignment_offset;
7880 /* minimum I/O size without performance penalty in logical blocks. */
79
- __u16 min_io_size;
81
+ __virtio16 min_io_size;
8082 /* optimal sustained I/O size in logical blocks. */
81
- __u32 opt_io_size;
83
+ __virtio32 opt_io_size;
8284
8385 /* writeback mode (if VIRTIO_BLK_F_CONFIG_WCE) */
8486 __u8 wce;
8587 __u8 unused;
8688
8789 /* number of vqs, only available when VIRTIO_BLK_F_MQ is set */
88
- __u16 num_queues;
90
+ __virtio16 num_queues;
91
+
92
+ /* the next 3 entries are guarded by VIRTIO_BLK_F_DISCARD */
93
+ /*
94
+ * The maximum discard sectors (in 512-byte sectors) for
95
+ * one segment.
96
+ */
97
+ __virtio32 max_discard_sectors;
98
+ /*
99
+ * The maximum number of discard segments in a
100
+ * discard command.
101
+ */
102
+ __virtio32 max_discard_seg;
103
+ /* Discard commands must be aligned to this number of sectors. */
104
+ __virtio32 discard_sector_alignment;
105
+
106
+ /* the next 3 entries are guarded by VIRTIO_BLK_F_WRITE_ZEROES */
107
+ /*
108
+ * The maximum number of write zeroes sectors (in 512-byte sectors) in
109
+ * one segment.
110
+ */
111
+ __virtio32 max_write_zeroes_sectors;
112
+ /*
113
+ * The maximum number of segments in a write zeroes
114
+ * command.
115
+ */
116
+ __virtio32 max_write_zeroes_seg;
117
+ /*
118
+ * Set if a VIRTIO_BLK_T_WRITE_ZEROES request may result in the
119
+ * deallocation of one or more of the sectors.
120
+ */
121
+ __u8 write_zeroes_may_unmap;
122
+
123
+ __u8 unused1[3];
89124 } __attribute__((packed));
90125
91126 /*
....@@ -114,6 +149,12 @@
114149 /* Get device ID command */
115150 #define VIRTIO_BLK_T_GET_ID 8
116151
152
+/* Discard command */
153
+#define VIRTIO_BLK_T_DISCARD 11
154
+
155
+/* Write zeroes command */
156
+#define VIRTIO_BLK_T_WRITE_ZEROES 13
157
+
117158 #ifndef VIRTIO_BLK_NO_LEGACY
118159 /* Barrier before this op. */
119160 #define VIRTIO_BLK_T_BARRIER 0x80000000
....@@ -133,6 +174,19 @@
133174 __virtio64 sector;
134175 };
135176
177
+/* Unmap this range (only valid for write zeroes command) */
178
+#define VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP 0x00000001
179
+
180
+/* Discard/write zeroes range for each request. */
181
+struct virtio_blk_discard_write_zeroes {
182
+ /* discard/write zeroes start sector */
183
+ __le64 sector;
184
+ /* number of discard/write zeroes sectors */
185
+ __le32 num_sectors;
186
+ /* flags for this range */
187
+ __le32 flags;
188
+};
189
+
136190 #ifndef VIRTIO_BLK_NO_LEGACY
137191 struct virtio_scsi_inhdr {
138192 __virtio32 errors;