Regression: add chdir-open and rmdir-open test programs
authorErez Zadok <ezk@cs.sunysb.edu>
Wed, 27 Apr 2011 09:54:42 +0000 (05:54 -0400)
committerErez Zadok <ezk@cs.sunysb.edu>
Wed, 27 Apr 2011 09:54:42 +0000 (05:54 -0400)
Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
progs/Makefile
progs/chdir-open.c [new file with mode: 0644]
progs/rmdir-open.c [new file with mode: 0644]

index bfcb5c1c4272826636c1bf3d67304158ad038f30..54dedb6d7d45f7f5d3fce2edf8e99df8ad1724e7 100644 (file)
@@ -19,7 +19,8 @@
 CFLAGS=-g -Wall # -Werror # -lefence
 MOUNTPOINT=.
 BINS=open-unlink flock-copyup fsync truncate bug418 rmdircheckinode \
-       creat-open rename mapper queryfile mapper2 ftruncate-unlink
+       creat-open rename mapper queryfile mapper2 ftruncate-unlink \
+       rmdir-open chdir-open
 
 all: $(BINS)
 
diff --git a/progs/chdir-open.c b/progs/chdir-open.c
new file mode 100644 (file)
index 0000000..a169440
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2003-2007 Erez Zadok
+ * Copyright (c) 2003-2007 Stony Brook University
+ * Copyright (c) 2003-2007 The Research Foundation of SUNY
+ *
+ * For specific licensing information, see the COPYING file distributed with
+ * this package.
+ *
+ * This Copyright notice must be kept intact and distributed with all sources.
+ */
+
+#include <unistd.h>
+#include <linux/types.h>
+#include <linux/dirent.h>
+#include <linux/unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
+//#include <asm-generic/fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#define O_LARGEFILE    00100000
+#define O_DIRECTORY    0200000
+
+/* open a open dir chdir'd into */
+int main(int argc, char *argv[])
+{
+  char *dir = argv[1];
+  char *what2open = argv[2];
+  int fd, ret = 0;
+
+  if (argc != 3) {
+    fprintf(stderr, "Usage: %s dir what2open\n", argv[0]);
+    exit(1);
+  }
+
+#if 1
+  // NO OOPS if I skip the chdir and open(dir) directly
+  /* chdir into the dir */
+  ret = chdir(dir);
+  if (ret < 0) {
+    fprintf(stderr, "%s(%s): %s\n", dir, "chdir", strerror(errno));
+    exit(1);
+  }
+#endif
+#if 1
+  /* open the dir */
+  // NO OOPS if I skip the chdir and open(dir) directly
+//  fd = open(dir, O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY);
+//  fd = open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY);
+  // NO OOPS if I open(dir), but oops if I open(".") -- WTF
+  fd = open(what2open, O_RDONLY|O_DIRECTORY);
+  if (fd < 0) {
+    fprintf(stderr, "%s(%s): %s\n", ".", "open", strerror(errno));
+    exit(1);
+  }
+#endif
+#if 1
+  /* close the dir */
+  ret = close(fd);
+  if (ret < 0) {
+    fprintf(stderr, "%s(%s): %s\n", ".", "close", strerror(errno));
+    exit(1);
+  }
+#endif
+  /* all's well */
+  exit(0);
+}
diff --git a/progs/rmdir-open.c b/progs/rmdir-open.c
new file mode 100644 (file)
index 0000000..eb321f9
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2003-2007 Erez Zadok
+ * Copyright (c) 2003-2007 Stony Brook University
+ * Copyright (c) 2003-2007 The Research Foundation of SUNY
+ *
+ * For specific licensing information, see the COPYING file distributed with
+ * this package.
+ *
+ * This Copyright notice must be kept intact and distributed with all sources.
+ */
+
+#include <unistd.h>
+#include <linux/types.h>
+#include <linux/dirent.h>
+#include <linux/unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
+//#include <asm-generic/fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#define O_LARGEFILE    00100000
+#define O_DIRECTORY    0200000
+
+/* rmdir an open dir, which we're chdir'd into */
+int main(int argc, char *argv[])
+{
+  char *dir = argv[1];
+  struct stat sbuf;
+  struct dirent dent;
+  int fd, ret = 0;
+
+  if (argc != 2) {
+    fprintf(stderr, "Usage: %s dir2remove\n", argv[0]);
+    exit(1);
+  }
+
+#if 0
+  // NO DIFFERENCE -- STILL PANIC
+  /* try to unlink first -- should fail */
+  ret = unlink(dir);
+  if (ret < 0) {
+    fprintf(stderr, "%s(%s): %s\n", dir, "unlink", strerror(errno));
+    //    exit(1);     /* don't exit */
+  }
+#endif
+#if 0
+  // NO DIFFERENCE -- STILL PANIC
+  /* stat the dir */
+  ret = lstat(dir, &sbuf);
+  if (ret < 0) {
+    fprintf(stderr, "%s(%s): %s\n", dir, "lstat1", strerror(errno));
+    exit(1);
+  }
+#endif
+#if 1
+  // NO OOPS if I skip the chdir and open(dir) directly
+  /* chdir into the dir */
+  ret = chdir(dir);
+  if (ret < 0) {
+    fprintf(stderr, "%s(%s): %s\n", dir, "chdir", strerror(errno));
+    exit(1);
+  }
+#endif
+#if 0
+  // NO DIFFERENCE -- STILL PANIC
+  /* stat the cwd dir */
+  ret = lstat(".", &sbuf);
+  if (ret < 0) {
+    fprintf(stderr, "%s(%s): %s\n", ".", "lstat2", strerror(errno));
+    exit(1);
+  }
+#endif
+#if 1
+  /* open the dir */
+  // NO OOPS if I skip the chdir and open(dir) directly
+//  fd = open(dir, O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY);
+//  fd = open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY);
+  fd = open(".", O_RDONLY|O_DIRECTORY);
+  if (fd < 0) {
+    fprintf(stderr, "%s(%s): %s\n", ".", "open", strerror(errno));
+    exit(1);
+  }
+#endif
+#if 0
+  // NO DIFFERENCE -- STILL PANIC EVEN IF I DONT READ THE DIR
+  /* read the dir */
+  do {
+    ret = syscall(__NR_getdents, fd, &dent, 32768);
+    if (ret < 0) {
+      fprintf(stderr, "%s(%s): %s\n", ".", "getdent", strerror(errno));
+      exit(1);
+    }
+  } while (ret == 0);
+#endif
+#if 1
+  /* close the dir */
+  ret = close(fd);
+  if (ret < 0) {
+    fprintf(stderr, "%s(%s): %s\n", ".", "close", strerror(errno));
+    exit(1);
+  }
+#endif
+#if 0
+  // NO DIFFERENCE -- STILL PANIC
+  /* rmdir the dir */
+  ret = rmdir(dir);
+  if (ret < 0) {
+    fprintf(stderr, "%s(%s): %s\n", dir, "rmdir", strerror(errno));
+    exit(1);
+  }
+#endif
+  /* all's well */
+  fprintf(stderr, "%s: removed successfully\n", dir);
+  exit(0);
+}