* [PATCH] Btrfs: fix infinite loop in btrfs_shrink_device()
@ 2011-02-25 23:43 Ilya Dryomov
2011-02-26 2:05 ` Yan, Zheng
0 siblings, 1 reply; 4+ messages in thread
From: Ilya Dryomov @ 2011-02-25 23:43 UTC (permalink / raw)
To: linux-btrfs; +Cc: Chris Mason
In case of an ENOSPC error from btrfs_relocate_chunk() (line 2202) while
relocating a block group with offset 0 we end up endlessly looping.
This happens because key.offset -= 1 statement then unconditionally
brings us back to the beginnig of the loop (key.offset == (u64)-1).
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
---
fs/btrfs/volumes.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index dd13eb8..0cb94ce 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2212,7 +2212,8 @@ again:
goto done;
if (ret == -ENOSPC)
failed++;
- key.offset -= 1;
+ if (--key.offset == -1)
+ break;
}
if (failed && !retried) {
--
1.7.2.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Btrfs: fix infinite loop in btrfs_shrink_device()
2011-02-25 23:43 Ilya Dryomov
@ 2011-02-26 2:05 ` Yan, Zheng
2011-02-26 14:15 ` Ilya Dryomov
0 siblings, 1 reply; 4+ messages in thread
From: Yan, Zheng @ 2011-02-26 2:05 UTC (permalink / raw)
To: Ilya Dryomov; +Cc: linux-btrfs, Chris Mason
On Sat, Feb 26, 2011 at 7:43 AM, Ilya Dryomov <idryomov@gmail.com> wrot=
e:
> In case of an ENOSPC error from btrfs_relocate_chunk() (line 2202) wh=
ile
> relocating a block group with offset 0 we end up endlessly looping.
> This happens because key.offset -=3D 1 statement then unconditionally
> brings us back to the beginnig of the loop (key.offset =3D=3D (u64)-1=
).
>
> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
> ---
> =A0fs/btrfs/volumes.c | =A0 =A03 ++-
> =A01 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index dd13eb8..0cb94ce 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -2212,7 +2212,8 @@ again:
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto done;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (ret =3D=3D -ENOSPC)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0failed++;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 key.offset -=3D 1;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (--key.offset =3D=3D -1)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
> =A0 =A0 =A0 =A0}
it should be if (--key.offset =3D=3D (u64) -1)
>
> =A0 =A0 =A0 =A0if (failed && !retried) {
> --
> 1.7.2.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs=
" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at =A0http://vger.kernel.org/majordomo-info.html
>
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Btrfs: fix infinite loop in btrfs_shrink_device()
2011-02-26 2:05 ` Yan, Zheng
@ 2011-02-26 14:15 ` Ilya Dryomov
0 siblings, 0 replies; 4+ messages in thread
From: Ilya Dryomov @ 2011-02-26 14:15 UTC (permalink / raw)
To: Yan, Zheng ; +Cc: linux-btrfs, Chris Mason
On Sat, Feb 26, 2011 at 10:05:40AM +0800, Yan, Zheng wrote:
> On Sat, Feb 26, 2011 at 7:43 AM, Ilya Dryomov <idryomov@gmail.com> wr=
ote:
> > In case of an ENOSPC error from btrfs_relocate_chunk() (line 2202) =
while
> > relocating a block group with offset 0 we end up endlessly looping.
> > This happens because key.offset -=3D 1 statement then unconditional=
ly
> > brings us back to the beginnig of the loop (key.offset =3D=3D (u64)=
-1).
> >
> > Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
> > ---
> > =C2=A0fs/btrfs/volumes.c | =C2=A0 =C2=A03 ++-
> > =C2=A01 files changed, 2 insertions(+), 1 deletions(-)
> >
> > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> > index dd13eb8..0cb94ce 100644
> > --- a/fs/btrfs/volumes.c
> > +++ b/fs/btrfs/volumes.c
> > @@ -2212,7 +2212,8 @@ again:
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0goto done;
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (ret =3D=3D=
-ENOSPC)
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0failed++;
> > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 key.offset -=3D =
1;
> > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (--key.offset=
=3D=3D -1)
> > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 break;
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0}
>=20
> it should be if (--key.offset =3D=3D (u64) -1)
>=20
> >
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0if (failed && !retried) {
> > --
> > 1.7.2.3
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-btr=
fs" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at =C2=A0http://vger.kernel.org/majordomo-info.=
html
> >
I wonder how I managed to screw that up, I got it right in the commit
description.. Sorry for the noise, here is an updated version.
---
=46rom: Ilya Dryomov <idryomov@gmail.com>
Date: Sat, 26 Feb 2011 01:29:25 +0200
Subject: [PATCH] Btrfs: fix infinite loop in btrfs_shrink_device()
In case of an ENOSPC error from btrfs_relocate_chunk() (line 2202) whil=
e
relocating a block group with offset 0 we end up endlessly looping.
This happens because key.offset -=3D 1 statement then unconditionally
brings us back to the beginning of the loop (key.offset =3D=3D (u64)-1)=
=2E
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
---
fs/btrfs/volumes.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index dd13eb8..cd334ae 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2212,7 +2212,8 @@ again:
goto done;
if (ret =3D=3D -ENOSPC)
failed++;
- key.offset -=3D 1;
+ if (--key.offset =3D=3D (u64)-1)
+ break;
}
=20
if (failed && !retried) {
--=20
1.7.2.3
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] Btrfs: fix infinite loop in btrfs_shrink_device()
@ 2012-03-27 15:14 Ilya Dryomov
0 siblings, 0 replies; 4+ messages in thread
From: Ilya Dryomov @ 2012-03-27 15:14 UTC (permalink / raw)
To: linux-btrfs; +Cc: Chris Mason, idryomov
If relocate of block group 0 fails with ENOSPC we end up infinitely
looping because key.offset -= 1 statement in that case brings us back to
where we started.
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
---
fs/btrfs/volumes.c | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index bcc0acd..be2d4e0 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2987,7 +2987,7 @@ again:
key.offset = (u64)-1;
key.type = BTRFS_DEV_EXTENT_KEY;
- while (1) {
+ do {
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0)
goto done;
@@ -3029,8 +3029,7 @@ again:
goto done;
if (ret == -ENOSPC)
failed++;
- key.offset -= 1;
- }
+ } while (key.offset-- > 0);
if (failed && !retried) {
failed = 0;
--
1.7.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-03-27 15:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-27 15:14 [PATCH] Btrfs: fix infinite loop in btrfs_shrink_device() Ilya Dryomov
-- strict thread matches above, loose matches on Subject: below --
2011-02-25 23:43 Ilya Dryomov
2011-02-26 2:05 ` Yan, Zheng
2011-02-26 14:15 ` Ilya Dryomov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).