[ovs-dev] [PreQoS 08/13] netlink: Make nl_sock_transact() discard reply if 'replyp' is null.

Justin Pettit jpettit at nicira.com
Thu Jun 3 16:50:11 UTC 2010


Looks good.

--Justin


On May 27, 2010, at 1:33 PM, Ben Pfaff wrote:

> Sometimes only the success or failure return value is interesting, not the
> details of the reply, so this simplifies some callers.
> ---
> lib/netlink.c              |   19 ++++++++++++++-----
> vswitchd/proc-net-compat.c |    5 ++---
> 2 files changed, 16 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/netlink.c b/lib/netlink.c
> index 2ff20c8..35e2e92 100644
> --- a/lib/netlink.c
> +++ b/lib/netlink.c
> @@ -341,9 +341,12 @@ try_again:
> }
> 
> /* Sends 'request' to the kernel via 'sock' and waits for a response.  If
> - * successful, stores the reply into '*replyp' and returns 0.  The caller is
> - * responsible for destroying the reply with ofpbuf_delete().  On failure,
> - * returns a positive errno value and stores a null pointer into '*replyp'.
> + * successful, returns 0.  On failure, returns a positive errno value.
> + *
> + * If 'replyp' is nonnull, then on success '*replyp' is set to the kernel's
> + * reply, which the caller is responsible for freeing with ofpbuf_delete(), and
> + * on failure '*replyp' is set to NULL.  If 'replyp' is null, then the kernel's
> + * reply, if any, is discarded.
>  *
>  * nlmsg_len in 'msg' will be finalized to match msg->size, and nlmsg_pid will
>  * be set to 'sock''s pid, before the message is sent.  NLM_F_ACK will be set
> @@ -386,7 +389,9 @@ nl_sock_transact(struct nl_sock *sock,
>     struct ofpbuf *reply;
>     int retval;
> 
> -    *replyp = NULL;
> +    if (replyp) {
> +        *replyp = NULL;
> +    }
> 
>     /* Ensure that we get a reply even if this message doesn't ordinarily call
>      * for one. */
> @@ -425,7 +430,11 @@ recv:
>         return retval != EAGAIN ? retval : EPROTO;
>     }
> 
> -    *replyp = reply;
> +    if (replyp) {
> +        *replyp = reply;
> +    } else {
> +        ofpbuf_delete(reply);
> +    }
>     return 0;
> }
> 
> diff --git a/vswitchd/proc-net-compat.c b/vswitchd/proc-net-compat.c
> index 72eb7be..106a7c3 100644
> --- a/vswitchd/proc-net-compat.c
> +++ b/vswitchd/proc-net-compat.c
> @@ -72,7 +72,7 @@ proc_net_compat_init(void)
> static int
> set_proc_file(const char *dir, const char *file, const char *data)
> {
> -    struct ofpbuf request, *reply;
> +    struct ofpbuf request;
>     int retval;
> 
>     ofpbuf_init(&request, 0);
> @@ -84,9 +84,8 @@ set_proc_file(const char *dir, const char *file, const char *data)
>         nl_msg_put_string(&request, BRC_GENL_A_PROC_DATA, data);
>     }
> 
> -    retval = nl_sock_transact(brc_sock, &request, &reply);
> +    retval = nl_sock_transact(brc_sock, &request, NULL);
>     ofpbuf_uninit(&request);
> -    ofpbuf_delete(reply);
>     if (retval) {
>         VLOG_WARN_RL(&rl, "failed to %s /proc/%s/%s (%s)",
>                      data ? "update" : "remove", dir, file, strerror(retval));
> -- 
> 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