Skip to contentSkip to conversation

GFS2: New truncate sequence

Cluster-devel Steven Whitehouse 1 participant 1 message Mar 12, 2010 GFS2 file system

lore
Share & tools
lore
#0 lore raw

I've been working on this on and off in spare moments. This has now passed a few basic tests, so I think its time to dust it down and post it more widely.

There are in fact two parts to this, the second part is to remove the i_disksize variable since after this, initial patch, it will always be identical to the inode's i_size. Thats a simple exercise, for a follow up patch.

This is a nice clean up of the truncate code, reducing the code size by approx 50 lines of code. This patch also ensures that we correctly truncate files which have been extended but not written to (e.g. if the copy from userspace results in a segfault).

fs/gfs2/aops.c +4 -1
index 0c1d0b8..371bea5 100644
@@ -698,8 +698,11 @@ out:
 		return 0;
 
 	page_cache_release(page);
+	gfs2_trans_end(sdp);
 	if (pos + len > ip->i_inode.i_size)
-		vmtruncate(&ip->i_inode, ip->i_inode.i_size);
+		gfs2_trim_blocks(&ip->i_inode);
+	goto out_trans_fail;
+
 out_endtrans:
 	gfs2_trans_end(sdp);
 out_trans_fail:
fs/gfs2/bmap.c +78 -122

284 lines not on this page · raw message

fs/gfs2/bmap.h +12 -9
index c983177..0f0217f 100644
@@ -44,14 +44,17 @@ static inline void gfs2_write_calc_reserv(const struct gfs2_inode *ip,
 	}
 }
 
-int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page);
-int gfs2_block_map(struct inode *inode, sector_t lblock, struct buffer_head *bh, int create);
-int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen);
-
-int gfs2_truncatei(struct gfs2_inode *ip, u64 size);
-int gfs2_truncatei_resume(struct gfs2_inode *ip);
-int gfs2_file_dealloc(struct gfs2_inode *ip);
-int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
-			      unsigned int len, int *alloc_required);
+extern int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page);
+extern int gfs2_block_map(struct inode *inode, sector_t lblock,
+			  struct buffer_head *bh, int create);
+extern int gfs2_extent_map(struct inode *inode, u64 lblock, int *new,
+			   u64 *dblock, unsigned *extlen);
+
+extern int gfs2_setattr_size(struct inode *inode, u64 size);
+extern void gfs2_trim_blocks(struct inode *inode);
+extern int gfs2_truncatei_resume(struct gfs2_inode *ip);
+extern int gfs2_file_dealloc(struct gfs2_inode *ip);
+extern int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
+				     unsigned int len, int *alloc_required);
 
 #endif /* __BMAP_DOT_H__ */
fs/gfs2/ops_inode.c +1 -24
index 4e64352..44742a7 100644
@@ -1071,29 +1071,6 @@ int gfs2_permission(struct inode *inode, int mask)
 	return error;
 }
 
-static int setattr_size(struct inode *inode, struct iattr *attr)
-{
-	struct gfs2_inode *ip = GFS2_I(inode);
-	struct gfs2_sbd *sdp = GFS2_SB(inode);
-	int error;
-
-	if (attr->ia_size != ip->i_disksize) {
-		error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
-		if (error)
-			return error;
-		error = vmtruncate(inode, attr->ia_size);
-		gfs2_trans_end(sdp);
-		if (error) 
-			return error;
-	}
-
-	error = gfs2_truncatei(ip, attr->ia_size);
-	if (error && (inode->i_size != ip->i_disksize))
-		i_size_write(inode, ip->i_disksize);
-
-	return error;
-}
-
 static int setattr_chown(struct inode *inode, struct iattr *attr)
 {
 	struct gfs2_inode *ip = GFS2_I(inode);
@@ -1186,7 +1163,7 @@ static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
 		goto out;
 
 	if (attr->ia_valid & ATTR_SIZE)
-		error = setattr_size(inode, attr);
+		error = gfs2_setattr_size(inode, attr->ia_size);
 	else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
 		error = setattr_chown(inode, attr);
 	else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode))