mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-09-01 11:15:57 +00:00
The virtio_blk_do_io() function can enter the QCOW code through
disk_image__{read,write,flush}() from multiple threads because it uses a thread
pool for I/O requests. Thus, use locking to make the QCOW2 code thread-safe.
Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
34 lines
755 B
C
34 lines
755 B
C
#ifndef KVM__MUTEX_H
|
|
#define KVM__MUTEX_H
|
|
|
|
#include <pthread.h>
|
|
|
|
#include "kvm/util.h"
|
|
|
|
/*
|
|
* Kernel-alike mutex API - to make it easier for kernel developers
|
|
* to write user-space code! :-)
|
|
*/
|
|
|
|
#define DEFINE_MUTEX(mutex) pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER
|
|
|
|
static inline void mutex_init(pthread_mutex_t *mutex)
|
|
{
|
|
if (pthread_mutex_init(mutex, NULL) != 0)
|
|
die("unexpected pthread_mutex_init() failure!");
|
|
}
|
|
|
|
static inline void mutex_lock(pthread_mutex_t *mutex)
|
|
{
|
|
if (pthread_mutex_lock(mutex) != 0)
|
|
die("unexpected pthread_mutex_lock() failure!");
|
|
}
|
|
|
|
static inline void mutex_unlock(pthread_mutex_t *mutex)
|
|
{
|
|
if (pthread_mutex_unlock(mutex) != 0)
|
|
die("unexpected pthread_mutex_unlock() failure!");
|
|
}
|
|
|
|
#endif /* KVM__MUTEX_H */
|