Skip to content

Commit 5fcff61

Browse files
AstralBobAndreas Gruenbacher
authored andcommitted
gfs2: use i_lock spin_lock for inode qadata
Before this patch, functions gfs2_qa_get and _put used the i_rw_mutex to prevent simultaneous access to its i_qadata. But i_rw_mutex is now used for many other things, including iomap_begin and end, which causes a conflict according to lockdep. We cannot just remove the lock since simultaneous opens (gfs2_open -> gfs2_open_common -> gfs2_qa_get) can then stomp on each others values for i_qadata. This patch solves the conflict by using the i_lock spin_lock in the inode to prevent simultaneous access. Signed-off-by: Bob Peterson <[email protected]> Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent f4a4756 commit 5fcff61

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

fs/gfs2/quota.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -528,34 +528,42 @@ static void qdsb_put(struct gfs2_quota_data *qd)
528528
*/
529529
int gfs2_qa_get(struct gfs2_inode *ip)
530530
{
531-
int error = 0;
532531
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
532+
struct inode *inode = &ip->i_inode;
533533

534534
if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF)
535535
return 0;
536536

537-
down_write(&ip->i_rw_mutex);
537+
spin_lock(&inode->i_lock);
538538
if (ip->i_qadata == NULL) {
539-
ip->i_qadata = kmem_cache_zalloc(gfs2_qadata_cachep, GFP_NOFS);
540-
if (!ip->i_qadata) {
541-
error = -ENOMEM;
542-
goto out;
543-
}
539+
struct gfs2_qadata *tmp;
540+
541+
spin_unlock(&inode->i_lock);
542+
tmp = kmem_cache_zalloc(gfs2_qadata_cachep, GFP_NOFS);
543+
if (!tmp)
544+
return -ENOMEM;
545+
546+
spin_lock(&inode->i_lock);
547+
if (ip->i_qadata == NULL)
548+
ip->i_qadata = tmp;
549+
else
550+
kmem_cache_free(gfs2_qadata_cachep, tmp);
544551
}
545552
ip->i_qadata->qa_ref++;
546-
out:
547-
up_write(&ip->i_rw_mutex);
548-
return error;
553+
spin_unlock(&inode->i_lock);
554+
return 0;
549555
}
550556

551557
void gfs2_qa_put(struct gfs2_inode *ip)
552558
{
553-
down_write(&ip->i_rw_mutex);
559+
struct inode *inode = &ip->i_inode;
560+
561+
spin_lock(&inode->i_lock);
554562
if (ip->i_qadata && --ip->i_qadata->qa_ref == 0) {
555563
kmem_cache_free(gfs2_qadata_cachep, ip->i_qadata);
556564
ip->i_qadata = NULL;
557565
}
558-
up_write(&ip->i_rw_mutex);
566+
spin_unlock(&inode->i_lock);
559567
}
560568

561569
int gfs2_quota_hold(struct gfs2_inode *ip, kuid_t uid, kgid_t gid)

0 commit comments

Comments
 (0)