[libvirt] [PATCH 0/3] leave cgroup value checking to kernel
by Chen Hanxiao
From: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
Since 2.6.39, kernel changed the minimum weight of device blkio
while libvirt hard-coded the value range checking.
So we should leave the job of checking to kernel.
Chen Hanxiao (3):
[libvirt]docs: change the minimum weight description for blkio
[libvirt]cgroup: show error when EINVAL caught
[libvirt]cgroup: leave value checking to kernel
docs/formatdomain.html.in | 6 ++++--
src/util/vircgroup.c | 26 +++++++++++---------------
tools/virsh.pod | 11 ++++++-----
3 files changed, 21 insertions(+), 22 deletions(-)
--
1.8.2.1
11 years, 2 months
[libvirt] [PATCH v3]LXC: Helper function for checking permission of dir when userns enabled
by Chen Hanxiao
From: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
If we enable userns, the process with uid/gid in idmap
should have enough permission to access dir we provided
for containers.
Currently, the debug log is very implicit
or misleading sometimes.
This patch will help clarify this for us
when using debug log or virsh.
v2: syntax-check clean
v3: reliable method for checking permission of dir
Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
src/lxc/lxc_container.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 88 insertions(+)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 8abaea0..9a05e30 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -110,6 +110,13 @@ struct __lxc_child_argv {
int handshakefd;
};
+typedef struct __lxc_userns_DirPermCheck_argv lxc_userns_DirPermCheck_argv_t;
+struct __lxc_userns_DirPermCheck_argv {
+ uid_t uid;
+ gid_t gid;
+ virDomainDefPtr vmDef;
+};
+
static int lxcContainerMountFSBlock(virDomainFSDefPtr fs,
const char *srcprefix);
@@ -1829,6 +1836,84 @@ lxcNeedNetworkNamespace(virDomainDefPtr def)
return false;
}
+static
+int lxcContainerCheckDirPermissionChild(void *argv)
+{
+ size_t i;
+ lxc_userns_DirPermCheck_argv_t *args = argv;
+ uid_t uid = args->uid;
+ uid_t gid = args->gid;
+ virDomainDefPtr vmDef = args->vmDef;
+ char *path;
+
+ if (virSetUIDGID(uid, gid, NULL, 0) < 0) {
+ virReportSystemError(errno, "%s",
+ _("setuid or setgid failed"));
+ _exit(-1);
+ }
+
+ for (i = 0; i < vmDef->nfss; i++) {
+ path = vmDef->fss[i]->src;
+ if (access(path, R_OK) || access(path, W_OK) || virFileIsExecutable(path)) {
+ VIR_DEBUG("Src dir '%s' does not belong to uid/gid: %d/%d",
+ vmDef->fss[i]->src, uid, gid);
+ _exit(-1);
+ }
+ }
+
+ _exit(0);
+}
+
+/*
+ * Helper function for helping check
+ * whether we have enough privilege
+ * to operate the source dir when userns enabled
+ * @vmDef: pointer to vm definition structure
+ * Returns 0 on success or -1 in case of error
+ */
+static int
+lxcContainerCheckDirPermission(virDomainDefPtr vmDef)
+{
+ uid_t uid;
+ gid_t gid;
+ int cpid = 0;
+ int status;
+ char *childStack;
+ char *stack;
+ int flags = SIGCHLD;
+
+ uid = vmDef->idmap.uidmap[0].target;
+ gid = vmDef->idmap.gidmap[0].target;
+
+ lxc_userns_DirPermCheck_argv_t args = {
+ .uid = uid,
+ .gid = gid,
+ .vmDef = vmDef
+ };
+
+ if (VIR_ALLOC_N(stack, getpagesize() * 4) < 0)
+ return -1;
+
+ childStack = stack + (getpagesize() * 4);
+ cpid = clone(lxcContainerCheckDirPermissionChild, childStack, flags, &args);
+ VIR_FREE(stack);
+ if (cpid < 0) {
+ virReportSystemError(errno, "%s",
+ _("Unable to clone to check permission of directory"));
+ return -1;
+ } else if (virProcessWait(cpid, &status) < 0) {
+ return -1;
+ }
+
+ if (WEXITSTATUS(status) != 0) {
+ virReportSystemError(errno, "%s",
+ _("Check the permission of source dir provided for container"));
+ return -1;
+ }
+
+ return 0;
+}
+
/**
* lxcContainerStart:
* @def: pointer to virtual machine structure
@@ -1880,6 +1965,9 @@ int lxcContainerStart(virDomainDefPtr def,
if (userns_supported()) {
VIR_DEBUG("Enable user namespace");
cflags |= CLONE_NEWUSER;
+ if (lxcContainerCheckDirPermission(def) < 0) {
+ return -1;
+ }
} else {
virReportSystemError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Kernel doesn't support user namespace"));
--
1.8.2.1
11 years, 2 months
Re: [libvirt] [Qemu-devel] [RFC PATCH] spapr-vty: workaround "reg" property for old kernels
by Anthony Liguori
On Tue, Oct 15, 2013 at 3:47 PM, Alexey Kardashevskiy <aik(a)ozlabs.ru> wrote:
> On 10/16/2013 02:03 AM, Alexander Graf wrote:
>> On 10/15/2013 10:50 AM, Alexey Kardashevskiy wrote:
>>> Old kernels (< 3.1) handle hvcX devices different in different parts.
>>> Sometime the kernel assumes that the hvc device numbers start from zero
>>> and if there is just one hvc, then it is hvc0.
>>>
>>> However kernel's add_preferred_console() uses the very last byte of
>>> the VTY's "reg" property as an hvc number so it might end up with something
>>> different than hvc.
>>>
>>> The problem appears on SLES11SP3 and RHEL6. If to run QEMU without
>>> -nodefaults, then the default VTY is created first on a VIO bus and gets
>>> reg==0x71000000 so it will be hvc0 and everything will be fine.
>>> If to run QEMU with:
>>> -nodefaults \
>>> -chardev "socket,id=char1,host=localhost,port=8001,server,telnet,mux=on" \
>>> -device "spapr-vty,chardev=char1" \
>>> -mon "chardev=char1,mode=readline,id=mon1" \
>>>
>>> then the exactly the same config is expected but in this case spapr-vty
>>> gets reg==0x71000001 and therefore it becomes hvc1 and lots of debug
>>> output is missing. SLES11SP3 does not even boot as /dev/console is
>>> redirected to /dev/hvc0 which is dead.
>>>
>>> The issue can be solved by manual selection of VTY's "reg" property to
>>> have last byte equal to zero.
>>>
>>> The alternative would be to use separate "reg" property counter for
>>> automatic "reg" property generation and this is what the patch does.
>>>
>>> Signed-off-by: Alexey Kardashevskiy<aik(a)ozlabs.ru>
>>> ---
>>>
>>> Since libvirt uses "-nodefault" a lot and in this case "spapr-nvram" gets
>>> created first and gets reg=0x71000000, we cannot just ignore this. Also,
>>> it does not seem an option to require libvirt users to specify spapr-vty
>>> "reg" property every time.
>>>
>>> Can anyone think of a simpler solutionu? Thanks.
>>>
>>>
>>> ---
>>> hw/ppc/spapr_vio.c | 7 ++++++-
>>> include/hw/ppc/spapr_vio.h | 1 +
>>> 2 files changed, 7 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c
>>> index a6a0a51..2d56950 100644
>>> --- a/hw/ppc/spapr_vio.c
>>> +++ b/hw/ppc/spapr_vio.c
>>> @@ -438,7 +438,11 @@ static int spapr_vio_busdev_init(DeviceState *qdev)
>>> VIOsPAPRBus *bus = DO_UPCAST(VIOsPAPRBus, bus,
>>> dev->qdev.parent_bus);
>>>
>>> do {
>>> - dev->reg = bus->next_reg++;
>>> + if (!object_dynamic_cast(OBJECT(qdev), "spapr-vty")) {
>>> + dev->reg = bus->next_reg++;
>>> + } else {
>>> + dev->reg = bus->next_vty_reg++;
>>> + }
>>> } while (reg_conflict(dev));
>>> }
>>>
>>> @@ -501,6 +505,7 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
>>> qbus = qbus_create(TYPE_SPAPR_VIO_BUS, dev, "spapr-vio");
>>> bus = DO_UPCAST(VIOsPAPRBus, bus, qbus);
>>> bus->next_reg = 0x71000000;
>>> + bus->next_vty_reg = 0x71000100;
>>
>> This breaks as soon as you pass in more than 0x100 devices that are non-vty
>> into the guest, no?
>
> Will we ever have this much? Ah, anyway, this code already checks if the
> address is taken and fails if it is. And there is still a possibility to
> assign addresses manually.
>
>> The reg property really describes the virtual slot a device is in.
>
> We use 0x71000000. I saw xmls from libvirt where VTY's reg is 0x30000000.
> Whether it is a slot or not, QEMU/SLOF/Kernel does not seem to care about
> absolute value :)
>
>> Couldn't
>> we do that allocation explicitly and push it from libvirt, just like we do
>> it with the slots for PCI?
Yes, this is the only solution. We make no promises with respect to
argument ordering. libvirt needs to explicitly specify reg values to
create a stable device tree (just like it does with PCI).
Regards,
Anthony Liguori
>
> That is the other possibility, yes. But in this case "-nodefaults" must not
> create spapr-nvram automatically and if we do that, we'll break existing
> setups.
>
>
>>
>>
>> Alex
>>
>>
>>>
>>> /* hcall-vio */
>>> spapr_register_hypercall(H_VIO_SIGNAL, h_vio_signal);
>>> diff --git a/include/hw/ppc/spapr_vio.h b/include/hw/ppc/spapr_vio.h
>>> index d8b3b03..3a92d9e 100644
>>> --- a/include/hw/ppc/spapr_vio.h
>>> +++ b/include/hw/ppc/spapr_vio.h
>>> @@ -73,6 +73,7 @@ struct VIOsPAPRDevice {
>>> struct VIOsPAPRBus {
>>> BusState bus;
>>> uint32_t next_reg;
>>> + uint32_t next_vty_reg;
>>> int (*init)(VIOsPAPRDevice *dev);
>>> int (*devnode)(VIOsPAPRDevice *dev, void *fdt, int node_off);
>>> };
>>
>
>
> --
> Alexey
>
11 years, 2 months
[libvirt] [PATCHv2] Ignore thin pool LVM devices.
by Dusty Mabe
This should resolve:
https://bugzilla.redhat.com/show_bug.cgi?id=924672
For BZ 924672 the problem stems from the fact that thin pool logical
volume devices show up in /sbin/lvs output just like normal logical
volumes do. Libvirt incorrectly assumes they are just normal logical
volumes and that they will have a corresponding /dev/vgname/lvname
device that has been created by udev and tries to use this device.
To illustrate here is an example of the /dev/vgname/ directory and
the lvs output for a normal lv, thin lv, and thin pool:
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
lv vgguests -wi-a---- 1.00g
pool vgguests twi-a-tz- 11.00g 0.00
thinlv vgguests Vwi-a-tz- 1.00g pool 0.00
total 0
lrwxrwxrwx. 1 root root 7 Oct 8 19:35 lv -> ../dm-7
lrwxrwxrwx. 1 root root 7 Oct 8 19:37 thinlv -> ../dm-6
This patch modifies virStorageBackendLogicalMakeVol() to ignore thin pool
devices.
---
src/storage/storage_backend_logical.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index a1a37a1..81ee4a4 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -85,6 +85,14 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool,
if (attrs[4] != 'a')
return 0;
+ /*
+ * Skip thin pools(t). These show up in normal lvs output
+ * but do not have a corresponding /dev/$vg/$lv device that
+ * is created by udev. This breaks assumptions in later code.
+ */
+ if (attrs[0] == 't')
+ return 0;
+
/* See if we're only looking for a specific volume */
if (data != NULL) {
vol = data;
--
1.8.3.1
11 years, 2 months
[libvirt] [libvirt-sandbox PATCH] Add filter support.
by Ian Main
This patch adds two new classes, filterref and filterref-parameter.
Network interfaces can now have an associated filter reference with any
number of filterref parameters. Also added filter= option to
virt-sandbox tool.
---
libvirt-sandbox/Makefile.am | 4 +
.../libvirt-sandbox-builder-container.c | 37 +++-
libvirt-sandbox/libvirt-sandbox-builder-machine.c | 36 ++++
...rt-sandbox-config-network-filterref-parameter.c | 205 ++++++++++++++++++++
...rt-sandbox-config-network-filterref-parameter.h | 75 ++++++++
.../libvirt-sandbox-config-network-filterref.c | 209 +++++++++++++++++++++
.../libvirt-sandbox-config-network-filterref.h | 75 ++++++++
libvirt-sandbox/libvirt-sandbox-config-network.c | 33 ++++
libvirt-sandbox/libvirt-sandbox-config-network.h | 4 +
libvirt-sandbox/libvirt-sandbox-config.c | 39 ++++
libvirt-sandbox/libvirt-sandbox.h | 2 +
libvirt-sandbox/libvirt-sandbox.sym | 14 ++
12 files changed, 732 insertions(+), 1 deletion(-)
create mode 100644 libvirt-sandbox/libvirt-sandbox-config-network-filterref-parameter.c
create mode 100644 libvirt-sandbox/libvirt-sandbox-config-network-filterref-parameter.h
create mode 100644 libvirt-sandbox/libvirt-sandbox-config-network-filterref.c
create mode 100644 libvirt-sandbox/libvirt-sandbox-config-network-filterref.h
diff --git a/libvirt-sandbox/Makefile.am b/libvirt-sandbox/Makefile.am
index 0882490..4de8766 100644
--- a/libvirt-sandbox/Makefile.am
+++ b/libvirt-sandbox/Makefile.am
@@ -57,6 +57,8 @@ SANDBOX_HEADER_FILES = \
libvirt-sandbox-config.h \
libvirt-sandbox-config-network.h \
libvirt-sandbox-config-network-address.h \
+ libvirt-sandbox-config-network-filterref.h \
+ libvirt-sandbox-config-network-filterref-parameter.h \
libvirt-sandbox-config-network-route.h \
libvirt-sandbox-config-mount.h \
libvirt-sandbox-config-mount-file.h \
@@ -85,6 +87,8 @@ SANDBOX_SOURCE_FILES = \
libvirt-sandbox-config.c \
libvirt-sandbox-config-network.c \
libvirt-sandbox-config-network-address.c \
+ libvirt-sandbox-config-network-filterref.c \
+ libvirt-sandbox-config-network-filterref-parameter.c \
libvirt-sandbox-config-network-route.c \
libvirt-sandbox-config-mount.c \
libvirt-sandbox-config-mount-file.c \
diff --git a/libvirt-sandbox/libvirt-sandbox-builder-container.c b/libvirt-sandbox/libvirt-sandbox-builder-container.c
index 43ee5ef..193b777 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder-container.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder-container.c
@@ -319,11 +319,12 @@ static gboolean gvir_sandbox_builder_container_construct_devices(GVirSandboxBuil
g_list_foreach(mounts, (GFunc)g_object_unref, NULL);
g_list_free(mounts);
-
tmp = networks = gvir_sandbox_config_get_networks(config);
while (tmp) {
const gchar *source, *mac;
GVirSandboxConfigNetwork *network = GVIR_SANDBOX_CONFIG_NETWORK(tmp->data);
+ GVirSandboxConfigNetworkFilterref *filterref;
+ GVirConfigDomainInterfaceFilterref *glib_fref;
iface = gvir_config_domain_interface_network_new();
source = gvir_sandbox_config_network_get_source(network);
@@ -339,6 +340,40 @@ static gboolean gvir_sandbox_builder_container_construct_devices(GVirSandboxBuil
gvir_config_domain_add_device(domain,
GVIR_CONFIG_DOMAIN_DEVICE(iface));
+
+ filterref = gvir_sandbox_config_network_get_filterref(network);
+ if (filterref) {
+ GList *param_iter, *parameters;
+ const gchar *fref_name = gvir_sandbox_config_network_filterref_get_filter(filterref);
+ glib_fref = gvir_config_domain_interface_filterref_new();
+ gvir_config_domain_interface_filterref_set_filter(glib_fref, fref_name);
+ param_iter = parameters = gvir_sandbox_config_network_filterref_get_parameters(filterref);
+ while (param_iter) {
+ const gchar *name;
+ const gchar *value;
+ GVirSandboxConfigNetworkFilterrefParameter *param = GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF_PARAMETER(param_iter->data);
+ GVirConfigDomainInterfaceFilterrefParameter *glib_param;
+
+ name = gvir_sandbox_config_network_filterref_parameter_get_name(param);
+ value = gvir_sandbox_config_network_filterref_parameter_get_value(param);
+
+ glib_param = gvir_config_domain_interface_filterref_parameter_new();
+ gvir_config_domain_interface_filterref_parameter_set_name(glib_param, name);
+ gvir_config_domain_interface_filterref_parameter_set_value(glib_param, value);
+
+ gvir_config_domain_interface_filterref_add_parameter(glib_fref, glib_param);
+ g_object_unref(glib_param);
+
+ param_iter = param_iter->next;
+ }
+
+ g_list_foreach(parameters, (GFunc)g_object_unref, NULL);
+ g_list_free(parameters);
+
+ gvir_config_domain_interface_set_filterref(GVIR_CONFIG_DOMAIN_INTERFACE(iface), glib_fref);
+ g_object_unref(glib_fref);
+ }
+
g_object_unref(iface);
tmp = tmp->next;
diff --git a/libvirt-sandbox/libvirt-sandbox-builder-machine.c b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
index a8c5d8c..072bbbe 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder-machine.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
@@ -577,6 +577,8 @@ static gboolean gvir_sandbox_builder_machine_construct_devices(GVirSandboxBuilde
while (tmp) {
const gchar *source, *mac;
GVirSandboxConfigNetwork *network = GVIR_SANDBOX_CONFIG_NETWORK(tmp->data);
+ GVirSandboxConfigNetworkFilterref *filterref;
+ GVirConfigDomainInterfaceFilterref *glib_fref;
source = gvir_sandbox_config_network_get_source(network);
if (source) {
@@ -596,6 +598,40 @@ static gboolean gvir_sandbox_builder_machine_construct_devices(GVirSandboxBuilde
gvir_config_domain_add_device(domain,
GVIR_CONFIG_DOMAIN_DEVICE(iface));
+
+ filterref = gvir_sandbox_config_network_get_filterref(network);
+ if (filterref) {
+ GList *param_iter, *parameters;
+ const gchar *fref_name = gvir_sandbox_config_network_filterref_get_filter(filterref);
+ glib_fref = gvir_config_domain_interface_filterref_new();
+ gvir_config_domain_interface_filterref_set_filter(glib_fref, fref_name);
+ param_iter = parameters = gvir_sandbox_config_network_filterref_get_parameters(filterref);
+ while (param_iter) {
+ const gchar *name;
+ const gchar *value;
+ GVirSandboxConfigNetworkFilterrefParameter *param = GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF_PARAMETER(param_iter->data);
+ GVirConfigDomainInterfaceFilterrefParameter *glib_param;
+
+ name = gvir_sandbox_config_network_filterref_parameter_get_name(param);
+ value = gvir_sandbox_config_network_filterref_parameter_get_value(param);
+
+ glib_param = gvir_config_domain_interface_filterref_parameter_new();
+ gvir_config_domain_interface_filterref_parameter_set_name(glib_param, name);
+ gvir_config_domain_interface_filterref_parameter_set_value(glib_param, value);
+
+ gvir_config_domain_interface_filterref_add_parameter(glib_fref, glib_param);
+ g_object_unref(glib_param);
+
+ param_iter = param_iter->next;
+ }
+
+ g_list_foreach(parameters, (GFunc)g_object_unref, NULL);
+ g_list_free(parameters);
+
+ gvir_config_domain_interface_set_filterref(iface, glib_fref);
+ g_object_unref(glib_fref);
+ }
+
g_object_unref(iface);
tmp = tmp->next;
diff --git a/libvirt-sandbox/libvirt-sandbox-config-network-filterref-parameter.c b/libvirt-sandbox/libvirt-sandbox-config-network-filterref-parameter.c
new file mode 100644
index 0000000..c1ed941
--- /dev/null
+++ b/libvirt-sandbox/libvirt-sandbox-config-network-filterref-parameter.c
@@ -0,0 +1,205 @@
+/*
+ * libvirt-sandbox-config-network-filterref-parameter.c: libvirt sandbox configuration
+ *
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Ian Main <imain(a)redhat.com>
+ */
+
+#include <config.h>
+#include <string.h>
+
+#include "libvirt-sandbox/libvirt-sandbox.h"
+
+/**
+ * SECTION: libvirt-sandbox-config-network-filterref-parameter
+ * @short_description: Set parameters for a filter reference.
+ * @include: libvirt-sandbox/libvirt-sandbox.h
+ *
+ * Provides an object to store filter parameter name and value.
+ *
+ * The GVirSandboxConfigNetworkFilterrefParameter object stores a
+ * name and value required to set a single parameter of a filter reference.
+ */
+
+#define GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF_PARAMETER_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF_PARAMETER, GVirSandboxConfigNetworkFilterrefParameterPrivate))
+
+struct _GVirSandboxConfigNetworkFilterrefParameterPrivate
+{
+ gchar *name;
+ gchar *value;
+};
+
+G_DEFINE_TYPE(GVirSandboxConfigNetworkFilterrefParameter, gvir_sandbox_config_network_filterref_parameter, G_TYPE_OBJECT);
+
+
+enum {
+ PROP_0,
+ PROP_NAME,
+ PROP_VALUE,
+};
+
+enum {
+ LAST_SIGNAL
+};
+
+//static gint signals[LAST_SIGNAL];
+
+
+static void gvir_sandbox_config_network_filterref_parameter_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GVirSandboxConfigNetworkFilterrefParameter *config = GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF_PARAMETER(object);
+ GVirSandboxConfigNetworkFilterrefParameterPrivate *priv = config->priv;
+
+ switch (prop_id) {
+ case PROP_NAME:
+ g_value_set_string(value, priv->name);
+ break;
+
+ case PROP_VALUE:
+ g_value_set_string(value, priv->value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ }
+}
+
+
+static void gvir_sandbox_config_network_filterref_parameter_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GVirSandboxConfigNetworkFilterrefParameter *config = GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF_PARAMETER(object);
+ GVirSandboxConfigNetworkFilterrefParameterPrivate *priv = config->priv;
+
+ switch (prop_id) {
+ case PROP_NAME:
+ g_free(priv->name);
+ priv->name = g_value_dup_string(value);
+ break;
+
+ case PROP_VALUE:
+ g_free(priv->value);
+ priv->value = g_value_dup_string(value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ }
+}
+
+
+static void gvir_sandbox_config_network_filterref_parameter_finalize(GObject *object)
+{
+ GVirSandboxConfigNetworkFilterrefParameter *config = GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF_PARAMETER(object);
+ GVirSandboxConfigNetworkFilterrefParameterPrivate *priv = config->priv;
+
+ g_free(priv->name);
+ g_free(priv->value);
+
+ G_OBJECT_CLASS(gvir_sandbox_config_network_filterref_parameter_parent_class)->finalize(object);
+}
+
+
+static void gvir_sandbox_config_network_filterref_parameter_class_init(GVirSandboxConfigNetworkFilterrefParameterClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ object_class->finalize = gvir_sandbox_config_network_filterref_parameter_finalize;
+ object_class->get_property = gvir_sandbox_config_network_filterref_parameter_get_property;
+ object_class->set_property = gvir_sandbox_config_network_filterref_parameter_set_property;
+
+ g_object_class_install_property(object_class,
+ PROP_NAME,
+ g_param_spec_string("name",
+ "Name",
+ "Name of parameter",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_WRITABLE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+
+ g_object_class_install_property(object_class,
+ PROP_VALUE,
+ g_param_spec_string("value",
+ "Value",
+ "Value of parameter",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_WRITABLE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+
+ g_type_class_add_private(klass, sizeof(GVirSandboxConfigNetworkFilterrefParameterPrivate));
+}
+
+
+static void gvir_sandbox_config_network_filterref_parameter_init(GVirSandboxConfigNetworkFilterrefParameter *param)
+{
+ param->priv = GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF_PARAMETER_GET_PRIVATE(param);
+}
+
+
+/**
+ * gvir_sandbox_config_network_filterref_parameter_new:
+ *
+ * Create a new network config with DHCP enabled
+ *
+ * Returns: (transfer full): a new sandbox network object
+ */
+GVirSandboxConfigNetworkFilterrefParameter *gvir_sandbox_config_network_filterref_parameter_new(void)
+{
+ return GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF_PARAMETER(g_object_new(GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF_PARAMETER,
+ NULL));
+}
+
+void gvir_sandbox_config_network_filterref_parameter_set_name(GVirSandboxConfigNetworkFilterrefParameter *param,
+ const gchar *name)
+{
+ GVirSandboxConfigNetworkFilterrefParameterPrivate *priv = param->priv;
+ g_free(priv->name);
+ priv->name = g_strdup(name);
+}
+
+const gchar *gvir_sandbox_config_network_filterref_parameter_get_name(GVirSandboxConfigNetworkFilterrefParameter *param)
+{
+ GVirSandboxConfigNetworkFilterrefParameterPrivate *priv = param->priv;
+ return priv->name;
+}
+
+void gvir_sandbox_config_network_filterref_parameter_set_value(GVirSandboxConfigNetworkFilterrefParameter *param,
+ const gchar *value)
+{
+ GVirSandboxConfigNetworkFilterrefParameterPrivate *priv = param->priv;
+ g_free(priv->value);
+ priv->value = g_strdup(value);
+}
+
+const gchar *gvir_sandbox_config_network_filterref_parameter_get_value(GVirSandboxConfigNetworkFilterrefParameter *param)
+{
+ GVirSandboxConfigNetworkFilterrefParameterPrivate *priv = param->priv;
+ return priv->value;
+}
diff --git a/libvirt-sandbox/libvirt-sandbox-config-network-filterref-parameter.h b/libvirt-sandbox/libvirt-sandbox-config-network-filterref-parameter.h
new file mode 100644
index 0000000..f40895f
--- /dev/null
+++ b/libvirt-sandbox/libvirt-sandbox-config-network-filterref-parameter.h
@@ -0,0 +1,75 @@
+/*
+ * libvirt-sandbox-config-network-filterref-parameter.h: libvirt sandbox configuration
+ *
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Ian Main <imain(a)redhat.com>
+ */
+
+#if !defined(__LIBVIRT_SANDBOX_H__) && !defined(LIBVIRT_SANDBOX_BUILD)
+#error "Only <libvirt-sandbox/libvirt-sandbox.h> can be included directly."
+#endif
+
+#ifndef __LIBVIRT_SANDBOX_CONFIG_NETWORK_FILTERREF_PARAMETER_H__
+#define __LIBVIRT_SANDBOX_CONFIG_NETWORK_FILTERREF_PARAMETER_H__
+
+G_BEGIN_DECLS
+
+#define GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF_PARAMETER (gvir_sandbox_config_network_filterref_parameter_get_type ())
+#define GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF_PARAMETER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF_PARAMETER, GVirSandboxConfigNetworkFilterrefParameter))
+#define GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF_PARAMETER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF_PARAMETER, GVirSandboxConfigNetworkFilterrefParameterClass))
+#define GVIR_SANDBOX_IS_CONFIG_NETWORK_FILTERREF_PARAMETER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF_PARAMETER))
+#define GVIR_SANDBOX_IS_CONFIG_NETWORK_FILTERREF_PARAMETER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF_PARAMETER))
+#define GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF_PARAMETER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF_PARAMETER, GVirSandboxConfigNetworkFilterrefParameterClass))
+
+#define GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF_PARAMETER_HANDLE (gvir_sandbox_config_network_filterref_parameter_handle_get_type ())
+
+typedef struct _GVirSandboxConfigNetworkFilterrefParameter GVirSandboxConfigNetworkFilterrefParameter;
+typedef struct _GVirSandboxConfigNetworkFilterrefParameterPrivate GVirSandboxConfigNetworkFilterrefParameterPrivate;
+typedef struct _GVirSandboxConfigNetworkFilterrefParameterClass GVirSandboxConfigNetworkFilterrefParameterClass;
+
+struct _GVirSandboxConfigNetworkFilterrefParameter
+{
+ GObject parent;
+
+ GVirSandboxConfigNetworkFilterrefParameterPrivate *priv;
+
+ /* Do not add fields to this struct */
+};
+
+struct _GVirSandboxConfigNetworkFilterrefParameterClass
+{
+ GObjectClass parent_class;
+
+ gpointer padding[LIBVIRT_SANDBOX_CLASS_PADDING];
+};
+
+GType gvir_sandbox_config_network_filterref_parameter_get_type(void);
+
+GVirSandboxConfigNetworkFilterrefParameter *gvir_sandbox_config_network_filterref_parameter_new(void);
+
+void gvir_sandbox_config_network_filterref_parameter_set_name(GVirSandboxConfigNetworkFilterrefParameter *param,
+ const gchar *name);
+const gchar *gvir_sandbox_config_network_filterref_parameter_get_name(GVirSandboxConfigNetworkFilterrefParameter *param);
+
+void gvir_sandbox_config_network_filterref_parameter_set_value(GVirSandboxConfigNetworkFilterrefParameter *param,
+ const gchar *value);
+const gchar *gvir_sandbox_config_network_filterref_parameter_get_value(GVirSandboxConfigNetworkFilterrefParameter *param);
+
+G_END_DECLS
+
+#endif /* __LIBVIRT_SANDBOX_CONFIG_NETWORK_FILTERREF_PARAMETER_H__ */
diff --git a/libvirt-sandbox/libvirt-sandbox-config-network-filterref.c b/libvirt-sandbox/libvirt-sandbox-config-network-filterref.c
new file mode 100644
index 0000000..ee8ff89
--- /dev/null
+++ b/libvirt-sandbox/libvirt-sandbox-config-network-filterref.c
@@ -0,0 +1,209 @@
+/*
+ * libvirt-sandbox-config-mount.c: libvirt sandbox configuration
+ *
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Ian Main <imain(a)redhat.com>
+ */
+
+#include <config.h>
+#include <string.h>
+
+#include "libvirt-sandbox/libvirt-sandbox.h"
+
+/**
+ * SECTION: libvirt-sandbox-config-network-filterref
+ * @short_description: Add a network filter to a network interface.
+ * @include: libvirt-sandbox/libvirt-sandbox.h
+ * @see_aloso: #GVirSandboxConfig
+ *
+ * Provides an object to store the name of the filter reference.
+ *
+ * The GVirSandboxConfigNetworkFilterref object stores the name of the filter
+ * references associated with a network interface.
+ */
+
+#define GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF, GVirSandboxConfigNetworkFilterrefPrivate))
+
+struct _GVirSandboxConfigNetworkFilterrefPrivate
+{
+ gchar *filter;
+ GList *parameters;
+};
+
+G_DEFINE_TYPE(GVirSandboxConfigNetworkFilterref, gvir_sandbox_config_network_filterref, G_TYPE_OBJECT);
+
+
+enum {
+ PROP_0,
+ PROP_FILTER
+};
+
+enum {
+ LAST_SIGNAL
+};
+
+//static gint signals[LAST_SIGNAL];
+
+static void gvir_sandbox_config_network_filterref_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GVirSandboxConfigNetworkFilterref *config = GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF(object);
+ GVirSandboxConfigNetworkFilterrefPrivate *priv = config->priv;
+
+ switch (prop_id) {
+ case PROP_FILTER:
+ g_value_set_string(value, priv->filter);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ }
+}
+
+
+static void gvir_sandbox_config_network_filterref_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GVirSandboxConfigNetworkFilterref *config = GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF(object);
+ GVirSandboxConfigNetworkFilterrefPrivate *priv = config->priv;
+
+ switch (prop_id) {
+ case PROP_FILTER:
+ g_free(priv->filter);
+ priv->filter = g_value_dup_string(value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ }
+}
+
+
+
+static void gvir_sandbox_config_network_filterref_finalize(GObject *object)
+{
+ GVirSandboxConfigNetworkFilterref *config = GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF(object);
+ GVirSandboxConfigNetworkFilterrefPrivate *priv = config->priv;
+
+ g_free(priv->filter);
+ g_list_foreach(priv->parameters, (GFunc)g_object_unref, NULL);
+
+ G_OBJECT_CLASS(gvir_sandbox_config_network_filterref_parent_class)->finalize(object);
+}
+
+
+static void gvir_sandbox_config_network_filterref_class_init(GVirSandboxConfigNetworkFilterrefClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ object_class->finalize = gvir_sandbox_config_network_filterref_finalize;
+ object_class->get_property = gvir_sandbox_config_network_filterref_get_property;
+ object_class->set_property = gvir_sandbox_config_network_filterref_set_property;
+
+ g_object_class_install_property(object_class,
+ PROP_FILTER,
+ g_param_spec_string("filter",
+ "Filter name",
+ "The filter reference name",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+
+ g_type_class_add_private(klass, sizeof(GVirSandboxConfigNetworkFilterrefPrivate));
+}
+
+/**
+ * gvir_sandbox_config_network_filterref_new:
+ *
+ * Create a new network filterref config.
+ *
+ * Returns: (transfer full): a new sandbox network_filterref object
+ */
+GVirSandboxConfigNetworkFilterref *gvir_sandbox_config_network_filterref_new(void)
+{
+ return GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF(g_object_new(GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF,
+ NULL));
+}
+
+
+static void gvir_sandbox_config_network_filterref_init(GVirSandboxConfigNetworkFilterref *config)
+{
+ config->priv = GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF_GET_PRIVATE(config);
+}
+
+
+/**
+ * gvir_sandbox_config_network_filterref_get_filter:
+ * @config: (transfer none): the network filter reference name
+ *
+ * Retrieves the network filter reference name.
+ *
+ * Returns: (transfer none): the network filter reference name.
+ */
+const gchar *gvir_sandbox_config_network_filterref_get_filter(GVirSandboxConfigNetworkFilterref *config)
+{
+ GVirSandboxConfigNetworkFilterrefPrivate *priv = config->priv;
+ return priv->filter;
+}
+
+void gvir_sandbox_config_network_filterref_set_filter(GVirSandboxConfigNetworkFilterref *config,
+ const gchar *name)
+{
+ GVirSandboxConfigNetworkFilterrefPrivate *priv = config->priv;
+ g_free(priv->filter);
+ priv->filter = g_strdup(name);
+}
+
+/**
+ * gvir_sandbox_config_network_filterref_add_parameter:
+ * @filter: (transfer none): the network filter reference.
+ * @param: (transfer none): the filter parameter
+ *
+ * Add a parameter to a network filter reference.
+ */
+void gvir_sandbox_config_network_filterref_add_parameter(GVirSandboxConfigNetworkFilterref *filter,
+ GVirSandboxConfigNetworkFilterrefParameter *param)
+{
+ GVirSandboxConfigNetworkFilterrefPrivate *priv = filter->priv;
+ priv->parameters = g_list_append(priv->parameters, g_object_ref(param));
+}
+
+
+/**
+ * gvir_sandbox_config_network_filterref_get_parameters:
+ * @filter: (transfer none): the filter reference configuration
+ *
+ * Retrieve the list of parameters associated with a network filter reference
+ *
+ * Returns: (transfer full)(element-type GVirSandboxConfigNetworkFilterrefParameter): the parameter list
+ */
+GList *gvir_sandbox_config_network_filterref_get_parameters(GVirSandboxConfigNetworkFilterref *filter)
+{
+ GVirSandboxConfigNetworkFilterrefPrivate *priv = filter->priv;
+ g_list_foreach(priv->parameters, (GFunc)g_object_ref, NULL);
+ return g_list_copy(priv->parameters);
+}
diff --git a/libvirt-sandbox/libvirt-sandbox-config-network-filterref.h b/libvirt-sandbox/libvirt-sandbox-config-network-filterref.h
new file mode 100644
index 0000000..5d264a5
--- /dev/null
+++ b/libvirt-sandbox/libvirt-sandbox-config-network-filterref.h
@@ -0,0 +1,75 @@
+/*
+ * libvirt-sandbox-config-mount.h: libvirt sandbox configuration
+ *
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Ian Main <imain(a)redhat.com>
+ */
+
+#if !defined(__LIBVIRT_SANDBOX_H__) && !defined(LIBVIRT_SANDBOX_BUILD)
+#error "Only <libvirt-sandbox/libvirt-sandbox.h> can be included directly."
+#endif
+
+#ifndef __LIBVIRT_SANDBOX_CONFIG_NETWORK_FILTERREF_H__
+#define __LIBVIRT_SANDBOX_CONFIG_NETWORK_FILTERREF_H__
+
+G_BEGIN_DECLS
+
+#define GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF (gvir_sandbox_config_network_filterref_get_type ())
+#define GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF, GVirSandboxConfigNetworkFilterref))
+#define GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF, GVirSandboxConfigNetworkFilterrefClass))
+#define GVIR_SANDBOX_IS_CONFIG_NETWORK_FILTERREF(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF))
+#define GVIR_SANDBOX_IS_CONFIG_NETWORK_FILTERREF_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF))
+#define GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF, GVirSandboxConfigNetworkFilterrefClass))
+
+#define GVIR_SANDBOX_TYPE_CONFIG_NETWORK_FILTERREF_HANDLE (gvir_sandbox_config_network_filterref_handle_get_type ())
+
+typedef struct _GVirSandboxConfigNetworkFilterref GVirSandboxConfigNetworkFilterref;
+typedef struct _GVirSandboxConfigNetworkFilterrefPrivate GVirSandboxConfigNetworkFilterrefPrivate;
+typedef struct _GVirSandboxConfigNetworkFilterrefClass GVirSandboxConfigNetworkFilterrefClass;
+
+struct _GVirSandboxConfigNetworkFilterref
+{
+ GObject parent;
+
+ GVirSandboxConfigNetworkFilterrefPrivate *priv;
+
+ /* Do not add fields to this struct */
+};
+
+struct _GVirSandboxConfigNetworkFilterrefClass
+{
+ GObjectClass parent_class;
+
+ gpointer padding[LIBVIRT_SANDBOX_CLASS_PADDING];
+};
+
+GType gvir_sandbox_config_network_filterref_get_type(void);
+
+GVirSandboxConfigNetworkFilterref *gvir_sandbox_config_network_filterref_new(void);
+
+const gchar *gvir_sandbox_config_network_filterref_get_filter(GVirSandboxConfigNetworkFilterref *config);
+void gvir_sandbox_config_network_filterref_set_filter(GVirSandboxConfigNetworkFilterref *filter, const gchar *name);
+
+void gvir_sandbox_config_network_filterref_add_parameter(GVirSandboxConfigNetworkFilterref *filter,
+ GVirSandboxConfigNetworkFilterrefParameter *param);
+GList *gvir_sandbox_config_network_filterref_get_parameters(GVirSandboxConfigNetworkFilterref *filter);
+
+
+G_END_DECLS
+
+#endif /* __LIBVIRT_SANDBOX_CONFIG_NETWORK_FILTERREF_H__ */
diff --git a/libvirt-sandbox/libvirt-sandbox-config-network.c b/libvirt-sandbox/libvirt-sandbox-config-network.c
index 7e7c015..555a360 100644
--- a/libvirt-sandbox/libvirt-sandbox-config-network.c
+++ b/libvirt-sandbox/libvirt-sandbox-config-network.c
@@ -47,6 +47,7 @@ struct _GVirSandboxConfigNetworkPrivate
gchar *mac;
GList *routes;
GList *addrs;
+ GVirSandboxConfigNetworkFilterref *filterref;
};
G_DEFINE_TYPE(GVirSandboxConfigNetwork, gvir_sandbox_config_network, G_TYPE_OBJECT);
@@ -285,6 +286,38 @@ GList *gvir_sandbox_config_network_get_addresses(GVirSandboxConfigNetwork *confi
}
/**
+ * gvir_sandbox_config_network_set_filterref:
+ * @config: (transfer none): the sandbox network configuration
+ * @ref: (transfer none): the network filterref
+ *
+ * Set a network filterref for the given network.
+ */
+void gvir_sandbox_config_network_set_filterref(GVirSandboxConfigNetwork *config,
+ GVirSandboxConfigNetworkFilterref *filterref)
+{
+ GVirSandboxConfigNetworkPrivate *priv = config->priv;
+ if (priv->filterref)
+ g_object_unref(priv->filterref);
+ priv->filterref = g_object_ref(filterref);
+}
+
+
+/**
+ * gvir_sandbox_config_network_get_filterref:
+ * @config: (transfer none): the sandbox network configuration
+ *
+ * Retrieve the associated filter reference.
+ *
+ * Returns: (transfer none): The associated filter reference.
+ */
+GVirSandboxConfigNetworkFilterref *gvir_sandbox_config_network_get_filterref(GVirSandboxConfigNetwork *config)
+{
+ GVirSandboxConfigNetworkPrivate *priv = config->priv;
+ return priv->filterref;
+}
+
+
+/**
* gvir_sandbox_config_network_add_route:
* @config: (transfer none): the sandbox network configuration
* @addr: (transfer none): the network route
diff --git a/libvirt-sandbox/libvirt-sandbox-config-network.h b/libvirt-sandbox/libvirt-sandbox-config-network.h
index d926fd1..4a52221 100644
--- a/libvirt-sandbox/libvirt-sandbox-config-network.h
+++ b/libvirt-sandbox/libvirt-sandbox-config-network.h
@@ -78,6 +78,10 @@ void gvir_sandbox_config_network_add_address(GVirSandboxConfigNetwork *config,
GVirSandboxConfigNetworkAddress *addr);
GList *gvir_sandbox_config_network_get_addresses(GVirSandboxConfigNetwork *config);
+void gvir_sandbox_config_network_set_filterref(GVirSandboxConfigNetwork *config,
+ GVirSandboxConfigNetworkFilterref *ref);
+GVirSandboxConfigNetworkFilterref *gvir_sandbox_config_network_get_filterref(GVirSandboxConfigNetwork *config);
+
void gvir_sandbox_config_network_add_route(GVirSandboxConfigNetwork *config,
GVirSandboxConfigNetworkRoute *addr);
GList *gvir_sandbox_config_network_get_routes(GVirSandboxConfigNetwork *config);
diff --git a/libvirt-sandbox/libvirt-sandbox-config.c b/libvirt-sandbox/libvirt-sandbox-config.c
index b1525a1..af21dbc 100644
--- a/libvirt-sandbox/libvirt-sandbox-config.c
+++ b/libvirt-sandbox/libvirt-sandbox-config.c
@@ -911,6 +911,8 @@ gboolean gvir_sandbox_config_add_network_strv(GVirSandboxConfig *config,
* source=private,address=192.168.122.1/24%192.168.122.255,
* address=192.168.122.1/24%192.168.122.255,address=2001:212::204:2/64
* route=192.168.122.255/24%192.168.1.1
+ * filter=clean-traffic
+ * filter.ip=192.168.122.1
*/
gboolean gvir_sandbox_config_add_network_opts(GVirSandboxConfig *config,
const gchar *network,
@@ -924,8 +926,10 @@ gboolean gvir_sandbox_config_add_network_opts(GVirSandboxConfig *config,
gchar **params = g_strsplit(network, ",", 50);
gsize j = 0;
GVirSandboxConfigNetwork *net;
+ GVirSandboxConfigNetworkFilterref *filter;
net = gvir_sandbox_config_network_new();
+ filter = gvir_sandbox_config_network_filterref_new();
gvir_sandbox_config_network_set_dhcp(net, FALSE);
while (params && params[j]) {
@@ -947,6 +951,40 @@ gboolean gvir_sandbox_config_add_network_opts(GVirSandboxConfig *config,
} else if (g_str_has_prefix(param, "mac=")) {
gvir_sandbox_config_network_set_mac(net,
param + strlen("mac="));
+ } else if (g_str_has_prefix(param, "filter.")) {
+ GVirSandboxConfigNetworkFilterrefParameter *filter_param;
+ gchar *tail = g_strdup(param + strlen("filter."));
+ gchar *equ = g_strrstr(tail, "=");
+ gchar *name, *name_up, *value;
+
+ if (equ == NULL) {
+ g_free(tail);
+ g_set_error(error, GVIR_SANDBOX_CONFIG_ERROR, 0,
+ _("No assignment in filter parameter configuration"));
+ g_object_unref(net);
+ goto cleanup;
+ }
+
+ name = g_strndup(tail, equ - tail);
+ value = g_strdup(equ + 1);
+ /* Convert to upcase for convenience. */
+ name_up = g_ascii_strup(name, -1);
+ g_free(name);
+
+ filter_param = gvir_sandbox_config_network_filterref_parameter_new();
+ gvir_sandbox_config_network_filterref_parameter_set_name(filter_param, name_up);
+ gvir_sandbox_config_network_filterref_parameter_set_value(filter_param, value);
+ gvir_sandbox_config_network_filterref_add_parameter(filter, filter_param);
+
+ g_free(tail);
+ g_free(name_up);
+ g_free(value);
+ } else if (g_str_has_prefix(param, "filter=")) {
+ gchar *name = g_strdup(param + strlen("filter="));
+
+ gvir_sandbox_config_network_filterref_set_filter(filter, name);
+ gvir_sandbox_config_network_set_filterref(net, filter);
+ g_free(name);
} else if (g_str_has_prefix(param, "address=")) {
GVirSandboxConfigNetworkAddress *addr;
GInetAddress *primaryaddr;
@@ -1090,6 +1128,7 @@ gboolean gvir_sandbox_config_add_network_opts(GVirSandboxConfig *config,
ret = TRUE;
cleanup:
+ g_object_unref(filter);
return ret;
}
diff --git a/libvirt-sandbox/libvirt-sandbox.h b/libvirt-sandbox/libvirt-sandbox.h
index a3f0b2c..7a2d3bf 100644
--- a/libvirt-sandbox/libvirt-sandbox.h
+++ b/libvirt-sandbox/libvirt-sandbox.h
@@ -37,6 +37,8 @@
#include <libvirt-sandbox/libvirt-sandbox-config-mount-guest-bind.h>
#include <libvirt-sandbox/libvirt-sandbox-config-mount-ram.h>
#include <libvirt-sandbox/libvirt-sandbox-config-network-address.h>
+#include <libvirt-sandbox/libvirt-sandbox-config-network-filterref-parameter.h>
+#include <libvirt-sandbox/libvirt-sandbox-config-network-filterref.h>
#include <libvirt-sandbox/libvirt-sandbox-config-network-route.h>
#include <libvirt-sandbox/libvirt-sandbox-config-network.h>
#include <libvirt-sandbox/libvirt-sandbox-config.h>
diff --git a/libvirt-sandbox/libvirt-sandbox.sym b/libvirt-sandbox/libvirt-sandbox.sym
index 7b7c8be..02c69a3 100644
--- a/libvirt-sandbox/libvirt-sandbox.sym
+++ b/libvirt-sandbox/libvirt-sandbox.sym
@@ -44,6 +44,7 @@ LIBVIRT_SANDBOX_0.2.1 {
gvir_sandbox_config_mount_ram_set_usage;
gvir_sandbox_config_network_add_address;
+ gvir_sandbox_config_network_set_filterref;
gvir_sandbox_config_network_add_route;
gvir_sandbox_config_network_get_type;
gvir_sandbox_config_network_get_dhcp;
@@ -51,6 +52,7 @@ LIBVIRT_SANDBOX_0.2.1 {
gvir_sandbox_config_network_get_source;
gvir_sandbox_config_network_get_routes;
gvir_sandbox_config_network_get_addresses;
+ gvir_sandbox_config_network_get_filterref;
gvir_sandbox_config_network_new;
gvir_sandbox_config_network_set_dhcp;
gvir_sandbox_config_network_set_mac;
@@ -65,6 +67,18 @@ LIBVIRT_SANDBOX_0.2.1 {
gvir_sandbox_config_network_address_set_primary;
gvir_sandbox_config_network_address_set_prefix;
+ gvir_sandbox_config_network_filterref_get_type;
+ gvir_sandbox_config_network_filterref_new;
+ gvir_sandbox_config_network_filterref_get_filter;
+ gvir_sandbox_config_network_filterref_set_filter;
+
+ gvir_sandbox_config_network_filterref_parameter_get_type;
+ gvir_sandbox_config_network_filterref_parameter_new;
+ gvir_sandbox_config_network_filterref_parameter_get_name;
+ gvir_sandbox_config_network_filterref_parameter_set_name;
+ gvir_sandbox_config_network_filterref_parameter_get_value;
+ gvir_sandbox_config_network_filterref_parameter_set_value;
+
gvir_sandbox_config_network_route_get_type;
gvir_sandbox_config_network_route_get_prefix;
gvir_sandbox_config_network_route_get_gateway;
--
1.8.1.4
11 years, 2 months
[libvirt] [PATCH] domain_conf.c: Initialize arrVar and cntVar
by Michal Privoznik
Some ancient gcc fails to see the variables are initialized in a
separate function and a false positive is produced:
cc1: warnings being treated as errors
conf/domain_conf.c: In function 'virDomainChrGetDomainPtrs':
conf/domain_conf.c:10342: error: 'arrVar' may be used uninitialized in this function [-Wuninitialized]
conf/domain_conf.c:10343: error: 'cntVar' may be used uninitialized in this function [-Wuninitialized]
conf/domain_conf.c: In function 'virDomainChrInsert':
conf/domain_conf.c:10362: error: 'arrPtr' may be used uninitialized in this function [-Wuninitialized]
conf/domain_conf.c:10363: error: 'cntPtr' may be used uninitialized in this function [-Wuninitialized]
conf/domain_conf.c: In function 'virDomainChrRemove':
conf/domain_conf.c:10374: error: 'arrPtr' may be used uninitialized in this function [-Wuninitialized]
conf/domain_conf.c:10375: error: 'cntPtr' may be used uninitialized in this function [-Wuninitialized]
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
Pushed under build breaker and trivial rules.
src/conf/domain_conf.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 365de77..562d98b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -10339,8 +10339,8 @@ virDomainChrGetDomainPtrs(const virDomainDef *vmdef,
const virDomainChrDef ***arrPtr,
size_t *cntPtr)
{
- virDomainChrDef ***arrVar;
- size_t *cntVar;
+ virDomainChrDef ***arrVar = NULL;
+ size_t *cntVar = NULL;
/* Cast away const; we add it back in the final assignment. */
virDomainChrGetDomainPtrsInternal((virDomainDefPtr) vmdef, type,
@@ -10359,8 +10359,8 @@ int
virDomainChrInsert(virDomainDefPtr vmdef,
virDomainChrDefPtr chr)
{
- virDomainChrDefPtr **arrPtr;
- size_t *cntPtr;
+ virDomainChrDefPtr **arrPtr = NULL;
+ size_t *cntPtr = NULL;
virDomainChrGetDomainPtrsInternal(vmdef, chr->deviceType, &arrPtr, &cntPtr);
@@ -10371,8 +10371,8 @@ virDomainChrDefPtr
virDomainChrRemove(virDomainDefPtr vmdef,
virDomainChrDefPtr chr)
{
- virDomainChrDefPtr ret, **arrPtr;
- size_t i, *cntPtr;
+ virDomainChrDefPtr ret, **arrPtr = NULL;
+ size_t i, *cntPtr = NULL;
virDomainChrGetDomainPtrsInternal(vmdef, chr->deviceType, &arrPtr, &cntPtr);
--
1.8.1.5
11 years, 2 months
[libvirt] [PATCH 1/2] vbox: assemble duplicate state conversions
by Ryota Ozaki
Signed-off-by: Ryota Ozaki <ozaki.ryota(a)gmail.com>
---
src/vbox/vbox_tmpl.c | 70 +++++++++++++++++-----------------------------------
1 file changed, 22 insertions(+), 48 deletions(-)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 5e5ea85..10a3775 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1912,6 +1912,26 @@ cleanup:
return ret;
}
+static virDomainState vboxConvertState(enum MachineState state) {
+ switch (state) {
+ case MachineState_Running:
+ return VIR_DOMAIN_RUNNING;
+ case MachineState_Stuck:
+ return VIR_DOMAIN_BLOCKED;
+ case MachineState_Paused:
+ return VIR_DOMAIN_PAUSED;
+ case MachineState_Stopping:
+ return VIR_DOMAIN_SHUTDOWN;
+ case MachineState_PoweredOff:
+ return VIR_DOMAIN_SHUTOFF;
+ case MachineState_Aborted:
+ return VIR_DOMAIN_CRASHED;
+ case MachineState_Null:
+ default:
+ return VIR_DOMAIN_NOSTATE;
+ }
+}
+
static int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info) {
VBOX_OBJECT_CHECK(dom->conn, int, -1);
vboxArray machines = VBOX_ARRAY_INITIALIZER;
@@ -1972,30 +1992,7 @@ static int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info) {
info->nrVirtCpu = CPUCount;
info->memory = memorySize * 1024;
info->maxMem = maxMemorySize * 1024;
- switch (state) {
- case MachineState_Running:
- info->state = VIR_DOMAIN_RUNNING;
- break;
- case MachineState_Stuck:
- info->state = VIR_DOMAIN_BLOCKED;
- break;
- case MachineState_Paused:
- info->state = VIR_DOMAIN_PAUSED;
- break;
- case MachineState_Stopping:
- info->state = VIR_DOMAIN_SHUTDOWN;
- break;
- case MachineState_PoweredOff:
- info->state = VIR_DOMAIN_SHUTOFF;
- break;
- case MachineState_Aborted:
- info->state = VIR_DOMAIN_CRASHED;
- break;
- case MachineState_Null:
- default:
- info->state = VIR_DOMAIN_NOSTATE;
- break;
- }
+ info->state = vboxConvertState(state);
ret = 0;
}
@@ -2038,30 +2035,7 @@ vboxDomainGetState(virDomainPtr dom,
machine->vtbl->GetState(machine, &mstate);
- switch (mstate) {
- case MachineState_Running:
- *state = VIR_DOMAIN_RUNNING;
- break;
- case MachineState_Stuck:
- *state = VIR_DOMAIN_BLOCKED;
- break;
- case MachineState_Paused:
- *state = VIR_DOMAIN_PAUSED;
- break;
- case MachineState_Stopping:
- *state = VIR_DOMAIN_SHUTDOWN;
- break;
- case MachineState_PoweredOff:
- *state = VIR_DOMAIN_SHUTOFF;
- break;
- case MachineState_Aborted:
- *state = VIR_DOMAIN_CRASHED;
- break;
- case MachineState_Null:
- default:
- *state = VIR_DOMAIN_NOSTATE;
- break;
- }
+ *state = vboxConvertState(mstate);
if (reason)
*reason = 0;
--
1.8.4
11 years, 2 months
[libvirt] [RESEND][PATCH] esx: Fix floppy.fileName handling in the vmx file parser
by Geoff Hickey
[Updated to include unit tests]
The vmx file parsing code was reporting errors when parsing floppy.fileName
entries if the filename didn't end in .flp. There is no such restriction in
ESX; even using the GUI to configure floppy filenames you can specify any
arbitrary file with any extension.
Fix by changing the vmx parsing code so that it uses the floppy.fileType
value to determine whether floppy.fileName refers to a block device or a
regular file.
Also remove code that would have generated an error if no floppy.fileName
was specified. This is not an error either.
Updated the floppy tests in vmx2xmltest.c and xml2vmxtest.c.
---
src/vmx/vmx.c | 28 ++++------------------------
tests/vmx2xmldata/vmx2xml-floppy-file.vmx | 3 +++
tests/vmx2xmldata/vmx2xml-floppy-file.xml | 5 +++++
tests/xml2vmxdata/xml2vmx-floppy-file.vmx | 4 +++-
tests/xml2vmxdata/xml2vmx-floppy-file.xml | 4 ++++
5 files changed, 19 insertions(+), 25 deletions(-)
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 36bc338..48487f8 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -2250,27 +2250,14 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
goto cleanup;
}
} else if (device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
- if (virFileHasSuffix(fileName, ".flp")) {
- if (fileType != NULL) {
- if (STRCASENEQ(fileType, "file")) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Expecting VMX entry '%s' to be 'file' but "
- "found '%s'"), fileType_name, fileType);
- goto cleanup;
- }
- }
-
- (*def)->type = VIR_DOMAIN_DISK_TYPE_FILE;
- (*def)->src = ctx->parseFileName(fileName, ctx->opaque);
-
- if ((*def)->src == NULL) {
- goto cleanup;
- }
- } else if (fileType != NULL && STRCASEEQ(fileType, "device")) {
+ if (fileType != NULL && STRCASEEQ(fileType, "device")) {
(*def)->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
(*def)->src = fileName;
fileName = NULL;
+ } else if (fileType != NULL && STRCASEEQ(fileType, "file")) {
+ (*def)->type = VIR_DOMAIN_DISK_TYPE_FILE;
+ (*def)->src = ctx->parseFileName(fileName, ctx->opaque);
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid or not yet handled value '%s' "
@@ -3538,13 +3525,6 @@ virVMXFormatFloppy(virVMXContext *ctx, virDomainDiskDefPtr def,
virBufferAsprintf(buffer, "floppy%d.fileType = \"file\"\n", unit);
if (def->src != NULL) {
- if (! virFileHasSuffix(def->src, ".flp")) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Image file for floppy '%s' has unsupported "
- "suffix, expecting '.flp'"), def->dst);
- return -1;
- }
-
fileName = ctx->formatFileName(def->src, ctx->opaque);
if (fileName == NULL) {
diff --git a/tests/vmx2xmldata/vmx2xml-floppy-file.vmx b/tests/vmx2xmldata/vmx2xml-floppy-file.vmx
index b9ee81b..344ac78 100644
--- a/tests/vmx2xmldata/vmx2xml-floppy-file.vmx
+++ b/tests/vmx2xmldata/vmx2xml-floppy-file.vmx
@@ -3,3 +3,6 @@ virtualHW.version = "4"
floppy0.present = "true"
floppy0.fileType = "file"
floppy0.fileName = "floppy.flp"
+floppy1.present = "true"
+floppy1.fileType = "file"
+floppy1.fileName = "floppy"
\ No newline at end of file
diff --git a/tests/vmx2xmldata/vmx2xml-floppy-file.xml b/tests/vmx2xmldata/vmx2xml-floppy-file.xml
index f62320f..40f70d3 100644
--- a/tests/vmx2xmldata/vmx2xml-floppy-file.xml
+++ b/tests/vmx2xmldata/vmx2xml-floppy-file.xml
@@ -16,6 +16,11 @@
<target dev='fda' bus='fdc'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
+ <disk type='file' device='floppy'>
+ <source file='[datastore] directory/floppy'/>
+ <target dev='fdb' bus='fdc'/>
+ <address type='drive' controller='0' bus='0' target='0' unit='1'/>
+ </disk>
<controller type='fdc' index='0'/>
<video>
<model type='vmvga' vram='4096'/>
diff --git a/tests/xml2vmxdata/xml2vmx-floppy-file.vmx b/tests/xml2vmxdata/xml2vmx-floppy-file.vmx
index 11ffb01..b8ffc1e 100644
--- a/tests/xml2vmxdata/xml2vmx-floppy-file.vmx
+++ b/tests/xml2vmxdata/xml2vmx-floppy-file.vmx
@@ -9,4 +9,6 @@ numvcpus = "1"
floppy0.present = "true"
floppy0.fileType = "file"
floppy0.fileName = "/vmfs/volumes/testing/floppy.flp"
-floppy1.present = "false"
+floppy1.present = "true"
+floppy1.fileType = "file"
+floppy1.fileName = "/vmfs/volumes/testing/floppy1"
diff --git a/tests/xml2vmxdata/xml2vmx-floppy-file.xml b/tests/xml2vmxdata/xml2vmx-floppy-file.xml
index 83598b3..119113a 100644
--- a/tests/xml2vmxdata/xml2vmx-floppy-file.xml
+++ b/tests/xml2vmxdata/xml2vmx-floppy-file.xml
@@ -10,5 +10,9 @@
<source file='[testing] floppy.flp'/>
<target dev='fda' bus='fdc'/>
</disk>
+ <disk type='file' device='floppy'>
+ <source file='[testing] floppy1'/>
+ <target dev='fdb' bus='fdc'/>
+ </disk>
</devices>
</domain>
--
1.8.1.2
11 years, 2 months
[libvirt] [PATCH] network: Remove unnecessary check in networkRadvdConfContents
by Hongwei Bi
Since there is a check on configbuf through virBufferError(),
it is not necessary to check configstr and report OOM again.
Signed-off-by: Hongwei Bi <hwbi2008(a)gmail.com>
---
src/network/bridge_driver.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 8787bdb..ec40e0c 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -1312,10 +1312,7 @@ networkRadvdConfContents(virNetworkObjPtr network, char **configstr)
virReportOOMError();
goto cleanup;
}
- if (!(*configstr = virBufferContentAndReset(&configbuf))) {
- virReportOOMError();
- goto cleanup;
- }
+ *configstr = virBufferContentAndReset(&configbuf);
}
ret = 0;
--
1.8.1.2
11 years, 2 months
[libvirt] [PATCH] network: Add a missing check in bridge_driver.c
by Hongwei Bi
---
src/network/bridge_driver.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 8787bdb..73375f0 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -1107,7 +1107,8 @@ networkStartDhcpDaemon(virNetworkDriverStatePtr driver,
if (dctx == NULL)
goto cleanup;
- dnsmasqCapsRefresh(&driver->dnsmasqCaps, false);
+ if (dnsmasqCapsRefresh(&driver->dnsmasqCaps, false) < 0)
+ goto cleanup;
ret = networkBuildDhcpDaemonCommandLine(network, &cmd, pidfile,
dctx, driver->dnsmasqCaps);
--
1.8.1.2
11 years, 2 months