Skip to content

Report z/VM paging and spool allocation via VMCP - #995

Open
ca6iya wants to merge 4 commits into
openmainframeproject:masterfrom
ca6iya:cursor/vmcp-alloc-page-spool-f4bd
Open

ca6iya wants to merge 4 commits into
openmainframeproject:masterfrom
ca6iya:cursor/vmcp-alloc-page-spool-f4bd

Conversation

@ca6iya

@ca6iya ca6iya commented Nov 18, 2026 •

Copy link
Copy Markdown

Motivation

Paging and spool allocation are capacity numbers CP already reports but most monitoring tools don't surface. On current z/VM systems, running out of either is rare, so the goal here is visibility and trending rather than outage prevention: spool grows quietly with dumps and leftover files, and paging use rises as guests are overcommitted. (For reference, CP warns at 90% full with HCP401I, and only when paging and spool are both exhausted does it take abend PGT004.) Monitoring tools and exporters need these values when Feilong runs with use_smapi=False and can't ask SMAPI. This adds them to the VMCP host-info path from #983.

The commands go through the existing VMCPHandler._run and do not set a timeout of their own, so they stay compatible with #992 (configurable VMCP timeouts, still open). Once #992 merges, these queries use its general vmcp_timeout_seconds (default 240s). There is no second timeout implementation.

Commands

Issued only from the existing host-info request, and only when use_smapi is False:

  • QUERY ALLOC PAGE (IBM-defined CP privilege class D) — total, used, available, and percent used for paging space, plus per-extent detail from the same output.
  • QUERY ALLOC SPOOL (IBM-defined CP privilege class D) — total, used, available, and percent used for spool space, plus per-extent detail.

One vmcp invocation per query. The invocation passes --buffer=256K. vmcp's default response buffer is 8 KB (8192 bytes). When a response is larger, vmcp prints only the first 8 KB and exits with return code 2, and a system with many paging or spool extents can exceed that. 256 KB, within vmcp's 4 KB to 1 MB range, caps the response.

The parsed result, including a failure such as a missing class D privilege, is cached in the Feilong process for alloc_cache_seconds (default 60). Repeated host-info calls within that interval reuse the last sample and do not issue another CP command. A lock covers the refresh so overlapping calls share one pair of commands. There is no background thread. Callers that need a new sample should not poll host info faster than the TTL. Set alloc_cache_seconds to 0 to query on every host-info call.

New host-info fields

Returned by SDK host_get_info and GET /host. Counts are 4 KB pages, except extent_start and extent_end, which are cylinder numbers on CKD volumes and page numbers on FBA volumes, as CP reports them. Each count is null, and each volume list is null, when the data was not collected (SMAPI mode, missing class D, vmcp missing, or unparsable output). Host info still succeeds in that case.

Field Meaning
paging_total Paging pages from the CP SUMMARY line
paging_used Paging pages in use
paging_available paging_total - paging_used
paging_percent_used SUMMARY percent used
paging_volumes One dict per PAGE extent
spool_total Spool pages from the CP SUMMARY line
spool_used Spool pages in use
spool_available spool_total - spool_used
spool_percent_used SUMMARY percent used
spool_volumes One dict per SPOOL extent

Each extent dict has volid, rdev, extent_start, extent_end, total, used, high, percent_used, draining, active, dump, shared, and not_found. active reflects the ACT flag, which CP shows for a PAGE extent that is actively draining. That flag comes with Active Drain for PAGE volumes (z/VM 7.4 APAR VM66891, and 7.5), and it is always false on earlier levels.

With use_smapi=True (the default) the commands are not issued and the fields are null.

Privilege class

The guest that hosts Feilong needs CP privilege class D, the IBM-defined class for QUERY ALLOC, or whatever class the installation has assigned to it with MODIFY COMMAND. A general user with only class G is not authorized. CP interprets an unauthorized option only in the formats the user is authorized for, so such a guest typically gets HCP003E Invalid option - ALLOC rather than a privilege-specific message. The other documented QUERY ALLOC errors are HCP013E (conflicting option) and HCP1002E (volume identifier does not exist). That is logged as a warning and does not fail the host-info request. The failure is cached for the same TTL, so the next host-info call within alloc_cache_seconds does not repeat the CP command.

Performance

  • No new threads, polling loops, or daemons. The commands run only when host info is requested and the in-process cache has expired.
  • Two vmcp calls on a cache miss, each with a 256 KB output cap (--buffer=256K). Parsing is one pass over the lines (regex and split).
  • No new third-party dependencies.
  • Successes and failures are reused for alloc_cache_seconds (default 60). A lock serializes the refresh. Callers should not poll faster than that interval.

