* The AIO daemon, most of the actual work is done in aio_process_*, * but the setup (and address space mgmt) is done in this routine. */
| 1064 | * but the setup (and address space mgmt) is done in this routine. |
| 1065 | */ |
| 1066 | static void |
| 1067 | aio_daemon(void *_id) |
| 1068 | { |
| 1069 | struct kaiocb *job; |
| 1070 | struct aioproc *aiop; |
| 1071 | struct kaioinfo *ki; |
| 1072 | struct proc *p; |
| 1073 | struct vmspace *myvm; |
| 1074 | struct thread *td = curthread; |
| 1075 | int id = (intptr_t)_id; |
| 1076 | |
| 1077 | /* |
| 1078 | * Grab an extra reference on the daemon's vmspace so that it |
| 1079 | * doesn't get freed by jobs that switch to a different |
| 1080 | * vmspace. |
| 1081 | */ |
| 1082 | p = td->td_proc; |
| 1083 | myvm = vmspace_acquire_ref(p); |
| 1084 | |
| 1085 | KASSERT(p->p_textvp == NULL, ("kthread has a textvp")); |
| 1086 | |
| 1087 | /* |
| 1088 | * Allocate and ready the aio control info. There is one aiop structure |
| 1089 | * per daemon. |
| 1090 | */ |
| 1091 | aiop = uma_zalloc(aiop_zone, M_WAITOK); |
| 1092 | aiop->aioproc = p; |
| 1093 | aiop->aioprocflags = 0; |
| 1094 | |
| 1095 | /* |
| 1096 | * Wakeup parent process. (Parent sleeps to keep from blasting away |
| 1097 | * and creating too many daemons.) |
| 1098 | */ |
| 1099 | sema_post(&aio_newproc_sem); |
| 1100 | |
| 1101 | mtx_lock(&aio_job_mtx); |
| 1102 | for (;;) { |
| 1103 | /* |
| 1104 | * Take daemon off of free queue |
| 1105 | */ |
| 1106 | if (aiop->aioprocflags & AIOP_FREE) { |
| 1107 | TAILQ_REMOVE(&aio_freeproc, aiop, list); |
| 1108 | aiop->aioprocflags &= ~AIOP_FREE; |
| 1109 | } |
| 1110 | |
| 1111 | /* |
| 1112 | * Check for jobs. |
| 1113 | */ |
| 1114 | while ((job = aio_selectjob(aiop)) != NULL) { |
| 1115 | mtx_unlock(&aio_job_mtx); |
| 1116 | |
| 1117 | ki = job->userproc->p_aioinfo; |
| 1118 | job->handle_fn(job); |
| 1119 | |
| 1120 | mtx_lock(&aio_job_mtx); |
| 1121 | /* Decrement the active job count. */ |
| 1122 | ki->kaio_active_count--; |
| 1123 | } |
nothing calls this directly
no test coverage detected