Skip to content

Read disk statistics from devstat on DragonFly BSD - #3791

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:dragonfly-devstat
Oct 12, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:dragonfly-devstat

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Fixes getDiskStores on DragonFly BSD, which returned no disks: the inherited FreeBSD code needs iostat -x and geom, and DragonFly has neither.

Change

  • New DragonFlyBsdHWDiskStore in oshi-common (new package oshi.hardware.common.platform.unix.dragonflybsd) parses the struct devstat records in the kern.devstat.all sysctl: an 8-byte generation counter, then one 200-byte record per device. Offsets are from sys/devicestat.h on x86_64, the only architecture DragonFly supports, and were checked against bytes read on a live system.
  • A disk is reported when it appears in both kern.disks and devstat, so unconfigured vnode disks (vn0–vn3) are skipped.
  • Reads, writes, bytes, queue length and transfer (busy) time come from the record.
  • The JNA and FFM DragonFly HALs override getDiskStores and only fetch the sysctl's bytes.
  • NativeComparisonTest.diskStoreUpdateAttributes no longer skips DragonFly.

Not covered

Model, serial number, size and partitions are only readable through the disk devices, which are root:operator 0640 on DragonFly, so they remain unknown / 0 / empty. The boot log names the controller (vtblk0), not the disk (vbd0), so it can't fill these in reliably.

Verification

DragonFly BSD 6.4 (cfarm152), JDK 25:

  • JNA and FFM reports list vbd0 (87.6M reads / 5.2 TiB, 638M writes / 38 TiB) and md0, with counters growing between runs.
  • oshi-common, oshi-core and oshi-core-ffm test suites pass, including DisksTest.
  • -Pnative-comparison: diskStores and diskStoreUpdateAttributes pass.

Summary by CodeRabbit

  • New Features
    • DragonFly BSD disk stores now report disk names and available read/write activity, byte counts, queue length, and transfer time.
    • Disk model, serial number, size, and partition details remain unavailable.

DragonFly BSD inherited FreeBSD's disk enumeration, which needs iostat -x
and geom. DragonFly has neither, so getDiskStores returned no disks.

Add DragonFlyBsdHWDiskStore in oshi-common, which parses the struct devstat
records in the kern.devstat.all sysctl: an 8-byte generation counter, then
one 200-byte record per device. The offsets are from sys/devicestat.h on
x86_64, the only architecture DragonFly supports, and were checked against
bytes read on a DragonFly 6.4 guest. A disk is reported when it appears in
both kern.disks and devstat, so unconfigured vnode disks are skipped. Reads,
writes, bytes, queue length and busy time come from the record. The JNA and
FFM HALs only fetch the sysctl's bytes.

The model, serial number, size and partitions are readable only through the
disk devices, which are root-only on DragonFly, so they remain unknown.

NativeComparisonTest no longer skips diskStoreUpdateAttributes on DragonFly.

Verified on DragonFly BSD 6.4 (cfarm152), JNA and FFM: vbd0 and md0 listed
with growing counters; oshi-common, oshi-core and oshi-core-ffm test suites
and -Pnative-comparison pass.
@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 15b3ee95-a6c9-4ce4-8e04-bb400e7d4e80

📥 Commits

Reviewing files that changed from the base of the PR and between 7a220ba and 5756a2a.


📒 Files selected for processing (9)
  • CHANGELOG.md
  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/dragonflybsd/DragonFlyBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/dragonflybsd/package-info.java
  • oshi-common/src/test/java/module-info.test
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/dragonflybsd/DragonFlyBsdHWDiskStoreTest.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerJNA.java

💤 Files with no reviewable changes (1)
  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📜 Recent review details
⏰ Context from checks skipped due to timeout. (10)
  • GitHub Check: Test JDK 25, NetBSD
  • GitHub Check: Test JDK 25, FreeBSD
  • GitHub Check: Test JDK 25, OpenIndiana
  • GitHub Check: Test JDK 25, OpenBSD
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Error Prone
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)

🧰 Additional context used
📚 Code guidelines (2)
AGENTS.md — auto-discovered
CONTRIBUTING.md — auto-discovered

📓 Path-based instructions (3)
Source excerpt: **Banned APIs** (`config/forbidden-apis.txt` and friends, enforced by `forbiddenapis:check`): `oshi-core-ffm` may not reference `com.sun.jna.**`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/dragonflybsd/DragonFlyBsdHardwareAbstractionLayerFFM.java

