- Objects must never be exclusively locked for any prolonged time
- Code which sleeps must be able to time out after suitable period
- - Must be safe against dispatch asynchronous events from monitor
+ - Must be safe against dispatch of asynchronous events from monitor
Basic locking primitives
This is the top level lock on the entire driver. Every API call in
the QEMU driver is blocked while this is held, though some internal
callbacks may still run asynchronously. This lock must never be held
- for anything which sleeps/waits (ie monitor commands)
+ for anything which sleeps/waits (i.e. monitor commands)
When obtaining the driver lock, under *NO* circumstances must
any lock be held on a virDomainObjPtr. This *WILL* result in
to have the driver locked when re-acquiring the dropped locked, since the
reference count prevents it being freed by another thread.
- This lock must not be held for anything which sleeps/waits (ie monitor
+ This lock must not be held for anything which sleeps/waits (i.e. monitor
commands).
whenever it hits a piece of code which may sleep/wait, and
re-acquire it after the sleep/wait. Whenever an asynchronous job
wants to talk to the monitor, it needs to acquire nested job (a
- special kind of normla job) to obtain exclusive access to the
+ special kind of normal job) to obtain exclusive access to the
monitor.
Since the virDomainObjPtr lock was dropped while waiting for the
- Increments ref count on virDomainObjPtr
- Waits until the job is compatible with current async job or no
async job is running
- - Waits job.cond condition 'job.active != 0' using virDomainObjPtr
+ - Waits for job.cond condition 'job.active != 0' using virDomainObjPtr
mutex
- Rechecks if the job is still compatible and repeats waiting if it
isn't
- Unlocks driver
- Waits until the job is compatible with current async job or no
async job is running
- - Waits job.cond condition 'job.active != 0' using virDomainObjPtr
+ - Waits for job.cond condition 'job.active != 0' using virDomainObjPtr
mutex
- Rechecks if the job is still compatible and repeats waiting if it
isn't
- Locks virDomainObjPtr
NB: this variant is required in order to comply with lock ordering
- rules for virDomainObjPtr vs driver
+ rules for virDomainObjPtr vs. driver
qemuDomainObjEndJob()
qemuDomainObjBeginAsyncJob() (if driver is unlocked)
- Increments ref count on virDomainObjPtr
- Waits until no async job is running
- - Waits job.cond condition 'job.active != 0' using virDomainObjPtr
+ - Waits for job.cond condition 'job.active != 0' using virDomainObjPtr
mutex
- Rechecks if any async job was started while waiting on job.cond
and repeats waiting in that case
- Increments ref count on virDomainObjPtr
- Unlocks driver
- Waits until no async job is running
- - Waits job.cond condition 'job.active != 0' using virDomainObjPtr
+ - Waits for job.cond condition 'job.active != 0' using virDomainObjPtr
mutex
- Rechecks if any async job was started while waiting on job.cond
and repeats waiting in that case
- * Accessing something directly todo with a virDomainObjPtr
+ * Accessing something directly to do with a virDomainObjPtr
virDomainObjPtr obj;
- * Accessing something directly todo with a virDomainObjPtr and driver
+ * Accessing something directly to do with a virDomainObjPtr and driver
virDomainObjPtr obj;
- * Updating something directly todo with a virDomainObjPtr
+ * Updating something directly to do with a virDomainObjPtr
virDomainObjPtr obj;
- qemuDriverLockRO(driver);
+ qemuDriverLock(driver);
obj = virDomainFindByUUID(driver->domains, dom->uuid);
qemuDriverUnlock(driver);
virDomainObjPtr obj;
qemuDomainObjPrivatePtr priv;
- qemuDriverLockRO(driver);
+ qemuDriverLock(driver);
obj = virDomainFindByUUID(driver->domains, dom->uuid);
qemuDriverUnlock(driver);
...do prep work...
if (virDomainObjIsActive(vm)) {
+ /* using ignore_value is safe since vm is active */
ignore_value(qemuDomainObjEnterMonitor(obj));
qemuMonitorXXXX(priv->mon);
qemuDomainObjExitMonitor(obj);
...do prep work...
if (virDomainObjIsActive(vm)) {
+ /* using ignore_value is safe since vm is active */
ignore_value(qemuDomainObjEnterMonitorWithDriver(driver, obj));
qemuMonitorXXXX(priv->mon);
qemuDomainObjExitMonitorWithDriver(driver, obj);