Skip to content

Commit 1b223f7

Browse files
author
Andreas Gruenbacher
committed
gfs2: Eliminate ip->i_gh
Now that gfs2_file_buffered_write is the only remaining user of ip->i_gh, we can move the glock holder to the stack (or rather, use the one we already have on the stack); there is no need for keeping the holder in the inode anymore. This is slightly complicated by the fact that we're using ip->i_gh for the statfs inode in gfs2_file_buffered_write as well. Writing to the statfs inode isn't very common, so allocate the statfs holder dynamically when needed. Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent b924bda commit 1b223f7

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

fs/gfs2/file.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -876,24 +876,33 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
876876
return written ? written : ret;
877877
}
878878

879-
static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, struct iov_iter *from)
879+
static ssize_t gfs2_file_buffered_write(struct kiocb *iocb,
880+
struct iov_iter *from,
881+
struct gfs2_holder *gh)
880882
{
881883
struct file *file = iocb->ki_filp;
882884
struct inode *inode = file_inode(file);
883885
struct gfs2_inode *ip = GFS2_I(inode);
884886
struct gfs2_sbd *sdp = GFS2_SB(inode);
887+
struct gfs2_holder *statfs_gh = NULL;
885888
ssize_t ret;
886889

887-
gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &ip->i_gh);
888-
ret = gfs2_glock_nq(&ip->i_gh);
890+
if (inode == sdp->sd_rindex) {
891+
statfs_gh = kmalloc(sizeof(*statfs_gh), GFP_NOFS);
892+
if (!statfs_gh)
893+
return -ENOMEM;
894+
}
895+
896+
gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, gh);
897+
ret = gfs2_glock_nq(gh);
889898
if (ret)
890899
goto out_uninit;
891900

892901
if (inode == sdp->sd_rindex) {
893902
struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
894903

895904
ret = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE,
896-
GL_NOCACHE, &m_ip->i_gh);
905+
GL_NOCACHE, statfs_gh);
897906
if (ret)
898907
goto out_unlock;
899908
}
@@ -904,16 +913,15 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, struct iov_iter *fro
904913
if (ret > 0)
905914
iocb->ki_pos += ret;
906915

907-
if (inode == sdp->sd_rindex) {
908-
struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
909-
910-
gfs2_glock_dq_uninit(&m_ip->i_gh);
911-
}
916+
if (inode == sdp->sd_rindex)
917+
gfs2_glock_dq_uninit(statfs_gh);
912918

913919
out_unlock:
914-
gfs2_glock_dq(&ip->i_gh);
920+
gfs2_glock_dq(gh);
915921
out_uninit:
916-
gfs2_holder_uninit(&ip->i_gh);
922+
gfs2_holder_uninit(gh);
923+
if (statfs_gh)
924+
kfree(statfs_gh);
917925
return ret;
918926
}
919927

@@ -968,7 +976,7 @@ static ssize_t gfs2_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
968976
goto out_unlock;
969977

970978
iocb->ki_flags |= IOCB_DSYNC;
971-
buffered = gfs2_file_buffered_write(iocb, from);
979+
buffered = gfs2_file_buffered_write(iocb, from, &gh);
972980
if (unlikely(buffered <= 0)) {
973981
if (!ret)
974982
ret = buffered;
@@ -989,7 +997,7 @@ static ssize_t gfs2_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
989997
if (!ret || ret2 > 0)
990998
ret += ret2;
991999
} else {
992-
ret = gfs2_file_buffered_write(iocb, from);
1000+
ret = gfs2_file_buffered_write(iocb, from, &gh);
9931001
if (likely(ret > 0))
9941002
ret = generic_write_sync(iocb, ret);
9951003
}

fs/gfs2/incore.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,8 @@ struct gfs2_inode {
387387
u64 i_generation;
388388
u64 i_eattr;
389389
unsigned long i_flags; /* GIF_... */
390-
struct gfs2_glock *i_gl; /* Move into i_gh? */
390+
struct gfs2_glock *i_gl;
391391
struct gfs2_holder i_iopen_gh;
392-
struct gfs2_holder i_gh; /* for prepare/commit_write only */
393392
struct gfs2_qadata *i_qadata; /* quota allocation data */
394393
struct gfs2_holder i_rgd_gh;
395394
struct gfs2_blkreserv i_res; /* rgrp multi-block reservation */

0 commit comments

Comments
 (0)