FreeBSD Bugzilla – Attachment 185771 Details for
Bug 217261
sys/aio/aio_test:aio_md_test fails semi-frequently with Jenkins with "aio_write failed: Operation not supported"
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Test program
aio_physio_test.c (text/x-csrc), 3.45 KB, created by
John Baldwin
on 2017-08-25 22:57:24 UTC
(
hide
)
Description:
Test program
Filename:
MIME Type:
Creator:
John Baldwin
Created:
2017-08-25 22:57:24 UTC
Size:
3.45 KB
patch
obsolete
>/*- > * > * Try to exercise the EAGAIN case in aio_qphysio case. > */ > >#include <sys/param.h> >#include <sys/ioctl.h> >#include <sys/mdioctl.h> >#include <aio.h> >#include <err.h> >#include <errno.h> >#include <fcntl.h> >#include <pthread.h> >#include <stdatomic.h> >#include <stdio.h> >#include <stdlib.h> >#include <string.h> >#include <unistd.h> > >#define MD_SIZE (16 * 1024) > >static sig_atomic_t info, quit; > >static atomic_ulong submitted, completed; >static int mdfd = -1, mdunit; > >static void >usage(void) >{ > > fprintf(stderr, "aio_physio_test [-c threads]\n"); > exit(1); >} > >static void >info_handler(int sig) >{ > info = 1; >} > >static void >handler(int sig) >{ > quit = 1; >} > >static void >md_destroy(void) >{ > struct md_ioctl mdio; > int fd; > > if (mdfd >= 0) > close(mdfd); > fd = open("/dev/mdctl", O_RDWR); > if (fd < 0) > err(1, "open(/dev/mdctl)"); > > memset(&mdio, 0, sizeof(mdio)); > mdio.md_version = MDIOVERSION; > mdio.md_unit = mdunit; > if (ioctl(fd, MDIOCDETACH, &mdio) == -1) > warn("ioctl MDIOCDETACH"); > close(fd); >} > >static int >md_open(void) >{ > struct md_ioctl mdio; > char pathname[PATH_MAX]; > int fd; > > fd = open("/dev/mdctl", O_RDWR); > if (fd < 0) > err(1, "open(/dev/mdctl)"); > > memset(&mdio, 0, sizeof(mdio)); > mdio.md_version = MDIOVERSION; > mdio.md_type = MD_MALLOC; > mdio.md_options = MD_AUTOUNIT | MD_COMPRESS; > mdio.md_mediasize = MD_SIZE; > mdio.md_sectorsize = 512; > > if (ioctl(fd, MDIOCATTACH, &mdio) < 0) > err(1, "ioctl MDIOCATTACH"); > close(fd); > > mdunit = mdio.md_unit; > printf("created md%u\n", mdunit); > if (atexit(md_destroy) == -1) { > warn("atexit"); > md_destroy(); > exit(1); > } > > snprintf(pathname, PATH_MAX, "/dev/md%d", mdunit); > fd = open(pathname, O_RDWR); > if (fd < 0) > err(1, "open /dev/md%d", mdunit); > return (fd); >} > >static void >submit_request(struct aiocb *cb) >{ > unsigned long retries; > > for (retries = 0;; retries++) { > if (aio_read(cb) == 0) > break; > if (errno != EAGAIN) > err(1, "aio_read"); > usleep(1000); > } > if (retries != 0) > printf("Request took %lu retries\n", retries); > submitted++; >} > >static void * >worker_thread(void *arg) >{ > const struct aiocb *cbp[1]; > struct aiocb cb; > char *buffer; > > cbp[0] = &cb; > buffer = malloc(MD_SIZE); > if (buffer == NULL) > err(1, "malloc"); > while (!quit) { > cb.aio_nbytes = MD_SIZE; > cb.aio_fildes = mdfd; > cb.aio_buf = buffer; > submit_request(&cb); > > usleep(250); > > if (aio_suspend(cbp, 1, NULL) == -1) > err(1, "aio_suspend"); > (void)aio_return(&cb); > completed++; > } > return (NULL); >} > >int >main(int ac, char **av) >{ > pthread_t *workers; > int ch, max_requests = 16; > > while ((ch = getopt(ac, av, "c:")) != -1) > switch (ch) { > case 'c': > max_requests = atoi(optarg); > break; > default: > usage(); > } > av += optind; > ac -= optind; > if (ac != 0) > usage(); > > mdfd = md_open(); > signal(SIGQUIT, handler); > signal(SIGINT, handler); > signal(SIGTERM, handler); > signal(SIGINFO, info_handler); > > workers = calloc(max_requests, sizeof(*workers)); > if (workers == NULL) > err(1, "calloc"); > submitted = completed = 0; > for (int i = 0; i < max_requests; i++) { > int error = pthread_create(&workers[i], NULL, worker_thread, > NULL); > if (error) > errc(1, error, "pthread_create"); > } > while (!quit) { > if (info) { > printf("%lu submitted, %lu completed\n", submitted, > completed); > info = 0; > } > sleep(1); > } > for (int i = 0; i < max_requests; i++) { > int error = pthread_join(workers[i], NULL); > if (error) > warnc(error, "pthread_join"); > } > > printf("%lu submitted, %lu completed\n", submitted, completed); > return (0); >}
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 217261
: 185771