linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Akinobu Mita <akinobu.mita@gmail.com>
To: linux-scsi@vger.kernel.org
Cc: Akinobu Mita <akinobu.mita@gmail.com>,
	"James E.J. Bottomley" <JBottomley@parallels.com>,
	Douglas Gilbert <dgilbert@interlog.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>
Subject: [PATCH 2/5] scsi_debug: factor out copying PI from dif_storep to prot_sglist
Date: Wed, 18 Sep 2013 21:27:25 +0900	[thread overview]
Message-ID: <1379507248-15929-3-git-send-email-akinobu.mita@gmail.com> (raw)
In-Reply-To: <1379507248-15929-1-git-send-email-akinobu.mita@gmail.com>

If data integrity support is enabled, prot_verify_read() is called in
response to READ commands and it verifies protection info from dif_storep
by comparing against fake_storep, and copies protection info to
prot_sglist.

This factors out the portion of copying protection info into a separate
function.  It will also be reused in the next change after supporting
the opposite direction (copying prot_sglist to dif_storep).

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>
Cc: Douglas Gilbert <dgilbert@interlog.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org
---
 drivers/scsi/scsi_debug.c | 52 ++++++++++++++++++++++++++---------------------
 1 file changed, 29 insertions(+), 23 deletions(-)

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index f640b6b..99e74d7 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -1789,37 +1789,16 @@ static int dif_verify(struct sd_dif_tuple *sdt, const void *data,
 	return 0;
 }
 
-static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec,
-			    unsigned int sectors, u32 ei_lba)
+static void dif_copy_prot(struct scsi_cmnd *SCpnt, sector_t sector,
+			  unsigned int sectors)
 {
 	unsigned int i, resid;
 	struct scatterlist *psgl;
-	struct sd_dif_tuple *sdt;
-	sector_t sector;
 	void *paddr;
 	const void *dif_store_end = dif_storep + sdebug_store_sectors;
 
-	for (i = 0; i < sectors; i++) {
-		int ret;
-
-		sector = start_sec + i;
-		sdt = dif_store(sector);
-
-		if (sdt->app_tag == 0xffff)
-			continue;
-
-		ret = dif_verify(sdt, fake_store(sector), sector, ei_lba);
-		if (ret) {
-			dif_errors++;
-			return ret;
-		}
-
-		ei_lba++;
-	}
-
 	/* Bytes of protection data to copy into sgl */
 	resid = sectors * sizeof(*dif_storep);
-	sector = start_sec;
 
 	scsi_for_each_prot_sg(SCpnt, psgl, scsi_prot_sg_count(SCpnt), i) {
 		int len = min(psgl->length, resid);
@@ -1839,7 +1818,34 @@ static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec,
 		resid -= len;
 		kunmap_atomic(paddr);
 	}
+}
+
+static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec,
+			    unsigned int sectors, u32 ei_lba)
+{
+	unsigned int i;
+	struct sd_dif_tuple *sdt;
+	sector_t sector;
+
+	for (i = 0; i < sectors; i++) {
+		int ret;
+
+		sector = start_sec + i;
+		sdt = dif_store(sector);
+
+		if (sdt->app_tag == 0xffff)
+			continue;
+
+		ret = dif_verify(sdt, fake_store(sector), sector, ei_lba);
+		if (ret) {
+			dif_errors++;
+			return ret;
+		}
+
+		ei_lba++;
+	}
 
+	dif_copy_prot(SCpnt, start_sec, sectors);
 	dix_reads++;
 
 	return 0;
-- 
1.8.3.1


  parent reply	other threads:[~2013-09-18 12:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-18 12:27 [PATCH 0/5] scsi_debug: several fixes related to data integrity support Akinobu Mita
2013-09-18 12:27 ` [PATCH 1/5] scsi_debug: fix buffer overrun when DIF/DIX is enabled and virtual_gb > 0 Akinobu Mita
2013-09-20 22:13   ` Martin K. Petersen
2013-09-18 12:27 ` Akinobu Mita [this message]
2013-09-20 22:20   ` [PATCH 2/5] scsi_debug: factor out copying PI from dif_storep to prot_sglist Martin K. Petersen
2013-09-18 12:27 ` [PATCH 3/5] scsi_debug: avoid partial copying PI from prot_sglist to dif_storep Akinobu Mita
2013-09-20 22:23   ` Martin K. Petersen
2013-09-18 12:27 ` [PATCH 4/5] scsi_debug: fix invalid value check for guard module parameter Akinobu Mita
2013-09-20 22:23   ` Martin K. Petersen
2013-09-18 12:27 ` [PATCH 5/5] scsi_debug: fix sparse warnings related to data integrity field Akinobu Mita
2013-09-20 22:24   ` Martin K. Petersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1379507248-15929-3-git-send-email-akinobu.mita@gmail.com \
    --to=akinobu.mita@gmail.com \
    --cc=JBottomley@parallels.com \
    --cc=dgilbert@interlog.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).