Skip to content

vfs: return an SMB read-ahead connection with its pool's window - #19943

Merged
LibretroAdmin merged 3 commits into
libretro:masterfrom
Davey-Hughes:smb-pool-swap
Oct 30, 2026
Merged

LibretroAdmin merged 3 commits into
libretro:masterfrom
Davey-Hughes:smb-pool-swap

Conversation

@Davey-Hughes

@Davey-Hughes Davey-Hughes commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

This PR first fixed the SMB pool being freed under its users on a settings change. #19939's pool table already fixes that on master, so it is now down to the one fix master still lacks, plus a test for the settings-change case.

Changes

  1. Read-ahead window restored from the pool's key. A read-ahead stream turns off the client read-ahead on its prefetcher's pooled connection while the prefetcher runs.
    • It turned it off before opening the file. If the open or the prefetcher then failed, the slot went back to its pool with no window.
    • On close it set the window from the current settings, not from the key the pool was built with. A pool is used again when the settings return to its key, so after a read-ahead change a connection could go back to its pool with the wrong window.
    • The window now goes off only after a successful open, and comes back from the pool's key on every path. Performance only; no data is affected.
  2. Test: settings switched under the workers. vfs_threads_test gains a phase in which a thread switches the settings between two connection keys while four workers open, read and list. Slots are then taken from and given back to two pools, as a settings edit would cause. The existing two-shares phase covers a second share; this covers the key changing.

Testing

  • vfs_threads_test, vfs_test, smb_idle_test and cloud_sync_test pass under ASan.
  • vfs_threads_test passes under TSan with 0 warnings, for the built-in client and libsmb2.
  • Each commit builds and passes on its own.
  • C89 and --disable-threads builds pass.
  • The new phase also passes on master's pool code.

@Davey-Hughes Davey-Hughes changed the title vfs: keep a replaced SMB pool alive while threads may use it vfs: return an SMB read-ahead connection with its pool's window Oct 30, 2026
A read-ahead stream turns off the client read-ahead on its
prefetcher's pooled connection while the prefetcher runs. It did so
before opening the file and left it off when the open or the
prefetcher failed, so the slot went back to its pool with no window.
On close it set the window from the current settings, but a pool
keeps the settings it was built with and is used again when the
settings return to them, so after a read-ahead change a connection
could go back to its pool with the wrong window. The window now goes
off only after a successful open and is restored from the pool's key
whenever it was turned off.
A new phase has a thread switch the settings between two connection
keys while the workers open, read and list, so slots are taken from
and given back to two pools as a settings edit would. The two-shares
phase covers a second share; this covers the key changing under them.
A stream with a prefetcher open while read-ahead is turned off now
checks, once it closes, that every idle pooled connection still has
its pool's window. This fails without the read-ahead fix before it.
smb_pool_windows_ok() makes the check, with a getter for the window
the built-in client holds.

The switching phase is driven by the workers, each moving the key on
after a round, instead of a thread spinning on smb_init_cfg(). It
switches across five keys, more than there are pools, half of them
with read-ahead off, so idle pools are evicted beside busy ones, and
it checks the windows once the workers are done.
@LibretroAdmin
LibretroAdmin merged commit 6425754 into libretro:master Oct 30, 2026
137 of 139 checks passed
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