2022-09-14 18:48:07

by Gianfranco Dutka

[permalink] [raw]
Subject: [PATCH] fat: device-level-flush-after-sync

This patch forces a device-level flush after the generic Linux
code for sync has run.

The kernel depends upon filesystem-specific code to flush when
the filesystem itself thinks it is necessary, and otherwise
does nothing. Someone expecting sync to behave as expected
might be in for a rude surprise.

The usual caveats apply: Devices that do not implement flush
or whose implementation is buggy will not behave well. IO
that occurs after the sync will not be flushed.

Signed-off-by: Ken Kofman <[email protected]>

---
fs/fat/inode.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index a38238d75c08..ddaed94ee48f 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -823,6 +823,14 @@ static int fat_remount(struct super_block *sb, int *flags, char *data)
return 0;
}

+static int fat_sync_fs(struct super_block *sb, int wait)
+{
+ if (wait)
+ return blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL);
+ else
+ return 0;
+}
+
static int fat_statfs(struct dentry *dentry, struct kstatfs *buf)
{
struct super_block *sb = dentry->d_sb;
@@ -937,6 +945,7 @@ static const struct super_operations fat_sops = {
.put_super = fat_put_super,
.statfs = fat_statfs,
.remount_fs = fat_remount,
+ .sync_fs = fat_sync_fs,

.show_options = fat_show_options,
};
--
2.37.0


2022-09-14 19:38:54

by OGAWA Hirofumi

[permalink] [raw]
Subject: Re: [PATCH] fat: device-level-flush-after-sync

Gianfranco <[email protected]> writes:

> This patch forces a device-level flush after the generic Linux
> code for sync has run.
>
> The kernel depends upon filesystem-specific code to flush when
> the filesystem itself thinks it is necessary, and otherwise
> does nothing. Someone expecting sync to behave as expected
> might be in for a rude surprise.
>
> The usual caveats apply: Devices that do not implement flush
> or whose implementation is buggy will not behave well. IO
> that occurs after the sync will not be flushed.

Does this patch fix the issue? After the ->sync_fs(), bdev page caches
including FAT data are still dirty, isn't it?

Thanks.

> Signed-off-by: Ken Kofman <[email protected]>
>
> ---
> fs/fat/inode.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/fs/fat/inode.c b/fs/fat/inode.c
> index a38238d75c08..ddaed94ee48f 100644
> --- a/fs/fat/inode.c
> +++ b/fs/fat/inode.c
> @@ -823,6 +823,14 @@ static int fat_remount(struct super_block *sb, int *flags, char *data)
> return 0;
> }
>
> +static int fat_sync_fs(struct super_block *sb, int wait)
> +{
> + if (wait)
> + return blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL);
> + else
> + return 0;
> +}
> +
> static int fat_statfs(struct dentry *dentry, struct kstatfs *buf)
> {
> struct super_block *sb = dentry->d_sb;
> @@ -937,6 +945,7 @@ static const struct super_operations fat_sops = {
> .put_super = fat_put_super,
> .statfs = fat_statfs,
> .remount_fs = fat_remount,
> + .sync_fs = fat_sync_fs,
>
> .show_options = fat_show_options,
> };

--
OGAWA Hirofumi <[email protected]>

2022-09-15 13:10:40

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] fat: device-level-flush-after-sync

Hi Gianfranco,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.0-rc5 next-20220915]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Gianfranco/fat-device-level-flush-after-sync/20220915-014337
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 3245cb65fd91cd514801bf91f5a3066d562f0ac4
config: x86_64-randconfig-a011 (https://download.01.org/0day-ci/archive/20220915/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-5) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/b1130c74311f7b8c0713f373a8dc20b572883fca
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Gianfranco/fat-device-level-flush-after-sync/20220915-014337
git checkout b1130c74311f7b8c0713f373a8dc20b572883fca
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash fs/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

fs/fat/inode.c: In function 'fat_sync_fs':
>> fs/fat/inode.c:829:24: error: too many arguments to function 'blkdev_issue_flush'
829 | return blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL);
| ^~~~~~~~~~~~~~~~~~
In file included from fs/fat/inode.c:21:
include/linux/blkdev.h:1031:5: note: declared here
1031 | int blkdev_issue_flush(struct block_device *bdev);
| ^~~~~~~~~~~~~~~~~~


vim +/blkdev_issue_flush +829 fs/fat/inode.c

825
826 static int fat_sync_fs(struct super_block *sb, int wait)
827 {
828 if (wait)
> 829 return blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL);
830 else
831 return 0;
832 }
833

--
0-DAY CI Kernel Test Service
https://01.org/lkp

2022-09-15 20:31:56

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] fat: device-level-flush-after-sync

Hi Gianfranco,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.0-rc5 next-20220915]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Gianfranco/fat-device-level-flush-after-sync/20220915-014337
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 3245cb65fd91cd514801bf91f5a3066d562f0ac4
config: x86_64-randconfig-a012 (https://download.01.org/0day-ci/archive/20220916/[email protected]/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/b1130c74311f7b8c0713f373a8dc20b572883fca
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Gianfranco/fat-device-level-flush-after-sync/20220915-014337
git checkout b1130c74311f7b8c0713f373a8dc20b572883fca
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash fs/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

>> fs/fat/inode.c:829:41: error: too many arguments to function call, expected single argument 'bdev', have 3 arguments
return blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL);
~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~
include/linux/gfp_types.h:333:20: note: expanded from macro 'GFP_KERNEL'
#define GFP_KERNEL (__GFP_RECLAIM | __GFP_IO | __GFP_FS)
^
include/linux/blkdev.h:1031:5: note: 'blkdev_issue_flush' declared here
int blkdev_issue_flush(struct block_device *bdev);
^
1 error generated.


vim +/bdev +829 fs/fat/inode.c

825
826 static int fat_sync_fs(struct super_block *sb, int wait)
827 {
828 if (wait)
> 829 return blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL);
830 else
831 return 0;
832 }
833

--
0-DAY CI Kernel Test Service
https://01.org/lkp