7 #include <sys/socket.h>
8 #include <sys/sendfile.h>
10 #include <sys/socket.h>
12 #include <liblustre.h>
13 #include <lnet/lnetctl.h>
15 #include <lustre_lib.h>
17 #include <lustre/liblustreapi.h>
19 #define syserr(str) { perror(str); exit(-1); }
21 int main(int argc, char *argv[])
31 int page_size = sysconf(_SC_PAGESIZE);
35 fprintf(stderr, "%s <source file> <dest file>\n", argv[0]);
42 if (stat(sfile, &stbuf) < 0) {
43 if (errno == ENOENT) {
44 /* assume doing non-object file testing */
45 infd = open(sfile, O_LOV_DELAY_CREATE|O_CREAT|O_RDWR,
48 syserr("open source file:");
50 size = random() % (1 * 1024 * 1024) + 1024;
51 if (ftruncate(infd, (off_t)size) < 0)
52 syserr("truncate file error:");
54 syserr("stat file: ");
56 } else if (S_ISREG(stbuf.st_mode)) {
57 size = (int)stbuf.st_size;
58 infd = open(sfile, O_RDONLY, 0644);
60 syserr("Open an existing file error:");
62 fprintf(stderr, "%s is not a regular file\n", sfile);
66 outfd = open(tfile, O_WRONLY|O_TRUNC|O_CREAT, 0666);
68 syserr("open dest file:");
70 rc = socketpair(AF_LOCAL, SOCK_STREAM, 0, sd);
79 seg_size = (size < page_size) ? size : (random() % size + 1);
80 if (seg_size > 4 * page_size)
81 seg_size = 4 * page_size;
82 rc = sendfile(sd[0], infd, &pos, seg_size);
90 buf = malloc(seg_size);
91 rc = read(sd[1], buf, seg_size);
93 syserr("read from socket:");
95 rc2 = write(outfd, buf, rc);
97 syserr("write dest file error:");
100 close(sd[1]), close(infd), close(outfd);
102 sprintf(cmd, "cmp %s %s\n", sfile, tfile);