2017-03-11 16:19:03 +00:00
|
|
|
/*
|
|
|
|
* bhyve_conf.c: bhyve config file
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Roman Bogorodskiy
|
|
|
|
*
|
|
|
|
* 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 "viralloc.h"
|
|
|
|
#include "virlog.h"
|
|
|
|
#include "virstring.h"
|
|
|
|
#include "bhyve_conf.h"
|
2019-01-17 15:07:20 +00:00
|
|
|
#include "bhyve_domain.h"
|
2017-03-11 16:19:03 +00:00
|
|
|
#include "configmake.h"
|
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_BHYVE
|
|
|
|
|
|
|
|
VIR_LOG_INIT("bhyve.bhyve_conf");
|
|
|
|
|
|
|
|
static virClassPtr virBhyveDriverConfigClass;
|
|
|
|
static void virBhyveDriverConfigDispose(void *obj);
|
|
|
|
|
|
|
|
static int virBhyveConfigOnceInit(void)
|
|
|
|
{
|
2018-09-13 08:55:20 +00:00
|
|
|
if (!VIR_CLASS_NEW(virBhyveDriverConfig, virClassForObject()))
|
|
|
|
return -1;
|
2017-03-11 16:19:03 +00:00
|
|
|
|
2018-09-13 08:55:20 +00:00
|
|
|
return 0;
|
2017-03-11 16:19:03 +00:00
|
|
|
}
|
|
|
|
|
2019-01-20 17:23:29 +00:00
|
|
|
VIR_ONCE_GLOBAL_INIT(virBhyveConfig);
|
2017-03-11 16:19:03 +00:00
|
|
|
|
|
|
|
virBhyveDriverConfigPtr
|
|
|
|
virBhyveDriverConfigNew(void)
|
|
|
|
{
|
|
|
|
virBhyveDriverConfigPtr cfg;
|
|
|
|
|
|
|
|
if (virBhyveConfigInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(cfg = virObjectNew(virBhyveDriverConfigClass)))
|
|
|
|
return NULL;
|
|
|
|
|
2019-10-20 11:49:46 +00:00
|
|
|
cfg->firmwareDir = g_strdup(DATADIR "/uefi-firmware");
|
2017-03-11 16:19:03 +00:00
|
|
|
|
|
|
|
return cfg;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
virBhyveLoadDriverConfig(virBhyveDriverConfigPtr cfg,
|
|
|
|
const char *filename)
|
|
|
|
{
|
2019-10-15 12:47:50 +00:00
|
|
|
g_autoptr(virConf) conf = NULL;
|
2017-03-11 16:19:03 +00:00
|
|
|
|
|
|
|
if (access(filename, R_OK) == -1) {
|
|
|
|
VIR_INFO("Could not read bhyve config file %s", filename);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(conf = virConfReadFile(filename, 0)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (virConfGetValueString(conf, "firmware_dir",
|
|
|
|
&cfg->firmwareDir) < 0)
|
2019-09-09 15:56:26 +00:00
|
|
|
return -1;
|
2017-03-11 16:19:03 +00:00
|
|
|
|
2019-09-09 15:56:26 +00:00
|
|
|
return 0;
|
2017-03-11 16:19:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virBhyveDriverConfigPtr
|
|
|
|
virBhyveDriverGetConfig(bhyveConnPtr driver)
|
|
|
|
{
|
|
|
|
virBhyveDriverConfigPtr cfg;
|
|
|
|
bhyveDriverLock(driver);
|
|
|
|
cfg = virObjectRef(driver->config);
|
|
|
|
bhyveDriverUnlock(driver);
|
|
|
|
return cfg;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
virBhyveDriverConfigDispose(void *obj)
|
|
|
|
{
|
|
|
|
virBhyveDriverConfigPtr cfg = obj;
|
|
|
|
|
|
|
|
VIR_FREE(cfg->firmwareDir);
|
|
|
|
}
|
2019-01-17 15:07:20 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
bhyveDomainCmdlineDefFree(bhyveDomainCmdlineDefPtr def)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!def)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < def->num_args; i++)
|
|
|
|
VIR_FREE(def->args[i]);
|
|
|
|
|
|
|
|
VIR_FREE(def->args);
|
|
|
|
VIR_FREE(def);
|
|
|
|
}
|