Skip to content

Fix error for non slot devices.#11

Open
SimonFair wants to merge 2 commits into
mainfrom
Disks-capacity-size-
Open

Fix error for non slot devices.#11
SimonFair wants to merge 2 commits into
mainfrom
Disks-capacity-size-

Conversation

@SimonFair

@SimonFair SimonFair commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Add animation for zfs array disk.

Summary by CodeRabbit

  • New Features

    • Added support for animating “peer” disks that belong to the same storage group.
  • Bug Fixes

    • Improved ZFS disk-to-bay mapping for array-backed devices by recognizing additional md/mapper-style aliases.
    • Skips improperly named disks when generating the displayed disk inventory.
  • Tests

    • Added/updated ZFS fixtures and a new array-device scenario to verify correct JSON output and mapping behavior.

Add animation for zfs array disk.
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 84cd6e37-b101-44f0-b0b6-3b4cbd89d3d1

📥 Commits

Reviewing files that changed from the base of the PR and between ae41552 and d0552e0.

📒 Files selected for processing (1)
  • tests/run.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/run.php

📝 Walkthrough

Walkthrough

The PHP zfs_info.php gains md-device alias registration in the drivemap lookup, removes the pool-member warning generation from verify_zfs_device_format(), and filters non-card-drive disk entries in generate_zfs_info(). A new tests/fixtures/zfs_array/ directory supplies zpool_status, zpool_iostat, and list fixtures for disk1 and zmirror pools, with new assertions in tests/run.php. Separately, a JS showStorageGroupPeers helper is added and wired into showAnimations.

Changes

PHP ZFS backend: array device lookup, filtering, and tests

Layer / File(s) Summary
ZFS lookup aliases, warning removal, and name filtering
php/zfs_info.php
zfs_drivemap_lookup() registers md<N>, /dev/md<N>, /dev/mapper/md<N>, and p1 variants for storage-label bay ids. verify_zfs_device_format() is reduced to returning an empty $alert array. generate_zfs_info() skips disk entries whose name doesn't match ^\d+-\d+$.
zfs_array fixtures and test assertions
tests/fixtures/zfs_array/*, tests/run.php
Adds zfs_list.txt, zpool_list.txt, and eight zpool_status_*/zpool_iostat_* fixture files for disk1 and zmirror. Test block sets fixture dir to zfs_array, calls the zfs_info endpoint, and asserts md1p1→bay 1-1 mapping, absence of raw device keys, and empty warnings.

JS storage group peer animation

Layer / File(s) Summary
showStorageGroupPeers implementation and call-site integration
assets/45d/45drives-disks/assets/index.bbceb330.js
Adds p5.showStorageGroupPeers which looks up the current disk's storage group, iterates members against diskLocations2, and calls p5.animateZpools(...) for each peer with a valid image. p5.showAnimations is updated to call this new helper.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 Hop hop, the arrays now map with care,
md1p1 finds its bay — it's finally there!
Old warnings silenced, the noise stripped clean,
Peer disks animate across the screen.
New fixtures planted, assertions bloom bright,
The drivemap burrows deeper into the night! 🌙


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 1 warning)

