inode.c (f0e6c98593eb8a77edb7dd0edb22bb9f9368c567) | inode.c (632eaeab1feb5d78c1e2bfb1d2dfc0ebb8ac187f) |
---|---|
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 * --- 2284 unchanged lines hidden (view full) --- 2293 } 2294 2295 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) 2296 goto retry; 2297out: 2298 return ret; 2299} 2300 | 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 * --- 2284 unchanged lines hidden (view full) --- 2293 } 2294 2295 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) 2296 goto retry; 2297out: 2298 return ret; 2299} 2300 |
2301/* 2302 * Check if we should update i_disksize 2303 * when write to the end of file but not require block allocation 2304 */ 2305static int ext4_da_should_update_i_disksize(struct page *page, 2306 unsigned long offset) 2307{ 2308 struct buffer_head *bh; 2309 struct inode *inode = page->mapping->host; 2310 unsigned int idx; 2311 int i; 2312 2313 bh = page_buffers(page); 2314 idx = offset >> inode->i_blkbits; 2315 2316 for (i=0; i < idx; i++) 2317 bh = bh->b_this_page; 2318 2319 if (!buffer_mapped(bh) || (buffer_delay(bh))) 2320 return 0; 2321 return 1; 2322} 2323 |
|
2301static int ext4_da_write_end(struct file *file, 2302 struct address_space *mapping, 2303 loff_t pos, unsigned len, unsigned copied, 2304 struct page *page, void *fsdata) 2305{ 2306 struct inode *inode = mapping->host; 2307 int ret = 0, ret2; 2308 handle_t *handle = ext4_journal_current_handle(); 2309 loff_t new_i_size; | 2324static int ext4_da_write_end(struct file *file, 2325 struct address_space *mapping, 2326 loff_t pos, unsigned len, unsigned copied, 2327 struct page *page, void *fsdata) 2328{ 2329 struct inode *inode = mapping->host; 2330 int ret = 0, ret2; 2331 handle_t *handle = ext4_journal_current_handle(); 2332 loff_t new_i_size; |
2333 unsigned long start, end; |
|
2310 | 2334 |
2335 start = pos & (PAGE_CACHE_SIZE - 1); 2336 end = start + copied -1; 2337 |
|
2311 /* 2312 * generic_write_end() will run mark_inode_dirty() if i_size 2313 * changes. So let's piggyback the i_disksize mark_inode_dirty 2314 * into that. 2315 */ 2316 2317 new_i_size = pos + copied; | 2338 /* 2339 * generic_write_end() will run mark_inode_dirty() if i_size 2340 * changes. So let's piggyback the i_disksize mark_inode_dirty 2341 * into that. 2342 */ 2343 2344 new_i_size = pos + copied; |
2318 if (new_i_size > EXT4_I(inode)->i_disksize) 2319 if (!walk_page_buffers(NULL, page_buffers(page), 2320 0, len, NULL, ext4_bh_unmapped_or_delay)){ 2321 /* 2322 * Updating i_disksize when extending file without 2323 * needing block allocation 2324 */ 2325 if (ext4_should_order_data(inode)) 2326 ret = ext4_jbd2_file_inode(handle, inode); | 2345 if (new_i_size > EXT4_I(inode)->i_disksize) { 2346 if (ext4_da_should_update_i_disksize(page, end)) { 2347 down_write(&EXT4_I(inode)->i_data_sem); 2348 if (new_i_size > EXT4_I(inode)->i_disksize) { 2349 /* 2350 * Updating i_disksize when extending file 2351 * without needing block allocation 2352 */ 2353 if (ext4_should_order_data(inode)) 2354 ret = ext4_jbd2_file_inode(handle, 2355 inode); |
2327 | 2356 |
2328 EXT4_I(inode)->i_disksize = new_i_size; | 2357 EXT4_I(inode)->i_disksize = new_i_size; 2358 } 2359 up_write(&EXT4_I(inode)->i_data_sem); |
2329 } | 2360 } |
2361 } |
|
2330 ret2 = generic_write_end(file, mapping, pos, len, copied, 2331 page, fsdata); 2332 copied = ret2; 2333 if (ret2 < 0) 2334 ret = ret2; 2335 ret2 = ext4_journal_stop(handle); 2336 if (!ret) 2337 ret = ret2; --- 1051 unchanged lines hidden (view full) --- 3389 * 3390 * Implication: the file must always be in a sane, consistent 3391 * truncatable state while each transaction commits. 3392 */ 3393 if (ext4_orphan_add(handle, inode)) 3394 goto out_stop; 3395 3396 /* | 2362 ret2 = generic_write_end(file, mapping, pos, len, copied, 2363 page, fsdata); 2364 copied = ret2; 2365 if (ret2 < 0) 2366 ret = ret2; 2367 ret2 = ext4_journal_stop(handle); 2368 if (!ret) 2369 ret = ret2; --- 1051 unchanged lines hidden (view full) --- 3421 * 3422 * Implication: the file must always be in a sane, consistent 3423 * truncatable state while each transaction commits. 3424 */ 3425 if (ext4_orphan_add(handle, inode)) 3426 goto out_stop; 3427 3428 /* |
3429 * From here we block out all ext4_get_block() callers who want to 3430 * modify the block allocation tree. 3431 */ 3432 down_write(&ei->i_data_sem); 3433 /* |
|
3397 * The orphan list entry will now protect us from any crash which 3398 * occurs before the truncate completes, so it is now safe to propagate 3399 * the new, shorter inode size (held for now in i_size) into the 3400 * on-disk inode. We do this via i_disksize, which is the value which 3401 * ext4 *really* writes onto the disk inode. 3402 */ 3403 ei->i_disksize = inode->i_size; 3404 | 3434 * The orphan list entry will now protect us from any crash which 3435 * occurs before the truncate completes, so it is now safe to propagate 3436 * the new, shorter inode size (held for now in i_size) into the 3437 * on-disk inode. We do this via i_disksize, which is the value which 3438 * ext4 *really* writes onto the disk inode. 3439 */ 3440 ei->i_disksize = inode->i_size; 3441 |
3405 /* 3406 * From here we block out all ext4_get_block() callers who want to 3407 * modify the block allocation tree. 3408 */ 3409 down_write(&ei->i_data_sem); 3410 | |
3411 if (n == 1) { /* direct blocks */ 3412 ext4_free_data(handle, inode, NULL, i_data+offsets[0], 3413 i_data + EXT4_NDIR_BLOCKS); 3414 goto do_indirects; 3415 } 3416 3417 partial = ext4_find_shared(inode, n, offsets, chain, &nr); 3418 /* Kill the top of shared branch (not detached) */ --- 1158 unchanged lines hidden --- | 3442 if (n == 1) { /* direct blocks */ 3443 ext4_free_data(handle, inode, NULL, i_data+offsets[0], 3444 i_data + EXT4_NDIR_BLOCKS); 3445 goto do_indirects; 3446 } 3447 3448 partial = ext4_find_shared(inode, n, offsets, chain, &nr); 3449 /* Kill the top of shared branch (not detached) */ --- 1158 unchanged lines hidden --- |