external/e2fsprogs
リビジョン | 16ffbacc8ae687d89366175752469372ffe3c142 (tree) |
---|---|
日時 | 2017-04-27 09:08:47 |
作者 | Theodore Ts'o <tytso@mit....> |
コミッター | Keun-young Park |
e2fsck: update quota when optimizing the extent tree
If quota is enabled, optimizing the extent tree wouldn't update the
in-memory quota statistics, so that a subsequent e2fsck run would show
that the quota usage statistics on disk were incorrect.
Google-Bug-Id: 36391645
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
(cherry picked from commit 96c8e668f7c780dccbc12b7ecc4cac9a5db2bc97)
Change-Id: I429a0ac64b1cc9e5a288f61ba3942e391e575013
@@ -208,17 +208,19 @@ static int find_blocks(ext2_filsys fs, blk64_t *blocknr, e2_blkcnt_t blockcnt, | ||
208 | 208 | static errcode_t rebuild_extent_tree(e2fsck_t ctx, struct extent_list *list, |
209 | 209 | ext2_ino_t ino) |
210 | 210 | { |
211 | - struct ext2_inode inode; | |
211 | + struct ext2_inode_large inode; | |
212 | 212 | errcode_t retval; |
213 | 213 | ext2_extent_handle_t handle; |
214 | 214 | unsigned int i, ext_written; |
215 | 215 | struct ext2fs_extent *ex, extent; |
216 | + blk64_t start_val, delta; | |
216 | 217 | |
217 | 218 | list->count = 0; |
218 | 219 | list->blocks_freed = 0; |
219 | 220 | list->ino = ino; |
220 | 221 | list->ext_read = 0; |
221 | - e2fsck_read_inode(ctx, ino, &inode, "rebuild_extents"); | |
222 | + e2fsck_read_inode_full(ctx, ino, EXT2_INODE(&inode), sizeof(inode), | |
223 | + "rebuild_extents"); | |
222 | 224 | |
223 | 225 | /* Skip deleted inodes and inline data files */ |
224 | 226 | if (inode.i_links_count == 0 || |
@@ -248,16 +250,20 @@ extents_loaded: | ||
248 | 250 | memset(inode.i_block, 0, sizeof(inode.i_block)); |
249 | 251 | |
250 | 252 | /* Make a note of freed blocks */ |
251 | - retval = ext2fs_iblk_sub_blocks(ctx->fs, &inode, list->blocks_freed); | |
253 | + quota_data_sub(ctx->qctx, &inode, ino, | |
254 | + list->blocks_freed * ctx->fs->blocksize); | |
255 | + retval = ext2fs_iblk_sub_blocks(ctx->fs, EXT2_INODE(&inode), | |
256 | + list->blocks_freed); | |
252 | 257 | if (retval) |
253 | 258 | goto err; |
254 | 259 | |
255 | 260 | /* Now stuff extents into the file */ |
256 | - retval = ext2fs_extent_open2(ctx->fs, ino, &inode, &handle); | |
261 | + retval = ext2fs_extent_open2(ctx->fs, ino, EXT2_INODE(&inode), &handle); | |
257 | 262 | if (retval) |
258 | 263 | goto err; |
259 | 264 | |
260 | 265 | ext_written = 0; |
266 | + start_val = ext2fs_inode_i_blocks(ctx->fs, EXT2_INODE(&inode)); | |
261 | 267 | for (i = 0, ex = list->extents; i < list->count; i++, ex++) { |
262 | 268 | memcpy(&extent, ex, sizeof(struct ext2fs_extent)); |
263 | 269 | extent.e_flags &= EXT2_EXTENT_FLAGS_UNINIT; |
@@ -295,11 +301,21 @@ extents_loaded: | ||
295 | 301 | ext_written++; |
296 | 302 | } |
297 | 303 | |
304 | + delta = ext2fs_inode_i_blocks(ctx->fs, EXT2_INODE(&inode)) - start_val; | |
305 | + if (delta) { | |
306 | + if (!ext2fs_has_feature_huge_file(ctx->fs->super) || | |
307 | + !(inode.i_flags & EXT4_HUGE_FILE_FL)) | |
308 | + delta <<= 9; | |
309 | + else | |
310 | + delta *= ctx->fs->blocksize; | |
311 | + quota_data_add(ctx->qctx, &inode, ino, delta); | |
312 | + } | |
313 | + | |
298 | 314 | #if defined(DEBUG) || defined(DEBUG_SUMMARY) |
299 | 315 | printf("rebuild: ino=%d extents=%d->%d\n", ino, list->ext_read, |
300 | 316 | ext_written); |
301 | 317 | #endif |
302 | - e2fsck_write_inode(ctx, ino, &inode, "rebuild_extents"); | |
318 | + e2fsck_write_inode(ctx, ino, EXT2_INODE(&inode), "rebuild_extents"); | |
303 | 319 | |
304 | 320 | err2: |
305 | 321 | ext2fs_extent_free(handle); |