Compare commits

..

No commits in common. "master" and "upstream/0.4.1" have entirely different histories.

102 changed files with 66 additions and 649 deletions

1
.github/FUNDING.yml vendored
View File

@ -1 +0,0 @@
custom: [https://www.buymeacoffee.com/namiltd]

View File

@ -1,62 +0,0 @@
name: "CodeQL"
on:
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- cron: '0 20 * * 6'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['cpp']
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2
# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

4
.gitignore vendored
View File

@ -1,4 +0,0 @@
*.o
/megatrace
/megactl
/megasasctl

42
debian/changelog vendored
View File

@ -1,42 +0,0 @@
megactl (0.4.5-1) unstable; urgency=medium
[ Petter Reinholdtsen ]
* New upstream version 0.4.5
- Dropped all patches now applied upstream.
-- Petter Reinholdtsen <pere@debian.org> Fri, 16 Aug 2024 22:58:24 +0200
megactl (0.4.4-4) unstable; urgency=medium
* Fixed typo in patch metadata.
* Added 0040-hardening.patch to use CPPFLAGS for hardening during build.
-- Petter Reinholdtsen <pere@debian.org> Wed, 08 May 2024 18:38:44 +0200
megactl (0.4.4-3) unstable; urgency=medium
[ Petter Reinholdtsen ]
* Added some patches fetched from upstream to improve appstrea
metainfo and compiler warnings.
* Updated Standards-Version from 4.6.2 to 4.7.0.
-- Jérémy Lal <kapouer@melix.org> Wed, 17 Apr 2024 13:39:31 +0200
megactl (0.4.4-2) unstable; urgency=medium
* Description: mention megacli. Reformat. Closes: #1069175.
-- Jérémy Lal <kapouer@melix.org> Wed, 17 Apr 2024 13:37:56 +0200
megactl (0.4.4-1) unstable; urgency=medium
* New upstream version 0.4.4
* Drop applied patches
-- Jérémy Lal <kapouer@melix.org> Mon, 15 Apr 2024 11:18:11 +0200
megactl (0.4.3+git20240307.6b1fdab-1) unstable; urgency=medium
* Initial release (Closes: #1065322).
-- Petter Reinholdtsen <pere@debian.org> Thu, 07 Mar 2024 15:41:23 +0100

25
debian/control vendored
View File

@ -1,25 +0,0 @@
Source: megactl
Section: admin
Priority: optional
Maintainer: Jérémy Lal <kapouer@melix.org>
Uploaders: Petter Reinholdtsen <pere@debian.org>
Rules-Requires-Root: no
Build-Depends: debhelper-compat (= 12)
Standards-Version: 4.7.0
Homepage: https://github.com/namiltd/megactl/
Vcs-Browser: https://salsa.debian.org/debian/megactl
Vcs-Git: https://salsa.debian.org/debian/megactl.git
Package: megactl
Architecture: any
Depends: ${misc:Depends}, ${shlibs:Depends}
Description: LSI Megaraid Control and Monitoring Tools
Reports diagnostics on megaraid and megaraid_sas adapters and
attached disks, similar to the original "megacli" tool.
The adapters are also known as Dell PERC2, PERC3, PERC4 and PERC5.
Permits dumping of controller log pages for inspection of error,
temperature, and self-test conditions, initiates self-test
diagnostics, and documents adapter and logical drive configuration.
Target devices may be adapters, (e.g. a0), enclosures (e.g. a0e0),
or individual disks (e.g. a0e0s0). If no target is specified,
reports configuration and drive state on all adapters.

46
debian/copyright vendored
View File

@ -1,46 +0,0 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Source: https://github.com/namiltd/megactl/
Upstream-Name: megactl
Upstream-Contact: Mieczyslaw Nalewaj
Files: *
Copyright:
1984-2003 J. Schilling
1998 D. Dorau, C. Wohlgemuth
2003-2005 LSI Logic Corporation.
2007 Jefferson Ogata
License: GPL-2.0+
Files: megactl.metainfo.xml
Copyright: 2024 Petter Reinholdtsen
License: CC0-1.0
To the extent possible under law, the author(s) have dedicated all
copyright and related and neighboring rights to this software to the
public domain worldwide. This software is distributed without any
warranty.
.
A copy of the CC0 1.0 Universal license can be found in
/usr/share/common-licenses/CC0-1.0.
Files: debian/*
Copyright:
2024 Petter Reinholdtsen <pere@debian.org>
License: GPL-2.0+
License: GPL-2.0+
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, 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; see the file COPYING. If not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
.
On Debian systems, the complete text of the GNU General Public License
Version 2 can be found in `/usr/share/common-licenses/GPL-2'.

2
debian/gbp.conf vendored
View File

@ -1,2 +0,0 @@
[DEFAULT]
pristine-tar = True

View File

@ -1,2 +0,0 @@
megactl.1
megasasctl.1

View File

@ -1,3 +0,0 @@
0xxx: Grabbed from upstream development.
1xxx: Possibly relevant for upstream adoption.
2xxx: Only relevant for official Debian release.

15
debian/rules vendored
View File

@ -1,15 +0,0 @@
#!/usr/bin/make -f
export DH_VERBOSE = 1
# See FEATURE AREAS in dpkg-buildflags(1).
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
# See ENVIRONMENT in dpkg-buildflags(1).
# Package maintainers to append CFLAGS.
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
# Package maintainers to append LDFLAGS.
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
%:
dh $@

11
debian/salsa-ci.yml vendored
View File

@ -1,11 +0,0 @@
# For more information on what jobs are run see:
# https://salsa.debian.org/salsa-ci-team/pipeline
#
# To enable the jobs, go to your repository (at salsa.debian.org)
# and click over Settings > CI/CD > Expand (in General pipelines).
# In "CI/CD configuration file" write debian/salsa-ci.yml and click
# in "Save Changes". The CI tests will run after the next commit.
---
include:
- https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/salsa-ci.yml
- https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/pipeline-jobs.yml

View File

@ -1 +0,0 @@
3.0 (quilt)

View File

@ -1,5 +0,0 @@
Bug-Database: https://github.com/namiltd/megactl/issues
Bug-Submit: https://github.com/namiltd/megactl/issues/new
Documentation: https://github.com/<user>/megactl/wiki
Repository-Browse: https://github.com/namiltd/megactl/
Repository: https://github.com/namiltd/megactl.git

8
debian/watch vendored
View File

@ -1,8 +0,0 @@
# See uscan(1) for format.
# Compulsory line, this is a version 4 file.
version=4
opts="filenamemangle=s%(?:.*?)?v?(@ANY_VERSION@@ARCHIVE_EXT@)%@PACKAGE@-$1%" \
https://github.com/namiltd/megactl/tags \
(?:.*?/)v?@ANY_VERSION@@ARCHIVE_EXT@

View File

@ -1,83 +0,0 @@
.\" Text automatically generated by txt2man
.TH megactl 1 "03 March 2024" ""
.SH NAME
megactl \- diagnostics on megaraid adapters and attached disks.
.SH SYNOPSIS
megactl [\fB-vest\fP] [\fB-H\fP] [\fB-l\fP log-page-nr] [\fB-T\fP long|short] [target \.\.\.]
.PP
Reports diagnostics on megaraid adapters and attached disks. Permits
dumping of controller log pages for inspection of error, temperature,
and self-test conditions, initiates self-test diagnostics, and documents
adapter and logical drive configuration. Target devices may be adapters,
(e.g. a0), channels (e.g. a0c0), or individual disks (e.g. a0c0t0). If
no target is specified, reports configuration and drive state on all
adapters. If a target matches a collection of disks, operations are
applied to all matching devices. Options are:
.TP
.B
\fB-v\fP
Increase program verbosity.
.TP
.B
\fB-e\fP
Dump read (0x03), write (0x02), and verify (0x05) error log
pages.
.TP
.B
\fB-s\fP
Dump self-test (0x10) log page.
.TP
.B
\fB-t\fP
Dump temperature (0x0d) log page.
.TP
.B
\fB-l\fP page
Dump the specified log page. Log page 0 documents the log pages
the device supports.
.TP
.B
\fB-p\fP
Do not report physical disks. Reports only adapters and logical
drives. Useful for concisely documenting adapter configuration.
.TP
.B
\fB-T\fP test
Initiate the background short or long self-test procedure. The
test may take up to an hour to complete, but does not inhibit
access to the device. The test may be monitored using the \fB-s\fP
option.
.TP
.B
\fB-H\fP
Perform an adapter health check. Inspects state of all logical
and physical drives and battery backup unit and reports problem
conditions. If all is well, generates no output. Useful in a
cron job.
.TP
.B
\fB-B\fP
When performing health check, do not treat battery problems as
failures.
.TP
.B
\fB-V\fP
Show version.
.PP
N.B. The background long self test is a useful tool for diagnosing
problems with individual disks. But be cautious with program usage.
"megactl \fB-T\fP long" with no targets will initiate a background long self
test on every drive on every adapter. This may not be what you want.
.PP
By default, the health check option inspects log pages 0x02, 0x03, and
0x05 for uncorrected read, write, and verify errors, 0x0d for excess
temperature conditions, and 0x10 for failed self tests. If, however, any
of the log page options is specified, only the designated log pages are
inspected.
.PP
This program requires the device file /dev/megadev0 to be present on
the system. If your system does not have this device file, you may
create it either by executing Dell's "dellmgr" program once, or by
locating the megadev entry in /proc/devices and creating /dev/megadev0
as a character device with suitable permissions with a matching major
device number and a minor number of 0.

View File

@ -1,53 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<component>
<id>com.github.namiltd.megactl</id>
<metadata_license>CC0-1.0</metadata_license>
<name>megactl</name>
<summary>LSI Megaraid Control and Monitoring Tools</summary>
<description>
<p>
Provide tools to query hard drive and RAID volume status from
PERC2, PERC3, PERC4 and PERC5 adapters.
</p>
</description>
<url type="homepage">https://github.com/namiltd/megactl/</url>
<developer_name>Mieczyslaw Nalewaj</developer_name>
<provides>
<modalias>lkmodule:megaraid</modalias>
<modalias>lkmodule:megaraid_sas</modalias>
<modalias>pci:v00001000d000010E7sv*</modalias>
<modalias>pci:v00001000d000010E4sv*</modalias>
<modalias>pci:v00001000d000010E3sv*</modalias>
<modalias>pci:v00001000d000010E0sv*</modalias>
<modalias>pci:v00001000d000010E6sv*</modalias>
<modalias>pci:v00001000d000010E5sv*</modalias>
<modalias>pci:v00001000d000010E2sv*</modalias>
<modalias>pci:v00001000d000010E1sv*</modalias>
<modalias>pci:v00001000d0000001Csv*</modalias>
<modalias>pci:v00001000d0000001Bsv*</modalias>
<modalias>pci:v00001000d00000017sv*</modalias>
<modalias>pci:v00001000d00000016sv*</modalias>
<modalias>pci:v00001000d00000015sv*</modalias>
<modalias>pci:v00001000d00000014sv*</modalias>
<modalias>pci:v00001000d00000053sv*</modalias>
<modalias>pci:v00001000d00000052sv*</modalias>
<modalias>pci:v00001000d000000CFsv*</modalias>
<modalias>pci:v00001000d000000CEsv*</modalias>
<modalias>pci:v00001000d0000005Fsv*</modalias>
<modalias>pci:v00001000d0000005Dsv*</modalias>
<modalias>pci:v00001000d0000002Fsv*</modalias>
<modalias>pci:v00001000d0000005Bsv*</modalias>
<modalias>pci:v00001028d00000015sv*</modalias>
<modalias>pci:v00001000d00000413sv*</modalias>
<modalias>pci:v00001000d00000071sv*</modalias>
<modalias>pci:v00001000d00000073sv*</modalias>
<modalias>pci:v00001000d00000079sv*</modalias>
<modalias>pci:v00001000d00000078sv*</modalias>
<modalias>pci:v00001000d0000007Csv*</modalias>
<modalias>pci:v00001000d00000060sv*</modalias>
<modalias>pci:v00001000d00000411sv*</modalias>
<modalias>pci:v00008086d00001960sv*</modalias>
<modalias>pci:v0000101Ed00009060sv*</modalias>
<modalias>pci:v0000101Ed00009010sv*</modalias>
</provides>
</component>

View File

@ -1,83 +0,0 @@
.\" Text automatically generated by txt2man
.TH megasasctl 1 "03 March 2024" ""
.SH NAME
megasasctl \- diagnostics on megaraid adapters and attached disks.
.SH SYNOPSIS
megasasctl [\fB-vest\fP] [\fB-H\fP] [\fB-l\fP log-page-nr] [\fB-T\fP long|short] [target \.\.\.]
.PP
Reports diagnostics on megaraid adapters and attached disks. Permits
dumping of controller log pages for inspection of error, temperature,
and self-test conditions, initiates self-test diagnostics, and documents
adapter and logical drive configuration. Target devices may be adapters,
(e.g. a0), enclosures (e.g. a0e0), or individual disks (e.g. a0e0s0). If
no target is specified, reports configuration and drive state on all
adapters. If a target matches a collection of disks, operations are
applied to all matching devices. Options are:
.TP
.B
\fB-v\fP
Increase program verbosity.
.TP
.B
\fB-e\fP
Dump read (0x03), write (0x02), and verify (0x05) error log
pages.
.TP
.B
\fB-s\fP
Dump self-test (0x10) log page.
.TP
.B
\fB-t\fP
Dump temperature (0x0d) log page.
.TP
.B
\fB-l\fP page
Dump the specified log page. Log page 0 documents the log pages
the device supports.
.TP
.B
\fB-p\fP
Do not report physical disks. Reports only adapters and logical
drives. Useful for concisely documenting adapter configuration.
.TP
.B
\fB-T\fP test
Initiate the background short or long self-test procedure. The
test may take up to an hour to complete, but does not inhibit
access to the device. The test may be monitored using the \fB-s\fP
option.
.TP
.B
\fB-H\fP
Perform an adapter health check. Inspects state of all logical
and physical drives and battery backup unit and reports problem
conditions. If all is well, generates no output. Useful in a
cron job.
.TP
.B
\fB-B\fP
When performing health check, do not treat battery problems as
failures.
.TP
.B
\fB-V\fP
Show version.
.PP
N.B. The background long self test is a useful tool for diagnosing
problems with individual disks. But be cautious with program usage.
"megasasctl \fB-T\fP long" with no targets will initiate a background long self
test on every drive on every adapter. This may not be what you want.
.PP
By default, the health check option inspects log pages 0x02, 0x03, and
0x05 for uncorrected read, write, and verify errors, 0x0d for excess
temperature conditions, and 0x10 for failed self tests. If, however, any
of the log page options is specified, only the designated log pages are
inspected.
.PP
This program requires the device file /dev/megaraid_sas_ioctl_node to be
present on the system. If your system does not have this device file,
you may create it either by executing LSI's "MegaCli" program once,
or by locating the megadev_sas_ioctl entry in /proc/devices and creating
/dev/megaraid_sas_ioctl_node as a character device with suitable
permissions with a matching major device number and a minor number of 0.

View File

@ -1,17 +1,11 @@
DESTDIR:=
PREFIX:= /usr
BINDIR:= $(PREFIX)/bin
METAINFODIR:= $(PREFIX)/share/metainfo/
INSTALL= install
SRCS= megactl.c adapter.c megaioctl.c megatrace.c callinfo.c dumpbytes.c logpage.c ntrim.c SRCS= megactl.c adapter.c megaioctl.c megatrace.c callinfo.c dumpbytes.c logpage.c ntrim.c
INC= -I./schily -Iincludes-hack INC= -I./schily -Iincludes-hack
HDRS= mega.h adapter.h megaioctl.h callinfo.h logpage.h dumpbytes.h HDRS= mega.h adapter.h megaioctl.h callinfo.h logpage.h dumpbytes.h
CPPFLAGS+= ARCH= -m32
CFLAGS+= -g -Wall $(INC) $(ARCH) $(CPPFLAGS) CFLAGS= -g -Wall $(INC) $(ARCH)
LDFLAGS+= -g $(ARCH) LDFLAGS= -g $(ARCH)
PROGRAMS= megactl megasasctl PROGRAMS= megactl megasasctl megatrace
all: $(PROGRAMS) all: $(PROGRAMS)
@ -30,12 +24,6 @@ megasasctl.o: megactl.c
%.o: Makefile.bak %.c %.o: Makefile.bak %.c
$(CC) $(CFLAGS) -c -o $@ $*.c $(CC) $(CFLAGS) -c -o $@ $*.c
install: $(PROGRAMS)
$(INSTALL) -d $(DESTDIR)$(BINDIR)/
$(INSTALL) $(PROGRAMS) $(DESTDIR)$(BINDIR)
$(INSTALL) -d $(DESTDIR)$(METAINFODIR)/
$(INSTALL) -m644 megactl.metainfo.xml $(DESTDIR)$(METAINFODIR)/
clean: clean:
$(RM) $(PROGRAMS) *.o $(RM) $(PROGRAMS) *.o

View File

@ -57,8 +57,7 @@ static void batteryStatus5 (struct adapter_config *a)
a->battery.module_missing = !(a->q.v5.adapinfo.hw_present.bbu); a->battery.module_missing = !(a->q.v5.adapinfo.hw_present.bbu);
a->battery.pack_missing = b->type == MEGA_BATTERY_TYPE_NONE; a->battery.pack_missing = b->type == MEGA_BATTERY_TYPE_NONE;
/*a->battery.low_voltage = b->remaining_capacity_alarm || b->remaining_time_alarm || b->fully_discharged;*/ a->battery.low_voltage = b->remaining_capacity_alarm || b->remaining_time_alarm || b->fully_discharged;
a->battery.low_voltage = !b->fully_charged && (b->remaining_time_alarm || b->remaining_capacity_alarm || b->fully_discharged) ;
a->battery.high_temperature = b->over_temperature != 0; a->battery.high_temperature = b->over_temperature != 0;
a->battery.over_charged = b->over_charged != 0; a->battery.over_charged = b->over_charged != 0;
switch (b->charger_status) switch (b->charger_status)
@ -70,7 +69,7 @@ static void batteryStatus5 (struct adapter_config *a)
} }
a->battery.voltage = b->voltage; a->battery.voltage = b->voltage;
a->battery.temperature = b->temperature; a->battery.temperature = b->temperature;
a->battery.healthy = !(a->battery.module_missing || a->battery.pack_missing || a->battery.low_voltage || a->battery.high_temperature /*|| a->battery.cycles_exceeded */|| (a->battery.charger_state != ChargerStateComplete) || (!b->health)); a->battery.healthy = !(a->battery.module_missing || a->battery.pack_missing || a->battery.low_voltage || a->battery.high_temperature || a->battery.cycles_exceeded || (a->battery.charger_state != ChargerStateComplete) || (!b->health));
} }
@ -137,7 +136,7 @@ struct log_page_list *getDriveLogPage (struct physical_drive_info *d, uint8_t pa
} }
static int cmpPhysical (const void *a, const void *b) int cmpPhysical (const void *a, const void *b)
{ {
struct physical_drive_info *x = *((struct physical_drive_info **) a); struct physical_drive_info *x = *((struct physical_drive_info **) a);
struct physical_drive_info *y = *((struct physical_drive_info **) b); struct physical_drive_info *y = *((struct physical_drive_info **) b);
@ -193,10 +192,7 @@ struct physical_drive_info *getPhysicalDriveInfo (struct adapter_config *a, uint
d->channel = info->enclosure; d->channel = info->enclosure;
d->id = info->slot; d->id = info->slot;
if (d->channel == DISK_NOENC) snprintf (d->name, sizeof (d->name), "%se%us%u", a->name, d->channel, d->id);
snprintf (d->name, sizeof (d->name), "%se*s%u", a->name, d->id);
else
snprintf (d->name, sizeof (d->name), "%se%us%u", a->name, d->channel, d->id);
d->inquiry = info->inquiry.inq; d->inquiry = info->inquiry.inq;
strncpy (d->vendor, d->inquiry.vendor_info, sizeof (d->vendor) - 1); strncpy (d->vendor, d->inquiry.vendor_info, sizeof (d->vendor) - 1);
@ -373,7 +369,7 @@ static char *getAdapterConfig2 (struct adapter_config *a)
return "invalid number of logical drives"; return "invalid number of logical drives";
a->num_channels = pinfo->nchannels; a->num_channels = pinfo->nchannels;
if ((a->channel = (uint16_t *) malloc (a->num_channels * sizeof (*a->channel))) == NULL) if ((a->channel = (uint8_t *) malloc (a->num_channels * sizeof (*a->channel))) == NULL)
return "out of memory (channels)"; return "out of memory (channels)";
for (k = 0; k < a->num_channels; ++k) for (k = 0; k < a->num_channels; ++k)
a->channel[k] = k; a->channel[k] = k;
@ -507,7 +503,7 @@ static char *getAdapterConfig3 (struct adapter_config *a)
case 4: break; case 4: break;
default: return "invalid number of channels"; default: return "invalid number of channels";
} }
strncpy (a->product, (char *) pinfo->product_name, sizeof (a->product)); strncpy (a->product, (char *) pinfo->product_name, sizeof (pinfo->product_name));
a->product[sizeof (a->product) - 1] = '\0'; a->product[sizeof (a->product) - 1] = '\0';
ntrim (a->product); ntrim (a->product);
strncpy (a->bios, (char *) pinfo->bios_version, sizeof (a->bios)); strncpy (a->bios, (char *) pinfo->bios_version, sizeof (a->bios));
@ -523,7 +519,7 @@ static char *getAdapterConfig3 (struct adapter_config *a)
return "invalid number of logical drives"; return "invalid number of logical drives";
a->num_channels = pinfo->nchannels; a->num_channels = pinfo->nchannels;
if ((a->channel = (uint16_t *) malloc (a->num_channels * sizeof (*a->channel))) == NULL) if ((a->channel = (uint8_t *) malloc (a->num_channels * sizeof (*a->channel))) == NULL)
return "out of memory (channels)"; return "out of memory (channels)";
for (k = 0; k < a->num_channels; ++k) for (k = 0; k < a->num_channels; ++k)
a->channel[k] = k; a->channel[k] = k;
@ -634,7 +630,7 @@ static char *getAdapterConfig3 (struct adapter_config *a)
} }
static int cmpChannel (const void *a, const void *b) int cmpChannel (const void *a, const void *b)
{ {
int x = (int) *((uint8_t *) a); int x = (int) *((uint8_t *) a);
int y = (int) *((uint8_t *) b); int y = (int) *((uint8_t *) b);
@ -665,7 +661,7 @@ static char *getAdapterConfig5 (struct adapter_config *a)
a->dram_size = pinfo->memory_size; a->dram_size = pinfo->memory_size;
snprintf (a->name, sizeof (a->name), "a%u", a->target.adapno); snprintf (a->name, sizeof (a->name), "a%u", a->target.adapno);
strncpy (a->product, (char *) pinfo->product_name, sizeof (a->product)); strncpy (a->product, (char *) pinfo->product_name, sizeof (pinfo->product_name));
a->product[sizeof (a->product) - 1] = '\0'; a->product[sizeof (a->product) - 1] = '\0';
ntrim (a->product); ntrim (a->product);
@ -700,37 +696,13 @@ static char *getAdapterConfig5 (struct adapter_config *a)
/* Didn't find this enclosure; extend the map */ /* Didn't find this enclosure; extend the map */
++a->num_channels; ++a->num_channels;
if ((a->channel = (uint16_t *) realloc (a->channel, a->num_channels * sizeof (*a->channel))) == NULL) if ((a->channel = (uint8_t *) realloc (a->channel, a->num_channels * sizeof (*a->channel))) == NULL)
return "out of memory (channels)"; return "out of memory (channels)";
a->channel[a->num_channels - 1] = device->device[k].enclosure; a->channel[a->num_channels - 1] = device->device[k].enclosure;
} }
qsort (a->channel, a->num_channels, sizeof (*a->channel), cmpChannel); qsort (a->channel, a->num_channels, sizeof (*a->channel), cmpChannel);
/* Some notes: a->num_physicals = pinfo->pd_present_count;
Different meanings on different models.
- FC_MAX_PHYSICAL_DEVICES used on older controllers, which is 256
disks (overallocation)
- pd_disk_present_count is number of working drives, not counting
missing drives
- pd_present_count is unclear. It is pd_disk_present_count + 1 on some
controllers
- device_interface.port_count contains number of physical ports on the
controller
pd_present_count was used here, but in some controllers causes segfaults
when there is a failed drive, and not enough space is allocated.
Since there cannot be more devices than there are ports, that is a safe
number to set without going overboard.
*/
a->num_physicals = pinfo->device_interface.port_count;
/* On some controllers, namely the PERC6e, the controller does not know
how many ports there are in the enclosure. Fall back to the worst case
scenario. */
if (a->num_physicals < pinfo->pd_disk_present_count)
a->num_physicals = FC_MAX_PHYSICAL_DEVICES;
if ((a->physical = (struct physical_drive_info *) malloc (a->num_physicals * sizeof (*a->physical))) == NULL) if ((a->physical = (struct physical_drive_info *) malloc (a->num_physicals * sizeof (*a->physical))) == NULL)
return "out of memory (physical drives)"; return "out of memory (physical drives)";
memset (a->physical, 0, a->num_physicals * sizeof (*a->physical)); memset (a->physical, 0, a->num_physicals * sizeof (*a->physical));

