From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <olivier.matz@6wind.com>
Received: from mail.droids-corp.org (zoll.droids-corp.org [94.23.50.67])
 by dpdk.org (Postfix) with ESMTP id 6DBF28E01
 for <dev@dpdk.org>; Tue,  3 Apr 2018 10:26:23 +0200 (CEST)
Received: from lfbn-lil-1-702-109.w81-254.abo.wanadoo.fr ([81.254.39.109]
 helo=droids-corp.org)
 by mail.droids-corp.org with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.89) (envelope-from <olivier.matz@6wind.com>)
 id 1f3HHJ-0004sF-W8; Tue, 03 Apr 2018 10:26:55 +0200
Received: by droids-corp.org (sSMTP sendmail emulation);
 Tue, 03 Apr 2018 10:26:15 +0200
Date: Tue, 3 Apr 2018 10:26:15 +0200
From: Olivier Matz <olivier.matz@6wind.com>
To: Yongseok Koh <yskoh@mellanox.com>
Cc: wenzhuo.lu@intel.com, jingjing.wu@intel.com, adrien.mazarguil@6wind.com,
 nelio.laranjeiro@6wind.com, dev@dpdk.org
Message-ID: <20180403082615.etnr33cuyey7i3u3@platinum>
References: <20180310012532.15809-1-yskoh@mellanox.com>
 <20180402185008.13073-1-yskoh@mellanox.com>
 <20180402185008.13073-2-yskoh@mellanox.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20180402185008.13073-2-yskoh@mellanox.com>
User-Agent: NeoMutt/20170113 (1.7.2)
Subject: Re: [dpdk-dev] [PATCH v2 1/6] mbuf: add buffer offset field for
 flexible indirection
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Tue, 03 Apr 2018 08:26:23 -0000

Hi,

On Mon, Apr 02, 2018 at 11:50:03AM -0700, Yongseok Koh wrote:
> When attaching a mbuf, indirect mbuf has to point to start of buffer of
> direct mbuf. By adding buf_off field to rte_mbuf, this becomes more
> flexible. Indirect mbuf can point to any part of direct mbuf by calling
> rte_pktmbuf_attach_at().
> 
> Possible use-cases could be:
> - If a packet has multiple layers of encapsulation, multiple indirect
>   buffers can reference different layers of the encapsulated packet.
> - A large direct mbuf can even contain multiple packets in series and
>   each packet can be referenced by multiple mbuf indirections.
> 
> Signed-off-by: Yongseok Koh <yskoh@mellanox.com>

I think the current API is already able to do what you want.

1/ Here is a mbuf m with its data

               off
               <-->
                      len
          +----+   <---------->
          |    |
        +-|----v----------------------+
        | |    -----------------------|
m       | buf  |    XXXXXXXXXXX      ||
        |      -----------------------|
        +-----------------------------+


2/ clone m:

  c = rte_pktmbuf_alloc(pool);
  rte_pktmbuf_attach(c, m);

  Note that c has its own offset and length fields.


               off
               <-->
                      len
          +----+   <---------->
          |    |
        +-|----v----------------------+
        | |    -----------------------|
m       | buf  |    XXXXXXXXXXX      ||
        |      -----------------------|
        +------^----------------------+
               |
          +----+
indirect  |
        +-|---------------------------+
        | |    -----------------------|
c       | buf  |                     ||
        |      -----------------------|
        +-----------------------------+

                off    len
                <--><---------->


3/ remove some data from c without changing m

   rte_pktmbuf_adj(c, 10)   // at head
   rte_pktmbuf_trim(c, 10)  // at tail


Please let me know if it fits your needs.

Regards,
Olivier