Skip to content

Commit abdc644

Browse files
yangerkuntytso
authored andcommitted
ext4: add mask of ext4 flags to swap
The reason is that while swapping two inode, we swap the flags too. Some flags such as EXT4_JOURNAL_DATA_FL can really confuse the things since we're not resetting the address operations structure. The simplest way to keep things sane is to restrict the flags that can be swapped. Signed-off-by: yangerkun <yangerkun@huawei.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@vger.kernel.org
1 parent aa507b5 commit abdc644

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎fs/ext4/ext4.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ struct flex_groups {
426426
/* Flags that are appropriate for non-directories/regular files. */
427427
#define EXT4_OTHER_FLMASK (EXT4_NODUMP_FL | EXT4_NOATIME_FL)
428428

429+
/* The only flags that should be swapped */
430+
#define EXT4_FL_SHOULD_SWAP (EXT4_HUGE_FILE_FL | EXT4_EXTENTS_FL)
431+
429432
/* Mask out flags that are inappropriate for the given type of inode. */
430433
static inline __u32 ext4_mask_flags(umode_t mode, __u32 flags)
431434
{

‎fs/ext4/ioctl.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static void swap_inode_data(struct inode *inode1, struct inode *inode2)
6363
loff_t isize;
6464
struct ext4_inode_info *ei1;
6565
struct ext4_inode_info *ei2;
66+
unsigned long tmp;
6667

6768
ei1 = EXT4_I(inode1);
6869
ei2 = EXT4_I(inode2);
@@ -72,7 +73,10 @@ static void swap_inode_data(struct inode *inode1, struct inode *inode2)
7273
swap(inode1->i_mtime, inode2->i_mtime);
7374

7475
memswap(ei1->i_data, ei2->i_data, sizeof(ei1->i_data));
75-
swap(ei1->i_flags, ei2->i_flags);
76+
tmp = ei1->i_flags & EXT4_FL_SHOULD_SWAP;
77+
ei1->i_flags = (ei2->i_flags & EXT4_FL_SHOULD_SWAP) |
78+
(ei1->i_flags & ~EXT4_FL_SHOULD_SWAP);
79+
ei2->i_flags = tmp | (ei2->i_flags & ~EXT4_FL_SHOULD_SWAP);
7680
swap(ei1->i_disksize, ei2->i_disksize);
7781
ext4_es_remove_extent(inode1, 0, EXT_MAX_BLOCKS);
7882
ext4_es_remove_extent(inode2, 0, EXT_MAX_BLOCKS);

0 commit comments

Comments
 (0)