ext4: fix synchronization of quota files in journal=data mode

In journal=data mode, it is not enough to do write_inode_now as done in
vfs_quota_on() to write all data to their final location (which is
needed for quota_read to work correctly). Calling journal_flush() does
its job.

Cc: <linux-ext4@vger.kernel.org>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Mingming Cao <cmm@us.ibm.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

authored by Jan Kara and committed by Theodore Ts'o 0623543b cd59e7b9

+27 -8
+27 -8
fs/ext4/super.c
··· 3170 3170 3171 3171 if (!test_opt(sb, QUOTA)) 3172 3172 return -EINVAL; 3173 - /* Not journalling quota? */ 3174 - if ((!EXT4_SB(sb)->s_qf_names[USRQUOTA] && 3175 - !EXT4_SB(sb)->s_qf_names[GRPQUOTA]) || remount) 3173 + /* When remounting, no checks are needed and in fact, path is NULL */ 3174 + if (remount) 3176 3175 return vfs_quota_on(sb, type, format_id, path, remount); 3176 + 3177 3177 err = path_lookup(path, LOOKUP_FOLLOW, &nd); 3178 3178 if (err) 3179 3179 return err; 3180 + 3180 3181 /* Quotafile not on the same filesystem? */ 3181 3182 if (nd.path.mnt->mnt_sb != sb) { 3182 3183 path_put(&nd.path); 3183 3184 return -EXDEV; 3184 3185 } 3185 - /* Quotafile not of fs root? */ 3186 - if (nd.path.dentry->d_parent->d_inode != sb->s_root->d_inode) 3187 - printk(KERN_WARNING 3188 - "EXT4-fs: Quota file not on filesystem root. " 3189 - "Journalled quota will not work.\n"); 3186 + /* Journaling quota? */ 3187 + if (EXT4_SB(sb)->s_qf_names[type]) { 3188 + /* Quotafile not of fs root? */ 3189 + if (nd.path.dentry->d_parent->d_inode != sb->s_root->d_inode) 3190 + printk(KERN_WARNING 3191 + "EXT4-fs: Quota file not on filesystem root. " 3192 + "Journaled quota will not work.\n"); 3193 + } 3194 + 3195 + /* 3196 + * When we journal data on quota file, we have to flush journal to see 3197 + * all updates to the file when we bypass pagecache... 3198 + */ 3199 + if (ext4_should_journal_data(nd.path.dentry->d_inode)) { 3200 + /* 3201 + * We don't need to lock updates but journal_flush() could 3202 + * otherwise be livelocked... 3203 + */ 3204 + jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); 3205 + jbd2_journal_flush(EXT4_SB(sb)->s_journal); 3206 + jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); 3207 + } 3208 + 3190 3209 path_put(&nd.path); 3191 3210 return vfs_quota_on(sb, type, format_id, path, remount); 3192 3211 }