Skip to content

Commit

Permalink
iov_iter: Separate type from direction and use accessor functions
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dhowells committed Oct 23, 2018
1 parent 00e2370 commit aa563d7
Show file tree
Hide file tree
Showing 40 changed files with 96 additions and 105 deletions.
2 changes: 1 addition & 1 deletion drivers/block/drbd/drbd_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@ int drbd_send(struct drbd_connection *connection, struct socket *sock,

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

iov_iter_kvec(&msg.msg_iter, WRITE | ITER_KVEC, &iov, 1, size);
iov_iter_kvec(&msg.msg_iter, WRITE, &iov, 1, size);

if (sock == connection->data.socket) {
rcu_read_lock();
Expand Down
2 changes: 1 addition & 1 deletion drivers/block/drbd/drbd_receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ static int drbd_recv_short(struct socket *sock, void *buf, size_t size, int flag
struct msghdr msg = {
.msg_flags = (flags ? flags : MSG_WAITALL | MSG_NOSIGNAL)
};
iov_iter_kvec(&msg.msg_iter, READ | ITER_KVEC, &iov, 1, size);
iov_iter_kvec(&msg.msg_iter, READ, &iov, 1, size);
return sock_recvmsg(sock, &msg, msg.msg_flags);
}

Expand Down
9 changes: 4 additions & 5 deletions drivers/block/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ static int lo_write_bvec(struct file *file, struct bio_vec *bvec, loff_t *ppos)
struct iov_iter i;
ssize_t bw;

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

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

rq_for_each_segment(bvec, rq, iter) {
iov_iter_bvec(&i, ITER_BVEC, &bvec, 1, bvec.bv_len);
iov_iter_bvec(&i, READ, &bvec, 1, bvec.bv_len);
len = vfs_iter_read(lo->lo_backing_file, &i, &pos, 0);
if (len < 0)
return len;
Expand Down Expand Up @@ -387,7 +387,7 @@ static int lo_read_transfer(struct loop_device *lo, struct request *rq,
b.bv_offset = 0;
b.bv_len = bvec.bv_len;

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

iov_iter_bvec(&iter, ITER_BVEC | rw, bvec,
segments, blk_rq_bytes(rq));
iov_iter_bvec(&iter, rw, bvec, segments, blk_rq_bytes(rq));
iter.iov_offset = offset;

cmd->iocb.ki_pos = pos;
Expand Down
12 changes: 5 additions & 7 deletions drivers/block/nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
u32 nbd_cmd_flags = 0;
int sent = nsock->sent, skip = 0;

iov_iter_kvec(&from, WRITE | ITER_KVEC, &iov, 1, sizeof(request));
iov_iter_kvec(&from, WRITE, &iov, 1, sizeof(request));

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

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

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

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

iov_iter_kvec(&from, WRITE | ITER_KVEC, &iov, 1, sizeof(request));
iov_iter_kvec(&from, WRITE, &iov, 1, sizeof(request));
mutex_lock(&nsock->tx_lock);
ret = sock_xmit(nbd, i, 1, &from, 0, NULL);
if (ret <= 0)
Expand Down
4 changes: 2 additions & 2 deletions drivers/fsi/fsi-sbefifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ static void sbefifo_collect_async_ffdc(struct sbefifo *sbefifo)
}
ffdc_iov.iov_base = ffdc;
ffdc_iov.iov_len = SBEFIFO_MAX_FFDC_SIZE;
iov_iter_kvec(&ffdc_iter, WRITE | ITER_KVEC, &ffdc_iov, 1, SBEFIFO_MAX_FFDC_SIZE);
iov_iter_kvec(&ffdc_iter, WRITE, &ffdc_iov, 1, SBEFIFO_MAX_FFDC_SIZE);
cmd[0] = cpu_to_be32(2);
cmd[1] = cpu_to_be32(SBEFIFO_CMD_GET_SBE_FFDC);
rc = sbefifo_do_command(sbefifo, cmd, 2, &ffdc_iter);
Expand Down Expand Up @@ -735,7 +735,7 @@ int sbefifo_submit(struct device *dev, const __be32 *command, size_t cmd_len,
rbytes = (*resp_len) * sizeof(__be32);
resp_iov.iov_base = response;
resp_iov.iov_len = rbytes;
iov_iter_kvec(&resp_iter, WRITE | ITER_KVEC, &resp_iov, 1, rbytes);
iov_iter_kvec(&resp_iter, WRITE, &resp_iov, 1, rbytes);

/* Perform the command */
mutex_lock(&sbefifo->lock);
Expand Down
3 changes: 1 addition & 2 deletions drivers/isdn/mISDN/l1oip_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,7 @@ l1oip_socket_thread(void *data)
printk(KERN_DEBUG "%s: socket created and open\n",
__func__);
while (!signal_pending(current)) {
iov_iter_kvec(&msg.msg_iter, READ | ITER_KVEC, &iov, 1,
recvbuf_size);
iov_iter_kvec(&msg.msg_iter, READ, &iov, 1, recvbuf_size);
recvlen = sock_recvmsg(socket, &msg, 0);
if (recvlen > 0) {
l1oip_socket_parse(hc, &sin_rx, recvbuf, recvlen);
Expand Down
6 changes: 3 additions & 3 deletions drivers/misc/vmw_vmci/vmci_queue_pair.c
Original file line number Diff line number Diff line change
Expand Up @@ -3030,7 +3030,7 @@ ssize_t vmci_qpair_enqueue(struct vmci_qp *qpair,
if (!qpair || !buf)
return VMCI_ERROR_INVALID_ARGS;

iov_iter_kvec(&from, WRITE | ITER_KVEC, &v, 1, buf_size);
iov_iter_kvec(&from, WRITE, &v, 1, buf_size);

qp_lock(qpair);

Expand Down Expand Up @@ -3074,7 +3074,7 @@ ssize_t vmci_qpair_dequeue(struct vmci_qp *qpair,
if (!qpair || !buf)
return VMCI_ERROR_INVALID_ARGS;

iov_iter_kvec(&to, READ | ITER_KVEC, &v, 1, buf_size);
iov_iter_kvec(&to, READ, &v, 1, buf_size);

qp_lock(qpair);

Expand Down Expand Up @@ -3119,7 +3119,7 @@ ssize_t vmci_qpair_peek(struct vmci_qp *qpair,
if (!qpair || !buf)
return VMCI_ERROR_INVALID_ARGS;

iov_iter_kvec(&to, READ | ITER_KVEC, &v, 1, buf_size);
iov_iter_kvec(&to, READ, &v, 1, buf_size);

qp_lock(qpair);

Expand Down
2 changes: 1 addition & 1 deletion drivers/nvme/target/io-cmd-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static ssize_t nvmet_file_submit_bvec(struct nvmet_req *req, loff_t pos,
rw = READ;
}

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

iocb->ki_pos = pos;
iocb->ki_filp = req->ns->file;
Expand Down
6 changes: 2 additions & 4 deletions drivers/target/iscsi/iscsi_target_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1258,8 +1258,7 @@ static int iscsit_do_rx_data(
return -1;

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

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

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

iov_iter_kvec(&msg.msg_iter, WRITE | ITER_KVEC,
iov, iov_count, data);
iov_iter_kvec(&msg.msg_iter, WRITE, iov, iov_count, data);

while (msg_data_left(&msg)) {
int tx_loop = sock_sendmsg(conn->sock, &msg);
Expand Down
6 changes: 3 additions & 3 deletions drivers/target/target_core_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ fd_execute_rw_aio(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
len += sg->length;
}

iov_iter_bvec(&iter, ITER_BVEC | is_write, bvec, sgl_nents, len);
iov_iter_bvec(&iter, is_write, bvec, sgl_nents, len);

aio_cmd->cmd = cmd;
aio_cmd->len = len;
Expand Down Expand Up @@ -353,7 +353,7 @@ static int fd_do_rw(struct se_cmd *cmd, struct file *fd,
len += sg->length;
}

iov_iter_bvec(&iter, ITER_BVEC, bvec, sgl_nents, len);
iov_iter_bvec(&iter, READ, bvec, sgl_nents, len);
if (is_write)
ret = vfs_iter_write(fd, &iter, &pos, 0);
else
Expand Down Expand Up @@ -490,7 +490,7 @@ fd_execute_write_same(struct se_cmd *cmd)
len += se_dev->dev_attrib.block_size;
}

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

kfree(bvec);
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/usbip/usbip_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ int usbip_recv(struct socket *sock, void *buf, int size)
if (!sock || !buf || !size)
return -EINVAL;

iov_iter_kvec(&msg.msg_iter, READ|ITER_KVEC, &iov, 1, size);
iov_iter_kvec(&msg.msg_iter, READ, &iov, 1, size);

usbip_dbg_xmit("enter\n");

Expand Down
8 changes: 4 additions & 4 deletions drivers/xen/pvcalls-back.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ static void pvcalls_conn_back_read(void *opaque)
if (masked_prod < masked_cons) {
vec[0].iov_base = data->in + masked_prod;
vec[0].iov_len = wanted;
iov_iter_kvec(&msg.msg_iter, ITER_KVEC|WRITE, vec, 1, wanted);
iov_iter_kvec(&msg.msg_iter, WRITE, vec, 1, wanted);
} else {
vec[0].iov_base = data->in + masked_prod;
vec[0].iov_len = array_size - masked_prod;
vec[1].iov_base = data->in;
vec[1].iov_len = wanted - vec[0].iov_len;
iov_iter_kvec(&msg.msg_iter, ITER_KVEC|WRITE, vec, 2, wanted);
iov_iter_kvec(&msg.msg_iter, WRITE, vec, 2, wanted);
}

atomic_set(&map->read, 0);
Expand Down Expand Up @@ -195,13 +195,13 @@ static void pvcalls_conn_back_write(struct sock_mapping *map)
if (pvcalls_mask(prod, array_size) > pvcalls_mask(cons, array_size)) {
vec[0].iov_base = data->out + pvcalls_mask(cons, array_size);
vec[0].iov_len = size;
iov_iter_kvec(&msg.msg_iter, ITER_KVEC|READ, vec, 1, size);
iov_iter_kvec(&msg.msg_iter, READ, vec, 1, size);
} else {
vec[0].iov_base = data->out + pvcalls_mask(cons, array_size);
vec[0].iov_len = array_size - pvcalls_mask(cons, array_size);
vec[1].iov_base = data->out;
vec[1].iov_len = size - vec[0].iov_len;
iov_iter_kvec(&msg.msg_iter, ITER_KVEC|READ, vec, 2, size);
iov_iter_kvec(&msg.msg_iter, READ, vec, 2, size);
}

atomic_set(&map->write, 0);
Expand Down
4 changes: 2 additions & 2 deletions fs/9p/vfs_addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static int v9fs_fid_readpage(struct p9_fid *fid, struct page *page)
if (retval == 0)
return retval;

iov_iter_bvec(&to, ITER_BVEC | READ, &bvec, 1, PAGE_SIZE);
iov_iter_bvec(&to, READ, &bvec, 1, PAGE_SIZE);

retval = p9_client_read(fid, page_offset(page), &to, &err);
if (err) {
Expand Down Expand Up @@ -175,7 +175,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
bvec.bv_page = page;
bvec.bv_offset = 0;
bvec.bv_len = len;
iov_iter_bvec(&from, ITER_BVEC | WRITE, &bvec, 1, len);
iov_iter_bvec(&from, WRITE, &bvec, 1, len);

/* We should have writeback_fid always set */
BUG_ON(!v9inode->writeback_fid);
Expand Down
2 changes: 1 addition & 1 deletion fs/9p/vfs_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx)
if (rdir->tail == rdir->head) {
struct iov_iter to;
int n;
iov_iter_kvec(&to, READ | ITER_KVEC, &kvec, 1, buflen);
iov_iter_kvec(&to, READ, &kvec, 1, buflen);
n = p9_client_read(file->private_data, ctx->pos, &to,
&err);
if (err)
Expand Down
4 changes: 2 additions & 2 deletions fs/9p/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ssize_t v9fs_fid_xattr_get(struct p9_fid *fid, const char *name,
struct iov_iter to;
int err;

iov_iter_kvec(&to, READ | ITER_KVEC, &kvec, 1, buffer_size);
iov_iter_kvec(&to, READ, &kvec, 1, buffer_size);

attr_fid = p9_client_xattrwalk(fid, name, &attr_size);
if (IS_ERR(attr_fid)) {
Expand Down Expand Up @@ -107,7 +107,7 @@ int v9fs_fid_xattr_set(struct p9_fid *fid, const char *name,
struct iov_iter from;
int retval, err;

iov_iter_kvec(&from, WRITE | ITER_KVEC, &kvec, 1, value_len);
iov_iter_kvec(&from, WRITE, &kvec, 1, value_len);

p9_debug(P9_DEBUG_VFS, "name = %s value_len = %zu flags = %d\n",
name, value_len, flags);
Expand Down
15 changes: 7 additions & 8 deletions fs/afs/rxrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ static void afs_load_bvec(struct afs_call *call, struct msghdr *msg,
offset = 0;
}

iov_iter_bvec(&msg->msg_iter, WRITE | ITER_BVEC, bv, nr, bytes);
iov_iter_bvec(&msg->msg_iter, WRITE, bv, nr, bytes);
}

/*
Expand Down Expand Up @@ -401,8 +401,7 @@ long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call,

msg.msg_name = NULL;
msg.msg_namelen = 0;
iov_iter_kvec(&msg.msg_iter, WRITE | ITER_KVEC, iov, 1,
call->request_size);
iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, call->request_size);
msg.msg_control = NULL;
msg.msg_controllen = 0;
msg.msg_flags = MSG_WAITALL | (call->send_pages ? MSG_MORE : 0);
Expand Down Expand Up @@ -432,7 +431,7 @@ long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call,
rxrpc_kernel_abort_call(call->net->socket, rxcall,
RX_USER_ABORT, ret, "KSD");
} else {
iov_iter_kvec(&msg.msg_iter, READ | ITER_KVEC, NULL, 0, 0);
iov_iter_kvec(&msg.msg_iter, READ, NULL, 0, 0);
rxrpc_kernel_recv_data(call->net->socket, rxcall,
&msg.msg_iter, false,
&call->abort_code, &call->service_id);
Expand Down Expand Up @@ -468,7 +467,7 @@ static void afs_deliver_to_call(struct afs_call *call)
if (state == AFS_CALL_SV_AWAIT_ACK) {
struct iov_iter iter;

iov_iter_kvec(&iter, READ | ITER_KVEC, NULL, 0, 0);
iov_iter_kvec(&iter, READ, NULL, 0, 0);
ret = rxrpc_kernel_recv_data(call->net->socket,
call->rxcall, &iter, false,
&remote_abort,
Expand Down Expand Up @@ -825,7 +824,7 @@ void afs_send_empty_reply(struct afs_call *call)

msg.msg_name = NULL;
msg.msg_namelen = 0;
iov_iter_kvec(&msg.msg_iter, WRITE | ITER_KVEC, NULL, 0, 0);
iov_iter_kvec(&msg.msg_iter, WRITE, NULL, 0, 0);
msg.msg_control = NULL;
msg.msg_controllen = 0;
msg.msg_flags = 0;
Expand Down Expand Up @@ -864,7 +863,7 @@ void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len)
iov[0].iov_len = len;
msg.msg_name = NULL;
msg.msg_namelen = 0;
iov_iter_kvec(&msg.msg_iter, WRITE | ITER_KVEC, iov, 1, len);
iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, len);
msg.msg_control = NULL;
msg.msg_controllen = 0;
msg.msg_flags = 0;
Expand Down Expand Up @@ -905,7 +904,7 @@ int afs_extract_data(struct afs_call *call, void *buf, size_t count,

iov.iov_base = buf + call->offset;
iov.iov_len = count - call->offset;
iov_iter_kvec(&iter, ITER_KVEC | READ, &iov, 1, count - call->offset);
iov_iter_kvec(&iter, READ, &iov, 1, count - call->offset);

ret = rxrpc_kernel_recv_data(net->socket, call->rxcall, &iter,
want_more, &remote_abort,
Expand Down
5 changes: 2 additions & 3 deletions fs/ceph/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ static void ceph_aio_complete_req(struct ceph_osd_request *req)
aio_req->total_len = rc + zlen;
}

iov_iter_bvec(&i, ITER_BVEC, osd_data->bvec_pos.bvecs,
iov_iter_bvec(&i, READ, osd_data->bvec_pos.bvecs,
osd_data->num_bvecs,
osd_data->bvec_pos.iter.bi_size);
iov_iter_advance(&i, rc);
Expand Down Expand Up @@ -1044,8 +1044,7 @@ ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter,
int zlen = min_t(size_t, len - ret,
size - pos - ret);

iov_iter_bvec(&i, ITER_BVEC, bvecs, num_pages,
len);
iov_iter_bvec(&i, READ, bvecs, num_pages, len);
iov_iter_advance(&i, ret);
iov_iter_zero(zlen, &i);
ret += zlen;
Expand Down
4 changes: 2 additions & 2 deletions fs/cifs/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ cifs_read_from_socket(struct TCP_Server_Info *server, char *buf,
{
struct msghdr smb_msg;
struct kvec iov = {.iov_base = buf, .iov_len = to_read};
iov_iter_kvec(&smb_msg.msg_iter, READ | ITER_KVEC, &iov, 1, to_read);
iov_iter_kvec(&smb_msg.msg_iter, READ, &iov, 1, to_read);

return cifs_readv_from_socket(server, &smb_msg);
}
Expand All @@ -600,7 +600,7 @@ cifs_read_page_from_socket(struct TCP_Server_Info *server, struct page *page,
struct msghdr smb_msg;
struct bio_vec bv = {
.bv_page = page, .bv_len = to_read, .bv_offset = page_offset};
iov_iter_bvec(&smb_msg.msg_iter, READ | ITER_BVEC, &bv, 1, to_read);
iov_iter_bvec(&smb_msg.msg_iter, READ, &bv, 1, to_read);
return cifs_readv_from_socket(server, &smb_msg);
}

Expand Down
Loading

0 comments on commit aa563d7

Please sign in to comment.