[v2,04/10] kni: add rte_kni_free to KNI library
Checks
Commit Message
Add the new rte_kni_free() API function to the KNI library.
This function will be called by DPDK applications after
rte_kni_release() to free the KNI interface resources from the
kernel driver.
Signed-off-by: Dan Gora <dg@adax.com>
---
lib/librte_kni/rte_kni.c | 32 +++++++++++++++++++++++++++++---
lib/librte_kni/rte_kni.h | 31 +++++++++++++++++++++++++++----
2 files changed, 56 insertions(+), 7 deletions(-)
@@ -463,8 +463,6 @@ int
rte_kni_release(struct rte_kni *kni)
{
struct rte_kni_device_info dev_info;
- uint32_t slot_id;
- uint32_t retry = 5;
if (!kni || !kni->in_use)
return -1;
@@ -475,6 +473,34 @@ rte_kni_release(struct rte_kni *kni)
return -1;
}
+ kni->in_use = 0;
+ return 0;
+}
+
+int
+rte_kni_free(struct rte_kni *kni)
+{
+ uint32_t slot_id;
+ uint32_t retry = 5;
+ struct rte_kni_device_info dev_info;
+
+ if (!kni)
+ return -EINVAL;
+
+ /* Must call rte_kni_release() first */
+ if (kni->in_use)
+ return -EBUSY;
+
+ /*
+ * Free the FIFOs in the kernel and remove it from the list
+ * of devices to poll
+ */
+ snprintf(dev_info.name, sizeof(dev_info.name), "%s", kni->name);
+ if (ioctl(kni_fd, RTE_KNI_IOCTL_FREE, &dev_info) < 0) {
+ RTE_LOG(ERR, KNI, "Fail to release kni device\n");
+ return -1;
+ }
+
/* mbufs in all fifo should be released, except request/response */
/* wait until all rxq packets processed by kernel */
@@ -497,7 +523,7 @@ rte_kni_release(struct rte_kni *kni)
if (slot_id > kni_memzone_pool.max_ifaces) {
RTE_LOG(ERR, KNI, "KNI pool: corrupted slot ID: %d, max: %d\n",
slot_id, kni_memzone_pool.max_ifaces);
- return -1;
+ return -EINVAL;
}
kni_memzone_pool_release(&kni_memzone_pool.slots[slot_id]);
@@ -112,11 +112,17 @@ struct rte_kni *rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
const struct rte_kni_conf *conf, struct rte_kni_ops *ops);
/**
- * Release KNI interface according to the context. It will also release the
- * paired KNI interface in kernel space. All processing on the specific KNI
- * context need to be stopped before calling this interface.
+ * Release specified KNI interface. This will stop data transfer to and from
+ * this interface and will remove the paired KNI interface in kernel space.
*
- * rte_kni_release is thread safe.
+ * @note This function will trigger the kernel to remove the interface, which
+ * may trigger the RTE_KNI_REQ_CFG_NETWORK_IF KNI callback. This function will
+ * block until this callback is handled or times out. The user should ensure
+ * that rte_kni_handle_request() is called for this interface in a separate
+ * thread to handle this callback to avoid this delay.
+ *
+ * rte_kni_release() is thread safe, but should not be called from the same
+ * thread as rte_kni_handle_request().
*
* @param kni
* The pointer to the context of an existent KNI interface.
@@ -127,6 +133,23 @@ struct rte_kni *rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
*/
int rte_kni_release(struct rte_kni *kni);
+/**
+ * Free specified KNI interface. It will also free the KNI interface resources
+ * in kernel space. No KNI functions for this interface should be called after
+ * or at the same time as calling this function. rte_kni_release() must be
+ * called before this function to release the kernel interface.
+ *
+ * @param kni
+ * The pointer to the context of an existent KNI interface.
+ *
+ * @return
+ * - 0 indicates success.
+ * - -EINVAL: Invalid kni structure.
+ * - -EBUSY: KNI interface still in use. Must call rte_kni_release().
+ */
+int __rte_experimental
+rte_kni_free(struct rte_kni *kni);
+
/**
* It is used to handle the request mbufs sent from kernel space.
* Then analyzes it and calls the specific actions for the specific requests.