summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2020-03-06 16:02:54 +0100
committerSimon Rettberg2020-03-06 16:02:54 +0100
commit9f11c67b291b50e0f1c98d2e85db22a33d2e2d11 (patch)
treea9f0b2e8598ca6cd3d96766c568d3bd6e4debf76
parent[SERVER] Handle "warn unused result" cases (diff)
downloaddnbd3-9f11c67b291b50e0f1c98d2e85db22a33d2e2d11.tar.gz
dnbd3-9f11c67b291b50e0f1c98d2e85db22a33d2e2d11.tar.xz
dnbd3-9f11c67b291b50e0f1c98d2e85db22a33d2e2d11.zip
[SERVER] Add printf macro for image (name:rid as %s:%d)
-rw-r--r--src/server/altservers.c4
-rw-r--r--src/server/globals.h1
-rw-r--r--src/server/image.c32
-rw-r--r--src/server/uplink.c20
4 files changed, 27 insertions, 30 deletions
diff --git a/src/server/altservers.c b/src/server/altservers.c
index 380737c..35da3a2 100644
--- a/src/server/altservers.c
+++ b/src/server/altservers.c
@@ -14,7 +14,7 @@
#include <inttypes.h>
#include <jansson.h>
-#define LOG(lvl, msg, ...) logadd(lvl, msg " (%s:%d)", __VA_ARGS__, image->name, (int)image->rid)
+#define LOG(lvl, msg, ...) logadd(lvl, msg " (%s:%d)", __VA_ARGS__, PIMG(image))
#define LOG_GOTO(jumplabel, lvl, ...) do { LOG(lvl, __VA_ARGS__); goto jumplabel; } while (0);
#define ERROR_GOTO(jumplabel, ...) LOG_GOTO(jumplabel, LOG_ERROR, __VA_ARGS__)
@@ -524,7 +524,7 @@ static void altservers_findUplinkInternal(dnbd3_uplink_t *uplink)
logadd( LOG_WARNING, "Image has gone away that was queued for RTT measurement" );
return;
}
- LOG( LOG_DEBUG2, "Running alt check for %s:%d", image->name, (int)image->rid );
+ logadd( LOG_DEBUG2, "Running alt check for %s:%d", PIMG(image) );
assert( uplink->rttTestResult == RTT_INPROGRESS );
// Test them all
dnbd3_server_connection_t best = { .fd = -1 };
diff --git a/src/server/globals.h b/src/server/globals.h
index 211fe2d..1bb6857 100644
--- a/src/server/globals.h
+++ b/src/server/globals.h
@@ -148,6 +148,7 @@ struct _dnbd3_image
uint16_t rid; // revision of image
pthread_mutex_t lock;
};
+#define PIMG(x) (x)->name, (int)(x)->rid
struct _dnbd3_client
{
diff --git a/src/server/image.c b/src/server/image.c
index 32c9efe..18e91d9 100644
--- a/src/server/image.c
+++ b/src/server/image.c
@@ -290,13 +290,11 @@ bool image_ensureOpen(dnbd3_image_t *image)
if ( image->crc32 == NULL ) {
// Cannot verify further, hope for the best
image->problem.changed = false;
- logadd( LOG_DEBUG1, "Size of image %s:%d changed back to expected value",
- image->name, (int)image->rid );
+ logadd( LOG_DEBUG1, "Size of image %s:%d changed back to expected value", PIMG(image) );
} else if ( image_checkRandomBlocks( image, 1, newFd ) ) {
// This should have checked the first block (if complete) -> All is well again
image->problem.changed = false;
- logadd( LOG_DEBUG1, "Size and CRC of image %s:%d changed back to expected value",
- image->name, (int)image->rid );
+ logadd( LOG_DEBUG1, "Size and CRC of image %s:%d changed back to expected value", PIMG(image) );
}
} else {
image->problem.changed = sizeChanged;
@@ -624,7 +622,7 @@ static dnbd3_image_t* image_free(dnbd3_image_t *image)
{
assert( image != NULL );
assert( image->users == 0 );
- logadd( ( _shutdown ? LOG_DEBUG1 : LOG_INFO ), "Freeing image %s:%d", image->name, (int)image->rid );
+ logadd( ( _shutdown ? LOG_DEBUG1 : LOG_INFO ), "Freeing image %s:%d", PIMG(image) );
// uplink_shutdown might return false to tell us
// that the shutdown is in progress. Bail out since
// this will get called again when the uplink is done.
@@ -852,16 +850,16 @@ static bool image_load(char *base, char *path, int withUplink)
// Compare data just loaded to identical image we apparently already loaded
if ( existing != NULL ) {
if ( existing->realFilesize != realFilesize ) {
- logadd( LOG_WARNING, "Size of image '%s:%d' has changed.", existing->name, (int)existing->rid );
+ logadd( LOG_WARNING, "Size of image '%s:%d' has changed.", PIMG(existing) );
// Image will be replaced below
} else if ( existing->crc32 != NULL && crc32list != NULL
&& memcmp( existing->crc32, crc32list, sizeof(uint32_t) * hashBlockCount ) != 0 ) {
- logadd( LOG_WARNING, "CRC32 list of image '%s:%d' has changed.", existing->name, (int)existing->rid );
+ logadd( LOG_WARNING, "CRC32 list of image '%s:%d' has changed.", PIMG(existing) );
logadd( LOG_WARNING, "The image will be reloaded, but you should NOT replace existing images while the server is running." );
logadd( LOG_WARNING, "Actually even if it's not running this should never be done. Use a new RID instead!" );
// Image will be replaced below
} else if ( existing->crc32 == NULL && crc32list != NULL ) {
- logadd( LOG_INFO, "Found CRC-32 list for already loaded image '%s:%d', adding...", existing->name, (int)existing->rid );
+ logadd( LOG_INFO, "Found CRC-32 list for already loaded image '%s:%d', adding...", PIMG(existing) );
existing->crc32 = crc32list;
existing->masterCrc32 = masterCrc;
crc32list = NULL;
@@ -869,7 +867,7 @@ static bool image_load(char *base, char *path, int withUplink)
goto load_error; // Keep existing
} else if ( existing->ref_cacheMap != NULL && cache == NULL ) {
// Just ignore that fact, if replication is really complete the cache map will be removed anyways
- logadd( LOG_INFO, "Image '%s:%d' has no cache map on disk!", existing->name, (int)existing->rid );
+ logadd( LOG_INFO, "Image '%s:%d' has no cache map on disk!", PIMG(existing) );
function_return = true;
goto load_error; // Keep existing
} else {
@@ -940,7 +938,7 @@ static bool image_load(char *base, char *path, int withUplink)
image = image_free( image );
goto load_error;
}
- logadd( LOG_DEBUG1, "Loaded image '%s:%d'\n", image->name, (int)image->rid );
+ logadd( LOG_DEBUG1, "Loaded image '%s:%d'\n", PIMG(image) );
function_return = true;
// Clean exit:
@@ -1790,7 +1788,7 @@ static bool image_ensureDiskSpace(uint64_t size, bool force)
image_release( oldest ); // We did users++ above; image might have to be freed entirely
return false;
}
- logadd( LOG_INFO, "'%s:%d' has to go!", oldest->name, (int)oldest->rid );
+ logadd( LOG_INFO, "'%s:%d' has to go!", PIMG(oldest) );
char *filename = strdup( oldest->path ); // Copy name as we remove the image first
oldest = image_remove( oldest ); // Remove from list first...
oldest = image_release( oldest ); // Decrease users counter; if it falls to 0, image will be freed
@@ -1825,10 +1823,8 @@ static void* closeUnusedFds(void* nix UNUSED)
dnbd3_image_t * const image = _images[i];
if ( image == NULL || image->readFd == -1 )
continue;
- // TODO: Also close for idle uplinks (uplink_connectionShouldShutdown)
- // TODO: And close writeFd for idle uplinks....
if ( image->users == 0 && image->uplinkref == NULL && timing_reached( &image->atime, &deadline ) ) {
- logadd( LOG_DEBUG1, "Inactive fd closed for %s:%d", image->name, (int)image->rid );
+ logadd( LOG_DEBUG1, "Inactive fd closed for %s:%d", PIMG(image) );
fds[fdindex++] = image->readFd;
image->readFd = -1; // Not a race; image->users is 0 and to increase it you need imageListLock
if ( fdindex == FDCOUNT )
@@ -1900,11 +1896,11 @@ static void* saveLoadAllCacheMaps(void* nix UNUSED)
// it periodically, since we might read from a shared storage that
// another server instance is writing to.
if ( full || !cache->unchanged && !image->problem.read ) {
- logadd( LOG_DEBUG2, "Reloading cache map of %s:%d", image->name, (int)image->rid );
+ logadd( LOG_DEBUG2, "Reloading cache map of %s:%d", PIMG(image) );
dnbd3_cache_map_t *onDisk = image_loadCacheMap(image->path, image->virtualFilesize);
if ( onDisk == NULL ) {
// Should be complete now
- logadd( LOG_DEBUG1, "External replication of %s:%d complete", image->name, (int)image->rid );
+ logadd( LOG_DEBUG1, "External replication of %s:%d complete", PIMG(image) );
ref_setref( &image->ref_cacheMap, NULL );
} else {
const int mapSize = IMGSIZE_TO_MAPBYTES( image->virtualFilesize );
@@ -1945,7 +1941,7 @@ static void saveCacheMap(dnbd3_image_t *image)
if ( cache == NULL )
return; // Race - wasn't NULL in function call above...
- logadd( LOG_DEBUG2, "Saving cache map of %s:%d", image->name, (int)image->rid );
+ logadd( LOG_DEBUG2, "Saving cache map of %s:%d", PIMG(image) );
const size_t size = IMGSIZE_TO_MAPBYTES(image->virtualFilesize);
char mapfile[strlen( image->path ) + 4 + 1];
strcpy( mapfile, image->path );
@@ -2015,7 +2011,7 @@ static void allocCacheMap(dnbd3_image_t *image, bool complete)
memset( cache->map, val, byteSize );
mutex_lock( &image->lock );
if ( image->ref_cacheMap != NULL ) {
- logadd( LOG_WARNING, "BUG: allocCacheMap called but there already is a cache map for %s:%d", image->name, (int)image->rid );
+ logadd( LOG_WARNING, "BUG: allocCacheMap called but there already is a map for %s:%d", PIMG(image) );
free( cache );
} else {
ref_setref( &image->ref_cacheMap, &cache->reference );
diff --git a/src/server/uplink.c b/src/server/uplink.c
index 71d9f94..7c7cd1c 100644
--- a/src/server/uplink.c
+++ b/src/server/uplink.c
@@ -171,7 +171,7 @@ bool uplink_shutdown(dnbd3_image_t *image)
image->users++; // Prevent free while uplink shuts down
signal_call( uplink->signal );
} else {
- logadd( LOG_ERROR, "This will never happen. '%s:%d'", image->name, (int)image->rid );
+ logadd( LOG_ERROR, "This will never happen. '%s:%d'", PIMG(image) );
}
cancelAllRequests( uplink );
ref_setref( &image->uplinkref, NULL );
@@ -201,7 +201,7 @@ static void cancelAllRequests(dnbd3_uplink_t *uplink)
static void uplink_free(ref *ref)
{
dnbd3_uplink_t *uplink = container_of(ref, dnbd3_uplink_t, reference);
- logadd( LOG_DEBUG1, "Freeing uplink for '%s:%d'", uplink->image->name, (int)uplink->image->rid );
+ logadd( LOG_DEBUG1, "Freeing uplink for '%s:%d'", PIMG(uplink->image) );
assert( uplink->queueLen == 0 );
if ( uplink->signal != NULL ) {
signal_close( uplink->signal );
@@ -572,7 +572,7 @@ static void* uplink_mainloop(void *data)
}
// Don't keep uplink established if we're idle for too much
if ( uplink_connectionShouldShutdown( uplink ) ) {
- logadd( LOG_DEBUG1, "Closing idle uplink for image %s:%d", uplink->image->name, (int)uplink->image->rid );
+ logadd( LOG_DEBUG1, "Closing idle uplink for image %s:%d", PIMG(uplink->image) );
goto cleanup;
}
}
@@ -915,11 +915,13 @@ static void uplink_handleReceive(dnbd3_uplink_t *uplink)
tryAgain = false;
continue; // Write handle to image successfully re-opened, try again
}
- logadd( LOG_DEBUG1, "Error trying to cache data for %s:%d -- errno=%d", uplink->image->name, (int)uplink->image->rid, err );
+ logadd( LOG_DEBUG1, "Error trying to cache data for %s:%d -- errno=%d",
+ PIMG(uplink->image), err );
break;
}
if ( unlikely( ret <= 0 || (uint32_t)ret > inReply.size - done ) ) {
- logadd( LOG_WARNING, "Unexpected return value %d from pwrite to %s:%d", ret, uplink->image->name, (int)uplink->image->rid );
+ logadd( LOG_WARNING, "Unexpected return value %d from pwrite to %s:%d",
+ ret, PIMG(uplink->image) );
break;
}
done += (uint32_t)ret;
@@ -929,7 +931,7 @@ static void uplink_handleReceive(dnbd3_uplink_t *uplink)
}
if ( unlikely( ret == -1 && ( err == EBADF || err == EINVAL || err == EIO ) ) ) {
logadd( LOG_WARNING, "Error writing received data for %s:%d (errno=%d); disabling caching.",
- uplink->image->name, (int)uplink->image->rid, err );
+ PIMG(uplink->image), err );
}
}
// 2) Figure out which clients are interested in it
@@ -1098,8 +1100,7 @@ static void uplink_addCrc32(dnbd3_uplink_t *uplink)
lists_crc = crc32( lists_crc, (uint8_t*)buffer, bytes );
lists_crc = net_order_32( lists_crc );
if ( lists_crc != masterCrc ) {
- logadd( LOG_WARNING, "Received corrupted crc32 list from uplink server (%s:%d)!",
- uplink->image->name, (int)uplink->image->rid );
+ logadd( LOG_WARNING, "Received corrupted crc32 list from uplink server (%s:%d)!", PIMG(uplink->image) );
free( buffer );
return;
}
@@ -1115,8 +1116,7 @@ static void uplink_addCrc32(dnbd3_uplink_t *uplink)
close( fd );
if ( (size_t)ret != sizeof(masterCrc) + bytes ) {
unlink( path );
- logadd( LOG_WARNING, "Could not write crc32 file for %s:%d",
- uplink->image->name, (int)uplink->image->rid );
+ logadd( LOG_WARNING, "Could not write crc32 file for %s:%d", PIMG(uplink->image) );
}
}
}