Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 148791 Details for
Bug 198859
race in aio io_submit write/read
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
testcase for shortread
aio_backread.c (text/x-csrc), 4.33 KB, created by
Rafal Wijata
on 2007-02-26 13:28:06 UTC
(
hide
)
Description:
testcase for shortread
Filename:
MIME Type:
Creator:
Rafal Wijata
Created:
2007-02-26 13:28:06 UTC
Size:
4.33 KB
patch
obsolete
>#include <stdio.h> >#include <stdlib.h> >#include <unistd.h> >#include <sys/types.h> >#include <sys/stat.h> >#include <libaio.h> >#include <malloc.h> >#define __USE_GNU >#include <fcntl.h> >#include <pthread.h> > >#define BUFSIZE 1024 >#define REDSIZE (64*1024) >#define MAX_AIO_EVENTS 10240 > >void fun_writeN(void* ptr); >void fun_read(void* ptr); > >int handle = 0; >char *buf, *bufRed; >io_context_t ctxp; >struct iocb *iocbs[MAX_AIO_EVENTS]; >struct iocb *rocbs[MAX_AIO_EVENTS]; >struct io_event ioevents[MAX_AIO_EVENTS]; > >volatile int submittedSize = 0; //synchronization > >int main() >{ > pthread_t thread_read; > pthread_t thread_write; > int i; > > printf("aiotest start\n"); > > if ((buf = (char*)memalign(512, BUFSIZE)) == NULL) { perror("buf memalign"); exit(-1); } > if ((bufRed = (char*)memalign(512, REDSIZE)) == NULL) { perror("buf memalign"); exit(-1); } > > for (i = 0; i < BUFSIZE; ++i) { buf[i] = 'A' + (char)(i % ('Z'-'A'+1)); } > buf[BUFSIZE-1] = '\n'; > > handle = open("/tmp/aiotest.dat", O_CREAT | O_TRUNC | O_DIRECT | O_RDWR, 0600); > if (handle == -1) { perror("open file"); exit(-1); } > > memset(&ctxp, 0, sizeof(ctxp)); > if (io_setup(MAX_AIO_EVENTS, &ctxp) != 0) { perror("io_setup"); exit(-1); } > > for (i = 0; i < MAX_AIO_EVENTS; ++i) //prepare writes > { > if ((iocbs[i] = (struct iocb*)calloc(1, sizeof(struct iocb))) == NULL) { perror("calloc struct iocb"); exit(-1); } > if ((rocbs[i] = (struct iocb*)calloc(1, sizeof(struct iocb))) == NULL) { perror("calloc struct iocb"); exit(-1); } > iocbs[i]->data = (void*)(-1); > iocbs[i]->aio_fildes = handle; > iocbs[i]->aio_lio_opcode = IO_CMD_PWRITE; > iocbs[i]->aio_reqprio = 0; > iocbs[i]->u.c.buf = bufRed; > iocbs[i]->u.c.nbytes = BUFSIZE; > iocbs[i]->u.c.offset = BUFSIZE*i; > } > > pthread_create(&thread_read, NULL, (void*)&fun_read, NULL); > pthread_create(&thread_write, NULL, (void*)&fun_writeN, NULL); > > pthread_join(thread_read, NULL); > pthread_join(thread_write, NULL); > > io_destroy(ctxp); > close(handle); > > printf("aiotest stop\n"); > > return 0; >} > >void fun_read(void* ptr) >{ > int i, gotWrite, rocbCnt = 0; > long n = MAX_AIO_EVENTS; > struct stat filestat; > long long exSize; > printf("read thread %lu start\n", pthread_self()); > while (n>0) > { > long r = io_getevents(ctxp, 1, MAX_AIO_EVENTS, ioevents, NULL); > if (r > 0) > { > n -= r; > gotWrite = 0; > for (i = 0; i < r; ++i) > { > if (ioevents[i].obj->data == (void*)(-1)) //write > { > if (BUFSIZE != ioevents[i].res) > { > fprintf(stderr, "wrong write: expected %d bytes, receiced %ld\n", BUFSIZE, ioevents[i].res); > exit(-1); > } > gotWrite++; > exSize = ioevents[i].obj->u.c.offset + BUFSIZE; >#ifdef DO_SYNCH > //we'll wait until io_submit() for this callback finished > while(exSize > submittedSize) sched_yield(); >#endif > } else { > //printf("read %ld+%ld back\n", ioevents[i].obj->u.c.offset, ioevents[i].res); > if ((long)ioevents[i].obj->data > ioevents[i].res) > { > fprintf(stderr, "short read: expected at least %ld bytes, receiced %ld\n", ioevents[i].obj->data, ioevents[i].res); > exit(-1); > } > } > } > if (gotWrite) > { > //submit one read no matter how many writes was finished, reuse iocb > rocbs[rocbCnt]->aio_fildes = handle; > rocbs[rocbCnt]->aio_reqprio = 0; > rocbs[rocbCnt]->aio_lio_opcode = IO_CMD_PREAD; > rocbs[rocbCnt]->u.c.buf = bufRed; > rocbs[rocbCnt]->u.c.nbytes = REDSIZE; > rocbs[rocbCnt]->u.c.offset = ((exSize > (12*1024)) ? (exSize - (12*1024)) : 0); //8K back > rocbs[rocbCnt]->data = (void*)(exSize - rocbs[rocbCnt]->u.c.offset); //at least this many bytes we should read > //printf("io_submit(%lld): %lld + %ld(%ld)\n", exSize, rocbs[rocbCnt]->u.c.offset, rocbs[rocbCnt]->u.c.nbytes, (long)(rocbs[rocbCnt]->data)); > if ((io_submit(ctxp, 1, &(rocbs[rocbCnt])) != 1)) { perror("fun_read io_submit"); exit(-1); } > n++; //notify one more submit > rocbCnt++; > } > } > else if (r < 0) { perror ("fun read io_getevents"); } > } > printf("read thread %lu stop\n", pthread_self()); >} > >void fun_writeN(void* ptr) >{ > > int i; > printf("write thread %lu start\n", pthread_self()); > for(i = 0; i < MAX_AIO_EVENTS; ++i) > { > if ((io_submit(ctxp, 1, &(iocbs[i])) != 1)) > { > perror("fun_write io_submit"); exit(-1); > } >#ifdef DO_SYNCH > submittedSize += BUFSIZE; >#endif > } > printf("write thread %lu stop\n", pthread_self()); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 198859
: 148791