On 6/18/19 6:43 AM, Vladimir Sementsov-Ogievskiy wrote: > We'll need some connection parameters to be available all the time to > implement nbd reconnect. So, let's refactor them: define additional > parameters in BDRVNBDState, drop them from function parameters, drop > nbd_client_init and separate options parsing instead from nbd_open. > > Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]> > --- > block/nbd.c | 125 +++++++++++++++++++++++++++------------------------- > 1 file changed, 64 insertions(+), 61 deletions(-) >
> @@ -1659,20 +1630,19 @@ static int nbd_open(BlockDriverState *bs, QDict
> *options, int flags,
> error_setg(errp, "TLS only supported over IP sockets");
> goto error;
> }
> - hostname = s->saddr->u.inet.host;
> + s->hostname = s->saddr->u.inet.host;
> }
>
> - /* NBD handshake */
> - ret = nbd_client_init(bs, s->saddr, s->export, tlscreds, hostname,
> - qemu_opt_get(opts, "x-dirty-bitmap"),
> - qemu_opt_get_number(opts, "reconnect-delay", 0),
> - errp);
> + s->x_dirty_bitmap = g_strdup(qemu_opt_get(opts, "x-dirty-bitmap"));
> + s->reconnect_delay = qemu_opt_get_number(opts, "reconnect-delay", 0);
> +
> + ret = 0;
>
> error:
> - if (tlscreds) {
> - object_unref(OBJECT(tlscreds));
> - }
> if (ret < 0) {
> + if (s->tlscreds) {
> + object_unref(OBJECT(s->tlscreds));
> + }
Pre-existing, but object_unref(NULL) is safe, making this a useless 'if'.
> @@ -1726,9 +1725,13 @@ static void nbd_close(BlockDriverState *bs)
>
> nbd_client_close(bs);
>
> + if (s->tlscreds) {
> + object_unref(OBJECT(s->tlscreds));
> + }
and copied here.
> qapi_free_SocketAddress(s->saddr);
> g_free(s->export);
> g_free(s->tlscredsid);
> + g_free(s->x_dirty_bitmap);
Do we need to duplicate s->x_dirty_bitmap with s->info.x_dirty_bitmap,
or make the latter be const char * and reuse the pointer from the former
rather than strdup'ing it? (I don't think it affects the refactoring
done in this patch, but is possibly worth a separate cleanup patch).
I can fix up the two useless 'if's.
Reviewed-by: Eric Blake <[email protected]>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
