[libvirt] [PATCH] esx: Support SMBIOS host mode
by Matthias Bolte
---
src/esx/esx_vmx.c | 27 ++++++++++++++++++++++++++-
tests/vmx2xmldata/vmx2xml-smbios.vmx | 3 +++
tests/vmx2xmldata/vmx2xml-smbios.xml | 16 ++++++++++++++++
tests/vmx2xmltest.c | 2 ++
tests/xml2vmxdata/xml2vmx-smbios.vmx | 11 +++++++++++
tests/xml2vmxdata/xml2vmx-smbios.xml | 9 +++++++++
tests/xml2vmxtest.c | 2 ++
7 files changed, 69 insertions(+), 1 deletions(-)
create mode 100644 tests/vmx2xmldata/vmx2xml-smbios.vmx
create mode 100644 tests/vmx2xmldata/vmx2xml-smbios.xml
create mode 100644 tests/xml2vmxdata/xml2vmx-smbios.vmx
create mode 100644 tests/xml2vmxdata/xml2vmx-smbios.xml
diff --git a/src/esx/esx_vmx.c b/src/esx/esx_vmx.c
index b853bdf..5cbb835 100644
--- a/src/esx/esx_vmx.c
+++ b/src/esx/esx_vmx.c
@@ -74,6 +74,7 @@ def->os
->loader
->bootloader
->bootloaderArgs
+->smbios_mode <=> smbios.reflecthost = "<value>" # <value> == true means SMBIOS_HOST, otherwise it's SMBIOS_EMULATE, defaults to "false"
@@ -880,6 +881,7 @@ esxVMX_ParseConfig(esxVMX_Context *ctx, virCapsPtr caps, const char *vmx,
long long numvcpus = 0;
char *sched_cpu_affinity = NULL;
char *guestOS = NULL;
+ bool smbios_reflecthost = false;
int controller;
int bus;
int port;
@@ -1195,6 +1197,16 @@ esxVMX_ParseConfig(esxVMX_Context *ctx, virCapsPtr caps, const char *vmx,
goto cleanup;
}
+ /* vmx:smbios.reflecthost -> def:os.smbios_mode */
+ if (esxUtil_GetConfigBoolean(conf, "smbios.reflecthost",
+ &smbios_reflecthost, false, true) < 0) {
+ goto cleanup;
+ }
+
+ if (smbios_reflecthost) {
+ def->os.smbios_mode = VIR_DOMAIN_SMBIOS_HOST;
+ }
+
/* def:features */
/* FIXME */
@@ -2552,7 +2564,7 @@ esxVMX_FormatConfig(esxVMX_Context *ctx, virCapsPtr caps, virDomainDefPtr def,
goto cleanup;
}
- /* def:arch -> vmx:guestOS */
+ /* def:os.arch -> vmx:guestOS */
if (def->os.arch == NULL || STRCASEEQ(def->os.arch, "i686")) {
virBufferAddLit(&buffer, "guestOS = \"other\"\n");
} else if (STRCASEEQ(def->os.arch, "x86_64")) {
@@ -2564,6 +2576,19 @@ esxVMX_FormatConfig(esxVMX_Context *ctx, virCapsPtr caps, virDomainDefPtr def,
goto cleanup;
}
+ /* def:os.smbios_mode -> vmx:smbios.reflecthost */
+ if (def->os.smbios_mode == VIR_DOMAIN_SMBIOS_NONE ||
+ def->os.smbios_mode == VIR_DOMAIN_SMBIOS_EMULATE) {
+ /* nothing */
+ } else if (def->os.smbios_mode == VIR_DOMAIN_SMBIOS_HOST) {
+ virBufferAddLit(&buffer, "smbios.reflecthost = \"true\"\n");
+ } else {
+ ESX_ERROR(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Unsupported SMBIOS mode '%s'"),
+ virDomainSmbiosModeTypeToString(def->os.smbios_mode));
+ goto cleanup;
+ }
+
/* def:uuid -> vmx:uuid.action, vmx:uuid.bios */
if (memcmp(def->uuid, zero, VIR_UUID_BUFLEN) == 0) {
virBufferAddLit(&buffer, "uuid.action = \"create\"\n");
diff --git a/tests/vmx2xmldata/vmx2xml-smbios.vmx b/tests/vmx2xmldata/vmx2xml-smbios.vmx
new file mode 100644
index 0000000..16258b0
--- /dev/null
+++ b/tests/vmx2xmldata/vmx2xml-smbios.vmx
@@ -0,0 +1,3 @@
+config.version = "8"
+virtualHW.version = "4"
+smbios.reflecthost = "true"
diff --git a/tests/vmx2xmldata/vmx2xml-smbios.xml b/tests/vmx2xmldata/vmx2xml-smbios.xml
new file mode 100644
index 0000000..db13001
--- /dev/null
+++ b/tests/vmx2xmldata/vmx2xml-smbios.xml
@@ -0,0 +1,16 @@
+<domain type='vmware'>
+ <uuid>00000000-0000-0000-0000-000000000000</uuid>
+ <memory>32768</memory>
+ <currentMemory>32768</currentMemory>
+ <vcpu>1</vcpu>
+ <os>
+ <type arch='i686'>hvm</type>
+ <smbios mode='host'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ </devices>
+</domain>
diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c
index 2d59297..ba50034 100644
--- a/tests/vmx2xmltest.c
+++ b/tests/vmx2xmltest.c
@@ -285,6 +285,8 @@ mymain(int argc, char **argv)
DO_TEST("annotation", "annotation", esxVI_ProductVersion_ESX35);
+ DO_TEST("smbios", "smbios", esxVI_ProductVersion_ESX35);
+
virCapabilitiesFree(caps);
return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
diff --git a/tests/xml2vmxdata/xml2vmx-smbios.vmx b/tests/xml2vmxdata/xml2vmx-smbios.vmx
new file mode 100644
index 0000000..8a54cca
--- /dev/null
+++ b/tests/xml2vmxdata/xml2vmx-smbios.vmx
@@ -0,0 +1,11 @@
+.encoding = "UTF-8"
+config.version = "8"
+virtualHW.version = "4"
+guestOS = "other"
+smbios.reflecthost = "true"
+uuid.bios = "56 4d 9b ef ac d9 b4 e0-c8 f0 ae a8 b9 10 35 15"
+displayName = "smbios"
+memsize = "4"
+numvcpus = "1"
+floppy0.present = "false"
+floppy1.present = "false"
diff --git a/tests/xml2vmxdata/xml2vmx-smbios.xml b/tests/xml2vmxdata/xml2vmx-smbios.xml
new file mode 100644
index 0000000..b19e9c7
--- /dev/null
+++ b/tests/xml2vmxdata/xml2vmx-smbios.xml
@@ -0,0 +1,9 @@
+<domain type='vmware'>
+ <name>smbios</name>
+ <uuid>564d9bef-acd9-b4e0-c8f0-aea8b9103515</uuid>
+ <memory>4096</memory>
+ <os>
+ <type>hvm</type>
+ <smbios mode='host'/>
+ </os>
+</domain>
diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c
index db7eb53..7041877 100644
--- a/tests/xml2vmxtest.c
+++ b/tests/xml2vmxtest.c
@@ -278,6 +278,8 @@ mymain(int argc, char **argv)
DO_TEST("annotation", "annotation", esxVI_ProductVersion_ESX35);
+ DO_TEST("smbios", "smbios", esxVI_ProductVersion_ESX35);
+
virCapabilitiesFree(caps);
return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
--
1.7.0.4
14 years
[libvirt] [PATCH v2] [RESEND] macvtap: convert nl msg construction to use libnl
by Stefan Berger
Resending this mail using 'Evolution'.
V2:
- forgot to convert two more functions that were hidden in #defines
- small nits
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 | 321 ++++++++++++++++++++++-------------------------------
1 file changed, 137 insertions(+), 184 deletions(-)
Index: libvirt-acl/src/util/macvtap.c
===================================================================
--- libvirt-acl.orig/src/util/macvtap.c
+++ libvirt-acl/src/util/macvtap.c
@@ -191,51 +191,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
@@ -247,74 +202,63 @@ 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));
-
- nlInit(nlm, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL, RTM_NEWLINK);
+ nl_msg = nlmsg_alloc_simple(RTM_NEWLINK,
+ 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_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)
- return -1;
+ if (nlComm(nlmsg_hdr(nl_msg), &recvbuf, &recvbuflen, 0) < 0) {
+ rc = -1;
+ goto err_exit;
+ }
if (recvbuflen < NLMSG_LENGTH(0) || recvbuf == NULL)
goto malformed_resp;
@@ -352,50 +296,58 @@ link_add(const char *type,
goto malformed_resp;
}
+err_exit:
+ nlmsg_free(nl_msg);
+
VIR_FREE(recvbuf);
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;
}
static int
-link_del(const char *name)
+link_del(const char *ifname)
{
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(ifname)+1, ifname) < 0)
goto buffer_too_small;
- if (nlComm(nlm, &recvbuf, &recvbuflen, 0) < 0)
- return -1;
+ if (nlComm(nlmsg_hdr(nl_msg), &recvbuf, &recvbuflen, 0) < 0) {
+ rc = -1;
+ goto err_exit;
+ }
if (recvbuflen < NLMSG_LENGTH(0) || recvbuf == NULL)
goto malformed_resp;
@@ -411,7 +363,7 @@ link_del(const char *name)
if (err->error) {
virReportSystemError(-err->error,
_("error destroying %s interface"),
- name);
+ ifname);
rc = -1;
}
break;
@@ -423,19 +375,26 @@ link_del(const char *name)
goto malformed_resp;
}
+err_exit:
+ nlmsg_free(nl_msg);
+
VIR_FREE(recvbuf);
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;
}
@@ -783,40 +742,44 @@ link_dump(bool nltarget_kernel, const ch
struct nlattr **tb, char **recvbuf)
{
int rc = 0;
- char nlmsgbuf[NLMSGBUF_SIZE] = { 0, };
- 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,
.ifi_index = ifindex
};
unsigned int recvbuflen;
uint32_t pid = 0;
+ struct nl_msg *nl_msg;
*recvbuf = NULL;
- nlInit(nlm, NLM_F_REQUEST, RTM_GETLINK);
+ nl_msg = nlmsg_alloc_simple(RTM_GETLINK, NLM_F_REQUEST);
+ 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;
if (ifindex < 0 && ifname) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_IFNAME,
- ifname, strlen(ifname) + 1);
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0)
goto buffer_too_small;
}
if (!nltarget_kernel) {
pid = getLldpadPid();
- if (pid == 0)
- return -1;
+ if (pid == 0) {
+ rc = -1;
+ goto err_exit;
+ }
}
- if (nlComm(nlm, recvbuf, &recvbuflen, pid) < 0)
- return -1;
+ if (nlComm(nlmsg_hdr(nl_msg), recvbuf, &recvbuflen, pid) < 0) {
+ rc = -1;
+ goto err_exit;
+ }
if (recvbuflen < NLMSG_LENGTH(0) || *recvbuf == NULL)
goto malformed_resp;
@@ -852,17 +815,24 @@ link_dump(bool nltarget_kernel, const ch
if (rc != 0)
VIR_FREE(*recvbuf);
+err_exit:
+ 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;
}
@@ -1046,11 +1016,8 @@ doPortProfileOpSetLink(bool nltarget_ker
uint8_t op)
{
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, *vfports = NULL, *vfport;
struct ifinfomsg ifinfo = {
.ifi_family = AF_UNSPEC,
.ifi_index = ifindex,
@@ -1058,23 +1025,24 @@ doPortProfileOpSetLink(bool nltarget_ker
char *recvbuf = NULL;
unsigned int recvbuflen = 0;
uint32_t pid = 0;
+ struct nl_msg *nl_msg;
+ struct nlattr *vfports = NULL, *vfport;
- memset(&nlmsgbuf, 0, sizeof(nlmsgbuf));
-
- nlInit(nlm, NLM_F_REQUEST, RTM_SETLINK);
+ nl_msg = nlmsg_alloc_simple(RTM_SETLINK, NLM_F_REQUEST);
+ 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;
- 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;
if (macaddr && vlanid >= 0) {
- struct rtattr *vfinfolist, *vfinfo;
+ struct nlattr *vfinfolist, *vfinfo;
struct ifla_vf_mac ifla_vf_mac = {
.vf = vf,
.mac = { 0, },
@@ -1087,110 +1055,88 @@ doPortProfileOpSetLink(bool nltarget_ker
memcpy(ifla_vf_mac.mac, macaddr, 6);
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_VFINFO_LIST,
- NULL, 0);
- if (!rta ||
- !(vfinfolist = nlAppend(nlm, sizeof(nlmsgbuf),
- rtattbuf, rta->rta_len)))
+ if (!(vfinfolist = nla_nest_start(nl_msg, IFLA_VFINFO_LIST)))
goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_VF_INFO,
- NULL, 0);
- if (!rta ||
- !(vfinfo = nlAppend(nlm, sizeof(nlmsgbuf),
- rtattbuf, rta->rta_len)))
+ if (!(vfinfo = nla_nest_start(nl_msg, IFLA_VF_INFO)))
goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_VF_MAC,
- &ifla_vf_mac, sizeof(ifla_vf_mac));
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (!nla_put(nl_msg, IFLA_VF_MAC, sizeof(ifla_vf_mac),
+ &ifla_vf_mac) < 0)
goto buffer_too_small;
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_VF_VLAN,
- &ifla_vf_vlan, sizeof(ifla_vf_vlan));
-
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (!nla_put(nl_msg, IFLA_VF_VLAN, sizeof(ifla_vf_vlan),
+ &ifla_vf_vlan) < 0)
goto buffer_too_small;
- vfinfo->rta_len = (char *)nlm + nlm->nlmsg_len - (char *)vfinfo;
-
- vfinfolist->rta_len = (char *)nlm + nlm->nlmsg_len -
- (char *)vfinfolist;
+ nla_nest_end(nl_msg, vfinfo);
+ nla_nest_end(nl_msg, vfinfolist);
}
if (vf == PORT_SELF_VF && nltarget_kernel) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_PORT_SELF, NULL, 0);
+ if (!(vfport = nla_nest_start(nl_msg, IFLA_PORT_SELF)))
+ goto buffer_too_small;
} else {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_VF_PORTS, NULL, 0);
- if (!rta ||
- !(vfports = nlAppend(nlm, sizeof(nlmsgbuf),
- rtattbuf, rta->rta_len)))
+ if (!(vfports = nla_nest_start(nl_msg, IFLA_VF_PORTS)))
goto buffer_too_small;
/* begin nesting vfports */
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_VF_PORT, NULL, 0);
+ if (!(vfport = nla_nest_start(nl_msg, IFLA_VF_PORT)))
+ goto buffer_too_small;
}
- if (!rta ||
- !(vfport = nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len)))
- goto buffer_too_small;
-
if (profileId) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_PORT_PROFILE,
- profileId, strlen(profileId) + 1);
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (nla_put(nl_msg, IFLA_PORT_PROFILE, strlen(profileId) + 1,
+ profileId) < 0)
goto buffer_too_small;
}
if (portVsi) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_PORT_VSI_TYPE,
- portVsi, sizeof(*portVsi));
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (nla_put(nl_msg, IFLA_PORT_VSI_TYPE, sizeof(*portVsi),
+ portVsi) < 0)
goto buffer_too_small;
}
if (instanceId) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_PORT_INSTANCE_UUID,
- instanceId, VIR_UUID_BUFLEN);
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (nla_put(nl_msg, IFLA_PORT_INSTANCE_UUID, VIR_UUID_BUFLEN,
+ instanceId) < 0)
goto buffer_too_small;
}
if (hostUUID) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_PORT_HOST_UUID,
- hostUUID, VIR_UUID_BUFLEN);
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (nla_put(nl_msg, IFLA_PORT_HOST_UUID, VIR_UUID_BUFLEN,
+ hostUUID) < 0)
goto buffer_too_small;
}
if (vf != PORT_SELF_VF) {
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_PORT_VF,
- &vf, sizeof(vf));
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (nla_put(nl_msg, IFLA_PORT_VF, sizeof(vf), &vf) < 0)
goto buffer_too_small;
}
- rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_PORT_REQUEST,
- &op, sizeof(op));
- if (!rta || !nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))
+ if (nla_put(nl_msg, IFLA_PORT_REQUEST, sizeof(op), &op) < 0)
goto buffer_too_small;
/* end nesting of vport */
- vfport->rta_len = (char *)nlm + nlm->nlmsg_len - (char *)vfport;
+ nla_nest_end(nl_msg, vfport);
if (vfports) {
/* end nesting of vfports */
- vfports->rta_len = (char *)nlm + nlm->nlmsg_len - (char *)vfports;
+ nla_nest_end(nl_msg, vfports);
}
if (!nltarget_kernel) {
pid = getLldpadPid();
- if (pid == 0)
- return -1;
+ if (pid == 0) {
+ rc = -1;
+ goto err_exit;
+ }
}
- if (nlComm(nlm, &recvbuf, &recvbuflen, pid) < 0)
- return -1;
+ if (nlComm(nlmsg_hdr(nl_msg), &recvbuf, &recvbuflen, pid) < 0) {
+ rc = -1;
+ goto err_exit;
+ }
if (recvbuflen < NLMSG_LENGTH(0) || recvbuf == NULL)
goto malformed_resp;
@@ -1218,19 +1164,26 @@ doPortProfileOpSetLink(bool nltarget_ker
goto malformed_resp;
}
+err_exit:
+ nlmsg_free(nl_msg);
+
VIR_FREE(recvbuf);
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;
}
14 years
[libvirt] [PATCH] remote_driver.c: fix non-literal format strings w/o args
by Laine Stump
Pushed another of these under the trivial rule (with correct email address
this time!).
I guess I run into these so often because I build with --disable-nls and most other people don't...
---
src/remote/remote_driver.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 4492b6b..f45476a 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -8481,7 +8481,7 @@ remoteStreamEventAddCallback(virStreamPtr st,
if (privst->cb) {
remoteError(VIR_ERR_INTERNAL_ERROR,
- _("multiple stream callbacks not supported"));
+ "%s", _("multiple stream callbacks not supported"));
goto cleanup;
}
@@ -8521,7 +8521,7 @@ remoteStreamEventUpdateCallback(virStreamPtr st,
if (!privst->cb) {
remoteError(VIR_ERR_INTERNAL_ERROR,
- _("no stream callback registered"));
+ "%s", _("no stream callback registered"));
goto cleanup;
}
@@ -8548,7 +8548,7 @@ remoteStreamEventRemoveCallback(virStreamPtr st)
if (!privst->cb) {
remoteError(VIR_ERR_INTERNAL_ERROR,
- _("no stream callback registered"));
+ "%s", _("no stream callback registered"));
goto cleanup;
}
--
1.7.1
14 years
[libvirt] [PATCH] ignore SELinuxSetFilecon error in SELinuxSetSecurityFileLabel if on nfs
by Laine Stump
If virDomainAttachDevice() was called with an image that was located
on a root-squashed NFS server, and in a directory that was unreadable
by root on the machine running libvirtd, the attach would fail due to
an attempt to change the selinux label of the image with EACCES (which
isn't covered as an ignore case in SELinuxSetFilecon())
NFS doesn't support SELinux labelling anyway, so we mimic the failure
handling of commit 93a18bbafaf11729d3ca1241e11bee133d77fa77, which
just ignores the errors if the target is on an NFS filesystem (in
SELinuxSetSecurityAllLabel() only, though.)
This can be seen as a follow-on to commit
347d266c51705f4987fa5ce2a0ecb314ed8745ce, which ignores file open
failures of files on NFS that occur directly in
virDomainDiskDefForeachPath() (also necessary), but does not ignore
failures in functions that are called from there (eg
SELinuxSetSecurityFileLabel()).
---
src/security/security_selinux.c | 15 +++++++++++----
1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 7dd9b14..a9b63ea 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -453,20 +453,27 @@ SELinuxSetSecurityFileLabel(virDomainDiskDefPtr disk,
void *opaque)
{
const virSecurityLabelDefPtr secdef = opaque;
+ int ret;
if (depth == 0) {
if (disk->shared) {
- return SELinuxSetFilecon(path, default_image_context);
+ ret = SELinuxSetFilecon(path, default_image_context);
} else if (disk->readonly) {
- return SELinuxSetFilecon(path, default_content_context);
+ ret = SELinuxSetFilecon(path, default_content_context);
} else if (secdef->imagelabel) {
- return SELinuxSetFilecon(path, secdef->imagelabel);
+ ret = SELinuxSetFilecon(path, secdef->imagelabel);
} else {
return 0;
}
} else {
- return SELinuxSetFilecon(path, default_content_context);
+ ret = SELinuxSetFilecon(path, default_content_context);
}
+ if (ret < 0 &&
+ virStorageFileIsSharedFSType(path,
+ VIR_STORAGE_FILE_SHFS_NFS) != 1)
+ return ret;
+ else
+ return 0;
}
static int
--
1.7.1
14 years
[libvirt] Different approach to locking
by Richard W.M. Jones
I get the feeling that the locking manager is meant to be a
libvirt-internal API. I'll throw out this idea instead: How about
making the concept of "reserving" a VM into a public libvirt API?
/* Reserve 'dom'.
*
* flags:
* VIR_DOMAIN_RESERVE_READONLY: reserve for read-only access
*/
int virDomainReserve (virDomainPtr dom, unsigned flags);
/* Drop reservation of 'dom'.
*/
int virDomainUnReserve (virDomainPtr dom);
The reservation would also be dropped when the current libvirt
connection is closed.
libvirt/libvirtd would acquire the locks on our behalf.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v
14 years
[libvirt] Per user preference file
by Justin Clift
Hi all,
Had a thought the other night, about a possible approach to having a "per user" libvirt preferences file.
How about, in the user's home directory, we have a single text file, say ".libvirt-prefs", structured something like this:
[common]
default_uri = qemu+ssh://somehost/system
default_socket = /path/to/somewhere-socket
default_session_type = system
tls_client_cert = /path/to/somewhere.cert
tls_client_key = /path/to/somewhere.key
log_file=/path/to/logfile.log
some_other_preference=value
[gtk-vnc]
tls_client_cert = /path/that/overrides/the/common/section/if/present/somefile.cert
tls_client_key = /path/that/overrides/the/common/section/if/present/somefile.key
[virt-viewer]
more_overrides=/value/foo
The suggestion being, that we have a [common] section with preferences that general libvirt client apps can use (ie virsh). But also allowing other libvirt client apps (ie virt-viewer), to store overrides to that.
Just thinking it would be useful to have these things in one place, so sensible defaults can be set once (ie for TLS certs), and things will then "automagically" use them.
+ Justin
14 years
[libvirt] dommemstat return nothing
by arnaud.champion@devatom.fr
?Hi,
I'm currently working on dommemstat C# bindings, and I have a little problem, with virsh under fedora or under linux, dommemstat return nothing. Is it normal ? A suggestion ?
Regards,
Arnaud Champion
14 years
[libvirt] auto-generating HACKING?
by Eric Blake
Right now, docs/hacking.html.in contains more data than HACKING. Back
in March(! - commit d1c754168) the plan was to add a Makefile rule to
autogenerate HACKING via some xml filter; but this still hasn't
happened. Can anyone with a better skill set than me at setting up xml
filters step in and help?
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
14 years