2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2013 Peter Grehan <grehan@freebsd.org>
6 * Copyright 2020 Joyent, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include <sys/param.h>
36 #ifndef WITHOUT_CAPSICUM
37 #include <sys/capsicum.h>
39 #include <sys/queue.h>
40 #include <sys/errno.h>
42 #include <sys/ioctl.h>
46 #ifndef WITHOUT_CAPSICUM
47 #include <capsicum_helpers.h>
55 #include <pthread_np.h>
60 #include <machine/atomic.h>
61 #include <machine/vmm_snapshot.h>
70 #define BLOCKIF_SIG 0xb109b109
72 #define BLOCKIF_NUMTHR 8
73 #define BLOCKIF_MAXREQ (BLOCKIF_RING_MAX + BLOCKIF_NUMTHR)
91 TAILQ_ENTRY(blockif_elem) be_link;
92 struct blockif_req *be_req;
94 enum blockstat be_status;
113 pthread_t bc_btid[BLOCKIF_NUMTHR];
114 pthread_mutex_t bc_mtx;
115 pthread_cond_t bc_cond;
116 pthread_cond_t bc_paused_cond;
117 pthread_cond_t bc_work_done_cond;
118 blockif_resize_cb *bc_resize_cb;
119 void *bc_resize_cb_arg;
120 struct mevent *bc_resize_event;
122 /* Request elements and free/pending/busy queues */
123 TAILQ_HEAD(, blockif_elem) bc_freeq;
124 TAILQ_HEAD(, blockif_elem) bc_pendq;
125 TAILQ_HEAD(, blockif_elem) bc_busyq;
126 struct blockif_elem bc_reqs[BLOCKIF_MAXREQ];
129 static pthread_once_t blockif_once = PTHREAD_ONCE_INIT;
131 struct blockif_sig_elem {
132 pthread_mutex_t bse_mtx;
133 pthread_cond_t bse_cond;
135 struct blockif_sig_elem *bse_next;
138 static struct blockif_sig_elem *blockif_bse_head;
141 blockif_enqueue(struct blockif_ctxt *bc, struct blockif_req *breq,
144 struct blockif_elem *be, *tbe;
148 be = TAILQ_FIRST(&bc->bc_freeq);
150 assert(be->be_status == BST_FREE);
151 TAILQ_REMOVE(&bc->bc_freeq, be, be_link);
158 off = breq->br_offset;
159 for (i = 0; i < breq->br_iovcnt; i++)
160 off += breq->br_iov[i].iov_len;
166 TAILQ_FOREACH(tbe, &bc->bc_pendq, be_link) {
167 if (tbe->be_block == breq->br_offset)
171 TAILQ_FOREACH(tbe, &bc->bc_busyq, be_link) {
172 if (tbe->be_block == breq->br_offset)
177 be->be_status = BST_PEND;
179 be->be_status = BST_BLOCK;
180 TAILQ_INSERT_TAIL(&bc->bc_pendq, be, be_link);
181 return (be->be_status == BST_PEND);
185 blockif_dequeue(struct blockif_ctxt *bc, pthread_t t, struct blockif_elem **bep)
187 struct blockif_elem *be;
189 TAILQ_FOREACH(be, &bc->bc_pendq, be_link) {
190 if (be->be_status == BST_PEND)
192 assert(be->be_status == BST_BLOCK);
196 TAILQ_REMOVE(&bc->bc_pendq, be, be_link);
197 be->be_status = BST_BUSY;
199 TAILQ_INSERT_TAIL(&bc->bc_busyq, be, be_link);
205 blockif_complete(struct blockif_ctxt *bc, struct blockif_elem *be)
207 struct blockif_elem *tbe;
209 if (be->be_status == BST_DONE || be->be_status == BST_BUSY)
210 TAILQ_REMOVE(&bc->bc_busyq, be, be_link);
212 TAILQ_REMOVE(&bc->bc_pendq, be, be_link);
213 TAILQ_FOREACH(tbe, &bc->bc_pendq, be_link) {
214 if (tbe->be_req->br_offset == be->be_block)
215 tbe->be_status = BST_PEND;
218 be->be_status = BST_FREE;
220 TAILQ_INSERT_TAIL(&bc->bc_freeq, be, be_link);
224 blockif_flush_bc(struct blockif_ctxt *bc)
227 if (ioctl(bc->bc_fd, DIOCGFLUSH))
229 } else if (fsync(bc->bc_fd))
236 blockif_proc(struct blockif_ctxt *bc, struct blockif_elem *be, uint8_t *buf)
238 struct blockif_req *br;
240 ssize_t clen, len, off, boff, voff;
242 struct spacectl_range range;
245 if (br->br_iovcnt <= 1)
251 if ((len = preadv(bc->bc_fd, br->br_iov, br->br_iovcnt,
260 while (br->br_resid > 0) {
261 len = MIN(br->br_resid, MAXPHYS);
262 if (pread(bc->bc_fd, buf, len, br->br_offset +
269 clen = MIN(len - boff, br->br_iov[i].iov_len -
271 memcpy(br->br_iov[i].iov_base + voff,
273 if (clen < br->br_iov[i].iov_len - voff)
280 } while (boff < len);
291 if ((len = pwritev(bc->bc_fd, br->br_iov, br->br_iovcnt,
300 while (br->br_resid > 0) {
301 len = MIN(br->br_resid, MAXPHYS);
304 clen = MIN(len - boff, br->br_iov[i].iov_len -
307 br->br_iov[i].iov_base + voff, clen);
308 if (clen < br->br_iov[i].iov_len - voff)
315 } while (boff < len);
316 if (pwrite(bc->bc_fd, buf, len, br->br_offset +
326 err = blockif_flush_bc(bc);
329 if (!bc->bc_candelete)
331 else if (bc->bc_rdonly)
333 else if (bc->bc_ischr) {
334 arg[0] = br->br_offset;
335 arg[1] = br->br_resid;
336 if (ioctl(bc->bc_fd, DIOCGDELETE, arg))
341 range.r_offset = br->br_offset;
342 range.r_len = br->br_resid;
344 while (range.r_len > 0) {
345 if (fspacectl(bc->bc_fd, SPACECTL_DEALLOC,
346 &range, 0, &range) != 0) {
360 be->be_status = BST_DONE;
362 (*br->br_callback)(br, err);
366 blockif_thr(void *arg)
368 struct blockif_ctxt *bc;
369 struct blockif_elem *be;
375 buf = malloc(MAXPHYS);
380 pthread_mutex_lock(&bc->bc_mtx);
384 /* We cannot process work if the interface is paused */
385 while (!bc->bc_paused && blockif_dequeue(bc, t, &be)) {
386 pthread_mutex_unlock(&bc->bc_mtx);
387 blockif_proc(bc, be, buf);
388 pthread_mutex_lock(&bc->bc_mtx);
389 blockif_complete(bc, be);
394 /* If none of the workers are busy, notify the main thread */
395 if (bc->bc_work_count == 0)
396 pthread_cond_broadcast(&bc->bc_work_done_cond);
398 /* Check ctxt status here to see if exit requested */
402 /* Make all worker threads wait here if the device is paused */
403 while (bc->bc_paused)
404 pthread_cond_wait(&bc->bc_paused_cond, &bc->bc_mtx);
406 pthread_cond_wait(&bc->bc_cond, &bc->bc_mtx);
408 pthread_mutex_unlock(&bc->bc_mtx);
417 blockif_sigcont_handler(int signal, enum ev_type type, void *arg)
419 struct blockif_sig_elem *bse;
423 * Process the entire list even if not intended for
427 bse = blockif_bse_head;
430 } while (!atomic_cmpset_ptr((uintptr_t *)&blockif_bse_head,
432 (uintptr_t)bse->bse_next));
434 pthread_mutex_lock(&bse->bse_mtx);
435 bse->bse_pending = 0;
436 pthread_cond_signal(&bse->bse_cond);
437 pthread_mutex_unlock(&bse->bse_mtx);
444 mevent_add(SIGCONT, EVF_SIGNAL, blockif_sigcont_handler, NULL);
445 (void) signal(SIGCONT, SIG_IGN);
449 blockif_legacy_config(nvlist_t *nvl, const char *opts)
456 cp = strchr(opts, ',');
458 set_config_value_node(nvl, "path", opts);
461 path = strndup(opts, cp - opts);
462 set_config_value_node(nvl, "path", path);
464 return (pci_parse_legacy_config(nvl, cp + 1));
467 struct blockif_ctxt *
468 blockif_open(nvlist_t *nvl, const char *ident)
470 char tname[MAXCOMLEN + 1];
471 char name[MAXPATHLEN];
472 const char *path, *pssval, *ssval;
474 struct blockif_ctxt *bc;
476 struct diocgattr_arg arg;
477 off_t size, psectsz, psectoff;
478 int extra, fd, i, sectsz;
479 int ro, candelete, geom, ssopt, pssopt;
482 #ifndef WITHOUT_CAPSICUM
484 cap_ioctl_t cmds[] = { DIOCGFLUSH, DIOCGDELETE };
487 pthread_once(&blockif_once, blockif_init);
495 if (get_config_bool_node_default(nvl, "nocache", false))
497 if (get_config_bool_node_default(nvl, "nodelete", false))
499 if (get_config_bool_node_default(nvl, "sync", false) ||
500 get_config_bool_node_default(nvl, "direct", false))
502 if (get_config_bool_node_default(nvl, "ro", false))
504 ssval = get_config_value_node(nvl, "sectorsize");
506 ssopt = strtol(ssval, &cp, 10);
508 EPRINTLN("Invalid sector size \"%s\"", ssval);
513 } else if (*cp == '/') {
515 pssopt = strtol(pssval, &cp, 10);
516 if (cp == pssval || *cp != '\0') {
517 EPRINTLN("Invalid sector size \"%s\"", ssval);
521 EPRINTLN("Invalid sector size \"%s\"", ssval);
526 path = get_config_value_node(nvl, "path");
528 EPRINTLN("Missing \"path\" for block device.");
532 fd = open(path, (ro ? O_RDONLY : O_RDWR) | extra);
534 /* Attempt a r/w fail with a r/o open */
535 fd = open(path, O_RDONLY | extra);
540 warn("Could not open backing file: %s", path);
544 if (fstat(fd, &sbuf) < 0) {
545 warn("Could not stat backing file %s", path);
549 #ifndef WITHOUT_CAPSICUM
550 cap_rights_init(&rights, CAP_FSYNC, CAP_IOCTL, CAP_READ, CAP_SEEK,
551 CAP_WRITE, CAP_FSTAT, CAP_EVENT);
553 cap_rights_clear(&rights, CAP_FSYNC, CAP_WRITE);
555 if (caph_rights_limit(fd, &rights) == -1)
556 errx(EX_OSERR, "Unable to apply rights for sandbox");
560 * Deal with raw devices
564 psectsz = psectoff = 0;
565 candelete = geom = 0;
566 if (S_ISCHR(sbuf.st_mode)) {
567 if (ioctl(fd, DIOCGMEDIASIZE, &size) < 0 ||
568 ioctl(fd, DIOCGSECTORSIZE, §sz)) {
569 perror("Could not fetch dev blk/sector size");
574 if (ioctl(fd, DIOCGSTRIPESIZE, &psectsz) == 0 && psectsz > 0)
575 ioctl(fd, DIOCGSTRIPEOFFSET, &psectoff);
576 strlcpy(arg.name, "GEOM::candelete", sizeof(arg.name));
577 arg.len = sizeof(arg.value.i);
578 if (nodelete == 0 && ioctl(fd, DIOCGATTR, &arg) == 0)
579 candelete = arg.value.i;
580 if (ioctl(fd, DIOCGPROVIDERNAME, name) == 0)
583 psectsz = sbuf.st_blksize;
584 /* Avoid fallback implementation */
585 candelete = fpathconf(fd, _PC_DEALLOC_PRESENT) == 1;
588 #ifndef WITHOUT_CAPSICUM
589 if (caph_ioctls_limit(fd, cmds, nitems(cmds)) == -1)
590 errx(EX_OSERR, "Unable to apply rights for sandbox");
594 if (!powerof2(ssopt) || !powerof2(pssopt) || ssopt < 512 ||
596 EPRINTLN("Invalid sector size %d/%d",
602 * Some backend drivers (e.g. cd0, ada0) require that the I/O
603 * size be a multiple of the device's sector size.
605 * Validate that the emulated sector size complies with this
608 if (S_ISCHR(sbuf.st_mode)) {
609 if (ssopt < sectsz || (ssopt % sectsz) != 0) {
610 EPRINTLN("Sector size %d incompatible "
611 "with underlying device sector size %d",
622 bc = calloc(1, sizeof(struct blockif_ctxt));
628 bc->bc_magic = BLOCKIF_SIG;
630 bc->bc_ischr = S_ISCHR(sbuf.st_mode);
631 bc->bc_isgeom = geom;
632 bc->bc_candelete = candelete;
635 bc->bc_sectsz = sectsz;
636 bc->bc_psectsz = psectsz;
637 bc->bc_psectoff = psectoff;
638 pthread_mutex_init(&bc->bc_mtx, NULL);
639 pthread_cond_init(&bc->bc_cond, NULL);
641 bc->bc_work_count = 0;
642 pthread_cond_init(&bc->bc_paused_cond, NULL);
643 pthread_cond_init(&bc->bc_work_done_cond, NULL);
644 TAILQ_INIT(&bc->bc_freeq);
645 TAILQ_INIT(&bc->bc_pendq);
646 TAILQ_INIT(&bc->bc_busyq);
647 for (i = 0; i < BLOCKIF_MAXREQ; i++) {
648 bc->bc_reqs[i].be_status = BST_FREE;
649 TAILQ_INSERT_HEAD(&bc->bc_freeq, &bc->bc_reqs[i], be_link);
652 for (i = 0; i < BLOCKIF_NUMTHR; i++) {
653 pthread_create(&bc->bc_btid[i], NULL, blockif_thr, bc);
654 snprintf(tname, sizeof(tname), "blk-%s-%d", ident, i);
655 pthread_set_name_np(bc->bc_btid[i], tname);
666 blockif_resized(int fd, enum ev_type type, void *arg)
668 struct blockif_ctxt *bc;
671 if (fstat(fd, &sb) != 0)
675 pthread_mutex_lock(&bc->bc_mtx);
676 if (sb.st_size != bc->bc_size) {
677 bc->bc_size = sb.st_size;
678 bc->bc_resize_cb(bc, bc->bc_resize_cb_arg, bc->bc_size);
680 pthread_mutex_unlock(&bc->bc_mtx);
684 blockif_register_resize_callback(struct blockif_ctxt *bc, blockif_resize_cb *cb,
693 pthread_mutex_lock(&bc->bc_mtx);
694 if (bc->bc_resize_cb != NULL) {
699 assert(bc->bc_closing == 0);
701 if (fstat(bc->bc_fd, &sb) != 0) {
706 bc->bc_resize_event = mevent_add_flags(bc->bc_fd, EVF_VNODE,
707 EVFF_ATTRIB, blockif_resized, bc);
708 if (bc->bc_resize_event == NULL) {
713 bc->bc_resize_cb = cb;
714 bc->bc_resize_cb_arg = cb_arg;
716 pthread_mutex_unlock(&bc->bc_mtx);
722 blockif_request(struct blockif_ctxt *bc, struct blockif_req *breq,
729 pthread_mutex_lock(&bc->bc_mtx);
730 if (!TAILQ_EMPTY(&bc->bc_freeq)) {
732 * Enqueue and inform the block i/o thread
733 * that there is work available
735 if (blockif_enqueue(bc, breq, op))
736 pthread_cond_signal(&bc->bc_cond);
739 * Callers are not allowed to enqueue more than
740 * the specified blockif queue limit. Return an
741 * error to indicate that the queue length has been
746 pthread_mutex_unlock(&bc->bc_mtx);
752 blockif_read(struct blockif_ctxt *bc, struct blockif_req *breq)
755 assert(bc->bc_magic == BLOCKIF_SIG);
756 return (blockif_request(bc, breq, BOP_READ));
760 blockif_write(struct blockif_ctxt *bc, struct blockif_req *breq)
763 assert(bc->bc_magic == BLOCKIF_SIG);
764 return (blockif_request(bc, breq, BOP_WRITE));
768 blockif_flush(struct blockif_ctxt *bc, struct blockif_req *breq)
771 assert(bc->bc_magic == BLOCKIF_SIG);
772 return (blockif_request(bc, breq, BOP_FLUSH));
776 blockif_delete(struct blockif_ctxt *bc, struct blockif_req *breq)
779 assert(bc->bc_magic == BLOCKIF_SIG);
780 return (blockif_request(bc, breq, BOP_DELETE));
784 blockif_cancel(struct blockif_ctxt *bc, struct blockif_req *breq)
786 struct blockif_elem *be;
788 assert(bc->bc_magic == BLOCKIF_SIG);
790 pthread_mutex_lock(&bc->bc_mtx);
791 /* XXX: not waiting while paused */
794 * Check pending requests.
796 TAILQ_FOREACH(be, &bc->bc_pendq, be_link) {
797 if (be->be_req == breq)
804 blockif_complete(bc, be);
805 pthread_mutex_unlock(&bc->bc_mtx);
811 * Check in-flight requests.
813 TAILQ_FOREACH(be, &bc->bc_busyq, be_link) {
814 if (be->be_req == breq)
821 pthread_mutex_unlock(&bc->bc_mtx);
826 * Interrupt the processing thread to force it return
827 * prematurely via it's normal callback path.
829 while (be->be_status == BST_BUSY) {
830 struct blockif_sig_elem bse, *old_head;
832 pthread_mutex_init(&bse.bse_mtx, NULL);
833 pthread_cond_init(&bse.bse_cond, NULL);
838 old_head = blockif_bse_head;
839 bse.bse_next = old_head;
840 } while (!atomic_cmpset_ptr((uintptr_t *)&blockif_bse_head,
844 pthread_kill(be->be_tid, SIGCONT);
846 pthread_mutex_lock(&bse.bse_mtx);
847 while (bse.bse_pending)
848 pthread_cond_wait(&bse.bse_cond, &bse.bse_mtx);
849 pthread_mutex_unlock(&bse.bse_mtx);
852 pthread_mutex_unlock(&bc->bc_mtx);
855 * The processing thread has been interrupted. Since it's not
856 * clear if the callback has been invoked yet, return EBUSY.
862 blockif_close(struct blockif_ctxt *bc)
867 assert(bc->bc_magic == BLOCKIF_SIG);
870 * Stop the block i/o thread
872 pthread_mutex_lock(&bc->bc_mtx);
874 if (bc->bc_resize_event != NULL)
875 mevent_disable(bc->bc_resize_event);
876 pthread_mutex_unlock(&bc->bc_mtx);
877 pthread_cond_broadcast(&bc->bc_cond);
878 for (i = 0; i < BLOCKIF_NUMTHR; i++)
879 pthread_join(bc->bc_btid[i], &jval);
881 /* XXX Cancel queued i/o's ??? */
894 * Return virtual C/H/S values for a given block. Use the algorithm
895 * outlined in the VHD specification to calculate values.
898 blockif_chs(struct blockif_ctxt *bc, uint16_t *c, uint8_t *h, uint8_t *s)
900 off_t sectors; /* total sectors of the block dev */
901 off_t hcyl; /* cylinders times heads */
902 uint16_t secpt; /* sectors per track */
905 assert(bc->bc_magic == BLOCKIF_SIG);
907 sectors = bc->bc_size / bc->bc_sectsz;
909 /* Clamp the size to the largest possible with CHS */
910 if (sectors > 65535UL*16*255)
911 sectors = 65535UL*16*255;
913 if (sectors >= 65536UL*16*63) {
916 hcyl = sectors / secpt;
919 hcyl = sectors / secpt;
920 heads = (hcyl + 1023) / 1024;
925 if (hcyl >= (heads * 1024) || heads > 16) {
928 hcyl = sectors / secpt;
930 if (hcyl >= (heads * 1024)) {
933 hcyl = sectors / secpt;
946 blockif_size(struct blockif_ctxt *bc)
949 assert(bc->bc_magic == BLOCKIF_SIG);
950 return (bc->bc_size);
954 blockif_sectsz(struct blockif_ctxt *bc)
957 assert(bc->bc_magic == BLOCKIF_SIG);
958 return (bc->bc_sectsz);
962 blockif_psectsz(struct blockif_ctxt *bc, int *size, int *off)
965 assert(bc->bc_magic == BLOCKIF_SIG);
966 *size = bc->bc_psectsz;
967 *off = bc->bc_psectoff;
971 blockif_queuesz(struct blockif_ctxt *bc)
974 assert(bc->bc_magic == BLOCKIF_SIG);
975 return (BLOCKIF_MAXREQ - 1);
979 blockif_is_ro(struct blockif_ctxt *bc)
982 assert(bc->bc_magic == BLOCKIF_SIG);
983 return (bc->bc_rdonly);
987 blockif_candelete(struct blockif_ctxt *bc)
990 assert(bc->bc_magic == BLOCKIF_SIG);
991 return (bc->bc_candelete);
994 #ifdef BHYVE_SNAPSHOT
996 blockif_pause(struct blockif_ctxt *bc)
999 assert(bc->bc_magic == BLOCKIF_SIG);
1001 pthread_mutex_lock(&bc->bc_mtx);
1004 /* The interface is paused. Wait for workers to finish their work */
1005 while (bc->bc_work_count)
1006 pthread_cond_wait(&bc->bc_work_done_cond, &bc->bc_mtx);
1007 pthread_mutex_unlock(&bc->bc_mtx);
1009 if (blockif_flush_bc(bc))
1010 fprintf(stderr, "%s: [WARN] failed to flush backing file.\r\n",
1015 blockif_resume(struct blockif_ctxt *bc)
1018 assert(bc->bc_magic == BLOCKIF_SIG);
1020 pthread_mutex_lock(&bc->bc_mtx);
1022 /* resume the threads waiting for paused */
1023 pthread_cond_broadcast(&bc->bc_paused_cond);
1024 /* kick the threads after restore */
1025 pthread_cond_broadcast(&bc->bc_cond);
1026 pthread_mutex_unlock(&bc->bc_mtx);
1030 blockif_snapshot_req(struct blockif_req *br, struct vm_snapshot_meta *meta)
1036 SNAPSHOT_VAR_OR_LEAVE(br->br_iovcnt, meta, ret, done);
1037 SNAPSHOT_VAR_OR_LEAVE(br->br_offset, meta, ret, done);
1038 SNAPSHOT_VAR_OR_LEAVE(br->br_resid, meta, ret, done);
1041 * XXX: The callback and parameter must be filled by the virtualized
1042 * device that uses the interface, during its init; we're not touching
1046 /* Snapshot the iovecs. */
1047 for (i = 0; i < br->br_iovcnt; i++) {
1048 iov = &br->br_iov[i];
1050 SNAPSHOT_VAR_OR_LEAVE(iov->iov_len, meta, ret, done);
1052 /* We assume the iov is a guest-mapped address. */
1053 SNAPSHOT_GUEST2HOST_ADDR_OR_LEAVE(iov->iov_base, iov->iov_len,
1054 false, meta, ret, done);
1062 blockif_snapshot(struct blockif_ctxt *bc, struct vm_snapshot_meta *meta)
1066 if (bc->bc_paused == 0) {
1067 fprintf(stderr, "%s: Snapshot failed: "
1068 "interface not paused.\r\n", __func__);
1072 pthread_mutex_lock(&bc->bc_mtx);
1074 SNAPSHOT_VAR_OR_LEAVE(bc->bc_magic, meta, ret, done);
1075 SNAPSHOT_VAR_OR_LEAVE(bc->bc_ischr, meta, ret, done);
1076 SNAPSHOT_VAR_OR_LEAVE(bc->bc_isgeom, meta, ret, done);
1077 SNAPSHOT_VAR_OR_LEAVE(bc->bc_candelete, meta, ret, done);
1078 SNAPSHOT_VAR_OR_LEAVE(bc->bc_rdonly, meta, ret, done);
1079 SNAPSHOT_VAR_OR_LEAVE(bc->bc_size, meta, ret, done);
1080 SNAPSHOT_VAR_OR_LEAVE(bc->bc_sectsz, meta, ret, done);
1081 SNAPSHOT_VAR_OR_LEAVE(bc->bc_psectsz, meta, ret, done);
1082 SNAPSHOT_VAR_OR_LEAVE(bc->bc_psectoff, meta, ret, done);
1083 SNAPSHOT_VAR_OR_LEAVE(bc->bc_closing, meta, ret, done);
1086 pthread_mutex_unlock(&bc->bc_mtx);