Page MenuHomeFreeBSD

D61937.1795575076.diff
No OneTemporary

Authored By
Unknown
Size
6 KB
Referenced Files
None
Subscribers
None

D61937.1795575076.diff

Index: sys/fs/ext2fs/ext2_alloc.c
===================================================================
--- sys/fs/ext2fs/ext2_alloc.c
+++ sys/fs/ext2fs/ext2_alloc.c
@@ -190,12 +190,12 @@
fs = ip->i_e2fs;
/* Hard caps: free blocks, cluster summaries, group size, sysctl. */
- maxlen = (uint32_t)fs->e2fs_fbcount;
- if (fs->e2fs_contigsumsize > 0 && (uint32_t)fs->e2fs_contigsumsize < maxlen)
+ maxlen = fs->e2fs_fbcount;
+ if (fs->e2fs_contigsumsize > 0 && (uint64_t)fs->e2fs_contigsumsize < maxlen)
maxlen = fs->e2fs_contigsumsize;
- if ((uint32_t)fs->e2fs_bpg < maxlen)
+ if ((uint64_t)fs->e2fs_bpg < maxlen)
maxlen = fs->e2fs_bpg;
- if ((uint32_t)ext2_alloc_max_run < maxlen)
+ if ((uint64_t)ext2_alloc_max_run < maxlen)
maxlen = ext2_alloc_max_run;
if (maxlen < logical_length)
return (0);
@@ -1617,7 +1617,7 @@
fs->e2fs_maxcluster[cg] = i;
goto fail;
}
- mtx_assert(EXT2_MTX(ump), MA_NOTOWNED);
+ mtx_assert(EXT2_MTX(ump), MA_OWNED);
EXT2_UNLOCK(ump);
/* Search the bitmap to find a big enough cluster like in FFS. */
@@ -1656,6 +1656,19 @@
panic("ext2_clusteralloc: allocated out of group");
EXT2_LOCK(ump);
+ if (EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_GDT_CSUM) ||
+ EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_METADATA_CKSUM)) {
+ error = ext2_gd_b_bitmap_csum_verify(fs, cg, bp);
+ if (error) {
+ EXT2_UNLOCK(ump);
+ goto fail_lock;
+ }
+ }
+ error = ext2_b_bitmap_validate(fs, bp, cg);
+ if (error) {
+ EXT2_UNLOCK(ump);
+ goto fail_lock;
+ }
for (i = 0; i < len; i += fs->e2fs_fpb) {
setbit(bbp, bno + i);
ext2_clusteracct(fs, bbp, cg, bno + i, -1);
@@ -1666,6 +1679,8 @@
fs->e2fs_fmod = 1;
EXT2_UNLOCK(ump);
+ ext2_gd_b_bitmap_csum_set(fs, cg, bp);
+ ext2_b_bitmap_validate(fs, bp, cg);
bdwrite(bp);
return (cg * fs->e2fs_bpg + le32toh(fs->e2fs->e2fs_first_dblock)
+ bno);
Index: sys/fs/ext2fs/ext2_balloc.c
===================================================================
--- sys/fs/ext2fs/ext2_balloc.c
+++ sys/fs/ext2fs/ext2_balloc.c
@@ -215,6 +215,7 @@
* Write synchronously so that indirect blocks
* never point at garbage.
*/
+ bp->b_flags |= B_INVALONERR;
if ((error = bwrite(bp)) != 0) {
/* bwrite() released bp; pref is still unreferenced. */
ext2_rollback_unpublished(ip, pref, 1);
@@ -264,6 +265,7 @@
* Write synchronously so that indirect blocks
* never point at garbage.
*/
+ nbp->b_flags |= B_INVALONERR;
if ((error = bwrite(nbp)) != 0) {
/* bwrite() released nbp; pref is still unreferenced. */
ext2_rollback_unpublished(ip, pref, 1);
@@ -278,6 +280,7 @@
* at the top of the next iteration.
*/
if (flags & IO_SYNC) {
+ bp->b_flags |= B_INVALONERR;
if ((error = bwrite(bp)) != 0) {
/*
* The child indirect block is on disk but
@@ -340,6 +343,7 @@
* delayed write.
*/
if (flags & IO_SYNC) {
+ bp->b_flags |= B_INVALONERR;
if ((error = bwrite(bp)) != 0) {
/*
* The parent indirect block did not reach
Index: sys/fs/ext2fs/ext2_extents.c
===================================================================
--- sys/fs/ext2fs/ext2_extents.c
+++ sys/fs/ext2fs/ext2_extents.c
@@ -830,20 +830,9 @@
return (EIO);
ext4_ext_fill_path_buf(path, bp);
ext2_extent_blk_csum_set(ip, bp->b_data);
+ bp->b_flags |= B_INVALONERR;
error = bwrite(bp);
if (error) {
- /*
- * bwrite() left the modified extent tree dirty in
- * the cache. Discard it, so a later read sees the
- * on-disk tree instead of one naming blocks the
- * caller's rollback is about to free.
- */
- bp = getblk(ip->i_devvp, fsbtodb(fs, blk),
- fs->e2fs_bsize, 0, 0, 0);
- if (bp) {
- bundirty(bp);
- brelse(bp);
- }
return (error);
}
} else {
@@ -972,8 +961,10 @@
M_EXT2EXTENTS, M_WAITOK | M_ZERO);
for (a = 0; a < depth - at; a++) {
newblk = ext4_ext_alloc_meta(ip);
- if (newblk == 0)
+ if (newblk == 0) {
+ error = ENOSPC;
goto cleanup;
+ }
ablks[a] = newblk;
}
@@ -1013,6 +1004,7 @@
}
ext2_extent_blk_csum_set(ip, bp->b_data);
+ bp->b_flags |= B_INVALONERR;
error = bwrite(bp);
bp = NULL;
if (error)
@@ -1063,14 +1055,16 @@
neh->eh_ecount = htole16(le16toh(neh->eh_ecount) + m);
}
- ext2_extent_blk_csum_set(ip, bp->b_data);
- error = bwrite(bp);
- bp = NULL;
- if (error)
- goto cleanup;
+ext2_extent_blk_csum_set(ip, bp->b_data);
+ bp->b_flags |= B_INVALONERR;
+ error = bwrite(bp);
+ bp = NULL;
+ if (error) {
+ goto cleanup;
+ }
- /* Fix old index. */
- if (m) {
+ /* Fix old index. */
+ if (m) {
path[i].ep_header->eh_ecount =
htole16(le16toh(path[i].ep_header->eh_ecount) - m);
error = ext4_ext_dirty(ip, path + i);
@@ -1117,7 +1111,7 @@
newblk = ext4_ext_alloc_meta(ip);
if (newblk == 0)
- return (error);
+ return (ENOSPC);
bp = getblk(ip->i_devvp, fsbtodb(fs, newblk), fs->e2fs_bsize, 0, 0, 0);
if (!bp) {
@@ -1138,9 +1132,11 @@
neh->eh_max = htole16(ext4_ext_space_block(ip));
ext2_extent_blk_csum_set(ip, bp->b_data);
+ bp->b_flags |= B_INVALONERR;
error = bwrite(bp);
if (error) {
ext2_rollback_unpublished(ip, newblk, 1);
+ bp = NULL;
goto out;
}
@@ -1274,6 +1270,8 @@
struct ext4_extent *ex, *nex, *nearex;
struct ext4_extent_path *npath;
int depth, len, error, next;
+ char saved_i_data[sizeof(ip->i_data)];
+ bool saved_i_data_valid = false;
depth = ext4_ext_inode_depth(ip);
ex = path[depth].ep_ext;
@@ -1284,6 +1282,10 @@
/* Insert block into found extent. */
if (ex && ext4_can_extents_be_merged(ex, newext)) {
+ if (depth == 0) {
+ memcpy(saved_i_data, ip->i_data, sizeof(ip->i_data));
+ saved_i_data_valid = true;
+ }
ex->e_len = htole16(le16toh(ex->e_len) + le16toh(newext->e_len));
eh = path[depth].ep_header;
nearex = ex;
@@ -1332,6 +1334,10 @@
eh = path[depth].ep_header;
has_space:
+ if (depth == 0 && !saved_i_data_valid) {
+ memcpy(saved_i_data, ip->i_data, sizeof(ip->i_data));
+ saved_i_data_valid = true;
+ }
nearex = path[depth].ep_ext;
if (!nearex) {
/* Create new extent in the leaf. */
@@ -1387,8 +1393,12 @@
goto cleanup;
error = ext4_ext_dirty(ip, path + depth);
- if (error)
+ if (error) {
+ if (depth == 0 && saved_i_data_valid) {
+ memcpy(ip->i_data, saved_i_data, sizeof(ip->i_data));
+ }
goto cleanup;
+ }
/*
* ext4_ext_dirty() wrote the tree out, so the extent now names

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 25, 2:51 AM (22 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41952111
Default Alt Text
D61937.1795575076.diff (6 KB)

Event Timeline