Codebase list virt-viewer / fa39c53
Reconnect to libvirtd after connection breaks Currently, if user wants to reconnect to a domain he can use '-r' cmd line argument. This makes virt-viewer listen to domain events. However, if connection to libvirtd breaks somehow, we will receive no longer any event. Hence we must reconnect to the libvirt. Michal Privoznik 11 years ago
4 changed file(s) with 57 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
66 Christophe Fergeau <cfergeau@redhat.com>
77 Marc-André Lureau <marcandre.lureau@redhat.com>
88 Hans de Goede <hdegoede@redhat.com>
9 Michal Privoznik <mprivozn@redhat.com>
910
1011 With additional patches from:
1112
1313
1414 GLIB2_REQUIRED=2.22.0
1515 LIBXML2_REQUIRED="2.6.0"
16 LIBVIRT_REQUIRED="0.9.7"
16 LIBVIRT_REQUIRED="0.10.0"
1717 GTK2_REQUIRED="2.18.0"
1818 GTK3_REQUIRED="3.0"
1919 GTK_VNC1_REQUIRED="0.3.8"
10091009 g_return_if_fail(VIRT_VIEWER_IS_APP(self));
10101010 VirtViewerAppPrivate *priv = self->priv;
10111011
1012 DEBUG_LOG("reconnect_poll: %d", priv->reconnect_poll);
1013
10121014 if (priv->reconnect_poll != 0)
10131015 return;
10141016
488488 return 0;
489489 }
490490
491 static void
492 virt_viewer_conn_event(virConnectPtr conn G_GNUC_UNUSED,
493 int reason,
494 void *opaque)
495 {
496 VirtViewer *self = opaque;
497 VirtViewerApp *app = VIRT_VIEWER_APP(self);
498 VirtViewerPrivate *priv = self->priv;
499
500 DEBUG_LOG("Got connection event %d", reason);
501
502 virConnectClose(priv->conn);
503 priv->conn = NULL;
504
505 virt_viewer_app_start_reconnect_poll(app);
506 }
507
508 static int virt_viewer_connect(VirtViewerApp *app);
509
491510 static int
492511 virt_viewer_initial_connect(VirtViewerApp *app)
493512 {
496515 int ret = -1;
497516 VirtViewer *self = VIRT_VIEWER(app);
498517 VirtViewerPrivate *priv = self->priv;
518
519
520 DEBUG_LOG("initial connect");
521
522 if (!priv->conn &&
523 virt_viewer_connect(app) < 0) {
524 virt_viewer_app_show_status(app, _("Waiting for libvirt to start"));
525 goto done;
526 }
499527
500528 virt_viewer_app_show_status(app, _("Finding guest domain"));
501529 dom = virt_viewer_lookup_domain(self);
617645 return ret;
618646 }
619647
620
621 static gboolean
622 virt_viewer_start(VirtViewerApp *app)
648 static int
649 virt_viewer_connect(VirtViewerApp *app)
623650 {
624651 VirtViewer *self = VIRT_VIEWER(app);
625652 VirtViewerPrivate *priv = self->priv;
636663 if (!virt_viewer_app_get_attach(app))
637664 oflags |= VIR_CONNECT_RO;
638665
639 virt_viewer_events_register();
640
641 virSetErrorFunc(NULL, virt_viewer_error_func);
666 DEBUG_LOG("connecting ...");
642667
643668 virt_viewer_app_trace(app, "Opening connection to libvirt with URI %s",
644669 priv->uri ? priv->uri : "<null>");
649674 if (!priv->conn) {
650675 virt_viewer_app_simple_message_dialog(app, _("Unable to connect to libvirt with URI %s"),
651676 priv->uri ? priv->uri : _("[none]"));
652 return FALSE;
677 return -1;
653678 }
654679
655680 if (virt_viewer_app_initial_connect(app) < 0)
656 return FALSE;
681 return -1;
657682
658683 if (virConnectDomainEventRegister(priv->conn,
659684 virt_viewer_domain_event,
668693 DEBUG_LOG("No domain events, falling back to polling");
669694 virt_viewer_app_start_reconnect_poll(app);
670695 }
696
697 if (virConnectRegisterCloseCallback(priv->conn,
698 virt_viewer_conn_event,
699 self,
700 NULL) < 0) {
701 DEBUG_LOG("Unable to register close callback on libvirt connection");
702 }
703
704 return 0;
705 }
706
707 static gboolean
708 virt_viewer_start(VirtViewerApp *app)
709 {
710 virt_viewer_events_register();
711
712 virSetErrorFunc(NULL, virt_viewer_error_func);
713
714 if (virt_viewer_connect(app) < 0)
715 return FALSE;
671716
672717 return VIRT_VIEWER_APP_CLASS(virt_viewer_parent_class)->start(app);
673718 }