Lines Matching +full:1 +full:br +full:- +full:10
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
11 * 1. Redistributions of source code must retain the above copyright
142 be = TAILQ_FIRST(&bc->bc_freeq); in blockif_enqueue()
144 assert(be->be_status == BST_FREE); in blockif_enqueue()
145 TAILQ_REMOVE(&bc->bc_freeq, be, be_link); in blockif_enqueue()
146 be->be_req = breq; in blockif_enqueue()
147 be->be_op = op; in blockif_enqueue()
152 off = breq->br_offset; in blockif_enqueue()
153 for (i = 0; i < breq->br_iovcnt; i++) in blockif_enqueue()
154 off += breq->br_iov[i].iov_len; in blockif_enqueue()
159 be->be_block = off; in blockif_enqueue()
160 TAILQ_FOREACH(tbe, &bc->bc_pendq, be_link) { in blockif_enqueue()
161 if (tbe->be_block == breq->br_offset) in blockif_enqueue()
165 TAILQ_FOREACH(tbe, &bc->bc_busyq, be_link) { in blockif_enqueue()
166 if (tbe->be_block == breq->br_offset) in blockif_enqueue()
171 be->be_status = BST_PEND; in blockif_enqueue()
173 be->be_status = BST_BLOCK; in blockif_enqueue()
174 TAILQ_INSERT_TAIL(&bc->bc_pendq, be, be_link); in blockif_enqueue()
175 return (be->be_status == BST_PEND); in blockif_enqueue()
183 TAILQ_FOREACH(be, &bc->bc_pendq, be_link) { in blockif_dequeue()
184 if (be->be_status == BST_PEND) in blockif_dequeue()
186 assert(be->be_status == BST_BLOCK); in blockif_dequeue()
190 TAILQ_REMOVE(&bc->bc_pendq, be, be_link); in blockif_dequeue()
191 be->be_status = BST_BUSY; in blockif_dequeue()
192 be->be_tid = t; in blockif_dequeue()
193 TAILQ_INSERT_TAIL(&bc->bc_busyq, be, be_link); in blockif_dequeue()
195 return (1); in blockif_dequeue()
203 if (be->be_status == BST_DONE || be->be_status == BST_BUSY) in blockif_complete()
204 TAILQ_REMOVE(&bc->bc_busyq, be, be_link); in blockif_complete()
206 TAILQ_REMOVE(&bc->bc_pendq, be, be_link); in blockif_complete()
207 TAILQ_FOREACH(tbe, &bc->bc_pendq, be_link) { in blockif_complete()
208 if (tbe->be_req->br_offset == be->be_block) in blockif_complete()
209 tbe->be_status = BST_PEND; in blockif_complete()
211 be->be_tid = 0; in blockif_complete()
212 be->be_status = BST_FREE; in blockif_complete()
213 be->be_req = NULL; in blockif_complete()
214 TAILQ_INSERT_TAIL(&bc->bc_freeq, be, be_link); in blockif_complete()
220 if (bc->bc_ischr) { in blockif_flush_bc()
221 if (ioctl(bc->bc_fd, DIOCGFLUSH)) in blockif_flush_bc()
223 } else if (fsync(bc->bc_fd)) in blockif_flush_bc()
233 struct blockif_req *br; in blockif_proc() local
239 br = be->be_req; in blockif_proc()
240 assert(br->br_resid >= 0); in blockif_proc()
242 if (br->br_iovcnt <= 1) in blockif_proc()
245 switch (be->be_op) { in blockif_proc()
248 if ((n = preadv(bc->bc_fd, br->br_iov, br->br_iovcnt, in blockif_proc()
249 br->br_offset)) < 0) in blockif_proc()
252 br->br_resid -= n; in blockif_proc()
257 while (br->br_resid > 0) { in blockif_proc()
258 len = MIN(br->br_resid, MAXPHYS); in blockif_proc()
259 n = pread(bc->bc_fd, buf, len, br->br_offset + off); in blockif_proc()
267 clen = MIN(len - boff, br->br_iov[i].iov_len - in blockif_proc()
269 memcpy((uint8_t *)br->br_iov[i].iov_base + voff, in blockif_proc()
271 if (clen < br->br_iov[i].iov_len - voff) in blockif_proc()
280 br->br_resid -= len; in blockif_proc()
284 if (bc->bc_rdonly) { in blockif_proc()
289 if ((n = pwritev(bc->bc_fd, br->br_iov, br->br_iovcnt, in blockif_proc()
290 br->br_offset)) < 0) in blockif_proc()
293 br->br_resid -= n; in blockif_proc()
298 while (br->br_resid > 0) { in blockif_proc()
299 len = MIN(br->br_resid, MAXPHYS); in blockif_proc()
302 clen = MIN(len - boff, br->br_iov[i].iov_len - in blockif_proc()
305 (uint8_t *)br->br_iov[i].iov_base + voff, in blockif_proc()
307 if (clen < br->br_iov[i].iov_len - voff) in blockif_proc()
316 n = pwrite(bc->bc_fd, buf, len, br->br_offset + off); in blockif_proc()
322 br->br_resid -= n; in blockif_proc()
329 if (!bc->bc_candelete) in blockif_proc()
331 else if (bc->bc_rdonly) in blockif_proc()
333 else if (bc->bc_ischr) { in blockif_proc()
334 arg[0] = br->br_offset; in blockif_proc()
335 arg[1] = br->br_resid; in blockif_proc()
336 if (ioctl(bc->bc_fd, DIOCGDELETE, arg)) in blockif_proc()
339 br->br_resid = 0; in blockif_proc()
341 range.r_offset = br->br_offset; in blockif_proc()
342 range.r_len = br->br_resid; in blockif_proc()
345 if (fspacectl(bc->bc_fd, SPACECTL_DEALLOC, in blockif_proc()
352 br->br_resid = 0; in blockif_proc()
360 be->be_status = BST_DONE; in blockif_proc()
362 (*br->br_callback)(br, err); in blockif_proc()
368 return (TAILQ_EMPTY(&bc->bc_pendq) && TAILQ_EMPTY(&bc->bc_busyq)); in blockif_empty()
380 if (bc->bc_isgeom) in blockif_thr()
386 pthread_mutex_lock(&bc->bc_mtx); in blockif_thr()
389 pthread_mutex_unlock(&bc->bc_mtx); in blockif_thr()
391 pthread_mutex_lock(&bc->bc_mtx); in blockif_thr()
397 pthread_cond_broadcast(&bc->bc_work_done_cond); in blockif_thr()
400 if (bc->bc_closing) in blockif_thr()
403 pthread_cond_wait(&bc->bc_cond, &bc->bc_mtx); in blockif_thr()
405 pthread_mutex_unlock(&bc->bc_mtx); in blockif_thr()
430 (uintptr_t)bse->bse_next)); in blockif_sigcont_handler()
432 pthread_mutex_lock(&bse->bse_mtx); in blockif_sigcont_handler()
433 bse->bse_pending = 0; in blockif_sigcont_handler()
434 pthread_cond_signal(&bse->bse_cond); in blockif_sigcont_handler()
435 pthread_mutex_unlock(&bse->bse_mtx); in blockif_sigcont_handler()
459 path = strndup(opts, cp - opts); in blockif_legacy_config()
462 return (pci_parse_legacy_config(nvl, cp + 1)); in blockif_legacy_config()
469 if (bc->bc_bootindex < 0) in blockif_add_boot_device()
472 return (pci_emul_add_boot_device(pi, bc->bc_bootindex)); in blockif_add_boot_device()
478 char tname[MAXCOMLEN + 1]; in blockif_open()
498 fd = -1; in blockif_open()
503 bootindex = -1; in blockif_open()
508 nodelete = 1; in blockif_open()
513 ro = 1; in blockif_open()
516 ssopt = strtol(ssval, &cp, 10); in blockif_open()
524 pssval = cp + 1; in blockif_open()
525 pssopt = strtol(pssval, &cp, 10); in blockif_open()
551 ro = 1; in blockif_open()
570 if (caph_rights_limit(fd, &rights) == -1) in blockif_open()
596 geom = 1; in blockif_open()
600 candelete = fpathconf(fd, _PC_DEALLOC_PRESENT) == 1; in blockif_open()
604 if (caph_ioctls_limit(fd, cmds, nitems(cmds)) == -1) in blockif_open()
637 bc = calloc(1, sizeof(struct blockif_ctxt)); in blockif_open()
643 bc->bc_magic = BLOCKIF_SIG; in blockif_open()
644 bc->bc_fd = fd; in blockif_open()
645 bc->bc_ischr = S_ISCHR(sbuf.st_mode); in blockif_open()
646 bc->bc_isgeom = geom; in blockif_open()
647 bc->bc_candelete = candelete; in blockif_open()
648 bc->bc_rdonly = ro; in blockif_open()
649 bc->bc_size = size; in blockif_open()
650 bc->bc_sectsz = sectsz; in blockif_open()
651 bc->bc_psectsz = psectsz; in blockif_open()
652 bc->bc_psectoff = psectoff; in blockif_open()
653 pthread_mutex_init(&bc->bc_mtx, NULL); in blockif_open()
654 pthread_cond_init(&bc->bc_cond, NULL); in blockif_open()
655 bc->bc_paused = 0; in blockif_open()
656 pthread_cond_init(&bc->bc_work_done_cond, NULL); in blockif_open()
657 TAILQ_INIT(&bc->bc_freeq); in blockif_open()
658 TAILQ_INIT(&bc->bc_pendq); in blockif_open()
659 TAILQ_INIT(&bc->bc_busyq); in blockif_open()
660 bc->bc_bootindex = bootindex; in blockif_open()
662 bc->bc_reqs[i].be_status = BST_FREE; in blockif_open()
663 TAILQ_INSERT_HEAD(&bc->bc_freeq, &bc->bc_reqs[i], be_link); in blockif_open()
667 pthread_create(&bc->bc_btid[i], NULL, blockif_thr, bc); in blockif_open()
668 snprintf(tname, sizeof(tname), "blk-%s-%d", ident, i); in blockif_open()
669 pthread_set_name_np(bc->bc_btid[i], tname); in blockif_open()
699 pthread_mutex_lock(&bc->bc_mtx); in blockif_resized()
700 if (mediasize != bc->bc_size) { in blockif_resized()
701 bc->bc_size = mediasize; in blockif_resized()
702 bc->bc_resize_cb(bc, bc->bc_resize_cb_arg, bc->bc_size); in blockif_resized()
704 pthread_mutex_unlock(&bc->bc_mtx); in blockif_resized()
719 pthread_mutex_lock(&bc->bc_mtx); in blockif_register_resize_callback()
720 if (bc->bc_resize_cb != NULL) { in blockif_register_resize_callback()
725 assert(bc->bc_closing == 0); in blockif_register_resize_callback()
727 if (fstat(bc->bc_fd, &sb) != 0) { in blockif_register_resize_callback()
732 bc->bc_resize_event = mevent_add_flags(bc->bc_fd, EVF_VNODE, in blockif_register_resize_callback()
734 if (bc->bc_resize_event == NULL) { in blockif_register_resize_callback()
739 bc->bc_resize_cb = cb; in blockif_register_resize_callback()
740 bc->bc_resize_cb_arg = cb_arg; in blockif_register_resize_callback()
742 pthread_mutex_unlock(&bc->bc_mtx); in blockif_register_resize_callback()
755 pthread_mutex_lock(&bc->bc_mtx); in blockif_request()
756 assert(!bc->bc_paused); in blockif_request()
757 if (!TAILQ_EMPTY(&bc->bc_freeq)) { in blockif_request()
763 pthread_cond_signal(&bc->bc_cond); in blockif_request()
773 pthread_mutex_unlock(&bc->bc_mtx); in blockif_request()
781 assert(bc->bc_magic == BLOCKIF_SIG); in blockif_read()
788 assert(bc->bc_magic == BLOCKIF_SIG); in blockif_write()
795 assert(bc->bc_magic == BLOCKIF_SIG); in blockif_flush()
802 assert(bc->bc_magic == BLOCKIF_SIG); in blockif_delete()
811 assert(bc->bc_magic == BLOCKIF_SIG); in blockif_cancel()
813 pthread_mutex_lock(&bc->bc_mtx); in blockif_cancel()
819 TAILQ_FOREACH(be, &bc->bc_pendq, be_link) { in blockif_cancel()
820 if (be->be_req == breq) in blockif_cancel()
828 pthread_mutex_unlock(&bc->bc_mtx); in blockif_cancel()
834 * Check in-flight requests. in blockif_cancel()
836 TAILQ_FOREACH(be, &bc->bc_busyq, be_link) { in blockif_cancel()
837 if (be->be_req == breq) in blockif_cancel()
844 pthread_mutex_unlock(&bc->bc_mtx); in blockif_cancel()
852 while (be->be_status == BST_BUSY) { in blockif_cancel()
858 bse.bse_pending = 1; in blockif_cancel()
867 pthread_kill(be->be_tid, SIGCONT); in blockif_cancel()
875 pthread_mutex_unlock(&bc->bc_mtx); in blockif_cancel()
890 assert(bc->bc_magic == BLOCKIF_SIG); in blockif_close()
895 pthread_mutex_lock(&bc->bc_mtx); in blockif_close()
896 bc->bc_closing = 1; in blockif_close()
897 if (bc->bc_resize_event != NULL) in blockif_close()
898 mevent_disable(bc->bc_resize_event); in blockif_close()
899 pthread_mutex_unlock(&bc->bc_mtx); in blockif_close()
900 pthread_cond_broadcast(&bc->bc_cond); in blockif_close()
902 pthread_join(bc->bc_btid[i], &jval); in blockif_close()
909 bc->bc_magic = 0; in blockif_close()
910 close(bc->bc_fd); in blockif_close()
928 assert(bc->bc_magic == BLOCKIF_SIG); in blockif_chs()
930 sectors = bc->bc_size / bc->bc_sectsz; in blockif_chs()
971 assert(bc->bc_magic == BLOCKIF_SIG); in blockif_size()
972 return (bc->bc_size); in blockif_size()
978 assert(bc->bc_magic == BLOCKIF_SIG); in blockif_sectsz()
979 return (bc->bc_sectsz); in blockif_sectsz()
985 assert(bc->bc_magic == BLOCKIF_SIG); in blockif_psectsz()
986 *size = bc->bc_psectsz; in blockif_psectsz()
987 *off = bc->bc_psectoff; in blockif_psectsz()
993 assert(bc->bc_magic == BLOCKIF_SIG); in blockif_queuesz()
994 return (BLOCKIF_MAXREQ - 1); in blockif_queuesz()
1000 assert(bc->bc_magic == BLOCKIF_SIG); in blockif_is_ro()
1001 return (bc->bc_rdonly); in blockif_is_ro()
1007 assert(bc->bc_magic == BLOCKIF_SIG); in blockif_candelete()
1008 return (bc->bc_candelete); in blockif_candelete()
1016 assert(bc->bc_magic == BLOCKIF_SIG); in blockif_pause()
1018 pthread_mutex_lock(&bc->bc_mtx); in blockif_pause()
1019 bc->bc_paused = 1; in blockif_pause()
1023 pthread_cond_wait(&bc->bc_work_done_cond, &bc->bc_mtx); in blockif_pause()
1024 pthread_mutex_unlock(&bc->bc_mtx); in blockif_pause()
1026 if (!bc->bc_rdonly && blockif_flush_bc(bc)) in blockif_pause()
1035 assert(bc->bc_magic == BLOCKIF_SIG); in blockif_resume()
1037 pthread_mutex_lock(&bc->bc_mtx); in blockif_resume()
1038 bc->bc_paused = 0; in blockif_resume()
1039 pthread_mutex_unlock(&bc->bc_mtx); in blockif_resume()