inode.c (bad97817dece759dd6c0b24f862b7d0ed588edda) inode.c (9206c561554c948111d3cf6fc563a0beaaf790b3)
1/*
2 * linux/fs/ext4/inode.c
3 *
4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
8 *

--- 2164 unchanged lines hidden (view full) ---

2173}
2174
2175/*
2176 * mpage_map_and_submit_extent - map extent starting at mpd->lblk of length
2177 * mpd->len and submit pages underlying it for IO
2178 *
2179 * @handle - handle for journal operations
2180 * @mpd - extent to map
1/*
2 * linux/fs/ext4/inode.c
3 *
4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
8 *

--- 2164 unchanged lines hidden (view full) ---

2173}
2174
2175/*
2176 * mpage_map_and_submit_extent - map extent starting at mpd->lblk of length
2177 * mpd->len and submit pages underlying it for IO
2178 *
2179 * @handle - handle for journal operations
2180 * @mpd - extent to map
2181 * @give_up_on_write - we set this to true iff there is a fatal error and there
2182 * is no hope of writing the data. The caller should discard
2183 * dirty pages to avoid infinite loops.
2181 *
2182 * The function maps extent starting at mpd->lblk of length mpd->len. If it is
2183 * delayed, blocks are allocated, if it is unwritten, we may need to convert
2184 * them to initialized or split the described range from larger unwritten
2185 * extent. Note that we need not map all the described range since allocation
2186 * can return less blocks or the range is covered by more unwritten extents. We
2187 * cannot map more because we are limited by reserved transaction credits. On
2188 * the other hand we always make sure that the last touched page is fully

--- 101 unchanged lines hidden (view full) ---

2290 * unnecessary complication, it is actually inevitable in blocksize < pagesize
2291 * case as we need to track IO to all buffers underlying a page in one io_end.
2292 */
2293static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
2294{
2295 struct address_space *mapping = mpd->inode->i_mapping;
2296 struct pagevec pvec;
2297 unsigned int nr_pages;
2184 *
2185 * The function maps extent starting at mpd->lblk of length mpd->len. If it is
2186 * delayed, blocks are allocated, if it is unwritten, we may need to convert
2187 * them to initialized or split the described range from larger unwritten
2188 * extent. Note that we need not map all the described range since allocation
2189 * can return less blocks or the range is covered by more unwritten extents. We
2190 * cannot map more because we are limited by reserved transaction credits. On
2191 * the other hand we always make sure that the last touched page is fully

--- 101 unchanged lines hidden (view full) ---

2293 * unnecessary complication, it is actually inevitable in blocksize < pagesize
2294 * case as we need to track IO to all buffers underlying a page in one io_end.
2295 */
2296static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
2297{
2298 struct address_space *mapping = mpd->inode->i_mapping;
2299 struct pagevec pvec;
2300 unsigned int nr_pages;
2301 long left = mpd->wbc->nr_to_write;
2298 pgoff_t index = mpd->first_page;
2299 pgoff_t end = mpd->last_page;
2300 int tag;
2301 int i, err = 0;
2302 int blkbits = mpd->inode->i_blkbits;
2303 ext4_lblk_t lblk;
2304 struct buffer_head *head;
2305

--- 19 unchanged lines hidden (view full) ---

2325 * invalidated (changing page->mapping to NULL), or
2326 * even swizzled back from swapper_space to tmpfs file
2327 * mapping. However, page->index will not change
2328 * because we have a reference on the page.
2329 */
2330 if (page->index > end)
2331 goto out;
2332
2302 pgoff_t index = mpd->first_page;
2303 pgoff_t end = mpd->last_page;
2304 int tag;
2305 int i, err = 0;
2306 int blkbits = mpd->inode->i_blkbits;
2307 ext4_lblk_t lblk;
2308 struct buffer_head *head;
2309

--- 19 unchanged lines hidden (view full) ---

2329 * invalidated (changing page->mapping to NULL), or
2330 * even swizzled back from swapper_space to tmpfs file
2331 * mapping. However, page->index will not change
2332 * because we have a reference on the page.
2333 */
2334 if (page->index > end)
2335 goto out;
2336
2337 /*
2338 * Accumulated enough dirty pages? This doesn't apply
2339 * to WB_SYNC_ALL mode. For integrity sync we have to
2340 * keep going because someone may be concurrently
2341 * dirtying pages, and we might have synced a lot of
2342 * newly appeared dirty pages, but have not synced all
2343 * of the old dirty pages.
2344 */
2345 if (mpd->wbc->sync_mode == WB_SYNC_NONE && left <= 0)
2346 goto out;
2347
2333 /* If we can't merge this page, we are done. */
2334 if (mpd->map.m_len > 0 && mpd->next_page != page->index)
2335 goto out;
2336
2337 lock_page(page);
2338 /*
2339 * If the page is no longer dirty, or its mapping no
2340 * longer corresponds to inode we are writing (which

--- 18 unchanged lines hidden (view full) ---

2359 /* Add all dirty buffers to mpd */
2360 lblk = ((ext4_lblk_t)page->index) <<
2361 (PAGE_CACHE_SHIFT - blkbits);
2362 head = page_buffers(page);
2363 err = mpage_process_page_bufs(mpd, head, head, lblk);
2364 if (err <= 0)
2365 goto out;
2366 err = 0;
2348 /* If we can't merge this page, we are done. */
2349 if (mpd->map.m_len > 0 && mpd->next_page != page->index)
2350 goto out;
2351
2352 lock_page(page);
2353 /*
2354 * If the page is no longer dirty, or its mapping no
2355 * longer corresponds to inode we are writing (which

--- 18 unchanged lines hidden (view full) ---

2374 /* Add all dirty buffers to mpd */
2375 lblk = ((ext4_lblk_t)page->index) <<
2376 (PAGE_CACHE_SHIFT - blkbits);
2377 head = page_buffers(page);
2378 err = mpage_process_page_bufs(mpd, head, head, lblk);
2379 if (err <= 0)
2380 goto out;
2381 err = 0;
2367
2368 /*
2369 * Accumulated enough dirty pages? This doesn't apply
2370 * to WB_SYNC_ALL mode. For integrity sync we have to
2371 * keep going because someone may be concurrently
2372 * dirtying pages, and we might have synced a lot of
2373 * newly appeared dirty pages, but have not synced all
2374 * of the old dirty pages.
2375 */
2376 if (mpd->wbc->sync_mode == WB_SYNC_NONE &&
2377 mpd->next_page - mpd->first_page >=
2378 mpd->wbc->nr_to_write)
2379 goto out;
2382 left--;
2380 }
2381 pagevec_release(&pvec);
2382 cond_resched();
2383 }
2384 return 0;
2385out:
2386 pagevec_release(&pvec);
2387 return err;

