Skip to content

Commit 4c5c301

Browse files
author
Andreas Gruenbacher
committed
gfs2: Pass glock holder to gfs2_file_direct_{read,write}
Pass a pointer to the existing glock holder from gfs2_file_{read,write}_iter to gfs2_file_direct_{read,write} to save some stack space. Suggested-by: Matthew Wilcox <[email protected]> Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent 5deaf1f commit 4c5c301

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

fs/gfs2/file.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -781,39 +781,39 @@ static int gfs2_fsync(struct file *file, loff_t start, loff_t end,
781781
return ret ? ret : ret1;
782782
}
783783

784-
static ssize_t gfs2_file_direct_read(struct kiocb *iocb, struct iov_iter *to)
784+
static ssize_t gfs2_file_direct_read(struct kiocb *iocb, struct iov_iter *to,
785+
struct gfs2_holder *gh)
785786
{
786787
struct file *file = iocb->ki_filp;
787788
struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
788789
size_t count = iov_iter_count(to);
789-
struct gfs2_holder gh;
790790
ssize_t ret;
791791

792792
if (!count)
793793
return 0; /* skip atime */
794794

795-
gfs2_holder_init(ip->i_gl, LM_ST_DEFERRED, 0, &gh);
796-
ret = gfs2_glock_nq(&gh);
795+
gfs2_holder_init(ip->i_gl, LM_ST_DEFERRED, 0, gh);
796+
ret = gfs2_glock_nq(gh);
797797
if (ret)
798798
goto out_uninit;
799799

800800
ret = iomap_dio_rw(iocb, to, &gfs2_iomap_ops, NULL,
801801
is_sync_kiocb(iocb));
802802

803-
gfs2_glock_dq(&gh);
803+
gfs2_glock_dq(gh);
804804
out_uninit:
805-
gfs2_holder_uninit(&gh);
805+
gfs2_holder_uninit(gh);
806806
return ret;
807807
}
808808

809-
static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from)
809+
static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from,
810+
struct gfs2_holder *gh)
810811
{
811812
struct file *file = iocb->ki_filp;
812813
struct inode *inode = file->f_mapping->host;
813814
struct gfs2_inode *ip = GFS2_I(inode);
814815
size_t len = iov_iter_count(from);
815816
loff_t offset = iocb->ki_pos;
816-
struct gfs2_holder gh;
817817
ssize_t ret;
818818

819819
/*
@@ -824,8 +824,8 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from)
824824
* unfortunately, have the option of only flushing a range like the
825825
* VFS does.
826826
*/
827-
gfs2_holder_init(ip->i_gl, LM_ST_DEFERRED, 0, &gh);
828-
ret = gfs2_glock_nq(&gh);
827+
gfs2_holder_init(ip->i_gl, LM_ST_DEFERRED, 0, gh);
828+
ret = gfs2_glock_nq(gh);
829829
if (ret)
830830
goto out_uninit;
831831

@@ -837,9 +837,9 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from)
837837
is_sync_kiocb(iocb));
838838

839839
out:
840-
gfs2_glock_dq(&gh);
840+
gfs2_glock_dq(gh);
841841
out_uninit:
842-
gfs2_holder_uninit(&gh);
842+
gfs2_holder_uninit(gh);
843843
return ret;
844844
}
845845

@@ -851,7 +851,7 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
851851
ssize_t ret;
852852

853853
if (iocb->ki_flags & IOCB_DIRECT) {
854-
ret = gfs2_file_direct_read(iocb, to);
854+
ret = gfs2_file_direct_read(iocb, to, &gh);
855855
if (likely(ret != -ENOTBLK))
856856
return ret;
857857
iocb->ki_flags &= ~IOCB_DIRECT;
@@ -900,13 +900,12 @@ static ssize_t gfs2_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
900900
struct file *file = iocb->ki_filp;
901901
struct inode *inode = file_inode(file);
902902
struct gfs2_inode *ip = GFS2_I(inode);
903+
struct gfs2_holder gh;
903904
ssize_t ret;
904905

905906
gfs2_size_hint(file, iocb->ki_pos, iov_iter_count(from));
906907

907908
if (iocb->ki_flags & IOCB_APPEND) {
908-
struct gfs2_holder gh;
909-
910909
ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
911910
if (ret)
912911
return ret;
@@ -930,7 +929,7 @@ static ssize_t gfs2_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
930929
struct address_space *mapping = file->f_mapping;
931930
ssize_t buffered, ret2;
932931

933-
ret = gfs2_file_direct_write(iocb, from);
932+
ret = gfs2_file_direct_write(iocb, from, &gh);
934933
if (ret < 0 || !iov_iter_count(from))
935934
goto out_unlock;
936935

0 commit comments

Comments
 (0)