[Test] Add API to tunnel channels

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Attached is a simple test program to exercise virDomainOpenChannel that
echoes a toupper()'d string and exits.  Edit the #defines as necessary
to match your setup.  You'll need a channel defined in the guest similar
to:

    <channel type="unix">
      <source mode="bind" path="/tmp/guestfsd.sock"/>
      <target type="virtio" name="org.libguestfs.channel.0"/>
    </channel>

Run the test, and then inside of the VM, you should be able to:

    [root@f17-minimal ~]# socat - /dev/virtio-ports/org.libguestfs.channel.0
    hello world
    HELLO WORLD
    [root@f17-minimal ~]#

#include <ctype.h>
#include <err.h>
#include <stdlib.h>
#include <string.h>
#include <libvirt/libvirt.h>

#define CONNECT_URI "qemu+ssh://root@localhost/system"
#define DOMAIN "f17-minimal"
#define CHANNEL "org.libguestfs.channel.0"
#define BUF_SIZE 80

void upper(char *c)
{
  while (*c != '\0') {
    *c = toupper((unsigned char)*c);
    c++;
  }
}

int main(int argc, char *argv[])
{
  virConnectPtr conn;
  virDomainPtr dom;
  virStreamPtr st;
  int bytes_read;
  char buf[BUF_SIZE];

  if ((conn = virConnectOpen(CONNECT_URI)) == NULL)
    errx(1, "virConnectOpen");

  if ((dom = virDomainLookupByName(conn, DOMAIN)) == NULL)
    errx(1, "virDomainLookupByName");

  if ((st = virStreamNew(conn, 0)) == NULL)
    errx(1, "virStreamNew");

  if (virDomainOpenChannel(dom, CHANNEL, st, 0) == -1)
    errx(1, "virDomainOpenChannel");

  if ((bytes_read = virStreamRecv(st, buf, BUF_SIZE)) > 0) {
    buf[bytes_read] = '\0';
    upper(buf);
    virStreamSend(st, buf, strnlen(buf, BUF_SIZE));
  }

  if (virStreamFinish(st) < 0)
    errx(1, "virStreamFinish");
  if (virStreamFree(st) < 0)
    errx(1, "virStreamFree");
  return 0;
}
--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]