summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2013-07-08 11:12:30 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2013-07-08 11:12:30 +0200
commit7a05d6fac03cd1d96ef219ad64cb2a61c8300c47 (patch)
treeed8a36e984ffb3683a2428e345c774481dd34ba8
parente559567111b9b5dd46cf5e3278e71cc0b2423cfa (diff)
parent09a547f9155e54fd34c4fab20ff98d906cedb2c2 (diff)
Merge remote-tracking branch 'origin/tarfs/master' into tarfs
-rw-r--r--Makefile2
-rw-r--r--cache.c6
-rw-r--r--cache.h2
-rw-r--r--debug.c8
-rw-r--r--netfs.c12
-rw-r--r--tarfs.c36
-rw-r--r--tarfs.h8
-rw-r--r--tarlist.c10
-rw-r--r--zipstores.c52
9 files changed, 72 insertions, 64 deletions
diff --git a/Makefile b/Makefile
index 87c85d38e..e3936bfda 100644
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,7 @@ CFLAGS += -DDEBUG_ZIP # zip stores debugging
# Note: -lz has to be first otherwise inflate() will be the exec server's
# inflate function
LDFLAGS = -L~ -lz -L. -lnetfs -lfshelp -liohelp -lports \
- -lihash -lshouldbeinlibc -lthreads -lstore -lbz2 #-lpthread
+ -lihash -lshouldbeinlibc -lpthread -lstore -lbz2
CTAGS = ctags
SRC = main.c netfs.c tarfs.c tarlist.c fs.c cache.c tar.c names.c \
diff --git a/cache.c b/cache.c
index 685e0ea04..fefc36857 100644
--- a/cache.c
+++ b/cache.c
@@ -32,8 +32,8 @@
#include "debug.h"
/* Locking/unlocking a node's cache */
-#define LOCK(Node) mutex_lock (&CACHE_INFO ((Node), lock))
-#define UNLOCK(Node) mutex_unlock (&CACHE_INFO ((Node), lock));
+#define LOCK(Node) pthread_mutex_lock (&CACHE_INFO ((Node), lock))
+#define UNLOCK(Node) pthread_mutex_unlock (&CACHE_INFO ((Node), lock));
/* Tar file callback (in tarfs.c). */
static error_t (* read_file) (struct node *node,
@@ -76,7 +76,7 @@ cache_create (struct node *node)
CACHE_INFO (node, size) = blocks;
debug (("Node %s: Initial block vector size: %u", node->nn->name, blocks));
- mutex_init (&CACHE_INFO (node, lock));
+ pthread_mutex_init (&CACHE_INFO (node, lock), NULL);
return 0;
}
diff --git a/cache.h b/cache.h
index 781f2cb52..0c3659ea8 100644
--- a/cache.h
+++ b/cache.h
@@ -46,7 +46,7 @@ struct cache
size_t size;
/* Lock of this cache */
- struct mutex lock;
+ pthread_mutex_t lock;
};
/* Initializes the cache backend. READ is the method that will be called
diff --git a/debug.c b/debug.c
index ed839501b..2f61fbc63 100644
--- a/debug.c
+++ b/debug.c
@@ -26,10 +26,10 @@
#include <errno.h>
#include <error.h>
#include <string.h>
-#include <cthreads.h>
+#include <pthread.h>
-static struct mutex debug_lock;
+static pthread_mutex_t debug_lock;
static char *debug_function = NULL;
static FILE *debug_file = NULL;
@@ -54,7 +54,7 @@ __debug_start (const char *function)
if (!debug_file)
return;
- mutex_lock (&debug_lock);
+ pthread_mutex_lock (&debug_lock);
debug_function = strdup (function);
}
@@ -84,5 +84,5 @@ __debug_end ()
free (debug_function);
debug_function = NULL;
fflush (debug_file);
- mutex_unlock (&debug_lock);
+ pthread_mutex_unlock (&debug_lock);
}
diff --git a/netfs.c b/netfs.c
index 77e53dc85..1b006a3fc 100644
--- a/netfs.c
+++ b/netfs.c
@@ -77,13 +77,13 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir,
if (!err && *np)
{
if (*np != dir)
- mutex_lock (&(*np)->lock);
+ pthread_mutex_lock (&(*np)->lock);
debug (("Node %s: %i references", name, (*np)->references));
netfs_nref (*np);
}
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
return err;
}
@@ -640,7 +640,7 @@ netfs_attempt_unlink (struct iouser *user, struct node *dir,
if (!err)
{
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
debug (("Node %s: %i references", name, node->references));
err = fshelp_isowner (&node->nn_stat, user);
@@ -648,7 +648,7 @@ netfs_attempt_unlink (struct iouser *user, struct node *dir,
if (!err)
err = backend.unlink_node (node);
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
}
}
else
@@ -758,12 +758,12 @@ netfs_attempt_create_file (struct iouser *user, struct node *dir,
if (!err && *np)
{
debug (("Node %s: %i references", name, (*np)->references));
- mutex_lock (&(*np)->lock);
+ pthread_mutex_lock (&(*np)->lock);
netfs_nref (*np);
}
}
- mutex_unlock (&dir->lock);
+ pthread_mutex_unlock (&dir->lock);
return err;
}
diff --git a/tarfs.c b/tarfs.c
index a0e769240..495c35507 100644
--- a/tarfs.c
+++ b/tarfs.c
@@ -77,7 +77,7 @@ const struct argp_option fs_options[] =
/* Tar file store & lock. */
static struct store *tar_file;
-static struct mutex tar_file_lock;
+static pthread_mutex_t tar_file_lock;
/* Archive parsing hook (see tar.c) */
extern int (* tar_header_hook) (tar_record_t *, struct archive *);
@@ -143,7 +143,7 @@ read_from_file (struct node *node, off_t offset, size_t howmuch,
store_offset_t start = NODE_INFO(node)->tar->offset;
void *d = data;
- mutex_lock (&tar_file_lock);
+ pthread_mutex_lock (&tar_file_lock);
if (!tar_file)
err = open_store ();
@@ -155,7 +155,7 @@ read_from_file (struct node *node, off_t offset, size_t howmuch,
&d,
actually_read);
- mutex_unlock (&tar_file_lock);
+ pthread_mutex_unlock (&tar_file_lock);
if (err)
return err;
@@ -280,11 +280,11 @@ tarfs_set_options (char *argz, size_t argz_len)
{
if (!tarfs_options.readonly)
{
- mutex_lock (&tar_file_lock);
+ pthread_mutex_lock (&tar_file_lock);
tarfs_options.readonly = 1;
close_store ();
err = open_store ();
- mutex_unlock (&tar_file_lock);
+ pthread_mutex_unlock (&tar_file_lock);
if (err)
tarfs_options.readonly = 0;
@@ -296,11 +296,11 @@ tarfs_set_options (char *argz, size_t argz_len)
{
if (tarfs_options.readonly)
{
- mutex_lock (&tar_file_lock);
+ pthread_mutex_lock (&tar_file_lock);
tarfs_options.readonly = 0;
close_store ();
err = open_store ();
- mutex_unlock (&tar_file_lock);
+ pthread_mutex_unlock (&tar_file_lock);
if (err)
tarfs_options.readonly = 1;
@@ -511,15 +511,18 @@ tarfs_init (struct node **root, struct iouser *user)
error_t err;
/* Go ahead: parse and build. */
- mutex_lock (&tar_file_lock);
+ pthread_mutex_lock (&tar_file_lock);
err = tar_open_archive (tar_file);
- mutex_unlock (&tar_file_lock);
+ pthread_mutex_unlock (&tar_file_lock);
if (err)
error (1, 0, "Invalid tar archive (%s)", tarfs_options.file_name);
#if 0
else
- cthread_fork ((cthread_fn_t) sync_archive, NULL);
+ {
+ pthread_t t;
+ pthread_create (&t, NULL, (void*(*)(void*)) sync_archive, NULL);
+ }
#endif
}
@@ -586,7 +589,10 @@ tarfs_init (struct node **root, struct iouser *user)
if (st.st_size)
{
if (tarfs_options.threaded)
- cthread_fork ((cthread_fn_t) read_archive, NULL);
+ {
+ pthread_t t;
+ pthread_create(&t, NULL, (void*(*)(void*)) read_archive, NULL);
+ }
else
read_archive ();
}
@@ -1083,7 +1089,7 @@ tarfs_sync_fs (int wait)
while (1)
{
- mutex_lock (&tar_file_lock);
+ pthread_mutex_lock (&tar_file_lock);
if (!tar_file)
err = open_store ();
@@ -1091,7 +1097,7 @@ tarfs_sync_fs (int wait)
if (!err)
err = store_write (tar_file, offset, buf, len, amount);
- mutex_unlock (&tar_file_lock);
+ pthread_mutex_unlock (&tar_file_lock);
cnt++;
@@ -1139,7 +1145,7 @@ tarfs_sync_fs (int wait)
size_t size;
/* Lock the node first */
- mutex_lock (&node->lock);
+ pthread_mutex_lock (&node->lock);
have_to_sync = (tar->offset != file_offs + RECORDSIZE);
path = fs_get_path_from_root (netfs_root_node, node);
size = node->nn_stat.st_size;
@@ -1258,7 +1264,7 @@ tarfs_sync_fs (int wait)
cache_free (node);
free (path);
- mutex_unlock (&node->lock);
+ pthread_mutex_unlock (&node->lock);
/* Go to next item. */
tar = tar->next;
diff --git a/tarfs.h b/tarfs.h
index 9e3923999..2cc55ac92 100644
--- a/tarfs.h
+++ b/tarfs.h
@@ -77,7 +77,7 @@ struct tar_item
struct tar_list
{
struct tar_item *head;
- struct mutex lock;
+ pthread_mutex_t lock;
};
/* Unless stated otherwise, all the following functions taking a tar_list
@@ -114,13 +114,13 @@ extern void tar_put_item (struct tar_item **prev_tar, struct tar_item *tar);
/* An iterator. */
#define tar_list_iterate(List, Item, Expr1, Expr2) \
- for ((Item) = (mutex_lock (&(List)->lock), (List)->head); \
+ for ((Item) = (pthread_mutex_lock (&(List)->lock), (List)->head); \
(Expr1); (Expr2))
/* These two macros can be used to implement critical things (e.g. traversing
the whole list). */
-#define tar_list_lock(List) mutex_lock (&(List)->lock);
-#define tar_list_unlock(List) mutex_unlock (&(List)->lock);
+#define tar_list_lock(List) pthread_mutex_lock (&(List)->lock);
+#define tar_list_unlock(List) pthread_mutex_unlock (&(List)->lock);
/** Node information. **/
diff --git a/tarlist.c b/tarlist.c
index 22cabc7fd..f4321f1ca 100644
--- a/tarlist.c
+++ b/tarlist.c
@@ -36,7 +36,7 @@ void
tar_list_init (struct tar_list *list)
{
list->head = NULL;
- mutex_init (&list->lock);
+ pthread_mutex_init (&list->lock, NULL);
}
/* Make a tar item containing the given information. NEW points to the
@@ -71,7 +71,7 @@ tar_insert_item (struct tar_list *list,
assert (prev != new);
- mutex_lock (&list->lock);
+ pthread_mutex_lock (&list->lock);
head = &list->head;
if (! prev)
@@ -97,7 +97,7 @@ tar_insert_item (struct tar_list *list,
if (next)
next->prev = new;
- mutex_unlock (&list->lock);
+ pthread_mutex_unlock (&list->lock);
return 0;
}
@@ -136,9 +136,9 @@ tar_unlink_item_safe (struct tar_list *list, struct tar_item *item)
void
tar_unlink_item (struct tar_list *list, struct tar_item *tar)
{
- mutex_lock (&list->lock);
+ pthread_mutex_lock (&list->lock);
tar_unlink_item_safe (list, tar);
- mutex_unlock (&list->lock);
+ pthread_mutex_unlock (&list->lock);
}
diff --git a/zipstores.c b/zipstores.c
index f495938dc..ca8beaa3b 100644
--- a/zipstores.c
+++ b/zipstores.c
@@ -22,6 +22,8 @@
# error "Don't try to compile this file directly."
#endif
+#include <pthread.h>
+
/* Stringification macros stolen from libstore's unzipstores.c */
#define STRINGIFY(name) STRINGIFY_1(name)
@@ -97,7 +99,7 @@ struct stream_state
#endif
/* Stream lock */
- struct mutex lock;
+ pthread_mutex_t lock;
};
/* Zip object information */
@@ -136,7 +138,7 @@ struct ZIP (object)
size_t size;
/* Cache lock */
- struct mutex lock;
+ pthread_mutex_t lock;
} cache;
};
@@ -209,7 +211,7 @@ ZIP (stream_read_init) (struct ZIP (object) *zip)
int zerr;
ZIP_STREAM *stream = &zip->read.stream;
- mutex_lock (&zip->read.lock);
+ pthread_mutex_lock (&zip->read.lock);
/* Check whether STREAM had already been initialized */
if (stream->state)
@@ -238,7 +240,7 @@ ZIP (stream_read_init) (struct ZIP (object) *zip)
#endif
}
- mutex_unlock (&zip->read.lock);
+ pthread_mutex_unlock (&zip->read.lock);
return err;
}
@@ -252,13 +254,13 @@ ZIP (stream_write_init) (struct ZIP (object) *zip)
ZIP_STREAM *stream = &zip->write.stream;
int zerr;
- mutex_lock (&zip->write.lock);
+ pthread_mutex_lock (&zip->write.lock);
/* Check whether STREAM has already been initialized */
if (stream->state)
{
zerr = ZIP_COMPRESS_END (stream);
- err = ZIP (error) (stream, err);
+ err = ZIP (error) (stream, zerr);
assert_perror (err);
}
#ifdef ZIP_HAS_HEADER
@@ -308,7 +310,7 @@ ZIP (stream_write_init) (struct ZIP (object) *zip)
#endif
}
- mutex_unlock (&zip->write.lock);
+ pthread_mutex_unlock (&zip->write.lock);
return err;
}
@@ -344,7 +346,7 @@ ZIP (stream_read) (struct ZIP (object) *const zip,
store_offset_t zip_start = *zip_offs;
- mutex_lock (&zip->read.lock);
+ pthread_mutex_lock (&zip->read.lock);
assert (zip->read.zip_status != STATUS_IDLE);
/* Check whether we have already reached the end of stream */
@@ -352,7 +354,7 @@ ZIP (stream_read) (struct ZIP (object) *const zip,
{
debug (("eof: doing nothing"));
*len = 0;
- mutex_unlock (&zip->read.lock);
+ pthread_mutex_unlock (&zip->read.lock);
return 0;
}
@@ -362,7 +364,7 @@ ZIP (stream_read) (struct ZIP (object) *const zip,
*len = 0;
zip->read.zip_status = STATUS_EOF;
zip->read.file_status = STATUS_EOF;
- mutex_unlock (&zip->read.lock);
+ pthread_mutex_unlock (&zip->read.lock);
return 0;
}
@@ -432,7 +434,7 @@ ZIP (stream_read) (struct ZIP (object) *const zip,
debug (("requested/read = %i / %i", amount, *len));
assert (*len <= amount);
- mutex_unlock (&zip->read.lock);
+ pthread_mutex_unlock (&zip->read.lock);
return err;
}
@@ -482,7 +484,7 @@ ZIP (stream_write) (struct ZIP (object) *const zip,
}
- mutex_lock (&zip->write.lock);
+ pthread_mutex_lock (&zip->write.lock);
assert (zip->write.zip_status != STATUS_IDLE);
if (zip->write.zip_status == STATUS_EOF)
@@ -490,7 +492,7 @@ ZIP (stream_write) (struct ZIP (object) *const zip,
/* End of file reached */
debug (("eof: doing nothing"));
*len = 0;
- mutex_unlock (&zip->write.lock);
+ pthread_mutex_unlock (&zip->write.lock);
return 0;
}
@@ -579,7 +581,7 @@ ZIP (stream_write) (struct ZIP (object) *const zip,
end:
debug (("requested/written = %i / %i", amount, *len));
- mutex_unlock (&zip->write.lock);
+ pthread_mutex_unlock (&zip->write.lock);
return err;
}
@@ -669,7 +671,7 @@ ZIP (read) (struct store *store,
block_offset = BLOCK_RELATIVE_OFFSET (offset);
/* Lock the file during the whole reading (XXX: not very fine-grained) */
- mutex_lock (&zip->cache.lock);
+ pthread_mutex_lock (&zip->cache.lock);
blocks = zip->cache.blocks;
blocks_size = zip->cache.size;
@@ -705,7 +707,7 @@ ZIP (read) (struct store *store,
datap = datap + read;
}
- mutex_unlock (&zip->cache.lock);
+ pthread_mutex_unlock (&zip->cache.lock);
return err;
}
@@ -766,14 +768,14 @@ ZIP (write) (struct store *store,
int block = BLOCK_NUMBER (offset); /* 1st block to read. */
const void *datap = buf; /* current pointer */
- mutex_lock (&zip->cache.lock);
+ pthread_mutex_lock (&zip->cache.lock);
blocks = zip->cache.blocks;
if (offset >= store->size)
{
debug (("Trying to write at offs %lli (size=%u)", offset, store->size));
*amount = 0;
- mutex_unlock (&zip->cache.lock);
+ pthread_mutex_unlock (&zip->cache.lock);
return EIO;
}
@@ -824,7 +826,7 @@ ZIP (write) (struct store *store,
datap = datap + write;
}
- mutex_unlock (&zip->cache.lock);
+ pthread_mutex_unlock (&zip->cache.lock);
return err;
}
@@ -839,7 +841,7 @@ ZIP (set_size) (struct store *store, size_t size)
char ***blocks;
size_t newsize, oldsize; /* Size of BLOCKS */
- mutex_lock (&zip->cache.lock);
+ pthread_mutex_lock (&zip->cache.lock);
blocks_size = &zip->cache.size;
blocks = &zip->cache.blocks;
oldsize = *blocks_size;
@@ -886,7 +888,7 @@ ZIP (set_size) (struct store *store, size_t size)
if (!err)
store->size = store->end = store->wrap_src = store->runs[0].length = size;
- mutex_unlock (&zip->cache.lock);
+ pthread_mutex_unlock (&zip->cache.lock);
debug (("newsize is %lli (err = %s)", store->size, strerror (err)));
@@ -1065,7 +1067,7 @@ ZIP (sync) (struct store *store)
/* Hold the cache lock till the end--anyway, no one should try to get
this lock since we are called from store_free (). */
- mutex_lock (&zip->cache.lock);
+ pthread_mutex_lock (&zip->cache.lock);
blocks = zip->cache.blocks;
/* Initialize STREAM since this should not have be done before. */
@@ -1229,9 +1231,9 @@ ZIP (open) (const char *name, int flags,
zip->store = *store;
stream = &zip->read.stream;
- mutex_init (&zip->read.lock);
- mutex_init (&zip->write.lock);
- mutex_init (&zip->cache.lock);
+ pthread_mutex_init (&zip->read.lock, NULL);
+ pthread_mutex_init (&zip->write.lock, NULL);
+ pthread_mutex_init (&zip->cache.lock, NULL);
(*store)->flags = flags;
(*store)->block_size = 1;