2020#include "core-attribute.h"
2121#include "core-mounts.h"
2222
23+ #if defined(HAVE_LINUX_FS_H )
24+ #include <linux/fs.h>
25+ #endif
26+
27+ #include <sys/ioctl.h>
28+
2329#if defined(HAVE_SYS_FILE_H )
2430#include <sys/file.h>
2531#endif
@@ -594,6 +600,114 @@ static int stress_rofs_file_fsync(
594600 return 0 ;
595601}
596602
603+ typedef int (* stress_rofs_file_ioctl_func_t )(const int fd );
604+
605+ #if defined(FS_IOC_GETVERSION )
606+ static int stress_rofs_file_ioctl_ioc_get_version (const int fd )
607+ {
608+ int version ;
609+
610+ return ioctl (fd , FS_IOC_GETVERSION , & version );
611+ }
612+ #endif
613+
614+ #if defined(FS_IOC_GETFSLABEL ) && \
615+ defined(FSLABEL_MAX )
616+ static int stress_rofs_file_ioctl_ioc_getfslabel (const int fd )
617+ {
618+ char label [FSLABEL_MAX ];
619+
620+ return ioctl (fd , FS_IOC_GETFSLABEL , label );
621+ }
622+ #endif
623+
624+ #if defined(FS_IOC_GETFLAGS )
625+ static int stress_rofs_file_ioctl_ioc_getflags (const int fd )
626+ {
627+ int attr = 0 ;
628+
629+ return ioctl (fd , FS_IOC_GETFLAGS , & attr );
630+ }
631+ #endif
632+
633+ #if defined(FIGETBSZ )
634+ static int stress_rofs_file_ioctl_figetbsz (const int fd )
635+ {
636+ int isz ;
637+
638+ return ioctl (fd , FIGETBSZ , & isz );
639+ }
640+ #endif
641+
642+ #if defined(FIONREAD )
643+ static int stress_rofs_file_ioctl_fionread (const int fd )
644+ {
645+ int isz ;
646+
647+ return ioctl (fd , FIONREAD , & isz );
648+ }
649+ #endif
650+
651+ #if defined(FIOQSIZE )
652+ static int stress_rofs_file_ioctl_fioqsize (const int fd )
653+ {
654+ shim_loff_t sz ;
655+
656+ return ioctl (fd , FIOQSIZE , & sz );
657+ }
658+ #endif
659+
660+ static const stress_rofs_file_ioctl_func_t stress_rofs_file_ioctl_funcs [] = {
661+ #if defined(FS_IOC_GETVERSION )
662+ stress_rofs_file_ioctl_ioc_get_version ,
663+ #endif
664+ #if defined(FS_IOC_GETFSLABEL ) && \
665+ defined (FSLABEL_MAX )
666+ stress_rofs_file_ioctl_ioc_getfslabel ,
667+ #endif
668+ #if defined(FS_IOC_GETFLAGS )
669+ stress_rofs_file_ioctl_ioc_getflags ,
670+ #endif
671+ #if defined(FIGETBSZ )
672+ stress_rofs_file_ioctl_figetbsz ,
673+ #endif
674+ #if defined(FIONREAD )
675+ stress_rofs_file_ioctl_fionread ,
676+ #endif
677+ #if defined(FIOQSIZE )
678+ stress_rofs_file_ioctl_fioqsize ,
679+ #endif
680+ };
681+
682+ /*
683+ * stress_rofs_file_ioctl()
684+ * exercise various randomly selected ioctl calls
685+ */
686+ static int stress_rofs_file_ioctl (
687+ stress_args_t * args ,
688+ const char * path ,
689+ double * count ,
690+ stress_rofs_info_t * info )
691+ {
692+ int fd ;
693+ const size_t n_ioctl_funcs = SIZEOF_ARRAY (stress_rofs_file_ioctl_funcs );
694+ size_t idx ;
695+
696+ if (n_ioctl_funcs < 1 )
697+ return 0 ;
698+
699+ fd = stres_rofs_file_open (args , path , info );
700+ if (fd < 0 )
701+ return -1 ;
702+
703+ idx = stress_mwcsizemodn (n_ioctl_funcs );
704+ if (stress_rofs_file_ioctl_funcs [idx ](fd ) == 0 )
705+ (* count ) += 1.0 ;
706+
707+ (void )close (fd );
708+ return 0 ;
709+ }
710+
597711static const stress_rofs_method_t stress_rofs_methods [] = {
598712 { "lstat" , stress_rofs_file_lstat },
599713 { "valid open/close" , stress_rofs_file_valid_open_close },
@@ -618,6 +732,7 @@ static const stress_rofs_method_t stress_rofs_methods[] = {
618732 { "flock" , stress_rofs_file_flock },
619733#endif
620734 { "fsync" , stress_rofs_file_fsync },
735+ { "ioctl" , stress_rofs_file_ioctl },
621736};
622737
623738static stress_metrics_t stress_rofs_metrics [SIZEOF_ARRAY (stress_rofs_methods )];
@@ -847,5 +962,5 @@ const stressor_info_t stress_rofs_info = {
847962 .opts = opts ,
848963 .verify = VERIFY_ALWAYS ,
849964 .help = help ,
850- .max_metrics_items = 11 ,
965+ .max_metrics_items = 12 ,
851966};
0 commit comments