/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2013 Peter Grehan <[email protected]>4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728/*29* The block API to be used by bhyve block-device emulations. The routines30* are thread safe, with no assumptions about the context of the completion31* callback - it may occur in the caller's context, or asynchronously in32* another thread.33*/3435#ifndef _BLOCK_IF_H_36#define _BLOCK_IF_H_3738#include <sys/nv.h>39#include <sys/uio.h>40#include <sys/unistd.h>4142struct vm_snapshot_meta;434445/*46* BLOCKIF_IOV_MAX is the maximum number of scatter/gather entries in47* a single request. BLOCKIF_RING_MAX is the maxmimum number of48* pending requests that can be queued.49*/50#define BLOCKIF_IOV_MAX 128 /* not practical to be IOV_MAX */51#define BLOCKIF_RING_MAX 1285253struct blockif_req {54int br_iovcnt;55off_t br_offset;56ssize_t br_resid;57void (*br_callback)(struct blockif_req *req, int err);58void *br_param;59struct iovec br_iov[BLOCKIF_IOV_MAX];60};6162struct pci_devinst;63struct blockif_ctxt;6465typedef void blockif_resize_cb(struct blockif_ctxt *, void *, size_t);6667int blockif_legacy_config(nvlist_t *nvl, const char *opts);68int blockif_add_boot_device(struct pci_devinst *const pi, struct blockif_ctxt *const bc);69struct blockif_ctxt *blockif_open(nvlist_t *nvl, const char *ident);70int blockif_register_resize_callback(struct blockif_ctxt *bc,71blockif_resize_cb *cb, void *cb_arg);72off_t blockif_size(struct blockif_ctxt *bc);73void blockif_chs(struct blockif_ctxt *bc, uint16_t *c, uint8_t *h,74uint8_t *s);75int blockif_sectsz(struct blockif_ctxt *bc);76void blockif_psectsz(struct blockif_ctxt *bc, int *size, int *off);77int blockif_queuesz(struct blockif_ctxt *bc);78int blockif_is_ro(struct blockif_ctxt *bc);79int blockif_candelete(struct blockif_ctxt *bc);80int blockif_read(struct blockif_ctxt *bc, struct blockif_req *breq);81int blockif_write(struct blockif_ctxt *bc, struct blockif_req *breq);82int blockif_flush(struct blockif_ctxt *bc, struct blockif_req *breq);83int blockif_delete(struct blockif_ctxt *bc, struct blockif_req *breq);84int blockif_cancel(struct blockif_ctxt *bc, struct blockif_req *breq);85int blockif_close(struct blockif_ctxt *bc);86#ifdef BHYVE_SNAPSHOT87void blockif_pause(struct blockif_ctxt *bc);88void blockif_resume(struct blockif_ctxt *bc);89#endif9091#endif /* _BLOCK_IF_H_ */929394