Skip to contentSkip to conversation

erofs: fix up erofs_lookup tracepoint

PATCH In review Gao Xiang 3 participants 5 messages Sep 21, 2021 – Sep 23, 2021

Subsystems (3)
lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/2 erofs: fix up erofs_lookup tracepoint

Fix up a misuse that the filename pointer isn't always valid in the ring buffer, and we should copy the content instead.

Fixes 13f06f48f7bf ("staging: erofs: support tracepoint")
---
 include/trace/events/erofs.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/trace/events/erofs.h +3 -3
index bf9806f..db4f2ce 100644
@@ -35,20 +35,20 @@
 	TP_STRUCT__entry(
 		__field(dev_t,		dev	)
 		__field(erofs_nid_t,	nid	)
-		__field(const char *,	name	)
+		__string(name,		dentry->d_name.name	)
 		__field(unsigned int,	flags	)
 	),
 
 	TP_fast_assign(
 		__entry->dev	= dir->i_sb->s_dev;
 		__entry->nid	= EROFS_I(dir)->nid;
-		__entry->name	= dentry->d_name.name;
+		__assign_str(name, dentry->d_name.name);
 		__entry->flags	= flags;
 	),
 
 	TP_printk("dev = (%d,%d), pnid = %llu, name:%s, flags:%x",
 		show_dev_nid(__entry),
-		__entry->name,
+		__get_str(name),
 		__entry->flags)
 );
 
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 2/2 erofs: clean up erofs_map_blocks tracepoints

Since the new type of chunk-based files is introduced, there is no need to leave flatmode tracepoints. Rename to erofs_map_blocks.

Add the missing FIEMAP tracepoint map flag as well.

---
 fs/erofs/data.c              | 31 ++++++++++++++-----------------
 include/trace/events/erofs.h |  7 ++++---
 2 files changed, 18 insertions(+), 20 deletions(-)
fs/erofs/data.c +14 -17
index 9db8297..020c3e0 100644
@@ -26,14 +26,11 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
 				     struct erofs_map_blocks *map,
 				     int flags)
 {
-	int err = 0;
 	erofs_blk_t nblocks, lastblk;
 	u64 offset = map->m_la;
 	struct erofs_inode *vi = EROFS_I(inode);
 	bool tailendpacking = (vi->datalayout == EROFS_INODE_FLAT_INLINE);
 
-	trace_erofs_map_blocks_flatmode_enter(inode, map, flags);
-
 	nblocks = DIV_ROUND_UP(inode->i_size, PAGE_SIZE);
 	lastblk = nblocks - tailendpacking;
 
@@ -57,8 +54,7 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
 				  "inline data cross block boundary @ nid %llu",
 				  vi->nid);
 			DBG_BUGON(1);
-			err = -EFSCORRUPTED;
-			goto err_out;
+			return -EFSCORRUPTED;
 		}
 
 		map->m_flags |= EROFS_MAP_META;
@@ -67,14 +63,10 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
 			  "internal error @ nid: %llu (size %llu), m_la 0x%llx",
 			  vi->nid, inode->i_size, map->m_la);
 		DBG_BUGON(1);
-		err = -EIO;
-		goto err_out;
+		return -EIO;
 	}
-
 	map->m_llen = map->m_plen;
