summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-04-26 11:17:39 +0000
committerSander Vrijders <sander.vrijders@ugent.be>2017-04-26 11:17:39 +0000
commitad522c14994ae19c5a6507ee10ebcacdbf3cf107 (patch)
tree4e4d3b4f8da805ca9f0f0733977ff678c064660f /src
parentea16fc664673d65c0e3e51591258be4d3b8be406 (diff)
parente2c8623e66d66f4b9c8619349d11375a32ac2134 (diff)
downloadouroboros-ad522c14994ae19c5a6507ee10ebcacdbf3cf107.tar.gz
ouroboros-ad522c14994ae19c5a6507ee10ebcacdbf3cf107.zip
Merged in dstaesse/ouroboros/be-shm-reserve (pull request #493)
lib: Add call to reserve blocks in rdrbuff
Diffstat (limited to 'src')
-rw-r--r--src/ipcpd/normal/dt.c12
-rw-r--r--src/ipcpd/normal/fa.c2
-rw-r--r--src/ipcpd/normal/frct.c10
-rw-r--r--src/ipcpd/normal/shm_pci.h2
-rw-r--r--src/ipcpd/shim-eth-llc/main.c2
-rw-r--r--src/ipcpd/shim-udp/main.c4
-rw-r--r--src/lib/dev.c28
-rw-r--r--src/lib/shm_rdrbuff.c25
8 files changed, 62 insertions, 23 deletions
diff --git a/src/ipcpd/normal/dt.c b/src/ipcpd/normal/dt.c
index 593064f4..6ac73a93 100644
--- a/src/ipcpd/normal/dt.c
+++ b/src/ipcpd/normal/dt.c
@@ -93,7 +93,7 @@ static int sdu_handler(int fd,
if (pci.dst_addr != ipcpi.dt_addr) {
if (pci.ttl == 0) {
log_dbg("TTL was zero.");
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return 0;
}
@@ -103,7 +103,7 @@ static int sdu_handler(int fd,
if (fd < 0) {
pff_unlock(dt.pff[qc]);
log_err("No next hop for %" PRIu64, pci.dst_addr);
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -1;
}
@@ -111,7 +111,7 @@ static int sdu_handler(int fd,
if (ipcp_flow_write(fd, sdb)) {
log_err("Failed to write SDU to fd %d.", fd);
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -1;
}
} else {
@@ -268,7 +268,7 @@ int dt_write_sdu(struct pci * pci,
pff_unlock(dt.pff[pci->qos_id]);
log_err("Could not get nhop for address %" PRIu64,
pci->dst_addr);
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -1;
}
@@ -276,13 +276,13 @@ int dt_write_sdu(struct pci * pci,
if (shm_pci_ser(sdb, pci)) {
log_err("Failed to serialize PDU.");
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -1;
}
if (ipcp_flow_write(fd, sdb)) {
log_err("Failed to write SDU to fd %d.", fd);
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -1;
}
diff --git a/src/ipcpd/normal/fa.c b/src/ipcpd/normal/fa.c
index 6c3df7a1..131100db 100644
--- a/src/ipcpd/normal/fa.c
+++ b/src/ipcpd/normal/fa.c
@@ -61,7 +61,7 @@ static int sdu_handler(int fd,
if (frct_i_write_sdu(fa.fd_to_cep_id[fd], sdb)) {
pthread_rwlock_unlock(&fa.flows_lock);
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
log_warn("Failed to hand SDU to FRCT.");
return -1;
}
diff --git a/src/ipcpd/normal/frct.c b/src/ipcpd/normal/frct.c
index bfcde1b3..71e32bd1 100644
--- a/src/ipcpd/normal/frct.c
+++ b/src/ipcpd/normal/frct.c
@@ -229,7 +229,7 @@ int frct_post_sdu(struct pci * pci,
pci->src_cep_id);
if (instance == NULL) {
pthread_mutex_unlock(&frct.instances_lock);
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -ENOMEM;
}
id = instance->cep_id;
@@ -237,7 +237,7 @@ int frct_post_sdu(struct pci * pci,
instance = frct.instances[pci->dst_cep_id];
if (instance == NULL) {
pthread_mutex_unlock(&frct.instances_lock);
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -1;
}
id = pci->dst_cep_id;
@@ -253,16 +253,16 @@ int frct_post_sdu(struct pci * pci,
if (fa_post_buf(id, &buf)) {
log_err("Failed to hand buffer to FA.");
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -1;
}
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
} else {
/* FIXME: Known cep-ids are delivered to FA (minimal DTP) */
if (fa_post_sdu(pci->dst_cep_id, sdb)) {
log_err("Failed to hand SDU to FA.");
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -1;
}
}
diff --git a/src/ipcpd/normal/shm_pci.h b/src/ipcpd/normal/shm_pci.h
index 0c54c883..ff0b17ea 100644
--- a/src/ipcpd/normal/shm_pci.h
+++ b/src/ipcpd/normal/shm_pci.h
@@ -23,7 +23,7 @@
#ifndef OUROBOROS_IPCPD_NORMAL_SHM_PCI_H
#define OUROBOROS_IPCPD_NORMAL_SHM_PCI_H
-#include <ouroboros/shm_rdrbuff.h>
+#include <ouroboros/shm_du_buff.h>
#include <ouroboros/utils.h>
#include <ouroboros/qos.h>
diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c
index 36cb12c4..72889236 100644
--- a/src/ipcpd/shim-eth-llc/main.c
+++ b/src/ipcpd/shim-eth-llc/main.c
@@ -731,7 +731,7 @@ static void * eth_llc_ipcp_sdu_writer(void * o)
shm_du_buff_head(sdb),
shm_du_buff_tail(sdb)
- shm_du_buff_head(sdb));
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
}
pthread_rwlock_unlock(&eth_llc_data.flows_lock);
}
diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c
index 20e9b272..a3e87b86 100644
--- a/src/ipcpd/shim-udp/main.c
+++ b/src/ipcpd/shim-udp/main.c
@@ -501,7 +501,7 @@ static void * ipcp_udp_sdu_loop(void * o)
if (ipcp_get_state() != IPCP_OPERATIONAL) {
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return (void *) 0; /* -ENOTENROLLED */
}
@@ -516,7 +516,7 @@ static void * ipcp_udp_sdu_loop(void * o)
0) < 0)
log_err("Failed to send SDU.");
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
}
}
diff --git a/src/lib/dev.c b/src/lib/dev.c
index 757f26a8..c46cd407 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -1430,6 +1430,32 @@ int ipcp_flow_write(int fd,
return 0;
}
+int ipcp_sdb_reserve(struct shm_du_buff ** sdb,
+ size_t len)
+{
+ struct shm_rdrbuff * rdrb;
+ ssize_t idx;
+
+ pthread_rwlock_rdlock(&ai.data_lock);
+
+ rdrb = ai.rdrb;
+
+ pthread_rwlock_unlock(&ai.data_lock);
+
+ idx = shm_rdrbuff_write_b(rdrb,
+ DU_BUFF_HEADSPACE,
+ DU_BUFF_TAILSPACE,
+ NULL,
+ len);
+
+ if (idx < 0)
+ return -1;
+
+ *sdb = shm_rdrbuff_get(rdrb, idx);
+
+ return 0;
+}
+
int ipcp_flow_fini(int fd)
{
struct shm_rbuff * rx_rb;
@@ -1539,7 +1565,7 @@ int ipcp_read_shim(int fd,
return 0;
}
-void ipcp_flow_del(struct shm_du_buff * sdb)
+void ipcp_sdb_release(struct shm_du_buff * sdb)
{
shm_rdrbuff_remove(ai.rdrb, shm_du_buff_get_idx(sdb));
}
diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c
index 9dffdf74..ed9c3847 100644
--- a/src/lib/shm_rdrbuff.c
+++ b/src/lib/shm_rdrbuff.c
@@ -24,6 +24,7 @@
#include <ouroboros/config.h>
#include <ouroboros/errno.h>
#include <ouroboros/shm_rdrbuff.h>
+#include <ouroboros/shm_du_buff.h>
#include <ouroboros/time_utils.h>
#include <pthread.h>
@@ -333,7 +334,6 @@ ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb,
ssize_t sz = size + sizeof(*sdb);
assert(rdrb);
- assert(data);
#ifndef SHM_RDRB_MULTI_BLOCK
if (sz > SHM_RDRB_BLOCK_SIZE)
@@ -392,7 +392,8 @@ ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb,
sdb->du_head = headspace;
sdb->du_tail = sdb->du_head + len;
- memcpy(((uint8_t *) (sdb + 1)) + headspace, data, len);
+ if (data != NULL)
+ memcpy(((uint8_t *) (sdb + 1)) + headspace, data, len);
return sdb->idx;
}
@@ -412,7 +413,6 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb,
ssize_t sz = size + sizeof(*sdb);
assert(rdrb);
- assert(data);
#ifndef SHM_RDRB_MULTI_BLOCK
if (sz > SHM_RDRB_BLOCK_SIZE)
@@ -472,7 +472,9 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb,
sdb->size = size;
sdb->du_head = headspace;
sdb->du_tail = sdb->du_head + len;
- memcpy(((uint8_t *) (sdb + 1)) + headspace, data, len);
+
+ if (data != NULL)
+ memcpy(((uint8_t *) (sdb + 1)) + headspace, data, len);
return sdb->idx;
}
@@ -495,7 +497,8 @@ ssize_t shm_rdrbuff_read(uint8_t ** dst,
return len;
}
-struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb, size_t idx)
+struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb,
+ size_t idx)
{
struct shm_du_buff * sdb;
@@ -507,7 +510,8 @@ struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb, size_t idx)
return sdb;
}
-int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb, size_t idx)
+int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb,
+ size_t idx)
{
assert(rdrb);
assert(idx < (SHM_BUFFER_SIZE));
@@ -609,3 +613,12 @@ void shm_du_buff_tail_release(struct shm_du_buff * sdb,
sdb->du_tail -= size;
}
+
+void shm_du_buff_truncate(struct shm_du_buff * sdb,
+ size_t len)
+{
+ assert(sdb);
+ assert(len <= sdb->size);
+
+ sdb->du_tail -= sdb->size - len;
+}