Skip to content

Downgrade MULTI sentinel in rev_host_clear#68

Open
ChuWeiChang wants to merge 1 commit into
sysprog21:mainfrom
ChuWeiChang:Fallback-of-MULTI-sentinel-in-rev_host_clear
Open

Downgrade MULTI sentinel in rev_host_clear#68
ChuWeiChang wants to merge 1 commit into
sysprog21:mainfrom
ChuWeiChang:Fallback-of-MULTI-sentinel-in-rev_host_clear

Conversation

@ChuWeiChang
Copy link
Copy Markdown
Contributor

@ChuWeiChang ChuWeiChang commented May 14, 2026

As stated in #38 (comment), MULTI sentinel in host_to_vfd[] is never recover to vfd once it is set. This PR fixes it by adding a per-host-FD reference count host_fd_refs[] that tracks how many VFDs alias each host FD:

rev_host_set increments the count before writing the slot.
rev_host_clear decrements it on close. When the count falls to 1, it searches for the surviving VFD and writes it directly into host_to_vfd, downgrading MULTI back to a valid mapping. When the count reaches 0, the slot is cleared to KBOX_HOST_VFD_NONE as before.

A new unit test test-fd-table-refcount.c covers the single-holder, two-sharer, and downgrade cases.


Summary by cubic

Fixes stale MULTI entries in the reverse host-FD map by tracking per-host FD refs and downgrading back to a direct mapping when only one VFD remains. Restores correct reverse lookups after shared FDs are closed.

  • Bug Fixes
    • Add host_fd_refs[]; initialize in kbox_fd_table_init.
    • rev_host_set increments; rev_host_clear decrements.
    • On refs == 1, search for the survivor and restore a direct mapping (if the search hits the closing VFD, hide it and retry). On refs == 0, clear to KBOX_HOST_VFD_NONE.
    • Add unit test (test-fd-table-refcount) covering single, shared, and downgrade cases.

Written for commit 0000cbd. Summary will update on new commits.

host_to_vfd stayed MULTI even after all but one VFD aliasing a host FD
had closed, breaking reverse lookups for the survivor. Add host_fd_refs
to track share counts: on close, decrement and, when the count falls to
1, search for the surviving VFD and restore a direct mapping instead of
leaving MULTI in place.

Change-Id: I196608b0dfe31492786928f71ba4a1e4801fc532
@ChuWeiChang ChuWeiChang force-pushed the Fallback-of-MULTI-sentinel-in-rev_host_clear branch from 00005dc to 0000cbd Compare May 14, 2026 08:25
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 5 files

@ChuWeiChang
Copy link
Copy Markdown
Contributor Author

net-wget-external is failing due to DNS resolution of www.google.com timing out in the runner — this is unrelated to the fd-table changes in this PR. Could @jserv re-run the integration job?

@jserv
Copy link
Copy Markdown
Contributor

jserv commented May 14, 2026

net-wget-external is failing due to DNS resolution of www.google.com timing out in the runner — this is unrelated to the fd-table changes in this PR. Could @jserv re-run the integration job?

DONE. Make test script more robust.

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.

2 participants