-err_out:
-	trace_erofs_map_blocks_flatmode_exit(inode, map, flags, 0);
-	return err;
+	return 0;
 }
 
 static int erofs_map_blocks(struct inode *inode,
@@ -89,6 +81,7 @@ static int erofs_map_blocks(struct inode *inode,
 	erofs_off_t pos;
 	int err = 0;
 
+	trace_erofs_map_blocks_enter(inode, map, flags);
 	if (map->m_la >= inode->i_size) {
 		/* leave out-of-bound access unmapped */
 		map->m_flags = 0;
@@ -96,8 +89,10 @@ static int erofs_map_blocks(struct inode *inode,
 		goto out;
 	}
 
-	if (vi->datalayout != EROFS_INODE_CHUNK_BASED)
-		return erofs_map_blocks_flatmode(inode, map, flags);
+	if (vi->datalayout != EROFS_INODE_CHUNK_BASED) {
+		err = erofs_map_blocks_flatmode(inode, map, flags);
+		goto out;
+	}
 
 	if (vi->chunkformat & EROFS_CHUNK_FORMAT_INDEXES)
 		unit = sizeof(*idx);			/* chunk index */
@@ -109,9 +104,10 @@ static int erofs_map_blocks(struct inode *inode,
 		    vi->xattr_isize, unit) + unit * chunknr;
 
 	page = erofs_get_meta_page(inode->i_sb, erofs_blknr(pos));
-	if (IS_ERR(page))
-		return PTR_ERR(page);
-
+	if (IS_ERR(page)) {
+		err = PTR_ERR(page);
+		goto out;
+	}
 	map->m_la = chunknr << vi->chunkbits;
 	map->m_plen = min_t(erofs_off_t, 1UL << vi->chunkbits,
 			    roundup(inode->i_size - map->m_la, EROFS_BLKSIZ));
@@ -147,11 +143,12 @@ static int erofs_map_blocks(struct inode *inode,
 		map->m_flags = EROFS_MAP_MAPPED;
 		break;
 	}
+	map->m_llen = map->m_plen;
 out_unlock:
 	unlock_page(page);
 	put_page(page);
 out:
-	map->m_llen = map->m_plen;
+	trace_erofs_map_blocks_exit(inode, map, flags, 0);
 	return err;
 }
 
include/trace/events/erofs.h +4 -3
index db4f2ce..5c91edd 100644
@@ -19,7 +19,8 @@
 		{ 1,		"DIR" })
 
 #define show_map_flags(flags) __print_flags(flags, "|",	\
-	{ EROFS_GET_BLOCKS_RAW,	"RAW" })
+	{ EROFS_GET_BLOCKS_RAW,	"RAW" },		\
+	{ EROFS_GET_BLOCKS_FIEMAP, "FIEMAP" })
 
 #define show_mflags(flags) __print_flags(flags, "",	\
 	{ EROFS_MAP_MAPPED,	"M" },			\
@@ -169,7 +170,7 @@
 		  __entry->flags ? show_map_flags(__entry->flags) : "NULL")
 );
 
-DEFINE_EVENT(erofs__map_blocks_enter, erofs_map_blocks_flatmode_enter,
+DEFINE_EVENT(erofs__map_blocks_enter, erofs_map_blocks_enter,
 	TP_PROTO(struct inode *inode, struct erofs_map_blocks *map,
 		 unsigned flags),
 
@@ -221,7 +222,7 @@
 		  show_mflags(__entry->mflags), __entry->ret)
 );
 
