LCOV - code coverage report
Current view: top level - io_uring - notif.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 48 0.0 %
Date: 2023-03-27 20:00:47 Functions: 0 5 0.0 %

          Line data    Source code
       1             : #include <linux/kernel.h>
       2             : #include <linux/errno.h>
       3             : #include <linux/file.h>
       4             : #include <linux/slab.h>
       5             : #include <linux/net.h>
       6             : #include <linux/io_uring.h>
       7             : 
       8             : #include "io_uring.h"
       9             : #include "notif.h"
      10             : #include "rsrc.h"
      11             : 
      12           0 : static void io_notif_complete_tw_ext(struct io_kiocb *notif, bool *locked)
      13             : {
      14           0 :         struct io_notif_data *nd = io_notif_to_data(notif);
      15           0 :         struct io_ring_ctx *ctx = notif->ctx;
      16             : 
      17           0 :         if (nd->zc_report && (nd->zc_copied || !nd->zc_used))
      18           0 :                 notif->cqe.res |= IORING_NOTIF_USAGE_ZC_COPIED;
      19             : 
      20           0 :         if (nd->account_pages && ctx->user) {
      21           0 :                 __io_unaccount_mem(ctx->user, nd->account_pages);
      22           0 :                 nd->account_pages = 0;
      23             :         }
      24           0 :         io_req_task_complete(notif, locked);
      25           0 : }
      26             : 
      27           0 : static void io_tx_ubuf_callback(struct sk_buff *skb, struct ubuf_info *uarg,
      28             :                                 bool success)
      29             : {
      30           0 :         struct io_notif_data *nd = container_of(uarg, struct io_notif_data, uarg);
      31           0 :         struct io_kiocb *notif = cmd_to_io_kiocb(nd);
      32             : 
      33           0 :         if (refcount_dec_and_test(&uarg->refcnt))
      34             :                 io_req_task_work_add(notif);
      35           0 : }
      36             : 
      37           0 : static void io_tx_ubuf_callback_ext(struct sk_buff *skb, struct ubuf_info *uarg,
      38             :                              bool success)
      39             : {
      40           0 :         struct io_notif_data *nd = container_of(uarg, struct io_notif_data, uarg);
      41             : 
      42           0 :         if (nd->zc_report) {
      43           0 :                 if (success && !nd->zc_used && skb)
      44           0 :                         WRITE_ONCE(nd->zc_used, true);
      45           0 :                 else if (!success && !nd->zc_copied)
      46           0 :                         WRITE_ONCE(nd->zc_copied, true);
      47             :         }
      48           0 :         io_tx_ubuf_callback(skb, uarg, success);
      49           0 : }
      50             : 
      51           0 : void io_notif_set_extended(struct io_kiocb *notif)
      52             : {
      53           0 :         struct io_notif_data *nd = io_notif_to_data(notif);
      54             : 
      55           0 :         if (nd->uarg.callback != io_tx_ubuf_callback_ext) {
      56           0 :                 nd->account_pages = 0;
      57           0 :                 nd->zc_report = false;
      58           0 :                 nd->zc_used = false;
      59           0 :                 nd->zc_copied = false;
      60           0 :                 nd->uarg.callback = io_tx_ubuf_callback_ext;
      61           0 :                 notif->io_task_work.func = io_notif_complete_tw_ext;
      62             :         }
      63           0 : }
      64             : 
      65           0 : struct io_kiocb *io_alloc_notif(struct io_ring_ctx *ctx)
      66             :         __must_hold(&ctx->uring_lock)
      67             : {
      68             :         struct io_kiocb *notif;
      69             :         struct io_notif_data *nd;
      70             : 
      71           0 :         if (unlikely(!io_alloc_req(ctx, &notif)))
      72             :                 return NULL;
      73           0 :         notif->opcode = IORING_OP_NOP;
      74           0 :         notif->flags = 0;
      75           0 :         notif->file = NULL;
      76           0 :         notif->task = current;
      77           0 :         io_get_task_refs(1);
      78           0 :         notif->rsrc_node = NULL;
      79           0 :         notif->io_task_work.func = io_req_task_complete;
      80             : 
      81           0 :         nd = io_notif_to_data(notif);
      82           0 :         nd->uarg.flags = SKBFL_ZEROCOPY_FRAG | SKBFL_DONT_ORPHAN;
      83           0 :         nd->uarg.callback = io_tx_ubuf_callback;
      84           0 :         refcount_set(&nd->uarg.refcnt, 1);
      85           0 :         return notif;
      86             : }

Generated by: LCOV version 1.14