[CRIU] [PATCH 18/18] zdtm: Add fanotify00 test

Andrew Vagin avagin at parallels.com
Fri Jan 11 15:52:29 EST 2013


On Fri, Jan 11, 2013 at 08:58:19PM +0400, Cyrill Gorcunov wrote:
> 
> This one is pretty trivial and need to be extented for
> more masks and flags, but fine for now.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  test/zdtm.sh                       |   1 +
>  test/zdtm/live/static/Makefile     |   1 +
>  test/zdtm/live/static/fanotify00.c | 110 +++++++++++++++++++++++++++++++++++++
>  3 files changed, 112 insertions(+)
>  create mode 100644 test/zdtm/live/static/fanotify00.c
> 

> diff --git a/test/zdtm.sh b/test/zdtm.sh
> index 70da472..28eddea 100644
> --- a/test/zdtm.sh
> +++ b/test/zdtm.sh
> @@ -128,6 +128,7 @@ static/socket-tcpbuf6
>  static/eventfs00
>  static/signalfd00
>  static/inotify00
> +static/fanotify00
>  $IPC_TEST_LIST
>  "
>  
> diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
> index 07c92c5..538576d 100644
> --- a/test/zdtm/live/static/Makefile
> +++ b/test/zdtm/live/static/Makefile
> @@ -66,6 +66,7 @@ TST_NOFILE	=				\
>  		eventfs00			\
>  		signalfd00			\
>  		inotify00			\
> +		fanotify00			\
>  		uptime_grow			\
>  		session00			\
>  		rlimits00			\
> diff --git a/test/zdtm/live/static/fanotify00.c b/test/zdtm/live/static/fanotify00.c
> new file mode 100644
> index 0000000..caeb0cb
> --- /dev/null
> +++ b/test/zdtm/live/static/fanotify00.c
> @@ -0,0 +1,110 @@
> +#define _GNU_SOURCE         /* See feature_test_macros(7) */
> +#include <unistd.h>
> +#include <limits.h>
> +
> +#include <sys/types.h>
> +#include <sys/ioctl.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
> +#include <string.h>
> +#include <stdio.h>
> +#include <errno.h>
> +#include <sys/inotify.h>
> +#include <unistd.h>
> +#include <stdlib.h>
> +#include <linux/fanotify.h>
> +
> +#include "zdtmtst.h"
> +
> +#ifdef __x86_64__
> +# define __NR_fanotify_init	300
> +# define __NR_fanotify_mark	301
> +#else
> +# define __NR_fanotify_init	338
> +# define __NR_fanotify_mark	339
> +#endif
> +
> +const char *test_doc	= "Check for fanotify delivery";
> +const char *test_author	= "Cyrill Gorcunov <gorcunov at openvz.org>";
> +
> +const char fanotify_path[] = "fanotify-del-after-cr";
> +
> +#define BUFF_SIZE ((sizeof(struct inotify_event) + PATH_MAX))
> +
> +static int fanotify_init(unsigned int flags, unsigned int event_f_flags)
> +{
> +	return syscall(__NR_fanotify_init, flags, event_f_flags);
> +}
> +
> +static int fanotify_mark(int fanotify_fd, unsigned int flags, unsigned long mask,
> +			 int dfd, const char *pathname)
> +{
> +	return syscall(__NR_fanotify_mark, fanotify_fd, flags, mask, dfd, pathname);
> +}
> +
> +int main (int argc, char *argv[])
> +{
> +	char buf[BUFF_SIZE];
> +	int fa_fd, fd, del_after;
> +
> +	test_init(argc, argv);
> +
> +	fa_fd = fanotify_init(FAN_NONBLOCK | O_RDONLY | O_LARGEFILE |
> +			      FAN_CLASS_NOTIF | FAN_UNLIMITED_QUEUE,
> +			      0);
> +	if (fa_fd < 0) {
> +		fail("fanotify_init failed\n");
fail() can't be used before checkpoint/restore (test_waitsig).
err() should be used here.
> +		exit(1);
> +	}
> +
> +	del_after = open(fanotify_path, O_CREAT | O_TRUNC);
> +	if (del_after < 0) {
> +		fail("open failed\n");
> +		exit(1);
> +	}
> +
> +	if (fanotify_mark(fa_fd, FAN_MARK_ADD,
> +			  FAN_MODIFY | FAN_ACCESS | FAN_OPEN | FAN_CLOSE,
> +			  AT_FDCWD, fanotify_path)) {
> +		fail("fanotify_mark failed\n");
> +		exit(1);
> +	}
> +
> +	if (fanotify_mark(fa_fd, FAN_MARK_ADD | FAN_MARK_MOUNT,
> +			  FAN_ONDIR | FAN_OPEN | FAN_CLOSE,
> +			  AT_FDCWD, "/")) {
> +		fail("fanotify_mark failed\n");
> +		exit(1);
> +	}
> +
> +	if (fanotify_mark(fa_fd, FAN_MARK_ADD | FAN_MARK_MOUNT |
> +			  FAN_MARK_IGNORED_MASK | FAN_MARK_IGNORED_SURV_MODIFY,
> +			  FAN_MODIFY | FAN_ACCESS,
> +			  AT_FDCWD, "/")) {
> +		fail("fanotify_mark failed\n");
> +		exit(1);
> +	}
> +
> +	test_daemon();
> +	test_waitsig();
> +
> +	fd = open("/", O_RDONLY);
> +	close(fd);
> +
> +	fd = open(fanotify_path, O_RDWR);
> +	close(fd);
> +
> +	if (unlink(fanotify_path)) {
> +		fail("can't unlink %s\n", fanotify_path);
> +		exit(1);
> +	}
> +
> +	if (read(fa_fd, buf, sizeof(buf)) <= 0) {
> +		fail("No events in fanotify queue\n");
> +		exit(1);
> +	}
> +
> +	pass();
> +
> +	return 0;
> +}

> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> http://lists.openvz.org/mailman/listinfo/criu



More information about the CRIU mailing list