void create_file(char *name, long filesize, int fill) { static char filename[MAX_FILENAME_LEN]; char errmsg[MAX_FILENAME_LEN + 20]; char buf[1024 * 8]; char c = 'A' + size; int fd, rc; short zero = 0; long left = filesize; /* Process 0 creates the test file(s) */ if (rank == 0) { sprintf(filename, "%s/%s", testdir, name); remove_file_or_dir(filename); if ((fd = creat(filename, FILEMODE)) == -1) { sprintf(errmsg, "create of file %s", filename); FAIL(errmsg); } if (filesize > 0) { if (lseek(fd, filesize - 1, SEEK_SET) == -1) { close(fd); sprintf(errmsg, "lseek of file %s", filename); FAIL(errmsg); } if (write(fd, &zero, 1) == -1) { close(fd); sprintf(errmsg, "write of file %s", filename); FAIL(errmsg); } } if (filesize > 0 && fill) { if (lseek(fd, 0, SEEK_SET) == -1) { close(fd); sprintf(errmsg, "lseek of file %s", filename); FAIL(errmsg); } memset(buf, c, 1024); while (left > 0) { if ((rc = write(fd, buf, left > (1024 * 8) ? (1024 * 8) : left)) == -1) { close(fd); sprintf(errmsg, "write of file %s", filename); FAIL(errmsg); } left -= rc; } } if (close(fd) == -1) { sprintf(errmsg, "close of file %s", filename); FAIL(errmsg); } } }
void rw_file(char *name, long stride, unsigned int seed) { char filename[MAX_FILENAME_LEN]; char errmsg[MAX_FILENAME_LEN+20]; char *buf, *o_buf; struct lov_user_md lum = {0}; int fd, rc, i, bad = 0, root = 0; long off; long page_size = sysconf(_SC_PAGESIZE); sprintf(filename, "%s/%s", testdir, name); if (rank == 0) { remove_file_or_dir(filename); lum.lmm_magic = LOV_USER_MAGIC; lum.lmm_stripe_size = 0; lum.lmm_stripe_count = 0; lum.lmm_stripe_offset = -1; fd = open(filename, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE, FILEMODE); if (fd == -1) { sprintf(errmsg, "open of file %s", filename); FAIL(errmsg); } rc = ioctl(fd, LL_IOC_LOV_SETSTRIPE, &lum); if (rc == -1) { sprintf(errmsg, "ioctl SETSTRIPE of file %s", filename); FAIL(errmsg); } if (close(fd) == -1) { sprintf(errmsg, "close of file %s", filename); FAIL(errmsg); } } MPI_Barrier(MPI_COMM_WORLD); if (stride < 0) { if (rank == 0) { srandom(seed); while (stride < page_size/2) { stride = random(); stride -= stride % 16; if (stride < 0) stride = -stride; stride %= 2 * lum.lmm_stripe_size; } } MPI_Barrier(MPI_COMM_WORLD); MPI_Bcast(&stride, 1, MPI_LONG, root, MPI_COMM_WORLD); } MPI_Barrier(MPI_COMM_WORLD); buf = (char *)malloc(stride); if (buf == NULL) { sprintf(errmsg, "malloc of buf with size %ld", stride); FAIL(errmsg); } if (rank == 0) { fd = open(filename, O_RDWR); if (fd == -1) { sprintf(errmsg, "open of file %s", filename); FAIL(errmsg); } off = 0; fill_stride(buf, stride, 0, off); rc = write(fd, buf, stride); if (rc != stride) { sprintf(errmsg, "write of file %s return %d", filename, rc); FAIL(errmsg); } off += stride; while (off < size * stride) { fill_stride(buf, stride, 0x8080808080808080ULL, off); rc = write(fd, buf, stride); if (rc != stride) { sprintf(errmsg, "write of file %s return %d", filename, rc); FAIL(errmsg); } off += stride; } if (close(fd) == -1) { sprintf(errmsg, "close of file %s", filename); FAIL(errmsg); } } MPI_Barrier(MPI_COMM_WORLD); o_buf = (char *)malloc(stride); if (o_buf == NULL) { sprintf(errmsg, "malloc of o_buf with size %ld", stride); FAIL(errmsg); } fd = open(filename, O_RDWR); if (fd == -1) { sprintf(errmsg, "open of file %s", filename); FAIL(errmsg); } off = 0; for (i = 1; i < size; ++i) { if (rank == i) { rc = lseek(fd, off, SEEK_SET); if (rc != off) { sprintf(errmsg, "lseek of file %s return %d", filename, rc); FAIL(errmsg); } rc = read(fd, buf, stride); if (rc != stride) { if (rc > 0) { fill_stride(o_buf, rc, i - 1, off); dump_diff(o_buf, buf, rc, off); } sprintf(errmsg, "read of file %s return %d", filename, rc); FAIL(errmsg); } fill_stride(o_buf, stride, i - 1, off); if (memcmp(o_buf, buf, stride) != 0) { dump_diff(o_buf, buf, stride, off); errno = 0; sprintf(errmsg, "Error: diff data read from %s", filename); FAIL(errmsg); } } off += stride; if (rank == i) { fill_stride(buf, stride, i, off); rc = write(fd, buf, stride); if (rc != stride) { sprintf(errmsg, "write of file %s return %d", filename, rc); FAIL(errmsg); } } MPI_Barrier(MPI_COMM_WORLD); } if (close(fd) == -1) { sprintf(errmsg, "close of file %s", filename); FAIL(errmsg); } MPI_Barrier(MPI_COMM_WORLD); if (rank == 0) { fd = open(filename, O_RDONLY); if (fd == -1) { sprintf(errmsg, "open of file %s", filename); FAIL(errmsg); } off = 0; for (i = 0; i < size; ++i) { rc = read(fd, buf, stride); if (rc != stride) { if (rc > 0) { fill_stride(o_buf, rc, i, off); dump_diff(o_buf, buf, rc, off); } sprintf(errmsg, "read of file %s", filename); FAIL(errmsg); } fill_stride(o_buf, stride, i, off); if (memcmp(o_buf, buf, stride) != 0) { bad = 1; dump_diff(o_buf, buf, stride, off); } off += stride; } if (bad == 1) { errno = 0; sprintf(errmsg, "Error: diff data read from %s", filename); FAIL(errmsg); } } MPI_Barrier(MPI_COMM_WORLD); fprintf(stderr, "passed barrier 5\n"); free(buf); free(o_buf); }