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$
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
42256052Sgrehan#define BLOCKIF_IOV_MAX		32	/* 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;
48256052Sgrehan	void		(*br_callback)(struct blockif_req *req, int err);
49256052Sgrehan	void		*br_param;
50256052Sgrehan};
51256052Sgrehan
52256052Sgrehanstruct blockif_ctxt;
53256052Sgrehanstruct blockif_ctxt *blockif_open(const char *optstr, const char *ident);
54256052Sgrehanoff_t	blockif_size(struct blockif_ctxt *bc);
55256052Sgrehanint	blockif_sectsz(struct blockif_ctxt *bc);
56256052Sgrehanint	blockif_queuesz(struct blockif_ctxt *bc);
57256052Sgrehanint	blockif_is_ro(struct blockif_ctxt *bc);
58256052Sgrehanint	blockif_read(struct blockif_ctxt *bc, struct blockif_req *breq);
59256052Sgrehanint	blockif_write(struct blockif_ctxt *bc, struct blockif_req *breq);
60256052Sgrehanint	blockif_flush(struct blockif_ctxt *bc, struct blockif_req *breq);
61256052Sgrehanint	blockif_cancel(struct blockif_ctxt *bc, struct blockif_req *breq);
62256052Sgrehanint	blockif_close(struct blockif_ctxt *bc);
63256052Sgrehan
64256052Sgrehan#endif /* _BLOCK_IF_H_ */
65