提交 18d68462 编写于 作者: E Eric Blake

qemu: simplify monitor callbacks

A future patch will change reference counting idioms; consolidating
this pattern now makes the next patch smaller (touch only the new
macro rather than every caller).

* src/qemu/qemu_monitor.c (QEMU_MONITOR_CALLBACK): New helper.
(qemuMonitorGetDiskSecret, qemuMonitorEmitShutdown)
(qemuMonitorEmitReset, qemuMonitorEmitPowerdown)
(qemuMonitorEmitStop, qemuMonitorEmitRTCChange)
(qemuMonitorEmitWatchdog, qemuMonitorEmitIOError)
(qemuMonitorEmitGraphics): Use it to reduce duplication.
上级 6afa49a9
...@@ -755,6 +755,16 @@ int qemuMonitorHMPCommandWithFd(qemuMonitorPtr mon, ...@@ -755,6 +755,16 @@ int qemuMonitorHMPCommandWithFd(qemuMonitorPtr mon,
return qemuMonitorTextCommandWithFd(mon, cmd, scm_fd, reply); return qemuMonitorTextCommandWithFd(mon, cmd, scm_fd, reply);
} }
/* Ensure proper locking around callbacks. */
#define QEMU_MONITOR_CALLBACK(mon, ret, callback, ...) \
do { \
qemuMonitorRef(mon); \
qemuMonitorUnlock(mon); \
if ((mon)->cb && (mon)->cb->callback) \
(ret) = ((mon)->cb->callback)(mon, __VA_ARGS__); \
qemuMonitorLock(mon); \
qemuMonitorUnref(mon); \
} while (0)
int qemuMonitorGetDiskSecret(qemuMonitorPtr mon, int qemuMonitorGetDiskSecret(qemuMonitorPtr mon,
virConnectPtr conn, virConnectPtr conn,
...@@ -766,12 +776,8 @@ int qemuMonitorGetDiskSecret(qemuMonitorPtr mon, ...@@ -766,12 +776,8 @@ int qemuMonitorGetDiskSecret(qemuMonitorPtr mon,
*secret = NULL; *secret = NULL;
*secretLen = 0; *secretLen = 0;
qemuMonitorRef(mon); QEMU_MONITOR_CALLBACK(mon, ret, diskSecretLookup, conn, mon->vm,
qemuMonitorUnlock(mon); path, secret, secretLen);
if (mon->cb && mon->cb->diskSecretLookup)
ret = mon->cb->diskSecretLookup(mon, conn, mon->vm, path, secret, secretLen);
qemuMonitorLock(mon);
qemuMonitorUnref(mon);
return ret; return ret;
} }
...@@ -781,12 +787,7 @@ int qemuMonitorEmitShutdown(qemuMonitorPtr mon) ...@@ -781,12 +787,7 @@ int qemuMonitorEmitShutdown(qemuMonitorPtr mon)
int ret = -1; int ret = -1;
VIR_DEBUG("mon=%p", mon); VIR_DEBUG("mon=%p", mon);
qemuMonitorRef(mon); QEMU_MONITOR_CALLBACK(mon, ret, domainShutdown, mon->vm);
qemuMonitorUnlock(mon);
if (mon->cb && mon->cb->domainShutdown)
ret = mon->cb->domainShutdown(mon, mon->vm);
qemuMonitorLock(mon);
qemuMonitorUnref(mon);
return ret; return ret;
} }
...@@ -796,12 +797,7 @@ int qemuMonitorEmitReset(qemuMonitorPtr mon) ...@@ -796,12 +797,7 @@ int qemuMonitorEmitReset(qemuMonitorPtr mon)
int ret = -1; int ret = -1;
VIR_DEBUG("mon=%p", mon); VIR_DEBUG("mon=%p", mon);
qemuMonitorRef(mon); QEMU_MONITOR_CALLBACK(mon, ret, domainReset, mon->vm);
qemuMonitorUnlock(mon);
if (mon->cb && mon->cb->domainReset)
ret = mon->cb->domainReset(mon, mon->vm);
qemuMonitorLock(mon);
qemuMonitorUnref(mon);
return ret; return ret;
} }
...@@ -811,12 +807,7 @@ int qemuMonitorEmitPowerdown(qemuMonitorPtr mon) ...@@ -811,12 +807,7 @@ int qemuMonitorEmitPowerdown(qemuMonitorPtr mon)
int ret = -1; int ret = -1;
VIR_DEBUG("mon=%p", mon); VIR_DEBUG("mon=%p", mon);
qemuMonitorRef(mon); QEMU_MONITOR_CALLBACK(mon, ret, domainPowerdown, mon->vm);
qemuMonitorUnlock(mon);
if (mon->cb && mon->cb->domainPowerdown)
ret = mon->cb->domainPowerdown(mon, mon->vm);
qemuMonitorLock(mon);
qemuMonitorUnref(mon);
return ret; return ret;
} }
...@@ -826,12 +817,7 @@ int qemuMonitorEmitStop(qemuMonitorPtr mon) ...@@ -826,12 +817,7 @@ int qemuMonitorEmitStop(qemuMonitorPtr mon)
int ret = -1; int ret = -1;
VIR_DEBUG("mon=%p", mon); VIR_DEBUG("mon=%p", mon);
qemuMonitorRef(mon); QEMU_MONITOR_CALLBACK(mon, ret, domainStop, mon->vm);
qemuMonitorUnlock(mon);
if (mon->cb && mon->cb->domainStop)
ret = mon->cb->domainStop(mon, mon->vm);
qemuMonitorLock(mon);
qemuMonitorUnref(mon);
return ret; return ret;
} }
...@@ -841,12 +827,7 @@ int qemuMonitorEmitRTCChange(qemuMonitorPtr mon, long long offset) ...@@ -841,12 +827,7 @@ int qemuMonitorEmitRTCChange(qemuMonitorPtr mon, long long offset)
int ret = -1; int ret = -1;
VIR_DEBUG("mon=%p", mon); VIR_DEBUG("mon=%p", mon);
qemuMonitorRef(mon); QEMU_MONITOR_CALLBACK(mon, ret, domainRTCChange, mon->vm, offset);
qemuMonitorUnlock(mon);
if (mon->cb && mon->cb->domainRTCChange)
ret = mon->cb->domainRTCChange(mon, mon->vm, offset);
qemuMonitorLock(mon);
qemuMonitorUnref(mon);
return ret; return ret;
} }
...@@ -856,12 +837,7 @@ int qemuMonitorEmitWatchdog(qemuMonitorPtr mon, int action) ...@@ -856,12 +837,7 @@ int qemuMonitorEmitWatchdog(qemuMonitorPtr mon, int action)
int ret = -1; int ret = -1;
VIR_DEBUG("mon=%p", mon); VIR_DEBUG("mon=%p", mon);
qemuMonitorRef(mon); QEMU_MONITOR_CALLBACK(mon, ret, domainWatchdog, mon->vm, action);
qemuMonitorUnlock(mon);
if (mon->cb && mon->cb->domainWatchdog)
ret = mon->cb->domainWatchdog(mon, mon->vm, action);
qemuMonitorLock(mon);
qemuMonitorUnref(mon);
return ret; return ret;
} }
...@@ -874,12 +850,8 @@ int qemuMonitorEmitIOError(qemuMonitorPtr mon, ...@@ -874,12 +850,8 @@ int qemuMonitorEmitIOError(qemuMonitorPtr mon,
int ret = -1; int ret = -1;
VIR_DEBUG("mon=%p", mon); VIR_DEBUG("mon=%p", mon);
qemuMonitorRef(mon); QEMU_MONITOR_CALLBACK(mon, ret, domainIOError, mon->vm,
qemuMonitorUnlock(mon); diskAlias, action, reason);
if (mon->cb && mon->cb->domainIOError)
ret = mon->cb->domainIOError(mon, mon->vm, diskAlias, action, reason);
qemuMonitorLock(mon);
qemuMonitorUnref(mon);
return ret; return ret;
} }
...@@ -899,16 +871,10 @@ int qemuMonitorEmitGraphics(qemuMonitorPtr mon, ...@@ -899,16 +871,10 @@ int qemuMonitorEmitGraphics(qemuMonitorPtr mon,
int ret = -1; int ret = -1;
VIR_DEBUG("mon=%p", mon); VIR_DEBUG("mon=%p", mon);
qemuMonitorRef(mon); QEMU_MONITOR_CALLBACK(mon, ret, domainGraphics, mon->vm, phase,
qemuMonitorUnlock(mon); localFamily, localNode, localService,
if (mon->cb && mon->cb->domainGraphics) remoteFamily, remoteNode, remoteService,
ret = mon->cb->domainGraphics(mon, mon->vm, authScheme, x509dname, saslUsername);
phase,
localFamily, localNode, localService,
remoteFamily, remoteNode, remoteService,
authScheme, x509dname, saslUsername);
qemuMonitorLock(mon);
qemuMonitorUnref(mon);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册