return tapfd;
}
+static const char *
+qemuNetTypeToHostNet(int type)
+{
+ switch (type) {
+ case VIR_DOMAIN_NET_TYPE_NETWORK:
+ case VIR_DOMAIN_NET_TYPE_BRIDGE:
+ case VIR_DOMAIN_NET_TYPE_ETHERNET:
+ return "tap";
+
+ case VIR_DOMAIN_NET_TYPE_CLIENT:
+ case VIR_DOMAIN_NET_TYPE_SERVER:
+ case VIR_DOMAIN_NET_TYPE_MCAST:
+ return "socket";
+
+ case VIR_DOMAIN_NET_TYPE_USER:
+ default:
+ return "user";
+ }
+}
+
+static int
+qemuAssignNetNames(virDomainDefPtr def,
+ virDomainNetDefPtr net)
+{
+ char *nic_name, *hostnet_name;
+ int i, nic_index = 0, hostnet_index = 0;
+
+ for (i = 0; i < def->nnets; i++) {
+ if (def->nets[i] == net)
+ continue;
+
+ if (!def->nets[i]->nic_name || !def->nets[i]->hostnet_name)
+ continue;
+
+ if ((def->nets[i]->model == NULL && net->model == NULL) ||
+ (def->nets[i]->model != NULL && net->model != NULL &&
+ STREQ(def->nets[i]->model, net->model)))
+ ++nic_index;
+
+ if (STREQ(qemuNetTypeToHostNet(def->nets[i]->type),
+ qemuNetTypeToHostNet(net->type)))
+ ++hostnet_index;
+ }
+
+ if (virAsprintf(&nic_name, "%s.%d",
+ net->model ? net->model : "nic",
+ nic_index) < 0)
+ return -1;
+
+ if (virAsprintf(&hostnet_name, "%s.%d",
+ qemuNetTypeToHostNet(net->type),
+ hostnet_index) < 0) {
+ VIR_FREE(nic_name);
+ return -1;
+ }
+
+ net->nic_name = nic_name;
+ net->hostnet_name = hostnet_name;
+
+ return 0;
+}
+
static int
qemuBuildNicStr(virConnectPtr conn,
virDomainNetDefPtr net,
char **str)
{
if (virAsprintf(str,
- "%snic%cmacaddr=%02x:%02x:%02x:%02x:%02x:%02x,vlan=%d%s%s",
+ "%snic%cmacaddr=%02x:%02x:%02x:%02x:%02x:%02x,vlan=%d%s%s%s%s",
prefix ? prefix : "",
type_sep,
net->mac[0], net->mac[1],
net->mac[4], net->mac[5],
vlan,
(net->model ? ",model=" : ""),
- (net->model ? net->model : "")) < 0) {
+ (net->model ? net->model : ""),
+ (net->nic_name ? ",name=" : ""),
+ (net->nic_name ? net->nic_name : "")) < 0) {
virReportOOMError(conn);
return -1;
}
switch (net->type) {
case VIR_DOMAIN_NET_TYPE_NETWORK:
case VIR_DOMAIN_NET_TYPE_BRIDGE:
- if (virAsprintf(str, "%stap%cfd=%d,vlan=%d",
+ if (virAsprintf(str, "%stap%cfd=%d,vlan=%d%s%s",
prefix ? prefix : "",
- type_sep, tapfd, vlan) < 0) {
+ type_sep, tapfd, vlan,
+ (net->hostnet_name ? ",name=" : ""),
+ (net->hostnet_name ? net->hostnet_name : "")) < 0) {
virReportOOMError(conn);
return -1;
}
type_sep = ',';
}
virBufferVSprintf(&buf, "%cvlan=%d", type_sep, vlan);
+ if (net->hostnet_name) {
+ virBufferVSprintf(&buf, "%cname=%s", type_sep,
+ net->hostnet_name);
+ type_sep = ',';
+ }
if (virBufferError(&buf)) {
virReportOOMError(conn);
return -1;
break;
}
- if (virAsprintf(str, "%ssocket%c%s=%s:%d,vlan=%d",
+ if (virAsprintf(str, "%ssocket%c%s=%s:%d,vlan=%d%s%s",
prefix ? prefix : "",
type_sep, mode,
net->data.socket.address,
net->data.socket.port,
- vlan) < 0) {
+ vlan,
+ (net->hostnet_name ? ",name=" : ""),
+ (net->hostnet_name ? net->hostnet_name : "")) < 0) {
virReportOOMError(conn);
return -1;
}
case VIR_DOMAIN_NET_TYPE_USER:
default:
- if (virAsprintf(str, "%suser%cvlan=%d",
+ if (virAsprintf(str, "%suser%cvlan=%d%s%s",
prefix ? prefix : "",
- type_sep, vlan) < 0) {
+ type_sep, vlan,
+ (net->hostnet_name ? ",name=" : ""),
+ (net->hostnet_name ? net->hostnet_name : "")) < 0) {
virReportOOMError(conn);
return -1;
}
char *nic, *host;
int tapfd = -1;
+ if ((qemuCmdFlags & QEMUD_CMD_FLAG_NET_NAME) &&
+ qemuAssignNetNames(def, net) < 0)
+ goto no_memory;
+
if (qemuBuildNicStr(conn, net, NULL, ',', i, &nic) < 0)
goto error;
--- /dev/null
+<domain type='qemu'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory>219200</memory>
+ <currentMemory>219200</currentMemory>
+ <vcpu>1</vcpu>
+ <os>
+ <type arch='i686' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu</emulator>
+ <disk type='block' device='disk'>
+ <source dev='/dev/HostVG/QEMUGuest1'/>
+ <target dev='hda' bus='ide'/>
+ </disk>
+ <interface type='ethernet'>
+ <mac address='00:11:22:33:44:55'/>
+ <script path='/etc/qemu-ifup'/>
+ </interface>
+ <interface type='ethernet'>
+ <mac address='00:11:22:33:44:56'/>
+ <script path='/etc/qemu-ifup'/>
+ <model type='e1000'/>
+ </interface>
+ </devices>
+</domain>