From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202508 header.b=lkTGdUEo; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id C7CEE5A0279 for ; Wed, 06 Aug 2025 04:23:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202508; t=1754447034; bh=qIT/9TB+ipK7XfgRK38ki9ibl/x5gypfWoUoJekpP1g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lkTGdUEoXtRWAczNpATGkJbFl95RRSW2DZydJtwub7Vdqc8sF67m1M9KF13k+Iz4Z eDyU1dsV5ra76B6tPzS0zZbFg6SZxTPmLJyn17F+X52ypOcL9vqcMwmGIvfXg8+pMJ bNd++N2Ny3vcB0V0S64ft+ctEg/GXNeljuwPF5ce/gflUOJSnOvki0keWDSMFtI7py p50H0HPqx8xPyYAe4YcQlyfZX7gYr/9Sg5O2jGJ+SU4G6YUzto+IUmm2TRblSVnRK4 iC9+2e+ka1v3HJFLmm+Bouvd4BE7zEGChgEV2PqTCYZIRaq5kYcGPdC4/KvkcoGMub lmB9pH7xpZ7SQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4bxYy23Pt9z4xZh; Wed, 6 Aug 2025 12:23:54 +1000 (AEST) Date: Wed, 6 Aug 2025 12:14:28 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v8 06/30] packet: Add packet_data() Message-ID: References: <20250805154628.301343-1-lvivier@redhat.com> <20250805154628.301343-7-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="tqOqnPrQOAh+/4C7" Content-Disposition: inline In-Reply-To: <20250805154628.301343-7-lvivier@redhat.com> Message-ID-Hash: XUABO77YMNPJGE3VL6VR6UU5KLANM7L4 X-Message-ID-Hash: XUABO77YMNPJGE3VL6VR6UU5KLANM7L4 X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --tqOqnPrQOAh+/4C7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Aug 05, 2025 at 05:46:04PM +0200, Laurent Vivier wrote: > packet_data() gets the data range from a packet descriptor from a > given pool. >=20 > It uses iov_tail to return the packet memory. >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson I assume the idea is to eventually replace packet_get() with this? > --- > packet.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > packet.h | 5 +++++ > 2 files changed, 47 insertions(+) >=20 > diff --git a/packet.c b/packet.c > index 98ded4e27aae..82adc9fd1a39 100644 > --- a/packet.c > +++ b/packet.c > @@ -190,6 +190,48 @@ void *packet_get_do(const struct pool *p, const size= _t idx, > return r; > } > =20 > +/** > + * packet_data_do() - Get data range from packet descriptor from given p= ool > + * @p: Packet pool > + * @idx: Index of packet descriptor in pool > + * @data: IOV tail to store the address of the data (output) > + * @func: For tracing: name of calling function, NULL means no trace() > + * @line: For tracing: caller line of function call > + * > + * Return: false if packet index is invalid, true otherwise. > + * If something wrong with @data, don't return at all (assert). > + */ > +/* cppcheck-suppress unusedFunction */ > +bool packet_data_do(const struct pool *p, size_t idx, > + struct iov_tail *data, > + const char *func, int line) > +{ > + size_t i; > + > + ASSERT_WITH_MSG(p->count <=3D p->size, > + "Corrupted pool count: %zu, size: %zu, %s:%i", > + p->count, p->size, func, line); > + > + if (idx >=3D p->count) { > + debug("packet %zu from pool size: %zu, count: %zu, " > + "%s:%i", idx, p->size, p->count, func, line); > + return false; > + } > + > + data->cnt =3D 1; > + data->off =3D 0; > + data->iov =3D &p->pkt[idx]; > + > + for (i =3D 0; i < data->cnt; i++) { > + ASSERT_WITH_MSG(!packet_check_range(p, data->iov[i].iov_base, > + data->iov[i].iov_len, > + func, line), > + "Corrupt packet pool, %s:%i", func, line); > + } > + > + return true; > +} > + > /** > * pool_flush() - Flush a packet pool > * @p: Pointer to packet pool > diff --git a/packet.h b/packet.h > index af40b39b5251..062afb978124 100644 > --- a/packet.h > +++ b/packet.h > @@ -39,6 +39,9 @@ void *packet_get_try_do(const struct pool *p, const siz= e_t idx, > void *packet_get_do(const struct pool *p, const size_t idx, > size_t offset, size_t len, size_t *left, > const char *func, int line); > +bool packet_data_do(const struct pool *p, const size_t idx, > + struct iov_tail *data, > + const char *func, int line); > bool pool_full(const struct pool *p); > void pool_flush(struct pool *p); > =20 > @@ -49,6 +52,8 @@ void pool_flush(struct pool *p); > packet_get_try_do(p, idx, offset, len, left, __func__, __LINE__) > #define packet_get(p, idx, offset, len, left) \ > packet_get_do(p, idx, offset, len, left, __func__, __LINE__) > +#define packet_data(p, idx, data) \ > + packet_data_do(p, idx, data, __func__, __LINE__) > =20 > #define PACKET_POOL_DECL(_name, _size, _buf) \ > struct _name ## _t { \ --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --tqOqnPrQOAh+/4C7 Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmiSunYACgkQzQJF27ox 2GeW7w/9GqJTEspOLeWJbFeKtLVSXS1HjOXQ96qt3oxzLqh2Oe2KXrwNREuD/Ccp LVUmz9R8iIrAA4ICWVBeVfPgR39hyEctSfeU0Bq/Dw0N+9H/DGUnBQbDNbOr2pef Z01sATjd3m2rvm5qEilPdECA6IJdU8XfTQzXy99UClXgDzPFZEYeThhVQ567RVVf mmPlzM045k0+ssISCXDsYvBh4EM89RGa6Z4ofqdtiOTIARzUUhv+T7prY5u8p4e6 JN8yBwFJMdd8kSFK0JASdb6C+a7vma2BaZJbQd9rXtgcLgWQVuYd7vywb8OsMe2Q 4DmbaBBkKp+TJR7tcZQ+h4S60dP+rn10uBKylOTmi5H9nRRwZnniVabm8IRQIz2x 1C2BFnUJxbXH4iwQAop8ht2v138ax5ak5AA6zkDMkpSWxrmqAtGq4zH7fNrBSS3u B9xvEfE1Yvc2JFkMGCDSVIIMPTgRTXUzPweYpfZ7Qv9TGA1ZUPG65wAR6/3fHPLh 2hzwxt5GUN/lbNs2Id4vjsNmicveMR087ipUJRPlgnP1hfKUHu09TpaMYlrZTVjb 3yszy6bdzItP1TMzqsGgAGPBEd6f/CwJyRXC/eGj+f//WP+eaP8IhAXWx//qCNr1 N7iGQaLv2SpPoGWA4niI+SRYkFoqj/l05dBOahnoInN4QCkg+6w= =uD6T -----END PGP SIGNATURE----- --tqOqnPrQOAh+/4C7--