author | Alberto Bertogli
<albertito@blitiri.com.ar> 2009-04-17 21:13:58 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2009-04-18 00:35:00 UTC |
parent | c88c1173e46ad481c14c1fa97765d6c27e59d36d |
libjio/journal.c | +21 | -2 |
diff --git a/libjio/journal.c b/libjio/journal.c index 2055da9..550e1c3 100644 --- a/libjio/journal.c +++ b/libjio/journal.c @@ -303,11 +303,30 @@ error: * when journal_save() fails. */ int journal_free(struct journal_op *jop) { - unlink(jop->name); + int rv; + + rv = -1; + + if (unlink(jop->name)) { + /* we do not want to leave a possibly complete transaction + * file around when the transaction was not commited and the + * unlink failed, so we attempt to truncate it, and if that + * fails we corrupt the checksum as a last resort */ + if (ftruncate(jop->fd, 0) != 0) { + if (pwrite(jop->fd, "\0\0\0\0", 4, jop->curpos - 4) + != 4) + goto exit; + if (fdatasync(jop->fd) != 0) + goto exit; + } + } fiu_exit_on("jio/commit/pre_ok_free_tid"); free_tid(jop->fs, jop->id); + rv = 0; + +exit: close(jop->fd); if (jop->name) @@ -315,7 +334,7 @@ int journal_free(struct journal_op *jop) free(jop); - return 0; + return rv; }