megactl/debian/patches/002-No_enclosure_support.patch
2025-08-06 17:01:19 +02:00

67 lines
2.6 KiB
Diff

Author:
Description: The root of the problem is that a lot of the logic behind building
the enclosure map and printing the disk list compares directly the
adapter channel list with the physical disk enclosure number, like so:
if (device->device[k].enclosure == a->channel[j])
The problem is that one is a uint16_t and the other is a uint8_t.
When an enclosure is not present, the value comes back as all-ones.
So, the code was trying in numerous places to compare 0xffff with
0xff. Adjusting the struct so both members are uint16_t fixes this.
The patch also changes the output when no enclosure is present to
put an asterisk as the enclosure ID in the output.
The output on the same machine now looks like this:
a0 PERC 5/i Integrated encl:1 ldrv:2 batt:good
a0d0 19GiB RAID 5 1x4 DEGRADED
a0d1 5567GiB RAID 5 1x4 DEGRADED
a0e*s0 1863GiB a0d0+ online errs: media:0 other:28
a0e*s1 1863GiB a0d0+ rebuild errs: media:0 other:26
a0e*s2 1863GiB a0d0+ online errs: media:0 other:28
a0e*s3 1863GiB a0d0+ online errs: media:0 other:28
--- megactl.orig/src/adapter.c
+++ megactl/src/adapter.c
@@ -192,7 +192,10 @@ struct physical_drive_info *getPhysicalD
d->channel = info->enclosure;
d->id = info->slot;
- snprintf (d->name, sizeof (d->name), "%se%us%u", a->name, d->channel, d->id);
+ if (d->channel == DISK_NOENC)
+ 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;
strncpy (d->vendor, d->inquiry.vendor_info, sizeof (d->vendor) - 1);
@@ -691,6 +694,7 @@ static char *getAdapterConfig5 (struct a
for (j = 0; j < a->num_channels; ++j)
if (device->device[k].enclosure == a->channel[j])
break;
+
if (j < a->num_channels)
continue;
--- megactl.orig/src/mega.h
+++ megactl/src/mega.h
@@ -114,6 +114,9 @@ struct list_head {
#define SCSI_SELFTEST_FOREGROUND_SHORT 0x05
#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. */
typedef struct {
@@ -545,7 +548,7 @@ struct adapter_config
uint16_t dram_size; /* size of DRAM in MB */
uint16_t rebuild_rate; /* rebuild rate as percentage */
uint16_t num_channels; /* number of channels or enclosures */
- uint8_t *channel; /* channel/enclosure map */
+ uint16_t *channel; /* channel/enclosure map */
uint16_t num_physicals;
struct physical_drive_info *physical;
struct physical_drive_info **physical_list; /* ordered list of physical devices */