Call srand() to make sure request handles are properly randomised
This commit is contained in:
@@ -694,7 +694,7 @@ void mirror_limit_cb( struct ev_loop *loop, ev_timer *w, int revents )
|
|||||||
* if it has, start migrating. If it's not finished, then enabling the bitset
|
* if it has, start migrating. If it's not finished, then enabling the bitset
|
||||||
* stream does not go well for us.
|
* stream does not go well for us.
|
||||||
*/
|
*/
|
||||||
void mirror_begin_cb( struct ev_loop *loop, ev_timer *w, int revents )
|
static void mirror_begin_cb( struct ev_loop *loop, ev_timer *w, int revents )
|
||||||
{
|
{
|
||||||
struct mirror_ctrl* ctrl = (struct mirror_ctrl*) w->data;
|
struct mirror_ctrl* ctrl = (struct mirror_ctrl*) w->data;
|
||||||
NULLCHECK( ctrl );
|
NULLCHECK( ctrl );
|
||||||
@@ -750,7 +750,8 @@ void mirror_run( struct server *serve )
|
|||||||
|
|
||||||
ctrl.ev_loop = EV_DEFAULT;
|
ctrl.ev_loop = EV_DEFAULT;
|
||||||
|
|
||||||
/* gcc warns on -O2. clang is fine. Seems to be the fault of ev.h */
|
/* gcc warns with -Wstrict-aliasing on -O2. clang doesn't
|
||||||
|
* implement this warning. Seems to be the fault of ev.h */
|
||||||
ev_init( &ctrl.begin_watcher, mirror_begin_cb );
|
ev_init( &ctrl.begin_watcher, mirror_begin_cb );
|
||||||
ctrl.begin_watcher.repeat = 1.0; // We check bps every second. seems sane.
|
ctrl.begin_watcher.repeat = 1.0; // We check bps every second. seems sane.
|
||||||
ctrl.begin_watcher.data = (void*) &ctrl;
|
ctrl.begin_watcher.data = (void*) &ctrl;
|
||||||
|
@@ -103,10 +103,13 @@ int socket_nbd_write_hello(int fd, off64_t out_size)
|
|||||||
|
|
||||||
void fill_request(struct nbd_request *request, int type, off64_t from, int len)
|
void fill_request(struct nbd_request *request, int type, off64_t from, int len)
|
||||||
{
|
{
|
||||||
|
int32_t handle_i[2];
|
||||||
|
handle_i[0] = rand();
|
||||||
|
handle_i[1] = rand();
|
||||||
|
|
||||||
request->magic = htobe32(REQUEST_MAGIC);
|
request->magic = htobe32(REQUEST_MAGIC);
|
||||||
request->type = htobe32(type);
|
request->type = htobe32(type);
|
||||||
((int*) request->handle)[0] = rand();
|
memcpy( request->handle, handle_i, sizeof(request->handle) );
|
||||||
((int*) request->handle)[1] = rand();
|
|
||||||
request->from = htobe64(from);
|
request->from = htobe64(from);
|
||||||
request->len = htobe32(len);
|
request->len = htobe32(len);
|
||||||
}
|
}
|
||||||
|
@@ -2,12 +2,16 @@
|
|||||||
#include "mode.h"
|
#include "mode.h"
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
signal(SIGPIPE, SIG_IGN); /* calls to splice() unhelpfully throw this */
|
signal(SIGPIPE, SIG_IGN); /* calls to splice() unhelpfully throw this */
|
||||||
error_init();
|
error_init();
|
||||||
|
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
exit_err( help_help_text );
|
exit_err( help_help_text );
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "mode.h"
|
#include "mode.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@@ -102,6 +104,8 @@ int main( int argc, char *argv[] )
|
|||||||
exit_action.sa_mask = mask;
|
exit_action.sa_mask = mask;
|
||||||
exit_action.sa_flags = 0;
|
exit_action.sa_flags = 0;
|
||||||
|
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
c = getopt_long( argc, argv, proxy_short_options, proxy_options, NULL );
|
c = getopt_long( argc, argv, proxy_short_options, proxy_options, NULL );
|
||||||
if ( -1 == c ) { break; }
|
if ( -1 == c ) { break; }
|
||||||
|
Reference in New Issue
Block a user