#NEWLINE# def handshake( self , conn , addr ) : #NEWLINE# #INDENT# 'Initiate the connection, server sends first.' #NEWLINE# conn . send ( 'NBDMAGIC' ) #NEWLINE# conn . send ( 'IHAVEOPT' ) #NEWLINE# conn . send ( struct . pack ( '!H' , 3 ) ) #NEWLINE# [ cflags ] = struct . unpack ( '!I' , conn . recv ( 4 ) ) #NEWLINE# op = 0 #NEWLINE# while ( op != 1 ) : #NEWLINE# #INDENT# [ magic ] = struct . unpack ( '!Q' , conn . recv ( 8 ) ) #NEWLINE# [ op ] = struct . unpack ( '!I' , conn . recv ( 4 ) ) #NEWLINE# if ( op != 1 ) : #NEWLINE# #INDENT# self . send_reply ( conn , addr , ( ( 2 ** 31 ) + 1 ) , '' ) #NEWLINE# #UNINDENT# #UNINDENT# [ namelen ] = struct . unpack ( '!I' , conn . recv ( 4 ) ) #NEWLINE# name = conn . recv ( namelen ) #NEWLINE# if ( name != self . bd ) : #NEWLINE# #INDENT# self . logger . debug ( 'Blockdevice names do not match {0} != {1}' . format ( self . bd , name ) ) #NEWLINE# conn . close ( ) #NEWLINE# return 1 #NEWLINE# #UNINDENT# self . logger . info ( 'Received request for {0} from {1}' . format ( name , addr ) ) #NEWLINE# exportinfo = struct . pack ( '!Q' , self . bdsize ) #NEWLINE# flags = ( 0 if self . write else 2 ) #NEWLINE# exportinfo += struct . pack ( '!H' , flags ) #NEWLINE# exportinfo += ( chr ( 0 ) * ( 0 if ( cflags & 2 ) else 124 ) ) #NEWLINE# conn . send ( exportinfo )