Whamcloud - gitweb
LU-16747 llapi: fix race in get_root_path_slow() 82/50682/6
authorEtienne AUJAMES <etienne.aujames@cea.fr>
Tue, 18 Apr 2023 13:34:23 +0000 (15:34 +0200)
committerOleg Drokin <green@whamcloud.com>
Tue, 20 Jun 2023 03:40:39 +0000 (03:40 +0000)
commit9ef1e097d53000233f9ba23319268f467c276173
tree1b57a4e5d202e28cad961d8e72816476ce968209
parent2e5941f94e496559235fa568b48ed03954db2dba
LU-16747 llapi: fix race in get_root_path_slow()

The patch bdf7788d ("LU-8585 llapi: use open_by_handle_at in
llapi_open_by_fid") caches the Lustre root fd to avoid re-openning
it each time an ioctl() is needed on the fs.

For now, only 1 entry is stored. If a llapi call is performed on
another mountpoint, llapi needs to close the old root fd and open a
new one.

A race condition exists at startup, when root_cached.fd is not
initialized yet. Several threads try to determine root information at
the same time (in get_root_path_slow()). Those threads will close(),
open() and update different "root_cached.fd".
The usage of a closed root fd will return EBADFD (e.g: in
llapi_open_by_fid(), llapi_hsm_request() or llapi_fid2path()).

This patch checks if the fs is the same before updating the root
entry. If so, the root entry (and cached root fd) will not be changed.

Add the regresion test sanityn 85 (llapi_root_test).

Test-Parameters: trivial testlist=sanityn env=ONLY=85,ONLY_REPEAT=20
Test-Parameters: testlist=sanityn
Test-Parameters: testlist=sanity
Fixes: bdf7788d ("LU-8585 llapi: use open_by_handle_at in llapi_open_by_fid")
Signed-off-by: Etienne AUJAMES <eaujames@ddn.com>
Change-Id: I681aac7d5715022e700cdb092db94deaa6bf6a8f
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50682
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Guillaume Courrier <guillaume.courrier@cea.fr>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/.gitignore
lustre/tests/Makefile.am
lustre/tests/llapi_root_test.c [new file with mode: 0644]
lustre/tests/sanityn.sh
lustre/utils/liblustreapi_root.c