qemu-nbd:multiple files server
RFC PATCH 1/1 qemu-nbd:multiple files server
This patch allows the NBD client to select the file to use.
It modifies the NBD protocol to allow the client to provide a filename if the NBD server reports a disk size of 0.
Example:
# add in /etc/services
nbd 1024/tcp
# add in /etc/inetd.conf
nbd stream tcp nowait root /usr/local/bin/qemu-nbd /usr/local/bin/qemu-nbd --nocache --read-only --port 0 --directory /ISO
In /ISO, there are:
debian-31r0a-amd64-netinst.iso openSUSE-10.3-GM-x86_64-mini.iso debian-40r0-i386-netinst.iso ubuntu-6.06-desktop-amd64.iso debian-40r0-i386-xfce-CD-1.iso ubuntu-7.10-desktop-amd64.iso debian-40r1-amd64-netinst.iso ubuntu-8.04-desktop-i386.iso debian-40r1-powerpc-netinst.iso winxp_64.iso
Then I can start qemu with:
x86_64-softmmu/qemu-system-x86_64 -net nic -net tap -hda new_disk.qcow2 -cdrom nbd:my_nbd_server:1024:ubuntu-6.06-desktop-amd64.iso -boot d
or
x86_64-softmmu/qemu-system-x86_64 -net nic -net tap -hda new_disk.qcow2 -cdrom nbd:my_nbd_server:1024:winxp_64.iso -boot d
My goal is to be able to provide an install CD server, without configuring BOOTD/DHCP/TFTP server.
Signature · 3 lines
----------------- [email protected] ------------------ "La perfection est atteinte non quand il ne reste rien à ajouter mais quand il ne reste rien à enlever." Saint Exupéry
--- block-nbd.c | 16 ++++++++++++++ nbd.c | 47 +++++++++++++++++++++++++++++++++++++++++ nbd.h | 2 + qemu-nbd.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 124 insertions(+), 9 deletions(-)
nbd.c +47 -0
@@ -337,6 +337,53 @@ int nbd_receive_negotiate(int csock, offreturn 0 ; } +int nbd_filename (int csock,const char *filename) +{ +uint8_t len; + +if (!filename ||strlen (filename) >254 ) { + errno =EINVAL ; +return -1 ; + } + + len =strlen (filename) +1 ; +if (write_sync (csock, &len,sizeof (uint8_t )) != +sizeof (uint8_t )) { +LOG ("read failed" ); + errno =EINVAL ; +return -1 ; + } +if (len &&write_sync (csock, (char *)filename, len) != len) { +LOG ("read failed" ); + errno =EINVAL ; +return -1 ; + } +return 0 ; +} + +int nbd_receive_filename (int csock,char *filename) +{ +uint8_t len; + filename[0 ] ='\0' ; +if (read_sync (csock, &len,sizeof (uint8_t )) !=sizeof (uint8_t )) { +LOG ("read failed" ); + errno =EINVAL ; +return -1 ; + } +if (len ==0 ) { +LOG ("read failed" ); + errno =EINVAL ; +return -1 ; + } +if (read_sync (csock, filename, len) != len) { +LOG ("read failed" ); + errno =EINVAL ; +return -1 ; + } + filename[len] =0 ; +return 0 ; +} +int nbd_init (int fd,int csock,off_t size,size_t blocksize) {TRACE ("Setting block size to %lu" , (unsigned long )blocksize);
nbd.h +2 -0
@@ -52,6 +52,8 @@ int unix_socket_incoming(const char *patint nbd_negotiate (int csock,off_t size);int nbd_receive_negotiate (int csock,off_t *size,size_t *blocksize); +int nbd_filename (int csock,const char *filename); +int nbd_receive_filename (int csock,char *filename);int nbd_init (int fd,int csock,off_t size,size_t blocksize);int nbd_send_request (int csock,struct nbd_request *request);int nbd_receive_reply (int csock,struct nbd_reply *reply);
block-nbd.c +16 -0
@@ -47,6 +47,7 @@ static int nbd_open(BlockDriverState *bsoff_t size;size_t blocksize;int ret; +const char *name =NULL ;if ((flags &BDRV_O_CREAT ))return -EINVAL ;
@@ -79,6 +80,10 @@ static int nbd_open(BlockDriverState *bsif (r == p)return -EINVAL ; sock =tcp_socket_outgoing (hostname, port); +if (*r ==':' ) { + r++; + name = r; + } }if (sock ==-1 )
@@ -88,6 +93,17 @@ static int nbd_open(BlockDriverState *bsif (ret ==-1 )return -errno; +if (size ==0 ) { +if (name ==NULL ) +return -EINVAL ; + ret =nbd_filename (sock, name); +if (ret ==-1 ) +return -errno; + ret =nbd_receive_negotiate (sock, &size, &blocksize); +if (ret ==-1 ) +return -errno; + } + s->sock = sock; s->size = size; s->blocksize = blocksize;
qemu-nbd.c +59 -9
119 lines not on this page · raw message
Quoted 5 lines · Laurent Vivier
This patch allows the NBD client to select the file to use.
It modifies the NBD protocol to allow the client to provide a filename if the NBD server reports a disk size of 0.
I don't have a problem with it from a client/server perspective, but we need to make sure that we're extending the NBD protocol in a way that's compatible with other implementations.
So please make sure Paul is on board with how you're extending the protocol.
Regards,
Anthony Liguori
Quoted 31 lines
Example:
# add in /etc/servicesnbd 1024/tcp
# add in /etc/inetd.confnbd stream tcp nowait root
/usr/local/bin/qemu-nbd/usr/local/bin/qemu-nbd--nocache --read-only --port 0 --directory /ISOIn /ISO, there are:
debian-31r0a-amd64-netinst.iso openSUSE-10.3-GM-x86_64-mini.iso debian-40r0-i386-netinst.iso ubuntu-6.06-desktop-amd64.iso debian-40r0-i386-xfce-CD-1.iso ubuntu-7.10-desktop-amd64.iso debian-40r1-amd64-netinst.iso ubuntu-8.04-desktop-i386.iso debian-40r1-powerpc-netinst.iso winxp_64.isoThen I can start qemu with:
x86_64-softmmu/qemu-system-x86_64 -net nic -net tap -hda new_disk.qcow2 -cdrom nbd:my_nbd_server:1024:ubuntu-6.06-desktop-amd64.iso -boot d
or
x86_64-softmmu/qemu-system-x86_64 -net nic -net tap -hda new_disk.qcow2 -cdrom nbd:my_nbd_server:1024:winxp_64.iso -boot d
My goal is to be able to provide an install CD server, without configuring BOOTD/DHCP/TFTP server.
Signed-off-by Laurent Vivier <[email protected]>