This involved several things:
- Remove unused variables
- Mark variables that may or may not be used when specific macros are
defined, but which we still want to define for the other cases without
having to #ifdef too much, as such by way of G_GNUC_UNUSED.
- use varargs macros instead of the DEBUG[2-5] ones (which we can now do
since we require a C99 compiler).
- cast integers to what we request in the format string, and
standardize on assuming that size_t is an unsigned int everywhere.
This may not always be correct (depending on whether we do LFS
support), but debugging statements that are not 100% correct (as long
as they contain a value that maps one-on-one to the right bit pattern)
isn't a huge problem.
- Move the "include cliserv.h" to below the "include glib.h", so we
don't define macros twice.
#ifndef G_GNUC_NORETURN
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
#define G_GNUC_NORETURN __attribute__((__noreturn__))
#ifndef G_GNUC_NORETURN
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
#define G_GNUC_NORETURN __attribute__((__noreturn__))
+#define G_GNUC_UNUSED __attribute__((unused))
#else
#define G_GNUC_NORETURN
#else
#define G_GNUC_NORETURN
int cont=0;
int timeout=0;
int sdp=0;
int cont=0;
int timeout=0;
int sdp=0;
+ int G_GNUC_UNUSED nofork=0; // if -dNOFORK
u64 size64;
u32 flags;
int c;
u64 size64;
u32 flags;
int c;
/* Debugging macros */
//#define DODBG
#ifdef DODBG
/* Debugging macros */
//#define DODBG
#ifdef DODBG
-#define DEBUG( a ) printf( a )
-#define DEBUG2( a,b ) printf( a,b )
-#define DEBUG3( a,b,c ) printf( a,b,c )
-#define DEBUG4( a,b,c,d ) printf( a,b,c,d )
-#define DEBUG5( a,b,c,d,e ) printf( a,b,c,d,e )
+#define DEBUG(...) printf(__VA_ARGS__)
-#define DEBUG( a )
-#define DEBUG2( a,b )
-#define DEBUG3( a,b,c )
-#define DEBUG4( a,b,c,d )
-#define DEBUG5( a,b,c,d,e )
#endif
#ifndef PACKAGE_VERSION
#define PACKAGE_VERSION ""
#endif
#ifndef PACKAGE_VERSION
#define PACKAGE_VERSION ""
if(!i) {
msg3(LOG_INFO, "SIGCHLD received for an unknown child with PID %ld", (long)pid);
} else {
if(!i) {
msg3(LOG_INFO, "SIGCHLD received for an unknown child with PID %ld", (long)pid);
} else {
- DEBUG2("Removing %d from the list of children", pid);
+ DEBUG("Removing %d from the list of children", pid);
g_hash_table_remove(children, &pid);
}
}
g_hash_table_remove(children, &pid);
}
}
if (es > ((off_t)0)) {
return es;
} else {
if (es > ((off_t)0)) {
return es;
} else {
- DEBUG2("lseek failed: %d", errno==EBADF?1:(errno==ESPIPE?2:(errno==EINVAL?3:4)));
+ DEBUG("lseek failed: %d", errno==EBADF?1:(errno==ESPIPE?2:(errno==EINVAL?3:4)));
}
err("Could not find size of exported block device: %m");
}
err("Could not find size of exported block device: %m");
if(maxbytes && len > maxbytes)
len = maxbytes;
if(maxbytes && len > maxbytes)
len = maxbytes;
- DEBUG5("(WRITE to fd %d offset %llu len %u fua %d), ", fhandle, foffset, len, fua);
+ DEBUG("(WRITE to fd %d offset %llu len %u fua %d), ", fhandle, (long long unsigned)foffset, (unsigned int)len, fua);
myseek(fhandle, foffset);
retval = write(fhandle, buf, len);
myseek(fhandle, foffset);
retval = write(fhandle, buf, len);
if(maxbytes && len > maxbytes)
len = maxbytes;
if(maxbytes && len > maxbytes)
len = maxbytes;
- DEBUG4("(READ from fd %d offset %llu len %u), ", fhandle, foffset, len);
+ DEBUG("(READ from fd %d offset %llu len %u), ", fhandle, (long long unsigned int)foffset, (unsigned int)len);
myseek(fhandle, foffset);
return read(fhandle, buf, len);
myseek(fhandle, foffset);
return read(fhandle, buf, len);
if (!(client->server->flags & F_COPYONWRITE))
return(rawexpread_fully(a, buf, len, client));
if (!(client->server->flags & F_COPYONWRITE))
return(rawexpread_fully(a, buf, len, client));
- DEBUG3("Asked to read %d bytes at %llu.\n", len, (unsigned long long)a);
+ DEBUG("Asked to read %u bytes at %llu.\n", (unsigned int)len, (unsigned long long)a);
mapl=a/DIFFPAGESIZE; maph=(a+len-1)/DIFFPAGESIZE;
mapl=a/DIFFPAGESIZE; maph=(a+len-1)/DIFFPAGESIZE;
rdlen=(0<DIFFPAGESIZE-offset && len<(size_t)(DIFFPAGESIZE-offset)) ?
len : (size_t)DIFFPAGESIZE-offset;
if (client->difmap[mapcnt]!=(u32)(-1)) { /* the block is already there */
rdlen=(0<DIFFPAGESIZE-offset && len<(size_t)(DIFFPAGESIZE-offset)) ?
len : (size_t)DIFFPAGESIZE-offset;
if (client->difmap[mapcnt]!=(u32)(-1)) { /* the block is already there */
- DEBUG3("Page %llu is at %lu\n", (unsigned long long)mapcnt,
+ DEBUG("Page %llu is at %lu\n", (unsigned long long)mapcnt,
(unsigned long)(client->difmap[mapcnt]));
myseek(client->difffile, client->difmap[mapcnt]*DIFFPAGESIZE+offset);
if (read(client->difffile, buf, rdlen) != rdlen) return -1;
} else { /* the block is not there */
(unsigned long)(client->difmap[mapcnt]));
myseek(client->difffile, client->difmap[mapcnt]*DIFFPAGESIZE+offset);
if (read(client->difffile, buf, rdlen) != rdlen) return -1;
} else { /* the block is not there */
- DEBUG2("Page %llu is not here, we read the original one\n",
+ DEBUG("Page %llu is not here, we read the original one\n",
(unsigned long long)mapcnt);
if(rawexpread_fully(a, buf, rdlen, client)) return -1;
}
(unsigned long long)mapcnt);
if(rawexpread_fully(a, buf, rdlen, client)) return -1;
}
if (!(client->server->flags & F_COPYONWRITE))
return(rawexpwrite_fully(a, buf, len, client, fua));
if (!(client->server->flags & F_COPYONWRITE))
return(rawexpwrite_fully(a, buf, len, client, fua));
- DEBUG3("Asked to write %d bytes at %llu.\n", len, (unsigned long long)a);
+ DEBUG("Asked to write %u bytes at %llu.\n", (unsigned int)len, (unsigned long long)a);
mapl=a/DIFFPAGESIZE ; maph=(a+len-1)/DIFFPAGESIZE ;
mapl=a/DIFFPAGESIZE ; maph=(a+len-1)/DIFFPAGESIZE ;
len : (size_t)DIFFPAGESIZE-offset;
if (client->difmap[mapcnt]!=(u32)(-1)) { /* the block is already there */
len : (size_t)DIFFPAGESIZE-offset;
if (client->difmap[mapcnt]!=(u32)(-1)) { /* the block is already there */
- DEBUG3("Page %llu is at %lu\n", (unsigned long long)mapcnt,
+ DEBUG("Page %llu is at %lu\n", (unsigned long long)mapcnt,
(unsigned long)(client->difmap[mapcnt])) ;
myseek(client->difffile,
client->difmap[mapcnt]*DIFFPAGESIZE+offset);
(unsigned long)(client->difmap[mapcnt])) ;
myseek(client->difffile,
client->difmap[mapcnt]*DIFFPAGESIZE+offset);
} else { /* the block is not there */
myseek(client->difffile,client->difffilelen*DIFFPAGESIZE) ;
client->difmap[mapcnt]=(client->server->flags&F_SPARSE)?mapcnt:client->difffilelen++;
} else { /* the block is not there */
myseek(client->difffile,client->difffilelen*DIFFPAGESIZE) ;
client->difmap[mapcnt]=(client->server->flags&F_SPARSE)?mapcnt:client->difffilelen++;
- DEBUG3("Page %llu is not here, we put it at %lu\n",
+ DEBUG("Page %llu is not here, we put it at %lu\n",
(unsigned long long)mapcnt,
(unsigned long)(client->difmap[mapcnt]));
rdlen=DIFFPAGESIZE ;
(unsigned long long)mapcnt,
(unsigned long)(client->difmap[mapcnt]));
rdlen=DIFFPAGESIZE ;
}
int expflush(CLIENT *client) {
}
int expflush(CLIENT *client) {
- int fhandle;
- off_t foffset;
- size_t maxbytes;
gint i;
if (client->server->flags & F_COPYONWRITE) {
gint i;
if (client->server->flags & F_COPYONWRITE) {
} else {
currlen = len;
}
} else {
currlen = len;
}
-#ifdef DODBG
- printf("%s from %llu (%llu) len %d, ", command ? "WRITE" :
+ DEBUG("%s from %llu (%llu) len %d, ", command ? "WRITE" :
"READ", (unsigned long long)request.from,
"READ", (unsigned long long)request.from,
- (unsigned long long)request.from / 512, len);
-#endif
+ (unsigned long long)request.from / 512, (unsigned int)len);
memcpy(reply.handle, request.handle, sizeof(reply.handle));
if ((command==NBD_CMD_WRITE) || (command==NBD_CMD_READ)) {
memcpy(reply.handle, request.handle, sizeof(reply.handle));
if ((command==NBD_CMD_WRITE) || (command==NBD_CMD_READ)) {
} else {
tmpname=g_strdup(client->exportname);
}
} else {
tmpname=g_strdup(client->exportname);
}
- DEBUG2( "Opening %s\n", tmpname );
+ DEBUG( "Opening %s\n", tmpname );
fi.fhandle = open(tmpname, mode);
if(fi.fhandle == -1 && mode == O_RDWR) {
/* Try again because maybe media was read-only */
fi.fhandle = open(tmpname, mode);
if(fi.fhandle == -1 && mode == O_RDWR) {
/* Try again because maybe media was read-only */
#include <unistd.h>
#include "config.h"
#include "lfs.h"
#include <unistd.h>
#include "config.h"
#include "lfs.h"
-#define MY_NAME "nbd-tester-client"
-#include "cliserv.h"
-
#include <netinet/in.h>
#include <glib.h>
#include <netinet/in.h>
#include <glib.h>
+#define MY_NAME "nbd-tester-client"
+#include "cliserv.h"
+
static gchar errstr[1024];
const static int errstr_len=1024;
static gchar errstr[1024];
const static int errstr_len=1024;
int retval=0;
struct nbd_request req;
struct nbd_reply rep;
int retval=0;
struct nbd_request req;
struct nbd_reply rep;
int i=0;
int serverflags = 0;
int i=0;
int serverflags = 0;
- pid_t mypid = getpid();
+ pid_t G_GNUC_UNUSED mypid = getpid();
char buf[((1024*1024)+sizeof(struct nbd_request)/2)<<1];
bool got_err;
char buf[((1024*1024)+sizeof(struct nbd_request)/2)<<1];
bool got_err;
int throughput_test(gchar* hostname, int port, char* name, int sock,
char sock_is_open, char close_sock, int testflags) {
long long int i;
int throughput_test(gchar* hostname, int port, char* name, int sock,
char sock_is_open, char close_sock, int testflags) {
long long int i;
char writebuf[1024];
struct nbd_request req;
int requests=0;
char writebuf[1024];
struct nbd_request req;
int requests=0;
char speedchar[2] = { '\0', '\0' };
int retval=0;
int serverflags = 0;
char speedchar[2] = { '\0', '\0' };
int retval=0;
int serverflags = 0;
signed int do_write=TRUE;
pid_t mypid = getpid();
signed int do_write=TRUE;
pid_t mypid = getpid();
int integrity_test(gchar* hostname, int port, char* name, int sock,
char sock_is_open, char close_sock, int testflags) {
int integrity_test(gchar* hostname, int port, char* name, int sock,
char sock_is_open, char close_sock, int testflags) {
- struct nbd_request req;
struct nbd_reply rep;
fd_set rset;
fd_set wset;
struct nbd_reply rep;
fd_set rset;
fd_set wset;
char speedchar[2] = { '\0', '\0' };
int retval=0;
int serverflags = 0;
char speedchar[2] = { '\0', '\0' };
int retval=0;
int serverflags = 0;
- pid_t mypid = getpid();
+ pid_t G_GNUC_UNUSED mypid = getpid();
int blkhashfd = -1;
char *blkhashname=NULL;
uint32_t *blkhash = NULL;
int blkhashfd = -1;
char *blkhashname=NULL;
uint32_t *blkhash = NULL;
uint32_t command;
uint64_t from;
uint32_t len;
uint32_t command;
uint64_t from;
uint32_t len;