From: Andreas Gruenbacher <agruenba@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH v3 10/20] gfs2: Move lock flush locking to gfs2_trans_{begin, end}
Date: Wed, 27 Jan 2021 22:07:36 +0100 [thread overview]
Message-ID: <20210127210746.16958-11-agruenba@redhat.com> (raw)
In-Reply-To: <20210127210746.16958-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 2e84ba153cdf..2e74137322bd 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -420,7 +420,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 @@ void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks)
* 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;
}
@@ -1126,10 +1107,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 16efbe614279..cbc097ca9244 100644
--- a/fs/gfs2/log.h
+++ b/fs/gfs2/log.h
@@ -66,7 +66,7 @@ extern unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct);
extern void gfs2_remove_from_ail(struct gfs2_bufdata *bd);
extern bool gfs2_log_is_empty(struct gfs2_sbd *sdp);
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 void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
u64 seq, u32 tail, u32 lblock, u32 flags,
int op_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:[~2021-01-27 21:07 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-27 21:07 [Cluster-devel] [PATCH v3 00/20] Some log space management cleanups Andreas Gruenbacher
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 01/20] gfs2: Un-obfuscate function jdesc_find_i Andreas Gruenbacher
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 02/20] gfs2: Simplify the buf_limit and databuf_limit definitions Andreas Gruenbacher
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 03/20] gfs2: Minor gfs2_write_revokes cleanups Andreas Gruenbacher
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 04/20] gfs2: Some documentation updates Andreas Gruenbacher
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 05/20] gfs2: Minor debugging improvement Andreas Gruenbacher
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 06/20] gfs2: Rename gfs2_{write => flush}_revokes Andreas Gruenbacher
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 07/20] gfs2: Clean up ail2_empty Andreas Gruenbacher
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 08/20] gfs2: Get rid of on-stack transactions Andreas Gruenbacher
2021-01-28 9:21 ` Steven Whitehouse
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 09/20] gfs2: Get rid of sd_reserving_log Andreas Gruenbacher
2021-01-27 21:07 ` Andreas Gruenbacher [this message]
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 11/20] gfs2: Don't wait for journal flush in clean_journal Andreas Gruenbacher
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 12/20] gfs2: Clean up gfs2_log_reserve Andreas Gruenbacher
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 13/20] gfs2: Use a tighter bound in gfs2_trans_begin Andreas Gruenbacher
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 14/20] gfs2: Get rid of current_tail() Andreas Gruenbacher
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 15/20] gfs2: Move function gfs2_ail_empty_tr Andreas Gruenbacher
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 16/20] gfs2: No revokes for transactions at the tail of the log Andreas Gruenbacher
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 17/20] gfs2: Remove sd_log_committed_revoke Andreas Gruenbacher
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 18/20] gfs2: Remove sd_log_blks_reserved Andreas Gruenbacher
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 19/20] gfs2: Rework the log space allocation logic Andreas Gruenbacher
2021-01-27 21:07 ` [Cluster-devel] [PATCH v3 20/20] gfs2: Per-revoke accounting in transactions 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=20210127210746.16958-11-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).