[ovs-dev] [PreQoS 13/13] netdev-linux: Create rtnetlink socket up front instead of on demand.

Ben Pfaff blp at nicira.com
Tue Jun 8 18:52:04 UTC 2010


Thanks, fixed.

On Thu, Jun 03, 2010 at 10:17:02AM -0700, Justin Pettit wrote:
> I didn't actually apply all the patches, so maybe I missed it, but
> shouldn't you get rid of the rtnl_sock declaration and call to
> get_rtnl_sock() in netdev_linux_remove_policing()?
> 
> Otherwise, looks good.
> 
> --Justin
> 
> 
> On May 27, 2010, at 1:33 PM, Ben Pfaff wrote:
> 
> > This simplifies a bit of existing code since it is known that an rtnetlink
> > socket will always be available.  It will simplify additional code in
> > upcoming patches.
> > ---
> > lib/netdev-linux.c |   45 ++++++++++++++-------------------------------
> > 1 files changed, 14 insertions(+), 31 deletions(-)
> > 
> > diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
> > index 554c5b0..6cab35b 100644
> > --- a/lib/netdev-linux.c
> > +++ b/lib/netdev-linux.c
> > @@ -122,6 +122,9 @@ struct netdev_linux {
> > /* An AF_INET socket (used for ioctl operations). */
> > static int af_inet_sock = -1;
> > 
> > +/* A Netlink routing socket that is not subscribed to any multicast groups. */
> > +static struct nl_sock *rtnl_sock;
> > +
> > struct netdev_linux_notifier {
> >     struct netdev_notifier notifier;
> >     struct list node;
> > @@ -155,7 +158,6 @@ static int set_etheraddr(const char *netdev_name, int hwaddr_family,
> >                          const uint8_t[ETH_ADDR_LEN]);
> > static int get_stats_via_netlink(int ifindex, struct netdev_stats *stats);
> > static int get_stats_via_proc(const char *netdev_name, struct netdev_stats *stats);
> > -static int get_rtnl_sock(struct nl_sock **);
> > 
> > static bool
> > is_netdev_linux_class(const struct netdev_class *netdev_class)
> > @@ -181,17 +183,27 @@ netdev_linux_cast(const struct netdev *netdev)
> > 
> >     return CONTAINER_OF(netdev, struct netdev_linux, netdev);
> > }
> > -
> > +
> > static int
> > netdev_linux_init(void)
> > {
> >     static int status = -1;
> >     if (status < 0) {
> > +        /* Create AF_INET socket. */
> >         af_inet_sock = socket(AF_INET, SOCK_DGRAM, 0);
> >         status = af_inet_sock >= 0 ? 0 : errno;
> >         if (status) {
> >             VLOG_ERR("failed to create inet socket: %s", strerror(status));
> >         }
> > +
> > +        /* Create rtnetlink socket. */
> > +        if (!status) {
> > +            status = nl_sock_create(NETLINK_ROUTE, 0, 0, 0, &rtnl_sock);
> > +            if (status) {
> > +                VLOG_ERR_RL(&rl, "failed to create rtnetlink socket: %s",
> > +                            strerror(status));
> > +            }
> > +        }
> >     }
> >     return status;
> > }
> > @@ -1698,7 +1710,6 @@ get_stats_via_netlink(int ifindex, struct netdev_stats *stats)
> >                          .min_len = sizeof(struct rtnl_link_stats) },
> >     };
> > 
> > -    struct nl_sock *rtnl_sock;
> >     struct ofpbuf request;
> >     struct ofpbuf *reply;
> >     struct ifinfomsg *ifi;
> > @@ -1706,11 +1717,6 @@ get_stats_via_netlink(int ifindex, struct netdev_stats *stats)
> >     struct nlattr *attrs[ARRAY_SIZE(rtnlgrp_link_policy)];
> >     int error;
> > 
> > -    error = get_rtnl_sock(&rtnl_sock);
> > -    if (error) {
> > -        return error;
> > -    }
> > -
> >     ofpbuf_init(&request, 0);
> >     nl_msg_put_nlmsghdr(&request, sizeof *ifi, RTM_GETLINK, NLM_F_REQUEST);
> >     ifi = ofpbuf_put_zeros(&request, sizeof *ifi);
> > @@ -1971,26 +1977,3 @@ netdev_linux_get_ipv4(const struct netdev *netdev, struct in_addr *ip,
> >     }
> >     return error;
> > }
> > -
> > -/* Obtains a Netlink routing socket that is not subscribed to any multicast
> > - * groups.  Returns 0 if successful, otherwise a positive errno value.  Stores
> > - * the socket in '*rtnl_sockp' if successful, otherwise a null pointer. */
> > -static int
> > -get_rtnl_sock(struct nl_sock **rtnl_sockp)
> > -{
> > -    static struct nl_sock *sock;
> > -    int error;
> > -
> > -    if (!sock) {
> > -        error = nl_sock_create(NETLINK_ROUTE, 0, 0, 0, &sock);
> > -        if (error) {
> > -            VLOG_ERR_RL(&rl, "failed to create rtnetlink socket: %s",
> > -                        strerror(error));
> > -        }
> > -    } else {
> > -        error = 0;
> > -    }
> > -
> > -    *rtnl_sockp = sock;
> > -    return error;
> > -}
> > -- 
> > 1.7.1
> > 
> > 
> > _______________________________________________
> > dev mailing list
> > dev at openvswitch.org
> > http://openvswitch.org/mailman/listinfo/dev_openvswitch.org
> 




More information about the dev mailing list