summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
74056cd)
Cleanup numerous code style issues in the mmap_sanity.c test:
- whitespace at end of line
- spaces around operators
- indentation
- line wrapping at 80 columns
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: I7481d358732effa58875cbf2a2d545bf741ecab0
Reviewed-on: http://review.whamcloud.com/2291
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Yu Jian <yujian@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
long page_size;
char mmap_sanity[256];
long page_size;
char mmap_sanity[256];
static void usage(void)
{
printf("Usage: mmap_sanity -d dir [-m dir2]\n");
static void usage(void)
{
printf("Usage: mmap_sanity -d dir [-m dir2]\n");
child = fork();
if (child < 0)
child = fork();
if (child < 0)
else if (child)
return 0;
if (dir2 != NULL) {
rc = remote_tst(tc, dir2);
} else {
else if (child)
return 0;
if (dir2 != NULL) {
rc = remote_tst(tc, dir2);
} else {
fprintf(stderr, "invalid argument!\n");
}
_exit(rc);
fprintf(stderr, "invalid argument!\n");
}
_exit(rc);
{
char buf[1024], *file;
int fdr, fdw, count, rc = 0;
{
char buf[1024], *file;
int fdr, fdw, count, rc = 0;
page_size = sysconf(_SC_PAGESIZE);
if (page_size == -1) {
perror("sysconf(_SC_PAGESIZE)");
page_size = sysconf(_SC_PAGESIZE);
if (page_size == -1) {
perror("sysconf(_SC_PAGESIZE)");
}
/* copy myself to lustre for another client */
fdr = open(myself, O_RDONLY);
if (fdr < 0) {
perror(myself);
}
/* copy myself to lustre for another client */
fdr = open(myself, O_RDONLY);
if (fdr < 0) {
perror(myself);
}
file = strrchr(myself, '/');
if (file == NULL) {
fprintf(stderr, "can't get test filename\n");
close(fdr);
}
file = strrchr(myself, '/');
if (file == NULL) {
fprintf(stderr, "can't get test filename\n");
close(fdr);
}
file++;
sprintf(mmap_sanity, "%s/%s", dir, file);
}
file++;
sprintf(mmap_sanity, "%s/%s", dir, file);
if (fdw < 0) {
perror(mmap_sanity);
close(fdr);
if (fdw < 0) {
perror(mmap_sanity);
close(fdr);
}
while ((count = read(fdr, buf, sizeof(buf))) != 0) {
int writes;
if (count < 0) {
perror("read()");
}
while ((count = read(fdr, buf, sizeof(buf))) != 0) {
int writes;
if (count < 0) {
perror("read()");
break;
}
writes = write(fdw, buf, count);
if (writes != count) {
perror("write()");
break;
}
writes = write(fdw, buf, count);
if (writes != count) {
perror("write()");
region = page_size * 10;
sprintf(mmap_file, "%s/%s", mnt, "mmap_file1");
region = page_size * 10;
sprintf(mmap_file, "%s/%s", mnt, "mmap_file1");
if (unlink(mmap_file) && errno != ENOENT) {
perror("unlink()");
if (unlink(mmap_file) && errno != ENOENT) {
perror("unlink()");
}
fd = open(mmap_file, O_CREAT|O_RDWR, 0600);
if (fd < 0) {
perror(mmap_file);
}
fd = open(mmap_file, O_CREAT|O_RDWR, 0600);
if (fd < 0) {
perror(mmap_file);
}
if (ftruncate(fd, region) < 0) {
perror("ftruncate()");
}
if (ftruncate(fd, region) < 0) {
perror("ftruncate()");
goto out_close;
}
ptr = mmap(NULL, region, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap()");
goto out_close;
}
ptr = mmap(NULL, region, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap()");
goto out_close;
}
memset(ptr, 'a', region);
goto out_close;
}
memset(ptr, 'a', region);
if (unlink(mmap_file) && errno != ENOENT) {
perror("unlink()");
if (unlink(mmap_file) && errno != ENOENT) {
perror("unlink()");
}
fd = open(mmap_file, O_CREAT|O_RDWR, 0600);
if (fd < 0) {
perror(mmap_file);
}
fd = open(mmap_file, O_CREAT|O_RDWR, 0600);
if (fd < 0) {
perror(mmap_file);
}
if (ftruncate(fd, page_size) < 0) {
perror("ftruncate()");
}
if (ftruncate(fd, page_size) < 0) {
perror("ftruncate()");
goto out_close;
}
ptr = mmap(NULL, page_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap()");
goto out_close;
}
ptr = mmap(NULL, page_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap()");
goto out_close;
}
memcpy(ptr, "blah", strlen("blah"));
goto out_close;
}
memcpy(ptr, "blah", strlen("blah"));
out_close:
close(fd);
if (rc)
out_close:
close(fd);
if (rc)
fd = open(mmap_file, O_RDONLY);
if (fd < 0) {
perror(mmap_file);
fd = open(mmap_file, O_RDONLY);
if (fd < 0) {
perror(mmap_file);
}
rc = read(fd, buf, sizeof(buf));
if (rc < 0) {
perror("read()");
}
rc = read(fd, buf, sizeof(buf));
if (rc < 0) {
perror("read()");
goto out_close;
}
rc = 0;
goto out_close;
}
rc = 0;
if (strncmp("blah", buf, strlen("blah")) == 0) {
fprintf(stderr, "mmap write back with MAP_PRIVATE!\n");
if (strncmp("blah", buf, strlen("blah")) == 0) {
fprintf(stderr, "mmap write back with MAP_PRIVATE!\n");
}
close(fd);
unlink(mmap_file);
}
close(fd);
unlink(mmap_file);
region = page_size * 100;
sprintf(mmap_file, "%s/%s", mnt, "mmap_file3");
region = page_size * 100;
sprintf(mmap_file, "%s/%s", mnt, "mmap_file3");
if (unlink(mmap_file) && errno != ENOENT) {
perror("unlink()");
if (unlink(mmap_file) && errno != ENOENT) {
perror("unlink()");
}
fd = open(mmap_file, O_CREAT|O_RDWR, 0600);
if (fd < 0) {
perror(mmap_file);
}
fd = open(mmap_file, O_CREAT|O_RDWR, 0600);
if (fd < 0) {
perror(mmap_file);
}
if (ftruncate(fd, region) < 0) {
perror("ftruncate()");
}
if (ftruncate(fd, region) < 0) {
perror("ftruncate()");
goto out_close;
}
ptr = mmap(NULL, region, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap()");
goto out_close;
}
ptr = mmap(NULL, region, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap()");
goto out_close;
}
rc = mmap_run(3);
if (rc)
goto out_unmap;
goto out_close;
}
rc = mmap_run(3);
if (rc)
goto out_unmap;
memset(ptr, 'a', region);
sleep(2); /* wait for remote test finish */
out_unmap:
memset(ptr, 'a', region);
sleep(2); /* wait for remote test finish */
out_unmap:
close(fd);
unlink(mmap_file);
return rc;
close(fd);
unlink(mmap_file);
return rc;
static int remote_tst3(char *mnt)
{
static int remote_tst3(char *mnt)
{
fd = open(mmap_file, O_RDWR, 0600);
if (fd < 0) {
perror(mmap_file);
fd = open(mmap_file, O_RDWR, 0600);
if (fd < 0) {
perror(mmap_file);
}
ptr = mmap(NULL, region, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap()");
}
ptr = mmap(NULL, region, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap()");
goto out_close;
}
memset(ptr, 'b', region);
memset(ptr, 'c', region);
goto out_close;
}
memset(ptr, 'b', region);
memset(ptr, 'c', region);
munmap(ptr, region);
out_close:
close(fd);
munmap(ptr, region);
out_close:
close(fd);
if (unlink(filea) && errno != ENOENT) {
perror("unlink()");
if (unlink(filea) && errno != ENOENT) {
perror("unlink()");
}
if (unlink(fileb) && errno != ENOENT) {
perror("unlink()");
}
if (unlink(fileb) && errno != ENOENT) {
perror("unlink()");
}
fdr = fdw = -1;
fdr = open(fileb, O_CREAT|O_RDWR, 0600);
if (fdr < 0) {
perror(fileb);
}
fdr = fdw = -1;
fdr = open(fileb, O_CREAT|O_RDWR, 0600);
if (fdr < 0) {
perror(fileb);
}
if (ftruncate(fdr, region) < 0) {
perror("ftruncate()");
}
if (ftruncate(fdr, region) < 0) {
perror("ftruncate()");
goto out_close;
}
fdw = open(filea, O_CREAT|O_RDWR, 0600);
if (fdw < 0) {
perror(filea);
goto out_close;
}
fdw = open(filea, O_CREAT|O_RDWR, 0600);
if (fdw < 0) {
perror(filea);
goto out_close;
}
if (ftruncate(fdw, region) < 0) {
perror("ftruncate()");
goto out_close;
}
if (ftruncate(fdw, region) < 0) {
perror("ftruncate()");
ptr = mmap(NULL, region, PROT_READ|PROT_WRITE, MAP_SHARED, fdr, 0);
if (ptr == MAP_FAILED) {
perror("mmap()");
ptr = mmap(NULL, region, PROT_READ|PROT_WRITE, MAP_SHARED, fdr, 0);
if (ptr == MAP_FAILED) {
perror("mmap()");
goto out_close;
}
rc = mmap_run(4);
if (rc)
goto out_unmap;
goto out_close;
}
rc = mmap_run(4);
if (rc)
goto out_unmap;
memset(ptr, '1', region);
memset(ptr, '1', region);
rc = write(fdw, ptr, region);
if (rc <= 0) {
perror("write()");
rc = write(fdw, ptr, region);
if (rc <= 0) {
perror("write()");
fdr = open(filea, O_RDWR, 0600);
if (fdr < 0) {
perror(filea);
fdr = open(filea, O_RDWR, 0600);
if (fdr < 0) {
perror(filea);
}
fdw = open(fileb, O_RDWR, 0600);
if (fdw < 0) {
perror(fileb);
}
fdw = open(fileb, O_RDWR, 0600);
if (fdw < 0) {
perror(fileb);
goto out_close;
}
ptr = mmap(NULL, region, PROT_READ|PROT_WRITE, MAP_SHARED, fdr, 0);
if (ptr == MAP_FAILED) {
perror("mmap()");
goto out_close;
}
ptr = mmap(NULL, region, PROT_READ|PROT_WRITE, MAP_SHARED, fdr, 0);
if (ptr == MAP_FAILED) {
perror("mmap()");
rc = write(fdw, ptr, region);
if (rc <= 0) {
perror("write()");
rc = write(fdw, ptr, region);
if (rc <= 0) {
perror("write()");
munmap(ptr, region);
out_close:
if (fdr >= 0)
munmap(ptr, region);
out_close:
if (fdr >= 0)
child = fork();
if (child < 0)
child = fork();
if (child < 0)
else if (child) {
int status;
rc = waitpid(child, &status, WNOHANG);
else if (child) {
int status;
rc = waitpid(child, &status, WNOHANG);
- sprintf(cmd, "ls /proc/fs/lustre/ldlm/namespaces/*-%s-*/lru_size", prefix);
+ sprintf(cmd,
+ "ls /proc/fs/lustre/ldlm/namespaces/*-%s-*/lru_size",
+ prefix);
else
sprintf(cmd, "ls /proc/fs/lustre/ldlm/namespaces/*/lru_size");
file = popen(cmd, "r");
if (file == NULL) {
perror("popen()");
else
sprintf(cmd, "ls /proc/fs/lustre/ldlm/namespaces/*/lru_size");
file = popen(cmd, "r");
if (file == NULL) {
perror("popen()");
}
while (fgets(line, len, file)) {
}
while (fgets(line, len, file)) {
f = fopen(line, "w");
if (f == NULL) {
perror("fopen()");
f = fopen(line, "w");
if (f == NULL) {
perror("fopen()");
break;
}
rc = fwrite("clear", strlen("clear") + 1, 1, f);
if (rc < 1) {
perror("fwrite()");
break;
}
rc = fwrite("clear", strlen("clear") + 1, 1, f);
if (rc < 1) {
perror("fwrite()");
if (unlink(mmap_file) && errno != ENOENT) {
perror("unlink()");
if (unlink(mmap_file) && errno != ENOENT) {
perror("unlink()");
}
fd = open(mmap_file, O_CREAT|O_RDWR, 0600);
if (fd < 0) {
perror(mmap_file);
}
fd = open(mmap_file, O_CREAT|O_RDWR, 0600);
if (fd < 0) {
perror(mmap_file);
}
if (ftruncate(fd, region) < 0) {
perror("ftruncate()");
}
if (ftruncate(fd, region) < 0) {
perror("ftruncate()");
goto out_close;
}
ptr = mmap(NULL, region, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap()");
goto out_close;
}
ptr = mmap(NULL, region, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap()");
goto out_close;
}
memset(ptr, 'a', region);
goto out_close;
}
memset(ptr, 'a', region);
rc = read(fd, ptr + off, off * 2);
if (rc != off * 2) {
perror("read()");
rc = read(fd, ptr + off, off * 2);
if (rc != off * 2) {
perror("read()");
goto out_unmap;
}
rc = write(fd, ptr + off, off * 2);
if (rc != off * 2) {
perror("write()");
goto out_unmap;
}
rc = write(fd, ptr + off, off * 2);
if (rc != off * 2) {
perror("write()");
sprintf(mmap_file2, "%s/%s", dir2, "mmap_file6");
if (unlink(mmap_file) && errno != ENOENT) {
perror("unlink()");
sprintf(mmap_file2, "%s/%s", dir2, "mmap_file6");
if (unlink(mmap_file) && errno != ENOENT) {
perror("unlink()");
}
fd = open(mmap_file, O_CREAT|O_RDWR, 0600);
if (fd < 0) {
perror(mmap_file);
}
fd = open(mmap_file, O_CREAT|O_RDWR, 0600);
if (fd < 0) {
perror(mmap_file);
}
if (ftruncate(fd, page_size) < 0) {
perror("ftruncate()");
}
if (ftruncate(fd, page_size) < 0) {
perror("ftruncate()");
goto out;
}
fd2 = open(mmap_file2, O_RDWR, 0600);
if (fd2 < 0) {
perror(mmap_file2);
goto out;
}
fd2 = open(mmap_file2, O_RDWR, 0600);
if (fd2 < 0) {
perror(mmap_file2);
goto out;
}
ptr = mmap(NULL, page_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap()");
goto out;
}
ptr = mmap(NULL, page_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap()");
ptr2 = mmap(NULL, page_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd2, 0);
if (ptr2 == MAP_FAILED) {
perror("mmap()");
ptr2 = mmap(NULL, page_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd2, 0);
if (ptr2 == MAP_FAILED) {
perror("mmap()");
memcpy(ptr, "blah", strlen("blah"));
if (strncmp(ptr, ptr2, strlen("blah"))) {
fprintf(stderr, "client2 mmap mismatch!\n");
memcpy(ptr, "blah", strlen("blah"));
if (strncmp(ptr, ptr2, strlen("blah"))) {
fprintf(stderr, "client2 mmap mismatch!\n");
goto out;
}
memcpy(ptr2, "foo", strlen("foo"));
if (strncmp(ptr, ptr2, strlen("foo"))) {
fprintf(stderr, "client1 mmap mismatch!\n");
goto out;
}
memcpy(ptr2, "foo", strlen("foo"));
if (strncmp(ptr, ptr2, strlen("foo"))) {
fprintf(stderr, "client1 mmap mismatch!\n");
- if (snprintf(fname, 256, "%s/mmap_tst7.%s",
- mnt, (rw == 0) ? "read":"write") >= 256) {
+ if (snprintf(fname, 256, "%s/mmap_tst7.%s", mnt,
+ (rw == 0) ? "read" : "write") >= 256) {
fprintf(stderr, "dir name too long\n");
fprintf(stderr, "dir name too long\n");
goto out;
}
fd = open(fname, O_RDWR | O_DIRECT | O_CREAT, 0644);
if (fd == -1) {
perror("open");
goto out;
}
fd = open(fname, O_RDWR | O_DIRECT | O_CREAT, 0644);
if (fd == -1) {
perror("open");
goto out;
}
if (ftruncate(fd, 2 * page_size) == -1) {
perror("truncate");
goto out;
}
if (ftruncate(fd, 2 * page_size) == -1) {
perror("truncate");
goto out;
}
buf = mmap(NULL, page_size * 2,
PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (buf == MAP_FAILED) {
perror("mmap");
goto out;
}
buf = mmap(NULL, page_size * 2,
PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (buf == MAP_FAILED) {
perror("mmap");
goto out;
}
/* ensure the second page isn't mapped */
munmap(buf + page_size, page_size);
bytes = (rw == 0) ? read(fd, buf, 2 * page_size) :
goto out;
}
/* ensure the second page isn't mapped */
munmap(buf + page_size, page_size);
bytes = (rw == 0) ? read(fd, buf, 2 * page_size) :
- write(fd, buf, 2 * page_size);
+ write(fd, buf, 2 * page_size);
/* Expected behavior */
if (bytes == page_size)
goto out;
/* Expected behavior */
if (bytes == page_size)
goto out;
fprintf(stderr, "%s returned %zd, errno = %d\n",
fprintf(stderr, "%s returned %zd, errno = %d\n",
- (rw == 0)?"read":"write", bytes, errno);
- rc = EIO;
+ (rw == 0) ? "read" : "write", bytes, errno);
+ rc = -EIO;
out:
if (buf != MAP_FAILED)
munmap(buf, page_size);
out:
if (buf != MAP_FAILED)
munmap(buf, page_size);
if (snprintf(fname, 256, "%s/mmap_tst8", mnt) >= 256) {
fprintf(stderr, "dir name too long\n");
if (snprintf(fname, 256, "%s/mmap_tst8", mnt) >= 256) {
fprintf(stderr, "dir name too long\n");
goto out;
}
fd = open(fname, O_RDWR | O_CREAT, 0644);
if (fd == -1) {
perror("open");
goto out;
}
fd = open(fname, O_RDWR | O_CREAT, 0644);
if (fd == -1) {
perror("open");
goto out;
}
if (ftruncate(fd, page_size) == -1) {
perror("truncate");
goto out;
}
if (ftruncate(fd, page_size) == -1) {
perror("truncate");
goto out;
}
buf = mmap(NULL, page_size * 2,
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (buf == MAP_FAILED) {
perror("mmap");
goto out;
}
buf = mmap(NULL, page_size * 2,
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (buf == MAP_FAILED) {
perror("mmap");
pid = waitpid(pid, &status, 0);
if (pid < 0) {
perror("wait");
pid = waitpid(pid, &status, 0);
if (pid < 0) {
perror("wait");
if (WIFSIGNALED(status) && SIGBUS == WTERMSIG(status))
rc = 0;
} else {
perror("fork");
if (WIFSIGNALED(status) && SIGBUS == WTERMSIG(status))
rc = 0;
} else {
perror("fork");
static int remote_tst(int tc, char *mnt)
{
int rc = 0;
static int remote_tst(int tc, char *mnt)
{
int rc = 0;
case 3:
rc = remote_tst3(mnt);
break;
case 3:
rc = remote_tst3(mnt);
break;
break;
default:
fprintf(stderr, "wrong test case number %d\n", tc);
break;
default:
fprintf(stderr, "wrong test case number %d\n", tc);
struct test_case {
int tc; /* test case number */
char *desc; /* test description */
struct test_case {
int tc; /* test case number */
char *desc; /* test description */
- int (* test_fn)(char *mnt); /* test function */
+ int (*test_fn)(char *mnt); /* test function */
int node_cnt; /* node count */
};
int node_cnt; /* node count */
};
{ 1, "mmap test1: basic mmap operation", mmap_tst1, 1 },
{ 2, "mmap test2: MAP_PRIVATE not write back", mmap_tst2, 1 },
{ 3, "mmap test3: concurrent mmap ops on two nodes", mmap_tst3, 2 },
{ 1, "mmap test1: basic mmap operation", mmap_tst1, 1 },
{ 2, "mmap test2: MAP_PRIVATE not write back", mmap_tst2, 1 },
{ 3, "mmap test3: concurrent mmap ops on two nodes", mmap_tst3, 2 },
- { 4, "mmap test4: c1 write to f1 from mmapped f2, "
+ { 4, "mmap test4: c1 write to f1 from mmapped f2, "
"c2 write to f1 from mmapped f1", mmap_tst4, 2 },
{ 5, "mmap test5: read/write file to/from the buffer "
"which mmapped to just this file", mmap_tst5, 1 },
"c2 write to f1 from mmapped f1", mmap_tst4, 2 },
{ 5, "mmap test5: read/write file to/from the buffer "
"which mmapped to just this file", mmap_tst5, 1 },
- { 6, "mmap test6: check mmap write/read content on two nodes",
+ { 6, "mmap test6: check mmap write/read content on two nodes",
mmap_tst6, 2 },
{ 7, "mmap test7: file i/o with an unmapped buffer", mmap_tst7, 1},
{ 8, "mmap test8: SIGBUS for beyond file size", mmap_tst8, 1},
mmap_tst6, 2 },
{ 7, "mmap test7: file i/o with an unmapped buffer", mmap_tst7, 1},
{ 8, "mmap test8: SIGBUS for beyond file size", mmap_tst8, 1},
int main(int argc, char **argv)
{
int main(int argc, char **argv)
{
struct test_case *test;
int c, rc = 0;
struct test_case *test;
int c, rc = 0;
- for(;;) {
- c = getopt(argc, argv, "d:m:");
- if ( c == -1 )
+ while ((c = getopt(argc, argv, "d:m:")) != -1) {
+ switch (c) {
+ case 'd':
+ dir = optarg;
+ break;
+ case 'm':
+ dir2 = optarg;
+ break;
+ default:
+ usage();
-
- switch(c) {
- case 'd':
- dir = optarg;
- break;
- case 'm':
- dir2 = optarg;
- break;
- default:
- case '?':
- usage();
- break;
if (mmap_initialize(argv[0]) != 0) {
fprintf(stderr, "mmap_initialize failed!\n");
if (mmap_initialize(argv[0]) != 0) {
fprintf(stderr, "mmap_initialize failed!\n");
}
for (test = tests; test->tc; test++) {
}
for (test = tests; test->tc; test++) {