On Fri 14-09-18 14:21:04, Richard Guy Briggs wrote:
On 2018-09-04 18:06, Jan Kara wrote:
> Add stress test for stressing audit tree watches by adding and deleting
> rules while events are generated and watched filesystems are mounted and
> unmounted in parallel.
A couple of minor comments below, but otherwise looks reasonable to me.
Reviewed-by: Richard Guy Briggs <rgb(a)redhat.com>
I assume you've tested this with more than $dirs = 4 and sleep(60)?
I've tested it to run for longer time (couple hours) but I don't think I've
tested more directories. I can try that out.
> +sub umount_all {
> + my($dir,$dirs,$ignore_fail) = @_;
> +
> + for (my $i=0; $i < $dirs; $i++) {
> + while (system("umount $dir/leaf$i >& /dev/null") > 0
&&
> + $ignore_fail == 0) {
> + # Nothing - loop until umount succeeds
> + }
> + }
Shouldn't this set of tmpfs be unmounted after the bind mounts that
follow, in reverse order to the way they were mounted?
The order does not really matter. Once bind mount is created, it is
independent entity from the original mount (well, except for possible mount
inheritance) so you can unmount them in arbitrary order.
> +# create temp directory
> +my $dir = tempdir( TEMPLATE => '/tmp/audit-testsuite-XXXX', CLEANUP
=> 1 );
> +
> +# create stdout/stderr sinks
> +( my $fh_out, my $stdout ) = tempfile(
> + TEMPLATE => '/tmp/audit-testsuite-out-XXXX',
> + UNLINK => 1
> +);
> +( my $fh_err, my $stderr ) = tempfile(
> + TEMPLATE => '/tmp/audit-testsuite-err-XXXX',
> + UNLINK => 1
> +);
> +
> +###
> +# tests
> +
> +my $dirs = 4;
> +
> +# setup directory hierarchy
> +for (my $i=0; $i < $dirs; $i++) {
> + mkdir $dir."/dir".$i;
> + for (my $j=0; $j < $dirs; $j++) {
> + mkdir $dir."/dir".$i."/subdir".$j;
> + }
> +}
> +mkdir "$dir/mnt";
> +for (my $i=0; $i < $dirs; $i++) {
> + mkdir "$dir/mnt/mnt$i";
> + mkdir "$dir/leaf$i";
> +}
> +
> +my $stat_pid = fork();
> +
> +if ($stat_pid == 0) {
> + run_stat($dir, $dirs);
> + # Never reached
> + exit;
> +}
> +
> +my $mount_pid = fork();
> +
> +if ($mount_pid == 0) {
> + run_mount($dir, $dirs);
> + # Never reached
> + exit;
> +}
> +
> +my $key = key_gen();
> +
> +my $audit_pid = fork();
> +
> +if ($audit_pid == 0) {
> + run_mark_audit($dir, $dirs, $key);
> + # Never reached
> + exit;
> +}
> +
> +# Sleep for a minute to let stress test run...
> +sleep(60);
> +ok(1);
> +
> +###
> +# cleanup
> +
> +kill('KILL', $stat_pid, $mount_pid, $audit_pid);
> +# Wait for children to terminate
> +waitpid($stat_pid, 0);
> +waitpid($mount_pid, 0);
> +waitpid($audit_pid, 0);
> +system("auditctl -D >& /dev/null");
> +umount_all($dir, $dirs, 1);
Should all the subdirectories in the temp directory be deleted, or are
they all cleaned up recursively by the tempdir command?
The CLEANUP / UNLINK parameters to tempdir() and tempfile() functions
should make sure everything is removed on exit (including possible
subdirs).
Honza
--
Jan Kara <jack(a)suse.com>
SUSE Labs, CR