[CRIU] [PATCH 2/8] zdtm: Add test for opened ghost directory
Pavel Emelyanov
xemul at parallels.com
Thu Jul 3 08:07:14 PDT 2014
Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
test/zdtm.sh | 1 +
test/zdtm/.gitignore | 1 +
test/zdtm/live/static/Makefile | 1 +
test/zdtm/live/static/rmdir_open.c | 70 ++++++++++++++++++++++++++++++++++++++
4 files changed, 73 insertions(+)
create mode 100644 test/zdtm/live/static/rmdir_open.c
diff --git a/test/zdtm.sh b/test/zdtm.sh
index 5ed405c..2fa4bcf 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -78,6 +78,7 @@ static/unlink_fstat03
static/unlink_mmap00
static/unlink_mmap01
static/unlink_mmap02
+static/rmdir_open
static/eventfs00
static/signalfd00
static/inotify00
diff --git a/test/zdtm/.gitignore b/test/zdtm/.gitignore
index ed5578f..7b88d9a 100644
--- a/test/zdtm/.gitignore
+++ b/test/zdtm/.gitignore
@@ -143,6 +143,7 @@
/live/static/unlink_mmap00
/live/static/unlink_mmap01
/live/static/unlink_mmap02
+/live/static/rmdir_open
/live/static/uptime_grow
/live/static/utsname
/live/static/vdso00
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index f41fd80..387fbf5 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -160,6 +160,7 @@ TST_DIR = \
tempfs \
bind-mount \
cgroup00 \
+ rmdir_open \
TST_DIR_FILE = \
chroot \
diff --git a/test/zdtm/live/static/rmdir_open.c b/test/zdtm/live/static/rmdir_open.c
new file mode 100644
index 0000000..981729d
--- /dev/null
+++ b/test/zdtm/live/static/rmdir_open.c
@@ -0,0 +1,70 @@
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc = "Check that opened removed dir works";
+const char *test_author = "Pavel Emelianov <xemul at parallels.com>";
+
+char *dirname;
+TEST_OPTION(dirname, string, "directory name", 1);
+
+int main(int argc, char **argv)
+{
+ int fd;
+ struct stat st;
+
+ test_init(argc, argv);
+
+ if (mkdir(dirname, 0700)) {
+ err("Can't make dir\n");
+ goto out;
+ }
+
+ fd = open(dirname, O_DIRECTORY);
+ if (fd < 0) {
+ err("Can't open dir\n");
+ goto outr;
+ }
+
+ if (rmdir(dirname)) {
+ err("Can't remove dir\n");
+ goto outr;
+ }
+
+ test_daemon();
+ test_waitsig();
+
+ /*
+ * We can't compare anything with previous, since
+ * inode _will_ change, so can the device. The only
+ * reasonable thing we can do is check that the fd
+ * still points to some removed directory.
+ */
+ if (fstat(fd, &st)) {
+ fail("Can't stat fd\n");
+ goto out;
+ }
+
+ if (!S_ISDIR(st.st_mode)) {
+ fail("Fd is no longer directory\n");
+ goto out;
+ }
+
+ if (st.st_nlink != 0) {
+ fail("Directory is not removed\n");
+ goto out;
+ }
+
+ pass();
+ return 0;
+
+outr:
+ rmdir(dirname);
+out:
+ return 1;
+}
--
1.8.3.1
More information about the CRIU
mailing list