2 * Copyright (C) 2013 Red Hat Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of Red Hat nor the names of its contributors may be
17 * used to endorse or promote products derived from this software without
18 * specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #ifndef NBDKIT_INTERNAL_H
35 #define NBDKIT_INTERNAL_H
39 #include <sys/socket.h>
42 #include "nbdkit-plugin.h"
45 #define UNIX_PATH_MAX 104
47 #define UNIX_PATH_MAX 108
51 extern const char *ipaddr
;
52 extern const char *port
;
54 extern char *unixsocket
;
57 extern volatile int quit
;
60 extern void cleanup_free (void *ptr
);
61 #ifdef HAVE_ATTRIBUTE_CLEANUP
62 #define CLEANUP_FREE __attribute__((cleanup (cleanup_free)))
70 pthread_mutex_t request_lock
;
79 extern int handle_single_connection (int sockin
, int sockout
);
82 #define debug nbdkit_debug
85 extern void plugin_register (const char *_filename
, void *_dl
, struct nbdkit_plugin
*(*plugin_init
) (void));
86 extern void plugin_cleanup (void);
87 extern const char *plugin_name (void);
88 extern void plugin_usage (void);
89 extern void plugin_version (void);
90 extern void plugin_config (const char *key
, const char *value
);
91 extern void plugin_config_complete (void);
92 extern void plugin_lock_connection (void);
93 extern void plugin_unlock_connection (void);
94 extern void plugin_lock_request (struct connection
*conn
);
95 extern void plugin_unlock_request (struct connection
*conn
);
96 extern int plugin_open (struct connection
*conn
, int readonly
);
97 extern void plugin_close (struct connection
*conn
);
98 extern int64_t plugin_get_size (struct connection
*conn
);
99 extern int plugin_can_write (struct connection
*conn
);
100 extern int plugin_can_flush (struct connection
*conn
);
101 extern int plugin_is_rotational (struct connection
*conn
);
102 extern int plugin_can_trim (struct connection
*conn
);
103 extern int plugin_pread (struct connection
*conn
, void *buf
, uint32_t count
, uint64_t offset
);
104 extern int plugin_pwrite (struct connection
*conn
, void *buf
, uint32_t count
, uint64_t offset
);
105 extern int plugin_flush (struct connection
*conn
);
106 extern int plugin_trim (struct connection
*conn
, uint32_t count
, uint64_t offset
);
109 extern int *bind_unix_socket (size_t *);
110 extern int *bind_tcpip_socket (size_t *);
111 extern void accept_incoming_connections (int *socks
, size_t nr_socks
);
112 extern void free_listening_sockets (int *socks
, size_t nr_socks
);
115 extern void tls_init (void);
116 extern void tls_new_server_thread (void);
117 extern void tls_set_name (const char *name
);
118 extern void tls_set_instance_num (size_t instance_num
);
119 extern void tls_set_sockaddr (struct sockaddr
*addr
, socklen_t addrlen
);
120 extern const char *tls_get_name (void);
121 extern size_t tls_get_instance_num (void);
122 /*extern void tls_get_sockaddr ();*/
125 extern int xread (int sock
, void *buf
, size_t len
);
126 extern int xwrite (int sock
, const void *buf
, size_t len
);
128 /* Declare program_name. */
129 #if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME == 1
131 #define program_name program_invocation_short_name
133 #define program_name "nbdkit"
136 #endif /* NBDKIT_INTERNAL_H */