Skip to content

Commit 048bfb5

Browse files
yangerkungregkh
authored andcommitted
ext4: update quota information while swapping boot loader inode
commit aa507b5 upstream. While do swap between two inode, they swap i_data without update quota information. Also, swap_inode_boot_loader can do "revert" somtimes, so update the quota while all operations has been finished. Signed-off-by: yangerkun <yangerkun@huawei.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 071f681 commit 048bfb5

1 file changed

Lines changed: 43 additions & 13 deletions

File tree

‎fs/ext4/ioctl.c‎

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ static void swap_inode_data(struct inode *inode1, struct inode *inode2)
6868
ei2 = EXT4_I(inode2);
6969

7070
swap(inode1->i_version, inode2->i_version);
71-
swap(inode1->i_blocks, inode2->i_blocks);
72-
swap(inode1->i_bytes, inode2->i_bytes);
7371
swap(inode1->i_atime, inode2->i_atime);
7472
swap(inode1->i_mtime, inode2->i_mtime);
7573

@@ -115,6 +113,9 @@ static long swap_inode_boot_loader(struct super_block *sb,
115113
int err;
116114
struct inode *inode_bl;
117115
struct ext4_inode_info *ei_bl;
116+
qsize_t size, size_bl, diff;
117+
blkcnt_t blocks;
118+
unsigned short bytes;
118119

119120
inode_bl = ext4_iget(sb, EXT4_BOOT_LOADER_INO, EXT4_IGET_SPECIAL);
120121
if (IS_ERR(inode_bl))
@@ -180,6 +181,13 @@ static long swap_inode_boot_loader(struct super_block *sb,
180181
memset(ei_bl->i_data, 0, sizeof(ei_bl->i_data));
181182
}
182183

184+
err = dquot_initialize(inode);
185+
if (err)
186+
goto err_out1;
187+
188+
size = (qsize_t)(inode->i_blocks) * (1 << 9) + inode->i_bytes;
189+
size_bl = (qsize_t)(inode_bl->i_blocks) * (1 << 9) + inode_bl->i_bytes;
190+
diff = size - size_bl;
183191
swap_inode_data(inode, inode_bl);
184192

185193
inode->i_ctime = inode_bl->i_ctime = current_time(inode);
@@ -193,24 +201,46 @@ static long swap_inode_boot_loader(struct super_block *sb,
193201

194202
err = ext4_mark_inode_dirty(handle, inode);
195203
if (err < 0) {
204+
/* No need to update quota information. */
196205
ext4_warning(inode->i_sb,
197206
"couldn't mark inode #%lu dirty (err %d)",
198207
inode->i_ino, err);
199208
/* Revert all changes: */
200209
swap_inode_data(inode, inode_bl);
201210
ext4_mark_inode_dirty(handle, inode);
202-
} else {
203-
err = ext4_mark_inode_dirty(handle, inode_bl);
204-
if (err < 0) {
205-
ext4_warning(inode_bl->i_sb,
206-
"couldn't mark inode #%lu dirty (err %d)",
207-
inode_bl->i_ino, err);
208-
/* Revert all changes: */
209-
swap_inode_data(inode, inode_bl);
210-
ext4_mark_inode_dirty(handle, inode);
211-
ext4_mark_inode_dirty(handle, inode_bl);
212-
}
211+
goto err_out1;
212+
}
213+
214+
blocks = inode_bl->i_blocks;
215+
bytes = inode_bl->i_bytes;
216+
inode_bl->i_blocks = inode->i_blocks;
217+
inode_bl->i_bytes = inode->i_bytes;
218+
err = ext4_mark_inode_dirty(handle, inode_bl);
219+
if (err < 0) {
220+
/* No need to update quota information. */
221+
ext4_warning(inode_bl->i_sb,
222+
"couldn't mark inode #%lu dirty (err %d)",
223+
inode_bl->i_ino, err);
224+
goto revert;
213225
}
226+
227+
/* Bootloader inode should not be counted into quota information. */
228+
if (diff > 0)
229+
dquot_free_space(inode, diff);
230+
else
231+
err = dquot_alloc_space(inode, -1 * diff);
232+
233+
if (err < 0) {
234+
revert:
235+
/* Revert all changes: */
236+
inode_bl->i_blocks = blocks;
237+
inode_bl->i_bytes = bytes;
238+
swap_inode_data(inode, inode_bl);
239+
ext4_mark_inode_dirty(handle, inode);
240+
ext4_mark_inode_dirty(handle, inode_bl);
241+
}
242+
243+
err_out1:
214244
ext4_journal_stop(handle);
215245
ext4_double_up_write_data_sem(inode, inode_bl);
216246

0 commit comments

Comments
 (0)