<br><tt><font size=2>Eric Blake <eblake@redhat.com> wrote on 05/10/2010
12:48:18 PM:<br>
<br>
<br>
> libvir-list</font></tt>
<br><tt><font size=2>> <br>
> On 05/07/2010 12:09 PM, Stefan Berger wrote:<br>
> > In this patch I am adding functions that help to iteratively
determine<br>
> > the root physical interface of a given interface. An example
would be<br>
> > that a macvtap device is linked to eth0.100 which in turn is
linked to<br>
> > eth0. Given the name or interface index of the macvtap device
that is<br>
> > linked to eth0.100, eth0 is found by following the links to the
end. I<br>
> > am using now the netlink library to parse the returned netlink
messages<br>
> > and for that I am making additions to configure.ac and the rpm
spec file<br>
> > to check for the netlink and netlink-devel packages respectively.
In the<br>
> > configure.ac the requirement to have the netlink library is dependent
on<br>
> > having macvtap.<br>
> > <br>
> >  <br>
> > +static struct nla_policy ifla_policy[ IFLA_MAX + 1] =<br>
> > +{<br>
> > +  [IFLA_IFNAME ]    = {.type = NLA_STRING },<br>
> > +  [IFLA_LINK]       = {.type = NLA_U32 },<br>
> > +};<br>
> <br>
> Spacing is inconsistent here.  How about:<br>
> <br>
> static struct nla_policy ifla_policy[IFLA_MAX + 1] = {<br>
>   [IFLA_IFNAME]   = { .type = NLA_STRING },<br>
>   [IFLA_LINK]     = { .type = NLA_U32 },<br>
> };</font></tt>
<br>
<br><tt><font size=2>Ok. Done.</font></tt>
<br>
<br><tt><font size=2><br>
> <br>
> <br>
> > +<br>
> > +<br>
> > +static int<br>
> > +link_dump(int ifindex, const char *ifname, struct nlattr **tb,<br>
> > +          char **recvbuf)<br>
> > +{<br>
> > +    int rc = 0;<br>
> > +    char nlmsgbuf[256];<br>
> <br>
> Is there a #define for this, to avoid a magic number?</font></tt>
<br>
<br><tt><font size=2>I replaced this with a #define now. Also 2 other places
were touched.</font></tt>
<br>
<br><tt><font size=2><br>
> <br>
> > +    struct nlmsghdr *nlm = (struct nlmsghdr *)nlmsgbuf,
*resp;<br>
> > +    struct nlmsgerr *err;<br>
> > +    char rtattbuf[64];<br>
> <br>
> Likewise.</font></tt>
<br>
<br><tt><font size=2>Introduced #define.</font></tt>
<br><tt><font size=2><br>
> <br>
> > +    struct rtattr *rta;<br>
> > +    struct ifinfomsg i = {<br>
> > +        .ifi_family = AF_UNSPEC,<br>
> > +        .ifi_index  = ifindex<br>
> > +    };<br>
> > +    int recvbuflen;<br>
> > +<br>
> > +    *recvbuf = NULL;<br>
> > +<br>
> > +    memset(&nlmsgbuf, 0, sizeof(nlmsgbuf));<br>
> <br>
> Instead of using memset here, I would zero-initialize the array at
its<br>
> declaration:<br>
> <br>
> char nlmsgbuf[256] = { 0 };</font></tt>
<br>
<br><tt><font size=2>Doing that now.</font></tt>
<br><tt><font size=2><br>
> <br>
> I'm not sure whether gcc generates code any differently for the two
styles.<br>
> <br>
> > +<br>
> > +    nlInit(nlm, NLM_F_REQUEST, RTM_GETLINK);<br>
> > +<br>
> > +    if (!nlAppend(nlm, sizeof(nlmsgbuf), &i, sizeof(i)))<br>
> > +        goto buffer_too_small;<br>
> > +<br>
> > +    if (ifindex < 0 && ifname != NULL)
{<br>
> > +        rta = rtattrCreate(rtattbuf, sizeof(rtattbuf),
IFLA_IFNAME,<br>
> > +                  
        ifname, strlen(ifname)+1);<br>
> <br>
> Spacing: strlen(ifname) + 1</font></tt>
<br>
<br><tt><font size=2>Done.</font></tt>
<br><tt><font size=2><br>
> <br>
> > +        if (!rta)<br>
> > +            goto buffer_too_small;<br>
> > +<br>
> > +        if (!nlAppend(nlm, sizeof(nlmsgbuf),
rtattbuf, rta->rta_len))<br>
> > +            goto buffer_too_small;<br>
> > +    }<br>
> > +<br>
> > +    if (nlComm(nlm, recvbuf, &recvbuflen) <
0)<br>
> > +        return -1;<br>
> > +<br>
> > +    if (recvbuflen < NLMSG_LENGTH(0) || *recvbuf
== NULL)<br>
> > +        goto malformed_resp;<br>
> > +<br>
> > +    resp = (struct nlmsghdr *)*recvbuf;<br>
> > +<br>
> > +    switch (resp->nlmsg_type) {<br>
> > +    case NLMSG_ERROR:<br>
> > +        err = (struct nlmsgerr *)NLMSG_DATA(resp);<br>
> > +        if (resp->nlmsg_len < NLMSG_LENGTH(sizeof(*err)))<br>
> > +            goto malformed_resp;<br>
> > +<br>
> > +        switch (-err->error) {<br>
> > +        case 0:<br>
> > +        break;<br>
> > +<br>
> > +        default:<br>
> <br>
> Given that you have only one non-default case, is this worth a switch,<br>
> or is it simpler to write as 'if (err->error)'?</font></tt>
<br>
<br><tt><font size=2>For consistency reasons with the other code I'd like
to keep it that way.</font></tt>
<br>
<br><tt><font size=2><br>
> > +<br>
> > +    if (nth)<br>
> > +        *nth = i-1;<br>
> <br>
> Spacing: i - 1</font></tt>
<br>
<br><tt><font size=2>Done.</font></tt>
<br><tt><font size=2><br>
<br>
> > ===================================================================<br>
> > --- libvirt-acl.orig/src/Makefile.am<br>
> > +++ libvirt-acl/src/Makefile.am<br>
> > @@ -932,7 +932,7 @@ libvirt_la_LDFLAGS = $(VERSION_SCRIPT_FL<br>
> >                  
    -version-info $(LIBVIRT_VERSION_INFO) \<br>
> >                  
   $(COVERAGE_CFLAGS:-f%=-Wc,-f%) \<br>
> >                  
   $(LIBXML_LIBS) \<br>
> > -                  
 $(LIBPCAP_LIBS) \<br>
> > +                  
 $(LIBPCAP_LIBS) $(LIBNL_LIBS) \<br>
> >            $(DRIVER_MODULE_LIBS)
\<br>
> >            $(CYGWIN_EXTRA_LDFLAGS)
$(MINGW_EXTRA_LDFLAGS)<br>
> >  libvirt_la_CFLAGS = $(COVERAGE_CFLAGS) -DIN_LIBVIRT<br>
> > @@ -985,7 +985,7 @@ libvirt_lxc_SOURCES =      
           \<br>
> >        $(NWFILTER_PARAM_CONF_SOURCES)<br>
> >  libvirt_lxc_LDFLAGS = $(WARN_CFLAGS) $(COVERAGE_LDCFLAGS)
$<br>
> (CAPNG_LIBS) $(YAJL_LIBS)<br>
> >  libvirt_lxc_LDADD = $(LIBXML_LIBS) $(NUMACTL_LIBS) $(LIB_PTHREAD)
\<br>
> > -      ../gnulib/lib/libgnu.la<br>
> > +      $(LIBNL_LIBS) ../gnulib/lib/libgnu.la<br>
> <br>
> When rebasing this patch, remember that these additions go in LIBADD,<br>
> not LDADD.</font></tt>
<br>
<br><tt><font size=2>I saw that this was changed for the above. I am not
introducing </font></tt>
<br>
<br><tt><font size=2><br>
> > +if test "$with_macvtap" = "yes"; then<br>
> > +    PKG_CHECK_MODULES(LIBNL, libnl-1 >= $LIBNL_REQUIRED,
[<br>
> <br>
> Missing M4 quoting:<br>
> <br>
> PKG_CHECK_MODULES([LIBNL], [libnl-1 >= $LIBNL_REQUIRED], [</font></tt>
<br>
<br><tt><font size=2>Yes. Majority is without so far...</font></tt>
<br>
<br><tt><font size=2>> <br>
> I think I mentioned enough things that it's worth seeing a v2 before<br>
> giving an ack.</font></tt>
<br>
<br><tt><font size=2>I'll post v2 shortly.</font></tt>
<br>
<br><tt><font size=2>   Stefan</font></tt>
<br>