Revision 8754dc49

View differences:

include/HostShare.h
117 117
    static int get_pci_value(const char * name,
118 118
                             const VectorAttribute * pci_device,
119 119
                             unsigned int& value);
120
    /**
121
     *  Sets the PCI device address in the Virtual Machine as follows;
122
     *    - VM_DOMAIN: 0x0000
123
     *    - VM_BUS: dbus or VM_BUS in PCI attribute
124
     *    - VM_SLOT: PCI_ID + 1
125
     *    - VM_FUNCTION: 0
126
     *    - VM_ADDRESS: BUS:SLOT.0
127
     *  @param pci_device to set the address in
128
     *  @param default_bus if not set in PCI attribute (PCI_PASSTHROUGH_BUS
129
     *   in oned.conf)
130
     *  @return -1 if wrong bus 0 on success
131
     */
132
    static int set_pci_address(VectorAttribute * pci_device, const string& dbus);
120 133

  
121 134
private:
122 135
    /**
share/etc/oned.conf
199 199
# for vxlan networks.
200 200
#     start: First VNI to use
201 201
#     NOTE: reserved is not supported by this pool
202
#
203
# PCI_PASSTHROUGH_BUS: Default bus to attach passthrough devices in the guest,
204
# in hex notation. It may be overwritten in the PCI device using the BUS 
205
# attribute.
202 206
#*******************************************************************************
203 207

  
204 208
NETWORK_SIZE = 254
......
214 218
    START = "2"
215 219
]
216 220

  
221
#PCI_PASSTHROUGH_BUS = "0x01"
222

  
217 223
#*******************************************************************************
218 224
# DataStore Configuration
219 225
#*******************************************************************************
src/host/HostShare.cc
267 267
    return 1;
268 268
}
269 269

  
270

  
271
/* ------------------------------------------------------------------------*/
272
/* ------------------------------------------------------------------------*/
273

  
274
int HostSharePCI::set_pci_address(VectorAttribute * pci_device,
275
        const string& dbus)
276
{
277
    string        bus;
278
    ostringstream oss;
279

  
280
    unsigned int ibus, slot;
281

  
282
    // ------------------- DOMAIN & FUNCTION -------------------------
283
	pci_device->replace("VM_DOMAIN", "0x0000");
284
	pci_device->replace("VM_FUNCTION", "0");
285

  
286
    // --------------------------- BUS -------------------------------
287
    bus = pci_device->vector_value("VM_BUS");
288

  
289
    if ( bus.empty() )
290
    {
291
        bus = dbus;
292
    }
293

  
294
    istringstream iss(bus);
295

  
296
    iss >> hex >> ibus;
297

  
298
    if (iss.fail() || !iss.eof())
299
    {
300
        return -1;
301
    }
302

  
303
    oss << showbase << internal << setfill('0') << hex << setw(4) << ibus;
304

  
305
    pci_device->replace("VM_BUS", oss.str());
306

  
307
    // --------------------- SLOT (PCI_ID +1) -----------------------
308
    oss.str("");
309

  
310
    pci_device->vector_value("PCI_ID", slot);
311

  
312
    slot = slot + 1;
313

  
314
    oss << showbase << internal << setfill('0') << hex << setw(4) << slot;
315

  
316
    pci_device->replace("VM_SLOT", oss.str());
317

  
318
    // ------------------- ADDRESS (BUS:SLOT.0) ---------------------
319
    oss.str("");
320

  
321
    oss << noshowbase<<internal<<hex<<setfill('0')<<setw(2) << ibus << ":"
322
        << noshowbase<<internal<<hex<<setfill('0')<<setw(2) << slot << ".0";
323

  
324
    pci_device->replace("VM_ADDRESS", oss.str());
325

  
326
    return 0;
327
}
328

  
270 329
/* ------------------------------------------------------------------------*/
271 330
/* ------------------------------------------------------------------------*/
272 331

  
src/nebula/NebulaTemplate.cc
451 451
#  MAC_PREFIX
452 452
#  VLAN_ID
453 453
#  VXLAN_ID
454
#  PCI_PASSTHROUGH_BUS
454 455
#*******************************************************************************
455 456
*/
456 457
    set_conf_single("MAC_PREFIX", "02:00");