--- 27 unchanged lines hidden (view full) ---

2415 trace_ext4_writepages(inode, wbc);
2416
2417 /*
2418 * No pages to write? This is mainly a kludge to avoid starting
2419 * a transaction for special inodes like journal inode on last iput()
2420 * because that could violate lock ordering on umount
2421 */
2422 if (!mapping->nrpages || !mapping_tagged(mapping, PAGECACHE_TAG_DIRTY))
2383 }
2384 pagevec_release(&pvec);
2385 cond_resched();
2386 }
2387 return 0;
2388out:
2389 pagevec_release(&pvec);
2390 return err;

--- 27 unchanged lines hidden (view full) ---

2418 trace_ext4_writepages(inode, wbc);
2419
2420 /*
2421 * No pages to write? This is mainly a kludge to avoid starting
2422 * a transaction for special inodes like journal inode on last iput()
2423 * because that could violate lock ordering on umount
2424 */
2425 if (!mapping->nrpages || !mapping_tagged(mapping, PAGECACHE_TAG_DIRTY))
2423 return 0;
2426 goto out_writepages;
2424
2425 if (ext4_should_journal_data(inode)) {
2426 struct blk_plug plug;
2427
2428 if (ext4_should_journal_data(inode)) {
2429 struct blk_plug plug;
2427 int ret;
2428
2429 blk_start_plug(&plug);
2430 ret = write_cache_pages(mapping, wbc, __writepage, mapping);
2431 blk_finish_plug(&plug);
2430
2431 blk_start_plug(&plug);
2432 ret = write_cache_pages(mapping, wbc, __writepage, mapping);
2433 blk_finish_plug(&plug);
2432 return ret;
2434 goto out_writepages;
2433 }
2434
2435 /*
2436 * If the filesystem has aborted, it is read-only, so return
2437 * right away instead of dumping stack traces later on that
2438 * will obscure the real source of the problem. We test
2439 * EXT4_MF_FS_ABORTED instead of sb->s_flag's MS_RDONLY because
2440 * the latter could be true if the filesystem is mounted
2441 * read-only, and in that case, ext4_writepages should
2442 * *never* be called, so if that ever happens, we would want
2443 * the stack trace.
2444 */
2435 }
2436
2437 /*
2438 * If the filesystem has aborted, it is read-only, so return
2439 * right away instead of dumping stack traces later on that
2440 * will obscure the real source of the problem. We test
2441 * EXT4_MF_FS_ABORTED instead of sb->s_flag's MS_RDONLY because
2442 * the latter could be true if the filesystem is mounted
2443 * read-only, and in that case, ext4_writepages should
2444 * *never* be called, so if that ever happens, we would want
2445 * the stack trace.
2446 */
2445 if (unlikely(sbi->s_mount_flags & EXT4_MF_FS_ABORTED))
2446 return -EROFS;
2447 if (unlikely(sbi->s_mount_flags & EXT4_MF_FS_ABORTED)) {
2448 ret = -EROFS;
2449 goto out_writepages;
2450 }
2447
2448 if (ext4_should_dioread_nolock(inode)) {
2449 /*
2450 * We may need to convert up to one extent per block in
2451 * the page and we may dirty the inode.
2452 */
2453 rsv_blocks = 1 + (PAGE_CACHE_SIZE >> inode->i_blkbits);
2454 }

