Skip to contentSkip to conversation

block,scsi,ide: unify sector and data_len, take#2

PATCH In review Tejun Heo 8 participants 58 messages May 4, 2009 – May 13, 2009

Subsystems (25)
lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

PATCH 1/1 block,scsi,ide: unify sector and data_len, take#2

Hello,

Upon ack, please pull from the following git tree.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git block-unify-sector-and-data_len

This is the second take of block-unify-sector-and-data_len patchset. The primary goal of this patchset is to consolidate all the similar bug slightly different current position and data length fields in struct request. For detailed description, please read the description in the last take[L]. Changes from the last take[L] are

* Acked-by:'s added

* osd resid_len conversion was missing as pointed out by Boaz Harrosh, fixed.

* patch to cleanup request length accessor usages after the conversion added.

This patchset contains the following eleven patches.

0001-nbd-don-t-clear-rq-sector-and-nr_sectors-unnecessa.patch 0002-ide-tape-don-t-initialize-rq-sector-for-rw-request.patch 0003-block-add-rq-resid_len.patch 0004-block-implement-blk_rq_pos-cur_-sectors-and-conv.patch 0005-block-convert-to-pos-and-nr_sectors-accessors.patch 0006-ide-convert-to-rq-pos-and-nr_sectors-accessors.patch 0007-block-drop-request-hard_-and-nr_sectors.patch 0008-block-cleanup-rq-data_len-usages.patch 0009-ide-cleanup-rq-data_len-usages.patch 0010-block-hide-request-sector-and-data_len.patch 0011-block-blk_rq_-cur_-_-sectors-bytes-usage-cleanup.patch

This patchset is on top of

linux-2.6-block#for-2.6.31 (f68adec3c7155a8bbf32a90cb4c4d0737df045d9)
+ linux-2.6-ide#for-next (03682411b1ccd38cbde2e9a6ab43884ff34fbefc)

and contains the following changes.

 arch/um/drivers/ubd_kern.c               |    2 
 block/as-iosched.c                       |   18 +++--
 block/blk-barrier.c                      |    4 -
 block/blk-core.c                         |  100 ++++++++++++-------------------
 block/blk-map.c                          |    2 
 block/blk-merge.c                        |   46 ++------------
 block/blk.h                              |    1 
 block/bsg.c                              |    8 +-
 block/cfq-iosched.c                      |   30 ++++-----
 block/deadline-iosched.c                 |    2 
 block/elevator.c                         |   22 +++---
 block/scsi_ioctl.c                       |    2 
 drivers/ata/libata-scsi.c                |    2 
 drivers/block/DAC960.c                   |    6 -
 drivers/block/amiflop.c                  |    6 -
 drivers/block/ataflop.c                  |   10 +--
 drivers/block/cciss.c                    |   35 ++++------
 drivers/block/cpqarray.c                 |    9 +-
 drivers/block/floppy.c                   |   54 ++++++++--------
 drivers/block/hd.c                       |   14 ++--
 drivers/block/nbd.c                      |   19 +----
 drivers/block/paride/pcd.c               |    4 -
 drivers/block/paride/pd.c                |    8 +-
 drivers/block/paride/pf.c                |    8 +-
 drivers/block/ps3disk.c                  |    9 +-
 drivers/block/sunvdc.c                   |    2 
 drivers/block/swim3.c                    |   34 +++++-----
 drivers/block/sx8.c                      |    6 -
 drivers/block/ub.c                       |   16 ++--
 drivers/block/viodasd.c                  |    8 +-
 drivers/block/virtio_blk.c               |    2 
 drivers/block/xd.c                       |    4 -
 drivers/block/xen-blkfront.c             |   11 +--
 drivers/block/xsysace.c                  |   25 ++++---
 drivers/block/z2ram.c                    |    6 -
 drivers/cdrom/gdrom.c                    |    6 -
 drivers/cdrom/viocd.c                    |    2 
 drivers/ide/ide-atapi.c                  |   13 ----
 drivers/ide/ide-cd.c                     |   44 ++++---------
 drivers/ide/ide-disk.c                   |    8 +-
 drivers/ide/ide-dma.c                    |    2 
 drivers/ide/ide-floppy.c                 |   10 +--
 drivers/ide/ide-io.c                     |   10 +--
 drivers/ide/ide-lib.c                    |    2 
 drivers/ide/ide-tape.c                   |   11 +--
 drivers/ide/ide-taskfile.c               |    2 
 drivers/ide/pdc202xx_old.c               |    2 
 drivers/ide/tc86c001.c                   |    2 
 drivers/ide/tx4939ide.c                  |    2 
 drivers/memstick/core/mspro_block.c      |    6 -
 drivers/message/fusion/mptsas.c          |   21 +++---
 drivers/message/i2o/i2o_block.c          |   28 +++-----
 drivers/mmc/card/block.c                 |   10 +--
 drivers/mtd/mtd_blkdevs.c                |    7 +-
 drivers/s390/block/dasd.c                |    2 
 drivers/s390/block/dasd_diag.c           |    5 -
 drivers/s390/block/dasd_eckd.c           |    6 -
 drivers/s390/block/dasd_fba.c            |    7 +-
 drivers/s390/char/tape_34xx.c            |    2 
 drivers/s390/char/tape_3590.c            |    2 
 drivers/s390/char/tape_block.c           |    2 
 drivers/sbus/char/jsflash.c              |    4 -
 drivers/scsi/eata.c                      |   24 +++----
 drivers/scsi/libsas/sas_expander.c       |   14 +---
 drivers/scsi/libsas/sas_host_smp.c       |   52 ++++++++--------
 drivers/scsi/lpfc/lpfc_scsi.c            |   22 +++---
 drivers/scsi/mpt2sas/mpt2sas_transport.c |   23 +++----
 drivers/scsi/osd/osd_initiator.c         |    4 -
 drivers/scsi/scsi_lib.c                  |   46 ++++++--------
 drivers/scsi/scsi_tgt_lib.c              |    2 
 drivers/scsi/sd.c                        |   24 +++----
 drivers/scsi/sd_dif.c                    |    2 
 drivers/scsi/sg.c                        |    2 
 drivers/scsi/sr.c                        |   15 ++--
 drivers/scsi/st.c                        |    2 
 drivers/scsi/u14-34f.c                   |   22 +++---
 fs/exofs/osd.c                           |    4 -
 include/linux/bio.h                      |    6 -
 include/linux/blkdev.h                   |   56 ++++++++++-------
 include/linux/elevator.h                 |    2 
 include/scsi/scsi_cmnd.h                 |    2 
 kernel/trace/blktrace.c                  |   16 ++--
 82 files changed, 508 insertions(+), 585 deletions(-)

Thanks.

--
tejun

[L] http://lkml.org/lkml/2009/4/29/173

author
#1 lore raw

PATCH 1/11 nbd: don't clear rq->sector and nr_sectors unnecessarily

There's no reason to clear rq->sector and nr_sectors after calling blk_rq_init(). They're guaranteed to be clear. Drop unnecessary clearing.

[ Impact: cleanup ]

Cc Paul Clements <[email protected]>
---
 drivers/block/nbd.c |    7 -------
 1 files changed, 0 insertions(+), 7 deletions(-)
drivers/block/nbd.c +0 -7
index 4d6de4f..a9ab8be 100644
@@ -580,13 +580,6 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
 		blk_rq_init(NULL, &sreq);
 		sreq.cmd_type = REQ_TYPE_SPECIAL;
 		nbd_cmd(&sreq) = NBD_CMD_DISC;
-		/*
-		 * Set these to sane values in case server implementation
-		 * fails to check the request type first and also to keep
-		 * debugging output cleaner.
-		 */
-		sreq.sector = 0;
-		sreq.nr_sectors = 0;
 		if (!lo->sock)
 			return -EINVAL;
 		nbd_send_req(lo, &sreq);
Signature · 1 line
1.6.0.2
author
#2 lore raw

PATCH 2/11 ide-tape: don't initialize rq->sector for rw requests

In reply to Tejun Heo

rq->sector is set to the tape->first_frame but it's never actually used and not even in the correct unit (512 byte sectors). Don't set it.

[ Impact: cleanup ]

---
 drivers/ide/ide-tape.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/ide/ide-tape.c +0 -1
index 8dfc688..7149224 100644
@@ -892,7 +892,6 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int size)
 	rq->cmd_type = REQ_TYPE_SPECIAL;
 	rq->cmd[13] = cmd;
 	rq->rq_disk = tape->disk;
-	rq->sector = tape->first_frame;
 
 	if (size) {
 		ret = blk_rq_map_kern(drive->queue, rq, tape->buf, size,
Signature · 1 line
1.6.0.2
author
#3 lore raw

PATCH 3/11 block: add rq->resid_len

In reply to Tejun Heo

rq->data_len served two purposes - the length of data buffer on issue and the residual count on completion. This duality creates some headaches.

First of all, block layer and low level drivers can't really determine what rq->data_len contains while a request is executing. It could be the total request length or it coulde be anything else one of the lower layers is using to keep track of residual count. This complicates things because blk_rq_bytes() and thus [__]blk_end_request_all() relies on rq->data_len for PC commands. Drivers which want to report residual count should first cache the total request length, update rq->data_len and then complete the request with the cached data length.

Secondly, it makes requests default to reporting full residual count, ie. reporting that no data transfer occurred. The residual count is an exception not the norm; however, the driver should clear rq->data_len to zero to signify the normal cases while leaving it alone means no data transfer occurred at all. This reverse default behavior complicates code unnecessarily and renders block PC on some drivers (ide-tape/floppy) unuseable.

This patch adds rq->resid_len which is used only for residual count.

While at it, remove now unnecessasry blk_rq_bytes() caching in ide_pc_intr() as rq->data_len is not changed anymore.

Boaz: spotted missing conversion in osd.

[ Impact: cleanup residual count handling, report 0 resid by default ]

Cc James Bottomley <[email protected]>
Cc Bartlomiej Zolnierkiewicz <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Sergei Shtylyov <[email protected]>
Cc Mike Miller <[email protected]>
Cc Eric Moore <[email protected]>
Cc Alan Stern <[email protected]>
Cc FUJITA Tomonori <[email protected]>
Cc Doug Gilbert <[email protected]>
Cc Mike Miller <[email protected]>
Cc Eric Moore <[email protected]>
Cc Darrick J. Wong <[email protected]>
Cc Pete Zaitcev <[email protected]>
Cc Boaz Harrosh <[email protected]>
---
 block/bsg.c                              |    8 +++---
 block/scsi_ioctl.c                       |    2 +-
 drivers/block/cciss.c                    |   13 +++-------
 drivers/block/ub.c                       |    6 +---
 drivers/ide/ide-atapi.c                  |    9 +------
 drivers/ide/ide-cd.c                     |   13 ++++------
 drivers/ide/ide-tape.c                   |    4 +-
 drivers/message/fusion/mptsas.c          |    3 +-
 drivers/scsi/libsas/sas_expander.c       |    6 +----
 drivers/scsi/libsas/sas_host_smp.c       |   38 +++++++++++++++--------------
 drivers/scsi/mpt2sas/mpt2sas_transport.c |    4 +--
 drivers/scsi/scsi_lib.c                  |   24 +++++++++---------
 drivers/scsi/sg.c                        |    2 +-
 drivers/scsi/st.c                        |    2 +-
 fs/exofs/osd.c                           |    4 +-
 include/linux/blkdev.h                   |    1 +
 16 files changed, 59 insertions(+), 80 deletions(-)
block/bsg.c +4 -4
index 206060e..2d746e3 100644
@@ -445,14 +445,14 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
 	}
 
 	if (rq->next_rq) {
-		hdr->dout_resid = rq->data_len;
-		hdr->din_resid = rq->next_rq->data_len;
+		hdr->dout_resid = rq->resid_len;
+		hdr->din_resid = rq->next_rq->resid_len;
 		blk_rq_unmap_user(bidi_bio);
 		blk_put_request(rq->next_rq);
 	} else if (rq_data_dir(rq) == READ)
-		hdr->din_resid = rq->data_len;
+		hdr->din_resid = rq->resid_len;
 	else
-		hdr->dout_resid = rq->data_len;
+		hdr->dout_resid = rq->resid_len;
 
 	/*
 	 * If the request generated a negative error number, return it
block/scsi_ioctl.c +1 -1
index 58cf456..a9670dd 100644
@@ -230,7 +230,7 @@ static int blk_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr,
 	hdr->info = 0;
 	if (hdr->masked_status || hdr->host_status || hdr->driver_status)
 		hdr->info |= SG_INFO_CHECK;
-	hdr->resid = rq->data_len;
+	hdr->resid = rq->resid_len;
 	hdr->sb_len_wr = 0;
 
 	if (rq->sense_len && hdr->sbp) {
drivers/block/cciss.c +4 -9
index 4d4d5e0..f22d493 100644
@@ -1299,7 +1299,6 @@ static void cciss_softirq_done(struct request *rq)
 {
 	CommandList_struct *cmd = rq->completion_data;
 	ctlr_info_t *h = hba[cmd->ctlr];
-	unsigned int nr_bytes;
 	unsigned long flags;
 	u64bit temp64;
 	int i, ddir;
@@ -1321,15 +1320,11 @@ static void cciss_softirq_done(struct request *rq)
 	printk("Done with %p\n", rq);
 #endif				/* CCISS_DEBUG */
 
-	/*
-	 * Store the full size and set the residual count for pc requests
-	 */
-	nr_bytes = blk_rq_bytes(rq);
+	/* set the residual count for pc requests */
 	if (blk_pc_request(rq))
-		rq->data_len = cmd->err_info->ResidualCnt;
+		rq->resid_len = cmd->err_info->ResidualCnt;
 
-	if (blk_end_request(rq, (rq->errors == 0) ? 0 : -EIO, nr_bytes))
-		BUG();
+	blk_end_request_all(rq, (rq->errors == 0) ? 0 : -EIO);
 
 	spin_lock_irqsave(&h->lock, flags);
 	cmd_free(h, cmd, 1);
@@ -2691,7 +2686,7 @@ static inline void complete_command(ctlr_info_t *h, CommandList_struct *cmd,
 			printk(KERN_WARNING "cciss: cmd %p has"
 			       " completed with data underrun "
 			       "reported\n", cmd);
-			cmd->rq->data_len = cmd->err_info->ResidualCnt;
+			cmd->rq->resid_len = cmd->err_info->ResidualCnt;
 		}
 		break;
 	case CMD_DATA_OVERRUN:
drivers/block/ub.c +2 -4
index 689cd27..8c2cc71 100644
@@ -783,10 +783,8 @@ static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
 
 	if (cmd->error == 0) {
 		if (blk_pc_request(rq)) {
-			if (cmd->act_len >= rq->data_len)
-				rq->data_len = 0;
-			else
-				rq->data_len -= cmd->act_len;
+			if (cmd->act_len < rq->data_len)
+				rq->resid_len = rq->data_len - cmd->act_len;
 			scsi_status = 0;
 		} else {
 			if (cmd->act_len != cmd->len) {
drivers/ide/ide-atapi.c +1 -8
index afe5a43..e4a02a0 100644
@@ -367,7 +367,6 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
 	/* No more interrupts */
 	if ((stat & ATA_DRQ) == 0) {
 		int uptodate, error;
-		unsigned int done;
 
 		debug_log("Packet command completed, %d bytes transferred\n",
 			  pc->xferred);
@@ -406,12 +405,6 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
 		if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0)
 			dsc = 1;
 
-		/*
-		 * ->pc_callback() might change rq->data_len for
-		 * residual count, cache total length.
-		 */
-		done = blk_rq_bytes(rq);
-
 		/* Command finished - Call the callback function */
 		uptodate = drive->pc_callback(drive, dsc);
 
@@ -431,7 +424,7 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
 			error = uptodate ? 0 : -EIO;
 		}
 
-		ide_complete_rq(drive, error, done);
+		ide_complete_rq(drive, error, blk_rq_bytes(rq));
 		return ide_stopped;
 	}
 
drivers/ide/ide-cd.c +5 -8
index a75e4ee..cc8ac5b 100644
@@ -518,7 +518,7 @@ int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd,
 		error = blk_execute_rq(drive->queue, info->disk, rq, 0);
 
 		if (buffer)
-			*bufflen = rq->data_len;
+			*bufflen = rq->resid_len;
 
 		flags = rq->cmd_flags;
 		blk_put_request(rq);
@@ -706,11 +706,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
 
 out_end:
 	if (blk_pc_request(rq) && rc == 0) {
-		unsigned int dlen = rq->data_len;
-
-		rq->data_len = 0;
-
-		if (blk_end_request(rq, 0, dlen))
+		if (blk_end_request(rq, 0, rq->data_len))
 			BUG();
 
 		hwif->rq = NULL;
@@ -739,9 +735,10 @@ out_end:
 			nsectors = 1;
 
 		if (blk_fs_request(rq) == 0) {
-			rq->data_len -= (cmd->nbytes - cmd->nleft);
+			rq->resid_len = rq->data_len -
+				(cmd->nbytes - cmd->nleft);
 			if (uptodate == 0 && (cmd->tf_flags & IDE_TFLAG_WRITE))
-				rq->data_len += cmd->last_xfer_len;
+				rq->resid_len += cmd->last_xfer_len;
 		}
 
 		ide_complete_rq(drive, uptodate ? 0 : -EIO, nsectors << 9);
drivers/ide/ide-tape.c +2 -2
index 7149224..3813a0e 100644
@@ -380,7 +380,7 @@ static int ide_tape_callback(ide_drive_t *drive, int dsc)
 		}
 
 		tape->first_frame += blocks;
-		rq->data_len -= blocks * tape->blk_size;
+		rq->resid_len = blk_rq_bytes(rq) - blocks * tape->blk_size;
 
 		if (pc->error) {
 			uptodate = 0;
@@ -903,7 +903,7 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int size)
 	blk_execute_rq(drive->queue, tape->disk, rq, 0);
 
 	/* calculate the number of transferred bytes and update buffer state */
-	size -= rq->data_len;
+	size -= rq->resid_len;
 	tape->cur = tape->buf;
 	if (cmd == REQ_IDETAPE_READ)
 		tape->valid = size;
drivers/message/fusion/mptsas.c +1 -2
index a9019f0..5d5f347 100644
@@ -1357,8 +1357,7 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 		smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
 		memcpy(req->sense, smprep, sizeof(*smprep));
 		req->sense_len = sizeof(*smprep);
-		req->data_len = 0;
-		rsp->data_len -= smprep->ResponseDataLength;
+		rsp->resid_len = rsp->data_len - smprep->ResponseDataLength;
 	} else {
 		printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n",
 		    ioc->name, __func__);
drivers/scsi/libsas/sas_expander.c +1 -5
index 3da02e4..6605ec9 100644
@@ -1936,12 +1936,8 @@ int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 			       bio_data(rsp->bio), rsp->data_len);
 	if (ret > 0) {
 		/* positive number is the untransferred residual */
-		rsp->data_len = ret;
-		req->data_len = 0;
+		rsp->resid_len = ret;
 		ret = 0;
-	} else if (ret == 0) {
-		rsp->data_len = 0;
-		req->data_len = 0;
 	}
 
 	return ret;
drivers/scsi/libsas/sas_host_smp.c +20 -18
index d110a36..89952ed 100644
@@ -134,7 +134,7 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 {
 	u8 *req_data = NULL, *resp_data = NULL, *buf;
 	struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
-	int error = -EINVAL, resp_data_len = rsp->data_len;
+	int error = -EINVAL;
 
 	/* eight is the minimum size for request and response frames */
 	if (req->data_len < 8 || rsp->data_len < 8)
@@ -176,17 +176,20 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 	resp_data[1] = req_data[1];
 	resp_data[2] = SMP_RESP_FUNC_UNK;
 
+	req->resid_len = req->data_len;
+	rsp->resid_len = rsp->data_len;
+
 	switch (req_data[1]) {
 	case SMP_REPORT_GENERAL:
-		req->data_len -= 8;
-		resp_data_len -= 32;
+		req->resid_len -= 8;
+		rsp->resid_len -= 32;
 		resp_data[2] = SMP_RESP_FUNC_ACC;
 		resp_data[9] = sas_ha->num_phys;
 		break;
 
 	case SMP_REPORT_MANUF_INFO:
-		req->data_len -= 8;
-		resp_data_len -= 64;
+		req->resid_len -= 8;
+		rsp->resid_len -= 64;
 		resp_data[2] = SMP_RESP_FUNC_ACC;
 		memcpy(resp_data + 12, shost->hostt->name,
 		       SAS_EXPANDER_VENDOR_ID_LEN);
@@ -199,13 +202,13 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 		break;
 
 	case SMP_DISCOVER:
-		req->data_len -= 16;
-		if ((int)req->data_len < 0) {
-			req->data_len = 0;
+		req->resid_len -= 16;
+		if ((int)req->resid_len < 0) {
+			req->resid_len = 0;
 			error = -EINVAL;
 			goto out;
 		}
-		resp_data_len -= 56;
+		rsp->resid_len -= 56;
 		sas_host_smp_discover(sas_ha, resp_data, req_data[9]);
 		break;
 
@@ -215,13 +218,13 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 		break;
 
 	case SMP_REPORT_PHY_SATA:
-		req->data_len -= 16;
-		if ((int)req->data_len < 0) {
-			req->data_len = 0;
+		req->resid_len -= 16;
+		if ((int)req->resid_len < 0) {
+			req->resid_len = 0;
 			error = -EINVAL;
 			goto out;
 		}
-		resp_data_len -= 60;
+		rsp->resid_len -= 60;
 		sas_report_phy_sata(sas_ha, resp_data, req_data[9]);
 		break;
 
@@ -238,13 +241,13 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 		break;
 
 	case SMP_PHY_CONTROL:
-		req->data_len -= 44;
-		if ((int)req->data_len < 0) {
-			req->data_len = 0;
+		req->resid_len -= 44;
+		if ((int)req->resid_len < 0) {
+			req->resid_len = 0;
 			error = -EINVAL;
 			goto out;
 		}
-		resp_data_len -= 8;
+		rsp->resid_len -= 8;
 		sas_phy_control(sas_ha, req_data[9], req_data[10],
 				req_data[32] >> 4, req_data[33] >> 4,
 				resp_data);
@@ -265,7 +268,6 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 	flush_kernel_dcache_page(bio_page(rsp->bio));
 	kunmap_atomic(buf - bio_offset(rsp->bio), KM_USER0);
 	local_irq_enable();
-	rsp->data_len = resp_data_len;
 
  out:
 	kfree(req_data);
drivers/scsi/mpt2sas/mpt2sas_transport.c +1 -3
index e03dc0b..53759c5 100644
@@ -1170,9 +1170,7 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 
 		memcpy(req->sense, mpi_reply, sizeof(*mpi_reply));
 		req->sense_len = sizeof(*mpi_reply);
-		req->data_len = 0;
-		rsp->data_len -= mpi_reply->ResponseDataLength;
-
+		rsp->resid_len = rsp->data_len - mpi_reply->ResponseDataLength;
 	} else {
 		dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT
 		    "%s - no reply\n", ioc->name, __func__));
drivers/scsi/scsi_lib.c +12 -12
index aa9fc57..7d49ef5 100644
@@ -240,11 +240,11 @@ int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
 	 * is invalid.  Prevent the garbage from being misinterpreted
 	 * and prevent security leaks by zeroing out the excess data.
 	 */
-	if (unlikely(req->data_len > 0 && req->data_len <= bufflen))
-		memset(buffer + (bufflen - req->data_len), 0, req->data_len);
+	if (unlikely(req->resid_len > 0 && req->resid_len <= bufflen))
+		memset(buffer + (bufflen - req->resid_len), 0, req->resid_len);
 
 	if (resid)
-		*resid = req->data_len;
+		*resid = req->resid_len;
 	ret = req->errors;
  out:
 	blk_put_request(req);
@@ -549,7 +549,7 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error,
 		int leftover = (req->hard_nr_sectors << 9);
 
 		if (blk_pc_request(req))
-			leftover = req->data_len;
+			leftover = req->resid_len;
 
 		/* kill remainder if no retrys */
 		if (error && scsi_noretry_cmd(cmd))
@@ -673,11 +673,11 @@ void scsi_release_buffers(struct scsi_cmnd *cmd)
 EXPORT_SYMBOL(scsi_release_buffers);
 
 /*
- * Bidi commands Must be complete as a whole, both sides at once.
- * If part of the bytes were written and lld returned
- * scsi_in()->resid and/or scsi_out()->resid this information will be left
- * in req->data_len and req->next_rq->data_len. The upper-layer driver can
- * decide what to do with this information.
+ * Bidi commands Must be complete as a whole, both sides at once.  If
+ * part of the bytes were written and lld returned scsi_in()->resid
+ * and/or scsi_out()->resid this information will be left in
+ * req->resid_len and req->next_rq->resid_len. The upper-layer driver
+ * can decide what to do with this information.
  */
 static void scsi_end_bidi_request(struct scsi_cmnd *cmd)
 {
@@ -685,8 +685,8 @@ static void scsi_end_bidi_request(struct scsi_cmnd *cmd)
 	unsigned int dlen = req->data_len;
 	unsigned int next_dlen = req->next_rq->data_len;
 
-	req->data_len = scsi_out(cmd)->resid;
-	req->next_rq->data_len = scsi_in(cmd)->resid;
+	req->resid_len = scsi_out(cmd)->resid;
+	req->next_rq->resid_len = scsi_in(cmd)->resid;
 
 	/* The req and req->next_rq have not been completed */
 	BUG_ON(blk_end_bidi_request(req, 0, dlen, next_dlen));
@@ -778,7 +778,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
 			scsi_end_bidi_request(cmd);
 			return;
 		}
-		req->data_len = scsi_get_resid(cmd);
+		req->resid_len = scsi_get_resid(cmd);
 	}
 
 	BUG_ON(blk_bidi_rq(req)); /* bidi not support for !blk_pc_request yet */
drivers/scsi/sg.c +1 -1
index 82312df..dec4c70 100644
@@ -1260,7 +1260,7 @@ static void sg_rq_end_io(struct request *rq, int uptodate)
 
 	sense = rq->sense;
 	result = rq->errors;
-	resid = rq->data_len;
+	resid = rq->resid_len;
 
 	SCSI_LOG_TIMEOUT(4, printk("sg_cmd_done: %s, pack_id=%d, res=0x%x\n",
 		sdp->disk->disk_name, srp->header.pack_id, result));
drivers/scsi/st.c +1 -1
index eb24efe..8681b70 100644
@@ -463,7 +463,7 @@ static void st_scsi_execute_end(struct request *req, int uptodate)
 	struct scsi_tape *STp = SRpnt->stp;
 
 	STp->buffer->cmdstat.midlevel_result = SRpnt->result = req->errors;
-	STp->buffer->cmdstat.residual = req->data_len;
+	STp->buffer->cmdstat.residual = req->resid_len;
 
 	if (SRpnt->waiting)
 		complete(SRpnt->waiting);
fs/exofs/osd.c +2 -2
index b249ae9..06ca926 100644
@@ -50,10 +50,10 @@ int exofs_check_ok_resid(struct osd_request *or, u64 *in_resid, u64 *out_resid)
 
 	/* FIXME: should be include in osd_sense_info */
 	if (in_resid)
-		*in_resid = or->in.req ? or->in.req->data_len : 0;
+		*in_resid = or->in.req ? or->in.req->resid_len : 0;
 
 	if (out_resid)
-		*out_resid = or->out.req ? or->out.req->data_len : 0;
+		*out_resid = or->out.req ? or->out.req->resid_len : 0;
 
 	return ret;
 }
include/linux/blkdev.h +1 -0
index e3726d6..7ab93d9 100644
@@ -229,6 +229,7 @@ struct request {
 	unsigned int data_len;
 	unsigned int extra_len;	/* length of alignment and padding */
 	unsigned int sense_len;
+	unsigned int resid_len;	/* residual count */
 	void *sense;
 
 	unsigned long deadline;
Signature · 1 line
1.6.0.2
#4 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Hello.

Quoted 32 lines · Tejun Heo

rq->data_len served two purposes - the length of data buffer on issue and the residual count on completion. This duality creates some headaches.

First of all, block layer and low level drivers can't really determine what rq->data_len contains while a request is executing. It could be the total request length or it coulde be anything else one of the lower layers is using to keep track of residual count. This complicates things because blk_rq_bytes() and thus [__]blk_end_request_all() relies on rq->data_len for PC commands. Drivers which want to report residual count should first cache the total request length, update rq->data_len and then complete the request with the cached data length.

Secondly, it makes requests default to reporting full residual count, ie. reporting that no data transfer occurred. The residual count is an exception not the norm; however, the driver should clear rq->data_len to zero to signify the normal cases while leaving it alone means no data transfer occurred at all. This reverse default behavior complicates code unnecessarily and renders block PC on some drivers (ide-tape/floppy) unuseable.

This patch adds rq->resid_len which is used only for residual count.

While at it, remove now unnecessasry blk_rq_bytes() caching in ide_pc_intr() as rq->data_len is not changed anymore.

Boaz: spotted missing conversion in osd.

[ Impact: cleanup residual count handling, report 0 resid by default ]

[...]

drivers/ide/ide-tape.c static int ide_tape_callback(ide_drive_t *drive, int dsc) · line 383

Quoted 10 lines
drivers/ide/ide-tape.c +1 -1
index 7149224..3813a0e 100644
@@ -380,7 +380,7 @@ static int ide_tape_callback(ide_drive_t *drive, int dsc)
 		}
 
 		tape->first_frame += blocks;
-		rq->data_len -= blocks * tape->blk_size;
+		rq->resid_len = blk_rq_bytes(rq) - blocks * tape->blk_size;

Is it already guaranteed that rq->data_len == blk_rq_bytes(rq) here?

MBR, Sergei

author
#5 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 8 lines · Sergei Shtylyov
Quoted 8 lines
drivers/ide/ide-tape.c +0 -0
index 7149224..3813a0e 100644
@@ -380,7 +380,7 @@ static int ide_tape_callback(ide_drive_t *drive,
 int dsc)
         }
 
Quoted 5 lines

drivers/ide/ide-tape.c static int ide_tape_callback(ide_drive_t *drive, int dsc) · line 383

Quoted 3 lines
drivers/ide/ide-tape.c +1 -1
         tape->first_frame += blocks;
-        rq->data_len -= blocks * tape->blk_size;
+        rq->resid_len = blk_rq_bytes(rq) - blocks * tape->blk_size;

Is it already guaranteed that rq->data_len == blk_rq_bytes(rq) here?

Oops, no. I'll move it to later ide-cleanup-rq-data_len-usages patch.

Thanks.

Signature · 1 line
tejun
Reviewed-by Reviewed-by Reviewed-by Reviewed-by Reviewed-by Reviewed-by on v1 3/11
#7 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

In reply to Tejun Heo
Quoted 49 lines · Tejun Heo

rq->data_len served two purposes - the length of data buffer on issue and the residual count on completion. This duality creates some headaches.

First of all, block layer and low level drivers can't really determine what rq->data_len contains while a request is executing. It could be the total request length or it coulde be anything else one of the lower layers is using to keep track of residual count. This complicates things because blk_rq_bytes() and thus [__]blk_end_request_all() relies on rq->data_len for PC commands. Drivers which want to report residual count should first cache the total request length, update rq->data_len and then complete the request with the cached data length.

Secondly, it makes requests default to reporting full residual count, ie. reporting that no data transfer occurred. The residual count is an exception not the norm; however, the driver should clear rq->data_len to zero to signify the normal cases while leaving it alone means no data transfer occurred at all. This reverse default behavior complicates code unnecessarily and renders block PC on some drivers (ide-tape/floppy) unuseable.

This patch adds rq->resid_len which is used only for residual count.

While at it, remove now unnecessasry blk_rq_bytes() caching in ide_pc_intr() as rq->data_len is not changed anymore.

Boaz: spotted missing conversion in osd.

[ Impact: cleanup residual count handling, report 0 resid by default ]

Cc James Bottomley <[email protected]>
Cc Bartlomiej Zolnierkiewicz <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Sergei Shtylyov <[email protected]>
Cc Mike Miller <[email protected]>
Cc Eric Moore <[email protected]>
Cc Alan Stern <[email protected]>
Cc FUJITA Tomonori <[email protected]>
Cc Doug Gilbert <[email protected]>
Cc Mike Miller <[email protected]>
Cc Eric Moore <[email protected]>
Cc Darrick J. Wong <[email protected]>
Cc Pete Zaitcev <[email protected]>
Cc Boaz Harrosh <[email protected]>
---
 block/bsg.c                              |    8 +++---
 block/scsi_ioctl.c                       |    2 +-

<snip>

Quoted 11 lines
 drivers/message/fusion/mptsas.c          |    3 +-
 drivers/scsi/libsas/sas_expander.c       |    6 +----
 drivers/scsi/libsas/sas_host_smp.c       |   38 +++++++++++++++--------------
 drivers/scsi/mpt2sas/mpt2sas_transport.c |    4 +--
 drivers/scsi/scsi_lib.c                  |   24 +++++++++---------
 drivers/scsi/sg.c                        |    2 +-
 drivers/scsi/st.c                        |    2 +-
 fs/exofs/osd.c                           |    4 +-
 include/linux/blkdev.h                   |    1 +
 16 files changed, 59 insertions(+), 80 deletions(-)

Hi Tejun, I've carefully reviewed these files which I know more about. The drivers/block files I've skipped, since I'm not familiar with this code.

Except a small fallout, it looks very good. See some comments plus Ack/review below

Thank you for doing this.

Quoted 13 lines
block/bsg.c +2 -2
index 206060e..2d746e3 100644
@@ -445,14 +445,14 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
 	}
 
 	if (rq->next_rq) {
-		hdr->dout_resid = rq->data_len;
-		hdr->din_resid = rq->next_rq->data_len;
+		hdr->dout_resid = rq->resid_len;
+		hdr->din_resid = rq->next_rq->resid_len;
 		blk_rq_unmap_user(bidi_bio);

block/bsg.c static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr, · line 458

Quoted 10 lines
block/bsg.c +2 -2
 		blk_put_request(rq->next_rq);
 	} else if (rq_data_dir(rq) == READ)
-		hdr->din_resid = rq->data_len;
+		hdr->din_resid = rq->resid_len;
 	else
-		hdr->dout_resid = rq->data_len;
+		hdr->dout_resid = rq->resid_len;
 
 	/*
 	 * If the request generated a negative error number, return it

block/scsi_ioctl.c static int blk_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr, · line 236

Quoted 13 lines
block/scsi_ioctl.c +1 -1
index 58cf456..a9670dd 100644
@@ -230,7 +230,7 @@ static int blk_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr,
 	hdr->info = 0;
 	if (hdr->masked_status || hdr->host_status || hdr->driver_status)
 		hdr->info |= SG_INFO_CHECK;
-	hdr->resid = rq->data_len;
+	hdr->resid = rq->resid_len;
 	hdr->sb_len_wr = 0;
 
 	if (rq->sense_len && hdr->sbp) {

<snip>

Quoted 5 lines
drivers/message/fusion/mptsas.c +0 -0
index a9019f0..5d5f347 100644

drivers/message/fusion/mptsas.c static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1363

Quoted 9 lines
drivers/message/fusion/mptsas.c +1 -2
@@ -1357,8 +1357,7 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 		smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
 		memcpy(req->sense, smprep, sizeof(*smprep));
 		req->sense_len = sizeof(*smprep);
-		req->data_len = 0;
-		rsp->data_len -= smprep->ResponseDataLength;
+		rsp->resid_len = rsp->data_len - smprep->ResponseDataLength;
 	} else {
 		printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n",
 		    ioc->name, __func__);

I think original code was assuming full residual count on the else side (not MPT_IOCTL_STATUS_RF_VALID). So maybe add:

+ rsp->resid_len = rsp->data_len;

Quoted 8 lines
drivers/scsi/libsas/sas_expander.c +0 -0
index 3da02e4..6605ec9 100644
@@ -1936,12 +1936,8 @@ int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 			       bio_data(rsp->bio), rsp->data_len);
 	if (ret > 0) {
 		/* positive number is the untransferred residual */

drivers/scsi/libsas/sas_expander.c int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1943

Quoted 10 lines
drivers/scsi/libsas/sas_expander.c +1 -5
-		rsp->data_len = ret;
-		req->data_len = 0;
+		rsp->resid_len = ret;
 		ret = 0;
-	} else if (ret == 0) {
-		rsp->data_len = 0;
-		req->data_len = 0;
 	}
 
 	return ret;

This is actually a bug fix, as well as a strait conversion

Quoted 93 lines
drivers/scsi/libsas/sas_host_smp.c +20 -17
index d110a36..89952ed 100644
@@ -134,7 +134,7 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 {
 	u8 *req_data = NULL, *resp_data = NULL, *buf;
 	struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
-	int error = -EINVAL, resp_data_len = rsp->data_len;
+	int error = -EINVAL;
 
 	/* eight is the minimum size for request and response frames */
 	if (req->data_len < 8 || rsp->data_len < 8)
@@ -176,17 +176,20 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 	resp_data[1] = req_data[1];
 	resp_data[2] = SMP_RESP_FUNC_UNK;
 
+	req->resid_len = req->data_len;
+	rsp->resid_len = rsp->data_len;
+
 	switch (req_data[1]) {
 	case SMP_REPORT_GENERAL:
-		req->data_len -= 8;
-		resp_data_len -= 32;
+		req->resid_len -= 8;
+		rsp->resid_len -= 32;
 		resp_data[2] = SMP_RESP_FUNC_ACC;
 		resp_data[9] = sas_ha->num_phys;
 		break;
 
 	case SMP_REPORT_MANUF_INFO:
-		req->data_len -= 8;
-		resp_data_len -= 64;
+		req->resid_len -= 8;
+		rsp->resid_len -= 64;
 		resp_data[2] = SMP_RESP_FUNC_ACC;
 		memcpy(resp_data + 12, shost->hostt->name,
 		       SAS_EXPANDER_VENDOR_ID_LEN);
@@ -199,13 +202,13 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 		break;
 
 	case SMP_DISCOVER:
-		req->data_len -= 16;
-		if ((int)req->data_len < 0) {
-			req->data_len = 0;
+		req->resid_len -= 16;
+		if ((int)req->resid_len < 0) {
+			req->resid_len = 0;
 			error = -EINVAL;
 			goto out;
 		}
-		resp_data_len -= 56;
+		rsp->resid_len -= 56;
 		sas_host_smp_discover(sas_ha, resp_data, req_data[9]);
 		break;
 
@@ -215,13 +218,13 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 		break;
 
 	case SMP_REPORT_PHY_SATA:
-		req->data_len -= 16;
-		if ((int)req->data_len < 0) {
-			req->data_len = 0;
+		req->resid_len -= 16;
+		if ((int)req->resid_len < 0) {
+			req->resid_len = 0;
 			error = -EINVAL;
 			goto out;
 		}
-		resp_data_len -= 60;
+		rsp->resid_len -= 60;
 		sas_report_phy_sata(sas_ha, resp_data, req_data[9]);
 		break;
 
@@ -238,13 +241,13 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 		break;
 
 	case SMP_PHY_CONTROL:
-		req->data_len -= 44;
-		if ((int)req->data_len < 0) {
-			req->data_len = 0;
+		req->resid_len -= 44;
+		if ((int)req->resid_len < 0) {
+			req->resid_len = 0;
 			error = -EINVAL;
 			goto out;
 		}
-		resp_data_len -= 8;
+		rsp->resid_len -= 8;
 		sas_phy_control(sas_ha, req_data[9], req_data[10],
 				req_data[32] >> 4, req_data[33] >> 4,
 				resp_data);

drivers/scsi/libsas/sas_host_smp.c int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req, · line 273

Quoted 7 lines
drivers/scsi/libsas/sas_host_smp.c +0 -1
@@ -265,7 +268,6 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 	flush_kernel_dcache_page(bio_page(rsp->bio));
 	kunmap_atomic(buf - bio_offset(rsp->bio), KM_USER0);
 	local_irq_enable();
-	rsp->data_len = resp_data_len;
 
  out:
 	kfree(req_data);
Quoted 5 lines
drivers/scsi/mpt2sas/mpt2sas_transport.c +0 -0
index e03dc0b..53759c5 100644

drivers/scsi/mpt2sas/mpt2sas_transport.c transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1176

Quoted 10 lines
drivers/scsi/mpt2sas/mpt2sas_transport.c +1 -3
@@ -1170,9 +1170,7 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 
 		memcpy(req->sense, mpi_reply, sizeof(*mpi_reply));
 		req->sense_len = sizeof(*mpi_reply);
-		req->data_len = 0;
-		rsp->data_len -= mpi_reply->ResponseDataLength;
-
+		rsp->resid_len = rsp->data_len - mpi_reply->ResponseDataLength;
 	} else {
 		dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT
 		    "%s - no reply\n", ioc->name, __func__));

Here it's the same as in mptsas_smp_handler. The else case was returning full residual count on error, maybe an:
+ rsp->resid_len = rsp->data_len;

Quoted 20 lines
drivers/scsi/scsi_lib.c +3 -3
index aa9fc57..7d49ef5 100644
@@ -240,11 +240,11 @@ int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
 	 * is invalid.  Prevent the garbage from being misinterpreted
 	 * and prevent security leaks by zeroing out the excess data.
 	 */
-	if (unlikely(req->data_len > 0 && req->data_len <= bufflen))
-		memset(buffer + (bufflen - req->data_len), 0, req->data_len);
+	if (unlikely(req->resid_len > 0 && req->resid_len <= bufflen))
+		memset(buffer + (bufflen - req->resid_len), 0, req->resid_len);
 
 	if (resid)
-		*resid = req->data_len;
+		*resid = req->resid_len;
 	ret = req->errors;
  out:
 	blk_put_request(req);

drivers/scsi/scsi_lib.c static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error, · line 552

Quoted 5 lines
drivers/scsi/scsi_lib.c +1 -1
@@ -549,7 +549,7 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error,
 		int leftover = (req->hard_nr_sectors << 9);
 
 		if (blk_pc_request(req))
-			leftover = req->data_len;
+			leftover = req->resid_len;

This is the fallout:

The above is just a case of:

- int leftover = (req->hard_nr_sectors << 9);
-
- if (blk_pc_request(req))
- leftover = req->data_len;
+ int leftover = blk_rq_bytes();

Which you separated into to stages, much later right?

Quoted 32 lines
drivers/scsi/scsi_lib.c +7 -7
 		/* kill remainder if no retrys */
 		if (error && scsi_noretry_cmd(cmd))
@@ -673,11 +673,11 @@ void scsi_release_buffers(struct scsi_cmnd *cmd)
 EXPORT_SYMBOL(scsi_release_buffers);
 
 /*
- * Bidi commands Must be complete as a whole, both sides at once.
- * If part of the bytes were written and lld returned
- * scsi_in()->resid and/or scsi_out()->resid this information will be left
- * in req->data_len and req->next_rq->data_len. The upper-layer driver can
- * decide what to do with this information.
+ * Bidi commands Must be complete as a whole, both sides at once.  If
+ * part of the bytes were written and lld returned scsi_in()->resid
+ * and/or scsi_out()->resid this information will be left in
+ * req->resid_len and req->next_rq->resid_len. The upper-layer driver
+ * can decide what to do with this information.
  */
 static void scsi_end_bidi_request(struct scsi_cmnd *cmd)
 {
@@ -685,8 +685,8 @@ static void scsi_end_bidi_request(struct scsi_cmnd *cmd)
 	unsigned int dlen = req->data_len;
 	unsigned int next_dlen = req->next_rq->data_len;
 
-	req->data_len = scsi_out(cmd)->resid;
-	req->next_rq->data_len = scsi_in(cmd)->resid;
+	req->resid_len = scsi_out(cmd)->resid;
+	req->next_rq->resid_len = scsi_in(cmd)->resid;
 
 	/* The req and req->next_rq have not been completed */
 	BUG_ON(blk_end_bidi_request(req, 0, dlen, next_dlen));

drivers/scsi/scsi_lib.c void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) · line 784

Quoted 8 lines
drivers/scsi/scsi_lib.c +1 -1
@@ -778,7 +778,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
 			scsi_end_bidi_request(cmd);
 			return;
 		}
-		req->data_len = scsi_get_resid(cmd);
+		req->resid_len = scsi_get_resid(cmd);
 	}
 
 	BUG_ON(blk_bidi_rq(req)); /* bidi not support for !blk_pc_request yet */

Except the fallout the rest of scsi_lib looks good, specifically the bidi_parts.

I'll send a farther cleanup to scsi_lib based on this patchset later.

drivers/scsi/sg.c static void sg_rq_end_io(struct request *rq, int uptodate) · line 1266

Quoted 13 lines
drivers/scsi/sg.c +1 -1
index 82312df..dec4c70 100644
@@ -1260,7 +1260,7 @@ static void sg_rq_end_io(struct request *rq, int uptodate)
 
 	sense = rq->sense;
 	result = rq->errors;
-	resid = rq->data_len;
+	resid = rq->resid_len;
 
 	SCSI_LOG_TIMEOUT(4, printk("sg_cmd_done: %s, pack_id=%d, res=0x%x\n",
 		sdp->disk->disk_name, srp->header.pack_id, result));

drivers/scsi/st.c static void st_scsi_execute_end(struct request *req, int uptodate) · line 469

Quoted 13 lines
drivers/scsi/st.c +1 -1
index eb24efe..8681b70 100644
@@ -463,7 +463,7 @@ static void st_scsi_execute_end(struct request *req, int uptodate)
 	struct scsi_tape *STp = SRpnt->stp;
 
 	STp->buffer->cmdstat.midlevel_result = SRpnt->result = req->errors;
-	STp->buffer->cmdstat.residual = req->data_len;
+	STp->buffer->cmdstat.residual = req->resid_len;
 
 	if (SRpnt->waiting)
 		complete(SRpnt->waiting);
Quoted 7 lines
fs/exofs/osd.c +0 -0
index b249ae9..06ca926 100644
@@ -50,10 +50,10 @@ int exofs_check_ok_resid(struct osd_request *or, u64 *in_resid, u64 *out_resid)
 
 	/* FIXME: should be include in osd_sense_info */

fs/exofs/osd.c int exofs_check_ok_resid(struct osd_request *or, u64 *in_resid, u64 *out_resid) · line 59

Quoted 10 lines
fs/exofs/osd.c +2 -2
 	if (in_resid)
-		*in_resid = or->in.req ? or->in.req->data_len : 0;
+		*in_resid = or->in.req ? or->in.req->resid_len : 0;
 
 	if (out_resid)
-		*out_resid = or->out.req ? or->out.req->data_len : 0;
+		*out_resid = or->out.req ? or->out.req->resid_len : 0;
 
 	return ret;
 }

<snip>

Dear Tejun.
I've started farther cleanup based on your patchset. However I had a merge conflict when merging your branch with Linus-2.6.30-rc5, around the block areas, do you know what that might be? I've continued to work based on your branch alone, but will wait and post it later once things settle.

Thanks
Boaz

author
#8 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Hello, Boaz.

Quoted 6 lines · Boaz Harrosh

Hi Tejun, I've carefully reviewed these files which I know more about. The drivers/block files I've skipped, since I'm not familiar with this code.

Except a small fallout, it looks very good. See some comments plus Ack/review below

Thanks a lot for reviewing it closely. It's really nice to have careful extra pair of eyes on the changes. :-)

Quoted 16 lines

drivers/message/fusion/mptsas.c static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1363

Quoted 12 lines
drivers/message/fusion/mptsas.c +1 -2
@@ -1357,8 +1357,7 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 		smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
 		memcpy(req->sense, smprep, sizeof(*smprep));
 		req->sense_len = sizeof(*smprep);
-		req->data_len = 0;
-		rsp->data_len -= smprep->ResponseDataLength;
+		rsp->resid_len = rsp->data_len - smprep->ResponseDataLength;
 	} else {
 		printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n",
 		    ioc->name, __func__);

I think original code was assuming full residual count on the else side (not MPT_IOCTL_STATUS_RF_VALID). So maybe add:

drivers/scsi/libsas/sas_host_smp.c int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req, · line 180

Quoted 1 line
drivers/scsi/libsas/sas_host_smp.c +1 -0
+		rsp->resid_len = rsp->data_len;

Does resid_len make any sense w/ failed requests? I think we would be better off with declaring residual count to be undefined on request failure. Is there any place which depends on it?

That said, the value is eventually exported to userland, so it might be better to not change it. Eh... I don't know.

Quoted 17 lines
Quoted 17 lines
drivers/scsi/libsas/sas_expander.c +1 -5
index 3da02e4..6605ec9 100644
@@ -1936,12 +1936,8 @@ int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 			       bio_data(rsp->bio), rsp->data_len);
 	if (ret > 0) {
 		/* positive number is the untransferred residual */
-		rsp->data_len = ret;
-		req->data_len = 0;
+		rsp->resid_len = ret;
 		ret = 0;
-	} else if (ret == 0) {
-		rsp->data_len = 0;
-		req->data_len = 0;
 	}
 
Quoted 3 lines

drivers/scsi/libsas/sas_expander.c int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1943

Quoted 1 line
drivers/scsi/libsas/sas_expander.c +0 -0
 	return ret;

This is actually a bug fix, as well as a strait conversion

Can you elaborate a bit about the bug fix part?

Quoted 17 lines

drivers/scsi/libsas/sas_expander.c static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error, · line 552

Quoted 6 lines
drivers/scsi/libsas/sas_expander.c +1 -1
@@ -549,7 +549,7 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error,
 		int leftover = (req->hard_nr_sectors << 9);
 
 		if (blk_pc_request(req))
-			leftover = req->data_len;
+			leftover = req->resid_len;

This is the fallout:

The above is just a case of:

(quoted diff) +1 -4
-		int leftover = (req->hard_nr_sectors << 9);
-
-		if (blk_pc_request(req))
-			leftover = req->data_len;
+		int leftover = blk_rq_bytes();
Quoted 1 line

Which you separated into to stages, much later right?

Aieee.. yeah, that's one stupid misconversion. That function should just use blk_end_request_all(). Will fix. Thanks for spotting it.

Quoted 8 lines
Quoted 8 lines
drivers/scsi/libsas/sas_expander.c +1 -1
@@ -778,7 +778,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
 			scsi_end_bidi_request(cmd);
 			return;
 		}
-		req->data_len = scsi_get_resid(cmd);
+		req->resid_len = scsi_get_resid(cmd);
 	}
 
Quoted 6 lines

drivers/scsi/libsas/sas_expander.c void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) · line 784

Quoted 1 line
drivers/scsi/libsas/sas_expander.c +0 -0
 	BUG_ON(blk_bidi_rq(req)); /* bidi not support for !blk_pc_request yet */

Except the fallout the rest of scsi_lib looks good, specifically the bidi_parts.

I'll send a farther cleanup to scsi_lib based on this patchset later.

Cool.

Quoted 5 lines

I've started farther cleanup based on your patchset. However I had a merge conflict when merging your branch with Linus-2.6.30-rc5, around the block areas, do you know what that might be? I've continued to work based on your branch alone, but will wait and post it later once things settle.

I saw a conflict in blkdev.h but there could be other things. I think it should be fine to just base things on my branch. I or Jens should be able to handle merge conflicts later.

I'll update the patchset and repost soonish.

Thanks a lot.

Signature · 1 line
tejun
maintainer
#9 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 30 lines · On Mon, 11 May 2009 08:48:53 +0900 Tejun Heo <[email protected]> wrote:

Hello, Boaz.

Quoted 6 lines · Boaz Harrosh

Hi Tejun, I've carefully reviewed these files which I know more about. The drivers/block files I've skipped, since I'm not familiar with this code.

Except a small fallout, it looks very good. See some comments plus Ack/review below

Thanks a lot for reviewing it closely. It's really nice to have careful extra pair of eyes on the changes. :-)

Quoted 16 lines

drivers/message/fusion/mptsas.c static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1363

Quoted 12 lines
drivers/message/fusion/mptsas.c +1 -2
@@ -1357,8 +1357,7 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 		smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
 		memcpy(req->sense, smprep, sizeof(*smprep));
 		req->sense_len = sizeof(*smprep);
-		req->data_len = 0;
-		rsp->data_len -= smprep->ResponseDataLength;
+		rsp->resid_len = rsp->data_len - smprep->ResponseDataLength;
 	} else {
 		printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n",
 		    ioc->name, __func__);

I think original code was assuming full residual count on the else side (not MPT_IOCTL_STATUS_RF_VALID). So maybe add:

Quoted 5 lines

drivers/scsi/libsas/sas_host_smp.c int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req, · line 180

Quoted 1 line
drivers/scsi/libsas/sas_host_smp.c +1 -0
+		rsp->resid_len = rsp->data_len;

Does resid_len make any sense w/ failed requests? I think we would be better off with declaring residual count to be undefined on request failure. Is there any place which depends on it?

IIRC, I wrote the code. I think that this doesn't matter but it's better not to change the behavior unless Eric ack on this change (maybe LSI has some management binary that assume this behavior though it's unlikely).

maintainer
#10 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 39 lines · FUJITA Tomonori
Quoted 30 lines · On Mon, 11 May 2009 08:48:53 +0900 Tejun Heo <[email protected]> wrote:

Hello, Boaz.

Quoted 6 lines · Boaz Harrosh

Hi Tejun, I've carefully reviewed these files which I know more about. The drivers/block files I've skipped, since I'm not familiar with this code.

Except a small fallout, it looks very good. See some comments plus Ack/review below

Thanks a lot for reviewing it closely. It's really nice to have careful extra pair of eyes on the changes. :-)

Quoted 16 lines

drivers/message/fusion/mptsas.c static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1363

Quoted 12 lines
drivers/message/fusion/mptsas.c +1 -2
@@ -1357,8 +1357,7 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 		smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
 		memcpy(req->sense, smprep, sizeof(*smprep));
 		req->sense_len = sizeof(*smprep);
-		req->data_len = 0;
-		rsp->data_len -= smprep->ResponseDataLength;
+		rsp->resid_len = rsp->data_len - smprep->ResponseDataLength;
 	} else {
 		printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n",
 		    ioc->name, __func__);

I think original code was assuming full residual count on the else side (not MPT_IOCTL_STATUS_RF_VALID). So maybe add:

Quoted 5 lines

drivers/scsi/libsas/sas_host_smp.c int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req, · line 180

Quoted 1 line
drivers/scsi/libsas/sas_host_smp.c +1 -0
+		rsp->resid_len = rsp->data_len;

Does resid_len make any sense w/ failed requests? I think we would be better off with declaring residual count to be undefined on request failure. Is there any place which depends on it?

Quoted 4 lines

IIRC, I wrote the code. I think that this doesn't matter but it's better not to change the behavior unless Eric ack on this change (maybe LSI has some management binary that assume this behavior though it's unlikely).

Actually, yes it does, for many possible reasons.

The first being if the device is too stupid to report an actual sector location the next best way of determining where the error occurred is from the residual. We don't make use of this in kernel (perhaps we should?) but some of the user space programs for CD/DVD burning do.

James

maintainer
#11 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 45 lines · On Mon, 11 May 2009 09:18:20 -0500 James Bottomley…
Quoted 39 lines · FUJITA Tomonori
Quoted 30 lines · On Mon, 11 May 2009 08:48:53 +0900 Tejun Heo <[email protected]> wrote:

Hello, Boaz.

Quoted 6 lines · Boaz Harrosh

Hi Tejun, I've carefully reviewed these files which I know more about. The drivers/block files I've skipped, since I'm not familiar with this code.

Except a small fallout, it looks very good. See some comments plus Ack/review below

Thanks a lot for reviewing it closely. It's really nice to have careful extra pair of eyes on the changes. :-)

Quoted 16 lines

drivers/message/fusion/mptsas.c static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1363

Quoted 12 lines
drivers/message/fusion/mptsas.c +1 -2
@@ -1357,8 +1357,7 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 		smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
 		memcpy(req->sense, smprep, sizeof(*smprep));
 		req->sense_len = sizeof(*smprep);
-		req->data_len = 0;
-		rsp->data_len -= smprep->ResponseDataLength;
+		rsp->resid_len = rsp->data_len - smprep->ResponseDataLength;
 	} else {
 		printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n",
 		    ioc->name, __func__);

I think original code was assuming full residual count on the else side (not MPT_IOCTL_STATUS_RF_VALID). So maybe add:

Quoted 5 lines

drivers/scsi/libsas/sas_host_smp.c int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req, · line 180

Quoted 1 line
drivers/scsi/libsas/sas_host_smp.c +1 -0
+		rsp->resid_len = rsp->data_len;

Does resid_len make any sense w/ failed requests? I think we would be better off with declaring residual count to be undefined on request failure. Is there any place which depends on it?

Quoted 4 lines

IIRC, I wrote the code. I think that this doesn't matter but it's better not to change the behavior unless Eric ack on this change (maybe LSI has some management binary that assume this behavior though it's unlikely).

Quoted 6 lines

Actually, yes it does, for many possible reasons.

The first being if the device is too stupid to report an actual sector location the next best way of determining where the error occurred is from the residual. We don't make use of this in kernel (perhaps we should?) but some of the user space programs for CD/DVD burning do.

This function is for SAS management protocol. Are there many possible reasons?

maintainer
#12 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 50 lines · FUJITA Tomonori
Quoted 47 lines · On Mon, 11 May 2009 09:18:20 -0500 James Bottomley…
Quoted 39 lines · FUJITA Tomonori
Quoted 30 lines · On Mon, 11 May 2009 08:48:53 +0900 Tejun Heo <[email protected]> wrote:

Hello, Boaz.

Quoted 6 lines · Boaz Harrosh

Hi Tejun, I've carefully reviewed these files which I know more about. The drivers/block files I've skipped, since I'm not familiar with this code.

Except a small fallout, it looks very good. See some comments plus Ack/review below

Thanks a lot for reviewing it closely. It's really nice to have careful extra pair of eyes on the changes. :-)

Quoted 16 lines

drivers/message/fusion/mptsas.c static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1363

Quoted 12 lines
drivers/message/fusion/mptsas.c +1 -2
@@ -1357,8 +1357,7 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 		smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
 		memcpy(req->sense, smprep, sizeof(*smprep));
 		req->sense_len = sizeof(*smprep);
-		req->data_len = 0;
-		rsp->data_len -= smprep->ResponseDataLength;
+		rsp->resid_len = rsp->data_len - smprep->ResponseDataLength;
 	} else {
 		printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n",
 		    ioc->name, __func__);

I think original code was assuming full residual count on the else side (not MPT_IOCTL_STATUS_RF_VALID). So maybe add:

Quoted 5 lines

drivers/scsi/libsas/sas_host_smp.c int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req, · line 180

Quoted 1 line
drivers/scsi/libsas/sas_host_smp.c +1 -0
+		rsp->resid_len = rsp->data_len;

Does resid_len make any sense w/ failed requests? I think we would be better off with declaring residual count to be undefined on request failure. Is there any place which depends on it?

Quoted 4 lines

IIRC, I wrote the code. I think that this doesn't matter but it's better not to change the behavior unless Eric ack on this change (maybe LSI has some management binary that assume this behavior though it's unlikely).

Actually, yes it does, for many possible reasons.

Quoted 7 lines
Quoted 4 lines

The first being if the device is too stupid to report an actual sector location the next best way of determining where the error occurred is from the residual. We don't make use of this in kernel (perhaps we should?) but some of the user space programs for CD/DVD burning do.

This function is for SAS management protocol. Are there many possible reasons?

It still indicates how much of the frame was transferred and we have the information, so why not set it. Not doing so would be different from other data transfer functions and so violate the principle of least surprise.

For SAS 1.1 ... the frames are small, so it's not that relevant. For SAS 2.0 the SMP functions become multi-frame, so I could see this becoming relevant for some of the zone SMP commands.

James

maintainer
#13 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 56 lines · On Mon, 11 May 2009 10:13:29 -0500 James Bottomley…
Quoted 55 lines · FUJITA Tomonori
Quoted 51 lines · On Mon, 11 May 2009 09:18:20 -0500 James Bottomley…
Quoted 39 lines · FUJITA Tomonori
Quoted 30 lines · On Mon, 11 May 2009 08:48:53 +0900 Tejun Heo <[email protected]> wrote:

Hello, Boaz.

Quoted 6 lines · Boaz Harrosh

Hi Tejun, I've carefully reviewed these files which I know more about. The drivers/block files I've skipped, since I'm not familiar with this code.

Except a small fallout, it looks very good. See some comments plus Ack/review below

Thanks a lot for reviewing it closely. It's really nice to have careful extra pair of eyes on the changes. :-)

Quoted 16 lines

drivers/message/fusion/mptsas.c static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1363

Quoted 12 lines
drivers/message/fusion/mptsas.c +1 -2
@@ -1357,8 +1357,7 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 		smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
 		memcpy(req->sense, smprep, sizeof(*smprep));
 		req->sense_len = sizeof(*smprep);
-		req->data_len = 0;
-		rsp->data_len -= smprep->ResponseDataLength;
+		rsp->resid_len = rsp->data_len - smprep->ResponseDataLength;
 	} else {
 		printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n",
 		    ioc->name, __func__);

I think original code was assuming full residual count on the else side (not MPT_IOCTL_STATUS_RF_VALID). So maybe add:

Quoted 5 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		rsp->resid_len = rsp->data_len;

Does resid_len make any sense w/ failed requests? I think we would be better off with declaring residual count to be undefined on request failure. Is there any place which depends on it?

Quoted 4 lines

IIRC, I wrote the code. I think that this doesn't matter but it's better not to change the behavior unless Eric ack on this change (maybe LSI has some management binary that assume this behavior though it's unlikely).

Actually, yes it does, for many possible reasons.

The first being if the device is too stupid to report an actual sector location the next best way of determining where the error occurred is from the residual. We don't make use of this in kernel (perhaps we should?) but some of the user space programs for CD/DVD burning do.

Quoted 7 lines
Quoted 2 lines

This function is for SAS management protocol. Are there many possible reasons?

It still indicates how much of the frame was transferred and we have the information, so why not set it. Not doing so would be different from other data transfer functions and so violate the principle of least surprise.

As I wrote in the first reply, I agree with you. I wrote the original code in that way. I was just curious to know if there are example applications that could be broken due to this behavior.

Quoted 3 lines

For SAS 1.1 ... the frames are small, so it's not that relevant. For SAS 2.0 the SMP functions become multi-frame, so I could see this becoming relevant for some of the zone SMP commands.

I see, thanks.

author
#14 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

In reply to James Bottomley

Hello, all.

Quoted 8 lines · James Bottomley
Quoted 7 lines
Quoted 3 lines

Does resid_len make any sense w/ failed requests? I think we would be better off with declaring residual count to be undefined on request failure. Is there any place which depends on it?

IIRC, I wrote the code. I think that this doesn't matter but it's better not to change the behavior unless Eric ack on this change (maybe LSI has some management binary that assume this behavior though it's unlikely).

Quoted 6 lines

Actually, yes it does, for many possible reasons.

The first being if the device is too stupid to report an actual sector location the next best way of determining where the error occurred is from the residual. We don't make use of this in kernel (perhaps we should?) but some of the user space programs for CD/DVD burning do.

Really? Residual count on command success is used but on failure? That's a dangerous territory. When a SG_IO fails, the only data the app should be accessing is the sense data if the status indicates its validity. The problems with residual count on failed command are...

* Not well defined. What does it mean really? It can't indicate successful partial transfer. If the request partially succeeded, the required behavior is to successfully complete the request partially with residual count and then fail the latter part when issued again. If the failure applies to the whole request but location information is useful, it should be carried in the sense data.

* What about corner values? What does 0 or full resid count on failure mean?

* Different layers of failing. In SG_IO interface, a request may fail with -EIO way before it reaches block layer. Residual count can't be set to any meaningful value in these cases. We can set it to full count for these fast fail paths, but do we really wanna go there? Another problem is when a driver is missing SG_IO capability. Who's responsible for setting resid count in that case? How is upper layer gonna determine a SG_IO failed because lower level driver didn't support it or it genuinely failed?

I think it's just silly to give any meaning to resid count when the request fails. It's best to leave the field unmodified or just declare it undefined.

Thanks.

Signature · 1 line
tejun
maintainer
#15 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 23 lines · Tejun Heo

Hello, all.

Quoted 8 lines · James Bottomley
Quoted 7 lines
Quoted 3 lines

Does resid_len make any sense w/ failed requests? I think we would be better off with declaring residual count to be undefined on request failure. Is there any place which depends on it?

IIRC, I wrote the code. I think that this doesn't matter but it's better not to change the behavior unless Eric ack on this change (maybe LSI has some management binary that assume this behavior though it's unlikely).

Quoted 6 lines

Actually, yes it does, for many possible reasons.

The first being if the device is too stupid to report an actual sector location the next best way of determining where the error occurred is from the residual. We don't make use of this in kernel (perhaps we should?) but some of the user space programs for CD/DVD burning do.

Really? Residual count on command success is used but on failure? That's a dangerous territory. When a SG_IO fails, the only data the app should be accessing is the sense data if the status indicates its validity. The problems with residual count on failed command are...

Quoted 7 lines

* Not well defined. What does it mean really? It can't indicate successful partial transfer. If the request partially succeeded, the required behavior is to successfully complete the request partially with residual count and then fail the latter part when issued again. If the failure applies to the whole request but location information is useful, it should be carried in the sense data.

The definition is the amount of data transfer requested less the actual that went over the wire ... that's certainly a well defined quantity; although, one could argue about what this means in the device. Certainly I agree that just because the data was transferred to or from the device is no guarantee that the device did anything with it (or transferred it accurately).

Quoted 2 lines

* What about corner values? What does 0 or full resid count on failure mean?

0 means everything transferred, full residual means nothing did.

Quoted 8 lines

* Different layers of failing. In SG_IO interface, a request may fail with -EIO way before it reaches block layer. Residual count can't be set to any meaningful value in these cases. We can set it to full count for these fast fail paths, but do we really wanna go there? Another problem is when a driver is missing SG_IO capability. Who's responsible for setting resid count in that case? How is upper layer gonna determine a SG_IO failed because lower level driver didn't support it or it genuinely failed?

Well, I prefer the concept of transfer length, which would be initialised to zero ... however, residuals should be initialised to the actual transfer count.

Quoted 3 lines

I think it's just silly to give any meaning to resid count when the request fails. It's best to leave the field unmodified or just declare it undefined.

It's current behaviour. Technically that makes it part of the SG_IO ABI ... although it could be deprecated if someone can verify there are no current users.

James

author
#16 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Hello, James.

Quoted 8 lines · James Bottomley
Quoted 7 lines

* Not well defined. What does it mean really? It can't indicate successful partial transfer. If the request partially succeeded, the required behavior is to successfully complete the request partially with residual count and then fail the latter part when issued again. If the failure applies to the whole request but location information is useful, it should be carried in the sense data.

Quoted 6 lines

The definition is the amount of data transfer requested less the actual that went over the wire ... that's certainly a well defined quantity; although, one could argue about what this means in the device. Certainly I agree that just because the data was transferred to or from the device is no guarantee that the device did anything with it (or transferred it accurately).

I think it's more like how many bytes are valid where the validity is defined as the number of meaningful bytes on dev -> host commands and the number of bytes the device actually consumed on the other direction. Please note that this is different from the number of bytes transferred due to padding or under other error conditions.

Quoted 4 lines
Quoted 2 lines

* What about corner values? What does 0 or full resid count on failure mean?

0 means everything transferred, full residual means nothing did.

Yeap, I was wondering about the combination 0 resid count + failure. What would it mean? All bytes are valid but the command failed?

Quoted 13 lines
Quoted 8 lines

* Different layers of failing. In SG_IO interface, a request may fail with -EIO way before it reaches block layer. Residual count can't be set to any meaningful value in these cases. We can set it to full count for these fast fail paths, but do we really wanna go there? Another problem is when a driver is missing SG_IO capability. Who's responsible for setting resid count in that case? How is upper layer gonna determine a SG_IO failed because lower level driver didn't support it or it genuinely failed?

Well, I prefer the concept of transfer length, which would be initialised to zero ... however, residuals should be initialised to the actual transfer count.

Quoted 7 lines
Quoted 3 lines

I think it's just silly to give any meaning to resid count when the request fails. It's best to leave the field unmodified or just declare it undefined.

It's current behaviour. Technically that makes it part of the SG_IO ABI ... although it could be deprecated if someone can verify there are no current users.

The behavior wasn't guaranteed before the change in paths including SG_IO fast fail one. libata and ide have been and are completely funky about residual counts anyway so I highly doubt anyone has been depending on it.

There's nothing wrong with keeping the original behavior in itself but to me it looks like it would be a bad precedence when no one should depend on the behavior.

Thanks.

Signature · 1 line
tejun
maintainer
#17 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 18 lines · Tejun Heo

Hello, James.

Quoted 8 lines · James Bottomley
Quoted 7 lines

* Not well defined. What does it mean really? It can't indicate successful partial transfer. If the request partially succeeded, the required behavior is to successfully complete the request partially with residual count and then fail the latter part when issued again. If the failure applies to the whole request but location information is useful, it should be carried in the sense data.

Quoted 6 lines

The definition is the amount of data transfer requested less the actual that went over the wire ... that's certainly a well defined quantity; although, one could argue about what this means in the device. Certainly I agree that just because the data was transferred to or from the device is no guarantee that the device did anything with it (or transferred it accurately).

Quoted 5 lines

I think it's more like how many bytes are valid where the validity is defined as the number of meaningful bytes on dev -> host commands and the number of bytes the device actually consumed on the other direction. Please note that this is different from the number of bytes transferred due to padding or under other error conditions.

For failed commands we don't have that information. All we know is how many bytes were actually transferred (because the HBA keeps a count), so it's the actual transfer count we use to construct the residual. No imputation of validity or otherwise. It just says I transferred this amount, based on the error make of it what you will.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

* What about corner values? What does 0 or full resid count on failure mean?

0 means everything transferred, full residual means nothing did.

Yeap, I was wondering about the combination 0 resid count + failure. What would it mean? All bytes are valid but the command failed?

Well, there are certain SCSI conditions called deferred errors and the like where we return Check Condition but everything's OK, redisual count should be zero, same goes for recovered errors ... there are actually lots of things we can get back as an "error" which means I'm warning you of something, but the transfer was OK. Likewise we get unit attentions (essentialy AENs) which mean I'm telling you something before you start,
so please try again. Here residual would be the full transfer. Also,
we have the nasty USB case where no error return but an actual residual tells you something really went wrong.

Quoted 21 lines
Quoted 13 lines
Quoted 8 lines

* Different layers of failing. In SG_IO interface, a request may fail with -EIO way before it reaches block layer. Residual count can't be set to any meaningful value in these cases. We can set it to full count for these fast fail paths, but do we really wanna go there? Another problem is when a driver is missing SG_IO capability. Who's responsible for setting resid count in that case? How is upper layer gonna determine a SG_IO failed because lower level driver didn't support it or it genuinely failed?

Well, I prefer the concept of transfer length, which would be initialised to zero ... however, residuals should be initialised to the actual transfer count.

Quoted 7 lines
Quoted 3 lines

I think it's just silly to give any meaning to resid count when the request fails. It's best to leave the field unmodified or just declare it undefined.

It's current behaviour. Technically that makes it part of the SG_IO ABI ... although it could be deprecated if someone can verify there are no current users.

Quoted 8 lines

The behavior wasn't guaranteed before the change in paths including SG_IO fast fail one. libata and ide have been and are completely funky about residual counts anyway so I highly doubt anyone has been depending on it.

There's nothing wrong with keeping the original behavior in itself but to me it looks like it would be a bad precedence when no one should depend on the behavior.

OK, that's what we'll do then, thanks.

James

#18 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 25 lines · James Bottomley
Quoted 18 lines · Tejun Heo

Hello, James.

Quoted 8 lines · James Bottomley
Quoted 7 lines

* Not well defined. What does it mean really? It can't indicate successful partial transfer. If the request partially succeeded, the required behavior is to successfully complete the request partially with residual count and then fail the latter part when issued again. If the failure applies to the whole request but location information is useful, it should be carried in the sense data.

Quoted 6 lines

The definition is the amount of data transfer requested less the actual that went over the wire ... that's certainly a well defined quantity; although, one could argue about what this means in the device. Certainly I agree that just because the data was transferred to or from the device is no guarantee that the device did anything with it (or transferred it accurately).

Quoted 5 lines

I think it's more like how many bytes are valid where the validity is defined as the number of meaningful bytes on dev -> host commands and the number of bytes the device actually consumed on the other direction. Please note that this is different from the number of bytes transferred due to padding or under other error conditions.

Quoted 5 lines

For failed commands we don't have that information. All we know is how many bytes were actually transferred (because the HBA keeps a count), so it's the actual transfer count we use to construct the residual. No imputation of validity or otherwise. It just says I transferred this amount, based on the error make of it what you will.

It might help to agree on terminology. For example, in the USB mass-storage protocol, "Error" means the command or its result could not be transferred at all -- a problem at the link layer. "Failure" means the command was received and possibly executed to some extent, but the device returned Check Condition status. "Success" means the same as failure except that the device returned Okay status rather than Check Condition.

So for an error, the residue is meaningless (although you could say that it was equal to the full transfer length if you want). For a failure or a success it is meaningful, and it need not be the same as the amount of data transferred.

Incidentally, as long as we're trying to be precise about terminology, the correct term is "residue", not "residual". In fact, the last time I checked a copy of the SCSI spec the word "residual" did not occur anywhere in it.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

* What about corner values? What does 0 or full resid count on failure mean?

0 means everything transferred, full residual means nothing did.

Yeap, I was wondering about the combination 0 resid count + failure. What would it mean? All bytes are valid but the command failed?

Quoted 9 lines

Well, there are certain SCSI conditions called deferred errors and the like where we return Check Condition but everything's OK, redisual count should be zero, same goes for recovered errors ... there are actually lots of things we can get back as an "error" which means I'm warning you of something, but the transfer was OK. Likewise we get unit attentions (essentialy AENs) which mean I'm telling you something before you start,
so please try again. Here residual would be the full transfer. Also,
we have the nasty USB case where no error return but an actual residual tells you something really went wrong.

These should all be described either as failures or as successes with a partial transfer, not as errors.

Alan Stern

author
#19 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

In reply to James Bottomley

Hello, James.

Quoted 11 lines · James Bottomley
Quoted 5 lines

I think it's more like how many bytes are valid where the validity is defined as the number of meaningful bytes on dev -> host commands and the number of bytes the device actually consumed on the other direction. Please note that this is different from the number of bytes transferred due to padding or under other error conditions.

For failed commands we don't have that information. All we know is how many bytes were actually transferred (because the HBA keeps a count), so it's the actual transfer count we use to construct the residual. No imputation of validity or otherwise. It just says I transferred this amount, based on the error make of it what you will.

Hmmm... so two separate meaning depending on command success/failure? I doubt high level code or user application can make much use out of raw transfer byte count. It doesn't mean all that much as it varies depending on specific transport protocol in use.

Quoted 11 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

* What about corner values? What does 0 or full resid count on failure mean?

0 means everything transferred, full residual means nothing did.

Yeap, I was wondering about the combination 0 resid count + failure. What would it mean? All bytes are valid but the command failed?

Well, there are certain SCSI conditions called deferred errors and the like where we return Check Condition but everything's OK, redisual count should be zero, same goes for recovered errors ... there are actually lots of things we can get back as an "error" which means I'm warning you of something, but the transfer was OK.

Shouldn't those be request successful w/ sense data? Please note that the term "error" in this context means failure of block layer request not SCSI layer CHECK SENSE.

Quoted 3 lines

Likewise we get unit attentions (essentialy AENs) which mean I'm telling you something before you start, so please try again. Here residual would be the full transfer.

And these are request failures.

Quoted 2 lines

Also, we have the nasty USB case where no error return but an actual residual tells you something really went wrong.

This is something to be interpreted by lld, be it usb or scsi layer, from block layer POV, if it's partial completion, it's success w/ residue count. If nothing really happened, it's request failure.

Quoted 10 lines
Quoted 8 lines

The behavior wasn't guaranteed before the change in paths including SG_IO fast fail one. libata and ide have been and are completely funky about residual counts anyway so I highly doubt anyone has been depending on it.

There's nothing wrong with keeping the original behavior in itself but to me it looks like it would be a bad precedence when no one should depend on the behavior.

OK, that's what we'll do then, thanks.

I'm still reluctant to do it because...

* Its definition still isn't clear (well, at least to me) and if it's defined as the number of valid bytes on request success and the number of bytes HBA transferred on request failure, I don't think it's all that useful.

* Seen from userland, residue count on request failure has never been guaranteed and there doesn't seem to be any valid in kernel user.

* It would be extra code explicitly setting the residue count to full on failure path. If it's something necessary, full residue count on failure needs to be made default. If not, it will only add more confusion.

Thanks.

Signature · 1 line
tejun
maintainer
#20 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 15 lines · Tejun Heo

Hello, James.

Quoted 11 lines · James Bottomley
Quoted 5 lines

I think it's more like how many bytes are valid where the validity is defined as the number of meaningful bytes on dev -> host commands and the number of bytes the device actually consumed on the other direction. Please note that this is different from the number of bytes transferred due to padding or under other error conditions.

For failed commands we don't have that information. All we know is how many bytes were actually transferred (because the HBA keeps a count), so it's the actual transfer count we use to construct the residual. No imputation of validity or otherwise. It just says I transferred this amount, based on the error make of it what you will.

Quoted 4 lines

Hmmm... so two separate meaning depending on command success/failure? I doubt high level code or user application can make much use out of raw transfer byte count. It doesn't mean all that much as it varies depending on specific transport protocol in use.

Well, no, the definition is the same in both cases: how much data went over the wire. In the success case, you assume that means the device processed it correctly. In the failure case you need to interpret the error (and possibly device specific knowledge) to determine what it means.

Quoted 12 lines
Quoted 11 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

* What about corner values? What does 0 or full resid count on failure mean?

0 means everything transferred, full residual means nothing did.

Yeap, I was wondering about the combination 0 resid count + failure. What would it mean? All bytes are valid but the command failed?

Well, there are certain SCSI conditions called deferred errors and the like where we return Check Condition but everything's OK, redisual count should be zero, same goes for recovered errors ... there are actually lots of things we can get back as an "error" which means I'm warning you of something, but the transfer was OK.

Quoted 3 lines

Shouldn't those be request successful w/ sense data? Please note that the term "error" in this context means failure of block layer request not SCSI layer CHECK SENSE.

Heh, well, this is where we get into interpretations. For SG_IO requests, we have three separate ways of returning error. The error return to the block layer, the results return and the sense code. The error to block is a somewhat later addition to the layer, so not all cases are handled right or agreed (for instance we just altered BLOCK_PC with recovered error from -EIO to no error). So hopefully we've just decided that deferred and current but recovered all fall into the no error to block, but results and sense to the user.

Note that the error to block is basically discarded from SG_IO before we return to the user, so the user *only* has results and sense to go by, thus the concept of residual not valid on error to block is something the user can't check. That's why a consistent definition in all cases (i.e. the amount of data the HBA transferred) is the correct one and allows userspace to make the determination of what it should do based on the returns it gets.

Quoted 22 lines
Quoted 3 lines

Likewise we get unit attentions (essentialy AENs) which mean I'm telling you something before you start, so please try again. Here residual would be the full transfer.

And these are request failures.

Quoted 2 lines

Also, we have the nasty USB case where no error return but an actual residual tells you something really went wrong.

This is something to be interpreted by lld, be it usb or scsi layer, from block layer POV, if it's partial completion, it's success w/ residue count. If nothing really happened, it's request failure.

Quoted 9 lines
Quoted 8 lines

The behavior wasn't guaranteed before the change in paths including SG_IO fast fail one. libata and ide have been and are completely funky about residual counts anyway so I highly doubt anyone has been depending on it.

There's nothing wrong with keeping the original behavior in itself but to me it looks like it would be a bad precedence when no one should depend on the behavior.

Quoted 8 lines
Quoted 1 line

OK, that's what we'll do then, thanks.

I'm still reluctant to do it because...

* Its definition still isn't clear (well, at least to me) and if it's defined as the number of valid bytes on request success and the number of bytes HBA transferred on request failure, I don't think it's all that useful.

It's not valid bytes in either case ... it's number transferred. One can infer from a successful SCSI status code that number transferred == valid bytes, but I'd rather we didn't say that.

Quoted 2 lines

* Seen from userland, residue count on request failure has never been guaranteed and there doesn't seem to be any valid in kernel user.

But that's the point ... we don't define for userland what request failure is very well.

Quoted 4 lines

* It would be extra code explicitly setting the residue count to full on failure path. If it's something necessary, full residue count on failure needs to be made default. If not, it will only add more confusion.

OK, so if what you're asking is that we can regard the residue as invalid if SG_IO itself returns an error, then I can agree ... but not if blk_end_request() returns error, because that error gets ignored by SG_IO.

James

author
#21 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Hello, James.

Quoted 13 lines · James Bottomley
Quoted 3 lines

Shouldn't those be request successful w/ sense data? Please note that the term "error" in this context means failure of block layer request not SCSI layer CHECK SENSE.

Heh, well, this is where we get into interpretations. For SG_IO requests, we have three separate ways of returning error. The error return to the block layer, the results return and the sense code. The error to block is a somewhat later addition to the layer, so not all cases are handled right or agreed (for instance we just altered BLOCK_PC with recovered error from -EIO to no error). So hopefully we've just decided that deferred and current but recovered all fall into the no error to block, but results and sense to the user.

Quoted 7 lines

Note that the error to block is basically discarded from SG_IO before we return to the user, so the user *only* has results and sense to go by, thus the concept of residual not valid on error to block is something the user can't check. That's why a consistent definition in all cases (i.e. the amount of data the HBA transferred) is the correct one and allows userspace to make the determination of what it should do based on the returns it gets.

Okay, I was thinking SG_IO will return error for rq failures and I remember pretty clearly following the failure path recently while debugging eject problem but my memory is pretty unreliable. Checking... oops, yeap, you're right.

Quoted 22 lines
Quoted 6 lines

I'm still reluctant to do it because...

* Its definition still isn't clear (well, at least to me) and if it's defined as the number of valid bytes on request success and the number of bytes HBA transferred on request failure, I don't think it's all that useful.

It's not valid bytes in either case ... it's number transferred. One can infer from a successful SCSI status code that number transferred == valid bytes, but I'd rather we didn't say that.

Quoted 2 lines

* Seen from userland, residue count on request failure has never been guaranteed and there doesn't seem to be any valid in kernel user.

But that's the point ... we don't define for userland what request failure is very well.

Quoted 4 lines

* It would be extra code explicitly setting the residue count to full on failure path. If it's something necessary, full residue count on failure needs to be made default. If not, it will only add more confusion.

Quoted 4 lines

OK, so if what you're asking is that we can regard the residue as invalid if SG_IO itself returns an error, then I can agree ... but not if blk_end_request() returns error, because that error gets ignored by SG_IO.

I was confused that rq failure would cause error return from SG_IO. Sorry about that. There still is a problem tho. Buffer for a bounced SG_IO request is copied back on failure but when a bounced kernel PC request fails, the data is not copied back in bio_copy_kern_endio(). This is what would break Boaz's code.

So, it seems what we should do is

1. Always copy back bounced buffer whether the request failed or not. Whether resid_len should be considered while copying back, I'm not sure about given that resid_len isn't properly implemented in some drivers.

2. Revert the original behavior of setting resid_len to full on request issue and audit the affected code paths.

How does it sound?

Thanks.

Signature · 1 line
tejun
#22 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

In reply to Tejun Heo
Quoted 8 lines · Tejun Heo

Does resid_len make any sense w/ failed requests? I think we would be better off with declaring residual count to be undefined on request failure. Is there any place which depends on it?

That said, the value is eventually exported to userland, so it might be better to not change it. Eh... I don't know.

When possible, residual should be exact because the residual amount is not bounced and might even be zeroed-out for security, as the meaning of residual is that these bytes are garbage.

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
drivers/scsi/libsas/sas_expander.c +1 -5
index 3da02e4..6605ec9 100644
@@ -1936,12 +1936,8 @@ int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 			       bio_data(rsp->bio), rsp->data_len);
 	if (ret > 0) {
 		/* positive number is the untransferred residual */
-		rsp->data_len = ret;
-		req->data_len = 0;
+		rsp->resid_len = ret;
 		ret = 0;
-	} else if (ret == 0) {
-		rsp->data_len = 0;
-		req->data_len = 0;
 	}
 
Quoted 5 lines
Quoted 2 lines

drivers/scsi/libsas/sas_expander.c int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1943

Quoted 1 line
drivers/scsi/libsas/sas_expander.c +0 -0
 	return ret;

This is actually a bug fix, as well as a strait conversion

Can you elaborate a bit about the bug fix part?

Nothing big really, just that before (according to the comment), the theoretical negative case would be full-residual. and now it is zero (untouched).

I know that in iscsi a negative residual is possible which means over-flow. That is:
the target had more data to give then the buffer had space for. (which is not an error at all)

Quoted 16 lines
Quoted 16 lines

drivers/scsi/libsas/sas_expander.c static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error, · line 552

Quoted 6 lines
drivers/scsi/libsas/sas_expander.c +1 -1
@@ -549,7 +549,7 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error,
 		int leftover = (req->hard_nr_sectors << 9);
 
 		if (blk_pc_request(req))
-			leftover = req->data_len;
+			leftover = req->resid_len;

This is the fallout:

The above is just a case of:

(quoted diff) +1 -4
-		int leftover = (req->hard_nr_sectors << 9);
-
-		if (blk_pc_request(req))
-			leftover = req->data_len;
+		int leftover = blk_rq_bytes();
Quoted 5 lines
Quoted 1 line

Which you separated into to stages, much later right?

Aieee.. yeah, that's one stupid misconversion. That function should just use blk_end_request_all(). Will fix. Thanks for spotting it.

Yes, there is a couple of other places that have that with the meaning of blk_end_request_all() (Have I commented on one?). Are you doing this conversion in these patchset? or this is for a second pass?

Quoted 3 lines

Thanks a lot.

Thanks
Boaz

maintainer
#23 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 20 lines · On Mon, 11 May 2009 14:31:41 +0300 Boaz Harrosh <[email protected]> wrote:
Quoted 20 lines
Quoted 19 lines
Quoted 8 lines
drivers/scsi/libsas/sas_expander.c +0 -0
index 3da02e4..6605ec9 100644
@@ -1936,12 +1936,8 @@ int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 			       bio_data(rsp->bio), rsp->data_len);
 	if (ret > 0) {
 		/* positive number is the untransferred residual */

drivers/scsi/libsas/sas_expander.c int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1943

Quoted 10 lines
drivers/scsi/libsas/sas_expander.c +1 -5
-		rsp->data_len = ret;
-		req->data_len = 0;
+		rsp->resid_len = ret;
 		ret = 0;
-	} else if (ret == 0) {
-		rsp->data_len = 0;
-		req->data_len = 0;
 	}
 
 	return ret;

This is actually a bug fix, as well as a strait conversion

Quoted 8 lines
Quoted 2 lines

Can you elaborate a bit about the bug fix part?

Nothing big really, just that before (according to the comment), the theoretical negative case would be full-residual. and now it is zero (untouched).

I know that in iscsi a negative residual is possible which means over-flow. That is:
the target had more data to give then the buffer had space for. (which is not an error at all)

Hmm, iSCSI? This code is for SAS management Protocol.

smp_execute_task returns a negative value for some errors (ENOMEM, the hardware doesn't respond, etc). It's not related with 'transferred buffer length' at all.

#24 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 24 lines · FUJITA Tomonori
Quoted 21 lines · On Mon, 11 May 2009 14:31:41 +0300 Boaz Harrosh <[email protected]> wrote:
Quoted 21 lines
Quoted 17 lines
Quoted 17 lines
drivers/scsi/libsas/sas_expander.c +1 -5
index 3da02e4..6605ec9 100644
@@ -1936,12 +1936,8 @@ int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 			       bio_data(rsp->bio), rsp->data_len);
 	if (ret > 0) {
 		/* positive number is the untransferred residual */
-		rsp->data_len = ret;
-		req->data_len = 0;
+		rsp->resid_len = ret;
 		ret = 0;
-	} else if (ret == 0) {
-		rsp->data_len = 0;
-		req->data_len = 0;
 	}
 
Quoted 2 lines

drivers/scsi/libsas/sas_expander.c int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1943

Quoted 1 line
drivers/scsi/libsas/sas_expander.c +0 -0
 	return ret;

This is actually a bug fix, as well as a strait conversion

Can you elaborate a bit about the bug fix part?

Quoted 8 lines
Quoted 5 lines

Nothing big really, just that before (according to the comment), the theoretical negative case would be full-residual. and now it is zero (untouched).

I know that in iscsi a negative residual is possible which means over-flow. That is:
the target had more data to give then the buffer had space for. (which is not an error at all)

Hmm, iSCSI? This code is for SAS management Protocol.

I gave that as an example of what the scsi standard says about negative residual count return from the target. If SAS as sepecific and different meaning to negative residual, it should be noted and handled.

Quoted 3 lines

smp_execute_task returns a negative value for some errors (ENOMEM, the hardware doesn't respond, etc). It's not related with 'transferred buffer length' at all.

This is a serious problem, and a violation of the block/scsi stacks. If so, then in that case error/status should be set properly. And residual cleared.

Failing to return an error might theoretically be catastrophic. If what you say is certain then previous behaviour is better then after this patch.

I'm not at all familiar with this code. Could you send a patch to fix these things?

Thanks
Boaz

maintainer
#25 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 31 lines · On Tue, 12 May 2009 11:58:28 +0300 Boaz Harrosh <[email protected]> wrote:
Quoted 30 lines · FUJITA Tomonori
Quoted 26 lines · On Mon, 11 May 2009 14:31:41 +0300 Boaz Harrosh <[email protected]> wrote:
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
drivers/scsi/libsas/sas_expander.c +1 -5
index 3da02e4..6605ec9 100644
@@ -1936,12 +1936,8 @@ int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 			       bio_data(rsp->bio), rsp->data_len);
 	if (ret > 0) {
 		/* positive number is the untransferred residual */
-		rsp->data_len = ret;
-		req->data_len = 0;
+		rsp->resid_len = ret;
 		ret = 0;
-	} else if (ret == 0) {
-		rsp->data_len = 0;
-		req->data_len = 0;
 	}
 
Quoted 4 lines
Quoted 2 lines

drivers/scsi/libsas/sas_expander.c int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1943

Quoted 1 line
drivers/scsi/libsas/sas_expander.c +0 -0
 	return ret;

This is actually a bug fix, as well as a strait conversion

Can you elaborate a bit about the bug fix part?

Nothing big really, just that before (according to the comment), the theoretical negative case would be full-residual. and now it is zero (untouched).

I know that in iscsi a negative residual is possible which means over-flow. That is:
the target had more data to give then the buffer had space for. (which is not an error at all)

Quoted 6 lines
Quoted 2 lines

Hmm, iSCSI? This code is for SAS management Protocol.

I gave that as an example of what the scsi standard says about negative residual count return from the target. If SAS as sepecific and different meaning to negative residual, it should be noted and handled.

Please read the code first.

If sas_smp_handler() returns a negative value, a lld doesn't transfer anything. The original code used full-residual. The original code is fine. Your 'this is a bug fix' claim is wrong. We need to revert the original behavior though.

#26 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 39 lines · FUJITA Tomonori
Quoted 28 lines · On Tue, 12 May 2009 11:58:28 +0300 Boaz Harrosh <[email protected]> wrote:
Quoted 27 lines · FUJITA Tomonori
Quoted 24 lines · On Mon, 11 May 2009 14:31:41 +0300 Boaz Harrosh <[email protected]> wrote:
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
drivers/scsi/libsas/sas_expander.c +1 -5
index 3da02e4..6605ec9 100644
@@ -1936,12 +1936,8 @@ int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 			       bio_data(rsp->bio), rsp->data_len);
 	if (ret > 0) {
 		/* positive number is the untransferred residual */
-		rsp->data_len = ret;
-		req->data_len = 0;
+		rsp->resid_len = ret;
 		ret = 0;
-	} else if (ret == 0) {
-		rsp->data_len = 0;
-		req->data_len = 0;
 	}
 
Quoted 4 lines
Quoted 2 lines

drivers/scsi/libsas/sas_expander.c int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1943

Quoted 1 line
drivers/scsi/libsas/sas_expander.c +0 -0
 	return ret;

This is actually a bug fix, as well as a strait conversion

Can you elaborate a bit about the bug fix part?

Nothing big really, just that before (according to the comment), the theoretical negative case would be full-residual. and now it is zero (untouched).

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I know that in iscsi a negative residual is possible which means over-flow. That is:
the target had more data to give then the buffer had space for. (which is not an error at all)

Hmm, iSCSI? This code is for SAS management Protocol.

I gave that as an example of what the scsi standard says about negative residual count return from the target. If SAS as sepecific and different meaning to negative residual, it should be noted and handled.

Quoted 6 lines

Please read the code first.

If sas_smp_handler() returns a negative value, a lld doesn't transfer anything. The original code used full-residual. The original code is fine. Your 'this is a bug fix' claim is wrong. We need to revert the original behavior though.

Please read my full reply, I said yes old code was better, but not good enough, error status must be returned also in this case.

This code is already submitted are you sending a fix?

Thanks
Boaz

maintainer
#27 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

In reply to FUJITA Tomonori
Quoted 37 lines · On Wed, 13 May 2009 00:00:47 +0900 FUJITA Tomonori…
Quoted 34 lines · On Tue, 12 May 2009 11:58:28 +0300 Boaz Harrosh <[email protected]> wrote:
Quoted 32 lines · FUJITA Tomonori
Quoted 19 lines · On Mon, 11 May 2009 14:31:41 +0300 Boaz Harrosh <[email protected]> wrote:
Quoted 19 lines
Quoted 19 lines
Quoted 8 lines
drivers/scsi/libsas/sas_expander.c +0 -0
index 3da02e4..6605ec9 100644
@@ -1936,12 +1936,8 @@ int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 			       bio_data(rsp->bio), rsp->data_len);
 	if (ret > 0) {
 		/* positive number is the untransferred residual */

drivers/scsi/libsas/sas_expander.c int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1943

Quoted 10 lines
drivers/scsi/libsas/sas_expander.c +1 -5
-		rsp->data_len = ret;
-		req->data_len = 0;
+		rsp->resid_len = ret;
 		ret = 0;
-	} else if (ret == 0) {
-		rsp->data_len = 0;
-		req->data_len = 0;
 	}
 
 	return ret;

This is actually a bug fix, as well as a strait conversion

Quoted 7 lines
Quoted 2 lines

Can you elaborate a bit about the bug fix part?

Nothing big really, just that before (according to the comment), the theoretical negative case would be full-residual. and now it is zero (untouched).

I know that in iscsi a negative residual is possible which means over-flow. That is:
the target had more data to give then the buffer had space for. (which is not an error at all)

Hmm, iSCSI? This code is for SAS management Protocol.

Quoted 7 lines
Quoted 3 lines

I gave that as an example of what the scsi standard says about negative residual count return from the target. If SAS as sepecific and different meaning to negative residual, it should be noted and handled.

Please read the code first.

If sas_smp_handler() returns a negative value, a lld doesn't transfer

Oops, smp_execute_task()

Quoted 3 lines

anything. The original code used full-residual. The original code is fine. Your 'this is a bug fix' claim is wrong. We need to revert the original behavior though.

Note that you could claim that we should handle residual here when you find SAS_DATA_OVERRUN in smp_execute_task(). I guess that it means INVALID_REQUEST_FRAME_LENGTH; the driver sent the data and doesn't get anything. So we could do better about residual for the error but I didn't know about the lld spec and I kept the code that the vendor submitted.

author
#28 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

In reply to Boaz Harrosh

Hello, Boaz.

Quoted 11 lines · Boaz Harrosh
Quoted 6 lines · Tejun Heo

Does resid_len make any sense w/ failed requests? I think we would be better off with declaring residual count to be undefined on request failure. Is there any place which depends on it?

That said, the value is eventually exported to userland, so it might be better to not change it. Eh... I don't know.

When possible, residual should be exact because the residual amount is not bounced and might even be zeroed-out for security, as the meaning of residual is that these bytes are garbage.

When a request failed, the whole buffer is garbage. There's no partial transfer. There shouldn't be. I don't think residual count on request failure means anything. Also, the 'whenever possible' doesn't mean much when the issuer can't determine whether the value is valid or not. On success, we should guarantee resid count is valid, on failure, I don't see a way we can.

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

index 3da02e4..6605ec9 100644

drivers/scsi/libsas/sas_expander.c +1 -5
@@ -1936,12 +1936,8 @@ int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 			       bio_data(rsp->bio), rsp->data_len);
 	if (ret > 0) {
 		/* positive number is the untransferred residual */
-		rsp->data_len = ret;
-		req->data_len = 0;
+		rsp->resid_len = ret;
 		ret = 0;
-	} else if (ret == 0) {
-		rsp->data_len = 0;
-		req->data_len = 0;
 	}
 
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

drivers/scsi/libsas/sas_expander.c int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1943

Quoted 1 line
drivers/scsi/libsas/sas_expander.c +0 -0
 	return ret;

This is actually a bug fix, as well as a strait conversion

Can you elaborate a bit about the bug fix part?

Nothing big really, just that before (according to the comment), the theoretical negative case would be full-residual. and now it is zero (untouched).

Yeah, the same thing as above, I suppose.

Quoted 3 lines

I know that in iscsi a negative residual is possible which means over-flow. That is: the target had more data to give then the buffer had space for. (which is not an error at all)

Hmm... I've never seen negative residual in use. Is it even defined?

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The above is just a case of:

(quoted diff) +1 -4
-		int leftover = (req->hard_nr_sectors << 9);
-
-		if (blk_pc_request(req))
-			leftover = req->data_len;
+		int leftover = blk_rq_bytes();
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Which you separated into to stages, much later right?

Aieee.. yeah, that's one stupid misconversion. That function should just use blk_end_request_all(). Will fix. Thanks for spotting it.

Yes, there is a couple of other places that have that with the meaning of blk_end_request_all() (Have I commented on one?). Are you doing this conversion in these patchset? or this is for a second pass?

If you spot some, please go ahead and submit patches. I don't have any patch in my queue which hasn't been posted.

Thanks.

Signature · 1 line
tejun
#29 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 8 lines · Tejun Heo

Hello, Boaz.

Quoted 5 lines · Boaz Harrosh
Quoted 4 lines · Tejun Heo

Does resid_len make any sense w/ failed requests? I think we would be better off with declaring residual count to be undefined on request failure. Is there any place which depends on it?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

That said, the value is eventually exported to userland, so it might be better to not change it. Eh... I don't know.

When possible, residual should be exact because the residual amount is not bounced and might even be zeroed-out for security, as the meaning of residual is that these bytes are garbage.

When a request failed, the whole buffer is garbage.

ret is the transferred size, right? I don't see any check for success/failure in below code.

Quoted 3 lines

There's no
partial transfer. There shouldn't be. I don't think residual count on request failure means anything.

That's not true, there are many cases when transfer failed eventually but some bytes are valid. Even the simple read/write case. Imagine a very large transfer with last sector encounter a "bad sector". that can be critical, (trying to rescue a disk). And many other examples.

Also, the 'whenever possible'

Quoted 4 lines

doesn't mean much when the issuer can't determine whether the value is valid or not. On success, we should guarantee resid count is valid, on failure, I don't see a way we can.

Code is as strong as it's weakest link, right? If lower driver/firmware is brain-dead, what can we do? But why give up where you can do better?

The scsi standard is very clear about what every one should do with the residual and what it means at every stage, everyone should do his part. Here at the middle layer we need to correctly translate what lower level returned and pass it up the chain.

Must stacks are amateuristic in regard to error handling but some are not, what should we strive for, if we can?

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

index 3da02e4..6605ec9 100644

drivers/scsi/libsas/sas_expander.c +1 -5
@@ -1936,12 +1936,8 @@ int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 			       bio_data(rsp->bio), rsp->data_len);
 	if (ret > 0) {
 		/* positive number is the untransferred residual */
-		rsp->data_len = ret;
-		req->data_len = 0;
+		rsp->resid_len = ret;
 		ret = 0;
-	} else if (ret == 0) {
-		rsp->data_len = 0;
-		req->data_len = 0;
 	}
 
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

drivers/scsi/libsas/sas_expander.c int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, · line 1943

Quoted 1 line
drivers/scsi/libsas/sas_expander.c +0 -0
 	return ret;

This is actually a bug fix, as well as a strait conversion

Can you elaborate a bit about the bug fix part?

Nothing big really, just that before (according to the comment), the theoretical negative case would be full-residual. and now it is zero (untouched).

Yeah, the same thing as above, I suppose.

Should we check for errors then?

Quoted 6 lines
Quoted 3 lines

I know that in iscsi a negative residual is possible which means over-flow. That is: the target had more data to give then the buffer had space for. (which is not an error at all)

Hmm... I've never seen negative residual in use. Is it even defined?

It is defined, as I explained before. But yes no one uses it in Kernel. The "good" low-level drivers fix it up by setting resid to zero, in that case. (other wise the upper layers might crash)

Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The above is just a case of:

(quoted diff) +1 -4
-		int leftover = (req->hard_nr_sectors << 9);
-
-		if (blk_pc_request(req))
-			leftover = req->data_len;
+		int leftover = blk_rq_bytes();
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Which you separated into to stages, much later right?

Aieee.. yeah, that's one stupid misconversion. That function should just use blk_end_request_all(). Will fix. Thanks for spotting it.

Yes, there is a couple of other places that have that with the meaning of blk_end_request_all() (Have I commented on one?). Are you doing this conversion in these patchset? or this is for a second pass?

Quoted 5 lines

If you spot some, please go ahead and submit patches. I don't have any patch in my queue which hasn't been posted.

Thanks.

Thanks
Boaz

author
#30 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Hello, Boaz.

Quoted 5 lines · Boaz Harrosh
Quoted 1 line

When a request failed, the whole buffer is garbage.

ret is the transferred size, right? I don't see any check for success/failure in below code.

Quoted 8 lines
Quoted 3 lines

There's no
partial transfer. There shouldn't be. I don't think residual count on request failure means anything.

That's not true, there are many cases when transfer failed eventually but some bytes are valid. Even the simple read/write case. Imagine a very large transfer with last sector encounter a "bad sector". that can be critical, (trying to rescue a disk). And many other examples.

No, it doesn't work like that. As I wrote before, those partial transfers are returned to the issuer as partial _SUCCESS_ not partial failure. ie. it's successful request w/ positive residual count not the other way around. The error is communicated to the issuer when the leftover is re-issued. There's no such thing as partial failure.

Please consider write failing after successfully writing certain number of bytes. A failed write command MUST NOT cause any actual write on the device.

Residual count is not about how many bytes have been transferred. The number of transferred bytes itself doesn't mean a thing because it changes depending on which transfer protocol is used regardless of where the actual failure is. Residual count is about how many bytes have been actually produced or consumed and when a command fails none should have been.

Quoted 15 lines
Quoted 5 lines

Also, the 'whenever possible'
doesn't mean much when the issuer can't determine whether the value is valid or not. On success, we should guarantee resid count is valid, on failure, I don't see a way we can.

Code is as strong as it's weakest link, right? If lower driver/firmware is brain-dead, what can we do? But why give up where you can do better?

The scsi standard is very clear about what every one should do with the residual and what it means at every stage, everyone should do his part. Here at the middle layer we need to correctly translate what lower level returned and pass it up the chain.

Quoted 4 lines

Must stacks are amateuristic in regard to error handling but some are not, what

should we strive for, if we can?

No it's not about being good or bad. It's about being plain undefined. There is no value in setting an inherently undefined value to certain values in certain corner cases.

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

I know that in iscsi a negative residual is possible which means over-flow. That is: the target had more data to give then the buffer had space for. (which is not an error at all)

Hmm... I've never seen negative residual in use. Is it even defined?

It is defined, as I explained before. But yes no one uses it in Kernel. The "good" low-level drivers fix it up by setting resid to zero, in that case. (other wise the upper layers might crash)

If the upper layer might crash if the value is negative, I think it's quite understandable to call negative values to be undefined. Or should we call it unsupported?

Thanks.

Signature · 1 line
tejun
#31 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Tejun Heo wrote:
...

Quoted 10 lines

Please consider write failing after successfully writing certain number of bytes. A failed write command MUST NOT cause any actual write on the device.

Residual count is not about how many bytes have been transferred. The number of transferred bytes itself doesn't mean a thing because it changes depending on which transfer protocol is used regardless of where the actual failure is. Residual count is about how many bytes have been actually produced or consumed and when a command fails none should have been.

Please note that in the above 'command' and 'residual count' are not as defined in SCSI. Those terms refer to how those concepts are used in the kernel and via SG_IO interface.

Thanks.

Signature · 1 line
tejun
#32 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

In reply to Tejun Heo
Quoted 21 lines · Tejun Heo

Hello, Boaz.

Quoted 11 lines · Boaz Harrosh
Quoted 1 line

When a request failed, the whole buffer is garbage.

ret is the transferred size, right? I don't see any check for success/failure in below code.

Quoted 3 lines

There's no
partial transfer. There shouldn't be. I don't think residual count on request failure means anything.

That's not true, there are many cases when transfer failed eventually but some bytes are valid. Even the simple read/write case. Imagine a very large transfer with last sector encounter a "bad sector". that can be critical, (trying to rescue a disk). And many other examples.

No, it doesn't work like that. As I wrote before, those partial transfers are returned to the issuer as partial _SUCCESS_ not partial failure. ie. it's successful request w/ positive residual count not the other way around. The error is communicated to the issuer when the leftover is re-issued. There's no such thing as partial failure.

Quoted 4 lines

Please consider write failing after successfully writing certain number of bytes. A failed write command MUST NOT cause any actual write on the device.

I know for sure that scsi has other cases. The above is a per-command per-sense-information. Some commands might write/read some bytes and still return CHECK-CONDITION with some sense-info+residual pertaining what was actually executed.

Quoted 7 lines

Residual count is not about how many bytes have been transferred. The number of transferred bytes itself doesn't mean a thing because it changes depending on which transfer protocol is used regardless of where the actual failure is. Residual count is about how many bytes have been actually produced or consumed and when a command fails none should have been.

See above. I know for a fact that this is not always the case, and that it is a per command. In fact I relay on such behaviour in the osd filesystems. If the midlayer would filter such cases for me I would have had data corruptions.

[Read passed end of osd-object will read up to end, and return a warning
check condition. With a choice of returning zero-bytes at invalid bytes or returning residual]

Quoted 4 lines

Please note that in the above 'command' and 'residual count' are not as defined in SCSI. Those terms refer to how those concepts are used in the kernel and via SG_IO interface.

I do have Kernel code that relays on this. I do use bsg's SG_IO successfully that has above behaviour.

That is: total transparency of residual count and sense information communicated between user-code and target. Then user-code can make intelligent decisions based on what he's done. And this is what the Kernel policy should be. No more, no less.

Quoted 14 lines
Quoted 14 lines
Quoted 5 lines

Also, the 'whenever possible'
doesn't mean much when the issuer can't determine whether the value is valid or not. On success, we should guarantee resid count is valid, on failure, I don't see a way we can.

Code is as strong as it's weakest link, right? If lower driver/firmware is brain-dead, what can we do? But why give up where you can do better?

The scsi standard is very clear about what every one should do with the residual and what it means at every stage, everyone should do his part. Here at the middle layer we need to correctly translate what lower level returned and pass it up the chain.

Quoted 9 lines
Quoted 4 lines

Must stacks are amateuristic in regard to error handling but some are not, what

should we strive for, if we can?

No it's not about being good or bad. It's about being plain undefined. There is no value in setting an inherently undefined value to certain values in certain corner cases.

Again. With some commands/subsystems these are undefined, with some like SCSI, they are very well defined in all cases. (Even in the undefined cases). So please keep them intact, some code might want to relay on this.

(On the undefined cases Kernel should set a policy on what is returned)

Quoted 12 lines
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

I know that in iscsi a negative residual is possible which means over-flow. That is: the target had more data to give then the buffer had space for. (which is not an error at all)

Hmm... I've never seen negative residual in use. Is it even defined?

It is defined, as I explained before. But yes no one uses it in Kernel. The "good" low-level drivers fix it up by setting resid to zero, in that case. (other wise the upper layers might crash)

If the upper layer might crash if the value is negative, I think it's quite understandable to call negative values to be undefined. Or should we call it unsupported?

Yes, unsupported.

Since current meaning means success, actually, and there is no real extra information that users need.
Look at it this way, until today negative meant Zero with extra information which no one cares for.

Quoted 2 lines

Thanks.

Cheers
Boaz

author
#33 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Hello, Boaz.

Quoted 9 lines · Boaz Harrosh
Quoted 4 lines

Please consider write failing after successfully writing certain number of bytes. A failed write command MUST NOT cause any actual write on the device.

I know for sure that scsi has other cases. The above is a per-command per-sense-information. Some commands might write/read some bytes and still return CHECK-CONDITION with some sense-info+residual pertaining what was actually executed.

I see, so we're talking about two different layers here. At least at the block layer, there's nothing like partial failure. I highly doubt it would work with buffer bouncing and etc. A failed request is a failed request. It may have sense request but doesn't have any meaningful actual data.

Quoted 7 lines
Quoted 7 lines

Residual count is not about how many bytes have been transferred. The number of transferred bytes itself doesn't mean a thing because it changes depending on which transfer protocol is used regardless of where the actual failure is. Residual count is about how many bytes have been actually produced or consumed and when a command fails none should have been.

Quoted 8 lines

See above. I know for a fact that this is not always the case, and that it is a per command. In fact I relay on such behaviour in the osd filesystems. If the midlayer would filter such cases for me I would have had data corruptions.

[Read passed end of osd-object will read up to end, and return a
warning check condition. With a choice of returning zero-bytes at invalid bytes or returning residual]

Umm... If it's going through block layer, it should be split in such a way that the initial partial part is completed successuflly and then the latter part fails when re-issued. Not sure whether that would be possible for your code tho.

Quoted 11 lines
Quoted 3 lines

Please note that in the above 'command' and 'residual count' are not as defined in SCSI. Those terms refer to how those concepts are used in the kernel and via SG_IO interface.

I do have Kernel code that relays on this. I do use bsg's SG_IO successfully that has above behaviour.

That is: total transparency of residual count and sense information communicated between user-code and target. Then user-code can make intelligent decisions based on what he's done. And this is what the Kernel policy should be. No more, no less.

I'm not sure the said code is safe with regard to buffer bouncing and all.

...

Quoted 5 lines
Quoted 4 lines

No it's not about being good or bad. It's about being plain undefined. There is no value in setting an inherently undefined value to certain values in certain corner cases.

Quoted 7 lines

Again. With some commands/subsystems these are undefined, with some like SCSI, they are very well defined in all cases. (Even in the undefined cases). So please keep them intact, some code might want to relay on this.

(On the undefined cases Kernel should set a policy on what is returned)

IIUC, it's undefined at the block layer, well, at least till now and it working for your code could just be dumb luck (bouncing not happened or data transfer direction is to device or whatever).

So, basically, your code which depends on residual count on failure is broken. :-(

Thanks.

Signature · 1 line
tejun
#34 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 12 lines · Tejun Heo

Hello, Boaz.

Quoted 8 lines · Boaz Harrosh
Quoted 4 lines

Please consider write failing after successfully writing certain number of bytes. A failed write command MUST NOT cause any actual write on the device.

I know for sure that scsi has other cases. The above is a per-command per-sense-information. Some commands might write/read some bytes and still return CHECK-CONDITION with some sense-info+residual pertaining what was actually executed.

Quoted 6 lines

I see, so we're talking about two different layers here. At least at the block layer, there's nothing like partial failure. I highly doubt it would work with buffer bouncing and etc. A failed request is a failed request. It may have sense request but doesn't have any meaningful actual data.

You are right, on reads I might be screwed.

Quoted 48 lines
Quoted 7 lines
Quoted 7 lines

Residual count is not about how many bytes have been transferred. The number of transferred bytes itself doesn't mean a thing because it changes depending on which transfer protocol is used regardless of where the actual failure is. Residual count is about how many bytes have been actually produced or consumed and when a command fails none should have been.

Quoted 8 lines

See above. I know for a fact that this is not always the case, and that it is a per command. In fact I relay on such behaviour in the osd filesystems. If the midlayer would filter such cases for me I would have had data corruptions.

[Read passed end of osd-object will read up to end, and return a
warning check condition. With a choice of returning zero-bytes at invalid bytes or returning residual]

Umm... If it's going through block layer, it should be split in such a way that the initial partial part is completed successuflly and then the latter part fails when re-issued. Not sure whether that would be possible for your code tho.

Quoted 10 lines
Quoted 3 lines

Please note that in the above 'command' and 'residual count' are not as defined in SCSI. Those terms refer to how those concepts are used in the kernel and via SG_IO interface.

I do have Kernel code that relays on this. I do use bsg's SG_IO successfully that has above behaviour.

That is: total transparency of residual count and sense information communicated between user-code and target. Then user-code can make intelligent decisions based on what he's done. And this is what the Kernel policy should be. No more, no less.

I'm not sure the said code is safe with regard to buffer bouncing and all.

...

Quoted 11 lines
Quoted 4 lines

No it's not about being good or bad. It's about being plain undefined. There is no value in setting an inherently undefined value to certain values in certain corner cases.

Again. With some commands/subsystems these are undefined, with some like SCSI, they are very well defined in all cases. (Even in the undefined cases). So please keep them intact, some code might want to relay on this.

(On the undefined cases Kernel should set a policy on what is returned)

Quoted 7 lines

IIUC, it's undefined at the block layer, well, at least till now and it working for your code could just be dumb luck (bouncing not happened or data transfer direction is to device or whatever).

So, basically, your code which depends on residual count on failure is broken. :-(

Yes, you are unfortunately, totally right. As I sent the last patches (blk_make_request) I realized that current osd code has a bug in that it does not bounce properly, all of the buffers. Since there is only iscsi transports, which are byte-aligned, and the network does it's own highmem bouncing, in practice there is no such bug.

But you are right, not thanks to block policy.

Quoted 2 lines

Thanks.

The solution to this, I think, is that the bouncing layer should receive a residual count, and not bounce anything beyond what's transferred. (On reads, writes does nothing), and zero-out the rest. This of course means that all block drivers make sure residual is properly set, the way it should as explained in this thread. (SCSI does the right thing where it can, for example see scsi_execute())

Thanks for bringing this up. Another unfortunate item on my todo list. Boaz

author
#35 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 7 lines · Boaz Harrosh

The solution to this, I think, is that the bouncing layer should receive a residual count, and not bounce anything beyond what's transferred. (On reads, writes does nothing), and zero-out the rest. This of course means that all block drivers make sure residual is properly set, the way it should as explained in this thread. (SCSI does the right thing where it can, for example see scsi_execute())

Umm... shouldn't the request just be successfully finished with positive residue count and with sense data if necessary? Block layer request failure means, and has always meant, complete failure.

Thanks.

Signature · 1 line
tejun
#36 lore raw

Re: [PATCH 03/11] block: add rq->resid_len

Quoted 10 lines · Tejun Heo
Quoted 7 lines · Boaz Harrosh

The solution to this, I think, is that the bouncing layer should receive a residual count, and not bounce anything beyond what's transferred. (On reads, writes does nothing), and zero-out the rest. This of course means that all block drivers make sure residual is properly set, the way it should as explained in this thread. (SCSI does the right thing where it can, for example see scsi_execute())

Quoted 4 lines

Umm... shouldn't the request just be successfully finished with positive residue count and with sense data if necessary? Block layer request failure means, and has always meant, complete failure.

I see, however if so then bouncing must take into consideration the residual count in the successful case, so not to copy garbage bytes. And drivers audited to make sure residual is set accordingly.

I wish we would set resid_len to data_len at begining and let drivers reset that on success properly, like SCSI does. I'll look at it farther when I have a bit of time.

Finally I see a distinct separate usage for the request->error member?

Quoted 2 lines

Thanks.

Thanks
Boaz

author
#37 lore raw

PATCH 4/11 block: implement blk_rq_pos/[cur_]sectors() and convert obvious ones

In reply to Tejun Heo

Implement accessors - blk_rq_pos(), blk_rq_sectors() and blk_rq_cur_sectors() which return rq->sector, rq->hard_nr_sectors and rq->hard_cur_sectors respectively and convert direct references of the said fields to the accessors.

This is in preparation of request data length handling cleanup.

const added to struct request * parameter to accessors as suggested by Geert Uytterhoeven.

[ Impact: cleanup ]

---
 block/blk-barrier.c             |    2 +-
 block/blk-core.c                |    2 +-
 block/cfq-iosched.c             |    2 +-
 drivers/block/ps3disk.c         |    2 +-
 drivers/block/viodasd.c         |    6 +++---
 drivers/block/xsysace.c         |   10 +++++-----
 drivers/ide/ide-cd.c            |    8 ++++----
 drivers/ide/ide-io.c            |    4 ++--
 drivers/message/i2o/i2o_block.c |    2 +-
 drivers/scsi/scsi_lib.c         |    2 +-
 include/linux/blkdev.h          |   23 ++++++++++++++++++++---
 kernel/trace/blktrace.c         |    4 ++--
 12 files changed, 42 insertions(+), 25 deletions(-)
block/blk-barrier.c +1 -1
index c8d0876..c167de5 100644
@@ -163,7 +163,7 @@ static inline bool start_ordered(struct request_queue *q, struct request **rqp)
 	 * For an empty barrier, there's no actual BAR request, which
 	 * in turn makes POSTFLUSH unnecessary.  Mask them off.
 	 */
-	if (!rq->hard_nr_sectors) {
+	if (!blk_rq_sectors(rq)) {
 		q->ordered &= ~(QUEUE_ORDERED_DO_BAR |
 				QUEUE_ORDERED_DO_POSTFLUSH);
 		/*
block/blk-core.c +1 -1
index 394c5bd..895e55b 100644
@@ -1683,7 +1683,7 @@ static void blk_account_io_done(struct request *req)
 unsigned int blk_rq_bytes(struct request *rq)
 {
 	if (blk_fs_request(rq))
-		return rq->hard_nr_sectors << 9;
+		return blk_rq_sectors(rq) << 9;
 
 	return rq->data_len;
 }
block/cfq-iosched.c +1 -1
index def0c69..575083a 100644
@@ -760,7 +760,7 @@ static void cfq_activate_request(struct request_queue *q, struct request *rq)
 	cfq_log_cfqq(cfqd, RQ_CFQQ(rq), "activate rq, drv=%d",
 						cfqd->rq_in_driver);
 
-	cfqd->last_position = rq->hard_sector + rq->hard_nr_sectors;
+	cfqd->last_position = blk_rq_pos(rq) + blk_rq_sectors(rq);
 }
 
 static void cfq_deactivate_request(struct request_queue *q, struct request *rq)
drivers/block/ps3disk.c +1 -1
index f6586e4..c238867 100644
@@ -136,7 +136,7 @@ static int ps3disk_submit_request_sg(struct ps3_storage_device *dev,
 	dev_dbg(&dev->sbd.core,
 		"%s:%u: %s req has %u bvecs for %lu sectors %lu hard sectors\n",
 		__func__, __LINE__, op, n, req->nr_sectors,
-		req->hard_nr_sectors);
+		blk_rq_sectors(req));
 #endif
 
 	start_sector = req->sector * priv->blocking_factor;
drivers/block/viodasd.c +3 -3
index ecccf65..e821eed 100644
@@ -368,12 +368,12 @@ static void do_viodasd_request(struct request_queue *q)
 		blkdev_dequeue_request(req);
 		/* check that request contains a valid command */
 		if (!blk_fs_request(req)) {
-			viodasd_end_request(req, -EIO, req->hard_nr_sectors);
+			viodasd_end_request(req, -EIO, blk_rq_sectors(req));
 			continue;
 		}
 		/* Try sending the request */
 		if (send_request(req) != 0)
-			viodasd_end_request(req, -EIO, req->hard_nr_sectors);
+			viodasd_end_request(req, -EIO, blk_rq_sectors(req));
 	}
 }
 
@@ -590,7 +590,7 @@ static int viodasd_handle_read_write(struct vioblocklpevent *bevent)
 		err = vio_lookup_rc(viodasd_err_table, bevent->sub_result);
 		printk(VIOD_KERN_WARNING "read/write error %d:0x%04x (%s)\n",
 				event->xRc, bevent->sub_result, err->msg);
-		num_sect = req->hard_nr_sectors;
+		num_sect = blk_rq_sectors(req);
 	}
 	qlock = req->q->queue_lock;
 	spin_lock_irqsave(qlock, irq_flags);
drivers/block/xsysace.c +5 -5
index b1e1d7e..5722931 100644
@@ -645,8 +645,8 @@ static void ace_fsm_dostate(struct ace_device *ace)
 
 		/* Okay, it's a data request, set it up for transfer */
 		dev_dbg(ace->dev,
-			"request: sec=%llx hcnt=%lx, ccnt=%x, dir=%i\n",
-			(unsigned long long) req->sector, req->hard_nr_sectors,
+			"request: sec=%llx hcnt=%x, ccnt=%x, dir=%i\n",
+			(unsigned long long) req->sector, blk_rq_sectors(req),
 			req->current_nr_sectors, rq_data_dir(req));
 
 		ace->req = req;
@@ -654,7 +654,7 @@ static void ace_fsm_dostate(struct ace_device *ace)
 		ace->data_count = req->current_nr_sectors * ACE_BUF_PER_SECTOR;
 		ace_out32(ace, ACE_MPULBA, req->sector & 0x0FFFFFFF);
 
-		count = req->hard_nr_sectors;
+		count = blk_rq_sectors(req);
 		if (rq_data_dir(req)) {
 			/* Kick off write request */
 			dev_dbg(ace->dev, "write data\n");
@@ -719,8 +719,8 @@ static void ace_fsm_dostate(struct ace_device *ace)
 		/* bio finished; is there another one? */
 		if (__blk_end_request(ace->req, 0,
 					blk_rq_cur_bytes(ace->req))) {
-			/* dev_dbg(ace->dev, "next block; h=%li c=%i\n",
-			 *      ace->req->hard_nr_sectors,
+			/* dev_dbg(ace->dev, "next block; h=%u c=%u\n",
+			 *      blk_rq_sectors(ace->req),
 			 *      ace->req->current_nr_sectors);
 			 */
 			ace->data_ptr = ace->req->buffer;
drivers/ide/ide-cd.c +4 -4
index cc8ac5b..474b283 100644
@@ -729,7 +729,7 @@ out_end:
 		if (blk_pc_request(rq))
 			nsectors = (rq->data_len + 511) >> 9;
 		else
-			nsectors = rq->hard_nr_sectors;
+			nsectors = blk_rq_sectors(rq);
 
 		if (nsectors == 0)
 			nsectors = 1;
@@ -874,7 +874,7 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
 
 	return ide_issue_pc(drive, &cmd);
 out_end:
-	nsectors = rq->hard_nr_sectors;
+	nsectors = blk_rq_sectors(rq);
 
 	if (nsectors == 0)
 		nsectors = 1;
@@ -1358,8 +1358,8 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
 static int ide_cdrom_prep_fs(struct request_queue *q, struct request *rq)
 {
 	int hard_sect = queue_hardsect_size(q);
-	long block = (long)rq->hard_sector / (hard_sect >> 9);
-	unsigned long blocks = rq->hard_nr_sectors / (hard_sect >> 9);
+	long block = (long)blk_rq_pos(rq) / (hard_sect >> 9);
+	unsigned long blocks = blk_rq_sectors(rq) / (hard_sect >> 9);
 
 	memset(rq->cmd, 0, BLK_MAX_CDB);
 
drivers/ide/ide-io.c +2 -2
index a0309ea..df23bcb 100644
@@ -118,7 +118,7 @@ unsigned int ide_rq_bytes(struct request *rq)
 	if (blk_pc_request(rq))
 		return rq->data_len;
 	else
-		return rq->hard_cur_sectors << 9;
+		return blk_rq_cur_sectors(rq) << 9;
 }
 EXPORT_SYMBOL_GPL(ide_rq_bytes);
 
@@ -133,7 +133,7 @@ int ide_complete_rq(ide_drive_t *drive, int error, unsigned int nr_bytes)
 	 * and complete the whole request right now
 	 */
 	if (blk_noretry_request(rq) && error <= 0)
-		nr_bytes = rq->hard_nr_sectors << 9;
+		nr_bytes = blk_rq_sectors(rq) << 9;
 
 	rc = ide_end_rq(drive, rq, error, nr_bytes);
 	if (rc == 0)
drivers/message/i2o/i2o_block.c +1 -1
index 221317e..56e60f0 100644
@@ -427,7 +427,7 @@ static void i2o_block_end_request(struct request *req, int error,
 	unsigned long flags;
 
 	if (blk_end_request(req, error, nr_bytes)) {
-		int leftover = (req->hard_nr_sectors << KERNEL_SECTOR_SHIFT);
+		int leftover = (blk_rq_sectors(req) << KERNEL_SECTOR_SHIFT);
 
 		if (blk_pc_request(req))
 			leftover = req->data_len;
drivers/scsi/scsi_lib.c +1 -1
index 7d49ef5..9ff0ca9 100644
@@ -546,7 +546,7 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error,
 	 * to queue the remainder of them.
 	 */
 	if (blk_end_request(req, error, bytes)) {
-		int leftover = (req->hard_nr_sectors << 9);
+		int leftover = blk_rq_sectors(req) << 9;
 
 		if (blk_pc_request(req))
 			leftover = req->resid_len;
include/linux/blkdev.h +20 -3
index 7ab93d9..b921d91 100644
@@ -833,13 +833,30 @@ static inline void blk_run_address_space(struct address_space *mapping)
 extern void blkdev_dequeue_request(struct request *req);
 
 /*
- * blk_end_request() takes bytes instead of sectors as a complete size.
- * blk_rq_bytes() returns bytes left to complete in the entire request.
- * blk_rq_cur_bytes() returns bytes left to complete in the current segment.
+ * blk_rq_pos()		: the current sector
+ * blk_rq_bytes()	: bytes left in the entire request
+ * blk_rq_cur_bytes()	: bytes left in the current segment
+ * blk_rq_sectors()	: sectors left in the entire request
+ * blk_rq_cur_sectors()	: sectors left in the current segment
  */
+static inline sector_t blk_rq_pos(const struct request *rq)
+{
+	return rq->hard_sector;
+}
+
 extern unsigned int blk_rq_bytes(struct request *rq);
 extern unsigned int blk_rq_cur_bytes(struct request *rq);
 
+static inline unsigned int blk_rq_sectors(const struct request *rq)
+{
+	return rq->hard_nr_sectors;
+}
+
+static inline unsigned int blk_rq_cur_sectors(const struct request *rq)
+{
+	return rq->hard_cur_sectors;
+}
+
 /*
  * Request completion related functions.
  *
kernel/trace/blktrace.c +2 -2
index 921ef5d..42f1c11 100644
@@ -646,7 +646,7 @@ static void blk_add_trace_rq(struct request_queue *q, struct request *rq,
 				rq->cmd_len, rq->cmd);
 	} else  {
 		what |= BLK_TC_ACT(BLK_TC_FS);
-		__blk_add_trace(bt, rq->hard_sector, rq->hard_nr_sectors << 9,
+		__blk_add_trace(bt, blk_rq_pos(rq), blk_rq_sectors(rq) << 9,
 				rw, what, rq->errors, 0, NULL);
 	}
 }
@@ -857,7 +857,7 @@ void blk_add_driver_data(struct request_queue *q,
 		__blk_add_trace(bt, 0, rq->data_len, 0, BLK_TA_DRV_DATA,
 				rq->errors, len, data);
 	else
-		__blk_add_trace(bt, rq->hard_sector, rq->hard_nr_sectors << 9,
+		__blk_add_trace(bt, blk_rq_pos(rq), blk_rq_sectors(rq) << 9,
 				0, BLK_TA_DRV_DATA, rq->errors, len, data);
 }
 EXPORT_SYMBOL_GPL(blk_add_driver_data);
Signature · 1 line
1.6.0.2
Acked-by on v1 4/11
#38 lore raw

Re: [PATCH 04/11] block: implement blk_rq_pos/[cur_]sectors() and convert obvious ones

Quoted 2 lines · Tejun Heo

Implement accessors - blk_rq_pos(), blk_rq_sectors() and blk_rq_cur_sectors() which return rq->sector, rq->hard_nr_sectors and

Well, blk_rq_pos() returns rq->hard_sector, not rq->sector, doesn't it?

Quoted 8 lines

rq->hard_cur_sectors respectively and convert direct references of the said fields to the accessors.

This is in preparation of request data length handling cleanup.

const added to struct request * parameter to accessors as suggested by Geert Uytterhoeven.

Quoted 7 lines

[ Impact: cleanup ]

Quoted 12 lines
include/linux/blkdev.h +1 -3
index 7ab93d9..b921d91 100644
@@ -833,13 +833,30 @@ static inline void blk_run_address_space(struct address_space *mapping)
 extern void blkdev_dequeue_request(struct request *req);
 
 /*
- * blk_end_request() takes bytes instead of sectors as a complete size.
- * blk_rq_bytes() returns bytes left to complete in the entire request.
- * blk_rq_cur_bytes() returns bytes left to complete in the current segment.
+ * blk_rq_pos()		: the current sector

include/linux/blkdev.h static inline void blk_run_address_space(struct address_space *mapping) · line 846

Quoted 10 lines
include/linux/blkdev.h +9 -0
+ * blk_rq_bytes()	: bytes left in the entire request
+ * blk_rq_cur_bytes()	: bytes left in the current segment
+ * blk_rq_sectors()	: sectors left in the entire request
+ * blk_rq_cur_sectors()	: sectors left in the current segment
  */
+static inline sector_t blk_rq_pos(const struct request *rq)
+{
+	return rq->hard_sector;
+}
+

[...]

MBR, Sergei

author
#39 lore raw

Re: [PATCH 04/11] block: implement blk_rq_pos/[cur_]sectors() and convert obvious ones

Quoted 6 lines · Sergei Shtylyov
Quoted 2 lines · Tejun Heo

Implement accessors - blk_rq_pos(), blk_rq_sectors() and blk_rq_cur_sectors() which return rq->sector, rq->hard_nr_sectors and

   Well, blk_rq_pos() returns rq->hard_sector, not rq->sector, doesn't it?

Right, description updated.

Thanks.

Signature · 1 line
tejun
author
#40 lore raw

PATCH 5/11 block: convert to pos and nr_sectors accessors

In reply to Tejun Heo

With recent cleanups, there is no place where low level driver directly manipulates request fields. This means that the 'hard' request fields always equal the !hard fields. Convert all rq->sectors, nr_sectors and current_nr_sectors references to accessors.

[ Impact: use pos and nr_sectors accessors ]

Cc James Bottomley <[email protected]>
Cc Bartlomiej Zolnierkiewicz <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Sergei Shtylyov <[email protected]>
Cc Mike Miller <[email protected]>
Cc Eric Moore <[email protected]>
Cc Alan Stern <[email protected]>
Cc FUJITA Tomonori <[email protected]>
Cc Pete Zaitcev <[email protected]>
Cc Stephen Rothwell <[email protected]>
Cc Paul Clements <[email protected]>
Cc Tim Waugh <[email protected]>
Cc Jeff Garzik <[email protected]>
Cc Jeremy Fitzhardinge <[email protected]>
Cc Alex Dubov <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Dario Ballabio <[email protected]>
Cc David S. Miller <[email protected]>
Cc Rusty Russell <[email protected]>
---
 arch/um/drivers/ubd_kern.c          |    2 +-
 block/as-iosched.c                  |   18 ++++++-----
 block/blk-barrier.c                 |    2 +-
 block/blk-core.c                    |   17 +++++------
 block/blk-merge.c                   |   10 +++---
 block/cfq-iosched.c                 |   18 ++++++------
 block/deadline-iosched.c            |    2 +-
 block/elevator.c                    |   22 +++++++-------
 drivers/block/DAC960.c              |    6 ++--
 drivers/block/amiflop.c             |    6 ++--
 drivers/block/ataflop.c             |   10 +++---
 drivers/block/cciss.c               |   22 +++++++-------
 drivers/block/cpqarray.c            |    9 +++--
 drivers/block/floppy.c              |   53 ++++++++++++++++++-----------------
 drivers/block/hd.c                  |   14 ++++----
 drivers/block/nbd.c                 |   12 ++++----
 drivers/block/paride/pcd.c          |    4 +-
 drivers/block/paride/pd.c           |    8 ++--
 drivers/block/paride/pf.c           |    8 ++--
 drivers/block/ps3disk.c             |    9 ++---
 drivers/block/sunvdc.c              |    2 +-
 drivers/block/swim3.c               |   34 ++++++++++++----------
 drivers/block/sx8.c                 |    6 ++--
 drivers/block/ub.c                  |    6 ++--
 drivers/block/viodasd.c             |    2 +-
 drivers/block/virtio_blk.c          |    2 +-
 drivers/block/xd.c                  |    4 +-
 drivers/block/xen-blkfront.c        |   11 +++----
 drivers/block/xsysace.c             |   17 ++++++-----
 drivers/block/z2ram.c               |    6 ++--
 drivers/cdrom/gdrom.c               |    6 ++--
 drivers/cdrom/viocd.c               |    2 +-
 drivers/memstick/core/mspro_block.c |    6 ++--
 drivers/message/i2o/i2o_block.c     |   20 +++++++------
 drivers/mmc/card/block.c            |   10 +++---
 drivers/mtd/mtd_blkdevs.c           |    7 ++--
 drivers/s390/block/dasd.c           |    2 +-
 drivers/s390/block/dasd_diag.c      |    5 ++-
 drivers/s390/block/dasd_eckd.c      |    6 ++--
 drivers/s390/block/dasd_fba.c       |    7 ++--
 drivers/s390/char/tape_34xx.c       |    2 +-
 drivers/s390/char/tape_3590.c       |    2 +-
 drivers/s390/char/tape_block.c      |    2 +-
 drivers/sbus/char/jsflash.c         |    4 +-
 drivers/scsi/eata.c                 |   24 ++++++++--------
 drivers/scsi/lpfc/lpfc_scsi.c       |   22 +++++++-------
 drivers/scsi/scsi_lib.c             |    6 ++--
 drivers/scsi/sd.c                   |   24 ++++++++--------
 drivers/scsi/sd_dif.c               |    2 +-
 drivers/scsi/sr.c                   |   15 +++++----
 drivers/scsi/u14-34f.c              |   22 ++++++++------
 include/scsi/scsi_cmnd.h            |    2 +-
 52 files changed, 276 insertions(+), 264 deletions(-)
arch/um/drivers/ubd_kern.c +1 -1
index 4330127..402ba8f 100644
@@ -1239,7 +1239,7 @@ static void do_ubd_request(struct request_queue *q)
 		}
 
 		req = dev->request;
-		sector = req->sector;
+		sector = blk_rq_pos(req);
 		while(dev->start_sg < dev->end_sg){
 			struct scatterlist *sg = &dev->sg[dev->start_sg];
 
block/as-iosched.c +10 -8
index 45bd070..7a12cf6 100644
@@ -306,8 +306,8 @@ as_choose_req(struct as_data *ad, struct request *rq1, struct request *rq2)
 	data_dir = rq_is_sync(rq1);
 
 	last = ad->last_sector[data_dir];
-	s1 = rq1->sector;
-	s2 = rq2->sector;
+	s1 = blk_rq_pos(rq1);
+	s2 = blk_rq_pos(rq2);
 
 	BUG_ON(data_dir != rq_is_sync(rq2));
 
@@ -566,13 +566,15 @@ static void as_update_iohist(struct as_data *ad, struct as_io_context *aic,
 			as_update_thinktime(ad, aic, thinktime);
 
 			/* Calculate read -> read seek distance */
-			if (aic->last_request_pos < rq->sector)
-				seek_dist = rq->sector - aic->last_request_pos;
+			if (aic->last_request_pos < blk_rq_pos(rq))
+				seek_dist = blk_rq_pos(rq) -
+					    aic->last_request_pos;
 			else
-				seek_dist = aic->last_request_pos - rq->sector;
+				seek_dist = aic->last_request_pos -
+					    blk_rq_pos(rq);
 			as_update_seekdist(ad, aic, seek_dist);
 		}
-		aic->last_request_pos = rq->sector + rq->nr_sectors;
+		aic->last_request_pos = blk_rq_pos(rq) + blk_rq_sectors(rq);
 		set_bit(AS_TASK_IOSTARTED, &aic->state);
 		spin_unlock(&aic->lock);
 	}
@@ -587,7 +589,7 @@ static int as_close_req(struct as_data *ad, struct as_io_context *aic,
 {
 	unsigned long delay;	/* jiffies */
 	sector_t last = ad->last_sector[ad->batch_data_dir];
-	sector_t next = rq->sector;
+	sector_t next = blk_rq_pos(rq);
 	sector_t delta; /* acceptable close offset (in sectors) */
 	sector_t s;
 
@@ -981,7 +983,7 @@ static void as_move_to_dispatch(struct as_data *ad, struct request *rq)
 	 * This has to be set in order to be correctly updated by
 	 * as_find_next_rq
 	 */
-	ad->last_sector[data_dir] = rq->sector + rq->nr_sectors;
+	ad->last_sector[data_dir] = blk_rq_pos(rq) + blk_rq_sectors(rq);
 
 	if (data_dir == BLK_RW_SYNC) {
 		struct io_context *ioc = RQ_IOC(rq);
block/blk-barrier.c +1 -1
index c167de5..8713c2f 100644
@@ -324,7 +324,7 @@ int blkdev_issue_flush(struct block_device *bdev, sector_t *error_sector)
 	/*
 	 * The driver must store the error location in ->bi_sector, if
 	 * it supports it. For non-stacked drivers, this should be copied
-	 * from rq->sector.
+	 * from blk_rq_pos(rq).
 	 */
 	if (error_sector)
 		*error_sector = bio->bi_sector;
block/blk-core.c +8 -9
index 895e55b..82dc206 100644
@@ -72,7 +72,7 @@ static void drive_stat_acct(struct request *rq, int new_io)
 		return;
 
 	cpu = part_stat_lock();
-	part = disk_map_sector_rcu(rq->rq_disk, rq->sector);
+	part = disk_map_sector_rcu(rq->rq_disk, blk_rq_pos(rq));
 
 	if (!new_io)
 		part_stat_inc(cpu, part, merges[rw]);
@@ -185,10 +185,9 @@ void blk_dump_rq_flags(struct request *rq, char *msg)
 		rq->rq_disk ? rq->rq_disk->disk_name : "?", rq->cmd_type,
 		rq->cmd_flags);
 
-	printk(KERN_INFO "  sector %llu, nr/cnr %lu/%u\n",
-						(unsigned long long)rq->sector,
-						rq->nr_sectors,
-						rq->current_nr_sectors);
+	printk(KERN_INFO "  sector %llu, nr/cnr %u/%u\n",
+	       (unsigned long long)blk_rq_pos(rq),
+	       blk_rq_sectors(rq), blk_rq_cur_sectors(rq));
 	printk(KERN_INFO "  bio %p, biotail %p, buffer %p, len %u\n",
 						rq->bio, rq->biotail,
 						rq->buffer, rq->data_len);
@@ -1557,7 +1556,7 @@ EXPORT_SYMBOL(submit_bio);
  */
 int blk_rq_check_limits(struct request_queue *q, struct request *rq)
 {
-	if (rq->nr_sectors > q->max_sectors ||
+	if (blk_rq_sectors(rq) > q->max_sectors ||
 	    rq->data_len > q->max_hw_sectors << 9) {
 		printk(KERN_ERR "%s: over max size limit.\n", __func__);
 		return -EIO;
@@ -1645,7 +1644,7 @@ static void blk_account_io_completion(struct request *req, unsigned int bytes)
 		int cpu;
 
 		cpu = part_stat_lock();
-		part = disk_map_sector_rcu(req->rq_disk, req->sector);
+		part = disk_map_sector_rcu(req->rq_disk, blk_rq_pos(req));
 		part_stat_add(cpu, part, sectors[rw], bytes >> 9);
 		part_stat_unlock();
 	}
@@ -1665,7 +1664,7 @@ static void blk_account_io_done(struct request *req)
 		int cpu;
 
 		cpu = part_stat_lock();
-		part = disk_map_sector_rcu(req->rq_disk, req->sector);
+		part = disk_map_sector_rcu(req->rq_disk, blk_rq_pos(req));
 
 		part_stat_inc(cpu, part, ios[rw]);
 		part_stat_add(cpu, part, ticks[rw], duration);
@@ -1846,7 +1845,7 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
 	if (error && (blk_fs_request(req) && !(req->cmd_flags & REQ_QUIET))) {
 		printk(KERN_ERR "end_request: I/O error, dev %s, sector %llu\n",
 				req->rq_disk ? req->rq_disk->disk_name : "?",
-				(unsigned long long)req->sector);
+				(unsigned long long)blk_rq_pos(req));
 	}
 
 	blk_account_io_completion(req, nr_bytes);
block/blk-merge.c +5 -5
index 23d2a6f..bf62a87 100644
@@ -259,7 +259,7 @@ int ll_back_merge_fn(struct request_queue *q, struct request *req,
 	else
 		max_sectors = q->max_sectors;
 
-	if (req->nr_sectors + bio_sectors(bio) > max_sectors) {
+	if (blk_rq_sectors(req) + bio_sectors(bio) > max_sectors) {
 		req->cmd_flags |= REQ_NOMERGE;
 		if (req == q->last_merge)
 			q->last_merge = NULL;
@@ -284,7 +284,7 @@ int ll_front_merge_fn(struct request_queue *q, struct request *req,
 		max_sectors = q->max_sectors;
 
 
-	if (req->nr_sectors + bio_sectors(bio) > max_sectors) {
+	if (blk_rq_sectors(req) + bio_sectors(bio) > max_sectors) {
 		req->cmd_flags |= REQ_NOMERGE;
 		if (req == q->last_merge)
 			q->last_merge = NULL;
@@ -315,7 +315,7 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
 	/*
 	 * Will it become too large?
 	 */
-	if ((req->nr_sectors + next->nr_sectors) > q->max_sectors)
+	if ((blk_rq_sectors(req) + blk_rq_sectors(next)) > q->max_sectors)
 		return 0;
 
 	total_phys_segments = req->nr_phys_segments + next->nr_phys_segments;
@@ -345,7 +345,7 @@ static void blk_account_io_merge(struct request *req)
 		int cpu;
 
 		cpu = part_stat_lock();
-		part = disk_map_sector_rcu(req->rq_disk, req->sector);
+		part = disk_map_sector_rcu(req->rq_disk, blk_rq_pos(req));
 
 		part_round_stats(cpu, part);
 		part_dec_in_flight(part);
@@ -366,7 +366,7 @@ static int attempt_merge(struct request_queue *q, struct request *req,
 	/*
 	 * not contiguous
 	 */
-	if (req->sector + req->nr_sectors != next->sector)
+	if (blk_rq_pos(req) + blk_rq_sectors(req) != blk_rq_pos(next))
 		return 0;
 
 	if (rq_data_dir(req) != rq_data_dir(next)
block/cfq-iosched.c +9 -9
index 575083a..db4d990 100644
@@ -349,8 +349,8 @@ cfq_choose_req(struct cfq_data *cfqd, struct request *rq1, struct request *rq2)
 	else if (rq_is_meta(rq2) && !rq_is_meta(rq1))
 		return rq2;
 
-	s1 = rq1->sector;
-	s2 = rq2->sector;
+	s1 = blk_rq_pos(rq1);
+	s2 = blk_rq_pos(rq2);
 
 	last = cfqd->last_position;
 
@@ -949,10 +949,10 @@ static struct cfq_queue *cfq_set_active_queue(struct cfq_data *cfqd,
 static inline sector_t cfq_dist_from_last(struct cfq_data *cfqd,
 					  struct request *rq)
 {
-	if (rq->sector >= cfqd->last_position)
-		return rq->sector - cfqd->last_position;
+	if (blk_rq_pos(rq) >= cfqd->last_position)
+		return blk_rq_pos(rq) - cfqd->last_position;
 	else
-		return cfqd->last_position - rq->sector;
+		return cfqd->last_position - blk_rq_pos(rq);
 }
 
 #define CIC_SEEK_THR	8 * 1024
@@ -1918,10 +1918,10 @@ cfq_update_io_seektime(struct cfq_data *cfqd, struct cfq_io_context *cic,
 
 	if (!cic->last_request_pos)
 		sdist = 0;
-	else if (cic->last_request_pos < rq->sector)
-		sdist = rq->sector - cic->last_request_pos;
+	else if (cic->last_request_pos < blk_rq_pos(rq))
+		sdist = blk_rq_pos(rq) - cic->last_request_pos;
 	else
-		sdist = cic->last_request_pos - rq->sector;
+		sdist = cic->last_request_pos - blk_rq_pos(rq);
 
 	/*
 	 * Don't allow the seek distance to get too large from the
@@ -2071,7 +2071,7 @@ cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq,
 	cfq_update_io_seektime(cfqd, cic, rq);
 	cfq_update_idle_window(cfqd, cfqq, cic);
 
-	cic->last_request_pos = rq->sector + rq->nr_sectors;
+	cic->last_request_pos = blk_rq_pos(rq) + blk_rq_sectors(rq);
 
 	if (cfqq == cfqd->active_queue) {
 		/*
block/deadline-iosched.c +1 -1
index c4d991d..b547cbc 100644
@@ -138,7 +138,7 @@ deadline_merge(struct request_queue *q, struct request **req, struct bio *bio)
 
 		__rq = elv_rb_find(&dd->sort_list[bio_data_dir(bio)], sector);
 		if (__rq) {
-			BUG_ON(sector != __rq->sector);
+			BUG_ON(sector != blk_rq_pos(__rq));
 
 			if (elv_rq_merge_ok(__rq, bio)) {
 				ret = ELEVATOR_FRONT_MERGE;
block/elevator.c +11 -11
index 1af5d9f..9189200 100644
@@ -52,7 +52,7 @@ static const int elv_hash_shift = 6;
 #define ELV_HASH_FN(sec)	\
 		(hash_long(ELV_HASH_BLOCK((sec)), elv_hash_shift))
 #define ELV_HASH_ENTRIES	(1 << elv_hash_shift)
-#define rq_hash_key(rq)		((rq)->sector + (rq)->nr_sectors)
+#define rq_hash_key(rq)		(blk_rq_pos(rq) + blk_rq_sectors(rq))
 
 DEFINE_TRACE(block_rq_insert);
 DEFINE_TRACE(block_rq_issue);
@@ -119,9 +119,9 @@ static inline int elv_try_merge(struct request *__rq, struct bio *bio)
 	 * we can merge and sequence is ok, check if it's possible
 	 */
 	if (elv_rq_merge_ok(__rq, bio)) {
-		if (__rq->sector + __rq->nr_sectors == bio->bi_sector)
+		if (blk_rq_pos(__rq) + blk_rq_sectors(__rq) == bio->bi_sector)
 			ret = ELEVATOR_BACK_MERGE;
-		else if (__rq->sector - bio_sectors(bio) == bio->bi_sector)
+		else if (blk_rq_pos(__rq) - bio_sectors(bio) == bio->bi_sector)
 			ret = ELEVATOR_FRONT_MERGE;
 	}
 
@@ -370,9 +370,9 @@ struct request *elv_rb_add(struct rb_root *root, struct request *rq)
 		parent = *p;
 		__rq = rb_entry(parent, struct request, rb_node);
 
-		if (rq->sector < __rq->sector)
+		if (blk_rq_pos(rq) < blk_rq_pos(__rq))
 			p = &(*p)->rb_left;
-		else if (rq->sector > __rq->sector)
+		else if (blk_rq_pos(rq) > blk_rq_pos(__rq))
 			p = &(*p)->rb_right;
 		else
 			return __rq;
@@ -400,9 +400,9 @@ struct request *elv_rb_find(struct rb_root *root, sector_t sector)
 	while (n) {
 		rq = rb_entry(n, struct request, rb_node);
 
-		if (sector < rq->sector)
+		if (sector < blk_rq_pos(rq))
 			n = n->rb_left;
-		else if (sector > rq->sector)
+		else if (sector > blk_rq_pos(rq))
 			n = n->rb_right;
 		else
 			return rq;
@@ -441,14 +441,14 @@ void elv_dispatch_sort(struct request_queue *q, struct request *rq)
 			break;
 		if (pos->cmd_flags & stop_flags)
 			break;
-		if (rq->sector >= boundary) {
-			if (pos->sector < boundary)
+		if (blk_rq_pos(rq) >= boundary) {
+			if (blk_rq_pos(pos) < boundary)
 				continue;
 		} else {
-			if (pos->sector >= boundary)
+			if (blk_rq_pos(pos) >= boundary)
 				break;
 		}
-		if (rq->sector >= pos->sector)
+		if (blk_rq_pos(rq) >= blk_rq_pos(pos))
 			break;
 	}
 
drivers/block/DAC960.c +3 -3
index f22ed6c..774ab05 100644
@@ -3338,8 +3338,8 @@ static int DAC960_process_queue(DAC960_Controller_T *Controller, struct request_
 	}
 	Command->Completion = Request->end_io_data;
 	Command->LogicalDriveNumber = (long)Request->rq_disk->private_data;
-	Command->BlockNumber = Request->sector;
-	Command->BlockCount = Request->nr_sectors;
+	Command->BlockNumber = blk_rq_pos(Request);
+	Command->BlockCount = blk_rq_sectors(Request);
 	Command->Request = Request;
 	blkdev_dequeue_request(Request);
 	Command->SegmentCount = blk_rq_map_sg(req_q,
@@ -3431,7 +3431,7 @@ static void DAC960_queue_partial_rw(DAC960_Command_T *Command)
    * successfully as possible.
    */
   Command->SegmentCount = 1;
-  Command->BlockNumber = Request->sector;
+  Command->BlockNumber = blk_rq_pos(Request);
   Command->BlockCount = 1;
   DAC960_QueueReadWriteCommand(Command);
   return;
drivers/block/amiflop.c +3 -3
index 8ff95f2..e4a14b9 100644
@@ -1351,13 +1351,13 @@ static void redo_fd_request(void)
 	drive = floppy - unit;
 
 	/* Here someone could investigate to be more efficient */
-	for (cnt = 0; cnt < CURRENT->current_nr_sectors; cnt++) { 
+	for (cnt = 0; cnt < blk_rq_cur_sectors(CURRENT); cnt++) {
 #ifdef DEBUG
 		printk("fd: sector %ld + %d requested for %s\n",
-		       CURRENT->sector,cnt,
+		       blk_rq_pos(CURRENT), cnt,
 		       (rq_data_dir(CURRENT) == READ) ? "read" : "write");
 #endif
-		block = CURRENT->sector + cnt;
+		block = blk_rq_pos(CURRENT) + cnt;
 		if ((int)block > floppy->blocks) {
 			__blk_end_request_cur(CURRENT, -EIO);
 			goto repeat;
drivers/block/ataflop.c +5 -5
index 2506728..234024c 100644
@@ -725,7 +725,7 @@ static void do_fd_action( int drive )
 	    if (IS_BUFFERED( drive, ReqSide, ReqTrack )) {
 		if (ReqCmd == READ) {
 		    copy_buffer( SECTOR_BUFFER(ReqSector), ReqData );
-		    if (++ReqCnt < CURRENT->current_nr_sectors) {
+		    if (++ReqCnt < blk_rq_cur_sectors(CURRENT)) {
 			/* read next sector */
 			setup_req_params( drive );
 			goto repeat;
@@ -1130,7 +1130,7 @@ static void fd_rwsec_done1(int status)
 		}
 	}
   
-	if (++ReqCnt < CURRENT->current_nr_sectors) {
+	if (++ReqCnt < blk_rq_cur_sectors(CURRENT)) {
 		/* read next sector */
 		setup_req_params( SelectedDrive );
 		do_fd_action( SelectedDrive );
@@ -1394,7 +1394,7 @@ static void redo_fd_request(void)
 
 	DPRINT(("redo_fd_request: CURRENT=%p dev=%s CURRENT->sector=%ld\n",
 		CURRENT, CURRENT ? CURRENT->rq_disk->disk_name : "",
-		CURRENT ? CURRENT->sector : 0 ));
+		CURRENT ? blk_rq_pos(CURRENT) : 0 ));
 
 	IsFormatting = 0;
 
@@ -1440,7 +1440,7 @@ repeat:
 		UD.autoprobe = 0;
 	}
 	
-	if (CURRENT->sector + 1 > UDT->blocks) {
+	if (blk_rq_pos(CURRENT) + 1 > UDT->blocks) {
 		__blk_end_request_cur(CURRENT, -EIO);
 		goto repeat;
 	}
@@ -1450,7 +1450,7 @@ repeat:
 		
 	ReqCnt = 0;
 	ReqCmd = rq_data_dir(CURRENT);
-	ReqBlock = CURRENT->sector;
+	ReqBlock = blk_rq_pos(CURRENT);
 	ReqBuffer = CURRENT->buffer;
 	setup_req_params( drive );
 	do_fd_action( drive );
drivers/block/cciss.c +11 -11
index f22d493..ab7b04c 100644
@@ -2835,10 +2835,10 @@ static void do_cciss_request(struct request_queue *q)
 	c->Request.Timeout = 0;	// Don't time out
 	c->Request.CDB[0] =
 	    (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write;
-	start_blk = creq->sector;
+	start_blk = blk_rq_pos(creq);
 #ifdef CCISS_DEBUG
-	printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n", (int)creq->sector,
-	       (int)creq->nr_sectors);
+	printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n",
+	       (int)blk_rq_pos(creq), (int)blk_rq_sectors(creq));
 #endif				/* CCISS_DEBUG */
 
 	sg_init_table(tmp_sg, MAXSGENTRIES);
@@ -2864,8 +2864,8 @@ static void do_cciss_request(struct request_queue *q)
 		h->maxSG = seg;
 
 #ifdef CCISS_DEBUG
-	printk(KERN_DEBUG "cciss: Submitting %lu sectors in %d segments\n",
-	       creq->nr_sectors, seg);
+	printk(KERN_DEBUG "cciss: Submitting %u sectors in %d segments\n",
+	       blk_rq_sectors(creq), seg);
 #endif				/* CCISS_DEBUG */
 
 	c->Header.SGList = c->Header.SGTotal = seg;
@@ -2877,8 +2877,8 @@ static void do_cciss_request(struct request_queue *q)
 			c->Request.CDB[4] = (start_blk >> 8) & 0xff;
 			c->Request.CDB[5] = start_blk & 0xff;
 			c->Request.CDB[6] = 0;	// (sect >> 24) & 0xff; MSB
-			c->Request.CDB[7] = (creq->nr_sectors >> 8) & 0xff;
-			c->Request.CDB[8] = creq->nr_sectors & 0xff;
+			c->Request.CDB[7] = (blk_rq_sectors(creq) >> 8) & 0xff;
+			c->Request.CDB[8] = blk_rq_sectors(creq) & 0xff;
 			c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0;
 		} else {
 			u32 upper32 = upper_32_bits(start_blk);
@@ -2893,10 +2893,10 @@ static void do_cciss_request(struct request_queue *q)
 			c->Request.CDB[7]= (start_blk >> 16) & 0xff;
 			c->Request.CDB[8]= (start_blk >>  8) & 0xff;
 			c->Request.CDB[9]= start_blk & 0xff;
-			c->Request.CDB[10]= (creq->nr_sectors >>  24) & 0xff;
-			c->Request.CDB[11]= (creq->nr_sectors >>  16) & 0xff;
-			c->Request.CDB[12]= (creq->nr_sectors >>  8) & 0xff;
-			c->Request.CDB[13]= creq->nr_sectors & 0xff;
+			c->Request.CDB[10]= (blk_rq_sectors(creq) >> 24) & 0xff;
+			c->Request.CDB[11]= (blk_rq_sectors(creq) >> 16) & 0xff;
+			c->Request.CDB[12]= (blk_rq_sectors(creq) >>  8) & 0xff;
+			c->Request.CDB[13]= blk_rq_sectors(creq) & 0xff;
 			c->Request.CDB[14] = c->Request.CDB[15] = 0;
 		}
 	} else if (blk_pc_request(creq)) {
drivers/block/cpqarray.c +5 -4
index 488a8f4..a5caeff 100644
@@ -919,10 +919,11 @@ queue_next:
 	c->hdr.size = sizeof(rblk_t) >> 2;
 	c->size += sizeof(rblk_t);
 
-	c->req.hdr.blk = creq->sector;
+	c->req.hdr.blk = blk_rq_pos(creq);
 	c->rq = creq;
 DBGPX(
-	printk("sector=%d, nr_sectors=%d\n", creq->sector, creq->nr_sectors);
+	printk("sector=%d, nr_sectors=%u\n",
+	       blk_rq_pos(creq), blk_rq_sectors(creq));
 );
 	sg_init_table(tmp_sg, SG_MAX);
 	seg = blk_rq_map_sg(q, creq, tmp_sg);
@@ -940,9 +941,9 @@ DBGPX(
 						 tmp_sg[i].offset,
 						 tmp_sg[i].length, dir);
 	}
-DBGPX(	printk("Submitting %d sectors in %d segments\n", creq->nr_sectors, seg); );
+DBGPX(	printk("Submitting %u sectors in %d segments\n", blk_rq_sectors(creq), seg); );
 	c->req.hdr.sg_cnt = seg;
-	c->req.hdr.blk_cnt = creq->nr_sectors;
+	c->req.hdr.blk_cnt = blk_rq_sectors(creq);
 	c->req.hdr.cmd = (rq_data_dir(creq) == READ) ? IDA_READ : IDA_WRITE;
 	c->type = CMD_RWREQ;
 
drivers/block/floppy.c +27 -26

146 lines not on this page · raw message

drivers/block/hd.c +7 -7
index 75b9ca9..a3b3994 100644
@@ -228,7 +228,7 @@ static void dump_status(const char *msg, unsigned int stat)
 			printk(", CHS=%d/%d/%d", (inb(HD_HCYL)<<8) + inb(HD_LCYL),
 				inb(HD_CURRENT) & 0xf, inb(HD_SECTOR));
 			if (CURRENT)
-				printk(", sector=%ld", CURRENT->sector);
+				printk(", sector=%ld", blk_rq_pos(CURRENT));
 		}
 		printk("\n");
 	}
@@ -457,9 +457,9 @@ ok_to_read:
 	req = CURRENT;
 	insw(HD_DATA, req->buffer, 256);
 #ifdef DEBUG
-	printk("%s: read: sector %ld, remaining = %ld, buffer=%p\n",
-		req->rq_disk->disk_name, req->sector + 1, req->nr_sectors - 1,
-		req->buffer+512);
+	printk("%s: read: sector %ld, remaining = %u, buffer=%p\n",
+	       req->rq_disk->disk_name, blk_rq_pos(req) + 1,
+	       blk_rq_sectors(req) - 1, req->buffer+512);
 #endif
 	if (__blk_end_request(req, 0, 512)) {
 		SET_HANDLER(&read_intr);
@@ -485,7 +485,7 @@ static void write_intr(void)
 			continue;
 		if (!OK_STATUS(i))
 			break;
-		if ((req->nr_sectors <= 1) || (i & DRQ_STAT))
+		if ((blk_rq_sectors(req) <= 1) || (i & DRQ_STAT))
 			goto ok_to_write;
 	} while (--retries > 0);
 	dump_status("write_intr", i);
@@ -589,8 +589,8 @@ repeat:
 		return;
 	}
 	disk = req->rq_disk->private_data;
-	block = req->sector;
-	nsect = req->nr_sectors;
+	block = blk_rq_pos(req);
+	nsect = blk_rq_sectors(req);
 	if (block >= get_capacity(req->rq_disk) ||
 	    ((block+nsect) > get_capacity(req->rq_disk))) {
 		printk("%s: bad access: block=%d, count=%d\n",
drivers/block/nbd.c +6 -6
index a9ab8be..977a573 100644
@@ -110,7 +110,7 @@ static void nbd_end_request(struct request *req)
 			req, error ? "failed" : "done");
 
 	spin_lock_irqsave(q->queue_lock, flags);
-	__blk_end_request(req, error, req->nr_sectors << 9);
+	__blk_end_request(req, error, blk_rq_sectors(req) << 9);
 	spin_unlock_irqrestore(q->queue_lock, flags);
 }
 
@@ -231,19 +231,19 @@ static int nbd_send_req(struct nbd_device *lo, struct request *req)
 {
 	int result, flags;
 	struct nbd_request request;
-	unsigned long size = req->nr_sectors << 9;
+	unsigned long size = blk_rq_sectors(req) << 9;
 
 	request.magic = htonl(NBD_REQUEST_MAGIC);
 	request.type = htonl(nbd_cmd(req));
-	request.from = cpu_to_be64((u64) req->sector << 9);
+	request.from = cpu_to_be64((u64)blk_rq_pos(req) << 9);
 	request.len = htonl(size);
 	memcpy(request.handle, &req, sizeof(req));
 
-	dprintk(DBG_TX, "%s: request %p: sending control (%s@%llu,%luB)\n",
+	dprintk(DBG_TX, "%s: request %p: sending control (%s@%llu,%uB)\n",
 			lo->disk->disk_name, req,
 			nbdcmd_to_ascii(nbd_cmd(req)),
-			(unsigned long long)req->sector << 9,
-			req->nr_sectors << 9);
+			(unsigned long long)blk_rq_pos(req) << 9,
+			blk_rq_sectors(req) << 9);
 	result = sock_xmit(lo, 1, &request, sizeof(request),
 			(nbd_cmd(req) == NBD_CMD_WRITE) ? MSG_MORE : 0);
 	if (result <= 0) {
drivers/block/paride/pcd.c +2 -2
index 9fd57c2..2d5dc0a 100644
@@ -728,8 +728,8 @@ static void do_pcd_request(struct request_queue * q)
 			if (cd != pcd_current)
 				pcd_bufblk = -1;
 			pcd_current = cd;
-			pcd_sector = pcd_req->sector;
-			pcd_count = pcd_req->current_nr_sectors;
+			pcd_sector = blk_rq_pos(pcd_req);
+			pcd_count = blk_rq_cur_sectors(pcd_req);
 			pcd_buf = pcd_req->buffer;
 			pcd_busy = 1;
 			ps_set_intr(do_pcd_read, NULL, 0, nice);
drivers/block/paride/pd.c +4 -4
index 0732df4..9ec5d4a 100644
@@ -444,11 +444,11 @@ static enum action do_pd_io_start(void)
 
 	pd_cmd = rq_data_dir(pd_req);
 	if (pd_cmd == READ || pd_cmd == WRITE) {
-		pd_block = pd_req->sector;
-		pd_count = pd_req->current_nr_sectors;
+		pd_block = blk_rq_pos(pd_req);
+		pd_count = blk_rq_cur_sectors(pd_req);
 		if (pd_block + pd_count > get_capacity(pd_req->rq_disk))
 			return Fail;
-		pd_run = pd_req->nr_sectors;
+		pd_run = blk_rq_sectors(pd_req);
 		pd_buf = pd_req->buffer;
 		pd_retries = 0;
 		if (pd_cmd == READ)
@@ -479,7 +479,7 @@ static int pd_next_buf(void)
 		return 0;
 	spin_lock_irqsave(&pd_lock, saved_flags);
 	__blk_end_request_cur(pd_req, 0);
-	pd_count = pd_req->current_nr_sectors;
+	pd_count = blk_rq_cur_sectors(pd_req);
 	pd_buf = pd_req->buffer;
 	spin_unlock_irqrestore(&pd_lock, saved_flags);
 	return 0;
drivers/block/paride/pf.c +4 -4
index 3871e35..e88c889 100644
@@ -768,9 +768,9 @@ repeat:
 		return;
 
 	pf_current = pf_req->rq_disk->private_data;
-	pf_block = pf_req->sector;
-	pf_run = pf_req->nr_sectors;
-	pf_count = pf_req->current_nr_sectors;
+	pf_block = blk_rq_pos(pf_req);
+	pf_run = blk_rq_sectors(pf_req);
+	pf_count = blk_rq_cur_sectors(pf_req);
 
 	if (pf_block + pf_count > get_capacity(pf_req->rq_disk)) {
 		pf_end_request(-EIO);
@@ -810,7 +810,7 @@ static int pf_next_buf(void)
 		spin_unlock_irqrestore(&pf_spin_lock, saved_flags);
 		if (!pf_req)
 			return 1;
-		pf_count = pf_req->current_nr_sectors;
+		pf_count = blk_rq_cur_sectors(pf_req);
 		pf_buf = pf_req->buffer;
 	}
 	return 0;
drivers/block/ps3disk.c +4 -5
index c238867..8d58308 100644
@@ -134,13 +134,12 @@ static int ps3disk_submit_request_sg(struct ps3_storage_device *dev,
 	rq_for_each_segment(bv, req, iter)
 		n++;
 	dev_dbg(&dev->sbd.core,
-		"%s:%u: %s req has %u bvecs for %lu sectors %lu hard sectors\n",
-		__func__, __LINE__, op, n, req->nr_sectors,
-		blk_rq_sectors(req));
+		"%s:%u: %s req has %u bvecs for %u sectors\n",
+		__func__, __LINE__, op, n, blk_rq_sectors(req));
 #endif
 
-	start_sector = req->sector * priv->blocking_factor;
-	sectors = req->nr_sectors * priv->blocking_factor;
+	start_sector = blk_rq_pos(req) * priv->blocking_factor;
+	sectors = blk_rq_sectors(req) * priv->blocking_factor;
 	dev_dbg(&dev->sbd.core, "%s:%u: %s %llu sectors starting at %llu\n",
 		__func__, __LINE__, op, sectors, start_sector);
 
drivers/block/sunvdc.c +1 -1
index f59887c..9f351bf 100644
@@ -416,7 +416,7 @@ static int __send_request(struct request *req)
 		desc->slice = 0;
 	}
 	desc->status = ~0;
-	desc->offset = (req->sector << 9) / port->vdisk_block_size;
+	desc->offset = (blk_rq_pos(req) << 9) / port->vdisk_block_size;
 	desc->size = len;
 	desc->ncookies = err;
 
drivers/block/swim3.c +18 -16
index 4248559..c1b9a4d 100644
@@ -312,14 +312,14 @@ static void start_request(struct floppy_state *fs)
 	}
 	while (fs->state == idle && (req = elv_next_request(swim3_queue))) {
 #if 0
-		printk("do_fd_req: dev=%s cmd=%d sec=%ld nr_sec=%ld buf=%p\n",
+		printk("do_fd_req: dev=%s cmd=%d sec=%ld nr_sec=%u buf=%p\n",
 		       req->rq_disk->disk_name, req->cmd,
-		       (long)req->sector, req->nr_sectors, req->buffer);
-		printk("           errors=%d current_nr_sectors=%ld\n",
-		       req->errors, req->current_nr_sectors);
+		       (long)blk_rq_pos(req), blk_rq_sectors(req), req->buffer);
+		printk("           errors=%d current_nr_sectors=%u\n",
+		       req->errors, blk_rq_cur_sectors(req));
 #endif
 
-		if (req->sector >= fs->total_secs) {
+		if (blk_rq_pos(req) >= fs->total_secs) {
 			__blk_end_request_cur(req, -EIO);
 			continue;
 		}
@@ -337,13 +337,14 @@ static void start_request(struct floppy_state *fs)
 			}
 		}
 
-		/* Do not remove the cast. req->sector is now a sector_t and
-		 * can be 64 bits, but it will never go past 32 bits for this
-		 * driver anyway, so we can safely cast it down and not have
-		 * to do a 64/32 division
+		/* Do not remove the cast. blk_rq_pos(req) is now a
+		 * sector_t and can be 64 bits, but it will never go
+		 * past 32 bits for this driver anyway, so we can
+		 * safely cast it down and not have to do a 64/32
+		 * division
 		 */
-		fs->req_cyl = ((long)req->sector) / fs->secpercyl;
-		x = ((long)req->sector) % fs->secpercyl;
+		fs->req_cyl = ((long)blk_rq_pos(req)) / fs->secpercyl;
+		x = ((long)blk_rq_pos(req)) % fs->secpercyl;
 		fs->head = x / fs->secpertrack;
 		fs->req_sector = x % fs->secpertrack + 1;
 		fd_req = req;
@@ -420,7 +421,7 @@ static inline void setup_transfer(struct floppy_state *fs)
 	struct dbdma_cmd *cp = fs->dma_cmd;
 	struct dbdma_regs __iomem *dr = fs->dma;
 
-	if (fd_req->current_nr_sectors <= 0) {
+	if (blk_rq_cur_sectors(fd_req) <= 0) {
 		printk(KERN_ERR "swim3: transfer 0 sectors?\n");
 		return;
 	}
@@ -428,8 +429,8 @@ static inline void setup_transfer(struct floppy_state *fs)
 		n = 1;
 	else {
 		n = fs->secpertrack - fs->req_sector + 1;
-		if (n > fd_req->current_nr_sectors)
-			n = fd_req->current_nr_sectors;
+		if (n > blk_rq_cur_sectors(fd_req))
+			n = blk_rq_cur_sectors(fd_req);
 	}
 	fs->scount = n;
 	swim3_select(fs, fs->head? READ_DATA_1: READ_DATA_0);
@@ -600,7 +601,8 @@ static void xfer_timeout(unsigned long data)
 	out_8(&sw->control_bic, WRITE_SECTORS | DO_ACTION);
 	out_8(&sw->select, RELAX);
 	printk(KERN_ERR "swim3: timeout %sing sector %ld\n",
-	       (rq_data_dir(fd_req)==WRITE? "writ": "read"), (long)fd_req->sector);
+	       (rq_data_dir(fd_req)==WRITE? "writ": "read"),
+	       (long)blk_rq_pos(fd_req));
 	__blk_end_request_cur(fd_req, -EIO);
 	fs->state = idle;
 	start_request(fs);
@@ -714,7 +716,7 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id)
 			} else {
 				printk("swim3: error %sing block %ld (err=%x)\n",
 				       rq_data_dir(fd_req) == WRITE? "writ": "read",
-				       (long)fd_req->sector, err);
+				       (long)blk_rq_pos(fd_req), err);
 				__blk_end_request_cur(fd_req, -EIO);
 				fs->state = idle;
 			}
drivers/block/sx8.c +3 -3
index 60e85bb..087c94c 100644
@@ -903,10 +903,10 @@ queue_one_request:
 	msg->sg_count	= n_elem;
 	msg->sg_type	= SGT_32BIT;
 	msg->handle	= cpu_to_le32(TAG_ENCODE(crq->tag));
-	msg->lba	= cpu_to_le32(rq->sector & 0xffffffff);
-	tmp		= (rq->sector >> 16) >> 16;
+	msg->lba	= cpu_to_le32(blk_rq_pos(rq) & 0xffffffff);
+	tmp		= (blk_rq_pos(rq) >> 16) >> 16;
 	msg->lba_high	= cpu_to_le16( (u16) tmp );
-	msg->lba_count	= cpu_to_le16(rq->nr_sectors);
+	msg->lba_count	= cpu_to_le16(blk_rq_sectors(rq));
 
 	msg_size = sizeof(struct carm_msg_rw) - sizeof(msg->sg);
 	for (i = 0; i < n_elem; i++) {
drivers/block/ub.c +3 -3
index 8c2cc71..dc3b899 100644
@@ -726,8 +726,8 @@ static void ub_cmd_build_block(struct ub_dev *sc, struct ub_lun *lun,
 	 * The call to blk_queue_hardsect_size() guarantees that request
 	 * is aligned, but it is given in terms of 512 byte units, always.
 	 */
-	block = rq->sector >> lun->capacity.bshift;
-	nblks = rq->nr_sectors >> lun->capacity.bshift;
+	block = blk_rq_pos(rq) >> lun->capacity.bshift;
+	nblks = blk_rq_sectors(rq) >> lun->capacity.bshift;
 
 	cmd->cdb[0] = (cmd->dir == UB_DIR_READ)? READ_10: WRITE_10;
 	/* 10-byte uses 4 bytes of LBA: 2147483648KB, 2097152MB, 2048GB */
@@ -739,7 +739,7 @@ static void ub_cmd_build_block(struct ub_dev *sc, struct ub_lun *lun,
 	cmd->cdb[8] = nblks;
 	cmd->cdb_len = 10;
 
-	cmd->len = rq->nr_sectors * 512;
+	cmd->len = blk_rq_sectors(rq) * 512;
 }
 
 static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun,
drivers/block/viodasd.c +1 -1
index e821eed..2086cb1 100644
@@ -252,7 +252,7 @@ static int send_request(struct request *req)
 	struct viodasd_device *d;
 	unsigned long flags;
 
-	start = (u64)req->sector << 9;
+	start = (u64)blk_rq_pos(req) << 9;
 
 	if (rq_data_dir(req) == READ) {
 		direction = DMA_FROM_DEVICE;
drivers/block/virtio_blk.c +1 -1
index 50745e6..1980ab4 100644
@@ -85,7 +85,7 @@ static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
 	vbr->req = req;
 	if (blk_fs_request(vbr->req)) {
 		vbr->out_hdr.type = 0;
-		vbr->out_hdr.sector = vbr->req->sector;
+		vbr->out_hdr.sector = blk_rq_pos(vbr->req);
 		vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
 	} else if (blk_pc_request(vbr->req)) {
 		vbr->out_hdr.type = VIRTIO_BLK_T_SCSI_CMD;
drivers/block/xd.c +2 -2
index 14be4c1..4ef8801 100644
@@ -306,8 +306,8 @@ static void do_xd_request (struct request_queue * q)
 		return;
 
 	while ((req = elv_next_request(q)) != NULL) {
-		unsigned block = req->sector;
-		unsigned count = req->nr_sectors;
+		unsigned block = blk_rq_pos(req);
+		unsigned count = blk_rq_sectors(req);
 		XD_INFO *disk = req->rq_disk->private_data;
 		int res = 0;
 		int retry;
drivers/block/xen-blkfront.c +5 -6
index b456447..91fc565 100644
@@ -231,7 +231,7 @@ static int blkif_queue_request(struct request *req)
 	info->shadow[id].request = (unsigned long)req;
 
 	ring_req->id = id;
-	ring_req->sector_number = (blkif_sector_t)req->sector;
+	ring_req->sector_number = (blkif_sector_t)blk_rq_pos(req);
 	ring_req->handle = info->handle;
 
 	ring_req->operation = rq_data_dir(req) ?
@@ -310,11 +310,10 @@ static void do_blkif_request(struct request_queue *rq)
 			goto wait;
 
 		pr_debug("do_blk_req %p: cmd %p, sec %lx, "
-			 "(%u/%li) buffer:%p [%s]\n",
-			 req, req->cmd, (unsigned long)req->sector,
-			 req->current_nr_sectors,
-			 req->nr_sectors, req->buffer,
-			 rq_data_dir(req) ? "write" : "read");
+			 "(%u/%u) buffer:%p [%s]\n",
+			 req, req->cmd, (unsigned long)blk_rq_pos(req),
+			 blk_rq_cur_sectors(req), blk_rq_sectors(req),
+			 req->buffer, rq_data_dir(req) ? "write" : "read");
 
 
 		blkdev_dequeue_request(req);
drivers/block/xsysace.c +9 -8
index 5722931..97c99b4 100644
@@ -646,13 +646,14 @@ static void ace_fsm_dostate(struct ace_device *ace)
 		/* Okay, it's a data request, set it up for transfer */
 		dev_dbg(ace->dev,
 			"request: sec=%llx hcnt=%x, ccnt=%x, dir=%i\n",
-			(unsigned long long) req->sector, blk_rq_sectors(req),
-			req->current_nr_sectors, rq_data_dir(req));
+			(unsigned long long)blk_rq_pos(req),
+			blk_rq_sectors(req), blk_rq_cur_sectors(req),
+			rq_data_dir(req));
 
 		ace->req = req;
 		ace->data_ptr = req->buffer;
-		ace->data_count = req->current_nr_sectors * ACE_BUF_PER_SECTOR;
-		ace_out32(ace, ACE_MPULBA, req->sector & 0x0FFFFFFF);
+		ace->data_count = blk_rq_cur_sectors(req) * ACE_BUF_PER_SECTOR;
+		ace_out32(ace, ACE_MPULBA, blk_rq_pos(req) & 0x0FFFFFFF);
 
 		count = blk_rq_sectors(req);
 		if (rq_data_dir(req)) {
@@ -688,7 +689,7 @@ static void ace_fsm_dostate(struct ace_device *ace)
 			dev_dbg(ace->dev,
 				"CFBSY set; t=%i iter=%i c=%i dc=%i irq=%i\n",
 				ace->fsm_task, ace->fsm_iter_num,
-				ace->req->current_nr_sectors * 16,
+				blk_rq_cur_sectors(ace->req) * 16,
 				ace->data_count, ace->in_irq);
 			ace_fsm_yield(ace);	/* need to poll CFBSY bit */
 			break;
@@ -697,7 +698,7 @@ static void ace_fsm_dostate(struct ace_device *ace)
 			dev_dbg(ace->dev,
 				"DATABUF not set; t=%i iter=%i c=%i dc=%i irq=%i\n",
 				ace->fsm_task, ace->fsm_iter_num,
-				ace->req->current_nr_sectors * 16,
+				blk_rq_cur_sectors(ace->req) * 16,
 				ace->data_count, ace->in_irq);
 			ace_fsm_yieldirq(ace);
 			break;
@@ -721,10 +722,10 @@ static void ace_fsm_dostate(struct ace_device *ace)
 					blk_rq_cur_bytes(ace->req))) {
 			/* dev_dbg(ace->dev, "next block; h=%u c=%u\n",
 			 *      blk_rq_sectors(ace->req),
-			 *      ace->req->current_nr_sectors);
+			 *      blk_rq_cur_sectors(ace->req));
 			 */
 			ace->data_ptr = ace->req->buffer;
-			ace->data_count = ace->req->current_nr_sectors * 16;
+			ace->data_count = blk_rq_cur_sectors(ace->req) * 16;
 			ace_fsm_yieldirq(ace);
 			break;
 		}
drivers/block/z2ram.c +3 -3
index b66ad58..d4e6b71 100644
@@ -71,12 +71,12 @@ static void do_z2_request(struct request_queue *q)
 {
 	struct request *req;
 	while ((req = elv_next_request(q)) != NULL) {
-		unsigned long start = req->sector << 9;
-		unsigned long len  = req->current_nr_sectors << 9;
+		unsigned long start = blk_rq_pos(req) << 9;
+		unsigned long len  = blk_rq_cur_sectors(req) << 9;
 
 		if (start + len > z2ram_size) {
 			printk( KERN_ERR DEVICE_NAME ": bad access: block=%lu, count=%u\n",
-				req->sector, req->current_nr_sectors);
+				blk_rq_pos(req), blk_rq_cur_sectors(req));
 			__blk_end_request_cur(req, -EIO);
 			continue;
 		}
drivers/cdrom/gdrom.c +3 -3
index cab2b1f..488423c 100644
@@ -584,8 +584,8 @@ static void gdrom_readdisk_dma(struct work_struct *work)
 	list_for_each_safe(elem, next, &gdrom_deferred) {
 		req = list_entry(elem, struct request, queuelist);
 		spin_unlock(&gdrom_lock);
-		block = req->sector/GD_TO_BLK + GD_SESSION_OFFSET;
-		block_cnt = req->nr_sectors/GD_TO_BLK;
+		block = blk_rq_pos(req)/GD_TO_BLK + GD_SESSION_OFFSET;
+		block_cnt = blk_rq_sectors(req)/GD_TO_BLK;
 		ctrl_outl(PHYSADDR(req->buffer), GDROM_DMA_STARTADDR_REG);
 		ctrl_outl(block_cnt * GDROM_HARD_SECTOR, GDROM_DMA_LENGTH_REG);
 		ctrl_outl(1, GDROM_DMA_DIRECTION_REG);
@@ -661,7 +661,7 @@ static void gdrom_request(struct request_queue *rq)
 			printk(" write request ignored\n");
 			__blk_end_request_cur(req, -EIO);
 		}
-		if (req->nr_sectors)
+		if (blk_rq_sectors(req))
 			gdrom_request_handler_dma(req);
 		else
 			__blk_end_request_cur(req, -EIO);
drivers/cdrom/viocd.c +1 -1
index cc3efa0..6e190a9 100644
@@ -282,7 +282,7 @@ static int send_request(struct request *req)
 			viopath_targetinst(viopath_hostLp),
 			(u64)req, VIOVERSION << 16,
 			((u64)DEVICE_NR(diskinfo) << 48) | dmaaddr,
-			(u64)req->sector * 512, len, 0);
+			(u64)blk_rq_pos(req) * 512, len, 0);
 	if (hvrc != HvLpEvent_Rc_Good) {
 		printk(VIOCD_KERN_WARNING "hv error on op %d\n", (int)hvrc);
 		return -1;
drivers/memstick/core/mspro_block.c +3 -3
index a416346..9e600d2 100644
@@ -677,10 +677,10 @@ try_again:
 			continue;
 		}
 
-		t_sec = msb->block_req->sector << 9;
+		t_sec = blk_rq_pos(msb->block_req) << 9;
 		sector_div(t_sec, msb->page_size);
 
-		count = msb->block_req->nr_sectors << 9;
+		count = blk_rq_sectors(msb->block_req) << 9;
 		count /= msb->page_size;
 
 		param.system = msb->system;
@@ -745,7 +745,7 @@ static int mspro_block_complete_req(struct memstick_dev *card, int error)
 					t_len *= msb->page_size;
 			}
 		} else
-			t_len = msb->block_req->nr_sectors << 9;
+			t_len = blk_rq_sectors(msb->block_req) << 9;
 
 		dev_dbg(&card->dev, "transferred %x (%d)\n", t_len, error);
 
drivers/message/i2o/i2o_block.c +11 -9
index 56e60f0..510eb47 100644
@@ -761,7 +761,7 @@ static int i2o_block_transfer(struct request *req)
 			break;
 
 		case CACHE_SMARTFETCH:
-			if (req->nr_sectors > 16)
+			if (blk_rq_sectors(req) > 16)
 				ctl_flags = 0x201F0008;
 			else
 				ctl_flags = 0x001F0000;
@@ -781,13 +781,13 @@ static int i2o_block_transfer(struct request *req)
 			ctl_flags = 0x001F0010;
 			break;
 		case CACHE_SMARTBACK:
-			if (req->nr_sectors > 16)
+			if (blk_rq_sectors(req) > 16)
 				ctl_flags = 0x001F0004;
 			else
 				ctl_flags = 0x001F0010;
 			break;
 		case CACHE_SMARTTHROUGH:
-			if (req->nr_sectors > 16)
+			if (blk_rq_sectors(req) > 16)
 				ctl_flags = 0x001F0004;
 			else
 				ctl_flags = 0x001F0010;
@@ -827,22 +827,24 @@ static int i2o_block_transfer(struct request *req)
 
 		*mptr++ = cpu_to_le32(scsi_flags);
 
-		*((u32 *) & cmd[2]) = cpu_to_be32(req->sector * hwsec);
-		*((u16 *) & cmd[7]) = cpu_to_be16(req->nr_sectors * hwsec);
+		*((u32 *) & cmd[2]) = cpu_to_be32(blk_rq_pos(req) * hwsec);
+		*((u16 *) & cmd[7]) = cpu_to_be16(blk_rq_sectors(req) * hwsec);
 
 		memcpy(mptr, cmd, 10);
 		mptr += 4;
-		*mptr++ = cpu_to_le32(req->nr_sectors << KERNEL_SECTOR_SHIFT);
+		*mptr++ =
+		    cpu_to_le32(blk_rq_sectors(req) << KERNEL_SECTOR_SHIFT);
 	} else
 #endif
 	{
 		msg->u.head[1] = cpu_to_le32(cmd | HOST_TID << 12 | tid);
 		*mptr++ = cpu_to_le32(ctl_flags);
-		*mptr++ = cpu_to_le32(req->nr_sectors << KERNEL_SECTOR_SHIFT);
 		*mptr++ =
-		    cpu_to_le32((u32) (req->sector << KERNEL_SECTOR_SHIFT));
+		    cpu_to_le32(blk_rq_sectors(req) << KERNEL_SECTOR_SHIFT);
+		*mptr++ =
+		    cpu_to_le32((u32) (blk_rq_pos(req) << KERNEL_SECTOR_SHIFT));
 		*mptr++ =
-		    cpu_to_le32(req->sector >> (32 - KERNEL_SECTOR_SHIFT));
+		    cpu_to_le32(blk_rq_pos(req) >> (32 - KERNEL_SECTOR_SHIFT));
 	}
 
 	if (!i2o_block_sglist_alloc(c, ireq, &mptr)) {
drivers/mmc/card/block.c +5 -5
index fe8041e..949e997 100644
@@ -243,7 +243,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
 		brq.mrq.cmd = &brq.cmd;
 		brq.mrq.data = &brq.data;
 
-		brq.cmd.arg = req->sector;
+		brq.cmd.arg = blk_rq_pos(req);
 		if (!mmc_card_blockaddr(card))
 			brq.cmd.arg <<= 9;
 		brq.cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
@@ -251,7 +251,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
 		brq.stop.opcode = MMC_STOP_TRANSMISSION;
 		brq.stop.arg = 0;
 		brq.stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
-		brq.data.blocks = req->nr_sectors;
+		brq.data.blocks = blk_rq_sectors(req);
 
 		/*
 		 * After a read error, we redo the request one sector at a time
@@ -293,7 +293,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
 		 * Adjust the sg list so it is the same size as the
 		 * request.
 		 */
-		if (brq.data.blocks != req->nr_sectors) {
+		if (brq.data.blocks != blk_rq_sectors(req)) {
 			int i, data_size = brq.data.blocks << 9;
 			struct scatterlist *sg;
 
@@ -344,8 +344,8 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
 			printk(KERN_ERR "%s: error %d transferring data,"
 			       " sector %u, nr %u, card status %#x\n",
 			       req->rq_disk->disk_name, brq.data.error,
-			       (unsigned)req->sector,
-			       (unsigned)req->nr_sectors, status);
+			       (unsigned)blk_rq_pos(req),
+			       (unsigned)blk_rq_sectors(req), status);
 		}
 
 		if (brq.stop.error) {
drivers/mtd/mtd_blkdevs.c +4 -3
index 76c4c8d..4ea2e67 100644
@@ -47,8 +47,8 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
 	unsigned long block, nsect;
 	char *buf;
 
-	block = req->sector << 9 >> tr->blkshift;
-	nsect = req->current_nr_sectors << 9 >> tr->blkshift;
+	block = blk_rq_pos(req) << 9 >> tr->blkshift;
+	nsect = blk_rq_cur_sectors(req) << 9 >> tr->blkshift;
 
 	buf = req->buffer;
 
@@ -59,7 +59,8 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
 	if (!blk_fs_request(req))
 		return -EIO;
 
-	if (req->sector + req->current_nr_sectors > get_capacity(req->rq_disk))
+	if (blk_rq_pos(req) + blk_rq_cur_sectors(req) >
+	    get_capacity(req->rq_disk))
 		return -EIO;
 
 	switch(rq_data_dir(req)) {
drivers/s390/block/dasd.c +1 -1
index fabec95..7df03c7 100644
@@ -603,7 +603,7 @@ static void dasd_profile_end(struct dasd_block *block,
 	if (dasd_profile_level != DASD_PROFILE_ON)
 		return;
 
-	sectors = req->nr_sectors;
+	sectors = blk_rq_sectors(req);
 	if (!cqr->buildclk || !cqr->startclk ||
 	    !cqr->stopclk || !cqr->endclk ||
 	    !sectors)
drivers/s390/block/dasd_diag.c +3 -2
index b9a7f77..2efaddf 100644
@@ -505,8 +505,9 @@ static struct dasd_ccw_req *dasd_diag_build_cp(struct dasd_device *memdev,
 		return ERR_PTR(-EINVAL);
 	blksize = block->bp_block;
 	/* Calculate record id of first and last block. */
-	first_rec = req->sector >> block->s2b_shift;
-	last_rec = (req->sector + req->nr_sectors - 1) >> block->s2b_shift;
+	first_rec = blk_rq_pos(req) >> block->s2b_shift;
+	last_rec =
+		(blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
 	/* Check struct bio and count the number of blocks for the request. */
 	count = 0;
 	rq_for_each_segment(bv, req, iter) {
drivers/s390/block/dasd_eckd.c +3 -3
index cb52da0..a41c940 100644
@@ -2354,10 +2354,10 @@ static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
 	blksize = block->bp_block;
 	blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
 	/* Calculate record id of first and last block. */
-	first_rec = first_trk = req->sector >> block->s2b_shift;
+	first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
 	first_offs = sector_div(first_trk, blk_per_trk);
 	last_rec = last_trk =
-		(req->sector + req->nr_sectors - 1) >> block->s2b_shift;
+		(blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
 	last_offs = sector_div(last_trk, blk_per_trk);
 	cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
 
@@ -2420,7 +2420,7 @@ dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
 	private = (struct dasd_eckd_private *) cqr->block->base->private;
 	blksize = cqr->block->bp_block;
 	blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
-	recid = req->sector >> cqr->block->s2b_shift;
+	recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
 	ccw = cqr->cpaddr;
 	/* Skip over define extent & locate record. */
 	ccw++;
drivers/s390/block/dasd_fba.c +4 -3
index a3eb6fd..8912358 100644
@@ -270,8 +270,9 @@ static struct dasd_ccw_req *dasd_fba_build_cp(struct dasd_device * memdev,
 		return ERR_PTR(-EINVAL);
 	blksize = block->bp_block;
 	/* Calculate record id of first and last block. */
-	first_rec = req->sector >> block->s2b_shift;
-	last_rec = (req->sector + req->nr_sectors - 1) >> block->s2b_shift;
+	first_rec = blk_rq_pos(req) >> block->s2b_shift;
+	last_rec =
+		(blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
 	/* Check struct bio and count the number of blocks for the request. */
 	count = 0;
 	cidaw = 0;
@@ -309,7 +310,7 @@ static struct dasd_ccw_req *dasd_fba_build_cp(struct dasd_device * memdev,
 	ccw = cqr->cpaddr;
 	/* First ccw is define extent. */
 	define_extent(ccw++, cqr->data, rq_data_dir(req),
-		      block->bp_block, req->sector, req->nr_sectors);
+		      block->bp_block, blk_rq_pos(req), blk_rq_sectors(req));
 	/* Build locate_record + read/write ccws. */
 	idaws = (unsigned long *) (cqr->data + sizeof(struct DE_fba_data));
 	LO_data = (struct LO_fba_data *) (idaws + cidaw);
drivers/s390/char/tape_34xx.c +1 -1
index 5f8e8ef..2d00a38 100644
@@ -1134,7 +1134,7 @@ tape_34xx_bread(struct tape_device *device, struct request *req)
 	/* Setup ccws. */
 	request->op = TO_BLOCK;
 	start_block = (struct tape_34xx_block_id *) request->cpdata;
-	start_block->block = req->sector >> TAPEBLOCK_HSEC_S2B;
+	start_block->block = blk_rq_pos(req) >> TAPEBLOCK_HSEC_S2B;
 	DBF_EVENT(6, "start_block = %i\n", start_block->block);
 
 	ccw = request->cpaddr;
drivers/s390/char/tape_3590.c +1 -1
index 823b05b..c453b2f 100644
@@ -633,7 +633,7 @@ tape_3590_bread(struct tape_device *device, struct request *req)
 	struct req_iterator iter;
 
 	DBF_EVENT(6, "xBREDid:");
-	start_block = req->sector >> TAPEBLOCK_HSEC_S2B;
+	start_block = blk_rq_pos(req) >> TAPEBLOCK_HSEC_S2B;
 	DBF_EVENT(6, "start_block = %i\n", start_block);
 
 	rq_for_each_segment(bv, req, iter)
drivers/s390/char/tape_block.c +1 -1
index 86596d3..5d035e4 100644
@@ -87,7 +87,7 @@ __tapeblock_end_request(struct tape_request *ccw_req, void *data)
 	if (ccw_req->rc == 0)
 		/* Update position. */
 		device->blk_data.block_position =
-			(req->sector + req->nr_sectors) >> TAPEBLOCK_HSEC_S2B;
+		  (blk_rq_pos(req) + blk_rq_sectors(req)) >> TAPEBLOCK_HSEC_S2B;
 	else
 		/* We lost the position information due to an error. */
 		device->blk_data.block_position = -1;
drivers/sbus/char/jsflash.c +2 -2
index 0961788..2132c90 100644
@@ -188,8 +188,8 @@ static void jsfd_do_request(struct request_queue *q)
 
 	while ((req = elv_next_request(q)) != NULL) {
 		struct jsfd_part *jdp = req->rq_disk->private_data;
-		unsigned long offset = req->sector << 9;
-		size_t len = req->current_nr_sectors << 9;
+		unsigned long offset = blk_rq_pos(req) << 9;
+		size_t len = blk_rq_cur_sectors(req) << 9;
 
 		if ((offset + len) > jdp->dsize) {
 			__blk_end_request_cur(req, -EIO);
drivers/scsi/eata.c +12 -12
index be5099d..c7076ce 100644
@@ -1825,7 +1825,7 @@ static int eata2x_queuecommand(struct scsi_cmnd *SCpnt,
 	if (linked_comm && SCpnt->device->queue_depth > 2
 	    && TLDEV(SCpnt->device->type)) {
 		ha->cp_stat[i] = READY;
-		flush_dev(SCpnt->device, SCpnt->request->sector, ha, 0);
+		flush_dev(SCpnt->device, blk_rq_pos(SCpnt->request), ha, 0);
 		return 0;
 	}
 
@@ -2144,13 +2144,13 @@ static int reorder(struct hostdata *ha, unsigned long cursec,
 		if (!cpp->din)
 			input_only = 0;
 
-		if (SCpnt->request->sector < minsec)
-			minsec = SCpnt->request->sector;
-		if (SCpnt->request->sector > maxsec)
-			maxsec = SCpnt->request->sector;
+		if (blk_rq_pos(SCpnt->request) < minsec)
+			minsec = blk_rq_pos(SCpnt->request);
+		if (blk_rq_pos(SCpnt->request) > maxsec)
+			maxsec = blk_rq_pos(SCpnt->request);
 
-		sl[n] = SCpnt->request->sector;
-		ioseek += SCpnt->request->nr_sectors;
+		sl[n] = blk_rq_pos(SCpnt->request);
+		ioseek += blk_rq_sectors(SCpnt->request);
 
 		if (!n)
 			continue;
@@ -2190,7 +2190,7 @@ static int reorder(struct hostdata *ha, unsigned long cursec,
 			k = il[n];
 			cpp = &ha->cp[k];
 			SCpnt = cpp->SCpnt;
-			ll[n] = SCpnt->request->nr_sectors;
+			ll[n] = blk_rq_sectors(SCpnt->request);
 			pl[n] = SCpnt->serial_number;
 
 			if (!n)
@@ -2236,12 +2236,12 @@ static int reorder(struct hostdata *ha, unsigned long cursec,
 			cpp = &ha->cp[k];
 			SCpnt = cpp->SCpnt;
 			scmd_printk(KERN_INFO, SCpnt,
-			    "%s pid %ld mb %d fc %d nr %d sec %ld ns %ld"
+			    "%s pid %ld mb %d fc %d nr %d sec %ld ns %u"
 			     " cur %ld s:%c r:%c rev:%c in:%c ov:%c xd %d.\n",
 			     (ihdlr ? "ihdlr" : "qcomm"),
 			     SCpnt->serial_number, k, flushcount,
-			     n_ready, SCpnt->request->sector,
-			     SCpnt->request->nr_sectors, cursec, YESNO(s),
+			     n_ready, blk_rq_pos(SCpnt->request),
+			     blk_rq_sectors(SCpnt->request), cursec, YESNO(s),
 			     YESNO(r), YESNO(rev), YESNO(input_only),
 			     YESNO(overlap), cpp->din);
 		}
@@ -2408,7 +2408,7 @@ static irqreturn_t ihdlr(struct Scsi_Host *shost)
 
 	if (linked_comm && SCpnt->device->queue_depth > 2
 	    && TLDEV(SCpnt->device->type))
-		flush_dev(SCpnt->device, SCpnt->request->sector, ha, 1);
+		flush_dev(SCpnt->device, blk_rq_pos(SCpnt->request), ha, 1);
 
 	tstatus = status_byte(spp->target_status);
 
drivers/scsi/lpfc/lpfc_scsi.c +11 -11
index 36fd2e7..a8fab39 100644
@@ -1313,10 +1313,10 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd,
 	uint32_t bgstat = bgf->bgstat;
 	uint64_t failing_sector = 0;
 
-	printk(KERN_ERR "BG ERROR in cmd 0x%x lba 0x%llx blk cnt 0x%lx "
+	printk(KERN_ERR "BG ERROR in cmd 0x%x lba 0x%llx blk cnt 0x%x "
 			"bgstat=0x%x bghm=0x%x\n",
 			cmd->cmnd[0], (unsigned long long)scsi_get_lba(cmd),
-			cmd->request->nr_sectors, bgstat, bghm);
+			blk_rq_sectors(cmd->request), bgstat, bghm);
 
 	spin_lock(&_dump_buf_lock);
 	if (!_dump_buf_done) {
@@ -2375,15 +2375,15 @@ lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
 		if (cmnd->cmnd[0] == READ_10)
 			lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
 					"9035 BLKGRD: READ @ sector %llu, "
-					 "count %lu\n",
-					 (unsigned long long)scsi_get_lba(cmnd),
-					cmnd->request->nr_sectors);
+					"count %u\n",
+					(unsigned long long)scsi_get_lba(cmnd),
+					blk_rq_sectors(cmnd->request));
 		else if (cmnd->cmnd[0] == WRITE_10)
 			lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
 					"9036 BLKGRD: WRITE @ sector %llu, "
-					"count %lu cmd=%p\n",
+					"count %u cmd=%p\n",
 					(unsigned long long)scsi_get_lba(cmnd),
-					cmnd->request->nr_sectors,
+					blk_rq_sectors(cmnd->request),
 					cmnd);
 
 		err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
@@ -2403,15 +2403,15 @@ lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
 		if (cmnd->cmnd[0] == READ_10)
 			lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
 					 "9040 dbg: READ @ sector %llu, "
-					 "count %lu\n",
+					 "count %u\n",
 					 (unsigned long long)scsi_get_lba(cmnd),
-					 cmnd->request->nr_sectors);
+					 blk_rq_sectors(cmnd->request));
 		else if (cmnd->cmnd[0] == WRITE_10)
 			lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
 					 "9041 dbg: WRITE @ sector %llu, "
-					 "count %lu cmd=%p\n",
+					 "count %u cmd=%p\n",
 					 (unsigned long long)scsi_get_lba(cmnd),
-					 cmnd->request->nr_sectors, cmnd);
+					 blk_rq_sectors(cmnd->request), cmnd);
 		else
 			lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
 					 "9042 dbg: parser not implemented\n");
drivers/scsi/scsi_lib.c +3 -3
index 9ff0ca9..39b3acf 100644
@@ -787,9 +787,9 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
 	 * Next deal with any sectors which we were able to correctly
 	 * handle.
 	 */
-	SCSI_LOG_HLCOMPLETE(1, printk("%ld sectors total, "
+	SCSI_LOG_HLCOMPLETE(1, printk("%u sectors total, "
 				      "%d bytes done.\n",
-				      req->nr_sectors, good_bytes));
+				      blk_rq_sectors(req), good_bytes));
 
 	/*
 	 * Recovered errors need reporting, but they're always treated
@@ -968,7 +968,7 @@ static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb,
 	if (blk_pc_request(req))
 		sdb->length = req->data_len;
 	else
-		sdb->length = req->nr_sectors << 9;
+		sdb->length = blk_rq_sectors(req) << 9;
 	return BLKPREP_OK;
 }
 
drivers/scsi/sd.c +12 -12
index 3fcb64b..70c4dd9 100644
@@ -383,9 +383,9 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
 	struct scsi_device *sdp = q->queuedata;
 	struct gendisk *disk = rq->rq_disk;
 	struct scsi_disk *sdkp;
-	sector_t block = rq->sector;
+	sector_t block = blk_rq_pos(rq);
 	sector_t threshold;
-	unsigned int this_count = rq->nr_sectors;
+	unsigned int this_count = blk_rq_sectors(rq);
 	int ret, host_dif;
 
 	if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
@@ -412,10 +412,10 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
 					this_count));
 
 	if (!sdp || !scsi_device_online(sdp) ||
- 	    block + rq->nr_sectors > get_capacity(disk)) {
+	    block + blk_rq_sectors(rq) > get_capacity(disk)) {
 		SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt,
-						"Finishing %ld sectors\n",
-						rq->nr_sectors));
+						"Finishing %u sectors\n",
+						blk_rq_sectors(rq)));
 		SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt,
 						"Retry with 0x%p\n", SCpnt));
 		goto out;
@@ -462,7 +462,7 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
 	 * for this.
 	 */
 	if (sdp->sector_size == 1024) {
-		if ((block & 1) || (rq->nr_sectors & 1)) {
+		if ((block & 1) || (blk_rq_sectors(rq) & 1)) {
 			scmd_printk(KERN_ERR, SCpnt,
 				    "Bad block number requested\n");
 			goto out;
@@ -472,7 +472,7 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
 		}
 	}
 	if (sdp->sector_size == 2048) {
-		if ((block & 3) || (rq->nr_sectors & 3)) {
+		if ((block & 3) || (blk_rq_sectors(rq) & 3)) {
 			scmd_printk(KERN_ERR, SCpnt,
 				    "Bad block number requested\n");
 			goto out;
@@ -482,7 +482,7 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
 		}
 	}
 	if (sdp->sector_size == 4096) {
-		if ((block & 7) || (rq->nr_sectors & 7)) {
+		if ((block & 7) || (blk_rq_sectors(rq) & 7)) {
 			scmd_printk(KERN_ERR, SCpnt,
 				    "Bad block number requested\n");
 			goto out;
@@ -511,10 +511,10 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
 	}
 
 	SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt,
-					"%s %d/%ld 512 byte blocks.\n",
+					"%s %d/%u 512 byte blocks.\n",
 					(rq_data_dir(rq) == WRITE) ?
 					"writing" : "reading", this_count,
-					rq->nr_sectors));
+					blk_rq_sectors(rq)));
 
 	/* Set RDPROTECT/WRPROTECT if disk is formatted with DIF */
 	host_dif = scsi_host_dif_capable(sdp->host, sdkp->protection_type);
@@ -970,8 +970,8 @@ static struct block_device_operations sd_fops = {
 
 static unsigned int sd_completed_bytes(struct scsi_cmnd *scmd)
 {
-	u64 start_lba = scmd->request->sector;
-	u64 end_lba = scmd->request->sector + (scsi_bufflen(scmd) / 512);
+	u64 start_lba = blk_rq_pos(scmd->request);
+	u64 end_lba = blk_rq_pos(scmd->request) + (scsi_bufflen(scmd) / 512);
 	u64 bad_lba;
 	int info_valid;
 
drivers/scsi/sd_dif.c +1 -1
index 184dff4..82f14a9 100644
@@ -507,7 +507,7 @@ void sd_dif_complete(struct scsi_cmnd *scmd, unsigned int good_bytes)
 	sector_sz = scmd->device->sector_size;
 	sectors = good_bytes / sector_sz;
 
-	phys = scmd->request->sector & 0xffffffff;
+	phys = blk_rq_pos(scmd->request) & 0xffffffff;
 	if (sector_sz == 4096)
 		phys >>= 3;
 
drivers/scsi/sr.c +8 -7
index 0e1a0f2..fddba53 100644
@@ -292,7 +292,8 @@ static int sr_done(struct scsi_cmnd *SCpnt)
 			if (cd->device->sector_size == 2048)
 				error_sector <<= 2;
 			error_sector &= ~(block_sectors - 1);
-			good_bytes = (error_sector - SCpnt->request->sector) << 9;
+			good_bytes = (error_sector -
+				      blk_rq_pos(SCpnt->request)) << 9;
 			if (good_bytes < 0 || good_bytes >= this_count)
 				good_bytes = 0;
 			/*
@@ -349,8 +350,8 @@ static int sr_prep_fn(struct request_queue *q, struct request *rq)
 				cd->disk->disk_name, block));
 
 	if (!cd->device || !scsi_device_online(cd->device)) {
-		SCSI_LOG_HLQUEUE(2, printk("Finishing %ld sectors\n",
-					rq->nr_sectors));
+		SCSI_LOG_HLQUEUE(2, printk("Finishing %u sectors\n",
+					   blk_rq_sectors(rq)));
 		SCSI_LOG_HLQUEUE(2, printk("Retry with 0x%p\n", SCpnt));
 		goto out;
 	}
@@ -413,7 +414,7 @@ static int sr_prep_fn(struct request_queue *q, struct request *rq)
 	/*
 	 * request doesn't start on hw block boundary, add scatter pads
 	 */
-	if (((unsigned int)rq->sector % (s_size >> 9)) ||
+	if (((unsigned int)blk_rq_pos(rq) % (s_size >> 9)) ||
 	    (scsi_bufflen(SCpnt) % s_size)) {
 		scmd_printk(KERN_NOTICE, SCpnt, "unaligned transfer\n");
 		goto out;
@@ -422,14 +423,14 @@ static int sr_prep_fn(struct request_queue *q, struct request *rq)
 	this_count = (scsi_bufflen(SCpnt) >> 9) / (s_size >> 9);
 
 
-	SCSI_LOG_HLQUEUE(2, printk("%s : %s %d/%ld 512 byte blocks.\n",
+	SCSI_LOG_HLQUEUE(2, printk("%s : %s %d/%u 512 byte blocks.\n",
 				cd->cdi.name,
 				(rq_data_dir(rq) == WRITE) ?
 					"writing" : "reading",
-				this_count, rq->nr_sectors));
+				this_count, blk_rq_sectors(rq)));
 
 	SCpnt->cmnd[1] = 0;
-	block = (unsigned int)rq->sector / (s_size >> 9);
+	block = (unsigned int)blk_rq_pos(rq) / (s_size >> 9);
 
 	if (this_count > 0xffff) {
 		this_count = 0xffff;
drivers/scsi/u14-34f.c +12 -10
index 601e951..54023d4 100644
@@ -1306,7 +1306,7 @@ static int u14_34f_queuecommand(struct scsi_cmnd *SCpnt, void (*done)(struct scs
    if (linked_comm && SCpnt->device->queue_depth > 2
                                      && TLDEV(SCpnt->device->type)) {
       HD(j)->cp_stat[i] = READY;
-      flush_dev(SCpnt->device, SCpnt->request->sector, j, FALSE);
+      flush_dev(SCpnt->device, blk_rq_pos(SCpnt->request), j, FALSE);
       return 0;
       }
 
@@ -1610,11 +1610,13 @@ static int reorder(unsigned int j, unsigned long cursec,
 
       if (!(cpp->xdir == DTD_IN)) input_only = FALSE;
 
-      if (SCpnt->request->sector < minsec) minsec = SCpnt->request->sector;
-      if (SCpnt->request->sector > maxsec) maxsec = SCpnt->request->sector;
+      if (blk_rq_pos(SCpnt->request) < minsec)
+	 minsec = blk_rq_pos(SCpnt->request);
+      if (blk_rq_pos(SCpnt->request) > maxsec)
+	 maxsec = blk_rq_pos(SCpnt->request);
 
-      sl[n] = SCpnt->request->sector;
-      ioseek += SCpnt->request->nr_sectors;
+      sl[n] = blk_rq_pos(SCpnt->request);
+      ioseek += blk_rq_sectors(SCpnt->request);
 
       if (!n) continue;
 
@@ -1642,7 +1644,7 @@ static int reorder(unsigned int j, unsigned long cursec,
 
    if (!input_only) for (n = 0; n < n_ready; n++) {
       k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt;
-      ll[n] = SCpnt->request->nr_sectors; pl[n] = SCpnt->serial_number;
+      ll[n] = blk_rq_sectors(SCpnt->request); pl[n] = SCpnt->serial_number;
 
       if (!n) continue;
 
@@ -1666,12 +1668,12 @@ static int reorder(unsigned int j, unsigned long cursec,
    if (link_statistics && (overlap || !(flushcount % link_statistics)))
       for (n = 0; n < n_ready; n++) {
          k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt;
-         printk("%s %d.%d:%d pid %ld mb %d fc %d nr %d sec %ld ns %ld"\
+         printk("%s %d.%d:%d pid %ld mb %d fc %d nr %d sec %ld ns %u"\
                 " cur %ld s:%c r:%c rev:%c in:%c ov:%c xd %d.\n",
                 (ihdlr ? "ihdlr" : "qcomm"), SCpnt->channel, SCpnt->target,
                 SCpnt->lun, SCpnt->serial_number, k, flushcount, n_ready,
-                SCpnt->request->sector, SCpnt->request->nr_sectors, cursec,
-                YESNO(s), YESNO(r), YESNO(rev), YESNO(input_only),
+                blk_rq_pos(SCpnt->request), blk_rq_sectors(SCpnt->request),
+		cursec, YESNO(s), YESNO(r), YESNO(rev), YESNO(input_only),
                 YESNO(overlap), cpp->xdir);
          }
 #endif
@@ -1799,7 +1801,7 @@ static irqreturn_t ihdlr(unsigned int j)
 
    if (linked_comm && SCpnt->device->queue_depth > 2
                                      && TLDEV(SCpnt->device->type))
-      flush_dev(SCpnt->device, SCpnt->request->sector, j, TRUE);
+      flush_dev(SCpnt->device, blk_rq_pos(SCpnt->request), j, TRUE);
 
    tstatus = status_byte(spp->target_status);
 
include/scsi/scsi_cmnd.h +1 -1
index 43b50d3..3878d1d 100644
@@ -270,7 +270,7 @@ static inline unsigned char scsi_get_prot_type(struct scsi_cmnd *scmd)
 
 static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd)
 {
-	return scmd->request->sector;
+	return blk_rq_pos(scmd->request);
 }
 
 static inline unsigned scsi_prot_sg_count(struct scsi_cmnd *cmd)
Signature · 1 line
1.6.0.2
Tested-by Acked-by on v1 5/11
#41 lore raw

Re: [PATCH 05/11] block: convert to pos and nr_sectors accessors

Quoted 6 lines · Tejun Heo

With recent cleanups, there is no place where low level driver directly manipulates request fields. This means that the 'hard' request fields always equal the !hard fields. Convert all rq->sectors, nr_sectors and current_nr_sectors references to accessors.

Quoted 8 lines

[ Impact: use pos and nr_sectors accessors ]

I have re-tested this on the Dreamcast and it still works :)

author
#42 lore raw

Re: [PATCH 05/11] block: convert to pos and nr_sectors accessors

Quoted 16 lines · Adrian McMenamin
Quoted 6 lines · Tejun Heo

With recent cleanups, there is no place where low level driver directly manipulates request fields. This means that the 'hard' request fields always equal the !hard fields. Convert all rq->sectors, nr_sectors and current_nr_sectors references to accessors.

Quoted 8 lines

[ Impact: use pos and nr_sectors accessors ]

Quoted 4 lines

I have re-tested this on the Dreamcast and it still works :)

Thanks. Much appreciated.

Signature · 1 line
tejun
author
#43 lore raw

PATCH 6/11 ide: convert to rq pos and nr_sectors accessors

In reply to Tejun Heo

ide doesn't manipulate request fields anymore and thus all hard and their soft equivalents are always equal. Convert all references to accessors.

[ Impact: use pos and nr_sectors accessors ]

---
 drivers/ide/ide-cd.c       |    8 ++++----
 drivers/ide/ide-disk.c     |    8 ++++----
 drivers/ide/ide-dma.c      |    2 +-
 drivers/ide/ide-floppy.c   |    6 +++---
 drivers/ide/ide-io.c       |    4 ++--
 drivers/ide/ide-lib.c      |    2 +-
 drivers/ide/ide-tape.c     |    6 +++---
 drivers/ide/ide-taskfile.c |    2 +-
 drivers/ide/pdc202xx_old.c |    2 +-
 drivers/ide/tc86c001.c     |    2 +-
 drivers/ide/tx4939ide.c    |    2 +-
 11 files changed, 22 insertions(+), 22 deletions(-)
drivers/ide/ide-cd.c +4 -4
index 474b283..94a341b 100644
@@ -774,8 +774,8 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
 	}
 
 	/* fs requests *must* be hardware frame aligned */
-	if ((rq->nr_sectors & (sectors_per_frame - 1)) ||
-	    (rq->sector & (sectors_per_frame - 1)))
+	if ((blk_rq_sectors(rq) & (sectors_per_frame - 1)) ||
+	    (blk_rq_pos(rq) & (sectors_per_frame - 1)))
 		return ide_stopped;
 
 	/* use DMA, if possible */
@@ -867,8 +867,8 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
 	cmd.rq = rq;
 
 	if (blk_fs_request(rq) || rq->data_len) {
-		ide_init_sg_cmd(&cmd, blk_fs_request(rq) ? (rq->nr_sectors << 9)
-							 : rq->data_len);
+		ide_init_sg_cmd(&cmd, blk_fs_request(rq) ?
+				(blk_rq_sectors(rq) << 9) : rq->data_len);
 		ide_map_sg(drive, &cmd);
 	}
 
drivers/ide/ide-disk.c +4 -4
index c243880..ad18e14 100644
@@ -82,7 +82,7 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
 					sector_t block)
 {
 	ide_hwif_t *hwif	= drive->hwif;
-	u16 nsectors		= (u16)rq->nr_sectors;
+	u16 nsectors		= (u16)blk_rq_sectors(rq);
 	u8 lba48		= !!(drive->dev_flags & IDE_DFLAG_LBA48);
 	u8 dma			= !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
 	struct ide_cmd		cmd;
@@ -90,7 +90,7 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
 	ide_startstop_t		rc;
 
 	if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && lba48 && dma) {
-		if (block + rq->nr_sectors > 1ULL << 28)
+		if (block + blk_rq_sectors(rq) > 1ULL << 28)
 			dma = 0;
 		else
 			lba48 = 0;
@@ -195,9 +195,9 @@ static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
 
 	ledtrig_ide_activity();
 
-	pr_debug("%s: %sing: block=%llu, sectors=%lu, buffer=0x%08lx\n",
+	pr_debug("%s: %sing: block=%llu, sectors=%u, buffer=0x%08lx\n",
 		 drive->name, rq_data_dir(rq) == READ ? "read" : "writ",
-		 (unsigned long long)block, rq->nr_sectors,
+		 (unsigned long long)block, blk_rq_sectors(rq),
 		 (unsigned long)rq->buffer);
 
 	if (hwif->rw_disk)
drivers/ide/ide-dma.c +1 -1
index d9123ec..001f68f 100644
@@ -103,7 +103,7 @@ ide_startstop_t ide_dma_intr(ide_drive_t *drive)
 				ide_finish_cmd(drive, cmd, stat);
 			else
 				ide_complete_rq(drive, 0,
-						cmd->rq->nr_sectors << 9);
+						blk_rq_sectors(cmd->rq) << 9);
 			return ide_stopped;
 		}
 		printk(KERN_ERR "%s: %s: bad DMA status (0x%02x)\n",
drivers/ide/ide-floppy.c +3 -3
index 537b7c5..1c460bd 100644
@@ -194,7 +194,7 @@ static void idefloppy_create_rw_cmd(ide_drive_t *drive,
 {
 	struct ide_disk_obj *floppy = drive->driver_data;
 	int block = sector / floppy->bs_factor;
-	int blocks = rq->nr_sectors / floppy->bs_factor;
+	int blocks = blk_rq_sectors(rq) / floppy->bs_factor;
 	int cmd = rq_data_dir(rq);
 
 	ide_debug_log(IDE_DBG_FUNC, "block: %d, blocks: %d", block, blocks);
@@ -259,8 +259,8 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
 			goto out_end;
 	}
 	if (blk_fs_request(rq)) {
-		if (((long)rq->sector % floppy->bs_factor) ||
-		    (rq->nr_sectors % floppy->bs_factor)) {
+		if (((long)blk_rq_pos(rq) % floppy->bs_factor) ||
+		    (blk_rq_sectors(rq) % floppy->bs_factor)) {
 			printk(KERN_ERR PFX "%s: unsupported r/w rq size\n",
 				drive->name);
 			goto out_end;
drivers/ide/ide-io.c +2 -2
index df23bcb..59799ca 100644
@@ -279,7 +279,7 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
 
 	if (cmd) {
 		if (cmd->protocol == ATA_PROT_PIO) {
-			ide_init_sg_cmd(cmd, rq->nr_sectors << 9);
+			ide_init_sg_cmd(cmd, blk_rq_sectors(rq) << 9);
 			ide_map_sg(drive, cmd);
 		}
 
@@ -387,7 +387,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
 
 		drv = *(struct ide_driver **)rq->rq_disk->private_data;
 
-		return drv->do_request(drive, rq, rq->sector);
+		return drv->do_request(drive, rq, blk_rq_pos(rq));
 	}
 	return do_special(drive);
 kill_rq:
drivers/ide/ide-lib.c +1 -1
index 56ff8c4..05b7fbc 100644
@@ -114,7 +114,7 @@ static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
 
 		if (rq)
 			printk(KERN_CONT ", sector=%llu",
-			       (unsigned long long)rq->sector);
+			       (unsigned long long)blk_rq_pos(rq));
 	}
 	printk(KERN_CONT "\n");
 }
drivers/ide/ide-tape.c +3 -3
index 3813a0e..e166045 100644
@@ -586,7 +586,7 @@ static void ide_tape_create_rw_cmd(idetape_tape_t *tape,
 				   struct ide_atapi_pc *pc, struct request *rq,
 				   u8 opcode)
 {
-	unsigned int length = rq->nr_sectors;
+	unsigned int length = blk_rq_sectors(rq);
 
 	ide_init_pc(pc);
 	put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
@@ -617,8 +617,8 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
 	struct ide_cmd cmd;
 	u8 stat;
 
-	debug_log(DBG_SENSE, "sector: %llu, nr_sectors: %lu\n"
-		  (unsigned long long)rq->sector, rq->nr_sectors);
+	debug_log(DBG_SENSE, "sector: %llu, nr_sectors: %u\n"
+		  (unsigned long long)blk_rq_pos(rq), blk_rq_sectors(rq));
 
 	if (!(blk_special_request(rq) || blk_sense_request(rq))) {
 		/* We do not support buffer cache originated requests. */
drivers/ide/ide-taskfile.c +1 -1
index f400eb4..a0c3e1b 100644
@@ -385,7 +385,7 @@ out_end:
 	if ((cmd->tf_flags & IDE_TFLAG_FS) == 0)
 		ide_finish_cmd(drive, cmd, stat);
 	else
-		ide_complete_rq(drive, 0, cmd->rq->nr_sectors << 9);
+		ide_complete_rq(drive, 0, blk_rq_sectors(cmd->rq) << 9);
 	return ide_stopped;
 out_err:
 	ide_error_cmd(drive, cmd);
drivers/ide/pdc202xx_old.c +1 -1
index 248a54b..c2a16a8 100644
@@ -177,7 +177,7 @@ static void pdc202xx_dma_start(ide_drive_t *drive)
 		u8 clock = inb(high_16 + 0x11);
 
 		outb(clock | (hwif->channel ? 0x08 : 0x02), high_16 + 0x11);
-		word_count = (rq->nr_sectors << 8);
+		word_count = (blk_rq_sectors(rq) << 8);
 		word_count = (rq_data_dir(rq) == READ) ?
 					word_count | 0x05000000 :
 					word_count | 0x06000000;
drivers/ide/tc86c001.c +1 -1
index b4cf42d..05a93d6 100644
@@ -112,7 +112,7 @@ static void tc86c001_dma_start(ide_drive_t *drive)
 	ide_hwif_t *hwif	= drive->hwif;
 	unsigned long sc_base	= hwif->config_data;
 	unsigned long twcr_port	= sc_base + (drive->dn ? 0x06 : 0x04);
-	unsigned long nsectors	= hwif->rq->nr_sectors;
+	unsigned long nsectors	= blk_rq_sectors(hwif->rq);
 
 	/*
 	 * We have to manually load the sector count and size into
drivers/ide/tx4939ide.c +1 -1
index 564422d..5ca7622 100644
@@ -307,7 +307,7 @@ static int tx4939ide_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
 	tx4939ide_writew(SECTOR_SIZE / 2, base, drive->dn ?
 			 TX4939IDE_Xfer_Cnt_2 : TX4939IDE_Xfer_Cnt_1);
 
-	tx4939ide_writew(cmd->rq->nr_sectors, base, TX4939IDE_Sec_Cnt);
+	tx4939ide_writew(blk_rq_sectors(cmd->rq), base, TX4939IDE_Sec_Cnt);
 
 	return 0;
 }
Signature · 1 line
1.6.0.2
author
#44 lore raw

PATCH 7/11 block: drop request->hard_* and *nr_sectors

In reply to Tejun Heo

struct request has had a few different ways to represent some properties of a request. ->hard_* represent block layer's view of the request progress (completion cursor) and the ones without the prefix are supposed to represent the issue cursor and allowed to be updated as necessary by the low level drivers. The thing is that as block layer supports partial completion, the two cursors really aren't necessary and only cause confusion. In addition, manual management of request detail from low level drivers is cumbersome and error-prone at the very least.

Another interesting duplicate fields are rq->[hard_]nr_sectors and rq->{hard_cur|current}_nr_sectors against rq->data_len and rq->bio->bi_size. This is more convoluted than the hard_ case.

rq->[hard_]nr_sectors are initialized for requests with bio but blk_rq_bytes() uses it only for !pc requests. rq->data_len is initialized for all request but blk_rq_bytes() uses it only for pc requests. This causes good amount of confusion throughout block layer and its drivers and determining the request length has been a bit of black magic which may or may not work depending on circumstances and what the specific LLD is actually doing.

rq->{hard_cur|current}_nr_sectors represent the number of sectors in the contiguous data area at the front. This is mainly used by drivers which transfers data by walking request segment-by-segment. This value always equals rq->bio->bi_size >> 9. However, data length for pc requests may not be multiple of 512 bytes and using this field becomes a bit confusing.

In general, having multiple fields to represent the same property leads only to confusion and subtle bugs. With recent block low level driver cleanups, no driver is accessing or manipulating these duplicate fields directly. Drop all the duplicates. Now rq->sector means the current sector, rq->data_len the current total length and rq->bio->bi_size the current segment length. Everything else is defined in terms of these three and available only through accessors.

* blk_recalc_rq_sectors() is collapsed into blk_update_request() and now handles pc and fs requests equally other than rq->sector update. This means that now pc requests can use partial completion too (no in-kernel user yet tho).

* bio_cur_sectors() is replaced with bio_cur_bytes() as block layer now uses byte count as the primary data length.

* blk_rq_pos() is now guranteed to be always correct. In-block users converted.

* blk_rq_bytes() is now guaranteed to be always valid as is blk_rq_sectors(). In-block users converted.

* blk_rq_sectors() is now guaranteed to equal blk_rq_bytes() >> 9. More convenient one is used.

* blk_rq_bytes() and blk_rq_cur_bytes() are now inlined and take const pointer to request.

[ Impact: API cleanup, single way to represent one property of a request ]

Cc Boaz Harrosh <[email protected]>
---
 block/blk-core.c         |   81 +++++++++++++++++-----------------------------
 block/blk-merge.c        |   36 ++------------------
 block/blk.h              |    1 -
 block/cfq-iosched.c      |   10 +++---
 include/linux/bio.h      |    6 ++--
 include/linux/blkdev.h   |   37 +++++++++------------
 include/linux/elevator.h |    2 +-
 kernel/trace/blktrace.c  |   16 ++++----
 8 files changed, 67 insertions(+), 122 deletions(-)
block/blk-core.c +30 -51
index 82dc206..3596ca7 100644
@@ -127,7 +127,7 @@ void blk_rq_init(struct request_queue *q, struct request *rq)
 	INIT_LIST_HEAD(&rq->timeout_list);
 	rq->cpu = -1;
 	rq->q = q;
-	rq->sector = rq->hard_sector = (sector_t) -1;
+	rq->sector = (sector_t) -1;
 	INIT_HLIST_NODE(&rq->hash);
 	RB_CLEAR_NODE(&rq->rb_node);
 	rq->cmd = rq->__cmd;
@@ -189,8 +189,7 @@ void blk_dump_rq_flags(struct request *rq, char *msg)
 	       (unsigned long long)blk_rq_pos(rq),
 	       blk_rq_sectors(rq), blk_rq_cur_sectors(rq));
 	printk(KERN_INFO "  bio %p, biotail %p, buffer %p, len %u\n",
-						rq->bio, rq->biotail,
-						rq->buffer, rq->data_len);
+	       rq->bio, rq->biotail, rq->buffer, blk_rq_bytes(rq));
 
 	if (blk_pc_request(rq)) {
 		printk(KERN_INFO "  cdb: ");
@@ -1096,7 +1095,7 @@ void init_request_from_bio(struct request *req, struct bio *bio)
 		req->cmd_flags |= REQ_NOIDLE;
 
 	req->errors = 0;
-	req->hard_sector = req->sector = bio->bi_sector;
+	req->sector = bio->bi_sector;
 	req->ioprio = bio_prio(bio);
 	blk_rq_bio_prep(req->q, req, bio);
 }
@@ -1113,14 +1112,13 @@ static inline bool queue_should_plug(struct request_queue *q)
 static int __make_request(struct request_queue *q, struct bio *bio)
 {
 	struct request *req;
-	int el_ret, nr_sectors;
+	int el_ret;
+	unsigned int bytes = bio->bi_size;
 	const unsigned short prio = bio_prio(bio);
 	const int sync = bio_sync(bio);
 	const int unplug = bio_unplug(bio);
 	int rw_flags;
 
-	nr_sectors = bio_sectors(bio);
-
 	/*
 	 * low level driver can indicate that it wants pages above a
 	 * certain limit bounced to low memory (ie for highmem, or even
@@ -1145,7 +1143,7 @@ static int __make_request(struct request_queue *q, struct bio *bio)
 
 		req->biotail->bi_next = bio;
 		req->biotail = bio;
-		req->nr_sectors = req->hard_nr_sectors += nr_sectors;
+		req->data_len += bytes;
 		req->ioprio = ioprio_best(req->ioprio, prio);
 		if (!blk_rq_cpu_valid(req))
 			req->cpu = bio->bi_comp_cpu;
@@ -1171,10 +1169,8 @@ static int __make_request(struct request_queue *q, struct bio *bio)
 		 * not touch req->buffer either...
 		 */
 		req->buffer = bio_data(bio);
-		req->current_nr_sectors = bio_cur_sectors(bio);
-		req->hard_cur_sectors = req->current_nr_sectors;
-		req->sector = req->hard_sector = bio->bi_sector;
-		req->nr_sectors = req->hard_nr_sectors += nr_sectors;
+		req->sector = bio->bi_sector;
+		req->data_len += bytes;
 		req->ioprio = ioprio_best(req->ioprio, prio);
 		if (!blk_rq_cpu_valid(req))
 			req->cpu = bio->bi_comp_cpu;
@@ -1557,7 +1553,7 @@ EXPORT_SYMBOL(submit_bio);
 int blk_rq_check_limits(struct request_queue *q, struct request *rq)
 {
 	if (blk_rq_sectors(rq) > q->max_sectors ||
-	    rq->data_len > q->max_hw_sectors << 9) {
+	    blk_rq_bytes(rq) > q->max_hw_sectors << 9) {
 		printk(KERN_ERR "%s: over max size limit.\n", __func__);
 		return -EIO;
 	}
@@ -1675,35 +1671,6 @@ static void blk_account_io_done(struct request *req)
 	}
 }
 
-/**
- * blk_rq_bytes - Returns bytes left to complete in the entire request
- * @rq: the request being processed
- **/
-unsigned int blk_rq_bytes(struct request *rq)
-{
-	if (blk_fs_request(rq))
-		return blk_rq_sectors(rq) << 9;
-
-	return rq->data_len;
-}
-EXPORT_SYMBOL_GPL(blk_rq_bytes);
-
-/**
- * blk_rq_cur_bytes - Returns bytes left to complete in the current segment
- * @rq: the request being processed
- **/
-unsigned int blk_rq_cur_bytes(struct request *rq)
-{
-	if (blk_fs_request(rq))
-		return rq->current_nr_sectors << 9;
-
-	if (rq->bio)
-		return rq->bio->bi_size;
-
-	return rq->data_len;
-}
-EXPORT_SYMBOL_GPL(blk_rq_cur_bytes);
-
 struct request *elv_next_request(struct request_queue *q)
 {
 	struct request *rq;
@@ -1736,7 +1703,7 @@ struct request *elv_next_request(struct request_queue *q)
 		if (rq->cmd_flags & REQ_DONTPREP)
 			break;
 
-		if (q->dma_drain_size && rq->data_len) {
+		if (q->dma_drain_size && blk_rq_bytes(rq)) {
 			/*
 			 * make sure space for the drain appears we
 			 * know we can do this because max_hw_segments
@@ -1759,7 +1726,7 @@ struct request *elv_next_request(struct request_queue *q)
 			 * avoid resource deadlock.  REQ_STARTED will
 			 * prevent other fs requests from passing this one.
 			 */
-			if (q->dma_drain_size && rq->data_len &&
+			if (q->dma_drain_size && blk_rq_bytes(rq) &&
 			    !(rq->cmd_flags & REQ_DONTPREP)) {
 				/*
 				 * remove the space for the drain we added
@@ -1911,8 +1878,7 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
 		 * can find how many bytes remain in the request
 		 * later.
 		 */
-		req->nr_sectors = req->hard_nr_sectors = 0;
-		req->current_nr_sectors = req->hard_cur_sectors = 0;
+		req->data_len = 0;
 		return false;
 	}
 
@@ -1926,8 +1892,25 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
 		bio_iovec(bio)->bv_len -= nr_bytes;
 	}
 
-	blk_recalc_rq_sectors(req, total_bytes >> 9);
+	req->data_len -= total_bytes;
+	req->buffer = bio_data(req->bio);
+
+	/* update sector only for requests with clear definition of sector */
+	if (blk_fs_request(req) || blk_discard_rq(req))
+		req->sector += total_bytes >> 9;
+
+	/*
+	 * If total number of sectors is less than the first segment
+	 * size, something has gone terribly wrong.
+	 */
+	if (blk_rq_bytes(req) < blk_rq_cur_bytes(req)) {
+		printk(KERN_ERR "blk: request botched\n");
+		req->data_len = blk_rq_cur_bytes(req);
+	}
+
+	/* recalculate the number of segments */
 	blk_recalc_rq_segments(req);
+
 	return true;
 }
 EXPORT_SYMBOL_GPL(blk_update_request);
@@ -2049,11 +2032,7 @@ void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
 		rq->nr_phys_segments = bio_phys_segments(q, bio);
 		rq->buffer = bio_data(bio);
 	}
-	rq->current_nr_sectors = bio_cur_sectors(bio);
-	rq->hard_cur_sectors = rq->current_nr_sectors;
-	rq->hard_nr_sectors = rq->nr_sectors = bio_sectors(bio);
 	rq->data_len = bio->bi_size;
-
 	rq->bio = rq->biotail = bio;
 
 	if (bio->bi_bdev)
block/blk-merge.c +4 -32
index bf62a87..b8df66a 100644
@@ -9,35 +9,6 @@
 
 #include "blk.h"
 
-void blk_recalc_rq_sectors(struct request *rq, int nsect)
-{
-	if (blk_fs_request(rq) || blk_discard_rq(rq)) {
-		rq->hard_sector += nsect;
-		rq->hard_nr_sectors -= nsect;
-
-		/*
-		 * Move the I/O submission pointers ahead if required.
-		 */
-		if ((rq->nr_sectors >= rq->hard_nr_sectors) &&
-		    (rq->sector <= rq->hard_sector)) {
-			rq->sector = rq->hard_sector;
-			rq->nr_sectors = rq->hard_nr_sectors;
-			rq->hard_cur_sectors = bio_cur_sectors(rq->bio);
-			rq->current_nr_sectors = rq->hard_cur_sectors;
-			rq->buffer = bio_data(rq->bio);
-		}
-
-		/*
-		 * if total number of sectors is less than the first segment
-		 * size, something has gone terribly wrong
-		 */
-		if (rq->nr_sectors < rq->current_nr_sectors) {
-			printk(KERN_ERR "blk: request botched\n");
-			rq->nr_sectors = rq->current_nr_sectors;
-		}
-	}
-}
-
 static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
 					     struct bio *bio)
 {
@@ -199,8 +170,9 @@ new_segment:
 
 
 	if (unlikely(rq->cmd_flags & REQ_COPY_USER) &&
-	    (rq->data_len & q->dma_pad_mask)) {
-		unsigned int pad_len = (q->dma_pad_mask & ~rq->data_len) + 1;
+	    (blk_rq_bytes(rq) & q->dma_pad_mask)) {
+		unsigned int pad_len =
+			(q->dma_pad_mask & ~blk_rq_bytes(rq)) + 1;
 
 		sg->length += pad_len;
 		rq->extra_len += pad_len;
@@ -398,7 +370,7 @@ static int attempt_merge(struct request_queue *q, struct request *req,
 	req->biotail->bi_next = next->bio;
 	req->biotail = next->biotail;
 
-	req->nr_sectors = req->hard_nr_sectors += next->hard_nr_sectors;
+	req->data_len += blk_rq_bytes(next);
 
 	elv_merge_requests(q, req, next);
 
block/blk.h +0 -1
index 5111559..ab54529 100644
@@ -101,7 +101,6 @@ int ll_front_merge_fn(struct request_queue *q, struct request *req,
 int attempt_back_merge(struct request_queue *q, struct request *rq);
 int attempt_front_merge(struct request_queue *q, struct request *rq);
 void blk_recalc_rq_segments(struct request *rq);
-void blk_recalc_rq_sectors(struct request *rq, int nsect);
 
 void blk_queue_congestion_threshold(struct request_queue *q);
 
block/cfq-iosched.c +5 -5
index db4d990..99ac430 100644
@@ -579,9 +579,9 @@ cfq_prio_tree_lookup(struct cfq_data *cfqd, struct rb_root *root,
 		 * Sort strictly based on sector.  Smallest to the left,
 		 * largest to the right.
 		 */
-		if (sector > cfqq->next_rq->sector)
+		if (sector > blk_rq_pos(cfqq->next_rq))
 			n = &(*p)->rb_right;
-		else if (sector < cfqq->next_rq->sector)
+		else if (sector < blk_rq_pos(cfqq->next_rq))
 			n = &(*p)->rb_left;
 		else
 			break;
@@ -611,8 +611,8 @@ static void cfq_prio_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq)
 		return;
 
 	cfqq->p_root = &cfqd->prio_trees[cfqq->org_ioprio];
-	__cfqq = cfq_prio_tree_lookup(cfqd, cfqq->p_root, cfqq->next_rq->sector,
-					 &parent, &p);
+	__cfqq = cfq_prio_tree_lookup(cfqd, cfqq->p_root,
+				      blk_rq_pos(cfqq->next_rq), &parent, &p);
 	if (!__cfqq) {
 		rb_link_node(&cfqq->p_node, parent, p);
 		rb_insert_color(&cfqq->p_node, cfqq->p_root);
@@ -996,7 +996,7 @@ static struct cfq_queue *cfqq_close(struct cfq_data *cfqd,
 	if (cfq_rq_close(cfqd, __cfqq->next_rq))
 		return __cfqq;
 
-	if (__cfqq->next_rq->sector < sector)
+	if (blk_rq_pos(__cfqq->next_rq) < sector)
 		node = rb_next(&__cfqq->p_node);
 	else
 		node = rb_prev(&__cfqq->p_node);
include/linux/bio.h +3 -3
index f37ca8c..d30ec6f 100644
@@ -218,12 +218,12 @@ struct bio {
 #define bio_sectors(bio)	((bio)->bi_size >> 9)
 #define bio_empty_barrier(bio)	(bio_barrier(bio) && !bio_has_data(bio) && !bio_discard(bio))
 
-static inline unsigned int bio_cur_sectors(struct bio *bio)
+static inline unsigned int bio_cur_bytes(struct bio *bio)
 {
 	if (bio->bi_vcnt)
-		return bio_iovec(bio)->bv_len >> 9;
+		return bio_iovec(bio)->bv_len;
 	else /* dataless requests such as discard */
-		return bio->bi_size >> 9;
+		return bio->bi_size;
 }
 
 static inline void *bio_data(struct bio *bio)
include/linux/blkdev.h +16 -21
index b921d91..723d22e 100644
@@ -166,19 +166,8 @@ struct request {
 	enum rq_cmd_type_bits cmd_type;
 	unsigned long atomic_flags;
 
-	/* Maintain bio traversal state for part by part I/O submission.
-	 * hard_* are block layer internals, no driver should touch them!
-	 */
-
-	sector_t sector;		/* next sector to submit */
-	sector_t hard_sector;		/* next sector to complete */
-	unsigned long nr_sectors;	/* no. of sectors left to submit */
-	unsigned long hard_nr_sectors;	/* no. of sectors left to complete */
-	/* no. of sectors left to submit in the current segment */
-	unsigned int current_nr_sectors;
-
-	/* no. of sectors left to complete in the current segment */
-	unsigned int hard_cur_sectors;
+	sector_t sector;	/* sector cursor */
+	unsigned int data_len;	/* total data len, don't access directly */
 
 	struct bio *bio;
 	struct bio *biotail;
@@ -226,7 +215,6 @@ struct request {
 	unsigned char __cmd[BLK_MAX_CDB];
 	unsigned char *cmd;
 
-	unsigned int data_len;
 	unsigned int extra_len;	/* length of alignment and padding */
 	unsigned int sense_len;
 	unsigned int resid_len;	/* residual count */
@@ -841,20 +829,27 @@ extern void blkdev_dequeue_request(struct request *req);
  */
 static inline sector_t blk_rq_pos(const struct request *rq)
 {
-	return rq->hard_sector;
+	return rq->sector;
+}
+
+static inline unsigned int blk_rq_bytes(const struct request *rq)
+{
+	return rq->data_len;
 }
 
-extern unsigned int blk_rq_bytes(struct request *rq);
-extern unsigned int blk_rq_cur_bytes(struct request *rq);
+static inline int blk_rq_cur_bytes(const struct request *rq)
+{
+	return rq->bio ? bio_cur_bytes(rq->bio) : 0;
+}
 
 static inline unsigned int blk_rq_sectors(const struct request *rq)
 {
-	return rq->hard_nr_sectors;
+	return blk_rq_bytes(rq) >> 9;
 }
 
 static inline unsigned int blk_rq_cur_sectors(const struct request *rq)
 {
-	return rq->hard_cur_sectors;
+	return blk_rq_cur_bytes(rq) >> 9;
 }
 
 /*
@@ -929,7 +924,7 @@ static inline void blk_end_request_all(struct request *rq, int error)
  */
 static inline bool blk_end_request_cur(struct request *rq, int error)
 {
-	return blk_end_request(rq, error, rq->hard_cur_sectors << 9);
+	return blk_end_request(rq, error, blk_rq_cur_bytes(rq));
 }
 
 /**
@@ -982,7 +977,7 @@ static inline void __blk_end_request_all(struct request *rq, int error)
  */
 static inline bool __blk_end_request_cur(struct request *rq, int error)
 {
-	return __blk_end_request(rq, error, rq->hard_cur_sectors << 9);
+	return __blk_end_request(rq, error, blk_rq_cur_bytes(rq));
 }
 
 extern void blk_complete_request(struct request *);
include/linux/elevator.h +1 -1
index c59b769..4e46287 100644
@@ -171,7 +171,7 @@ enum {
 	ELV_MQUEUE_MUST,
 };
 
-#define rq_end_sector(rq)	((rq)->sector + (rq)->nr_sectors)
+#define rq_end_sector(rq)	(blk_rq_pos(rq) + blk_rq_sectors(rq))
 #define rb_entry_rq(node)	rb_entry((node), struct request, rb_node)
 
 /*
kernel/trace/blktrace.c +8 -8
index 42f1c11..5708a14 100644
@@ -642,12 +642,12 @@ static void blk_add_trace_rq(struct request_queue *q, struct request *rq,
 
 	if (blk_pc_request(rq)) {
 		what |= BLK_TC_ACT(BLK_TC_PC);
-		__blk_add_trace(bt, 0, rq->data_len, rw, what, rq->errors,
-				rq->cmd_len, rq->cmd);
+		__blk_add_trace(bt, 0, blk_rq_bytes(rq), rw,
+				what, rq->errors, rq->cmd_len, rq->cmd);
 	} else  {
 		what |= BLK_TC_ACT(BLK_TC_FS);
-		__blk_add_trace(bt, blk_rq_pos(rq), blk_rq_sectors(rq) << 9,
-				rw, what, rq->errors, 0, NULL);
+		__blk_add_trace(bt, blk_rq_pos(rq), blk_rq_bytes(rq), rw,
+				what, rq->errors, 0, NULL);
 	}
 }
 
@@ -854,11 +854,11 @@ void blk_add_driver_data(struct request_queue *q,
 		return;
 
 	if (blk_pc_request(rq))
-		__blk_add_trace(bt, 0, rq->data_len, 0, BLK_TA_DRV_DATA,
-				rq->errors, len, data);
+		__blk_add_trace(bt, 0, blk_rq_bytes(rq), 0,
+				BLK_TA_DRV_DATA, rq->errors, len, data);
 	else
-		__blk_add_trace(bt, blk_rq_pos(rq), blk_rq_sectors(rq) << 9,
-				0, BLK_TA_DRV_DATA, rq->errors, len, data);
+		__blk_add_trace(bt, blk_rq_pos(rq), blk_rq_bytes(rq), 0,
+				BLK_TA_DRV_DATA, rq->errors, len, data);
 }
 EXPORT_SYMBOL_GPL(blk_add_driver_data);
 
Signature · 1 line
1.6.0.2
author
#45 lore raw

PATCH 8/11 block: cleanup rq->data_len usages

In reply to Tejun Heo

With recent unification of fields, it's now guaranteed that rq->data_len always equals blk_rq_bytes(). Convert all non-IDE direct users to accessors. IDE will be converted in a separate patch.

Boaz: spotted incorrect data_len/resid_len conversion in osd.

[ Impact: convert direct rq->data_len usages to blk_rq_bytes() ]

Cc Pete Zaitcev <[email protected]>
Cc Eric Moore <[email protected]>
Cc Markus Lidel <[email protected]>
Cc Darrick J. Wong <[email protected]>
Cc James Bottomley <[email protected]>
Cc Eric Moore <[email protected]>
Cc Boaz Harrosh <[email protected]>
Cc FUJITA Tomonori <[email protected]>
---
 drivers/ata/libata-scsi.c                |    2 +-
 drivers/block/ub.c                       |    8 ++++----
 drivers/message/fusion/mptsas.c          |   20 ++++++++++----------
 drivers/message/i2o/i2o_block.c          |    2 +-
 drivers/scsi/libsas/sas_expander.c       |    8 ++++----
 drivers/scsi/libsas/sas_host_smp.c       |   18 +++++++++---------
 drivers/scsi/mpt2sas/mpt2sas_transport.c |   21 +++++++++++----------
 drivers/scsi/osd/osd_initiator.c         |    4 ++--
 drivers/scsi/scsi_lib.c                  |   13 ++++++-------
 drivers/scsi/scsi_tgt_lib.c              |    2 +-
 10 files changed, 49 insertions(+), 49 deletions(-)
drivers/ata/libata-scsi.c +1 -1
index 2733b0c..6e4c600 100644
@@ -1084,7 +1084,7 @@ static int atapi_drain_needed(struct request *rq)
 	if (likely(!blk_pc_request(rq)))
 		return 0;
 
-	if (!rq->data_len || (rq->cmd_flags & REQ_RW))
+	if (!blk_rq_bytes(rq) || (rq->cmd_flags & REQ_RW))
 		return 0;
 
 	return atapi_cmd_type(rq->cmd[0]) == ATAPI_MISC;
drivers/block/ub.c +4 -4
index dc3b899..1591f61 100644
@@ -747,7 +747,7 @@ static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun,
 {
 	struct request *rq = urq->rq;
 
-	if (rq->data_len == 0) {
+	if (blk_rq_bytes(rq) == 0) {
 		cmd->dir = UB_DIR_NONE;
 	} else {
 		if (rq_data_dir(rq) == WRITE)
@@ -762,7 +762,7 @@ static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun,
 	memcpy(&cmd->cdb, rq->cmd, rq->cmd_len);
 	cmd->cdb_len = rq->cmd_len;
 
-	cmd->len = rq->data_len;
+	cmd->len = blk_rq_bytes(rq);
 
 	/*
 	 * To reapply this to every URB is not as incorrect as it looks.
@@ -783,8 +783,8 @@ static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
 
 	if (cmd->error == 0) {
 		if (blk_pc_request(rq)) {
-			if (cmd->act_len < rq->data_len)
-				rq->resid_len = rq->data_len - cmd->act_len;
+			if (cmd->act_len < blk_rq_bytes(rq))
+				rq->resid_len = blk_rq_bytes(rq) - cmd->act_len;
 			scsi_status = 0;
 		} else {
 			if (cmd->act_len != cmd->len) {
drivers/message/fusion/mptsas.c +10 -10
index 5d5f347..4e6fcf0 100644
@@ -1277,8 +1277,8 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 	/* do we need to support multiple segments? */
 	if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
 		printk(MYIOC_s_ERR_FMT "%s: multiple segments req %u %u, rsp %u %u\n",
-		    ioc->name, __func__, req->bio->bi_vcnt, req->data_len,
-		    rsp->bio->bi_vcnt, rsp->data_len);
+		    ioc->name, __func__, req->bio->bi_vcnt, blk_rq_bytes(req),
+		    rsp->bio->bi_vcnt, blk_rq_bytes(rsp));
 		return -EINVAL;
 	}
 
@@ -1295,7 +1295,7 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 	smpreq = (SmpPassthroughRequest_t *)mf;
 	memset(smpreq, 0, sizeof(*smpreq));
 
-	smpreq->RequestDataLength = cpu_to_le16(req->data_len - 4);
+	smpreq->RequestDataLength = cpu_to_le16(blk_rq_bytes(req) - 4);
 	smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
 
 	if (rphy)
@@ -1321,10 +1321,10 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 		       MPI_SGE_FLAGS_END_OF_BUFFER |
 		       MPI_SGE_FLAGS_DIRECTION |
 		       mpt_addr_size()) << MPI_SGE_FLAGS_SHIFT;
-	flagsLength |= (req->data_len - 4);
+	flagsLength |= (blk_rq_bytes(req) - 4);
 
 	dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio),
-				      req->data_len, PCI_DMA_BIDIRECTIONAL);
+				      blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL);
 	if (!dma_addr_out)
 		goto put_mf;
 	mpt_add_sge(psge, flagsLength, dma_addr_out);
@@ -1332,9 +1332,9 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 
 	/* response */
 	flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
-	flagsLength |= rsp->data_len + 4;
+	flagsLength |= blk_rq_bytes(rsp) + 4;
 	dma_addr_in =  pci_map_single(ioc->pcidev, bio_data(rsp->bio),
-				      rsp->data_len, PCI_DMA_BIDIRECTIONAL);
+				      blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL);
 	if (!dma_addr_in)
 		goto unmap;
 	mpt_add_sge(psge, flagsLength, dma_addr_in);
@@ -1357,7 +1357,7 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 		smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
 		memcpy(req->sense, smprep, sizeof(*smprep));
 		req->sense_len = sizeof(*smprep);
-		rsp->resid_len = rsp->data_len - smprep->ResponseDataLength;
+		rsp->resid_len = blk_rq_bytes(rsp) - smprep->ResponseDataLength;
 	} else {
 		printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n",
 		    ioc->name, __func__);
@@ -1365,10 +1365,10 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 	}
 unmap:
 	if (dma_addr_out)
-		pci_unmap_single(ioc->pcidev, dma_addr_out, req->data_len,
+		pci_unmap_single(ioc->pcidev, dma_addr_out, blk_rq_bytes(req),
 				 PCI_DMA_BIDIRECTIONAL);
 	if (dma_addr_in)
-		pci_unmap_single(ioc->pcidev, dma_addr_in, rsp->data_len,
+		pci_unmap_single(ioc->pcidev, dma_addr_in, blk_rq_bytes(rsp),
 				 PCI_DMA_BIDIRECTIONAL);
 put_mf:
 	if (mf)
drivers/message/i2o/i2o_block.c +1 -1
index 510eb47..6b61d28 100644
@@ -430,7 +430,7 @@ static void i2o_block_end_request(struct request *req, int error,
 		int leftover = (blk_rq_sectors(req) << KERNEL_SECTOR_SHIFT);
 
 		if (blk_pc_request(req))
-			leftover = req->data_len;
+			leftover = blk_rq_bytes(req);
 
 		if (error)
 			blk_end_request(req, -EIO, leftover);
drivers/scsi/libsas/sas_expander.c +4 -4
index 6605ec9..531af9e 100644
@@ -1927,13 +1927,13 @@ int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 	/* do we need to support multiple segments? */
 	if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
 		printk("%s: multiple segments req %u %u, rsp %u %u\n",
-		       __func__, req->bio->bi_vcnt, req->data_len,
-		       rsp->bio->bi_vcnt, rsp->data_len);
+		       __func__, req->bio->bi_vcnt, blk_rq_bytes(req),
+		       rsp->bio->bi_vcnt, blk_rq_bytes(rsp));
 		return -EINVAL;
 	}
 
-	ret = smp_execute_task(dev, bio_data(req->bio), req->data_len,
-			       bio_data(rsp->bio), rsp->data_len);
+	ret = smp_execute_task(dev, bio_data(req->bio), blk_rq_bytes(req),
+			       bio_data(rsp->bio), blk_rq_bytes(rsp));
 	if (ret > 0) {
 		/* positive number is the untransferred residual */
 		rsp->resid_len = ret;
drivers/scsi/libsas/sas_host_smp.c +9 -9
index 89952ed..be9a951 100644
@@ -137,21 +137,21 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 	int error = -EINVAL;
 
 	/* eight is the minimum size for request and response frames */
-	if (req->data_len < 8 || rsp->data_len < 8)
+	if (blk_rq_bytes(req) < 8 || blk_rq_bytes(rsp) < 8)
 		goto out;
 
-	if (bio_offset(req->bio) + req->data_len > PAGE_SIZE ||
-	    bio_offset(rsp->bio) + rsp->data_len > PAGE_SIZE) {
+	if (bio_offset(req->bio) + blk_rq_bytes(req) > PAGE_SIZE ||
+	    bio_offset(rsp->bio) + blk_rq_bytes(rsp) > PAGE_SIZE) {
 		shost_printk(KERN_ERR, shost,
 			"SMP request/response frame crosses page boundary");
 		goto out;
 	}
 
-	req_data = kzalloc(req->data_len, GFP_KERNEL);
+	req_data = kzalloc(blk_rq_bytes(req), GFP_KERNEL);
 
 	/* make sure frame can always be built ... we copy
 	 * back only the requested length */
-	resp_data = kzalloc(max(rsp->data_len, 128U), GFP_KERNEL);
+	resp_data = kzalloc(max(blk_rq_bytes(rsp), 128U), GFP_KERNEL);
 
 	if (!req_data || !resp_data) {
 		error = -ENOMEM;
@@ -160,7 +160,7 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 
 	local_irq_disable();
 	buf = kmap_atomic(bio_page(req->bio), KM_USER0) + bio_offset(req->bio);
-	memcpy(req_data, buf, req->data_len);
+	memcpy(req_data, buf, blk_rq_bytes(req));
 	kunmap_atomic(buf - bio_offset(req->bio), KM_USER0);
 	local_irq_enable();
 
@@ -176,8 +176,8 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 	resp_data[1] = req_data[1];
 	resp_data[2] = SMP_RESP_FUNC_UNK;
 
-	req->resid_len = req->data_len;
-	rsp->resid_len = rsp->data_len;
+	req->resid_len = blk_rq_bytes(req);
+	rsp->resid_len = blk_rq_bytes(rsp);
 
 	switch (req_data[1]) {
 	case SMP_REPORT_GENERAL:
@@ -264,7 +264,7 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 
 	local_irq_disable();
 	buf = kmap_atomic(bio_page(rsp->bio), KM_USER0) + bio_offset(rsp->bio);
-	memcpy(buf, resp_data, rsp->data_len);
+	memcpy(buf, resp_data, blk_rq_bytes(rsp));
 	flush_kernel_dcache_page(bio_page(rsp->bio));
 	kunmap_atomic(buf - bio_offset(rsp->bio), KM_USER0);
 	local_irq_enable();
drivers/scsi/mpt2sas/mpt2sas_transport.c +11 -10
index 53759c5..af95a44 100644
@@ -1041,7 +1041,7 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 	if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
 		printk(MPT2SAS_ERR_FMT "%s: multiple segments req %u %u, "
 		    "rsp %u %u\n", ioc->name, __func__, req->bio->bi_vcnt,
-		    req->data_len, rsp->bio->bi_vcnt, rsp->data_len);
+		    blk_rq_bytes(req), rsp->bio->bi_vcnt, blk_rq_bytes(rsp));
 		return -EINVAL;
 	}
 
@@ -1104,7 +1104,7 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 	*((u64 *)&mpi_request->SASAddress) = (rphy) ?
 	    cpu_to_le64(rphy->identify.sas_address) :
 	    cpu_to_le64(ioc->sas_hba.sas_address);
-	mpi_request->RequestDataLength = cpu_to_le16(req->data_len - 4);
+	mpi_request->RequestDataLength = cpu_to_le16(blk_rq_bytes(req) - 4);
 	psge = &mpi_request->SGL;
 
 	/* WRITE sgel first */
@@ -1112,13 +1112,13 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 	    MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC);
 	sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
 	dma_addr_out = pci_map_single(ioc->pdev, bio_data(req->bio),
-	      req->data_len, PCI_DMA_BIDIRECTIONAL);
+		blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL);
 	if (!dma_addr_out) {
 		mpt2sas_base_free_smid(ioc, le16_to_cpu(smid));
 		goto unmap;
 	}
 
-	ioc->base_add_sg_single(psge, sgl_flags | (req->data_len - 4),
+	ioc->base_add_sg_single(psge, sgl_flags | (blk_rq_bytes(req) - 4),
 	    dma_addr_out);
 
 	/* incr sgel */
@@ -1129,14 +1129,14 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 	    MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
 	    MPI2_SGE_FLAGS_END_OF_LIST);
 	sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
-	dma_addr_in =  pci_map_single(ioc->pdev, bio_data(rsp->bio),
-	      rsp->data_len, PCI_DMA_BIDIRECTIONAL);
+	dma_addr_in = pci_map_single(ioc->pdev, bio_data(rsp->bio),
+				     blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL);
 	if (!dma_addr_in) {
 		mpt2sas_base_free_smid(ioc, le16_to_cpu(smid));
 		goto unmap;
 	}
 
-	ioc->base_add_sg_single(psge, sgl_flags | (rsp->data_len + 4),
+	ioc->base_add_sg_single(psge, sgl_flags | (blk_rq_bytes(rsp) + 4),
 	    dma_addr_in);
 
 	dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s - "
@@ -1170,7 +1170,8 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 
 		memcpy(req->sense, mpi_reply, sizeof(*mpi_reply));
 		req->sense_len = sizeof(*mpi_reply);
-		rsp->resid_len = rsp->data_len - mpi_reply->ResponseDataLength;
+		rsp->resid_len = blk_rq_bytes(rsp) -
+				 mpi_reply->ResponseDataLength;
 	} else {
 		dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT
 		    "%s - no reply\n", ioc->name, __func__));
@@ -1186,10 +1187,10 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 
  unmap:
 	if (dma_addr_out)
-		pci_unmap_single(ioc->pdev, dma_addr_out, req->data_len,
+		pci_unmap_single(ioc->pdev, dma_addr_out, blk_rq_bytes(req),
 		    PCI_DMA_BIDIRECTIONAL);
 	if (dma_addr_in)
-		pci_unmap_single(ioc->pdev, dma_addr_in, rsp->data_len,
+		pci_unmap_single(ioc->pdev, dma_addr_in, blk_rq_bytes(rsp),
 		    PCI_DMA_BIDIRECTIONAL);
 
  out:
drivers/scsi/osd/osd_initiator.c +2 -2
index 2a5f077..d178a8b 100644
@@ -1299,7 +1299,7 @@ int osd_finalize_request(struct osd_request *or,
 			return ret;
 		}
 		OSD_DEBUG("out bytes=%llu (bytes_req=%u)\n",
-			_LLU(or->out.total_bytes), or->out.req->data_len);
+			_LLU(or->out.total_bytes), blk_rq_bytes(or->out.req));
 	}
 	if (or->in.bio) {
 		ret = blk_rq_append_bio(or->request->q, or->in.req, or->in.bio);
@@ -1308,7 +1308,7 @@ int osd_finalize_request(struct osd_request *or,
 			return ret;
 		}
 		OSD_DEBUG("in bytes=%llu (bytes_req=%u)\n",
-			_LLU(or->in.total_bytes), or->in.req->data_len);
+			_LLU(or->in.total_bytes), blk_rq_bytes(or->in.req));
 	}
 
 	or->out.pad_buff = sg_out_pad_buffer;
drivers/scsi/scsi_lib.c +6 -7
index 39b3acf..3d16c70 100644
@@ -682,14 +682,13 @@ EXPORT_SYMBOL(scsi_release_buffers);
 static void scsi_end_bidi_request(struct scsi_cmnd *cmd)
 {
 	struct request *req = cmd->request;
-	unsigned int dlen = req->data_len;
-	unsigned int next_dlen = req->next_rq->data_len;
 
 	req->resid_len = scsi_out(cmd)->resid;
 	req->next_rq->resid_len = scsi_in(cmd)->resid;
 
 	/* The req and req->next_rq have not been completed */
-	BUG_ON(blk_end_bidi_request(req, 0, dlen, next_dlen));
+	BUG_ON(blk_end_bidi_request(req, 0, blk_rq_bytes(req),
+				    blk_rq_bytes(req->next_rq)));
 
 	scsi_release_buffers(cmd);
 
@@ -966,7 +965,7 @@ static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb,
 	BUG_ON(count > sdb->table.nents);
 	sdb->table.nents = count;
 	if (blk_pc_request(req))
-		sdb->length = req->data_len;
+		sdb->length = blk_rq_bytes(req);
 	else
 		sdb->length = blk_rq_sectors(req) << 9;
 	return BLKPREP_OK;
@@ -1087,21 +1086,21 @@ int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req)
 		if (unlikely(ret))
 			return ret;
 	} else {
-		BUG_ON(req->data_len);
+		BUG_ON(blk_rq_bytes(req));
 
 		memset(&cmd->sdb, 0, sizeof(cmd->sdb));
 		req->buffer = NULL;
 	}
 
 	cmd->cmd_len = req->cmd_len;
-	if (!req->data_len)
+	if (!blk_rq_bytes(req))
 		cmd->sc_data_direction = DMA_NONE;
 	else if (rq_data_dir(req) == WRITE)
 		cmd->sc_data_direction = DMA_TO_DEVICE;
 	else
 		cmd->sc_data_direction = DMA_FROM_DEVICE;
 	
-	cmd->transfersize = req->data_len;
+	cmd->transfersize = blk_rq_bytes(req);
 	cmd->allowed = req->retries;
 	return BLKPREP_OK;
 }
drivers/scsi/scsi_tgt_lib.c +1 -1
index 48ba413..1030327 100644
@@ -387,7 +387,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
 	 * we use REQ_TYPE_BLOCK_PC so scsi_init_io doesn't set the
 	 * length for us.
 	 */
-	cmd->sdb.length = rq->data_len;
+	cmd->sdb.length = blk_rq_bytes(rq);
 
 	return 0;
 
Signature · 1 line
1.6.0.2
Acked-by on v1 8/11
#46 lore raw

Re: [PATCH 08/11] block: cleanup rq->data_len usages

Quoted 9 lines · Tejun Heo

With recent unification of fields, it's now guaranteed that rq->data_len always equals blk_rq_bytes(). Convert all non-IDE direct users to accessors. IDE will be converted in a separate patch.

Boaz: spotted incorrect data_len/resid_len conversion in osd.

[ Impact: convert direct rq->data_len usages to blk_rq_bytes() ]

MBR, Sergei

Reviewed-by on v1 8/11
#47 lore raw

Re: [PATCH 08/11] block: cleanup rq->data_len usages

In reply to Tejun Heo
Quoted 152 lines · Tejun Heo

With recent unification of fields, it's now guaranteed that rq->data_len always equals blk_rq_bytes(). Convert all non-IDE direct users to accessors. IDE will be converted in a separate patch.

Boaz: spotted incorrect data_len/resid_len conversion in osd.

[ Impact: convert direct rq->data_len usages to blk_rq_bytes() ]

Cc Pete Zaitcev <[email protected]>
Cc Eric Moore <[email protected]>
Cc Markus Lidel <[email protected]>
Cc Darrick J. Wong <[email protected]>
Cc James Bottomley <[email protected]>
Cc Eric Moore <[email protected]>
Cc Boaz Harrosh <[email protected]>
Cc FUJITA Tomonori <[email protected]>
---
 drivers/ata/libata-scsi.c                |    2 +-
 drivers/block/ub.c                       |    8 ++++----
 drivers/message/fusion/mptsas.c          |   20 ++++++++++----------
 drivers/message/i2o/i2o_block.c          |    2 +-
 drivers/scsi/libsas/sas_expander.c       |    8 ++++----
 drivers/scsi/libsas/sas_host_smp.c       |   18 +++++++++---------
 drivers/scsi/mpt2sas/mpt2sas_transport.c |   21 +++++++++++----------
 drivers/scsi/osd/osd_initiator.c         |    4 ++--
 drivers/scsi/scsi_lib.c                  |   13 ++++++-------
 drivers/scsi/scsi_tgt_lib.c              |    2 +-
 10 files changed, 49 insertions(+), 49 deletions(-)
drivers/ata/libata-scsi.c +1 -1
index 2733b0c..6e4c600 100644
@@ -1084,7 +1084,7 @@ static int atapi_drain_needed(struct request *rq)
 	if (likely(!blk_pc_request(rq)))
 		return 0;
 
-	if (!rq->data_len || (rq->cmd_flags & REQ_RW))
+	if (!blk_rq_bytes(rq) || (rq->cmd_flags & REQ_RW))
 		return 0;
 
 	return atapi_cmd_type(rq->cmd[0]) == ATAPI_MISC;
drivers/block/ub.c +4 -4
index dc3b899..1591f61 100644
@@ -747,7 +747,7 @@ static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun,
 {
 	struct request *rq = urq->rq;
 
-	if (rq->data_len == 0) {
+	if (blk_rq_bytes(rq) == 0) {
 		cmd->dir = UB_DIR_NONE;
 	} else {
 		if (rq_data_dir(rq) == WRITE)
@@ -762,7 +762,7 @@ static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun,
 	memcpy(&cmd->cdb, rq->cmd, rq->cmd_len);
 	cmd->cdb_len = rq->cmd_len;
 
-	cmd->len = rq->data_len;
+	cmd->len = blk_rq_bytes(rq);
 
 	/*
 	 * To reapply this to every URB is not as incorrect as it looks.
@@ -783,8 +783,8 @@ static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
 
 	if (cmd->error == 0) {
 		if (blk_pc_request(rq)) {
-			if (cmd->act_len < rq->data_len)
-				rq->resid_len = rq->data_len - cmd->act_len;
+			if (cmd->act_len < blk_rq_bytes(rq))
+				rq->resid_len = blk_rq_bytes(rq) - cmd->act_len;
 			scsi_status = 0;
 		} else {
 			if (cmd->act_len != cmd->len) {
drivers/message/fusion/mptsas.c +10 -10
index 5d5f347..4e6fcf0 100644
@@ -1277,8 +1277,8 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 	/* do we need to support multiple segments? */
 	if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
 		printk(MYIOC_s_ERR_FMT "%s: multiple segments req %u %u, rsp %u %u\n",
-		    ioc->name, __func__, req->bio->bi_vcnt, req->data_len,
-		    rsp->bio->bi_vcnt, rsp->data_len);
+		    ioc->name, __func__, req->bio->bi_vcnt, blk_rq_bytes(req),
+		    rsp->bio->bi_vcnt, blk_rq_bytes(rsp));
 		return -EINVAL;
 	}
 
@@ -1295,7 +1295,7 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 	smpreq = (SmpPassthroughRequest_t *)mf;
 	memset(smpreq, 0, sizeof(*smpreq));
 
-	smpreq->RequestDataLength = cpu_to_le16(req->data_len - 4);
+	smpreq->RequestDataLength = cpu_to_le16(blk_rq_bytes(req) - 4);
 	smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
 
 	if (rphy)
@@ -1321,10 +1321,10 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 		       MPI_SGE_FLAGS_END_OF_BUFFER |
 		       MPI_SGE_FLAGS_DIRECTION |
 		       mpt_addr_size()) << MPI_SGE_FLAGS_SHIFT;
-	flagsLength |= (req->data_len - 4);
+	flagsLength |= (blk_rq_bytes(req) - 4);
 
 	dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio),
-				      req->data_len, PCI_DMA_BIDIRECTIONAL);
+				      blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL);
 	if (!dma_addr_out)
 		goto put_mf;
 	mpt_add_sge(psge, flagsLength, dma_addr_out);
@@ -1332,9 +1332,9 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 
 	/* response */
 	flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
-	flagsLength |= rsp->data_len + 4;
+	flagsLength |= blk_rq_bytes(rsp) + 4;
 	dma_addr_in =  pci_map_single(ioc->pcidev, bio_data(rsp->bio),
-				      rsp->data_len, PCI_DMA_BIDIRECTIONAL);
+				      blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL);
 	if (!dma_addr_in)
 		goto unmap;
 	mpt_add_sge(psge, flagsLength, dma_addr_in);
@@ -1357,7 +1357,7 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 		smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
 		memcpy(req->sense, smprep, sizeof(*smprep));
 		req->sense_len = sizeof(*smprep);
-		rsp->resid_len = rsp->data_len - smprep->ResponseDataLength;
+		rsp->resid_len = blk_rq_bytes(rsp) - smprep->ResponseDataLength;
 	} else {
 		printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n",
 		    ioc->name, __func__);
@@ -1365,10 +1365,10 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 	}
 unmap:
 	if (dma_addr_out)
-		pci_unmap_single(ioc->pcidev, dma_addr_out, req->data_len,
+		pci_unmap_single(ioc->pcidev, dma_addr_out, blk_rq_bytes(req),
 				 PCI_DMA_BIDIRECTIONAL);
 	if (dma_addr_in)
-		pci_unmap_single(ioc->pcidev, dma_addr_in, rsp->data_len,
+		pci_unmap_single(ioc->pcidev, dma_addr_in, blk_rq_bytes(rsp),
 				 PCI_DMA_BIDIRECTIONAL);
 put_mf:
 	if (mf)
drivers/message/i2o/i2o_block.c +0 -0
index 510eb47..6b61d28 100644

drivers/message/i2o/i2o_block.c static void i2o_block_end_request(struct request *req, int error, · line 436

Quoted 8 lines
drivers/message/i2o/i2o_block.c +1 -1
@@ -430,7 +430,7 @@ static void i2o_block_end_request(struct request *req, int error,
 		int leftover = (blk_rq_sectors(req) << KERNEL_SECTOR_SHIFT);
 
 		if (blk_pc_request(req))
-			leftover = req->data_len;
+			leftover = blk_rq_bytes(req);
 
 		if (error)
 			blk_end_request(req, -EIO, leftover);

Note:
This can be blk_end_request_all() and "int leftover =" dropped.

Quoted 175 lines
drivers/scsi/libsas/sas_expander.c +4 -4
index 6605ec9..531af9e 100644
@@ -1927,13 +1927,13 @@ int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 	/* do we need to support multiple segments? */
 	if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
 		printk("%s: multiple segments req %u %u, rsp %u %u\n",
-		       __func__, req->bio->bi_vcnt, req->data_len,
-		       rsp->bio->bi_vcnt, rsp->data_len);
+		       __func__, req->bio->bi_vcnt, blk_rq_bytes(req),
+		       rsp->bio->bi_vcnt, blk_rq_bytes(rsp));
 		return -EINVAL;
 	}
 
-	ret = smp_execute_task(dev, bio_data(req->bio), req->data_len,
-			       bio_data(rsp->bio), rsp->data_len);
+	ret = smp_execute_task(dev, bio_data(req->bio), blk_rq_bytes(req),
+			       bio_data(rsp->bio), blk_rq_bytes(rsp));
 	if (ret > 0) {
 		/* positive number is the untransferred residual */
 		rsp->resid_len = ret;
drivers/scsi/libsas/sas_host_smp.c +9 -9
index 89952ed..be9a951 100644
@@ -137,21 +137,21 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 	int error = -EINVAL;
 
 	/* eight is the minimum size for request and response frames */
-	if (req->data_len < 8 || rsp->data_len < 8)
+	if (blk_rq_bytes(req) < 8 || blk_rq_bytes(rsp) < 8)
 		goto out;
 
-	if (bio_offset(req->bio) + req->data_len > PAGE_SIZE ||
-	    bio_offset(rsp->bio) + rsp->data_len > PAGE_SIZE) {
+	if (bio_offset(req->bio) + blk_rq_bytes(req) > PAGE_SIZE ||
+	    bio_offset(rsp->bio) + blk_rq_bytes(rsp) > PAGE_SIZE) {
 		shost_printk(KERN_ERR, shost,
 			"SMP request/response frame crosses page boundary");
 		goto out;
 	}
 
-	req_data = kzalloc(req->data_len, GFP_KERNEL);
+	req_data = kzalloc(blk_rq_bytes(req), GFP_KERNEL);
 
 	/* make sure frame can always be built ... we copy
 	 * back only the requested length */
-	resp_data = kzalloc(max(rsp->data_len, 128U), GFP_KERNEL);
+	resp_data = kzalloc(max(blk_rq_bytes(rsp), 128U), GFP_KERNEL);
 
 	if (!req_data || !resp_data) {
 		error = -ENOMEM;
@@ -160,7 +160,7 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 
 	local_irq_disable();
 	buf = kmap_atomic(bio_page(req->bio), KM_USER0) + bio_offset(req->bio);
-	memcpy(req_data, buf, req->data_len);
+	memcpy(req_data, buf, blk_rq_bytes(req));
 	kunmap_atomic(buf - bio_offset(req->bio), KM_USER0);
 	local_irq_enable();
 
@@ -176,8 +176,8 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 	resp_data[1] = req_data[1];
 	resp_data[2] = SMP_RESP_FUNC_UNK;
 
-	req->resid_len = req->data_len;
-	rsp->resid_len = rsp->data_len;
+	req->resid_len = blk_rq_bytes(req);
+	rsp->resid_len = blk_rq_bytes(rsp);
 
 	switch (req_data[1]) {
 	case SMP_REPORT_GENERAL:
@@ -264,7 +264,7 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 
 	local_irq_disable();
 	buf = kmap_atomic(bio_page(rsp->bio), KM_USER0) + bio_offset(rsp->bio);
-	memcpy(buf, resp_data, rsp->data_len);
+	memcpy(buf, resp_data, blk_rq_bytes(rsp));
 	flush_kernel_dcache_page(bio_page(rsp->bio));
 	kunmap_atomic(buf - bio_offset(rsp->bio), KM_USER0);
 	local_irq_enable();
drivers/scsi/mpt2sas/mpt2sas_transport.c +11 -10
index 53759c5..af95a44 100644
@@ -1041,7 +1041,7 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 	if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
 		printk(MPT2SAS_ERR_FMT "%s: multiple segments req %u %u, "
 		    "rsp %u %u\n", ioc->name, __func__, req->bio->bi_vcnt,
-		    req->data_len, rsp->bio->bi_vcnt, rsp->data_len);
+		    blk_rq_bytes(req), rsp->bio->bi_vcnt, blk_rq_bytes(rsp));
 		return -EINVAL;
 	}
 
@@ -1104,7 +1104,7 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 	*((u64 *)&mpi_request->SASAddress) = (rphy) ?
 	    cpu_to_le64(rphy->identify.sas_address) :
 	    cpu_to_le64(ioc->sas_hba.sas_address);
-	mpi_request->RequestDataLength = cpu_to_le16(req->data_len - 4);
+	mpi_request->RequestDataLength = cpu_to_le16(blk_rq_bytes(req) - 4);
 	psge = &mpi_request->SGL;
 
 	/* WRITE sgel first */
@@ -1112,13 +1112,13 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 	    MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC);
 	sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
 	dma_addr_out = pci_map_single(ioc->pdev, bio_data(req->bio),
-	      req->data_len, PCI_DMA_BIDIRECTIONAL);
+		blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL);
 	if (!dma_addr_out) {
 		mpt2sas_base_free_smid(ioc, le16_to_cpu(smid));
 		goto unmap;
 	}
 
-	ioc->base_add_sg_single(psge, sgl_flags | (req->data_len - 4),
+	ioc->base_add_sg_single(psge, sgl_flags | (blk_rq_bytes(req) - 4),
 	    dma_addr_out);
 
 	/* incr sgel */
@@ -1129,14 +1129,14 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 	    MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
 	    MPI2_SGE_FLAGS_END_OF_LIST);
 	sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
-	dma_addr_in =  pci_map_single(ioc->pdev, bio_data(rsp->bio),
-	      rsp->data_len, PCI_DMA_BIDIRECTIONAL);
+	dma_addr_in = pci_map_single(ioc->pdev, bio_data(rsp->bio),
+				     blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL);
 	if (!dma_addr_in) {
 		mpt2sas_base_free_smid(ioc, le16_to_cpu(smid));
 		goto unmap;
 	}
 
-	ioc->base_add_sg_single(psge, sgl_flags | (rsp->data_len + 4),
+	ioc->base_add_sg_single(psge, sgl_flags | (blk_rq_bytes(rsp) + 4),
 	    dma_addr_in);
 
 	dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s - "
@@ -1170,7 +1170,8 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 
 		memcpy(req->sense, mpi_reply, sizeof(*mpi_reply));
 		req->sense_len = sizeof(*mpi_reply);
-		rsp->resid_len = rsp->data_len - mpi_reply->ResponseDataLength;
+		rsp->resid_len = blk_rq_bytes(rsp) -
+				 mpi_reply->ResponseDataLength;
 	} else {
 		dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT
 		    "%s - no reply\n", ioc->name, __func__));
@@ -1186,10 +1187,10 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 
  unmap:
 	if (dma_addr_out)
-		pci_unmap_single(ioc->pdev, dma_addr_out, req->data_len,
+		pci_unmap_single(ioc->pdev, dma_addr_out, blk_rq_bytes(req),
 		    PCI_DMA_BIDIRECTIONAL);
 	if (dma_addr_in)
-		pci_unmap_single(ioc->pdev, dma_addr_in, rsp->data_len,
+		pci_unmap_single(ioc->pdev, dma_addr_in, blk_rq_bytes(rsp),
 		    PCI_DMA_BIDIRECTIONAL);
 
  out:
drivers/scsi/osd/osd_initiator.c +1 -1
index 2a5f077..d178a8b 100644
@@ -1299,7 +1299,7 @@ int osd_finalize_request(struct osd_request *or,
 			return ret;
 		}
 		OSD_DEBUG("out bytes=%llu (bytes_req=%u)\n",
-			_LLU(or->out.total_bytes), or->out.req->data_len);
+			_LLU(or->out.total_bytes), blk_rq_bytes(or->out.req));
 	}
 	if (or->in.bio) {
 		ret = blk_rq_append_bio(or->request->q, or->in.req, or->in.bio);

drivers/scsi/osd/osd_initiator.c int osd_finalize_request(struct osd_request *or, · line 1314

Quoted 8 lines
drivers/scsi/osd/osd_initiator.c +1 -1
@@ -1308,7 +1308,7 @@ int osd_finalize_request(struct osd_request *or,
 			return ret;
 		}
 		OSD_DEBUG("in bytes=%llu (bytes_req=%u)\n",
-			_LLU(or->in.total_bytes), or->in.req->data_len);
+			_LLU(or->in.total_bytes), blk_rq_bytes(or->in.req));
 	}
 
 	or->out.pad_buff = sg_out_pad_buffer;

Stupid prints. I'll Q a patch that removes them once this is accepted. Thanks.

Quoted 45 lines
drivers/scsi/scsi_lib.c +5 -6
index 39b3acf..3d16c70 100644
@@ -682,14 +682,13 @@ EXPORT_SYMBOL(scsi_release_buffers);
 static void scsi_end_bidi_request(struct scsi_cmnd *cmd)
 {
 	struct request *req = cmd->request;
-	unsigned int dlen = req->data_len;
-	unsigned int next_dlen = req->next_rq->data_len;
 
 	req->resid_len = scsi_out(cmd)->resid;
 	req->next_rq->resid_len = scsi_in(cmd)->resid;
 
 	/* The req and req->next_rq have not been completed */
-	BUG_ON(blk_end_bidi_request(req, 0, dlen, next_dlen));
+	BUG_ON(blk_end_bidi_request(req, 0, blk_rq_bytes(req),
+				    blk_rq_bytes(req->next_rq)));
 
 	scsi_release_buffers(cmd);
 
@@ -966,7 +965,7 @@ static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb,
 	BUG_ON(count > sdb->table.nents);
 	sdb->table.nents = count;
 	if (blk_pc_request(req))
-		sdb->length = req->data_len;
+		sdb->length = blk_rq_bytes(req);
 	else
 		sdb->length = blk_rq_sectors(req) << 9;
 	return BLKPREP_OK;
@@ -1087,21 +1086,21 @@ int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req)
 		if (unlikely(ret))
 			return ret;
 	} else {
-		BUG_ON(req->data_len);
+		BUG_ON(blk_rq_bytes(req));
 
 		memset(&cmd->sdb, 0, sizeof(cmd->sdb));
 		req->buffer = NULL;
 	}
 
 	cmd->cmd_len = req->cmd_len;
-	if (!req->data_len)
+	if (!blk_rq_bytes(req))
 		cmd->sc_data_direction = DMA_NONE;

drivers/scsi/scsi_lib.c int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req) · line 1106

Quoted 10 lines
drivers/scsi/scsi_lib.c +1 -1
 	else if (rq_data_dir(req) == WRITE)
 		cmd->sc_data_direction = DMA_TO_DEVICE;
 	else
 		cmd->sc_data_direction = DMA_FROM_DEVICE;
 
-	cmd->transfersize = req->data_len;
+	cmd->transfersize = blk_rq_bytes(req);
 	cmd->allowed = req->retries;
 	return BLKPREP_OK;
 }

drivers/scsi/scsi_tgt_lib.c static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd, · line 390

Quoted 10 lines
drivers/scsi/scsi_tgt_lib.c +1 -1
index 48ba413..1030327 100644
@@ -387,7 +387,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
 	 * we use REQ_TYPE_BLOCK_PC so scsi_init_io doesn't set the
 	 * length for us.
 	 */
-	cmd->sdb.length = rq->data_len;
+	cmd->sdb.length = blk_rq_bytes(rq);

Note to self:
This code and the comment is wrong scsi_init_io does set everything right. It should be dropped. Once everything settles, I'll send a patch to remove this.

drivers/scsi/scsi_tgt_lib.c static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd, · line 392

Quoted 3 lines
drivers/scsi/scsi_tgt_lib.c +0 -0
 	return 0;
 

I've reviewed all the scsi parts.

(We had a 24 hours internet outage so these replys where delayed)

Thanks
Boaz

author
#48 lore raw

PATCH 9/11 ide: cleanup rq->data_len usages

In reply to Tejun Heo

With recent unification of fields, it's now guaranteed that rq->data_len always equals blk_rq_bytes(). Convert all direct users to accessors.

[ Impact: convert direct rq->data_len usages to blk_rq_bytes() ]

---
 drivers/ide/ide-atapi.c  |    4 ++--
 drivers/ide/ide-cd.c     |   25 +++++++------------------
 drivers/ide/ide-floppy.c |    4 ++--
 drivers/ide/ide-io.c     |    2 +-
 4 files changed, 12 insertions(+), 23 deletions(-)
drivers/ide/ide-atapi.c +2 -2
index e4a02a0..792534d 100644
@@ -255,7 +255,7 @@ void ide_retry_pc(ide_drive_t *drive)
 	ide_init_pc(pc);
 	memcpy(pc->c, sense_rq->cmd, 12);
 	pc->buf = bio_data(sense_rq->bio);	/* pointer to mapped address */
-	pc->req_xfer = sense_rq->data_len;
+	pc->req_xfer = blk_rq_bytes(sense_rq);
 
 	if (drive->media == ide_tape)
 		set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
@@ -303,7 +303,7 @@ int ide_cd_get_xferlen(struct request *rq)
 		return 32768;
 	else if (blk_sense_request(rq) || blk_pc_request(rq) ||
 			 rq->cmd_type == REQ_TYPE_ATA_PC)
-		return rq->data_len;
+		return blk_rq_bytes(rq);
 	else
 		return 0;
 }
drivers/ide/ide-cd.c +7 -18
index 94a341b..1a58b38 100644
@@ -576,7 +576,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
 	struct request *rq = hwif->rq;
 	ide_expiry_t *expiry = NULL;
 	int dma_error = 0, dma, thislen, uptodate = 0;
-	int write = (rq_data_dir(rq) == WRITE) ? 1 : 0, rc = 0, nsectors;
+	int write = (rq_data_dir(rq) == WRITE) ? 1 : 0, rc = 0;
 	int sense = blk_sense_request(rq);
 	unsigned int timeout;
 	u16 len;
@@ -706,9 +706,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
 
 out_end:
 	if (blk_pc_request(rq) && rc == 0) {
-		if (blk_end_request(rq, 0, rq->data_len))
-			BUG();
-
+		blk_end_request_all(rq, 0);
 		hwif->rq = NULL;
 	} else {
 		if (sense && uptodate)
@@ -726,22 +724,14 @@ out_end:
 			ide_cd_error_cmd(drive, cmd);
 
 		/* make sure it's fully ended */
-		if (blk_pc_request(rq))
-			nsectors = (rq->data_len + 511) >> 9;
-		else
-			nsectors = blk_rq_sectors(rq);
-
-		if (nsectors == 0)
-			nsectors = 1;
-
 		if (blk_fs_request(rq) == 0) {
-			rq->resid_len = rq->data_len -
+			rq->resid_len = blk_rq_bytes(rq) -
 				(cmd->nbytes - cmd->nleft);
 			if (uptodate == 0 && (cmd->tf_flags & IDE_TFLAG_WRITE))
 				rq->resid_len += cmd->last_xfer_len;
 		}
 
-		ide_complete_rq(drive, uptodate ? 0 : -EIO, nsectors << 9);
+		ide_complete_rq(drive, uptodate ? 0 : -EIO, blk_rq_bytes(rq));
 
 		if (sense && rc == 2)
 			ide_error(drive, "request sense failure", stat);
@@ -818,7 +808,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
 		 */
 		alignment = queue_dma_alignment(q) | q->dma_pad_mask;
 		if ((unsigned long)buf & alignment
-		    || rq->data_len & q->dma_pad_mask
+		    || blk_rq_bytes(rq) & q->dma_pad_mask
 		    || object_is_on_stack(buf))
 			drive->dma = 0;
 	}
@@ -866,9 +856,8 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
 
 	cmd.rq = rq;
 
-	if (blk_fs_request(rq) || rq->data_len) {
-		ide_init_sg_cmd(&cmd, blk_fs_request(rq) ?
-				(blk_rq_sectors(rq) << 9) : rq->data_len);
+	if (blk_fs_request(rq) || blk_rq_bytes(rq)) {
+		ide_init_sg_cmd(&cmd, blk_rq_bytes(rq));
 		ide_map_sg(drive, &cmd);
 	}
 
drivers/ide/ide-floppy.c +2 -2
index 1c460bd..6509817 100644
@@ -220,14 +220,14 @@ static void idefloppy_blockpc_cmd(struct ide_disk_obj *floppy,
 	ide_init_pc(pc);
 	memcpy(pc->c, rq->cmd, sizeof(pc->c));
 	pc->rq = rq;
-	if (rq->data_len) {
+	if (blk_rq_bytes(rq)) {
 		pc->flags |= PC_FLAG_DMA_OK;
 		if (rq_data_dir(rq) == WRITE)
 			pc->flags |= PC_FLAG_WRITING;
 	}
 	/* pio will be performed by ide_pio_bytes() which handles sg fine */
 	pc->buf = NULL;
-	pc->req_xfer = pc->buf_size = rq->data_len;
+	pc->req_xfer = pc->buf_size = blk_rq_bytes(rq);
 }
 
 static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
drivers/ide/ide-io.c +1 -1
index 59799ca..ca2519d 100644
@@ -116,7 +116,7 @@ void ide_complete_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat, u8 err)
 unsigned int ide_rq_bytes(struct request *rq)
 {
 	if (blk_pc_request(rq))
-		return rq->data_len;
+		return blk_rq_bytes(rq);
 	else
 		return blk_rq_cur_sectors(rq) << 9;
 }
Signature · 1 line
1.6.0.2
author
#49 lore raw

PATCH 10/11 block: hide request sector and data_len

In reply to Tejun Heo

Block low level drivers for some reason have been pretty good at abusing block layer API. Especially struct request's fields tend to get violated in all possible ways. Make it clear that low level drivers MUST NOT access or manipulate rq->sector and rq->data_len directly by prefixing them with double underscores.

This change is also necessary to break build of out-of-tree codes which assume the previous block API where internal fields can be manipulated and rq->data_len carries residual count on completion.

[ Impact: hide internal fields, block API change ]

---
 block/blk-core.c       |   20 ++++++++++----------
 block/blk-map.c        |    2 +-
 block/blk-merge.c      |    2 +-
 include/linux/blkdev.h |    9 +++++----
 4 files changed, 17 insertions(+), 16 deletions(-)
block/blk-core.c +10 -10
index 3596ca7..6226a38 100644
@@ -127,7 +127,7 @@ void blk_rq_init(struct request_queue *q, struct request *rq)
 	INIT_LIST_HEAD(&rq->timeout_list);
 	rq->cpu = -1;
 	rq->q = q;
-	rq->sector = (sector_t) -1;
+	rq->__sector = (sector_t) -1;
 	INIT_HLIST_NODE(&rq->hash);
 	RB_CLEAR_NODE(&rq->rb_node);
 	rq->cmd = rq->__cmd;
@@ -1095,7 +1095,7 @@ void init_request_from_bio(struct request *req, struct bio *bio)
 		req->cmd_flags |= REQ_NOIDLE;
 
 	req->errors = 0;
-	req->sector = bio->bi_sector;
+	req->__sector = bio->bi_sector;
 	req->ioprio = bio_prio(bio);
 	blk_rq_bio_prep(req->q, req, bio);
 }
@@ -1143,7 +1143,7 @@ static int __make_request(struct request_queue *q, struct bio *bio)
 
 		req->biotail->bi_next = bio;
 		req->biotail = bio;
-		req->data_len += bytes;
+		req->__data_len += bytes;
 		req->ioprio = ioprio_best(req->ioprio, prio);
 		if (!blk_rq_cpu_valid(req))
 			req->cpu = bio->bi_comp_cpu;
@@ -1169,8 +1169,8 @@ static int __make_request(struct request_queue *q, struct bio *bio)
 		 * not touch req->buffer either...
 		 */
 		req->buffer = bio_data(bio);
-		req->sector = bio->bi_sector;
-		req->data_len += bytes;
+		req->__sector = bio->bi_sector;
+		req->__data_len += bytes;
 		req->ioprio = ioprio_best(req->ioprio, prio);
 		if (!blk_rq_cpu_valid(req))
 			req->cpu = bio->bi_comp_cpu;
@@ -1878,7 +1878,7 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
 		 * can find how many bytes remain in the request
 		 * later.
 		 */
-		req->data_len = 0;
+		req->__data_len = 0;
 		return false;
 	}
 
@@ -1892,12 +1892,12 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
 		bio_iovec(bio)->bv_len -= nr_bytes;
 	}
 
-	req->data_len -= total_bytes;
+	req->__data_len -= total_bytes;
 	req->buffer = bio_data(req->bio);
 
 	/* update sector only for requests with clear definition of sector */
 	if (blk_fs_request(req) || blk_discard_rq(req))
-		req->sector += total_bytes >> 9;
+		req->__sector += total_bytes >> 9;
 
 	/*
 	 * If total number of sectors is less than the first segment
@@ -1905,7 +1905,7 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
 	 */
 	if (blk_rq_bytes(req) < blk_rq_cur_bytes(req)) {
 		printk(KERN_ERR "blk: request botched\n");
-		req->data_len = blk_rq_cur_bytes(req);
+		req->__data_len = blk_rq_cur_bytes(req);
 	}
 
 	/* recalculate the number of segments */
@@ -2032,7 +2032,7 @@ void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
 		rq->nr_phys_segments = bio_phys_segments(q, bio);
 		rq->buffer = bio_data(bio);
 	}
-	rq->data_len = bio->bi_size;
+	rq->__data_len = bio->bi_size;
 	rq->bio = rq->biotail = bio;
 
 	if (bio->bi_bdev)
block/blk-map.c +1 -1
index 694fefa..56082be 100644
@@ -20,7 +20,7 @@ int blk_rq_append_bio(struct request_queue *q, struct request *rq,
 		rq->biotail->bi_next = bio;
 		rq->biotail = bio;
 
-		rq->data_len += bio->bi_size;
+		rq->__data_len += bio->bi_size;
 	}
 	return 0;
 }
block/blk-merge.c +1 -1
index b8df66a..4974dd5 100644
@@ -370,7 +370,7 @@ static int attempt_merge(struct request_queue *q, struct request *req,
 	req->biotail->bi_next = next->bio;
 	req->biotail = next->biotail;
 
-	req->data_len += blk_rq_bytes(next);
+	req->__data_len += blk_rq_bytes(next);
 
 	elv_merge_requests(q, req, next);
 
include/linux/blkdev.h +5 -4
index 723d22e..6617abd 100644
@@ -166,8 +166,9 @@ struct request {
 	enum rq_cmd_type_bits cmd_type;
 	unsigned long atomic_flags;
 
-	sector_t sector;	/* sector cursor */
-	unsigned int data_len;	/* total data len, don't access directly */
+	/* the following two fields are internal, NEVER access directly */
+	sector_t __sector;		/* sector cursor */
+	unsigned int __data_len;	/* total data len */
 
 	struct bio *bio;
 	struct bio *biotail;
@@ -829,12 +830,12 @@ extern void blkdev_dequeue_request(struct request *req);
  */
 static inline sector_t blk_rq_pos(const struct request *rq)
 {
-	return rq->sector;
+	return rq->__sector;
 }
 
 static inline unsigned int blk_rq_bytes(const struct request *rq)
 {
-	return rq->data_len;
+	return rq->__data_len;
 }
 
 static inline int blk_rq_cur_bytes(const struct request *rq)
Signature · 1 line
1.6.0.2
author
#50 lore raw

PATCH 11/11 block: blk_rq_[cur_]_{sectors|bytes}() usage cleanup

In reply to Tejun Heo

With the previous changes, the followings are now guaranteed for all requests in any valid state.

* blk_rq_sectors() == blk_rq_bytes() >> 9
* blk_rq_cur_sectors() == blk_rq_cur_bytes() >> 9

Clean up accessor usages. Notable changes are

* nbd,i2o_block: end_all used instead of explicit byte count
* scsi_lib: unnecessary conditional on request type removed

[ Impact: cleanup ]

Cc Paul Clements <[email protected]>
Cc Pete Zaitcev <[email protected]>
Cc Alex Dubov <[email protected]>
Cc Markus Lidel <[email protected]>
Cc David Woodhouse <[email protected]>
Cc James Bottomley <[email protected]>
Cc Boaz Harrosh <[email protected]>
---
 drivers/block/floppy.c              |    7 +++----
 drivers/block/nbd.c                 |    6 +++---
 drivers/block/ub.c                  |    2 +-
 drivers/block/z2ram.c               |    2 +-
 drivers/memstick/core/mspro_block.c |    4 ++--
 drivers/message/i2o/i2o_block.c     |   16 ++++------------
 drivers/mtd/mtd_blkdevs.c           |    2 +-
 drivers/sbus/char/jsflash.c         |    2 +-
 drivers/scsi/scsi_lib.c             |    7 ++-----
 9 files changed, 18 insertions(+), 30 deletions(-)
drivers/block/floppy.c +3 -4
index 4524862..1e27ed9 100644
@@ -2512,8 +2512,7 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2)
 
 	remaining = current_count_sectors << 9;
 #ifdef FLOPPY_SANITY_CHECK
-	if ((remaining >> 9) > blk_rq_sectors(current_req) &&
-	    CT(COMMAND) == FD_WRITE) {
+	if (remaining > blk_rq_bytes(current_req) && CT(COMMAND) == FD_WRITE) {
 		DPRINT("in copy buffer\n");
 		printk("current_count_sectors=%ld\n", current_count_sectors);
 		printk("remaining=%d\n", remaining >> 9);
@@ -2530,7 +2529,7 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2)
 
 	dma_buffer = floppy_track_buffer + ((fsector_t - buffer_min) << 9);
 
-	size = blk_rq_cur_sectors(current_req) << 9;
+	size = blk_rq_cur_bytes(current_req);
 
 	rq_for_each_segment(bv, current_req, iter) {
 		if (!remaining)
@@ -2879,7 +2878,7 @@ static int make_raw_rw_request(void)
 				printk("write\n");
 			return 0;
 		}
-	} else if (raw_cmd->length > blk_rq_sectors(current_req) << 9 ||
+	} else if (raw_cmd->length > blk_rq_bytes(current_req) ||
 		   current_count_sectors > blk_rq_sectors(current_req)) {
 		DPRINT("buffer overrun in direct transfer\n");
 		return 0;
drivers/block/nbd.c +3 -3
index 977a573..fad167d 100644
@@ -110,7 +110,7 @@ static void nbd_end_request(struct request *req)
 			req, error ? "failed" : "done");
 
 	spin_lock_irqsave(q->queue_lock, flags);
-	__blk_end_request(req, error, blk_rq_sectors(req) << 9);
+	__blk_end_request_all(req, error);
 	spin_unlock_irqrestore(q->queue_lock, flags);
 }
 
@@ -231,7 +231,7 @@ static int nbd_send_req(struct nbd_device *lo, struct request *req)
 {
 	int result, flags;
 	struct nbd_request request;
-	unsigned long size = blk_rq_sectors(req) << 9;
+	unsigned long size = blk_rq_bytes(req);
 
 	request.magic = htonl(NBD_REQUEST_MAGIC);
 	request.type = htonl(nbd_cmd(req));
@@ -243,7 +243,7 @@ static int nbd_send_req(struct nbd_device *lo, struct request *req)
 			lo->disk->disk_name, req,
 			nbdcmd_to_ascii(nbd_cmd(req)),
 			(unsigned long long)blk_rq_pos(req) << 9,
-			blk_rq_sectors(req) << 9);
+			blk_rq_bytes(req));
 	result = sock_xmit(lo, 1, &request, sizeof(request),
 			(nbd_cmd(req) == NBD_CMD_WRITE) ? MSG_MORE : 0);
 	if (result <= 0) {
drivers/block/ub.c +1 -1
index 1591f61..40d03cf 100644
@@ -739,7 +739,7 @@ static void ub_cmd_build_block(struct ub_dev *sc, struct ub_lun *lun,
 	cmd->cdb[8] = nblks;
 	cmd->cdb_len = 10;
 
-	cmd->len = blk_rq_sectors(rq) * 512;
+	cmd->len = blk_rq_bytes(rq);
 }
 
 static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun,
drivers/block/z2ram.c +1 -1
index d4e6b71..6a13838 100644
@@ -72,7 +72,7 @@ static void do_z2_request(struct request_queue *q)
 	struct request *req;
 	while ((req = elv_next_request(q)) != NULL) {
 		unsigned long start = blk_rq_pos(req) << 9;
-		unsigned long len  = blk_rq_cur_sectors(req) << 9;
+		unsigned long len  = blk_rq_cur_bytes(req);
 
 		if (start + len > z2ram_size) {
 			printk( KERN_ERR DEVICE_NAME ": bad access: block=%lu, count=%u\n",
drivers/memstick/core/mspro_block.c +2 -2
index 9e600d2..93b2c61 100644
@@ -680,7 +680,7 @@ try_again:
 		t_sec = blk_rq_pos(msb->block_req) << 9;
 		sector_div(t_sec, msb->page_size);
 
-		count = blk_rq_sectors(msb->block_req) << 9;
+		count = blk_rq_bytes(msb->block_req);
 		count /= msb->page_size;
 
 		param.system = msb->system;
@@ -745,7 +745,7 @@ static int mspro_block_complete_req(struct memstick_dev *card, int error)
 					t_len *= msb->page_size;
 			}
 		} else
-			t_len = blk_rq_sectors(msb->block_req) << 9;
+			t_len = blk_rq_bytes(msb->block_req);
 
 		dev_dbg(&card->dev, "transferred %x (%d)\n", t_len, error);
 
drivers/message/i2o/i2o_block.c +4 -12
index 6b61d28..e153f5d 100644
@@ -426,15 +426,9 @@ static void i2o_block_end_request(struct request *req, int error,
 	struct request_queue *q = req->q;
 	unsigned long flags;
 
-	if (blk_end_request(req, error, nr_bytes)) {
-		int leftover = (blk_rq_sectors(req) << KERNEL_SECTOR_SHIFT);
-
-		if (blk_pc_request(req))
-			leftover = blk_rq_bytes(req);
-
+	if (blk_end_request(req, error, nr_bytes))
 		if (error)
-			blk_end_request(req, -EIO, leftover);
-	}
+			blk_end_request_all(req, -EIO);
 
 	spin_lock_irqsave(q->queue_lock, flags);
 
@@ -832,15 +826,13 @@ static int i2o_block_transfer(struct request *req)
 
 		memcpy(mptr, cmd, 10);
 		mptr += 4;
-		*mptr++ =
-		    cpu_to_le32(blk_rq_sectors(req) << KERNEL_SECTOR_SHIFT);
+		*mptr++ = cpu_to_le32(blk_rq_bytes(req));
 	} else
 #endif
 	{
 		msg->u.head[1] = cpu_to_le32(cmd | HOST_TID << 12 | tid);
 		*mptr++ = cpu_to_le32(ctl_flags);
-		*mptr++ =
-		    cpu_to_le32(blk_rq_sectors(req) << KERNEL_SECTOR_SHIFT);
+		*mptr++ = cpu_to_le32(blk_rq_bytes(req));
 		*mptr++ =
 		    cpu_to_le32((u32) (blk_rq_pos(req) << KERNEL_SECTOR_SHIFT));
 		*mptr++ =
drivers/mtd/mtd_blkdevs.c +1 -1
index 4ea2e67..50c76a2 100644
@@ -48,7 +48,7 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
 	char *buf;
 
 	block = blk_rq_pos(req) << 9 >> tr->blkshift;
-	nsect = blk_rq_cur_sectors(req) << 9 >> tr->blkshift;
+	nsect = blk_rq_cur_bytes(req) >> tr->blkshift;
 
 	buf = req->buffer;
 
drivers/sbus/char/jsflash.c +1 -1
index 2132c90..d56ddaa 100644
@@ -189,7 +189,7 @@ static void jsfd_do_request(struct request_queue *q)
 	while ((req = elv_next_request(q)) != NULL) {
 		struct jsfd_part *jdp = req->rq_disk->private_data;
 		unsigned long offset = blk_rq_pos(req) << 9;
-		size_t len = blk_rq_cur_sectors(req) << 9;
+		size_t len = blk_rq_cur_bytes(req);
 
 		if ((offset + len) > jdp->dsize) {
 			__blk_end_request_cur(req, -EIO);
drivers/scsi/scsi_lib.c +2 -5
index 3d16c70..ee308f6 100644
@@ -546,7 +546,7 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error,
 	 * to queue the remainder of them.
 	 */
 	if (blk_end_request(req, error, bytes)) {
-		int leftover = blk_rq_sectors(req) << 9;
+		int leftover = blk_rq_bytes(req);
 
 		if (blk_pc_request(req))
 			leftover = req->resid_len;
@@ -964,10 +964,7 @@ static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb,
 	count = blk_rq_map_sg(req->q, req, sdb->table.sgl);
 	BUG_ON(count > sdb->table.nents);
 	sdb->table.nents = count;
-	if (blk_pc_request(req))
-		sdb->length = blk_rq_bytes(req);
-	else
-		sdb->length = blk_rq_sectors(req) << 9;
+	sdb->length = blk_rq_bytes(req);
 	return BLKPREP_OK;
 }
 
Signature · 1 line
1.6.0.2
#51 lore raw
In reply to Tejun Heo

Hello,

Quoted 3 lines · Tejun Heo

Upon ack, please pull from the following git tree.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git block-unify-sector-and-data_len

git tree has been updated as per comments.

* Acked-by:'s added.

* Too early blk_rq_bytes() conversion in ide-tape pushed to later patch.

Both changes are minor and don't make any difference to the final result. The new commit is f7ff5f0d7cda0b0da5e7de36dd97ff75412bbe16.

Thanks.

Signature · 1 line
tejun
#52 lore raw
Quoted 9 lines · Tejun Heo

Hello,

Quoted 3 lines · Tejun Heo

Upon ack, please pull from the following git tree.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git block-unify-sector-and-data_len

git tree has been updated as per comments.

Quoted 7 lines

* Acked-by:'s added.

* Too early blk_rq_bytes() conversion in ide-tape pushed to later patch.

Both changes are minor and don't make any difference to the final result. The new commit is f7ff5f0d7cda0b0da5e7de36dd97ff75412bbe16.

Tree updated again. Changes are...

* I forgot to convert new drivers (mg_disk and swim) to accessors. 0005-block-convert-to-pos-and-nr_sectors-accessors.patch updated to convert these new drivers.

* Acked-by added.

The new commit is 1df2a196e28cc8f97919dc530dc1c019e1d3a968.

diff f7ff5f0d..1df2a196 follows. The conversions are straight forward.

 drivers/block/mg_disk.c |   25 +++++++++++++------------
 drivers/block/swim.c    |    6 +++---
 2 files changed, 16 insertions(+), 15 deletions(-)
drivers/block/mg_disk.c +13 -12
index 71e56cc..826c349 100644
@@ -220,7 +220,8 @@ static void mg_dump_status(const char *msg, unsigned int stat,
 			if (host->breq) {
 				req = elv_next_request(host->breq);
 				if (req)
-					printk(", sector=%u", (u32)req->sector);
+					printk(", sector=%u",
+					       (unsigned int)blk_rq_pos(req));
 			}
 
 		}
@@ -493,12 +494,12 @@ static void mg_read(struct request *req)
 	u32 j;
 	struct mg_host *host = req->rq_disk->private_data;
 
-	if (mg_out(host, req->sector, req->nr_sectors, MG_CMD_RD, NULL) !=
-			MG_ERR_NONE)
+	if (mg_out(host, blk_rq_pos(req), blk_rq_sectors(req),
+		   MG_CMD_RD, NULL) != MG_ERR_NONE)
 		mg_bad_rw_intr(host);
 
 	MG_DBG("requested %d sects (from %ld), buffer=0x%p\n",
-	       req->nr_sectors, req->sector, req->buffer);
+	       blk_rq_sectors(req), blk_rq_pos(req), req->buffer);
 
 	do {
 		u16 *buff = (u16 *)req->buffer;
@@ -522,14 +523,14 @@ static void mg_write(struct request *req)
 	u32 j;
 	struct mg_host *host = req->rq_disk->private_data;
 
-	if (mg_out(host, req->sector, req->nr_sectors, MG_CMD_WR, NULL) !=
-			MG_ERR_NONE) {
+	if (mg_out(host, blk_rq_pos(req), blk_rq_sectors(req),
+		   MG_CMD_WR, NULL) != MG_ERR_NONE) {
 		mg_bad_rw_intr(host);
 		return;
 	}
 
 	MG_DBG("requested %d sects (from %ld), buffer=0x%p\n",
-	       req->nr_sectors, req->sector, req->buffer);
+	       blk_rq_sectors(req), blk_rq_pos(req), req->buffer);
 
 	do {
 		u16 *buff = (u16 *)req->buffer;
@@ -579,7 +580,7 @@ ok_to_read:
 			      (i << 1));
 
 	MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n",
-			req->sector, req->nr_sectors - 1, req->buffer);
+	       blk_rq_pos(req), blk_rq_sectors(req) - 1, req->buffer);
 
 	/* send read confirm */
 	outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND);
@@ -609,7 +610,7 @@ static void mg_write_intr(struct mg_host *host)
 			break;
 		if (!MG_READY_OK(i))
 			break;
-		if ((req->nr_sectors <= 1) || (i & ATA_DRQ))
+		if ((blk_rq_sectors(req) <= 1) || (i & ATA_DRQ))
 			goto ok_to_write;
 	} while (0);
 	mg_dump_status("mg_write_intr", i, host);
@@ -627,7 +628,7 @@ ok_to_write:
 			buff++;
 		}
 		MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n",
-				req->sector, req->nr_sectors, req->buffer);
+		       blk_rq_pos(req), blk_rq_sectors(req), req->buffer);
 		host->mg_do_intr = mg_write_intr;
 		mod_timer(&host->timer, jiffies + 3 * HZ);
 	}
@@ -749,9 +750,9 @@ static void mg_request(struct request_queue *q)
 
 		del_timer(&host->timer);
 
-		sect_num = req->sector;
+		sect_num = blk_rq_pos(req);
 		/* deal whole segments */
-		sect_cnt = req->nr_sectors;
+		sect_cnt = blk_rq_sectors(req);
 
 		/* sanity check */
 		if (sect_num >= get_capacity(req->rq_disk) ||
drivers/block/swim.c +3 -3
index 97ef426..fc6a1c3 100644
@@ -531,7 +531,7 @@ static void redo_fd_request(struct request_queue *q)
 	while ((req = elv_next_request(q))) {
 
 		fs = req->rq_disk->private_data;
-		if (req->sector < 0 || req->sector >= fs->total_secs) {
+		if (blk_rq_pos(req) >= fs->total_secs) {
 			__blk_end_request_cur(req, -EIO);
 			continue;
 		}
@@ -551,8 +551,8 @@ static void redo_fd_request(struct request_queue *q)
 			__blk_end_request_cur(req, -EIO);
 			break;
 		case READ:
-			if (floppy_read_sectors(fs, req->sector,
-						req->current_nr_sectors,
+			if (floppy_read_sectors(fs, blk_rq_pos(req),
+						blk_rq_cur_sectors(req),
 						req->buffer)) {
 				__blk_end_request_cur(req, -EIO);
 				continue;
Signature · 1 line
tejun
maintainer
#53 lore raw
In reply to Tejun Heo
Quoted 11 lines · On Mon, 4 May 2009 16:58:36 +0900 Tejun Heo <[email protected]> wrote:

Hello,

Upon ack, please pull from the following git tree.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git block-unify-sector-and-data_len

This is the second take of block-unify-sector-and-data_len patchset. The primary goal of this patchset is to consolidate all the similar bug slightly different current position and data length fields in struct request. For detailed description, please read the description in the last take[L]. Changes from the last take[L] are

Looks really nice. Finally, the block insulates the internal! SCSI did two years ago ;)

maintainer
#54 lore raw
Quoted 9 lines · On Thu, 7 May 2009 19:23:34 +0900 FUJITA Tomonori…
Quoted 6 lines · On Mon, 4 May 2009 16:58:36 +0900 Tejun Heo <[email protected]> wrote:

Hello,

Upon ack, please pull from the following git tree.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git block-unify-sector-and-data_len

Quoted 8 lines
Quoted 5 lines

This is the second take of block-unify-sector-and-data_len patchset. The primary goal of this patchset is to consolidate all the similar bug slightly different current position and data length fields in struct request. For detailed description, please read the description in the last take[L]. Changes from the last take[L] are

Looks really nice. Finally, the block insulates the internal! SCSI did two years ago ;)

btw, you are still working on the cleanups of the block API, right?

I also want to see some cleanups of request completion functions a bit (e.g. we don't need _bidi_ stuff, we have too many completion functions, etc...).

author
#55 lore raw

Hello,

Quoted 1 line · FUJITA Tomonori

btw, you are still working on the cleanups of the block API, right?

The patchset I sent out today was the last large cleanup patchset I had waiting. I think I'm now ready to move onto adding new features.

Quoted 3 lines

I also want to see some cleanups of request completion functions a bit (e.g. we don't need _bidi_ stuff, we have too many completion functions, etc...).

Hmmm... the bidi stuff not being used widely, I didn't pay too much attention to it. What do you have in mind? Can you elaborate a bit? We changed the API a lot anyway so if there's more to do doing it now wouldn't be a bad idea.

Thanks.

Signature · 1 line
tejun
#56 lore raw
In reply to Tejun Heo
Quoted 125 lines · Tejun Heo

Hello,

Upon ack, please pull from the following git tree.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git block-unify-sector-and-data_len

This is the second take of block-unify-sector-and-data_len patchset. The primary goal of this patchset is to consolidate all the similar bug slightly different current position and data length fields in struct request. For detailed description, please read the description in the last take[L]. Changes from the last take[L] are

* Acked-by:'s added

* osd resid_len conversion was missing as pointed out by Boaz Harrosh, fixed.

* patch to cleanup request length accessor usages after the conversion added.

This patchset contains the following eleven patches.

0001-nbd-don-t-clear-rq-sector-and-nr_sectors-unnecessa.patch 0002-ide-tape-don-t-initialize-rq-sector-for-rw-request.patch 0003-block-add-rq-resid_len.patch 0004-block-implement-blk_rq_pos-cur_-sectors-and-conv.patch 0005-block-convert-to-pos-and-nr_sectors-accessors.patch 0006-ide-convert-to-rq-pos-and-nr_sectors-accessors.patch 0007-block-drop-request-hard_-and-nr_sectors.patch 0008-block-cleanup-rq-data_len-usages.patch 0009-ide-cleanup-rq-data_len-usages.patch 0010-block-hide-request-sector-and-data_len.patch 0011-block-blk_rq_-cur_-_-sectors-bytes-usage-cleanup.patch

This patchset is on top of

linux-2.6-block#for-2.6.31 (f68adec3c7155a8bbf32a90cb4c4d0737df045d9)
+ linux-2.6-ide#for-next (03682411b1ccd38cbde2e9a6ab43884ff34fbefc)

and contains the following changes.

 arch/um/drivers/ubd_kern.c               |    2 
 block/as-iosched.c                       |   18 +++--
 block/blk-barrier.c                      |    4 -
 block/blk-core.c                         |  100 ++++++++++++-------------------
 block/blk-map.c                          |    2 
 block/blk-merge.c                        |   46 ++------------
 block/blk.h                              |    1 
 block/bsg.c                              |    8 +-
 block/cfq-iosched.c                      |   30 ++++-----
 block/deadline-iosched.c                 |    2 
 block/elevator.c                         |   22 +++---
 block/scsi_ioctl.c                       |    2 
 drivers/ata/libata-scsi.c                |    2 
 drivers/block/DAC960.c                   |    6 -
 drivers/block/amiflop.c                  |    6 -
 drivers/block/ataflop.c                  |   10 +--
 drivers/block/cciss.c                    |   35 ++++------
 drivers/block/cpqarray.c                 |    9 +-
 drivers/block/floppy.c                   |   54 ++++++++--------
 drivers/block/hd.c                       |   14 ++--
 drivers/block/nbd.c                      |   19 +----
 drivers/block/paride/pcd.c               |    4 -
 drivers/block/paride/pd.c                |    8 +-
 drivers/block/paride/pf.c                |    8 +-
 drivers/block/ps3disk.c                  |    9 +-
 drivers/block/sunvdc.c                   |    2 
 drivers/block/swim3.c                    |   34 +++++-----
 drivers/block/sx8.c                      |    6 -
 drivers/block/ub.c                       |   16 ++--
 drivers/block/viodasd.c                  |    8 +-
 drivers/block/virtio_blk.c               |    2 
 drivers/block/xd.c                       |    4 -
 drivers/block/xen-blkfront.c             |   11 +--
 drivers/block/xsysace.c                  |   25 ++++---
 drivers/block/z2ram.c                    |    6 -
 drivers/cdrom/gdrom.c                    |    6 -
 drivers/cdrom/viocd.c                    |    2 
 drivers/ide/ide-atapi.c                  |   13 ----
 drivers/ide/ide-cd.c                     |   44 ++++---------
 drivers/ide/ide-disk.c                   |    8 +-
 drivers/ide/ide-dma.c                    |    2 
 drivers/ide/ide-floppy.c                 |   10 +--
 drivers/ide/ide-io.c                     |   10 +--
 drivers/ide/ide-lib.c                    |    2 
 drivers/ide/ide-tape.c                   |   11 +--
 drivers/ide/ide-taskfile.c               |    2 
 drivers/ide/pdc202xx_old.c               |    2 
 drivers/ide/tc86c001.c                   |    2 
 drivers/ide/tx4939ide.c                  |    2 
 drivers/memstick/core/mspro_block.c      |    6 -
 drivers/message/fusion/mptsas.c          |   21 +++---
 drivers/message/i2o/i2o_block.c          |   28 +++-----
 drivers/mmc/card/block.c                 |   10 +--
 drivers/mtd/mtd_blkdevs.c                |    7 +-
 drivers/s390/block/dasd.c                |    2 
 drivers/s390/block/dasd_diag.c           |    5 -
 drivers/s390/block/dasd_eckd.c           |    6 -
 drivers/s390/block/dasd_fba.c            |    7 +-
 drivers/s390/char/tape_34xx.c            |    2 
 drivers/s390/char/tape_3590.c            |    2 
 drivers/s390/char/tape_block.c           |    2 
 drivers/sbus/char/jsflash.c              |    4 -
 drivers/scsi/eata.c                      |   24 +++----
 drivers/scsi/libsas/sas_expander.c       |   14 +---
 drivers/scsi/libsas/sas_host_smp.c       |   52 ++++++++--------
 drivers/scsi/lpfc/lpfc_scsi.c            |   22 +++---
 drivers/scsi/mpt2sas/mpt2sas_transport.c |   23 +++----
 drivers/scsi/osd/osd_initiator.c         |    4 -
 drivers/scsi/scsi_lib.c                  |   46 ++++++--------
 drivers/scsi/scsi_tgt_lib.c              |    2 
 drivers/scsi/sd.c                        |   24 +++----
 drivers/scsi/sd_dif.c                    |    2 
 drivers/scsi/sg.c                        |    2 
 drivers/scsi/sr.c                        |   15 ++--
 drivers/scsi/st.c                        |    2 
 drivers/scsi/u14-34f.c                   |   22 +++---
 fs/exofs/osd.c                           |    4 -
 include/linux/bio.h                      |    6 -
 include/linux/blkdev.h                   |   56 ++++++++++-------
 include/linux/elevator.h                 |    2 
 include/scsi/scsi_cmnd.h                 |    2 
 kernel/trace/blktrace.c                  |   16 ++--
 82 files changed, 508 insertions(+), 585 deletions(-)
Quoted 6 lines

Thanks.

--
tejun

[L] http://lkml.org/lkml/2009/4/29/173

Hi Tejun

I've inspected all scsi touching patches and refrained from comments on the simple rename bunch. They all look very good accept that one place. (which will effect 2 patches)

There are few more places that can use blk_end_request_all() after these changes.

(The same internet outage on this reply)

Thanks
Boaz

author
#57 lore raw

Hello, Boaz.

Quoted 8 lines · Boaz Harrosh

I've inspected all scsi touching patches and refrained from comments on the simple rename bunch. They all look very good accept that one place. (which will effect 2 patches)

There are few more places that can use blk_end_request_all() after these changes.

(The same internet outage on this reply)

The tree is now in Jens' tree, so it won't be rebased from this point on. Please go ahead and submit patches.

Thanks.

Signature · 1 line
tejun