From: Zoltan Kiss Date: Wed, 20 Jul 2016 17:16:38 +0000 (+0100) Subject: mempool: adjust name size in related data types X-Git-Tag: spdx-start~6132 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=38c9817ee1d8531bf099e954d5d66a531af9b8b8;p=dpdk.git mempool: adjust name size in related data types A recent patch brought up an issue about the size of the 'name' fields: 85cf0079 mem: avoid memzone/mempool/ring name truncation These relations should be observed: 1. Each ring creates a memzone with a prefixed name: RTE_RING_NAMESIZE <= RTE_MEMZONE_NAMESIZE - strlen(RTE_RING_MZ_PREFIX) 2. There are some mempool handlers which create a ring with a prefixed name: RTE_MEMPOOL_NAMESIZE <= RTE_RING_NAMESIZE - strlen(RTE_MEMPOOL_MZ_PREFIX) 3. A mempool can create up to RTE_MAX_MEMZONE pre and postfixed memzones: sprintf(postfix, "_%d", RTE_MAX_MEMZONE) RTE_MEMPOOL_NAMESIZE <= RTE_MEMZONE_NAMESIZE - strlen(RTE_MEMPOOL_MZ_PREFIX) - strlen(postfix) Setting all of them to 32 hides this restriction from the application. This patch decreases the mempool and ring string size to accommodate for these prefixes, but it doesn't apply the 3rd constraint. Applications relying on these constants need to be recompiled, otherwise they'll run into ENAMETOOLONG issues. The size of the arrays are kept 32 for ABI compatibility, it can be decreased next time the ABI changes. Signed-off-by: Zoltan Kiss Acked-by: Olivier Matz --- diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index 4a8fbb1e5b..059ad9e53d 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -123,7 +123,9 @@ struct rte_mempool_objsz { /**< Total size of an object (header + elt + trailer). */ }; -#define RTE_MEMPOOL_NAMESIZE 32 /**< Maximum length of a memory pool. */ +/**< Maximum length of a memory pool's name. */ +#define RTE_MEMPOOL_NAMESIZE (RTE_RING_NAMESIZE - \ + sizeof(RTE_MEMPOOL_MZ_PREFIX) + 1) #define RTE_MEMPOOL_MZ_PREFIX "MP_" /* "MP_" */ @@ -208,7 +210,12 @@ struct rte_mempool_memhdr { * The RTE mempool structure. */ struct rte_mempool { - char name[RTE_MEMPOOL_NAMESIZE]; /**< Name of mempool. */ + /* + * Note: this field kept the RTE_MEMZONE_NAMESIZE size due to ABI + * compatibility requirements, it could be changed to + * RTE_MEMPOOL_NAMESIZE next time the ABI changes + */ + char name[RTE_MEMZONE_NAMESIZE]; /**< Name of mempool. */ union { void *pool_data; /**< Ring or pool to store objects. */ uint64_t pool_id; /**< External mempool identifier. */ diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h index eb45e41449..0e22e6946f 100644 --- a/lib/librte_ring/rte_ring.h +++ b/lib/librte_ring/rte_ring.h @@ -100,6 +100,7 @@ extern "C" { #include #include #include +#include #define RTE_TAILQ_RING_NAME "RTE_RING" @@ -126,8 +127,10 @@ struct rte_ring_debug_stats { } __rte_cache_aligned; #endif -#define RTE_RING_NAMESIZE 32 /**< The maximum length of a ring name. */ #define RTE_RING_MZ_PREFIX "RG_" +/**< The maximum length of a ring name. */ +#define RTE_RING_NAMESIZE (RTE_MEMZONE_NAMESIZE - \ + sizeof(RTE_RING_MZ_PREFIX) + 1) #ifndef RTE_RING_PAUSE_REP_COUNT #define RTE_RING_PAUSE_REP_COUNT 0 /**< Yield after pause num of times, no yield @@ -147,7 +150,12 @@ struct rte_memzone; /* forward declaration, so as not to require memzone.h */ * a problem. */ struct rte_ring { - char name[RTE_RING_NAMESIZE]; /**< Name of the ring. */ + /* + * Note: this field kept the RTE_MEMZONE_NAMESIZE size due to ABI + * compatibility requirements, it could be changed to RTE_RING_NAMESIZE + * next time the ABI changes + */ + char name[RTE_MEMZONE_NAMESIZE]; /**< Name of the ring. */ int flags; /**< Flags supplied at creation. */ const struct rte_memzone *memzone; /**< Memzone, if any, containing the rte_ring */