2012-08-02 19:06:50 +00:00
|
|
|
/*
|
2014-03-07 13:38:51 +00:00
|
|
|
* lock_daemon_config.c: virtlockd config file handling
|
2012-08-02 19:06:50 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006-2012 Red Hat, Inc.
|
|
|
|
* Copyright (C) 2006 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* 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 "lock_daemon_config.h"
|
2012-12-12 16:35:35 +00:00
|
|
|
#include "virconf.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2015-03-16 14:02:41 +00:00
|
|
|
#include "rpc/virnetdaemon.h"
|
2012-08-02 19:06:50 +00:00
|
|
|
#include "configmake.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
|
|
|
#include "virutil.h"
|
2012-08-02 19:06:50 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_CONF
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("locking.lock_daemon_config");
|
|
|
|
|
2012-08-02 19:06:50 +00:00
|
|
|
int
|
|
|
|
virLockDaemonConfigFilePath(bool privileged, char **configfile)
|
|
|
|
{
|
|
|
|
if (privileged) {
|
2019-10-20 11:49:46 +00:00
|
|
|
*configfile = g_strdup(SYSCONFDIR "/libvirt/virtlockd.conf");
|
2012-08-02 19:06:50 +00:00
|
|
|
} else {
|
2019-12-19 08:42:57 +00:00
|
|
|
g_autofree char *configdir = NULL;
|
2012-08-02 19:06:50 +00:00
|
|
|
|
2019-12-19 08:43:51 +00:00
|
|
|
configdir = virGetUserConfigDirectory();
|
2012-08-02 19:06:50 +00:00
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
*configfile = g_strdup_printf("%s/virtlockd.conf", configdir);
|
2012-08-02 19:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virLockDaemonConfigPtr
|
2019-10-14 12:45:33 +00:00
|
|
|
virLockDaemonConfigNew(bool privileged G_GNUC_UNUSED)
|
2012-08-02 19:06:50 +00:00
|
|
|
{
|
|
|
|
virLockDaemonConfigPtr data;
|
|
|
|
|
2020-09-29 16:45:18 +00:00
|
|
|
data = g_new0(virLockDaemonConfig, 1);
|
2012-08-02 19:06:50 +00:00
|
|
|
|
2013-08-19 11:38:23 +00:00
|
|
|
data->max_clients = 1024;
|
2018-01-19 14:54:00 +00:00
|
|
|
data->admin_max_clients = 5000;
|
2012-08-02 19:06:50 +00:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
virLockDaemonConfigFree(virLockDaemonConfigPtr data)
|
|
|
|
{
|
|
|
|
if (!data)
|
|
|
|
return;
|
|
|
|
|
2021-02-03 19:37:59 +00:00
|
|
|
g_free(data->log_filters);
|
|
|
|
g_free(data->log_outputs);
|
2012-08-02 19:06:50 +00:00
|
|
|
|
2021-02-03 19:37:59 +00:00
|
|
|
g_free(data);
|
2012-08-02 19:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
virLockDaemonConfigLoadOptions(virLockDaemonConfigPtr data,
|
|
|
|
virConfPtr conf)
|
|
|
|
{
|
2016-07-08 10:45:37 +00:00
|
|
|
if (virConfGetValueUInt(conf, "log_level", &data->log_level) < 0)
|
|
|
|
return -1;
|
|
|
|
if (virConfGetValueString(conf, "log_filters", &data->log_filters) < 0)
|
|
|
|
return -1;
|
2016-12-13 17:33:27 +00:00
|
|
|
if (virConfGetValueString(conf, "log_outputs", &data->log_outputs) < 0)
|
2016-07-08 10:45:37 +00:00
|
|
|
return -1;
|
|
|
|
if (virConfGetValueUInt(conf, "max_clients", &data->max_clients) < 0)
|
|
|
|
return -1;
|
2018-01-19 14:54:00 +00:00
|
|
|
if (virConfGetValueUInt(conf, "admin_max_clients", &data->admin_max_clients) < 0)
|
|
|
|
return -1;
|
2012-08-02 19:06:50 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Read the config file if it exists.
|
|
|
|
* Only used in the remote case, hence the name.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virLockDaemonConfigLoadFile(virLockDaemonConfigPtr data,
|
|
|
|
const char *filename,
|
|
|
|
bool allow_missing)
|
|
|
|
{
|
2019-10-15 12:47:50 +00:00
|
|
|
g_autoptr(virConf) conf = NULL;
|
2012-08-02 19:06:50 +00:00
|
|
|
|
|
|
|
if (allow_missing &&
|
|
|
|
access(filename, R_OK) == -1 &&
|
|
|
|
errno == ENOENT)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
conf = virConfReadFile(filename, 0);
|
|
|
|
if (!conf)
|
|
|
|
return -1;
|
|
|
|
|
2019-09-09 15:56:26 +00:00
|
|
|
return virLockDaemonConfigLoadOptions(data, conf);
|
2012-08-02 19:06:50 +00:00
|
|
|
}
|