[CRIU] [PATCH] zdtm:fifo: check that read only fifo descriptor
is restored
Andrew Vagin
avagin at parallels.com
Fri Jun 8 05:06:00 EDT 2012
Test: zdtm/live/static/fifo_ro
====================== ERROR ======================
Dump log : /root/cyrillos/crtools/test/dump/fifo_ro/11204/dump.log
Restore log: /root/cyrillos/crtools/test/dump/fifo_ro/11204/restore.log
Creating fifo pipe_id=0xfff93fe6 id=0x2
Splicing data size=65536 off=4096
Error (pipes.c:158): 0x2: Error splicing data: Bad file descriptor
On Fri, Jun 08, 2012 at 01:03:57PM +0400, Andrey Vagin wrote:
>
> * Create fifo and two descriptors rw and ro
> * Write data and close rw descriptor
> * Suspend/resume
> * Read data from ro descriptor
> ---
> test/zdtm/live/static/Makefile | 1 +
> test/zdtm/live/static/fifo_ro.c | 94 +++++++++++++++++++++++++++++++++++++++
> 2 files changed, 95 insertions(+), 0 deletions(-)
> create mode 100644 test/zdtm/live/static/fifo_ro.c
>
> diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
> index 3e2dfa8..1fc9b0e 100644
> --- a/test/zdtm/live/static/Makefile
> +++ b/test/zdtm/live/static/Makefile
> @@ -65,6 +65,7 @@ TST_FILE = \
> unlink_largefile \
> mtime_mmap \
> fifo \
> + fifo_ro \
> fifo_wronly \
> unlink_fifo \
> unlink_fifo_wronly \
> diff --git a/test/zdtm/live/static/fifo_ro.c b/test/zdtm/live/static/fifo_ro.c
> new file mode 100644
> index 0000000..edb66b5
> --- /dev/null
> +++ b/test/zdtm/live/static/fifo_ro.c
> @@ -0,0 +1,94 @@
> +#include <errno.h>
> +#include <unistd.h>
> +#include <stdlib.h>
> +#include <sys/mount.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
> +
> +#include "zdtmtst.h"
> +
> +const char *test_doc = "Check that a fifo read-only descriptor is restored with data";
> +const char *test_author = "Andrew Vagin <avagin at openvz.org>";
> +
> +char *filename;
> +TEST_OPTION(filename, string, "file name", 1);
> +
> +#define BUF_SIZE (16 * 4096) /* A fifo buffer has 16 slots by default */
> +
> +int main(int argc, char **argv)
> +{
> + int fd;
> + int fd_ro;
> + struct stat st;
> + mode_t mode = S_IFIFO | 0700;
> + uint8_t buf[BUF_SIZE];
> + uint32_t crc;
> + int ret;;
> +
> + test_init(argc, argv);
> +
> + if (mknod(filename, mode, 0)) {
> + err("can't make fifo \"%s\": %m\n", filename);
> + exit(1);
> + }
> +
> + fd = open(filename, O_RDWR);
> + if (fd < 0) {
> + err("can't open %s: %m\n", filename);
> + return 1;
> + }
> +
> + fd_ro = open(filename, O_RDONLY);
> + if (fd_ro < 0) {
> + err("can't open %s: %m\n", filename);
> + return 1;
> + }
> +
> + crc = ~0;
> + datagen(buf, BUF_SIZE, &crc);
> + ret = write(fd, buf, BUF_SIZE);
> + if (ret != BUF_SIZE) {
> + err("write() failed\n");
> + return 1;
> + }
> +
> + close(fd);
> +
> + test_daemon();
> + test_waitsig();
> +
> + ret = read(fd_ro, buf, BUF_SIZE);
> + if (ret != BUF_SIZE) {
> + err("read() failed\n");
> + return 1;
> + }
> +
> + crc = ~0;
> + if (datachk(buf, BUF_SIZE, &crc)) {
> + fail("data corrupted\n");
> + return 1;
> + }
> +
> + if (close(fd_ro) < 0) {
> + fail("can't close %s: %m", filename);
> + return 1;
> + }
> +
> + if (stat(filename, &st) < 0) {
> + fail("can't stat %s: %m", filename);
> + return 1;
> + }
> +
> + if (st.st_mode != mode) {
> + fail("%s is no longer the fifo we had", filename);
> + return 1;
> + }
> +
> + if (unlink(filename) < 0) {
> + fail("can't unlink %s: %m", filename);
> + return 1;
> + }
> +
> + pass();
> + return 0;
> +}
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://openvz.org/mailman/listinfo/criu
More information about the CRIU
mailing list