From: Andreas Gruenbacher <agruenba@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 09/12] gfs2: Move lock flush locking to gfs2_trans_{begin, end}
Date: Mon, 14 Dec 2020 09:54:39 +0100 [thread overview]
Message-ID: <20201214085442.45467-10-agruenba@redhat.com> (raw)
In-Reply-To: <20201214085442.45467-1-agruenba@redhat.com>
Move the read locking of sd_log_flush_lock from gfs2_log_reserve to
gfs2_trans_begin, and its unlocking from gfs2_log_release to
gfs2_trans_end. Use gfs2_log_release in two places in which it was open
coded before.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
fs/gfs2/log.c | 28 +++-------------------------
fs/gfs2/log.h | 2 +-
fs/gfs2/trans.c | 23 ++++++++++++++++-------
3 files changed, 20 insertions(+), 33 deletions(-)
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index 8c46f8f64c9e..b0d4ce4992ed 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -411,7 +411,6 @@ void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks)
trace_gfs2_log_blocks(sdp, blks);
gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <=
sdp->sd_jdesc->jd_blocks);
- up_read(&sdp->sd_log_flush_lock);
}
/**
@@ -439,22 +438,16 @@ bool gfs2_log_is_empty(struct gfs2_sbd *sdp) {
* with queued waiters, we use an exclusive wait. This means that when we
* get woken with enough journal space to get our reservation, we need to
* wake the next waiter on the list.
- *
- * Returns: errno
*/
-int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks)
+void gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks)
{
- int ret = 0;
unsigned reserved_blks = 7 * (4096 / sdp->sd_vfs->s_blocksize);
unsigned wanted = blks + reserved_blks;
DEFINE_WAIT(wait);
int did_wait = 0;
unsigned int free_blocks;
- if (gfs2_assert_warn(sdp, blks) ||
- gfs2_assert_warn(sdp, blks <= sdp->sd_jdesc->jd_blocks))
- return -EINVAL;
atomic_add(blks, &sdp->sd_log_blks_needed);
retry:
free_blocks = atomic_read(&sdp->sd_log_blks_free);
@@ -482,13 +475,6 @@ int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks)
*/
if (unlikely(did_wait))
wake_up(&sdp->sd_log_waitq);
-
- down_read(&sdp->sd_log_flush_lock);
- if (unlikely(!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags))) {
- gfs2_log_release(sdp, blks);
- ret = -EROFS;
- }
- return ret;
}
/**
@@ -585,12 +571,7 @@ static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail)
unsigned int dist = log_distance(sdp, new_tail, sdp->sd_log_tail);
ail2_empty(sdp, new_tail);
-
- atomic_add(dist, &sdp->sd_log_blks_free);
- trace_gfs2_log_blocks(sdp, dist);
- gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <=
- sdp->sd_jdesc->jd_blocks);
-
+ gfs2_log_release(sdp, dist);
sdp->sd_log_tail = new_tail;
}
@@ -1125,10 +1106,7 @@ static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
maxres = sdp->sd_log_blks_reserved + tr->tr_reserved;
gfs2_assert_withdraw(sdp, maxres >= reserved);
unused = maxres - reserved;
- atomic_add(unused, &sdp->sd_log_blks_free);
- trace_gfs2_log_blocks(sdp, unused);
- gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <=
- sdp->sd_jdesc->jd_blocks);
+ gfs2_log_release(sdp, unused);
sdp->sd_log_blks_reserved = reserved;
gfs2_log_unlock(sdp);
diff --git a/fs/gfs2/log.h b/fs/gfs2/log.h
index f483e706db3a..db3bb3564ea0 100644
--- a/fs/gfs2/log.h
+++ b/fs/gfs2/log.h
@@ -65,7 +65,7 @@ extern void gfs2_ordered_del_inode(struct gfs2_inode *ip);
extern unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct);
extern void gfs2_remove_from_ail(struct gfs2_bufdata *bd);
extern void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks);
-extern int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks);
+extern void gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks);
extern bool gfs2_log_is_empty(struct gfs2_sbd *sdp);
extern void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
u64 seq, u32 tail, u32 lblock, u32 flags,
diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c
index e33cb8da056a..c9d8247ffa19 100644
--- a/fs/gfs2/trans.c
+++ b/fs/gfs2/trans.c
@@ -70,12 +70,22 @@ int __gfs2_trans_begin(struct gfs2_sbd *sdp, unsigned int blocks,
INIT_LIST_HEAD(&tr->tr_ail1_list);
INIT_LIST_HEAD(&tr->tr_ail2_list);
+ if (gfs2_assert_warn(sdp, tr->tr_reserved <= sdp->sd_jdesc->jd_blocks)) {
+ error = -EINVAL;
+ goto fail;
+ }
+
sb_start_intwrite(sdp->sd_vfs);
- error = gfs2_log_reserve(sdp, tr->tr_reserved);
- if (error) {
- if (error == -EROFS)
- wake_up(&sdp->sd_log_waitq);
+ gfs2_log_reserve(sdp, tr->tr_reserved);
+
+ down_read(&sdp->sd_log_flush_lock);
+ if (unlikely(!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags))) {
+ gfs2_log_release(sdp, tr->tr_reserved);
+ up_read(&sdp->sd_log_flush_lock);
+ sb_end_intwrite(sdp->sd_vfs);
+ wake_up(&sdp->sd_log_waitq);
+ error = -EROFS;
goto fail;
}
@@ -84,9 +94,7 @@ int __gfs2_trans_begin(struct gfs2_sbd *sdp, unsigned int blocks,
return 0;
fail:
- sb_end_intwrite(sdp->sd_vfs);
kmem_cache_free(gfs2_trans_cachep, tr);
-
return error;
}
@@ -105,8 +113,9 @@ void gfs2_trans_end(struct gfs2_sbd *sdp)
if (!test_bit(TR_TOUCHED, &tr->tr_flags)) {
gfs2_log_release(sdp, tr->tr_reserved);
- gfs2_trans_free(sdp, tr);
+ up_read(&sdp->sd_log_flush_lock);
sb_end_intwrite(sdp->sd_vfs);
+ gfs2_trans_free(sdp, tr);
return;
}
--
2.26.2
next prev parent reply other threads:[~2020-12-14 8:54 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-14 8:54 [Cluster-devel] [RFC PATCH 00/12] Some log space management cleanups Andreas Gruenbacher
2020-12-14 8:54 ` [Cluster-devel] [PATCH 01/12] gfs2: Deobfuscate function jdesc_find_i Andreas Gruenbacher
2020-12-14 8:54 ` [Cluster-devel] [PATCH 02/12] gfs2: Simplify the buf_limit and databuf_limit definitions Andreas Gruenbacher
2020-12-14 8:54 ` [Cluster-devel] [PATCH 03/12] gfs2: Minor gfs2_write_revokes cleanups Andreas Gruenbacher
2020-12-14 8:54 ` [Cluster-devel] [PATCH 04/12] gfs2: Some documentation clarifications Andreas Gruenbacher
2020-12-14 8:54 ` [Cluster-devel] [PATCH 05/12] gfs2: A minor debugging improvement Andreas Gruenbacher
2020-12-14 8:54 ` [Cluster-devel] [PATCH 06/12] gfs2: Clean up ail2_empty Andreas Gruenbacher
2020-12-14 8:54 ` [Cluster-devel] [PATCH 07/12] gfs2: Get rid of on-stack transactions Andreas Gruenbacher
2020-12-14 14:02 ` Bob Peterson
2020-12-14 14:05 ` Steven Whitehouse
2020-12-14 17:08 ` Andreas Gruenbacher
2020-12-14 8:54 ` [Cluster-devel] [PATCH 08/12] gfs2: Get rid of sd_reserving_log Andreas Gruenbacher
2020-12-14 8:54 ` Andreas Gruenbacher [this message]
2020-12-14 8:54 ` [Cluster-devel] [PATCH 10/12] gfs2: Don't wait for journal flush in clean_journal Andreas Gruenbacher
2020-12-14 8:54 ` [Cluster-devel] [PATCH 11/12] gfs2: Clean up gfs2_log_reserve Andreas Gruenbacher
2020-12-14 8:54 ` [Cluster-devel] [PATCH 12/12] gfs2: Use a tighter bound in gfs2_trans_begin Andreas Gruenbacher
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=20201214085442.45467-10-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).