Skip to contentSkip to conversation

GFS2: Add function gfs2_get_iomap

PATCH Superseded Bob Peterson 3 participants 6 messages Aug 11, 2016 – Aug 18, 2016 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 GFS2: Add function gfs2_get_iomap

Hi,

This patch replaces the GFS2 fiemap implementation that used vfs function __generic_block_fiemap with a new implementation that uses the new iomap-based fiemap interface. This allows GFS2's fiemap to skip holes. The time to do filefrag on a file with a 1 petabyte hole is reduced from several days or weeks, to milliseconds. Note that there are Kconfig changes that affect everyone.

---

fs/Kconfig +1 -1
index 2bc7ad7..d601aeb 100644
@@ -11,7 +11,7 @@ config DCACHE_WORD_ACCESS
 if BLOCK
 
 config FS_IOMAP
-	bool
+	bool "File System IOMAP Support"
 
 source "fs/ext2/Kconfig"
 source "fs/ext4/Kconfig"
fs/gfs2/Kconfig +1 -0
index 90c6a8f..f8fa955 100644
@@ -25,6 +25,7 @@ config GFS2_FS
 config GFS2_FS_LOCKING_DLM
 	bool "GFS2 DLM locking"
 	depends on (GFS2_FS!=n) && NET && INET && (IPV6 || IPV6=n) && \
+		FS_IOMAP && \
 		CONFIGFS_FS && SYSFS && (DLM=y || DLM=GFS2_FS)
 	help
 	  Multiple node locking module for GFS2
fs/gfs2/bmap.c +149 -0

155 lines not on this page · raw message

fs/gfs2/bmap.h +4 -0
index 81ded5e..8da2429 100644
@@ -10,6 +10,8 @@
 #ifndef __BMAP_DOT_H__
 #define __BMAP_DOT_H__
 
+#include <linux/iomap.h>
+
 #include "inode.h"
 
 struct inode;
@@ -47,6 +49,8 @@ static inline void gfs2_write_calc_reserv(const struct gfs2_inode *ip,
 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_get_iomap(struct inode *inode, loff_t pos,
+			  ssize_t length, struct iomap *iomap);
 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);
fs/gfs2/inode.c +49 -12

96 lines not on this page · raw message

#2 lore raw

PATCH 1/1 GFS2: Add function gfs2_get_iomap

Hi,

Quoted 103 lines · Bob Peterson

Hi,

This patch replaces the GFS2 fiemap implementation that used vfs function __generic_block_fiemap with a new implementation that uses the new iomap-based fiemap interface. This allows GFS2's fiemap to skip holes. The time to do filefrag on a file with a 1 petabyte hole is reduced from several days or weeks, to milliseconds. Note that there are Kconfig changes that affect everyone.

---

fs/Kconfig +1 -1
index 2bc7ad7..d601aeb 100644
@@ -11,7 +11,7 @@ config DCACHE_WORD_ACCESS
  if BLOCK
 
  config FS_IOMAP
-	bool
+	bool "File System IOMAP Support"
 
  source "fs/ext2/Kconfig"
  source "fs/ext4/Kconfig"
fs/gfs2/Kconfig +1 -0
index 90c6a8f..f8fa955 100644
@@ -25,6 +25,7 @@ config GFS2_FS
  config GFS2_FS_LOCKING_DLM
  	bool "GFS2 DLM locking"
  	depends on (GFS2_FS!=n) && NET && INET && (IPV6 || IPV6=n) && \
+		FS_IOMAP && \
  		CONFIGFS_FS && SYSFS && (DLM=y || DLM=GFS2_FS)
  	help
  	  Multiple node locking module for GFS2
