From f9b94dcafa867c38dfaeb9b24f37b392d1ad80d8 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 14 Jan 2015 13:55:34 +0100 Subject: [SERVER] Crank up warning levels of gcc and fix them all (mostly sign compare and some unused params) Also allow newline at end of alt-servers file without complaining about it not being a valid alt server definition. --- src/kernel/sysfs.c | 5 ++++- src/server/altservers.c | 15 ++++++++++----- src/server/fileutil.c | 2 +- src/server/globals.c | 2 +- src/server/globals.h | 2 +- src/server/image.c | 23 ++++++++++++----------- src/server/integrity.c | 2 +- src/server/locks.c | 2 +- src/server/net.c | 2 +- src/server/protocol.h | 6 +++--- src/server/uplink.c | 4 ++-- src/types.h | 6 ++++++ 12 files changed, 43 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/kernel/sysfs.c b/src/kernel/sysfs.c index d219c86..efe1cad 100644 --- a/src/kernel/sysfs.c +++ b/src/kernel/sysfs.c @@ -189,11 +189,14 @@ struct kobj_type device_ktype = void dnbd3_sysfs_init(dnbd3_device_t *dev) { + int error; struct kobject *kobj = &dev->kobj; struct kobj_type *ktype = &device_ktype; struct kobject *parent = &disk_to_dev(dev->disk)->kobj; - kobject_init_and_add(kobj, ktype, parent, "net"); + error = kobject_init_and_add(kobj, ktype, parent, "%s", "net"); + if (error) + printk("Error initializing dnbd3 device!\n"); } void dnbd3_sysfs_exit(dnbd3_device_t *dev) diff --git a/src/server/altservers.c b/src/server/altservers.c index 457405f..e9bdba5 100644 --- a/src/server/altservers.c +++ b/src/server/altservers.c @@ -66,8 +66,7 @@ int altservers_load() FILE *fp = fopen( name, "r" ); free( name ); if ( fp == NULL ) return -1; - while ( !feof( fp ) ) { - if ( fgets( buffer, 1000, fp ) == NULL ) break; + while ( fgets( buffer, 1000, fp ) != NULL ) { bool isPrivate = false; bool isClientOnly = false; for (line = buffer; *line != '\0'; ) { // Trim left and scan for "-" prefix @@ -76,9 +75,15 @@ int altservers_load() else if ( *line != ' ' && *line != '\t' ) break; line++; } + if ( *line == '\r' || *line == '\n' || *line == '\0' ) continue; // Ignore empty lines trim_right( line ); - space = strchr( line, ' ' ); - if ( space != NULL ) *space++ = '\0'; + space = line; + while ( *space != '\0' ) { + if ( *space == ' ' || *space == '\t' ) break; + space++; + } + if ( *space == '\0' ) space = NULL; + else *space++ = '\0'; if ( !parse_address( line, &host ) ) { if ( space != NULL ) *--space = ' '; memlogf( "[WARNING] Invalid entry in alt-servers file ignored: '%s'", line ); @@ -336,7 +341,7 @@ void altservers_serverFailed(const dnbd3_host_t * const host) * will update quite quickly. Needs to be improved some time, ie. by only * updating the rtt if the last update was at least X seconds ago. */ -static void *altservers_main(void *data) +static void *altservers_main(void *data UNUSED) { const int ALTS = 4; int ret, itLink, itAlt, numAlts; diff --git a/src/server/fileutil.c b/src/server/fileutil.c index d16c4d8..645519b 100644 --- a/src/server/fileutil.c +++ b/src/server/fileutil.c @@ -53,7 +53,7 @@ bool file_alloc(int fd, uint64_t offset, uint64_t size) { if ( fallocate( fd, 0, offset, size ) == 0 ) return true; // fast way if ( posix_fallocate( fd, offset, size ) == 0 ) return true; // slow way - if ( lseek( fd, offset + size - 1, SEEK_SET ) != offset ) return false; // dumb way + if ( lseek( fd, offset + size - 1, SEEK_SET ) != (off_t)offset ) return false; // dumb way if ( write( fd, "", 1 ) != 1 ) return false; return true; } diff --git a/src/server/globals.c b/src/server/globals.c index b441c8e..e5f844d 100644 --- a/src/server/globals.c +++ b/src/server/globals.c @@ -22,7 +22,7 @@ int _clientTimeout = 15000; #define SAVE_TO_VAR_BOOL(ss, kk) do { if (strcmp(section, #ss) == 0 && strcmp(key, #kk) == 0) _ ## kk = atoi(value) != 0 || strcmp(value, "true") == 0 || strcmp(value, "True") == 0 || strcmp(value, "true") == 0; } while (0) #define SAVE_TO_VAR_INT(ss, kk) do { if (strcmp(section, #ss) == 0 && strcmp(key, #kk) == 0) _ ## kk = atoi(value); } while (0) -static int ini_handler(void *custom, const char* section, const char* key, const char* value) +static int ini_handler(void *custom UNUSED, const char* section, const char* key, const char* value) { if ( _basePath == NULL ) SAVE_TO_VAR_STR( dnbd3, basePath ); SAVE_TO_VAR_BOOL( dnbd3, vmdkLegacyMode ); diff --git a/src/server/globals.h b/src/server/globals.h index 4b99e38..1edf44f 100644 --- a/src/server/globals.h +++ b/src/server/globals.h @@ -53,7 +53,7 @@ struct _dnbd3_connection dnbd3_host_t betterServer; // The better server int betterFd; // Active connection to better server, ready to use uint8_t *recvBuffer; // Buffer for receiving payload - int recvBufferLen; // Len of ^^ + uint32_t recvBufferLen; // Len of ^^ volatile bool shutdown; // signal this thread to stop, must only be set from uplink_shutdown() or cleanup in uplink_mainloop() int replicatedLastBlock; // bool telling if the last block has been replicated yet uint64_t replicationHandle; // Handle of pending replication request diff --git a/src/server/image.c b/src/server/image.c index e6d0ab4..27b737e 100644 --- a/src/server/image.c +++ b/src/server/image.c @@ -566,14 +566,15 @@ static bool image_load(char *base, char *path, int withUplink) goto load_error; } // Determine file size - int64_t fileSize = lseek( fdImage, 0, SEEK_END ); - if ( fileSize < 0 ) { + const off_t seekret = lseek( fdImage, 0, SEEK_END ); + if ( seekret < 0 ) { memlogf( "[ERROR] Could not seek to end of file '%s'", path ); goto load_error; - } else if ( fileSize == 0 ) { + } else if ( seekret == 0 ) { memlogf( "[WARNING] Empty image file '%s'", path ); goto load_error; } + uint64_t fileSize = (uint64_t)seekret; // Filesize must be multiple of 4096 if ( fileSize % DNBD3_BLOCK_SIZE != 0 ) { memlogf( "[INFO] Image size of '%s' is not a multiple of %d, fixing...", path, (int)DNBD3_BLOCK_SIZE ); @@ -715,9 +716,9 @@ static uint8_t* image_loadCacheMap(const char * const imagePath, const int64_t f sprintf( mapFile, "%s.map", imagePath ); int fdMap = open( mapFile, O_RDONLY ); if ( fdMap >= 0 ) { - size_t map_size = IMGSIZE_TO_MAPBYTES( fileSize ); + const int map_size = IMGSIZE_TO_MAPBYTES( fileSize ); retval = calloc( 1, map_size ); - int rd = read( fdMap, retval, map_size ); + const ssize_t rd = read( fdMap, retval, map_size ); if ( map_size != rd ) { memlogf( "[WARNING] Could only read %d of expected %d bytes of cache map of '%s'", (int)rd, (int)map_size, fileSize ); // Could not read complete map, that means the rest of the image file will be considered incomplete @@ -750,7 +751,7 @@ static uint32_t* image_loadCrcList(const char * const imagePath, const int64_t f memlogf( "[WARNING] Error reading first crc32 of '%s'", imagePath ); } else { retval = calloc( hashBlocks, sizeof(uint32_t) ); - if ( read( fdHash, retval, hashBlocks * sizeof(uint32_t) ) != hashBlocks * sizeof(uint32_t) ) { + if ( read( fdHash, retval, hashBlocks * sizeof(uint32_t) ) != hashBlocks * (ssize_t)sizeof(uint32_t) ) { free( retval ); retval = NULL; memlogf( "[WARNING] Could not read crc32 list of '%s'", imagePath ); @@ -1061,7 +1062,7 @@ bool image_generateCrcFile(char *image) int remaining = HASH_BLOCK_SIZE; hasSum = false; while ( remaining > 0 ) { - const int blockSize = MIN(remaining, sizeof(buffer)); + const int blockSize = MIN(remaining, (int)sizeof(buffer)); const int ret = read( fdImage, buffer, blockSize ); if ( ret < 0 ) { // Error printf( "Read error\n" ); @@ -1163,9 +1164,9 @@ int image_getCompletenessEstimate(const dnbd3_image_t * const image) if ( image->cache_map == NULL ) return image->working ? 100 : 0; int i; int percent = 0; - const size_t len = IMGSIZE_TO_MAPBYTES(image->filesize); + const int len = IMGSIZE_TO_MAPBYTES(image->filesize); if ( len == 0 ) return 0; - for (i = 0; i < len; ++i) { + for ( i = 0; i < len; ++i ) { if ( image->cache_map[i] == 0xff ) { percent += 100; } else if ( image->cache_map[i] > 0 ) { @@ -1192,7 +1193,7 @@ bool image_checkBlocksCrc32(int fd, uint32_t *crc32list, const int *blocks, cons int bytes = 0; const int bytesToGo = MIN(HASH_BLOCK_SIZE, fileSize - ((int64_t)*blocks * HASH_BLOCK_SIZE)); while ( bytes < bytesToGo ) { - const int n = MIN(sizeof(buffer), bytesToGo - bytes); + const int n = MIN((int)sizeof(buffer), bytesToGo - bytes); const int r = read( fd, buffer, n ); if ( r <= 0 ) { memlogf( "Read error" ); @@ -1251,7 +1252,7 @@ static bool image_ensureDiskSpace(uint64_t size) memlogf( "[WARNING] Could not get free disk space (errno %d), will assume there is enough space left... ;-)\n", e ); return true; } - if ( available > size ) return true; + if ( (uint64_t)available > size ) return true; if ( dnbd3_serverUptime() < 10 * 3600 ) { memlogf( "[INFO] Only %dMiB free, %dMiB requested, but server uptime < 10 hours...", (int)(available / (1024ll * 1024ll)), (int)(size / (1024 * 1024)) ); diff --git a/src/server/integrity.c b/src/server/integrity.c index 2911085..547f8d3 100644 --- a/src/server/integrity.c +++ b/src/server/integrity.c @@ -97,7 +97,7 @@ void integrity_check(dnbd3_image_t *image, int block) pthread_mutex_unlock( &integrityQueueLock ); } -static void* integrity_main(void *data) +static void* integrity_main(void * data UNUSED) { int i; uint8_t *buffer = NULL; diff --git a/src/server/locks.c b/src/server/locks.c index 3c1956f..cf35986 100644 --- a/src/server/locks.c +++ b/src/server/locks.c @@ -259,7 +259,7 @@ void debug_dump_lock_stats() pthread_spin_unlock( &initdestory ); } -static void *debug_thread_watchdog(void *something) +static void *debug_thread_watchdog(void *something UNUSED) { setThreadName("debug-watchdog"); while ( !_shutdown ) { diff --git a/src/server/net.c b/src/server/net.c index b7c0ff2..8e8741a 100644 --- a/src/server/net.c +++ b/src/server/net.c @@ -107,7 +107,7 @@ static inline bool send_reply(int sock, dnbd3_reply_t *reply, void *payload) iov[0].iov_len = sizeof(dnbd3_reply_t); iov[1].iov_base = payload; iov[1].iov_len = (size_t)size; - if ( writev( sock, iov, 2 ) != sizeof(dnbd3_reply_t) + size ) { + if ( (size_t)writev( sock, iov, 2 ) != sizeof(dnbd3_reply_t) + size ) { printf( "[DEBUG] Send failed (reply with payload of %u bytes)\n", size ); return false; } diff --git a/src/server/protocol.h b/src/server/protocol.h index b0a1f43..ad286d1 100644 --- a/src/server/protocol.h +++ b/src/server/protocol.h @@ -59,7 +59,7 @@ static inline bool dnbd3_select_image(int sock, char *lower_name, uint16_t rid, iov[0].iov_len = sizeof(request); iov[1].iov_base = &serialized; iov[1].iov_len = len; - return writev( sock, iov, 2 ) == len + sizeof(request); + return writev( sock, iov, 2 ) == len + (ssize_t)sizeof(request); } static inline bool dnbd3_get_block(int sock, uint64_t offset, uint32_t size, uint64_t handle) @@ -95,9 +95,9 @@ static inline bool dnbd3_get_crc32(int sock, uint32_t *master, void *buffer, siz if ( reply.cmd != CMD_GET_CRC32 || reply.size > *bufferLen ) return false; *bufferLen = reply.size; if ( recv( sock, master, sizeof(uint32_t), MSG_WAITALL | MSG_NOSIGNAL ) != sizeof(uint32_t) ) return false; - int done = 0; + uint32_t done = 0; while ( done < reply.size ) { - const int ret = recv( sock, (char*)buffer + done, reply.size - done, 0 ); + const ssize_t ret = recv( sock, (char*)buffer + done, reply.size - done, 0 ); if ( ret <= 0 ) return false; done += ret; } diff --git a/src/server/uplink.c b/src/server/uplink.c index 0b526fd..cc82fe0 100644 --- a/src/server/uplink.c +++ b/src/server/uplink.c @@ -458,12 +458,11 @@ static void uplink_sendReplicationRequest(dnbd3_connection_t *link) spin_unlock( &image->lock ); return; } - const size_t len = IMGSIZE_TO_MAPBYTES( image->filesize ) - 1; + const int len = IMGSIZE_TO_MAPBYTES( image->filesize ) - 1; const uint32_t requestBlockSize = DNBD3_BLOCK_SIZE * 8; for (int i = 0; i <= len; ++i) { if ( image->cache_map == NULL || link->fd == -1 ) break; if ( image->cache_map[i] == 0xff || (i == len && link->replicatedLastBlock) ) continue; - if ( i == len ) link->replicatedLastBlock = true; // Special treatment, last byte in map could represent less than 8 blocks link->replicationHandle = 1; // Prevent race condition spin_unlock( &image->lock ); // Unlocked - do not break or continue here... @@ -474,6 +473,7 @@ static void uplink_sendReplicationRequest(dnbd3_connection_t *link) printf( "[DEBUG] Error sending background replication request to uplink server!\n" ); return; } + if ( i == len ) link->replicatedLastBlock = true; // Special treatment, last byte in map could represent less than 8 blocks return; // Request was sent, bail out, nothing is locked } spin_unlock( &image->lock ); diff --git a/src/types.h b/src/types.h index 027a1f1..7303baa 100644 --- a/src/types.h +++ b/src/types.h @@ -34,6 +34,12 @@ #define MAX(a,b) ((a) > (b) ? (a) : (b)) #endif +#ifdef __GNUC__ +#define UNUSED __attribute__ ((unused)) +#else +#define UNUSED dfg dsfg dg +#endif + // ioctl #define DNBD3_MAGIC 'd' #define IOCTL_OPEN _IO(0xab, 1) -- cgit v1.2.3-55-g7522