python: Refer caller to Threads section in documentation.
[nbdkit/ericb.git] / include / nbdkit-common.h
blobe2a8b88e7d7dae7f35d8fb36549e60acb9b6d3e7
1 /* nbdkit
2 * Copyright (C) 2013-2019 Red Hat Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of Red Hat nor the names of its contributors may be
16 * used to endorse or promote products derived from this software without
17 * specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
33 #ifndef NBDKIT_COMMON_H
34 #define NBDKIT_COMMON_H
36 #if !defined (NBDKIT_PLUGIN_H) && !defined (NBDKIT_FILTER_H)
37 #error this header file should not be directly included
38 #endif
40 #include <stdarg.h>
41 #include <stdint.h>
42 #include <errno.h>
43 #include <sys/socket.h>
45 #include <nbdkit-version.h>
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
51 #if defined(__GNUC__) || defined(__clang__)
52 #define ATTRIBUTE_FORMAT_PRINTF(fmtpos, argpos) \
53 __attribute__((__format__ (__printf__, fmtpos, argpos)))
54 #else
55 #define ATTRIBUTE_FORMAT_PRINTF(fmtpos, argpos)
56 #endif
58 #define NBDKIT_THREAD_MODEL_SERIALIZE_CONNECTIONS 0
59 #define NBDKIT_THREAD_MODEL_SERIALIZE_ALL_REQUESTS 1
60 #define NBDKIT_THREAD_MODEL_SERIALIZE_REQUESTS 2
61 #define NBDKIT_THREAD_MODEL_PARALLEL 3
63 #define NBDKIT_FLAG_MAY_TRIM (1<<0) /* Maps to !NBD_CMD_FLAG_NO_HOLE */
64 #define NBDKIT_FLAG_FUA (1<<1) /* Maps to NBD_CMD_FLAG_FUA */
65 #define NBDKIT_FLAG_REQ_ONE (1<<2) /* Maps to NBD_CMD_FLAG_REQ_ONE */
66 #define NBDKIT_FLAG_FAST_ZERO (1<<3) /* Maps to NBD_CMD_FLAG_FAST_ZERO */
68 #define NBDKIT_FUA_NONE 0
69 #define NBDKIT_FUA_EMULATE 1
70 #define NBDKIT_FUA_NATIVE 2
72 #define NBDKIT_CACHE_NONE 0
73 #define NBDKIT_CACHE_EMULATE 1
74 #define NBDKIT_CACHE_NATIVE 2
76 #define NBDKIT_EXTENT_HOLE (1<<0) /* Same as NBD_STATE_HOLE */
77 #define NBDKIT_EXTENT_ZERO (1<<1) /* Same as NBD_STATE_ZERO */
79 extern void nbdkit_error (const char *msg, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
80 extern void nbdkit_verror (const char *msg, va_list args);
81 extern void nbdkit_debug (const char *msg, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
82 extern void nbdkit_vdebug (const char *msg, va_list args);
84 extern char *nbdkit_absolute_path (const char *path);
85 extern int64_t nbdkit_parse_size (const char *str);
86 extern int nbdkit_parse_bool (const char *str);
87 extern int nbdkit_parse_int (const char *what, const char *str,
88 int *r);
89 extern int nbdkit_parse_unsigned (const char *what, const char *str,
90 unsigned *r);
91 extern int nbdkit_parse_int8_t (const char *what, const char *str,
92 int8_t *r);
93 extern int nbdkit_parse_uint8_t (const char *what, const char *str,
94 uint8_t *r);
95 extern int nbdkit_parse_int16_t (const char *what, const char *str,
96 int16_t *r);
97 extern int nbdkit_parse_uint16_t (const char *what, const char *str,
98 uint16_t *r);
99 extern int nbdkit_parse_int32_t (const char *what, const char *str,
100 int32_t *r);
101 extern int nbdkit_parse_uint32_t (const char *what, const char *str,
102 uint32_t *r);
103 extern int nbdkit_parse_int64_t (const char *what, const char *str,
104 int64_t *r);
105 extern int nbdkit_parse_uint64_t (const char *what, const char *str,
106 uint64_t *r);
107 extern int nbdkit_read_password (const char *value, char **password);
108 extern char *nbdkit_realpath (const char *path);
109 extern int nbdkit_nanosleep (unsigned sec, unsigned nsec);
110 extern const char *nbdkit_export_name (void);
111 extern int nbdkit_peer_name (struct sockaddr *addr, socklen_t *addrlen);
113 struct nbdkit_extents;
114 extern int nbdkit_add_extent (struct nbdkit_extents *,
115 uint64_t offset, uint64_t length, uint32_t type);
117 /* A static non-NULL pointer which can be used when you don't need a
118 * per-connection handle.
120 #define NBDKIT_HANDLE_NOT_NEEDED (&errno)
122 #ifdef __cplusplus
124 #endif
126 #ifdef __cplusplus
127 #define NBDKIT_CXX_LANG_C extern "C"
128 #else
129 #define NBDKIT_CXX_LANG_C /* nothing */
130 #endif
132 #endif /* NBDKIT_COMMON_H */