1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
/*
CpqArray Deamon, a program to monitor and remotely configure a
SmartArray controller.
Copyright (C) 1999-2003 Hugo Trippaers
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 Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
$Header: /cvsroot/cpqarrayd/cciss_functions.c,v 1.1 2003/09/24 16:05:25 spark Exp $
*/
#include "config.h"
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/cciss_ioctl.h>
#include "cciss_structs.h"
const char *logicaldrivestatusstr[] = {
"Logical drive is ok",
"Logical drive is failing",
"Logical drive is not configured",
"Logical drive is using interim recovery mode",
"Logical drive is ready for recovery operation",
"Logical drive is is currently recovering",
"Wrong physical drive was replaced",
"A physical drive is not properly connected",
"Hardware is overheating",
"Hardware has overheated",
"Logical drive is currently expanding",
"Logical drive is not yet available",
"Logical drive is queued for expansion",
};
const char *sparestatusstr[] = {
"online",
};
const char *cciss_get_logical_drive_statusstr(int statuscode) {
return logicaldrivestatusstr[statuscode];
}
const char *cciss_get_spare_statusstr(int statuscode) {
return sparestatusstr[statuscode];
}
int
cciss_get_logical_luns (int device_fd, cciss_report_logicallun_struct * logluns)
{
int result, outfile;
IOCTL_Command_struct iocommand;
unsigned char *buffer;
iocommand.LUN_info.LunAddrBytes[0] = 0;
iocommand.LUN_info.LunAddrBytes[1] = 0;
iocommand.LUN_info.LunAddrBytes[2] = 0;
iocommand.LUN_info.LunAddrBytes[3] = 0;
iocommand.LUN_info.LunAddrBytes[4] = 0;
iocommand.LUN_info.LunAddrBytes[5] = 0;
iocommand.LUN_info.LunAddrBytes[6] = 0;
iocommand.LUN_info.LunAddrBytes[7] = 0;
iocommand.Request.Type.Type = TYPE_CMD;
iocommand.Request.Type.Attribute = ATTR_SIMPLE;
iocommand.Request.Type.Direction = XFER_READ;
iocommand.Request.Timeout = 0; /* don't time out */
iocommand.Request.CDBLen = 12;
iocommand.Request.CDB[0] = 0xC2; /* Report logical LUNs */
iocommand.Request.CDB[1] = 0x0; /* reserved, leave 0 */
iocommand.Request.CDB[2] = 0x0; /* reserved, leave 0 */
iocommand.Request.CDB[3] = 0x0; /* reserved, leave 0 */
iocommand.Request.CDB[4] = 0x0; /* reserved, leave 0 */
iocommand.Request.CDB[5] = 0x0; /* reserved, leave 0 */
iocommand.Request.CDB[6] = 0x0; /* byte 6-9 alloc length = 128 (0x80)*/
iocommand.Request.CDB[7] = 0x0;
iocommand.Request.CDB[8] = 0x0;
iocommand.Request.CDB[9] = 0x80;
iocommand.Request.CDB[10] = 0x0; /* reserved, leave 0 */
iocommand.Request.CDB[11] = 0x0; /* control ? */
buffer = (unsigned char *) malloc (128);
memset (buffer, 0x0, 128);
iocommand.buf_size = 128;
iocommand.buf = buffer;
result = ioctl (device_fd, CCISS_PASSTHRU, &iocommand);
if (result < 0)
{
return -1;
}
/* Data underrun is OK since we do not proccess data */
if (iocommand.error_info.CommandStatus != 0 && iocommand.error_info.CommandStatus != 2)
{
printf ("FATAL: 'Report Logical LUNs' failed with comnmand Status %d\n", iocommand.error_info.CommandStatus);
return -2;
}
memcpy (logluns, buffer, 128);
return 0;
}
int
cciss_get_event (int device_fd, int reset_pointer, cciss_event_type * event)
{
int result, outfile;
IOCTL_Command_struct iocommand;
unsigned char *buffer;
iocommand.LUN_info.LunAddrBytes[0] = 0;
iocommand.LUN_info.LunAddrBytes[1] = 0;
iocommand.LUN_info.LunAddrBytes[2] = 0;
iocommand.LUN_info.LunAddrBytes[3] = 0;
iocommand.LUN_info.LunAddrBytes[4] = 0;
iocommand.LUN_info.LunAddrBytes[5] = 0;
iocommand.LUN_info.LunAddrBytes[6] = 0;
iocommand.LUN_info.LunAddrBytes[7] = 0;
iocommand.Request.Type.Type = TYPE_CMD;
iocommand.Request.Type.Attribute = ATTR_SIMPLE;
iocommand.Request.Type.Direction = XFER_READ;
iocommand.Request.Timeout = 0; /* don't time out */
iocommand.Request.CDBLen = 13;
iocommand.Request.CDB[0] = 0xC0; /* CISS Read */
iocommand.Request.CDB[1] = 0xD0; /* Notify on Event */
iocommand.Request.CDB[2] = 0x0; /* reserved, leave 0 */
iocommand.Request.CDB[3] = 0x0; /* reserved, leave 0 */
iocommand.Request.CDB[4] = 0x0;
iocommand.Request.CDB[5] = 0x0;
iocommand.Request.CDB[6] = 0x0;
iocommand.Request.CDB[7] = (reset_pointer) ? 0x7 : 0x3; /* 7 = start at oldest, 3 is get current */
iocommand.Request.CDB[8] = 0x0;
iocommand.Request.CDB[9] = 0x0;
iocommand.Request.CDB[10] = 0x2;
iocommand.Request.CDB[11] = 0x0;
iocommand.Request.CDB[12] = 0x0;
buffer = (unsigned char *) malloc (512);
memset (buffer, 0x0, 512);
iocommand.buf_size = 512;
iocommand.buf = buffer;
result = ioctl (device_fd, CCISS_PASSTHRU, &iocommand);
if (result < 0)
{
perror (" * ioctl failed");
return -1;
}
if (iocommand.error_info.CommandStatus == 1) {
printf (" * Command succeeded with dataoverrun (code %d)\n", iocommand.error_info.CommandStatus);
}
else if (iocommand.error_info.CommandStatus == 2) {
printf (" * Command succeeded with dataunderrun (code %d)\n", iocommand.error_info.CommandStatus);
}
else if (iocommand.error_info.CommandStatus != 0)
{
printf (" * Command failed with Comnmand Status %d\n", iocommand.error_info.CommandStatus);
return -1;
}
memcpy (event, buffer, 512);
return 0;
}
|