From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 51A0D8DB3 for ; Fri, 22 Jan 2016 14:40:47 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 22 Jan 2016 05:40:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,331,1449561600"; d="scan'208";a="896082551" Received: from irsmsx102.ger.corp.intel.com ([163.33.3.155]) by orsmga002.jf.intel.com with ESMTP; 22 Jan 2016 05:40:45 -0800 Received: from irsmsx107.ger.corp.intel.com ([169.254.10.201]) by IRSMSX102.ger.corp.intel.com ([169.254.2.97]) with mapi id 14.03.0248.002; Fri, 22 Jan 2016 13:40:44 +0000 From: "Mrzyglod, DanielX T" To: Stephen Hemminger , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH 1/2] mbuf: Add rte_pktmbuf_copy Thread-Index: AQHQuqBSoqYWm4sX6kKbm3YYOBcqQp8IvfIw Date: Fri, 22 Jan 2016 13:40:44 +0000 Message-ID: <7ADD74816B4C8A45B56203CBA65FE5A63346A5A4@IRSMSX107.ger.corp.intel.com> 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> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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: Fri, 22 Jan 2016 13:40:47 -0000 >-----Original Message----- >From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Stephen Hemminger >Sent: Friday, July 10, 2015 1:38 AM >To: dev@dpdk.org >Cc: Mike Davison ; Stephen Hemminger > >Subject: [dpdk-dev] [PATCH 1/2] mbuf: Add rte_pktmbuf_copy > >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 =3D=3D 1); > } > >+/* >+ * Creates a copy of the given packet mbuf. >+ * >+ * Walks through all segments of the given packet mbuf, and for each of t= hem: >+ * - 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 value= s >+ * 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 =3D NULL; >+ struct rte_mbuf **prev =3D &mc; >+ >+ do { >+ struct rte_mbuf *mi; >+ >+ mi =3D rte_pktmbuf_alloc(mp); >+ if (unlikely(mi =3D=3D NULL)) { >+ rte_pktmbuf_free(mc); >+ return NULL; >+ } >+ >+ mi->data_off =3D md->data_off; >+ mi->data_len =3D md->data_len; >+ mi->port =3D md->port; >+ mi->vlan_tci =3D md->vlan_tci; >+ mi->tx_offload =3D md->tx_offload; >+ mi->hash =3D md->hash; >+ >+ mi->next =3D NULL; >+ mi->pkt_len =3D md->pkt_len; >+ mi->nb_segs =3D md->nb_segs; >+ mi->ol_flags =3D md->ol_flags; >+ mi->packet_type =3D md->packet_type; >+ >+ rte_memcpy(rte_pktmbuf_mtod(mi, char *), >+ rte_pktmbuf_mtod(md, char *), >+ md->data_len); >+ >+ *prev =3D mi; >+ prev =3D &mi->next; >+ } while ((md =3D md->next) !=3D NULL); >+ >+ *prev =3D NULL; >+ __rte_mbuf_sanity_check(mc, 1); >+ return mc; >+} >+ > /** > * Dump an mbuf structure to the console. > * >-- >2.1.4 Hi Stephen :> This patch look useful in case of backup buffs.=20 There will be second approach ?