Skip to content

Commit 8d89e06

Browse files
author
Andreas Gruenbacher
committed
gfs2: Get rid of some unnecessary quota locking
With the locking the previous patch has introduced for each struct gfs2_quota_data object, sd_quota_mutex has become largely irrelevant. By waiting on the buffer head instead of waiting on the mutex in get_bh(), it becomes completely irrelevant and can be removed. Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent d5563f4 commit 8d89e06

File tree

3 files changed

+27
-28
lines changed

3 files changed

+27
-28
lines changed

fs/gfs2/incore.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,6 @@ struct gfs2_sbd {
782782

783783
struct list_head sd_quota_list;
784784
atomic_t sd_quota_count;
785-
struct mutex sd_quota_mutex;
786785
struct mutex sd_quota_sync_mutex;
787786
wait_queue_head_t sd_quota_wait;
788787

fs/gfs2/ops_fstype.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
103103
init_completion(&sdp->sd_journal_ready);
104104

105105
INIT_LIST_HEAD(&sdp->sd_quota_list);
106-
mutex_init(&sdp->sd_quota_mutex);
107106
mutex_init(&sdp->sd_quota_sync_mutex);
108107
init_waitqueue_head(&sdp->sd_quota_wait);
109108
spin_lock_init(&sdp->sd_bitmap_lock);

fs/gfs2/quota.c

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -397,16 +397,17 @@ static int bh_get(struct gfs2_quota_data *qd)
397397
struct inode *inode = sdp->sd_qc_inode;
398398
struct gfs2_inode *ip = GFS2_I(inode);
399399
unsigned int block, offset;
400-
struct buffer_head *bh;
400+
struct buffer_head *bh = NULL;
401401
struct iomap iomap = { };
402402
int error;
403403

404-
mutex_lock(&sdp->sd_quota_mutex);
405-
406-
if (qd->qd_bh_count++) {
407-
mutex_unlock(&sdp->sd_quota_mutex);
404+
spin_lock(&qd->qd_lockref.lock);
405+
if (qd->qd_bh_count) {
406+
qd->qd_bh_count++;
407+
spin_unlock(&qd->qd_lockref.lock);
408408
return 0;
409409
}
410+
spin_unlock(&qd->qd_lockref.lock);
410411

411412
block = qd->qd_slot / sdp->sd_qc_per_block;
412413
offset = qd->qd_slot % sdp->sd_qc_per_block;
@@ -415,48 +416,50 @@ static int bh_get(struct gfs2_quota_data *qd)
415416
(loff_t)block << inode->i_blkbits,
416417
i_blocksize(inode), &iomap);
417418
if (error)
418-
goto fail;
419+
return error;
419420
error = -ENOENT;
420421
if (iomap.type != IOMAP_MAPPED)
421-
goto fail;
422+
return error;
422423

423424
error = gfs2_meta_read(ip->i_gl, iomap.addr >> inode->i_blkbits,
424425
DIO_WAIT, 0, &bh);
425426
if (error)
426-
goto fail;
427+
return error;
427428
error = -EIO;
428429
if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_QC))
429-
goto fail_brelse;
430-
431-
qd->qd_bh = bh;
432-
qd->qd_bh_qc = (struct gfs2_quota_change *)
433-
(bh->b_data + sizeof(struct gfs2_meta_header) +
434-
offset * sizeof(struct gfs2_quota_change));
435-
436-
mutex_unlock(&sdp->sd_quota_mutex);
430+
goto out;
437431

438-
return 0;
432+
spin_lock(&qd->qd_lockref.lock);
433+
if (qd->qd_bh == NULL) {
434+
qd->qd_bh = bh;
435+
qd->qd_bh_qc = (struct gfs2_quota_change *)
436+
(bh->b_data + sizeof(struct gfs2_meta_header) +
437+
offset * sizeof(struct gfs2_quota_change));
438+
bh = NULL;
439+
}
440+
qd->qd_bh_count++;
441+
spin_unlock(&qd->qd_lockref.lock);
442+
error = 0;
439443

440-
fail_brelse:
444+
out:
441445
brelse(bh);
442-
fail:
443-
qd->qd_bh_count--;
444-
mutex_unlock(&sdp->sd_quota_mutex);
445446
return error;
446447
}
447448

448449
static void bh_put(struct gfs2_quota_data *qd)
449450
{
450451
struct gfs2_sbd *sdp = qd->qd_sbd;
452+
struct buffer_head *bh = NULL;
451453

452-
mutex_lock(&sdp->sd_quota_mutex);
454+
spin_lock(&qd->qd_lockref.lock);
453455
gfs2_assert(sdp, qd->qd_bh_count);
454456
if (!--qd->qd_bh_count) {
455-
brelse(qd->qd_bh);
457+
bh = qd->qd_bh;
456458
qd->qd_bh = NULL;
457459
qd->qd_bh_qc = NULL;
458460
}
459-
mutex_unlock(&sdp->sd_quota_mutex);
461+
spin_unlock(&qd->qd_lockref.lock);
462+
brelse(bh);
460463
}
461464

462465
static bool qd_grab_sync(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd,
@@ -676,7 +679,6 @@ static void do_qc(struct gfs2_quota_data *qd, s64 change)
676679
bool needs_put = false;
677680
s64 x;
678681

679-
mutex_lock(&sdp->sd_quota_mutex);
680682
gfs2_trans_add_meta(ip->i_gl, qd->qd_bh);
681683

682684
/*
@@ -720,7 +722,6 @@ static void do_qc(struct gfs2_quota_data *qd, s64 change)
720722
}
721723
if (change < 0) /* Reset quiet flag if we freed some blocks */
722724
clear_bit(QDF_QMSG_QUIET, &qd->qd_flags);
723-
mutex_unlock(&sdp->sd_quota_mutex);
724725
}
725726

726727
static int gfs2_write_buf_to_page(struct gfs2_sbd *sdp, unsigned long index,

0 commit comments

Comments
 (0)