1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
5 * Author: You Feng <youfeng@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <sys/types.h>
31 #include <sys/ioctl.h>
34 #include "lustre/lustre_user.h"
37 #define MAX_PROCESSES 8
44 struct timeval t1, t2;
47 static char datestring[80];
51 timestamp = time(NULL);
52 strftime(datestring, 80, "%T", localtime(×tamp));
57 inline void begin(char *str) {
58 if (verbose > 0 && rank == 0) {
59 gettimeofday(&t1, NULL);
60 printf("%s:\tBeginning %s\n", timestamp(), str);
65 inline void end(char *str) {
68 MPI_Barrier(MPI_COMM_WORLD);
69 if (verbose > 0 && rank == 0) {
70 gettimeofday(&t2, NULL);
71 elapsed = (t2.tv_sec + ((float)t2.tv_usec/1000000))
72 - (t1.tv_sec + ((float)t1.tv_usec/1000000));
74 printf("%s:\tFinished %-15s(%.2f min)\n",
75 timestamp(), str, elapsed / 60);
77 printf("%s:\tFinished %-15s(%.3f sec)\n",
78 timestamp(), str, elapsed);
85 void dump_diff(char *orig_buf, char *buf, int size, long _off)
90 printf("commpared buf size %d, at offset %lu\n\n", size, _off);
93 printf("original buf:\n");
95 end = orig_buf + size;
98 printf(" %8lx", *(long *)p);
103 if (i%8) printf("\n\n");
108 printf("different data: diff_data(orig_data)\n");
115 if (memcmp(p, orig_buf + off, sizeof(long)) != 0) {
116 printf("\toff: %5d,\tdata: %8lx (%8lx)\n", off,
118 *(unsigned long *)(orig_buf + off));
124 printf("\n %d total differents found\n\n", diff);
128 void lp_gethostname(void)
130 if (gethostname(hostname, 1024) == -1) {
131 fprintf(stderr, "gethostname: (%d)%s", errno, strerror(errno));
132 MPI_Abort(MPI_COMM_WORLD, 2);
136 /* This function does not FAIL if the requested "name" does not exit.
137 * This is just to clean up any files or directories left over from
140 void remove_file_or_dir(char *name)
143 char errmsg[MAX_FILENAME_LEN + 20];
145 if (stat(name, &statbuf) != -1) {
146 if (S_ISREG(statbuf.st_mode)) {
147 printf("stale file found\n");
148 if (unlink(name) == -1) {
149 sprintf(errmsg, "unlink of %s", name);
153 if (S_ISDIR(statbuf.st_mode)) {
154 printf("stale directory found\n");
155 if (rmdir(name) == -1) {
156 sprintf(errmsg, "rmdir of %s", name);
163 void create_file(char *name, long filesize, int fill)
165 static char filename[MAX_FILENAME_LEN];
166 char errmsg[MAX_FILENAME_LEN + 20];
171 long left = filesize;
173 /* Process 0 creates the test file(s) */
175 sprintf(filename, "%s/%s", testdir, name);
176 remove_file_or_dir(filename);
177 if ((fd = creat(filename, FILEMODE)) == -1) {
178 sprintf(errmsg, "create of file %s", filename);
182 if (lseek(fd, filesize - 1, SEEK_SET) == -1) {
184 sprintf(errmsg, "lseek of file %s", filename);
187 if (write(fd, &zero, 1) == -1) {
189 sprintf(errmsg, "write of file %s", filename);
193 if (filesize > 0 && fill) {
194 if (lseek(fd, 0, SEEK_SET) == -1) {
196 sprintf(errmsg, "lseek of file %s", filename);
199 memset(buf, c, 1024);
201 if ((rc = write(fd, buf,
202 left > (1024 * 8) ? (1024 * 8) : left))
205 sprintf(errmsg, "write of file %s", filename);
211 if (close(fd) == -1) {
212 sprintf(errmsg, "close of file %s", filename);
218 void check_stat(char *filename, struct stat *state, struct stat *old_state)
220 char errmsg[MAX_FILENAME_LEN+20];
222 if (stat(filename, state) == -1) {
223 sprintf(errmsg, "stat of file %s", filename);
227 if (memcmp(state, old_state, sizeof(struct stat)) != 0) {
229 sprintf(errmsg, LP_STAT_FMT, LP_STAT_ARGS);
234 void remove_file(char *name)
236 char filename[MAX_FILENAME_LEN];
237 char errmsg[MAX_FILENAME_LEN + 20];
239 /* Process 0 remove the file(s) */
241 sprintf(filename, "%s/%s", testdir, name);
242 if (unlink(filename) == -1) {
243 sprintf(errmsg, "unlink of file %s", filename);
249 void fill_stride(char *buf, int buf_size, long long rank, long long _off)
252 long long off, data[2];
253 int cp, left = buf_size;
259 cp = left > sizeof(data) ? sizeof(data) : left;