fs/gfs2/bmap.c +59 -0
index 6e2bec1..685f1ed 100644
@@ -588,6 +588,155 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock,
  }
 
  /**
+ * hole_size - figure out the size of a hole
+ * @ip: The inode
+ * @lblock: The logical starting block number
+ * @mp: The metapath
+ *
+ * Returns: The hole size in bytes
+ *
+ */
+static u64 hole_size(struct inode *inode, sector_t lblock, struct metapath *mp)
+{
+	struct gfs2_inode *ip = GFS2_I(inode);
+	struct gfs2_sbd *sdp = GFS2_SB(inode);
+	struct metapath mp_eof;
+	unsigned int end_of_metadata = ip->i_height - 1;
+	u64 factor = 1;
+	int hgt = end_of_metadata;
+	u64 holesz = 0, holestep;
+	const __be64 *first, *end, *ptr;
+	const struct buffer_head *bh;
+	u64 isize = i_size_read(inode);
+	int zeroptrs;
+	bool done = false;
+
+	/* Get another metapath, to the very last byte */
+	find_metapath(sdp, (isize - 1) >> inode->i_blkbits, &mp_eof,
+		      ip->i_height);
+	for (hgt = end_of_metadata; hgt >= 0 && !done; hgt--) {
+		bh = mp->mp_bh[hgt];
+		if (bh) {
+			zeroptrs = 0;
+			first = metapointer(hgt, mp);
+			end = (const __be64 *)(bh->b_data + bh->b_size);
+
+			for (ptr = first; ptr < end; ptr++) {
+				if (*ptr) {
+					done = true;
+					break;
+				} else {
+					zeroptrs++;
+				}
+			}
+		} else {
+			zeroptrs = sdp->sd_inptrs;
+		}
+		holestep = min(factor * zeroptrs,
+			       isize - (lblock + (zeroptrs * holesz)));
+		holesz += holestep;
+		if (lblock + holesz >= isize)
+			return holesz << inode->i_blkbits;
+
+		factor *= sdp->sd_inptrs;
+		if (hgt && (mp->mp_list[hgt - 1] < mp_eof.mp_list[hgt - 1]))
+			(mp->mp_list[hgt - 1])++;
+	}
+	return holesz << inode->i_blkbits;
+}
+
+/**
+ * gfs2_get_iomap - Map blocks from an inode to disk blocks

fs/gfs2/bmap.c static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock, · line 659

Quoted 10 lines
fs/gfs2/bmap.c +10 -0
+ * @mapping: The address space
+ * @pos: Starting position in bytes
+ * @length: Length to map, in bytes
+ * @iomap: The iomap structure
+ *
+ * Returns: errno
+ */
+
+int gfs2_get_iomap(struct inode *inode, loff_t pos, ssize_t length,
+		   struct iomap *iomap)

This function should be merged with gfs2_block_map() I think, so that gfs2_block_map just becomes a wrapper (which will eventually go away) for this function. Otherwise we will have two parallel but slightly different implementations of block mapping to maintain.

[snip]

Quoted 38 lines
fs/gfs2/inode.c +22 -1
index e4da0ec..0d705ef 100644
@@ -17,7 +17,7 @@
  #include <linux/posix_acl.h>
  #include <linux/gfs2_ondisk.h>
  #include <linux/crc32.h>
-#include <linux/fiemap.h>
+#include <linux/iomap.h>
  #include <linux/security.h>
  #include <asm/uaccess.h>
 
@@ -1990,28 +1990,65 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
  	return 0;
  }
 
+static int gfs2_iomap_fiemap_begin(struct inode *inode, loff_t offset,
+				   loff_t length, unsigned flags,
+				   struct iomap *iomap)
+{
+	struct gfs2_inode *ip = GFS2_I(inode);
+	struct gfs2_holder *gh;
+	int ret;
+
+	gh = kzalloc(sizeof(struct gfs2_holder), GFP_NOFS);
+	if (!gh)
+		return -ENOMEM;
+
+	ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, gh);
+	if (ret) {
+		kfree(gh);
+		return ret;
+	}
+	ret = gfs2_get_iomap(inode, offset, length, iomap);
+	if (ret)
+		gfs2_glock_dq_uninit(gh);
+	return ret;

fs/gfs2/inode.c static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, · line 2023

