Skip to content

Commit 80dcc31

Browse files
committed
Merge tag 'gfs2-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2
Pull GFS2 updates from Bob Peterson: "Here is a list of patches we've accumulated for GFS2 for the current upstream merge window. Most of the patches fix GFS2 quotas, which were not properly enforced. There's another that adds me as a GFS2 co-maintainer, and a couple patches that fix a kernel panic doing splice_write on GFS2 as well as a few correctness patches" * tag 'gfs2-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2: gfs2: fix quota refresh race in do_glock() gfs2: incorrect check for debugfs returns gfs2: allow fallocate to max out quotas/fs efficiently gfs2: allow quota_check and inplace_reserve to return available blocks gfs2: perform quota checks against allocation parameters GFS2: Move gfs2_file_splice_write outside of #ifdef GFS2: Allocate reservation during splice_write GFS2: gfs2_set_acl(): Cache "no acl" as well Add myself (Bob Peterson) as a maintainer of GFS2
2 parents 78d5dcd + 3013317 commit 80dcc31

13 files changed

Lines changed: 186 additions & 97 deletions

File tree

‎MAINTAINERS‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4337,10 +4337,10 @@ F: scripts/get_maintainer.pl
43374337

43384338
GFS2 FILE SYSTEM
43394339
M: Steven Whitehouse <swhiteho@redhat.com>
4340+
M: Bob Peterson <rpeterso@redhat.com>
43404341
L: cluster-devel@redhat.com
43414342
W: http://sources.redhat.com/cluster/
4342-
T: git git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-fixes.git
4343-
T: git git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-nmw.git
4343+
T: git git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2.git
43444344
S: Supported
43454345
F: Documentation/filesystems/gfs2*.txt
43464346
F: fs/gfs2/

‎fs/gfs2/acl.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@ int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
110110
error = __gfs2_xattr_set(inode, name, data, len, 0, GFS2_EATYPE_SYS);
111111
if (error)
112112
goto out;
113-
114-
if (acl)
115-
set_cached_acl(inode, type, acl);
116-
else
117-
forget_cached_acl(inode, type);
113+
set_cached_acl(inode, type, acl);
118114
out:
119115
kfree(data);
120116
return error;

‎fs/gfs2/aops.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,12 +671,12 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
671671

