* [PATCH v2 0/3] further lockref cleanups
@ 2025-01-30 13:56 Andreas Gruenbacher
2025-01-30 13:56 ` [PATCH v2 1/3] gfs2: use lockref_init for gl_lockref Andreas Gruenbacher
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Andreas Gruenbacher @ 2025-01-30 13:56 UTC (permalink / raw)
To: Christian Brauner
Cc: Andreas Gruenbacher, Christoph Hellwig, gfs2, linux-fsdevel,
linux-kernel
Here's an updated version with:
* An additional comment saying that lockref_init() initializes
count to 1.
* Reviewed-by tags from Christoph.
Thanks,
Andreas
Andreas Gruenbacher (3):
gfs2: use lockref_init for gl_lockref
gfs2: switch to lockref_init(..., 1)
lockref: remove count argument of lockref_init
fs/dcache.c | 2 +-
fs/erofs/zdata.c | 2 +-
fs/gfs2/glock.c | 2 +-
fs/gfs2/main.c | 1 -
fs/gfs2/quota.c | 4 ++--
include/linux/lockref.h | 7 ++++---
6 files changed, 9 insertions(+), 9 deletions(-)
--
2.48.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/3] gfs2: use lockref_init for gl_lockref
2025-01-30 13:56 [PATCH v2 0/3] further lockref cleanups Andreas Gruenbacher
@ 2025-01-30 13:56 ` Andreas Gruenbacher
2025-01-30 13:56 ` [PATCH v2 2/3] gfs2: switch to lockref_init(..., 1) Andreas Gruenbacher
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Andreas Gruenbacher @ 2025-01-30 13:56 UTC (permalink / raw)
To: Christian Brauner
Cc: Andreas Gruenbacher, Christoph Hellwig, gfs2, linux-fsdevel,
linux-kernel
Move the initialization of gl_lockref from gfs2_init_glock_once() to
gfs2_glock_get(). This allows to use lockref_init() there.
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
fs/gfs2/glock.c | 2 +-
fs/gfs2/main.c | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 8c4c1f871a88..b29eb71e3e29 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -1201,8 +1201,8 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
if (glops->go_instantiate)
gl->gl_flags |= BIT(GLF_INSTANTIATE_NEEDED);
gl->gl_name = name;
+ lockref_init(&gl->gl_lockref, 1);
lockdep_set_subclass(&gl->gl_lockref.lock, glops->go_subclass);
- gl->gl_lockref.count = 1;
gl->gl_state = LM_ST_UNLOCKED;
gl->gl_target = LM_ST_UNLOCKED;
gl->gl_demote_state = LM_ST_EXCLUSIVE;
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
index 04cadc02e5a6..0727f60ad028 100644
--- a/fs/gfs2/main.c
+++ b/fs/gfs2/main.c
@@ -51,7 +51,6 @@ static void gfs2_init_glock_once(void *foo)
{
struct gfs2_glock *gl = foo;
- spin_lock_init(&gl->gl_lockref.lock);
INIT_LIST_HEAD(&gl->gl_holders);
INIT_LIST_HEAD(&gl->gl_lru);
INIT_LIST_HEAD(&gl->gl_ail_list);
--
2.48.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] gfs2: switch to lockref_init(..., 1)
2025-01-30 13:56 [PATCH v2 0/3] further lockref cleanups Andreas Gruenbacher
2025-01-30 13:56 ` [PATCH v2 1/3] gfs2: use lockref_init for gl_lockref Andreas Gruenbacher
@ 2025-01-30 13:56 ` Andreas Gruenbacher
2025-01-30 13:56 ` [PATCH v2 3/3] lockref: remove count argument of lockref_init Andreas Gruenbacher
2025-01-30 15:05 ` [PATCH v2 0/3] further lockref cleanups Christian Brauner
3 siblings, 0 replies; 5+ messages in thread
From: Andreas Gruenbacher @ 2025-01-30 13:56 UTC (permalink / raw)
To: Christian Brauner
Cc: Andreas Gruenbacher, Christoph Hellwig, gfs2, linux-fsdevel,
linux-kernel
In qd_alloc(), initialize the lockref count to 1 to cover the common
case. Compensate for that in gfs2_quota_init() by adjusting the count
back down to 0; this only occurs when mounting the filesystem rw.
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
fs/gfs2/quota.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index 58bc5013ca49..6ae529a5388b 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -236,7 +236,7 @@ static struct gfs2_quota_data *qd_alloc(unsigned hash, struct gfs2_sbd *sdp, str
return NULL;
qd->qd_sbd = sdp;
- lockref_init(&qd->qd_lockref, 0);
+ lockref_init(&qd->qd_lockref, 1);
qd->qd_id = qid;
qd->qd_slot = -1;
INIT_LIST_HEAD(&qd->qd_lru);
@@ -297,7 +297,6 @@ static int qd_get(struct gfs2_sbd *sdp, struct kqid qid,
spin_lock_bucket(hash);
*qdp = qd = gfs2_qd_search_bucket(hash, sdp, qid);
if (qd == NULL) {
- new_qd->qd_lockref.count++;
*qdp = new_qd;
list_add(&new_qd->qd_list, &sdp->sd_quota_list);
hlist_bl_add_head_rcu(&new_qd->qd_hlist, &qd_hash_table[hash]);
@@ -1450,6 +1449,7 @@ int gfs2_quota_init(struct gfs2_sbd *sdp)
if (qd == NULL)
goto fail_brelse;
+ qd->qd_lockref.count = 0;
set_bit(QDF_CHANGE, &qd->qd_flags);
qd->qd_change = qc_change;
qd->qd_slot = slot;
--
2.48.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] lockref: remove count argument of lockref_init
2025-01-30 13:56 [PATCH v2 0/3] further lockref cleanups Andreas Gruenbacher
2025-01-30 13:56 ` [PATCH v2 1/3] gfs2: use lockref_init for gl_lockref Andreas Gruenbacher
2025-01-30 13:56 ` [PATCH v2 2/3] gfs2: switch to lockref_init(..., 1) Andreas Gruenbacher
@ 2025-01-30 13:56 ` Andreas Gruenbacher
2025-01-30 15:05 ` [PATCH v2 0/3] further lockref cleanups Christian Brauner
3 siblings, 0 replies; 5+ messages in thread
From: Andreas Gruenbacher @ 2025-01-30 13:56 UTC (permalink / raw)
To: Christian Brauner
Cc: Andreas Gruenbacher, Christoph Hellwig, gfs2, linux-fsdevel,
linux-kernel
All users of lockref_init() now initialize the count to 1, so hardcode
that and remove the count argument.
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
fs/dcache.c | 2 +-
fs/erofs/zdata.c | 2 +-
fs/gfs2/glock.c | 2 +-
fs/gfs2/quota.c | 2 +-
include/linux/lockref.h | 7 ++++---
5 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/fs/dcache.c b/fs/dcache.c
index 1a01d7a6a7a9..973a66dd3adf 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1682,7 +1682,7 @@ static struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
smp_store_release(&dentry->d_name.name, dname); /* ^^^ */
dentry->d_flags = 0;
- lockref_init(&dentry->d_lockref, 1);
+ lockref_init(&dentry->d_lockref);
seqcount_spinlock_init(&dentry->d_seq, &dentry->d_lock);
dentry->d_inode = NULL;
dentry->d_parent = dentry;
diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index 254f6ad2c336..85a08230d7c2 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -747,7 +747,7 @@ static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe)
if (IS_ERR(pcl))
return PTR_ERR(pcl);
- lockref_init(&pcl->lockref, 1); /* one ref for this request */
+ lockref_init(&pcl->lockref); /* one ref for this request */
pcl->algorithmformat = map->m_algorithmformat;
pcl->length = 0;
pcl->partial = true;
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index b29eb71e3e29..65c07aa95718 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -1201,7 +1201,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
if (glops->go_instantiate)
gl->gl_flags |= BIT(GLF_INSTANTIATE_NEEDED);
gl->gl_name = name;
- lockref_init(&gl->gl_lockref, 1);
+ lockref_init(&gl->gl_lockref);
lockdep_set_subclass(&gl->gl_lockref.lock, glops->go_subclass);
gl->gl_state = LM_ST_UNLOCKED;
gl->gl_target = LM_ST_UNLOCKED;
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index 6ae529a5388b..2298e06797ac 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -236,7 +236,7 @@ static struct gfs2_quota_data *qd_alloc(unsigned hash, struct gfs2_sbd *sdp, str
return NULL;
qd->qd_sbd = sdp;
- lockref_init(&qd->qd_lockref, 1);
+ lockref_init(&qd->qd_lockref);
qd->qd_id = qid;
qd->qd_slot = -1;
INIT_LIST_HEAD(&qd->qd_lru);
diff --git a/include/linux/lockref.h b/include/linux/lockref.h
index c39f119659ba..676721ee878d 100644
--- a/include/linux/lockref.h
+++ b/include/linux/lockref.h
@@ -37,12 +37,13 @@ struct lockref {
/**
* lockref_init - Initialize a lockref
* @lockref: pointer to lockref structure
- * @count: initial count
+ *
+ * Initializes @lockref->count to 1.
*/
-static inline void lockref_init(struct lockref *lockref, unsigned int count)
+static inline void lockref_init(struct lockref *lockref)
{
spin_lock_init(&lockref->lock);
- lockref->count = count;
+ lockref->count = 1;
}
void lockref_get(struct lockref *lockref);
--
2.48.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/3] further lockref cleanups
2025-01-30 13:56 [PATCH v2 0/3] further lockref cleanups Andreas Gruenbacher
` (2 preceding siblings ...)
2025-01-30 13:56 ` [PATCH v2 3/3] lockref: remove count argument of lockref_init Andreas Gruenbacher
@ 2025-01-30 15:05 ` Christian Brauner
3 siblings, 0 replies; 5+ messages in thread
From: Christian Brauner @ 2025-01-30 15:05 UTC (permalink / raw)
To: Andreas Gruenbacher
Cc: Christian Brauner, Christoph Hellwig, gfs2, linux-fsdevel, linux-kernel
On Thu, 30 Jan 2025 14:56:20 +0100, Andreas Gruenbacher wrote:
> Here's an updated version with:
>
> * An additional comment saying that lockref_init() initializes
> count to 1.
>
> * Reviewed-by tags from Christoph.
>
> [...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes
[1/3] gfs2: use lockref_init for gl_lockref
https://git.kernel.org/vfs/vfs/c/6c789b8e0913
[2/3] gfs2: switch to lockref_init(..., 1)
https://git.kernel.org/vfs/vfs/c/69469b7ad4a4
[3/3] lockref: remove count argument of lockref_init
https://git.kernel.org/vfs/vfs/c/24239add174c
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-01-30 15:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-30 13:56 [PATCH v2 0/3] further lockref cleanups Andreas Gruenbacher
2025-01-30 13:56 ` [PATCH v2 1/3] gfs2: use lockref_init for gl_lockref Andreas Gruenbacher
2025-01-30 13:56 ` [PATCH v2 2/3] gfs2: switch to lockref_init(..., 1) Andreas Gruenbacher
2025-01-30 13:56 ` [PATCH v2 3/3] lockref: remove count argument of lockref_init Andreas Gruenbacher
2025-01-30 15:05 ` [PATCH v2 0/3] further lockref cleanups Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®