1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
41 #include <sys/types.h>
42 #include <sys/socket.h>
43 #include <sys/sendfile.h>
45 #include <sys/socket.h>
47 #include <liblustre.h>
48 #include <lnet/lnetctl.h>
50 #include <lustre_lib.h>
52 #include <lustre/liblustreapi.h>
54 #define syserr(str) { perror(str); exit(-1); }
56 int main(int argc, char *argv[])
61 unsigned long bufsize = 1024 * 1024;
70 fprintf(stderr, "%s <source file> <dest file>\n", argv[0]);
77 if (stat(sfile, &stbuf) < 0) {
78 if (errno == ENOENT) {
79 /* assume doing non-object file testing */
80 infd = open(sfile, O_LOV_DELAY_CREATE|O_CREAT|O_RDWR,
83 syserr("open source file:");
85 size = random() % (1 * 1024 * 1024) + 1024;
86 if (ftruncate(infd, (off_t)size) < 0)
87 syserr("truncate file error:");
89 syserr("stat file: ");
91 } else if (S_ISREG(stbuf.st_mode)) {
92 size = (int)stbuf.st_size;
93 infd = open(sfile, O_RDONLY, 0644);
95 syserr("Open an existing file error:");
97 fprintf(stderr, "%s is not a regular file\n", sfile);
101 outfd = open(tfile, O_WRONLY|O_TRUNC|O_CREAT, 0666);
103 syserr("open dest file:");
105 rc = socketpair(AF_LOCAL, SOCK_STREAM, 0, sd);
107 syserr("socketpair");
109 rc = fcntl(sd[0], F_SETFL, O_NONBLOCK);
113 rc = setsockopt(sd[0], SOL_SOCKET, SO_SNDBUF,
114 &bufsize, sizeof(bufsize));
116 syserr("setsockopt");
125 seg_size = random() % bufsize + 1;
130 rc = sendfile(sd[0], infd, &pos, seg_size);
140 if (read(sd[1], buf, rc) < 0)
141 syserr("read from socket:");
143 rc2 = write(outfd, buf, rc);
145 syserr("write dest file error:");
149 close(sd[1]), close(infd), close(outfd);
151 sprintf(cmd, "cmp %s %s\n", sfile, tfile);