block_if.h revision 280370
11556Srgrimes/*-
21556Srgrimes * Copyright (c) 2013  Peter Grehan <grehan@freebsd.org>
31556Srgrimes * All rights reserved.
41556Srgrimes *
51556Srgrimes * Redistribution and use in source and binary forms, with or without
61556Srgrimes * modification, are permitted provided that the following conditions
71556Srgrimes * are met:
81556Srgrimes * 1. Redistributions of source code must retain the above copyright
91556Srgrimes *    notice, this list of conditions and the following disclaimer.
101556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111556Srgrimes *    notice, this list of conditions and the following disclaimer in the
121556Srgrimes *    documentation and/or other materials provided with the distribution.
131556Srgrimes *
141556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
151556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
161556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
171556Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
181556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
191556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
201556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
211556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
221556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
231556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
241556Srgrimes * SUCH DAMAGE.
251556Srgrimes *
261556Srgrimes * $FreeBSD: stable/10/usr.sbin/bhyve/block_if.h 280370 2015-03-23 14:36:53Z mav $
271556Srgrimes */
281556Srgrimes
291556Srgrimes/*
301556Srgrimes * The block API to be used by bhyve block-device emulations. The routines
3136152Scharnier * are thread safe, with no assumptions about the context of the completion
3236152Scharnier * callback - it may occur in the caller's context, or asynchronously in
3336152Scharnier * another thread.
341556Srgrimes */
3599110Sobrien
3699110Sobrien#ifndef _BLOCK_IF_H_
371556Srgrimes#define _BLOCK_IF_H_
381556Srgrimes
391556Srgrimes#include <sys/uio.h>
401556Srgrimes#include <sys/unistd.h>
411556Srgrimes
421556Srgrimes#define BLOCKIF_IOV_MAX		32	/* not practical to be IOV_MAX */
4390111Simp
4476810Skrisstruct blockif_req {
451556Srgrimes	struct iovec	br_iov[BLOCKIF_IOV_MAX];
4676810Skris	int		br_iovcnt;
471556Srgrimes	off_t		br_offset;
481556Srgrimes	void		(*br_callback)(struct blockif_req *req, int err);
491556Srgrimes	void		*br_param;
501556Srgrimes};
511556Srgrimes
521556Srgrimesstruct blockif_ctxt;
531556Srgrimesstruct blockif_ctxt *blockif_open(const char *optstr, const char *ident);
541556Srgrimesoff_t	blockif_size(struct blockif_ctxt *bc);
55228406Sedvoid	blockif_chs(struct blockif_ctxt *bc, uint16_t *c, uint8_t *h,
561556Srgrimes    uint8_t *s);
571556Srgrimesint	blockif_sectsz(struct blockif_ctxt *bc);
581556Srgrimesvoid	blockif_psectsz(struct blockif_ctxt *bc, int *size, int *off);
591556Srgrimesint	blockif_queuesz(struct blockif_ctxt *bc);
601556Srgrimesint	blockif_is_ro(struct blockif_ctxt *bc);
611556Srgrimesint	blockif_candelete(struct blockif_ctxt *bc);
621556Srgrimesint	blockif_read(struct blockif_ctxt *bc, struct blockif_req *breq);
631556Srgrimesint	blockif_write(struct blockif_ctxt *bc, struct blockif_req *breq);
641556Srgrimesint	blockif_flush(struct blockif_ctxt *bc, struct blockif_req *breq);
651556Srgrimesint	blockif_delete(struct blockif_ctxt *bc, struct blockif_req *breq);
661556Srgrimesint	blockif_cancel(struct blockif_ctxt *bc, struct blockif_req *breq);
671556Srgrimesint	blockif_close(struct blockif_ctxt *bc);
681556Srgrimes
691556Srgrimes#endif /* _BLOCK_IF_H_ */
701556Srgrimes