提交 1daaebfa 编写于 作者: M Mark McLoughlin

Add SCM_RIGHTS support to QEMU monitor code

Add qemudMonitorCommandWithFd() which allows a file descriptor to be
sent to qemu over a unix monitor socket using SCM_RIGHTS. See the
unix(7) and cmsg(3) man pages.

* src/qemu_conf.c: add a scm_fd param to qemudMonitorCommandExtra(),
  add qemudMonitorCommandWithFd(), implement SCM_RIGHTS support in
  qemudMonitorSendUnix()
上级 7d9576ed
...@@ -112,10 +112,15 @@ static int qemudDomainGetMaxVcpus(virDomainPtr dom); ...@@ -112,10 +112,15 @@ static int qemudDomainGetMaxVcpus(virDomainPtr dom);
static int qemudMonitorCommand(const virDomainObjPtr vm, static int qemudMonitorCommand(const virDomainObjPtr vm,
const char *cmd, const char *cmd,
char **reply); char **reply);
static int qemudMonitorCommandWithFd(const virDomainObjPtr vm,
const char *cmd,
int scm_fd,
char **reply);
static int qemudMonitorCommandExtra(const virDomainObjPtr vm, static int qemudMonitorCommandExtra(const virDomainObjPtr vm,
const char *cmd, const char *cmd,
const char *extra, const char *extra,
const char *extraPrompt, const char *extraPrompt,
int scm_fd,
char **reply); char **reply);
static int qemudDomainSetMemoryBalloon(virConnectPtr conn, static int qemudDomainSetMemoryBalloon(virConnectPtr conn,
virDomainObjPtr vm, virDomainObjPtr vm,
...@@ -1276,7 +1281,7 @@ qemudInitPasswords(virConnectPtr conn, ...@@ -1276,7 +1281,7 @@ qemudInitPasswords(virConnectPtr conn,
vm->def->graphics[0]->data.vnc.passwd : vm->def->graphics[0]->data.vnc.passwd :
driver->vncPassword, driver->vncPassword,
QEMU_PASSWD_PROMPT, QEMU_PASSWD_PROMPT,
&info) < 0) { -1, &info) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"%s", _("setting VNC password failed")); "%s", _("setting VNC password failed"));
return -1; return -1;
...@@ -2216,7 +2221,8 @@ qemuMonitorDiscardPendingData(virDomainObjPtr vm) { ...@@ -2216,7 +2221,8 @@ qemuMonitorDiscardPendingData(virDomainObjPtr vm) {
static int static int
qemudMonitorSendUnix(const virDomainObjPtr vm, qemudMonitorSendUnix(const virDomainObjPtr vm,
const char *cmd, const char *cmd,
size_t cmdlen) size_t cmdlen,
int scm_fd)
{ {
struct msghdr msg; struct msghdr msg;
struct iovec iov[1]; struct iovec iov[1];
...@@ -2230,6 +2236,20 @@ qemudMonitorSendUnix(const virDomainObjPtr vm, ...@@ -2230,6 +2236,20 @@ qemudMonitorSendUnix(const virDomainObjPtr vm,
msg.msg_iov = iov; msg.msg_iov = iov;
msg.msg_iovlen = 1; msg.msg_iovlen = 1;
if (scm_fd != -1) {
char control[CMSG_SPACE(sizeof(int))];
struct cmsghdr *cmsg;
msg.msg_control = control;
msg.msg_controllen = sizeof(control);
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
memcpy(CMSG_DATA(cmsg), &scm_fd, sizeof(int));
}
do { do {
ret = sendmsg(vm->monitor, &msg, 0); ret = sendmsg(vm->monitor, &msg, 0);
} while (ret < 0 && errno == EINTR); } while (ret < 0 && errno == EINTR);
...@@ -2239,7 +2259,8 @@ qemudMonitorSendUnix(const virDomainObjPtr vm, ...@@ -2239,7 +2259,8 @@ qemudMonitorSendUnix(const virDomainObjPtr vm,
static int static int
qemudMonitorSend(const virDomainObjPtr vm, qemudMonitorSend(const virDomainObjPtr vm,
const char *cmd) const char *cmd,
int scm_fd)
{ {
char *full; char *full;
size_t len; size_t len;
...@@ -2252,7 +2273,7 @@ qemudMonitorSend(const virDomainObjPtr vm, ...@@ -2252,7 +2273,7 @@ qemudMonitorSend(const virDomainObjPtr vm,
switch (vm->monitor_chr->type) { switch (vm->monitor_chr->type) {
case VIR_DOMAIN_CHR_TYPE_UNIX: case VIR_DOMAIN_CHR_TYPE_UNIX:
if (qemudMonitorSendUnix(vm, full, len) < 0) if (qemudMonitorSendUnix(vm, full, len, scm_fd) < 0)
goto out; goto out;
break; break;
default: default:
...@@ -2273,13 +2294,14 @@ qemudMonitorCommandExtra(const virDomainObjPtr vm, ...@@ -2273,13 +2294,14 @@ qemudMonitorCommandExtra(const virDomainObjPtr vm,
const char *cmd, const char *cmd,
const char *extra, const char *extra,
const char *extraPrompt, const char *extraPrompt,
int scm_fd,
char **reply) { char **reply) {
int size = 0; int size = 0;
char *buf = NULL; char *buf = NULL;
qemuMonitorDiscardPendingData(vm); qemuMonitorDiscardPendingData(vm);
if (qemudMonitorSend(vm, cmd) < 0) if (qemudMonitorSend(vm, cmd, scm_fd) < 0)
return -1; return -1;
*reply = NULL; *reply = NULL;
...@@ -2314,7 +2336,7 @@ qemudMonitorCommandExtra(const virDomainObjPtr vm, ...@@ -2314,7 +2336,7 @@ qemudMonitorCommandExtra(const virDomainObjPtr vm,
if (buf) { if (buf) {
if (extra) { if (extra) {
if (strstr(buf, extraPrompt) != NULL) { if (strstr(buf, extraPrompt) != NULL) {
if (qemudMonitorSend(vm, extra) < 0) if (qemudMonitorSend(vm, extra, -1) < 0)
return -1; return -1;
extra = NULL; extra = NULL;
} }
...@@ -2354,15 +2376,21 @@ qemudMonitorCommandExtra(const virDomainObjPtr vm, ...@@ -2354,15 +2376,21 @@ qemudMonitorCommandExtra(const virDomainObjPtr vm,
return -1; return -1;
} }
static int
qemudMonitorCommandWithFd(const virDomainObjPtr vm,
const char *cmd,
int scm_fd,
char **reply) {
return qemudMonitorCommandExtra(vm, cmd, NULL, NULL, scm_fd, reply);
}
static int static int
qemudMonitorCommand(const virDomainObjPtr vm, qemudMonitorCommand(const virDomainObjPtr vm,
const char *cmd, const char *cmd,
char **reply) { char **reply) {
return qemudMonitorCommandExtra(vm, cmd, NULL, NULL, reply); return qemudMonitorCommandWithFd(vm, cmd, -1, reply);
} }
static virDrvOpenStatus qemudOpen(virConnectPtr conn, static virDrvOpenStatus qemudOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED, virConnectAuthPtr auth ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED) { int flags ATTRIBUTE_UNUSED) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册