From: Andreas Gruenbacher <agruenba@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 04/11] gfs2: Minor gfs2_free_extlen cleanup
Date: Fri, 11 Jan 2019 17:05:41 +0100 [thread overview]
Message-ID: <20190111160548.9423-5-agruenba@redhat.com> (raw)
In-Reply-To: <20190111160548.9423-1-agruenba@redhat.com>
Limit the n_unaligned argument of gfs2_unaligned_extlen to the number of
blocks to scan so that the len argument can never underrun.
Slightly simplify the unaligned block logic in gfs2_free_extlen.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
fs/gfs2/rgrp.c | 30 +++++++++++++-----------------
1 file changed, 13 insertions(+), 17 deletions(-)
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 2ce46e372b020..f06755dae951e 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -335,8 +335,6 @@ static bool gfs2_unaligned_extlen(struct gfs2_rbm *rbm, u32 n_unaligned, u32 *le
if (res != GFS2_BLKST_FREE)
return true;
(*len)--;
- if (*len == 0)
- return true;
if (gfs2_rbm_incr(rbm))
return true;
}
@@ -362,7 +360,6 @@ static bool gfs2_unaligned_extlen(struct gfs2_rbm *rbm, u32 n_unaligned, u32 *le
static u32 gfs2_free_extlen(const struct gfs2_rbm *rrbm, u32 len)
{
struct gfs2_rbm rbm = *rrbm;
- u32 n_unaligned = rbm.offset & 3;
u32 size = len;
u32 bytes;
u32 chunk_size;
@@ -370,11 +367,14 @@ static u32 gfs2_free_extlen(const struct gfs2_rbm *rrbm, u32 len)
u64 block;
struct gfs2_bitmap *bi;
- if (n_unaligned &&
- gfs2_unaligned_extlen(&rbm, 4 - n_unaligned, &len))
- goto out;
+ /* Deal with unaligned bits at the front */
+ if (rbm.offset & 3) {
+ u32 n_unaligned = min(4 - (rbm.offset & 3), len);
+
+ if (gfs2_unaligned_extlen(&rbm, n_unaligned, &len))
+ goto out;
+ }
- n_unaligned = len & 3;
/* Start is now byte aligned */
while (len > 3) {
bi = rbm_bi(&rbm);
@@ -392,20 +392,16 @@ static u32 gfs2_free_extlen(const struct gfs2_rbm *rrbm, u32 len)
BUG_ON(len < chunk_size);
len -= chunk_size;
block = gfs2_rbm_to_block(&rbm);
- if (gfs2_rbm_from_block(&rbm, block + chunk_size)) {
- n_unaligned = 0;
- break;
- }
- if (ptr) {
- n_unaligned = 3;
+ if (gfs2_rbm_from_block(&rbm, block + chunk_size))
+ goto out;
+ if (ptr)
break;
- }
- n_unaligned = len & 3;
}
/* Deal with any bits left over@the end */
- if (n_unaligned)
- gfs2_unaligned_extlen(&rbm, n_unaligned, &len);
+ if (len)
+ gfs2_unaligned_extlen(&rbm, len, &len);
+
out:
return size - len;
}
--
2.20.1
next prev parent reply other threads:[~2019-01-11 16:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-11 16:05 [Cluster-devel] [PATCH 00/11] Read bitmap buffers on demand Andreas Gruenbacher
2019-01-11 16:05 ` [Cluster-devel] [PATCH 01/11] gfs2: Fix setting GBF_FULL in gfs2_rbm_find Andreas Gruenbacher
2019-01-11 16:05 ` [Cluster-devel] [PATCH 02/11] gfs2: Rename minext => minlen Andreas Gruenbacher
2019-01-11 16:05 ` [Cluster-devel] [PATCH 03/11] gfs2: Don't use struct gfs2_rbm in struct gfs2_extent Andreas Gruenbacher
2019-01-11 16:05 ` Andreas Gruenbacher [this message]
2019-01-11 16:05 ` [Cluster-devel] [PATCH 05/11] gfs2: Only use struct gfs2_rbm for bitmap manipulations Andreas Gruenbacher
2019-01-11 16:05 ` [Cluster-devel] [PATCH 06/11] gfs2: Minor gfs2_adjust_reservation and gfs2_alloc_extent cleanups Andreas Gruenbacher
2019-01-11 16:05 ` [Cluster-devel] [PATCH 07/11] gfs2: Minor gfs2_rgrp_send_discards cleanup Andreas Gruenbacher
2019-01-11 16:05 ` [Cluster-devel] [PATCH 08/11] gfs2: Add buffer head to struct gfs2_rgrpd Andreas Gruenbacher
2019-01-11 16:05 ` [Cluster-devel] [PATCH 09/11] gfs2: Read bitmap buffers on demand Andreas Gruenbacher
2019-01-14 17:12 ` Bob Peterson
2019-01-14 18:41 ` Andreas Gruenbacher
2019-01-14 22:08 ` Andreas Gruenbacher
2019-01-11 16:05 ` [Cluster-devel] [PATCH 10/11] gfs2: Clean up assertion, consistency check, and error reporting functions Andreas Gruenbacher
2019-01-14 16:27 ` Bob Peterson
2019-01-11 16:05 ` [Cluster-devel] [PATCH 11/11] gfs2: Skip gfs2_metatype_check for cached buffers Andreas Gruenbacher
2019-01-14 16:40 ` Bob Peterson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190111160548.9423-5-agruenba@redhat.com \
--to=agruenba@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).