From: Borislav Petkov <petkovbb@googlemail.com>
To: bzolnier@gmail.com
Cc: linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org,
Borislav Petkov <petkovbb@gmail.com>
Subject: [PATCH 04/18] ide-cd: cdrom_decode_status: factor out fs request error handling code
Date: Thu, 12 Jun 2008 08:40:56 +0200 [thread overview]
Message-ID: <1213252870-20474-5-git-send-email-petkovbb@gmail.com> (raw)
In-Reply-To: <1213252870-20474-1-git-send-email-petkovbb@gmail.com>
... into cdrom_handle_failed_fs_req(). There's a slight change in internal
functionality in the case when we have sense NOT_READY and the request is WRITE: the
original function cdrom_decode_status returned 1 in this case, which means "request
was ended." We accomplish the same by returning 0 instead, which falls through in the
if..else block and the surrounding cdrom_decode_status() returns 1 at the end instead
of jumping to the end_request label as is in all the other cases, so no change
in obvious functionality.
Signed-off-by: Borislav Petkov <petkovbb@gmail.com>
---
drivers/ide/ide-cd.c | 206 +++++++++++++++++++++++++++-----------------------
1 files changed, 111 insertions(+), 95 deletions(-)
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 16c4ce9..e63eea2 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -314,12 +314,115 @@ static int cdrom_handle_failed_pc_req(ide_drive_t *drive, struct request *rq,
return 1;
}
-
/*
- * Returns:
- * 0: if the request should be continued.
- * 1: if the request was ended.
+ * Handle errors from READ and WRITE requests. Do a request sense analysis when
+ * we have sense data. We need this in order to perform end of media processing.
*/
+static int cdrom_handle_failed_fs_req(ide_drive_t *drive, struct request *rq,
+ int sense_key, int stat)
+{
+ int err = 0;
+
+ if (blk_noretry_request(rq))
+ err = 1;
+
+ switch (sense_key) {
+ case NOT_READY:
+ /* tray open */
+ if (rq_data_dir(rq) == READ) {
+ cdrom_saw_media_change(drive);
+
+ /* fail the request */
+ printk(KERN_ERR "%s: tray open\n", drive->name);
+ err = 1;
+ } else {
+ struct cdrom_info *info = drive->driver_data;
+
+ /*
+ * Allow the drive 5 seconds to recover, some devices
+ * will return this error while flushing data from
+ * cache.
+ */
+ if (!rq->errors)
+ info->write_timeout = jiffies +
+ ATAPI_WAIT_WRITE_BUSY;
+ rq->errors = 1;
+
+ if (time_after(jiffies, info->write_timeout))
+ err = 1;
+ else {
+ unsigned long flags;
+
+ /*
+ * take a breather relying on the unplug timer
+ * to kick us again
+ */
+ spin_lock_irqsave(&ide_lock, flags);
+ blk_plug_device(drive->queue);
+ spin_unlock_irqrestore(&ide_lock, flags);
+ err = 0;
+ }
+ }
+ break;
+
+ case UNIT_ATTENTION:
+ /* media change */
+ cdrom_saw_media_change(drive);
+
+ /*
+ * Arrange to retry the request but be sure to give up if we've
+ * retried too many times.
+ */
+ if (++rq->errors > ERROR_MAX)
+ err = 1;
+ break;
+
+ case ILLEGAL_REQUEST:
+ case DATA_PROTECT:
+
+ /*
+ * No point in retrying after an illegal request or data
+ * protect error.
+ */
+ ide_dump_status_no_sense(drive, "command error", stat);
+ err = 1;
+ break;
+
+ case MEDIUM_ERROR:
+
+ /*
+ * No point in re-trying a zillion times on a bad sector. If we
+ * got here the error is not correctable.
+ */
+ ide_dump_status_no_sense(drive, "media error (bad sector)",
+ stat);
+ err = 1;
+ break;
+
+ case BLANK_CHECK:
+
+ /* disk appears blank ?? */
+ ide_dump_status_no_sense(drive, "media error (blank)", stat);
+ err = 1;
+ break;
+
+ default:
+ break;
+ }
+
+ if ((err & ~ABRT_ERR) != 0) {
+ /* go to the default handler for other errors */
+ ide_error(drive, "cdrom_handle_failed_fs_req", stat);
+ err = 1;
+ } else if ((++rq->errors > ERROR_MAX))
+
+ /* we've racked up too many retries, abort */
+ err = 1;
+
+ return err;
+}
+
+/* Returns 0 if the request should be continued, 1 otherwise. */
static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
{
struct request *rq = HWGROUP(drive)->rq;
@@ -363,104 +466,17 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
return 0;
} else if (blk_fs_request(rq)) {
- int do_end_request = 0;
-
- /* handle errors from READ and WRITE requests */
-
- if (blk_noretry_request(rq))
- do_end_request = 1;
-
- if (sense_key == NOT_READY) {
- /* tray open */
- if (rq_data_dir(rq) == READ) {
- cdrom_saw_media_change(drive);
- /* fail the request */
- printk(KERN_ERR "%s: tray open\n", drive->name);
- do_end_request = 1;
- } else {
- struct cdrom_info *info = drive->driver_data;
-
- /*
- * Allow the drive 5 seconds to recover, some
- * devices will return this error while flushing
- * data from cache.
- */
- if (!rq->errors)
- info->write_timeout = jiffies +
- ATAPI_WAIT_WRITE_BUSY;
- rq->errors = 1;
- if (time_after(jiffies, info->write_timeout))
- do_end_request = 1;
- else {
- unsigned long flags;
-
- /*
- * take a breather relying on the unplug
- * timer to kick us again
- */
- spin_lock_irqsave(&ide_lock, flags);
- blk_plug_device(drive->queue);
- spin_unlock_irqrestore(&ide_lock,
- flags);
- return 1;
- }
- }
- } else if (sense_key == UNIT_ATTENTION) {
- /* media change */
- cdrom_saw_media_change(drive);
-
- /*
- * Arrange to retry the request but be sure to give up
- * if we've retried too many times.
- */
- if (++rq->errors > ERROR_MAX)
- do_end_request = 1;
- } else if (sense_key == ILLEGAL_REQUEST ||
- sense_key == DATA_PROTECT) {
- /*
- * No point in retrying after an illegal request or data
- * protect error.
- */
- ide_dump_status_no_sense(drive, "command error", stat);
- do_end_request = 1;
- } else if (sense_key == MEDIUM_ERROR) {
- /*
- * No point in re-trying a zillion times on a bad
- * sector. If we got here the error is not correctable.
- */
- ide_dump_status_no_sense(drive,
- "media error (bad sector)",
- stat);
- do_end_request = 1;
- } else if (sense_key == BLANK_CHECK) {
- /* disk appears blank ?? */
- ide_dump_status_no_sense(drive, "media error (blank)",
- stat);
- do_end_request = 1;
- } else if ((err & ~ABRT_ERR) != 0) {
- /* go to the default handler for other errors */
- ide_error(drive, "cdrom_decode_status", stat);
- return 1;
- } else if ((++rq->errors > ERROR_MAX)) {
- /* we've racked up too many retries, abort */
- do_end_request = 1;
- }
-
- /*
- * End a request through request sense analysis when we have
- * sense data. We need this in order to perform end of media
- * processing.
- */
- if (do_end_request)
+ if (cdrom_handle_failed_fs_req(drive, rq, sense_key, stat))
goto end_request;
/*
- * If we got a CHECK_CONDITION status, queue
- * a request sense command.
+ * If we got a CHECK_CONDITION status, queue a request sense
+ * command.
*/
if (stat & ERR_STAT)
cdrom_queue_request_sense(drive, NULL, NULL);
+
} else {
blk_dump_rq_flags(rq, "ide-cd: bad rq");
cdrom_end_request(drive, 0);
--
1.5.5.1
next prev parent reply other threads:[~2008-06-12 6:41 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-12 6:40 [PATCH 00/18] misc generic ide stuff Borislav Petkov
2008-06-12 6:40 ` [PATCH 01/18] ide-cd: remove wait-for-idle-controller bit in cdrom_start_packet_command Borislav Petkov
2008-06-12 6:40 ` [PATCH 02/18] ide-cd: remove ide_cd_drain_data and ide_cd_pad_transfer Borislav Petkov
2008-06-14 17:29 ` Bartlomiej Zolnierkiewicz
2008-06-15 9:28 ` Borislav Petkov
2008-06-12 6:40 ` [PATCH 03/18] ide-cd: cdrom_decode_status: factor out block pc error handling code Borislav Petkov
2008-06-14 17:29 ` Bartlomiej Zolnierkiewicz
2008-08-15 7:34 ` Borislav Petkov
2008-08-16 20:26 ` Borislav Petkov
2008-08-15 7:34 ` Borislav Petkov
2008-06-12 6:40 ` Borislav Petkov [this message]
2008-06-12 6:40 ` [PATCH 05/18] ide-cd: ide_do_rw_cdrom: add the catch-all bad request case to the if-else block Borislav Petkov
2008-06-12 6:40 ` [PATCH 06/18] ide-cd: cdrom_start_seek: remove unused argument block Borislav Petkov
2008-06-12 6:40 ` [PATCH 07/18] ide-cd: mv ide_do_rw_cdrom ide_cd_do_request Borislav Petkov
2008-06-12 6:41 ` [PATCH 08/18] ide-cd: simplify request issuing path Borislav Petkov
2008-06-12 6:41 ` [PATCH 09/18] ide-cd: fold cdrom_start_seek into ide_cd_do_request Borislav Petkov
2008-06-12 6:41 ` [PATCH 10/18] ide-cd: move request prep from cdrom_start_seek_continuation to rq issue path Borislav Petkov
2008-06-12 6:41 ` [PATCH 11/18] ide-cd: move request prep from cdrom_start_rw_cont " Borislav Petkov
2008-06-12 6:41 ` [PATCH 12/18] ide-cd: move request prep chunk from cdrom_do_newpc_cont " Borislav Petkov
2008-06-12 6:41 ` [PATCH 13/18] ide-floppy: replace pc->c with rq->cmd Borislav Petkov
2008-06-14 17:40 ` Bartlomiej Zolnierkiewicz
2008-06-15 10:21 ` Borislav Petkov
2008-06-15 14:57 ` Bartlomiej Zolnierkiewicz
2008-06-12 6:41 ` [PATCH 14/18] ide-floppy: fold idefloppy_create_test_unit_ready_cmd into idefloppy_open Borislav Petkov
2008-06-12 6:41 ` [PATCH 15/18] ide-floppy: zero out the whole struct ide_atapi_pc on init Borislav Petkov
2008-06-12 6:41 ` [PATCH 16/18] ide-floppy: pass rq instead of pc to idefloppy_issue_pc Borislav Petkov
2008-06-12 6:41 ` [PATCH 17/18] ide-floppy: cleanup idefloppy_create_rw_cmd Borislav Petkov
2008-06-12 6:41 ` [PATCH 18/18] ide: use flags in IRQ handler Borislav Petkov
2008-06-14 17:47 ` Bartlomiej Zolnierkiewicz
2008-06-14 17:29 ` [PATCH 00/18] misc generic ide stuff Bartlomiej Zolnierkiewicz
2008-06-15 10:27 ` Borislav Petkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1213252870-20474-5-git-send-email-petkovbb@gmail.com \
--to=petkovbb@googlemail.com \
--cc=bzolnier@gmail.com \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=petkovbb@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).