Skip to content

Commit da071b4

Browse files
htejunJeff Garzik
authored andcommitted
libata: fix shutdown warning message printing
Unlocking ap->lock and ssleeping don't work because SCSI commands can be issued from completion path without context. Reimplement delayed completion by allowing translation functions to override qc->scsidone(), storing the original completion function to scmd->scsi_done() and overriding qc->scsidone() with a function which schedules delayed invocation of scmd->scsi_done(). This isn't pretty at all but all the ugly parts are thankfully contained in the stop translation path where the compat feature is implemented. Signed-off-by: Tejun Heo <htejun@gmail.com> Signed-off-by: Jeff Garzik <jeff@garzik.org>
1 parent 3cadbcc commit da071b4

1 file changed

Lines changed: 27 additions & 8 deletions

File tree

‎drivers/ata/libata-scsi.c‎

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,23 @@ int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth)
893893
return queue_depth;
894894
}
895895

896+
/* XXX: for ata_spindown_compat */
897+
static void ata_delayed_done_timerfn(unsigned long arg)
898+
{
899+
struct scsi_cmnd *scmd = (void *)arg;
900+
901+
scmd->scsi_done(scmd);
902+
}
903+
904+
/* XXX: for ata_spindown_compat */
905+
static void ata_delayed_done(struct scsi_cmnd *scmd)
906+
{
907+
static struct timer_list timer;
908+
909+
setup_timer(&timer, ata_delayed_done_timerfn, (unsigned long)scmd);
910+
mod_timer(&timer, jiffies + 5 * HZ);
911+
}
912+
896913
/**
897914
* ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command
898915
* @qc: Storage for translated ATA taskfile
@@ -952,19 +969,21 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc)
952969
if (ata_spindown_compat &&
953970
(system_state == SYSTEM_HALT ||
954971
system_state == SYSTEM_POWER_OFF)) {
955-
static int warned = 0;
972+
static unsigned long warned = 0;
956973

957-
if (!warned) {
958-
spin_unlock_irq(qc->ap->lock);
974+
if (!test_and_set_bit(0, &warned)) {
959975
ata_dev_printk(qc->dev, KERN_WARNING,
960976
"DISK MIGHT NOT BE SPUN DOWN PROPERLY. "
961977
"UPDATE SHUTDOWN UTILITY\n");
962978
ata_dev_printk(qc->dev, KERN_WARNING,
963979
"For more info, visit "
964980
"http://linux-ata.org/shutdown.html\n");
965-
warned = 1;
966-
ssleep(5);
967-
spin_lock_irq(qc->ap->lock);
981+
982+
/* ->scsi_done is not used, use it for
983+
* delayed completion.
984+
*/
985+
scmd->scsi_done = qc->scsidone;
986+
qc->scsidone = ata_delayed_done;
968987
}
969988
scmd->result = SAM_STAT_GOOD;
970989
return 1;
@@ -1488,14 +1507,14 @@ static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,
14881507

14891508
early_finish:
14901509
ata_qc_free(qc);
1491-
done(cmd);
1510+
qc->scsidone(cmd);
14921511
DPRINTK("EXIT - early finish (good or error)\n");
14931512
return 0;
14941513

14951514
err_did:
14961515
ata_qc_free(qc);
14971516
cmd->result = (DID_ERROR << 16);
1498-
done(cmd);
1517+
qc->scsidone(cmd);
14991518
err_mem:
15001519
DPRINTK("EXIT - internal\n");
15011520
return 0;

0 commit comments

Comments
 (0)