Formatting fixup

This commit is contained in:
Alex Young
2013-05-01 11:02:46 +01:00
parent 151b739e8d
commit e548cc53c8

View File

@@ -2,7 +2,7 @@
#include "readwrite.h"
#ifdef PREFETCH
#include "prefetch.h"
#include "prefetch.h"
#endif
@@ -244,12 +244,12 @@ int proxy_run_request_upstream( struct proxier* proxy )
unsigned char* rsp_data = proxy->rsp_buf + NBD_REPLY_SIZE;
struct nbd_reply_raw* reply_raw = (struct nbd_reply_raw*) rsp_hdr_raw;
struct nbd_request* request = &(proxy->req_hdr);
#ifdef PREFETCH
/* We only want to consider prefetching if we know we're not getting too much
* data back, if it's a read request, and if the prefetch won't try to read
* past the end of the file.
/* We only want to consider prefetching if we know we're not
* getting too much data back, if it's a read request, and if
* the prefetch won't try to read past the end of the file.
*/
int prefetching =
request->len <= PREFETCH_BUFSIZE &&
@@ -263,14 +263,18 @@ int proxy_run_request_upstream( struct proxier* proxy )
/* We need a malloc here because nbd_h2r_request craps
* out if passed an address on the stack
*/
struct nbd_request* rewrite_request = xmalloc( sizeof( struct nbd_request ) );
struct nbd_request* rewrite_request =
xmalloc( sizeof( struct nbd_request ) );
NULLCHECK( rewrite_request );
memcpy( rewrite_request, request, sizeof( struct nbd_request ) );
memcpy( rewrite_request,
request,
sizeof( struct nbd_request ) );
rewrite_request->len *= 2;
debug( "Prefetching %d bytes", rewrite_request->len );
nbd_h2r_request( rewrite_request, (struct nbd_request_raw *)proxy->req_buf );
nbd_h2r_request( rewrite_request,
(struct nbd_request_raw *)proxy->req_buf );
free( rewrite_request );
}
#endif
@@ -291,16 +295,20 @@ int proxy_run_request_upstream( struct proxier* proxy )
debug( "Prefetch hit!" );
/* First build a reply header */
struct nbd_reply prefetch_reply = {REPLY_MAGIC, 0, "01234567"};
struct nbd_reply prefetch_reply =
{REPLY_MAGIC, 0, "01234567"};
memcpy( &(prefetch_reply.handle), request->handle, 8 );
/* now copy it into the response */
nbd_h2r_reply( &prefetch_reply, reply_raw );
/* and the data */
memcpy( rsp_data, proxy->prefetch->buffer, proxy->prefetch->len );
memcpy( rsp_data,
proxy->prefetch->buffer,
proxy->prefetch->len );
proxy->rsp_buf_size = NBD_REPLY_SIZE + proxy->prefetch->len;
proxy->rsp_buf_size =
NBD_REPLY_SIZE + proxy->prefetch->len;
/* return early, our work here is done */
return 1;
@@ -312,17 +320,22 @@ int proxy_run_request_upstream( struct proxier* proxy )
* it's simpler (and therefore safer) than working out
* whether we can keep it or not.
*/
debug( "Blowing away prefetch cache on type %d request.", request->type );
debug("Blowing away prefetch cache on type %d request.",
request->type);
proxy->prefetch->is_full = 0;
}
#endif
if ( writeloop( proxy->upstream_fd, proxy->req_buf, proxy->req_buf_size ) == -1 ) {
if ( -1 == writeloop( proxy->upstream_fd,
proxy->req_buf,
proxy->req_buf_size ) ) {
warn( "Failed to send request to upstream" );
goto disconnect;
}
if ( readloop( proxy->upstream_fd, rsp_hdr_raw, NBD_REPLY_SIZE ) == -1 ) {
if ( -1 == readloop( proxy->upstream_fd,
rsp_hdr_raw,
NBD_REPLY_SIZE ) ) {
debug( "Failed to get reply header from upstream" );
goto disconnect;
}
@@ -335,23 +348,29 @@ int proxy_run_request_upstream( struct proxier* proxy )
goto disconnect;
}
debug( "NBD reply received from upstream. Response code: %"PRIu32, reply->error );
debug("NBD reply received from upstream. Response code: %"PRIu32,
reply->error );
if ( reply->error != 0 ) {
warn( "NBD error returned from upstream: %"PRIu32, reply->error );
warn( "NBD error returned from upstream: %"PRIu32,
reply->error );
}
if ( reply->error == 0 && request->type == REQUEST_READ ) {
#ifdef PREFETCH
if (readloop( proxy->upstream_fd, rsp_data, request->len ) == -1 ) {
if ( -1 == readloop( proxy->upstream_fd,
rsp_data,
request->len ) ) {
debug( "Failed to get reply data from upstream" );
goto disconnect;
}
if ( prefetching ) {
if ( readloop( proxy->upstream_fd, &(proxy->prefetch->buffer), request->len ) == -1 ) {
debug( "Failed to get prefetch reply data from upstream" );
if ( -1 == readloop( proxy->upstream_fd,
&(proxy->prefetch->buffer),
request->len ) ) {
debug( "Failed to get prefetch reply data "
"from upstream" );
goto disconnect;
}
proxy->prefetch->from = request->from + request->len;
@@ -360,7 +379,9 @@ int proxy_run_request_upstream( struct proxier* proxy )
}
#else
if (readloop( proxy->upstream_fd, rsp_data, request->len ) == -1 ) {
if ( -1 == readloop( proxy->upstream_fd,
rsp_data,
request->len ) ) {
debug( "Failed to get reply data from upstream" );
goto disconnect;
}