git » libjio » commit 8d28536

Check jtrans_add() return value in UNIX-alike API

author Alberto Bertogli
2009-04-23 23:07:24 UTC
committer Alberto Bertogli
2009-04-23 23:07:48 UTC
parent 0c91c44c44415ee1484ee9a189ca5428891eaa4d

Check jtrans_add() return value in UNIX-alike API

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

libjio/unix.c +14 -3

diff --git a/libjio/unix.c b/libjio/unix.c
index bd202ae..1a67847 100644
--- a/libjio/unix.c
+++ b/libjio/unix.c
@@ -98,7 +98,9 @@ ssize_t jwrite(struct jfs *fs, const void *buf, size_t count)
 	else
 		pos = lseek(fs->fd, 0, SEEK_CUR);
 
-	jtrans_add(ts, buf, count, pos);
+	rv = jtrans_add(ts, buf, count, pos);
+	if (rv < 0)
+		goto exit;
 
 	rv = jtrans_commit(ts);
 
@@ -107,6 +109,8 @@ ssize_t jwrite(struct jfs *fs, const void *buf, size_t count)
 		lseek(fs->fd, rv, SEEK_CUR);
 	}
 
+exit:
+
 	pthread_mutex_unlock(&(fs->lock));
 
 	jtrans_free(ts);
@@ -124,10 +128,13 @@ ssize_t jpwrite(struct jfs *fs, const void *buf, size_t count, off_t offset)
 	if (ts == NULL)
 		return -1;
 
-	jtrans_add(ts, buf, count, offset);
+	rv = jtrans_add(ts, buf, count, offset);
+	if (rv < 0)
+		goto exit;
 
 	rv = jtrans_commit(ts);
 
+exit:
 	jtrans_free(ts);
 
 	return rv;
@@ -156,7 +163,10 @@ ssize_t jwritev(struct jfs *fs, const struct iovec *vector, int count)
 
 	sum = 0;
 	for (i = 0; i < count; i++) {
-		jtrans_add(ts, vector[i].iov_base, vector[i].iov_len, t);
+		rv = jtrans_add(ts, vector[i].iov_base, vector[i].iov_len, t);
+		if (rv < 0)
+			goto exit;
+
 		sum += vector[i].iov_len;
 		t += vector[i].iov_len;
 	}
@@ -168,6 +178,7 @@ ssize_t jwritev(struct jfs *fs, const struct iovec *vector, int count)
 		lseek(fs->fd, rv, SEEK_CUR);
 	}
 
+exit:
 	pthread_mutex_unlock(&(fs->lock));
 
 	jtrans_free(ts);