Introduce socket_nbd_write_hello() and a macro to display errno results nicely

This commit is contained in:
nick
2013-02-08 15:53:27 +00:00
parent 56ce7d35c2
commit ecfd108a53
3 changed files with 21 additions and 0 deletions

View File

@@ -56,6 +56,25 @@ fail:
return 0;
}
int socket_nbd_write_hello(int fd, off64_t out_size)
{
struct nbd_init init;
struct nbd_init_raw init_raw;
memcpy(&init.passwd, INIT_PASSWD, 8);
init.magic = INIT_MAGIC;
init.size = out_size;
memset( &init_raw, 0, sizeof( init_raw ) ); // ensure reserved is 0s
nbd_h2r_init(&init, &init_raw);
if ( 0 > writeloop( fd, &init_raw, sizeof( init_raw ) ) ) {
warn( SHOW_ERRNO( "failed to write hello to socket" ) );
return 0;
}
return 1;
}
void fill_request(struct nbd_request *request, int type, off64_t from, int len)
{
request->magic = htobe32(REQUEST_MAGIC);