Skip to content

Commit 5081dc5

Browse files
cschoenebeckMichael Tokarev
authored andcommitted
9pfs: fix concurrent v9fs_reclaim_fd() calls
Even though this function is serialized to be always called from main thread, v9fs_reclaim_fd() is dispatching the coroutine to a worker thread in between via its v9fs_co_*() calls, hence leading to the situation where v9fs_reclaim_fd() is effectively executed multiple times simultaniously, which renders its LRU algorithm useless and causes high latency. Fix this by adding a simple boolean variable to ensure this function is only called once at a time. No synchronization needed for this boolean variable as this function is only entered and returned on main thread. Fixes: 7a46274 ('hw/9pfs: Add file descriptor reclaim support') Signed-off-by: Christian Schoenebeck <[email protected]> Reviewed-by: Greg Kurz <[email protected]> Message-Id: <5c622067efd66dd4ee5eca740dcf263f41db20b2.1741339452.git.qemu_oss@crudebyte.com> (cherry picked from commit 61da38d) Signed-off-by: Michael Tokarev <[email protected]>
1 parent 9340920 commit 5081dc5

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

hw/9pfs/9p.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,12 @@ void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu)
435435
GHashTableIter iter;
436436
gpointer fid;
437437

438+
/* prevent multiple coroutines running this function simultaniously */
439+
if (s->reclaiming) {
440+
return;
441+
}
442+
s->reclaiming = true;
443+
438444
g_hash_table_iter_init(&iter, s->fids);
439445

440446
QSLIST_HEAD(, V9fsFidState) reclaim_list =
@@ -510,6 +516,8 @@ void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu)
510516
*/
511517
put_fid(pdu, f);
512518
}
519+
520+
s->reclaiming = false;
513521
}
514522

515523
/*
@@ -4324,6 +4332,8 @@ int v9fs_device_realize_common(V9fsState *s, const V9fsTransport *t,
43244332
s->ctx.fst = &fse->fst;
43254333
fsdev_throttle_init(s->ctx.fst);
43264334

4335+
s->reclaiming = false;
4336+
43274337
rc = 0;
43284338
out:
43294339
if (rc) {

hw/9pfs/9p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ struct V9fsState {
362362
uint64_t qp_ndevices; /* Amount of entries in qpd_table. */
363363
uint16_t qp_affix_next;
364364
uint64_t qp_fullpath_next;
365+
bool reclaiming;
365366
};
366367

367368
/* 9p2000.L open flags */

0 commit comments

Comments
 (0)