mbuf: fix dynamic fields and flags with multiprocess
authorStephen Hemminger <stephen@networkplumber.org>
Wed, 4 Nov 2020 16:20:00 +0000 (08:20 -0800)
committerDavid Marchand <david.marchand@redhat.com>
Wed, 4 Nov 2020 19:47:14 +0000 (20:47 +0100)
The dynamic flag management is broken if rte_mbuf_dynflag_lookup()
is done in a secondary process because the local pointer to
the memzone is not ever initialized.

Fix it by using the same checks as dynfield_register().
I.e if shared memory zone has not been looked up already,
then discover it.

Fixes: 4958ca3a443a ("mbuf: support dynamic fields and flags")
Cc: stable@dpdk.org
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
lib/librte_mbuf/rte_mbuf_dyn.c

index e10f4fb..fd3e019 100644 (file)
@@ -174,7 +174,7 @@ __mbuf_dynfield_lookup(const char *name)
                        break;
        }
 
-       if (te == NULL) {
+       if (te == NULL || mbuf_dynfield == NULL) {
                rte_errno = ENOENT;
                return NULL;
        }
@@ -187,19 +187,15 @@ rte_mbuf_dynfield_lookup(const char *name, struct rte_mbuf_dynfield *params)
 {
        struct mbuf_dynfield_elt *mbuf_dynfield;
 
-       if (shm == NULL) {
-               rte_errno = ENOENT;
-               return -1;
-       }
-
        rte_mcfg_tailq_read_lock();
-       mbuf_dynfield = __mbuf_dynfield_lookup(name);
+       if (shm == NULL && init_shared_mem() < 0)
+               mbuf_dynfield = NULL;
+       else
+               mbuf_dynfield = __mbuf_dynfield_lookup(name);
        rte_mcfg_tailq_read_unlock();
 
-       if (mbuf_dynfield == NULL) {
-               rte_errno = ENOENT;
+       if (mbuf_dynfield == NULL)
                return -1;
-       }
 
        if (params != NULL)
                memcpy(params, &mbuf_dynfield->params, sizeof(*params));
@@ -386,19 +382,15 @@ rte_mbuf_dynflag_lookup(const char *name,
 {
        struct mbuf_dynflag_elt *mbuf_dynflag;
 
-       if (shm == NULL) {
-               rte_errno = ENOENT;
-               return -1;
-       }
-
        rte_mcfg_tailq_read_lock();
-       mbuf_dynflag = __mbuf_dynflag_lookup(name);
+       if (shm == NULL && init_shared_mem() < 0)
+               mbuf_dynflag = NULL;
+       else
+               mbuf_dynflag = __mbuf_dynflag_lookup(name);
        rte_mcfg_tailq_read_unlock();
 
-       if (mbuf_dynflag == NULL) {
-               rte_errno = ENOENT;
+       if (mbuf_dynflag == NULL)
                return -1;
-       }
 
        if (params != NULL)
                memcpy(params, &mbuf_dynflag->params, sizeof(*params));