-DEFINE_EVENT(erofs__map_blocks_exit, erofs_map_blocks_flatmode_exit,
+DEFINE_EVENT(erofs__map_blocks_exit, erofs_map_blocks_exit,
 	TP_PROTO(struct inode *inode, struct erofs_map_blocks *map,
 		 unsigned flags, int ret),
 
Signature · 1 line
1.8.3.1
maintainer
#2 lore raw

Re: [PATCH 2/2] erofs: clean up erofs_map_blocks tracepoints

fs/erofs/data.c static int erofs_map_blocks(struct inode *inode,

Quoted 66 lines · Gao Xiang

Since the new type of chunk-based files is introduced, there is no need to leave flatmode tracepoints. Rename to erofs_map_blocks.

Add the missing FIEMAP tracepoint map flag as well.

---
  fs/erofs/data.c              | 31 ++++++++++++++-----------------
  include/trace/events/erofs.h |  7 ++++---
  2 files changed, 18 insertions(+), 20 deletions(-)
fs/erofs/data.c +4 -11
index 9db8297..020c3e0 100644
@@ -26,14 +26,11 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
  				     struct erofs_map_blocks *map,
  				     int flags)
  {
-	int err = 0;
  	erofs_blk_t nblocks, lastblk;
  	u64 offset = map->m_la;
  	struct erofs_inode *vi = EROFS_I(inode);
  	bool tailendpacking = (vi->datalayout == EROFS_INODE_FLAT_INLINE);
 
-	trace_erofs_map_blocks_flatmode_enter(inode, map, flags);
-
  	nblocks = DIV_ROUND_UP(inode->i_size, PAGE_SIZE);
  	lastblk = nblocks - tailendpacking;
 
@@ -57,8 +54,7 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
  				  "inline data cross block boundary @ nid %llu",
  				  vi->nid);
  			DBG_BUGON(1);
-			err = -EFSCORRUPTED;
-			goto err_out;
+			return -EFSCORRUPTED;
  		}
 
  		map->m_flags |= EROFS_MAP_META;
@@ -67,14 +63,10 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
  			  "internal error @ nid: %llu (size %llu), m_la 0x%llx",
  			  vi->nid, inode->i_size, map->m_la);
  		DBG_BUGON(1);
-		err = -EIO;
-		goto err_out;
+		return -EIO;
  	}
-
  	map->m_llen = map->m_plen;
-err_out:
-	trace_erofs_map_blocks_flatmode_exit(inode, map, flags, 0);
-	return err;
+	return 0;
  }
 
  static int erofs_map_blocks(struct inode *inode,
@@ -89,6 +81,7 @@ static int erofs_map_blocks(struct inode *inode,
  	erofs_off_t pos;
  	int err = 0;
 
+	trace_erofs_map_blocks_enter(inode, map, flags);
  	if (map->m_la >= inode->i_size) {
  		/* leave out-of-bound access unmapped */
  		map->m_flags = 0;
@@ -96,8 +89,10 @@ static int erofs_map_blocks(struct inode *inode,

map->m_flags = 0;
map->m_plen = 0;

It needs to reset map->m_llen to zero here like we did after 'out' label before?

Thanks,

Quoted 73 lines
fs/erofs/data.c +10 -6
  		goto out;
  	}
 
-	if (vi->datalayout != EROFS_INODE_CHUNK_BASED)
-		return erofs_map_blocks_flatmode(inode, map, flags);
+	if (vi->datalayout != EROFS_INODE_CHUNK_BASED) {
+		err = erofs_map_blocks_flatmode(inode, map, flags);
+		goto out;
+	}
 
  	if (vi->chunkformat & EROFS_CHUNK_FORMAT_INDEXES)
  		unit = sizeof(*idx);			/* chunk index */
@@ -109,9 +104,10 @@ static int erofs_map_blocks(struct inode *inode,
  		    vi->xattr_isize, unit) + unit * chunknr;
 
  	page = erofs_get_meta_page(inode->i_sb, erofs_blknr(pos));
-	if (IS_ERR(page))
-		return PTR_ERR(page);
-
+	if (IS_ERR(page)) {
+		err = PTR_ERR(page);
+		goto out;
+	}
  	map->m_la = chunknr << vi->chunkbits;
  	map->m_plen = min_t(erofs_off_t, 1UL << vi->chunkbits,
  			    roundup(inode->i_size - map->m_la, EROFS_BLKSIZ));
@@ -147,11 +143,12 @@ static int erofs_map_blocks(struct inode *inode,
  		map->m_flags = EROFS_MAP_MAPPED;
  		break;
  	}
+	map->m_llen = map->m_plen;
  out_unlock:
  	unlock_page(page);
  	put_page(page);
  out:
-	map->m_llen = map->m_plen;
+	trace_erofs_map_blocks_exit(inode, map, flags, 0);
  	return err;
  }
 
include/trace/events/erofs.h +4 -3
index db4f2ce..5c91edd 100644
@@ -19,7 +19,8 @@
  		{ 1,		"DIR" })
 
  #define show_map_flags(flags) __print_flags(flags, "|",	\
-	{ EROFS_GET_BLOCKS_RAW,	"RAW" })
+	{ EROFS_GET_BLOCKS_RAW,	"RAW" },		\
+	{ EROFS_GET_BLOCKS_FIEMAP, "FIEMAP" })
 
  #define show_mflags(flags) __print_flags(flags, "",	\
  	{ EROFS_MAP_MAPPED,	"M" },			\
