2012-08-02 19:06:50 +00:00
|
|
|
/*
|
|
|
|
* lock_daemon.c: lock management daemon
|
|
|
|
*
|
2015-03-16 14:02:41 +00:00
|
|
|
* Copyright (C) 2006-2015 Red Hat, Inc.
|
2012-08-02 19:06:50 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "lock_daemon.h"
|
|
|
|
#include "lock_daemon_config.h"
|
2018-01-19 14:54:00 +00:00
|
|
|
#include "admin/admin_server_dispatch.h"
|
2012-12-13 17:44:57 +00:00
|
|
|
#include "virutil.h"
|
2012-08-02 19:06:50 +00:00
|
|
|
#include "virfile.h"
|
|
|
|
#include "virpidfile.h"
|
2012-08-03 09:27:07 +00:00
|
|
|
#include "virprocess.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-12 16:35:35 +00:00
|
|
|
#include "virconf.h"
|
2015-03-16 14:02:41 +00:00
|
|
|
#include "rpc/virnetdaemon.h"
|
2012-08-02 19:06:50 +00:00
|
|
|
#include "rpc/virnetserver.h"
|
|
|
|
#include "virrandom.h"
|
|
|
|
#include "virhash.h"
|
2012-12-13 18:01:25 +00:00
|
|
|
#include "viruuid.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2016-04-12 22:29:52 +00:00
|
|
|
#include "virgettext.h"
|
2019-04-01 10:14:26 +00:00
|
|
|
#include "virenum.h"
|
2012-08-02 19:06:50 +00:00
|
|
|
|
2012-08-03 09:27:07 +00:00
|
|
|
#include "locking/lock_daemon_dispatch.h"
|
|
|
|
#include "locking/lock_protocol.h"
|
|
|
|
|
2012-08-02 19:06:50 +00:00
|
|
|
#include "configmake.h"
|
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_LOCKING
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("locking.lock_daemon");
|
|
|
|
|
2012-08-03 09:27:07 +00:00
|
|
|
#define VIR_LOCK_DAEMON_NUM_LOCKSPACES 3
|
|
|
|
|
2012-08-02 19:06:50 +00:00
|
|
|
struct _virLockDaemon {
|
|
|
|
virMutex lock;
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetDaemonPtr dmn;
|
2012-08-03 09:27:07 +00:00
|
|
|
virHashTablePtr lockspaces;
|
|
|
|
virLockSpacePtr defaultLockspace;
|
2012-08-02 19:06:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virLockDaemonPtr lockDaemon = NULL;
|
|
|
|
|
2014-10-28 20:17:04 +00:00
|
|
|
static bool execRestart;
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
|
2012-08-02 19:06:50 +00:00
|
|
|
enum {
|
|
|
|
VIR_LOCK_DAEMON_ERR_NONE = 0,
|
|
|
|
VIR_LOCK_DAEMON_ERR_PIDFILE,
|
|
|
|
VIR_LOCK_DAEMON_ERR_RUNDIR,
|
|
|
|
VIR_LOCK_DAEMON_ERR_INIT,
|
|
|
|
VIR_LOCK_DAEMON_ERR_SIGNAL,
|
|
|
|
VIR_LOCK_DAEMON_ERR_PRIVS,
|
|
|
|
VIR_LOCK_DAEMON_ERR_NETWORK,
|
|
|
|
VIR_LOCK_DAEMON_ERR_CONFIG,
|
|
|
|
VIR_LOCK_DAEMON_ERR_HOOKS,
|
2013-12-09 06:23:28 +00:00
|
|
|
VIR_LOCK_DAEMON_ERR_REEXEC,
|
2012-08-02 19:06:50 +00:00
|
|
|
|
|
|
|
VIR_LOCK_DAEMON_ERR_LAST
|
|
|
|
};
|
|
|
|
|
2019-01-20 16:04:56 +00:00
|
|
|
VIR_ENUM_DECL(virDaemonErr);
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virDaemonErr,
|
|
|
|
VIR_LOCK_DAEMON_ERR_LAST,
|
2012-08-02 19:06:50 +00:00
|
|
|
"Initialization successful",
|
|
|
|
"Unable to obtain pidfile",
|
|
|
|
"Unable to create rundir",
|
|
|
|
"Unable to initialize libvirt",
|
|
|
|
"Unable to setup signal handlers",
|
|
|
|
"Unable to drop privileges",
|
|
|
|
"Unable to initialize network sockets",
|
|
|
|
"Unable to load configuration file",
|
2013-12-09 06:23:28 +00:00
|
|
|
"Unable to look for hook scripts",
|
2019-01-20 16:30:15 +00:00
|
|
|
"Unable to re-execute daemon",
|
|
|
|
);
|
2012-08-02 19:06:50 +00:00
|
|
|
|
|
|
|
static void *
|
|
|
|
virLockDaemonClientNew(virNetServerClientPtr client,
|
|
|
|
void *opaque);
|
|
|
|
static void
|
|
|
|
virLockDaemonClientFree(void *opaque);
|
|
|
|
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
static void *
|
|
|
|
virLockDaemonClientNewPostExecRestart(virNetServerClientPtr client,
|
|
|
|
virJSONValuePtr object,
|
|
|
|
void *opaque);
|
|
|
|
static virJSONValuePtr
|
|
|
|
virLockDaemonClientPreExecRestart(virNetServerClientPtr client,
|
|
|
|
void *opaque);
|
|
|
|
|
2012-08-02 19:06:50 +00:00
|
|
|
static void
|
|
|
|
virLockDaemonFree(virLockDaemonPtr lockd)
|
|
|
|
{
|
|
|
|
if (!lockd)
|
|
|
|
return;
|
|
|
|
|
2015-11-24 13:16:23 +00:00
|
|
|
virMutexDestroy(&lockd->lock);
|
2015-03-16 14:02:41 +00:00
|
|
|
virObjectUnref(lockd->dmn);
|
2012-08-03 09:27:07 +00:00
|
|
|
virHashFree(lockd->lockspaces);
|
|
|
|
virLockSpaceFree(lockd->defaultLockspace);
|
2012-08-02 19:06:50 +00:00
|
|
|
|
|
|
|
VIR_FREE(lockd);
|
|
|
|
}
|
|
|
|
|
2015-10-07 11:36:43 +00:00
|
|
|
static inline void
|
|
|
|
virLockDaemonLock(virLockDaemonPtr lockd)
|
|
|
|
{
|
|
|
|
virMutexLock(&lockd->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
virLockDaemonUnlock(virLockDaemonPtr lockd)
|
|
|
|
{
|
|
|
|
virMutexUnlock(&lockd->lock);
|
|
|
|
}
|
2012-08-02 19:06:50 +00:00
|
|
|
|
2012-08-03 09:27:07 +00:00
|
|
|
static void virLockDaemonLockSpaceDataFree(void *data,
|
|
|
|
const void *key ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
virLockSpaceFree(data);
|
|
|
|
}
|
|
|
|
|
2012-08-02 19:06:50 +00:00
|
|
|
static virLockDaemonPtr
|
2013-08-19 11:38:23 +00:00
|
|
|
virLockDaemonNew(virLockDaemonConfigPtr config, bool privileged)
|
2012-08-02 19:06:50 +00:00
|
|
|
{
|
|
|
|
virLockDaemonPtr lockd;
|
2018-01-19 14:54:00 +00:00
|
|
|
virNetServerPtr srv = NULL;
|
2012-08-02 19:06:50 +00:00
|
|
|
|
2013-07-04 10:11:02 +00:00
|
|
|
if (VIR_ALLOC(lockd) < 0)
|
2012-08-02 19:06:50 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (virMutexInit(&lockd->lock) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Unable to initialize mutex"));
|
|
|
|
VIR_FREE(lockd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-01-19 14:54:00 +00:00
|
|
|
if (!(lockd->dmn = virNetDaemonNew()))
|
|
|
|
goto error;
|
|
|
|
|
2016-04-13 18:54:40 +00:00
|
|
|
if (!(srv = virNetServerNew("virtlockd", 1,
|
2018-03-06 17:12:20 +00:00
|
|
|
0, 0, 0, config->max_clients,
|
2015-08-20 14:56:32 +00:00
|
|
|
config->max_clients, -1, 0,
|
|
|
|
virLockDaemonClientNew,
|
|
|
|
virLockDaemonClientPreExecRestart,
|
|
|
|
virLockDaemonClientFree,
|
|
|
|
(void*)(intptr_t)(privileged ? 0x1 : 0x0))))
|
2012-08-02 19:06:50 +00:00
|
|
|
goto error;
|
|
|
|
|
2018-01-19 14:54:00 +00:00
|
|
|
if (virNetDaemonAddServer(lockd->dmn, srv) < 0)
|
|
|
|
goto error;
|
|
|
|
virObjectUnref(srv);
|
|
|
|
srv = NULL;
|
|
|
|
|
|
|
|
if (!(srv = virNetServerNew("admin", 1,
|
2018-03-06 17:12:20 +00:00
|
|
|
0, 0, 0, config->admin_max_clients,
|
2018-01-19 14:54:00 +00:00
|
|
|
config->admin_max_clients, -1, 0,
|
|
|
|
remoteAdmClientNew,
|
|
|
|
remoteAdmClientPreExecRestart,
|
|
|
|
remoteAdmClientFree,
|
|
|
|
lockd->dmn)))
|
2015-03-16 14:02:41 +00:00
|
|
|
goto error;
|
2018-01-19 14:54:00 +00:00
|
|
|
|
|
|
|
if (virNetDaemonAddServer(lockd->dmn, srv) < 0)
|
|
|
|
goto error;
|
2017-10-28 21:03:20 +00:00
|
|
|
virObjectUnref(srv);
|
|
|
|
srv = NULL;
|
2015-03-16 14:02:41 +00:00
|
|
|
|
2012-08-03 09:27:07 +00:00
|
|
|
if (!(lockd->lockspaces = virHashCreate(VIR_LOCK_DAEMON_NUM_LOCKSPACES,
|
|
|
|
virLockDaemonLockSpaceDataFree)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(lockd->defaultLockspace = virLockSpaceNew(NULL)))
|
|
|
|
goto error;
|
|
|
|
|
2012-08-02 19:06:50 +00:00
|
|
|
return lockd;
|
|
|
|
|
2014-03-25 06:51:47 +00:00
|
|
|
error:
|
2017-10-28 21:03:20 +00:00
|
|
|
virObjectUnref(srv);
|
2012-08-02 19:06:50 +00:00
|
|
|
virLockDaemonFree(lockd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-22 17:38:55 +00:00
|
|
|
static virNetServerPtr
|
|
|
|
virLockDaemonNewServerPostExecRestart(virNetDaemonPtr dmn ATTRIBUTE_UNUSED,
|
|
|
|
const char *name,
|
|
|
|
virJSONValuePtr object,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
if (STREQ(name, "virtlockd")) {
|
|
|
|
return virNetServerNewPostExecRestart(object,
|
|
|
|
name,
|
|
|
|
virLockDaemonClientNew,
|
|
|
|
virLockDaemonClientNewPostExecRestart,
|
|
|
|
virLockDaemonClientPreExecRestart,
|
|
|
|
virLockDaemonClientFree,
|
|
|
|
opaque);
|
2018-01-19 14:54:00 +00:00
|
|
|
} else if (STREQ(name, "admin")) {
|
|
|
|
return virNetServerNewPostExecRestart(object,
|
|
|
|
name,
|
|
|
|
remoteAdmClientNew,
|
|
|
|
remoteAdmClientNewPostExecRestart,
|
|
|
|
remoteAdmClientPreExecRestart,
|
|
|
|
remoteAdmClientFree,
|
|
|
|
dmn);
|
2018-01-22 17:38:55 +00:00
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unexpected server name '%s' during restart"),
|
|
|
|
name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
static virLockDaemonPtr
|
|
|
|
virLockDaemonNewPostExecRestart(virJSONValuePtr object, bool privileged)
|
|
|
|
{
|
|
|
|
virLockDaemonPtr lockd;
|
|
|
|
virJSONValuePtr child;
|
|
|
|
virJSONValuePtr lockspaces;
|
|
|
|
size_t i;
|
2018-01-22 17:38:55 +00:00
|
|
|
const char *serverNames[] = { "virtlockd" };
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
|
2013-07-04 10:11:02 +00:00
|
|
|
if (VIR_ALLOC(lockd) < 0)
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (virMutexInit(&lockd->lock) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Unable to initialize mutex"));
|
|
|
|
VIR_FREE(lockd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(lockd->lockspaces = virHashCreate(VIR_LOCK_DAEMON_NUM_LOCKSPACES,
|
|
|
|
virLockDaemonLockSpaceDataFree)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(child = virJSONValueObjectGet(object, "defaultLockspace"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing defaultLockspace data from JSON file"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(lockd->defaultLockspace =
|
|
|
|
virLockSpaceNewPostExecRestart(child)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(lockspaces = virJSONValueObjectGet(object, "lockspaces"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing lockspaces data from JSON file"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2018-04-19 21:29:02 +00:00
|
|
|
if (!virJSONValueIsArray(lockspaces)) {
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2018-04-19 21:29:02 +00:00
|
|
|
_("Malformed lockspaces array"));
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2018-04-19 21:29:02 +00:00
|
|
|
for (i = 0; i < virJSONValueArraySize(lockspaces); i++) {
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
virLockSpacePtr lockspace;
|
|
|
|
|
|
|
|
child = virJSONValueArrayGet(lockspaces, i);
|
|
|
|
|
|
|
|
if (!(lockspace = virLockSpaceNewPostExecRestart(child)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virHashAddEntry(lockd->lockspaces,
|
|
|
|
virLockSpaceGetDirectory(lockspace),
|
|
|
|
lockspace) < 0) {
|
|
|
|
virLockSpaceFree(lockspace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-16 14:02:41 +00:00
|
|
|
if (virJSONValueObjectHasKey(object, "daemon")) {
|
|
|
|
if (!(child = virJSONValueObjectGet(object, "daemon"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Malformed daemon data from JSON file"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!(child = virJSONValueObjectGet(object, "server"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing server data from JSON file"));
|
|
|
|
goto error;
|
|
|
|
}
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
}
|
|
|
|
|
2018-01-22 17:38:55 +00:00
|
|
|
if (!(lockd->dmn = virNetDaemonNewPostExecRestart(child,
|
|
|
|
ARRAY_CARDINALITY(serverNames),
|
|
|
|
serverNames,
|
|
|
|
virLockDaemonNewServerPostExecRestart,
|
|
|
|
(void*)(intptr_t)(privileged ? 0x1 : 0x0))))
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
return lockd;
|
|
|
|
|
2014-03-25 06:51:47 +00:00
|
|
|
error:
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
virLockDaemonFree(lockd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-03 09:27:07 +00:00
|
|
|
int virLockDaemonAddLockSpace(virLockDaemonPtr lockd,
|
|
|
|
const char *path,
|
|
|
|
virLockSpacePtr lockspace)
|
|
|
|
{
|
|
|
|
int ret;
|
2015-10-07 11:36:43 +00:00
|
|
|
virLockDaemonLock(lockd);
|
2012-08-03 09:27:07 +00:00
|
|
|
ret = virHashAddEntry(lockd->lockspaces, path, lockspace);
|
2015-10-07 11:36:43 +00:00
|
|
|
virLockDaemonUnlock(lockd);
|
2012-08-03 09:27:07 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLockSpacePtr virLockDaemonFindLockSpace(virLockDaemonPtr lockd,
|
|
|
|
const char *path)
|
|
|
|
{
|
|
|
|
virLockSpacePtr lockspace;
|
2015-10-07 11:36:43 +00:00
|
|
|
virLockDaemonLock(lockd);
|
2012-08-03 09:27:07 +00:00
|
|
|
if (path && STRNEQ(path, ""))
|
|
|
|
lockspace = virHashLookup(lockd->lockspaces, path);
|
|
|
|
else
|
|
|
|
lockspace = lockd->defaultLockspace;
|
2015-10-07 11:36:43 +00:00
|
|
|
virLockDaemonUnlock(lockd);
|
2012-08-03 09:27:07 +00:00
|
|
|
return lockspace;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-02 19:06:50 +00:00
|
|
|
static int
|
|
|
|
virLockDaemonForkIntoBackground(const char *argv0)
|
|
|
|
{
|
|
|
|
int statuspipe[2];
|
|
|
|
if (pipe(statuspipe) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
pid_t pid = fork();
|
|
|
|
switch (pid) {
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
int stdinfd = -1;
|
|
|
|
int stdoutfd = -1;
|
|
|
|
int nextpid;
|
|
|
|
|
|
|
|
VIR_FORCE_CLOSE(statuspipe[0]);
|
|
|
|
|
|
|
|
if ((stdinfd = open("/dev/null", O_RDONLY)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
if ((stdoutfd = open("/dev/null", O_WRONLY)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
if (dup2(stdinfd, STDIN_FILENO) != STDIN_FILENO)
|
|
|
|
goto cleanup;
|
|
|
|
if (dup2(stdoutfd, STDOUT_FILENO) != STDOUT_FILENO)
|
|
|
|
goto cleanup;
|
|
|
|
if (dup2(stdoutfd, STDERR_FILENO) != STDERR_FILENO)
|
|
|
|
goto cleanup;
|
|
|
|
if (VIR_CLOSE(stdinfd) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
if (VIR_CLOSE(stdoutfd) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (setsid() < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
nextpid = fork();
|
|
|
|
switch (nextpid) {
|
|
|
|
case 0:
|
|
|
|
return statuspipe[1];
|
|
|
|
case -1:
|
|
|
|
return -1;
|
|
|
|
default:
|
|
|
|
_exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FORCE_CLOSE(stdoutfd);
|
|
|
|
VIR_FORCE_CLOSE(stdinfd);
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
int got, exitstatus = 0;
|
|
|
|
int ret;
|
|
|
|
char status;
|
|
|
|
|
|
|
|
VIR_FORCE_CLOSE(statuspipe[1]);
|
|
|
|
|
|
|
|
/* We wait to make sure the first child forked successfully */
|
|
|
|
if ((got = waitpid(pid, &exitstatus, 0)) < 0 ||
|
|
|
|
got != pid ||
|
|
|
|
exitstatus != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now block until the second child initializes successfully */
|
|
|
|
again:
|
|
|
|
ret = read(statuspipe[0], &status, 1);
|
|
|
|
if (ret == -1 && errno == EINTR)
|
|
|
|
goto again;
|
|
|
|
|
|
|
|
if (ret == 1 && status != 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
_("%s: error: %s. Check /var/log/messages or run without "
|
|
|
|
"--daemon for more info.\n"), argv0,
|
|
|
|
virDaemonErrTypeToString(status));
|
|
|
|
}
|
|
|
|
_exit(ret == 1 && status == 0 ? 0 : 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virLockDaemonUnixSocketPaths(bool privileged,
|
2018-01-19 14:54:00 +00:00
|
|
|
char **sockfile,
|
|
|
|
char **adminSockfile)
|
2012-08-02 19:06:50 +00:00
|
|
|
{
|
|
|
|
if (privileged) {
|
2019-08-20 15:05:12 +00:00
|
|
|
if (VIR_STRDUP(*sockfile, RUNSTATEDIR "/libvirt/virtlockd-sock") < 0 ||
|
|
|
|
VIR_STRDUP(*adminSockfile, RUNSTATEDIR "/libvirt/virtlockd-admin-sock") < 0)
|
2013-05-03 12:43:12 +00:00
|
|
|
goto error;
|
2012-08-02 19:06:50 +00:00
|
|
|
} else {
|
|
|
|
char *rundir = NULL;
|
|
|
|
mode_t old_umask;
|
|
|
|
|
|
|
|
if (!(rundir = virGetUserRuntimeDirectory()))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
old_umask = umask(077);
|
|
|
|
if (virFileMakePath(rundir) < 0) {
|
2015-11-24 13:16:23 +00:00
|
|
|
VIR_FREE(rundir);
|
2012-08-02 19:06:50 +00:00
|
|
|
umask(old_umask);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
umask(old_umask);
|
|
|
|
|
2018-01-19 14:54:00 +00:00
|
|
|
if (virAsprintf(sockfile, "%s/virtlockd-sock", rundir) < 0 ||
|
|
|
|
virAsprintf(adminSockfile, "%s/virtlockd-admin-sock", rundir) < 0) {
|
2012-08-02 19:06:50 +00:00
|
|
|
VIR_FREE(rundir);
|
2013-05-03 12:43:12 +00:00
|
|
|
goto error;
|
2012-08-02 19:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(rundir);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
2014-03-25 06:51:47 +00:00
|
|
|
error:
|
2012-08-02 19:06:50 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
virLockDaemonErrorHandler(void *opaque ATTRIBUTE_UNUSED,
|
|
|
|
virErrorPtr err ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
/* Don't do anything, since logging infrastructure already
|
|
|
|
* took care of reporting the error */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the logging environment
|
|
|
|
* By default if daemonized all errors go to the logfile libvirtd.log,
|
|
|
|
* but if verbose or error debugging is asked for then also output
|
|
|
|
* informational and debug messages. Default size if 64 kB.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
virLockDaemonSetupLogging(virLockDaemonConfigPtr config,
|
|
|
|
bool privileged,
|
|
|
|
bool verbose,
|
|
|
|
bool godaemon)
|
|
|
|
{
|
|
|
|
virLogReset();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Libvirtd's order of precedence is:
|
|
|
|
* cmdline > environment > config
|
|
|
|
*
|
2017-08-25 14:58:51 +00:00
|
|
|
* Given the precedence, we must process the variables in the opposite
|
2012-08-02 19:06:50 +00:00
|
|
|
* order, each one overriding the previous.
|
|
|
|
*/
|
|
|
|
if (config->log_level != 0)
|
|
|
|
virLogSetDefaultPriority(config->log_level);
|
|
|
|
|
2017-08-25 14:58:51 +00:00
|
|
|
/* In case the config is empty, both filters and outputs will become empty,
|
|
|
|
* however we can't start with empty outputs, thus we'll need to define and
|
|
|
|
* setup a default one.
|
2016-10-31 11:52:51 +00:00
|
|
|
*/
|
|
|
|
ignore_value(virLogSetFilters(config->log_filters));
|
|
|
|
ignore_value(virLogSetOutputs(config->log_outputs));
|
2012-08-02 19:06:50 +00:00
|
|
|
|
2016-10-31 11:52:51 +00:00
|
|
|
/* If there are some environment variables defined, use those instead */
|
|
|
|
virLogSetFromEnv();
|
2012-08-02 19:06:50 +00:00
|
|
|
|
2016-06-28 11:05:30 +00:00
|
|
|
/*
|
|
|
|
* Command line override for --verbose
|
|
|
|
*/
|
|
|
|
if ((verbose) && (virLogGetDefaultPriority() > VIR_LOG_INFO))
|
|
|
|
virLogSetDefaultPriority(VIR_LOG_INFO);
|
|
|
|
|
2017-08-25 14:58:51 +00:00
|
|
|
/* Define the default output. This is only applied if there was no setting
|
|
|
|
* from either the config or the environment.
|
|
|
|
*/
|
2019-06-21 15:40:02 +00:00
|
|
|
if (virLogSetDefaultOutput("virtlockd", godaemon, privileged) < 0)
|
2017-08-25 14:58:51 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (virLogGetNbOutputs() == 0)
|
|
|
|
virLogSetOutputs(virLogGetDefaultOutput());
|
|
|
|
|
2012-08-02 19:06:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Display version information. */
|
|
|
|
static void
|
|
|
|
virLockDaemonVersion(const char *argv0)
|
|
|
|
{
|
|
|
|
printf("%s (%s) %s\n", argv0, PACKAGE_NAME, PACKAGE_VERSION);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-03-16 14:02:41 +00:00
|
|
|
virLockDaemonShutdownHandler(virNetDaemonPtr dmn,
|
2012-08-02 19:06:50 +00:00
|
|
|
siginfo_t *sig ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetDaemonQuit(dmn);
|
2012-08-02 19:06:50 +00:00
|
|
|
}
|
|
|
|
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
static void
|
2015-03-16 14:02:41 +00:00
|
|
|
virLockDaemonExecRestartHandler(virNetDaemonPtr dmn,
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
siginfo_t *sig ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
execRestart = true;
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetDaemonQuit(dmn);
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 19:06:50 +00:00
|
|
|
static int
|
2015-03-16 14:02:41 +00:00
|
|
|
virLockDaemonSetupSignals(virNetDaemonPtr dmn)
|
2012-08-02 19:06:50 +00:00
|
|
|
{
|
2015-03-16 14:02:41 +00:00
|
|
|
if (virNetDaemonAddSignalHandler(dmn, SIGINT, virLockDaemonShutdownHandler, NULL) < 0)
|
2012-08-02 19:06:50 +00:00
|
|
|
return -1;
|
2015-03-16 14:02:41 +00:00
|
|
|
if (virNetDaemonAddSignalHandler(dmn, SIGQUIT, virLockDaemonShutdownHandler, NULL) < 0)
|
2012-08-02 19:06:50 +00:00
|
|
|
return -1;
|
2015-03-16 14:02:41 +00:00
|
|
|
if (virNetDaemonAddSignalHandler(dmn, SIGTERM, virLockDaemonShutdownHandler, NULL) < 0)
|
2012-08-02 19:06:50 +00:00
|
|
|
return -1;
|
2015-03-16 14:02:41 +00:00
|
|
|
if (virNetDaemonAddSignalHandler(dmn, SIGUSR1, virLockDaemonExecRestartHandler, NULL) < 0)
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
return -1;
|
2012-08-02 19:06:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-07 14:02:32 +00:00
|
|
|
|
2012-08-03 09:27:07 +00:00
|
|
|
struct virLockDaemonClientReleaseData {
|
|
|
|
virLockDaemonClientPtr client;
|
|
|
|
bool hadSomeLeases;
|
|
|
|
bool gotError;
|
|
|
|
};
|
|
|
|
|
2016-02-12 09:03:50 +00:00
|
|
|
static int
|
2012-08-03 09:27:07 +00:00
|
|
|
virLockDaemonClientReleaseLockspace(void *payload,
|
|
|
|
const void *name ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
virLockSpacePtr lockspace = payload;
|
|
|
|
struct virLockDaemonClientReleaseData *data = opaque;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = virLockSpaceReleaseResourcesForOwner(lockspace,
|
|
|
|
data->client->clientPid);
|
|
|
|
if (rc > 0)
|
|
|
|
data->hadSomeLeases = true;
|
|
|
|
else if (rc < 0)
|
|
|
|
data->gotError = true;
|
2016-02-12 09:03:50 +00:00
|
|
|
return 0;
|
2012-08-03 09:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-02 19:06:50 +00:00
|
|
|
static void
|
|
|
|
virLockDaemonClientFree(void *opaque)
|
|
|
|
{
|
|
|
|
virLockDaemonClientPtr priv = opaque;
|
|
|
|
|
|
|
|
if (!priv)
|
|
|
|
return;
|
|
|
|
|
2012-08-03 09:27:07 +00:00
|
|
|
VIR_DEBUG("priv=%p client=%lld owner=%lld",
|
2012-08-02 19:06:50 +00:00
|
|
|
priv,
|
2012-08-03 09:27:07 +00:00
|
|
|
(unsigned long long)priv->clientPid,
|
|
|
|
(unsigned long long)priv->ownerPid);
|
|
|
|
|
|
|
|
/* If client & owner match, this is the lock holder */
|
|
|
|
if (priv->clientPid == priv->ownerPid) {
|
|
|
|
size_t i;
|
|
|
|
struct virLockDaemonClientReleaseData data = {
|
|
|
|
.client = priv, .hadSomeLeases = false, .gotError = false
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Release all locks associated with this
|
|
|
|
* owner in all lockspaces */
|
2015-10-07 11:36:43 +00:00
|
|
|
virLockDaemonLock(lockDaemon);
|
2012-08-03 09:27:07 +00:00
|
|
|
virHashForEach(lockDaemon->lockspaces,
|
|
|
|
virLockDaemonClientReleaseLockspace,
|
|
|
|
&data);
|
|
|
|
virLockDaemonClientReleaseLockspace(lockDaemon->defaultLockspace,
|
|
|
|
"",
|
|
|
|
&data);
|
2015-10-07 11:36:43 +00:00
|
|
|
virLockDaemonUnlock(lockDaemon);
|
2012-08-03 09:27:07 +00:00
|
|
|
|
|
|
|
/* If the client had some active leases when it
|
|
|
|
* closed the connection, we must kill it off
|
|
|
|
* to make sure it doesn't do nasty stuff */
|
|
|
|
if (data.gotError || data.hadSomeLeases) {
|
2013-05-21 08:06:00 +00:00
|
|
|
for (i = 0; i < 15; i++) {
|
2012-08-03 09:27:07 +00:00
|
|
|
int signum;
|
|
|
|
if (i == 0)
|
|
|
|
signum = SIGTERM;
|
|
|
|
else if (i == 8)
|
|
|
|
signum = SIGKILL;
|
|
|
|
else
|
|
|
|
signum = 0;
|
2015-04-16 17:32:42 +00:00
|
|
|
if (priv->clientPid != 0 && virProcessKill(priv->clientPid, signum) < 0) {
|
2012-08-03 09:27:07 +00:00
|
|
|
if (errno == ESRCH)
|
|
|
|
break;
|
|
|
|
|
|
|
|
VIR_WARN("Failed to kill off pid %lld",
|
|
|
|
(unsigned long long)priv->clientPid);
|
|
|
|
}
|
2019-10-02 17:01:11 +00:00
|
|
|
g_usleep(200 * 1000);
|
2012-08-03 09:27:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-02 19:06:50 +00:00
|
|
|
|
|
|
|
virMutexDestroy(&priv->lock);
|
2018-08-26 06:48:47 +00:00
|
|
|
VIR_FREE(priv->ownerName);
|
2012-08-02 19:06:50 +00:00
|
|
|
VIR_FREE(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void *
|
|
|
|
virLockDaemonClientNew(virNetServerClientPtr client,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
virLockDaemonClientPtr priv;
|
|
|
|
uid_t clientuid;
|
|
|
|
gid_t clientgid;
|
2013-04-25 16:05:00 +00:00
|
|
|
unsigned long long timestamp;
|
2012-08-02 19:06:50 +00:00
|
|
|
bool privileged = opaque != NULL;
|
|
|
|
|
2013-07-04 10:11:02 +00:00
|
|
|
if (VIR_ALLOC(priv) < 0)
|
2012-08-02 19:06:50 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (virMutexInit(&priv->lock) < 0) {
|
|
|
|
VIR_FREE(priv);
|
2013-07-04 10:11:02 +00:00
|
|
|
virReportSystemError(errno, "%s", _("unable to init mutex"));
|
2012-08-02 19:06:50 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virNetServerClientGetUNIXIdentity(client,
|
|
|
|
&clientuid,
|
|
|
|
&clientgid,
|
2013-04-25 16:05:00 +00:00
|
|
|
&priv->clientPid,
|
|
|
|
×tamp) < 0)
|
2012-08-02 19:06:50 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
VIR_DEBUG("New client pid %llu uid %llu",
|
|
|
|
(unsigned long long)priv->clientPid,
|
|
|
|
(unsigned long long)clientuid);
|
|
|
|
|
|
|
|
if (!privileged) {
|
|
|
|
if (geteuid() != clientuid) {
|
2013-12-20 14:02:49 +00:00
|
|
|
virReportRestrictedError(_("Disallowing client %llu with uid %llu"),
|
|
|
|
(unsigned long long)priv->clientPid,
|
|
|
|
(unsigned long long)clientuid);
|
2012-08-02 19:06:50 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (clientuid != 0) {
|
2013-12-20 14:02:49 +00:00
|
|
|
virReportRestrictedError(_("Disallowing client %llu with uid %llu"),
|
|
|
|
(unsigned long long)priv->clientPid,
|
|
|
|
(unsigned long long)clientuid);
|
2012-08-02 19:06:50 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-17 15:38:47 +00:00
|
|
|
/* there's no closing handshake in the locking protocol */
|
|
|
|
virNetServerClientSetQuietEOF(client);
|
|
|
|
|
2012-08-02 19:06:50 +00:00
|
|
|
return priv;
|
|
|
|
|
2014-03-25 06:51:47 +00:00
|
|
|
error:
|
2012-08-02 19:06:50 +00:00
|
|
|
virMutexDestroy(&priv->lock);
|
|
|
|
VIR_FREE(priv);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
static void *
|
|
|
|
virLockDaemonClientNewPostExecRestart(virNetServerClientPtr client,
|
|
|
|
virJSONValuePtr object,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
virLockDaemonClientPtr priv = virLockDaemonClientNew(client, opaque);
|
|
|
|
unsigned int ownerPid;
|
|
|
|
const char *ownerUUID;
|
|
|
|
const char *ownerName;
|
|
|
|
|
|
|
|
if (!priv)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetBoolean(object, "restricted", &priv->restricted) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing restricted data in JSON document"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (virJSONValueObjectGetNumberUint(object, "ownerPid", &ownerPid) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing ownerPid data in JSON document"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
priv->ownerPid = (pid_t)ownerPid;
|
|
|
|
if (virJSONValueObjectGetNumberUint(object, "ownerId", &priv->ownerId) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing ownerId data in JSON document"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (!(ownerName = virJSONValueObjectGetString(object, "ownerName"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing ownerName data in JSON document"));
|
|
|
|
goto error;
|
|
|
|
}
|
2013-05-03 12:43:12 +00:00
|
|
|
if (VIR_STRDUP(priv->ownerName, ownerName) < 0)
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
goto error;
|
|
|
|
if (!(ownerUUID = virJSONValueObjectGetString(object, "ownerUUID"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing ownerUUID data in JSON document"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (virUUIDParse(ownerUUID, priv->ownerUUID) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing ownerUUID data in JSON document"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
return priv;
|
|
|
|
|
2014-03-25 06:51:47 +00:00
|
|
|
error:
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
virLockDaemonClientFree(priv);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static virJSONValuePtr
|
|
|
|
virLockDaemonClientPreExecRestart(virNetServerClientPtr client ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
virLockDaemonClientPtr priv = opaque;
|
|
|
|
virJSONValuePtr object = virJSONValueNewObject();
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
|
|
|
|
if (!object)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (virJSONValueObjectAppendBoolean(object, "restricted", priv->restricted) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot set restricted data in JSON document"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (virJSONValueObjectAppendNumberUint(object, "ownerPid", priv->ownerPid) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot set ownerPid data in JSON document"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (virJSONValueObjectAppendNumberUint(object, "ownerId", priv->ownerId) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot set ownerId data in JSON document"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (virJSONValueObjectAppendString(object, "ownerName", priv->ownerName) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot set ownerName data in JSON document"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
virUUIDFormat(priv->ownerUUID, uuidstr);
|
|
|
|
if (virJSONValueObjectAppendString(object, "ownerUUID", uuidstr) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot set ownerUUID data in JSON document"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return object;
|
|
|
|
|
2014-03-25 06:51:47 +00:00
|
|
|
error:
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
virJSONValueFree(object);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-11 08:07:45 +00:00
|
|
|
static int
|
|
|
|
virLockDaemonExecRestartStatePath(bool privileged,
|
|
|
|
char **state_file)
|
|
|
|
{
|
|
|
|
if (privileged) {
|
2019-08-20 15:05:12 +00:00
|
|
|
if (VIR_STRDUP(*state_file, RUNSTATEDIR "/virtlockd-restart-exec.json") < 0)
|
2013-12-11 08:07:45 +00:00
|
|
|
goto error;
|
|
|
|
} else {
|
|
|
|
char *rundir = NULL;
|
|
|
|
mode_t old_umask;
|
|
|
|
|
|
|
|
if (!(rundir = virGetUserRuntimeDirectory()))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
old_umask = umask(077);
|
|
|
|
if (virFileMakePath(rundir) < 0) {
|
|
|
|
umask(old_umask);
|
|
|
|
VIR_FREE(rundir);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
umask(old_umask);
|
|
|
|
|
|
|
|
if (virAsprintf(state_file, "%s/virtlockd-restart-exec.json", rundir) < 0) {
|
|
|
|
VIR_FREE(rundir);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(rundir);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2014-03-25 06:51:47 +00:00
|
|
|
error:
|
2013-12-11 08:07:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
|
|
|
|
static char *
|
|
|
|
virLockDaemonGetExecRestartMagic(void)
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
|
2013-07-04 10:11:02 +00:00
|
|
|
ignore_value(virAsprintf(&ret, "%lld", (long long int)getpid()));
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-12-11 08:07:45 +00:00
|
|
|
virLockDaemonPostExecRestart(const char *state_file,
|
|
|
|
const char *pid_file,
|
|
|
|
int *pid_file_fd,
|
|
|
|
bool privileged)
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
{
|
|
|
|
const char *gotmagic;
|
|
|
|
char *wantmagic = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
char *state = NULL;
|
|
|
|
virJSONValuePtr object = NULL;
|
|
|
|
|
|
|
|
VIR_DEBUG("Running post-restart exec");
|
|
|
|
|
2013-12-11 08:07:45 +00:00
|
|
|
if (!virFileExists(state_file)) {
|
|
|
|
VIR_DEBUG("No restart state file %s present",
|
|
|
|
state_file);
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-12-11 08:07:45 +00:00
|
|
|
if (virFileReadAll(state_file,
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
1024 * 1024 * 10, /* 10 MB */
|
|
|
|
&state) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
VIR_DEBUG("Loading state %s", state);
|
|
|
|
|
|
|
|
if (!(object = virJSONValueFromString(state)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
gotmagic = virJSONValueObjectGetString(object, "magic");
|
|
|
|
if (!gotmagic) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing magic data in JSON document"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(wantmagic = virLockDaemonGetExecRestartMagic()))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (STRNEQ(gotmagic, wantmagic)) {
|
|
|
|
VIR_WARN("Found restart exec file with old magic %s vs wanted %s",
|
|
|
|
gotmagic, wantmagic);
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-12-11 08:07:45 +00:00
|
|
|
/* Re-claim PID file now as we will not be daemonizing */
|
|
|
|
if (pid_file &&
|
2014-03-17 14:17:36 +00:00
|
|
|
(*pid_file_fd = virPidFileAcquirePath(pid_file, false, getpid())) < 0)
|
2013-12-11 08:07:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
if (!(lockDaemon = virLockDaemonNewPostExecRestart(object, privileged)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 1;
|
|
|
|
|
2014-03-25 06:51:47 +00:00
|
|
|
cleanup:
|
2013-12-11 08:07:45 +00:00
|
|
|
unlink(state_file);
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
VIR_FREE(wantmagic);
|
|
|
|
VIR_FREE(state);
|
|
|
|
virJSONValueFree(object);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-12-11 08:07:45 +00:00
|
|
|
virLockDaemonPreExecRestart(const char *state_file,
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetDaemonPtr dmn,
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
char **argv)
|
|
|
|
{
|
|
|
|
virJSONValuePtr child;
|
|
|
|
char *state = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr object;
|
|
|
|
char *magic;
|
|
|
|
virHashKeyValuePairPtr pairs = NULL, tmp;
|
|
|
|
virJSONValuePtr lockspaces;
|
|
|
|
|
|
|
|
VIR_DEBUG("Running pre-restart exec");
|
|
|
|
|
|
|
|
if (!(object = virJSONValueNewObject()))
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-03-16 14:02:41 +00:00
|
|
|
if (!(child = virNetDaemonPreExecRestart(dmn)))
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-03-16 14:02:41 +00:00
|
|
|
if (virJSONValueObjectAppend(object, "daemon", child) < 0) {
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
virJSONValueFree(child);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(child = virLockSpacePreExecRestart(lockDaemon->defaultLockspace)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virJSONValueObjectAppend(object, "defaultLockspace", child) < 0) {
|
|
|
|
virJSONValueFree(child);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(lockspaces = virJSONValueNewArray()))
|
|
|
|
goto cleanup;
|
|
|
|
if (virJSONValueObjectAppend(object, "lockspaces", lockspaces) < 0) {
|
|
|
|
virJSONValueFree(lockspaces);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tmp = pairs = virHashGetItems(lockDaemon->lockspaces, NULL);
|
|
|
|
while (tmp && tmp->key) {
|
|
|
|
virLockSpacePtr lockspace = (virLockSpacePtr)tmp->value;
|
|
|
|
|
|
|
|
if (!(child = virLockSpacePreExecRestart(lockspace)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virJSONValueArrayAppend(lockspaces, child) < 0) {
|
|
|
|
virJSONValueFree(child);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(magic = virLockDaemonGetExecRestartMagic()))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virJSONValueObjectAppendString(object, "magic", magic) < 0) {
|
|
|
|
VIR_FREE(magic);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(state = virJSONValueToString(object, true)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
VIR_DEBUG("Saving state %s", state);
|
|
|
|
|
2013-12-11 08:07:45 +00:00
|
|
|
if (virFileWriteStr(state_file,
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
state, 0700) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Unable to save state file %s"),
|
2013-12-11 08:07:45 +00:00
|
|
|
state_file);
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-12-11 08:07:45 +00:00
|
|
|
if (execvp(argv[0], argv) < 0) {
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
virReportSystemError(errno, "%s",
|
|
|
|
_("Unable to restart self"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
abort(); /* This should be impossible to reach */
|
|
|
|
|
2014-03-25 06:51:47 +00:00
|
|
|
cleanup:
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
VIR_FREE(pairs);
|
|
|
|
VIR_FREE(state);
|
|
|
|
virJSONValueFree(object);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-02 19:06:50 +00:00
|
|
|
static void
|
|
|
|
virLockDaemonUsage(const char *argv0, bool privileged)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
_("\n"
|
|
|
|
"Usage:\n"
|
|
|
|
" %s [options]\n"
|
|
|
|
"\n"
|
|
|
|
"Options:\n"
|
2013-08-13 11:14:15 +00:00
|
|
|
" -h | --help Display program help:\n"
|
2012-08-02 19:06:50 +00:00
|
|
|
" -v | --verbose Verbose messages.\n"
|
|
|
|
" -d | --daemon Run as a daemon & write PID file.\n"
|
2014-04-25 11:21:57 +00:00
|
|
|
" -t | --timeout <secs> Exit after timeout period.\n"
|
2012-08-02 19:06:50 +00:00
|
|
|
" -f | --config <file> Configuration file.\n"
|
2013-08-13 11:14:15 +00:00
|
|
|
" -V | --version Display version information.\n"
|
2012-08-02 19:06:50 +00:00
|
|
|
" -p | --pid-file <file> Change name of PID file.\n"
|
|
|
|
"\n"
|
|
|
|
"libvirt lock management daemon:\n"), argv0);
|
|
|
|
|
|
|
|
if (privileged) {
|
|
|
|
fprintf(stderr,
|
|
|
|
_("\n"
|
|
|
|
" Default paths:\n"
|
|
|
|
"\n"
|
|
|
|
" Configuration file (unless overridden by -f):\n"
|
|
|
|
" %s/libvirt/virtlockd.conf\n"
|
|
|
|
"\n"
|
|
|
|
" Sockets:\n"
|
2019-08-20 15:05:12 +00:00
|
|
|
" %s/libvirt/virtlockd-sock\n"
|
2012-08-02 19:06:50 +00:00
|
|
|
"\n"
|
|
|
|
" PID file (unless overridden by -p):\n"
|
2019-08-20 15:05:12 +00:00
|
|
|
" %s/virtlockd.pid\n"
|
2012-08-02 19:06:50 +00:00
|
|
|
"\n"),
|
|
|
|
SYSCONFDIR,
|
2019-08-20 15:05:12 +00:00
|
|
|
RUNSTATEDIR,
|
|
|
|
RUNSTATEDIR);
|
2012-08-02 19:06:50 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "%s",
|
|
|
|
_("\n"
|
|
|
|
" Default paths:\n"
|
|
|
|
"\n"
|
|
|
|
" Configuration file (unless overridden by -f):\n"
|
|
|
|
" $XDG_CONFIG_HOME/libvirt/virtlockd.conf\n"
|
|
|
|
"\n"
|
|
|
|
" Sockets:\n"
|
|
|
|
" $XDG_RUNTIME_DIR/libvirt/virtlockd-sock\n"
|
|
|
|
"\n"
|
|
|
|
" PID file:\n"
|
|
|
|
" $XDG_RUNTIME_DIR/libvirt/virtlockd.pid\n"
|
|
|
|
"\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2018-01-19 14:54:00 +00:00
|
|
|
virNetServerPtr lockSrv = NULL;
|
|
|
|
virNetServerPtr adminSrv = NULL;
|
2012-08-03 09:27:07 +00:00
|
|
|
virNetServerProgramPtr lockProgram = NULL;
|
2018-01-19 14:54:00 +00:00
|
|
|
virNetServerProgramPtr adminProgram = NULL;
|
2012-08-02 19:06:50 +00:00
|
|
|
char *remote_config_file = NULL;
|
|
|
|
int statuswrite = -1;
|
|
|
|
int ret = 1;
|
|
|
|
int verbose = 0;
|
|
|
|
int godaemon = 0;
|
|
|
|
char *run_dir = NULL;
|
|
|
|
char *pid_file = NULL;
|
|
|
|
int pid_file_fd = -1;
|
|
|
|
char *sock_file = NULL;
|
2018-01-19 14:54:00 +00:00
|
|
|
char *admin_sock_file = NULL;
|
2014-04-25 11:21:57 +00:00
|
|
|
int timeout = -1; /* -t: Shutdown timeout */
|
2013-12-11 08:07:45 +00:00
|
|
|
char *state_file = NULL;
|
2012-08-02 19:06:50 +00:00
|
|
|
bool implicit_conf = false;
|
|
|
|
mode_t old_umask;
|
|
|
|
bool privileged = false;
|
|
|
|
virLockDaemonConfigPtr config = NULL;
|
2011-07-07 14:02:32 +00:00
|
|
|
int rv;
|
2012-08-02 19:06:50 +00:00
|
|
|
|
|
|
|
struct option opts[] = {
|
2013-08-13 11:14:15 +00:00
|
|
|
{ "verbose", no_argument, &verbose, 'v'},
|
|
|
|
{ "daemon", no_argument, &godaemon, 'd'},
|
2012-08-02 19:06:50 +00:00
|
|
|
{ "config", required_argument, NULL, 'f'},
|
2014-04-25 11:21:57 +00:00
|
|
|
{ "timeout", required_argument, NULL, 't'},
|
2012-08-02 19:06:50 +00:00
|
|
|
{ "pid-file", required_argument, NULL, 'p'},
|
2013-08-13 11:14:15 +00:00
|
|
|
{ "version", no_argument, NULL, 'V' },
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
2012-08-02 19:06:50 +00:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2013-10-09 11:13:45 +00:00
|
|
|
privileged = geteuid() == 0;
|
2012-08-02 19:06:50 +00:00
|
|
|
|
2016-04-12 22:29:52 +00:00
|
|
|
if (virGettextInitialize() < 0 ||
|
2012-08-02 19:06:50 +00:00
|
|
|
virErrorInitialize() < 0) {
|
|
|
|
fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
int optidx = 0;
|
|
|
|
int c;
|
2014-04-25 11:21:57 +00:00
|
|
|
char *tmp;
|
2012-08-02 19:06:50 +00:00
|
|
|
|
2015-11-24 13:16:23 +00:00
|
|
|
c = getopt_long(argc, argv, "df:p:t:vVh", opts, &optidx);
|
2012-08-02 19:06:50 +00:00
|
|
|
|
2014-11-13 14:27:11 +00:00
|
|
|
if (c == -1)
|
2012-08-02 19:06:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 0:
|
|
|
|
/* Got one of the flags */
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
verbose = 1;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
godaemon = 1;
|
|
|
|
break;
|
|
|
|
|
2014-04-25 11:21:57 +00:00
|
|
|
case 't':
|
|
|
|
if (virStrToLong_i(optarg, &tmp, 10, &timeout) != 0
|
|
|
|
|| timeout <= 0
|
|
|
|
/* Ensure that we can multiply by 1000 without overflowing. */
|
|
|
|
|| timeout > INT_MAX / 1000) {
|
|
|
|
VIR_ERROR(_("Invalid value for timeout"));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-08-02 19:06:50 +00:00
|
|
|
case 'p':
|
|
|
|
VIR_FREE(pid_file);
|
2013-12-09 06:23:28 +00:00
|
|
|
if (VIR_STRDUP_QUIET(pid_file, optarg) < 0)
|
|
|
|
goto no_memory;
|
2012-08-02 19:06:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
VIR_FREE(remote_config_file);
|
2013-12-09 06:23:28 +00:00
|
|
|
if (VIR_STRDUP_QUIET(remote_config_file, optarg) < 0)
|
|
|
|
goto no_memory;
|
2012-08-02 19:06:50 +00:00
|
|
|
break;
|
|
|
|
|
2013-08-13 11:14:15 +00:00
|
|
|
case 'V':
|
2012-08-02 19:06:50 +00:00
|
|
|
virLockDaemonVersion(argv[0]);
|
2013-08-13 11:14:15 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2012-08-02 19:06:50 +00:00
|
|
|
|
2013-08-13 11:14:15 +00:00
|
|
|
case 'h':
|
2012-08-02 19:06:50 +00:00
|
|
|
virLockDaemonUsage(argv[0], privileged);
|
2013-08-13 11:14:15 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2012-08-02 19:06:50 +00:00
|
|
|
|
2013-08-13 11:14:15 +00:00
|
|
|
case '?':
|
2012-08-02 19:06:50 +00:00
|
|
|
default:
|
2013-08-13 11:14:15 +00:00
|
|
|
virLockDaemonUsage(argv[0], privileged);
|
2012-08-02 19:06:50 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-29 10:52:08 +00:00
|
|
|
virFileActivateDirOverrideForProg(argv[0]);
|
2014-04-24 14:57:36 +00:00
|
|
|
|
2012-08-02 19:06:50 +00:00
|
|
|
if (!(config = virLockDaemonConfigNew(privileged))) {
|
|
|
|
VIR_ERROR(_("Can't create initial configuration"));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No explicit config, so try and find a default one */
|
|
|
|
if (remote_config_file == NULL) {
|
|
|
|
implicit_conf = true;
|
|
|
|
if (virLockDaemonConfigFilePath(privileged,
|
|
|
|
&remote_config_file) < 0) {
|
|
|
|
VIR_ERROR(_("Can't determine config path"));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the config file if it exists*/
|
|
|
|
if (remote_config_file &&
|
|
|
|
virLockDaemonConfigLoadFile(config, remote_config_file, implicit_conf) < 0) {
|
2016-05-19 19:10:19 +00:00
|
|
|
VIR_ERROR(_("Can't load config file: %s: %s"),
|
|
|
|
virGetLastErrorMessage(), remote_config_file);
|
2012-08-02 19:06:50 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2018-08-26 06:48:47 +00:00
|
|
|
VIR_FREE(remote_config_file);
|
2012-08-02 19:06:50 +00:00
|
|
|
|
|
|
|
if (virLockDaemonSetupLogging(config, privileged, verbose, godaemon) < 0) {
|
|
|
|
VIR_ERROR(_("Can't initialize logging"));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pid_file &&
|
2014-09-07 17:52:34 +00:00
|
|
|
virPidFileConstructPath(privileged,
|
2019-08-20 15:05:12 +00:00
|
|
|
RUNSTATEDIR,
|
2014-09-07 17:52:34 +00:00
|
|
|
"virtlockd",
|
|
|
|
&pid_file) < 0) {
|
2012-08-02 19:06:50 +00:00
|
|
|
VIR_ERROR(_("Can't determine pid file path."));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
VIR_DEBUG("Decided on pid file path '%s'", NULLSTR(pid_file));
|
|
|
|
|
|
|
|
if (virLockDaemonUnixSocketPaths(privileged,
|
2018-01-19 14:54:00 +00:00
|
|
|
&sock_file,
|
|
|
|
&admin_sock_file) < 0) {
|
2012-08-02 19:06:50 +00:00
|
|
|
VIR_ERROR(_("Can't determine socket paths"));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2018-01-19 14:54:00 +00:00
|
|
|
VIR_DEBUG("Decided on socket paths '%s' and '%s'",
|
|
|
|
sock_file, admin_sock_file);
|
2012-08-02 19:06:50 +00:00
|
|
|
|
2013-12-11 08:07:45 +00:00
|
|
|
if (virLockDaemonExecRestartStatePath(privileged,
|
|
|
|
&state_file) < 0) {
|
|
|
|
VIR_ERROR(_("Can't determine restart state file path"));
|
|
|
|
exit(EXIT_FAILURE);
|
2012-08-02 19:06:50 +00:00
|
|
|
}
|
2013-12-11 08:07:45 +00:00
|
|
|
VIR_DEBUG("Decided on restart state file path '%s'",
|
|
|
|
state_file);
|
2012-08-02 19:06:50 +00:00
|
|
|
|
|
|
|
/* Ensure the rundir exists (on tmpfs on some systems) */
|
|
|
|
if (privileged) {
|
2019-08-20 15:05:12 +00:00
|
|
|
if (VIR_STRDUP_QUIET(run_dir, RUNSTATEDIR "/libvirt") < 0)
|
2013-12-09 06:23:28 +00:00
|
|
|
goto no_memory;
|
2012-08-02 19:06:50 +00:00
|
|
|
} else {
|
2013-01-16 10:51:21 +00:00
|
|
|
if (!(run_dir = virGetUserRuntimeDirectory())) {
|
2012-08-02 19:06:50 +00:00
|
|
|
VIR_ERROR(_("Can't determine user directory"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (privileged)
|
|
|
|
old_umask = umask(022);
|
|
|
|
else
|
|
|
|
old_umask = umask(077);
|
|
|
|
VIR_DEBUG("Ensuring run dir '%s' exists", run_dir);
|
|
|
|
if (virFileMakePath(run_dir) < 0) {
|
|
|
|
char ebuf[1024];
|
|
|
|
VIR_ERROR(_("unable to create rundir %s: %s"), run_dir,
|
|
|
|
virStrerror(errno, ebuf, sizeof(ebuf)));
|
|
|
|
ret = VIR_LOCK_DAEMON_ERR_RUNDIR;
|
2015-11-24 13:16:23 +00:00
|
|
|
umask(old_umask);
|
2012-08-02 19:06:50 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
umask(old_umask);
|
|
|
|
|
2013-12-11 08:07:45 +00:00
|
|
|
if ((rv = virLockDaemonPostExecRestart(state_file,
|
|
|
|
pid_file,
|
|
|
|
&pid_file_fd,
|
|
|
|
privileged)) < 0) {
|
2012-08-02 19:06:50 +00:00
|
|
|
ret = VIR_LOCK_DAEMON_ERR_INIT;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
virtlockd: Don't SIGSEGV on SIGUSR1
So we have this mechanism that on SIGUSR1 the virtlockd dumps its
internal state into a JSON file, reexec itself and the reloads
the internal state back. However, there's a bug in our
implementation:
(gdb) signal SIGUSR1
Continuing with signal SIGUSR1.
[Thread 0x7fd094f7b700 (LWP 10602) exited]
process 10600 is executing new program: /home/zippy/work/libvirt/libvirt.git/src/virtlockd
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7fb28bc3c700 (LWP 14501)]
Program received signal SIGSEGV, Segmentation fault.
0x00007fb29133d530 in virExpandN (ptrptr=0x70, size=8, countptr=0x68, add=1, report=true, domcode=7, filename=0x7fb29138aeab "rpc/virnetserver.c", funcname=0x7fb29138b680 <__FUNCTION__.15821> "virNetServerAddProgram", linenr=661) at util/viralloc.c:288
288 if (*countptr + add < *countptr) {
(gdb) bt
#0 0x00007fb29133d530 in virExpandN (ptrptr=0x70, size=8, countptr=0x68, add=1, report=true, domcode=7, filename=0x7fb29138aeab "rpc/virnetserver.c", funcname=0x7fb29138b680 <__FUNCTION__.15821> "virNetServerAddProgram", linenr=661) at util/viralloc.c:288
#1 0x00007fb29132a267 in virNetServerAddProgram (srv=0x0, prog=0x7fb2915d08b0) at rpc/virnetserver.c:661
#2 0x00007fb29131f27f in main (argc=1, argv=0x7fff8f771298) at locking/lock_daemon.c:1445
Notice the NULL @srv passed to frame 2? Usually, the @srv
variable is initialized on fresh start. However, in case of
daemon reload, the code path that is responsible for initializing
the value was not triggered and therefore we crashed immediately.
Fix this by always setting the variable.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-10-12 07:58:05 +00:00
|
|
|
/* rv == 1 means we successfully restored from the saved internal state
|
|
|
|
* (but still need to add @lockProgram into @srv). rv == 0 means that no
|
|
|
|
* saved state is present, therefore initialize from scratch here. */
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
if (rv == 0) {
|
2019-06-25 17:29:43 +00:00
|
|
|
VIR_AUTOPTR(virSystemdActivation) act = NULL;
|
|
|
|
virSystemdActivationMap actmap[] = {
|
|
|
|
{ .name = "virtlockd.socket", .family = AF_UNIX, .path = sock_file },
|
|
|
|
{ .name = "virtlockd-admin.socket", .family = AF_UNIX, .path = admin_sock_file },
|
|
|
|
};
|
|
|
|
|
2013-12-11 08:07:45 +00:00
|
|
|
if (godaemon) {
|
|
|
|
char ebuf[1024];
|
|
|
|
|
|
|
|
if (chdir("/") < 0) {
|
|
|
|
VIR_ERROR(_("cannot change to root directory: %s"),
|
|
|
|
virStrerror(errno, ebuf, sizeof(ebuf)));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((statuswrite = virLockDaemonForkIntoBackground(argv[0])) < 0) {
|
|
|
|
VIR_ERROR(_("Failed to fork as daemon: %s"),
|
|
|
|
virStrerror(errno, ebuf, sizeof(ebuf)));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we have a pidfile set, claim it now, exiting if already taken */
|
2014-03-17 14:17:36 +00:00
|
|
|
if ((pid_file_fd = virPidFileAcquirePath(pid_file, false, getpid())) < 0) {
|
2013-12-11 08:07:45 +00:00
|
|
|
ret = VIR_LOCK_DAEMON_ERR_PIDFILE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-08-19 11:38:23 +00:00
|
|
|
if (!(lockDaemon = virLockDaemonNew(config, privileged))) {
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
ret = VIR_LOCK_DAEMON_ERR_INIT;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2011-07-07 14:02:32 +00:00
|
|
|
|
2019-06-25 17:29:43 +00:00
|
|
|
if (virSystemdGetActivation(actmap,
|
|
|
|
ARRAY_CARDINALITY(actmap),
|
|
|
|
&act) < 0) {
|
|
|
|
ret = VIR_LOCK_DAEMON_ERR_NETWORK;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2018-01-19 14:54:00 +00:00
|
|
|
lockSrv = virNetDaemonGetServer(lockDaemon->dmn, "virtlockd");
|
|
|
|
adminSrv = virNetDaemonGetServer(lockDaemon->dmn, "admin");
|
2019-06-25 17:29:43 +00:00
|
|
|
|
|
|
|
if (virNetServerAddServiceUNIX(lockSrv,
|
|
|
|
act, "virtlockd.socket",
|
|
|
|
sock_file, 0700, 0, 0,
|
|
|
|
NULL,
|
|
|
|
false, 0, 1) < 0) {
|
|
|
|
ret = VIR_LOCK_DAEMON_ERR_NETWORK;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virNetServerAddServiceUNIX(adminSrv,
|
|
|
|
act, "virtlockd-admin.socket",
|
|
|
|
admin_sock_file, 0700, 0, 0,
|
|
|
|
NULL,
|
|
|
|
false, 0, 1) < 0) {
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
ret = VIR_LOCK_DAEMON_ERR_NETWORK;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2019-06-25 17:29:43 +00:00
|
|
|
if (act &&
|
|
|
|
virSystemdActivationComplete(act) < 0) {
|
|
|
|
ret = VIR_LOCK_DAEMON_ERR_NETWORK;
|
|
|
|
goto cleanup;
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
}
|
2019-06-25 17:29:43 +00:00
|
|
|
} else {
|
|
|
|
lockSrv = virNetDaemonGetServer(lockDaemon->dmn, "virtlockd");
|
|
|
|
/* If exec-restarting from old virtlockd, we won't have an
|
|
|
|
* admin server present */
|
|
|
|
if (virNetDaemonHasServer(lockDaemon->dmn, "admin"))
|
|
|
|
adminSrv = virNetDaemonGetServer(lockDaemon->dmn, "admin");
|
2012-08-02 19:06:50 +00:00
|
|
|
}
|
|
|
|
|
2014-04-25 11:21:57 +00:00
|
|
|
if (timeout != -1) {
|
|
|
|
VIR_DEBUG("Registering shutdown timeout %d", timeout);
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetDaemonAutoShutdown(lockDaemon->dmn,
|
2014-04-25 11:21:57 +00:00
|
|
|
timeout);
|
|
|
|
}
|
|
|
|
|
2015-03-16 14:02:41 +00:00
|
|
|
if ((virLockDaemonSetupSignals(lockDaemon->dmn)) < 0) {
|
2012-08-02 19:06:50 +00:00
|
|
|
ret = VIR_LOCK_DAEMON_ERR_SIGNAL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-08-03 09:27:07 +00:00
|
|
|
if (!(lockProgram = virNetServerProgramNew(VIR_LOCK_SPACE_PROTOCOL_PROGRAM,
|
|
|
|
VIR_LOCK_SPACE_PROTOCOL_PROGRAM_VERSION,
|
|
|
|
virLockSpaceProtocolProcs,
|
|
|
|
virLockSpaceProtocolNProcs))) {
|
|
|
|
ret = VIR_LOCK_DAEMON_ERR_INIT;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2015-03-16 14:02:41 +00:00
|
|
|
|
2018-01-19 14:54:00 +00:00
|
|
|
if (virNetServerAddProgram(lockSrv, lockProgram) < 0) {
|
2012-08-03 09:27:07 +00:00
|
|
|
ret = VIR_LOCK_DAEMON_ERR_INIT;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2018-01-19 14:54:00 +00:00
|
|
|
if (adminSrv != NULL) {
|
|
|
|
if (!(adminProgram = virNetServerProgramNew(ADMIN_PROGRAM,
|
|
|
|
ADMIN_PROTOCOL_VERSION,
|
|
|
|
adminProcs,
|
|
|
|
adminNProcs))) {
|
|
|
|
ret = VIR_LOCK_DAEMON_ERR_INIT;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virNetServerAddProgram(adminSrv, adminProgram) < 0) {
|
|
|
|
ret = VIR_LOCK_DAEMON_ERR_INIT;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-02 19:06:50 +00:00
|
|
|
/* Disable error func, now logging is setup */
|
|
|
|
virSetErrorFunc(NULL, virLockDaemonErrorHandler);
|
|
|
|
|
|
|
|
|
|
|
|
/* Tell parent of daemon that basic initialization is complete
|
|
|
|
* In particular we're ready to accept net connections & have
|
|
|
|
* written the pidfile
|
|
|
|
*/
|
|
|
|
if (statuswrite != -1) {
|
|
|
|
char status = 0;
|
|
|
|
while (write(statuswrite, &status, 1) == -1 &&
|
|
|
|
errno == EINTR)
|
|
|
|
;
|
|
|
|
VIR_FORCE_CLOSE(statuswrite);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start accepting new clients from network */
|
|
|
|
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetDaemonUpdateServices(lockDaemon->dmn, true);
|
|
|
|
virNetDaemonRun(lockDaemon->dmn);
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
|
|
|
|
if (execRestart &&
|
2013-12-11 08:07:45 +00:00
|
|
|
virLockDaemonPreExecRestart(state_file,
|
2015-03-16 14:02:41 +00:00
|
|
|
lockDaemon->dmn,
|
2013-12-11 08:07:45 +00:00
|
|
|
argv) < 0)
|
2013-12-09 06:23:28 +00:00
|
|
|
ret = VIR_LOCK_DAEMON_ERR_REEXEC;
|
Add support for re-exec() of virtlockd upon SIGUSR1
The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.
Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.
The state file contains information about all locks held and
all network services and clients currently active. An example
state document is
{
"server": {
"min_workers": 1,
"max_workers": 20,
"priority_workers": 0,
"max_clients": 20,
"keepaliveInterval": 4294967295,
"keepaliveCount": 0,
"keepaliveRequired": false,
"services": [
{
"auth": 0,
"readonly": false,
"nrequests_client_max": 1,
"socks": [
{
"fd": 6,
"errfd": -1,
"pid": 0,
"isClient": false
}
]
}
],
"clients": [
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 9,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1722,
"ownerId": 6,
"ownerName": "f18x86_64",
"ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
}
},
{
"auth": 0,
"readonly": false,
"nrequests_max": 1,
"sock": {
"fd": 10,
"errfd": -1,
"pid": 0,
"isClient": true
},
"privateData": {
"restricted": true,
"ownerPid": 1784,
"ownerId": 7,
"ownerName": "f16x86_64",
"ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
}
}
]
},
"defaultLockspace": {
"resources": [
{
"name": "/var/lib/libvirt/images/f16x86_64.raw",
"path": "/var/lib/libvirt/images/f16x86_64.raw",
"fd": 14,
"lockHeld": true,
"flags": 0,
"owners": [
1784
]
},
{
"name": "/var/lib/libvirt/images/shared.img",
"path": "/var/lib/libvirt/images/shared.img",
"fd": 12,
"lockHeld": true,
"flags": 1,
"owners": [
1722,
1784
]
},
{
"name": "/var/lib/libvirt/images/f18x86_64.img",
"path": "/var/lib/libvirt/images/f18x86_64.img",
"fd": 11,
"lockHeld": true,
"flags": 0,
"owners": [
1722
]
}
]
},
"lockspaces": [
],
"magic": "30199"
}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-07 11:13:26 +00:00
|
|
|
else
|
|
|
|
ret = 0;
|
2012-08-02 19:06:50 +00:00
|
|
|
|
2014-03-25 06:51:47 +00:00
|
|
|
cleanup:
|
2012-08-03 09:27:07 +00:00
|
|
|
virObjectUnref(lockProgram);
|
2018-01-19 14:54:00 +00:00
|
|
|
virObjectUnref(adminProgram);
|
|
|
|
virObjectUnref(lockSrv);
|
|
|
|
virObjectUnref(adminSrv);
|
2012-08-02 19:06:50 +00:00
|
|
|
virLockDaemonFree(lockDaemon);
|
|
|
|
if (statuswrite != -1) {
|
|
|
|
if (ret != 0) {
|
|
|
|
/* Tell parent of daemon what failed */
|
|
|
|
char status = ret;
|
|
|
|
while (write(statuswrite, &status, 1) == -1 &&
|
|
|
|
errno == EINTR)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
VIR_FORCE_CLOSE(statuswrite);
|
|
|
|
}
|
|
|
|
if (pid_file_fd != -1)
|
|
|
|
virPidFileReleasePath(pid_file, pid_file_fd);
|
|
|
|
VIR_FREE(pid_file);
|
|
|
|
VIR_FREE(sock_file);
|
2018-01-19 14:54:00 +00:00
|
|
|
VIR_FREE(admin_sock_file);
|
2013-12-11 08:07:45 +00:00
|
|
|
VIR_FREE(state_file);
|
2012-08-02 19:06:50 +00:00
|
|
|
VIR_FREE(run_dir);
|
2018-08-26 06:48:47 +00:00
|
|
|
virLockDaemonConfigFree(config);
|
2012-08-02 19:06:50 +00:00
|
|
|
return ret;
|
2013-12-09 06:23:28 +00:00
|
|
|
|
2014-03-25 06:51:47 +00:00
|
|
|
no_memory:
|
2013-12-09 06:23:28 +00:00
|
|
|
VIR_ERROR(_("Can't allocate memory"));
|
|
|
|
exit(EXIT_FAILURE);
|
2012-08-02 19:06:50 +00:00
|
|
|
}
|