[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 3/5] virDomainNetDefParseXML: suppress generation of MAC when VIR_DOMAIN_PARSE_NO_GENERATE is set



On Thu, Mar 17, 2011 at 12:55:50PM -0400, Laine Stump wrote:
> On 03/17/2011 10:38 AM, Michal Privoznik wrote:
> >---
> >  src/conf/domain_conf.c |   11 ++++++++---
> >  1 files changed, 8 insertions(+), 3 deletions(-)
> >
> >diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> >index c2c7057..7f9c178 100644
> >--- a/src/conf/domain_conf.c
> >+++ b/src/conf/domain_conf.c
> >@@ -2491,8 +2491,7 @@ virDomainNetDefParseXML(virCapsPtr caps,
> >      xmlNodePtr oldnode = ctxt->node;
> >      int ret;
> >
> >-    if ((VIR_ALLOC(def)<  0) ||
> >-        (VIR_ALLOC_N(def->mac,VIR_MAC_BUFLEN)<  0)) {
> >+    if (VIR_ALLOC(def)<  0) {
> >          virReportOOMError();
> >          return NULL;
> >      }
> >@@ -2588,6 +2587,12 @@ virDomainNetDefParseXML(virCapsPtr caps,
> >          cur = cur->next;
> >      }
> >
> >+    if ((macaddr || !(flags&  VIR_DOMAIN_PARSE_NO_GENERATE))&&
> >+        (VIR_ALLOC_N(def->mac, VIR_MAC_BUFLEN)<  0)) {
> >+        virReportOOMError();
> >+        goto error;
> >+    }
> >+
> >      if (macaddr) {
> >          if (virParseMacAddr((const char *)macaddr, def->mac)<  0) {
> >              virDomainReportError(VIR_ERR_INTERNAL_ERROR,
> >@@ -2595,7 +2600,7 @@ virDomainNetDefParseXML(virCapsPtr caps,
> >                                   (const char *)macaddr);
> >              goto error;
> >          }
> >-    } else {
> >+    } else if (!(flags&  VIR_DOMAIN_PARSE_NO_GENERATE)) {
> >          virCapabilitiesGenerateMac(caps, def->mac);
> 
> I'm going to voice my dislike of side-effects in Parse functions one
> last time (I think that a function called "...Parse" should
> interpret the data it's given, not add new data) and suggest that
> the Mac generation should always be done in the caller when needed
> rather than passing a strange flag down to the parser. (I know the
> parser was already generating the MAC; I think it should be changed
> to *not* do that) (or at the very least the flag shouldn't be "on ==
> don't do something extra", it should be "on == do something extra").

I understand your point, but the main issue with this is that there
a very many places where virDomainDefParseXML is called, and nearly
all of them require automatic MAC generation if omitted. If we pushed
that into the callers, then we'd trivally miss places where MAC
generation was required, and never notice until someone wonders why
a VM is getting a NIC with mac of all-zeroes.

In this specific case, rather than turning off MAC generation, what we
actually want to do is *mandate* that the MAC is always present in the
XML we're given. When detaching a NIC, it is never acceptable to leave
out the MAC addr. So I'd have a flag VIR_DOMAIN_PARSE_REQUIRE_MAC
and thus raise a fatal if omitted from the XML

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]