2016-10-25 15:11:41 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Test case for NBD's blockdev-add interface
|
|
|
|
#
|
|
|
|
# Copyright (C) 2016 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
|
|
|
import socket
|
|
|
|
import stat
|
|
|
|
import time
|
|
|
|
import iotests
|
|
|
|
from iotests import cachemode, imgfmt, qemu_img, qemu_nbd
|
|
|
|
|
|
|
|
NBD_PORT = 10811
|
|
|
|
|
|
|
|
test_img = os.path.join(iotests.test_dir, 'test.img')
|
|
|
|
unix_socket = os.path.join(iotests.test_dir, 'nbd.socket')
|
|
|
|
|
nbd: Tidy up blockdev-add interface
SocketAddress is a simple union, and simple unions are awkward: they
have their variant members wrapped in a "data" object on the wire, and
require additional indirections in C. I intend to limit its use to
existing external interfaces, and convert all internal interfaces to
SocketAddressFlat.
BlockdevOptionsNbd is an external interface using SocketAddress. We
already use SocketAddressFlat elsewhere in blockdev-add. Replace it
by SocketAddressFlat while we can (it's new in 2.9) for simplicity and
consistency. For example,
{ "execute": "blockdev-add",
"arguments": { "node-name": "foo", "driver": "nbd",
"server": { "type": "inet",
"data": { "host": "localhost",
"port": "12345" } } } }
becomes
{ "execute": "blockdev-add",
"arguments": { "node-name": "foo", "driver": "nbd",
"server": { "type": "inet",
"host": "localhost", "port": "12345" } } }
Since the internal interfaces still take SocketAddress, this requires
conversion function socket_address_crumple(). It'll go away when I
update the interfaces.
Unfortunately, SocketAddress is also visible in -drive since 2.8:
-drive if=none,driver=nbd,server.type=inet,server.data.host=127.0.0.1,server.data.port=12345
Nobody should be using it, as it's fairly new and has never been
documented, so adding still more compatibility gunk to keep it working
isn't worth the trouble. You now have to use
-drive if=none,driver=nbd,server.type=inet,server.host=127.0.0.1,server.port=12345
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-id: 1490895797-29094-9-git-send-email-armbru@redhat.com
[mreitz: Change iotest 147 accordingly]
Because of this interface change, iotest 147 has to be adapted.
Unfortunately, we cannot just flatten all of the addresses because
nbd-server-start still takes a plain SocketAddress. Therefore, we need
both and this is most easily achieved by writing the SocketAddress into
the code and flattening it where necessary.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20170330221243.17333-1-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2017-03-30 19:43:16 +02:00
|
|
|
|
|
|
|
def flatten_sock_addr(crumpled_address):
|
|
|
|
result = { 'type': crumpled_address['type'] }
|
|
|
|
result.update(crumpled_address['data'])
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
2016-10-25 15:11:41 +02:00
|
|
|
class NBDBlockdevAddBase(iotests.QMPTestCase):
|
2018-01-19 14:57:17 +01:00
|
|
|
def blockdev_add_options(self, address, export, node_name):
|
|
|
|
options = { 'node-name': node_name,
|
2016-10-25 15:11:41 +02:00
|
|
|
'driver': 'raw',
|
|
|
|
'file': {
|
|
|
|
'driver': 'nbd',
|
nbd-client: Refuse read-only client with BDRV_O_RDWR
The NBD spec says that clients should not try to write/trim to
an export advertised as read-only by the server. But we failed
to check that, and would allow the block layer to use NBD with
BDRV_O_RDWR even when the server is read-only, which meant we
were depending on the server sending a proper EPERM failure for
various commands, and also exposes a leaky abstraction: using
qemu-io in read-write mode would succeed on 'w -z 0 0' because
of local short-circuiting logic, but 'w 0 0' would send a
request over the wire (where it then depends on the server, and
fails at least for qemu-nbd but might pass for other NBD
implementations).
With this patch, a client MUST request read-only mode to access
a server that is doing a read-only export, or else it will get
a message like:
can't open device nbd://localhost:10809/foo: request for write access conflicts with read-only export
It is no longer possible to even attempt writes over the wire
(including the corner case of 0-length writes), because the block
layer enforces the explicit read-only request; this matches the
behavior of qcow2 when backed by a read-only POSIX file.
Fix several iotests to comply with the new behavior (since
qemu-nbd of an internal snapshot, as well as nbd-server-add over QMP,
default to a read-only export, we must tell blockdev-add/qemu-io to
set up a read-only client).
CC: qemu-stable@nongnu.org
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20171108215703.9295-3-eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2017-11-08 22:56:58 +01:00
|
|
|
'read-only': True,
|
2016-10-25 15:11:41 +02:00
|
|
|
'server': address
|
|
|
|
} }
|
|
|
|
if export is not None:
|
|
|
|
options['file']['export'] = export
|
|
|
|
return options
|
|
|
|
|
2018-01-19 14:57:17 +01:00
|
|
|
def client_test(self, filename, address, export=None,
|
|
|
|
node_name='nbd-blockdev', delete=True):
|
|
|
|
bao = self.blockdev_add_options(address, export, node_name)
|
2016-10-25 15:11:41 +02:00
|
|
|
result = self.vm.qmp('blockdev-add', **bao)
|
|
|
|
self.assert_qmp(result, 'return', {})
|
|
|
|
|
2018-01-19 14:57:17 +01:00
|
|
|
found = False
|
2016-10-25 15:11:41 +02:00
|
|
|
result = self.vm.qmp('query-named-block-nodes')
|
|
|
|
for node in result['return']:
|
2018-01-19 14:57:17 +01:00
|
|
|
if node['node-name'] == node_name:
|
|
|
|
found = True
|
2016-10-25 15:11:41 +02:00
|
|
|
if isinstance(filename, str):
|
|
|
|
self.assert_qmp(node, 'image/filename', filename)
|
|
|
|
else:
|
|
|
|
self.assert_json_filename_equal(node['image']['filename'],
|
|
|
|
filename)
|
|
|
|
break
|
2018-01-19 14:57:17 +01:00
|
|
|
self.assertTrue(found)
|
2016-10-25 15:11:41 +02:00
|
|
|
|
2018-01-19 14:57:17 +01:00
|
|
|
if delete:
|
|
|
|
result = self.vm.qmp('blockdev-del', node_name=node_name)
|
|
|
|
self.assert_qmp(result, 'return', {})
|
2016-10-25 15:11:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
class QemuNBD(NBDBlockdevAddBase):
|
|
|
|
def setUp(self):
|
|
|
|
qemu_img('create', '-f', iotests.imgfmt, test_img, '64k')
|
|
|
|
self.vm = iotests.VM()
|
|
|
|
self.vm.launch()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.vm.shutdown()
|
|
|
|
os.remove(test_img)
|
|
|
|
try:
|
|
|
|
os.remove(unix_socket)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _server_up(self, *args):
|
|
|
|
self.assertEqual(qemu_nbd('-f', imgfmt, test_img, *args), 0)
|
|
|
|
|
|
|
|
def test_inet(self):
|
|
|
|
self._server_up('-p', str(NBD_PORT))
|
|
|
|
address = { 'type': 'inet',
|
|
|
|
'data': {
|
|
|
|
'host': 'localhost',
|
|
|
|
'port': str(NBD_PORT)
|
|
|
|
} }
|
nbd: Tidy up blockdev-add interface
SocketAddress is a simple union, and simple unions are awkward: they
have their variant members wrapped in a "data" object on the wire, and
require additional indirections in C. I intend to limit its use to
existing external interfaces, and convert all internal interfaces to
SocketAddressFlat.
BlockdevOptionsNbd is an external interface using SocketAddress. We
already use SocketAddressFlat elsewhere in blockdev-add. Replace it
by SocketAddressFlat while we can (it's new in 2.9) for simplicity and
consistency. For example,
{ "execute": "blockdev-add",
"arguments": { "node-name": "foo", "driver": "nbd",
"server": { "type": "inet",
"data": { "host": "localhost",
"port": "12345" } } } }
becomes
{ "execute": "blockdev-add",
"arguments": { "node-name": "foo", "driver": "nbd",
"server": { "type": "inet",
"host": "localhost", "port": "12345" } } }
Since the internal interfaces still take SocketAddress, this requires
conversion function socket_address_crumple(). It'll go away when I
update the interfaces.
Unfortunately, SocketAddress is also visible in -drive since 2.8:
-drive if=none,driver=nbd,server.type=inet,server.data.host=127.0.0.1,server.data.port=12345
Nobody should be using it, as it's fairly new and has never been
documented, so adding still more compatibility gunk to keep it working
isn't worth the trouble. You now have to use
-drive if=none,driver=nbd,server.type=inet,server.host=127.0.0.1,server.port=12345
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-id: 1490895797-29094-9-git-send-email-armbru@redhat.com
[mreitz: Change iotest 147 accordingly]
Because of this interface change, iotest 147 has to be adapted.
Unfortunately, we cannot just flatten all of the addresses because
nbd-server-start still takes a plain SocketAddress. Therefore, we need
both and this is most easily achieved by writing the SocketAddress into
the code and flattening it where necessary.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20170330221243.17333-1-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2017-03-30 19:43:16 +02:00
|
|
|
self.client_test('nbd://localhost:%i' % NBD_PORT,
|
|
|
|
flatten_sock_addr(address))
|
2016-10-25 15:11:41 +02:00
|
|
|
|
|
|
|
def test_unix(self):
|
|
|
|
self._server_up('-k', unix_socket)
|
|
|
|
address = { 'type': 'unix',
|
|
|
|
'data': { 'path': unix_socket } }
|
nbd: Tidy up blockdev-add interface
SocketAddress is a simple union, and simple unions are awkward: they
have their variant members wrapped in a "data" object on the wire, and
require additional indirections in C. I intend to limit its use to
existing external interfaces, and convert all internal interfaces to
SocketAddressFlat.
BlockdevOptionsNbd is an external interface using SocketAddress. We
already use SocketAddressFlat elsewhere in blockdev-add. Replace it
by SocketAddressFlat while we can (it's new in 2.9) for simplicity and
consistency. For example,
{ "execute": "blockdev-add",
"arguments": { "node-name": "foo", "driver": "nbd",
"server": { "type": "inet",
"data": { "host": "localhost",
"port": "12345" } } } }
becomes
{ "execute": "blockdev-add",
"arguments": { "node-name": "foo", "driver": "nbd",
"server": { "type": "inet",
"host": "localhost", "port": "12345" } } }
Since the internal interfaces still take SocketAddress, this requires
conversion function socket_address_crumple(). It'll go away when I
update the interfaces.
Unfortunately, SocketAddress is also visible in -drive since 2.8:
-drive if=none,driver=nbd,server.type=inet,server.data.host=127.0.0.1,server.data.port=12345
Nobody should be using it, as it's fairly new and has never been
documented, so adding still more compatibility gunk to keep it working
isn't worth the trouble. You now have to use
-drive if=none,driver=nbd,server.type=inet,server.host=127.0.0.1,server.port=12345
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-id: 1490895797-29094-9-git-send-email-armbru@redhat.com
[mreitz: Change iotest 147 accordingly]
Because of this interface change, iotest 147 has to be adapted.
Unfortunately, we cannot just flatten all of the addresses because
nbd-server-start still takes a plain SocketAddress. Therefore, we need
both and this is most easily achieved by writing the SocketAddress into
the code and flattening it where necessary.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20170330221243.17333-1-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2017-03-30 19:43:16 +02:00
|
|
|
self.client_test('nbd+unix://?socket=' + unix_socket,
|
|
|
|
flatten_sock_addr(address))
|
2016-10-25 15:11:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
class BuiltinNBD(NBDBlockdevAddBase):
|
|
|
|
def setUp(self):
|
|
|
|
qemu_img('create', '-f', iotests.imgfmt, test_img, '64k')
|
|
|
|
self.vm = iotests.VM()
|
|
|
|
self.vm.launch()
|
|
|
|
self.server = iotests.VM('.server')
|
|
|
|
self.server.add_drive_raw('if=none,id=nbd-export,' +
|
|
|
|
'file=%s,' % test_img +
|
|
|
|
'format=%s,' % imgfmt +
|
|
|
|
'cache=%s' % cachemode)
|
|
|
|
self.server.launch()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.vm.shutdown()
|
|
|
|
self.server.shutdown()
|
|
|
|
os.remove(test_img)
|
|
|
|
try:
|
|
|
|
os.remove(unix_socket)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
2018-01-19 14:57:17 +01:00
|
|
|
def _server_up(self, address, export_name=None, export_name2=None):
|
2016-10-25 15:11:41 +02:00
|
|
|
result = self.server.qmp('nbd-server-start', addr=address)
|
|
|
|
self.assert_qmp(result, 'return', {})
|
|
|
|
|
2018-01-19 14:57:17 +01:00
|
|
|
if export_name is None:
|
|
|
|
result = self.server.qmp('nbd-server-add', device='nbd-export')
|
|
|
|
else:
|
|
|
|
result = self.server.qmp('nbd-server-add', device='nbd-export',
|
|
|
|
name=export_name)
|
2016-10-25 15:11:41 +02:00
|
|
|
self.assert_qmp(result, 'return', {})
|
|
|
|
|
2018-01-19 14:57:17 +01:00
|
|
|
if export_name2 is not None:
|
|
|
|
result = self.server.qmp('nbd-server-add', device='nbd-export',
|
|
|
|
name=export_name2)
|
|
|
|
self.assert_qmp(result, 'return', {})
|
|
|
|
|
|
|
|
|
2016-10-25 15:11:41 +02:00
|
|
|
def _server_down(self):
|
|
|
|
result = self.server.qmp('nbd-server-stop')
|
|
|
|
self.assert_qmp(result, 'return', {})
|
|
|
|
|
2018-01-19 14:57:17 +01:00
|
|
|
def do_test_inet(self, export_name=None):
|
|
|
|
address = { 'type': 'inet',
|
|
|
|
'data': {
|
|
|
|
'host': 'localhost',
|
|
|
|
'port': str(NBD_PORT)
|
|
|
|
} }
|
|
|
|
self._server_up(address, export_name)
|
|
|
|
export_name = export_name or 'nbd-export'
|
|
|
|
self.client_test('nbd://localhost:%i/%s' % (NBD_PORT, export_name),
|
|
|
|
flatten_sock_addr(address), export_name)
|
|
|
|
self._server_down()
|
|
|
|
|
|
|
|
def test_inet_default_export_name(self):
|
|
|
|
self.do_test_inet()
|
|
|
|
|
|
|
|
def test_inet_same_export_name(self):
|
|
|
|
self.do_test_inet('nbd-export')
|
|
|
|
|
|
|
|
def test_inet_different_export_name(self):
|
|
|
|
self.do_test_inet('shadow')
|
|
|
|
|
|
|
|
def test_inet_two_exports(self):
|
2016-10-25 15:11:41 +02:00
|
|
|
address = { 'type': 'inet',
|
|
|
|
'data': {
|
|
|
|
'host': 'localhost',
|
|
|
|
'port': str(NBD_PORT)
|
|
|
|
} }
|
2018-01-19 14:57:17 +01:00
|
|
|
self._server_up(address, 'exp1', 'exp2')
|
|
|
|
self.client_test('nbd://localhost:%i/%s' % (NBD_PORT, 'exp1'),
|
|
|
|
flatten_sock_addr(address), 'exp1', 'node1', False)
|
|
|
|
self.client_test('nbd://localhost:%i/%s' % (NBD_PORT, 'exp2'),
|
|
|
|
flatten_sock_addr(address), 'exp2', 'node2', False)
|
|
|
|
result = self.vm.qmp('blockdev-del', node_name='node1')
|
|
|
|
self.assert_qmp(result, 'return', {})
|
|
|
|
result = self.vm.qmp('blockdev-del', node_name='node2')
|
|
|
|
self.assert_qmp(result, 'return', {})
|
2016-10-25 15:11:41 +02:00
|
|
|
self._server_down()
|
|
|
|
|
|
|
|
def test_inet6(self):
|
2017-05-05 12:21:53 +02:00
|
|
|
try:
|
|
|
|
socket.getaddrinfo("::0", "0", socket.AF_INET6,
|
|
|
|
socket.SOCK_STREAM, socket.IPPROTO_TCP,
|
|
|
|
socket.AI_ADDRCONFIG | socket.AI_CANONNAME)
|
|
|
|
except socket.gaierror:
|
|
|
|
# IPv6 not available, skip
|
|
|
|
return
|
2016-10-25 15:11:41 +02:00
|
|
|
address = { 'type': 'inet',
|
|
|
|
'data': {
|
|
|
|
'host': '::1',
|
|
|
|
'port': str(NBD_PORT),
|
|
|
|
'ipv4': False,
|
|
|
|
'ipv6': True
|
|
|
|
} }
|
|
|
|
filename = { 'driver': 'raw',
|
|
|
|
'file': {
|
|
|
|
'driver': 'nbd',
|
|
|
|
'export': 'nbd-export',
|
nbd: Tidy up blockdev-add interface
SocketAddress is a simple union, and simple unions are awkward: they
have their variant members wrapped in a "data" object on the wire, and
require additional indirections in C. I intend to limit its use to
existing external interfaces, and convert all internal interfaces to
SocketAddressFlat.
BlockdevOptionsNbd is an external interface using SocketAddress. We
already use SocketAddressFlat elsewhere in blockdev-add. Replace it
by SocketAddressFlat while we can (it's new in 2.9) for simplicity and
consistency. For example,
{ "execute": "blockdev-add",
"arguments": { "node-name": "foo", "driver": "nbd",
"server": { "type": "inet",
"data": { "host": "localhost",
"port": "12345" } } } }
becomes
{ "execute": "blockdev-add",
"arguments": { "node-name": "foo", "driver": "nbd",
"server": { "type": "inet",
"host": "localhost", "port": "12345" } } }
Since the internal interfaces still take SocketAddress, this requires
conversion function socket_address_crumple(). It'll go away when I
update the interfaces.
Unfortunately, SocketAddress is also visible in -drive since 2.8:
-drive if=none,driver=nbd,server.type=inet,server.data.host=127.0.0.1,server.data.port=12345
Nobody should be using it, as it's fairly new and has never been
documented, so adding still more compatibility gunk to keep it working
isn't worth the trouble. You now have to use
-drive if=none,driver=nbd,server.type=inet,server.host=127.0.0.1,server.port=12345
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-id: 1490895797-29094-9-git-send-email-armbru@redhat.com
[mreitz: Change iotest 147 accordingly]
Because of this interface change, iotest 147 has to be adapted.
Unfortunately, we cannot just flatten all of the addresses because
nbd-server-start still takes a plain SocketAddress. Therefore, we need
both and this is most easily achieved by writing the SocketAddress into
the code and flattening it where necessary.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20170330221243.17333-1-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2017-03-30 19:43:16 +02:00
|
|
|
'server': flatten_sock_addr(address)
|
2016-10-25 15:11:41 +02:00
|
|
|
} }
|
|
|
|
self._server_up(address)
|
nbd: Tidy up blockdev-add interface
SocketAddress is a simple union, and simple unions are awkward: they
have their variant members wrapped in a "data" object on the wire, and
require additional indirections in C. I intend to limit its use to
existing external interfaces, and convert all internal interfaces to
SocketAddressFlat.
BlockdevOptionsNbd is an external interface using SocketAddress. We
already use SocketAddressFlat elsewhere in blockdev-add. Replace it
by SocketAddressFlat while we can (it's new in 2.9) for simplicity and
consistency. For example,
{ "execute": "blockdev-add",
"arguments": { "node-name": "foo", "driver": "nbd",
"server": { "type": "inet",
"data": { "host": "localhost",
"port": "12345" } } } }
becomes
{ "execute": "blockdev-add",
"arguments": { "node-name": "foo", "driver": "nbd",
"server": { "type": "inet",
"host": "localhost", "port": "12345" } } }
Since the internal interfaces still take SocketAddress, this requires
conversion function socket_address_crumple(). It'll go away when I
update the interfaces.
Unfortunately, SocketAddress is also visible in -drive since 2.8:
-drive if=none,driver=nbd,server.type=inet,server.data.host=127.0.0.1,server.data.port=12345
Nobody should be using it, as it's fairly new and has never been
documented, so adding still more compatibility gunk to keep it working
isn't worth the trouble. You now have to use
-drive if=none,driver=nbd,server.type=inet,server.host=127.0.0.1,server.port=12345
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-id: 1490895797-29094-9-git-send-email-armbru@redhat.com
[mreitz: Change iotest 147 accordingly]
Because of this interface change, iotest 147 has to be adapted.
Unfortunately, we cannot just flatten all of the addresses because
nbd-server-start still takes a plain SocketAddress. Therefore, we need
both and this is most easily achieved by writing the SocketAddress into
the code and flattening it where necessary.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20170330221243.17333-1-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2017-03-30 19:43:16 +02:00
|
|
|
self.client_test(filename, flatten_sock_addr(address), 'nbd-export')
|
2016-10-25 15:11:41 +02:00
|
|
|
self._server_down()
|
|
|
|
|
|
|
|
def test_unix(self):
|
|
|
|
address = { 'type': 'unix',
|
|
|
|
'data': { 'path': unix_socket } }
|
|
|
|
self._server_up(address)
|
|
|
|
self.client_test('nbd+unix:///nbd-export?socket=' + unix_socket,
|
nbd: Tidy up blockdev-add interface
SocketAddress is a simple union, and simple unions are awkward: they
have their variant members wrapped in a "data" object on the wire, and
require additional indirections in C. I intend to limit its use to
existing external interfaces, and convert all internal interfaces to
SocketAddressFlat.
BlockdevOptionsNbd is an external interface using SocketAddress. We
already use SocketAddressFlat elsewhere in blockdev-add. Replace it
by SocketAddressFlat while we can (it's new in 2.9) for simplicity and
consistency. For example,
{ "execute": "blockdev-add",
"arguments": { "node-name": "foo", "driver": "nbd",
"server": { "type": "inet",
"data": { "host": "localhost",
"port": "12345" } } } }
becomes
{ "execute": "blockdev-add",
"arguments": { "node-name": "foo", "driver": "nbd",
"server": { "type": "inet",
"host": "localhost", "port": "12345" } } }
Since the internal interfaces still take SocketAddress, this requires
conversion function socket_address_crumple(). It'll go away when I
update the interfaces.
Unfortunately, SocketAddress is also visible in -drive since 2.8:
-drive if=none,driver=nbd,server.type=inet,server.data.host=127.0.0.1,server.data.port=12345
Nobody should be using it, as it's fairly new and has never been
documented, so adding still more compatibility gunk to keep it working
isn't worth the trouble. You now have to use
-drive if=none,driver=nbd,server.type=inet,server.host=127.0.0.1,server.port=12345
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-id: 1490895797-29094-9-git-send-email-armbru@redhat.com
[mreitz: Change iotest 147 accordingly]
Because of this interface change, iotest 147 has to be adapted.
Unfortunately, we cannot just flatten all of the addresses because
nbd-server-start still takes a plain SocketAddress. Therefore, we need
both and this is most easily achieved by writing the SocketAddress into
the code and flattening it where necessary.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20170330221243.17333-1-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2017-03-30 19:43:16 +02:00
|
|
|
flatten_sock_addr(address), 'nbd-export')
|
2016-10-25 15:11:41 +02:00
|
|
|
self._server_down()
|
|
|
|
|
|
|
|
def test_fd(self):
|
|
|
|
self._server_up({ 'type': 'unix',
|
|
|
|
'data': { 'path': unix_socket } })
|
|
|
|
|
|
|
|
sockfd = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
|
|
sockfd.connect(unix_socket)
|
|
|
|
|
|
|
|
result = self.vm.send_fd_scm(str(sockfd.fileno()))
|
|
|
|
self.assertEqual(result, 0, 'Failed to send socket FD')
|
|
|
|
|
|
|
|
result = self.vm.qmp('getfd', fdname='nbd-fifo')
|
|
|
|
self.assert_qmp(result, 'return', {})
|
|
|
|
|
|
|
|
address = { 'type': 'fd',
|
|
|
|
'data': { 'str': 'nbd-fifo' } }
|
|
|
|
filename = { 'driver': 'raw',
|
|
|
|
'file': {
|
|
|
|
'driver': 'nbd',
|
|
|
|
'export': 'nbd-export',
|
nbd: Tidy up blockdev-add interface
SocketAddress is a simple union, and simple unions are awkward: they
have their variant members wrapped in a "data" object on the wire, and
require additional indirections in C. I intend to limit its use to
existing external interfaces, and convert all internal interfaces to
SocketAddressFlat.
BlockdevOptionsNbd is an external interface using SocketAddress. We
already use SocketAddressFlat elsewhere in blockdev-add. Replace it
by SocketAddressFlat while we can (it's new in 2.9) for simplicity and
consistency. For example,
{ "execute": "blockdev-add",
"arguments": { "node-name": "foo", "driver": "nbd",
"server": { "type": "inet",
"data": { "host": "localhost",
"port": "12345" } } } }
becomes
{ "execute": "blockdev-add",
"arguments": { "node-name": "foo", "driver": "nbd",
"server": { "type": "inet",
"host": "localhost", "port": "12345" } } }
Since the internal interfaces still take SocketAddress, this requires
conversion function socket_address_crumple(). It'll go away when I
update the interfaces.
Unfortunately, SocketAddress is also visible in -drive since 2.8:
-drive if=none,driver=nbd,server.type=inet,server.data.host=127.0.0.1,server.data.port=12345
Nobody should be using it, as it's fairly new and has never been
documented, so adding still more compatibility gunk to keep it working
isn't worth the trouble. You now have to use
-drive if=none,driver=nbd,server.type=inet,server.host=127.0.0.1,server.port=12345
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-id: 1490895797-29094-9-git-send-email-armbru@redhat.com
[mreitz: Change iotest 147 accordingly]
Because of this interface change, iotest 147 has to be adapted.
Unfortunately, we cannot just flatten all of the addresses because
nbd-server-start still takes a plain SocketAddress. Therefore, we need
both and this is most easily achieved by writing the SocketAddress into
the code and flattening it where necessary.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20170330221243.17333-1-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2017-03-30 19:43:16 +02:00
|
|
|
'server': flatten_sock_addr(address)
|
2016-10-25 15:11:41 +02:00
|
|
|
} }
|
nbd: Tidy up blockdev-add interface
SocketAddress is a simple union, and simple unions are awkward: they
have their variant members wrapped in a "data" object on the wire, and
require additional indirections in C. I intend to limit its use to
existing external interfaces, and convert all internal interfaces to
SocketAddressFlat.
BlockdevOptionsNbd is an external interface using SocketAddress. We
already use SocketAddressFlat elsewhere in blockdev-add. Replace it
by SocketAddressFlat while we can (it's new in 2.9) for simplicity and
consistency. For example,
{ "execute": "blockdev-add",
"arguments": { "node-name": "foo", "driver": "nbd",
"server": { "type": "inet",
"data": { "host": "localhost",
"port": "12345" } } } }
becomes
{ "execute": "blockdev-add",
"arguments": { "node-name": "foo", "driver": "nbd",
"server": { "type": "inet",
"host": "localhost", "port": "12345" } } }
Since the internal interfaces still take SocketAddress, this requires
conversion function socket_address_crumple(). It'll go away when I
update the interfaces.
Unfortunately, SocketAddress is also visible in -drive since 2.8:
-drive if=none,driver=nbd,server.type=inet,server.data.host=127.0.0.1,server.data.port=12345
Nobody should be using it, as it's fairly new and has never been
documented, so adding still more compatibility gunk to keep it working
isn't worth the trouble. You now have to use
-drive if=none,driver=nbd,server.type=inet,server.host=127.0.0.1,server.port=12345
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-id: 1490895797-29094-9-git-send-email-armbru@redhat.com
[mreitz: Change iotest 147 accordingly]
Because of this interface change, iotest 147 has to be adapted.
Unfortunately, we cannot just flatten all of the addresses because
nbd-server-start still takes a plain SocketAddress. Therefore, we need
both and this is most easily achieved by writing the SocketAddress into
the code and flattening it where necessary.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20170330221243.17333-1-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2017-03-30 19:43:16 +02:00
|
|
|
self.client_test(filename, flatten_sock_addr(address), 'nbd-export')
|
2016-10-25 15:11:41 +02:00
|
|
|
|
|
|
|
self._server_down()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# Need to support image creation
|
|
|
|
iotests.main(supported_fmts=['vpc', 'parallels', 'qcow', 'vdi', 'qcow2',
|
|
|
|
'vmdk', 'raw', 'vhdx', 'qed'])
|