summaryrefslogtreecommitdiff
path: root/libnetfs/make-node.c
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2014-05-18 13:34:12 +0200
committerJustus Winter <4winter@informatik.uni-hamburg.de>2014-05-28 14:50:54 +0200
commit94fecd72f41542c8dfa82bdf7b47742f8c29b321 (patch)
treefc2f152dc01b4b49e5de2d73993200ed197e4cae /libnetfs/make-node.c
parent80485401a9a5e9df03bd3a1503bc5e59d1f2e5c1 (diff)
libnetfs: add netfs_make_node_alloc to allocate fat nodes
libnetfs has two kind of nodes, struct node and struct netnode. struct node is used to store libnetfs specific data, while struct netnode contains user supplied data. Previously, both objects were allocated separatly, and a pointer from the node to the netnode provided a mapping from the former to the latter. Provide a function netfs_make_node_alloc that allocates both nodes in a contiguous region. This reduces the memory allocation overhead when creating nodes. It also makes the relation between node and netnode a simple offset calculation. Provide two functions to compute the netnode address from the node address and vice-versa. Most notably, this makes implementing a cache on top of libnetfs easier. Auxiliary data for the cache can be stored in the user-defined netnode, and the fat node can be used as the value. * libnetfs/make-node.c (init_node): Move initialization here. (netfs_make_node): Use init_node. (netfs_make_node_alloc): New function to allocate fat nodes. * libnetfs/netfs.h (netfs_make_node_alloc): New declaration. (_netfs_sizeof_struct_node): Likewise. (netfs_node_netnode): Compute netnode address from node address. (netfs_netnode_node): And vice-versa. * libnetfs/init-init.c (_netfs_sizeof_struct_node): New variable.
Diffstat (limited to 'libnetfs/make-node.c')
-rw-r--r--libnetfs/make-node.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/libnetfs/make-node.c b/libnetfs/make-node.c
index f20ada18..6bd8109c 100644
--- a/libnetfs/make-node.c
+++ b/libnetfs/make-node.c
@@ -21,13 +21,9 @@
#include "netfs.h"
#include <hurd/fshelp.h>
-struct node *
-netfs_make_node (struct netnode *nn)
+static struct node *
+init_node (struct node *np, struct netnode *nn)
{
- struct node *np = malloc (sizeof (struct node));
- if (! np)
- return NULL;
-
np->nn = nn;
pthread_mutex_init (&np->lock, NULL);
@@ -40,3 +36,24 @@ netfs_make_node (struct netnode *nn)
return np;
}
+
+struct node *
+netfs_make_node (struct netnode *nn)
+{
+ struct node *np = malloc (sizeof (struct node));
+ if (! np)
+ return NULL;
+
+ return init_node (np, nn);
+}
+
+struct node *
+netfs_make_node_alloc (size_t size)
+{
+ struct node *np = malloc (sizeof (struct node) + size);
+
+ if (np == NULL)
+ return NULL;
+
+ return init_node (np, netfs_node_netnode (np));
+}