@@ -169,7 +170,7 @@
  		  __entry->flags ? show_map_flags(__entry->flags) : "NULL")
  );
 
-DEFINE_EVENT(erofs__map_blocks_enter, erofs_map_blocks_flatmode_enter,
+DEFINE_EVENT(erofs__map_blocks_enter, erofs_map_blocks_enter,
  	TP_PROTO(struct inode *inode, struct erofs_map_blocks *map,
  		 unsigned flags),
 
@@ -221,7 +222,7 @@
  		  show_mflags(__entry->mflags), __entry->ret)
  );
 
-DEFINE_EVENT(erofs__map_blocks_exit, erofs_map_blocks_flatmode_exit,
+DEFINE_EVENT(erofs__map_blocks_exit, erofs_map_blocks_exit,
  	TP_PROTO(struct inode *inode, struct erofs_map_blocks *map,
  		 unsigned flags, int ret),
 
maintainer
#3 lore raw

Re: [PATCH 2/2] erofs: clean up erofs_map_blocks tracepoints

Hi Chao,

Quoted 66 lines · Chao Yu

fs/erofs/data.c static int erofs_map_blocks(struct inode *inode,

Quoted 61 lines · Gao Xiang

Since the new type of chunk-based files is introduced, there is no need to leave flatmode tracepoints. Rename to erofs_map_blocks.

Add the missing FIEMAP tracepoint map flag as well.

---
  fs/erofs/data.c              | 31 ++++++++++++++-----------------
  include/trace/events/erofs.h |  7 ++++---
  2 files changed, 18 insertions(+), 20 deletions(-)
fs/erofs/data.c +4 -11
index 9db8297..020c3e0 100644
@@ -26,14 +26,11 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
  				     struct erofs_map_blocks *map,
  				     int flags)
  {
-	int err = 0;
  	erofs_blk_t nblocks, lastblk;
  	u64 offset = map->m_la;
  	struct erofs_inode *vi = EROFS_I(inode);
  	bool tailendpacking = (vi->datalayout == EROFS_INODE_FLAT_INLINE);
-	trace_erofs_map_blocks_flatmode_enter(inode, map, flags);
-
  	nblocks = DIV_ROUND_UP(inode->i_size, PAGE_SIZE);
  	lastblk = nblocks - tailendpacking;
@@ -57,8 +54,7 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
  				  "inline data cross block boundary @ nid %llu",
  				  vi->nid);
  			DBG_BUGON(1);
-			err = -EFSCORRUPTED;
-			goto err_out;
+			return -EFSCORRUPTED;
  		}
  		map->m_flags |= EROFS_MAP_META;
@@ -67,14 +63,10 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
  			  "internal error @ nid: %llu (size %llu), m_la 0x%llx",
  			  vi->nid, inode->i_size, map->m_la);
  		DBG_BUGON(1);
-		err = -EIO;
-		goto err_out;
+		return -EIO;
  	}
-
  	map->m_llen = map->m_plen;
