From: Bob Peterson <rpeterso@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [GFS2 PATCH 11/15] gfs2: reduce redundant code in gfs2_trans_add_*
Date: Tue, 27 Jul 2021 12:37:05 -0500 [thread overview]
Message-ID: <20210727173709.210711-12-rpeterso@redhat.com> (raw)
In-Reply-To: <20210727173709.210711-1-rpeterso@redhat.com>
Before this patch, functions gfs2_trans_add_data and gfs2_trans_add_meta
did similar checks to see if the buffer_head had an existing bd element,
and if not, assigned one, temporarily dropping locks to allow for better
simultaneous operations. These checks were identical except that the
meta version held the page lock after unlocking the log_lock and buffer
lock.
This patch consolidates the similar code into the helper function,
gfs2_alloc_bufdata, for consistency and to eliminate code redundancy.
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
---
fs/gfs2/trans.c | 46 ++++++++++++++++++++--------------------------
1 file changed, 20 insertions(+), 26 deletions(-)
diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c
index 63fec11ef2ce..4f70d381fd67 100644
--- a/fs/gfs2/trans.c
+++ b/fs/gfs2/trans.c
@@ -163,8 +163,20 @@ void gfs2_trans_end(struct gfs2_sbd *sdp)
static struct gfs2_bufdata *gfs2_alloc_bufdata(struct gfs2_glock *gl,
struct buffer_head *bh)
{
+ struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
struct gfs2_bufdata *bd;
+ bd = bh->b_private;
+ if (bd)
+ goto out_check_gl;
+
+ gfs2_log_unlock(sdp);
+ unlock_buffer(bh);
+ lock_page(bh->b_page);
+ bd = bh->b_private;
+ if (bd)
+ goto out_noalloc;
+
bd = kmem_cache_zalloc(gfs2_bufdata_cachep, GFP_NOFS | __GFP_NOFAIL);
bd->bd_bh = bh;
bd->bd_gl = gl;
@@ -172,6 +184,12 @@ static struct gfs2_bufdata *gfs2_alloc_bufdata(struct gfs2_glock *gl,
INIT_LIST_HEAD(&bd->bd_ail_st_list);
INIT_LIST_HEAD(&bd->bd_ail_gl_list);
bh->b_private = bd;
+out_noalloc:
+ unlock_page(bh->b_page);
+ lock_buffer(bh);
+ gfs2_log_lock(sdp);
+out_check_gl:
+ gfs2_assert(sdp, bd->bd_gl == gl);
return bd;
}
@@ -201,18 +219,7 @@ void gfs2_trans_add_data(struct gfs2_glock *gl, struct buffer_head *bh)
goto out;
}
gfs2_log_lock(sdp);
- bd = bh->b_private;
- if (bd == NULL) {
- gfs2_log_unlock(sdp);
- unlock_buffer(bh);
- if (bh->b_private == NULL)
- bd = gfs2_alloc_bufdata(gl, bh);
- else
- bd = bh->b_private;
- lock_buffer(bh);
- gfs2_log_lock(sdp);
- }
- gfs2_assert(sdp, bd->bd_gl == gl);
+ bd = gfs2_alloc_bufdata(gl, bh);
set_bit(TR_TOUCHED, &tr->tr_flags);
if (list_empty(&bd->bd_list)) {
set_bit(GLF_LFLUSH, &bd->bd_gl->gl_flags);
@@ -241,20 +248,7 @@ void gfs2_trans_add_meta(struct gfs2_glock *gl, struct buffer_head *bh)
goto out;
}
gfs2_log_lock(sdp);
- bd = bh->b_private;
- if (bd == NULL) {
- gfs2_log_unlock(sdp);
- unlock_buffer(bh);
- lock_page(bh->b_page);
- if (bh->b_private == NULL)
- bd = gfs2_alloc_bufdata(gl, bh);
- else
- bd = bh->b_private;
- unlock_page(bh->b_page);
- lock_buffer(bh);
- gfs2_log_lock(sdp);
- }
- gfs2_assert(sdp, bd->bd_gl == gl);
+ bd = gfs2_alloc_bufdata(gl, bh);
set_bit(TR_TOUCHED, &tr->tr_flags);
if (!list_empty(&bd->bd_list))
goto out_unlock;
--
2.31.1
next prev parent reply other threads:[~2021-07-27 17:37 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-27 17:36 [Cluster-devel] [GFS2 PATCH 00/15] gfs2: misc. patch collection (V2) Bob Peterson
2021-07-27 17:36 ` [Cluster-devel] [GFS2 PATCH 01/15] gfs2: Add wrapper for iomap_file_buffered_write Bob Peterson
2021-07-27 17:36 ` [Cluster-devel] [GFS2 PATCH 02/15] gfs2: Fix glock recursion in freeze_go_xmote_bh Bob Peterson
2021-07-27 17:36 ` [Cluster-devel] [GFS2 PATCH 03/15] gfs2: Eliminate go_xmote_bh in favor of go_lock Bob Peterson
2021-07-27 17:36 ` [Cluster-devel] [GFS2 PATCH 04/15] gfs2: be more verbose replaying invalid rgrp blocks Bob Peterson
2021-07-27 17:36 ` [Cluster-devel] [GFS2 PATCH 05/15] gfs2: trivial clean up of gfs2_ail_error Bob Peterson
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 06/15] gfs2: tiny cleanup in gfs2_log_reserve Bob Peterson
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 07/15] gfs2: init system threads before freeze lock Bob Peterson
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 08/15] gfs2: Don't release and reacquire local statfs bh Bob Peterson
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 09/15] gfs2: fix deadlock in gfs2_ail1_empty withdraw Bob Peterson
2021-07-28 5:38 ` Andreas Gruenbacher
2021-07-28 13:30 ` Bob Peterson
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 10/15] gfs2: replace sd_aspace with sd_inode Bob Peterson
2021-07-27 17:37 ` Bob Peterson [this message]
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 12/15] gfs2: Make recovery error more readable Bob Peterson
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 13/15] gfs2: ignore usr|grp|prjquota mount options Bob Peterson
2021-07-28 18:28 ` Andreas Gruenbacher
2021-07-28 20:32 ` Bob Peterson
2021-07-28 20:57 ` Andreas Gruenbacher
2021-08-02 8:46 ` Andrew Price
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 14/15] fs: Move notify_change permission checks into may_setattr Bob Peterson
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 15/15] gfs2: Switch to may_setattr in gfs2_setattr Bob Peterson
2021-07-27 18:30 ` [Cluster-devel] [GFS2 PATCH 00/15] gfs2: misc. patch collection (V2) 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=20210727173709.210711-12-rpeterso@redhat.com \
--to=rpeterso@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).