diff options
Diffstat (limited to 'src/server/globals.h')
-rw-r--r-- | src/server/globals.h | 93 |
1 files changed, 71 insertions, 22 deletions
diff --git a/src/server/globals.h b/src/server/globals.h index df8c595..bde1184 100644 --- a/src/server/globals.h +++ b/src/server/globals.h @@ -1,9 +1,9 @@ #ifndef _GLOBALS_H_ #define _GLOBALS_H_ -#include "../types.h" -#include "../shared/fdsignal.h" -#include "../serverconfig.h" +#include <dnbd3/types.h> +#include <dnbd3/shared/fdsignal.h> +#include <dnbd3/config/server.h> #include <stdint.h> #include <stdatomic.h> #include <time.h> @@ -18,18 +18,30 @@ typedef struct _dnbd3_uplink dnbd3_uplink_t; typedef struct _dnbd3_image dnbd3_image_t; typedef struct _dnbd3_client dnbd3_client_t; -typedef struct +typedef void (*uplink_callback)(void *data, uint64_t handle, uint64_t start, uint32_t length, const char *buffer); + +typedef struct _dnbd3_queue_client { - uint64_t handle; // Client defined handle to pass back in reply - uint64_t from; // First byte offset of requested block (ie. 4096) - uint64_t to; // Last byte + 1 of requested block (ie. 8192, if request len is 4096, resulting in bytes 4096-8191) - dnbd3_client_t * client; // Client to send reply to - int status; // status of this entry: ULR_* -#ifdef _DEBUG - ticks entered; // When this request entered the queue (for debugging) + struct _dnbd3_queue_client *next; + void* data; // Passed back to callback + uint64_t handle; // Passed back to callback + uint64_t from, to; // Client range + uplink_callback callback; // Callback function +} dnbd3_queue_client_t; + +typedef struct _dnbd3_queue_entry +{ + struct _dnbd3_queue_entry *next; + uint64_t handle; // Our handle for this entry + uint64_t from; // First byte offset of requested block (ie. 4096) + uint64_t to; // Last byte + 1 of requested block (ie. 8192, if request len is 4096, resulting in bytes 4096-8191) + dnbd3_queue_client_t *clients; +#ifdef DEBUG + ticks entered; // When this request entered the queue (for debugging) #endif - uint8_t hopCount; // How many hops this request has already taken across proxies -} dnbd3_queued_request_t; + uint8_t hopCount; // How many hops this request has already taken across proxies + bool sent; // Already sent to uplink? +} dnbd3_queue_entry_t; typedef struct _ns { @@ -91,11 +103,12 @@ struct _dnbd3_uplink bool cycleDetected; // connection cycle between proxies detected for current remote server int nextReplicationIndex; // Which index in the cache map we should start looking for incomplete blocks at // If BGR == BGR_HASHBLOCK, -1 means "currently no incomplete block" - uint64_t replicationHandle; // Handle of pending replication request atomic_uint_fast64_t bytesReceived; // Number of bytes received by the uplink since startup. - atomic_int queueLen; // length of queue - uint32_t idleTime; // How many seconds the uplink was idle (apart from keep-alives) - dnbd3_queued_request_t queue[SERVER_MAX_UPLINK_QUEUE]; + atomic_uint_fast64_t bytesReceivedLastSave; // Number of bytes received when we last saved the cache map + int queueLen; // length of queue + int idleTime; // How many seconds the uplink was idle (apart from keep-alives) + dnbd3_queue_entry_t *queue; + atomic_uint_fast32_t queueId; dnbd3_alt_local_t altData[SERVER_MAX_ALTS]; }; @@ -110,6 +123,8 @@ typedef struct typedef struct { ref reference; + atomic_bool dirty; // Cache map has been modified outside uplink (only integrity checker for now) + bool unchanged; // How many times in a row a reloaded cache map went unchanged _Atomic uint8_t map[]; } dnbd3_cache_map_t; @@ -128,7 +143,6 @@ struct _dnbd3_image uint64_t virtualFilesize; // virtual size of image (real size rounded up to multiple of 4k) uint64_t realFilesize; // actual file size on disk ticks atime; // last access time - ticks lastWorkCheck; // last time a non-working image has been checked ticks nextCompletenessEstimate; // next time the completeness estimate should be updated uint32_t *crc32; // list of crc32 checksums for each 16MiB block in image uint32_t masterCrc32; // CRC-32 of the crc-32 list @@ -136,10 +150,18 @@ struct _dnbd3_image atomic_int completenessEstimate; // Completeness estimate in percent atomic_int users; // clients currently using this image. XXX Lock on imageListLock when modifying and checking whether the image should be freed. Reading it elsewhere is fine without the lock. int id; // Unique ID of this image. Only unique in the context of this running instance of DNBD3-Server - atomic_bool working; // true if image exists and completeness is == 100% or a working upstream proxy is connected + struct { + atomic_bool read; // Error reading from file + atomic_bool write; // Error writing to file + atomic_bool changed; // File disappeared or changed, thorough check required if it seems to be back + atomic_bool uplink; // No uplink connected + atomic_bool queue; // Too many requests waiting on uplink + } problem; uint16_t rid; // revision of image + bool accessed; // image was accessed since .meta was written pthread_mutex_t lock; }; +#define PIMG(x) (x)->name, (int)(x)->rid struct _dnbd3_client { @@ -147,6 +169,7 @@ struct _dnbd3_client atomic_uint_fast64_t bytesSent; // Byte counter for this client. dnbd3_image_t * _Atomic image; // Image in use by this client, or NULL during handshake int sock; + _Atomic uint8_t relayedCount; // How many requests are in-flight to the uplink server bool isServer; // true if a server in proxy mode, false if real client dnbd3_host_t host; char hostName[HOSTNAMELEN]; // inet_ntop version of host @@ -206,12 +229,12 @@ extern atomic_bool _removeMissingImages; /** * Read timeout when waiting for or sending data on an uplink */ -extern atomic_int _uplinkTimeout; +extern atomic_uint _uplinkTimeout; /** * Read timeout when waiting for or sending data from/to client */ -extern atomic_int _clientTimeout; +extern atomic_uint _clientTimeout; /** * If true, images with no active client will have their fd closed after some @@ -234,6 +257,11 @@ extern atomic_int _backgroundReplication; extern atomic_int _bgrMinClients; /** + * How many in-flight replication requests we should target (per uplink) + */ +extern atomic_int _bgrWindowSize; + +/** * (In proxy mode): If connecting client is a proxy, and the requested image * is not known locally, should we ask our known alt servers for it? * Otherwise the request is rejected. @@ -255,6 +283,12 @@ extern atomic_bool _lookupMissingForProxy; extern atomic_bool _sparseFiles; /** + * If true, don't abort image replication if preallocating + * the image fails, but retry with sparse file. + */ +extern atomic_bool _ignoreAllocErrors; + +/** * Port to listen on (default: #define PORT (5003)) */ extern atomic_int _listenPort; @@ -275,7 +309,7 @@ extern atomic_int _maxImages; * Usually this isn't even a megabyte for "real" clients (blockdev * or fuse). */ -extern atomic_int _maxPayload; +extern atomic_uint _maxPayload; /** * If in proxy mode, don't replicate images that are @@ -298,6 +332,21 @@ extern atomic_bool _pretendClient; extern atomic_int _autoFreeDiskSpaceDelay; /** + * When handling a client request, this sets the maximum amount + * of bytes we prefetch offset right at the end of the client request. + * The prefetch size will be MIN( length * 3, _maxPrefetch ), if + * length <= _maxPrefetch, so effectively, setting this to 0 disables + * any prefetching. + */ +extern atomic_uint _maxPrefetch; + +/** + * Use with care. Can severely degrade performance. + * Set either 0 or very high. + */ +extern atomic_uint _minRequestSize; + +/** * Load the server configuration. */ void globals_loadConfig(); |