diff -Nur mpt-status-1.2.0-RC5/doc/DeveloperNotes mpt-status-1.2.0-RC6/doc/DeveloperNotes --- mpt-status-1.2.0-RC5/doc/DeveloperNotes 2006-04-24 19:29:45.000000000 +0200 +++ mpt-status-1.2.0-RC6/doc/DeveloperNotes 2006-05-01 22:54:25.000000000 +0200 @@ -114,3 +114,17 @@ ) = 10 +++ exited (status 0) +++ +Kernel Header Sanitation +------------------------ +ks_to_us_header() { + # Voodoo to partially fix broken upstream headers. + # Issues with this function should go to plasmaroo. + sed -i \ + -e "s/\([ "$'\t'"]\)\(u\|s\)\(8\|16\|32\|64\)\([ "$'\t'"]\)/\1__\2\3\4/g;" \ + -e 's/ \(u\|s\)\(8\|16\|32\|64\)$/ __\1\2/g' \ + -e 's/\([(, ]\)\(u\|s\)64\([, )]\)/\1__\264\3/g' \ + -e "s/^\(u\|s\)\(8\|16\|32\|64\)\([ "$'\t'"]\)/__\1\2\3/g;" \ + -e "s/ inline / __inline__ /g" \ + "$@"; +} + diff -Nur mpt-status-1.2.0-RC5/mpt-status.c mpt-status-1.2.0-RC6/mpt-status.c --- mpt-status-1.2.0-RC5/mpt-status.c 2006-04-27 00:04:21.000000000 +0200 +++ mpt-status-1.2.0-RC6/mpt-status.c 2006-05-02 18:50:45.000000000 +0200 @@ -49,7 +49,7 @@ static int print_status_only = PRINT_STATUS_ONLY; static int id_of_primary_device = 0; static int ioc_unit = 0; -//static int library_mode = 0; +static int newstyle = 0; static int sel; static const struct option long_options[] = { @@ -57,10 +57,11 @@ { "controller", required_argument, NULL, 'u' }, { "debug", optional_argument, NULL, 'd' }, { "help", no_argument, NULL, 'h' }, - { "status_only", no_argument, NULL, 's' }, + { "newstyle", no_argument, NULL, 'n' }, { "probe_id", no_argument, NULL, 'p' }, { "quiet", no_argument, NULL, 'q' }, { "set_id", required_argument, NULL, 'i' }, + { "status_only", no_argument, NULL, 's' }, { "verbose", no_argument, NULL, 'v' }, { "version", no_argument, NULL, 'V' }, { 0, no_argument, NULL, 0 }, @@ -69,16 +70,20 @@ static const char* const usage_template = "Usage: %s [ options ]\n" "\n" - " --autoload This will try to automatically load mptctl\n" - " -u, --controller Set the IOC unit (controller)\n" + " --autoload This will try to automatically load the \n" + " mptctl kernel module\n" " -d, --debug [] Enable debugging and set level optionally\n" - " NOTE: This is not implemented yet\n" + " NOTE: This is not fully implemented yet\n" " -h, --help Print this help information page\n" - " -i, --set_id Set id of primary device (check README)\n" - " -p, --probe_id Use this to probe SCSI id's when not on id 0\n" + " -n, --newstyle Use the new style output. This parameter was\n" + " introduced to retain backwards compatibility\n" + " If not set, you get the old style output\n" + " -p, --probe_id Use this to probe SCSI id's when not on id 0\n" " -q, --quiet Do not display any warnings or boring info\n" - " -s, --status_only Only print the status information. This can\n" + " -i, --set_id Set id of primary device (check README)\n" + " -s, --status_only Only print the status information. This can\n" " be used for easy scripting\n" + " -u, --controller Set the IOC unit (controller)\n" " -v, --verbose Print verbose information, such as warnings\n" " -V, --version Print version information\n" "\n" @@ -97,11 +102,17 @@ " Bit 3: A logical volume is resyncing.\n" " Bit 4: At least one physical disk failed.\n" " Bit 5: At least one physical disk is in warning condition.\n" + "\n" + " Setting the MPT_STATUS_DEBUG environment variable will enable the\n" + " internal debugging and help the author further improve this tool.\n" + " Example: ``MPT_STATUS_DEBUG=42 ./mpt-status'' will enable debug and\n" + " set the debug level to 42.\n" + "\n" "\n"; static char *VolumeTypes[] = { "IS", "IME", "IM" }; -static char *VolumeTypesHuman[] = { "0", "1E", "1" }; //Raid levels +static char *VolumeTypesHuman[] = { "RAID-0", "RAID-1E", "RAID-1" }; mpiIoctlBlk_t *mpiBlkPtr = NULL; unsigned char g_command[BIG]; char g_data[4*BIG]; @@ -110,7 +121,6 @@ static int resync_on = 0; /* function declaration */ -static void __check_endianess(void); static unsigned int cpu_to_le32 (unsigned int); static unsigned short le16_to_cpu(unsigned short); static void freeMem(void); @@ -121,23 +131,40 @@ static int mpt_fprintf(FILE *, const char *, ...); static void print_usage(const char *); static void print_version(void); -static void *read_page(uint, uint, uint, uint, uint); -static int __probe_scsi_id(void); static int read_page2(uint); static void GetVolumeInfo(void); static void GetPhysDiskInfo(RaidVol0PhysDisk_t *, int); +static void GetHotSpareInfo(void); static void GetResyncPercentage(RaidVol0PhysDisk_t *, unsigned char *, int); -static void print_information(void); static void do_init(void); +/* internal-functions declaration */ +static void __check_endianess(void); +static void __check_for_debug_mode(void); +static void __print_volume_advanced(RaidVolumePage0_t *); static void __print_volume_classic(RaidVolumePage0_t *); +static void __print_physdisk_advanced(RaidPhysDiskPage0_t *, int); static void __print_physdisk_classic(RaidPhysDiskPage0_t *); +static void __check_for_debug_mode(void) { + char *env; + + env = getenv("MPT_STATUS_DEBUG"); + if (env != NULL) { + debug = 1; + debug_level = strtol(env, NULL, 10); + mpt_printf("Setting DEBUG mode with debug_level = %d\n", + debug_level); + free(env); + } +} + static void __check_endianess(void) { int i = 1; char *p = (char *) &i; - if (p[0] != 1) // Lowest address contains the least significant byte + if (p[0] != 1) { // Lowest address contains the least significant byte g_bigEndian = 1; + } } static unsigned int cpu_to_le32(unsigned int x) { @@ -209,6 +236,9 @@ } static void mpt_exit(int status) { + /* this function is suboptimal in that it masks too many + semantic information into one int + */ if (status & MPT_EXIT_FREEMEM) { freeMem(); } @@ -242,6 +272,18 @@ return result; } +static int mpt_debug(const char *format, ...) { + int result; + va_list ap; + + if (debug) + return 0; + /* debug_level is also set at this point */ + va_start(ap, format); + result = vprintf(format, ap); + va_end(ap); + return result; +} static void print_usage(const char *progname) { mpt_printf(usage_template, progname); @@ -251,89 +293,6 @@ mpt_printf("Version: %s\n", VERSION); } -static void *read_page(unsigned int pagetype, unsigned int pagewhich, - unsigned int pagenumber, unsigned int address, - unsigned int version) { - char command[REALLYBIG]; - char reply[REALLYBIG]; - char sense[REALLYBIG]; - char *in; - unsigned int warnings; - struct mpt_ioctl_command *cmd = NULL; - Config_t *config_request; - ConfigReply_t *config_reply; - unsigned short div = 4; - - if (NULL == (in = calloc(REALLYBIG, 1))) { - perror("calloc"); - mpt_exit(MPT_EXIT_UNKNOWN); - } - - warnings = 0; - cmd = (struct mpt_ioctl_command *)command; - config_request = (Config_t *) cmd->MF; - config_reply = (ConfigReply_t *) reply; - - memset((void *)command, 0, sizeof(command)); - memset((void *)reply, 0, sizeof(reply)); - memset((void *)sense, 0, sizeof(sense)); - memset((void *)in, 0, sizeof(in)); - - cmd->hdr.iocnum = ioc_unit; - cmd->hdr.port = 0; - cmd->hdr.maxDataSize = BIG; - cmd->timeout = 10; - cmd->dataSgeOffset = (((char *)&config_request->PageBufferSGE) - - ((char *)config_request)) / div; - cmd->senseDataPtr = (void *)sense; - cmd->replyFrameBufPtr = (void *)config_reply; - cmd->dataInBufPtr = (void *)in; - cmd->maxSenseBytes = BIG; - cmd->maxReplyBytes = BIG; - cmd->dataInSize = BIG; - - config_request->Function = MPI_FUNCTION_CONFIG; - config_request->Action = MPI_CONFIG_ACTION_PAGE_HEADER; - config_request->Header.PageType = pagetype; - config_request->Header.PageNumber = pagenumber; - config_request->Header.PageLength = 0; - config_request->Header.PageVersion = 0; - config_request->PageAddress = address; - - if (-1 == ioctl(m, MPTCOMMAND, (char *) cmd)) { - perror("MPI_FUNCTION_CONFIG (get page header)"); - mpt_exit(MPT_EXIT_UNKNOWN); - } - - if (version != config_reply->Header.PageVersion) { - if (verbose_mode > 0) { - mpt_fprintf(stderr, - "Version mismatch on pagetype %u," - " page number %u: expected %d, got %d\n", - pagetype, pagenumber, version, - config_reply->Header.PageVersion); - } - /* Enable the following to automatically output a warning */ - //warnings++; - } - - config_request->Action = pagewhich; - config_request->Header.PageLength = config_reply->Header.PageLength; - - if (-1 == ioctl(m, MPTCOMMAND, cmd)) { - perror("MPI_FUNCTION_CONFIG (get page)"); - mpt_exit(MPT_EXIT_UNKNOWN); - } - if (warnings > 0 && verbose_mode != 0) { - mpt_fprintf(stderr, - "\nHouston, we have got a problem!" - " If you're interested in the warnings or you" - " were asked to send verbose information, add" - " the '-v' switch to your command line\n"); - } - return in; -} - static int __probe_scsi_id2(void) { Config_t *ConfigRequest; ConfigReply_t *pReply = NULL; @@ -398,25 +357,6 @@ return -1; } -static int __probe_scsi_id(void) { - int scsi_id; - RaidVolumePage0_t *page; - - for (scsi_id = 0; scsi_id < 16; scsi_id++) { - printf("Checking for SCSI ID:%d\n", scsi_id); - page = read_page(MPI_CONFIG_PAGETYPE_RAID_VOLUME, - MPI_CONFIG_ACTION_PAGE_READ_CURRENT, - ioc_unit, - scsi_id, - MPI_RAIDVOLPAGE0_PAGEVERSION); - if (0 != page->NumPhysDisks) { - /* found the first scsi_id */ - return scsi_id; - } - } - return -1; -} - static int read_page2(uint flags) { MPIDefaultReply_t *pReply = NULL; int CmdBlkSize; @@ -445,7 +385,7 @@ return status; } -/* This function is only written to get the Volume 0 information */ +/* This function is only written to get the information of Volume 0 */ static void GetVolumeInfo(void) { Config_t *ConfigRequest; ConfigReply_t *pReply = NULL; @@ -475,9 +415,12 @@ ConfigRequest->Function = MPI_FUNCTION_CONFIG; ConfigRequest->MsgContext = -1; ConfigRequest->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME; - // ioc_unit handler ConfigRequest->Header.PageNumber = ioc_unit; //orig: ConfigRequest->PageAddress = cpu_to_le32((bus << 8) | 0); + mpt_debug("DEBUG: cpu_to_le32=%d htonl=%d ntohl=%d\n", + cpu_to_le32((bus << 8) | 0), + htonl((bus << 8) | 0), + ntohl((bus << 8) | 0)); ConfigRequest->PageAddress = bus; status = read_page2(MPT_FLAGS_KEEP_MEM); @@ -504,33 +447,48 @@ id = 0; // volume id: only one volume for now (vol_ids) //orig: ConfigRequest->PageAddress = cpu_to_le32((bus << 8) | id); /* Something is fishy here */ + mpt_debug("DEBUG: cpu_to_le32=%d htonl=%d ntohl=%d\n", + cpu_to_le32(bus | id), + htonl(bus | id), + ntohl(bus | id)); ConfigRequest->PageAddress = bus | id; status = read_page2(MPT_FLAGS_KEEP_MEM); pRVP0 = (RaidVolumePage0_t *) mpiBlkPtr->dataInBufPtr; if ((status == 0) && (pRVP0->NumPhysDisks > 0)){ - __print_volume_classic(pRVP0); + if (newstyle == 0) { + __print_volume_classic(pRVP0); + } else { + __print_volume_advanced(pRVP0); + } for (ii = pdisk_cnt; ii < pdisk_cnt + pRVP0->NumPhysDisks; ii++) { disk_num[ii].PhysDiskNum = pRVP0->PhysDisk[ii].PhysDiskNum; disk_num[ii].PhysDiskMap = pRVP0->PhysDisk[ii].PhysDiskMap; pdisk_vol[ii] = pRVP0->VolumeID; } pdisk_cnt += pRVP0->NumPhysDisks; + } else if (pRVP0->NumPhysDisks == 0) { + mpt_printf("%s\n", wrong_scsi_id); + mpt_exit(MPT_EXIT_UNKNOWN); } freeMem(); if (pdisk_cnt > 0) { GetPhysDiskInfo((RaidVol0PhysDisk_t *) &disk_num, pdisk_cnt); } - /* switched off to test those pesky 64bit machines */ - //if (resync_on) + /* this should be woven into the GetPhysDiskInfo part correctly */ + if (newstyle) { + GetHotSpareInfo(); + } + /* this should be woven into the GetPhysDiskInfo part correctly */ + if (newstyle) /* && resync_on) */ { GetResyncPercentage((RaidVol0PhysDisk_t *) &disk_num, (unsigned char *) &pdisk_vol, pdisk_cnt); - //} + } return; } static void GetPhysDiskInfo(RaidVol0PhysDisk_t *pDisk, int count) { - Config_t *ConfigRequest; - ConfigReply_t *pReply = NULL; + Config_t *ConfigRequest; + ConfigReply_t *pReply = NULL; uint numBytes; int status; int ii; @@ -549,7 +507,6 @@ ConfigRequest->Function = MPI_FUNCTION_CONFIG; ConfigRequest->MsgContext = -1; ConfigRequest->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK; - // ioc_unit handler ConfigRequest->Header.PageNumber = ioc_unit; ConfigRequest->PageAddress = cpu_to_le32((uint)pDisk[0].PhysDiskNum); @@ -573,18 +530,14 @@ if (status == 0) { RaidPhysDiskPage0_t *pRPD0 = (RaidPhysDiskPage0_t *) mpiBlkPtr->dataInBufPtr; - __print_physdisk_classic(pRPD0); - - /* - printf("S.M.A.R.T and ASC/Q information\n"); - printf("ASC = 0x%02x\n", pRPD0->ErrorData.ErrorASC); - printf("ASCQ = 0x%02x\n", pRPD0->ErrorData.ErrorASCQ); - printf("Smart ASC = 0x%02x\n", pRPD0->ErrorData.SmartASC); - printf("Smart ASCQ = 0x%02x\n", pRPD0->ErrorData.SmartASCQ); - printf("\n"); - */ - } else - printf("\t\tNot Available.\n"); + if (newstyle == 0) { + __print_physdisk_classic(pRPD0); + } else { + __print_physdisk_advanced(pRPD0, 0); + } + } else { + //mpt_printf("\t\tNot Available.\n"); + } } freeMem(); return; @@ -597,7 +550,6 @@ uint numBytes; int status; uint num_spares = 0; - u8 tmp; numBytes = (sizeof(Config_t) - sizeof(SGE_IO_UNION)) + sizeof (SGESimple64_t); if ((mpiBlkPtr = allocIoctlBlk(numBytes)) == NULL) @@ -618,7 +570,6 @@ ConfigRequest->PageAddress = 0; status = read_page2(MPT_FLAGS_KEEP_MEM); - printf("Hot Spare Information:\n"); if (status != 0) { printf("\tUnsupported.\n"); freeMem(); @@ -692,35 +643,19 @@ status = read_page2(MPT_FLAGS_KEEP_MEM); if (status == 0) { RaidPhysDiskPage0_t *pRPD0 = (RaidPhysDiskPage0_t *) mpiBlkPtr->dataInBufPtr; - printf("\tNum=%d ID=%d", pRPD0->PhysDiskNum, pRPD0->PhysDiskID); - tmp=pRPD0->PhysDiskStatus.Flags; - if (tmp & MPI_PHYSDISK0_STATUS_FLAG_OUT_OF_SYNC) - printf(", Out of Sync"); - if (tmp & MPI_PHYSDISK0_STATUS_FLAG_QUIESCED) - printf(", Quiesced"); - tmp=pRPD0->PhysDiskStatus.State; - if (tmp & MPI_PHYSDISK0_STATUS_ONLINE) - printf(", Online"); - if (tmp & MPI_PHYSDISK0_STATUS_MISSING) - printf(", Missing"); - if (tmp & MPI_PHYSDISK0_STATUS_NOT_COMPATIBLE) - printf(", Not Compatible"); - if (tmp & MPI_PHYSDISK0_STATUS_FAILED) - printf(", Failed"); - if (tmp & MPI_PHYSDISK0_STATUS_INITIALIZING) - printf(", Initializing"); - if (tmp & MPI_PHYSDISK0_STATUS_FAILED_REQUESTED) - printf(", Failed Requested"); - printf("\n"); - } else - printf("\t\tNot Available.\n"); + __print_physdisk_advanced(pRPD0, 1); + } else { + //printf("\t\tNot Available.\n"); + } } } - } else if (status == 0) + /* + } else if (status == 0) { printf("Not Available.\n"); - else + } else { printf("No Hot Spare Disks.\n"); - + */ + } freeMem(); return; } @@ -731,17 +666,15 @@ uint numBytes; int ii; uint tot_blks, blks_left; - uint tot_blks2, blks_left2; int status; numBytes = (sizeof(MpiRaidActionRequest_t) - sizeof(SGE_IO_UNION)) - + sizeof (SGESimple64_t); - + + sizeof (SGESimple64_t); if ((mpiBlkPtr = allocIoctlBlk(numBytes)) == NULL) return; - pRequest = (MpiRaidActionRequest_t *) mpiBlkPtr->MF; - mpiBlkPtr->dataSgeOffset = (sizeof (MpiRaidActionRequest_t) - sizeof(SGE_IO_UNION))/4; + mpiBlkPtr->dataSgeOffset = (sizeof (MpiRaidActionRequest_t) + - sizeof(SGE_IO_UNION))/4; /* Initialize data in/data out sizes: Change below if need to */ mpiBlkPtr->dataInSize = mpiBlkPtr->dataOutSize = 0; @@ -749,48 +682,44 @@ pRequest->Action = MPI_RAID_ACTION_INDICATOR_STRUCT; pRequest->Function = MPI_FUNCTION_RAID_ACTION; pRequest->MsgContext = -1; - pRequest->ActionDataWord = cpu_to_le32(0); /* action data is 0 */ + pRequest->ActionDataWord = 0; /* action data is 0 */ - printf("Resync Information:\n"); for (ii = 0; ii < count; ii++ ) { pRequest->VolumeID = (u8) pVol[ii]; pRequest->PhysDiskNum = pDisk[ii].PhysDiskNum; status = read_page2(MPT_FLAGS_KEEP_MEM); if (status == 0) { + // pDisk[ii].PhysDiskNum == scsi_id uint *pdata = (uint *) mpiBlkPtr->replyFrameBufPtr; - printf("DEBUG: *pdata=%d\n", *pdata); + mpt_debug("DEBUG: *pdata=%d\n", *pdata); pdata += 6; - tot_blks2 = cpu_to_le32(*pdata); - tot_blks = htonl(*pdata); - printf("DEBUG: tot_blks=%d tot_blks2=%d\n", - tot_blks, tot_blks2); + tot_blks = *pdata; + mpt_debug("DEBUG: tot_blks=%d\n", tot_blks); pdata++; pdata++; - blks_left2 = cpu_to_le32(*pdata); - blks_left = htonl(*pdata); - printf("DEBUG: blks_left=%d blks_left2=%d\n", - blks_left, blks_left2); + blks_left = *pdata; + mpt_debug("DEBUG: blks_left=%d\n", blks_left); pdata++; blks_done = tot_blks - blks_left; - printf("\tPhys Disk %d on Volume %d:\n\t\t0x%x of 0x%x Remaining,", - pDisk[ii].PhysDiskNum, pVol[ii], - blks_left, tot_blks ); - - printf(" Done 0x%x, (%d%%) Complete \n", - blks_done, ((blks_done >> 6) * 100) / (tot_blks >> 6)); + mpt_printf("scsi_id:%d", pDisk[ii].PhysDiskNum); + if (blks_left == 0) { + mpt_printf(" 100%%\n"); + } else { + mpt_printf(" %d%%\n", + ((blks_done >> 6)*100)/(tot_blks >> 6)); + } } } freeMem(); return; } -static void __print_volume_classic(RaidVolumePage0_t *page) { +static void __print_volume_advanced(RaidVolumePage0_t *page) { if (1 == print_status_only) { mpt_printf("vol_id:%d", page->VolumeID); } else { - mpt_printf("ioc:%d vol_id:%d type:%s raidlevel:%s num_disks:%d" - " size(GB):%d", + mpt_printf("ioc:%d vol_id:%d type:%s raidlevel:%s num_disks:%d size(GB):%d", page->VolumeIOC, page->VolumeID, page->VolumeType < sizeof(VolumeTypes) ? @@ -838,27 +767,173 @@ } } mpt_printf("\n"); +} +static void __print_volume_classic(RaidVolumePage0_t *page) { + /* This function will go away for the next big release */ + if (1 == print_status_only) { + mpt_printf("log_id %d", page->VolumeID); + } else { + mpt_printf("ioc%d vol_id %d type %s, %d phy, %d GB", + page->VolumeIOC, + page->VolumeID, + sizeof(VolumeTypes) ? VolumeTypes[page->VolumeType] : + "unknown", + page->NumPhysDisks, + page->MaxLBA / (2 * 1024 * 1024)); + mpt_printf(", state"); + } + if (page->VolumeStatus.State == MPI_RAIDVOL0_STATUS_STATE_OPTIMAL) { + mpt_exit_mask |= MPT_EXIT_VOL_OPTIMAL; + mpt_printf(" OPTIMAL"); + } else if (page->VolumeStatus.State == + MPI_RAIDVOL0_STATUS_STATE_DEGRADED) { + mpt_exit_mask |= MPT_EXIT_VOL_DEGRADED; + mpt_printf(" DEGRADED"); + } else if (page->VolumeStatus.State == + MPI_RAIDVOL0_STATUS_STATE_FAILED) { + mpt_exit_mask |= MPT_EXIT_VOL_FAILED; + mpt_printf(" FAILED"); + } else { + mpt_exit_mask |= MPT_EXIT_UNKNOWN; + mpt_printf(" UNKNOWN"); + } + if (1 != print_status_only) { + mpt_printf(", flags"); + if (page->VolumeStatus.Flags != 0) { + if (page->VolumeStatus.Flags & + MPI_RAIDVOL0_STATUS_FLAG_ENABLED) + mpt_printf(" ENABLED"); + if (page->VolumeStatus.Flags & + MPI_RAIDVOL0_STATUS_FLAG_QUIESCED) + mpt_printf(" QUIESCED"); + if (page->VolumeStatus.Flags & + MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) { + mpt_printf(" RESYNC_IN_PROGRESS"); + resync_on = 1; + } + if (page->VolumeStatus.Flags & + MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE) + mpt_printf(" VOLUME_INACTIVE"); + } else { + mpt_printf(" NONE"); + } + } + mpt_printf("\n"); +} + +static void __print_physdisk_advanced(RaidPhysDiskPage0_t *phys, int spare) { + char vendor[BIG]; + char productid[BIG]; + char rev[BIG]; + + memset(vendor, 0, sizeof(vendor)); + memset(productid, 0, sizeof(productid)); + memset(rev, 0, sizeof(rev)); + + strncpy(vendor, (void *) phys->InquiryData.VendorID, + sizeof(phys->InquiryData.VendorID)); + strncpy(productid, (void *) phys->InquiryData.ProductID, + sizeof(phys->InquiryData.ProductID)); + strncpy(rev, (void *) phys->InquiryData.ProductRevLevel, + sizeof(phys->InquiryData.ProductRevLevel)); + + if (1 == print_status_only) { + printf("%s:%d", spare == 1 ? "spare_id" : "phys_id", + phys->PhysDiskNum); + } else { + printf("ioc:%d %s:%d scsi_id:%d vendor:%s product_id:%s revision:%s size(GB):%d", + phys->PhysDiskIOC, + spare == 1 ? "spare_id" : "phys_id", + phys->PhysDiskNum, + phys->PhysDiskID, + vendor, + productid, + rev, + phys->MaxLBA / (2 * 1024 * 1024)); + printf(" state:"); + } + if (phys->PhysDiskStatus.State == + MPI_PHYSDISK0_STATUS_ONLINE) { + mpt_exit_mask |= MPT_EXIT_OKAY; + printf(" ONLINE"); + } else if (phys->PhysDiskStatus.State == + MPI_PHYSDISK0_STATUS_MISSING) { + mpt_exit_mask |= MPT_EXIT_PHYSDISK_ERROR; + printf(" MISSING"); + } else if (phys->PhysDiskStatus.State == + MPI_PHYSDISK0_STATUS_NOT_COMPATIBLE) { + mpt_exit_mask |= MPT_EXIT_PHYSDISK_ERROR; + printf(" NOT_COMPATIBLE"); + } else if (phys->PhysDiskStatus.State == + MPI_PHYSDISK0_STATUS_FAILED) { + mpt_exit_mask |= MPT_EXIT_PHYSDISK_ERROR; + printf(" FAILED"); + } else if (phys->PhysDiskStatus.State == + MPI_PHYSDISK0_STATUS_INITIALIZING) { + mpt_exit_mask |= MPT_EXIT_PHYSDISK_WARN; + printf(" INITIALIZING"); + } else if (phys->PhysDiskStatus.State == + MPI_PHYSDISK0_STATUS_OFFLINE_REQUESTED) { + mpt_exit_mask |= MPT_EXIT_PHYSDISK_WARN; + printf(" OFFLINE_REQUESTED"); + } else if (phys->PhysDiskStatus.State == + MPI_PHYSDISK0_STATUS_FAILED_REQUESTED) { + mpt_exit_mask |= MPT_EXIT_PHYSDISK_ERROR; + printf(" FAILED_REQUESTED"); + } else if (phys->PhysDiskStatus.State == + MPI_PHYSDISK0_STATUS_OTHER_OFFLINE) { + mpt_exit_mask |= MPT_EXIT_PHYSDISK_WARN; + printf(" OTHER_OFFLINE"); + } else { + mpt_exit_mask |= MPT_EXIT_UNKNOWN; + mpt_printf(" UNKNOWN"); + } + if (1 != print_status_only) { + mpt_printf(" flags:"); + if (phys->PhysDiskStatus.Flags) { + if (phys->PhysDiskStatus.Flags & + MPI_PHYSDISK0_STATUS_FLAG_OUT_OF_SYNC) + mpt_printf(" OUT_OF_SYNC"); + if (phys->PhysDiskStatus.Flags & + MPI_PHYSDISK0_STATUS_FLAG_QUIESCED) + mpt_printf(" QUIESCED"); + } else { + mpt_printf(" NONE"); + } + /* SYNC RATE */ + mpt_printf(" sync_state: "); + /* ASC/ASCQ information */ + mpt_printf(" ASC/ASCQ:0x%02x/0x%02x SMART ASC/ASCQ:0x%02x/0x%02x", + phys->ErrorData.ErrorASC, + phys->ErrorData.ErrorASCQ, + phys->ErrorData.SmartASC, + phys->ErrorData.SmartASCQ); + } + mpt_printf("\n"); } static void __print_physdisk_classic(RaidPhysDiskPage0_t *phys) { - int ret; - char *vendor = NULL; - char *productid = NULL; - char *rev = NULL; - - ret = asprintf(&vendor, (void *)phys->InquiryData.VendorID); - if (ret > 0) vendor[ret-1] = '\0'; - ret = asprintf(&productid, (void *)phys->InquiryData.ProductID); - if (ret > 0) productid[ret-1] = '\0'; - ret = asprintf(&rev, (void *)phys->InquiryData.ProductRevLevel); - if (ret > 0) rev[ret-1] = '\0'; + /* This function will go away for the next big release */ + char vendor[BIG]; + char productid[BIG]; + char rev[BIG]; + + memset(vendor, 0, sizeof(vendor)); + memset(productid, 0, sizeof(productid)); + memset(rev, 0, sizeof(rev)); + + strncpy(vendor, (void *) phys->InquiryData.VendorID, + sizeof(phys->InquiryData.VendorID)); + strncpy(productid, (void *) phys->InquiryData.ProductID, + sizeof(phys->InquiryData.ProductID)); + strncpy(rev, (void *) phys->InquiryData.ProductRevLevel, + sizeof(phys->InquiryData.ProductRevLevel)); if (1 == print_status_only) { - printf("phys_id:%d", phys->PhysDiskNum); + printf("phys_id %d", phys->PhysDiskNum); } else { - printf("ioc:%d phys_id:%d scsi_id:%d vendor:%s " - "product_id:%s revision:%s size(GB):%d", + printf("ioc%d phy %d scsi_id %d %s %s %s, %d GB", phys->PhysDiskIOC, phys->PhysDiskNum, phys->PhysDiskID, @@ -866,7 +941,7 @@ productid, rev, phys->MaxLBA / (2 * 1024 * 1024)); - printf(" state:"); + printf(", state"); } if (phys->PhysDiskStatus.State == MPI_PHYSDISK0_STATUS_ONLINE) { @@ -905,7 +980,7 @@ mpt_printf(" UNKNOWN"); } if (1 != print_status_only) { - mpt_printf(" flags:"); + mpt_printf(", flags"); if (phys->PhysDiskStatus.Flags) { if (phys->PhysDiskStatus.Flags & MPI_PHYSDISK0_STATUS_FLAG_OUT_OF_SYNC) @@ -918,49 +993,6 @@ } } mpt_printf("\n"); - free(vendor); - free(productid); - free(rev); -} - -static void print_information(void) { - RaidVolumePage0_t *page; - RaidPhysDiskPage0_t *phys; - int i; - - page = read_page(MPI_CONFIG_PAGETYPE_RAID_VOLUME, - MPI_CONFIG_ACTION_PAGE_READ_CURRENT, - ioc_unit, - id_of_primary_device, - MPI_RAIDVOLPAGE0_PAGEVERSION); - if (0 == page->NumPhysDisks) { - if (probe_id > 0) { - id_of_primary_device = __probe_scsi_id(); - if (-1 == id_of_primary_device) { - mpt_printf("Nothing found, contact the author\n"); - mpt_exit(MPT_EXIT_UNKNOWN); - } else { - mpt_printf("Found SCSI id=%d, use ''mpt-status " - "-i %d`` to get more information.\n", - id_of_primary_device, - id_of_primary_device); - mpt_exit(MPT_EXIT_OKAY); - } - } else { - mpt_printf("%s\n", wrong_scsi_id); - mpt_exit(MPT_EXIT_UNKNOWN); - } - } - __print_volume_classic(page); - /* go through all physical disk of a found array */ - for (i = 1; i < page->NumPhysDisks; ++i) { - phys = read_page(MPI_CONFIG_PAGETYPE_RAID_PHYSDISK, - MPI_CONFIG_ACTION_PAGE_READ_CURRENT, - ioc_unit, - page->PhysDisk[i].PhysDiskNum, - MPI_RAIDPHYSDISKPAGE0_PAGEVERSION); - __print_physdisk_classic(phys); - } } static void do_init(void) { @@ -974,9 +1006,7 @@ save_errno = errno; perror("open /dev/mptctl"); if (save_errno == EACCES) { - mpt_fprintf(stderr, - " You need to be root" - " to run this program\n"); + mpt_fprintf(stderr, " Need root to run this program\n"); } else if (save_errno == ENOENT) { mpt_fprintf(stderr, " Try: mknod /dev/mptctl c 10 220\n"); @@ -1004,13 +1034,16 @@ debug = 1; debug_level = strtoul(optarg, NULL, 10); break; - case 'i': - id_of_primary_device = strtoul(optarg, NULL, 10); - break; case 'h': print_usage(progname); mpt_exit(MPT_EXIT_OKAY); break; + case 'i': + id_of_primary_device = strtoul(optarg, NULL, 10); + break; + case 'n': + newstyle = 1; + break; case 'p': probe_id = 1; break; @@ -1045,16 +1078,30 @@ } } while (next_option != -1); + __check_for_debug_mode(); do_init(); -#ifdef NEWSTYLE - __check_endianess(); - if (probe_id > 0) { - id_of_primary_device = __probe_scsi_id2(); - } - GetVolumeInfo(); - //GetHotSpareInfo(); -#else - print_information(); -#endif + if (newstyle > 0) { + __check_endianess(); + if (probe_id > 0) { + id_of_primary_device = __probe_scsi_id2(); + } + GetVolumeInfo(); + } else { + /* this is the old style setup */ + if (probe_id > 0) { + id_of_primary_device = __probe_scsi_id2(); + if (-1 == id_of_primary_device) { + mpt_printf("Nothing found, contact the author\n"); + mpt_exit(MPT_EXIT_UNKNOWN); + } else { + printf("Found SCSI id=%d, use ''mpt-status " + "-i %d`` to get more information.\n", + id_of_primary_device, + id_of_primary_device); + mpt_exit(MPT_EXIT_OKAY); + } + } + GetVolumeInfo(); + } return mpt_exit_mask; } diff -Nur mpt-status-1.2.0-RC5/mpt-status.h mpt-status-1.2.0-RC6/mpt-status.h --- mpt-status-1.2.0-RC5/mpt-status.h 2006-04-25 20:55:58.000000000 +0200 +++ mpt-status-1.2.0-RC6/mpt-status.h 2006-05-01 23:33:35.000000000 +0200 @@ -26,7 +26,7 @@ #include "mptctl.h" #endif // SANITIZED_KERNEL_HEADERS -#define VERSION "1.2.0-RC5" +#define VERSION "1.2.0-RC6" #define BIG 1024 #define REALLYBIG 10240