Re: [libvirt] [PATCH] conf: report error in virCPUDefParseXML

2014-09-24 Thread Martin Kletzander

On Thu, Sep 25, 2014 at 12:23:31PM +0800, Jincheng Miao wrote:

When detected invalid 'memAccess', virCPUDefParseXML should report error.

Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1146334

Signed-off-by: Jincheng Miao 
---
src/conf/cpu_conf.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 116aa58..a1081b9 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -510,13 +510,13 @@ virCPUDefParseXML(xmlNodePtr node,
def->cells[cur_cell].memAccess =
virMemAccessTypeFromString(memAccessStr);

-if (def->cells[cur_cell].memAccess <= 0) {
+if ((int)def->cells[cur_cell].memAccess <= 0) {


Any reason for the explicit cast in here?


virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
   _("Invalid 'memAccess' attribute "
 "value '%s'"),
   memAccessStr);
VIR_FREE(memAccessStr);
-goto cleanup;
+goto error;


ACK to this line.

Martin


signature.asc
Description: Digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] nodeinfo: fix nodeGetFreePages when max node is zero

2014-09-24 Thread Jincheng Miao


On 09/24/2014 08:53 PM, Michal Privoznik wrote:

On 24.09.2014 14:00, Jincheng Miao wrote:


On 09/24/2014 07:40 PM, Michal Privoznik wrote:

On 24.09.2014 07:45, Jincheng Miao wrote:

In nodeGetFreePages, if startCell is given by '0',
and the max node number is '0' too. The for-loop
wouldn't be executed.
So convert it to while-loop.

Before:

virsh freepages --cellno 0 --pagesize 4

error: internal error: no suitable info found

After:

virsh freepages --cellno 0 --pagesize 4

4KiB: 472637

Signed-off-by: Jincheng Miao 
---
  src/nodeinfo.c | 7 ---
  1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 2459922..1fe190a 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -2042,18 +2042,19 @@ nodeGetFreePages(unsigned int npages,
  }

  lastCell = MIN(lastCell, startCell + cellCount);
+cell = startCell;

-for (cell = startCell; cell < lastCell; cell++) {
+do {
  for (i = 0; i < npages; i++) {
  unsigned int page_size = pages[i];
  unsigned int page_free;

-if (virNumaGetPageInfo(cell, page_size, 0, NULL,
&page_free) < 0)
+if (virNumaGetPageInfo(cell++, page_size, 0, NULL,
&page_free) < 0)
  goto cleanup;

  counts[ncounts++] = page_free;
  }
-}
+} while (cell < lastCell);

  if (!ncounts) {
  virReportError(VIR_ERR_INTERNAL_ERROR, "%s",



There's no need to switch to do-while loop. All what is needed is cell
<= lastCell in the for loop. I'm rewriting the patch and pushing. ACK.


Wait, if change the for condition to 'cell <= lastCell', and pass
startCell == -1,
the for-loop will execute twice, and will overwrite counts[1] which is
not allocated.


Oh, right. Seems like I'm brainwashed today. This is the diff I've 
forgot to 'git add':


diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 0a7642c..05eab6c 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -2041,7 +2041,7 @@ nodeGetFreePages(unsigned int npages,
 goto cleanup;
 }

-lastCell = MIN(lastCell, startCell + cellCount);
+lastCell = MIN(lastCell, startCell + cellCount - 1);


Yep, this is working now with this adjustment.



 for (cell = startCell; cell <= lastCell; cell++) {
 for (i = 0; i < npages; i++) {

Michal


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] conf: report error in virCPUDefParseXML

2014-09-24 Thread Jincheng Miao
When detected invalid 'memAccess', virCPUDefParseXML should report error.

Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1146334

Signed-off-by: Jincheng Miao 
---
 src/conf/cpu_conf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 116aa58..a1081b9 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -510,13 +510,13 @@ virCPUDefParseXML(xmlNodePtr node,
 def->cells[cur_cell].memAccess =
 virMemAccessTypeFromString(memAccessStr);
 
-if (def->cells[cur_cell].memAccess <= 0) {
+if ((int)def->cells[cur_cell].memAccess <= 0) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Invalid 'memAccess' attribute "
  "value '%s'"),
memAccessStr);
 VIR_FREE(memAccessStr);
-goto cleanup;
+goto error;
 }
 VIR_FREE(memAccessStr);
 }
-- 
1.9.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Is seems necessary to pass "migratable=no/yes" to qemu.

2014-09-24 Thread zhang bo
On 2014/9/24 19:49, Ján Tomko wrote:

> On 09/24/2014 05:28 AM, zhang bo wrote:
>> The patch
>> http://libvirt.org/git/?p=libvirt.git;a=commitdiff;h=de0aeafe9ce3eb414c8b5d3aa8995d776a2952de
>> removes invtsc flag in the host-model CPU.
>>
>> I'm wondering, will it be better to pass args "migratable=no/yes" to qemu, 
>> and let qemu complete the
>> remaining work? As that qemu has checked whether it's necessary to use 
>> invtsc or not.
> 
> The 'migratable' property is only for -cpu host (
> in libvirt).
> 
> For mode='host-model', libvirt detects the model and features of the host CPU
> and passes it as -cpu ,+feat,+feat2,...
> so we can't leave that to QEMU.
> 
>> --
>> "invtsc is available only if using: -cpu host,migratable=no,+invtsc."
>> http://git.qemu.org/?p=qemu.git;a=commit;h=120eee7d1fdb2eba15766cfff7b9bcdc902690b4
>> --
>>
>> There's another problem, if we do not pass "migratable=no" to qemu.
>> Consider if we set host mode to pass-through
>>-
>>   
>>   
>>-
>> then the vm->def->cpu->features contains invtsc. however, qemu will 
>> automatically remove this cpu flag
>> as that "migration=no" is not passed to it. thus, the guest will not start 
>> up. This problem is in fact
>> caused by the patch:
>> http://libvirt.org/git/?p=libvirt.git;a=commit;h=fba6bc47cbcabbe08d42279691efb0dff3b9c997,
>> it forbids guest domain to start up if the host has INVTSC while the 
>> guest(qemu) does not.
> 
> Regardless of QEMU support for invtsc, I'm only able to start the domain,
> restore or migration fails.
> 
> As far as I know, only 'invtsc' is the problematic feature, because it both
> a) can appear in the host CPU (so libvirt assumes -cpu host will add it)
> b) is checked by qemuProcessVerifyGuestCPU (and libvirt complains when it's
> not there)
> 
> For other features, we only add them to qemu command line and let qemu filter
> out the unsupported ones.
> 
>>-
>> for (i = 0; def->cpu && i < def->cpu->nfeatures; i++) {
>> virCPUFeatureDefPtr feature = &def->cpu->features[i];
>>
>> if (feature->policy != VIR_CPU_FEATURE_REQUIRE)
>> continue;
>>
>> if (STREQ(feature->name, "invtsc") &&
>> !cpuHasFeature(guestcpu, feature->name)) {
>> virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
>>_("host doesn't support invariant TSC"));
>> goto cleanup;
>> }
>> }
>> break;
>>--
>>
>>
>> In conclusion:
>> 1 Will it better to pass args "migratable=yes/no" to qemu rather than doing 
>> the mask-invtsc job in libvirt?
>> 2 If the guest has "pass-through" cpu mode, then it's unable to start up, 
>> because qemu removes invtsc, and
>> vm->def->cpu->features has it. It seems a BUG.
>>
> 
> I think the simplest fix for host-passthrough would be to apply the same
> filter host-model has.
> 
> But since using invtsc with host-passthrough requires both +invtsc and
> migratable=no, so we'd need to either add a 'migratable' option to
> host-passthrough (this would skip the filter and add migratable=on), or allow
> fine-tuning the features for host-passthrough too.
> 
> Jan
> 

   Additional to the 2 suggestions, will that be OK to remove the codes in 
