diff options
author | sr | 2012-09-03 21:00:26 +0200 |
---|---|---|
committer | sr | 2012-09-03 21:00:26 +0200 |
commit | 60b2ba6ef9ed779d750958b6422f05c93a4a2d91 (patch) | |
tree | 46fdacf6a9439947e91af4c3d9de3006d41e5380 /src/server/helper.h | |
parent | [*] Fixed and unified formatting (diff) | |
download | dnbd3-60b2ba6ef9ed779d750958b6422f05c93a4a2d91.tar.gz dnbd3-60b2ba6ef9ed779d750958b6422f05c93a4a2d91.tar.xz dnbd3-60b2ba6ef9ed779d750958b6422f05c93a4a2d91.zip |
[SERVER] Check which dnbd3 devices are idle and ready to use for proxy mode
[SERVER] Skeleton of server-to-server communication
[SERVER] Update access-time of images in use by actual clients
[*] Add dnbd3_host_t type to handle address+port+addrtype consistently across the project
Diffstat (limited to 'src/server/helper.h')
-rw-r--r-- | src/server/helper.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/server/helper.h b/src/server/helper.h new file mode 100644 index 0000000..e787c42 --- /dev/null +++ b/src/server/helper.h @@ -0,0 +1,30 @@ +#ifndef HELPER_H_ +#define HELPER_H_ + +#include "server.h" +#include <netinet/in.h> +#include <string.h> + +char parse_address(char *string, dnbd3_host_t *host); +char host_to_string(const dnbd3_host_t *host, char *target, size_t targetlen); +char is_valid_namespace(char *namespace); +char is_valid_imagename(char *namespace); +void strtolower(char *string); + +static inline int is_same_server(const dnbd3_trusted_server_t *const a, const dnbd3_trusted_server_t *const b) +{ + return (a->host.type == b->host.type) + && (a->host.port == b->host.port) + && (0 == memcmp(a->host.addr, b->host.addr, (a->host.type == AF_INET ? 4 : 16))); +} + +// one byte in the map covers 8 4kib blocks, so 32kib per byte +// "+ (1 << 15) - 1" is required to account for the last bit of +// the image that is smaller than 32kib +// this would be the case whenever the image file size is not a +// multiple of 32kib (= the number of blocks is not divisible by 8) +// ie: if the image is 49152 bytes and you do 49152 >> 15 you get 1, +// but you actually need 2 bytes to have a complete cache map +#define IMGSIZE_TO_MAPBYTES(bytes) ((int)(((bytes) + (1 << 15) - 1) >> 15)) + +#endif |