From 1f9595e358e96b3faa38e52bbd8f93e4b53109d3 Mon Sep 17 00:00:00 2001
From: chrfranke <chrfranke@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Sat, 20 Oct 2007 13:02:51 +0000
Subject: [PATCH] smartd: Don't start self tests in first pass to avoid
 performance problems during boot.

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@2430 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 sm5/CHANGELOG        |  6 +++++-
 sm5/smartd.8.in      |  8 ++++++--
 sm5/smartd.conf.5.in |  8 ++++++--
 sm5/smartd.cpp       | 25 +++++++++++++------------
 4 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/sm5/CHANGELOG b/sm5/CHANGELOG
index 2ae11453b..4a1f0d792 100644
--- a/sm5/CHANGELOG
+++ b/sm5/CHANGELOG
@@ -1,6 +1,6 @@
 CHANGELOG for smartmontools
 
-$Id: CHANGELOG,v 1.633 2007/09/14 20:52:14 chrfranke Exp $
+$Id: CHANGELOG,v 1.634 2007/10/20 13:02:50 chrfranke Exp $
 
 The most recent version of this file is:
 http://smartmontools.cvs.sourceforge.net/smartmontools/sm5/CHANGELOG?view=markup
@@ -33,6 +33,10 @@ NOTES FOR FUTURE RELEASES: see TODO file.
 
 <DEVELOPERS: ADDITIONS TO THE CHANGE LOG GO JUST BELOW HERE, PLEASE>
 
+  [CF] smartd: Don't start self tests in first pass to avoid
+       performance problems during boot.
+       https://bugzilla.novell.com/show_bug.cgi?id=192591
+
   [CF] Fixed regression in SMART STATUS command on Win9x/ME.
 
   [BA] Fixed 3ware issue with new controllers.  Documentation said
diff --git a/sm5/smartd.8.in b/sm5/smartd.8.in
index 240420d65..761aa3c95 100644
--- a/sm5/smartd.8.in
+++ b/sm5/smartd.8.in
@@ -1,7 +1,7 @@
 .ig
 Copyright (C) 2002-7 Bruce Allen <smartmontools-support@lists.sourceforge.net>
  
-$Id: smartd.8.in,v 1.118 2007/09/06 08:48:55 ballen4705 Exp $
+$Id: smartd.8.in,v 1.119 2007/10/20 13:02:50 chrfranke Exp $
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -939,6 +939,10 @@ interrupted to begin another test.
 \fBsmartd\fP will not attempt to run \fBany\fP type of test if another
 test was already started or run in the same hour.
 
