Formatting fixup

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

View File

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