Fix multithread issues when operating on a single shared file
authorChris Weber <weberc@netapp.com>
Fri, 22 Jul 2022 03:34:02 +0000 (03:34 +0000)
committerChris Weber <weberc@netapp.com>
Tue, 26 Jul 2022 17:33:52 +0000 (17:33 +0000)
commitacbda87c34c743ff2d9e125d9539bcfbbf49eb75
tree3ca99efd83577ca87614e43a12154b6ef66e1a2e
parent02a36caa69f5675f7144fbeddb7a32e1d35ce0c7
Fix multithread issues when operating on a single shared file

When nrfiles=1, numjobs>1 and create_serialize=0, multiple threads
try to create the single shared file in parallel. If the file was
pre-existing, but an incorrect size, then multiple threads are
deleting and creating at the same time. When all of this happens
in parallel, there is a chance that the file can end up the
incorrect size (the chance increases as numjobs increases).
These changes handle the corner case described above by having
a single thread create/extend the file prior to running all of
the threads in parallel. By doing this step early, when
setup_files() is called later, it should no longer need to
create or extend the file, avoiding the race condition. The user
still needs to set a fallocate option other than 'none' or the
file will end up 0 bytes in size and the race condition will
still occur. It would be simple to add a ftruncate() to the code
to force this, but that would override the user's choice of
fallocate options.

Signed-off-by: Chris Weber <weberc@netapp.com>
backend.c
file.h
filesetup.c