mirror of https://gitee.com/openkylin/linux.git
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>
This commit is contained in:
parent
fba90ffee8
commit
5cb81dabcc
|
@ -1811,7 +1811,8 @@ extern int ext4fs_dirhash(const char *name, int len, struct
|
||||||
|
|
||||||
/* ialloc.c */
|
/* ialloc.c */
|
||||||
extern struct inode *ext4_new_inode(handle_t *, struct inode *, int,
|
extern struct inode *ext4_new_inode(handle_t *, struct inode *, int,
|
||||||
const struct qstr *qstr, __u32 goal);
|
const struct qstr *qstr, __u32 goal,
|
||||||
|
uid_t *owner);
|
||||||
extern void ext4_free_inode(handle_t *, struct inode *);
|
extern void ext4_free_inode(handle_t *, struct inode *);
|
||||||
extern struct inode * ext4_orphan_get(struct super_block *, unsigned long);
|
extern struct inode * ext4_orphan_get(struct super_block *, unsigned long);
|
||||||
extern unsigned long ext4_count_free_inodes(struct super_block *);
|
extern unsigned long ext4_count_free_inodes(struct super_block *);
|
||||||
|
|
|
@ -691,7 +691,7 @@ static int ext4_claim_inode(struct super_block *sb,
|
||||||
* group to find a free inode.
|
* group to find a free inode.
|
||||||
*/
|
*/
|
||||||
struct inode *ext4_new_inode(handle_t *handle, struct inode *dir, int mode,
|
struct inode *ext4_new_inode(handle_t *handle, struct inode *dir, int mode,
|
||||||
const struct qstr *qstr, __u32 goal)
|
const struct qstr *qstr, __u32 goal, uid_t *owner)
|
||||||
{
|
{
|
||||||
struct super_block *sb;
|
struct super_block *sb;
|
||||||
struct buffer_head *inode_bitmap_bh = NULL;
|
struct buffer_head *inode_bitmap_bh = NULL;
|
||||||
|
@ -852,8 +852,11 @@ struct inode *ext4_new_inode(handle_t *handle, struct inode *dir, int mode,
|
||||||
flex_group = ext4_flex_group(sbi, group);
|
flex_group = ext4_flex_group(sbi, group);
|
||||||
atomic_dec(&sbi->s_flex_groups[flex_group].free_inodes);
|
atomic_dec(&sbi->s_flex_groups[flex_group].free_inodes);
|
||||||
}
|
}
|
||||||
|
if (owner) {
|
||||||
if (test_opt(sb, GRPID)) {
|
inode->i_mode = mode;
|
||||||
|
inode->i_uid = owner[0];
|
||||||
|
inode->i_gid = owner[1];
|
||||||
|
} else if (test_opt(sb, GRPID)) {
|
||||||
inode->i_mode = mode;
|
inode->i_mode = mode;
|
||||||
inode->i_uid = current_fsuid();
|
inode->i_uid = current_fsuid();
|
||||||
inode->i_gid = dir->i_gid;
|
inode->i_gid = dir->i_gid;
|
||||||
|
|
|
@ -439,6 +439,7 @@ int ext4_ext_migrate(struct inode *inode)
|
||||||
struct migrate_struct lb;
|
struct migrate_struct lb;
|
||||||
unsigned long max_entries;
|
unsigned long max_entries;
|
||||||
__u32 goal;
|
__u32 goal;
|
||||||
|
uid_t owner[2];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the filesystem does not support extents, or the inode
|
* If the filesystem does not support extents, or the inode
|
||||||
|
@ -466,10 +467,12 @@ int ext4_ext_migrate(struct inode *inode)
|
||||||
}
|
}
|
||||||
goal = (((inode->i_ino - 1) / EXT4_INODES_PER_GROUP(inode->i_sb)) *
|
goal = (((inode->i_ino - 1) / EXT4_INODES_PER_GROUP(inode->i_sb)) *
|
||||||
EXT4_INODES_PER_GROUP(inode->i_sb)) + 1;
|
EXT4_INODES_PER_GROUP(inode->i_sb)) + 1;
|
||||||
|
owner[0] = inode->i_uid;
|
||||||
|
owner[1] = inode->i_gid;
|
||||||
tmp_inode = ext4_new_inode(handle, inode->i_sb->s_root->d_inode,
|
tmp_inode = ext4_new_inode(handle, inode->i_sb->s_root->d_inode,
|
||||||
S_IFREG, NULL, goal);
|
S_IFREG, NULL, goal, owner);
|
||||||
if (IS_ERR(tmp_inode)) {
|
if (IS_ERR(tmp_inode)) {
|
||||||
retval = -ENOMEM;
|
retval = PTR_ERR(inode);
|
||||||
ext4_journal_stop(handle);
|
ext4_journal_stop(handle);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1754,7 +1754,7 @@ static int ext4_create(struct inode *dir, struct dentry *dentry, int mode,
|
||||||
if (IS_DIRSYNC(dir))
|
if (IS_DIRSYNC(dir))
|
||||||
ext4_handle_sync(handle);
|
ext4_handle_sync(handle);
|
||||||
|
|
||||||
inode = ext4_new_inode(handle, dir, mode, &dentry->d_name, 0);
|
inode = ext4_new_inode(handle, dir, mode, &dentry->d_name, 0, NULL);
|
||||||
err = PTR_ERR(inode);
|
err = PTR_ERR(inode);
|
||||||
if (!IS_ERR(inode)) {
|
if (!IS_ERR(inode)) {
|
||||||
inode->i_op = &ext4_file_inode_operations;
|
inode->i_op = &ext4_file_inode_operations;
|
||||||
|
@ -1790,7 +1790,7 @@ static int ext4_mknod(struct inode *dir, struct dentry *dentry,
|
||||||
if (IS_DIRSYNC(dir))
|
if (IS_DIRSYNC(dir))
|
||||||
ext4_handle_sync(handle);
|
ext4_handle_sync(handle);
|
||||||
|
|
||||||
inode = ext4_new_inode(handle, dir, mode, &dentry->d_name, 0);
|
inode = ext4_new_inode(handle, dir, mode, &dentry->d_name, 0, NULL);
|
||||||
err = PTR_ERR(inode);
|
err = PTR_ERR(inode);
|
||||||
if (!IS_ERR(inode)) {
|
if (!IS_ERR(inode)) {
|
||||||
init_special_inode(inode, inode->i_mode, rdev);
|
init_special_inode(inode, inode->i_mode, rdev);
|
||||||
|
@ -1830,7 +1830,7 @@ static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
|
||||||
ext4_handle_sync(handle);
|
ext4_handle_sync(handle);
|
||||||
|
|
||||||
inode = ext4_new_inode(handle, dir, S_IFDIR | mode,
|
inode = ext4_new_inode(handle, dir, S_IFDIR | mode,
|
||||||
&dentry->d_name, 0);
|
&dentry->d_name, 0, NULL);
|
||||||
err = PTR_ERR(inode);
|
err = PTR_ERR(inode);
|
||||||
if (IS_ERR(inode))
|
if (IS_ERR(inode))
|
||||||
goto out_stop;
|
goto out_stop;
|
||||||
|
@ -2277,7 +2277,7 @@ static int ext4_symlink(struct inode *dir,
|
||||||
ext4_handle_sync(handle);
|
ext4_handle_sync(handle);
|
||||||
|
|
||||||
inode = ext4_new_inode(handle, dir, S_IFLNK|S_IRWXUGO,
|
inode = ext4_new_inode(handle, dir, S_IFLNK|S_IRWXUGO,
|
||||||
&dentry->d_name, 0);
|
&dentry->d_name, 0, NULL);
|
||||||
err = PTR_ERR(inode);
|
err = PTR_ERR(inode);
|
||||||
if (IS_ERR(inode))
|
if (IS_ERR(inode))
|
||||||
goto out_stop;
|
goto out_stop;
|
||||||
|
|
Loading…
Reference in New Issue