lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1427012095-4095-3-git-send-email-ming.lei@canonical.com>
Date:	Sun, 22 Mar 2015 16:14:53 +0800
From:	Ming Lei <ming.lei@...onical.com>
To:	Jens Axboe <axboe@...com>, linux-kernel@...r.kernel.org
Cc:	Christoph Hellwig <hch@....de>, Al Viro <viro@...iv.linux.org.uk>,
	Maxim Patlasov <mpatlasov@...allels.com>,
	Ming Lei <ming.lei@...onical.com>
Subject: [PATCH 2/3] block: loop: unify interface type of lo_send and lo_receive

Preparing for conversion to vfs iterator based read/write, also
pass 'loop_cmd' instead of 'request' so that rw common stuff
can be put into loop_cmd easily.

Signed-off-by: Ming Lei <ming.lei@...onical.com>
---
 drivers/block/loop.c |   29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 965f117..c082cf7 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -289,7 +289,7 @@ static int do_lo_send_write(struct loop_device *lo, struct bio_vec *bvec,
 	return ret;
 }
 
-static int lo_send(struct loop_device *lo, struct request *rq, loff_t pos)
+static int lo_send(struct loop_device *lo, struct loop_cmd *cmd, loff_t pos)
 {
 	int (*do_lo_send)(struct loop_device *, struct bio_vec *, loff_t,
 			struct page *page);
@@ -297,6 +297,7 @@ static int lo_send(struct loop_device *lo, struct request *rq, loff_t pos)
 	struct req_iterator iter;
 	struct page *page = NULL;
 	int ret = 0;
+	struct request *rq = cmd->rq;
 
 	if (lo->transfer != transfer_none) {
 		page = alloc_page(GFP_NOIO | __GFP_HIGHMEM);
@@ -394,11 +395,13 @@ do_lo_receive(struct loop_device *lo,
 }
 
 static int
-lo_receive(struct loop_device *lo, struct request *rq, int bsize, loff_t pos)
+lo_receive(struct loop_device *lo, struct loop_cmd *cmd, loff_t pos)
 {
 	struct bio_vec bvec;
 	struct req_iterator iter;
 	ssize_t s;
+	struct request *rq = cmd->rq;
+	int	bsize = lo->lo_blocksize;
 
 	rq_for_each_segment(bvec, rq, iter) {
 		s = do_lo_receive(lo, &bvec, bsize, pos);
@@ -451,10 +454,24 @@ static int lo_req_flush(struct loop_device *lo, struct request *rq)
 	return ret;
 }
 
-static int do_req_filebacked(struct loop_device *lo, struct request *rq)
+static inline int lo_rw(struct loop_device *lo, struct loop_cmd *cmd,
+		loff_t pos, int rw)
+{
+	int ret;
+
+	if (rw == READ)
+		ret = lo_receive(lo, cmd, pos);
+	else
+		ret = lo_send(lo, cmd, pos);
+
+	return ret;
+}
+
+static int do_req_filebacked(struct loop_device *lo, struct loop_cmd *cmd)
 {
 	loff_t pos;
 	int ret;
+	struct request *rq = cmd->rq;
 
 	pos = ((loff_t) blk_rq_pos(rq) << 9) + lo->lo_offset;
 
@@ -464,9 +481,9 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
 		else if (rq->cmd_flags & REQ_DISCARD)
 			ret = lo_discard(lo, rq, pos);
 		else
-			ret = lo_send(lo, rq, pos);
+			ret = lo_rw(lo, cmd, pos, WRITE);
 	} else
-		ret = lo_receive(lo, rq, lo->lo_blocksize, pos);
+		ret = lo_rw(lo, cmd, pos, READ);
 
 	return ret;
 }
@@ -1514,7 +1531,7 @@ static void loop_handle_cmd(struct loop_cmd *cmd)
 	if (write && (lo->lo_flags & LO_FLAGS_READ_ONLY))
 		goto failed;
 
-	ret = do_req_filebacked(lo, cmd->rq);
+	ret = do_req_filebacked(lo, cmd);
 
  failed:
 	if (ret)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