@@ -28,36 +28,81 @@ static const stress_help_t help[] = {
2828 { NULL , NULL , NULL }
2929};
3030
31+ /*
32+ * stess_io_write()
33+ * write a 32 bit random value to bytes 0..3 of file
34+ */
35+ static void stess_io_write (const int fd )
36+ {
37+ uint32_t data = stress_mwc32 ();
38+
39+ VOID_RET (off_t , lseek (fd , 0 , SEEK_SET ));
40+ VOID_RET (ssize_t , write (fd , & data , sizeof (data )));
41+ }
42+
3143/*
3244 * stress on sync()
3345 * stress system by IO sync calls
3446 */
3547static int stress_io (stress_args_t * args )
3648{
3749 int rc = EXIT_SUCCESS ;
50+ int ret ;
3851#if defined(HAVE_SYNCFS )
39- int i , fd , n_mnts ;
52+ int i ;
53+ int fd_dir ;
54+ int fd_tmp ;
55+ const int fd_bad = stress_fs_bad_fd_get ();
56+ int n_mnts ;
4057 char * mnts [MAX_MNTS ];
58+ char filename [PATH_MAX ];
4159 int fds [MAX_MNTS ];
42- const int bad_fd = stress_fs_bad_fd_get ();
4360
4461 if (stress_instance_zero (args ))
4562 pr_inf ("%s: this is a legacy I/O sync stressor, consider using iomix instead\n" , args -> name );
4663
64+ ret = stress_fs_temp_dir_make_args (args );
65+ if (ret < 0 ) {
66+ rc = stress_exit_status ((int )- ret );
67+ return rc ;
68+ }
69+
70+ (void )stress_fs_temp_filename_args (args , filename , sizeof (filename ), stress_mwc32 ());
71+ if ((fd_tmp = open (filename , O_RDWR | O_CREAT , S_IRUSR | S_IWUSR )) < 0 ) {
72+ rc = stress_exit_status (errno );
73+ pr_fail ("%s: open %s failed, errno=%d (%s)\n" ,
74+ args -> name , filename , errno , strerror (errno ));
75+ goto tidy_dir ;
76+
77+ }
78+ (void )shim_unlink (filename );
79+
4780 n_mnts = stress_mount_get (mnts , MAX_MNTS );
4881 for (i = 0 ; i < n_mnts ; i ++ )
4982 fds [i ] = openat (AT_FDCWD , mnts [i ], O_RDONLY | O_NONBLOCK | O_DIRECTORY );
5083
51- fd = openat (AT_FDCWD , "." , O_RDONLY | O_NONBLOCK | O_DIRECTORY );
84+ fd_dir = openat (AT_FDCWD , "." , O_RDONLY | O_NONBLOCK | O_DIRECTORY );
5285#endif
5386 stress_proc_state_set (args -> name , STRESS_STATE_SYNC_WAIT );
5487 stress_sync_start_wait (args );
5588 stress_proc_state_set (args -> name , STRESS_STATE_RUN );
5689
5790 do {
91+ stess_io_write (fd_tmp );
92+ if (stress_mwc1 ()) {
93+ shim_fsync (fd_tmp );
94+ shim_fdatasync (fd_tmp );
95+ } else {
96+ shim_fdatasync (fd_tmp );
97+ shim_fsync (fd_tmp );
98+ }
99+
100+ stess_io_write (fd_tmp );
58101 shim_sync ();
59102#if defined(HAVE_SYNCFS )
60- if (UNLIKELY ((fd != -1 ) && (syncfs (fd ) < 0 ))) {
103+
104+ stess_io_write (fd_tmp );
105+ if (UNLIKELY ((fd_dir != -1 ) && (syncfs (fd_dir ) < 0 ))) {
61106 if (UNLIKELY (errno == ENOSYS ))
62107 goto bogo_inc ;
63108 pr_fail ("%s: syncfs failed, errno=%d (%s)\n" ,
@@ -87,9 +132,9 @@ static int stress_io(stress_args_t *args)
87132 /*
88133 * exercise with an invalid fd
89134 */
90- if (UNLIKELY (syncfs (bad_fd ) == 0 )) {
135+ if (UNLIKELY (syncfs (fd_bad ) == 0 )) {
91136 pr_fail ("%s: syncfs on invalid fd %d succeeded\n" ,
92- args -> name , bad_fd );
137+ args -> name , fd_bad );
93138 rc = EXIT_FAILURE ;
94139 goto tidy ;
95140 }
@@ -105,15 +150,19 @@ static int stress_io(stress_args_t *args)
105150#endif
106151 stress_proc_state_set (args -> name , STRESS_STATE_DEINIT );
107152#if defined(HAVE_SYNCFS )
108- if (fd != -1 )
109- (void )close (fd );
153+ if (fd_dir != -1 )
154+ (void )close (fd_dir );
110155
111156 stress_fs_close_fds (fds , n_mnts );
112157 stress_mount_free (mnts , n_mnts );
113158#else
114159 UNEXPECTED
115160#endif
116161
162+ (void )close (fd_tmp );
163+ tidy_dir :
164+ (void )stress_fs_temp_dir_rm_args (args );
165+
117166 return rc ;
118167}
119168
0 commit comments