aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorPete Zaitcev <zaitcev@redhat.com>2006-09-07 19:54:22 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2006-09-27 14:58:57 -0400
commitd1ad4ea331e78a5ff90eda7718da31bcbc1a9c38 (patch)
tree4f12208aa12a3cb2ccf066862474f7ef0ed0f999 /drivers/block
parent14acdcd32160767d7f2fa00803d2d764d3e3373a (diff)
USB: UB: Let cdrecord to see a device with media absent
The command "cdrecord dev=/dev/uba x.iso" prints nasty garbage if a blank is not in the drive. This happens because drivers have to set req->errors separately from just returning zero uptodate with end_that_request_first, end_that_request_last. These functions only set error in BIO, but sg_io() ignores it. Since we're on it, let cdrecord access a device when ->changed is set. It's useful if someone wants to know device capabilities without burning anything. Signed-Off-By: Pete Zaitcev <zaitcev@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/ub.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index d62b49fbf10c..45a8f402b07b 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -358,7 +358,7 @@ static void ub_cmd_build_block(struct ub_dev *sc, struct ub_lun *lun,
358static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun, 358static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun,
359 struct ub_scsi_cmd *cmd, struct ub_request *urq); 359 struct ub_scsi_cmd *cmd, struct ub_request *urq);
360static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd); 360static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd);
361static void ub_end_rq(struct request *rq, int uptodate); 361static void ub_end_rq(struct request *rq, unsigned int status);
362static int ub_rw_cmd_retry(struct ub_dev *sc, struct ub_lun *lun, 362static int ub_rw_cmd_retry(struct ub_dev *sc, struct ub_lun *lun,
363 struct ub_request *urq, struct ub_scsi_cmd *cmd); 363 struct ub_request *urq, struct ub_scsi_cmd *cmd);
364static int ub_submit_scsi(struct ub_dev *sc, struct ub_scsi_cmd *cmd); 364static int ub_submit_scsi(struct ub_dev *sc, struct ub_scsi_cmd *cmd);
@@ -639,9 +639,15 @@ static int ub_request_fn_1(struct ub_lun *lun, struct request *rq)
639 struct ub_request *urq; 639 struct ub_request *urq;
640 int n_elem; 640 int n_elem;
641 641
642 if (atomic_read(&sc->poison) || lun->changed) { 642 if (atomic_read(&sc->poison)) {
643 blkdev_dequeue_request(rq);
644 ub_end_rq(rq, DID_NO_CONNECT << 16);
645 return 0;
646 }
647
648 if (lun->changed && !blk_pc_request(rq)) {
643 blkdev_dequeue_request(rq); 649 blkdev_dequeue_request(rq);
644 ub_end_rq(rq, 0); 650 ub_end_rq(rq, SAM_STAT_CHECK_CONDITION);
645 return 0; 651 return 0;
646 } 652 }
647 653
@@ -693,7 +699,7 @@ static int ub_request_fn_1(struct ub_lun *lun, struct request *rq)
693 699
694drop: 700drop:
695 ub_put_cmd(lun, cmd); 701 ub_put_cmd(lun, cmd);
696 ub_end_rq(rq, 0); 702 ub_end_rq(rq, DID_ERROR << 16);
697 return 0; 703 return 0;
698} 704}
699 705
@@ -761,47 +767,53 @@ static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
761 struct ub_lun *lun = cmd->lun; 767 struct ub_lun *lun = cmd->lun;
762 struct ub_request *urq = cmd->back; 768 struct ub_request *urq = cmd->back;
763 struct request *rq; 769 struct request *rq;
764 int uptodate; 770 unsigned int scsi_status;
765 771
766 rq = urq->rq; 772 rq = urq->rq;
767 773
768 if (cmd->error == 0) { 774 if (cmd->error == 0) {
769 uptodate = 1;
770
771 if (blk_pc_request(rq)) { 775 if (blk_pc_request(rq)) {
772 if (cmd->act_len >= rq->data_len) 776 if (cmd->act_len >= rq->data_len)
773 rq->data_len = 0; 777 rq->data_len = 0;
774 else 778 else
775 rq->data_len -= cmd->act_len; 779 rq->data_len -= cmd->act_len;
776 } 780 }
781 scsi_status = 0;
777 } else { 782 } else {
778 uptodate = 0;
779
780 if (blk_pc_request(rq)) { 783 if (blk_pc_request(rq)) {
781 /* UB_SENSE_SIZE is smaller than SCSI_SENSE_BUFFERSIZE */ 784 /* UB_SENSE_SIZE is smaller than SCSI_SENSE_BUFFERSIZE */
782 memcpy(rq->sense, sc->top_sense, UB_SENSE_SIZE); 785 memcpy(rq->sense, sc->top_sense, UB_SENSE_SIZE);
783 rq->sense_len = UB_SENSE_SIZE; 786 rq->sense_len = UB_SENSE_SIZE;
784 if (sc->top_sense[0] != 0) 787 if (sc->top_sense[0] != 0)
785 rq->errors = SAM_STAT_CHECK_CONDITION; 788 scsi_status = SAM_STAT_CHECK_CONDITION;
786 else 789 else
787 rq->errors = DID_ERROR << 16; 790 scsi_status = DID_ERROR << 16;
788 } else { 791 } else {
789 if (cmd->error == -EIO) { 792 if (cmd->error == -EIO) {
790 if (ub_rw_cmd_retry(sc, lun, urq, cmd) == 0) 793 if (ub_rw_cmd_retry(sc, lun, urq, cmd) == 0)
791 return; 794 return;
792 } 795 }
796 scsi_status = SAM_STAT_CHECK_CONDITION;
793 } 797 }
794 } 798 }
795 799
796 urq->rq = NULL; 800 urq->rq = NULL;
797 801
798 ub_put_cmd(lun, cmd); 802 ub_put_cmd(lun, cmd);
799 ub_end_rq(rq, uptodate); 803 ub_end_rq(rq, scsi_status);
800 blk_start_queue(lun->disk->queue); 804 blk_start_queue(lun->disk->queue);
801} 805}
802 806
803static void ub_end_rq(struct request *rq, int uptodate) 807static void ub_end_rq(struct request *rq, unsigned int scsi_status)
804{ 808{
809 int uptodate;
810
811 if (scsi_status == 0) {
812 uptodate = 1;
813 } else {
814 uptodate = 0;
815 rq->errors = scsi_status;
816 }
805 end_that_request_first(rq, uptodate, rq->hard_nr_sectors); 817 end_that_request_first(rq, uptodate, rq->hard_nr_sectors);
806 end_that_request_last(rq, uptodate); 818 end_that_request_last(rq, uptodate);
807} 819}