qemuProcessVerifyGuestCPU that checks whether the vm->def has
   invtsc flag while qemu doesn't?

- if (STREQ(feature->name, "invtsc") &&
- !cpuHasFeature(guestcpu, feature->name)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-_("host doesn't support invariant TSC"));
- goto cleanup;
- }

   Removing these codes, plus with the solution that "add 'migratable' option 
to host-passthrough", it seems the problem would
   be gone, and invtsc would not be so 'distinctive' in libvirt any more.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 6/6] qemu: change macvtap device MAC address in response to NIC_RX_FILTER_CHANGED

2014-09-24 Thread John Ferlan


On 09/24/2014 05:50 AM, Laine Stump wrote:
> This patch fills in the functionality of
> processNicRxFilterChangedEvent().  It now checks if it is appropriate
> to respond to the NIC_RX_FILTER_CHANGED event (based on device type
> and configuration) and takes appropriate action. Currently it checks
> if the guest interface has been configured with
> trustGuestRxFilters='yes', and if the host side device is macvtap. If
> so, and the MAC address on the guest has changed, the MAC address of
> the macvtap device is changed to match.
> 
> The result of this is that networking from the guest will continue to
> work if the mac address of a macvtap-connected network device is
> changed from within the guest, as long as trustGuestRxFilters='yes'
> (previously changing the MAC address in the guest would break
> networking).
> ---
>  src/qemu/qemu_driver.c | 50 
> ++
>  1 file changed, 50 insertions(+)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 64f1d45..7801d91 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -4146,8 +4146,13 @@ processNicRxFilterChangedEvent(virQEMUDriverPtr driver,
> char *devAlias)
>  {
>  virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
> +qemuDomainObjPrivatePtr priv = vm->privateData;
>  virDomainDeviceDef dev;
>  virDomainNetDefPtr def;
> +virNetDevRxFilterPtr filter = NULL;
> +virMacAddr oldMAC;
> +char newMacStr[VIR_MAC_STRING_BUFLEN];
> +int ret;
>  
>  VIR_DEBUG("Received NIC_RX_FILTER_CHANGED event for device %s "
>"from domain %p %s",
> @@ -4175,11 +4180,55 @@ processNicRxFilterChangedEvent(virQEMUDriverPtr 
> driver,
>  }
>  def = dev.data.net;
>  
> +if (!virDomainNetGetActualTrustGuestRxFilters(def)) {
> +VIR_WARN("ignore NIC_RX_FILTER_CHANGED event for network "
> +  "device %s in domain %s",
> +  def->info.alias, vm->def->name);

So how often could this be emitted? Do we need some sort of "filter" to
only message once per life of the domain?

> +/* not sending "query-rx-filter" will also suppress any
> + * further NIC_RX_FILTER_CHANGED events for this device
> + */
> +goto endjob;
> +}
> +
>  /* handle the event - send query-rx-filter and respond to it. */
>  
>  VIR_DEBUG("process NIC_RX_FILTER_CHANGED event for network "
>"device %s in domain %s", def->info.alias, vm->def->name);
>  

There's no capabilities check necessary?  What if the command doesn't
exist in the underlying qemu?

> +qemuDomainObjEnterMonitor(driver, vm);
> +ret = qemuMonitorQueryRxFilter(priv->mon, devAlias, &filter);
> +qemuDomainObjExitMonitor(driver, vm);
> +if (ret < 0)
> +goto endjob;

You filled in a lot of data from the qemuMonitorQueryRxFilter(), but
you're only using filter->mac (e.g. main-mac).

Or am I missing something?

John

> +
> +virMacAddrFormat(&filter->mac, newMacStr);
> +
> +if (virDomainNetGetActualType(def) == VIR_DOMAIN_NET_TYPE_DIRECT) {
> +
> +/* For macvtap connections, set the macvtap device's MAC
> + * address to match that of the guest device.
> + */
> +
> +if (virNetDevGetMAC(def->ifname, &oldMAC) < 0) {
> +VIR_WARN("Couldn't get current MAC address of device %s "
> + "while responding to NIC_RX_FILTER_CHANGED",
> + def->ifname);
> +goto endjob;
> +}
> +
> +if (virMacAddrCmp(&oldMAC, &filter->mac)) {
> +/* set new MAC address from guest to associated macvtap device */
> +if (virNetDevSetMAC(def->ifname, &filter->mac) < 0) {
> +VIR_WARN("Couldn't set new MAC address %s to device %s "
> + "while responding to NIC_RX_FILTER_CHANGED",
> + newMacStr, def->ifname);
> +} else {
> +VIR_DEBUG("device %s MAC address set to %s",
> +  def->ifname, newMacStr);
> +}
> +}
> +}
> +
>   endjob:
>  /* We had an extra reference to vm before starting a new job so ending 
> the
>   * job is guaranteed not to remove the last reference.
> @@ -4187,6 +4236,7 @@ processNicRxFilterChangedEvent(virQEMUDriverPtr driver,
>  ignore_value(qemuDomainObjEndJob(driver, vm));
>  
>   cleanup:
> +virNetDevRxFilterFree(filter);
>  VIR_FREE(devAlias);
>  virObjectUnref(cfg);
>  }
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 5/6] qemu: setup infrastructure to handle NIC_RX_FILTER_CHANGED event

2014-09-24 Thread John Ferlan


On 09/24/2014 05:50 AM, Laine Stump wrote:
> NIC_RX_FILTER_CHANGED is sent by qemu any time a NIC driver in the
> guest modified the NIC's RX Filter (for example, if the MAC address of
> the NIC is changed by the guest).
> 
> This patch doesn't do anything useful with that event; it just sets up
> all the plumbing to get news of the event into a worker thread with
> all proper locking/reference counting, and provide an easy place to
> add in desired functionality.
> 
> For easy reference the next time a handler for a qemu event is
> written, here is the sequence:
> 
> The handler in qemu_json_monitor.c calls
> 
>qemu_json_monitor.c:qemuMonitorJSONHandleNicRxFilterChanged()
> 
> which calls
> 
>qemu_monitor.c:qemuMonitorEmitNicRxFilterChanged()
> 
> which uses QEMU_MONITOR_CALLBACK() to call
> mon->cb->domainNicRxFilterChanged(), ie:
> 
>qemuProcessHandleNicRxFilterChanged()
> 
> which will queue an event QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED for
> a worker thread to handle.
> 
> When the worker thread gets the event, it calls
> 
>qemuProcessEventHandler()
> 
> which calls
> 
>processNicRxFilterChangedEvent()
> 
> and *that* is where the actual work will be done (and any
> event-specific memory allocated during qemuProcessHandleXXX() will be
> freed) - it is the middle of this function where functionality behind
> the event will be added in the next patch; for now there is just a
> VIR_DEBUG() to log the event.


This is the kind of stuff while great in a commit message - is perhaps
even better in the comments of the code somewhere.  Not sure of which is
the "best place", but perhaps before the typedef enum {}
qemuProcessEventType;  At least someone will get a head start on the
various places they have to change.  Anyone adding an event has to start
there.


> ---
>  src/qemu/qemu_domain.h   |  1 +
>  src/qemu/qemu_driver.c   | 55 
> 
>  src/qemu/qemu_monitor.c  | 13 +++
>  src/qemu/qemu_monitor.h  |  7 ++
>  src/qemu/qemu_monitor_json.c | 17 ++
>  src/qemu/qemu_process.c  | 42 +
>  6 files changed, 135 insertions(+)
> 

Although not my area of expertise, things look good. Looks like all the
changes were very similar to other events added. Not the definitive ACK
you probably want, but hopefully someone else who's made changes in this
space recently can take a quick look to make sure you've covered everything.

My one question would be - is there any sort of issue if when
registering the event that the underlying qemu doesn't support/have the
NIC_RX_FILTER_CHANGED event defined?  Or does that just not matter and
all this does is take events sent to libvirt after registering at some
higher level to receive "any" event. It seems to be the latter through
qemuMonitorIO, but I figured I'd ask...


John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v2 0/4] Check migration configuration

2014-09-24 Thread Chen, Fan
ping? 


On Tue, 2014-09-23 at 12:04 +0800, Chen Fan wrote: 
> add some check in migration configuration.
> 
> Chen Fan (4):
>   virsocketaddr: return address family in virSocketAddrIsNumeric
>   migration: add migration_host support for Ipv6 address without
> brackets
>   conf: add virSocketAddrIsLocalhost to Check migration_host
>   conf: Check migration_address whether is localhost
> 
>  src/libvirt_private.syms   |  1 +
>  src/qemu/qemu.conf |  2 +-
>  src/qemu/qemu_conf.c   | 15 
>  src/qemu/qemu_migration.c  | 24 ++-
>  src/qemu/test_libvirtd_qemu.aug.in |  2 +-
>  src/util/virsocketaddr.c   | 48 
> ++
>  src/util/virsocketaddr.h   |  5 +++-
>  tests/sockettest.c |  2 +-
>  8 files changed, 80 insertions(+), 19 deletions(-)
> 


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 4/6] qemu: qemuMonitorQueryRxFilter - retrieve guest netdev rx-filter

2014-09-24 Thread John Ferlan


On 09/24/2014 05:50 AM, Laine Stump wrote:
> This function can be called at any time to get the current status of a
> guest's network device rx-filter. In particular it is useful to call
> after libvirt recieves a NIC_RX_FILTER_CHANGED event - this event only
> tells you that something has changed in the rx-filter, the details are
> retrieved with the query-rx-filter monitor command (only available in
> the json monitor). The commend sent to the qemu monitor looks like this:
> 
>   {"execute":"query-rx-filter", "arguments": {"name":"net2"} }'
> 
> and the results will look something like this:
> 
> {
> "return": [
> {
> "promiscuous": false,
> "name": "net2",
> "main-mac": "52:54:00:98:2d:e3",
> "unicast": "normal",
> "vlan": "normal",
> "vlan-table": [
> 42,
> 0
> ],
> "unicast-table": [
> 
> ],
> "multicast": "normal",
> "multicast-overflow": false,
> "unicast-overflow": false,
> "multicast-table": [
> "33:33:ff:98:2d:e3",
> "01:80:c2:00:00:21",
> "01:00:5e:00:00:fb",
> "33:33:ff:98:2d:e2",
> "01:00:5e:00:00:01",
> "33:33:00:00:00:01"
> ],
> "broadcast-allowed": false
> }
> ],
> "id": "libvirt-14"
> }
> 
> This is all parsed from JSON into a virNetDevRxFilter object for
> easier consumption. (unicast-table is usually empty, but is also an
> array of mac addresses similar to multicast-table).
> 
> (NB: LIBNL_CFLAGS was added to tests/Makefile.am because virnetdev.h
> now includes util/virnetlink.h, which includes netlink/msg.h when
> appropriate. Without LIBNL_CFLAGS, gcc can't find that file (if
> libnl/netlink isn't available, LIBNL_CFLAGS will be empty and
> virnetlink.h won't try to include netlink/msg.h anyway).)
> ---
>  src/qemu/qemu_monitor.c  |  26 ++
>  src/qemu/qemu_monitor.h  |   4 +
>  src/qemu/qemu_monitor_json.c | 215 
> +++
>  src/qemu/qemu_monitor_json.h |   3 +
>  tests/Makefile.am|   3 +
>  5 files changed, 251 insertions(+)
> 
> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
> index c25f002..48cbe3e 100644
> --- a/src/qemu/qemu_monitor.c
> +++ b/src/qemu/qemu_monitor.c
> @@ -2918,6 +2918,32 @@ int qemuMonitorRemoveNetdev(qemuMonitorPtr mon,
>  }
>  
>  
> +int
> +qemuMonitorQueryRxFilter(qemuMonitorPtr mon, const char *alias,
> + virNetDevRxFilterPtr *filter)
> +{
> +int ret = -1;
> +VIR_DEBUG("mon=%p alias=%s filter=%p",
> +  mon, alias, filter);
> +
> +if (!mon) {
> +virReportError(VIR_ERR_INVALID_ARG, "%s",
> +   _("monitor must not be NULL"));
> +return -1;
> +}

The "if (!mon->json)" usually goes here rather than later as an else.
Just trying to be consistent with other functions

I'm assuming at some point whomever calls this will check if the
query-rx-filter command exits (eg, the qemu capability exists)...

Again I haven't peeked ahead.

> +
> +
> +VIR_DEBUG("mon=%p, alias=%s", mon, alias);
> +
> +if (mon->json)
> +ret = qemuMonitorJSONQueryRxFilter(mon, alias, filter);
> +else
> +virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
> +   _("query-rx-filter requires JSON monitor"));
> +return ret;
> +}
> +
> +
>  int qemuMonitorGetPtyPaths(qemuMonitorPtr mon,
> virHashTablePtr paths)
>  {
> diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
> index 6b91e29..c37e36f 100644
> --- a/src/qemu/qemu_monitor.h
> +++ b/src/qemu/qemu_monitor.h
> @@ -31,6 +31,7 @@
>  # include "virbitmap.h"
>  # include "virhash.h"
>  # include "virjson.h"
> +# include "virnetdev.h"
>  # include "device_conf.h"
>  # include "cpu/cpu.h"
>  
> @@ -622,6 +623,9 @@ int qemuMonitorAddNetdev(qemuMonitorPtr mon,
>  int qemuMonitorRemoveNetdev(qemuMonitorPtr mon,
>  const char *alias);
>  
> +int qemuMonitorQueryRxFilter(qemuMonitorPtr mon, const char *alias,
> + virNetDevRxFilterPtr *filter);
> +
>  int qemuMonitorGetPtyPaths(qemuMonitorPtr mon,
> virHashTablePtr paths);
>  
> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index a3d7c2c..58007e6 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -3194,6 +3194,221 @@ int qemuMonitorJSONRemoveNetdev(qemuMonitorPtr mon,
>  }
>  
>  
> +static int
> +qemuMonitorJSONQueryRxFilterParse(virJSONValuePtr msg,
> +  virNetDevRxFilterPtr *filter)
> +{
> +int ret = -1;
> +const char *tmp;
> +virJSONValuePtr returnArray, entry, table, element;
> +int nTable;
> +size_t i;
> +virNetDevRxFilte

Re: [libvirt] [PATCH 3/6] util: define virNetDevRxFilter and basic utility functions

2014-09-24 Thread John Ferlan


On 09/24/2014 05:50 AM, Laine Stump wrote:
> This same structure will be used to retrieve RX filter info for
> interfaces on the host via netlink messages, and RX filter info for
> interfaces on the guest via the qemu "query-rx-filter" command.
> ---
>  src/libvirt_private.syms |  8 +++
>  src/util/virnetdev.c | 40 +
>  src/util/virnetdev.h | 57 
> +++-
>  3 files changed, 104 insertions(+), 1 deletion(-)
> 
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index bb2b9a3..e5723d2 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -1595,6 +1595,14 @@ virNetDevReplaceMacAddress;
>  virNetDevReplaceNetConfig;
>  virNetDevRestoreMacAddress;
>  virNetDevRestoreNetConfig;
> +virNetDevRxFilterFree;
> +virNetDevRxFilterMulticastModeTypeFromString;
> +virNetDevRxFilterMulticastModeTypeToString;
> +virNetDevRxFilterNew;
> +virNetDevRxFilterUnicastModeTypeFromString;
> +virNetDevRxFilterUnicastModeTypeToString;
> +virNetDevRxFilterVlanModeTypeFromString;
> +virNetDevRxFilterVlanModeTypeToString;
>  virNetDevSetIPv4Address;
>  virNetDevSetMAC;
>  virNetDevSetMTU;
> diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
> index 8815e18..dd1f530 100644
> --- a/src/util/virnetdev.c
> +++ b/src/util/virnetdev.c
> @@ -1932,3 +1932,43 @@ virNetDevGetLinkInfo(const char *ifname,
>  return 0;
>  }
>  #endif /* defined(__linux__) */
> +
> +
> +VIR_ENUM_IMPL(virNetDevRxFilterUnicastMode,
> +  VIR_NETDEV_RX_FILTER_UNICAST_MODE_LAST,
> +  "none",
> +  "normal");
> +
> +VIR_ENUM_IMPL(virNetDevRxFilterMulticastMode,
> +  VIR_NETDEV_RX_FILTER_MULTICAST_MODE_LAST,
> +  "none",
> +  "normal");
> +
> +VIR_ENUM_IMPL(virNetDevRxFilterVlanMode,
> +  VIR_NETDEV_RX_FILTER_VLAN_MODE_LAST,
> +  "none",
> +  "normal");

Is there ever a chance these could be different for one of these types?
Seems "excessive" to make 3 specific definitions when 1 generic one
could suffice (drop the "Unicast, Multicast, Vlan")

> +
> +
> +virNetDevRxFilterPtr
> +virNetDevRxFilterNew(void)
> +{
> +virNetDevRxFilterPtr filter;
> +
> +if (VIR_ALLOC(filter) < 0)
> +return NULL;
> +return filter;
> +}
> +
> +
> +void
> +virNetDevRxFilterFree(virNetDevRxFilterPtr filter)
> +{
> +if (filter) {
> +VIR_FREE(filter->name);
> +VIR_FREE(filter->unicast.table);
> +VIR_FREE(filter->multicast.table);
> +VIR_FREE(filter->vlan.table);

I haven't peeked ahead yet, but are these tables where the allocation is
allocate space for 10 table entries, allocate entries in each array
entry... If so, then the free will need to run through the tables.

Reason why I ask is I see size_t's for each structure indicating to me
it's a array of entries.

> +VIR_FREE(filter);
> +}
> +}
> diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h
> index 69e365e..307871c 100644
> --- a/src/util/virnetdev.h
> +++ b/src/util/virnetdev.h
> @@ -1,5 +1,5 @@
>  /*
> - * Copyright (C) 2007-2013 Red Hat, Inc.
> + * Copyright (C) 2007-2014 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
> @@ -37,6 +37,57 @@ typedef struct ifreq virIfreq;
>  typedef void virIfreq;
>  # endif
>  
> +typedef enum {
> +   VIR_NETDEV_RX_FILTER_UNICAST_MODE_NONE = 0,
> +   VIR_NETDEV_RX_FILTER_UNICAST_MODE_NORMAL,
> +
> +   VIR_NETDEV_RX_FILTER_UNICAST_MODE_LAST
> +} virNetDevRxFilterUnicastMode;
> +VIR_ENUM_DECL(virNetDevRxFilterUnicastMode)
> +
> +typedef enum {
> +   VIR_NETDEV_RX_FILTER_MULTICAST_MODE_NONE = 0,
> +   VIR_NETDEV_RX_FILTER_MULTICAST_MODE_NORMAL,
> +
> +   VIR_NETDEV_RX_FILTER_MULTICAST_MODE_LAST
> +} virNetDevRxFilterMulticastMode;
> +VIR_ENUM_DECL(virNetDevRxFilterMulticastMode)
> +
> +typedef enum {
> +   VIR_NETDEV_RX_FILTER_VLAN_MODE_NONE = 0,
> +   VIR_NETDEV_RX_FILTER_VLAN_MODE_NORMAL,
> +
> +   VIR_NETDEV_RX_FILTER_VLAN_MODE_LAST
> +} virNetDevRxFilterVlanMode;
> +VIR_ENUM_DECL(virNetDevRxFilterVlanMode)

Same here with respect to generic rather than specific

> +
> +typedef struct _virNetDevRxFilter virNetDevRxFilter;
> +typedef virNetDevRxFilter *virNetDevRxFilterPtr;
> +struct _virNetDevRxFilter {
> +char *name; /* the alias used by qemu, *not* name used by guest */
> +virMacAddr mac;
> +bool promiscuous;
> +bool broadcastAllowed;
> +
> +struct {
> +int mode; /* enum virNetDevRxFilterUnicastMode */
> +bool overflow;
> +virMacAddrPtr table;
> +size_t nTable;
> +} unicast;
> +struct {
> +int mode; /* enum virNetDevRxFilterMulticastMode */
> +bool overflow;
> +virMacAddrPtr table;
> +size_t nTable;
> +} multicast;
> +struct {
> +int mode; /* enum virNetDevRxFilterVlanMode */
> +

Re: [libvirt] [PATCH 2/6] network: set interface actual trustGuestRxFilters from network/portgroup

2014-09-24 Thread John Ferlan


On 09/24/2014 05:50 AM, Laine Stump wrote:
> As is done with other items such as vlan, virtualport, and bandwidth,
> set the actual trustGuestRxFilters value to be used by a domain
> interface according to a merge of the same attribute in the interface,
> portgroup, and network in use. the interface setting always takes
> precedence (if specified), followed by portgroup, and finally the
> setting in the network is used if it's not specified in the interface
> or portgroup.
> ---
>  src/network/bridge_driver.c | 11 +++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
> index 979fb13..548e354 100644
> --- a/src/network/bridge_driver.c
> +++ b/src/network/bridge_driver.c
> @@ -3794,6 +3794,17 @@ networkAllocateActualDevice(virDomainDefPtr dom,
>  if (vlan && virNetDevVlanCopy(&iface->data.network.actual->vlan, vlan) < 
> 0)
>  goto error;
>  
> +if (iface->trustGuestRxFilters != VIR_TRISTATE_BOOL_ABSENT)
> +   iface->data.network.actual->trustGuestRxFilters
> +  = iface->trustGuestRxFilters;
> +else if (portgroup &&
> + portgroup->trustGuestRxFilters != VIR_TRISTATE_BOOL_ABSENT)
> +   iface->data.network.actual->trustGuestRxFilters
> +  = portgroup->trustGuestRxFilters;
> +else if (netdef->trustGuestRxFilters != VIR_TRISTATE_BOOL_ABSENT)
> +   iface->data.network.actual->trustGuestRxFilters
> +  = netdef->trustGuestRxFilters;
> +

Since BOOL_ABSENT is 0 - you don't "need" the comparison - it may look
cleaner too

ACK either way

John

>  if ((netdef->forward.type == VIR_NETWORK_FORWARD_NONE) ||
>  (netdef->forward.type == VIR_NETWORK_FORWARD_NAT) ||
>  (netdef->forward.type == VIR_NETWORK_FORWARD_ROUTE)) {
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/6] conf: add trustGuestRxFilters attribute to network and domain interface

2014-09-24 Thread John Ferlan


On 09/24/2014 05:50 AM, Laine Stump wrote:
> This new attribute will control whether or not libvirt will pay
> attention to guest notifications about changes to network device mac
> addresses and receive filters. The default for this is 'no' (for
> security reasons). If it is set to 'yes' *and* the specified device
> model and connection support it (currently only macvtap+virtio) then
> libvirt will watch for NIC_RX_FILTER_CHANGED events, and when it
> receives one, it will issue a query-rx-filter command, retrieve the
> result, and modify the host-side macvtap interface's mac address and
> unicast/multicast filters accordingly.
> 
> The functionality behind this attribute will be in a later patch. This
> patch merely adds the attribute to the top-level of a domain's
>  as well as to  and , and adds
> documentation and schema/xml2xml tests. Rather than adding even more
> test files, I've just added the net attribute in various applicable
> places of existing test files.
> ---
>  docs/formatdomain.html.in  | 38 
>  docs/formatnetwork.html.in | 28 +--
>  docs/schemas/domaincommon.rng  |  5 +++
>  docs/schemas/network.rng   | 10 ++
>  src/conf/domain_conf.c | 42 
> ++
>  src/conf/domain_conf.h |  3 ++
>  src/conf/network_conf.c| 35 ++
>  src/conf/network_conf.h|  2 ++
>  src/libvirt_private.syms   |  1 +
>  tests/networkxml2xmlin/vepa-net.xml|  4 +--
>  tests/networkxml2xmlout/vepa-net.xml   |  4 +--
>  .../qemuxml2argv-net-virtio-network-portgroup.xml  |  4 +--
>  12 files changed, 160 insertions(+), 16 deletions(-)
> 
> diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
> index eefdd5e..17e180d 100644
> --- a/docs/formatdomain.html.in
> +++ b/docs/formatdomain.html.in
> @@ -3343,10 +3343,9 @@
>  
>...
>
> -
> -  
> -  
> -