Signed-off-by: Christoph Hellwig <hch@lst.de>

Index: sheepdog/sheep/group.c
===================================================================
--- sheepdog.orig/sheep/group.c	2012-05-07 10:56:03.861463810 +0200
+++ sheepdog/sheep/group.c	2012-05-07 10:59:08.769468543 +0200
@@ -148,13 +148,17 @@ int get_max_nr_copies_from(struct sd_nod
 
 struct vnode_info *get_vnode_info(void)
 {
+	assert(is_main_thread());
 	assert(current_vnode_info);
+
 	current_vnode_info->refcnt++;
 	return current_vnode_info;
 }
 
 void put_vnode_info(struct vnode_info *vnodes)
 {
+	assert(is_main_thread());
+
 	if (vnodes && --vnodes->refcnt == 0)
 		free(vnodes);
 }
Index: sheepdog/sheep/sheep.c
===================================================================
--- sheepdog.orig/sheep/sheep.c	2012-05-07 10:51:21.461456579 +0200
+++ sheepdog/sheep/sheep.c	2012-05-07 10:59:08.769468543 +0200
@@ -96,6 +96,8 @@ Available log levels:\n\
 static struct cluster_info __sys;
 struct cluster_info *sys = &__sys;
 
+pthread_t main_thread;
+
 int main(int argc, char **argv)
 {
 	int ch, longindex;
@@ -110,6 +112,8 @@ int main(int argc, char **argv)
 	char *p;
 	struct cluster_driver *cdrv;
 
+	main_thread = pthread_self();
+
 	signal(SIGPIPE, SIG_IGN);
 
 	while ((ch = getopt_long(argc, argv, short_options, long_options,
Index: sheepdog/sheep/sheep_priv.h
===================================================================
--- sheepdog.orig/sheep/sheep_priv.h	2012-05-07 10:58:00.181466786 +0200
+++ sheepdog/sheep/sheep_priv.h	2012-05-07 10:59:08.769468543 +0200
@@ -12,6 +12,7 @@
 #define __SHEEP_PRIV_H__
 
 #include <inttypes.h>
+#include <pthread.h>
 
 #include "sheepdog_proto.h"
 #include "event.h"
@@ -230,6 +231,13 @@ extern mode_t def_fmode;
 extern mode_t def_dmode;
 extern struct objlist_cache obj_list_cache;
 
+extern pthread_t main_thread;
+
+static inline int is_main_thread(void)
+{
+	return pthread_equal(pthread_self(), main_thread);
+}
+
 int create_listen_port(int port, void *data);
 
 int init_store(const char *dir);