+To avoid performance problems during system boot, \fBsmartd\fP will
+not attempt to run any scheduled tests following the very first
+device polling (unless \'\-q onecheck\' is specified).
+
 Each time a test is run, \fBsmartd\fP will log an entry to SYSLOG.
 You can use these or the '-q showtests' command-line option to verify
 that you constructed \fBREGEXP\fP correctly.  The matching order
@@ -1951,4 +1955,4 @@ smartmontools home page at \fBhttp://smartmontools.sourceforge.net/#references\f
 
 .SH
 CVS ID OF THIS PAGE:
-$Id: smartd.8.in,v 1.118 2007/09/06 08:48:55 ballen4705 Exp $
+$Id: smartd.8.in,v 1.119 2007/10/20 13:02:50 chrfranke Exp $
diff --git a/sm5/smartd.conf.5.in b/sm5/smartd.conf.5.in
index a13a7605c..db65ad289 100644
--- a/sm5/smartd.conf.5.in
+++ b/sm5/smartd.conf.5.in
@@ -1,7 +1,7 @@
 .ig
 Copyright (C) 2002-7 Bruce Allen <smartmontools-support@lists.sourceforge.net>
 
-$Id: smartd.conf.5.in,v 1.85 2007/09/14 20:48:18 chrfranke Exp $
+$Id: smartd.conf.5.in,v 1.86 2007/10/20 13:02:50 chrfranke Exp $
 
 This program is free software; you can redistribute it and/or modify it
 under the terms of the GNU General Public License as published by the Free
@@ -571,6 +571,10 @@ interrupted to begin another test.
 \fBsmartd\fP will not attempt to run \fBany\fP type of test if another
 test was already started or run in the same hour.
 
+To avoid performance problems during system boot, \fBsmartd\fP will
+not attempt to run any scheduled tests following the very first
+device polling (unless \'\-q onecheck\' is specified).
+
 Each time a test is run, \fBsmartd\fP will log an entry to SYSLOG.
 You can use these or the '-q showtests' command-line option to verify
 that you constructed \fBREGEXP\fP correctly.  The matching order
@@ -1353,4 +1357,4 @@ SEE ALSO:
 
 .SH
 CVS ID OF THIS PAGE:
-$Id: smartd.conf.5.in,v 1.85 2007/09/14 20:48:18 chrfranke Exp $
+$Id: smartd.conf.5.in,v 1.86 2007/10/20 13:02:50 chrfranke Exp $
diff --git a/sm5/smartd.cpp b/sm5/smartd.cpp
index dfe986c49..dd6179d99 100644
--- a/sm5/smartd.cpp
+++ b/sm5/smartd.cpp
@@ -119,14 +119,14 @@ extern "C" int getdomainname(char *, int); // no declaration in header files!
 extern const char *atacmdnames_c_cvsid, *atacmds_c_cvsid, *ataprint_c_cvsid, *escalade_c_cvsid, 
                   *knowndrives_c_cvsid, *os_XXXX_c_cvsid, *scsicmds_c_cvsid, *utility_c_cvsid;
 
-static const char *filenameandversion="$Id: smartd.cpp,v 1.392 2007/09/06 08:48:55 ballen4705 Exp $";
+static const char *filenameandversion="$Id: smartd.cpp,v 1.393 2007/10/20 13:02:51 chrfranke Exp $";
 #ifdef NEED_SOLARIS_ATA_CODE
 extern const char *os_solaris_ata_s_cvsid;
 #endif
 #ifdef _WIN32
 extern const char *daemon_win32_c_cvsid, *hostname_win32_c_cvsid, *syslog_win32_c_cvsid;
 #endif
-const char *smartd_c_cvsid="$Id: smartd.cpp,v 1.392 2007/09/06 08:48:55 ballen4705 Exp $" 
+const char *smartd_c_cvsid="$Id: smartd.cpp,v 1.393 2007/10/20 13:02:51 chrfranke Exp $" 
 ATACMDS_H_CVSID ATAPRINT_H_CVSID CONFIG_H_CVSID
 #ifdef DAEMON_WIN32_H_CVSID
 DAEMON_WIN32_H_CVSID
@@ -2041,7 +2041,7 @@ void PrintTestSchedule(cfgfile **atadevices, cfgfile **scsidevices){
   // FixGlibcTimeZoneBug(); // done in PrintOut()
   now=time(NULL);
   dateandtimezoneepoch(datenow, now);
-  for (seconds=0; seconds<3600L*24*90; seconds+=checktime) {
+  for (seconds=checktime; seconds<3600L*24*90; seconds+=checktime) {
     // Check for each device whether a test will be run
     time_t testtime = now + seconds;
     for (i=0; i<numdev; i++) {
@@ -2258,7 +2258,7 @@ static void CheckTemperature(cfgfile * cfg, unsigned char currtemp, unsigned cha
   }
 }
 
-int ATACheckDevice(cfgfile *cfg){
+int ATACheckDevice(cfgfile *cfg, bool allow_selftests){
   int fd,i;
   char *name=cfg->name;
   char *mode="ATA";
@@ -2297,7 +2297,7 @@ int ATACheckDevice(cfgfile *cfg){
   // sure) check whether a self test should be done now.
   // This check is done before powermode check to avoid missing self
   // tests on idle or sleeping disks.
-  if (cfg->testdata) {
+  if (allow_selftests && cfg->testdata) {
     // long test
     if (!cfg->testdata->not_cap_long && DoTestNow(cfg, 'L', 0)>0)
       testtype = 'L';
@@ -2546,7 +2546,7 @@ int ATACheckDevice(cfgfile *cfg){
   return 0;
 }
 
-int SCSICheckDevice(cfgfile *cfg)
+int SCSICheckDevice(cfgfile *cfg, bool allow_selftests)
 {
     UINT8 asc, ascq;
     UINT8 currenttemp;
@@ -2616,7 +2616,7 @@ int SCSICheckDevice(cfgfile *cfg)
     if (cfg->selftest)
       CheckSelfTestLogs(cfg, scsiCountFailedSelfTests(fd, 0));
     
-    if (cfg->testdata) {
+    if (allow_selftests && cfg->testdata) {
       // long (extended) background test
       if (!cfg->testdata->not_cap_long && DoTestNow(cfg, 'L', 0)>0)
         DoSCSISelfTest(fd, cfg, 'L');
@@ -2629,14 +2629,14 @@ int SCSICheckDevice(cfgfile *cfg)
 }
 
 // Checks the SMART status of all ATA and SCSI devices
-void CheckDevicesOnce(cfgfile **atadevices, cfgfile **scsidevices){
+void CheckDevicesOnce(cfgfile **atadevices, cfgfile **scsidevices, bool allow_selftests){
   int i;
   
   for (i=0; i<numdevata; i++) 
-    ATACheckDevice(atadevices[i]);
+    ATACheckDevice(atadevices[i], allow_selftests);
   
   for (i=0; i<numdevscsi; i++)
-    SCSICheckDevice(scsidevices[i]);
+    SCSICheckDevice(scsidevices[i], allow_selftests);
 
   return;
 }
@@ -4409,8 +4409,9 @@ static int smartd_main(int argc, char **argv)
       caughtsigHUP=0;
     }
 
-    // check all devices once
-    CheckDevicesOnce(atadevlist, scsidevlist); 
+    // check all devices once,
+    // self tests are not started in first pass unless '-q onecheck' is specified
+    CheckDevicesOnce(atadevlist, scsidevlist, (!firstpass || quit==3)); 
     
     // user has asked us to exit after first check
     if (quit==3) {
-- 
GitLab