Added .INCOMPLETE hack to aid with marking finished transfers.

This commit is contained in:
Matthew Bloch
2012-05-29 11:24:24 +01:00
parent ab0dfb5eca
commit 21ccd17ea5
4 changed files with 15 additions and 4 deletions

View File

@@ -92,6 +92,9 @@ void params_serve(
out->bind_to.v4.sin_port = htobe16(out->bind_to.v4.sin_port); out->bind_to.v4.sin_port = htobe16(out->bind_to.v4.sin_port);
out->filename = s_file; out->filename = s_file;
out->filename_incomplete = xmalloc(strlen(s_file)+11);
strcpy(out->filename_incomplete, s_file);
strcpy(out->filename_incomplete + strlen(s_file), ".INCOMPLETE");
} }
void params_readwrite( void params_readwrite(

View File

@@ -38,11 +38,13 @@ struct mode_serve_params {
int acl_entries; int acl_entries;
/** pointer to access control list entries*/ /** pointer to access control list entries*/
struct ip_and_mask (*acl)[0]; struct ip_and_mask (*acl)[0];
/** file name to serve */ /** (static) file name to serve */
char* filename; char* filename;
/** file name of INCOMPLETE flag */
char* filename_incomplete;
/** TCP backlog for listen() */ /** TCP backlog for listen() */
int tcp_backlog; int tcp_backlog;
/** file name of UNIX control socket (or NULL if none) */ /** (static) file name of UNIX control socket (or NULL if none) */
char* control_socket_name; char* control_socket_name;
/** size of file */ /** size of file */
off64_t size; off64_t size;

View File

@@ -43,9 +43,9 @@ void read_reply(int fd, struct nbd_request *request, struct nbd_reply *reply)
SERVER_ERROR_ON_FAILURE(readloop(fd, reply, sizeof(*reply)), SERVER_ERROR_ON_FAILURE(readloop(fd, reply, sizeof(*reply)),
"Couldn't read reply"); "Couldn't read reply");
if (be32toh(reply->magic) != REPLY_MAGIC) if (be32toh(reply->magic) != REPLY_MAGIC)
SERVER_ERROR("Reply magic incorrect (%p)", reply->magic); SERVER_ERROR("Reply magic incorrect (%p)", be32toh(reply->magic));
if (be32toh(reply->error) != 0) if (be32toh(reply->error) != 0)
SERVER_ERROR("Server replied with error %d", reply->error); SERVER_ERROR("Server replied with error %d", be32toh(reply->error));
if (strncmp(request->handle, reply->handle, 8) != 0) if (strncmp(request->handle, reply->handle, 8) != 0)
SERVER_ERROR("Did not reply with correct handle"); SERVER_ERROR("Did not reply with correct handle");
} }

View File

@@ -167,6 +167,12 @@ int client_serve_request(struct client_params* client)
switch (be32toh(request.type)) switch (be32toh(request.type))
{ {
case REQUEST_READ: case REQUEST_READ:
if (access(client->serve->filename_incomplete, F_OK) == 0 ) {
debug("read request while data incomplete");
reply.error = htobe32(10);
write(client->socket, &reply, sizeof(reply));
return 0;
}
case REQUEST_WRITE: case REQUEST_WRITE:
/* check it's not out of range */ /* check it's not out of range */
if (be64toh(request.from) < 0 || if (be64toh(request.from) < 0 ||