View File

@ -107,12 +107,23 @@ static char *friendlySize (uint64_t b, char *unit)
for (k = 0; (b >= 1024) && (k < sizeof (suffix) / sizeof (suffix[0]) - 1); ++k, b /= 1024) for (k = 0; (b >= 1024) && (k < sizeof (suffix) / sizeof (suffix[0]) - 1); ++k, b /= 1024)
; ;
snprintf (bytes, sizeof bytes, "%3llu%s%s", snprintf (bytes, sizeof bytes, "%3llu%s%s", b, suffix[k], unit);
(long long unsigned int)b, suffix[k], unit);
return bytes; return bytes;
} }
static uint32_t blocksToGB (uint32_t blocks)
{
return (long) (((uint64_t) blocks) * 512 / 1000000000);
}
static uint32_t blocksToGiB (uint32_t blocks)
{
return blocks / 2 / 1024 / 1024;
}
static uint64_t extractInt64 (void *u, size_t len) static uint64_t extractInt64 (void *u, size_t len)
{ {
uint64_t x; uint64_t x;
@ -367,8 +378,7 @@ void dumpLogPage (FILE *f, struct logData *x, void *log, size_t len, int verbosi
default: result = "unknown result"; notice = 0; break; default: result = "unknown result"; notice = 0; break;
} }
if (verbosity > notice) if (verbosity > notice)
fprintf (f, " %2d: timestamp %4ud%02uh: %10s %-30s seg:%u lba:%-8lld sk:%u asc:%u ascq:%u vs:%u\n", k, t->timestamp / 24, t->timestamp % 24, test, result, t->number, fprintf (f, " %2d: timestamp %4ud%02uh: %10s %-30s seg:%u lba:%-8lld sk:%u asc:%u ascq:%u vs:%u\n", k, t->timestamp / 24, t->timestamp % 24, test, result, t->number, t->lba, t->sense_key, t->additional_sense_code, t->additional_sense_code_qualifier, t->vendor_specific);
(long long int)t->lba, t->sense_key, t->additional_sense_code, t->additional_sense_code_qualifier, t->vendor_specific);
} }
} }
break; break;

