Re: [PATCH] block: Refactor get_tmp_filename()

2022-09-26 Thread Daniel P . Berrangé
On Sat, Sep 24, 2022 at 04:00:34PM +0800, Bin Meng wrote: > From: Bin Meng > > At present there are two callers of get_tmp_filename() and they are > inconsistent. > > One does: > > /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */ > char *tmp_filename = g_malloc0(PAT

Re: [PATCH v3] block: Refactor get_tmp_filename()

2022-09-26 Thread Daniel P . Berrangé
On Sun, Sep 25, 2022 at 12:32:00AM +0800, Bin Meng wrote: > From: Bin Meng > > At present there are two callers of get_tmp_filename() and they are > inconsistent. > > One does: > > /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */ > char *tmp_filename = g_malloc0(PAT

[PATCH v12 13/21] jobs: protect job.aio_context with BQL and job_mutex

2022-09-26 Thread Emanuele Giuseppe Esposito
In order to make it thread safe, implement a "fake rwlock", where we allow reads under BQL *or* job_mutex held, but writes only under BQL *and* job_mutex. The only write we have is in child_job_set_aio_ctx, which always happens under drain (so the job is paused). For this reason, introduce job_set

[PATCH v12 02/21] job.h: categorize fields in struct Job

2022-09-26 Thread Emanuele Giuseppe Esposito
Categorize the fields in struct Job to understand which ones need to be protected by the job mutex and which don't. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- include/qemu/job.h | 61

[PATCH v12 01/21] job.c: make job_mutex and job_lock/unlock() public

2022-09-26 Thread Emanuele Giuseppe Esposito
job mutex will be used to protect the job struct elements and list, replacing AioContext locks. Right now use a shared lock for all jobs, in order to keep things simple. Once the AioContext lock is gone, we can introduce per-job locks. To simplify the switch from aiocontext to job lock, introduce

[PATCH v12 08/21] jobs: add job lock in find_* functions

2022-09-26 Thread Emanuele Giuseppe Esposito
Both blockdev.c and job-qmp.c have TOC/TOU conditions, because they first search for the job and then perform an action on it. Therefore, we need to do the search + action under the same job mutex critical section. Note: at this stage, job_{lock/unlock} and job lock guard macros are *nop*. Signed

[PATCH v12 07/21] blockjob: introduce block_job _locked() APIs

2022-09-26 Thread Emanuele Giuseppe Esposito
Just as done with job.h, create _locked() functions in blockjob.h These functions will be later useful when caller has already taken the lock. All blockjob _locked functions call job _locked functions. Note: at this stage, job_{lock/unlock} and job lock guard macros are *nop*. Signed-off-by: Ema

[PATCH v12 05/21] job.c: add job_lock/unlock while keeping job.h intact

2022-09-26 Thread Emanuele Giuseppe Esposito
With "intact" we mean that all job.h functions implicitly take the lock. Therefore API callers are unmodified. This means that: - many static functions that will be always called with job lock held become _locked, and call _locked functions - all public functions take the lock internally if need

[PATCH v12 03/21] job.c: API functions not used outside should be static

2022-09-26 Thread Emanuele Giuseppe Esposito
job_event_* functions can all be static, as they are not used outside job.c. Same applies for job_txn_add_job(). Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Stefan Hajnoczi Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Kevin Wolf --- include/qemu/job.h | 18 --

[PATCH v12 20/21] blockjob: remove unused functions

2022-09-26 Thread Emanuele Giuseppe Esposito
These public functions are not used anywhere, thus can be dropped. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- blockjob.c | 16 ++-- include/block/blockjob.h | 31 +++

[PATCH v12 00/21] job: replace AioContext lock with job_mutex

2022-09-26 Thread Emanuele Giuseppe Esposito
In this series, we want to remove the AioContext lock and instead use the already existent job_mutex to protect the job structures and list. This is part of the work to get rid of AioContext lock usage in favour of smaller granularity locks. In order to simplify reviewer's job, job lock/unlock fun

[PATCH v12 16/21] blockjob: protect iostatus field in BlockJob struct

2022-09-26 Thread Emanuele Giuseppe Esposito
iostatus is the only field (together with .job) that needs protection using the job mutex. It is set in the main loop (GLOBAL_STATE functions) but read in I/O code (block_job_error_action). In order to protect it, change block_job_iostatus_set_err to block_job_iostatus_set_err_locked(), always ca

[PATCH v12 04/21] aio-wait.h: introduce AIO_WAIT_WHILE_UNLOCKED

2022-09-26 Thread Emanuele Giuseppe Esposito
Same as AIO_WAIT_WHILE macro, but if we are in the Main loop do not release and then acquire ctx_ 's aiocontext. Once all Aiocontext locks go away, this macro will replace AIO_WAIT_WHILE. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Stefan Hajnoczi Reviewed-by: Vladimir Sementsov-Ogie

[PATCH v12 06/21] job: move and update comments from blockjob.c

2022-09-26 Thread Emanuele Giuseppe Esposito
This comment applies more on job, it was left in blockjob as in the past the whole job logic was implemented there. Note: at this stage, job_{lock/unlock} and job lock guard macros are *nop*. No functional change intended. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Vladimir Sementso

[PATCH v12 09/21] jobs: use job locks also in the unit tests

2022-09-26 Thread Emanuele Giuseppe Esposito
Add missing job synchronization in the unit tests, with explicit locks. We are deliberately using _locked functions wrapped by a guard instead of a normal call because the normal call will be removed in future, as the only usage is limited to the tests. In other words, if a function like job_paus

[PATCH v12 15/21] blockjob: rename notifier callbacks as _locked

2022-09-26 Thread Emanuele Giuseppe Esposito
They all are called with job_lock held, in job_event_*_locked() Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf --- blockjob.c | 25 +++-- 1 file changed, 15 insertions(+), 10 deletion

[PATCH v12 18/21] job.c: enable job lock/unlock and remove Aiocontext locks

2022-09-26 Thread Emanuele Giuseppe Esposito
Change the job_{lock/unlock} and macros to use job_mutex. Now that they are not nop anymore, remove the aiocontext to avoid deadlocks. Therefore: - when possible, remove completely the aiocontext lock/unlock pair - if it is used by some other function too, reduce the locking section as much as

[PATCH v12 12/21] job: detect change of aiocontext within job coroutine

2022-09-26 Thread Emanuele Giuseppe Esposito
From: Paolo Bonzini We want to make sure access of job->aio_context is always done under either BQL or job_mutex. The problem is that using aio_co_enter(job->aiocontext, job->co) in job_start and job_enter_cond makes the coroutine immediately resume, so we can't hold the job lock. And caching it

[PATCH v12 10/21] block/mirror.c: use of job helpers in drivers

2022-09-26 Thread Emanuele Giuseppe Esposito
Once job lock is used and aiocontext is removed, mirror has to perform job operations under the same critical section, Note: at this stage, job_{lock/unlock} and job lock guard macros are *nop*. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/mirror

[PATCH v12 11/21] jobs: group together API calls under the same job lock

2022-09-26 Thread Emanuele Giuseppe Esposito
Now that the API offers also _locked() functions, take advantage of it and give also the caller control to take the lock and call _locked functions. This makes sense especially when we have for loops, because it makes no sense to have: for(job = job_next(); ...) where each job_next() takes the l

[PATCH v12 17/21] job.h: categorize JobDriver callbacks that need the AioContext lock

2022-09-26 Thread Emanuele Giuseppe Esposito
Some callbacks implementation use bdrv_* APIs that assume the AioContext lock is held. Make sure this invariant is documented. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/qemu/job.h | 27 +-- 1 file changed, 25 insertio

[PATCH v12 19/21] block_job_query: remove atomic read

2022-09-26 Thread Emanuele Giuseppe Esposito
Not sure what the atomic here was supposed to do, since job.busy is protected by the job lock. Since the whole function is called under job_mutex, just remove the atomic. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Stefan Hajnoczi Reviewed-by

[PATCH v12 14/21] blockjob.h: categorize fields in struct BlockJob

2022-09-26 Thread Emanuele Giuseppe Esposito
The same job lock is being used also to protect some of blockjob fields. Categorize them just as done in job.h. Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Emanuele Giuseppe Esposito --- include/block/blockjob.h | 32 ++-- 1 file changed, 26 insertions(+

[PATCH v12 21/21] job: remove unused functions

2022-09-26 Thread Emanuele Giuseppe Esposito
These public functions are not used anywhere, thus can be dropped. Also, since this is the final job API that doesn't use AioContext lock and replaces it with job_lock, adjust all remaining function documentation to clearly specify if the job lock is taken or not. Also document the locking require

Re: [PATCH] qemu-nbd: set timeout to qemu-nbd socket

2022-09-26 Thread Vladimir Sementsov-Ogievskiy
[+ Den] On 9/25/22 16:53, luzhipeng wrote: From: lu zhipeng Prevent the NBD socket stuck all the time, So set timeout. Signed-off-by: lu zhipeng --- nbd/client.c | 8 1 file changed, 8 insertions(+) diff --git a/nbd/client.c b/nbd/client.c index 30d5383cb1..89dde53a0f 100644 ---

Re: [PATCH v2] block: Refactor get_tmp_filename()

2022-09-26 Thread Markus Armbruster
Bin Meng writes: > From: Bin Meng > > At present there are two callers of get_tmp_filename() and they are > inconsistent. > > One does: > > /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */ > char *tmp_filename = g_malloc0(PATH_MAX + 1); > ... > ret = get_tmp_

Re: [PATCH] qemu-nbd: set timeout to qemu-nbd socket

2022-09-26 Thread Denis V. Lunev
On 9/26/22 12:05, Vladimir Sementsov-Ogievskiy wrote: [+ Den] On 9/25/22 16:53, luzhipeng wrote: From: lu zhipeng Prevent the NBD socket stuck all the time, So set timeout. Signed-off-by: lu zhipeng ---   nbd/client.c | 8   1 file changed, 8 insertions(+) diff --git a/nbd/client.c

Re: [PATCH v12 13/21] jobs: protect job.aio_context with BQL and job_mutex

2022-09-26 Thread Vladimir Sementsov-Ogievskiy
On 9/26/22 12:32, Emanuele Giuseppe Esposito wrote: In order to make it thread safe, implement a "fake rwlock", where we allow reads under BQL *or* job_mutex held, but writes only under BQL *and* job_mutex. The only write we have is in child_job_set_aio_ctx, which always happens under drain (so

Re: [PATCH v11 18/21] job.c: enable job lock/unlock and remove Aiocontext locks

2022-09-26 Thread Vladimir Sementsov-Ogievskiy
On 9/18/22 20:12, Emanuele Giuseppe Esposito wrote: --- a/qemu-img.c +++ b/qemu-img.c @@ -911,7 +911,6 @@ static void run_block_job(BlockJob *job, Error **errp)   AioContext *aio_context = block_job_get_aio_context(job);   int ret = 0;   -    aio_context_acquire(aio_context);   jo

Re: [PATCH v3 05/54] tests/qtest: ahci-test: Avoid using hardcoded /tmp

2022-09-26 Thread Thomas Huth
On 25/09/2022 13.29, Bin Meng wrote: From: Bin Meng This case was written to use hardcoded /tmp directory for temporary files. Update to use g_file_open_tmp() for a portable implementation. Signed-off-by: Bin Meng --- Changes in v3: - Split to a separate patch - Ensure g_autofree variable is

Re: [PATCH v12 18/21] job.c: enable job lock/unlock and remove Aiocontext locks

2022-09-26 Thread Vladimir Sementsov-Ogievskiy
On 9/26/22 12:32, Emanuele Giuseppe Esposito wrote: Change the job_{lock/unlock} and macros to use job_mutex. Now that they are not nop anymore, remove the aiocontext to avoid deadlocks. Therefore: - when possible, remove completely the aiocontext lock/unlock pair - if it is used by some other

Re: [PATCH v12 21/21] job: remove unused functions

2022-09-26 Thread Vladimir Sementsov-Ogievskiy
On 9/26/22 12:32, Emanuele Giuseppe Esposito wrote: These public functions are not used anywhere, thus can be dropped. Also, since this is the final job API that doesn't use AioContext lock and replaces it with job_lock, adjust all remaining function documentation to clearly specify if the job lo

Re: [PATCH] qemu-nbd: set timeout to qemu-nbd socket

2022-09-26 Thread Vladimir Sementsov-Ogievskiy
On 9/26/22 14:34, Denis V. Lunev wrote: On 9/26/22 12:05, Vladimir Sementsov-Ogievskiy wrote: [+ Den] On 9/25/22 16:53, luzhipeng wrote: From: lu zhipeng Prevent the NBD socket stuck all the time, So set timeout. Signed-off-by: lu zhipeng ---   nbd/client.c | 8   1 file changed, 8

[PATCH 1/1] 9pfs: avoid iterator invalidation in v9fs_mark_fids_unreclaim

2022-09-26 Thread Linus Heckemann
Previously, the yielding in v9fs_reopen_fid and put_fid could result in other parts of the code modifying the fid table. This would invalidate the hash table iterator, causing misbehaviour. Now we ensure that we complete the iteration before yielding, so that the iterator remains valid throughout

Re: [PATCH v3 09/54] tests/qtest: fdc-test: Avoid using hardcoded /tmp

2022-09-26 Thread Marc-André Lureau
On Sun, Sep 25, 2022 at 3:49 PM Bin Meng wrote: > From: Bin Meng > > This case was written to use hardcoded /tmp directory for temporary > files. Update to use g_file_open_tmp() for a portable implementation. > > Signed-off-by: Bin Meng > Reviewed-by: Marc-André Lureau > --- > > Changes in

Re: [PATCH v3 13/54] tests/qtest: ide-test: Avoid using hardcoded /tmp

2022-09-26 Thread Marc-André Lureau
On Sun, Sep 25, 2022 at 3:56 PM Bin Meng wrote: > From: Bin Meng > > This case was written to use hardcoded /tmp directory for temporary > files. Update to use g_file_open_tmp() for a portable implementation. > > Signed-off-by: Bin Meng > Reviewed-by: Marc-André Lureau > --- > > Changes in

Re: [PATCH v3 19/54] tests/qtest: virtio-blk-test: Avoid using hardcoded /tmp

2022-09-26 Thread Marc-André Lureau
On Sun, Sep 25, 2022 at 4:09 PM Bin Meng wrote: > From: Bin Meng > > This case was written to use hardcoded /tmp directory for temporary > files. Update to use g_file_open_tmp() for a portable implementation. > > Signed-off-by: Bin Meng > Reviewed-by: Marc-André Lureau > --- > > Changes in

Re: [PATCH v2] block: Refactor get_tmp_filename()

2022-09-26 Thread Bin Meng
On Mon, Sep 26, 2022 at 6:13 PM Markus Armbruster wrote: > > Bin Meng writes: > > > From: Bin Meng > > > > At present there are two callers of get_tmp_filename() and they are > > inconsistent. > > > > One does: > > > > /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */ > >

Re: [PATCH 1/1] 9pfs: avoid iterator invalidation in v9fs_mark_fids_unreclaim

2022-09-26 Thread Christian Schoenebeck
On Montag, 26. September 2022 14:42:06 CEST Linus Heckemann wrote: > Previously, the yielding in v9fs_reopen_fid and put_fid could result > in other parts of the code modifying the fid table. This would > invalidate the hash table iterator, causing misbehaviour. > > Now we ensure that we complete

Re: [PATCH v3 37/54] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32

2022-09-26 Thread Thomas Huth
On 25/09/2022 13.30, Bin Meng wrote: From: Bin Meng These test cases uses "blkdebug:path/to/config:path/to/image" for testing. On Windows, absolute file paths contain the delimiter ':' which causes the blkdebug filename parser fail to parse filenames. Signed-off-by: Bin Meng Reviewed-by: Marc

Re: [PATCH v3 37/54] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32

2022-09-26 Thread Bin Meng
Hi Thomas, On Tue, Sep 27, 2022 at 12:20 AM Thomas Huth wrote: > > On 25/09/2022 13.30, Bin Meng wrote: > > From: Bin Meng > > > > These test cases uses "blkdebug:path/to/config:path/to/image" for > > testing. On Windows, absolute file paths contain the delimiter ':' > > which causes the blkdebu

Re: [PATCH] qemu-nbd: set timeout to qemu-nbd socket

2022-09-26 Thread luzhipeng
在 2022/9/26 20:44, Vladimir Sementsov-Ogievskiy 写道: On 9/26/22 14:34, Denis V. Lunev wrote: On 9/26/22 12:05, Vladimir Sementsov-Ogievskiy wrote: [+ Den] On 9/25/22 16:53, luzhipeng wrote: From: lu zhipeng Prevent the NBD socket stuck all the time, So set timeout. Signed-off-by: lu zhip

Re: [PATCH v2] block: Refactor get_tmp_filename()

2022-09-26 Thread Markus Armbruster
Bin Meng writes: > On Mon, Sep 26, 2022 at 6:13 PM Markus Armbruster wrote: >> >> Bin Meng writes: >> >> > From: Bin Meng >> > >> > At present there are two callers of get_tmp_filename() and they are >> > inconsistent. >> > >> > One does: >> > >> > /* TODO: extra byte is a hack to ensure M

Re: [PATCH] qemu-nbd: set timeout to qemu-nbd socket

2022-09-26 Thread luzhipeng
在 2022/9/26 20:44, Vladimir Sementsov-Ogievskiy 写道: On 9/26/22 14:34, Denis V. Lunev wrote: On 9/26/22 12:05, Vladimir Sementsov-Ogievskiy wrote: [+ Den] On 9/25/22 16:53, luzhipeng wrote: From: lu zhipeng Prevent the NBD socket stuck all the time, So set timeout. Signed-off-by: lu zhip

Re: [PATCH v2] block: Refactor get_tmp_filename()

2022-09-26 Thread Bin Meng
Hi Markus, On Tue, Sep 27, 2022 at 2:22 PM Markus Armbruster wrote: > > Bin Meng writes: > > > On Mon, Sep 26, 2022 at 6:13 PM Markus Armbruster wrote: > >> > >> Bin Meng writes: > >> > >> > From: Bin Meng > >> > > >> > At present there are two callers of get_tmp_filename() and they are > >>