Skip to content

Commit b8cb5a5

Browse files
Tahsin Erdogantytso
authored andcommitted
ext4: fix quota charging for shared xattr blocks
ext4_xattr_block_set() calls dquot_alloc_block() to charge for an xattr block when new references are made. However if dquot_initialize() hasn't been called on an inode, request for charging is effectively ignored because ext4_inode_info->i_dquot is not initialized yet. Add dquot_initialize() to call paths that lead to ext4_xattr_block_set(). Signed-off-by: Tahsin Erdogan <tahsin@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Jan Kara <jack@suse.cz>
1 parent c41d342 commit b8cb5a5

5 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎fs/ext4/acl.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de>
55
*/
66

7+
#include <linux/quotaops.h>
78
#include "ext4_jbd2.h"
89
#include "ext4.h"
910
#include "xattr.h"
@@ -232,6 +233,9 @@ ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type)
232233
handle_t *handle;
233234
int error, retries = 0;
234235

236+
error = dquot_initialize(inode);
237+
if (error)
238+
return error;
235239
retry:
236240
handle = ext4_journal_start(inode, EXT4_HT_XATTR,
237241
ext4_jbd2_credits_xattr(inode));

‎fs/ext4/super.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,9 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,
11741174
return res;
11751175
}
11761176

1177+
res = dquot_initialize(inode);
1178+
if (res)
1179+
return res;
11771180
retry:
11781181
handle = ext4_journal_start(inode, EXT4_HT_MISC,
11791182
ext4_jbd2_credits_xattr(inode));

‎fs/ext4/xattr.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,8 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
888888
else {
889889
u32 ref;
890890

891+
WARN_ON_ONCE(dquot_initialize_needed(inode));
892+
891893
/* The old block is released after updating
892894
the inode. */
893895
error = dquot_alloc_block(inode,
@@ -954,6 +956,8 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
954956
/* We need to allocate a new block */
955957
ext4_fsblk_t goal, block;
956958

959+
WARN_ON_ONCE(dquot_initialize_needed(inode));
960+
957961
goal = ext4_group_first_block_no(sb,
958962
EXT4_I(inode)->i_block_group);
959963

@@ -1166,6 +1170,7 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
11661170
return -EINVAL;
11671171
if (strlen(name) > 255)
11681172
return -ERANGE;
1173+
11691174
ext4_write_lock_xattr(inode, &no_expand);
11701175

11711176
error = ext4_reserve_inode_write(handle, inode, &is.iloc);
@@ -1267,6 +1272,9 @@ ext4_xattr_set(struct inode *inode, int name_index, const char *name,
12671272
int error, retries = 0;
12681273
int credits = ext4_jbd2_credits_xattr(inode);
12691274

1275+
error = dquot_initialize(inode);
1276+
if (error)
1277+
return error;
12701278
retry:
12711279
handle = ext4_journal_start(inode, EXT4_HT_XATTR, credits);
12721280
if (IS_ERR(handle)) {

‎fs/quota/dquot.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,22 @@ int dquot_initialize(struct inode *inode)
15121512
}
15131513
EXPORT_SYMBOL(dquot_initialize);
15141514

1515+
bool dquot_initialize_needed(struct inode *inode)
1516+
{
1517+
struct dquot **dquots;
1518+
int i;
1519+
1520+
if (!dquot_active(inode))
1521+
return false;
1522+
1523+
dquots = i_dquot(inode);
1524+
for (i = 0; i < MAXQUOTAS; i++)
1525+
if (!dquots[i] && sb_has_quota_active(inode->i_sb, i))
1526+
return true;
1527+
return false;
1528+
}
1529+
EXPORT_SYMBOL(dquot_initialize_needed);
1530+
15151531
/*
15161532
* Release all quotas referenced by inode.
15171533
*

‎include/linux/quotaops.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void inode_sub_rsv_space(struct inode *inode, qsize_t number);
4444
void inode_reclaim_rsv_space(struct inode *inode, qsize_t number);
4545

4646
int dquot_initialize(struct inode *inode);
47+
bool dquot_initialize_needed(struct inode *inode);
4748
void dquot_drop(struct inode *inode);
4849
struct dquot *dqget(struct super_block *sb, struct kqid qid);
4950
static inline struct dquot *dqgrab(struct dquot *dquot)
@@ -207,6 +208,11 @@ static inline int dquot_initialize(struct inode *inode)
207208
return 0;
208209
}
209210

211+
static inline bool dquot_initialize_needed(struct inode *inode)
212+
{
213+
return false;
214+
}
215+
210216
static inline void dquot_drop(struct inode *inode)
211217
{
212218
}

0 commit comments

Comments
 (0)