From 242e4ccc3951cc5ac2e82b1e8524c939a8cd6241 Mon Sep 17 00:00:00 2001
From: samm2 <samm2@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Thu, 8 Oct 2009 23:43:46 +0000
Subject: [PATCH] Linux: Hiding debug messages coming from megaraid code, added
 autodetection of MegaRaid controller

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@2951 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 smartmontools/CHANGELOG    |  3 ++-
 smartmontools/os_linux.cpp | 16 ++++++++++------
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/smartmontools/CHANGELOG b/smartmontools/CHANGELOG
index b506d428c..f4a5cc806 100644
--- a/smartmontools/CHANGELOG
+++ b/smartmontools/CHANGELOG
@@ -43,7 +43,8 @@ NOTES FOR FUTURE RELEASES: see TODO file.
 
 <DEVELOPERS: ADDITIONS TO THE CHANGE LOG GO JUST BELOW HERE, PLEASE>
 
-  [AS] Linux: Autodetect DELL PERC controller.
+  [AS] Linux: Autodetect DELL PERC and MegaRAID controllers. 
+       Hiding debug messages coming from megaraid code.  
 
   [AS] Linux: Fixed SATA drives support on megaraid device (see ticket #15).
 
diff --git a/smartmontools/os_linux.cpp b/smartmontools/os_linux.cpp
index f5b0a387d..5a9d123e2 100644
--- a/smartmontools/os_linux.cpp
+++ b/smartmontools/os_linux.cpp
@@ -951,6 +951,7 @@ bool linux_megaraid_device::open()
   char line[128];
   int   mjr, n1;
   FILE *fp;
+  int report = con->reportscsiioctl; 
 
   if (!linux_smart_device::open())
     return false;
@@ -963,7 +964,7 @@ bool linux_megaraid_device::open()
   else if (ioctl(get_fd(), SCSI_IOCTL_GET_BUS_NUMBER, &m_hba) != 0) {
     int err = errno;
     linux_smart_device::close();
-    return set_err(err, "can't get hba");
+    return set_err(err, "can't get bus number");
   }
 
   /* Perform mknod of device ioctl node */
@@ -972,13 +973,15 @@ bool linux_megaraid_device::open()
   	n1=0;
   	if (sscanf(line, "%d megaraid_sas_ioctl%n", &mjr, &n1) == 1 && n1 == 22) {
 	   n1=mknod("/dev/megaraid_sas_ioctl_node", S_IFCHR, makedev(mjr, 0));
-	   printf("Creating /dev/megaraid_sas_ioctl_node = %d\n", n1 >= 0 ? 0 : errno);
+	   if(report > 0)
+	     printf("Creating /dev/megaraid_sas_ioctl_node = %d\n", n1 >= 0 ? 0 : errno);
 	   if (n1 >= 0 || errno == EEXIST)
 	      break;
 	}
 	else if (sscanf(line, "%d megadev%n", &mjr, &n1) == 1 && n1 == 11) {
 	   n1=mknod("/dev/megadev0", S_IFCHR, makedev(mjr, 0));
-	   printf("Creating /dev/megadev0 = %d\n", n1 >= 0 ? 0 : errno);
+	   if(report > 0)
+	     printf("Creating /dev/megadev0 = %d\n", n1 >= 0 ? 0 : errno);
 	   if (n1 >= 0 || errno == EEXIST)
 	      break;
 	}
@@ -1043,7 +1046,8 @@ bool linux_megaraid_device::scsi_pass_through(scsi_cmnd_io *iop)
   if (iop->cmnd[0] == 0x00)
     return true;
   if (iop->cmnd[0] == 0x85 && iop->cmnd[1] == 0x06) {
-    pout("Rejecting SMART/ATA command to controller\n");
+    if(report > 0)
+      pout("Rejecting SMART/ATA command to controller\n");
     // Emulate SMART STATUS CHECK drive reply
     // smartctl fail to work without this
     if(iop->cmnd[2]==0x2c) {
@@ -2677,9 +2681,9 @@ smart_device * linux_scsi_device::autodetect_open()
       return this;
     }
     // DELL?
-    if (!memcmp(req_buff + 8, "DELL    PERC", 12)) {
+    if (!memcmp(req_buff + 8, "DELL    PERC", 12) || !memcmp(req_buff + 8, "MegaRAID", 8)) {
       close();
-      set_err(EINVAL, "DELL controller, please try adding '-d megaraid,N'");
+      set_err(EINVAL, "DELL or MegaRaid controller, please try adding '-d megaraid,N'");
       return this;
     }
     
-- 
GitLab