......
468 469

  
469 470
    vattribute = new VectorAttribute("VXLAN_IDS",vvalue);
470 471
    conf_default.insert(make_pair(vattribute->name(),vattribute));
472

  
473
    set_conf_single("PCI_PASSTHROUGH_BUS", "0x01");
471 474
/*
472 475
#*******************************************************************************
473 476
# Datastore Configuration
src/vm/VirtualMachine.cc
1202 1202
/* -------------------------------------------------------------------------- */
1203 1203
/* -------------------------------------------------------------------------- */
1204 1204

  
1205
static int check_pci_attributes(VectorAttribute * pci, string& error_str)
1205
static int check_pci_attributes(VectorAttribute * pci, const string& default_bus,
1206
		string& error_str)
1206 1207
{
1207 1208
    static string attrs[] = {"VENDOR", "DEVICE", "CLASS"};
1208 1209
    static int num_attrs  = 3;
1209 1210

  
1210
    bool found = false;
1211
	string bus;
1212
    bool   found = false;
1211 1213

  
1212 1214
    for (int i = 0; i < num_attrs; i++)
1213 1215
    {
......
1231 1233
        return -1;
1232 1234
    }
1233 1235

  
1236
	if ( HostSharePCI::set_pci_address(pci, default_bus) != 0 )
1237
	{
1238
		error_str = "Wrong BUS in PCI attribute";
1239
		return -1;
1240
	}
1241

  
1234 1242
    return 0;
1235 1243
}
1236 1244

  
......
1250 1258
        obj_template->set(*it);
1251 1259
    }
1252 1260

  
1261
	Nebula& nd = Nebula::instance();
1262
	string  default_bus;
1263

  
1264
	nd.get_configuration_attribute("PCI_PASSTHROUGH_BUS", default_bus);
1265

  
1253 1266
    for (it = array_pci.begin(); it !=array_pci.end(); ++it)
1254 1267
    {
1255
        if ( check_pci_attributes(*it, error_str) != 0 )
1268
        if ( check_pci_attributes(*it, default_bus, error_str) != 0 )
1256 1269
        {
1257 1270
            return -1;
1258 1271
        }
src/vmm/LibVirtDriverKVM.cc
184 184

  
185 185
    vector<const VectorAttribute *> pci;
186 186

  
187
    string  domain          = "";
187
    string  domain   = "";
188 188
    /* bus is already defined for disks */
189
    string  slot            = "";
190
    string  func            = "";
189
    string  slot     = "";
190
    string  func     = "";
191

  
192
    string vm_domain = "";
193
    string vm_bus    = "";
194
    string vm_slot   = "";
195
    string vm_func   = "";
191 196

  
192 197
    const VectorAttribute * features;
193 198

  
......
1014 1019
        slot    = pci[i]->vector_value("SLOT");
1015 1020
        func    = pci[i]->vector_value("FUNCTION");
1016 1021

  
1022
        vm_domain  = pci[i]->vector_value("VM_DOMAIN");
1023
        vm_bus     = pci[i]->vector_value("VM_BUS");
1024
        vm_slot    = pci[i]->vector_value("VM_SLOT");
1025
        vm_func    = pci[i]->vector_value("VM_FUNCTION");
1026

  
1017 1027
        if ( domain.empty() || bus.empty() || slot.empty() || func.empty() )
1018 1028
        {
1019 1029
            vm->log("VMM", Log::WARNING,
......
1033 1043
             << "/>\n";
1034 1044
        file << "\t\t\t</source>\n";
1035 1045

  
1046
        if ( !vm_domain.empty() && !vm_bus.empty() && !vm_slot.empty() &&
1047
                !vm_func.empty() )
1048
        {
1049
            file << "\t\t\t\t<address type='pci'"
1050
                     << " domain="   << one_util::escape_xml_attr(vm_domain)
1051
                     << " bus="      << one_util::escape_xml_attr(vm_bus)
1052
                     << " slot="     << one_util::escape_xml_attr(vm_slot)
1053
                     << " function=" << one_util::escape_xml_attr(vm_func)
1054
                 << "/>\n";
1055
        }
1056

  
1036 1057
        file << "\t\t</hostdev>" << endl;
1037 1058
    }
1038 1059

  

Also available in: Unified diff