Skip to content

Commit 4ebe2db

Browse files
Yang Xiuweikawasaki
authored andcommitted
bsg: add uring_cmd support to BSG generic layer
Add io_uring command handler to the generic BSG layer. This handler validates that SQE128 and CQE32 flags are set (required for the command structure and status information), then delegates to the SCSI-specific handler. Signed-off-by: Yang Xiuwei <[email protected]>
1 parent b1f9e54 commit 4ebe2db

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

block/bsg.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/idr.h>
1313
#include <linux/bsg.h>
1414
#include <linux/slab.h>
15+
#include <linux/io_uring/cmd.h>
1516

1617
#include <scsi/scsi.h>
1718
#include <scsi/scsi_ioctl.h>
@@ -158,11 +159,38 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
158159
}
159160
}
160161

162+
static int bsg_uring_cmd_checks(unsigned int issue_flags)
163+
{
164+
/* BSG passthrough requires big SQE/CQE support */
165+
if ((issue_flags & (IO_URING_F_SQE128|IO_URING_F_CQE32)) !=
166+
(IO_URING_F_SQE128|IO_URING_F_CQE32))
167+
return -EOPNOTSUPP;
168+
return 0;
169+
}
170+
171+
static int bsg_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags)
172+
{
173+
struct bsg_device *bd = to_bsg_device(file_inode(ioucmd->file));
174+
struct request_queue *q = bd->queue;
175+
bool open_for_write = ioucmd->file->f_mode & FMODE_WRITE;
176+
int ret;
177+
178+
if (!q)
179+
return -EINVAL;
180+
181+
ret = bsg_uring_cmd_checks(issue_flags);
182+
if (ret)
183+
return ret;
184+
185+
return scsi_bsg_uring_cmd(q, ioucmd, issue_flags, open_for_write);
186+
}
187+
161188
static const struct file_operations bsg_fops = {
162189
.open = bsg_open,
163190
.release = bsg_release,
164191
.unlocked_ioctl = bsg_ioctl,
165192
.compat_ioctl = compat_ptr_ioctl,
193+
.uring_cmd = bsg_uring_cmd,
166194
.owner = THIS_MODULE,
167195
.llseek = default_llseek,
168196
};

drivers/scsi/scsi_bsg.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include <linux/bsg.h>
3+
#include <linux/io_uring/cmd.h>
34
#include <scsi/scsi.h>
45
#include <scsi/scsi_ioctl.h>
56
#include <scsi/scsi_cmnd.h>
@@ -9,6 +10,12 @@
910

1011
#define uptr64(val) ((void __user *)(uintptr_t)(val))
1112

13+
int scsi_bsg_uring_cmd(struct request_queue *q, struct io_uring_cmd *ioucmd,
14+
unsigned int issue_flags, bool open_for_write)
15+
{
16+
return -EOPNOTSUPP;
17+
}
18+
1219
static int scsi_bsg_sg_io_fn(struct request_queue *q, struct sg_io_v4 *hdr,
1320
bool open_for_write, unsigned int timeout)
1421
{

include/linux/bsg.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
struct bsg_device;
88
struct device;
99
struct request_queue;
10+
struct io_uring_cmd;
1011

1112
typedef int (bsg_sg_io_fn)(struct request_queue *, struct sg_io_v4 *hdr,
1213
bool open_for_write, unsigned int timeout);
@@ -16,4 +17,7 @@ struct bsg_device *bsg_register_queue(struct request_queue *q,
1617
bsg_sg_io_fn *sg_io_fn);
1718
void bsg_unregister_queue(struct bsg_device *bcd);
1819

20+
int scsi_bsg_uring_cmd(struct request_queue *q, struct io_uring_cmd *ioucmd,
21+
unsigned int issue_flags, bool open_for_write);
22+
1923
#endif /* _LINUX_BSG_H */

0 commit comments

Comments
 (0)