git » libjio » commit d75bbe8

[API BREAK] Make jtrans_add() return 0 on success and -1 on error

author Alberto Bertogli
2009-04-17 21:35:58 UTC
committer Alberto Bertogli
2009-04-18 00:35:00 UTC
parent 6d2d3b28f64edfe05107ddd5947512661c0f8f00

[API BREAK] Make jtrans_add() return 0 on success and -1 on error

That way it's more consistent with all the other functions.

As we're already breaking the API in this release, it's a good time to
make this change.

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

UPGRADING +2 -0
bindings/python2/libjio.c +1 -1
bindings/python3/libjio.c +1 -1
libjio/libjio.h +1 -1
libjio/trans.c +6 -6

diff --git a/UPGRADING b/UPGRADING
index 7962465..6cc3e10 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -13,6 +13,8 @@ take much effort. When it's mandatory, it will be noted.
       jtrans_free() frees it.
   - jtrans_commit() returns -1 on recovered errors, -2 on unrecovered errors
     (which are an indication of a severe underlying condition).
+  - jtrans_add() returns 0 on success and -1 on errors (it used to return 1 on
+    success and 0 on errors).
 
 -> 0.25
   - It is no longer necessary to pass O_SYNC to jopen() if lingering
diff --git a/bindings/python2/libjio.c b/bindings/python2/libjio.c
index 1e17b14..b48216d 100644
--- a/bindings/python2/libjio.c
+++ b/bindings/python2/libjio.c
@@ -470,7 +470,7 @@ static PyObject *jt_add(jtrans_object *tp, PyObject *args)
 		return NULL;
 
 	rv = jtrans_add(tp->ts, buf, len, offset);
-	if (rv == 0)
+	if (rv < 0)
 		return PyErr_SetFromErrno(PyExc_IOError);
 
 	return PyLong_FromLong(rv);
diff --git a/bindings/python3/libjio.c b/bindings/python3/libjio.c
index 32e1d41..afdc7d6 100644
--- a/bindings/python3/libjio.c
+++ b/bindings/python3/libjio.c
@@ -462,7 +462,7 @@ static PyObject *jt_add(jtrans_object *tp, PyObject *args)
 		return NULL;
 
 	rv = jtrans_add(tp->ts, buf, len, offset);
-	if (rv == 0)
+	if (rv < 0)
 		return PyErr_SetFromErrno(PyExc_IOError);
 
 	return PyLong_FromLong(rv);
diff --git a/libjio/libjio.h b/libjio/libjio.h
index 2e47f15..f3c0f13 100644
--- a/libjio/libjio.h
+++ b/libjio/libjio.h
@@ -129,7 +129,7 @@ jtrans_t *jtrans_init(jfs_t *fs);
  * @param buf buffer to write
  * @param count how many bytes from the buffer to write
  * @param offset offset to write at
- * @returns 1 on success, 0 on error
+ * @returns 0 on success, -1 on error
  */
 int jtrans_add(jtrans_t *ts, const void *buf, size_t count, off_t offset);
 
diff --git a/libjio/trans.c b/libjio/trans.c
index 2bb1b66..24fa823 100644
--- a/libjio/trans.c
+++ b/libjio/trans.c
@@ -84,12 +84,12 @@ int jtrans_add(struct jtrans *ts, const void *buf, size_t count, off_t offset)
 	/* fail for read-only accesses */
 	if (ts->flags & J_RDONLY) {
 		pthread_mutex_unlock(&(ts->lock));
-		return 0;
+		return -1;
 	}
 
 	if ((long long) ts->len + count > MAX_TSIZE) {
 		pthread_mutex_unlock(&(ts->lock));
-		return 0;
+		return -1;
 	}
 
 	/* find the last operation in the transaction and create a new one at
@@ -98,7 +98,7 @@ int jtrans_add(struct jtrans *ts, const void *buf, size_t count, off_t offset)
 		ts->op = malloc(sizeof(struct joper));
 		if (ts->op == NULL) {
 			pthread_mutex_unlock(&(ts->lock));
-			return 0;
+			return -1;
 		}
 		jop = ts->op;
 		jop->prev = NULL;
@@ -108,7 +108,7 @@ int jtrans_add(struct jtrans *ts, const void *buf, size_t count, off_t offset)
 		tmpop->next = malloc(sizeof(struct joper));
 		if (tmpop->next == NULL) {
 			pthread_mutex_unlock(&(ts->lock));
-			return 0;
+			return -1;
 		}
 		tmpop->next->prev = tmpop;
 		jop = tmpop->next;
@@ -124,7 +124,7 @@ int jtrans_add(struct jtrans *ts, const void *buf, size_t count, off_t offset)
 		}
 		free(jop);
 		pthread_mutex_unlock(&(ts->lock));
-		return 0;
+		return -1;
 	}
 
 	ts->numops++;
@@ -146,7 +146,7 @@ int jtrans_add(struct jtrans *ts, const void *buf, size_t count, off_t offset)
 		posix_fadvise(ts->fs->fd, offset, count, POSIX_FADV_WILLNEED);
 	}
 
-	return 1;
+	return 0;
 }
 
 /* Commit a transaction */