X-Git-Url: http://git.apps.os.sepia.ceph.com/?p=xfstests-dev.git;a=blobdiff_plain;f=src%2Fopen_by_handle.c;h=f5be2350e3fdefd447edb419467e812b550ea8fd;hp=7dfb395bd7fb5a31eb013766d358dab4ecb163b8;hb=555cdbee56476fa8e34cd8bd400f39fa70e0ece0;hpb=fbc0f6913e444fbbeb8f71360dbd73028595b675 diff --git a/src/open_by_handle.c b/src/open_by_handle.c index 7dfb395b..f5be2350 100644 --- a/src/open_by_handle.c +++ b/src/open_by_handle.c @@ -27,7 +27,7 @@ /* -usage: open_by_handle [-cludmrwapkh] [<-i|-o> ] [num_files] +usage: open_by_handle [-cludmrwapknhs] [<-i|-o> ] [num_files] Examples: @@ -43,36 +43,39 @@ Examples: open_by_handle -p [N] -3. Get file handles for existing test set and write them to a file. - Read file handles from file and open files by handle: +3. Get file handles for existing test set and write them to a file: open_by_handle -p -o [N] - open_by_handle -p -i [N] -4. Get file handles for existing test set, write data to files, +4. Read file handles from file and open files by handle without + dropping caches beforehand. Sleep afterhand to keep files open: + + open_by_handle -nps -i [N] + +5. Get file handles for existing test set, write data to files, drop caches, open all files by handle, read and verify written data, write new data to file: open_by_handle -rwa [N] -5. Get file handles for existing test set, unlink all test files, +6. Get file handles for existing test set, unlink all test files, remove test_dir, drop caches, try to open all files by handle and expect ESTALE: open_by_handle -dp [N] -6. Get file handles for existing test set, keep open file handles for all +7. Get file handles for existing test set, keep open file handles for all test files, unlink all test files, drop caches and try to open all files by handle (should work): open_by_handle -dk [N] -7. Get file handles for existing test set, rename all test files, +8. 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 [N] -8. Get file handles for existing test set, hardlink all test files, +9. 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): @@ -109,10 +112,11 @@ struct handle { void usage(void) { - fprintf(stderr, "usage: open_by_handle [-cludmrwapkh] [<-i|-o> ] [num_files]\n"); + fprintf(stderr, "usage: open_by_handle [-cludmrwapknhs] [<-i|-o> ] [num_files]\n"); fprintf(stderr, "\n"); fprintf(stderr, "open_by_handle -c [N] - create N test files under test_dir, try to get file handles and exit\n"); fprintf(stderr, "open_by_handle [N] - get file handles of test files, drop caches and try to open by handle\n"); + fprintf(stderr, "open_by_handle -n [N] - get file handles of test files and try to open by handle without drop caches\n"); fprintf(stderr, "open_by_handle -k [N] - get file handles of files that are kept open, drop caches and try to open by handle\n"); fprintf(stderr, "open_by_handle -w [N] - write data to test files before open by handle\n"); fprintf(stderr, "open_by_handle -r [N] - read data from test files after open by handle and verify written data\n"); @@ -124,6 +128,7 @@ void usage(void) fprintf(stderr, "open_by_handle -p - create/delete and try to open by handle also test_dir itself\n"); fprintf(stderr, "open_by_handle -i [N] - read test files handles from file and try to open by handle\n"); fprintf(stderr, "open_by_handle -o [N] - get file handles of test files and write handles to file\n"); + fprintf(stderr, "open_by_handle -s [N] - wait in sleep loop after opening files by handle to keep them open\n"); exit(EXIT_FAILURE); } @@ -144,12 +149,12 @@ int main(int argc, char **argv) int numfiles = 1; int create = 0, delete = 0, nlink = 1, move = 0; int rd = 0, wr = 0, wrafter = 0, parent = 0; - int keepopen = 0; + int keepopen = 0, drop_caches = 1, sleep_loop = 0; if (argc < 2) usage(); - while ((c = getopt(argc, argv, "cludmrwapkhi:o:")) != -1) { + while ((c = getopt(argc, argv, "cludmrwapknhi:o:s")) != -1) { switch (c) { case 'c': create = 1; @@ -186,6 +191,9 @@ int main(int argc, char **argv) case 'k': keepopen = 1; break; + case 'n': + drop_caches = 0; + break; case 'i': infile = optarg; in_fd = open(infile, O_RDONLY); @@ -202,6 +210,9 @@ int main(int argc, char **argv) return EXIT_FAILURE; } break; + case 's': + sleep_loop = 1; + break; default: fprintf(stderr, "illegal option '%s'\n", argv[optind]); case 'h': @@ -438,10 +449,12 @@ int main(int argc, char **argv) * buftarg page cache is emptied so that the inode cluster has to be * fetched from disk again for the open_by_handle() call. */ - ret = system("echo 3 > /proc/sys/vm/drop_caches"); - if (ret < 0) { - perror("drop_caches"); - return EXIT_FAILURE; + if (drop_caches) { + ret = system("echo 3 > /proc/sys/vm/drop_caches"); + if (ret < 0) { + perror("drop_caches"); + return EXIT_FAILURE; + } } /* @@ -469,7 +482,8 @@ int main(int argc, char **argv) perror(fname); return EXIT_FAILURE; } - close(fd); + if (!sleep_loop) + close(fd); continue; } else if (!nlink && !keepopen && fd < 0 && (errno == ENOENT || errno == ESTALE)) { continue; @@ -520,7 +534,8 @@ int main(int argc, char **argv) return EXIT_FAILURE; } } - close(fd); + if (!sleep_loop) + close(fd); } else if (nlink || !(errno == ENOENT || errno == ESTALE)) { printf("open_by_handle(%s) returned %d incorrectly on %s dir!\n", dname, errno, @@ -531,5 +546,13 @@ int main(int argc, char **argv) if (failed) return EXIT_FAILURE; + + /* + * Sleep keeping files open by handle - the program need to be killed + * to release the open files. + */ + while (sleep_loop) + sleep(1); + return EXIT_SUCCESS; }