Skip to contentSkip to conversation

gfs2: Pass write offset to gfs2_write_calc_reserv

PATCH New Abhi Das 1 participant 1 message Jul 19, 2018 GFS2 file system

lore
Share & tools
lore

Abhi Das

author
#0 lore raw

PATCH v3 1/2 gfs2: Pass write offset to gfs2_write_calc_reserv

Pass the offset of the write to gfs2_write_calc_reserv so that we can then compute a better upper bound of the number of indirect blocks required.

Fixed comments in quota.c:do_sync() to better explain block reservation calculation for quotas.

---
 fs/gfs2/bmap.c  |  4 ++--
 fs/gfs2/bmap.h  |  2 ++
 fs/gfs2/file.c  | 12 ++++++------
 fs/gfs2/quota.c | 46 ++++++++++++++++++++++++----------------------
 4 files changed, 34 insertions(+), 30 deletions(-)
fs/gfs2/bmap.c +2 -2
index 89f1f7d..7d3bb32 100644
@@ -1003,8 +1003,8 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
 	alloc_required = unstuff || iomap->type == IOMAP_HOLE;
 
 	if (alloc_required || gfs2_is_jdata(ip))
-		gfs2_write_calc_reserv(ip, iomap->length, &data_blocks,
-				       &ind_blocks);
+		gfs2_write_calc_reserv(ip, iomap->offset, iomap->length,
+				       &data_blocks, &ind_blocks);
 
 	if (alloc_required) {
 		struct gfs2_alloc_parms ap = {
fs/gfs2/bmap.h +2 -0
index 6b18fb3..6497053 100644
@@ -22,6 +22,7 @@ struct page;
 /**
  * gfs2_write_calc_reserv - calculate number of blocks needed to write to a file
  * @ip: the file
+ * @pos: file offset of the write
  * @len: the number of bytes to be written to the file
  * @data_blocks: returns the number of data blocks required
  * @ind_blocks: returns the number of indirect blocks required
@@ -29,6 +30,7 @@ struct page;
  */
 
 static inline void gfs2_write_calc_reserv(const struct gfs2_inode *ip,
+					  u64 pos,
 					  unsigned int len,
 					  unsigned int *data_blocks,
 					  unsigned int *ind_blocks)
fs/gfs2/file.c +6 -6
index 08369c6..93f59f9 100644
@@ -435,7 +435,7 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
 	if (ret)
 		goto out_unlock;
 
-	gfs2_write_calc_reserv(ip, PAGE_SIZE, &data_blocks, &ind_blocks);
+	gfs2_write_calc_reserv(ip, pos, PAGE_SIZE, &data_blocks, &ind_blocks);
 	ap.target = data_blocks + ind_blocks;
 	ret = gfs2_quota_lock_check(ip, &ap);
 	if (ret)
@@ -918,7 +918,7 @@ static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len,
  *
  * Returns: void, but @len, @data_blocks and @ind_blocks are filled in.
  */
-static void calc_max_reserv(struct gfs2_inode *ip, loff_t *len,
+static void calc_max_reserv(struct gfs2_inode *ip, loff_t pos, loff_t *len,
 			    unsigned int *data_blocks, unsigned int *ind_blocks,
 			    unsigned int max_blocks)
 {
@@ -936,7 +936,7 @@ static void calc_max_reserv(struct gfs2_inode *ip, loff_t *len,
 	*len = ((loff_t)max_data - 3) << sdp->sd_sb.sb_bsize_shift;
 	if (*len > max) {
 		*len = max;
-		gfs2_write_calc_reserv(ip, max, data_blocks, ind_blocks);
+		gfs2_write_calc_reserv(ip, pos, max, data_blocks, ind_blocks);
 	}
 }
 
@@ -969,7 +969,7 @@ static long __gfs2_fallocate(struct file *file, int mode, loff_t offset, loff_t
 
 	gfs2_size_hint(file, offset, len);
 
-	gfs2_write_calc_reserv(ip, PAGE_SIZE, &data_blocks, &ind_blocks);
+	gfs2_write_calc_reserv(ip, offset, PAGE_SIZE, &data_blocks, &ind_blocks);
 	ap.min_target = data_blocks + ind_blocks;
 
 	while (len > 0) {
@@ -991,7 +991,7 @@ static long __gfs2_fallocate(struct file *file, int mode, loff_t offset, loff_t
 		 * calculate a more realistic 'bytes' to serve as a good
 		 * starting point for the number of bytes we may be able
 		 * to write */
-		gfs2_write_calc_reserv(ip, bytes, &data_blocks, &ind_blocks);
+		gfs2_write_calc_reserv(ip, offset, bytes, &data_blocks, &ind_blocks);
 		ap.target = data_blocks + ind_blocks;
 
 		error = gfs2_quota_lock_check(ip, &ap);
@@ -1014,7 +1014,7 @@ static long __gfs2_fallocate(struct file *file, int mode, loff_t offset, loff_t
 		/* Almost done. Calculate bytes that can be written using
 		 * max_blks. We also recompute max_bytes, data_blocks and
 		 * ind_blocks */
-		calc_max_reserv(ip, &max_bytes, &data_blocks,
+		calc_max_reserv(ip, offset, &max_bytes, &data_blocks,
 				&ind_blocks, max_blks);
 
 		rblocks = RES_DINODE + ind_blocks + RES_STATFS + RES_QUOTA +
fs/gfs2/quota.c +24 -22

85 lines not on this page · raw message

Signature · 1 line
2.4.11