From dc81a51d59ccf31a5b47b989060a626e97a3d709 Mon Sep 17 00:00:00 2001 From: sr Date: Mon, 8 Jul 2013 18:46:26 +0200 Subject: Rewriting.... --- src/server/server.h | 62 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 23 deletions(-) (limited to 'src/server/server.h') diff --git a/src/server/server.h b/src/server/server.h index 47aa0c0..74ca1a1 100644 --- a/src/server/server.h +++ b/src/server/server.h @@ -28,22 +28,30 @@ #include "../config.h" #include "../types.h" +typedef struct +{ + int fd; +} dnbd3_connection_t; +/** + * Image struct. An image path could be something like + * /mnt/images/rz/zfs/Windows7 ZfS.vmdk.1 + * and the lower_name would then be + * rz/zfs/windows7 zfs.vmdk + */ typedef struct { - char *config_group; // exact name of group in config file that represents this image - char *low_name; // full (global) name of image, lowercased for comparison, eg. "uni-freiburg/rz/ubuntu-12.04" - int rid; // revision of provided image - char *file; // path to image file or device + char *path; // absolute path of the image + char *lower_name; // relative path, all lowercase, minus revision ID + int rid; // revision of image uint64_t filesize; // size of image - dnbd3_server_entry_t servers[NUMBER_SERVERS]; // known alt servers that also offer that image time_t atime; // last access time uint8_t *cache_map; // cache map telling which parts are locally cached - char *cache_file; // path to local cache of image (in case the image is read from a dnbd3 device) - char working; // whether this image is considered working. local images are "working" if the local file exists, proxied images have to have at least one working upstream server or a complete local cache file + dnbd3_connection_t *uplink; // NULL = local image / completely cached, pointer to a server connection otherwise + char working; // TRUE if image exists and completeness is == 100% or a working upstream proxy is connected time_t delete_soft; // unixtime telling when this image should be deleted. if there are still clients using this image it weill be kept, but new clients requesting the image will be rejected. 0 = never time_t delete_hard; // unixtime telling when this image should be deleted, no matter if there are still clients connected. 0 = never - uint8_t relayed; // TRUE if relayed from other server (needs dnbd3 client module loaded) + pthread_spinlock_t lock; } dnbd3_image_t; typedef struct @@ -51,7 +59,8 @@ typedef struct uint16_t len; uint8_t data[65535]; } dnbd3_binstring_t; -// Do not always allocate as much memory as required to hold the entire binstring struct, but only as much as is required to hold the actual data +// Do not always allocate as much memory as required to hold the entire binstring struct, +// but only as much as is required to hold the actual data #define NEW_BINSTRING(_name, _len) \ dnbd3_binstring_t *_name = malloc(sizeof(uint16_t) + _len); \ _name->len = _len @@ -63,30 +72,37 @@ typedef struct uint8_t is_server; // TRUE if a server in proxy mode, FALSE if real client pthread_t thread; dnbd3_image_t *image; + pthread_spinlock_t lock; GSList *sendqueue; // list of dnbd3_binstring_t* } dnbd3_client_t; typedef struct { - gchar *comment; - GSList *namespaces; // List of dnbd3_namespace_t - dnbd3_host_t host; - uint8_t unreachable; -} dnbd3_trusted_server_t; + time_t last_told; + dnbd3_host_t host; + char comment[COMMENT_LENGTH]; +} dnbd3_alt_server_t; typedef struct { - char *name; - uint8_t auto_replicate; - uint8_t recursive; -} dnbd3_namespace_t; + char comment[COMMENT_LENGTH]; + dnbd3_host_t host; + dnbd3_host_t mask; +} dnbd3_acess_rules_t; -extern GSList *_dnbd3_clients; // of dnbd3_client_t -extern pthread_spinlock_t _spinlock; -extern char *_config_file_name, *_rpc_password, *_cache_dir; -extern GSList *_dnbd3_images; // of dnbd3_image_t -extern GSList *_trusted_servers; +extern dnbd3_client_t *_clients[SERVER_MAX_CLIENTS]; +extern int _num_clients; +extern pthread_spinlock_t _clients_lock; + +extern dnbd3_image_t *_images[SERVER_MAX_IMAGES]; +extern int _num_images; +extern pthread_spinlock_t _images_lock; +extern dnbd3_alt_server_t *_alt_servers[SERVER_MAX_ALTS]; +extern int _num_alts; +extern pthread_spinlock_t _alts_lock; + +extern char *_config_file_name, *_rpc_password, *_cache_dir; #ifdef _DEBUG extern int _fake_delay; -- cgit v1.2.3-55-g7522