Testing

  • Unit tests mock the vmcp call. Fixtures follow the QUERY ALLOC response 2 layout in the CP Commands and Utilities Reference, which is the same for z/VM 7.2 through 7.5 apart from the ACT flag added in 7.4: single volume, multi-volume with a continuation line, volid repeated on every extent (DIAGNOSE buffer / vmcp style), spool DUMP / SHARED / NOT FOUND, and K suffix counts. Also covered: HCPxxx rejections such as HCP003E, vmcp unavailable, empty output, and garbled output. A privilege failure restores the request return code so host info is not failed.
  • Cache tests: a second host-info call inside the TTL does not call vmcp again; a call after the TTL does; a failure (None) is kept for the TTL and is not retried early.
  • python3 -m unittest discover -s smtLayer/tests/unit — 219 passed.
  • python3 -m unittest discover -s zvmsdk/tests/unit — 1109 passed, 4 skipped (run before this cache commit; the cache change is covered by the smtLayer host-info tests).
  • flake8 with the repo tox.ini pep8 settings — passed.

Parsing was validated against the documented sample layout, not against a live z/VM system. A check on a real z/VM 7.3 or 7.4 system would still be worthwhile, especially for abbreviated counts and a large number of paging volumes.

Assumptions

  • Headline numbers are the SUMMARY line. Per the CP reference, SUMMARY covers both usable and draining space, and the usable line excludes draining space and, for spool, dump-only space. CP prints these lines only when all volumes are queried, which is what these commands do. On an SSI member, spool volumes owned by another member appear as SHARED with no allocation data. The usable line is recognized so it is not mistaken for an extent, and it is not returned as its own fields. Extent flags include draining and dump, so a caller can derive usable space.
  • Abbreviated counts (600K, 10M, ...) are read as powers of 1024. The CP reference only says K, M, G, T, and P mean kilo through peta. 1024 matches published output, where a 10,016-cylinder 3390 page extent (1,802,880 pages) is shown as 1761K. CP rounds abbreviated values, so they are approximate to the last digit.
  • Any HCPxxx message is treated as a rejected command, because a missing privilege class surfaces as a generic message such as HCP003E and not as a dedicated authorization error.

OMP best-practices checklist

Checked against the Open Mainframe Project TAC repository recommendations as they apply to this contribution:

  • DCO. Single commit 687f7ea55eca2f6e64cbec88a77616f4963eb5b8 signed off as Signed-off-by: Manuel Cabiya <ca6iya@users.noreply.github.com>, matching the commit author and committer.
  • License. No third-party code or assets were copied in. No dependencies were added. The change is original work under the repository's existing Apache-2.0 license.
  • Copyright headers. No new source files. Every edited Python file already carries SPDX-License-Identifier: Apache-2.0, and those headers were left in place.
  • Contribution scope. One focused change. API docs (restapi.rst, parameters.yaml), the vmcp privilege table (quickstart.rst), the sample config, and the release notes (doc/source/change.rst) are updated. Commit subjects are within the 50-character limit in CONTRIBUTING.md, and the change includes tests.
  • Governance files. GOVERNANCE.md, MAINTAINERS.txt, CODE_OF_CONDUCT.md, LICENSE, and dco_signoffs/ were not modified.
  • Host-info cache. QUERY ALLOC PAGE and QUERY ALLOC SPOOL results, including failures, are reused for alloc_cache_seconds (default 60) under a lock, with no background thread. The privilege table and host-info docs state the 256 KB vmcp buffer and that callers should not poll faster than the TTL.

When use_smapi is false, collect QUERY ALLOC PAGE and QUERY ALLOC
SPOOL on the existing host-info request and return total, used,
available, percent used, and per-extent detail. Each command is one
vmcp invocation with --buffer=256K.

Results, including a failure such as a missing class D privilege, are
reused for alloc_cache_seconds (default 60). A lock covers the refresh.
There is no background thread, so repeated host-info calls do not issue
a CP command on every request. A missing privilege is a warning and does
not fail host info.

Signed-off-by: Manuel Cabiya <ca6iya@users.noreply.github.com>
Use time.monotonic for the QUERY ALLOC cache so a wall-clock step
does not keep a stale sample. When CP omits SUMMARY and an extent
that is not shared or not-found has no total or used count, leave
the host totals unset instead of summing the extents that did parse.

Signed-off-by: Manuel Cabiya <ca6iya@users.noreply.github.com>
Pass a 5 second timeout only for the optional allocation commands so
a hung vmcp cannot hold the host-info cache lock. Other _run callers
are unchanged. A timeout is a warning, returns no data, and leaves
the request results as they were.

Signed-off-by: Manuel Cabiya <ca6iya@users.noreply.github.com>
The second call after a timeout must fail the test if QUERY ALLOC
runs again. _run would otherwise swallow an AssertionError and the
cached None result would still look like a pass.

Signed-off-by: Manuel Cabiya <ca6iya@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