Skip to content

Commit aa563d7

Browse files
committed
iov_iter: Separate type from direction and use accessor functions
In the iov_iter struct, separate the iterator type from the iterator direction and use accessor functions to access them in most places. Convert a bunch of places to use switch-statements to access them rather then chains of bitwise-AND statements. This makes it easier to add further iterator types. Also, this can be more efficient as to implement a switch of small contiguous integers, the compiler can use ~50% fewer compare instructions than it has to use bitwise-and instructions. Further, cease passing the iterator type into the iterator setup function. The iterator function can set that itself. Only the direction is required. Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 00e2370 commit aa563d7

40 files changed

Lines changed: 96 additions & 105 deletions

File tree

‎drivers/block/drbd/drbd_main.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,7 @@ int drbd_send(struct drbd_connection *connection, struct socket *sock,
18561856

18571857
/* THINK if (signal_pending) return ... ? */
18581858

1859-
iov_iter_kvec(&msg.msg_iter, WRITE | ITER_KVEC, &iov, 1, size);
1859+
iov_iter_kvec(&msg.msg_iter, WRITE, &iov, 1, size);
18601860

18611861
if (sock == connection->data.socket) {
18621862
rcu_read_lock();

‎drivers/block/drbd/drbd_receiver.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ static int drbd_recv_short(struct socket *sock, void *buf, size_t size, int flag
516516
struct msghdr msg = {
517517
.msg_flags = (flags ? flags : MSG_WAITALL | MSG_NOSIGNAL)
518518
};
519-
iov_iter_kvec(&msg.msg_iter, READ | ITER_KVEC, &iov, 1, size);
519+
iov_iter_kvec(&msg.msg_iter, READ, &iov, 1, size);
520520
return sock_recvmsg(sock, &msg, msg.msg_flags);
521521
}
522522

‎drivers/block/loop.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static int lo_write_bvec(struct file *file, struct bio_vec *bvec, loff_t *ppos)
268268
struct iov_iter i;
269269
ssize_t bw;
270270

271-
iov_iter_bvec(&i, ITER_BVEC | WRITE, bvec, 1, bvec->bv_len);
271+
iov_iter_bvec(&i, WRITE, bvec, 1, bvec->bv_len);
272272

273273
file_start_write(file);
274274
bw = vfs_iter_write(file, &i, ppos, 0);
@@ -346,7 +346,7 @@ static int lo_read_simple(struct loop_device *lo, struct request *rq,
346346
ssize_t len;
347347

348348
rq_for_each_segment(bvec, rq, iter) {
349-
iov_iter_bvec(&i, ITER_BVEC, &bvec, 1, bvec.bv_len);
349+
iov_iter_bvec(&i, READ, &bvec, 1, bvec.bv_len);
350350
len = vfs_iter_read(lo->lo_backing_file, &i, &pos, 0);
351351
if (len < 0)
352352
return len;
@@ -387,7 +387,7 @@ static int lo_read_transfer(struct loop_device *lo, struct request *rq,
387387
b.bv_offset = 0;
388388
b.bv_len = bvec.bv_len;
389389

390-
iov_iter_bvec(&i, ITER_BVEC, &b, 1, b.bv_len);
390+
iov_iter_bvec(&i, READ, &b, 1, b.bv_len);
391391
len = vfs_iter_read(lo->lo_backing_file, &i, &pos, 0);
392392
if (len < 0) {
393393
ret = len;
@@ -554,8 +554,7 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
554554
}
555555
atomic_set(&cmd->ref, 2);
556556

557-
iov_iter_bvec(&iter, ITER_BVEC | rw, bvec,
558-
segments, blk_rq_bytes(rq));
557+
iov_iter_bvec(&iter, rw, bvec, segments, blk_rq_bytes(rq));
559558
iter.iov_offset = offset;
560559

561560
cmd->iocb.ki_pos = pos;

‎drivers/block/nbd.c‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
473473
u32 nbd_cmd_flags = 0;
474474
int sent = nsock->sent, skip = 0;
475475

476-
iov_iter_kvec(&from, WRITE | ITER_KVEC, &iov, 1, sizeof(request));
476+
iov_iter_kvec(&from, WRITE, &iov, 1, sizeof(request));
477477

478478
switch (req_op(req)) {
479479
case REQ_OP_DISCARD:
@@ -564,8 +564,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
564564

565565
dev_dbg(nbd_to_dev(nbd), "request %p: sending %d bytes data\n",
566566
req, bvec.bv_len);
567-
iov_iter_bvec(&from, ITER_BVEC | WRITE,
568-
&bvec, 1, bvec.bv_len);
567+
iov_iter_bvec(&from, WRITE, &bvec, 1, bvec.bv_len);
569568
if (skip) {
570569
if (skip >= iov_iter_count(&from)) {
571570
skip -= iov_iter_count(&from);
@@ -624,7 +623,7 @@ static struct nbd_cmd *nbd_read_stat(struct nbd_device *nbd, int index)
624623
int ret = 0;
625624

626625
reply.magic = 0;
627-
iov_iter_kvec(&to, READ | ITER_KVEC, &iov, 1, sizeof(reply));
626+
iov_iter_kvec(&to, READ, &iov, 1, sizeof(reply));
628627
result = sock_xmit(nbd, index, 0, &to, MSG_WAITALL, NULL);
629628
if (result <= 0) {
630629
if (!nbd_disconnected(config))
@@ -678,8 +677,7 @@ static struct nbd_cmd *nbd_read_stat(struct nbd_device *nbd, int index)
678677
struct bio_vec bvec;
679678

680679
rq_for_each_segment(bvec, req, iter) {
681-
iov_iter_bvec(&to, ITER_BVEC | READ,
682-
&bvec, 1, bvec.bv_len);
680+
iov_iter_bvec(&to, READ, &bvec, 1, bvec.bv_len);
683681
result = sock_xmit(nbd, index, 0, &to, MSG_WAITALL, NULL);
684682
if (result <= 0) {
685683
dev_err(disk_to_dev(nbd->disk), "Receive data failed (result %d)\n",
@@ -1073,7 +1071,7 @@ static void send_disconnects(struct nbd_device *nbd)
10731071
for (i = 0; i < config->num_connections; i++) {
10741072
struct nbd_sock *nsock = config->socks[i];
10751073

1076-
iov_iter_kvec(&from, WRITE | ITER_KVEC, &iov, 1, sizeof(request));
1074+
iov_iter_kvec(&from, WRITE, &iov, 1, sizeof(request));
10771075
mutex_lock(&nsock->tx_lock);
10781076
ret = sock_xmit(nbd, i, 1, &from, 0, NULL);
10791077
if (ret <= 0)

‎drivers/fsi/fsi-sbefifo.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ static void sbefifo_collect_async_ffdc(struct sbefifo *sbefifo)
638638
}
639639
ffdc_iov.iov_base = ffdc;
640640
ffdc_iov.iov_len = SBEFIFO_MAX_FFDC_SIZE;
641-
iov_iter_kvec(&ffdc_iter, WRITE | ITER_KVEC, &ffdc_iov, 1, SBEFIFO_MAX_FFDC_SIZE);
641+
iov_iter_kvec(&ffdc_iter, WRITE, &ffdc_iov, 1, SBEFIFO_MAX_FFDC_SIZE);
642642
cmd[0] = cpu_to_be32(2);
643643
cmd[1] = cpu_to_be32(SBEFIFO_CMD_GET_SBE_FFDC);
644644
rc = sbefifo_do_command(sbefifo, cmd, 2, &ffdc_iter);
@@ -735,7 +735,7 @@ int sbefifo_submit(struct device *dev, const __be32 *command, size_t cmd_len,
735735
rbytes = (*resp_len) * sizeof(__be32);
736736
resp_iov.iov_base = response;
737737
resp_iov.iov_len = rbytes;
738-
iov_iter_kvec(&resp_iter, WRITE | ITER_KVEC, &resp_iov, 1, rbytes);
738+
iov_iter_kvec(&resp_iter, WRITE, &resp_iov, 1, rbytes);
739739

740740
/* Perform the command */
741741
mutex_lock(&sbefifo->lock);

‎drivers/isdn/mISDN/l1oip_core.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,7 @@ l1oip_socket_thread(void *data)
718718
printk(KERN_DEBUG "%s: socket created and open\n",
719719
__func__);
720720
while (!signal_pending(current)) {
721-
iov_iter_kvec(&msg.msg_iter, READ | ITER_KVEC, &iov, 1,
722-
recvbuf_size);
721+
iov_iter_kvec(&msg.msg_iter, READ, &iov, 1, recvbuf_size);
723722
recvlen = sock_recvmsg(socket, &msg, 0);
724723
if (recvlen > 0) {
725724
l1oip_socket_parse(hc, &sin_rx, recvbuf, recvlen);

‎drivers/misc/vmw_vmci/vmci_queue_pair.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,7 +3030,7 @@ ssize_t vmci_qpair_enqueue(struct vmci_qp *qpair,
30303030
if (!qpair || !buf)
30313031
return VMCI_ERROR_INVALID_ARGS;
30323032

3033-
iov_iter_kvec(&from, WRITE | ITER_KVEC, &v, 1, buf_size);
3033+
iov_iter_kvec(&from, WRITE, &v, 1, buf_size);
30343034

30353035
qp_lock(qpair);
30363036

@@ -3074,7 +3074,7 @@ ssize_t vmci_qpair_dequeue(struct vmci_qp *qpair,
30743074
if (!qpair || !buf)
30753075
return VMCI_ERROR_INVALID_ARGS;
30763076

3077-
iov_iter_kvec(&to, READ | ITER_KVEC, &v, 1, buf_size);
3077+
iov_iter_kvec(&to, READ, &v, 1, buf_size);
30783078

30793079
qp_lock(qpair);
30803080

@@ -3119,7 +3119,7 @@ ssize_t vmci_qpair_peek(struct vmci_qp *qpair,
31193119
if (!qpair || !buf)
31203120
return VMCI_ERROR_INVALID_ARGS;
31213121

3122-
iov_iter_kvec(&to, READ | ITER_KVEC, &v, 1, buf_size);
3122+
iov_iter_kvec(&to, READ, &v, 1, buf_size);
31233123

31243124
qp_lock(qpair);
31253125

‎drivers/nvme/target/io-cmd-file.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static ssize_t nvmet_file_submit_bvec(struct nvmet_req *req, loff_t pos,
101101
rw = READ;
102102
}
103103

104-
iov_iter_bvec(&iter, ITER_BVEC | rw, req->f.bvec, nr_segs, count);
104+
iov_iter_bvec(&iter, rw, req->f.bvec, nr_segs, count);
105105

106106
iocb->ki_pos = pos;
107107
iocb->ki_filp = req->ns->file;

‎drivers/target/iscsi/iscsi_target_util.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,8 +1258,7 @@ static int iscsit_do_rx_data(
12581258
return -1;
12591259

12601260
memset(&msg, 0, sizeof(struct msghdr));
1261-
iov_iter_kvec(&msg.msg_iter, READ | ITER_KVEC,
1262-
count->iov, count->iov_count, data);
1261+
iov_iter_kvec(&msg.msg_iter, READ, count->iov, count->iov_count, data);
12631262

12641263
while (msg_data_left(&msg)) {
12651264
rx_loop = sock_recvmsg(conn->sock, &msg, MSG_WAITALL);
@@ -1315,8 +1314,7 @@ int tx_data(
13151314

13161315
memset(&msg, 0, sizeof(struct msghdr));
13171316

1318-
iov_iter_kvec(&msg.msg_iter, WRITE | ITER_KVEC,
1319-
iov, iov_count, data);
1317+
iov_iter_kvec(&msg.msg_iter, WRITE, iov, iov_count, data);
13201318

13211319
while (msg_data_left(&msg)) {
13221320
int tx_loop = sock_sendmsg(conn->sock, &msg);

‎drivers/target/target_core_file.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ fd_execute_rw_aio(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
303303
len += sg->length;
304304
}
305305

306-
iov_iter_bvec(&iter, ITER_BVEC | is_write, bvec, sgl_nents, len);
306+
iov_iter_bvec(&iter, is_write, bvec, sgl_nents, len);
307307

308308
aio_cmd->cmd = cmd;
309309
aio_cmd->len = len;
@@ -353,7 +353,7 @@ static int fd_do_rw(struct se_cmd *cmd, struct file *fd,
353353
len += sg->length;
354354
}
355355

356-
iov_iter_bvec(&iter, ITER_BVEC, bvec, sgl_nents, len);
356+
iov_iter_bvec(&iter, READ, bvec, sgl_nents, len);
357357
if (is_write)
358358
ret = vfs_iter_write(fd, &iter, &pos, 0);
359359
else
@@ -490,7 +490,7 @@ fd_execute_write_same(struct se_cmd *cmd)
490490
len += se_dev->dev_attrib.block_size;
491491
}
492492

493-
iov_iter_bvec(&iter, ITER_BVEC, bvec, nolb, len);
493+
iov_iter_bvec(&iter, READ, bvec, nolb, len);
494494
ret = vfs_iter_write(fd_dev->fd_file, &iter, &pos, 0);
495495

496496
kfree(bvec);

0 commit comments

Comments
 (0)