Quoted 10 lines
fs/gfs2/inode.c +10 -0
+}
+
+static int gfs2_iomap_fiemap_end(struct inode *inode, loff_t offset,
+				 loff_t length, ssize_t written,
+				 unsigned flags, struct iomap *iomap)
+{
+	struct gfs2_inode *ip = GFS2_I(inode);
+	struct gfs2_holder *gh;
+
+	gh = gfs2_glock_is_locked_by_me(ip->i_gl);

Is there a better way to pass the gh from the begin function to the end function? I'm sure that will work, but it is the kind of thing that might trip up the unwary in the future,

Otherwise I think it looks good,

Steve.

#3 lore raw

PATCH v2 1/1 GFS2: Add function gfs2_get_iomap

----- Original Message -----

| > +int gfs2_get_iomap(struct inode *inode, loff_t pos, ssize_t length,
| > +		   struct iomap *iomap)
| This function should be merged with gfs2_block_map() I think, so that
| gfs2_block_map just becomes a wrapper (which will eventually go away)
| for this function. Otherwise we will have two parallel but slightly
| different implementations of block mapping to maintain.

Yes, I guess that's worth doing. I did this and included the revised patch below.

| Is there a better way to pass the gh from the begin function to the end
| function? I'm sure that will work, but it is the kind of thing that
| might trip up the unwary in the future,

Yeah, I would have passed the gh another way, but Christoph didn't leave a good way in the iomap interface or other bits to do it. At least not that I can see. It might be worth changing the interface to add that flexibility for other file systems that might want to do this as well. It would be easy enough to add a (void *)private pointer or something that can be passed around. Christoph and Steve: Would you prefer I plumb something before I do the GFS2 bits?

For now, here's a replacement patch which still does it the only way possible.

Bob Peterson
Red Hat File Systems
---
This patch replaces the GFS2 fiemap implementation that used vfs function __generic_block_fiemap with a new implementation that uses the new iomap-based fiemap interface. This allows GFS2's fiemap to skip holes. The time to do filefrag on a file with a 1 petabyte hole is reduced from several days or weeks, to milliseconds. Note that there are Kconfig changes that affect everyone.

---

fs/gfs2/Kconfig +1 -0
index 90c6a8f..f8fa955 100644
@@ -25,6 +25,7 @@ config GFS2_FS
 config GFS2_FS_LOCKING_DLM
 	bool "GFS2 DLM locking"
 	depends on (GFS2_FS!=n) && NET && INET && (IPV6 || IPV6=n) && \
+		FS_IOMAP && \
 		CONFIGFS_FS && SYSFS && (DLM=y || DLM=GFS2_FS)
 	help
 	  Multiple node locking module for GFS2
fs/gfs2/bmap.c +173 -26

247 lines not on this page · raw message

fs/gfs2/bmap.h +4 -0
index 81ded5e..8da2429 100644
@@ -10,6 +10,8 @@
 #ifndef __BMAP_DOT_H__
 #define __BMAP_DOT_H__
 
+#include <linux/iomap.h>
+
 #include "inode.h"
 
 struct inode;
@@ -47,6 +49,8 @@ static inline void gfs2_write_calc_reserv(const struct gfs2_inode *ip,
 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_get_iomap(struct inode *inode, loff_t pos,
+			  ssize_t length, struct iomap *iomap);
 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);
fs/gfs2/inode.c +49 -12

96 lines not on this page · raw message

#4 lore raw

PATCH v2 1/1 GFS2: Add function gfs2_get_iomap

Hi,

Quoted 10 lines · Bob Peterson

----- Original Message -----

| > +int gfs2_get_iomap(struct inode *inode, loff_t pos, ssize_t length,
| > +		   struct iomap *iomap)
| This function should be merged with gfs2_block_map() I think, so that
| gfs2_block_map just becomes a wrapper (which will eventually go away)
| for this function. Otherwise we will have two parallel but slightly
| different implementations of block mapping to maintain.

Yes, I guess that's worth doing. I did this and included the revised patch below.

That wasn't quite what I was thinking of... comments below

Quoted 12 lines
| Is there a better way to pass the gh from the begin function to the end
| function? I'm sure that will work, but it is the kind of thing that
| might trip up the unwary in the future,

Yeah, I would have passed the gh another way, but Christoph didn't leave a good way in the iomap interface or other bits to do it. At least not that I can see. It might be worth changing the interface to add that flexibility for other file systems that might want to do this as well. It would be easy enough to add a (void *)private pointer or something that can be passed around. Christoph and Steve: Would you prefer I plumb something before I do the GFS2 bits?

Quoted 1 line

For now, here's a replacement patch which still does it the only way possible.

I think there is a possible race in case a single process opens the same file twice, unless I'm missing something there? It is an unlikely thing for someone to do, but we should allow for it anyway.

Quoted 96 lines

Bob Peterson
Red Hat File Systems
---
This patch replaces the GFS2 fiemap implementation that used vfs function __generic_block_fiemap with a new implementation that uses the new iomap-based fiemap interface. This allows GFS2's fiemap to skip holes. The time to do filefrag on a file with a 1 petabyte hole is reduced from several days or weeks, to milliseconds. Note that there are Kconfig changes that affect everyone.

---

fs/gfs2/Kconfig +1 -0
index 90c6a8f..f8fa955 100644
@@ -25,6 +25,7 @@ config GFS2_FS
  config GFS2_FS_LOCKING_DLM
  	bool "GFS2 DLM locking"
  	depends on (GFS2_FS!=n) && NET && INET && (IPV6 || IPV6=n) && \
+		FS_IOMAP && \
  		CONFIGFS_FS && SYSFS && (DLM=y || DLM=GFS2_FS)
  	help
  	  Multiple node locking module for GFS2
fs/gfs2/bmap.c +60 -0
index 6e2bec1..839f2a6 100644
@@ -588,6 +588,66 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock,
  }
 
  /**
+ * hole_size - figure out the size of a hole
+ * @ip: The inode
+ * @lblock: The logical starting block number
+ * @mp: The metapath
+ *
+ * Returns: The hole size in bytes
+ *
+ */
+static u64 hole_size(struct inode *inode, sector_t lblock, struct metapath *mp)
+{
+	struct gfs2_inode *ip = GFS2_I(inode);
+	struct gfs2_sbd *sdp = GFS2_SB(inode);
+	struct metapath mp_eof;
+	unsigned int end_of_metadata = ip->i_height - 1;
+	u64 factor = 1;
+	int hgt = end_of_metadata;
+	u64 holesz = 0, holestep;
+	const __be64 *first, *end, *ptr;
+	const struct buffer_head *bh;
+	u64 isize = i_size_read(inode);
+	int zeroptrs;
+	bool done = false;
+
+	/* Get another metapath, to the very last byte */
+	find_metapath(sdp, (isize - 1) >> inode->i_blkbits, &mp_eof,
+		      ip->i_height);
+	for (hgt = end_of_metadata; hgt >= 0 && !done; hgt--) {
+		bh = mp->mp_bh[hgt];
+		if (bh) {
+			zeroptrs = 0;
+			first = metapointer(hgt, mp);
+			end = (const __be64 *)(bh->b_data + bh->b_size);
+
+			for (ptr = first; ptr < end; ptr++) {
+				if (*ptr) {
+					done = true;
+					break;
+				} else {
+					zeroptrs++;
+				}
+			}
+		} else {
+			zeroptrs = sdp->sd_inptrs;
+		}
+		holestep = min(factor * zeroptrs,
+			       isize - (lblock + (zeroptrs * holesz)));
+		holesz += holestep;
+		if (lblock + holesz >= isize)
+			return holesz << inode->i_blkbits;
+
+		factor *= sdp->sd_inptrs;
+		if (hgt && (mp->mp_list[hgt - 1] < mp_eof.mp_list[hgt - 1]))
+			(mp->mp_list[hgt - 1])++;
+	}
+	return holesz << inode->i_blkbits;
+}
+
+enum gfs2_map_type { maptype_iomap = 1, maptype_bhmap = 2, };
+
+/**
   * gfs2_block_map - Map a block from an inode to a disk block
   * @inode: The inode
   * @lblock: The logical block number

fs/gfs2/bmap.c static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock, · line 667

Quoted 9 lines
fs/gfs2/bmap.c +3 -2
@@ -601,13 +661,14 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock,
   * Returns: errno
   */
 