View File

@ -114,8 +114,6 @@ struct list_head {
#define SCSI_SELFTEST_FOREGROUND_SHORT 0x05 #define SCSI_SELFTEST_FOREGROUND_SHORT 0x05
#define SCSI_SELFTEST_FOREGROUND_LONG 0x06 #define SCSI_SELFTEST_FOREGROUND_LONG 0x06
/* Drives without enclosure report this as the enclosure ID */
#define DISK_NOENC 0xffff
/* megaraid2 header file gets this wrong. */ /* megaraid2 header file gets this wrong. */
typedef struct { typedef struct {
@ -547,7 +545,7 @@ struct adapter_config
uint16_t dram_size; /* size of DRAM in MB */ uint16_t dram_size; /* size of DRAM in MB */
uint16_t rebuild_rate; /* rebuild rate as percentage */ uint16_t rebuild_rate; /* rebuild rate as percentage */
uint16_t num_channels; /* number of channels or enclosures */ uint16_t num_channels; /* number of channels or enclosures */
uint16_t *channel; /* channel/enclosure map */ uint8_t *channel; /* channel/enclosure map */
uint16_t num_physicals; uint16_t num_physicals;
struct physical_drive_info *physical; struct physical_drive_info *physical;
struct physical_drive_info **physical_list; /* ordered list of physical devices */ struct physical_drive_info **physical_list; /* ordered list of physical devices */

View File

@ -43,8 +43,6 @@ Cleaner log page output.
Fixes for 64-bit systems. Currently builds only with -m32. Fixes for 64-bit systems. Currently builds only with -m32.
Fetch TTY logs.
********************************************************************/ ********************************************************************/
#include "mega.h" #include "mega.h"
@ -63,8 +61,6 @@ Fetch TTY logs.
#include <signal.h> #include <signal.h>
#include <ctype.h> #include <ctype.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <scg/scsireg.h> #include <scg/scsireg.h>
@ -76,19 +72,17 @@ Fetch TTY logs.
#ifdef MEGA_SAS_CTL #ifdef MEGA_SAS_CTL
#define MEGA_DEVICE "/dev/megaraid_sas_ioctl_node" #define MEGA_DEVICE "/dev/megaraid_sas_ioctl_node"
#define MEGA_NAME "megaraid_sas_ioctl"
#else #else
#define MEGA_DEVICE "/dev/megadev0" #define MEGA_DEVICE "/dev/megadev0"
#define MEGA_NAME "megadev"
#define MEGA_MIN_VERSION 0x118c #define MEGA_MIN_VERSION 0x118c
#endif /* defined(MEGA_SAS_CTL) */ #endif /* defined(MEGA_SAS_CTL) */
static char *version = "0.4.3-hmage"; static char *version = "0.4.1";
static int verbosity = 0; static int verbosity = 0;
@ -161,7 +155,7 @@ MEGA_DEVICE " as a character device with suitable",
}; };
static void usage (const int ec, const char *format, ...) void usage (const int ec, const char *format, ...)
{ {
char **u; char **u;
va_list ap; va_list ap;
@ -211,14 +205,14 @@ static char *friendlySize (uint64_t b, char *unit)
int k; int k;
static char bytes[128]; static char bytes[128];
for (k = 0; (b >= 10000) && (k < sizeof (suffix) / sizeof (suffix[0]) - 1); ++k, b /= 1024) for (k = 0; (b >= 1024) && (k < sizeof (suffix) / sizeof (suffix[0]) - 1); ++k, b /= 1024)
; ;
snprintf (bytes, sizeof bytes, "%4"PRIu64"%s%s", b, suffix[k], unit); snprintf (bytes, sizeof bytes, "%3llu%s%s", b, suffix[k], unit);
return bytes; return bytes;
} }
static void describePhysicalDrive (FILE *f, struct physical_drive_info *d, int verbosity) void describePhysicalDrive (FILE *f, struct physical_drive_info *d, int verbosity)
{ {
char *state; char *state;
@ -241,7 +235,7 @@ static void describePhysicalDrive (FILE *f, struct physical_drive_info *d, int v
fprintf (f, " %8s %-16s", d->vendor, d->model); fprintf (f, " %8s %-16s", d->vendor, d->model);
if (verbosity > 1) if (verbosity > 1)
fprintf (f, " rev:%-4s s/n:%-20s", d->revision, d->serial); fprintf (f, " rev:%-4s s/n:%-20s", d->revision, d->serial);
fprintf (f, " %8s", friendlySize (d->blocks << 9, "B")); fprintf (f, " %7s", friendlySize (d->blocks << 9, "B"));
fprintf (f, " %5s%c", d->span && d->span->num_logical_drives ? d->span->logical_drive[0]->name : "", d->span && (d->span->num_logical_drives > 1) ? '+' : ' '); fprintf (f, " %5s%c", d->span && d->span->num_logical_drives ? d->span->logical_drive[0]->name : "", d->span && (d->span->num_logical_drives > 1) ? '+' : ' ');
fprintf (f, " %-8s", state); fprintf (f, " %-8s", state);
if (d->media_errors || d->other_errors) if (d->media_errors || d->other_errors)
@ -254,7 +248,7 @@ static void describePhysicalDrive (FILE *f, struct physical_drive_info *d, int v
} }
static void describeLogicalDrive (FILE *f, struct logical_drive_info *l, int verbosity) void describeLogicalDrive (FILE *f, struct logical_drive_info *l, int verbosity)
{ {
char *state; char *state;
uint64_t blocks; uint64_t blocks;
@ -279,12 +273,11 @@ static void describeLogicalDrive (FILE *f, struct logical_drive_info *l, int ver
case 0: blocks += r->blocks_per_disk * r->span->num_disks; break; case 0: blocks += r->blocks_per_disk * r->span->num_disks; break;
case 1: blocks += r->blocks_per_disk * r->span->num_disks / 2; break; case 1: blocks += r->blocks_per_disk * r->span->num_disks / 2; break;
case 5: blocks += r->blocks_per_disk * (r->span->num_disks - 1); break; case 5: blocks += r->blocks_per_disk * (r->span->num_disks - 1); break;
case 6: blocks += r->blocks_per_disk * (r->span->num_disks - 2); break;
} }
} }
fprintf (f, "%-8s", l->name); fprintf (f, "%-8s", l->name);
fprintf (f, " %8s", friendlySize (blocks << 9, "B")); fprintf (f, " %s", friendlySize (blocks << 9, "B"));
fprintf (f, " RAID %u%s", l->raid_level, l->num_spans > 1 ? "0" : " "); fprintf (f, " RAID %u%s", l->raid_level, l->num_spans > 1 ? "0" : " ");
fprintf (f, " %2ux%-2u", l->num_spans, l->span_size); fprintf (f, " %2ux%-2u", l->num_spans, l->span_size);
fprintf (f, " %s", state); fprintf (f, " %s", state);
@ -297,7 +290,7 @@ static void describeLogicalDrive (FILE *f, struct logical_drive_info *l, int ver
int j; int j;
r = &l->span[k]; r = &l->span[k];
fprintf (f, " row %2d:", k); fprintf (f, " row %2d:", k);
for (j = 0, p = r->span->disk; j < r->span->num_disks; ++j, ++p) for (j = 0, p = r->span->disk; j < r->span->num_disks; ++j, ++p)
{ {
char *flag = (*p)->state != PdStateOnline ? "*" : " "; char *flag = (*p)->state != PdStateOnline ? "*" : " ";
@ -309,7 +302,7 @@ static void describeLogicalDrive (FILE *f, struct logical_drive_info *l, int ver
} }
static void describeBattery (FILE *f, struct adapter_config *a, int verbosity) void describeBattery (FILE *f, struct adapter_config *a, int verbosity)
{ {
if (a->battery.healthy) if (a->battery.healthy)
fprintf (f, "good"); fprintf (f, "good");
@ -346,7 +339,7 @@ static void describeBattery (FILE *f, struct adapter_config *a, int verbosity)
} }
static void describeAdapter (FILE *f, struct adapter_config *a, int verbosity) void describeAdapter (FILE *f, struct adapter_config *a, int verbosity)
{ {
fprintf (f, "%-8s %-24s", a->name, a->product); fprintf (f, "%-8s %-24s", a->name, a->product);
if (verbosity > 0) if (verbosity > 0)
@ -366,8 +359,8 @@ int main (int argc, char **argv)
{ {
int k; int k;
int fd; int fd;
uint32_t driverVersion = 0;
uint32_t numAdapters; uint32_t numAdapters;
uint32_t driverVersion;
int startSelfTest = -1; int startSelfTest = -1;
int healthCheck = 0; int healthCheck = 0;
int checkBattery = 1; int checkBattery = 1;
@ -381,11 +374,6 @@ int main (int argc, char **argv)
uint8_t readLog[LOG_PAGE_MAX] = { 0, }; uint8_t readLog[LOG_PAGE_MAX] = { 0, };
int reportPhysical = 1; int reportPhysical = 1;
int showVersion = 0; int showVersion = 0;
FILE *fp;
char *line = NULL;
int major;
size_t len = 0;
char lf;
#ifdef MEGA_SAS_CTL #ifdef MEGA_SAS_CTL
int sas = 1; int sas = 1;
#else #else
@ -600,33 +588,8 @@ int main (int argc, char **argv)
if ((fd = open (device, O_RDONLY)) < 0) if ((fd = open (device, O_RDONLY)) < 0)
{ {
if ((fp = fopen ("/proc/devices", "r")) == NULL) fprintf (stderr, "unable to open device %s: %s\n", device, strerror (errno));
{ return 1;
fprintf (stderr, "file /proc/devices access error\n");
return 1;
} else {
while (getline(&line, &len, fp) != -1)
{
if ((sscanf(line, "%d "MEGA_NAME"%c", &major, &lf) == 2) && (lf = 10))
{
mknod(device, S_IFCHR /*| 0666*/, makedev(major, 0));
free(line);
break;
}
if (line)
{
free(line);
line = NULL;
}
}
fclose(fp);
}
if ((fd = open (device, O_RDONLY)) < 0)
{
fprintf (stderr, "unable to open device %s: %s\n", device, strerror (errno));
return 1;
}
} }
#ifndef MEGA_SAS_CTL #ifndef MEGA_SAS_CTL
@ -645,7 +608,7 @@ int main (int argc, char **argv)
if (megaGetNumAdapters (fd, &numAdapters, sas) < 0) if (megaGetNumAdapters (fd, &numAdapters, sas) < 0)
{ {
fprintf (stderr, "unable to find any adapters: %s\n", megaErrorString ()); fprintf (stderr, "unable to determine number of adapters: %s\n", megaErrorString ());
return 1; return 1;
} }
@ -843,9 +806,9 @@ int main (int argc, char **argv)
if (d->state == PdStateHotspare) if (d->state == PdStateHotspare)
{ {
if (x == 0) if (x == 0)
fprintf (stdout, "hot spares :"); fprintf (stdout, "hot spares :");
else if ((x % 8) == 0) else if ((x % 8) == 0)
fprintf (stdout, " :"); fprintf (stdout, " :");
fprintf (stdout, " %-8s", d->name); fprintf (stdout, " %-8s", d->name);
if (((++x) % 8) == 0) if (((++x) % 8) == 0)
fprintf (stdout, "\n"); fprintf (stdout, "\n");
@ -867,9 +830,9 @@ int main (int argc, char **argv)
if ((!(d->span)) && (d->state != PdStateHotspare)) if ((!(d->span)) && (d->state != PdStateHotspare))
{ {
if (x == 0) if (x == 0)
fprintf (stdout, "unconfigured:"); fprintf (stdout, "unconfigured :");
else if ((x % 8) == 0) else if ((x % 8) == 0)
fprintf (stdout, " :"); fprintf (stdout, " :");
fprintf (stdout, " %-8s", d->name); fprintf (stdout, " %-8s", d->name);
if (((++x) % 8) == 0) if (((++x) % 8) == 0)
fprintf (stdout, "\n"); fprintf (stdout, "\n");

View File

@ -25,7 +25,6 @@
/* Don't include <sys/types.h> */ /* Don't include <sys/types.h> */
#include <assert.h>
#include <memory.h> #include <memory.h>
#include <malloc.h> #include <malloc.h>
#include <errno.h> #include <errno.h>
@ -33,30 +32,9 @@
#include <scsi/scsi.h> #include <scsi/scsi.h>
/* This is arbitrary. */
#define MEGA_MAX_ADAPTERS 16
struct mega_adapter_map
{
uint8_t count; /* number of adapters found */
uint8_t host[MEGA_MAX_ADAPTERS]; /* map of adapter index to host number */
};
static struct mega_adapter_map *adapterMap = NULL;
int megaErrno = 0; int megaErrno = 0;
static u16 hostMap (u16 adapno)
{
if ((adapterMap == NULL) || (adapno >= adapterMap->count))
return 0;
return adapterMap->host[adapno];
}
static int doIoctl (struct mega_adapter_path *adapter, void *u) static int doIoctl (struct mega_adapter_path *adapter, void *u)
{ {
switch (adapter->type) switch (adapter->type)
@ -71,7 +49,7 @@ static int doIoctl (struct mega_adapter_path *adapter, void *u)
} }
static int driverQuery (int fd, void *data, uint32_t len, uint8_t subop) static int driverQuery (int fd, uint16_t adap, void *data, uint32_t len, uint8_t subop)
{ {
struct uioctl_t u; struct uioctl_t u;
struct mega_adapter_path adapter; struct mega_adapter_path adapter;
@ -86,7 +64,6 @@ static int driverQuery (int fd, void *data, uint32_t len, uint8_t subop)
memset (data, 0, len); memset (data, 0, len);
adapter.fd = fd; adapter.fd = fd;
adapter.adapno = 0;
adapter.type = MEGA_ADAPTER_V34; adapter.type = MEGA_ADAPTER_V34;
if (doIoctl (&adapter, &u) < 0) if (doIoctl (&adapter, &u) < 0)
{ {
@ -105,12 +82,11 @@ static int oldCommand (struct mega_adapter_path *adapter, void *data, uint32_t l
memset (&u, 0, sizeof u); memset (&u, 0, sizeof u);
u.outlen = len; u.outlen = len;
u.ui.fcs.opcode = M_RD_IOCTL_CMD; u.ui.fcs.opcode = M_RD_IOCTL_CMD;
u.ui.fcs.adapno = MKADAP(hostMap (adapter->adapno)); u.ui.fcs.adapno = MKADAP(adapter->adapno);
u.data = data; u.data = data;
m->cmd = cmd; m->cmd = cmd;
m->opcode = opcode; m->opcode = opcode;
m->subopcode = subopcode; m->subopcode = subopcode;
assert(UINT32_MAX > (uint32_t) data);
m->xferaddr = (uint32_t) data; m->xferaddr = (uint32_t) data;
if (data) if (data)
memset (data, 0, len); memset (data, 0, len);
@ -132,14 +108,13 @@ static int newCommand (struct mega_adapter_path *adapter, void *data, uint32_t l
memset (&u, 0, sizeof u); memset (&u, 0, sizeof u);
u.outlen = len; u.outlen = len;
u.ui.fcs.opcode = M_RD_IOCTL_CMD_NEW; u.ui.fcs.opcode = M_RD_IOCTL_CMD_NEW;
u.ui.fcs.adapno = MKADAP(hostMap (adapter->adapno)); u.ui.fcs.adapno = MKADAP(adapter->adapno);
u.ui.fcs.buffer = data; u.ui.fcs.buffer = data;
u.ui.fcs.length = len; u.ui.fcs.length = len;
u.data = data; u.data = data;
m->cmd = cmd; m->cmd = cmd;
m->opcode = opcode; m->opcode = opcode;
m->subopcode = subopcode; m->subopcode = subopcode;
assert(UINT32_MAX > (uint32_t) data);
m->xferaddr = (uint32_t) data; m->xferaddr = (uint32_t) data;
if (data) if (data)
memset (data, 0, len); memset (data, 0, len);
@ -159,7 +134,7 @@ static int sasCommand (struct mega_adapter_path *adapter, void *data, uint32_t l
struct megasas_dcmd_frame *f = (struct megasas_dcmd_frame *) &u.frame; struct megasas_dcmd_frame *f = (struct megasas_dcmd_frame *) &u.frame;
memset (&u, 0, sizeof u); memset (&u, 0, sizeof u);
u.host_no = hostMap (adapter->adapno); u.host_no = (u16) adapter->adapno;
f->cmd = MFI_CMD_DCMD; f->cmd = MFI_CMD_DCMD;
f->flags = (u16) flags; f->flags = (u16) flags;
@ -172,7 +147,6 @@ static int sasCommand (struct mega_adapter_path *adapter, void *data, uint32_t l
u.sgl[0].iov_base = data; u.sgl[0].iov_base = data;
u.sgl[0].iov_len = len; u.sgl[0].iov_len = len;
f->sge_count = 1; f->sge_count = 1;
assert(UINT32_MAX > (uint32_t) data);
f->data_xfer_len = (u32) len; f->data_xfer_len = (u32) len;
f->sgl.sge32[0].phys_addr = (u32) data; f->sgl.sge32[0].phys_addr = (u32) data;
f->sgl.sge32[0].length = (u32) len; f->sgl.sge32[0].length = (u32) len;
@ -201,15 +175,13 @@ static int passthruCommand (struct mega_adapter_path *adapter, void *data, uint3
memset (&u, 0, sizeof u); memset (&u, 0, sizeof u);
u.outlen = len; u.outlen = len;
u.ui.fcs.opcode = M_RD_IOCTL_CMD; u.ui.fcs.opcode = M_RD_IOCTL_CMD;
u.ui.fcs.adapno = MKADAP(hostMap (adapter->adapno)); u.ui.fcs.adapno = MKADAP(adapter->adapno);
u.data = data; u.data = data;
m->cmd = MBOXCMD_PASSTHRU; m->cmd = MBOXCMD_PASSTHRU;
assert(UINT32_MAX > (uint32_t) p);
m->xferaddr = (uint32_t) p; m->xferaddr = (uint32_t) p;
p->timeout = 3; p->timeout = 3;
p->ars = 1; p->ars = 1;
p->target = target; p->target = target;
assert(UINT32_MAX > (uint32_t) data);
p->dataxferaddr = (uint32_t) data; p->dataxferaddr = (uint32_t) data;
p->dataxferlen = len; p->dataxferlen = len;
p->scsistatus = 239; /* HMMM */ p->scsistatus = 239; /* HMMM */
@ -247,7 +219,7 @@ static int passthruCommand (struct mega_adapter_path *adapter, void *data, uint3
struct megasas_pthru_frame *f = (struct megasas_pthru_frame *) &u.frame; struct megasas_pthru_frame *f = (struct megasas_pthru_frame *) &u.frame;
memset (&u, 0, sizeof u); memset (&u, 0, sizeof u);
u.host_no = hostMap (adapter->adapno); u.host_no = (u16) adapter->adapno;
f->cmd = MFI_CMD_PD_SCSI_IO; f->cmd = MFI_CMD_PD_SCSI_IO;
f->target_id = target; f->target_id = target;
@ -263,7 +235,6 @@ static int passthruCommand (struct mega_adapter_path *adapter, void *data, uint3
u.sgl[0].iov_len = len; u.sgl[0].iov_len = len;
f->sge_count = 1; f->sge_count = 1;
assert(UINT32_MAX > (uint32_t) len);
f->data_xfer_len = (u32) len; f->data_xfer_len = (u32) len;
f->sgl.sge32[0].phys_addr = (u32) data; f->sgl.sge32[0].phys_addr = (u32) data;
f->sgl.sge32[0].length = (u32) len; f->sgl.sge32[0].length = (u32) len;
@ -415,7 +386,7 @@ int megaGetDriveErrorCount (struct mega_adapter_path *adapter, uint8_t target, s
int megaSasGetDeviceList (struct mega_adapter_path *adapter, struct mega_device_list_sas **data) int megaSasGetDeviceList (struct mega_adapter_path *adapter, struct mega_device_list_sas **data)
{ {
unsigned char buf[sizeof(struct mega_device_list_sas)]; unsigned char buf[0x20];
uint32_t len; uint32_t len;
if (sasCommand (adapter, buf, sizeof buf, 0x02010000, MFI_FRAME_DIR_READ, NULL, 0) < 0) if (sasCommand (adapter, buf, sizeof buf, 0x02010000, MFI_FRAME_DIR_READ, NULL, 0) < 0)
@ -480,55 +451,23 @@ int megaSasGetBatteryInfo (struct mega_adapter_path *adapter, struct mega_batter
int megaGetDriverVersion (int fd, uint32_t *version) int megaGetDriverVersion (int fd, uint32_t *version)
{ {
return driverQuery (fd, version, sizeof (*version), 'e'); return driverQuery (fd, 0, version, sizeof (*version), 'e');
} }
int megaGetNumAdapters (int fd, uint32_t *numAdapters, int sas) int megaGetNumAdapters (int fd, uint32_t *numAdapters, int sas)
{ {
static struct mega_adapter_map realMap;
uint8_t k;
uint8_t count;
if (sas) if (sas)
{ {
if (adapterMap == NULL) uint8_t k;
{ for (k = 0; k < 16; ++k)
struct mega_adapter_map fakeMap; if (megaSasAdapterPing (fd, k) < 0)
break;
/* initialize fake map to 1-to-1 map */ *numAdapters = k;
for (k = 0; k < MEGA_MAX_ADAPTERS; ++k) return 0;
fakeMap.host[k] = k;
fakeMap.count = k;
adapterMap = &fakeMap;
/* ping all possible adapters to build real map */
count = 0;
for (k = 0; k < MEGA_MAX_ADAPTERS; ++k)
if (megaSasAdapterPing (fd, k) >= 0)
realMap.host[count++] = k;
realMap.count = count;
adapterMap = &realMap;
}
} }
else else
{ return driverQuery (fd, 0, numAdapters, sizeof (*numAdapters), 'm');
if (adapterMap == NULL)
{
if (driverQuery (fd, &count, sizeof (count), 'm') < 0)
return -1;
if (count > MEGA_MAX_ADAPTERS)
count = MEGA_MAX_ADAPTERS;
for (k = 0; k < count; ++k)
realMap.host[k] = k;
realMap.count = count;
adapterMap = &realMap;
}
}
*numAdapters = adapterMap->count;
return 0;
} }

View File

@ -60,10 +60,6 @@ struct uioctl_t {
#pragma pack() #pragma pack()
/* Timestamps in the megaraid_sas event log are offset by this quantity. This is the epoch time of 2000-01-01T00:00:00 +0000. */
#define MEGA_SAS_TIME_OFFSET 0x386d4380
extern int megaErrno; extern int megaErrno;
extern int megaScsiDriveInquiry (struct mega_adapter_path *adapter, uint8_t target, void *data, uint32_t len, uint8_t pageCode, uint8_t evpd); extern int megaScsiDriveInquiry (struct mega_adapter_path *adapter, uint8_t target, void *data, uint32_t len, uint8_t pageCode, uint8_t evpd);
@ -84,10 +80,7 @@ extern int megaSasGetArrayConfig (struct mega_adapter_path *adapter, struct mega
extern int megaSasGetBatteryInfo (struct mega_adapter_path *adapter, struct mega_battery_info_sas *data); extern int megaSasGetBatteryInfo (struct mega_adapter_path *adapter, struct mega_battery_info_sas *data);
extern int megaGetDriverVersion (int fd, uint32_t *version); extern int megaGetDriverVersion (int fd, uint32_t *version);
/* You must call megaGetNumAdapters() before you issue any other inquiries, other than megaGetDriverVersion(). */
extern int megaGetNumAdapters (int fd, uint32_t *numAdapters, int sas); extern int megaGetNumAdapters (int fd, uint32_t *numAdapters, int sas);
extern int megaGetAdapterProductInfo (int fd, uint8_t adapno, mraid_pinfo_t *info); extern int megaGetAdapterProductInfo (int fd, uint8_t adapno, mraid_pinfo_t *info);
extern int megaSasGetAdapterProductInfo (int fd, uint8_t adapno, struct megasas_ctrl_info *info); extern int megaSasGetAdapterProductInfo (int fd, uint8_t adapno, struct megasas_ctrl_info *info);
extern int megaSasAdapterPing (int fd, uint8_t adapno); extern int megaSasAdapterPing (int fd, uint8_t adapno);

View File

@ -63,7 +63,7 @@ Fixes for 64-bit systems.
enum state { UNTRACED, INBOUND, OUTBOUND }; enum state { UNTRACED, INBOUND, OUTBOUND };
static inline void copyout (void *buf, size_t len, pid_t pid, uint32_t addr) void copyout (void *buf, size_t len, pid_t pid, uint32_t addr)
{ {
off_t k; off_t k;
uint32_t *z = (uint32_t *) buf; uint32_t *z = (uint32_t *) buf;
@ -77,7 +77,7 @@ static inline void copyout (void *buf, size_t len, pid_t pid, uint32_t addr)
} }
static inline void copyin (void *buf, size_t len, pid_t pid, uint32_t addr) void copyin (void *buf, size_t len, pid_t pid, uint32_t addr)
{ {
off_t k; off_t k;
uint32_t *z = (uint32_t *) buf; uint32_t *z = (uint32_t *) buf;

Some files were not shown because too many files have changed in this diff Show More