2012-06-22 10:05:41 +01:00
|
|
|
#include "status.h"
|
|
|
|
#include "serve.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
struct status * status_create( struct server * serve )
|
|
|
|
{
|
|
|
|
NULLCHECK( serve );
|
|
|
|
struct status * status;
|
2012-10-09 17:20:39 +01:00
|
|
|
|
2012-06-22 10:05:41 +01:00
|
|
|
status = xmalloc( sizeof( struct status ) );
|
2012-07-16 11:50:59 +01:00
|
|
|
status->pid = getpid();
|
2013-07-08 10:11:18 +01:00
|
|
|
status->size = serve->size;
|
2012-10-09 17:35:20 +01:00
|
|
|
status->has_control = serve->success;
|
2013-07-08 09:58:31 +01:00
|
|
|
|
2013-07-08 13:32:14 +01:00
|
|
|
server_lock_start_mirror( serve );
|
|
|
|
|
|
|
|
status->is_mirroring = NULL != serve->mirror;
|
2013-07-08 09:58:31 +01:00
|
|
|
if ( status->is_mirroring ) {
|
|
|
|
status->migration_pass = serve->mirror->pass;
|
2013-07-08 13:51:15 +01:00
|
|
|
status->pass_dirty_bytes = serve->mirror->this_pass_dirty;
|
|
|
|
status->pass_clean_bytes = serve->mirror->this_pass_clean;
|
2013-07-08 09:58:31 +01:00
|
|
|
}
|
|
|
|
|
2013-07-08 13:32:14 +01:00
|
|
|
server_unlock_start_mirror( serve );
|
|
|
|
|
2012-06-22 10:05:41 +01:00
|
|
|
return status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BOOL_S(var) (var ? "true" : "false" )
|
2012-07-16 11:50:59 +01:00
|
|
|
#define PRINT_BOOL( var ) \
|
2012-06-22 10:05:41 +01:00
|
|
|
do{dprintf( fd, #var "=%s ", BOOL_S( status->var ) );}while(0)
|
2012-07-16 11:50:59 +01:00
|
|
|
#define PRINT_INT( var ) \
|
|
|
|
do{dprintf( fd, #var "=%d ", status->var );}while(0)
|
2013-07-08 10:11:18 +01:00
|
|
|
#define PRINT_UINT64( var ) \
|
|
|
|
do{dprintf( fd, #var "=%"PRIu64" ", status->var );}while(0)
|
2012-06-22 10:05:41 +01:00
|
|
|
|
|
|
|
int status_write( struct status * status, int fd )
|
|
|
|
{
|
2012-07-16 11:50:59 +01:00
|
|
|
PRINT_INT( pid );
|
2013-07-08 10:11:18 +01:00
|
|
|
PRINT_UINT64( size );
|
2012-07-16 11:50:59 +01:00
|
|
|
PRINT_BOOL( is_mirroring );
|
|
|
|
PRINT_BOOL( has_control );
|
2013-07-08 09:58:31 +01:00
|
|
|
|
|
|
|
if ( status->is_mirroring ) {
|
|
|
|
PRINT_INT( migration_pass );
|
2013-07-08 14:27:04 +01:00
|
|
|
PRINT_UINT64( pass_dirty_bytes );
|
|
|
|
PRINT_UINT64( pass_clean_bytes );
|
2013-07-08 09:58:31 +01:00
|
|
|
}
|
|
|
|
|
2012-06-22 10:05:41 +01:00
|
|
|
dprintf(fd, "\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void status_destroy( struct status * status )
|
|
|
|
{
|
|
|
|
NULLCHECK( status );
|
|
|
|
free( status );
|
|
|
|
}
|
2013-07-08 09:58:31 +01:00
|
|
|
|