Commit aa563d7b authored by David Howells's avatar David Howells
Browse files

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: default avatarDavid Howells <dhowells@redhat.com>
parent 00e23707
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -1856,7 +1856,7 @@ int drbd_send(struct drbd_connection *connection, struct socket *sock,


	/* THINK  if (signal_pending) return ... ? */
	/* 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) {
	if (sock == connection->data.socket) {
		rcu_read_lock();
		rcu_read_lock();
+1 −1
Original line number Original line Diff line number Diff line
@@ -516,7 +516,7 @@ static int drbd_recv_short(struct socket *sock, void *buf, size_t size, int flag
	struct msghdr msg = {
	struct msghdr msg = {
		.msg_flags = (flags ? flags : MSG_WAITALL | MSG_NOSIGNAL)
		.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);
	return sock_recvmsg(sock, &msg, msg.msg_flags);
}
}


+4 −5
Original line number Original line Diff line number Diff line
@@ -268,7 +268,7 @@ static int lo_write_bvec(struct file *file, struct bio_vec *bvec, loff_t *ppos)
	struct iov_iter i;
	struct iov_iter i;
	ssize_t bw;
	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);
	file_start_write(file);
	bw = vfs_iter_write(file, &i, ppos, 0);
	bw = vfs_iter_write(file, &i, ppos, 0);
@@ -346,7 +346,7 @@ static int lo_read_simple(struct loop_device *lo, struct request *rq,
	ssize_t len;
	ssize_t len;


	rq_for_each_segment(bvec, rq, iter) {
	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);
		len = vfs_iter_read(lo->lo_backing_file, &i, &pos, 0);
		if (len < 0)
		if (len < 0)
			return len;
			return len;
@@ -387,7 +387,7 @@ static int lo_read_transfer(struct loop_device *lo, struct request *rq,
		b.bv_offset = 0;
		b.bv_offset = 0;
		b.bv_len = bvec.bv_len;
		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);
		len = vfs_iter_read(lo->lo_backing_file, &i, &pos, 0);
		if (len < 0) {
		if (len < 0) {
			ret = len;
			ret = len;
@@ -554,8 +554,7 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
	}
	}
	atomic_set(&cmd->ref, 2);
	atomic_set(&cmd->ref, 2);


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


	cmd->iocb.ki_pos = pos;
	cmd->iocb.ki_pos = pos;
+5 −7
Original line number Original line Diff line number Diff line
@@ -473,7 +473,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
	u32 nbd_cmd_flags = 0;
	u32 nbd_cmd_flags = 0;
	int sent = nsock->sent, skip = 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)) {
	switch (req_op(req)) {
	case REQ_OP_DISCARD:
	case REQ_OP_DISCARD:
@@ -564,8 +564,7 @@ send_pages:


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


	reply.magic = 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);
	result = sock_xmit(nbd, index, 0, &to, MSG_WAITALL, NULL);
	if (result <= 0) {
	if (result <= 0) {
		if (!nbd_disconnected(config))
		if (!nbd_disconnected(config))
@@ -678,8 +677,7 @@ static struct nbd_cmd *nbd_read_stat(struct nbd_device *nbd, int index)
		struct bio_vec bvec;
		struct bio_vec bvec;


		rq_for_each_segment(bvec, req, iter) {
		rq_for_each_segment(bvec, req, iter) {
			iov_iter_bvec(&to, ITER_BVEC | READ,
			iov_iter_bvec(&to, READ, &bvec, 1, bvec.bv_len);
				      &bvec, 1, bvec.bv_len);
			result = sock_xmit(nbd, index, 0, &to, MSG_WAITALL, NULL);
			result = sock_xmit(nbd, index, 0, &to, MSG_WAITALL, NULL);
			if (result <= 0) {
			if (result <= 0) {
				dev_err(disk_to_dev(nbd->disk), "Receive data failed (result %d)\n",
				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)
	for (i = 0; i < config->num_connections; i++) {
	for (i = 0; i < config->num_connections; i++) {
		struct nbd_sock *nsock = config->socks[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);
		mutex_lock(&nsock->tx_lock);
		ret = sock_xmit(nbd, i, 1, &from, 0, NULL);
		ret = sock_xmit(nbd, i, 1, &from, 0, NULL);
		if (ret <= 0)
		if (ret <= 0)
+2 −2
Original line number Original line Diff line number Diff line
@@ -638,7 +638,7 @@ static void sbefifo_collect_async_ffdc(struct sbefifo *sbefifo)
	}
	}
        ffdc_iov.iov_base = ffdc;
        ffdc_iov.iov_base = ffdc;
	ffdc_iov.iov_len = SBEFIFO_MAX_FFDC_SIZE;
	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[0] = cpu_to_be32(2);
	cmd[1] = cpu_to_be32(SBEFIFO_CMD_GET_SBE_FFDC);
	cmd[1] = cpu_to_be32(SBEFIFO_CMD_GET_SBE_FFDC);
	rc = sbefifo_do_command(sbefifo, cmd, 2, &ffdc_iter);
	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,
	rbytes = (*resp_len) * sizeof(__be32);
	rbytes = (*resp_len) * sizeof(__be32);
	resp_iov.iov_base = response;
	resp_iov.iov_base = response;
	resp_iov.iov_len = rbytes;
	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 */
	/* Perform the command */
	mutex_lock(&sbefifo->lock);
	mutex_lock(&sbefifo->lock);
Loading