diff options
author | Mark Fasheh <mark.fasheh@oracle.com> | 2007-08-28 20:13:23 -0400 |
---|---|---|
committer | Mark Fasheh <mark.fasheh@oracle.com> | 2007-10-12 14:54:35 -0400 |
commit | 65ed39d6ca78f07d2958814e08440e4264b6b488 (patch) | |
tree | 477623ef58810a6d32c8d23fbf17e5258495ddb0 /fs/ocfs2/aops.c | |
parent | 92e91ce2a30b2af53ebf077512801dc01e75cca5 (diff) |
ocfs2: move nonsparse hole-filling into ocfs2_write_begin()
By doing this, we can remove any higher level logic which has to have
knowledge of btree functionality - any callers of ocfs2_write_begin() can
now expect it to do anything necessary to prepare the inode for new data.
Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>
Reviewed-by: Joel Becker <joel.becker@oracle.com>
Diffstat (limited to 'fs/ocfs2/aops.c')
-rw-r--r-- | fs/ocfs2/aops.c | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index f37f25c931f5..fae07672eb18 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c | |||
@@ -301,12 +301,8 @@ int ocfs2_prepare_write_nolock(struct inode *inode, struct page *page, | |||
301 | { | 301 | { |
302 | int ret; | 302 | int ret; |
303 | 303 | ||
304 | down_read(&OCFS2_I(inode)->ip_alloc_sem); | ||
305 | |||
306 | ret = block_prepare_write(page, from, to, ocfs2_get_block); | 304 | ret = block_prepare_write(page, from, to, ocfs2_get_block); |
307 | 305 | ||
308 | up_read(&OCFS2_I(inode)->ip_alloc_sem); | ||
309 | |||
310 | return ret; | 306 | return ret; |
311 | } | 307 | } |
312 | 308 | ||
@@ -1360,6 +1356,36 @@ out: | |||
1360 | return ret; | 1356 | return ret; |
1361 | } | 1357 | } |
1362 | 1358 | ||
1359 | /* | ||
1360 | * This function only does anything for file systems which can't | ||
1361 | * handle sparse files. | ||
1362 | * | ||
1363 | * What we want to do here is fill in any hole between the current end | ||
1364 | * of allocation and the end of our write. That way the rest of the | ||
1365 | * write path can treat it as an non-allocating write, which has no | ||
1366 | * special case code for sparse/nonsparse files. | ||
1367 | */ | ||
1368 | static int ocfs2_expand_nonsparse_inode(struct inode *inode, loff_t pos, | ||
1369 | unsigned len, | ||
1370 | struct ocfs2_write_ctxt *wc) | ||
1371 | { | ||
1372 | int ret; | ||
1373 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
1374 | loff_t newsize = pos + len; | ||
1375 | |||
1376 | if (ocfs2_sparse_alloc(osb)) | ||
1377 | return 0; | ||
1378 | |||
1379 | if (newsize <= i_size_read(inode)) | ||
1380 | return 0; | ||
1381 | |||
1382 | ret = ocfs2_extend_no_holes(inode, newsize, newsize - len); | ||
1383 | if (ret) | ||
1384 | mlog_errno(ret); | ||
1385 | |||
1386 | return ret; | ||
1387 | } | ||
1388 | |||
1363 | int ocfs2_write_begin_nolock(struct address_space *mapping, | 1389 | int ocfs2_write_begin_nolock(struct address_space *mapping, |
1364 | loff_t pos, unsigned len, unsigned flags, | 1390 | loff_t pos, unsigned len, unsigned flags, |
1365 | struct page **pagep, void **fsdata, | 1391 | struct page **pagep, void **fsdata, |
@@ -1381,6 +1407,12 @@ int ocfs2_write_begin_nolock(struct address_space *mapping, | |||
1381 | return ret; | 1407 | return ret; |
1382 | } | 1408 | } |
1383 | 1409 | ||
1410 | ret = ocfs2_expand_nonsparse_inode(inode, pos, len, wc); | ||
1411 | if (ret) { | ||
1412 | mlog_errno(ret); | ||
1413 | goto out; | ||
1414 | } | ||
1415 | |||
1384 | ret = ocfs2_populate_write_desc(inode, wc, &clusters_to_alloc, | 1416 | ret = ocfs2_populate_write_desc(inode, wc, &clusters_to_alloc, |
1385 | &extents_to_split); | 1417 | &extents_to_split); |
1386 | if (ret) { | 1418 | if (ret) { |