1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

get rid of static global storage as much as possible for now

This commit is contained in:
Steffen Vogel 2015-12-13 00:42:59 +01:00
parent 59d76a3d7d
commit 399f29c496
8 changed files with 23 additions and 41 deletions

View file

@ -106,13 +106,4 @@ int if_get_irqs(struct interface *i);
*/
int if_set_affinity(struct interface *i, int affinity);
/** Search the global list of interfaces for a given index.
*
* @param index The interface index to search for
* @param interfaces A linked list of all interfaces
* @retval NULL if no interface with index was found.
* @retval >0 Success. A pointer to the interface.
*/
struct interface * if_lookup_index(int index);
#endif /* _IF_H_ */

View file

@ -32,7 +32,8 @@ __attribute__((constructor)) static void __register() { \
list_push(&node_types, vt); \
}
extern struct list node_types;
extern struct list nodes; /**< List of all nodes */
extern struct list node_types; /**< Vtable for virtual node sub types */
/* Forward declarations */
struct config_setting_t *cfg;

View file

@ -23,9 +23,6 @@
#include "utils.h"
#include "checks.h"
/** Linked list of interfaces. */
struct list interfaces;
struct interface * if_create(struct rtnl_link *link)
{
struct interface *i = alloc(sizeof(struct interface));
@ -41,7 +38,6 @@ struct interface * if_create(struct rtnl_link *link)
warn("Did not found any interrupts for interface '%s'", rtnl_link_get_name(i->nl_link));
list_init(&i->sockets, NULL);
list_push(&interfaces, i);
return i;
}
@ -205,14 +201,3 @@ int if_set_affinity(struct interface *i, int affinity)
return 0;
}
struct interface * if_lookup_index(int index)
{
list_foreach(struct interface *i, &interfaces) {
if (rtnl_link_get_ifindex(i->nl_link) == index)
return i;
}
return NULL;
}

View file

@ -12,8 +12,8 @@
#include "cfg.h"
#include "utils.h"
/** Vtable for virtual node sub types */
struct list node_types = LIST_INIT(NULL);
struct list nodes = LIST_INIT((dtor_cb_t) node_destroy); /**< List of all nodes */
struct list node_types = LIST_INIT(NULL); /**< Vtable for virtual node sub types */
int node_parse(struct node *n, config_setting_t *cfg)
{
@ -129,6 +129,7 @@ struct node * node_create(struct node_type *vt)
{
struct node *n = alloc(sizeof(struct node));
list_push(&nodes, n);
list_push(&vt->instances, n);
n->_vt = vt;
@ -146,6 +147,9 @@ void node_destroy(struct node *n)
{
if (n->_vt->destroy)
n->_vt->destroy(n);
list_remove(&nodes, n);
list_remove(&n->_vt->instances, n);
free(n->_vd);
free(n->_name);

View file

@ -32,12 +32,12 @@
#include "socket.h"
#include "checks.h"
/** Linked list of interfaces */
extern struct list interfaces;
/* Forward declartions */
static struct node_type vt;
/* Private static storage */
struct list interfaces;
int socket_init(int argc, char * argv[], config_setting_t *cfg)
{
if (check_root())
@ -58,12 +58,18 @@ int socket_init(int argc, char * argv[], config_setting_t *cfg)
free(buf);
}
int ifindex = rtnl_link_get_ifindex(link);
struct interface *i = if_lookup_index(ifindex);
if (!i)
i = if_create(link);
/* Search of existing interface with correct ifindex */
struct interface *i;
list_foreach(i, &interfaces) {
if (rtnl_link_get_ifindex(i->nl_link) == rtnl_link_get_ifindex(link))
goto found;
}
/* If not found, create a new interface */
i = if_create(link);
list_push(&interfaces, i);
list_push(&i->sockets, s);
found: list_push(&i->sockets, s);
}
/** @todo Improve mapping of NIC IRQs per path */

View file

@ -21,8 +21,7 @@
#include "hooks.h"
#include "path.h"
#include "utils.h"
extern struct list nodes;
#include "node.h"
struct list hooks;

View file

@ -25,7 +25,6 @@
#include "opal.h"
#endif
struct list nodes; /**< Linked list of nodes */
struct list paths; /**< Linked list of paths */
struct settings settings; /**< The global configuration */
static config_t config; /**< libconfig handle */
@ -143,7 +142,6 @@ int main(int argc, char *argv[])
error("Your kernel version is to old: required >= %u.%u", KERNEL_VERSION_MAJ, KERNEL_VERSION_MIN);
/* Initialize lists */
list_init(&nodes, (dtor_cb_t) node_destroy);
list_init(&paths, (dtor_cb_t) path_destroy);
info("Initialize real-time system");

View file

@ -21,8 +21,6 @@
#include "hist.h"
#include "timing.h"
/** Linked list of nodes */
struct list nodes;
/** The global configuration */
struct settings settings;