/* * 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; char *buf1, *buf2; buf1 = valloc(BUFSIZE); buf2 = valloc(BUFSIZE); if (!buf1 || !buf2) { tst_resm(TBROK | TERRNO, "valloc() failed"); free(buf1); free(buf2); return -1; } /* Allocate for buffers and data pointers */ seekoff = offset + bufsize * childnum; /* seek, write, read and verify */ for (i = 0; i < iter; i++) { fillbuf(buf1, bufsize, 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, buf1, 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); } int ret; if ((ret = read(fd_r, buf2, bufsize)) < bufsize) { tst_resm(TFAIL, "read failed: %s", strerror(errno)); return (-1); } if (bufcmp(buf1, buf2, bufsize) != 0) { tst_resm(TFAIL, "comparsion failed. Child=%d offset=%d", childnum, (int)seekoff); return (-1); } } return 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. * * XXX (garrcoop): shouldn't use libltp APIs because it runs forked. */ int runtest(int fd_r, int fd_w, int childnum, int action) { char *buf1; char *buf2; off_t seekoff; int bufsize = BUFSIZE; int i; /* Allocate for buffers */ seekoff = offset+bufsize * childnum; if ((buf1 = valloc(bufsize)) == 0) { tst_resm(TFAIL|TERRNO, "valloc for buf1 failed"); return(-1); } if ((buf2 = valloc(bufsize)) == 0) { tst_resm(TFAIL|TERRNO, "valloc for buf2 failed"); return(-1); } /* seek, write, read and verify */ for (i = 0; i < iter; i++) { fillbuf(buf1, bufsize, childnum+i); if (lseek(fd_w, seekoff, SEEK_SET) < 0) { tst_resm(TFAIL|TERRNO, "lseek (fd_w, ..) failed"); return(-1); } if (write(fd_w, buf1, bufsize) < bufsize) { tst_resm(TFAIL|TERRNO, "write failed"); return(-1); } if (action == READ_DIRECT) { /* Make sure data is on to disk before read */ if (fsync(fd_w) < 0) { tst_resm(TFAIL|TERRNO, "fsync failed"); return(-1); } } if (lseek(fd_r, seekoff, SEEK_SET) < 0) { tst_resm(TFAIL|TERRNO, "lseek(fd_r, ..) failed"); return(-1); } if (read(fd_r, buf2, bufsize) < bufsize) { tst_resm(TFAIL|TERRNO, "read failed"); return(-1); } if (bufcmp(buf1, buf2, bufsize) != 0) { tst_resm(TFAIL, "comparsion failed; child=%d offset=%d", childnum, (int)seekoff); return(-1); } } tst_exit(); }
int vbufcmp(struct iovec *iv1, struct iovec *iv2, int vcnt) { int i; for (i = 0; i < vcnt; iv1++, iv2++, i++) { if (bufcmp(iv1->iov_base, iv2->iov_base, iv1->iov_len) < 0) { fprintf(stderr, "Vector: %d, iv1base=%s, iv2base=%s\n", i, (char *)iv1->iov_base, (char *)iv2->iov_base); return(-1); } } return(0); }
/* * Reuse, or allocate (and program the page pods for) a new DDP buffer. The * "pages" array is handed over to this function and should not be used in any * way by the caller after that. */ static int select_ddp_buffer(struct adapter *sc, struct toepcb *toep, vm_page_t *pages, int npages, int db_off, int db_len) { struct ddp_buffer *db; struct tom_data *td = sc->tom_softc; int i, empty_slot = -1; /* Try to reuse */ for (i = 0; i < nitems(toep->db); i++) { if (bufcmp(toep->db[i], pages, npages, db_off, db_len) == 0) { free(pages, M_CXGBE); return (i); /* pages still held */ } else if (toep->db[i] == NULL && empty_slot < 0) empty_slot = i; } /* Allocate new buffer, write its page pods. */ db = alloc_ddp_buffer(td, pages, npages, db_off, db_len); if (db == NULL) { vm_page_unhold_pages(pages, npages); free(pages, M_CXGBE); return (-1); } if (write_page_pods(sc, toep, db) != 0) { vm_page_unhold_pages(pages, npages); free_ddp_buffer(td, db); return (-1); } i = empty_slot; if (i < 0) { i = arc4random() % nitems(toep->db); free_ddp_buffer(td, toep->db[i]); } toep->db[i] = db; CTR5(KTR_CXGBE, "%s: tid %d, DDP buffer[%d] = %p (tag 0x%x)", __func__, toep->tid, i, db, db->tag); return (i); }
int kycountdb( TEXT *pkeystr1, TEXT *pkeystr2, SMALL numcomps) { int i; pkeystr1++; /* advance past unnecessary length prefix */ pkeystr2++; /* ... */ /* repeat once for each component of the key */ /* comparing key comp1 with key comp2 loop */ for(i = 0; i < numcomps; i++,pkeystr1++, pkeystr2++) { /* check for unusual values */ if ( *(TTINY*)pkeystr1 > LKYFLAG || *(TTINY*)pkeystr2 > LKYFLAG ) { if ( *(TTINY*)pkeystr1 == *(TTINY*)pkeystr2 )continue; else return i; } if (*(TTINY*)pkeystr1 != *(TTINY*)pkeystr2) /* compare lengths */ return i; /* we must actually compare them */ if (bufcmp( pkeystr1+1, pkeystr2+1, (int)*(TTINY*)pkeystr1) != 0) return i; /* advance past the characters */ pkeystr1 += *(TTINY*)pkeystr1; pkeystr2 += *(TTINY*)pkeystr2; } /* fall through bottom means an exact match found */ return i; } /* end kycountdb */
/* * 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; }