Network Block Device
@PACKAGE_VERSION@
|
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <syslog.h>
#include <unistd.h>
#include "config.h"
#include "lfs.h"
#include <netinet/in.h>
#include <glib.h>
#include "cliserv.h"
Go to the source code of this file.
Data Structures | |
struct | reqcontext |
struct | rclist |
struct | chunk |
struct | chunklist |
struct | blkitem |
Macros | |
#define | MY_NAME "nbd-tester-client" |
#define | TEST_WRITE (1<<0) |
#define | TEST_FLUSH (1<<1) |
#define | READ_ALL_ERRCHK(f, buf, len, whereto, errmsg...) if((read_all(f, buf, len))<=0) { snprintf(errstr, errstr_len, ##errmsg); goto whereto; } |
#define | READ_ALL_ERR_RT(f, buf, len, whereto, rval, errmsg...) if((read_all(f, buf, len))<=0) { snprintf(errstr, errstr_len, ##errmsg); retval = rval; goto whereto; } |
#define | WRITE_ALL_ERRCHK(f, buf, len, whereto, errmsg...) if((write_all(f, buf, len))<=0) { snprintf(errstr, errstr_len, ##errmsg); goto whereto; } |
#define | WRITE_ALL_ERR_RT(f, buf, len, whereto, rval, errmsg...) if((write_all(f, buf, len))<=0) { snprintf(errstr, errstr_len, ##errmsg); retval = rval; goto whereto; } |
Typedefs | |
typedef int(* | testfunc )(gchar *, int, char *, int, char, char, int) |
Functions | |
void | rclist_unlink (struct rclist *l, struct reqcontext *p) |
void | rclist_addtail (struct rclist *l, struct reqcontext *p) |
void | chunklist_unlink (struct chunklist *l, struct chunk *p) |
void | chunklist_addtail (struct chunklist *l, struct chunk *p) |
void | addbuffer (struct chunklist *l, void *data, uint64_t len) |
int | writebuffer (int fd, struct chunklist *l) |
int | timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y) |
double | timeval_diff_to_double (struct timeval *x, struct timeval *y) |
static int | read_all (int f, void *buf, size_t len) |
static int | write_all (int f, void *buf, size_t len) |
int | setup_connection (gchar *hostname, int port, gchar *name, CONNECTION_TYPE ctype, int *serverflags) |
int | close_connection (int sock, CLOSE_TYPE type) |
int | read_packet_check_header (int sock, size_t datasize, long long int curhandle) |
int | oversize_test (gchar *hostname, int port, char *name, int sock, char sock_is_open, char close_sock, int testflags) |
int | throughput_test (gchar *hostname, int port, char *name, int sock, char sock_is_open, char close_sock, int testflags) |
static void | makebuf (char *buf, uint64_t seq, uint64_t blknum) |
static int | checkbuf (char *buf, uint64_t seq, uint64_t blknum) |
static void | dumpcommand (char *text, uint32_t command) |
uint64_t | getrandomhandle (GHashTable *phash) |
int | integrity_test (gchar *hostname, int port, char *name, int sock, char sock_is_open, char close_sock, int testflags) |
void | handle_nonopt (char *opt, gchar **hostname, long int *p) |
int | main (int argc, char **argv) |
Variables | |
static gchar | errstr [1024] |
static const int | errstr_len =1024 |
static uint64_t | size |
static int | looseordering = 0 |
static gchar * | transactionlog = "nbd-tester-client.tr" |
#define MY_NAME "nbd-tester-client" |
Definition at line 41 of file nbd-tester-client.c.
#define READ_ALL_ERR_RT | ( | f, | |
buf, | |||
len, | |||
whereto, | |||
rval, | |||
errmsg... | |||
) | if((read_all(f, buf, len))<=0) { snprintf(errstr, errstr_len, ##errmsg); retval = rval; goto whereto; } |
Definition at line 333 of file nbd-tester-client.c.
Referenced by oversize_test(), and read_packet_check_header().
#define READ_ALL_ERRCHK | ( | f, | |
buf, | |||
len, | |||
whereto, | |||
errmsg... | |||
) | if((read_all(f, buf, len))<=0) { snprintf(errstr, errstr_len, ##errmsg); goto whereto; } |
Definition at line 332 of file nbd-tester-client.c.
Referenced by integrity_test(), and setup_connection().
#define TEST_FLUSH (1<<1) |
Definition at line 268 of file nbd-tester-client.c.
Referenced by main(), and throughput_test().
#define TEST_WRITE (1<<0) |
Definition at line 267 of file nbd-tester-client.c.
Referenced by integrity_test(), main(), and throughput_test().
#define WRITE_ALL_ERR_RT | ( | f, | |
buf, | |||
len, | |||
whereto, | |||
rval, | |||
errmsg... | |||
) | if((write_all(f, buf, len))<=0) { snprintf(errstr, errstr_len, ##errmsg); retval = rval; goto whereto; } |
Definition at line 336 of file nbd-tester-client.c.
Referenced by oversize_test().
#define WRITE_ALL_ERRCHK | ( | f, | |
buf, | |||
len, | |||
whereto, | |||
errmsg... | |||
) | if((write_all(f, buf, len))<=0) { snprintf(errstr, errstr_len, ##errmsg); goto whereto; } |
Definition at line 335 of file nbd-tester-client.c.
Referenced by setup_connection().
typedef int(* testfunc)(gchar *, int, char *, int, char, char, int) |
Definition at line 1266 of file nbd-tester-client.c.
enum CLOSE_TYPE |
Enumerator | |
---|---|
CONNECTION_CLOSE_PROPERLY | |
CONNECTION_CLOSE_FAST |
Definition at line 61 of file nbd-tester-client.c.
enum CONNECTION_TYPE |
Enumerator | |
---|---|
CONNECTION_TYPE_NONE | |
CONNECTION_TYPE_CONNECT | |
CONNECTION_TYPE_INIT_PASSWD | |
CONNECTION_TYPE_CLISERV | |
CONNECTION_TYPE_FULL |
Definition at line 53 of file nbd-tester-client.c.
void addbuffer | ( | struct chunklist * | l, |
void * | data, | ||
uint64_t | len | ||
) |
Definition at line 191 of file nbd-tester-client.c.
References chunk::buffer, chunklist_addtail(), len, chunk::length, chunk::readptr, size, chunk::space, chunklist::tail, and chunk::writeptr.
Referenced by integrity_test().
|
inlinestatic |
Definition at line 717 of file nbd-tester-client.c.
References makebuf().
Referenced by integrity_test().
Definition at line 169 of file nbd-tester-client.c.
References chunklist::head, chunk::next, chunklist::numitems, chunk::prev, and chunklist::tail.
Referenced by addbuffer().
Definition at line 146 of file nbd-tester-client.c.
References chunklist::head, chunk::next, chunklist::numitems, chunk::prev, and chunklist::tail.
Referenced by writebuffer().
int close_connection | ( | int | sock, |
CLOSE_TYPE | type | ||
) |
Definition at line 422 of file nbd-tester-client.c.
References CONNECTION_CLOSE_FAST, CONNECTION_CLOSE_PROPERLY, errstr, errstr_len, nbd_request::from, nbd_request::handle, nbd_request::len, nbd_request::magic, NBD_CMD_DISC, NBD_REQUEST_MAGIC, and nbd_request::type.
Referenced by integrity_test(), and throughput_test().
|
inlinestatic |
Definition at line 723 of file nbd-tester-client.c.
References NBD_CMD_DISC, NBD_CMD_FLAG_FUA, NBD_CMD_FLUSH, NBD_CMD_MASK_COMMAND, NBD_CMD_READ, and NBD_CMD_WRITE.
Referenced by integrity_test().
uint64_t getrandomhandle | ( | GHashTable * | phash | ) |
Definition at line 754 of file nbd-tester-client.c.
References handle.
Referenced by integrity_test().
void handle_nonopt | ( | char * | opt, |
gchar ** | hostname, | ||
long int * | p | ||
) |
Definition at line 1248 of file nbd-tester-client.c.
Referenced by main().
int integrity_test | ( | gchar * | hostname, |
int | port, | ||
char * | name, | ||
int | sock, | ||
char | sock_is_open, | ||
char | close_sock, | ||
int | testflags | ||
) |
Definition at line 765 of file nbd-tester-client.c.
References addbuffer(), checkbuf(), close_connection(), CONNECTION_CLOSE_PROPERLY, CONNECTION_TYPE_FULL, dumpcommand(), err(), nbd_reply::error, errstr, errstr_len, from, nbd_request::from, G_GNUC_UNUSED, getrandomhandle(), handle, nbd_request::handle, nbd_reply::handle, rclist::head, chunklist::head, blkitem::inflightr, blkitem::inflightw, len, nbd_request::len, looseordering, magic, nbd_request::magic, nbd_reply::magic, makebuf(), NBD_CMD_DISC, NBD_CMD_FLUSH, NBD_CMD_MASK_COMMAND, NBD_CMD_READ, NBD_CMD_WRITE, NBD_FLAG_SEND_FLUSH, NBD_FLAG_SEND_FUA, NBD_REPLY_MAGIC, NBD_REQUEST_MAGIC, ntohll(), rclist::numitems, chunklist::numitems, reqcontext::orighandle, rclist_addtail(), rclist_unlink(), READ_ALL_ERRCHK, reqcontext::req, reqcontext::seq, blkitem::seq, setup_connection(), size, TEST_WRITE, timeval_diff_to_double(), transactionlog, nbd_request::type, and writebuffer().
Referenced by main().
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 1268 of file nbd-tester-client.c.
References errstr, handle_nonopt(), integrity_test(), logging(), looseordering, oversize_test(), TEST_FLUSH, TEST_WRITE, throughput_test(), and transactionlog.
|
inlinestatic |
Definition at line 700 of file nbd-tester-client.c.
Referenced by checkbuf(), and integrity_test().
int oversize_test | ( | gchar * | hostname, |
int | port, | ||
char * | name, | ||
int | sock, | ||
char | sock_is_open, | ||
char | close_sock, | ||
int | testflags | ||
) |
Definition at line 476 of file nbd-tester-client.c.
References CONNECTION_TYPE_FULL, err(), nbd_reply::error, errstr, errstr_len, nbd_request::from, G_GNUC_UNUSED, nbd_request::handle, htonll, nbd_request::len, nbd_request::magic, NBD_CMD_READ, NBD_REQUEST_MAGIC, READ_ALL_ERR_RT, setup_connection(), nbd_request::type, and WRITE_ALL_ERR_RT.
Referenced by main().
void rclist_addtail | ( | struct rclist * | l, |
struct reqcontext * | p | ||
) |
Definition at line 125 of file nbd-tester-client.c.
References rclist::head, reqcontext::next, rclist::numitems, reqcontext::prev, and rclist::tail.
Referenced by integrity_test().
void rclist_unlink | ( | struct rclist * | l, |
struct reqcontext * | p | ||
) |
Definition at line 102 of file nbd-tester-client.c.
References rclist::head, reqcontext::next, rclist::numitems, reqcontext::prev, and rclist::tail.
Referenced by integrity_test().
|
inlinestatic |
Definition at line 296 of file nbd-tester-client.c.
References errstr, and errstr_len.
int read_packet_check_header | ( | int | sock, |
size_t | datasize, | ||
long long int | curhandle | ||
) |
Definition at line 451 of file nbd-tester-client.c.
References nbd_reply::error, errstr, errstr_len, nbd_reply::handle, nbd_reply::magic, NBD_REPLY_MAGIC, and READ_ALL_ERR_RT.
Referenced by throughput_test().
int setup_connection | ( | gchar * | hostname, |
int | port, | ||
gchar * | name, | ||
CONNECTION_TYPE | ctype, | ||
int * | serverflags | ||
) |
Definition at line 338 of file nbd-tester-client.c.
References cliserv_magic, CONNECTION_TYPE_CLISERV, CONNECTION_TYPE_CONNECT, CONNECTION_TYPE_FULL, CONNECTION_TYPE_INIT_PASSWD, err(), errstr, errstr_len, htonll, INIT_PASSWD, NBD_OPT_EXPORT_NAME, ntohll(), opts_magic, READ_ALL_ERRCHK, setmysockopt(), size, and WRITE_ALL_ERRCHK.
Referenced by integrity_test(), oversize_test(), and throughput_test().
int throughput_test | ( | gchar * | hostname, |
int | port, | ||
char * | name, | ||
int | sock, | ||
char | sock_is_open, | ||
char | close_sock, | ||
int | testflags | ||
) |
Definition at line 545 of file nbd-tester-client.c.
References close_connection(), CONNECTION_CLOSE_PROPERLY, CONNECTION_TYPE_FULL, err(), errstr, errstr_len, nbd_request::from, nbd_request::handle, htonll, nbd_request::len, nbd_request::magic, NBD_CMD_FLAG_FUA, NBD_CMD_FLUSH, NBD_CMD_READ, NBD_CMD_WRITE, NBD_FLAG_SEND_FLUSH, NBD_FLAG_SEND_FUA, NBD_REQUEST_MAGIC, read_packet_check_header(), setup_connection(), size, TEST_FLUSH, TEST_WRITE, timeval_diff_to_double(), nbd_request::type, and write_all().
Referenced by main().
double timeval_diff_to_double | ( | struct timeval * | x, |
struct timeval * | y | ||
) |
Definition at line 290 of file nbd-tester-client.c.
References timeval_subtract().
Referenced by integrity_test(), and throughput_test().
int timeval_subtract | ( | struct timeval * | result, |
struct timeval * | x, | ||
struct timeval * | y | ||
) |
Definition at line 270 of file nbd-tester-client.c.
Referenced by timeval_diff_to_double().
|
inlinestatic |
Definition at line 314 of file nbd-tester-client.c.
References errstr, and errstr_len.
Referenced by throughput_test().
int writebuffer | ( | int | fd, |
struct chunklist * | l | ||
) |
Definition at line 229 of file nbd-tester-client.c.
References chunk::buffer, chunklist_unlink(), chunklist::head, chunk::length, and chunk::readptr.
Referenced by integrity_test().
|
static |
Definition at line 44 of file nbd-tester-client.c.
Referenced by close_connection(), integrity_test(), main(), oversize_test(), read_all(), read_packet_check_header(), setup_connection(), throughput_test(), and write_all().
|
static |
Definition at line 45 of file nbd-tester-client.c.
Referenced by close_connection(), integrity_test(), oversize_test(), read_all(), read_packet_check_header(), setup_connection(), throughput_test(), and write_all().
|
static |
Definition at line 49 of file nbd-tester-client.c.
Referenced by integrity_test(), and main().
|
static |
Definition at line 47 of file nbd-tester-client.c.
Referenced by addbuffer(), integrity_test(), setmysockopt(), setsizes(), setup_connection(), and throughput_test().
|
static |
Definition at line 51 of file nbd-tester-client.c.
Referenced by integrity_test(), and main().