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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
39 #include <sys/types.h>
40 #include <sys/socket.h>
41 #include <sys/sendfile.h>
43 #include <sys/socket.h>
45 #include <liblustre.h>
46 #include <lnet/lnetctl.h>
48 #include <lustre_lib.h>
50 #include <lustre/liblustreapi.h>
52 #define syserr(str) { perror(str); exit(-1); }
54 int main(int argc, char *argv[])
59 unsigned long bufsize = 1024 * 1024;
68 fprintf(stderr, "%s <source file> <dest file>\n", argv[0]);
75 if (stat(sfile, &stbuf) < 0) {
76 if (errno == ENOENT) {
77 /* assume doing non-object file testing */
78 infd = open(sfile, O_LOV_DELAY_CREATE|O_CREAT|O_RDWR,
81 syserr("open source file:");
83 size = random() % (1 * 1024 * 1024) + 1024;
84 if (ftruncate(infd, (off_t)size) < 0)
85 syserr("truncate file error:");
87 syserr("stat file: ");
89 } else if (S_ISREG(stbuf.st_mode)) {
90 size = (int)stbuf.st_size;
91 infd = open(sfile, O_RDONLY, 0644);
93 syserr("Open an existing file error:");
95 fprintf(stderr, "%s is not a regular file\n", sfile);
99 outfd = open(tfile, O_WRONLY|O_TRUNC|O_CREAT, 0666);
101 syserr("open dest file:");
103 rc = socketpair(AF_LOCAL, SOCK_STREAM, 0, sd);
105 syserr("socketpair");
107 rc = fcntl(sd[0], F_SETFL, O_NONBLOCK);
111 rc = setsockopt(sd[0], SOL_SOCKET, SO_SNDBUF,
112 &bufsize, sizeof(bufsize));
114 syserr("setsockopt");
123 seg_size = random() % bufsize + 1;
128 rc = sendfile(sd[0], infd, &pos, seg_size);
138 if (read(sd[1], buf, rc) < 0)
139 syserr("read from socket:");
141 rc2 = write(outfd, buf, rc);
143 syserr("write dest file error:");
147 close(sd[1]), close(infd), close(outfd);
149 sprintf(cmd, "cmp %s %s\n", sfile, tfile);