2012-06-06 10:55:50 +01:00
|
|
|
#ifndef SERVE_H
|
|
|
|
#define SERVE_H
|
2012-05-17 20:14:22 +01:00
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
2012-05-31 17:44:11 +01:00
|
|
|
|
|
|
|
#ifndef _LARGEFILE64_SOURCE
|
|
|
|
# define _LARGEFILE64_SOURCE
|
|
|
|
#endif
|
2012-05-17 20:14:22 +01:00
|
|
|
|
2012-05-19 12:48:03 +01:00
|
|
|
#include "parse.h"
|
2012-05-17 20:14:22 +01:00
|
|
|
|
2012-05-19 12:48:03 +01:00
|
|
|
#include <sys/types.h>
|
2012-05-17 20:14:22 +01:00
|
|
|
|
2012-06-06 11:27:52 +01:00
|
|
|
static const int block_allocation_resolution = 4096;//128<<10;
|
|
|
|
|
2012-05-24 01:39:35 +01:00
|
|
|
enum mirror_finish_action {
|
|
|
|
ACTION_PROXY,
|
|
|
|
ACTION_EXIT,
|
|
|
|
ACTION_NOTHING
|
|
|
|
};
|
|
|
|
|
2012-05-21 04:03:17 +01:00
|
|
|
struct mirror_status {
|
|
|
|
pthread_t thread;
|
|
|
|
int client;
|
|
|
|
char *filename;
|
|
|
|
off64_t max_bytes_per_second;
|
2012-05-24 01:39:35 +01:00
|
|
|
enum mirror_finish_action action_at_finish;
|
2012-05-21 04:03:17 +01:00
|
|
|
|
|
|
|
char *mapped;
|
|
|
|
struct bitset_mapping *dirty_map;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct control_params {
|
|
|
|
int socket;
|
2012-06-06 10:35:50 +01:00
|
|
|
struct server* serve;
|
2012-05-21 04:03:17 +01:00
|
|
|
};
|
|
|
|
|
2012-05-27 14:40:16 +01:00
|
|
|
#define MAX_NBD_CLIENTS 16
|
2012-06-06 10:35:50 +01:00
|
|
|
struct server {
|
2012-05-29 04:03:28 +01:00
|
|
|
/** address/port to bind to */
|
2012-05-17 20:14:22 +01:00
|
|
|
union mysockaddr bind_to;
|
2012-06-01 14:48:34 +01:00
|
|
|
/** does an empty ACL mean "deny all"? */
|
|
|
|
int default_deny;
|
2012-05-29 04:03:28 +01:00
|
|
|
/** number of entries in current access control list*/
|
2012-05-17 20:14:22 +01:00
|
|
|
int acl_entries;
|
2012-05-29 04:03:28 +01:00
|
|
|
/** pointer to access control list entries*/
|
2012-05-21 04:03:17 +01:00
|
|
|
struct ip_and_mask (*acl)[0];
|
2012-05-29 11:24:24 +01:00
|
|
|
/** (static) file name to serve */
|
2012-05-17 20:14:22 +01:00
|
|
|
char* filename;
|
2012-05-29 11:24:24 +01:00
|
|
|
/** file name of INCOMPLETE flag */
|
|
|
|
char* filename_incomplete;
|
2012-05-29 04:03:28 +01:00
|
|
|
/** TCP backlog for listen() */
|
2012-05-17 20:14:22 +01:00
|
|
|
int tcp_backlog;
|
2012-05-29 11:24:24 +01:00
|
|
|
/** (static) file name of UNIX control socket (or NULL if none) */
|
2012-05-18 18:44:34 +01:00
|
|
|
char* control_socket_name;
|
2012-05-29 04:03:28 +01:00
|
|
|
/** size of file */
|
2012-05-21 04:03:17 +01:00
|
|
|
off64_t size;
|
2012-05-29 00:59:12 +01:00
|
|
|
|
|
|
|
/* NB dining philosophers if we ever mave more than one thread
|
|
|
|
* that might need to pause the whole server. At the moment we only
|
|
|
|
* have the one.
|
|
|
|
*/
|
2012-05-29 04:03:28 +01:00
|
|
|
|
|
|
|
/** Claimed around any accept/thread starting loop */
|
|
|
|
pthread_mutex_t l_accept;
|
|
|
|
/** Claims around any I/O to this file */
|
|
|
|
pthread_mutex_t l_io;
|
|
|
|
|
|
|
|
/** set to non-zero to cause r/w requests to go via this fd */
|
|
|
|
int proxy_fd;
|
|
|
|
|
|
|
|
/** to interrupt accept loop and clients, write() to close_signal[1] */
|
|
|
|
int close_signal[2];
|
2012-05-21 04:03:17 +01:00
|
|
|
|
|
|
|
struct mirror_status* mirror;
|
2012-06-06 10:19:45 +01:00
|
|
|
int server_fd;
|
2012-06-06 10:35:50 +01:00
|
|
|
int control_fd;
|
2012-05-17 20:14:22 +01:00
|
|
|
|
|
|
|
char* block_allocation_map;
|
2012-05-27 14:40:16 +01:00
|
|
|
|
2012-05-30 20:13:56 +01:00
|
|
|
struct { pthread_t thread; union mysockaddr address; }
|
2012-05-27 14:40:16 +01:00
|
|
|
nbd_client[MAX_NBD_CLIENTS];
|
2012-05-17 20:14:22 +01:00
|
|
|
};
|
|
|
|
|
2012-06-06 11:27:52 +01:00
|
|
|
int server_detect_closed(struct server* serve);
|
|
|
|
void server_dirty(struct server *serve, off64_t from, int len);
|
|
|
|
|
|
|
|
|
2012-05-17 20:14:22 +01:00
|
|
|
struct mode_readwrite_params {
|
|
|
|
union mysockaddr connect_to;
|
|
|
|
off64_t from;
|
|
|
|
off64_t len;
|
|
|
|
int data_fd;
|
|
|
|
int client;
|
|
|
|
};
|
|
|
|
|
2012-05-19 12:48:03 +01:00
|
|
|
|
2012-05-17 20:14:22 +01:00
|
|
|
#endif
|
|
|
|
|