mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-07 08:36:02 -10:00
* nfs, smb: apply menu setting changes without a restart The clients took their settings at startup and after config_load only. Their numbers (NFS version, ports, timeout, read-ahead, connection count, SMB auth mode) are copies, so a menu change waited for a restart. Each change now hands the clients the current values. SMB keys its pools on the whole configuration, so its next connection uses the new values. The NFS pool matched a free connection by export alone, so a changed server, version or port could ride an old one. New settings now close the idle connections and advance a generation; a slot whose generation or server differs connects again. The pool is kept rather than replaced, so nfs_init_cfg() cannot free it under a thread that has just taken a slot. On version 4 an NFS port of 0 means 2049 and the mount port is unused; the sublabels say so. vfs_threads_test changes the ports while a prefetcher holds a slot. * nfs, smb: log why a network directory listing failed A failed file browser listing of an nfs:// or smb:// directory showed "Directory not found" and logged nothing. It now logs one error line with the URL, the settings the client ran with and the client's reason. The NFS client's reasons say what failed: the step and the server's status (v4.2 mount: LOOKUP roms: NFS4ERR_NOENT), the address a connect was refused at or timed out on, and RPC rejects such as PROG_MISMATCH or AUTH_TOOWEAK. A refusal (PERM, ACCESS, WRONGSEC, or a v3 MOUNT ACCES) adds that a Linux export needs 'insecure' for a client port above 1023, as this client's always is. A failed walk or redial keeps its own reason. Failures that never reach a server record one too: no export, no server in the URL, no SMB server set. SMB gets smb_get_last_error() to match nfs_get_last_error(). nfs_error_test checks the reasons without a server and against fake_nfs42.py. * nfs: open files keep the settings they were opened with An open nfs:// file or directory stored only its server and export, so after a settings change its next read reconnected with the new version and ports: a v3 handle sent over v4, or the stream's server asked on another server's port. Open files and directories now keep the version, ports and timeout they were opened with and reconnect with those. Each pool slot carries the parameters it connected with and is reused only on an exact match, which replaces the settings generation. Read-ahead is client-side and still follows the settings on every take. nfs_error_test reads an open file on across a port and version change. * smb: list a server's shares when no share is set Browsing smb://server with no share configured never listed anything. retro_vfs_opendir_impl rejected any SMB handle whose dir was NULL, which is exactly the handle retro_vfs_opendir_smb returns for a share list, and leaked it. The backend already reads and closes that handle, so the dispatcher now accepts it. The UWP dispatcher does the same and takes an entry's directory flag from the listing instead of a stat. vfs_test checks the share list through the dispatcher as well. * nfs: a file opened over a private connection keeps its export With no NFS Export set, the export comes from the URL and is found when connecting. When every pooled connection is busy, as it is once a few read-only streams' prefetchers hold one each, the open goes over a private connection and the file or directory handle recorded an empty export. Every later borrow then mounted "": refused on v3; on v4 the pseudo root, where the path under the export is not found, so such a stream never got its prefetcher. Record the export the connection was made with, through a new rnfs_get_export(). nfs_error_test opens a file by URL while a prefetcher holds the only slot. * nfs, smb: settings as immutable copies; pools keyed by the copy nfs_init_cfg() and smb_init_cfg() copy the settings they are given, strings included, and publish the copy through vfs_cfg_snapshot.h: a reader holds the copy it got between enter and leave, and a copy that was replaced is freed once nothing holds it - retro_retire.h's epochs where the pointer atomics are lock-free, a reference count under a short flag elsewhere. Menu edits may rewrite the settings in place while pool, prefetch and task threads read them. NFS resolves a URL against the held copy's export without copying it, and applies the timeout and read-ahead on every take: neither is part of what a connection must match. SMB pools remember the copy they were last matched to, so a take on that copy and share finds its pool without building or comparing a key. A READDIR failure names the result's own status. nfs_cfg_race_test and smb_cfg_race_test free the caller's struct right after handing it over, then resolve against it, and hand one struct over repeatedly while four threads stat and list; they need no server and run ahead of the server matrices in local_unfs3_test.sh and local_samba_test.sh. --------- Co-authored-by: LibretroAdmin <[email protected]>
109 lines
4.4 KiB
C
109 lines
4.4 KiB
C
/* Copyright (C) 2026 The RetroArch team
|
|
*
|
|
* ---------------------------------------------------------------------------------------
|
|
* The following license statement only applies to this file (vfs_implementation_nfs.h).
|
|
* ---------------------------------------------------------------------------------------
|
|
*
|
|
* Permission is hereby granted, free of charge,
|
|
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
|
* to deal in the Software without restriction, including without limitation the rights to
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
|
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
#ifndef VFS_IMPLEMENTATION_NFS_H
|
|
#define VFS_IMPLEMENTATION_NFS_H
|
|
|
|
#include <stdint.h>
|
|
#include <boolean.h>
|
|
#include <vfs/vfs.h>
|
|
#include <retro_common_api.h>
|
|
|
|
RETRO_BEGIN_DECLS
|
|
|
|
/* nfs:// backend over the built-in NFSv3 client (net/net_nfs3.c).
|
|
* URL shape: nfs://server/export/path, or nfs://server/path with the
|
|
* export from the settings, the path relative to it. */
|
|
|
|
#define RETRO_NFS_DEFAULT_TIMEOUT 5
|
|
#define RETRO_NFS_DEFAULT_NUM_CONTEXTS 4
|
|
|
|
#define RETRO_NFS_DIRENT_FILE 0
|
|
#define RETRO_NFS_DIRENT_DIR 1
|
|
|
|
struct nfs_settings
|
|
{
|
|
const char *server_address;
|
|
const char *export_path;
|
|
unsigned timeout; /* seconds */
|
|
unsigned num_contexts; /* connection pool size */
|
|
unsigned nfs_port; /* 0: ask the portmapper */
|
|
unsigned mount_port; /* 0: ask the portmapper */
|
|
unsigned version; /* 0/3: NFSv3; 4: NFSv4.0 (no portmapper,
|
|
* export is the server's pseudo path) */
|
|
unsigned readahead; /* KiB per open file; 0: the client's default */
|
|
};
|
|
typedef struct nfs_settings nfs_settings_t;
|
|
|
|
struct nfs_dirent
|
|
{
|
|
char name[256];
|
|
int type; /* RETRO_NFS_DIRENT_* */
|
|
int64_t size;
|
|
};
|
|
|
|
typedef struct
|
|
{
|
|
void *ctx; /* struct rnfs_ctx, from the pool */
|
|
void *dir; /* struct rnfs_dir */
|
|
struct nfs_dirent ent;
|
|
} nfs_dir_handle;
|
|
|
|
/* Hands the client new settings: they are copied, strings included,
|
|
* so the caller may change or free @new_cfg once this returns. */
|
|
bool nfs_init_cfg(const struct nfs_settings *new_cfg);
|
|
|
|
/* File operations */
|
|
bool retro_vfs_file_open_nfs(libretro_vfs_implementation_file *stream,
|
|
const char *path, unsigned mode, unsigned hints);
|
|
int64_t retro_vfs_file_read_nfs(libretro_vfs_implementation_file *stream,
|
|
void *s, uint64_t len);
|
|
int64_t retro_vfs_file_view_nfs(libretro_vfs_implementation_file *stream,
|
|
uint64_t len, const uint8_t **ptr);
|
|
int64_t retro_vfs_file_write_nfs(libretro_vfs_implementation_file *stream,
|
|
const void *s, uint64_t len);
|
|
int64_t retro_vfs_file_seek_nfs(libretro_vfs_implementation_file *stream,
|
|
int64_t offset, int whence);
|
|
int64_t retro_vfs_file_tell_nfs(libretro_vfs_implementation_file *stream);
|
|
int retro_vfs_file_close_nfs(libretro_vfs_implementation_file *stream);
|
|
|
|
/* Directory operations */
|
|
nfs_dir_handle *retro_vfs_opendir_nfs(const char *path, bool include_hidden);
|
|
struct nfs_dirent *retro_vfs_readdir_nfs(nfs_dir_handle *dh);
|
|
int retro_vfs_closedir_nfs(nfs_dir_handle *dh);
|
|
|
|
/* Stat / error / lifecycle */
|
|
int retro_vfs_stat_nfs(const char *path, int64_t *size);
|
|
int retro_vfs_file_error_nfs(libretro_vfs_implementation_file *stream);
|
|
void nfs_shutdown(void);
|
|
|
|
/* What read-ahead served from its windows and what it missed, in KiB,
|
|
* over the files closed since the last call; the counts are then reset.
|
|
* Both are 0 while read-ahead is off. */
|
|
void nfs_take_readahead_stats(unsigned *window_kib, unsigned *direct_kib);
|
|
bool nfs_probe_connection(void);
|
|
const char *nfs_get_last_error(void);
|
|
|
|
RETRO_END_DECLS
|
|
|
|
#endif /* VFS_IMPLEMENTATION_NFS_H */
|