Skip to content

Commit 5cb81da

Browse files
Dmitry Monakhovtytso
authored andcommitted
ext4: fix quota accounting during migration
The tmp_inode should have same uid/gid as the original inode. Otherwise new metadata blocks will be accounted to wrong quota-id, which will result in a quota leak after the inode migration is completed. Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent fba90ff commit 5cb81da

4 files changed

Lines changed: 17 additions & 10 deletions

File tree

‎fs/ext4/ext4.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,8 @@ extern int ext4fs_dirhash(const char *name, int len, struct
18111811

18121812
/* ialloc.c */
18131813
extern struct inode *ext4_new_inode(handle_t *, struct inode *, int,
1814-
const struct qstr *qstr, __u32 goal);
1814+
const struct qstr *qstr, __u32 goal,
1815+
uid_t *owner);
18151816
extern void ext4_free_inode(handle_t *, struct inode *);
18161817
extern struct inode * ext4_orphan_get(struct super_block *, unsigned long);
18171818
extern unsigned long ext4_count_free_inodes(struct super_block *);

‎fs/ext4/ialloc.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ static int ext4_claim_inode(struct super_block *sb,
691691
* group to find a free inode.
692692
*/
693693
struct inode *ext4_new_inode(handle_t *handle, struct inode *dir, int mode,
694-
const struct qstr *qstr, __u32 goal)
694+
const struct qstr *qstr, __u32 goal, uid_t *owner)
695695
{
696696
struct super_block *sb;
697697
struct buffer_head *inode_bitmap_bh = NULL;
@@ -852,8 +852,11 @@ struct inode *ext4_new_inode(handle_t *handle, struct inode *dir, int mode,
852852
flex_group = ext4_flex_group(sbi, group);
853853
atomic_dec(&sbi->s_flex_groups[flex_group].free_inodes);
854854
}
855-
856-
if (test_opt(sb, GRPID)) {
855+
if (owner) {
856+
inode->i_mode = mode;
857+
inode->i_uid = owner[0];
858+
inode->i_gid = owner[1];
859+
} else if (test_opt(sb, GRPID)) {
857860
inode->i_mode = mode;
858861
inode->i_uid = current_fsuid();
859862
inode->i_gid = dir->i_gid;

‎fs/ext4/migrate.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ int ext4_ext_migrate(struct inode *inode)
439439
struct migrate_struct lb;
440440
unsigned long max_entries;
441441
__u32 goal;
442+
uid_t owner[2];
442443

443444
/*
444445
* If the filesystem does not support extents, or the inode
@@ -466,10 +467,12 @@ int ext4_ext_migrate(struct inode *inode)
466467
}
467468
goal = (((inode->i_ino - 1) / EXT4_INODES_PER_GROUP(inode->i_sb)) *
468469
EXT4_INODES_PER_GROUP(inode->i_sb)) + 1;
470+
owner[0] = inode->i_uid;
471+
owner[1] = inode->i_gid;
469472
tmp_inode = ext4_new_inode(handle, inode->i_sb->s_root->d_inode,
470-
S_IFREG, NULL, goal);
473+
S_IFREG, NULL, goal, owner);
471474
if (IS_ERR(tmp_inode)) {
472-
retval = -ENOMEM;
475+
retval = PTR_ERR(inode);
473476
ext4_journal_stop(handle);
474477
return retval;
475478
}

‎fs/ext4/namei.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,7 @@ static int ext4_create(struct inode *dir, struct dentry *dentry, int mode,
17541754
if (IS_DIRSYNC(dir))
17551755
ext4_handle_sync(handle);
17561756

1757-
inode = ext4_new_inode(handle, dir, mode, &dentry->d_name, 0);
1757+
inode = ext4_new_inode(handle, dir, mode, &dentry->d_name, 0, NULL);
17581758
err = PTR_ERR(inode);
17591759
if (!IS_ERR(inode)) {
17601760
inode->i_op = &ext4_file_inode_operations;
@@ -1790,7 +1790,7 @@ static int ext4_mknod(struct inode *dir, struct dentry *dentry,
17901790
if (IS_DIRSYNC(dir))
17911791
ext4_handle_sync(handle);
17921792

1793-
inode = ext4_new_inode(handle, dir, mode, &dentry->d_name, 0);
1793+
inode = ext4_new_inode(handle, dir, mode, &dentry->d_name, 0, NULL);
17941794
err = PTR_ERR(inode);
17951795
if (!IS_ERR(inode)) {
17961796
init_special_inode(inode, inode->i_mode, rdev);
@@ -1830,7 +1830,7 @@ static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
18301830
ext4_handle_sync(handle);
18311831

18321832
inode = ext4_new_inode(handle, dir, S_IFDIR | mode,
1833-
&dentry->d_name, 0);
1833+
&dentry->d_name, 0, NULL);
18341834
err = PTR_ERR(inode);
18351835
if (IS_ERR(inode))
18361836
goto out_stop;
@@ -2277,7 +2277,7 @@ static int ext4_symlink(struct inode *dir,
22772277
ext4_handle_sync(handle);
22782278

22792279
inode = ext4_new_inode(handle, dir, S_IFLNK|S_IRWXUGO,
2280-
&dentry->d_name, 0);
2280+
&dentry->d_name, 0, NULL);
22812281
err = PTR_ERR(inode);
22822282
if (IS_ERR(inode))
22832283
goto out_stop;

0 commit comments

Comments
 (0)