
Fix jsync locking (we don't need fs->lock for fsync()), and add locking around
sections that touch the linger list (updating the comment too).


---

 cur-root/trans.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diff -puN trans.c~jsync_locking trans.c
--- cur/trans.c~jsync_locking	2004-08-28 21:47:04.000000000 -0300
+++ cur-root/trans.c	2004-08-30 00:51:26.993220472 -0300
@@ -363,9 +363,11 @@ ssize_t jtrans_commit(struct jtrans *ts)
 
 		linger->id = id;
 		linger->name = strdup(name);
-		linger->next = ts->fs->ltrans;
 
+		pthread_mutex_lock(&(ts->fs->lock));
+		linger->next = ts->fs->ltrans;
 		ts->fs->ltrans = linger;
+		pthread_mutex_unlock(&(ts->fs->lock));
 	} else {
 		/* the transaction has been applied, so we cleanup and remove
 		 * it from the disk */
@@ -522,10 +524,10 @@ int jopen(struct jfs *fs, const char *na
 	fs->flags = jflags;
 	fs->ltrans = NULL;
 
-	/* Note on fs->lock usage: this lock is used only inside the wrappers,
-	 * and exclusively to protect the file pointer. This means that it
-	 * must only be held while performing operations that depend or alter
-	 * the file pointer (jread, jreadv, jwrite, jwritev), but the others
+	/* Note on fs->lock usage: this lock is used only to protect the file
+	 * pointer and the linger list. This means that it must only be held
+	 * while performing operations that depend or alter the file pointer
+	 * or the linger list (jread, jreadv, jwrite, jwritev), but the others
 	 * (jpread, jpwrite) are left unprotected because they can be
 	 * performed in paralell as long as they don't affect the same portion
 	 * of the file (this is protected by lockf). The lock doesn't slow
@@ -596,12 +598,11 @@ int jsync(struct jfs *fs)
 	int rv;
 	struct jlinger *linger, *ltmp;
 
-	pthread_mutex_lock(&(fs->lock));
-
 	rv = fsync(fs->fd);
 	if (rv != 0)
-		goto exit;
+		return rv;
 
+	pthread_mutex_lock(&(fs->lock));
 	linger = fs->ltrans;
 	while (linger != NULL) {
 		free_tid(fs, linger->id);
@@ -614,9 +615,8 @@ int jsync(struct jfs *fs)
 		linger = ltmp;
 	}
 
-exit:
 	pthread_mutex_unlock(&(fs->lock));
-	return rv;
+	return 0;
 }
 
 /* close a file */
_