-int gfs2_block_map(struct inode *inode, sector_t lblock,
-		   struct buffer_head *bh_map, int create)
+static int _gfs2_block_map(struct inode *inode, loff_t pos, ssize_t length,
+			   int create, enum gfs2_map_type maptype,
+			   void *iomap_or_bh)
  {

Lets just call this gfs2_iomap() and make it take a struct iomap only. Then we'd have a new function with
the original name:

int gfs2_block_map(struct inode *inode, sector_t lblock,
struct buffer_head *bh_map, int create)

{
     struct iomap *iom;

     /* Set up iomap based on bh */

     ret = gfs2_iomap(inode, pos, length, create, &iom);

     /* Copy iomap data back into bh */

    return ret;
}

That way we use iomap as the main structure through our block mapping functions, removing the bh from those code paths entirely and gfs2_block_map() becomes a function for backwards compatibility that we'd eventually be able to remove. It also means that you don't need the gfs2_map_type enum either,

Steve.

#5 lore raw

PATCH v2 1/1 GFS2: Add function gfs2_get_iomap

In reply to Bob Peterson
Quoted 11 lines · Bob Peterson
| Is there a better way to pass the gh from the begin function to the end
| function? I'm sure that will work, but it is the kind of thing that
| might trip up the unwary in the future,

Yeah, I would have passed the gh another way, but Christoph didn't leave a good way in the iomap interface or other bits to do it. At least not that I can see. It might be worth changing the interface to add that flexibility for other file systems that might want to do this as well. It would be easy enough to add a (void *)private pointer or something that can be passed around. Christoph and Steve: Would you prefer I plumb something before I do the GFS2 bits?

The interface is not set in stone. If you have a good suggestion to improve it for your use case, send a patch.

#6 lore raw

PATCH 1/1 GFS2: Add function gfs2_get_iomap

In reply to Bob Peterson

fs/Kconfig config DCACHE_WORD_ACCESS · line 14

Quoted 3 lines

config FS_IOMAP

fs/Kconfig +1 -1
-	bool
+	bool "File System IOMAP Support"

This shouldn't be a user visible option...

fs/gfs2/Kconfig config GFS2_FS · line 29

Quoted 10 lines
fs/gfs2/Kconfig +1 -0
index 90c6a8f..f8fa955 100644
@@ -25,6 +25,7 @@ config GFS2_FS
 config GFS2_FS_LOCKING_DLM
 	bool "GFS2 DLM locking"
 	depends on (GFS2_FS!=n) && NET && INET && (IPV6 || IPV6=n) && \
+		FS_IOMAP && \
 		CONFIGFS_FS && SYSFS && (DLM=y || DLM=GFS2_FS)

... just use select here