[ovs-dev] [fd leak v2 1/3] dpif-linux: Factor out port dumping helper functions.

Alex Wang alexw at nicira.com
Mon Nov 25 19:31:51 UTC 2013


LGTM, thx


On Sat, Nov 2, 2013 at 10:23 PM, Ben Pfaff <blp at nicira.com> wrote:

> These helpers simplify new code to be added in an upcoming commit.
>
> Signed-off-by: Ben Pfaff <blp at nicira.com>
> ---
>  lib/dpif-linux.c |   46 +++++++++++++++++++++++++++++++++-------------
>  1 file changed, 33 insertions(+), 13 deletions(-)
>
> diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c
> index 42958d3..783ef31 100644
> --- a/lib/dpif-linux.c
> +++ b/lib/dpif-linux.c
> @@ -699,46 +699,66 @@ struct dpif_linux_port_state {
>      struct nl_dump dump;
>  };
>
> -static int
> -dpif_linux_port_dump_start(const struct dpif *dpif_, void **statep)
> +static void
> +dpif_linux_port_dump_start__(const struct dpif *dpif_, struct nl_dump
> *dump)
>  {
>      const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
> -    struct dpif_linux_port_state *state;
>      struct dpif_linux_vport request;
>      struct ofpbuf *buf;
>
> -    *statep = state = xmalloc(sizeof *state);
> -
>      dpif_linux_vport_init(&request);
>      request.cmd = OVS_VPORT_CMD_GET;
>      request.dp_ifindex = dpif->dp_ifindex;
>
>      buf = ofpbuf_new(1024);
>      dpif_linux_vport_to_ofpbuf(&request, buf);
> -    nl_dump_start(&state->dump, NETLINK_GENERIC, buf);
> +    nl_dump_start(dump, NETLINK_GENERIC, buf);
>      ofpbuf_delete(buf);
> +}
> +
> +static int
> +dpif_linux_port_dump_start(const struct dpif *dpif, void **statep)
> +{
> +    struct dpif_linux_port_state *state;
> +
> +    *statep = state = xmalloc(sizeof *state);
> +    dpif_linux_port_dump_start__(dpif, &state->dump);
>
>      return 0;
>  }
>
> +static bool
> +dpif_linux_port_dump_next__(const struct dpif *dpif_, struct nl_dump
> *dump,
> +                            struct dpif_linux_vport *vport)
> +{
> +    struct dpif_linux *dpif = dpif_linux_cast(dpif_);
> +    struct ofpbuf buf;
> +    int error;
> +
> +    if (!nl_dump_next(dump, &buf)) {
> +        return EOF;
> +    }
> +
> +    error = dpif_linux_vport_from_ofpbuf(vport, &buf);
> +    if (error) {
> +        VLOG_WARN_RL(&error_rl, "%s: failed to parse vport record (%s)",
> +                     dpif_name(&dpif->dpif), ovs_strerror(error));
> +    }
> +    return error;
> +}
> +
>  static int
>  dpif_linux_port_dump_next(const struct dpif *dpif OVS_UNUSED, void
> *state_,
>                            struct dpif_port *dpif_port)
>  {
>      struct dpif_linux_port_state *state = state_;
>      struct dpif_linux_vport vport;
> -    struct ofpbuf buf;
>      int error;
>
> -    if (!nl_dump_next(&state->dump, &buf)) {
> -        return EOF;
> -    }
> -
> -    error = dpif_linux_vport_from_ofpbuf(&vport, &buf);
> +    error = dpif_linux_port_dump_next__(dpif, &state->dump, &vport);
>      if (error) {
>          return error;
>      }
> -
>      dpif_port->name = CONST_CAST(char *, vport.name);
>      dpif_port->type = CONST_CAST(char *, get_vport_type(&vport));
>      dpif_port->port_no = vport.port_no;
> --
> 1.7.10.4
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-dev/attachments/20131125/aa670e98/attachment-0003.html>


More information about the dev mailing list