Commit 8085cd28 authored by Dave Kleikamp's avatar Dave Kleikamp

Fix free-space leak truncating files in JFS.

There was a bug truncating large files to non-zero lengths which led
to space not being marked free in the block map.
parent 9d260518
......@@ -720,6 +720,8 @@ tlock_t *txLock(tid_t tid, struct inode *ip, metapage_t * mp, int type)
le16_to_cpu(p->header.nextindex);
}
xtlck->lwm.length = 0; /* ! */
xtlck->twm.offset = 0;
xtlck->hwm.offset = 0;
xtlck->index = 2;
break;
......@@ -1868,6 +1870,7 @@ void xtLog(log_t * log, tblock_t * tblk, lrd_t * lrd, tlock_t * tlck)
*/
if (tlck->type & tlckTRUNCATE) {
pxd_t tpxd; /* truncated extent of xad */
int twm;
/*
* For truncation the entire linelock may be used, so it would
......@@ -1881,6 +1884,7 @@ void xtLog(log_t * log, tblock_t * tblk, lrd_t * lrd, tlock_t * tlck)
if (lwm == 0)
lwm = XTPAGEMAXSLOT;
hwm = xtlck->hwm.offset;
twm = xtlck->twm.offset;
/*
* write log records
......@@ -1906,9 +1910,9 @@ void xtLog(log_t * log, tblock_t * tblk, lrd_t * lrd, tlock_t * tlck)
}
/*
* truncate entry XAD[hwm == next - 1]:
* truncate entry XAD[twm == next - 1]:
*/
if (hwm == next - 1) {
if (twm == next - 1) {
/* init LOG_UPDATEMAP for logredo() to update bmap for
* free of truncated delta extent of the truncated
* entry XAD[next - 1]:
......@@ -1975,9 +1979,9 @@ void xtLog(log_t * log, tblock_t * tblk, lrd_t * lrd, tlock_t * tlck)
}
/*
* truncate entry XAD[hwm == next - 1]:
* truncate entry XAD[twm == next - 1]:
*/
if (hwm == next - 1) {
if (twm == next - 1) {
pxdlock_t *pxdlock;
/* format a maplock for txUpdateMap() to update bmap
......
......@@ -3574,6 +3574,7 @@ s64 xtTruncate(tid_t tid, struct inode *ip, s64 newsize, int flag)
min(index, (int)xtlck->lwm.offset) : index;
xtlck->lwm.length = index + 1 -
xtlck->lwm.offset;
xtlck->twm.offset = index;
pxdlock = (pxdlock_t *) & xtlck->pxdlock;
pxdlock->flag = mlckFREEPXD;
PXDaddress(&pxdlock->pxd, xaddr);
......@@ -3705,7 +3706,6 @@ s64 xtTruncate(tid_t tid, struct inode *ip, s64 newsize, int flag)
*/
tlck = txLock(tid, ip, mp, tlckXTREE);
xtlck = (xtlock_t *) & tlck->lock;
xtlck->twm.offset = index;
if (!(tlck->type & tlckTRUNCATE)) {
xtlck->hwm.offset =
le16_to_cpu(p->header.
......@@ -3782,7 +3782,6 @@ s64 xtTruncate(tid_t tid, struct inode *ip, s64 newsize, int flag)
*/
tlck = txLock(tid, ip, mp, tlckXTREE);
xtlck = (xtlock_t *) & tlck->lock;
xtlck->twm.offset = index;
xtlck->hwm.offset =
le16_to_cpu(p->header.nextindex) - 1;
tlck->type = tlckXTREE | tlckFREE;
......@@ -3989,11 +3988,10 @@ s64 xtTruncate_pmap(tid_t tid, struct inode *ip, s64 committed_size)
return (xoff + xlen) << JFS_SBI(ip->i_sb)->l2bsize;
}
tlck = txLock(tid, ip, mp, tlckXTREE);
tlck->type = tlckXTREE | tlckTRUNCATE;
tlck->type = tlckXTREE | tlckFREE;
xtlck = (xtlock_t *) & tlck->lock;
xtlck->hwm.offset = index;
tlck->type = tlckXTREE | tlckFREE;
XT_PUTPAGE(mp);
......@@ -4024,7 +4022,6 @@ s64 xtTruncate_pmap(tid_t tid, struct inode *ip, s64 committed_size)
*/
tlck = txLock(tid, ip, mp, tlckXTREE);
xtlck = (xtlock_t *) & tlck->lock;
xtlck->twm.offset = index;
xtlck->hwm.offset =
le16_to_cpu(p->header.nextindex) - 1;
tlck->type = tlckXTREE | tlckFREE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment