author | Alberto Bertogli
<albertito@gmail.com> 2004-07-15 02:22:53 UTC |
committer | Alberto Bertogli
<albertito@gmail.com> 2007-07-15 13:16:22 UTC |
parent | c6095eec8d70b0ebc9e601ab61c328e30e32567c |
libjio.h | +1 | -1 |
trans.c | +13 | -4 |
diff --git a/libjio.h b/libjio.h index 101a42e..52b74db 100644 --- a/libjio.h +++ b/libjio.h @@ -98,7 +98,7 @@ int jtrans_add(struct jtrans *ts, const void *buf, size_t count, off_t offset); int jtrans_commit(struct jtrans *ts); int jtrans_rollback(struct jtrans *ts); void jtrans_free(struct jtrans *ts); -void jsync(struct jfs *fs); +int jsync(struct jfs *fs); int jclose(struct jfs *fs); diff --git a/trans.c b/trans.c index 870001d..2d91594 100644 --- a/trans.c +++ b/trans.c @@ -558,11 +558,16 @@ int jopen(struct jfs *fs, const char *name, int flags, int mode, int jflags) } /* sync a file (makes sense only if using lingering transactions) */ -void jsync(struct jfs *fs) +int jsync(struct jfs *fs) { + int rv; struct jlinger *linger, *ltmp; - fsync(fs->fd); + pthread_mutex_lock(&(fs->lock)); + + rv = fsync(fs->fd); + if (rv != 0) + goto exit; linger = fs->ltrans; while (linger != NULL) { @@ -575,13 +580,17 @@ void jsync(struct jfs *fs) linger = ltmp; } + +exit: + pthread_mutex_unlock(&(fs->lock)); + return rv; } /* close a file */ int jclose(struct jfs *fs) { - jsync(fs); - + if (jsync(fs)) + return -1; if (close(fs->fd)) return -1; if (close(fs->jfd))