From: Coly Li <colyli@suse.de>
To: linux-bcache@vger.kernel.org
Cc: linux-block@vger.kernel.org, Coly Li <colyli@suse.de>,
stable@vger.kernel.org
Subject: [RFC PATCH v2 13/16] bcache: fix fifo index swapping condition in btree_flush_write()
Date: Sat, 20 Apr 2019 00:05:06 +0800 [thread overview]
Message-ID: <20190419160509.66298-14-colyli@suse.de> (raw)
In-Reply-To: <20190419160509.66298-1-colyli@suse.de>
Current journal_max_cmp() and journal_min_cmp() assume that smaller fifo
index indicating elder journal entries, but this is only true when fifo
index is not swapped.
Fifo structure journal.pin is implemented by a cycle buffer, if the head
index reaches highest location of the cycle buffer, it will be swapped
to 0. Once the swapping happens, it means a smaller fifo index might be
associated to a newer journal entry. So the btree node with oldest
journal entry won't be selected by btree_flush_write() to flush out to
cache device. The result is, the oldest journal entries may always has
no chance to be written into cache device, and after a reboot
bch_journal_replay() may complain some journal entries are missing.
This patch handles the fifo index swapping conditions properly, then in
btree_flush_write() the btree node with oldest journal entry can be
slected from c->flush_btree correctly.
Cc: stable@vger.kernel.org
Signed-off-by: Coly Li <colyli@suse.de>
---
drivers/md/bcache/journal.c | 47 +++++++++++++++++++++++++++++++++++++++------
1 file changed, 41 insertions(+), 6 deletions(-)
diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c
index bdb6f9cefe48..bc0e01151155 100644
--- a/drivers/md/bcache/journal.c
+++ b/drivers/md/bcache/journal.c
@@ -464,12 +464,47 @@ int bch_journal_replay(struct cache_set *s, struct list_head *list)
}
/* Journalling */
-#define journal_max_cmp(l, r) \
- (fifo_idx(&c->journal.pin, btree_current_write(l)->journal) < \
- fifo_idx(&(c)->journal.pin, btree_current_write(r)->journal))
-#define journal_min_cmp(l, r) \
- (fifo_idx(&c->journal.pin, btree_current_write(l)->journal) > \
- fifo_idx(&(c)->journal.pin, btree_current_write(r)->journal))
+#define journal_max_cmp(l, r) \
+({ \
+ int l_idx, r_idx, f_idx, b_idx; \
+ bool _ret = true; \
+ \
+ l_idx = fifo_idx(&c->journal.pin, btree_current_write(l)->journal); \
+ r_idx = fifo_idx(&c->journal.pin, btree_current_write(r)->journal); \
+ f_idx = c->journal.pin.front; \
+ b_idx = c->journal.pin.back; \
+ \
+ _ret = (l_idx < r_idx); \
+ /* in case fifo back pointer is swapped */ \
+ if (b_idx < f_idx) { \
+ if (l_idx <= b_idx && r_idx >= f_idx) \
+ _ret = false; \
+ else if (l_idx >= f_idx && r_idx <= b_idx) \
+ _ret = true; \
+ } \
+ _ret; \
+})
+
+#define journal_min_cmp(l, r) \
+({ \
+ int l_idx, r_idx, f_idx, b_idx; \
+ bool _ret = true; \
+ \
+ l_idx = fifo_idx(&c->journal.pin, btree_current_write(l)->journal); \
+ r_idx = fifo_idx(&c->journal.pin, btree_current_write(r)->journal); \
+ f_idx = c->journal.pin.front; \
+ b_idx = c->journal.pin.back; \
+ \
+ _ret = (l_idx > r_idx); \
+ /* in case fifo back pointer is swapped */ \
+ if (b_idx < f_idx) { \
+ if (l_idx <= b_idx && r_idx >= f_idx) \
+ _ret = true; \
+ else if (l_idx >= f_idx && r_idx <= b_idx) \
+ _ret = false; \
+ } \
+ _ret; \
+})
static void btree_flush_write(struct cache_set *c)
{
--
2.16.4
next prev parent reply other threads:[~2019-04-19 16:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190419160509.66298-1-colyli@suse.de>
2019-04-19 16:04 ` [RFC PATCH v2 02/16] bcache: never set 0 to KEY_PTRS of jouranl key in journal_reclaim() Coly Li
2019-04-23 6:50 ` Hannes Reinecke
2019-04-19 16:04 ` [RFC PATCH v2 03/16] bcache: reload jouranl key information during journal replay Coly Li
2019-04-23 6:54 ` Hannes Reinecke
2019-04-23 6:56 ` Coly Li
2019-04-19 16:05 ` Coly Li [this message]
[not found] ` <20190419231642.90AB82171F@mail.kernel.org>
2019-04-20 13:20 ` [RFC PATCH v2 13/16] bcache: fix fifo index swapping condition in btree_flush_write() Coly Li
2019-04-23 7:09 ` Hannes Reinecke
2019-04-23 7:16 ` Coly Li
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=20190419160509.66298-14-colyli@suse.de \
--to=colyli@suse.de \
--cc=linux-bcache@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=stable@vger.kernel.org \
/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