From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com [209.85.212.175]) by dpdk.org (Postfix) with ESMTP id 4E51ECF9 for ; Wed, 15 Jul 2015 12:14:08 +0200 (CEST) Received: by widic2 with SMTP id ic2so59389490wid.0 for ; Wed, 15 Jul 2015 03:14:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=ktL45HvLPTNjWNrZeX1ss6Dv2nMRQgtJZejXmEszAk0=; b=JK1+5NnPM8U89ER0nzyklThc9z4Op//T4aCikWPbUgZb5S1S4QRxGKNgVqOMI/H1Sm RzJf+TwR/UBkgqwUusqk87AnZB1VFT5Doyfsv8rjggoOHHcyguU7FQO5ThsenZHTiwSv xaCwO0lUFdAUSnd2/zFAc2CwklZ3m0OP4FAdZkAXzXCkjLZ3onidjadwEVuMUJsF4lmr dKdIyakd1aaazA5dh9XSU5eyGLil2jgtqNYBcLVZ6oD9gLNcixiQtSYR0xP6e/gFK/I1 euX4RZpGF4r8dgOc0+vIOjQXXjKcCu73DAFwUhzuekPXCt4APa49gYcr4XS9G16ghD5J UW/Q== X-Gm-Message-State: ALoCoQmWTheW0QOiki53ojNh4K8kY944MxOY97qgwM4iGhSzCJcm+/heJkaiFJDsSOa1HVeWcTFh X-Received: by 10.194.118.197 with SMTP id ko5mr6751428wjb.58.1436955248163; Wed, 15 Jul 2015 03:14:08 -0700 (PDT) Received: from [10.16.0.195] (6wind.net2.nerim.net. [213.41.151.210]) by smtp.gmail.com with ESMTPSA id k2sm8354407wif.4.2015.07.15.03.14.07 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jul 2015 03:14:07 -0700 (PDT) Message-ID: <55A63269.7050105@6wind.com> Date: Wed, 15 Jul 2015 12:14:01 +0200 From: Olivier MATZ User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-Version: 1.0 To: Stephen Hemminger , dev@dpdk.org References: <1436485068-30609-1-git-send-email-stephen@networkplumber.org> <1436485068-30609-2-git-send-email-stephen@networkplumber.org> In-Reply-To: <1436485068-30609-2-git-send-email-stephen@networkplumber.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Cc: Mike Davison , Stephen Hemminger Subject: Re: [dpdk-dev] [PATCH 1/2] mbuf: Add rte_pktmbuf_copy X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jul 2015 10:14:08 -0000 On 07/10/2015 01:37 AM, Stephen Hemminger wrote: > From: Stephen Hemminger > > Added rte_pktmbuf_copy() function since copying multi-part > segments is common issue and can be problematic. > > Signed-off-by: Mike Davison > Reviewed-by: Stephen Hemminger > --- > lib/librte_mbuf/rte_mbuf.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 59 insertions(+) > > diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h > index 80419df..f0a543b 100644 > --- a/lib/librte_mbuf/rte_mbuf.h > +++ b/lib/librte_mbuf/rte_mbuf.h > @@ -60,6 +60,7 @@ > #include > #include > #include > +#include > > #ifdef __cplusplus > extern "C" { > @@ -1272,6 +1273,64 @@ static inline int rte_pktmbuf_is_contiguous(const struct rte_mbuf *m) > return !!(m->nb_segs == 1); > } > > +/* > + * Creates a copy of the given packet mbuf. > + * > + * Walks through all segments of the given packet mbuf, and for each of them: > + * - Creates a new packet mbuf from the given pool. > + * - Copy segment to newly created mbuf. > + * Then updates pkt_len and nb_segs of the new packet mbuf to match values > + * from the original packet mbuf. > + * > + * @param md > + * The packet mbuf to be copied. > + * @param mp > + * The mempool from which the mbufs are allocated. > + * @return > + * - The pointer to the new mbuf on success. > + * - NULL if allocation fails. > + */ > +static inline struct rte_mbuf *rte_pktmbuf_copy(struct rte_mbuf *md, > + struct rte_mempool *mp) > +{ > + struct rte_mbuf *mc = NULL; > + struct rte_mbuf **prev = &mc; > + > + do { > + struct rte_mbuf *mi; > + > + mi = rte_pktmbuf_alloc(mp); > + if (unlikely(mi == NULL)) { > + rte_pktmbuf_free(mc); > + return NULL; > + } > + I think we should check that the destination mbuf is large enough to store the segment data. Then we have 2 options on failure: - split the original segment into several destination segments - return an error > + mi->data_off = md->data_off; > + mi->data_len = md->data_len; > + mi->port = md->port; > + mi->vlan_tci = md->vlan_tci; > + mi->tx_offload = md->tx_offload; > + mi->hash = md->hash; > + > + mi->next = NULL; > + mi->pkt_len = md->pkt_len; > + mi->nb_segs = md->nb_segs; > + mi->ol_flags = md->ol_flags; > + mi->packet_type = md->packet_type; > + > + rte_memcpy(rte_pktmbuf_mtod(mi, char *), > + rte_pktmbuf_mtod(md, char *), > + md->data_len); > + > + *prev = mi; > + prev = &mi->next; > + } while ((md = md->next) != NULL); > + > + *prev = NULL; > + __rte_mbuf_sanity_check(mc, 1); > + return mc; > +} > + > /** > * Dump an mbuf structure to the console. > * >