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]>
86 lines
3.8 KiB
Bash
Executable File
86 lines
3.8 KiB
Bash
Executable File
#!/bin/sh
|
|
# NFSv4.2 READ_PLUS against fake_nfs42.py, a minimal server that reports
|
|
# the holes the filesystem really holds (SEEK_DATA / SEEK_HOLE): a
|
|
# 32 MiB file with 1 MiB of data must read back octet for octet with
|
|
# its holes not crossing the network. No server here implements
|
|
# READ_PLUS right (nfs-ganesha's answers every range with an empty
|
|
# data run; local_ganesha_test.sh checks the client falls back to READ
|
|
# on it), hence the fake. Its encoding is checked apart from the client
|
|
# when tshark is installed: Wireshark's own NFS dissector decodes the
|
|
# replies and their data and holes must add up to the file.
|
|
# The fake also serves nfs_error_test: a failed listing must say why,
|
|
# and an open file must read on after a settings change.
|
|
# Runs as a Windows binary under Wine too (CC=..-mingw.. RUNNER=wine
|
|
# EXE=.exe); needs python3.
|
|
set -eu
|
|
cd "$(dirname "$0")"
|
|
command -v python3 >/dev/null 2>&1 || { echo "skip: no python3"; exit 0; }
|
|
make -s nfs_sparse_test nfs_error_test
|
|
RUN=${RUNNER:-}
|
|
EXE=${EXE:-}
|
|
PORT=20460
|
|
D=$(mktemp -d); chmod 755 $D
|
|
cleanup() {
|
|
[ -n "${SRV:-}" ] && kill $SRV 2>/dev/null || true
|
|
[ -n "${CAP:-}" ] && kill $CAP 2>/dev/null || true
|
|
[ -n "$KEEP_PCAP" ] && cp $D/rp.pcap $KEEP_PCAP 2>/dev/null; rm -rf $D
|
|
}
|
|
trap cleanup EXIT
|
|
KEEP_PCAP=${KEEP_PCAP:-}
|
|
truncate -s 32M $D/sparse.img
|
|
head -c 262144 /dev/urandom | dd of=$D/sparse.img bs=65536 seek=0 conv=notrunc status=none
|
|
head -c 524288 /dev/urandom | dd of=$D/sparse.img bs=65536 seek=160 conv=notrunc status=none
|
|
head -c 262144 /dev/urandom | dd of=$D/sparse.img bs=65536 seek=500 conv=notrunc status=none
|
|
python3 fake_nfs42.py $PORT $D > $D/fake.log 2>&1 &
|
|
SRV=$!
|
|
CAP=
|
|
if command -v tshark >/dev/null 2>&1 && [ "$(id -u)" = 0 ]; then
|
|
tshark -i lo -f "tcp port $PORT" -w $D/rp.pcap -q 2>$D/cap.log &
|
|
CAP=$!
|
|
# on a busy machine tshark takes longer than the server to start
|
|
n=0
|
|
until grep -q "Capturing on" $D/cap.log 2>/dev/null; do
|
|
n=$((n + 1))
|
|
[ $n -gt 150 ] && { echo "FAIL: tshark did not start capturing: $(cat $D/cap.log)"; exit 1; }
|
|
sleep 0.2
|
|
done
|
|
fi
|
|
# and the server to listen
|
|
n=0
|
|
until python3 -c "import socket,sys; socket.create_connection(('127.0.0.1', int(sys.argv[1])), 1).close()" $PORT 2>/dev/null; do
|
|
n=$((n + 1))
|
|
[ $n -gt 150 ] && { echo "FAIL: fake_nfs42.py did not listen: $(cat $D/fake.log)"; exit 1; }
|
|
sleep 0.2
|
|
done
|
|
local_path=$D/sparse.img
|
|
[ -n "$RUN" ] && local_path="Z:$D/sparse.img"
|
|
if $RUN ./nfs_sparse_test$EXE 127.0.0.1 /export $PORT sparse.img "$local_path" 1048576 plus > $D/res 2>&1; then
|
|
echo "ok: READ_PLUS: a 32 MiB file with 1 MiB of data, holes kept off the wire ($(grep replies $D/res | tr -d "\r"))"
|
|
else
|
|
echo "FAIL: READ_PLUS: $(cat $D/res)"; exit 1
|
|
fi
|
|
if [ -n "$CAP" ]; then
|
|
sleep 1; kill $CAP; wait $CAP 2>/dev/null || true; CAP=
|
|
sums=$(tshark -r $D/rp.pcap -d tcp.port==$PORT,rpc -Y "nfs.opcode == 68 && rpc.msgtyp == 1" -V 2>/dev/null | awk '
|
|
/Content Type: Data/ {k="d"; next}
|
|
/Content Type: Hole/ {k="h"; next}
|
|
k=="d" && /Read length:/ {d+=$3; k=""}
|
|
k=="h" && /^[ \t]*length:/ {h+=$2; k=""}
|
|
END {printf "%d %d", d, h}')
|
|
bad=$(tshark -r $D/rp.pcap -d tcp.port==$PORT,rpc -Y "_ws.malformed" 2>/dev/null | wc -l)
|
|
if [ "$sums" = "1048576 32505856" ] && [ "$bad" -eq 0 ]; then
|
|
echo "ok: Wireshark decodes the replies: 1048576 octets of data and 32505856 of holes"
|
|
else
|
|
echo "FAIL: Wireshark's decode: data and holes $sums, $bad packets it could not decode"; exit 1
|
|
fi
|
|
else
|
|
echo "skip: the independent decode needs tshark and root"
|
|
fi
|
|
# after the capture, whose sums its reads would add to
|
|
if $RUN ./nfs_error_test$EXE $PORT "$local_path" > $D/err 2>&1; then
|
|
tr -d "\r" < $D/err
|
|
else
|
|
echo "FAIL: nfs_error_test: $(cat $D/err)"; exit 1
|
|
fi
|
|
echo "[pass] nfs_retro local read_plus"
|