Skip to content

Commit 2a5f69a

Browse files
author
CKI KWF Bot
committed
Merge: gfs2: Add proper lockspace locking
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7391 JIRA: https://issues.redhat.com/browse/RHEL-116886 GFS2 has been calling functions like dlm_lock() even after the lockspace that these functions operate on has been released with dlm_release_lockspace(). It has always assumed that those functions would return -EINVAL in that case, but that was never guaranteed, and it certainly is no longer the case since commit 4db41bf ("dlm: remove ls_local_handle from struct dlm_ls"). To fix that, add proper lockspace locking. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Approved-by: Andrew Price <anprice@redhat.com> Approved-by: Paul Evans <pevans@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Approved-by: Abhi Das <adas@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
2 parents 31778b1 + a6f05c7 commit 2a5f69a

File tree

23 files changed

+440
-368
lines changed

23 files changed

+440
-368
lines changed

fs/gfs2/aops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ static int gfs2_read_folio(struct file *file, struct folio *folio)
465465
error = mpage_read_folio(folio, gfs2_block_map);
466466
}
467467

468-
if (unlikely(gfs2_withdrawn(sdp)))
468+
if (gfs2_withdrawing_or_withdrawn(sdp))
469469
return -EIO;
470470

471471
return error;

fs/gfs2/bmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ static int punch_hole(struct gfs2_inode *ip, u64 offset, u64 length)
18211821
gfs2_assert_withdraw(sdp, bh);
18221822
if (gfs2_assert_withdraw(sdp,
18231823
prev_bnr != bh->b_blocknr)) {
1824-
fs_emerg(sdp, "inode %llu, block:%llu, i_h:%u,"
1824+
fs_emerg(sdp, "inode %llu, block:%llu, i_h:%u, "
18251825
"s_h:%u, mp_h:%u\n",
18261826
(unsigned long long)ip->i_no_addr,
18271827
prev_bnr, ip->i_height, strip_h, mp_h);

fs/gfs2/file.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,7 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)
14161416
struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
14171417
struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host);
14181418
struct lm_lockstruct *ls = &sdp->sd_lockstruct;
1419+
int ret;
14191420

14201421
if (!(fl->fl_flags & FL_POSIX))
14211422
return -ENOLCK;
@@ -1424,17 +1425,23 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)
14241425
cmd = F_SETLK;
14251426
fl->fl_type = F_UNLCK;
14261427
}
1427-
if (unlikely(gfs2_withdrawn(sdp))) {
1428+
if (gfs2_withdrawing_or_withdrawn(sdp)) {
14281429
if (fl->fl_type == F_UNLCK)
14291430
locks_lock_file_wait(file, fl);
14301431
return -EIO;
14311432
}
1432-
if (IS_GETLK(cmd))
1433-
return dlm_posix_get(ls->ls_dlm, ip->i_no_addr, file, fl);
1434-
else if (fl->fl_type == F_UNLCK)
1435-
return dlm_posix_unlock(ls->ls_dlm, ip->i_no_addr, file, fl);
1436-
else
1437-
return dlm_posix_lock(ls->ls_dlm, ip->i_no_addr, file, cmd, fl);
1433+
down_read(&ls->ls_sem);
1434+
ret = -ENODEV;
1435+
if (likely(ls->ls_dlm != NULL)) {
1436+
if (IS_GETLK(cmd))
1437+
ret = dlm_posix_get(ls->ls_dlm, ip->i_no_addr, file, fl);
1438+
else if (fl->fl_type == F_UNLCK)
1439+
ret = dlm_posix_unlock(ls->ls_dlm, ip->i_no_addr, file, fl);
1440+
else
1441+
ret = dlm_posix_lock(ls->ls_dlm, ip->i_no_addr, file, cmd, fl);
1442+
}
1443+
up_read(&ls->ls_sem);
1444+
return ret;
14381445
}
14391446

14401447
static void __flock_holder_uninit(struct file *file, struct gfs2_holder *fl_gh)

0 commit comments

Comments
 (0)