4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
27 * This file is part of Lustre, http://www.lustre.org/
28 * Lustre is a trademark of Sun Microsystems, Inc.
37 #include <sys/types.h>
38 #include <sys/socket.h>
39 #include <sys/sendfile.h>
41 #include <sys/socket.h>
43 #include <lustre/lustreapi.h>
45 #define syserr(str) { perror(str); exit(-1); }
47 int main(int argc, char *argv[])
52 unsigned long bufsize = 1024 * 1024;
61 fprintf(stderr, "%s <source file> <dest file>\n", argv[0]);
68 if (stat(sfile, &stbuf) < 0) {
69 if (errno == ENOENT) {
70 /* assume doing non-object file testing */
72 O_LOV_DELAY_CREATE | O_CREAT | O_RDWR,
75 syserr("open source file:");
77 size = random() % (1 * 1024 * 1024) + 1024;
78 if (ftruncate(infd, (off_t)size) < 0)
79 syserr("truncate file error:");
81 syserr("stat file: ");
83 } else if (S_ISREG(stbuf.st_mode)) {
84 size = (int)stbuf.st_size;
85 infd = open(sfile, O_RDONLY, 0644);
87 syserr("Open an existing file error:");
89 fprintf(stderr, "%s is not a regular file\n", sfile);
93 outfd = open(tfile, O_WRONLY | O_TRUNC | O_CREAT, 0666);
95 syserr("open dest file:");
97 rc = socketpair(AF_LOCAL, SOCK_STREAM, 0, sd);
101 rc = fcntl(sd[0], F_SETFL, O_NONBLOCK);
105 rc = setsockopt(sd[0], SOL_SOCKET, SO_SNDBUF,
106 &bufsize, sizeof(bufsize));
108 syserr("setsockopt");
117 seg_size = random() % bufsize + 1;
122 rc = sendfile(sd[0], infd, &pos, seg_size);
132 if (read(sd[1], buf, rc) < 0)
133 syserr("read from socket:");
135 rc2 = write(outfd, buf, rc);
137 syserr("write dest file error:");
141 close(sd[1]), close(infd), close(outfd);
143 snprintf(cmd, sizeof(cmd), "cmp %s %s\n", sfile, tfile);