[libvirt] [PATCH 1/2] driver config: Introduce virFirmware object
Michal Privoznik
mprivozn at redhat.com
Wed May 25 09:32:17 UTC 2016
On 18.05.2016 18:38, Jim Fehlig wrote:
> The virQEMUDriverConfig object contains lists of
> loader:nvram pairs to advertise firmwares supported by
> by the driver, and qemu_conf.c contains code to populate
> the lists, all of which is useful for other drivers too.
>
> To avoid code duplication, introduce a virFirmware object
> to encapsulate firmware details and switch the qemu driver
> to use it.
>
> Signed-off-by: Jim Fehlig <jfehlig at suse.com>
> ---
> po/POTFILES.in | 1 +
> src/Makefile.am | 1 +
> src/libvirt_private.syms | 6 ++
> src/qemu/qemu_capabilities.c | 22 +++----
> src/qemu/qemu_capabilities.h | 5 +-
> src/qemu/qemu_conf.c | 127 ++++++----------------------------------
> src/qemu/qemu_conf.h | 7 +--
> src/qemu/qemu_driver.c | 2 +-
> src/qemu/qemu_process.c | 6 +-
> src/util/virfirmware.c | 135 +++++++++++++++++++++++++++++++++++++++++++
> src/util/virfirmware.h | 51 ++++++++++++++++
> tests/domaincapstest.c | 3 +-
> 12 files changed, 235 insertions(+), 131 deletions(-)
>
> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
> index e00ddca..078a37f 100644
> --- a/src/qemu/qemu_conf.c
> +++ b/src/qemu/qemu_conf.c
> @@ -327,20 +286,22 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
> cfg->stdioLogD = true;
>
> #ifdef DEFAULT_LOADER_NVRAM
> - if (virQEMUDriverConfigLoaderNVRAMParse(cfg, DEFAULT_LOADER_NVRAM) < 0)
> + if (virFirmwareParseList(DEFAULT_LOADER_NVRAM,
> + &cfg->firmwares,
> + &cfg->nfirmwares) < 0)
> goto error;
>
> #else
> -
> - if (VIR_ALLOC_N(cfg->loader, 2) < 0 ||
> - VIR_ALLOC_N(cfg->nvram, 2) < 0)
> + if (VIR_ALLOC_N(cfg->firmwares, 2) < 0)
> + goto error;
> + cfg->nfirmwares = 2;
> + if (VIR_ALLOC(cfg->firmwares[0]) < 0 || VIR_ALLOC(cfg->firmwares[1]) < 0)
> goto error;
> - cfg->nloader = 2;
>
> - if (VIR_STRDUP(cfg->loader[0], VIR_QEMU_AAVMF_LOADER_PATH) < 0 ||
> - VIR_STRDUP(cfg->nvram[0], VIR_QEMU_AAVMF_NVRAM_PATH) < 0 ||
> - VIR_STRDUP(cfg->loader[1], VIR_QEMU_OVMF_LOADER_PATH) < 0 ||
> - VIR_STRDUP(cfg->nvram[1], VIR_QEMU_OVMF_NVRAM_PATH) < 0)
> + if (VIR_STRDUP(cfg->firwares[0]->name, VIR_QEMU_AAVMF_LOADER_PATH) < 0 ||
> + VIR_STRDUP(cfg->firmwares[0]->nvram, VIR_QEMU_AAVMF_NVRAM_PATH) < 0 ||
> + VIR_STRDUP(cfg->firwares[1]->name, VIR_QEMU_OVMF_LOADER_PATH) < 0 ||
> + VIR_STRDUP(cfg->firmwares[1]->nvram, VIR_QEMU_OVMF_NVRAM_PATH) < 0)
s/firware/firmware/g
> goto error;
> #endif
>
> @@ -397,13 +358,7 @@ static void virQEMUDriverConfigDispose(void *obj)
>
> VIR_FREE(cfg->lockManagerName);
>
> - while (cfg->nloader) {
> - VIR_FREE(cfg->loader[cfg->nloader - 1]);
> - VIR_FREE(cfg->nvram[cfg->nloader - 1]);
> - cfg->nloader--;
> - }
> - VIR_FREE(cfg->loader);
> - VIR_FREE(cfg->nvram);
> + virFirmwareFreeList(cfg->firmwares, cfg->nfirmwares);
> }
>
>
> diff --git a/src/util/virfirmware.c b/src/util/virfirmware.c
> new file mode 100644
> index 0000000..e0eb6b9
> --- /dev/null
> +++ b/src/util/virfirmware.c
> @@ -0,0 +1,135 @@
> +/*
> + * virfirmware.c: Definition of firmware object and supporting functions
> + *
> + * Copyright (C) 2016 SUSE LINUX Products GmbH, Nuernberg, Germany.
> + *
> + * 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/>.
> + *
> + * Author: Jim Fehlig <jfehlig at suse.com>
> + */
> +
> +#include <config.h>
> +
> +#include "viralloc.h"
> +#include "virerror.h"
> +#include "virfirmware.h"
> +#include "virlog.h"
> +#include "virstring.h"
> +
> +#define VIR_FROM_THIS VIR_FROM_NONE
> +
> +VIR_LOG_INIT("util.firmware");
> +
> +
> +static void
> +virFirmwareFree(virFirmwarePtr firmware)
> +{
> + if (!firmware)
> + return;
> +
> + VIR_FREE(firmware->name);
> + VIR_FREE(firmware->nvram);
> + VIR_FREE(firmware);
> +}
> +
> +
> +void
> +virFirmwareFreeList(virFirmwarePtr *firmwares, size_t nfirmwares)
> +{
> + size_t i;
> +
> + for (i = 0; i < nfirmwares; i++)
> + virFirmwareFree(firmwares[i]);
As you point out too, @firmwares needs to be freed here.
> +}
> +
> +
> +int
ACK with those nits fixed.
Michal
More information about the libvir-list
mailing list