672672
if (alloc_required) {
673673
struct gfs2_alloc_parms ap = { .aflags = 0, };
674-
error = gfs2_quota_lock_check(ip);
674+
requested = data_blocks + ind_blocks;
675+
ap.target = requested;
676+
error = gfs2_quota_lock_check(ip, &ap);
675677
if (error)
676678
goto out_unlock;
677679

678-
requested = data_blocks + ind_blocks;
679-
ap.target = requested;
680680
error = gfs2_inplace_reserve(ip, &ap);
681681
if (error)
682682
goto out_qunlock;

‎fs/gfs2/bmap.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ static int do_grow(struct inode *inode, u64 size)
12241224

12251225
if (gfs2_is_stuffed(ip) &&
12261226
(size > (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)))) {
1227-
error = gfs2_quota_lock_check(ip);
1227+
error = gfs2_quota_lock_check(ip, &ap);
12281228
if (error)
12291229
return error;
12301230

‎fs/gfs2/file.c‎

Lines changed: 71 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,11 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
428428
if (ret)
429429
goto out_unlock;
430430

431-
ret = gfs2_quota_lock_check(ip);
432-
if (ret)
433-
goto out_unlock;
434431
gfs2_write_calc_reserv(ip, PAGE_CACHE_SIZE, &data_blocks, &ind_blocks);
435432
ap.target = data_blocks + ind_blocks;
433+
ret = gfs2_quota_lock_check(ip, &ap);
434+
if (ret)
435+
goto out_unlock;
436436
ret = gfs2_inplace_reserve(ip, &ap);
437437
if (ret)
438438
goto out_quota_unlock;
@@ -764,22 +764,30 @@ static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len,
764764
brelse(dibh);
765765
return error;
766766
}
767-
768-
static void calc_max_reserv(struct gfs2_inode *ip, loff_t max, loff_t *len,
769-
unsigned int *data_blocks, unsigned int *ind_blocks)
767+
/**
768+
* calc_max_reserv() - Reverse of write_calc_reserv. Given a number of
769+
* blocks, determine how many bytes can be written.
770+
* @ip: The inode in question.
771+
* @len: Max cap of bytes. What we return in *len must be <= this.
772+
* @data_blocks: Compute and return the number of data blocks needed
773+
* @ind_blocks: Compute and return the number of indirect blocks needed
774+
* @max_blocks: The total blocks available to work with.
775+
*
776+
* Returns: void, but @len, @data_blocks and @ind_blocks are filled in.
777+
*/
778+
static void calc_max_reserv(struct gfs2_inode *ip, loff_t *len,
779+
unsigned int *data_blocks, unsigned int *ind_blocks,
780+
unsigned int max_blocks)
770781
{
782+
loff_t max = *len;
771783
const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
772-
unsigned int max_blocks = ip->i_rgd->rd_free_clone;
773784
unsigned int tmp, max_data = max_blocks - 3 * (sdp->sd_max_height - 1);
774785

775786
for (tmp = max_data; tmp > sdp->sd_diptrs;) {
776787
tmp = DIV_ROUND_UP(tmp, sdp->sd_inptrs);
777788
max_data -= tmp;
778789
}
779-
/* This calculation isn't the exact reverse of gfs2_write_calc_reserve,
780-
so it might end up with fewer data blocks */
781-
if (max_data <= *data_blocks)
782-
return;
790+
783791
*data_blocks = max_data;
784792
*ind_blocks = max_blocks - max_data;
785793
*len = ((loff_t)max_data - 3) << sdp->sd_sb.sb_bsize_shift;
@@ -796,7 +804,7 @@ static long __gfs2_fallocate(struct file *file, int mode, loff_t offset, loff_t
796804
struct gfs2_inode *ip = GFS2_I(inode);
797805
struct gfs2_alloc_parms ap = { .aflags = 0, };
798806
unsigned int data_blocks = 0, ind_blocks = 0, rblocks;
799-
loff_t bytes, max_bytes;
807+
loff_t bytes, max_bytes, max_blks = UINT_MAX;
800808
int error;
801809
const loff_t pos = offset;
802810
const loff_t count = len;
@@ -818,6 +826,9 @@ static long __gfs2_fallocate(struct file *file, int mode, loff_t offset, loff_t
818826

819827
gfs2_size_hint(file, offset, len);
820828

829+
gfs2_write_calc_reserv(ip, PAGE_SIZE, &data_blocks, &ind_blocks);
830+
ap.min_target = data_blocks + ind_blocks;
831+
821832
while (len > 0) {
822833
if (len < bytes)
823834
bytes = len;
@@ -826,27 +837,41 @@ static long __gfs2_fallocate(struct file *file, int mode, loff_t offset, loff_t
826837
offset += bytes;
827838
continue;
828839
}
829-
error = gfs2_quota_lock_check(ip);
840+
841+
/* We need to determine how many bytes we can actually
842+
* fallocate without exceeding quota or going over the
843+
* end of the fs. We start off optimistically by assuming
844+
* we can write max_bytes */
845+
max_bytes = (len > max_chunk_size) ? max_chunk_size : len;
846+
847+
/* Since max_bytes is most likely a theoretical max, we
848+
* calculate a more realistic 'bytes' to serve as a good
849+
* starting point for the number of bytes we may be able
850+
* to write */
851+
gfs2_write_calc_reserv(ip, bytes, &data_blocks, &ind_blocks);
852+
ap.target = data_blocks + ind_blocks;
853+
854+
error = gfs2_quota_lock_check(ip, &ap);
830855
if (error)
831856
return error;
832-
retry:
833-
gfs2_write_calc_reserv(ip, bytes, &data_blocks, &ind_blocks);
857+
/* ap.allowed tells us how many blocks quota will allow
858+
* us to write. Check if this reduces max_blks */
859+
if (ap.allowed && ap.allowed < max_blks)
860+
max_blks = ap.allowed;
834861

835-
ap.target = data_blocks + ind_blocks;
836862
error = gfs2_inplace_reserve(ip, &ap);
837-
if (error) {
838-
if (error == -ENOSPC && bytes > sdp->sd_sb.sb_bsize) {
839-
bytes >>= 1;
840-
bytes &= bsize_mask;
841-
if (bytes == 0)
842-
bytes = sdp->sd_sb.sb_bsize;
843-
goto retry;
844-
}
863+
if (error)
845864
goto out_qunlock;
846-
}
847-
max_bytes = bytes;
848-
calc_max_reserv(ip, (len > max_chunk_size)? max_chunk_size: len,
849-
&max_bytes, &data_blocks, &ind_blocks);
865+
866+
/* check if the selected rgrp limits our max_blks further */
867+
if (ap.allowed && ap.allowed < max_blks)
868+
max_blks = ap.allowed;
869+
870+
/* Almost done. Calculate bytes that can be written using
871+
* max_blks. We also recompute max_bytes, data_blocks and
872+
* ind_blocks */
873+
calc_max_reserv(ip, &max_bytes, &data_blocks,
874+
&ind_blocks, max_blks);
850875

851876
rblocks = RES_DINODE + ind_blocks + RES_STATFS + RES_QUOTA +
852877
RES_RG_HDR + gfs2_rg_blocks(ip, data_blocks + ind_blocks);
@@ -930,6 +955,22 @@ static long gfs2_fallocate(struct file *file, int mode, loff_t offset, loff_t le
930955
return ret;
931956
}
932957

958+
static ssize_t gfs2_file_splice_write(struct pipe_inode_info *pipe,
959+
struct file *out, loff_t *ppos,
960+
size_t len, unsigned int flags)
961+
{
962+
int error;
963+
struct gfs2_inode *ip = GFS2_I(out->f_mapping->host);
964+
965+
error = gfs2_rs_alloc(ip);
966+
if (error)
967+
return (ssize_t)error;
968+
969+
gfs2_size_hint(out, *ppos, len);
970+
971+
return iter_file_splice_write(pipe, out, ppos, len, flags);
972+
}
973+
933974
#ifdef CONFIG_GFS2_FS_LOCKING_DLM
934975

935976
/**
@@ -1076,7 +1117,7 @@ const struct file_operations gfs2_file_fops = {
10761117
.lock = gfs2_lock,
10771118
.flock = gfs2_flock,
10781119
.splice_read = generic_file_splice_read,
1079-
.splice_write = iter_file_splice_write,
1120+
.splice_write = gfs2_file_splice_write,
10801121
.setlease = simple_nosetlease,
10811122
.fallocate = gfs2_fallocate,
10821123
};
@@ -1106,7 +1147,7 @@ const struct file_operations gfs2_file_fops_nolock = {
11061147
.release = gfs2_release,
11071148
.fsync = gfs2_fsync,
11081149
.splice_read = generic_file_splice_read,
1109-
.splice_write = iter_file_splice_write,
1150+
.splice_write = gfs2_file_splice_write,
11101151
.setlease = generic_setlease,
11111152
.fallocate = gfs2_fallocate,
11121153
};

‎fs/gfs2/glock.c‎

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,34 +2047,41 @@ static const struct file_operations gfs2_sbstats_fops = {
20472047

20482048
int gfs2_create_debugfs_file(struct gfs2_sbd *sdp)
20492049
{
2050-
sdp->debugfs_dir = debugfs_create_dir(sdp->sd_table_name, gfs2_root);
2051-
if (!sdp->debugfs_dir)
2052-
return -ENOMEM;
2053-
sdp->debugfs_dentry_glocks = debugfs_create_file("glocks",
2054-
S_IFREG | S_IRUGO,
2055-
sdp->debugfs_dir, sdp,
2056-
&gfs2_glocks_fops);
2057-
if (!sdp->debugfs_dentry_glocks)
2050+
struct dentry *dent;
2051+
2052+
dent = debugfs_create_dir(sdp->sd_table_name, gfs2_root);
2053+
if (IS_ERR_OR_NULL(dent))
2054+
goto fail;
2055+
sdp->debugfs_dir = dent;
2056+
2057+
dent = debugfs_create_file("glocks",
2058+
S_IFREG | S_IRUGO,
2059+
sdp->debugfs_dir, sdp,
2060+
&gfs2_glocks_fops);
2061+
if (IS_ERR_OR_NULL(dent))
20582062
goto fail;
2063+
sdp->debugfs_dentry_glocks = dent;
20592064

2060-
sdp->debugfs_dentry_glstats = debugfs_create_file("glstats",
2061-
S_IFREG | S_IRUGO,
2062-
sdp->debugfs_dir, sdp,
2063-
&gfs2_glstats_fops);
2064-
if (!sdp->debugfs_dentry_glstats)
2065+
dent = debugfs_create_file("glstats",
2066+
S_IFREG | S_IRUGO,
2067+
sdp->debugfs_dir, sdp,
2068+
&gfs2_glstats_fops);
2069+
if (IS_ERR_OR_NULL(dent))
20652070
goto fail;
2071+
sdp->debugfs_dentry_glstats = dent;
20662072

2067-
sdp->debugfs_dentry_sbstats = debugfs_create_file("sbstats",
2068-
S_IFREG | S_IRUGO,
2069-
sdp->debugfs_dir, sdp,
2070-
&gfs2_sbstats_fops);
2071-
if (!sdp->debugfs_dentry_sbstats)
2073+
dent = debugfs_create_file("sbstats",
2074+
S_IFREG | S_IRUGO,
2075+
sdp->debugfs_dir, sdp,
2076+
&gfs2_sbstats_fops);
2077+
if (IS_ERR_OR_NULL(dent))
20722078
goto fail;
2079+
sdp->debugfs_dentry_sbstats = dent;
20732080

20742081
return 0;
20752082
fail:
20762083
gfs2_delete_debugfs_file(sdp);
2077-
return -ENOMEM;
2084+
return dent ? PTR_ERR(dent) : -ENOMEM;
20782085
}
20792086

20802087
void gfs2_delete_debugfs_file(struct gfs2_sbd *sdp)
@@ -2100,6 +2107,8 @@ void gfs2_delete_debugfs_file(struct gfs2_sbd *sdp)
21002107
int gfs2_register_debugfs(void)
21012108
{
21022109
gfs2_root = debugfs_create_dir("gfs2", NULL);
2110+
if (IS_ERR(gfs2_root))
2111+
return PTR_ERR(gfs2_root);
21032112
return gfs2_root ? 0 : -ENOMEM;
21042113
}
21052114

‎fs/gfs2/incore.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,10 @@ struct gfs2_blkreserv {
301301
* to the allocation code.
302302
*/
303303
struct gfs2_alloc_parms {
304-
u32 target;
304+
u64 target;
305+
u32 min_target;
305306
u32 aflags;
307+
u64 allowed;
306308
};
307309

308310
enum {

‎fs/gfs2/inode.c‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ static int alloc_dinode(struct gfs2_inode *ip, u32 flags, unsigned *dblocks)
382382
struct gfs2_alloc_parms ap = { .target = *dblocks, .aflags = flags, };
383383
int error;
384384

385-
error = gfs2_quota_lock_check(ip);
385+
error = gfs2_quota_lock_check(ip, &ap);
386386
if (error)
387387
goto out;
388388

@@ -525,7 +525,7 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
525525
int error;
526526

527527
if (da->nr_blocks) {
528-
error = gfs2_quota_lock_check(dip);
528+
error = gfs2_quota_lock_check(dip, &ap);
529529
if (error)
530530
goto fail_quota_locks;
531531

@@ -953,7 +953,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
953953

954954
if (da.nr_blocks) {
955955
struct gfs2_alloc_parms ap = { .target = da.nr_blocks, };
956-
error = gfs2_quota_lock_check(dip);
956+
error = gfs2_quota_lock_check(dip, &ap);
957957
if (error)
958958
goto out_gunlock;
959959

@@ -1470,7 +1470,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
14701470

14711471
if (da.nr_blocks) {
14721472
struct gfs2_alloc_parms ap = { .target = da.nr_blocks, };
1473-
error = gfs2_quota_lock_check(ndip);
1473+
error = gfs2_quota_lock_check(ndip, &ap);
14741474
if (error)
14751475
goto out_gunlock;
14761476

@@ -1669,6 +1669,7 @@ static int setattr_chown(struct inode *inode, struct iattr *attr)
16691669
kuid_t ouid, nuid;
16701670
kgid_t ogid, ngid;
16711671
int error;
1672+
struct gfs2_alloc_parms ap;
16721673

16731674
ouid = inode->i_uid;
16741675
ogid = inode->i_gid;
@@ -1696,9 +1697,11 @@ static int setattr_chown(struct inode *inode, struct iattr *attr)
16961697
if (error)
16971698
goto out;
16981699

1700+
ap.target = gfs2_get_inode_blocks(&ip->i_inode);
1701+
16991702
if (!uid_eq(ouid, NO_UID_QUOTA_CHANGE) ||
17001703
!gid_eq(ogid, NO_GID_QUOTA_CHANGE)) {
1701-
error = gfs2_quota_check(ip, nuid, ngid);
1704+
error = gfs2_quota_check(ip, nuid, ngid, &ap);
17021705
if (error)
17031706
goto out_gunlock_q;
17041707
}
@@ -1713,9 +1716,8 @@ static int setattr_chown(struct inode *inode, struct iattr *attr)
17131716

17141717
if (!uid_eq(ouid, NO_UID_QUOTA_CHANGE) ||
17151718
!gid_eq(ogid, NO_GID_QUOTA_CHANGE)) {
1716-
u64 blocks = gfs2_get_inode_blocks(&ip->i_inode);
1717-
gfs2_quota_change(ip, -blocks, ouid, ogid);
1718-
gfs2_quota_change(ip, blocks, nuid, ngid);
1719+
gfs2_quota_change(ip, -ap.target, ouid, ogid);
1720+
gfs2_quota_change(ip, ap.target, nuid, ngid);
17191721
}
17201722

17211723
out_end_trans:

0 commit comments

Comments
 (0)