summaryrefslogtreecommitdiff
path: root/debian/patches/0002-libnetfs-add-netfs_make_node_alloc-to-allocate-fat-n.patch
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2014-05-22 08:23:16 +0200
committerJustus Winter <4winter@informatik.uni-hamburg.de>2014-05-22 08:23:16 +0200
commit78acdaa8fc996dbf70d23d69aea9f81499290c26 (patch)
tree9013f4a1894213f748a6e31a18a0340d6ee3fefc /debian/patches/0002-libnetfs-add-netfs_make_node_alloc-to-allocate-fat-n.patch
parentbd64a35db772d27e33b6cb1b50446b865b1c837e (diff)
add patch series
Diffstat (limited to 'debian/patches/0002-libnetfs-add-netfs_make_node_alloc-to-allocate-fat-n.patch')
-rw-r--r--debian/patches/0002-libnetfs-add-netfs_make_node_alloc-to-allocate-fat-n.patch116
1 files changed, 116 insertions, 0 deletions
diff --git a/debian/patches/0002-libnetfs-add-netfs_make_node_alloc-to-allocate-fat-n.patch b/debian/patches/0002-libnetfs-add-netfs_make_node_alloc-to-allocate-fat-n.patch
new file mode 100644
index 00000000..e013c1e3
--- /dev/null
+++ b/debian/patches/0002-libnetfs-add-netfs_make_node_alloc-to-allocate-fat-n.patch
@@ -0,0 +1,116 @@
+From b28098f0eb0637d1c06aa38ce6041c8e0916199d Mon Sep 17 00:00:00 2001
+From: Justus Winter <4winter@informatik.uni-hamburg.de>
+Date: Sun, 18 May 2014 13:34:12 +0200
+Subject: [PATCH 02/27] 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_node_netnode): Compute netnode address from node address.
+(netfs_netnode_node): And vice-versa.
+---
+ libnetfs/make-node.c | 29 +++++++++++++++++++++++------
+ libnetfs/netfs.h | 22 ++++++++++++++++++++++
+ 2 files changed, 45 insertions(+), 6 deletions(-)
+
+diff --git a/libnetfs/make-node.c b/libnetfs/make-node.c
+index f20ada1..6bd8109 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));
++}
+diff --git a/libnetfs/netfs.h b/libnetfs/netfs.h
+index aef4a3d..e3c3b3e 100644
+--- a/libnetfs/netfs.h
++++ b/libnetfs/netfs.h
+@@ -372,6 +372,28 @@ extern int netfs_maxsymlinks;
+ If an error occurs, NULL is returned. */
+ struct node *netfs_make_node (struct netnode *);
+
++/* Create a new node structure. Also allocate SIZE bytes for the
++ netnode. The address of the netnode can be obtained using
++ netfs_node_netnode. The new node will have one hard reference and
++ no light references. If an error occurs, NULL is returned. */
++struct node *netfs_make_node_alloc (size_t size);
++
++/* Return the address of the netnode for NODE. NODE must have been
++ allocated using netfs_make_node_alloc. */
++static inline struct netnode *
++netfs_node_netnode (struct node *node)
++{
++ return (struct netnode *) ((char *) node + sizeof (struct node));
++}
++
++/* Return the address of the node for NETNODE. NETNODE must have been
++ allocated using netfs_make_node_alloc. */
++static inline struct node *
++netfs_netnode_node (struct netnode *netnode)
++{
++ return (struct node *) ((char *) netnode - sizeof (struct node));
++}
++
+ /* Whenever node->references is to be touched, this lock must be
+ held. Cf. netfs_nrele, netfs_nput, netfs_nref and netfs_drop_node. */
+ extern pthread_spinlock_t netfs_node_refcnt_lock;
+--
+2.0.0.rc2
+