aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/ops_inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/gfs2/ops_inode.c')
-rw-r--r--fs/gfs2/ops_inode.c256
1 files changed, 0 insertions, 256 deletions
diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c
index 1501db4f0e6d..d8b26ac2e20b 100644
--- a/fs/gfs2/ops_inode.c
+++ b/fs/gfs2/ops_inode.c
@@ -18,8 +18,6 @@
18#include <linux/gfs2_ondisk.h> 18#include <linux/gfs2_ondisk.h>
19#include <linux/crc32.h> 19#include <linux/crc32.h>
20#include <linux/fiemap.h> 20#include <linux/fiemap.h>
21#include <linux/swap.h>
22#include <linux/falloc.h>
23#include <asm/uaccess.h> 21#include <asm/uaccess.h>
24 22
25#include "gfs2.h" 23#include "gfs2.h"
@@ -106,8 +104,6 @@ static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
106{ 104{
107 struct inode *inode = NULL; 105 struct inode *inode = NULL;
108 106
109 d_set_d_op(dentry, &gfs2_dops);
110
111 inode = gfs2_lookupi(dir, &dentry->d_name, 0); 107 inode = gfs2_lookupi(dir, &dentry->d_name, 0);
112 if (inode && IS_ERR(inode)) 108 if (inode && IS_ERR(inode))
113 return ERR_CAST(inode); 109 return ERR_CAST(inode);
@@ -1259,257 +1255,6 @@ static int gfs2_removexattr(struct dentry *dentry, const char *name)
1259 return ret; 1255 return ret;
1260} 1256}
1261 1257
1262static void empty_write_end(struct page *page, unsigned from,
1263 unsigned to)
1264{
1265 struct gfs2_inode *ip = GFS2_I(page->mapping->host);
1266
1267 page_zero_new_buffers(page, from, to);
1268 flush_dcache_page(page);
1269 mark_page_accessed(page);
1270
1271 if (!gfs2_is_writeback(ip))
1272 gfs2_page_add_databufs(ip, page, from, to);
1273
1274 block_commit_write(page, from, to);
1275}
1276
1277
1278static int write_empty_blocks(struct page *page, unsigned from, unsigned to)
1279{
1280 unsigned start, end, next;
1281 struct buffer_head *bh, *head;
1282 int error;
1283
1284 if (!page_has_buffers(page)) {
1285 error = __block_write_begin(page, from, to - from, gfs2_block_map);
1286 if (unlikely(error))
1287 return error;
1288
1289 empty_write_end(page, from, to);
1290 return 0;
1291 }
1292
1293 bh = head = page_buffers(page);
1294 next = end = 0;
1295 while (next < from) {
1296 next += bh->b_size;
1297 bh = bh->b_this_page;
1298 }
1299 start = next;
1300 do {
1301 next += bh->b_size;
1302 if (buffer_mapped(bh)) {
1303 if (end) {
1304 error = __block_write_begin(page, start, end - start,
1305 gfs2_block_map);
1306 if (unlikely(error))
1307 return error;
1308 empty_write_end(page, start, end);
1309 end = 0;
1310 }
1311 start = next;
1312 }
1313 else
1314 end = next;
1315 bh = bh->b_this_page;
1316 } while (next < to);
1317
1318 if (end) {
1319 error = __block_write_begin(page, start, end - start, gfs2_block_map);
1320 if (unlikely(error))
1321 return error;
1322 empty_write_end(page, start, end);
1323 }
1324
1325 return 0;
1326}
1327
1328static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len,
1329 int mode)
1330{
1331 struct gfs2_inode *ip = GFS2_I(inode);
1332 struct buffer_head *dibh;
1333 int error;
1334 u64 start = offset >> PAGE_CACHE_SHIFT;
1335 unsigned int start_offset = offset & ~PAGE_CACHE_MASK;
1336 u64 end = (offset + len - 1) >> PAGE_CACHE_SHIFT;
1337 pgoff_t curr;
1338 struct page *page;
1339 unsigned int end_offset = (offset + len) & ~PAGE_CACHE_MASK;
1340 unsigned int from, to;
1341
1342 if (!end_offset)
1343 end_offset = PAGE_CACHE_SIZE;
1344
1345 error = gfs2_meta_inode_buffer(ip, &dibh);
1346 if (unlikely(error))
1347 goto out;
1348
1349 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
1350
1351 if (gfs2_is_stuffed(ip)) {
1352 error = gfs2_unstuff_dinode(ip, NULL);
1353 if (unlikely(error))
1354 goto out;
1355 }
1356
1357 curr = start;
1358 offset = start << PAGE_CACHE_SHIFT;
1359 from = start_offset;
1360 to = PAGE_CACHE_SIZE;
1361 while (curr <= end) {
1362 page = grab_cache_page_write_begin(inode->i_mapping, curr,
1363 AOP_FLAG_NOFS);
1364 if (unlikely(!page)) {
1365 error = -ENOMEM;
1366 goto out;
1367 }
1368
1369 if (curr == end)
1370 to = end_offset;
1371 error = write_empty_blocks(page, from, to);
1372 if (!error && offset + to > inode->i_size &&
1373 !(mode & FALLOC_FL_KEEP_SIZE)) {
1374 i_size_write(inode, offset + to);
1375 }
1376 unlock_page(page);
1377 page_cache_release(page);
1378 if (error)
1379 goto out;
1380 curr++;
1381 offset += PAGE_CACHE_SIZE;
1382 from = 0;
1383 }
1384
1385 gfs2_dinode_out(ip, dibh->b_data);
1386 mark_inode_dirty(inode);
1387
1388 brelse(dibh);
1389
1390out:
1391 return error;
1392}
1393
1394static void calc_max_reserv(struct gfs2_inode *ip, loff_t max, loff_t *len,
1395 unsigned int *data_blocks, unsigned int *ind_blocks)
1396{
1397 const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1398 unsigned int max_blocks = ip->i_alloc->al_rgd->rd_free_clone;
1399 unsigned int tmp, max_data = max_blocks - 3 * (sdp->sd_max_height - 1);
1400
1401 for (tmp = max_data; tmp > sdp->sd_diptrs;) {
1402 tmp = DIV_ROUND_UP(tmp, sdp->sd_inptrs);
1403 max_data -= tmp;
1404 }
1405 /* This calculation isn't the exact reverse of gfs2_write_calc_reserve,
1406 so it might end up with fewer data blocks */
1407 if (max_data <= *data_blocks)
1408 return;
1409 *data_blocks = max_data;
1410 *ind_blocks = max_blocks - max_data;
1411 *len = ((loff_t)max_data - 3) << sdp->sd_sb.sb_bsize_shift;
1412 if (*len > max) {
1413 *len = max;
1414 gfs2_write_calc_reserv(ip, max, data_blocks, ind_blocks);
1415 }
1416}
1417
1418static long gfs2_fallocate(struct inode *inode, int mode, loff_t offset,
1419 loff_t len)
1420{
1421 struct gfs2_sbd *sdp = GFS2_SB(inode);
1422 struct gfs2_inode *ip = GFS2_I(inode);
1423 unsigned int data_blocks = 0, ind_blocks = 0, rblocks;
1424 loff_t bytes, max_bytes;
1425 struct gfs2_alloc *al;
1426 int error;
1427 loff_t next = (offset + len - 1) >> sdp->sd_sb.sb_bsize_shift;
1428 next = (next + 1) << sdp->sd_sb.sb_bsize_shift;
1429
1430 offset = (offset >> sdp->sd_sb.sb_bsize_shift) <<
1431 sdp->sd_sb.sb_bsize_shift;
1432
1433 len = next - offset;
1434 bytes = sdp->sd_max_rg_data * sdp->sd_sb.sb_bsize / 2;
1435 if (!bytes)
1436 bytes = UINT_MAX;
1437
1438 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &ip->i_gh);
1439 error = gfs2_glock_nq(&ip->i_gh);
1440 if (unlikely(error))
1441 goto out_uninit;
1442
1443 if (!gfs2_write_alloc_required(ip, offset, len))
1444 goto out_unlock;
1445
1446 while (len > 0) {
1447 if (len < bytes)
1448 bytes = len;
1449 al = gfs2_alloc_get(ip);
1450 if (!al) {
1451 error = -ENOMEM;
1452 goto out_unlock;
1453 }
1454
1455 error = gfs2_quota_lock_check(ip);
1456 if (error)
1457 goto out_alloc_put;
1458
1459retry:
1460 gfs2_write_calc_reserv(ip, bytes, &data_blocks, &ind_blocks);
1461
1462 al->al_requested = data_blocks + ind_blocks;
1463 error = gfs2_inplace_reserve(ip);
1464 if (error) {
1465 if (error == -ENOSPC && bytes > sdp->sd_sb.sb_bsize) {
1466 bytes >>= 1;
1467 goto retry;
1468 }
1469 goto out_qunlock;
1470 }
1471 max_bytes = bytes;
1472 calc_max_reserv(ip, len, &max_bytes, &data_blocks, &ind_blocks);
1473 al->al_requested = data_blocks + ind_blocks;
1474
1475 rblocks = RES_DINODE + ind_blocks + RES_STATFS + RES_QUOTA +
1476 RES_RG_HDR + gfs2_rg_blocks(al);
1477 if (gfs2_is_jdata(ip))
1478 rblocks += data_blocks ? data_blocks : 1;
1479
1480 error = gfs2_trans_begin(sdp, rblocks,
1481 PAGE_CACHE_SIZE/sdp->sd_sb.sb_bsize);
1482 if (error)
1483 goto out_trans_fail;
1484
1485 error = fallocate_chunk(inode, offset, max_bytes, mode);
1486 gfs2_trans_end(sdp);
1487
1488 if (error)
1489 goto out_trans_fail;
1490
1491 len -= max_bytes;
1492 offset += max_bytes;
1493 gfs2_inplace_release(ip);
1494 gfs2_quota_unlock(ip);
1495 gfs2_alloc_put(ip);
1496 }
1497 goto out_unlock;
1498
1499out_trans_fail:
1500 gfs2_inplace_release(ip);
1501out_qunlock:
1502 gfs2_quota_unlock(ip);
1503out_alloc_put:
1504 gfs2_alloc_put(ip);
1505out_unlock:
1506 gfs2_glock_dq(&ip->i_gh);
1507out_uninit:
1508 gfs2_holder_uninit(&ip->i_gh);
1509 return error;
1510}
1511
1512
1513static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 1258static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
1514 u64 start, u64 len) 1259 u64 start, u64 len)
1515{ 1260{
@@ -1560,7 +1305,6 @@ const struct inode_operations gfs2_file_iops = {
1560 .getxattr = gfs2_getxattr, 1305 .getxattr = gfs2_getxattr,
1561 .listxattr = gfs2_listxattr, 1306 .listxattr = gfs2_listxattr,
1562 .removexattr = gfs2_removexattr, 1307 .removexattr = gfs2_removexattr,
1563 .fallocate = gfs2_fallocate,
1564 .fiemap = gfs2_fiemap, 1308 .fiemap = gfs2_fiemap,
1565}; 1309};
1566 1310