Check name Status Explanation Resolution
Title check ❌ Error The pull request title does not follow the conventional commits format (e.g., fix:, feat:, etc.) as required by the project's merge policy. Update the title to follow conventional commits format, e.g., 'fix: error for non-slot devices' or 'fix: handle non-slot device errors'.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch Disks-capacity-size-
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch Disks-capacity-size-

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@assets/45d/45drives-disks/assets/index.bbceb330.js`:
- Around line 23297-23303: The forEach loop that animates storage group members
currently includes the current disk in the animation. Within the group.forEach
loop where dsk is iterated, add an additional condition to skip the current disk
(cd) so that only peer members are animated. Check if dsk.name (or dsk) matches
the current disk identifier and return early if it does, before calling
p5.animateZpools. This ensures peer-only highlighting by excluding the current
disk from the animation loop.

In `@php/zfs_info.php`:
- Around line 415-419: The verify_zfs_device_format() function currently returns
an empty alert array unconditionally, which suppresses warnings for all cases
including genuinely malformed or unexpectedly mapped devices. Modify the return
statement to conditionally return an empty array only for valid non-bay devices
(boot, flash, standalone NVMe pools), while ensuring that genuinely malformed or
unexpectedly mapped members still populate and return the alert array with
appropriate diagnostic warnings. This requires adding conditional logic before
the return statement to distinguish between non-slot devices that should be
silenced and actual format violations that should still be reported.

In `@tests/run.php`:
- Around line 556-567: The putenv call that sets DRIVEMAP_ZFS_FIXTURE_DIR at the
beginning of the test block mutates the global process environment and leaves it
set after the block completes, which can leak into subsequent tests. Capture the
original value of DRIVEMAP_ZFS_FIXTURE_DIR (if it exists) before the putenv
call, then restore it back to its original state after all the assertions in
this test block have completed, using another putenv call or by unsetting the
variable if it didn't exist before.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 872a8adf-684a-4aab-9b28-2d216e18abc5

📥 Commits

Reviewing files that changed from the base of the PR and between df20a1b and ae41552.

📒 Files selected for processing (13)
  • assets/45d/45drives-disks/assets/index.bbceb330.js
  • php/zfs_info.php
  • tests/fixtures/zfs_array/zfs_list.txt
  • tests/fixtures/zfs_array/zpool_iostat_disk1.txt
  • tests/fixtures/zfs_array/zpool_iostat_path_disk1.txt
  • tests/fixtures/zfs_array/zpool_iostat_path_zmirror.txt
  • tests/fixtures/zfs_array/zpool_iostat_zmirror.txt
  • tests/fixtures/zfs_array/zpool_list.txt
  • tests/fixtures/zfs_array/zpool_status_disk1.txt
  • tests/fixtures/zfs_array/zpool_status_path_disk1.txt
  • tests/fixtures/zfs_array/zpool_status_path_zmirror.txt
  • tests/fixtures/zfs_array/zpool_status_zmirror.txt
  • tests/run.php

Comment on lines +23297 to +23303
group.forEach((dsk) => {
const dsk_idx = diskLocations2.findIndex((loc) => loc.BAY === dsk.name);
if (dsk_idx < 0 || !diskLocations2[dsk_idx]?.image)
return;
const loc = diskLocations2[dsk_idx];
p5.animateZpools(loc.x, loc.y, loc.image.width, loc.image.height + y_offset, p5.zfsAnimationSteps, p5.zfsAnimationIndex, p5.zfsAnimationColors.storage_group.start, p5.zfsAnimationColors.storage_group.end, p5.zfsAnimationDir);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Exclude the current disk from peer-group animation.

showStorageGroupPeers currently animates all group members, including cd. For peer-only highlighting, skip the current disk in this loop.

Suggested fix
     group.forEach((dsk) => {
+      if (dsk.name === cd)
+        return;
       const dsk_idx = diskLocations2.findIndex((loc) => loc.BAY === dsk.name);
       if (dsk_idx < 0 || !diskLocations2[dsk_idx]?.image)
         return;
       const loc = diskLocations2[dsk_idx];
       p5.animateZpools(loc.x, loc.y, loc.image.width, loc.image.height + y_offset, p5.zfsAnimationSteps, p5.zfsAnimationIndex, p5.zfsAnimationColors.storage_group.start, p5.zfsAnimationColors.storage_group.end, p5.zfsAnimationDir);
     });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
group.forEach((dsk) => {
const dsk_idx = diskLocations2.findIndex((loc) => loc.BAY === dsk.name);
if (dsk_idx < 0 || !diskLocations2[dsk_idx]?.image)
return;
const loc = diskLocations2[dsk_idx];
p5.animateZpools(loc.x, loc.y, loc.image.width, loc.image.height + y_offset, p5.zfsAnimationSteps, p5.zfsAnimationIndex, p5.zfsAnimationColors.storage_group.start, p5.zfsAnimationColors.storage_group.end, p5.zfsAnimationDir);
});
group.forEach((dsk) => {
if (dsk.name === cd)
return;
const dsk_idx = diskLocations2.findIndex((loc) => loc.BAY === dsk.name);
if (dsk_idx < 0 || !diskLocations2[dsk_idx]?.image)
return;
const loc = diskLocations2[dsk_idx];
p5.animateZpools(loc.x, loc.y, loc.image.width, loc.image.height + y_offset, p5.zfsAnimationSteps, p5.zfsAnimationIndex, p5.zfsAnimationColors.storage_group.start, p5.zfsAnimationColors.storage_group.end, p5.zfsAnimationDir);
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@assets/45d/45drives-disks/assets/index.bbceb330.js` around lines 23297 -
23303, The forEach loop that animates storage group members currently includes
the current disk in the animation. Within the group.forEach loop where dsk is
iterated, add an additional condition to skip the current disk (cd) so that only
peer members are animated. Check if dsk.name (or dsk) matches the current disk
identifier and return early if it does, before calling p5.animateZpools. This
ensures peer-only highlighting by excluding the current disk from the animation
loop.