-err_out:
-	trace_erofs_map_blocks_flatmode_exit(inode, map, flags, 0);
-	return err;
+	return 0;
  }
  static int erofs_map_blocks(struct inode *inode,
@@ -89,6 +81,7 @@ static int erofs_map_blocks(struct inode *inode,
  	erofs_off_t pos;
  	int err = 0;
+	trace_erofs_map_blocks_enter(inode, map, flags);
  	if (map->m_la >= inode->i_size) {
  		/* leave out-of-bound access unmapped */
  		map->m_flags = 0;
@@ -96,8 +89,10 @@ static int erofs_map_blocks(struct inode *inode,

map->m_flags = 0;
map->m_plen = 0;

Quoted 1 line

It needs to reset map->m_llen to zero here like we did after 'out' label before?

Yeah, thanks for catching that! I will fix it in the next version (PATCH 2/2 will be delayed for 5.16...)

p.s. I might need to apply the following patches for 5.15 cycle in advance, could you help review these as well? Many thanks!
1. erofs: fix misbehavior of unsupported chunk format check
2. erofs: fix compacted_2b if compacted_4b_initial > totalidx

Thanks,
Gao Xiang

Quoted 66 lines

Thanks,

Quoted 63 lines
fs/erofs/data.c +10 -6
  		goto out;
  	}
-	if (vi->datalayout != EROFS_INODE_CHUNK_BASED)
-		return erofs_map_blocks_flatmode(inode, map, flags);
+	if (vi->datalayout != EROFS_INODE_CHUNK_BASED) {
+		err = erofs_map_blocks_flatmode(inode, map, flags);
+		goto out;
+	}
  	if (vi->chunkformat & EROFS_CHUNK_FORMAT_INDEXES)
  		unit = sizeof(*idx);			/* chunk index */
@@ -109,9 +104,10 @@ static int erofs_map_blocks(struct inode *inode,
  		    vi->xattr_isize, unit) + unit * chunknr;
  	page = erofs_get_meta_page(inode->i_sb, erofs_blknr(pos));
-	if (IS_ERR(page))
-		return PTR_ERR(page);
-
+	if (IS_ERR(page)) {
+		err = PTR_ERR(page);
+		goto out;
+	}
  	map->m_la = chunknr << vi->chunkbits;
  	map->m_plen = min_t(erofs_off_t, 1UL << vi->chunkbits,
  			    roundup(inode->i_size - map->m_la, EROFS_BLKSIZ));
@@ -147,11 +143,12 @@ static int erofs_map_blocks(struct inode *inode,
  		map->m_flags = EROFS_MAP_MAPPED;
  		break;
  	}
+	map->m_llen = map->m_plen;
  out_unlock:
  	unlock_page(page);
  	put_page(page);
  out:
-	map->m_llen = map->m_plen;
+	trace_erofs_map_blocks_exit(inode, map, flags, 0);
  	return err;
  }
include/trace/events/erofs.h +4 -3
index db4f2ce..5c91edd 100644
@@ -19,7 +19,8 @@
  		{ 1,		"DIR" })
  #define show_map_flags(flags) __print_flags(flags, "|",	\
-	{ EROFS_GET_BLOCKS_RAW,	"RAW" })
+	{ EROFS_GET_BLOCKS_RAW,	"RAW" },		\
+	{ EROFS_GET_BLOCKS_FIEMAP, "FIEMAP" })
  #define show_mflags(flags) __print_flags(flags, "",	\
  	{ EROFS_MAP_MAPPED,	"M" },			\
@@ -169,7 +170,7 @@
  		  __entry->flags ? show_map_flags(__entry->flags) : "NULL")
  );
-DEFINE_EVENT(erofs__map_blocks_enter, erofs_map_blocks_flatmode_enter,
+DEFINE_EVENT(erofs__map_blocks_enter, erofs_map_blocks_enter,
  	TP_PROTO(struct inode *inode, struct erofs_map_blocks *map,
  		 unsigned flags),
@@ -221,7 +222,7 @@
  		  show_mflags(__entry->mflags), __entry->ret)
  );
-DEFINE_EVENT(erofs__map_blocks_exit, erofs_map_blocks_flatmode_exit,
+DEFINE_EVENT(erofs__map_blocks_exit, erofs_map_blocks_exit,
  	TP_PROTO(struct inode *inode, struct erofs_map_blocks *map,
  		 unsigned flags, int ret),