aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Whitehouse <swhiteho@redhat.com>2014-01-06 07:03:05 -0500
committerSteven Whitehouse <swhiteho@redhat.com>2014-01-06 07:03:05 -0500
commit534cf9ca553953e4c12fa5f0d23e543f9a6ccbaf (patch)
tree755e7422a40d7720f6cc3f233bc96f5606a4f2ce
parent3c1c0ae1db74b1f3e606f42158b5dadd89105c1f (diff)
GFS2: Consolidate transaction blocks calculation for dir add
There are three cases where we need to calculate the number of blocks to reserve in a transaction involving linking an inode into a directory. The one in rename is a bit more complicated, but the basis of it is the same as for link and create. So it makes sense to move this calculation into a single function rather than repeating it three times. Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
-rw-r--r--fs/gfs2/inode.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 9ac8f13a8c37..fa4624feef0f 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -469,6 +469,28 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_inode *ip,
469 brelse(dibh); 469 brelse(dibh);
470} 470}
471 471
472/**
473 * gfs2_trans_da_blocks - Calculate number of blocks to link inode
474 * @dip: The directory we are linking into
475 * @da: The dir add information
476 * @nr_inodes: The number of inodes involved
477 *
478 * This calculate the number of blocks we need to reserve in a
479 * transaction to link @nr_inodes into a directory. In most cases
480 * @nr_inodes will be 2 (the directory plus the inode being linked in)
481 * but in case of rename, 4 may be required.
482 *
483 * Returns: Number of blocks
484 */
485
486static unsigned gfs2_trans_da_blks(const struct gfs2_inode *dip,
487 const struct gfs2_diradd *da,
488 unsigned nr_inodes)
489{
490 return da->nr_blocks + gfs2_rg_blocks(dip, da->nr_blocks) +
491 (nr_inodes * RES_DINODE) + RES_QUOTA + RES_STATFS;
492}
493
472static int link_dinode(struct gfs2_inode *dip, const struct qstr *name, 494static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
473 struct gfs2_inode *ip, struct gfs2_diradd *da) 495 struct gfs2_inode *ip, struct gfs2_diradd *da)
474{ 496{
@@ -485,10 +507,7 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
485 if (error) 507 if (error)
486 goto fail_quota_locks; 508 goto fail_quota_locks;
487 509
488 error = gfs2_trans_begin(sdp, da->nr_blocks + 510 error = gfs2_trans_begin(sdp, gfs2_trans_da_blks(dip, da, 2), 0);
489 gfs2_rg_blocks(dip, da->nr_blocks) +
490 2 * RES_DINODE +
491 RES_STATFS + RES_QUOTA, 0);
492 if (error) 511 if (error)
493 goto fail_ipreserv; 512 goto fail_ipreserv;
494 } else { 513 } else {
@@ -886,10 +905,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
886 if (error) 905 if (error)
887 goto out_gunlock_q; 906 goto out_gunlock_q;
888 907
889 error = gfs2_trans_begin(sdp, da.nr_blocks + 908 error = gfs2_trans_begin(sdp, gfs2_trans_da_blks(dip, &da, 2), 0);
890 gfs2_rg_blocks(dip, da.nr_blocks) +
891 2 * RES_DINODE + RES_STATFS +
892 RES_QUOTA, 0);
893 if (error) 909 if (error)
894 goto out_ipres; 910 goto out_ipres;
895 } else { 911 } else {
@@ -1403,10 +1419,8 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
1403 if (error) 1419 if (error)
1404 goto out_gunlock_q; 1420 goto out_gunlock_q;
1405 1421
1406 error = gfs2_trans_begin(sdp, da.nr_blocks + 1422 error = gfs2_trans_begin(sdp, gfs2_trans_da_blks(ndip, &da, 4) +
1407 gfs2_rg_blocks(ndip, da.nr_blocks) + 1423 4 * RES_LEAF + 4, 0);
1408 4 * RES_DINODE + 4 * RES_LEAF +
1409 RES_STATFS + RES_QUOTA + 4, 0);
1410 if (error) 1424 if (error)
1411 goto out_ipreserv; 1425 goto out_ipreserv;
1412 } else { 1426 } else {