@@ -710,7 +710,8 @@ static void do_write_with_advice(int argc, char **argv,
710710 const struct cmd_desc * cmd , bool with_advice )
711711{
712712 u64 buf_size = 0 , inc_num = 0 , written = 0 ;
713- u64 offset ;
713+ u64 offset , offset_byte ;
714+ bool random_offset = false;
714715 char * buf = NULL ;
715716 unsigned bs , count , i ;
716717 int flags = 0 ;
@@ -727,7 +728,11 @@ static void do_write_with_advice(int argc, char **argv,
727728
728729 buf_size = bs * F2FS_DEFAULT_BLKSIZE ;
729730
730- offset = atoi (argv [2 ]) * buf_size ;
731+ offset = atoi (argv [2 ]);
732+ if (atoi (argv [2 ]) < 0 ) {
733+ random_offset = true;
734+ offset = - offset ;
735+ }
731736
732737 buf = aligned_xalloc (F2FS_DEFAULT_BLKSIZE , buf_size );
733738 count = atoi (argv [3 ]);
@@ -812,10 +817,14 @@ static void do_write_with_advice(int argc, char **argv,
812817 else if (!strcmp (argv [4 ], "rand" ))
813818 * (int * )buf = rand ();
814819
820+ offset_byte = (random_offset ? rand () % offset :
821+ offset + i ) * buf_size ;
822+
815823 /* write data */
816824 max_time_t = get_current_us ();
817- ret = pwrite (fd , buf , buf_size , offset + buf_size * i );
825+ ret = pwrite (fd , buf , buf_size , offset_byte );
818826 max_time_t = get_current_us () - max_time_t ;
827+
819828 if (max_time < max_time_t )
820829 max_time = max_time_t ;
821830 if (ret != buf_size )
@@ -844,7 +853,7 @@ static void do_write_with_advice(int argc, char **argv,
844853 }
845854 }
846855
847- printf ("Written %" PRIu64 " bytes with pattern= %s, total_time= %" PRIu64 " us, max_latency= %" PRIu64 " us\n" ,
856+ printf ("Written %" PRIu64 " bytes with pattern = %s, total_time = %" PRIu64 " us, max_latency = %" PRIu64 " us\n" ,
848857 written , argv [4 ],
849858 get_current_us () - total_time ,
850859 max_time );
@@ -855,6 +864,8 @@ static void do_write_with_advice(int argc, char **argv,
855864#define write_help \
856865"f2fs_io write [chunk_size in 4kb] [offset in chunk_size] [count] [pattern] [IO] [file_path] {delay}\n\n" \
857866"Write given patten data in file_path\n" \
867+ "Offset can be a negative number which\n" \
868+ " indicates random write range for atomic operations.\n" \
858869"pattern can be\n" \
859870" zero : zeros\n" \
860871" inc_num : incrementing numbers\n" \
0 commit comments