From a30616df71f749fea536d7ffac19c72f6577f7fc Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Tue, 20 Feb 2024 16:26:13 +0530 Subject: [PATCH] LU-6142 tests: Fix style issues under lustre/tests This patch fixes issues reported by checkpatch for all files under folder lustre/tests Signed-off-by: Arshad Hussain Change-Id: I93f18f737c219222593b9689cd3c1b5eaba7630d Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54110 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Timothy Day Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/tests/badarea_io.c | 5 ++- lustre/tests/check_fallocate.c | 19 +++++----- lustre/tests/checkfiemap.c | 18 +++++---- lustre/tests/createmany.c | 27 ++++++++------ lustre/tests/flock_deadlock.c | 62 +++++++++++++++++-------------- lustre/tests/flocks_test.c | 16 +++----- lustre/tests/fsx.c | 3 +- lustre/tests/ll_sparseness_write.c | 2 +- lustre/tests/llapi_fid_test.c | 75 ++++++++++++++++++++------------------ lustre/tests/llapi_hsm_test.c | 27 +++++++------- lustre/tests/llapi_layout_test.c | 45 +++++++++++++++-------- lustre/tests/llapi_root_test.c | 12 ++++-- lustre/tests/lockahead_test.c | 61 +++++++++++++++++-------------- lustre/tests/memhog.c | 6 ++- lustre/tests/mmap_sanity.c | 2 +- lustre/tests/reads.c | 41 +++++++++++++-------- lustre/tests/rename_many.c | 34 +++++++++-------- lustre/tests/sendfile_grouplock.c | 12 +++--- lustre/tests/small_write.c | 19 +++++----- lustre/tests/statx.c | 55 ++++++++++------------------ lustre/tests/swap_lock_test.c | 51 +++++++++++++------------- 21 files changed, 315 insertions(+), 277 deletions(-) diff --git a/lustre/tests/badarea_io.c b/lustre/tests/badarea_io.c index 663c881..d91067b 100644 --- a/lustre/tests/badarea_io.c +++ b/lustre/tests/badarea_io.c @@ -36,8 +36,8 @@ int main(int argc, char **argv) { ssize_t rc; int fd; - void *volatile buf = (void *)0x4096000; void *volatile fd_ptr; + void *volatile buf = (void *)0x4096000; fd = open(argv[1], O_WRONLY); if (fd == -1) { @@ -46,7 +46,8 @@ int main(int argc, char **argv) } /* We need rc because Sles11 compiler warns against unchecked - * return value of read and write */ + * return value of read and write + */ rc = write(fd, buf, 5); if (rc != 5) perror("write badarea (Should have failed)"); diff --git a/lustre/tests/check_fallocate.c b/lustre/tests/check_fallocate.c index 72f27ad..b689f06 100644 --- a/lustre/tests/check_fallocate.c +++ b/lustre/tests/check_fallocate.c @@ -95,9 +95,10 @@ static int __do_fallocate(int fd, int mode, loff_t offset, loff_t len) rc = fallocate(fd, mode, offset, len); if (rc != 0) { - fprintf(stderr, "fallocate failed, error %s, mode %d, " - "offset %llu, len %llu\n", strerror(errno), mode, - (unsigned long long)offset, (unsigned long long)len); + fprintf(stderr, + "fallocate failed, error %s, mode %d, offset %llu, len %llu\n", + strerror(errno), mode, (unsigned long long)offset, + (unsigned long long)len); rc = errno; } @@ -116,12 +117,12 @@ static int post_fallocate_checks(int fd, int mode, loff_t offset, loff_t len, goto out; if (st.st_size != expected_new_size) { - fprintf(stderr, "fallocate succeeded but size reported " - "is wrong\n"); - fprintf(stderr, "mode %d, offset %llu, len %llu, " - "new_size %llu, expected_new_size %llu\n", mode, - (unsigned long long)offset, (unsigned long long)len, - (unsigned long long)st.st_size, + fprintf(stderr, + "fallocate succeeded but size reported is wrong\n"); + fprintf(stderr, + "mode %d, offset %llu, len %llu, new_size %llu, expected_new_size %llu\n", + mode, (unsigned long long)offset, + (unsigned long long)len, (unsigned long long)st.st_size, (unsigned long long)expected_new_size); rc = -1; } diff --git a/lustre/tests/checkfiemap.c b/lustre/tests/checkfiemap.c index f396bbf..65abc62 100644 --- a/lustre/tests/checkfiemap.c +++ b/lustre/tests/checkfiemap.c @@ -49,7 +49,8 @@ #define ONEMB 1048576 -static inline void print_extent_flags(unsigned int flags) { +static inline void print_extent_flags(unsigned int flags) +{ if (!flags) return; @@ -84,7 +85,8 @@ static inline void print_extent_flags(unsigned int flags) { /* This test executes fiemap ioctl and check * a) there are no file ranges marked with FIEMAP_EXTENT_UNWRITTEN - * b) data ranges sizes sum is equal to given in second param */ + * b) data ranges sizes sum is equal to given in second param + */ static int check_fiemap(int fd, long long expected_sum, unsigned int *mapped_extents) { @@ -119,9 +121,8 @@ static int check_fiemap(int fd, long long expected_sum, if (fm_extents[i].fe_flags & FIEMAP_EXTENT_UNWRITTEN) { fprintf(stderr, "Unwritten extent\n"); return -2; - } else { - ext_len_sum += fm_extents[i].fe_length; } + ext_len_sum += fm_extents[i].fe_length; } printf("No unwritten extents, extents number %u, sum of lengths %lli, expected sum %lli\n", @@ -129,11 +130,11 @@ static int check_fiemap(int fd, long long expected_sum, ext_len_sum, expected_sum); *mapped_extents = fiemap->fm_mapped_extents; - return ext_len_sum != expected_sum || (expected_sum && !*mapped_extents); + return ext_len_sum != expected_sum || + (expected_sum && !*mapped_extents); } -/** - * LU-17110 +/* LU-17110 * When userspace uses fiemap with fm_extent_count=0, it means that kernelspace * should return only the number of extents. So we should always check * fm_extent_count before accessing to fm_extents array. Otherwise this could @@ -162,7 +163,8 @@ static void *corruption_th(void *args) return (void *) (long long) -errno; } if (ta->expected_mapped != fiemap.fm_mapped_extents) { - fprintf(stderr, "mapped extents mismatch: expected=%d, returned=%d\n", + fprintf(stderr, + "mapped extents mismatch: expected=%d, returned=%d\n", ta->expected_mapped, fiemap.fm_mapped_extents); return (void *) -EINVAL; } diff --git a/lustre/tests/createmany.c b/lustre/tests/createmany.c index be3fed6..c293e0f 100644 --- a/lustre/tests/createmany.c +++ b/lustre/tests/createmany.c @@ -48,7 +48,8 @@ static void usage(const char *prog) { printf("usage: %s {-o [-k]|-m|-d|-l} [-u[]] " - "[-i mdt_index] [-t seconds] filenamefmt [[start] count]\n", prog); + "[-i mdt_index] [-t seconds] filenamefmt [[start] count]\n", + prog); printf("\t-i\tMDT to create the directories on\n" "\t-l\tlink files to existing file\n" "\t-m\tmknod regular files (don't create OST objects)\n" @@ -78,11 +79,12 @@ static char *get_file_name(const char *fmt, long n, int has_fmt_spec) static double now(void) { struct timeval tv; + gettimeofday(&tv, NULL); return (double)tv.tv_sec + (double)tv.tv_usec / 1000000; } -int main(int argc, char ** argv) +int main(int argc, char **argv) { bool do_open = false, do_keep = false, do_link = false; bool do_unlink = false, do_mknod = false, do_mkdir = false; @@ -102,8 +104,8 @@ int main(int argc, char ** argv) /* Handle the deprecated positional last argument "-seconds" */ if (argc > 1 && argv[argc - 1][0] == '-' && (end = strtol(argv[argc - 1] + 1, &endp, 0)) && *endp == '\0') { - fprintf(stderr, "warning: '-runtime' deprecated, " - "use '-t runtime' instead\n"); + fprintf(stderr, + "warning: '-runtime' deprecated, use '-t runtime' instead\n"); argv[--argc] = NULL; } else { /* Not '-number', let regular argument parsing handle it. */ @@ -192,7 +194,9 @@ int main(int argc, char ** argv) filename = get_file_name(fmt, begin, has_fmt_spec); if (do_open) { - int fd = open(filename, O_CREAT|O_RDWR, 0644); + int fd; + + fd = open(filename, O_CREAT|O_RDWR, 0644); if (fd < 0) { printf("open(%s) error: %s\n", filename, strerror(errno)); @@ -214,8 +218,10 @@ int main(int argc, char ** argv) } else if (do_mkdir) { if (stripe_offset != -1) { rc = llapi_dir_create_pool(filename, 0755, - stripe_offset, stripe_count, - stripe_pattern, NULL); + stripe_offset, + stripe_count, + stripe_pattern, + NULL); if (rc) { printf("llapi_dir_create_pool(%s) error: %s\n", filename, strerror(-rc)); @@ -262,8 +268,7 @@ int main(int argc, char ** argv) tmp = now(); if (tmp - last_t >= 10.0 || (tmp - last_t > 2.0 && (i % 10000) == 0)) { - printf(" - %s%s %ld (time %.2f total %.2f last %.2f)" - "\n", + printf(" - %s%s %ld (time %.2f total %.2f last %.2f)\n", do_open ? do_keep ? "open/keep" : "open/close" : do_mkdir ? "mkdir" : do_link ? "link" : do_mknod ? "create" : "", @@ -295,8 +300,8 @@ int main(int argc, char ** argv) if ((i != 0 && (i % 10000) == 0) || now() - last_t >= 10.0) { double tmp = now(); - printf(" - closed %ld (time %.2f total %.2f last %.2f)" - "\n", i, tmp, tmp - start, + printf(" - closed %ld (time %.2f total %.2f last %.2f)\n", + i, tmp, tmp - start, (i - last_i) / (tmp - last_t)); last_t = tmp; last_i = i; diff --git a/lustre/tests/flock_deadlock.c b/lustre/tests/flock_deadlock.c index 7692455..91a1d9a 100644 --- a/lustre/tests/flock_deadlock.c +++ b/lustre/tests/flock_deadlock.c @@ -20,11 +20,11 @@ * information or have any questions. * * GPL HEADER END -*/ + */ /* * Copyright 2012 Xyratex Technology Limited -*/ + */ #include #include @@ -85,21 +85,21 @@ enum { FLOCK_PUT = 1, }; -#define flock_call(fd, num, get, label) \ - flocks[num].l_type = get == FLOCK_GET ? F_WRLCK : F_UNLCK; \ - printf("%d: %s lock%d [%llu, %llu]\n", pid, \ - get == FLOCK_GET ? "taking" : "putting", \ - num, (unsigned long long)flocks[num].l_start, \ - (unsigned long long)flocks[num].l_start + flocks[num].l_len); \ - rc = fcntl(fd, F_SETLKW, &flocks[num]); \ - if (rc < 0) { \ - rc = errno; \ - fprintf(stderr, "%d: failed to %s lock%d, %s\n", \ - pid, get == FLOCK_GET ? "take" : "put", \ - num, strerror(errno)); \ - goto label; \ - } else { \ - printf("%d: done\n", pid); \ +#define flock_call(fd, num, get, label) \ + flocks[num].l_type = get == FLOCK_GET ? F_WRLCK : F_UNLCK; \ + printf("%d: %s lock%d [%llu, %llu]\n", pid, \ + get == FLOCK_GET ? "taking" : "putting", \ + num, (unsigned long long)flocks[num].l_start, \ + (unsigned long long)flocks[num].l_start + flocks[num].l_len); \ + rc = fcntl(fd, F_SETLKW, &flocks[num]); \ + if (rc < 0) { \ + rc = errno; \ + fprintf(stderr, "%d: failed to %s lock%d, %s\n", \ + pid, get == FLOCK_GET ? "take" : "put", \ + num, strerror(errno)); \ + goto label; \ + } else { \ + printf("%d: done\n", pid); \ } static void catch_alarm(int i) @@ -108,7 +108,7 @@ static void catch_alarm(int i) exit(124); } -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { struct sigaction act; int status; @@ -142,7 +142,8 @@ int main(int argc, char* argv[]) /* First of all, it should get blocked on flocks[1] * 2nd child. Later, should deadlock with flocks[2] - * parent, after cancelling flocks[1] 2nd child. */ + * parent, after cancelling flocks[1] 2nd child. + */ printf("%d: taking lock3 [%llu, %llu]\n", pid, (unsigned long long)flocks[3].l_start, (unsigned long long)flocks[3].l_start + @@ -152,16 +153,18 @@ int main(int argc, char* argv[]) sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGALRM); if (sigaction(SIGALRM, &act, NULL) < 0) { - fprintf(stderr, "SIGALRM signal setup failed" - ", errno: %d", errno); + fprintf(stderr, + "SIGALRM signal setup failed, errno: %d", + errno); rc = 3; goto err_lock1; } alarm(5); rc = fcntl(fd, F_SETLKW, &flocks[3]); if (rc >= 0) { - fprintf(stderr, "%d: should not succeed to " - "take lock3\n", pid); + fprintf(stderr, + "%d: should not succeed to take lock3\n", + pid); flock_call(fd, 3, FLOCK_PUT, err_lock1); rc = EINVAL; @@ -169,8 +172,9 @@ int main(int argc, char* argv[]) } if (errno != EDEADLK) { rc = errno; - fprintf(stderr, "%d: failed to take lock3: " - "%s\n", pid, strerror(errno)); + fprintf(stderr, + "%d: failed to take lock3: %s\n", pid, + strerror(errno)); goto err_lock1; } @@ -184,7 +188,8 @@ int main(int argc, char* argv[]) flock_call(fd, 1, FLOCK_GET, err_lock0); /* Let flocks[2] 2nd child get granted and - * flocks[3] 1st child, flocks[0] parent get blocked.*/ + * flocks[3] 1st child, flocks[0] parent get blocked. + */ printf("%d sleeping 2\n", pid); sleep(2); @@ -200,8 +205,9 @@ int main(int argc, char* argv[]) flock_call(fd, num, FLOCK_GET, err_lock0); - /* Should get blocked on flocks[0], 1st shild - * and succeed later. */ + /* Should get blocked on flocks[0], 1st child + * and succeed later. + */ flock_call(fd, 0, FLOCK_GET, err_lock1); flock_call(fd, 0, FLOCK_PUT, err_lock1); diff --git a/lustre/tests/flocks_test.c b/lustre/tests/flocks_test.c index 476506e..0ae537d0 100644 --- a/lustre/tests/flocks_test.c +++ b/lustre/tests/flocks_test.c @@ -53,9 +53,7 @@ static double now(void) return (double)tv.tv_sec + (double)tv.tv_usec / 1000000; } -/** - * helper functions - */ +/* helper functions */ static int t_fcntl(int fd, int cmd, ...) { va_list ap; @@ -129,9 +127,8 @@ static int t_unlink(const char *path) return rc; } -/** ================================================================= +/* * test number 1 - * * normal flock test */ static void t1_usage(void) @@ -198,9 +195,8 @@ out: return rc; } -/** =============================================================== +/* * test number 2 - * * 2 threads flock ops interweave */ struct thread_info { @@ -306,7 +302,7 @@ out: return rc; } -/** ================================================================= +/* * test number 3 * * Bug 24040: Two conflicting flocks from same process different fds should fail @@ -692,15 +688,13 @@ static int t6(int argc, char *argv[]) return rc; } -/** ============================================================== - * program entry - */ static void usage(void) { fprintf(stderr, "usage: flocks_test test# [corresponding arguments]\n"); } +/* program entry */ int main(int argc, char *argv[]) { int rc = EXIT_SUCCESS; diff --git a/lustre/tests/fsx.c b/lustre/tests/fsx.c index 9290f72..2a043d3 100644 --- a/lustre/tests/fsx.c +++ b/lustre/tests/fsx.c @@ -1443,8 +1443,7 @@ do_mirror_ops(int op) rc = WEXITSTATUS(rc); if (rc > 0) { prt("%s: %d\n", cmd, rc); - /** - * mirror split won't delete the last non-stale mirror, + /* mirror split won't delete the last non-stale mirror, * and returns EUCLEAN */ if (rc != EUCLEAN) diff --git a/lustre/tests/ll_sparseness_write.c b/lustre/tests/ll_sparseness_write.c index c0d1bd5..aea1f2b 100644 --- a/lustre/tests/ll_sparseness_write.c +++ b/lustre/tests/ll_sparseness_write.c @@ -47,7 +47,7 @@ * Return: 0 success * 1 failure */ -int main(int argc, char**argv) +int main(int argc, char **argv) { int p_size; unsigned int offset; diff --git a/lustre/tests/llapi_fid_test.c b/lustre/tests/llapi_fid_test.c index 21122ac..641ea57 100644 --- a/lustre/tests/llapi_fid_test.c +++ b/lustre/tests/llapi_fid_test.c @@ -100,7 +100,8 @@ static void cleanup(void) } /* Helper - call path2fid, fd2fid and fid2path against an existing - * file/directory */ + * file/directory + */ static void helper_fid2path(const char *filename, int fd) { struct lu_fid fid; @@ -138,8 +139,7 @@ static void helper_fid2path(const char *filename, int fd) ASSERTF(rc == 0, "llapi_fid2path failed for fid %s: %s", fidstr, strerror(-rc)); - /* Make sure both calls to llapi_fid2path returned the same - * data. */ + /* Make sure both calls to llapi_fid2path returned the same data. */ ASSERTF(strcmp(path1, path2) == 0, "paths are different: '%s' / '%s'", path1, path2); ASSERTF(recno1 == recno2, "recnos are different: %lld / %lld", @@ -155,8 +155,7 @@ static void helper_fid2path(const char *filename, int fd) ASSERTF(rc == 0, "llapi_fid2path failed for fid %s: %s", fidstr, strerror(-rc)); - /* Make sure both calls to llapi_fid2path returned the same - * data. */ + /* Make sure both calls to llapi_fid2path returned the same data. */ ASSERTF(strcmp(path1, path2) == 0, "paths are different: '%s' / '%s'", path1, path2); ASSERTF(recno1 == recno2, "recnos are different: %lld / %lld", @@ -174,8 +173,7 @@ static void helper_fid2path(const char *filename, int fd) "fids are different"); } - /* Pass the result back to fid2path and ensure the fid stays - * the same. */ + /* Pass result back to fid2path and ensure the fid stays the same. */ rc = snprintf(path3, sizeof(path3), "%s/%s", mnt_dir, path1); ASSERTF((rc > 0 && rc < sizeof(path3)), "invalid name"); rc = llapi_path2fid(path3, &fid2); @@ -223,7 +221,8 @@ static void test10(void) mainpath, strerror(errno)); /* Against a char device. Use same as /dev/null in case things - * go wrong. */ + * go wrong. + */ rc = stat("/dev/null", &statbuf); ASSERTF(rc == 0, "stat failed for /dev/null: %s", strerror(errno)); rc = mknod(mainpath, S_IFCHR, statbuf.st_rdev); @@ -315,8 +314,7 @@ static void test12(void) close(fd); - /* Check the file can still be opened, since fd2 is not - * closed. */ + /* Check the file can still be opened, since fd2 is not closed. */ fd3 = llapi_open_by_fid(mainpath, &fid, O_RDONLY); ASSERTF(fd3 >= 0, "llapi_open_by_fid for " DFID_NOBRACE ": %s", PFID(&fid), strerror(errno)); @@ -342,20 +340,21 @@ static void test20(void) ASSERTF((rc > 0 && rc < sizeof(testpath)), "invalid name for testpath '%s'", mainpath); - rc = mkdir(testpath, S_IRWXU); + rc = mkdir(testpath, 0700); ASSERTF(rc == 0, "mkdir failed for '%s': %s", testpath, strerror(errno)); len = strlen(testpath); /* Create subdirectories as long as we can. Each new subdir is - * "/x", so we need at least 3 characters left in testpath. */ + * "/x", so we need at least 3 characters left in testpath. + */ while (len <= sizeof(testpath) - 3) { strncat(testpath, "/x", sizeof(testpath) - 1); len += 2; - rc = mkdir(testpath, S_IRWXU); + rc = mkdir(testpath, 0700); ASSERTF(rc == 0, "mkdir failed for '%s': %s", testpath, strerror(errno)); @@ -368,8 +367,8 @@ static void test20(void) helper_fid2path(testpath, -1); /* Make sure we have created enough directories. Even with a - * reasonably long mountpath, we should have created at least - * 2000. */ + * reasonably long mountpath, we should have created at least 2000. + */ ASSERTF(dir_created >= 2000, "dir_created=%d -- '%s'", dir_created, testpath); } @@ -377,10 +376,10 @@ static void test20(void) /* Test linkno from fid2path */ static void test30(void) { - /* Note that since the links are stored in the extended - * attributes, only a few of these will fit (about 150 in this - * test). Still, create more than that to ensure the system - * doesn't break. See LU-5746. */ + /* Note that since the links are stored in the extended attributes, + * only a few of these will fit (about 150 in this test). Still, create + * more than that to ensure the system doesn't break. See LU-5746. + */ const int num_links = 1000; struct { char filename[PATH_MAX]; @@ -462,26 +461,26 @@ static void test30(void) ASSERTF(found == true, "link '%s' not found", buf2); if (linkno == i) { - /* The linkno hasn't changed. This - * means it is the last entry - * stored. */ + /* The linkno hasn't changed. This means it is + * the last entry stored. + */ past_link_limit = true; fprintf(stderr, "Was able to store %d links in the EA\n", i); - /* Also assume that some links were - * returned. It's hard to compute the - * exact value. */ + /* Also assume that some links were returned. + * It's hard to compute the exact value. + */ ASSERTF(i > 50, "not enough links were returned: %d", i); } } else { - /* Past the number of links stored in the EA, - * Lustre will simply return the original - * file. */ + /* Past the number of links stored in the EA, Lustre + * will simply return the original file. + */ ASSERTF(strcmp(buf2, links[0].filename) == 0, "unexpected link for record %d: '%s' / '%s'", i, buf2, links[0].filename); @@ -509,7 +508,8 @@ static void test31(void) } /* Test llapi_fd2parent/llapi_path2parent on mainpath (whatever its - * type). mainpath must exist. */ + * type). mainpath must exist. + */ static void help_test40(void) { struct lu_fid parent_fid; @@ -527,7 +527,8 @@ static void help_test40(void) /* By construction, mainpath is just under lustre_dir, so we * can check that the parent fid of mainpath is indeed the one - * of lustre_dir. */ + * of lustre_dir. + */ rc = llapi_path2fid(lustre_dir, &fid2); ASSERTF(rc == 0, "llapi_path2fid failed for '%s': %s", lustre_dir, strerror(-rc)); @@ -603,7 +604,8 @@ static void test41(void) } /* Test with linkno. Create sub directories, and put a link to the - * original file in them. */ + * original file in them. + */ static void test42(void) { @@ -644,7 +646,7 @@ static void test42(void) /* Create the subdirectories. */ for (i = 0; i < num_links; i++) { - rc = mkdir(links[i].subdir, S_IRWXU); + rc = mkdir(links[i].subdir, 0700); ASSERTF(rc == 0, "mkdir failed for '%s': %s", links[i].subdir, strerror(errno)); @@ -675,7 +677,8 @@ static void test42(void) } /* Query the links, making sure we got all of them. Do it in - * reverse order, just because! */ + * reverse order, just because! + */ for (linkno = num_links-1; linkno >= 0; linkno--) { bool found; @@ -749,10 +752,12 @@ int main(int argc, char *argv[]) } mnt_fd = open(mnt_dir, O_RDONLY|O_DIRECTORY); - ASSERTF(!(mnt_fd < 0), "cannot open '%s': %s\n", mnt_dir, strerror(errno)); + ASSERTF(!(mnt_fd < 0), "cannot open '%s': %s\n", mnt_dir, + strerror(errno)); /* Play nice with Lustre test scripts. Non-line buffered output - * stream under I/O redirection may appear incorrectly. */ + * stream under I/O redirection may appear incorrectly. + */ setvbuf(stdout, NULL, _IOLBF, 0); /* Create a test filename and reuse it. Remove possibly old files. */ diff --git a/lustre/tests/llapi_hsm_test.c b/lustre/tests/llapi_hsm_test.c index 5994431..890fb4a 100644 --- a/lustre/tests/llapi_hsm_test.c +++ b/lustre/tests/llapi_hsm_test.c @@ -33,8 +33,8 @@ */ /* All tests return 0 on success and non zero on error. The program will - * exit as soon a non zero error is returned. */ - + * exit as soon a non zero error is returned. + */ #include #include #include @@ -77,7 +77,8 @@ static bool is_bitmap; } while (0) /* Register and unregister 2000 times. Ensures there is no fd leak - * since there is usually 1024 fd per process. */ + * since there is usually 1024 fd per process. + */ static int test1(void) { int i; @@ -288,8 +289,7 @@ static int test7(void) return 0; } -/* Create the testfile of a given length. It returns a valid file - * descriptor. */ +/* Create the testfile of a given length. It returns a valid file descriptor. */ static char testfile[PATH_MAX]; static int create_testfile(size_t length) { @@ -304,8 +304,9 @@ static int create_testfile(size_t length) unlink(testfile); /* Use truncate so we can create a file (almost) as big as we - * want, while taking 0 bytes of data. */ - fd = creat(testfile, S_IRWXU); + * want, while taking 0 bytes of data. + */ + fd = creat(testfile, 0700); ASSERTF(fd >= 0, "create failed for '%s': %s", testfile, strerror(errno)); @@ -508,8 +509,7 @@ static void test52(void) strerror(-rc)); } -/* Helper to simulate archiving a file. No actual data movement - * happens. */ +/* Helper to simulate archiving a file. No actual data movement happens. */ static void helper_archiving(void (*progress) (struct hsm_copyaction_private *hcp, size_t length), const size_t length) @@ -756,8 +756,7 @@ static void test105_progress(struct hsm_copyaction_private *hcp, size_t length) ASSERTF(hca.hca_action == HUA_ARCHIVE, "hca_state=%u", hca.hca_action); - /* BUG - offset should be 2*length, or length should - * be 8*length */ + /* BUG - offset should be 2*length, or length should be 8*length */ ASSERTF(hca.hca_location.length == 10*length, "length=%llu", (unsigned long long)hca.hca_location.length); } @@ -966,8 +965,7 @@ static void test111(void) helper_archiving(test111_progress, length); } -/* Archive, with 10 reports, and duplicating them, checking - * progress. */ +/* Archive, with 10 reports, and duplicating them, checking progress. */ static void test112_progress(struct hsm_copyaction_private *hcp, size_t length) { int rc; @@ -1100,7 +1098,8 @@ int main(int argc, char *argv[]) } /* Play nice with Lustre test scripts. Non-line buffered output - * stream under I/O redirection may appear incorrectly. */ + * stream under I/O redirection may appear incorrectly. + */ setvbuf(stdout, NULL, _IOLBF, 0); PERFORM(test1); diff --git a/lustre/tests/llapi_layout_test.c b/lustre/tests/llapi_layout_test.c index c402b58..f9051a0 100644 --- a/lustre/tests/llapi_layout_test.c +++ b/lustre/tests/llapi_layout_test.c @@ -174,6 +174,7 @@ static void test1(void) snprintf(path, sizeof(path), "%s/%s", lustre_dir, T0FILE); struct llapi_layout *layout = llapi_layout_get_by_path(path, 0); + ASSERTF(layout != NULL, "errno = %d", errno); __test1_helper(layout); llapi_layout_free(layout); @@ -192,6 +193,7 @@ static void test2(void) ASSERTF(fd >= 0, "open(%s): errno = %d", path, errno); struct llapi_layout *layout = llapi_layout_get_by_fd(fd, 0); + ASSERTF(layout != NULL, "errno = %d", errno); rc = close(fd); @@ -256,6 +258,7 @@ static void test4(void) errno = 0; struct llapi_layout *layout = llapi_layout_get_by_path(path, 0); + ASSERTF(layout != NULL, "errno = %d", errno); rc = llapi_layout_stripe_count_get(layout, &count); @@ -303,6 +306,7 @@ static void test6(void) { errno = 0; struct llapi_layout *layout = llapi_layout_get_by_fd(9999, 0); + ASSERTF(layout == NULL && errno == EBADF, "errno = %d", errno); } @@ -343,13 +347,15 @@ static void test7(void) ASSERTF(rc == 0, "errno = %d", errno); errno = 0; struct llapi_layout *layout = llapi_layout_get_by_path(path, 0); + ASSERTF(layout == NULL && errno == EACCES, "errno = %d", errno); rc = seteuid(myuid); ASSERTF(rc == 0, "errno = %d", errno); } /* llapi_layout_get_by_path() returns default layout for file with no - * striping attributes. */ + * striping attributes. + */ #define T8FILE "t8" #define T8_DESC "llapi_layout_get_by_path ENODATA handling" static void test8(void) @@ -954,7 +960,7 @@ static void test22(void) rc = unlink(path); ASSERTF(rc == 0 || errno == ENOENT, "errno = %d", errno); - umask_orig = umask(S_IWGRP | S_IWOTH); + umask_orig = umask(0022); fd = llapi_layout_file_create(path, 0, mode_in, NULL); ASSERTF(fd >= 0, "errno = %d", errno); @@ -994,7 +1000,8 @@ static void test23(void) } /* llapi_layout_get_by_path(path, LAYOUT_GET_EXPECTED) returns expected layout - * for file with unspecified layout. */ + * for file with unspecified layout. + */ #define T24FILE "t24" #define T24_DESC "LAYOUT_GET_EXPECTED works with existing file" static void test24(void) @@ -1035,7 +1042,8 @@ static void test24(void) } /* llapi_layout_get_by_path(path, LAYOUT_GET_EXPECTED) returns expected layout - * for directory with unspecified layout. */ + * for directory with unspecified layout. + */ #define T25DIR "d25" #define T25_DESC "LAYOUT_GET_EXPECTED works with directory" static void test25(void) @@ -1073,7 +1081,8 @@ static void test25(void) } /* llapi_layout_get_by_path(path, LAYOUT_GET_EXPECTED) correctly combines - * specified attributes of parent directory with attributes filesystem root. */ + * specified attributes of parent directory with attributes filesystem root. + */ #define T26DIR "d26" #define T26_DESC "LAYOUT_GET_EXPECTED partially specified parent" #define T26_STRIPE_SIZE (1048576 * 4) @@ -1121,7 +1130,8 @@ static void test26(void) } /* llapi_layout_get_by_path(path, LAYOUT_GET_EXPECTED) work with - * non existing file. */ + * non existing file. + */ #define T27DIR "d27" #define T27_DESC "LAYOUT_GET_EXPECTED with non existing file" #define T27_STRIPE_SIZE (1048576 * 3) @@ -1172,7 +1182,8 @@ static void test27(void) } /* llapi_layout_stripe_count_get returns LLAPI_LAYOUT_WIDE for a directory - * with a stripe_count of -1. */ + * with a stripe_count of -1. + */ #define T28DIR "d28" #define T28_DESC "LLAPI_LAYOUT_WIDE returned as expected" static void test28(void) @@ -1353,7 +1364,8 @@ static void test30(void) ASSERTF(rc == 0, "errno %d", errno); /* add component without adjusting previous component's extent - * end will fail. */ + * end will fail. + */ rc = llapi_layout_comp_add(layout); ASSERTF(rc == -1 && errno == EINVAL, "rc %d, errno %d", rc, errno); @@ -1695,8 +1707,8 @@ static void test34(void) ASSERTF(rc == 0, "errno %d", errno); /* Set extension space flag on adjacent components: - * This is invalid, but can't be checked until we try to create the - * file. */ + * This is invalid, but can't be checked until we create the file. + */ rc = llapi_layout_comp_flags_set(layout, LCME_FL_EXTENSION); ASSERTF(rc == 0, "errno %d", errno); @@ -1710,8 +1722,7 @@ static void test34(void) rc = llapi_layout_comp_add(layout); ASSERTF(rc == 0, "errno %d", errno); - /* Convert this comp to zero-length so it can be followed by extension - * space */ + /* Convert this comp to 0-len that can be followed by extension space */ rc = llapi_layout_comp_extent_set(layout, start[2], start[2]); ASSERTF(rc == 0, "errno %d", errno); @@ -1797,7 +1808,8 @@ static void print_test_desc(int test_num, const char *test_desc, } /* This function runs a single test by forking the process. This way, - * if there is a segfault during a test, the test program won't crash. */ + * if there is a segfault during a test, the test program won't crash. + */ static int test(void (*test_fn)(), const char *test_desc, bool test_skip, int test_num) { @@ -1834,7 +1846,8 @@ static int test(void (*test_fn)(), const char *test_desc, bool test_skip, print_test_desc(test_num, test_desc, status_buf); } else if (pid == 0) { /* Run the test in the child process. Exit with 0 for success, - * non-zero for failure */ + * non-zero for failure + */ test_fn(); exit(0); } @@ -1947,11 +1960,13 @@ int main(int argc, char *argv[]) } /* Play nice with Lustre test scripts. Non-line buffered output - * stream under I/O redirection may appear incorrectly. */ + * stream under I/O redirection may appear incorrectly. + */ setvbuf(stdout, NULL, _IOLBF, 0); for (i = 0; i < NUM_TESTS; i++) { struct test_tbl_entry *tst = &test_tbl[i]; + if (test(tst->tte_fn, tst->tte_desc, tst->tte_skip, i) != 0) rc++; } diff --git a/lustre/tests/llapi_root_test.c b/lustre/tests/llapi_root_test.c index 628dac4..319bcb2 100644 --- a/lustre/tests/llapi_root_test.c +++ b/lustre/tests/llapi_root_test.c @@ -204,7 +204,8 @@ int main(int argc, char *argv[]) if (strcmp(basename(mainpath), basename(mainpath2)) != 0 || strcmp(mainpath, mainpath2) == 0) { - fprintf(stderr, "%s and %s should be the same file on 2 distinct mountpoints\n", + fprintf(stderr, + "%s and %s should be the same file on 2 distinct mountpoints\n", mainpath, mainpath2); return EXIT_FAILURE; } @@ -224,16 +225,19 @@ int main(int argc, char *argv[]) } if (strcmp(fsname, fsname2) != 0) { - fprintf(stderr, "%s and %s are not on the same filesystem (%s, %s)\n", + fprintf(stderr, + "%s and %s are not on the same filesystem (%s, %s)\n", mnt_dir, mnt_dir2, fsname, fsname2); return EXIT_FAILURE; } mnt_fd = open(mnt_dir, O_RDONLY|O_DIRECTORY); - ASSERTF(mnt_fd >= 0, "cannot open '%s': %s\n", mnt_dir, strerror(errno)); + ASSERTF(mnt_fd >= 0, "cannot open '%s': %s\n", mnt_dir, + strerror(errno)); mnt_fd2 = open(mnt_dir2, O_RDONLY|O_DIRECTORY); - ASSERTF(mnt_fd2 >= 0, "cannot open '%s': %s\n", mnt_dir2, strerror(errno)); + ASSERTF(mnt_fd2 >= 0, "cannot open '%s': %s\n", mnt_dir2, + strerror(errno)); fprintf(stderr, "Starting: %s %s %s\n\n", basename(argv[0]), mainpath, mainpath2); diff --git a/lustre/tests/lockahead_test.c b/lustre/tests/lockahead_test.c index 3373242..6f4af9b 100644 --- a/lustre/tests/lockahead_test.c +++ b/lustre/tests/lockahead_test.c @@ -115,7 +115,7 @@ static int test10(void) int rc; char buf[write_size]; - fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); + fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, 0600); ASSERTF(fd >= 0, "open failed for '%s': %s", mainpath, strerror(errno)); @@ -155,7 +155,7 @@ static int test11(void) int i; int enqueue_requests = 0; - fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); + fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, 0600); ASSERTF(fd >= 0, "open failed for '%s': %s", mainpath, strerror(errno)); @@ -225,7 +225,7 @@ static int test12(void) int i; int expected_lock_count = 0; - fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); + fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, 0600); ASSERTF(fd >= 0, "open failed for '%s': %s", mainpath, strerror(errno)); @@ -246,7 +246,8 @@ static int test12(void) i, advice[i].lla_lockahead_result); } /* Since all the requests are for the same extent, we should only have - * one lock at the end. */ + * one lock at the end. + */ expected_lock_count = 1; /* Ask again until we get the locks. */ @@ -288,7 +289,7 @@ static int test13(void) int i; int expected_lock_count = 0; - fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); + fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, 0600); ASSERTF(fd >= 0, "open failed for '%s': %s", mainpath, strerror(errno)); @@ -355,7 +356,7 @@ static int test14(void) const int num_blocks = 100; int expected_lock_count = 0; - fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); + fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, 0600); ASSERTF(fd >= 0, "open failed for '%s': %s", mainpath, strerror(errno)); @@ -423,7 +424,7 @@ static int test15(void) int i; int expected_lock_count = 0; - fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); + fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, 0600); ASSERTF(fd >= 0, "open failed for '%s': %s", mainpath, strerror(errno)); @@ -431,7 +432,8 @@ static int test15(void) for (i = 0; i < 100; i++) { /* The 'UL' designators are required to avoid undefined - * behavior which GCC turns in to an infinite loop */ + * behavior which GCC turns in to an infinite loop + */ __u64 start = i * 1024UL * 1024UL * 10UL; __u64 end = start + 1; @@ -471,14 +473,14 @@ static int test15(void) ASSERTF(rc == sizeof(buf), "write failed for '%s': %s", mainpath, strerror(errno)); /* The write should cancel the first lock (which was too small) - * and create one of its own, so the net effect on lock count is 0. */ + * and create one of its own, so the net effect on lock count is 0. + */ free(advice); close(fd); - /* We have to map our expected return in to the range of valid return - * codes, 0-255. */ + /* have to map expected return to range of valid values, 0-255 */ expected_lock_count = expected_lock_count/100; return expected_lock_count; @@ -498,7 +500,7 @@ static int test16(void) char buf[write_size]; int expected_lock_count = 0; - fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); + fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, 0600); ASSERTF(fd >= 0, "open failed for '%s': %s", mainpath, strerror(errno)); @@ -590,7 +592,8 @@ static int test16(void) } /* Use lockahead to verify behavior of ladvise locknoexpand, with O_NONBLOCK. - * There should be no change in behavior. */ + * There should be no change in behavior. + */ static int test17(void) { struct llapi_lu_ladvise *advice; @@ -604,8 +607,7 @@ static int test17(void) char buf[write_size]; int expected_lock_count = 0; - fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC | O_NONBLOCK, - S_IRUSR | S_IWUSR); + fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC | O_NONBLOCK, 0600); ASSERTF(fd >= 0, "open failed for '%s': %s", mainpath, strerror(errno)); @@ -706,7 +708,7 @@ static int test18(void) int i; int expected_lock_count = 0; - fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); + fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, 0600); ASSERTF(fd >= 0, "open failed for '%s': %s", mainpath, strerror(errno)); @@ -769,14 +771,15 @@ static int test19(void) int i; int expected_lock_count = 0; - fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); + fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, 0600); ASSERTF(fd >= 0, "open failed for '%s': %s", mainpath, strerror(errno)); advice = malloc(sizeof(struct llapi_lu_ladvise)*count); /* This should create a lock on the whole file, which will block lock - * ahead requests. */ + * ahead requests. + */ memset(buf, 0xaa, write_size); rc = write(fd, buf, write_size); ASSERTF(rc == sizeof(buf), "write failed for '%s': %s", @@ -822,7 +825,7 @@ static int test20(void) int i; int expected_lock_count = 1; - fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); + fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, 0600); ASSERTF(fd >= 0, "open failed for '%s': %s", mainpath, strerror(errno)); @@ -857,7 +860,8 @@ static int test20(void) advice.lla_lockahead_result); /* Convert to a sync request on smaller range, should match and not - * cancel */ + * cancel + */ setup_ladvise_lockahead(&advice, MODE_WRITE_USER, 0, 0, write_size - 1 - write_size/2, false); @@ -904,7 +908,7 @@ static int test21(void) int i; int expected_lock_count = 1; - fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); + fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, 0600); ASSERTF(fd >= 0, "open failed for '%s': %s", mainpath, strerror(errno)); @@ -939,7 +943,8 @@ static int test21(void) advice.lla_lockahead_result); /* Convert to a sync request on larger range, should cancel existing - * lock */ + * lock + */ setup_ladvise_lockahead(&advice, MODE_WRITE_USER, 0, 0, write_size*2 - 1, false); @@ -984,7 +989,7 @@ static int test22(void) size_t start = 0; size_t end = 0; - fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); + fd = open(mainpath, O_CREAT | O_RDWR | O_TRUNC, 0600); ASSERTF(fd >= 0, "open failed for '%s': %s", mainpath, strerror(errno)); @@ -1101,12 +1106,12 @@ static int test23(void) int rc; int i; - fd = open(mainpath, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); + fd = open(mainpath, O_CREAT | O_RDWR, 0600); ASSERTF(fd >= 0, "open failed for '%s': %s", mainpath, strerror(errno)); /* mainpath2 is a different Lustre mount */ - fd2 = open(mainpath2, O_RDWR, S_IRUSR | S_IWUSR); + fd2 = open(mainpath2, O_RDWR, 0600); ASSERTF(fd2 >= 0, "open failed for '%s': %s", mainpath2, strerror(errno)); @@ -1258,7 +1263,8 @@ int main(int argc, char *argv[]) } /* Play nice with Lustre test scripts. Non-line buffered output - * stream under I/O redirection may appear incorrectly. */ + * stream under I/O redirection may appear incorrectly. + */ setvbuf(stdout, NULL, _IOLBF, 0); /* Create a test filename and reuse it. Remove possibly old files. */ @@ -1296,7 +1302,8 @@ int main(int argc, char *argv[]) /* When running all the test cases, we can't use the return * from the last test case, as it might be non-zero to return * info, rather than for an error. Test cases assert and exit - * if an error occurs. */ + * if an error occurs. + */ rc = 0; break; case 10: diff --git a/lustre/tests/memhog.c b/lustre/tests/memhog.c index ce3a914..b7c47aa 100644 --- a/lustre/tests/memhog.c +++ b/lustre/tests/memhog.c @@ -49,9 +49,10 @@ int main(int argc, char *argv[]) if (argc == 2) { char *end = NULL; + kbtotal = strtoull(argv[1], &end, 0); - switch(*end) { + switch (*end) { case 'g': case 'G': kbtotal *= 1024; @@ -85,7 +86,8 @@ int main(int argc, char *argv[]) alloc = CHUNK; printf("[%d] allocating %lld kbytes in %u kbyte chunks\n", getpid(), kbtotal, alloc); - for (i = kballoc = 0; i < numchunk && alloc > 0; i++, kballoc += alloc){ + for (i = kballoc = 0; i < numchunk && alloc > 0; i++, + kballoc += alloc) { if (kbtotal - kballoc < alloc) alloc = kbtotal - kballoc; diff --git a/lustre/tests/mmap_sanity.c b/lustre/tests/mmap_sanity.c index a55936c..f3cc90f 100644 --- a/lustre/tests/mmap_sanity.c +++ b/lustre/tests/mmap_sanity.c @@ -131,7 +131,7 @@ static int mmap_initialize(char *myself) return rc; } -static void mmap_finalize() +static void mmap_finalize(void) { unlink(mmap_sanity); } diff --git a/lustre/tests/reads.c b/lustre/tests/reads.c index d42dc97..9b1e98e 100644 --- a/lustre/tests/reads.c +++ b/lustre/tests/reads.c @@ -120,7 +120,7 @@ int main(int argc, char **argv) usage(); return RR_PARSE; case 'v': - verbosity ++; + verbosity++; break; case 'f': fname = strdup(optarg); @@ -128,7 +128,8 @@ int main(int argc, char **argv) case 's': size = strtol(optarg, &term, 0); if (term == optarg) { - fprintf (stderr, "Can't parse size %s\n", optarg); + fprintf(stderr, "Can't parse size %s\n", + optarg); usage(); return RR_SET; } @@ -136,7 +137,8 @@ int main(int argc, char **argv) case 'b': bsize = strtol(optarg, &term, 0); if (term == optarg) { - fprintf (stderr, "Can't parse bsize %s\n", optarg); + fprintf(stderr, "Can't parse bsize %s\n", + optarg); usage(); return RR_SET; } @@ -144,7 +146,8 @@ int main(int argc, char **argv) case 'a': ad = (int)strtol(optarg, &term, 0); if (term == optarg) { - fprintf (stderr, "Can't parse ad %s\n", optarg); + fprintf(stderr, "Can't parse ad %s\n", + optarg); usage(); return RR_SET; } @@ -155,7 +158,8 @@ int main(int argc, char **argv) case 'S': seed = strtol(optarg, &term, 0); if (term == optarg) { - fprintf (stderr, "Can't parse seed %s\n", optarg); + fprintf(stderr, "Can't parse seed %s\n", + optarg); usage(); return RR_SET; } @@ -163,7 +167,8 @@ int main(int argc, char **argv) case 'n': iterations = strtol(optarg, &term, 0); if (term == optarg) { - fprintf (stderr, "Can't parse seed %s\n", optarg); + fprintf(stderr, "Can't parse seed %s\n", + optarg); usage(); return RR_SET; } @@ -173,23 +178,26 @@ int main(int argc, char **argv) case 't': timelimit = strtol(optarg, &term, 0); if (term == optarg) { - fprintf (stderr, "Can't parse seed %s\n", optarg); + fprintf(stderr, "Can't parse seed %s\n", + optarg); usage(); return RR_SET; } break; - case 'l': - stride_length = strtol(optarg, &term, 0); + case 'l': + stride_length = strtol(optarg, &term, 0); if (term == optarg) { - fprintf (stderr, "Can't parse seed %s\n", optarg); + fprintf(stderr, "Can't parse seed %s\n", + optarg); usage(); return RR_SET; } - break; + break; case 'o': stride_offset = strtol(optarg, &term, 0); if (term == optarg) { - fprintf (stderr, "Can't parse seed %s\n", optarg); + fprintf(stderr, "Can't parse seed %s\n", + optarg); usage(); return RR_SET; } @@ -197,7 +205,8 @@ int main(int argc, char **argv) case 'w': width = (int)strtol(optarg, &term, 0); if (term == optarg) { - fprintf (stderr, "Can't parse seed %s\n", optarg); + fprintf(stderr, "Can't parse seed %s\n", + optarg); usage(); return RR_SET; } @@ -246,12 +255,12 @@ int main(int argc, char **argv) srand(seed); gettimeofday(&start, NULL); timelimit += start.tv_sec; - for (i = 0; !iterations || i < iterations; i ++) { + for (i = 0; !iterations || i < iterations; i++) { unsigned long block_nr; int j; - if (stride_length) - block_nr = (unsigned long)(i*stride_length + + if (stride_length) + block_nr = (unsigned long)(i*stride_length + stride_offset) % nblocks; else block_nr = (unsigned long)((double)nblocks*rand()/ diff --git a/lustre/tests/rename_many.c b/lustre/tests/rename_many.c index 6e1164e..7522072 100644 --- a/lustre/tests/rename_many.c +++ b/lustre/tests/rename_many.c @@ -106,7 +106,7 @@ int main(int argc, char *argv[]) int i, c; while ((c = getopt(argc, argv, "cf:n:rs:vx")) != EOF) { - switch(c) { + switch (c) { case 'c': ++opt_create_only; break; @@ -115,7 +115,8 @@ int main(int argc, char *argv[]) if (i && end != NULL && *end == '\0') { file_count = i; } else { - fprintf(stderr, "bad file count '%s'\n",optarg); + fprintf(stderr, "bad file count '%s'\n", + optarg); usage(argv[0]); return 1; } @@ -125,7 +126,8 @@ int main(int argc, char *argv[]) if (i && end != NULL && *end == '\0') { loop_count = i; } else { - fprintf(stderr, "bad loop count '%s'\n",optarg); + fprintf(stderr, "bad loop count '%s'\n", + optarg); usage(argv[0]); return 1; } @@ -157,7 +159,7 @@ int main(int argc, char *argv[]) names = malloc(sizeof(struct names) * file_count); if (names == NULL) { perror("calloc"); - return(1); + return 1; } h2 = sprintf(msg, "%x", file_count); /* just to figure length */ @@ -189,16 +191,16 @@ int main(int argc, char *argv[]) } while (!stop && loop_count != 0 && loops < loop_count) { - int j,k,l,m; + int j, k, l, m; srand(seed + loops); - if (mkdir("tmp", S_IRWXU) == -1) { + if (mkdir("tmp", 0700) == -1) { perror("mkdir tmp"); - return(1); + return 1; } if (chdir("tmp") == -1) { perror("chdir tmp"); - return(1); + return 1; } for (i = 0; i < file_count ; i++) { @@ -214,7 +216,7 @@ int main(int argc, char *argv[]) } for (i = 0; i < file_count; i++) { - if (mknod(names[i].from, S_IFREG | S_IRWXU, 0) == -1) { + if (mknod(names[i].from, S_IFREG | 0700, 0) == -1) { sprintf(msg, "loop %d.%d: creat %s", loops, i, names[i].from); perror(msg); @@ -254,18 +256,18 @@ int main(int argc, char *argv[]) if (chdir("..") == -1) { perror("chdir .."); - return(1); + return 1; } if (rmdir("tmp") == -1) { if (chdir("tmp") == -1) { perror("chdir tmp 2"); - return(1); + return 1; } for (i = 0; i < file_count; i++) { if (unlink(names[i].from) != -1) { - fprintf(stderr, "loop %d.%d: " - "unexpected file %s\n", + fprintf(stderr, + "loop %d.%d: unexpected file %s\n", loops, i, names[i].to); unlink_errors++; if (!opt_exit_on_err) @@ -274,11 +276,11 @@ int main(int argc, char *argv[]) } if (chdir("..") == -1) { perror("chdir .. 2"); - return(1); + return 1; } if (rmdir("tmp") == -1) { perror("rmdir tmp"); - return(1); + return 1; } } @@ -289,5 +291,5 @@ int main(int argc, char *argv[]) if (!opt_verbose) handler(0); - return(0); + return 0; } diff --git a/lustre/tests/sendfile_grouplock.c b/lustre/tests/sendfile_grouplock.c index c293fd6..e0b74ce 100644 --- a/lustre/tests/sendfile_grouplock.c +++ b/lustre/tests/sendfile_grouplock.c @@ -116,8 +116,8 @@ static int crc_table_computed; static void make_crc_table(void) { unsigned long c; - int n, k; + for (n = 0; n < 256; n++) { c = (unsigned long) n; for (k = 0; k < 8; k++) { @@ -205,7 +205,8 @@ static unsigned long compute_crc(const char *fname) } /* Helper. Copy a file with sendfile. The destination will be - * created. If a group lock is 0, it means do not take one. */ + * created. If a group lock is 0, it means do not take one. + */ static int sendfile_copy(const char *source, int source_gid, const char *dest, int dest_gid) { @@ -253,8 +254,8 @@ static int sendfile_copy(const char *source, int source_gid, /* Although senfile can return less than requested, * that should not happen under present conditions. At * the very least, make sure that a decent size was - * copied. See LU-6371. */ - + * copied. See LU-6371. + */ ASSERTF(sret != 0, "sendfile read 0 bytes"); ASSERTF(sret > 0, "sendfile failed: %s", strerror(rc)); ASSERTF(sret > 100*1024, @@ -384,7 +385,8 @@ int main(int argc, char *argv[]) } /* Play nice with Lustre test scripts. Non-line buffered output - * stream under I/O redirection may appear incorrectly. */ + * stream under I/O redirection may appear incorrectly. + */ setvbuf(stdout, NULL, _IOLBF, 0); cleanup(); diff --git a/lustre/tests/small_write.c b/lustre/tests/small_write.c index 26c0f94..8d62a26 100644 --- a/lustre/tests/small_write.c +++ b/lustre/tests/small_write.c @@ -38,7 +38,8 @@ #define GOTO(label, rc) do { rc; goto label; } while (0) -int main (int argc, char **argv) { +int main(int argc, char **argv) +{ int fd, i, rc = 0; unsigned long bytes, lbytes; struct stat st; @@ -76,7 +77,7 @@ int main (int argc, char **argv) { GOTO(out_str2, rc = 6); } - for(i=0; i < bytes; i++) + for (i = 0; i < bytes; i++) str[i] = 'a' + (i % 26); str[i] = '\0'; @@ -104,7 +105,7 @@ int main (int argc, char **argv) { if (rc < 0 || st.st_size != bytes) { printf("bad file %lu size first write %lu != %lu: rc %d\n", (unsigned long)st.st_ino, (unsigned long)st.st_size, - bytes, rc); + bytes, rc); GOTO(out_fd, rc = 9); } @@ -124,7 +125,7 @@ int main (int argc, char **argv) { if (rc < 0 || st.st_size != bytes + bytes / 2) { printf("bad file %lu size second write %lu != %lu: rc %d\n", (unsigned long)st.st_ino, (unsigned long)st.st_size, - bytes, rc); + bytes, rc); GOTO(out_fd, rc = 12); } @@ -145,7 +146,7 @@ int main (int argc, char **argv) { if (rc < 0 || st.st_size != bytes + bytes / 2) { printf("bad file size after read %lu != %lu: rc %d\n", (unsigned long)st.st_size, bytes + bytes / 2, - rc); + rc); GOTO(out_fd, rc = 14); } @@ -164,11 +165,11 @@ int main (int argc, char **argv) { out_fd: close(fd); out_readbuf: - free(readbuf); + free(readbuf); out_str2: - free(str2); + free(str2); out_str: - free(str); + free(str); out: - return rc; + return rc; } diff --git a/lustre/tests/statx.c b/lustre/tests/statx.c index 7a98b33..b0c23b3 100644 --- a/lustre/tests/statx.c +++ b/lustre/tests/statx.c @@ -171,11 +171,9 @@ static char const printf_flags[] = "'-+ #0I"; /* Formats for the --terse option. */ static char const fmt_terse_fs[] = "%n %i %l %t %s %S %b %f %a %c %d\n"; -static char const fmt_terse_regular[] = "%n %s %b %f %u %g %D %i %h %t %T" - " %X %Y %Z %W %o\n"; +static char const fmt_terse_regular[] = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %W %o\n"; #ifdef HAVE_SELINUX -static char const fmt_terse_selinux[] = "%n %s %b %f %u %g %D %i %h %t %T" - " %X %Y %Z %W %o %C\n"; +static char const fmt_terse_selinux[] = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %W %o %C\n"; #endif static char *format; @@ -315,21 +313,21 @@ static char ftypelet(mode_t bits) static void strmode(mode_t mode, char *str) { str[0] = ftypelet(mode); - str[1] = mode & S_IRUSR ? 'r' : '-'; - str[2] = mode & S_IWUSR ? 'w' : '-'; + str[1] = mode & 0400 ? 'r' : '-'; + str[2] = mode & 0200 ? 'w' : '-'; str[3] = (mode & S_ISUID - ? (mode & S_IXUSR ? 's' : 'S') - : (mode & S_IXUSR ? 'x' : '-')); - str[4] = mode & S_IRGRP ? 'r' : '-'; - str[5] = mode & S_IWGRP ? 'w' : '-'; + ? (mode & 0100 ? 's' : 'S') + : (mode & 0100 ? 'x' : '-')); + str[4] = mode & 0040 ? 'r' : '-'; + str[5] = mode & 0020 ? 'w' : '-'; str[6] = (mode & S_ISGID - ? (mode & S_IXGRP ? 's' : 'S') - : (mode & S_IXGRP ? 'x' : '-')); - str[7] = mode & S_IROTH ? 'r' : '-'; - str[8] = mode & S_IWOTH ? 'w' : '-'; + ? (mode & 0010 ? 's' : 'S') + : (mode & 0010 ? 'x' : '-')); + str[7] = mode & 0004 ? 'r' : '-'; + str[8] = mode & 0002 ? 'w' : '-'; str[9] = (mode & S_ISVTX - ? (mode & S_IXOTH ? 't' : 'T') - : (mode & S_IXOTH ? 'x' : '-')); + ? (mode & 0001 ? 't' : 'T') + : (mode & 0001 ? 'x' : '-')); str[10] = ' '; str[11] = '\0'; } @@ -382,19 +380,6 @@ static void strmode(mode_t mode, char *str) static void filemodestring(struct statx const *stxp, char *str) { strmode(stxp->stx_mode, str); - -/* - if (S_TYPEISSEM(statp)) - str[0] = 'F'; - else if (IS_MIGRATED_FILE (statp)) - str[0] = 'M'; - else if (S_TYPEISMQ (statp)) - str[0] = 'Q'; - else if (S_TYPEISSHM (statp)) - str[0] = 'S'; - else if (S_TYPEISTMO (statp)) - str[0] = 'T'; - */ } /* gnulib/lib/file-type.c */ @@ -862,6 +847,7 @@ static void out_epoch_sec(char *pformat, size_t prefix_len, if (w > 1) { char *dst = pformat; char const *src = dst; + for (; src < p; src++) { if (*src == '-') frac_left_adjust = true; @@ -950,18 +936,17 @@ static int out_file_context(char *pformat, size_t prefix_len, /* Map a TS with negative TS.tv_nsec to {0,0}. */ static inline struct timespec neg_to_zero(struct timespec ts) { - if (ts.tv_nsec >= 0) { + if (ts.tv_nsec >= 0) return ts; - } else { - struct timespec z = {0, 0}; - return z; - } + struct timespec z = {0, 0}; + + return z; } /* All the mode bits that can be affected by chmod. */ #define CHMOD_MODE_BITS \ - (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) + (S_ISUID | S_ISGID | S_ISVTX | 0700 | 0070 | 0007) /* Print statx info. Return zero upon success, nonzero upon failure. */ static int print_statx(char *pformat, size_t prefix_len, unsigned int m, diff --git a/lustre/tests/swap_lock_test.c b/lustre/tests/swap_lock_test.c index f7760ee..ad8103a 100644 --- a/lustre/tests/swap_lock_test.c +++ b/lustre/tests/swap_lock_test.c @@ -95,8 +95,7 @@ static void cleanup(void) "rm command returned %d", WEXITSTATUS(rc)); } -/* Create a filename inside the test directory. Will assert on - * error. */ +/* Create a filename inside the test directory. Will assert on error. */ static char *create_file_name(const char *name) { char *filename; @@ -109,7 +108,8 @@ static char *create_file_name(const char *name) } /* Create a file of a given size in the test directory, filed with - * c. Will assert on error. */ + * character 'c'. Will assert on error. + */ static int create_file(const char *name, size_t size, unsigned char c) { int fd; @@ -201,8 +201,7 @@ static void test11(void) close(fd1); } -/* Test self swap, on different handles. It's a no-op and will always - * succeed. */ +/* Test self swap, on different handles. Is a no-op and will always succeed. */ static void test12(void) { int rc; @@ -247,7 +246,8 @@ static void test13(void) * operations. In the first swap, fd1 is on Lustre, so the * ioctl will succeed, but its processing will eventually fail * because fd2 is not on Lustre. In the second swap, the ioctl - * request is unknown, so ioctl() will directly fail. */ + * request is unknown, so ioctl() will directly fail. + */ rc = llapi_fswap_layouts(fd1, fd2, 0, 0, 0); ASSERTF(rc == -EINVAL, "llapi_fswap_layouts failed: %s", strerror(-rc)); @@ -269,9 +269,9 @@ static void test14(void) ASSERTF(rc == -EBADF, "llapi_fswap_layouts failed: %s", strerror(-rc)); - /* When run under a shell, rc is -EINVAL. When run under - * Lustre test suite, stdin is redirected, and rc is - * -ENOTTY. Catch both cases. */ + /* When run under a shell, rc is -EINVAL. When run under Lustre test + * suite, stdin is redirected, and rc is -ENOTTY. Catch both cases. + */ rc = llapi_fswap_layouts(0, 0, 0, 0, 0); ASSERTF(rc == -EINVAL || rc == -ENOTTY, "llapi_fswap_layouts failed: %s", @@ -641,8 +641,7 @@ static void test20(void) ASSERTF(rc == 0, "llapi_fswap_layouts failed: %s", strerror(-rc)); - /* Read from fd1. Its file pointer is now positioned inside - * the new data. */ + /* Read from fd1. file pointer is now positioned inside the new data. */ rc = read(fd1, buf, 1); ASSERTF(rc == 1, "read 1 byte on foo1 failed: %s", strerror(errno)); ASSERTF(buf[0] == 'y', "invalid data found on foo2: %x", buf[0]); @@ -653,8 +652,7 @@ static void test20(void) "invalid size found: %llu instead of %zu", (unsigned long long)stbuf.st_size, foo1_size); - /* Read from fd2. After the swap, the file pointer is past the - * data. */ + /* Read from fd2. After the swap, the file pointer is past the data. */ rc = read(fd2, buf, 1); ASSERTF(rc == 0, "unexpected read returned rc=%d (errno %s)", rc, strerror(errno)); @@ -731,7 +729,8 @@ static void test31(void) fd3 = create_file("foo3", foo3_size, 'z'); /* Note: swapping 3 fd this way will be back to original - * layouts every 2 loops. */ + * layouts every 2 loops. + */ for (i = 0; i < 999; i++) { rc = llapi_fswap_layouts(fd1, fd2, 0, 0, 0); ASSERTF(rc == 0, "llapi_fswap_layouts failed: %s", @@ -862,9 +861,9 @@ static void test42(void) ASSERTF(rc == 0, "mkdir failed for '%s': %s", mainpath, strerror(errno)); - /* Get dataversion for two files. - * Make sure values are different so that the following checks make - * sense. */ + /* Get dataversion for two files. Make sure values are different so that + * the following checks make sense. + */ fd1 = create_file("foo1", foo1_size, 'x'); rc = llapi_get_data_version(fd1, &dv1, LL_DV_RD_FLUSH); @@ -1141,7 +1140,8 @@ static void test54(void) } /* Swap group lock, lock a descriptor, and try to swap with it, on - * second descriptor. */ + * second descriptor. + */ static void test55(void) { int rc; @@ -1172,8 +1172,7 @@ static void test55(void) close(fd2); } -/* Swap group lock, lock a descriptor, and try to swap with another - * one. */ +/* Swap group lock, lock a descriptor, and try to swap with another one. */ static void test56(void) { int rc; @@ -1211,8 +1210,7 @@ static void test56(void) close(fd2); } -/* Swap group lock, lock both descriptor, and try to swap with another - * one. */ +/* Swap group lock, lock both descriptor, and try to swap with another one. */ static void test57(void) { int rc; @@ -1251,7 +1249,8 @@ static void test57(void) } /* Swap group lock, lock both descriptor with same gid, and try to - * swap with it. */ + * swap with it. + */ static void test58(void) { int rc; @@ -1288,8 +1287,7 @@ static void test58(void) close(fd2); } -/* Swap group lock, lock both descriptor with same gid, and swap with - * none. */ +/* Swap group lock, lock both descriptor with same gid, and swap with none. */ static void test59(void) { int rc; @@ -1367,7 +1365,8 @@ int main(int argc, char *argv[]) } /* Play nice with Lustre test scripts. Non-line buffered output - * stream under I/O redirection may appear incorrectly. */ + * stream under I/O redirection may appear incorrectly. + */ setvbuf(stdout, NULL, _IOLBF, 0); /* Create a test filename and reuse it. Remove possibly old files. */ -- 1.8.3.1