io_queue_init: pass in flags, not io_uring_params
We don't need any of the information in there in the caller, and this makes it harder to abuse as we don't require the caller to have memset() the struct first. Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
@@ -188,17 +188,20 @@ err:
|
|||||||
* Returns -1 on error, or zero on success. On success, 'ring'
|
* Returns -1 on error, or zero on success. On success, 'ring'
|
||||||
* contains the necessary information to read/write to the rings.
|
* contains the necessary information to read/write to the rings.
|
||||||
*/
|
*/
|
||||||
int io_uring_queue_init(unsigned entries, struct io_uring_params *p,
|
int io_uring_queue_init(unsigned entries, struct io_uring *ring, unsigned flags)
|
||||||
struct io_uring *ring)
|
|
||||||
{
|
{
|
||||||
|
struct io_uring_params p;
|
||||||
int fd, ret;
|
int fd, ret;
|
||||||
|
|
||||||
fd = io_uring_setup(entries, p);
|
memset(&p, 0, sizeof(p));
|
||||||
|
p.flags = flags;
|
||||||
|
|
||||||
|
fd = io_uring_setup(entries, &p);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
memset(ring, 0, sizeof(*ring));
|
memset(ring, 0, sizeof(*ring));
|
||||||
ret = io_uring_mmap(fd, p, &ring->sq, &ring->cq);
|
ret = io_uring_mmap(fd, &p, &ring->sq, &ring->cq);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ring->ring_fd = fd;
|
ring->ring_fd = fd;
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ extern int io_uring_register(int fd, unsigned int opcode, void *arg);
|
|||||||
/*
|
/*
|
||||||
* Library interface
|
* Library interface
|
||||||
*/
|
*/
|
||||||
extern int io_uring_queue_init(unsigned entries, struct io_uring_params *p,
|
extern int io_uring_queue_init(unsigned entries, struct io_uring *ring,
|
||||||
struct io_uring *ring);
|
unsigned flags);
|
||||||
extern void io_uring_queue_exit(struct io_uring *ring);
|
extern void io_uring_queue_exit(struct io_uring *ring);
|
||||||
extern int io_uring_get_completion(struct io_uring *ring,
|
extern int io_uring_get_completion(struct io_uring *ring,
|
||||||
struct io_uring_cqe **cqe_ptr);
|
struct io_uring_cqe **cqe_ptr);
|
||||||
|
|||||||
@@ -25,12 +25,9 @@ struct io_data {
|
|||||||
|
|
||||||
static int setup_context(unsigned entries, struct io_uring *ring)
|
static int setup_context(unsigned entries, struct io_uring *ring)
|
||||||
{
|
{
|
||||||
struct io_uring_params p;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
memset(&p, 0, sizeof(p));
|
ret = io_uring_queue_init(entries, ring, 0);
|
||||||
|
|
||||||
ret = io_uring_queue_init(entries, &p, ring);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "queue_init: %s\n", strerror(-ret));
|
fprintf(stderr, "queue_init: %s\n", strerror(-ret));
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct io_uring_params p;
|
|
||||||
struct io_uring ring;
|
struct io_uring ring;
|
||||||
int i, fd, ret, pending, done;
|
int i, fd, ret, pending, done;
|
||||||
struct io_uring_sqe *sqe;
|
struct io_uring_sqe *sqe;
|
||||||
@@ -29,9 +28,7 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&p, 0, sizeof(p));
|
ret = io_uring_queue_init(QD, &ring, 0);
|
||||||
|
|
||||||
ret = io_uring_queue_init(QD, &p, &ring);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "queue_init: %s\n", strerror(-ret));
|
fprintf(stderr, "queue_init: %s\n", strerror(-ret));
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user