Source excerpt: **Banned APIs** (`config/forbidden-apis.txt` and friends, enforced by `forbiddenapis:check`): `oshi-common` may not reference `com.sun.jna.**`, `java.lang.foreign.**`, or any `System.load`/`loadLibrary`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/test/java/module-info.test
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/dragonflybsd/package-info.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/dragonflybsd/DragonFlyBsdHWDiskStoreTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/dragonflybsd/DragonFlyBsdHWDiskStore.java

Source excerpt: The Changelog lets users know what's changed.

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Files:

  • CHANGELOG.md


📝 Walkthrough

Walkthrough

DragonFly BSD now exposes disk stores through JNA and FFM. The shared implementation parses kern.devstat.all records, filters them against kern.disks, and updates disk statistics. Tests cover parsing and updates, and benchmark checks now run on DragonFly BSD.

Changes

DragonFly BSD disk stores

Layer / File(s) Summary
Shared disk-store parsing and updates
oshi-common/src/main/java/oshi/hardware/common/platform/unix/dragonflybsd/*, oshi-common/src/main/java/module-info.java, oshi-common/src/test/java/module-info.test, oshi-common/src/test/java/oshi/hardware/common/platform/unix/dragonflybsd/*
Adds disk-store parsing for DragonFly BSD device statistics, filters stores against kernel disk names, and updates attributes. Tests cover record parsing, disk selection, and update behavior.
JNA and FFM integration
oshi-core/src/main/java/oshi/hardware/platform/unix/dragonflybsd/*, oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/dragonflybsd/*, oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java, CHANGELOG.md
Both HAL implementations provide kern.disks names and kern.devstat.all data to the shared implementation. The benchmark runs disk-store update checks on DragonFly BSD, and the changelog records the supported statistics.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant DragonFlyBsdHardwareAbstractionLayerJNA
  participant SysctlUtil
  participant DragonFlyBsdHWDiskStore
  DragonFlyBsdHardwareAbstractionLayerJNA->>SysctlUtil: Read kern.disks
  SysctlUtil-->>DragonFlyBsdHardwareAbstractionLayerJNA: Disk names
  DragonFlyBsdHardwareAbstractionLayerJNA->>DragonFlyBsdHWDiskStore: getDisks(names, queryDevstat)
  DragonFlyBsdHWDiskStore->>SysctlUtil: Read kern.devstat.all
  SysctlUtil-->>DragonFlyBsdHWDiskStore: Device-statistics bytes
  DragonFlyBsdHWDiskStore-->>DragonFlyBsdHardwareAbstractionLayerJNA: Parsed disk stores
Loading

Merge Risk: ⚪ Minimal · up to 5756a

Disks remain available, though transfer time can lag during sustained I/O and catch up afterward. This does not block merging.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 11.76% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 6 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: adding DragonFly BSD disk-statistics support using devstat.
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.

Full details: Docstring Coverage

Explanation

Docstring coverage is 11.76% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 6 files. (2 skipped: 2 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the disks at dawn,
Device counts are neatly drawn.
Bytes and busy time join the play,
JNA and FFM show the way.
The rabbit hops, then stores the hay.

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

@codecov

codecov Bot commented Oct 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.61538% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.56%. Comparing base (7a220ba) to head (5756a2a).

Files with missing lines Patch % Lines
...lybsd/DragonFlyBsdHardwareAbstractionLayerFFM.java 0.00% 3 Missing ⚠️
...lybsd/DragonFlyBsdHardwareAbstractionLayerJNA.java 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3791      +/-   ##
============================================
- Coverage     80.61%   80.56%   -0.05%     
- Complexity      320      547     +227     
============================================
  Files           724      725       +1     
  Lines         26027    26066      +39     
  Branches       4401     4408       +7     
============================================
+ Hits          20981    21001      +20     
- Misses         2799     2819      +20     
+ Partials       2247     2246       -1     
Flag Coverage Δ
freebsd 36.65% <84.61%> (+0.07%) ⬆️
linux 40.37% <84.61%> (+0.08%) ⬆️
macos 41.19% <84.61%> (+0.02%) ⬆️
netbsd 35.32% <84.61%> (+0.06%) ⬆️
openbsd 35.89% <84.61%> (+0.06%) ⬆️
solaris 37.21% <84.61%> (+0.06%) ⬆️
windows 47.44% <84.61%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbwiddis
dbwiddis merged commit c8fe762 into oshi:master Oct 12, 2026
20 checks passed
@dbwiddis
dbwiddis deleted the dragonfly-devstat branch October 12, 2026 02:23
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