[libvirt] [PATCH] macvtap: convert nl msg construction to use libnl
by Stefan Berger
In a first step I am converting the netlink message construction in
macvtap code to use libnl. It's pretty much a 1:1 conversion except that
now the message needs to be allocated and deallocated.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
src/util/macvtap.c | 145
+++++++++++++++++------------------------------------
1 file changed, 49 insertions(+), 96 deletions(-)
Index: libvirt-acl/src/util/macvtap.c
===================================================================
--- libvirt-acl.orig/src/util/macvtap.c
+++ libvirt-acl/src/util/macvtap.c
@@ -196,51 +196,6 @@ err_exit:
}
-static struct rtattr *
-rtattrCreate(char *buffer, int bufsize, int type,
- const void *data, int datalen)
-{
- struct rtattr *r = (struct rtattr *)buffer;
- r->rta_type = type;
- r->rta_len = RTA_LENGTH(datalen);
- if (r->rta_len > bufsize)
- return NULL;
- memcpy(RTA_DATA(r), data, datalen);
- return r;
-}
-
-
-static void
-nlInit(struct nlmsghdr *nlm, int flags, int type)
-{
- nlm->nlmsg_len = NLMSG_LENGTH(0);
- nlm->nlmsg_flags = flags;
- nlm->nlmsg_type = type;
-}
-
-
-static void
-nlAlign(struct nlmsghdr *nlm)
-{
- nlm->nlmsg_len = NLMSG_ALIGN(nlm->nlmsg_len);
-}
-
-
-static void *
-nlAppend(struct nlmsghdr *nlm, int totlen, const void *data, int datalen)
-{
- char *pos;
- nlAlign(nlm);
- if (nlm->nlmsg_len + NLMSG_ALIGN(datalen) > totlen)
- return NULL;
- pos = (char *)nlm + nlm->nlmsg_len;
- memcpy(pos, data, datalen);
- nlm->nlmsg_len += datalen;
- nlAlign(nlm);
- return pos;
-}
-
-
# if WITH_MACVTAP
static int
@@ -252,73 +207,60 @@ link_add(const char *type,
int *retry)
{
int rc = 0;
- char nlmsgbuf[NLMSGBUF_SIZE];
- struct nlmsghdr *nlm = (struct nlmsghdr *)nlmsgbuf, *resp;
+ struct nlmsghdr *resp;
struct nlmsgerr *err;
- char rtattbuf[RATTBUF_SIZE];
- struct rtattr *rta, *rta1, *li;
struct ifinfomsg ifinfo = { .ifi_family = AF_UNSPEC };
int ifindex;
char *recvbuf = NULL;
unsigned int recvbuflen;
+ struct nl_msg *nl_msg;
+ struct nlattr *linkinfo, *info_data;
if (ifaceGetIndex(true, srcdev, &ifindex) != 0)
return -1;
- *retry = 0;
-
- memset(&nlmsgbuf, 0, sizeof(nlmsgbuf));
+ nl_msg = nlmsg_alloc_simple(RTM_NEWLINK,
+ NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL);
+ if (!nl_msg) {
+ virReportOOMError();
+ return -1;
+ }
- nlInit(nlm, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL, RTM_NEWLINK);
+ *retry = 0;
- if (!nlAppend(nlm, sizeof(nlmsgbuf), &ifinfo, sizeof(ifinfo)))
+ if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0)
goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_LINK,
- &ifindex, sizeof(ifindex));
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (nla_put_u32(nl_msg, IFLA_LINK, ifindex) < 0)
goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_ADDRESS,
- macaddress, macaddrsize);
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (nla_put(nl_msg, IFLA_ADDRESS, macaddrsize, macaddress) < 0)
goto buffer_too_small;
- if (ifname) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_IFNAME,
- ifname, strlen(ifname) + 1);
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf,
rta->rta_len))
- goto buffer_too_small;
- }
+ if (ifname &&
+ nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0)
+ goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_LINKINFO, NULL, 0);
- if (!rta ||
- !(li = nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len)))
+ if (!(linkinfo = nla_nest_start(nl_msg, IFLA_LINKINFO)))
goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_INFO_KIND,
- type, strlen(type));
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (nla_put(nl_msg, IFLA_INFO_KIND, strlen(type), type) < 0)
goto buffer_too_small;
if (macvlan_mode > 0) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_INFO_DATA,
- NULL, 0);
- if (!rta ||
- !(rta1 = nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf,
rta->rta_len)))
+ if (!(info_data = nla_nest_start(nl_msg, IFLA_INFO_DATA)))
goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_MACVLAN_MODE,
- &macvlan_mode, sizeof(macvlan_mode));
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf,
rta->rta_len))
+ if (nla_put(nl_msg, IFLA_MACVLAN_MODE, sizeof(macvlan_mode),
+ &macvlan_mode) < 0)
goto buffer_too_small;
- rta1->rta_len = (char *)nlm + nlm->nlmsg_len - (char *)rta1;
+ nla_nest_end(nl_msg, info_data);
}
- li->rta_len = (char *)nlm + nlm->nlmsg_len - (char *)li;
+ nla_nest_end(nl_msg, linkinfo);
- if (nlComm(nlm, &recvbuf, &recvbuflen, 0) < 0)
+ if (nlComm(nlmsg_hdr(nl_msg), &recvbuf, &recvbuflen, 0) < 0)
return -1;
if (recvbuflen < NLMSG_LENGTH(0) || recvbuf == NULL)
@@ -359,17 +301,23 @@ link_add(const char *type,
VIR_FREE(recvbuf);
+ nlmsg_free(nl_msg);
+
return rc;
malformed_resp:
+ nlmsg_free(nl_msg);
+
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
_("malformed netlink response message"));
VIR_FREE(recvbuf);
return -1;
buffer_too_small:
+ nlmsg_free(nl_msg);
+
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("internal buffer is too small"));
+ _("allocated netlink buffer is too small"));
return -1;
}
@@ -378,28 +326,27 @@ static int
link_del(const char *name)
{
int rc = 0;
- char nlmsgbuf[NLMSGBUF_SIZE];
- struct nlmsghdr *nlm = (struct nlmsghdr *)nlmsgbuf, *resp;
+ struct nlmsghdr *resp;
struct nlmsgerr *err;
- char rtattbuf[RATTBUF_SIZE];
- struct rtattr *rta;
struct ifinfomsg ifinfo = { .ifi_family = AF_UNSPEC };
char *recvbuf = NULL;
unsigned int recvbuflen;
+ struct nl_msg *nl_msg;
- memset(&nlmsgbuf, 0, sizeof(nlmsgbuf));
-
- nlInit(nlm, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL, RTM_DELLINK);
+ nl_msg = nlmsg_alloc_simple(RTM_DELLINK,
+ NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL);
+ if (!nl_msg) {
+ virReportOOMError();
+ return -1;
+ }
- if (!nlAppend(nlm, sizeof(nlmsgbuf), &ifinfo, sizeof(ifinfo)))
+ if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0)
goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_IFNAME,
- name, strlen(name)+1);
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (nla_put(nl_msg, IFLA_IFNAME, strlen(name)+1, name) < 0)
goto buffer_too_small;
- if (nlComm(nlm, &recvbuf, &recvbuflen, 0) < 0)
+ if (nlComm(nlmsg_hdr(nl_msg), &recvbuf, &recvbuflen, 0) < 0)
return -1;
if (recvbuflen < NLMSG_LENGTH(0) || recvbuf == NULL)
@@ -430,17 +377,23 @@ link_del(const char *name)
VIR_FREE(recvbuf);
+ nlmsg_free(nl_msg);
+
return rc;
malformed_resp:
+ nlmsg_free(nl_msg);
+
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
_("malformed netlink response message"));
VIR_FREE(recvbuf);
return -1;
buffer_too_small:
+ nlmsg_free(nl_msg);
+
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("internal buffer is too small"));
+ _("allocated netlink buffer is too small"));
return -1;
}
13 years, 11 months
[libvirt] [PATCH] doc: fix typo in virsh.pod
by Osier Yang
---
tools/virsh.pod | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 5932aaa..f677383 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -301,7 +301,7 @@ L<http://libvirt.org/formatdomain.html#elementsCPU>
The following commands manipulate domains directly, as stated
previously most commands take domain-id as the first parameter. The
-I<domain-id> can be specified as an short integer, a name or a full UUID.
+I<domain-id> can be specified as a short integer, a name or a full UUID.
=over 4
@@ -326,7 +326,7 @@ If I<--console> is requested, attach to the console after creation.
B<Example>
virsh dumpxml <domain-id> > domain.xml
- edit domain.xml
+ virsh edit domain.xml
virsh create < domain.xml
=item B<define> I<FILE>
--
1.7.2.3
13 years, 11 months
[libvirt] [PATCH 6/7] Add sysinfo/smbios support to the QEmu driver
by Daniel Veillard
The patch is based on the possiblity in the QEmu command line to
add -smbios options allowing to override the default values picked
by QEmu. We need to detect this first from QEmu help output.
If the domain is defined with smbios to be inherited from host
then we pass the values coming from the Host own SMBIOS, but
if the domain is defined with smbios to come from sysinfo, we
use the ones coming from the domain definition.
* src/qemu/qemu_conf.h: add the QEMUD_CMD_FLAG_SMBIOS_TYPE enum
value
* src/qemu/qemu_conf.c: scan the help output for the smbios support,
and if available add support based on the domain definitions,
and host data
* tests/qemuhelptest.c: add the new enum in the outputs
Signed-off-by: Daniel Veillard <veillard(a)redhat.com>
---
src/qemu/qemu_conf.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_conf.h | 3 +-
tests/qemuhelptest.c | 15 ++++--
3 files changed, 129 insertions(+), 6 deletions(-)
13 years, 11 months
[libvirt] [PATCH 4/7] Add a sysinfo util module and read host info API
by Daniel Veillard
Move existing routines about virSysinfoDef to an util module,
add a new entry point virSysinfoRead() to read the host values
with dmidecode
* src/conf/domain_conf.c src/conf/domain_conf.h src/util/sysinfo.c
src/util/sysinfo.h: move to a new module, add virSysinfoRead()
* src/Makefile.am: handle the new module build
* src/libvirt_private.syms: new internal symbols
* include/libvirt/virterror.h src/util/virterror.c: defined a new
error code for that module
Signed-off-by: Daniel Veillard <veillard(a)redhat.com>
---
include/libvirt/virterror.h | 3 +-
po/POTFILES.in | 1 +
src/Makefile.am | 1 +
src/conf/domain_conf.c | 19 ----
src/conf/domain_conf.h | 25 +----
src/libvirt_private.syms | 5 +
src/util/sysinfo.c | 250 +++++++++++++++++++++++++++++++++++++++++++
src/util/sysinfo.h | 58 ++++++++++
src/util/virterror.c | 3 +
9 files changed, 321 insertions(+), 44 deletions(-)
create mode 100644 src/util/sysinfo.c
create mode 100644 src/util/sysinfo.h
13 years, 11 months
[libvirt] [PATCH 2/7] Sysinfo parsing and saving to/from configuration files
by Daniel Veillard
* src/conf/domain_conf.h: defines a new internal type added to the
domain structure
* src/conf/domain_conf.c: parsing and serialization of that new type
Signed-off-by: Daniel Veillard <veillard(a)redhat.com>
---
src/conf/domain_conf.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++-
src/conf/domain_conf.h | 26 +++++++
2 files changed, 217 insertions(+), 1 deletions(-)
13 years, 11 months
[libvirt] [PATCH] macvtap: libvirtd forgot macvtap device name during a shutdown/restart cycle
by Stefan Berger
During a shutdown/restart cycle libvirtd forgot the macvtap device name
that it had created on behalf of a VM so that a stale macvtap device
remained on the host when the VM terminated. Libvirtd has to actively
tear down a macvtap device and it uses its name for identifying which
device to tear down.
The solution is to not blank out the <target dev='...'/> completely, but
only blank it out on VMs that are not active. So, if a VM is active, the
device name makes it into the XML and is also being parsed. If a VM is
not active, the device name is discarded.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
src/conf/domain_conf.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Index: libvirt-acl/src/conf/domain_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/domain_conf.c
+++ libvirt-acl/src/conf/domain_conf.c
@@ -2343,7 +2343,8 @@ virDomainNetDefParseXML(virCapsPtr caps,
def->data.direct.linkdev = dev;
dev = NULL;
- VIR_FREE(ifname);
+ if ((flags & VIR_DOMAIN_XML_INACTIVE))
+ VIR_FREE(ifname);
break;
@@ -5801,6 +5802,8 @@ virDomainNetDefFormat(virBufferPtr buf,
virBufferAddLit(buf, "/>\n");
virVirtualPortProfileFormat(buf,
&def->data.direct.virtPortProfile,
" ");
+ if ((flags & VIR_DOMAIN_XML_INACTIVE))
+ VIR_FREE(def->ifname);
break;
case VIR_DOMAIN_NET_TYPE_USER:
13 years, 11 months
[libvirt] [PATCH 1/7] Sysinfo extension to relax-ng schemas
by Daniel Veillard
Currently includes a subset of the SMBIOS strings set
Signed-off-by: Daniel Veillard <veillard(a)redhat.com>
---
docs/schemas/domain.rng | 75 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 75 insertions(+), 0 deletions(-)
13 years, 11 months
[libvirt] Revamped Smbios/Sysinfo support
by Daniel Veillard
This patch set implements a new way to store system informations and
pass them to the domain, it's modelled on the SMBIOS support in
hypervisors and allow to override those informations in domains:
The simplest is the use of:
<smbios mode="host"/>
in which case the domain will try to inherit those values from
the Host own values, the classical use case is the use of OEM'ed
Windows versions where one need to export SMBIOS informations from
the host to the guest.
But the <sysinfo> construct allows to define those informations,
for example:
<sysinfo type="smbios">
<bios>
<entry name="vendor">QEmu/KVM</entry>
<entry name="version">0.13</entry>
</bios>
<system>
<entry name="manufacturer">Fedora</entry>
<entry name="product">Virt-Manager</entry>
<entry name="version">0.8.2-3.fc14</entry>
<entry name="serial">32dfcb37-5af1-552b-357c-be8c3aa38310</entry>
<entry name="uuid">c7a5fdbd-edaf-9455-926a-d65c16db1809</entry>
</system>
</sysinfo>
<smbios mode="sysinfo"/>
In that case libvirt hypervisor driver will try to set up those values
in the domain emulation.
The patch set attached implement those modes for QEmu, and based on our
previous reviews with Matthias the first mode should be implementable
in the ESX driver (for just a couple of settings though) and the VirtualBox
driver should be abble to implement both if we understood correctly,
Daniel
13 years, 11 months
[libvirt] [PATCH 7/7] Add a new test for sysinfo and smbios handling
by Daniel Veillard
Signed-off-by: Daniel Veillard <veillard(a)redhat.com>
---
tests/qemuxml2argvdata/qemuxml2argv-smbios.args | 1 +
tests/qemuxml2argvdata/qemuxml2argv-smbios.xml | 39 +++++++++++++++++++++++
tests/qemuxml2argvtest.c | 2 +
3 files changed, 42 insertions(+), 0 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-smbios.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-smbios.xml
13 years, 11 months