Commit 282dc178849882289d30e58b54be6b2799b351aa

Authored by Christoph Hellwig
Committed by Al Viro
1 parent ea0f04e595

get rid of cont_write_begin_newtrunc

Move the call to vmtruncate to get rid of accessive blocks to the callers
in preparation of the new truncate sequence and rename the non-truncating
version to cont_write_begin.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Showing 9 changed files with 62 additions and 30 deletions Side-by-side Diff

... ... @@ -50,10 +50,19 @@
50 50 loff_t pos, unsigned len, unsigned flags,
51 51 struct page **pagep, void **fsdata)
52 52 {
  53 + int ret;
  54 +
53 55 *pagep = NULL;
54   - return cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
  56 + ret = cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
55 57 adfs_get_block,
56 58 &ADFS_I(mapping->host)->mmu_private);
  59 + if (unlikely(ret)) {
  60 + loff_t isize = mapping->host->i_size;
  61 + if (pos + len > isize)
  62 + vmtruncate(mapping->host, isize);
  63 + }
  64 +
  65 + return ret;
57 66 }
58 67  
59 68 static sector_t _adfs_bmap(struct address_space *mapping, sector_t block)
... ... @@ -406,10 +406,19 @@
406 406 loff_t pos, unsigned len, unsigned flags,
407 407 struct page **pagep, void **fsdata)
408 408 {
  409 + int ret;
  410 +
409 411 *pagep = NULL;
410   - return cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
  412 + ret = cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
411 413 affs_get_block,
412 414 &AFFS_I(mapping->host)->mmu_private);
  415 + if (unlikely(ret)) {
  416 + loff_t isize = mapping->host->i_size;
  417 + if (pos + len > isize)
  418 + vmtruncate(mapping->host, isize);
  419 + }
  420 +
  421 + return ret;
413 422 }
414 423  
415 424 static sector_t _affs_bmap(struct address_space *mapping, sector_t block)
... ... @@ -2351,7 +2351,7 @@
2351 2351 * For moronic filesystems that do not allow holes in file.
2352 2352 * We may have to extend the file.
2353 2353 */
2354   -int cont_write_begin_newtrunc(struct file *file, struct address_space *mapping,
  2354 +int cont_write_begin(struct file *file, struct address_space *mapping,
2355 2355 loff_t pos, unsigned len, unsigned flags,
2356 2356 struct page **pagep, void **fsdata,
2357 2357 get_block_t *get_block, loff_t *bytes)
... ... @@ -2376,25 +2376,6 @@
2376 2376 flags, pagep, fsdata, get_block);
2377 2377 out:
2378 2378 return err;
2379   -}
2380   -EXPORT_SYMBOL(cont_write_begin_newtrunc);
2381   -
2382   -int cont_write_begin(struct file *file, struct address_space *mapping,
2383   - loff_t pos, unsigned len, unsigned flags,
2384   - struct page **pagep, void **fsdata,
2385   - get_block_t *get_block, loff_t *bytes)
2386   -{
2387   - int ret;
2388   -
2389   - ret = cont_write_begin_newtrunc(file, mapping, pos, len, flags,
2390   - pagep, fsdata, get_block, bytes);
2391   - if (unlikely(ret)) {
2392   - loff_t isize = mapping->host->i_size;
2393   - if (pos + len > isize)
2394   - vmtruncate(mapping->host, isize);
2395   - }
2396   -
2397   - return ret;
2398 2379 }
2399 2380 EXPORT_SYMBOL(cont_write_begin);
2400 2381  
... ... @@ -159,7 +159,7 @@
159 159 int err;
160 160  
161 161 *pagep = NULL;
162   - err = cont_write_begin_newtrunc(file, mapping, pos, len, flags,
  162 + err = cont_write_begin(file, mapping, pos, len, flags,
163 163 pagep, fsdata, fat_get_block,
164 164 &MSDOS_I(mapping->host)->mmu_private);
165 165 if (err < 0)
... ... @@ -39,10 +39,19 @@
39 39 loff_t pos, unsigned len, unsigned flags,
40 40 struct page **pagep, void **fsdata)
41 41 {
  42 + int ret;
  43 +
42 44 *pagep = NULL;
43   - return cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
  45 + ret = cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
44 46 hfs_get_block,
45 47 &HFS_I(mapping->host)->phys_size);
  48 + if (unlikely(ret)) {
  49 + loff_t isize = mapping->host->i_size;
  50 + if (pos + len > isize)
  51 + vmtruncate(mapping->host, isize);
  52 + }
  53 +
  54 + return ret;
46 55 }
47 56  
48 57 static sector_t hfs_bmap(struct address_space *mapping, sector_t block)
... ... @@ -31,10 +31,19 @@
31 31 loff_t pos, unsigned len, unsigned flags,
32 32 struct page **pagep, void **fsdata)
33 33 {
  34 + int ret;
  35 +
34 36 *pagep = NULL;
35   - return cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
  37 + ret = cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
36 38 hfsplus_get_block,
37 39 &HFSPLUS_I(mapping->host).phys_size);
  40 + if (unlikely(ret)) {
  41 + loff_t isize = mapping->host->i_size;
  42 + if (pos + len > isize)
  43 + vmtruncate(mapping->host, isize);
  44 + }
  45 +
  46 + return ret;
38 47 }
39 48  
40 49 static sector_t hfsplus_bmap(struct address_space *mapping, sector_t block)
... ... @@ -97,10 +97,19 @@
97 97 loff_t pos, unsigned len, unsigned flags,
98 98 struct page **pagep, void **fsdata)
99 99 {
  100 + int ret;
  101 +
100 102 *pagep = NULL;
101   - return cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
  103 + ret = cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
102 104 hpfs_get_block,
103 105 &hpfs_i(mapping->host)->mmu_private);
  106 + if (unlikely(ret)) {
  107 + loff_t isize = mapping->host->i_size;
  108 + if (pos + len > isize)
  109 + vmtruncate(mapping->host, isize);
  110 + }
  111 +
  112 + return ret;
104 113 }
105 114  
106 115 static sector_t _hpfs_bmap(struct address_space *mapping, sector_t block)
... ... @@ -320,10 +320,19 @@
320 320 struct page **pagep, void **fsdata)
321 321 {
322 322 struct qnx4_inode_info *qnx4_inode = qnx4_i(mapping->host);
  323 + int ret;
  324 +
323 325 *pagep = NULL;
324   - return cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
  326 + ret = cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
325 327 qnx4_get_block,
326 328 &qnx4_inode->mmu_private);
  329 + if (unlikely(ret)) {
  330 + loff_t isize = mapping->host->i_size;
  331 + if (pos + len > isize)
  332 + vmtruncate(mapping->host, isize);
  333 + }
  334 +
  335 + return ret;
327 336 }
328 337 static sector_t qnx4_bmap(struct address_space *mapping, sector_t block)
329 338 {
include/linux/buffer_head.h
... ... @@ -217,9 +217,6 @@
217 217 struct page *, void *);
218 218 void page_zero_new_buffers(struct page *page, unsigned from, unsigned to);
219 219 int block_prepare_write(struct page*, unsigned, unsigned, get_block_t*);
220   -int cont_write_begin_newtrunc(struct file *, struct address_space *, loff_t,
221   - unsigned, unsigned, struct page **, void **,
222   - get_block_t *, loff_t *);
223 220 int cont_write_begin(struct file *, struct address_space *, loff_t,
224 221 unsigned, unsigned, struct page **, void **,
225 222 get_block_t *, loff_t *);