1256052Sgrehan/*-
2256052Sgrehan * Copyright (c) 2013  Peter Grehan <grehan@freebsd.org>
3256052Sgrehan * All rights reserved.
4256052Sgrehan *
5256052Sgrehan * Redistribution and use in source and binary forms, with or without
6256052Sgrehan * modification, are permitted provided that the following conditions
7256052Sgrehan * are met:
8256052Sgrehan * 1. Redistributions of source code must retain the above copyright
9256052Sgrehan *    notice, this list of conditions and the following disclaimer.
10256052Sgrehan * 2. Redistributions in binary form must reproduce the above copyright
11256052Sgrehan *    notice, this list of conditions and the following disclaimer in the
12256052Sgrehan *    documentation and/or other materials provided with the distribution.
13256052Sgrehan *
14256052Sgrehan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
15256052Sgrehan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16256052Sgrehan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17256052Sgrehan * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18256052Sgrehan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19256052Sgrehan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20256052Sgrehan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21256052Sgrehan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22256052Sgrehan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23256052Sgrehan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24256052Sgrehan * SUCH DAMAGE.
25256052Sgrehan *
26256052Sgrehan * $FreeBSD: releng/11.0/usr.sbin/bhyve/block_if.h 283168 2015-05-21 04:19:22Z grehan $
27256052Sgrehan */
28256052Sgrehan
29256052Sgrehan/*
30256052Sgrehan * The block API to be used by bhyve block-device emulations. The routines
31256052Sgrehan * are thread safe, with no assumptions about the context of the completion
32256052Sgrehan * callback - it may occur in the caller's context, or asynchronously in
33256052Sgrehan * another thread.
34256052Sgrehan */
35256052Sgrehan
36256052Sgrehan#ifndef _BLOCK_IF_H_
37256052Sgrehan#define _BLOCK_IF_H_
38256052Sgrehan
39256052Sgrehan#include <sys/uio.h>
40256052Sgrehan#include <sys/unistd.h>
41256052Sgrehan
42283168Sgrehan#define BLOCKIF_IOV_MAX		33	/* not practical to be IOV_MAX */
43256052Sgrehan
44256052Sgrehanstruct blockif_req {
45256052Sgrehan	struct iovec	br_iov[BLOCKIF_IOV_MAX];
46256052Sgrehan	int		br_iovcnt;
47256052Sgrehan	off_t		br_offset;
48281700Smav	ssize_t		br_resid;
49256052Sgrehan	void		(*br_callback)(struct blockif_req *req, int err);
50256052Sgrehan	void		*br_param;
51256052Sgrehan};
52256052Sgrehan
53256052Sgrehanstruct blockif_ctxt;
54256052Sgrehanstruct blockif_ctxt *blockif_open(const char *optstr, const char *ident);
55256052Sgrehanoff_t	blockif_size(struct blockif_ctxt *bc);
56268638Sgrehanvoid	blockif_chs(struct blockif_ctxt *bc, uint16_t *c, uint8_t *h,
57268638Sgrehan    uint8_t *s);
58256052Sgrehanint	blockif_sectsz(struct blockif_ctxt *bc);
59279654Smavvoid	blockif_psectsz(struct blockif_ctxt *bc, int *size, int *off);
60256052Sgrehanint	blockif_queuesz(struct blockif_ctxt *bc);
61256052Sgrehanint	blockif_is_ro(struct blockif_ctxt *bc);
62279957Smavint	blockif_candelete(struct blockif_ctxt *bc);
63256052Sgrehanint	blockif_read(struct blockif_ctxt *bc, struct blockif_req *breq);
64256052Sgrehanint	blockif_write(struct blockif_ctxt *bc, struct blockif_req *breq);
65256052Sgrehanint	blockif_flush(struct blockif_ctxt *bc, struct blockif_req *breq);
66279957Smavint	blockif_delete(struct blockif_ctxt *bc, struct blockif_req *breq);
67256052Sgrehanint	blockif_cancel(struct blockif_ctxt *bc, struct blockif_req *breq);
68256052Sgrehanint	blockif_close(struct blockif_ctxt *bc);
69256052Sgrehan
70256052Sgrehan#endif /* _BLOCK_IF_H_ */
71