[PATCH v2] lib: Remove flows list from fset

  • From: Dimitri Staessens <dimitri@ouroboros.rocks>
  • To: ouroboros@xxxxxxxxxxxxx
  • Date: Mon, 28 Mar 2022 11:44:43 +0200

We don't need to iterate fsets anymore since the removal of fset_keepalive.

Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
---
 src/lib/dev.c | 64 ++-------------------------------------------------
 1 file changed, 2 insertions(+), 62 deletions(-)

diff --git a/src/lib/dev.c b/src/lib/dev.c
index 9709c427..705a474b 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -114,16 +114,8 @@ struct flow {
         struct frcti *        frcti;
 };
 
-struct flow_set_entry {
-        struct list_head next;
-
-        int fd;
-};
-
 struct flow_set {
         size_t           idx;
-
-        struct list_head flows;
         pthread_rwlock_t lock;
 };
 
@@ -367,6 +359,7 @@ static void flow_fini(int fd)
                         pthread_cancel(ai.tx);
                         pthread_join(ai.tx, NULL);
                 }
+
                 frcti_destroy(ai.flows[fd].frcti);
         }
 
@@ -1436,9 +1429,6 @@ struct flow_set * fset_create()
         if (set == NULL)
                 goto fail_malloc;
 
-        if (pthread_rwlock_init(&set->lock, NULL))
-                goto fail_lock_init;
-
         assert(ai.fqueues);
 
         pthread_rwlock_wrlock(&ai.lock);
@@ -1449,14 +1439,10 @@ struct flow_set * fset_create()
 
         pthread_rwlock_unlock(&ai.lock);
 
-        list_head_init(&set->flows);
-
         return set;
 
  fail_bmp_alloc:
         pthread_rwlock_unlock(&ai.lock);
-        pthread_rwlock_destroy(&set->lock);
- fail_lock_init:
         free(set);
  fail_malloc:
         return NULL;
@@ -1475,8 +1461,6 @@ void fset_destroy(struct flow_set * set)
 
         pthread_rwlock_unlock(&ai.lock);
 
-        pthread_rwlock_destroy(&set->lock);
-
         free(set);
 }
 
@@ -1500,23 +1484,9 @@ void fqueue_destroy(struct fqueue * fq)
 
 void fset_zero(struct flow_set * set)
 {
-        struct list_head * p;
-        struct list_head * h;
-
         if (set == NULL)
                 return;
 
-        pthread_rwlock_wrlock(&set->lock);
-
-        list_for_each_safe(p, h, &set->flows) {
-                struct flow_set_entry * e;
-                e = list_entry(p, struct flow_set_entry, next);
-                list_del(&e->next);
-                free(e);
-        }
-
-        pthread_rwlock_unlock(&set->lock);
-
         shm_flow_set_zero(ai.fqset, set->idx);
 }
 
@@ -1524,7 +1494,6 @@ int fset_add(struct flow_set * set,
              int               fd)
 {
         struct flow *           flow;
-        struct flow_set_entry * fse;
         int                     ret;
 
         if (set == NULL || fd < 0 || fd >= SYS_MAX_FLOWS)
@@ -1532,12 +1501,6 @@ int fset_add(struct flow_set * set,
 
         flow = &ai.flows[fd];
 
-        fse = malloc(sizeof(*fse));
-        if (fse == NULL)
-                return -ENOMEM;
-
-        fse->fd = fd;
-
         pthread_rwlock_rdlock(&ai.lock);
 
         if (flow->flow_id < 0) {
@@ -1549,12 +1512,6 @@ int fset_add(struct flow_set * set,
         if (ret < 0)
                 goto fail;
 
-        pthread_rwlock_wrlock(&set->lock);
-
-        list_add_tail(&fse->next, &set->flows);
-
-        pthread_rwlock_unlock(&set->lock);
-
         if (shm_rbuff_queued(ai.flows[fd].rx_rb))
                 shm_flow_set_notify(ai.fqset, ai.flows[fd].flow_id, FLOW_PKT);
 
@@ -1564,16 +1521,13 @@ int fset_add(struct flow_set * set,
 
  fail:
         pthread_rwlock_unlock(&ai.lock);
-        free(fse);
         return ret;
 }
 
 void fset_del(struct flow_set * set,
               int               fd)
 {
-        struct list_head * p;
-        struct list_head * h;
-        struct flow *      flow;
+        struct flow * flow;
 
         if (set == NULL || fd < 0 || fd >= SYS_MAX_FLOWS)
                 return;
@@ -1585,20 +1539,6 @@ void fset_del(struct flow_set * set,
         if (flow->flow_id >= 0)
                 shm_flow_set_del(ai.fqset, set->idx, flow->flow_id);
 
-        pthread_rwlock_wrlock(&set->lock);
-
-        list_for_each_safe(p, h, &set->flows) {
-                struct flow_set_entry * e;
-                e = list_entry(p, struct flow_set_entry, next);
-                if (e->fd == fd) {
-                        list_del(&e->next);
-                        free(e);
-                        break;
-                }
-        }
-
-        pthread_rwlock_unlock(&set->lock);
-
         pthread_rwlock_unlock(&ai.lock);
 }
 
-- 
2.35.1


Other related posts: