open_by_handle: test file handles of renamed files
authorAmir Goldstein <amir73il@gmail.com>
Thu, 2 Nov 2017 10:15:34 +0000 (12:15 +0200)
committerEryu Guan <eguan@redhat.com>
Fri, 10 Nov 2017 04:33:37 +0000 (12:33 +0800)
usage: open_by_handle -m <test_dir> [N]

Get file handles for existing test set, rename all test files,
drop cache and try to open all files by handle.

This is needed for testing that overlayfs can find the upper
inode from lower file handle even when upper is not in the same
path as lower.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
src/open_by_handle.c

index 52973c6ef654c32ad8aa29a08b7c33efcd5c50fc..8b12df37aebf25eae3c57088a636e0bc9cf04409 100644 (file)
@@ -27,7 +27,7 @@
 
 /*
 
 
 /*
 
-usage: open_by_handle [-c|-l|-u|-d] <test_dir> [num_files]
+usage: open_by_handle [-cludm] <test_dir> [num_files]
 
 Examples:
 
 
 Examples:
 
@@ -48,7 +48,12 @@ Examples:
 
    open_by_handle -d <test_dir> [N]
 
 
    open_by_handle -d <test_dir> [N]
 
-4. Get file handles for existing test set, hardlink all test files,
+4. Get file handles for existing test set, rename all test files,
+   drop caches, try to open all files by handle (should work):
+
+   open_by_handle -m <test_dir> [N]
+
+5. Get file handles for existing test set, hardlink all test files,
    then unlink the original files, drop caches and try to open all
    files by handle (should work):
 
    then unlink the original files, drop caches and try to open all
    files by handle (should work):
 
@@ -84,13 +89,14 @@ struct handle {
 
 void usage(void)
 {
 
 void usage(void)
 {
-       fprintf(stderr, "usage: open_by_handle [-c|-l|-u|-d] <test_dir> [num_files]\n");
+       fprintf(stderr, "usage: open_by_handle [-cludm] <test_dir> [num_files]\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "open_by_handle -c <test_dir> [N] - create N test files under test_dir, try to get file handles and exit\n");
        fprintf(stderr, "open_by_handle    <test_dir> [N] - get file handles of test files, drop caches and try to open by handle\n");
        fprintf(stderr, "open_by_handle -l <test_dir> [N] - create hardlinks to test files, drop caches and try to open by handle\n");
        fprintf(stderr, "open_by_handle -u <test_dir> [N] - unlink (hardlinked) test files, drop caches and try to open by handle\n");
        fprintf(stderr, "open_by_handle -d <test_dir> [N] - unlink test files and hardlinks, drop caches and try to open by handle\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "open_by_handle -c <test_dir> [N] - create N test files under test_dir, try to get file handles and exit\n");
        fprintf(stderr, "open_by_handle    <test_dir> [N] - get file handles of test files, drop caches and try to open by handle\n");
        fprintf(stderr, "open_by_handle -l <test_dir> [N] - create hardlinks to test files, drop caches and try to open by handle\n");
        fprintf(stderr, "open_by_handle -u <test_dir> [N] - unlink (hardlinked) test files, drop caches and try to open by handle\n");
        fprintf(stderr, "open_by_handle -d <test_dir> [N] - unlink test files and hardlinks, drop caches and try to open by handle\n");
+       fprintf(stderr, "open_by_handle -m <test_dir> [N] - rename test files, drop caches and try to open by handle\n");
        exit(EXIT_FAILURE);
 }
 
        exit(EXIT_FAILURE);
 }
 
@@ -105,12 +111,12 @@ int main(int argc, char **argv)
        char    *test_dir;
        int     mount_fd, mount_id;
        int     numfiles = 1;
        char    *test_dir;
        int     mount_fd, mount_id;
        int     numfiles = 1;
-       int     create = 0, delete = 0, nlink = 1;
+       int     create = 0, delete = 0, nlink = 1, move = 0;
 
        if (argc < 2 || argc > 4)
                usage();
 
 
        if (argc < 2 || argc > 4)
                usage();
 
-       while ((c = getopt(argc, argv, "clud")) != -1) {
+       while ((c = getopt(argc, argv, "cludm")) != -1) {
                switch (c) {
                case 'c':
                        create = 1;
                switch (c) {
                case 'c':
                        create = 1;
@@ -126,6 +132,9 @@ int main(int argc, char **argv)
                        delete = 1;
                        nlink = 0;
                        break;
                        delete = 1;
                        nlink = 0;
                        break;
+               case 'm':
+                       move = 1;
+                       break;
                default:
                        fprintf(stderr, "illegal option '%s'\n", argv[optind]);
                case 'h':
                default:
                        fprintf(stderr, "illegal option '%s'\n", argv[optind]);
                case 'h':
@@ -201,6 +210,18 @@ int main(int argc, char **argv)
                }
        }
 
                }
        }
 
+       /* rename the files */
+       for (i=0; move && i < numfiles; i++) {
+               sprintf(fname, "%s/file%06d", test_dir, i);
+               sprintf(fname2, "%s/link%06d", test_dir, i);
+               ret = rename(fname, fname2);
+               if (ret < 0) {
+                       strcat(fname2, ": rename");
+                       perror(fname2);
+                       return EXIT_FAILURE;
+               }
+       }
+
        /* unlink the files */
        for (i=0; delete && i < numfiles; i++) {
                sprintf(fname, "%s/file%06d", test_dir, i);
        /* unlink the files */
        for (i=0; delete && i < numfiles; i++) {
                sprintf(fname, "%s/file%06d", test_dir, i);