From 8d28536a5d3a10ecb6f4d1d4cb3b1337f685ed30 Mon Sep 17 00:00:00 2001
From: Alberto Bertogli <albertito@blitiri.com.ar>
Date: Thu, 23 Apr 2009 20:07:24 -0300
Subject: [PATCH 37/38] Check jtrans_add() return value in UNIX-alike API

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
---
 libjio/unix.c |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

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);
-- 
1.6.2.2.646.gb214

