gfs2-utils: RHEL7 - libgfs2: Add lgfs2_space_for_data()

Andrew Price andyp at fedoraproject.org
Mon Sep 8 17:33:12 UTC 2014


Gitweb:        http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=3db7b6c3e745f95c9fa07689cf178f59b57df2db
Commit:        3db7b6c3e745f95c9fa07689cf178f59b57df2db
Parent:        6c5bcef6d9b3c4c1dee4a2f9031a6c8e3c17fbab
Author:        Andrew Price <anprice at redhat.com>
AuthorDate:    Thu Feb 20 16:54:48 2014 +0000
Committer:     Andrew Price <anprice at redhat.com>
CommitterDate: Thu Jul 24 17:13:51 2014 +0100

libgfs2: Add lgfs2_space_for_data()

Add a function which calculates the total number of blocks required for
a file given the size of its contents.

Signed-off-by: Andrew Price <anprice at redhat.com>
---
 gfs2/libgfs2/fs_ops.c  |   18 ++++++++++++++++++
 gfs2/libgfs2/libgfs2.h |    2 ++
 2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 198f6eb..b95f2ed 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -273,6 +273,24 @@ void unstuff_dinode(struct gfs2_inode *ip)
 	ip->i_di.di_height = 1;
 }
 
+/**
+ * Calculate the total number of blocks required by a file containing 'bytes' bytes of data.
+ */
+uint64_t lgfs2_space_for_data(const struct gfs2_sbd *sdp, const unsigned bsize, const uint64_t bytes)
+{
+	uint64_t blks = (bytes + bsize - 1) / bsize;
+	uint64_t ptrs = blks;
+
+	if (bytes <= bsize - sizeof(struct gfs2_dinode))
+		return 1;
+
+	while (ptrs > sdp->sd_diptrs) {
+		ptrs = (ptrs + sdp->sd_inptrs - 1) / sdp->sd_inptrs;
+		blks += ptrs;
+	}
+	return blks + 1;
+}
+
 unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size)
 {
 	struct gfs2_sbd *sdp = ip->i_sbd;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 6248e4b..ce51e8c 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -450,6 +450,8 @@ extern void inode_put(struct gfs2_inode **ip);
 extern uint64_t data_alloc(struct gfs2_inode *ip);
 extern int lgfs2_meta_alloc(struct gfs2_inode *ip, uint64_t *blkno);
 extern int lgfs2_dinode_alloc(struct gfs2_sbd *sdp, const uint64_t blksreq, uint64_t *blkno);
+extern uint64_t lgfs2_space_for_data(const struct gfs2_sbd *sdp, unsigned bsize, uint64_t bytes);
+
 extern int gfs2_readi(struct gfs2_inode *ip, void *buf, uint64_t offset,
 		      unsigned int size);
 #define gfs2_writei(ip, buf, offset, size) \


More information about the cluster-commits mailing list