Пример #1
0
/*
 * runtest: write the data to the file. Read the data from the file and compare.
 *	For each iteration, write data starting at offse+iter*bufsize
 *	location in the file and read from there.
*/
int
runtest(int fd_r, int fd_w, int childnum, int action)
{
	off64_t	seekoff;
	int	i, bufsize = BUFSIZE;
	struct  iovec   *iov1, *iov2, *iovp;

	/* Allocate for buffers and data pointers */
	seekoff = offset+bufsize * childnum;
	if ((iov1 = (struct iovec *)valloc(sizeof(struct iovec)*nvector)) == NULL) {
		tst_resm(TFAIL, "valloc buf1 failed: %s", strerror(errno));
		return(-1);
	}
	if ((iov2 = (struct iovec *)valloc(sizeof(struct iovec)*nvector)) == NULL) {
		tst_resm(TFAIL, "valloc buf2 failed: %s", strerror(errno));
		return(-1);
	}
	for (i = 0, iovp = iov1; i < nvector; iovp++, i++) {
		if ((iovp->iov_base = valloc(bufsize)) == NULL) {
			tst_resm(TFAIL, "valloc for iovp->iov_base: %s",
			strerror(errno));
			return(-1);
		}
		iovp->iov_len = bufsize;
	}
	for (i = 0, iovp = iov2; i < nvector; iovp++, i++) {
		if ((iovp->iov_base = valloc(bufsize)) == NULL) {
			tst_resm(TFAIL, "valloc, iov2 for iovp->iov_base: %s",
			strerror(errno));
			return(-1);
		}
		iovp->iov_len = bufsize;
	}

	/* seek, write, read and verify */
	for (i = 0; i < iter; i++) {
		/*
		fillbuf(buf1, bufsize, childnum+i);
		*/
		vfillbuf(iov1, nvector, childnum+i);
		if (lseek(fd_w, seekoff, SEEK_SET) < 0) {
			tst_resm(TFAIL, "lseek before write failed: %s",
				strerror(errno));
			return(-1);
		}
		if (write(fd_w, iov1, bufsize) < bufsize) {
			tst_resm(TFAIL, "write failed: %s", strerror(errno));
			return(-1);
		}
		if (action == READ_DIRECT) {
			/* Make sure data is on to disk before read */
			if (fsync(fd_w) < 0) {
				tst_resm(TFAIL, "fsync failed: %s",
					strerror(errno));
				return(-1);
			}
		}
		if (lseek(fd_r, seekoff, SEEK_SET) < 0) {
			tst_resm(TFAIL, "lseek before read failed: %s",
				strerror(errno));
			return(-1);
		}
		if (read(fd_r, iov2, bufsize) < bufsize) {
			tst_resm(TFAIL, "read failed: %s", strerror(errno));
			return(-1);
		}
		if (bufcmp((char*)iov1, (char*)iov2, bufsize) != 0) {
			tst_resm(TFAIL, "comparsion failed. Child=%d offset=%d",
				childnum, (int)seekoff);
			return(-1);
		}
	}
	return 0;
}
Пример #2
0
/*
 * runtest: Write the data in vector array to the file. Read the data
 *	from the file into another vectory array and verify. Repeat the test.
*/
int runtest(int fd_r, int fd_w, int iter, off64_t offset, int action)
{
	int i;
	struct iovec *iov1, *iov2, *iovp;

	/* Allocate for buffers and data pointers */
	if ((iov1 =
	     (struct iovec *)valloc(sizeof(struct iovec) * nvector)) == NULL) {
		tst_resm(TFAIL, "valloc() buf1 failed: %s", strerror(errno));
		return (-1);
	}
	if ((iov2 =
	     (struct iovec *)valloc(sizeof(struct iovec) * nvector)) == NULL) {
		tst_resm(TFAIL, "valloc buf2 failed: %s", strerror(errno));
		return (-1);
	}
	for (i = 0, iovp = iov1; i < nvector; iovp++, i++) {
		if ((iovp->iov_base = valloc(bufsize)) == NULL) {
			tst_resm(TFAIL, "valloc for iovp->iov_base: %s",
				 strerror(errno));
			return (-1);
		}
		iovp->iov_len = bufsize;
	}
	for (i = 0, iovp = iov2; i < nvector; iovp++, i++) {
		if ((iovp->iov_base = valloc(bufsize)) == NULL) {
			tst_resm(TFAIL, "valloc, iov2 for iovp->iov_base: %s",
				 strerror(errno));
			return (-1);
		}
		iovp->iov_len = bufsize;
	}

	/* Test */
	for (i = 0; i < iter; i++) {
		vfillbuf(iov1, nvector, i);
		vfillbuf(iov2, nvector, i + 1);
		if (lseek(fd_w, offset, SEEK_SET) < 0) {
			tst_resm(TFAIL, "lseek before writev failed: %s",
				 strerror(errno));
			return (-1);
		}
		if (writev(fd_w, iov1, nvector) < 0) {
			tst_resm(TFAIL, "writev failed: %s", strerror(errno));
			return (-1);
		}
		if (lseek(fd_r, offset, SEEK_SET) < 0) {
			tst_resm(TFAIL, "lseek before readv failed: %s",
				 strerror(errno));
			return (-1);
		}
		if (readv(fd_r, iov2, nvector) < 0) {
			tst_resm(TFAIL, "readv failed: %s", strerror(errno));
			return (-1);
		}
		if (vbufcmp(iov1, iov2, nvector) != 0) {
			tst_resm(TFAIL, "readv/writev comparision failed");
			return (-1);
		}
	}

	/* Cleanup */
	for (i = 0, iovp = iov1; i < nvector; iovp++, i++) {
		free(iovp->iov_base);
	}
	for (i = 0, iovp = iov2; i < nvector; iovp++, i++) {
		free(iovp->iov_base);
	}
	free(iov1);
	free(iov2);
	return 0;
}