All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Btrfs-progs: fix btrfs-map-logical to only print extent mapping info
@ 2016-07-15  1:40 Liu Bo
  2016-07-15  2:22 ` Qu Wenruo
  0 siblings, 1 reply; 3+ messages in thread
From: Liu Bo @ 2016-07-15  1:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

I have a valid btrfs image which contains,
...
        item 10 key (1103101952 BLOCK_GROUP_ITEM 1288372224) itemoff 15947 itemsize 24
                block group used 655360 chunk_objectid 256 flags DATA|RAID5
        item 11 key (1103364096 EXTENT_ITEM 131072) itemoff 15894 itemsize 53
                extent refs 1 gen 11 flags DATA
                extent data backref root 5 objectid 258 offset 0 count 1
        item 12 key (1103888384 EXTENT_ITEM 262144) itemoff 15841 itemsize 53
                extent refs 1 gen 15 flags DATA
                extent data backref root 1 objectid 256 offset 0 count 1
        item 13 key (1104281600 EXTENT_ITEM 262144) itemoff 15788 itemsize 53
                extent refs 1 gen 15 flags DATA
                extent data backref root 1 objectid 257 offset 0 count 1
...

The extent [1103364096, 131072) has length 131072, but if we run

"btrfs-map-logical -l 1103364096 -b $((65536 * 3)) /dev/sda"

it will return mapping info 's of  non-existing extents.

It's because it assumes that extents's are contiguous on logical address,
when it's not true, after one loop (cur_logical += cur_len) and mapping
the next extent, we can get an extent that is out of our search range and
we end up with a negative @real_len and printing all mapping infos till
the disk end.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
 btrfs-map-logical.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/btrfs-map-logical.c b/btrfs-map-logical.c
index fd0286d..f421a50 100644
--- a/btrfs-map-logical.c
+++ b/btrfs-map-logical.c
@@ -329,6 +329,11 @@ int main(int argc, char **argv)
 			goto out_close_fd;
 		if (ret > 0)
 			break;
+		/* check again if there is overlap. */
+		if (cur_logical + cur_len < logical ||
+		    cur_logical >= logical + bytes)
+			break;
+
 		real_logical = max(logical, cur_logical);
 		real_len = min(logical + bytes, cur_logical + cur_len) -
 			   real_logical;
-- 
2.5.0


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

* Re: [PATCH] Btrfs-progs: fix btrfs-map-logical to only print extent mapping info
  2016-07-15  1:40 [PATCH] Btrfs-progs: fix btrfs-map-logical to only print extent mapping info Liu Bo
@ 2016-07-15  2:22 ` Qu Wenruo
  2016-07-15  9:45   ` David Sterba
  0 siblings, 1 reply; 3+ messages in thread
From: Qu Wenruo @ 2016-07-15  2:22 UTC (permalink / raw)
  To: Liu Bo, linux-btrfs; +Cc: David Sterba



At 07/15/2016 09:40 AM, Liu Bo wrote:
> I have a valid btrfs image which contains,
> ...
>         item 10 key (1103101952 BLOCK_GROUP_ITEM 1288372224) itemoff 15947 itemsize 24
>                 block group used 655360 chunk_objectid 256 flags DATA|RAID5
>         item 11 key (1103364096 EXTENT_ITEM 131072) itemoff 15894 itemsize 53
>                 extent refs 1 gen 11 flags DATA
>                 extent data backref root 5 objectid 258 offset 0 count 1
>         item 12 key (1103888384 EXTENT_ITEM 262144) itemoff 15841 itemsize 53
>                 extent refs 1 gen 15 flags DATA
>                 extent data backref root 1 objectid 256 offset 0 count 1
>         item 13 key (1104281600 EXTENT_ITEM 262144) itemoff 15788 itemsize 53
>                 extent refs 1 gen 15 flags DATA
>                 extent data backref root 1 objectid 257 offset 0 count 1
> ...
>
> The extent [1103364096, 131072) has length 131072, but if we run
>
> "btrfs-map-logical -l 1103364096 -b $((65536 * 3)) /dev/sda"
>
> it will return mapping info 's of  non-existing extents.
>
> It's because it assumes that extents's are contiguous on logical address,
> when it's not true, after one loop (cur_logical += cur_len) and mapping
> the next extent, we can get an extent that is out of our search range and
> we end up with a negative @real_len and printing all mapping infos till
> the disk end.
>
> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>

Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

Yes, the assumption of all extents are contiguous is quite wrong.
So your check is needed.

Thanks,
Qu
> ---
>  btrfs-map-logical.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/btrfs-map-logical.c b/btrfs-map-logical.c
> index fd0286d..f421a50 100644
> --- a/btrfs-map-logical.c
> +++ b/btrfs-map-logical.c
> @@ -329,6 +329,11 @@ int main(int argc, char **argv)
>  			goto out_close_fd;
>  		if (ret > 0)
>  			break;
> +		/* check again if there is overlap. */
> +		if (cur_logical + cur_len < logical ||
> +		    cur_logical >= logical + bytes)
> +			break;
> +
>  		real_logical = max(logical, cur_logical);
>  		real_len = min(logical + bytes, cur_logical + cur_len) -
>  			   real_logical;
>



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

* Re: [PATCH] Btrfs-progs: fix btrfs-map-logical to only print extent mapping info
  2016-07-15  2:22 ` Qu Wenruo
@ 2016-07-15  9:45   ` David Sterba
  0 siblings, 0 replies; 3+ messages in thread
From: David Sterba @ 2016-07-15  9:45 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: Liu Bo, linux-btrfs, David Sterba

On Fri, Jul 15, 2016 at 10:22:52AM +0800, Qu Wenruo wrote:
> 
> 
> At 07/15/2016 09:40 AM, Liu Bo wrote:
> > I have a valid btrfs image which contains,
> > ...
> >         item 10 key (1103101952 BLOCK_GROUP_ITEM 1288372224) itemoff 15947 itemsize 24
> >                 block group used 655360 chunk_objectid 256 flags DATA|RAID5
> >         item 11 key (1103364096 EXTENT_ITEM 131072) itemoff 15894 itemsize 53
> >                 extent refs 1 gen 11 flags DATA
> >                 extent data backref root 5 objectid 258 offset 0 count 1
> >         item 12 key (1103888384 EXTENT_ITEM 262144) itemoff 15841 itemsize 53
> >                 extent refs 1 gen 15 flags DATA
> >                 extent data backref root 1 objectid 256 offset 0 count 1
> >         item 13 key (1104281600 EXTENT_ITEM 262144) itemoff 15788 itemsize 53
> >                 extent refs 1 gen 15 flags DATA
> >                 extent data backref root 1 objectid 257 offset 0 count 1
> > ...
> >
> > The extent [1103364096, 131072) has length 131072, but if we run
> >
> > "btrfs-map-logical -l 1103364096 -b $((65536 * 3)) /dev/sda"
> >
> > it will return mapping info 's of  non-existing extents.
> >
> > It's because it assumes that extents's are contiguous on logical address,
> > when it's not true, after one loop (cur_logical += cur_len) and mapping
> > the next extent, we can get an extent that is out of our search range and
> > we end up with a negative @real_len and printing all mapping infos till
> > the disk end.
> >
> > Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
> 
> Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

Applied, thanks.

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

end of thread, other threads:[~2016-07-15  9:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-15  1:40 [PATCH] Btrfs-progs: fix btrfs-map-logical to only print extent mapping info Liu Bo
2016-07-15  2:22 ` Qu Wenruo
2016-07-15  9:45   ` David Sterba

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.