Formatted all code using indent

This commit is contained in:
Patrick J Cherry
2018-02-20 10:05:35 +00:00
parent 19a1127bde
commit f47f56d4c4
59 changed files with 7631 additions and 7762 deletions

View File

@@ -2,67 +2,77 @@
#include "util.h"
struct prefetch* prefetch_create( size_t size_bytes ){
struct prefetch *prefetch_create(size_t size_bytes)
{
struct prefetch* out = xmalloc( sizeof( struct prefetch ) );
NULLCHECK( out );
out->buffer = xmalloc( size_bytes );
NULLCHECK( out->buffer );
struct prefetch *out = xmalloc(sizeof(struct prefetch));
NULLCHECK(out);
out->size = size_bytes;
out->is_full = 0;
out->from = 0;
out->len = 0;
out->buffer = xmalloc(size_bytes);
NULLCHECK(out->buffer);
return out;
out->size = size_bytes;
out->is_full = 0;
out->from = 0;
out->len = 0;
return out;
}
void prefetch_destroy( struct prefetch *prefetch ) {
if( prefetch ) {
free( prefetch->buffer );
free( prefetch );
}
void prefetch_destroy(struct prefetch *prefetch)
{
if (prefetch) {
free(prefetch->buffer);
free(prefetch);
}
}
size_t prefetch_size( struct prefetch *prefetch){
if ( prefetch ) {
return prefetch->size;
} else {
return 0;
}
size_t prefetch_size(struct prefetch *prefetch)
{
if (prefetch) {
return prefetch->size;
} else {
return 0;
}
}
void prefetch_set_is_empty( struct prefetch *prefetch ){
prefetch_set_full( prefetch, 0 );
void prefetch_set_is_empty(struct prefetch *prefetch)
{
prefetch_set_full(prefetch, 0);
}
void prefetch_set_is_full( struct prefetch *prefetch ){
prefetch_set_full( prefetch, 1 );
void prefetch_set_is_full(struct prefetch *prefetch)
{
prefetch_set_full(prefetch, 1);
}
void prefetch_set_full( struct prefetch *prefetch, int val ){
if( prefetch ) {
prefetch->is_full = val;
}
void prefetch_set_full(struct prefetch *prefetch, int val)
{
if (prefetch) {
prefetch->is_full = val;
}
}
int prefetch_is_full( struct prefetch *prefetch ){
if( prefetch ) {
return prefetch->is_full;
} else {
return 0;
}
int prefetch_is_full(struct prefetch *prefetch)
{
if (prefetch) {
return prefetch->is_full;
} else {
return 0;
}
}
int prefetch_contains( struct prefetch *prefetch, uint64_t from, uint32_t len ){
NULLCHECK( prefetch );
return from >= prefetch->from &&
from + len <= prefetch->from + prefetch->len;
int prefetch_contains(struct prefetch *prefetch, uint64_t from,
uint32_t len)
{
NULLCHECK(prefetch);
return from >= prefetch->from &&
from + len <= prefetch->from + prefetch->len;
}
char *prefetch_offset( struct prefetch *prefetch, uint64_t from ){
NULLCHECK( prefetch );
return prefetch->buffer + (from - prefetch->from);
char *prefetch_offset(struct prefetch *prefetch, uint64_t from)
{
NULLCHECK(prefetch);
return prefetch->buffer + (from - prefetch->from);
}

View File

@@ -7,27 +7,28 @@
#define PREFETCH_BUFSIZE 4096
struct prefetch {
/* True if there is data in the buffer. */
int is_full;
/* The start point of the current content of buffer */
uint64_t from;
/* The length of the current content of buffer */
uint32_t len;
/* True if there is data in the buffer. */
int is_full;
/* The start point of the current content of buffer */
uint64_t from;
/* The length of the current content of buffer */
uint32_t len;
/* The total size of the buffer, in bytes. */
size_t size;
/* The total size of the buffer, in bytes. */
size_t size;
char *buffer;
char *buffer;
};
struct prefetch* prefetch_create( size_t size_bytes );
void prefetch_destroy( struct prefetch *prefetch );
size_t prefetch_size( struct prefetch *);
void prefetch_set_is_empty( struct prefetch *prefetch );
void prefetch_set_is_full( struct prefetch *prefetch );
void prefetch_set_full( struct prefetch *prefetch, int val );
int prefetch_is_full( struct prefetch *prefetch );
int prefetch_contains( struct prefetch *prefetch, uint64_t from, uint32_t len );
char *prefetch_offset( struct prefetch *prefetch, uint64_t from );
struct prefetch *prefetch_create(size_t size_bytes);
void prefetch_destroy(struct prefetch *prefetch);
size_t prefetch_size(struct prefetch *);
void prefetch_set_is_empty(struct prefetch *prefetch);
void prefetch_set_is_full(struct prefetch *prefetch);
void prefetch_set_full(struct prefetch *prefetch, int val);
int prefetch_is_full(struct prefetch *prefetch);
int prefetch_contains(struct prefetch *prefetch, uint64_t from,
uint32_t len);
char *prefetch_offset(struct prefetch *prefetch, uint64_t from);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -10,7 +10,7 @@
#include "self_pipe.h"
#ifdef PREFETCH
#include "prefetch.h"
#include "prefetch.h"
#endif
/** UPSTREAM_TIMEOUT
@@ -21,80 +21,77 @@
struct proxier {
/** address/port to bind to */
union mysockaddr listen_on;
union mysockaddr listen_on;
/** address/port to connect to */
union mysockaddr connect_to;
union mysockaddr connect_to;
/** address to bind to when making outgoing connections */
union mysockaddr connect_from;
int bind; /* Set to true if we should use it */
union mysockaddr connect_from;
int bind; /* Set to true if we should use it */
/* The socket we listen() on and accept() against */
int listen_fd;
/* The socket we listen() on and accept() against */
int listen_fd;
/* The socket returned by accept() that we receive requests from and send
* responses to
*/
int downstream_fd;
/* The socket returned by accept() that we receive requests from and send
* responses to
*/
int downstream_fd;
/* The socket returned by connect() that we send requests to and receive
* responses from
*/
int upstream_fd;
/* The socket returned by connect() that we send requests to and receive
* responses from
*/
int upstream_fd;
/* This is the size we advertise to the downstream server */
uint64_t upstream_size;
/* This is the size we advertise to the downstream server */
uint64_t upstream_size;
/* These are the transmission flags sent as part of the handshake */
uint32_t upstream_flags;
/* These are the transmission flags sent as part of the handshake */
uint32_t upstream_flags;
/* We transform the raw request header into here */
struct nbd_request req_hdr;
/* We transform the raw request header into here */
struct nbd_request req_hdr;
/* We transform the raw reply header into here */
struct nbd_reply rsp_hdr;
/* We transform the raw reply header into here */
struct nbd_reply rsp_hdr;
/* Used for our non-blocking negotiation with upstream. TODO: maybe use
* for downstream as well ( we currently overload rsp ) */
struct iobuf init;
/* Used for our non-blocking negotiation with upstream. TODO: maybe use
* for downstream as well ( we currently overload rsp ) */
struct iobuf init;
/* The current NBD request from downstream */
struct iobuf req;
/* The current NBD request from downstream */
struct iobuf req;
/* The current NBD reply from upstream */
struct iobuf rsp;
/* The current NBD reply from upstream */
struct iobuf rsp;
/* It's starting to feel like we need an object for a single proxy session.
* These two track how many requests we've sent so far, and whether the
* NBD_INIT code has been sent to the client yet.
*/
uint64_t req_count;
int hello_sent;
/* It's starting to feel like we need an object for a single proxy session.
* These two track how many requests we've sent so far, and whether the
* NBD_INIT code has been sent to the client yet.
*/
uint64_t req_count;
int hello_sent;
/** These are only used if we pass --cache on the command line */
/* While the in-flight request has been munged by prefetch, these two are
* set to true, and the original length of the request, respectively */
int is_prefetch_req;
uint32_t prefetch_req_orig_len;
/* While the in-flight request has been munged by prefetch, these two are
* set to true, and the original length of the request, respectively */
int is_prefetch_req;
uint32_t prefetch_req_orig_len;
/* And here, we actually store the prefetched data once it's returned */
struct prefetch *prefetch;
/* And here, we actually store the prefetched data once it's returned */
struct prefetch *prefetch;
/** */
};
struct proxier* proxy_create(
char* s_downstream_address,
char* s_downstream_port,
char* s_upstream_address,
char* s_upstream_port,
char* s_upstream_bind,
char* s_cache_bytes);
int do_proxy( struct proxier* proxy );
void proxy_cleanup( struct proxier* proxy );
void proxy_destroy( struct proxier* proxy );
struct proxier *proxy_create(char *s_downstream_address,
char *s_downstream_port,
char *s_upstream_address,
char *s_upstream_port,
char *s_upstream_bind, char *s_cache_bytes);
int do_proxy(struct proxier *proxy);
void proxy_cleanup(struct proxier *proxy);
void proxy_destroy(struct proxier *proxy);
#endif