From: Timmons C. Player <[email protected]>
Committer: Nadav Har'El <[email protected]>
Branch: master
drivers: fix maxnic argument usage
Change 6ac2b4fc3c287305e6d9716b08834f5ada19ce03 added a maxnic option
to the loader that limits the number of NICs used by OSv so that
user space apps may use the remainder. However, the updated driver probe
code neglected to consider whether the driver was actually used before
decrementing the maxnic count. This resulted in NICs possibly being
unusable when this options is set.
This change only decrements the maxnic counter when the drivers matches
the device.
Signed-off-by: Timmons C. Player <[email protected]>
Message-Id: <[email protected]>
---
diff --git a/drivers/virtio-net.cc b/drivers/virtio-net.cc
--- a/drivers/virtio-net.cc
+++ b/drivers/virtio-net.cc
@@ -856,11 +856,17 @@ u32 net::get_driver_features()
hw_driver* net::probe(hw_device* dev)
{
- if (opt_maxnic) {
- if (maxnic-- <= 0)
- return nullptr;
+ if (auto pci_dev = dynamic_cast<pci::device*>(dev)) {
+ if (pci_dev->get_id() == hw_device_id(VIRTIO_VENDOR_ID,
VIRTIO_NET_DEVICE_ID)) {
+ if (opt_maxnic && maxnic-- <= 0) {
+ return nullptr;
+ } else {
+ return new net(*pci_dev);
+ }
+ }
}
- return virtio::probe<net, VIRTIO_NET_DEVICE_ID>(dev);
+
+ return nullptr;
}
} // namespace virtio
diff --git a/drivers/vmxnet3.cc b/drivers/vmxnet3.cc
--- a/drivers/vmxnet3.cc
+++ b/drivers/vmxnet3.cc
@@ -420,16 +420,16 @@ void vmxnet3::fill_driver_shared()
hw_driver* vmxnet3::probe(hw_device* dev)
{
- if (opt_maxnic) {
- if (maxnic-- <= 0)
- return nullptr;
- }
try {
if (auto pci_dev = dynamic_cast<pci::device*>(dev)) {
pci_dev->dump_config();
if (pci_dev->get_id() ==
hw_device_id(pciconf::vendor_id, pciconf::device_id)) {
- return new vmxnet3(*pci_dev);
+ if (opt_maxnic && maxnic-- <= 0) {
+ return nullptr;
+ } else {
+ return new vmxnet3(*pci_dev);
+ }
}
}
} catch (std::exception& e) {
--
You received this message because you are subscribed to the Google Groups "OSv
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.