diff options
author | Greg Kurz <gkurz@linux.vnet.ibm.com> | 2016-06-06 11:52:34 +0200 |
---|---|---|
committer | Greg Kurz <gkurz@linux.vnet.ibm.com> | 2016-06-06 11:52:34 +0200 |
commit | 7cde47d4a89d5efefcc805788bc29133f4f3c5c7 (patch) | |
tree | 56025012a1648ccced4c5d1ea5f06b5536e245c6 /hw/9pfs/9p.h | |
parent | f314ea4e30a1ef87bf8845da952c6dd0bac20b95 (diff) | |
download | qemu-7cde47d4a89d5efefcc805788bc29133f4f3c5c7.tar.gz qemu-7cde47d4a89d5efefcc805788bc29133f4f3c5c7.tar.bz2 qemu-7cde47d4a89d5efefcc805788bc29133f4f3c5c7.zip |
9p: add locking to V9fsDir
If several threads concurrently call readdir() with the same directory
stream pointer, it is possible that they all get a pointer to the same
dirent structure, whose content is overwritten each time readdir() is
called.
We must thus serialize accesses to the dirent structure.
This may be achieved with a mutex like below:
lock_mutex();
readdir();
// work with the dirent
unlock_mutex();
This patch adds all the locking, to prepare the switch to readdir().
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
Diffstat (limited to 'hw/9pfs/9p.h')
-rw-r--r-- | hw/9pfs/9p.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index 92ee309ef4..46d787627a 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -169,8 +169,24 @@ typedef struct V9fsXattr typedef struct V9fsDir { DIR *stream; + QemuMutex readdir_mutex; } V9fsDir; +static inline void v9fs_readdir_lock(V9fsDir *dir) +{ + qemu_mutex_lock(&dir->readdir_mutex); +} + +static inline void v9fs_readdir_unlock(V9fsDir *dir) +{ + qemu_mutex_unlock(&dir->readdir_mutex); +} + +static inline void v9fs_readdir_init(V9fsDir *dir) +{ + qemu_mutex_init(&dir->readdir_mutex); +} + /* * Filled by fs driver on open and other * calls. |