Comment thread php/zfs_info.php
Comment on lines +415 to 419
// Non-bay devices such as boot, flash, and standalone NVMe pools are valid
// ZFS members, but there is no slot to annotate in the drivemap UI.
// Keep them in the pool list and skip user-facing warnings.
$alert = [];
if (!isset($status_obj[$pool_name])) {
return $alert;
}

$default_pattern = '/^\t (\d+-\d+)(?:-part[0-9])?\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+).*/m';
$unsupported_pattern = '/^\t (\S+)(?:-part[0-9])?\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+).*/m';

preg_match_all($default_pattern, $status_obj[$pool_name], $default_matches, PREG_SET_ORDER);
preg_match_all($unsupported_pattern, $status_obj[$pool_name], $unsupported_matches, PREG_SET_ORDER);

$default_disks = [];
foreach ($default_matches as $match) {
$default_disks[] = $match[1];
}

$unsupported_disks = [];
foreach ($unsupported_matches as $match) {
$unsupported_disks[] = $match[1];
}

if (count($unsupported_disks) > count($default_disks)) {
$filtered = array_values(array_diff($unsupported_disks, $default_disks));
$filtered = array_values(array_filter($filtered, function ($name) {
return !preg_match('/^(\d+-\d+)(?:-part[0-9])/', $name);
}));
$filtered = array_values(array_filter($filtered, function ($name) use ($disk_lookup) {
return !preg_match('/^\d+-\d+$/', canonical_zfs_disk_name($name, $disk_lookup));
}));

if (!$filtered) {
return $alert;
}

$alert[] = "ZFS status displayed by this module for zpool '$pool_name' may be incomplete.\n\n";
$alert[] = "This module can only display zfs status information for devices that are created using a device alias.\n\n";
$alert[] = "This can be done using the 45Drives cockpit-zfs-manager package:\nhttps://github.com/45Drives/cockpit-zfs-manager/releases/\n\n";
if ($filtered) {
$alert[] = "The following zfs devices do not conform:\n";
foreach ($filtered as $disk) {
$alert[] = "\t $disk\n";
}
}
$alert[] = "\n";
}

return $alert;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

verify_zfs_device_format() now suppresses all warnings, not only non-slot ones.

Line 415-419 returns an empty array unconditionally, so genuinely malformed or unexpectedly mapped members also lose diagnostics. That widens behavior beyond the stated non-slot suppression and weakens the API’s warning signal.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@php/zfs_info.php` around lines 415 - 419, The verify_zfs_device_format()
function currently returns an empty alert array unconditionally, which
suppresses warnings for all cases including genuinely malformed or unexpectedly
mapped devices. Modify the return statement to conditionally return an empty
array only for valid non-bay devices (boot, flash, standalone NVMe pools), while
ensuring that genuinely malformed or unexpectedly mapped members still populate
and return the alert array with appropriate diagnostic warnings. This requires
adding conditional logic before the return statement to distinguish between
non-slot devices that should be silenced and actual format violations that
should still be reported.

Comment thread tests/run.php Outdated
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant