All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] xfs_db: take BB cluster offset into account when using 'type' cmd
@ 2022-04-19 18:00 Andrey Albershteyn
  2022-04-19 18:29 ` Darrick J. Wong
  0 siblings, 1 reply; 2+ messages in thread
From: Andrey Albershteyn @ 2022-04-19 18:00 UTC (permalink / raw)
  To: linux-xfs; +Cc: Andrey Albershteyn

Changing the interpretation type of data under the cursor moves the
cursor to the beginning of BB cluster. When cursor is set to an
inode the cursor is offset in BB buffer. However, this offset is not
considered when type of the data is changed - the cursor points to
the beginning of BB buffer. For example:

$ xfs_db -c "inode 131" -c "daddr" -c "type text" \
	-c "daddr" /dev/sdb1
current daddr is 131
current daddr is 128

Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
---
Changes from V1:
- Refactor set_cur_boff() into separate funciton
---
 db/io.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/db/io.c b/db/io.c
index df97ed91..5aec31de 100644
--- a/db/io.c
+++ b/db/io.c
@@ -73,6 +73,13 @@ io_init(void)
 	add_command(&ring_cmd);
 }
 
+static inline void set_cur_boff(int off)
+{
+	iocur_top->boff = off;
+	iocur_top->off = ((xfs_off_t)iocur_top->bb << BBSHIFT) + off;
+	iocur_top->data = (void *)((char *)iocur_top->buf + off);
+}
+
 void
 off_cur(
 	int	off,
@@ -81,10 +88,8 @@ off_cur(
 	if (iocur_top == NULL || off + len > BBTOB(iocur_top->blen))
 		dbprintf(_("can't set block offset to %d\n"), off);
 	else {
-		iocur_top->boff = off;
-		iocur_top->off = ((xfs_off_t)iocur_top->bb << BBSHIFT) + off;
+		set_cur_boff(off);
 		iocur_top->len = len;
-		iocur_top->data = (void *)((char *)iocur_top->buf + off);
 	}
 }
 
@@ -589,6 +594,7 @@ set_iocur_type(
 	const typ_t	*type)
 {
 	int		bb_count = 1;	/* type's size in basic blocks */
+	int		boff = iocur_top->boff;
 
 	/*
 	 * Inodes are special; verifier checks all inodes in the chunk, the
@@ -613,6 +619,7 @@ set_iocur_type(
 		bb_count = BTOBB(byteize(fsize(type->fields,
 				       iocur_top->data, 0, 0)));
 	set_cur(type, iocur_top->bb, bb_count, DB_RING_IGN, NULL);
+	set_cur_boff(boff);
 }
 
 static void
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] xfs_db: take BB cluster offset into account when using 'type' cmd
  2022-04-19 18:00 [PATCH v2] xfs_db: take BB cluster offset into account when using 'type' cmd Andrey Albershteyn
@ 2022-04-19 18:29 ` Darrick J. Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Darrick J. Wong @ 2022-04-19 18:29 UTC (permalink / raw)
  To: Andrey Albershteyn; +Cc: linux-xfs

On Tue, Apr 19, 2022 at 08:00:39PM +0200, Andrey Albershteyn wrote:
> Changing the interpretation type of data under the cursor moves the
> cursor to the beginning of BB cluster. When cursor is set to an
> inode the cursor is offset in BB buffer. However, this offset is not
> considered when type of the data is changed - the cursor points to
> the beginning of BB buffer. For example:
> 
> $ xfs_db -c "inode 131" -c "daddr" -c "type text" \
> 	-c "daddr" /dev/sdb1
> current daddr is 131
> current daddr is 128
> 
> Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>

LGTM, thanks for fixing this longstanding annoyance :)
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
> Changes from V1:
> - Refactor set_cur_boff() into separate funciton
> ---
>  db/io.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/db/io.c b/db/io.c
> index df97ed91..5aec31de 100644
> --- a/db/io.c
> +++ b/db/io.c
> @@ -73,6 +73,13 @@ io_init(void)
>  	add_command(&ring_cmd);
>  }
>  
> +static inline void set_cur_boff(int off)
> +{
> +	iocur_top->boff = off;
> +	iocur_top->off = ((xfs_off_t)iocur_top->bb << BBSHIFT) + off;
> +	iocur_top->data = (void *)((char *)iocur_top->buf + off);
> +}
> +
>  void
>  off_cur(
>  	int	off,
> @@ -81,10 +88,8 @@ off_cur(
>  	if (iocur_top == NULL || off + len > BBTOB(iocur_top->blen))
>  		dbprintf(_("can't set block offset to %d\n"), off);
>  	else {
> -		iocur_top->boff = off;
> -		iocur_top->off = ((xfs_off_t)iocur_top->bb << BBSHIFT) + off;
> +		set_cur_boff(off);
>  		iocur_top->len = len;
> -		iocur_top->data = (void *)((char *)iocur_top->buf + off);
>  	}
>  }
>  
> @@ -589,6 +594,7 @@ set_iocur_type(
>  	const typ_t	*type)
>  {
>  	int		bb_count = 1;	/* type's size in basic blocks */
> +	int		boff = iocur_top->boff;
>  
>  	/*
>  	 * Inodes are special; verifier checks all inodes in the chunk, the
> @@ -613,6 +619,7 @@ set_iocur_type(
>  		bb_count = BTOBB(byteize(fsize(type->fields,
>  				       iocur_top->data, 0, 0)));
>  	set_cur(type, iocur_top->bb, bb_count, DB_RING_IGN, NULL);
> +	set_cur_boff(boff);
>  }
>  
>  static void
> -- 
> 2.27.0
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-19 18:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-19 18:00 [PATCH v2] xfs_db: take BB cluster offset into account when using 'type' cmd Andrey Albershteyn
2022-04-19 18:29 ` Darrick J. Wong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.