

I can't believe I didn't see it before. It's so obvious.

Instead of reading the current contents and write the previous data to the
disk, we should write current data. The library doesn't have the "j" just
because.

While at it, resurrect the old J_NOROLLBACK from the dead, so people that
don't need to rollback transactions will pay the penalty.

This is also paving the road for lingering transactions.


---

 cur-root/check.c   |   17 ++++++++++++-----
 cur-root/jiofsck.c |    2 +-
 cur-root/libjio.h  |    3 ++-
 cur-root/trans.c   |   18 ++++++++++--------
 4 files changed, 25 insertions(+), 15 deletions(-)

diff -puN trans.c~write_real_data trans.c
--- cur/trans.c~write_real_data	2004-07-13 18:16:42.261527912 -0300
+++ cur-root/trans.c	2004-07-13 18:16:42.267527000 -0300
@@ -265,10 +265,11 @@ int jtrans_commit(struct jtrans *ts)
 
 	/* save each transacion in the file */
 	for (op = ts->op; op != NULL; op = op->next) {
-		/* read the current content only if it's not there yet, which
-		 * is the normal case, but for rollbacking we fill it
+		/* read the current content only if the transaction is not
+		 * marked as NOROLLBACK, and if the data is not there yet,
+		 * which is the normal case, but for rollbacking we fill it
 		 * ourselves */
-		if (op->pdata == NULL) {
+		if (!(ts->flags & J_NOROLLBACK) && (op->pdata == NULL)) {
 			op->pdata = malloc(op->len);
 			if (op->pdata == NULL)
 				goto exit;
@@ -313,11 +314,11 @@ int jtrans_commit(struct jtrans *ts)
 		curpos += J_DISKOPHEADSIZE;
 
 		/* and save it to the disk */
-		rv = spwrite(fd, op->pdata, op->plen, curpos);
-		if (rv != op->plen)
+		rv = spwrite(fd, op->buf, op->len, curpos);
+		if (rv != op->len)
 			goto exit;
 
-		curpos += op->plen;
+		curpos += op->len;
 	}
 
 	/* this is a simple but efficient optimization: instead of doing
@@ -388,8 +389,9 @@ int jtrans_rollback(struct jtrans *ts)
 
 	/* FIXME: this looks like a mess! */
 
-	if (ts->op == NULL) {
-		/* we're trying to rollback an empty transaction */
+	if (ts->op == NULL || ts->flags & J_NOROLLBACK) {
+		/* we're either trying to rollback an empty or transaction, or
+		 * a one marked without rollbacking support */
 		return 0;
 	}
 
diff -puN libjio.h~write_real_data libjio.h
--- cur/libjio.h~write_real_data	2004-07-13 18:16:42.262527760 -0300
+++ cur-root/libjio.h	2004-07-13 18:16:42.267527000 -0300
@@ -59,7 +59,7 @@ struct jfsck_result {
 	int in_progress;	/* transactions in progress */
 	int broken;		/* transactions broken */
 	int apply_error;	/* errors applying the transaction */
-	int rollbacked;		/* transactions that were rollbacked */
+	int reapplied;		/* transactions that were reapplied */
 };
 
 
@@ -122,6 +122,7 @@ FILE *jfsopen(struct jfs *stream, const 
 
 /* jfs constants */
 #define J_NOLOCK	1	/* don't lock the file before operating on it */
+#define J_NOROLLBACK	2	/* no need to read rollback information */
 
 /* jtrans constants */
 #define J_COMMITED	1	/* mark a transaction as commited */
diff -puN check.c~write_real_data check.c
--- cur/check.c~write_real_data	2004-07-13 18:16:42.263527608 -0300
+++ cur-root/check.c	2004-07-13 18:16:42.267527000 -0300
@@ -60,11 +60,11 @@ static int fill_trans(unsigned char *map
 		op->offset = *( (uint64_t *) p);
 		p += 8;
 
-		if (len < (p - map) + op->plen)
+		if (len < (p - map) + op->len)
 			goto error;
 
-		op->pdata = (void *) p;
-		p += op->plen;
+		op->buf = (void *) p;
+		p += op->len;
 
 		if (ts->op == NULL) {
 			ts->op = op;
@@ -117,6 +117,10 @@ int jfsck(const char *name, struct jfsck
 	if (rv < 0 || !S_ISDIR(sinfo.st_mode))
 		return J_ENOJOURNAL;
 
+	fs.jdirfd = open(jdir, O_RDONLY);
+	if (fs.jdirfd < 0)
+		return J_ENOJOURNAL;
+
 	/* open the lock file, which is only used to complete the jfs
 	 * structure */
 	snprintf(jlockfile, PATH_MAX, "%s/%s", jdir, "lock");
@@ -188,7 +192,10 @@ int jfsck(const char *name, struct jfsck
 			goto loop;
 		}
 
-		rv = jtrans_rollback(curts);
+		/* remove flags from the transaction */
+		curts->flags = 0;
+
+		rv = jtrans_commit(curts);
 
 		munmap(map, filelen);
 
@@ -196,7 +203,7 @@ int jfsck(const char *name, struct jfsck
 			res->apply_error++;
 			goto loop;
 		}
-		res->rollbacked++;
+		res->reapplied++;
 
 
 loop:
diff -puN jiofsck.c~write_real_data jiofsck.c
--- cur/jiofsck.c~write_real_data	2004-07-13 18:16:42.265527304 -0300
+++ cur-root/jiofsck.c	2004-07-13 18:16:42.267527000 -0300
@@ -76,7 +76,7 @@ int main(int argc, char **argv)
 	printf("In progress:\t %d\n", res.in_progress);
 	printf("Broken:\t\t %d\n", res.broken);
 	printf("Apply error:\t %d\n", res.apply_error);
-	printf("Rollbacked:\t %d\n", res.rollbacked);
+	printf("Reapplied:\t %d\n", res.reapplied);
 	printf("\n");
 
 	if (!do_cleanup) {

_
