Network-connected analog processor QEMU monitor

Source: Internet
Author: User

1. QEMU monitor supports remote telnet access:

[Root@kvm-host ~]# qemu-system-x86_64-enable-kvm-smp 2-m 1024 vm2.img-monitor

For the-monitor option here, make the following note:

The code is as follows Copy Code
Tcp–raw TCP sockets #下面第2点, my example is raw TCP socket
Telnet–the Telnet protocol is used instead of raw TCP sockets. This is the preferred option over TCP as, can break out of the monitor using Ctrl-then typing quit. You can "T break out of the" monitor like this "connecting with the raw socket option
10.1.77.82–listen on this host/ip only. can use 127.0.0.1 if your want to only allow connections locally. If you are want to listen on the "any" IP address on the server, just leave this blank so your end up with two consecutive colons ie “::” .
4444–port number to listen on.
Server–listening in Server mode
Nowait–qemu'll wait for a client socket application to connect to the port before continuing unless this option are use D. In most cases you'll want to use the NOWAIT option.

Connect to remote Qemu monitor via telnet:

The code is as follows Copy Code
jay@jay-linux:~$ telnet 10.1.77.82 4444
Trying 10.1.77.82 ...
Connected to 10.1.77.82.
Escape character is ' ^] '.
QEMU 1.7.50 monitor-type ' help ' for more information
(QEMU) Info KVM
KVM support:enabled
(QEMU) Info status
VM status:running
(QEMU) Help migrate
Migrate [-d] [-b] [-i] URI--migrate to URI (using-d to Don't wait for completion)
-B for migration without shared storage with full copy of disk
I-migration without shared storage with incremental copy of disk (base image shared between SRC and destination)
(QEMU) Ctrl +] (disconnect telnet connection)
Telnet> quit (exit Telnet)
Connection closed.


2. QEMU monitor supports remote access to RAW sockets:

The code is as follows Copy Code
[Root@kvm-host ~]# qemu-system-x86_64-enable-kvm-smp 2-m 1024 vm2.img-monitor


You can use Netcat to connect to this socket:

The code is as follows Copy Code
jay@jay-linux:~$ NC 10.1.77.82 4444
QEMU 1.7.50 monitor-type ' help ' for more information
(QEMU) Info KVM
Info KVM
KVM support:enabled
(QEMU) ^c


I wrote a socket program for example to connect monitor, the effect is as follows:

The code is as follows Copy Code
jay@jay-linux:~/workspace/c-cpp.git/c2013$./monitor_client
Sending command ' info KVM
' To remote QEMU monitor
Output from Qemu monitor:qemu 1.7.50 monitor-type "Help" for more information
??,?
Output from QEMU Monitor: (QEMU) Info KVM
KVM support:enabled
(QEMU)



The above example of the socket program that connects to monitor is:

Https://github.com/smilejay/c-cpp/blob/master/c2013/socket_qemu_monitor_client.c

The code is as follows Copy Code
/* SOCKET_QEMU_MONITOR_CLINET.C
* Connect to remote QEMU monitor sockets and sending a command to the monitor.
* Author:jay <smile665@gmail.com>
*/

#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

int main (int argc, char *argv[])
{
int sockfd;
int Len;
struct SOCKADDR_IN address;
int result;
Char *cmd = "info kvmn";
Char output[200];

/* Create A socket for the client. */
SOCKFD = socket (af_inet, sock_stream, 0);

/* Name the socket, as agreed with the server. */
address.sin_family = af_inet;
ADDRESS.SIN_ADDR.S_ADDR = inet_addr ("10.1.77.82");
Address.sin_port = htons (4444);
Len = sizeof (address);

* Now connect our sockets to the server ' s socket. */
result = Connect (SOCKFD, (struct sockaddr *) &address, Len);

if (result = = 1) {
Perror ("Oops:socket connetion failed.");
Exit (1);
}

/* We can now read/write via SOCKFD. */
printf ("Sending command '%s ' to remote QEMU monitorn", cmd);
Write (sockfd, cmd, strlen (cmd));
Read (sockfd, output, sizeof (output));
printf ("Output from QEMU Monitor:%SN", output);
Read (sockfd, output, sizeof (output));
printf ("Output from QEMU Monitor:%SN", output);
Close (SOCKFD);
Exit (0);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.