Whamcloud - gitweb
b=2429
authorjacob <jacob>
Fri, 9 Jan 2004 21:10:11 +0000 (21:10 +0000)
committerjacob <jacob>
Fri, 9 Jan 2004 21:10:11 +0000 (21:10 +0000)
r=phil,shaver

fix renaming a file to itself, and add a couple of tests for this
case.

also, make rename.pl not spin waiting for children.

lustre/mds/mds_reint.c
lustre/tests/multiop.c
lustre/tests/rename.pl
lustre/tests/sanity.sh

index 22ca65b..626248d 100644 (file)
@@ -1664,6 +1664,10 @@ static int mds_reint_rename(struct mds_update_record *rec, int offset,
              de_new->d_inode->i_ino == de_tgtdir->d_inode->i_ino))
                 GOTO(cleanup, rc = -EINVAL);
 
+        if (de_old->d_inode == de_new->d_inode) {
+                GOTO(cleanup, rc = 0);
+        }
+
         /* if we are about to remove the target at first, pass the EA of
          * that inode to client to perform and cleanup on OST */
         body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body));
index 2be0b93..de59be6 100755 (executable)
@@ -21,10 +21,13 @@ char usage[] =
 "        D  open(O_DIRECTORY)\n"
 "        o  open(O_RDONLY)\n"
 "        O  open(O_CREAT|O_RDWR)\n"
+"        L  link\n"
+"        l  symlink\n"
 "        u  unlink\n"
 "        U  munmap\n"
 "        m  mknod\n"
 "        M  rw mmap to EOF (must open and stat prior)\n"
+"        N  rename\n"
 "        c  close\n"
 "        _  wait for signal\n"
 "        R  reference entire mmap-ed region\n"
@@ -41,15 +44,28 @@ char usage[] =
 
 void null_handler(int unused) { }
 
+static const char *
+pop_arg(int argc, char *argv[])
+{
+       static int cur_arg = 3;
+
+       if (cur_arg >= argc)
+               return NULL;
+
+       return argv[cur_arg++];
+}
+#define POP_ARG() (pop_arg(argc, argv))
+
 int main(int argc, char **argv)
 {
         char *fname, *commands;
+       const char *newfile;
         struct stat st;
        size_t mmap_len, i;
        unsigned char *mmap_ptr = NULL, junk = 0;
         int fd = -1;
 
-        if (argc != 3) {
+        if (argc < 3) {
                 fprintf(stderr, usage, argv[0]);
                 exit(1);
         }
@@ -82,6 +98,24 @@ int main(int argc, char **argv)
                                exit(1);
                        }
                        break;
+               case 'l':
+                       newfile = POP_ARG();
+                       if (!newfile)
+                               newfile = fname;
+                       if (symlink(fname, newfile)) {
+                               perror("symlink()");
+                               exit(1);
+                       }
+                       break;
+               case 'L':
+                       newfile = POP_ARG();
+                       if (!newfile)
+                               newfile = fname;
+                       if (link(fname, newfile)) {
+                               perror("symlink()");
+                               exit(1);
+                       }
+                       break;
                 case 'm':
                         if (mknod(fname, S_IFREG | 0644, 0) == -1) {
                                 perror("mknod(S_IFREG|0644, 0)");
@@ -97,6 +131,15 @@ int main(int argc, char **argv)
                                exit(1);
                        }
                        break;
+               case 'N':
+                       newfile = POP_ARG();
+                       if (!newfile)
+                               newfile = fname;
+                       if (rename (fname, newfile)) {
+                               perror("rename()");
+                               exit(1);
+                       }
+                       break;
                 case 'O':
                         fd = open(fname, O_CREAT|O_RDWR, 0644);
                         if (fd == -1) {
index ee9bb4d..dd6b5dc 100644 (file)
@@ -93,7 +93,7 @@ for (my $i=1; $i<=$num_threads; $i++) {
 # Wait for all our threads to finish.
 my $child = 0;
 do {
-    $child = waitpid(-1, WNOHANG);
+    $child = waitpid(-1, 0);
 } until $child > 0;
 sleep 1;
 
index 0e9f0b0..1147bcf 100644 (file)
@@ -611,6 +611,19 @@ test_24k() {
 }
 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
 
+# bug 2429 - rename foo foo foo creates invalid file
+test_24l() {
+       f="$DIR/f24l"
+       multiop $f OcNs || error
+}
+run_test 24l "Renaming a file to itself ========================"
+
+test_24m() {
+       f="$DIR/f24m"
+       multiop $f OcLN ${f}2 ${f}2 || error
+}
+run_test 24m "Renaming a file to a hard link to itself ========="
+
 test_25a() {
        echo '== symlink sanity ============================================='
        mkdir $DIR/d25