--- 2230 unchanged lines hidden (view full) ---

4685{
4686 struct inode *inode;
4687 unsigned long long delalloc_blocks;
4688
4689 inode = dentry->d_inode;
4690 generic_fillattr(inode, stat);
4691
4692 /*
2451
2452 if (ext4_should_dioread_nolock(inode)) {
2453 /*
2454 * We may need to convert up to one extent per block in
2455 * the page and we may dirty the inode.
2456 */
2457 rsv_blocks = 1 + (PAGE_CACHE_SIZE >> inode->i_blkbits);
2458 }

--- 2230 unchanged lines hidden (view full) ---

4689{
4690 struct inode *inode;
4691 unsigned long long delalloc_blocks;
4692
4693 inode = dentry->d_inode;
4694 generic_fillattr(inode, stat);
4695
4696 /*
4697 * If there is inline data in the inode, the inode will normally not
4698 * have data blocks allocated (it may have an external xattr block).
4699 * Report at least one sector for such files, so tools like tar, rsync,
4700 * others doen't incorrectly think the file is completely sparse.
4701 */
4702 if (unlikely(ext4_has_inline_data(inode)))
4703 stat->blocks += (stat->size + 511) >> 9;
4704
4705 /*
4693 * We can't update i_blocks if the block allocation is delayed
4694 * otherwise in the case of system crash before the real block
4695 * allocation is done, we will have i_blocks inconsistent with
4696 * on-disk file blocks.
4697 * We always keep i_blocks updated together with real
4698 * allocation. But to not confuse with user, stat
4699 * will return the blocks that include the delayed allocation
4700 * blocks for this file.
4701 */
4702 delalloc_blocks = EXT4_C2B(EXT4_SB(inode->i_sb),
4706 * We can't update i_blocks if the block allocation is delayed
4707 * otherwise in the case of system crash before the real block
4708 * allocation is done, we will have i_blocks inconsistent with
4709 * on-disk file blocks.
4710 * We always keep i_blocks updated together with real
4711 * allocation. But to not confuse with user, stat
4712 * will return the blocks that include the delayed allocation
4713 * blocks for this file.
4714 */
4715 delalloc_blocks = EXT4_C2B(EXT4_SB(inode->i_sb),
4703 EXT4_I(inode)->i_reserved_data_blocks);
4704
4705 stat->blocks += delalloc_blocks << (inode->i_sb->s_blocksize_bits-9);
4716 EXT4_I(inode)->i_reserved_data_blocks);
4717 stat->blocks += delalloc_blocks << (inode->i_sb->s_blocksize_bits - 9);
4706 return 0;
4707}
4708
4709static int ext4_index_trans_blocks(struct inode *inode, int lblocks,
4710 int pextents)
4711{
4712 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
4713 return ext4_ind_trans_blocks(inode, lblocks);

--- 446 unchanged lines hidden ---
4718 return 0;
4719}
4720
4721static int ext4_index_trans_blocks(struct inode *inode, int lblocks,
4722 int pextents)
4723{
4724 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
4725 return ext4_ind_trans_blocks(inode, lblocks);

--- 446 unchanged lines hidden ---