{"$schema": "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json",
 "version": "2.1.0",
 "runs": [{"tool": {"driver": {"name": "GNU C23",
                               "fullName": "GNU C23 (GCC) version 16.1.1 20260703 (Red Hat 16.1.1-4) (x86_64-redhat-linux)",
                               "version": "16.1.1 20260703 (Red Hat 16.1.1-4)",
                               "informationUri": "https://gcc.gnu.org/gcc-16/",
                               "rules": [{"id": "-Wanalyzer-va-list-leak",
                                          "helpUri": "https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Static-Analyzer-Options.html#index-Wanalyzer-va-list-leak"},
                                         {"id": "-Wanalyzer-possible-null-dereference",
                                          "helpUri": "https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Static-Analyzer-Options.html#index-Wanalyzer-possible-null-dereference"}]}},
           "taxonomies": [{"name": "CWE",
                           "version": "4.7",
                           "organization": "MITRE",
                           "shortDescription": {"text": "The MITRE Common Weakness Enumeration"},
                           "taxa": [{"id": "690",
                                     "helpUri": "https://cwe.mitre.org/data/definitions/690.html"}]}],
           "invocations": [{"arguments": ["/usr/libexec/gcc/x86_64-redhat-linux/16/cc1",
                                          "-quiet",
                                          "-I",
                                          "../src/include/",
                                          "-D",
                                          "_GNU_SOURCE",
                                          "-D",
                                          "__SANE_USERSPACE_TYPES__",
                                          "-D",
                                          "_LARGEFILE_SOURCE",
                                          "-D",
                                          "_FILE_OFFSET_BITS=64",
                                          "-D",
                                          "LIBURING_BUILD_TEST",
                                          "-include",
                                          "../config-host.h",
                                          "uring_cmd_ublk.c",
                                          "-quiet",
                                          "-dumpbase",
                                          "uring_cmd_ublk.c",
                                          "-dumpbase-ext",
                                          ".c",
                                          "-m64",
                                          "-mtune=generic",
                                          "-march=x86-64",
                                          "-mtls-dialect=gnu2",
                                          "-O2",
                                          "-Wno-unused-parameter",
                                          "-Wno-sign-compare",
                                          "-Wno-unknown-pragmas",
                                          "-flto=auto",
                                          "-ffat-lto-objects",
                                          "-fexceptions",
                                          "-fstack-protector-strong",
                                          "-fasynchronous-unwind-tables",
                                          "-fstack-clash-protection",
                                          "-fcf-protection=full",
                                          "-fno-omit-frame-pointer",
                                          "-fanalyzer",
                                          "-fdiagnostics-path-format=separate-events",
                                          "-fno-diagnostics-show-caret",
                                          "-fno-lto",
                                          "-fanalyzer-assume-nothrow",
                                          "-fdiagnostics-text-art-charset=none",
                                          "-fdiagnostics-set-output=sarif:file=/builddir/gcc-results/5743-zbbm.sarif",
                                          "-o",
                                          "/tmp/ccSuGuYq.s"],
                            "workingDirectory": {"uri": "/builddir/build/BUILD/liburing-2.13-build/liburing-2.13/test"},
                            "startTimeUtc": "2026-08-03T18:02:06Z",
                            "executionSuccessful": true,
                            "toolExecutionNotifications": [],
                            "endTimeUtc": "2026-08-03T18:02:14Z"}],
           "originalUriBaseIds": {"PWD": {"uri": "file:///builddir/build/BUILD/liburing-2.13-build/liburing-2.13/test/"}},
           "artifacts": [{"location": {"uri": "uring_cmd_ublk.c",
                                       "uriBaseId": "PWD"},
                          "sourceLanguage": "c",
                          "contents": {"text": "/* SPDX-License-Identifier: MIT */\n/*\n * Description: uring_cmd based ublk\n *\n * Covers cancellable uring_cmd feature.\n */\n#include <unistd.h>\n#include <stdlib.h>\n#include <assert.h>\n#include <stdio.h>\n#include <stdarg.h>\n#include <string.h>\n#include <pthread.h>\n#include <limits.h>\n#include <poll.h>\n#include <sys/syscall.h>\n#include <sys/mman.h>\n#include <sys/ioctl.h>\n#include <sys/inotify.h>\n#include <sys/wait.h>\n\n#include \"liburing.h\"\n#include \"helpers.h\"\n#ifdef CONFIG_HAVE_UBLK_HEADER\n#include <linux/ublk_cmd.h>\n\n/****************** part 1: libublk ********************/\n\n#define CTRL_DEV\t\t\"/dev/ublk-control\"\n#define UBLKC_DEV\t\t\"/dev/ublkc\"\n#define UBLKB_DEV\t\t\"/dev/ublkb\"\n#define UBLK_CTRL_RING_DEPTH            32\n\n/* queue idle timeout */\n#define UBLKSRV_IO_IDLE_SECS\t\t20\n\n#define UBLK_IO_MAX_BYTES               65536\n#define UBLK_MAX_QUEUES                 4\n#define UBLK_QUEUE_DEPTH                128\n\n#define UBLK_DBG_DEV            (1U << 0)\n#define UBLK_DBG_QUEUE          (1U << 1)\n#define UBLK_DBG_IO_CMD         (1U << 2)\n#define UBLK_DBG_IO             (1U << 3)\n#define UBLK_DBG_CTRL_CMD       (1U << 4)\n#define UBLK_LOG                (1U << 5)\n\nstruct ublk_dev;\nstruct ublk_queue;\n\nstruct ublk_ctrl_cmd_data {\n\t__u32 cmd_op;\n#define CTRL_CMD_HAS_DATA\t1\n#define CTRL_CMD_HAS_BUF\t2\n\t__u32 flags;\n\n\t__u64 data[2];\n\t__u64 addr;\n\t__u32 len;\n};\n\nstruct ublk_io {\n\tchar *buf_addr;\n\n#define UBLKSRV_NEED_FETCH_RQ\t\t(1UL << 0)\n#define UBLKSRV_NEED_COMMIT_RQ_COMP\t(1UL << 1)\n#define UBLKSRV_IO_FREE\t\t\t(1UL << 2)\n\tunsigned int flags;\n\n\tunsigned int result;\n};\n\nstruct ublk_tgt_ops {\n\tconst char *name;\n\tint (*init_tgt)(struct ublk_dev *);\n\tvoid (*deinit_tgt)(struct ublk_dev *);\n\n\tint (*queue_io)(struct ublk_queue *, int tag);\n\tvoid (*tgt_io_done)(struct ublk_queue *,\n\t\t\tint tag, const struct io_uring_cqe *);\n};\n\nstruct ublk_tgt {\n\tunsigned long dev_size;\n\tconst struct ublk_tgt_ops *ops;\n\tstruct ublk_params params;\n};\n\nstruct ublk_queue {\n\tint q_id;\n\tint q_depth;\n\tunsigned int cmd_inflight;\n\tunsigned int io_inflight;\n\tstruct ublk_dev *dev;\n\tconst struct ublk_tgt_ops *tgt_ops;\n\tchar *io_cmd_buf;\n\tstruct io_uring ring;\n\tstruct ublk_io ios[UBLK_QUEUE_DEPTH];\n#define UBLKSRV_QUEUE_STOPPING\t(1U << 0)\n#define UBLKSRV_QUEUE_IDLE\t(1U << 1)\n\tunsigned state;\n\tpid_t tid;\n\tpthread_t thread;\n};\n\nstruct ublk_dev {\n\tstruct ublk_tgt tgt;\n\tstruct ublksrv_ctrl_dev_info  dev_info;\n\tstruct ublk_queue q[UBLK_MAX_QUEUES];\n\n\tint fds[2];\t/* fds[0] points to /dev/ublkcN */\n\tint nr_fds;\n\tint ctrl_fd;\n\tstruct io_uring ring;\n};\n\n#ifndef offsetof\n#define offsetof(TYPE, MEMBER)  ((size_t)&((TYPE *)0)->MEMBER)\n#endif\n\n#ifndef container_of\n#define container_of(ptr, type, member) ({                              \\\n\tunsigned long __mptr = (unsigned long)(ptr);                    \\\n\t((type *)(__mptr - offsetof(type, member))); })\n#endif\n\n#define round_up(val, rnd) \\\n\t(((val) + ((rnd) - 1)) & ~((rnd) - 1))\n\nstatic unsigned int ublk_dbg_mask = 0;\n\nstatic const struct ublk_tgt_ops *ublk_find_tgt(const char *name);\n\nstatic inline int is_target_io(__u64 user_data)\n{\n\treturn (user_data & (1ULL << 63)) != 0;\n}\n\nstatic inline __u64 build_user_data(unsigned tag, unsigned op,\n\t\tunsigned tgt_data, unsigned is_target_io)\n{\n\tassert(!(tag >> 16) && !(op >> 8) && !(tgt_data >> 16));\n\n\treturn tag | (op << 16) | (tgt_data << 24) | (__u64)is_target_io << 63;\n}\n\nstatic inline unsigned int user_data_to_tag(__u64 user_data)\n{\n\treturn user_data & 0xffff;\n}\n\nstatic inline unsigned int user_data_to_op(__u64 user_data)\n{\n\treturn (user_data >> 16) & 0xff;\n}\n\nstatic void ublk_err(const char *fmt, ...)\n{\n\tva_list ap;\n\n\tva_start(ap, fmt);\n\tvfprintf(stderr, fmt, ap);\n}\n\nstatic void ublk_dbg(int level, const char *fmt, ...)\n{\n\tif (level & ublk_dbg_mask) {\n\t\tva_list ap;\n\t\tva_start(ap, fmt);\n\t\tvfprintf(stdout, fmt, ap);\n        }\n}\n\nstatic inline void *ublk_get_sqe_cmd(const struct io_uring_sqe *sqe)\n{\n\treturn (void *)&sqe->cmd;\n}\n\nstatic inline void ublk_mark_io_done(struct ublk_io *io, int res)\n{\n\tio->flags |= (UBLKSRV_NEED_COMMIT_RQ_COMP | UBLKSRV_IO_FREE);\n\tio->result = res;\n}\n\nstatic inline const struct ublksrv_io_desc *ublk_get_iod(\n                const struct ublk_queue *q, int tag)\n{\n        return (struct ublksrv_io_desc *)\n                &(q->io_cmd_buf[tag * sizeof(struct ublksrv_io_desc)]);\n}\n\nstatic inline void ublk_set_sqe_cmd_op(struct io_uring_sqe *sqe,\n\t\t__u32 cmd_op)\n{\n        __u32 *addr = (__u32 *)&sqe->off;\n\n        addr[0] = cmd_op;\n        addr[1] = 0;\n}\n\nstatic inline int ublk_setup_ring(struct io_uring *r, int depth,\n\t\tint cq_depth, unsigned flags)\n{\n\tstruct io_uring_params p;\n\n\tmemset(&p, 0, sizeof(p));\n\tp.flags = flags | IORING_SETUP_CQSIZE;\n\tp.cq_entries = cq_depth;\n\n\treturn io_uring_queue_init_params(depth, r, &p);\n}\n\nstatic void ublk_ctrl_init_cmd(struct ublk_dev *dev,\n\t\tstruct io_uring_sqe *sqe,\n\t\tstruct ublk_ctrl_cmd_data *data)\n{\n\tstruct ublksrv_ctrl_dev_info *info = &dev->dev_info;\n\tstruct ublksrv_ctrl_cmd *cmd = (struct ublksrv_ctrl_cmd *)ublk_get_sqe_cmd(sqe);\n\n\tsqe->fd = dev->ctrl_fd;\n\tsqe->opcode = IORING_OP_URING_CMD;\n\tsqe->ioprio = 0;\n\n\tif (data->flags & CTRL_CMD_HAS_BUF) {\n\t\tcmd->addr = data->addr;\n\t\tcmd->len = data->len;\n\t}\n\n\tif (data->flags & CTRL_CMD_HAS_DATA)\n\t\tcmd->data[0] = data->data[0];\n\n\tcmd->dev_id = info->dev_id;\n\tcmd->queue_id = -1;\n\n\tublk_set_sqe_cmd_op(sqe, data->cmd_op);\n\n\tio_uring_sqe_set_data(sqe, cmd);\n}\n\nstatic int __ublk_ctrl_cmd(struct ublk_dev *dev,\n\t\tstruct ublk_ctrl_cmd_data *data)\n{\n\tstruct io_uring_sqe *sqe;\n\tstruct io_uring_cqe *cqe;\n\tint ret = -EINVAL;\n\n\tsqe = io_uring_get_sqe(&dev->ring);\n\tif (!sqe) {\n\t\tublk_err(\"%s: can't get sqe ret %d\\n\", __func__, ret);\n\t\treturn ret;\n\t}\n\n\tublk_ctrl_init_cmd(dev, sqe, data);\n\n\tret = io_uring_submit(&dev->ring);\n\tif (ret < 0) {\n\t\tublk_err(\"uring submit ret %d\\n\", ret);\n\t\treturn ret;\n\t}\n\n\tret = io_uring_wait_cqe(&dev->ring, &cqe);\n\tif (ret < 0) {\n\t\tublk_err(\"wait cqe: %s\\n\", strerror(-ret));\n\t\treturn ret;\n\t}\n\tio_uring_cqe_seen(&dev->ring, cqe);\n\n\treturn cqe->res;\n}\n\nstatic int ublk_ctrl_start_dev(struct ublk_dev *dev,\n\t\tint daemon_pid)\n{\n\tstruct ublk_ctrl_cmd_data data = {\n\t\t.cmd_op\t= UBLK_U_CMD_START_DEV,\n\t\t.flags\t= CTRL_CMD_HAS_DATA,\n\t};\n\n\tdev->dev_info.ublksrv_pid = data.data[0] = daemon_pid;\n\n\treturn __ublk_ctrl_cmd(dev, &data);\n}\n\nstatic int ublk_ctrl_add_dev(struct ublk_dev *dev)\n{\n\tstruct ublk_ctrl_cmd_data data = {\n\t\t.cmd_op\t= UBLK_U_CMD_ADD_DEV,\n\t\t.flags\t= CTRL_CMD_HAS_BUF,\n\t\t.addr = (__u64) (uintptr_t) &dev->dev_info,\n\t\t.len = sizeof(struct ublksrv_ctrl_dev_info),\n\t};\n\n\treturn __ublk_ctrl_cmd(dev, &data);\n}\n\nstatic int ublk_ctrl_del_dev(struct ublk_dev *dev)\n{\n\tstruct ublk_ctrl_cmd_data data = {\n\t\t.cmd_op = UBLK_U_CMD_DEL_DEV,\n\t\t.flags = 0,\n\t};\n\n\treturn __ublk_ctrl_cmd(dev, &data);\n}\n\nstatic int ublk_ctrl_get_info(struct ublk_dev *dev)\n{\n\tstruct ublk_ctrl_cmd_data data = {\n\t\t.cmd_op\t= UBLK_U_CMD_GET_DEV_INFO,\n\t\t.flags\t= CTRL_CMD_HAS_BUF,\n\t\t.addr = (__u64) (uintptr_t) &dev->dev_info,\n\t\t.len = sizeof(struct ublksrv_ctrl_dev_info),\n\t};\n\n\treturn __ublk_ctrl_cmd(dev, &data);\n}\n\nstatic int ublk_ctrl_set_params(struct ublk_dev *dev,\n\t\tstruct ublk_params *params)\n{\n\tstruct ublk_ctrl_cmd_data data = {\n\t\t.cmd_op\t= UBLK_U_CMD_SET_PARAMS,\n\t\t.flags\t= CTRL_CMD_HAS_BUF,\n\t\t.addr = (__u64) (uintptr_t) params,\n\t\t.len = sizeof(*params),\n\t};\n\tparams->len = sizeof(*params);\n\treturn __ublk_ctrl_cmd(dev, &data);\n}\n\nstatic int ublk_ctrl_get_features(struct ublk_dev *dev,\n\t\t__u64 *features)\n{\n\tstruct ublk_ctrl_cmd_data data = {\n\t\t.cmd_op\t= UBLK_U_CMD_GET_FEATURES,\n\t\t.flags\t= CTRL_CMD_HAS_BUF,\n\t\t.addr = (__u64) (uintptr_t) features,\n\t\t.len = sizeof(*features),\n\t};\n\n\treturn __ublk_ctrl_cmd(dev, &data);\n}\n\nstatic void ublk_ctrl_deinit(struct ublk_dev *dev)\n{\n\tclose(dev->ctrl_fd);\n\tfree(dev);\n}\n\nstatic struct ublk_dev *ublk_ctrl_init(void)\n{\n\tstruct ublk_dev *dev = (struct ublk_dev *)calloc(1, sizeof(*dev));\n\tstruct ublksrv_ctrl_dev_info *info = &dev->dev_info;\n\tint ret;\n\n\tdev->ctrl_fd = open(CTRL_DEV, O_RDWR);\n\tif (dev->ctrl_fd < 0) {\n\t\tfree(dev);\n\t\treturn NULL;\n\t}\n\n\tinfo->max_io_buf_bytes = UBLK_IO_MAX_BYTES;\n\n\tret = ublk_setup_ring(&dev->ring, UBLK_CTRL_RING_DEPTH,\n\t\t\tUBLK_CTRL_RING_DEPTH, IORING_SETUP_SQE128);\n\tif (ret < 0) {\n\t\tublk_err(\"queue_init: %s\\n\", strerror(-ret));\n\t\tfree(dev);\n\t\treturn NULL;\n\t}\n\tdev->nr_fds = 1;\n\n\treturn dev;\n}\n\nstatic int ublk_queue_cmd_buf_sz(struct ublk_queue *q)\n{\n\tint size =  q->q_depth * sizeof(struct ublksrv_io_desc);\n\tunsigned int page_sz = getpagesize();\n\n\treturn round_up(size, page_sz);\n}\n\nstatic void ublk_queue_deinit(struct ublk_queue *q)\n{\n\tint i;\n\tint nr_ios = q->q_depth;\n\n\tio_uring_unregister_ring_fd(&q->ring);\n\n\tif (q->ring.ring_fd > 0) {\n\t\tio_uring_unregister_files(&q->ring);\n\t\tclose(q->ring.ring_fd);\n\t\tq->ring.ring_fd = -1;\n\t}\n\n\tif (q->io_cmd_buf)\n\t\tmunmap(q->io_cmd_buf, ublk_queue_cmd_buf_sz(q));\n\n\tfor (i = 0; i < nr_ios; i++)\n\t\tfree(q->ios[i].buf_addr);\n}\n\nstatic int ublk_queue_init(struct ublk_queue *q)\n{\n\tstruct ublk_dev *dev = q->dev;\n\tint depth = dev->dev_info.queue_depth;\n\tint i, ret = -1;\n\tint cmd_buf_size, io_buf_size;\n\tunsigned long off;\n\tint ring_depth = depth, cq_depth = depth;\n\n\tq->tgt_ops = dev->tgt.ops;\n\tq->state = 0;\n\tq->q_depth = depth;\n\tq->cmd_inflight = 0;\n\tq->tid = gettid();\n\n\tcmd_buf_size = ublk_queue_cmd_buf_sz(q);\n\toff = UBLKSRV_CMD_BUF_OFFSET +\n\t\tq->q_id * (UBLK_MAX_QUEUE_DEPTH * sizeof(struct ublksrv_io_desc));\n\tq->io_cmd_buf = (char *)mmap(0, cmd_buf_size, PROT_READ,\n\t\t\tMAP_SHARED | MAP_POPULATE, dev->fds[0], off);\n\tif (q->io_cmd_buf == MAP_FAILED) {\n\t\tublk_err(\"ublk dev %d queue %d map io_cmd_buf failed %m\\n\",\n\t\t\t\tq->dev->dev_info.dev_id, q->q_id);\n\t\tgoto fail;\n\t}\n\n\tio_buf_size = dev->dev_info.max_io_buf_bytes;\n\tfor (i = 0; i < q->q_depth; i++) {\n\t\tq->ios[i].buf_addr = NULL;\n\n\t\tif (posix_memalign((void **)&q->ios[i].buf_addr,\n\t\t\t\t\tgetpagesize(), io_buf_size)) {\n\t\t\tublk_err(\"ublk dev %d queue %d io %d posix_memalign failed %m\\n\",\n\t\t\t\t\tdev->dev_info.dev_id, q->q_id, i);\n\t\t\tgoto fail;\n\t\t}\n\t\tq->ios[i].flags = UBLKSRV_NEED_FETCH_RQ | UBLKSRV_IO_FREE;\n\t}\n\n\tret = ublk_setup_ring(&q->ring, ring_depth, cq_depth,\n\t\t\tIORING_SETUP_COOP_TASKRUN);\n\tif (ret < 0) {\n\t\tublk_err(\"ublk dev %d queue %d setup io_uring failed %d\\n\",\n\t\t\t\tq->dev->dev_info.dev_id, q->q_id, ret);\n\t\tgoto fail;\n\t}\n\n\tio_uring_register_ring_fd(&q->ring);\n\n\tret = io_uring_register_files(&q->ring, dev->fds, dev->nr_fds);\n\tif (ret) {\n\t\tublk_err(\"ublk dev %d queue %d register files failed %d\\n\",\n\t\t\t\tq->dev->dev_info.dev_id, q->q_id, ret);\n\t\tgoto fail;\n\t}\n\n\treturn 0;\n fail:\n\tublk_queue_deinit(q);\n\tublk_err(\"ublk dev %d queue %d failed\\n\",\n\t\t\tdev->dev_info.dev_id, q->q_id);\n\treturn -ENOMEM;\n}\n\nstatic int ublk_dev_prep(struct ublk_dev *dev)\n{\n\tint dev_id = dev->dev_info.dev_id;\n\tchar buf[64];\n\tint ret = 0;\n\n\tsnprintf(buf, 64, \"%s%d\", UBLKC_DEV, dev_id);\n\tdev->fds[0] = open(buf, O_RDWR);\n\tif (dev->fds[0] < 0) {\n\t\tret = -EBADF;\n\t\tublk_err(\"can't open %s, ret %d\\n\", buf, dev->fds[0]);\n\t\tgoto fail;\n\t}\n\n\tif (dev->tgt.ops->init_tgt)\n\t\tret = dev->tgt.ops->init_tgt(dev);\n\n\treturn ret;\nfail:\n\tclose(dev->fds[0]);\n\treturn ret;\n}\n\nstatic void ublk_dev_unprep(struct ublk_dev *dev)\n{\n\tif (dev->tgt.ops->deinit_tgt)\n\t\tdev->tgt.ops->deinit_tgt(dev);\n\tclose(dev->fds[0]);\n}\n\nstatic int ublk_queue_io_cmd(struct ublk_queue *q,\n\t\tstruct ublk_io *io, unsigned tag)\n{\n\tstruct ublksrv_io_cmd *cmd;\n\tstruct io_uring_sqe *sqe;\n\tunsigned int cmd_op = 0;\n\t__u64 user_data;\n\n\t/* only freed io can be issued */\n\tif (!(io->flags & UBLKSRV_IO_FREE))\n\t\treturn 0;\n\n\t/* we issue because we need either fetching or committing */\n\tif (!(io->flags &\n\t\t(UBLKSRV_NEED_FETCH_RQ | UBLKSRV_NEED_COMMIT_RQ_COMP)))\n\t\treturn 0;\n\n\tif (io->flags & UBLKSRV_NEED_COMMIT_RQ_COMP)\n\t\tcmd_op = UBLK_U_IO_COMMIT_AND_FETCH_REQ;\n\telse if (io->flags & UBLKSRV_NEED_FETCH_RQ)\n\t\tcmd_op = UBLK_U_IO_FETCH_REQ;\n\n\tsqe = io_uring_get_sqe(&q->ring);\n\tif (!sqe) {\n\t\tublk_err(\"%s: run out of sqe %d, tag %d\\n\",\n\t\t\t\t__func__, q->q_id, tag);\n\t\treturn -1;\n\t}\n\n\tcmd = (struct ublksrv_io_cmd *)ublk_get_sqe_cmd(sqe);\n\n\tif (cmd_op == UBLK_U_IO_COMMIT_AND_FETCH_REQ)\n\t\tcmd->result = io->result;\n\n\t/* These fields should be written once, never change */\n\tublk_set_sqe_cmd_op(sqe, cmd_op);\n\tsqe->fd\t\t= 0;\t/* dev->fds[0] */\n\tsqe->opcode\t= IORING_OP_URING_CMD;\n\tsqe->flags\t= IOSQE_FIXED_FILE;\n\tsqe->rw_flags\t= 0;\n\tcmd->tag\t= tag;\n\tcmd->addr\t= (__u64) (uintptr_t) io->buf_addr;\n\tcmd->q_id\t= q->q_id;\n\n\tuser_data = build_user_data(tag, _IOC_NR(cmd_op), 0, 0);\n\tio_uring_sqe_set_data64(sqe, user_data);\n\n\tio->flags = 0;\n\n\tq->cmd_inflight += 1;\n\n\tublk_dbg(UBLK_DBG_IO_CMD, \"%s: (qid %d tag %u cmd_op %u) iof %x stopping %d\\n\",\n\t\t\t__func__, q->q_id, tag, cmd_op,\n\t\t\tio->flags, !!(q->state & UBLKSRV_QUEUE_STOPPING));\n\treturn 1;\n}\n\nstatic int ublk_complete_io(struct ublk_queue *q,\n\t\tunsigned tag, int res)\n{\n\tstruct ublk_io *io = &q->ios[tag];\n\n\tublk_mark_io_done(io, res);\n\n\treturn ublk_queue_io_cmd(q, io, tag);\n}\n\nstatic void ublk_submit_fetch_commands(struct ublk_queue *q)\n{\n\tint i = 0;\n\n\tfor (i = 0; i < q->q_depth; i++)\n\t\tublk_queue_io_cmd(q, &q->ios[i], i);\n}\n\nstatic int ublk_queue_is_idle(struct ublk_queue *q)\n{\n\treturn !io_uring_sq_ready(&q->ring) && !q->io_inflight;\n}\n\nstatic int ublk_queue_is_done(struct ublk_queue *q)\n{\n\treturn (q->state & UBLKSRV_QUEUE_STOPPING) && ublk_queue_is_idle(q);\n}\n\nstatic inline void ublksrv_handle_tgt_cqe(struct ublk_queue *q,\n\t\tstruct io_uring_cqe *cqe)\n{\n\tunsigned tag = user_data_to_tag(cqe->user_data);\n\n\tif (cqe->res < 0 && cqe->res != -EAGAIN)\n\t\tublk_err(\"%s: failed tgt io: res %d qid %u tag %u, cmd_op %u\\n\",\n\t\t\t__func__, cqe->res, q->q_id,\n\t\t\tuser_data_to_tag(cqe->user_data),\n\t\t\tuser_data_to_op(cqe->user_data));\n\n\tif (q->tgt_ops->tgt_io_done)\n\t\tq->tgt_ops->tgt_io_done(q, tag, cqe);\n}\n\nstatic void ublk_handle_cqe(struct io_uring *r,\n\t\tstruct io_uring_cqe *cqe, void *data)\n{\n\tstruct ublk_queue *q = container_of(r, struct ublk_queue, ring);\n\tunsigned tag = user_data_to_tag(cqe->user_data);\n\tunsigned cmd_op = user_data_to_op(cqe->user_data);\n\tint fetch = (cqe->res != UBLK_IO_RES_ABORT) &&\n\t\t!(q->state & UBLKSRV_QUEUE_STOPPING);\n\tstruct ublk_io *io;\n\n\tublk_dbg(UBLK_DBG_IO_CMD, \"%s: res %d (qid %d tag %u cmd_op %u target %d) stopping %d\\n\",\n\t\t\t__func__, cqe->res, q->q_id, tag, cmd_op,\n\t\t\tis_target_io(cqe->user_data),\n\t\t\t(q->state & UBLKSRV_QUEUE_STOPPING));\n\n\t/* Don't retrieve io in case of target io */\n\tif (is_target_io(cqe->user_data)) {\n\t\tublksrv_handle_tgt_cqe(q, cqe);\n\t\treturn;\n\t}\n\n\tio = &q->ios[tag];\n\tq->cmd_inflight--;\n\n\tif (!fetch) {\n\t\tq->state |= UBLKSRV_QUEUE_STOPPING;\n\t\tio->flags &= ~UBLKSRV_NEED_FETCH_RQ;\n\t}\n\n\tif (cqe->res == UBLK_IO_RES_OK) {\n\t\tassert(tag < q->q_depth);\n\t\tq->tgt_ops->queue_io(q, tag);\n\t} else {\n\t\t/*\n\t\t * COMMIT_REQ will be completed immediately since no fetching\n\t\t * piggyback is required.\n\t\t *\n\t\t * Marking IO_FREE only, then this io won't be issued since\n\t\t * we only issue io with (UBLKSRV_IO_FREE | UBLKSRV_NEED_*)\n\t\t *\n\t\t * */\n\t\tio->flags = UBLKSRV_IO_FREE;\n\t}\n}\n\nstatic int ublk_reap_events_uring(struct io_uring *r)\n{\n\tstruct io_uring_cqe *cqe;\n\tunsigned head;\n\tint count = 0;\n\n\tio_uring_for_each_cqe(r, head, cqe) {\n\t\tublk_handle_cqe(r, cqe, NULL);\n\t\tcount += 1;\n\t}\n\tio_uring_cq_advance(r, count);\n\n\treturn count;\n}\n\nstatic int ublk_process_io(struct ublk_queue *q)\n{\n\tint ret, reapped;\n\n\tublk_dbg(UBLK_DBG_QUEUE, \"dev%d-q%d: to_submit %d inflight cmd %u stopping %d\\n\",\n\t\t\t\tq->dev->dev_info.dev_id,\n\t\t\t\tq->q_id, io_uring_sq_ready(&q->ring),\n\t\t\t\tq->cmd_inflight,\n\t\t\t\t(q->state & UBLKSRV_QUEUE_STOPPING));\n\n\tif (ublk_queue_is_done(q))\n\t\treturn -ENODEV;\n\n\tret = io_uring_submit_and_wait(&q->ring, 1);\n\treapped = ublk_reap_events_uring(&q->ring);\n\n\tublk_dbg(UBLK_DBG_QUEUE, \"submit result %d, reapped %d stop %d idle %d\\n\",\n\t\t\tret, reapped, (q->state & UBLKSRV_QUEUE_STOPPING),\n\t\t\t(q->state & UBLKSRV_QUEUE_IDLE));\n\n\treturn reapped;\n}\n\nstatic void *ublk_io_handler_fn(void *data)\n{\n\tstruct ublk_queue *q = data;\n\tint dev_id = q->dev->dev_info.dev_id;\n\tint ret;\n\n\tret = ublk_queue_init(q);\n\tif (ret) {\n\t\tublk_err(\"ublk dev %d queue %d init queue failed\\n\",\n\t\t\t\tdev_id, q->q_id);\n\t\treturn NULL;\n\t}\n\tublk_dbg(UBLK_DBG_QUEUE, \"tid %d: ublk dev %d queue %d started\\n\",\n\t\t\tq->tid, dev_id, q->q_id);\n\n\t/* submit all io commands to ublk driver */\n\tublk_submit_fetch_commands(q);\n\tdo {\n\t\tif (ublk_process_io(q) < 0)\n\t\t\tbreak;\n\t} while (1);\n\n\tublk_dbg(UBLK_DBG_QUEUE, \"ublk dev %d queue %d exited\\n\", dev_id, q->q_id);\n\tublk_queue_deinit(q);\n\treturn NULL;\n}\n\nstatic void ublk_set_parameters(struct ublk_dev *dev)\n{\n\tint ret;\n\n\tret = ublk_ctrl_set_params(dev, &dev->tgt.params);\n\tif (ret)\n\t\tublk_err(\"dev %d set basic parameter failed %d\\n\",\n\t\t\t\tdev->dev_info.dev_id, ret);\n}\n\nstatic int ublk_start_daemon(struct ublk_dev *dev)\n{\n\tint ret, i;\n\tvoid *thread_ret;\n\tconst struct ublksrv_ctrl_dev_info *dinfo = &dev->dev_info;\n\n\tif (daemon(1, 1) < 0)\n\t\treturn -errno;\n\n\tublk_dbg(UBLK_DBG_DEV, \"%s enter\\n\", __func__);\n\n\tret = ublk_dev_prep(dev);\n\tif (ret)\n\t\treturn ret;\n\n\tfor (i = 0; i < dinfo->nr_hw_queues; i++) {\n\t\tdev->q[i].dev = dev;\n\t\tdev->q[i].q_id = i;\n\t\tpthread_create(&dev->q[i].thread, NULL,\n\t\t\t\tublk_io_handler_fn,\n\t\t\t\t&dev->q[i]);\n\t}\n\n\t/* everything is fine now, start us */\n\tublk_set_parameters(dev);\n\tret = ublk_ctrl_start_dev(dev, getpid());\n\tif (ret < 0) {\n\t\tublk_err(\"%s: ublk_ctrl_start_dev failed: %d\\n\", __func__, ret);\n\t\tgoto fail;\n\t}\n\n\t/* wait until we are terminated */\n\tfor (i = 0; i < dinfo->nr_hw_queues; i++)\n\t\tpthread_join(dev->q[i].thread, &thread_ret);\n fail:\n\tublk_dev_unprep(dev);\n\tublk_dbg(UBLK_DBG_DEV, \"%s exit\\n\", __func__);\n\n\treturn ret;\n}\n\nstatic int wait_ublk_dev(char *dev_name, int evt_mask, unsigned timeout)\n{\n#define EV_SIZE (sizeof(struct inotify_event))\n#define EV_BUF_LEN (128 * (EV_SIZE + 16))\n\tstruct pollfd pfd;\n\tint fd, wd;\n\tint ret = -EINVAL;\n\n\tfd = inotify_init();\n\tif (fd < 0) {\n\t\tublk_dbg(UBLK_DBG_DEV, \"%s: inotify init failed\\n\", __func__);\n\t\treturn fd;\n\t}\n\n\twd = inotify_add_watch(fd, \"/dev\", evt_mask);\n\tif (wd == -1) {\n\t\tublk_dbg(UBLK_DBG_DEV, \"%s: add watch for /dev failed\\n\", __func__);\n\t\tgoto fail;\n\t}\n\n\tpfd.fd = fd;\n\tpfd.events = POLL_IN;\n\twhile (1) {\n\t\tint i = 0;\n\t\tchar buffer[EV_BUF_LEN];\n\t\tret = poll(&pfd, 1, 1000 * timeout);\n\n\t\tif (ret == -1) {\n\t\t\tublk_err(\"%s: poll inotify failed: %d\\n\", __func__, ret);\n\t\t\tgoto rm_watch;\n\t\t} else if (ret == 0) {\n\t\t\tublk_err(\"%s: poll inotify timeout\\n\", __func__);\n\t\t\tret = -ENOENT;\n\t\t\tgoto rm_watch;\n\t\t}\n\n\t\tret = read(fd, buffer, EV_BUF_LEN);\n\t\tif (ret < 0) {\n\t\t\tublk_err(\"%s: read inotify fd failed\\n\", __func__);\n\t\t\tgoto rm_watch;\n\t\t}\n\n\t\twhile (i < ret) {\n\t\t\tstruct inotify_event *event = (struct inotify_event *)&buffer[i];\n\n\t\t\tublk_dbg(UBLK_DBG_DEV, \"%s: inotify event %x %s\\n\",\n\t\t\t\t\t__func__, event->mask, event->name);\n\t\t\tif (event->mask & evt_mask) {\n\t\t\t\tif (!strcmp(event->name, dev_name)) {\n\t\t\t\t\tret = 0;\n\t\t\t\t\tgoto rm_watch;\n\t\t\t\t}\n\t\t\t}\n\t\t\ti += EV_SIZE + event->len;\n\t\t}\n\t}\nrm_watch:\n\tinotify_rm_watch(fd, wd);\nfail:\n\tclose(fd);\n\treturn ret;\n}\n\nstatic int ublk_stop_io_daemon(const struct ublk_dev *dev)\n{\n\tint daemon_pid = dev->dev_info.ublksrv_pid;\n\tint dev_id = dev->dev_info.dev_id;\n\tchar ublkc[64];\n\tint ret;\n\n\t/*\n\t * Wait until ublk char device is closed, when our daemon is shutdown\n\t */\n\tsnprintf(ublkc, sizeof(ublkc), \"%s%d\", \"ublkc\", dev_id);\n\tret = wait_ublk_dev(ublkc, IN_CLOSE_WRITE, 10);\n\twaitpid(dev->dev_info.ublksrv_pid, NULL, 0);\n\tublk_dbg(UBLK_DBG_DEV, \"%s: pid %d dev_id %d ret %d\\n\",\n\t\t\t__func__, daemon_pid, dev_id, ret);\n\n\treturn ret;\n}\n\nstatic int cmd_dev_add(char *tgt_type, int *exp_id, unsigned nr_queues,\n\t\t       unsigned depth)\n{\n\tconst struct ublk_tgt_ops *ops;\n\tstruct ublksrv_ctrl_dev_info *info;\n\tstruct ublk_dev *dev;\n\tint dev_id = *exp_id;\n\tchar ublkb[64];\n\tint ret;\n\n\tops = ublk_find_tgt(tgt_type);\n\tif (!ops) {\n\t\tublk_err(\"%s: no such tgt type, type %s\\n\",\n\t\t\t\t__func__, tgt_type);\n\t\treturn -ENODEV;\n\t}\n\n\tif (nr_queues > UBLK_MAX_QUEUES || depth > UBLK_QUEUE_DEPTH) {\n\t\tublk_err(\"%s: invalid nr_queues or depth queues %u depth %u\\n\",\n\t\t\t\t__func__, nr_queues, depth);\n\t\treturn -EINVAL;\n\t}\n\n\tdev = ublk_ctrl_init();\n\tif (!dev) {\n\t\tublk_err(\"%s: can't alloc dev id %d, type %s\\n\",\n\t\t\t\t__func__, dev_id, tgt_type);\n\t\treturn -ENOMEM;\n\t}\n\n\tinfo = &dev->dev_info;\n\tinfo->dev_id = dev_id;\n        info->nr_hw_queues = nr_queues;\n        info->queue_depth = depth;\n\tdev->tgt.ops = ops;\n\n\tret = ublk_ctrl_add_dev(dev);\n\tif (ret < 0) {\n\t\tublk_err(\"%s: can't add dev id %d, type %s ret %d\\n\",\n\t\t\t\t__func__, dev_id, tgt_type, ret);\n\t\tgoto fail;\n\t}\n\n\tswitch (fork()) {\n\tcase -1:\n\t\tgoto fail;\n\tcase 0:\n\t\tublk_start_daemon(dev);\n\t\treturn 0;\n\t}\n\n\t/*\n\t * Wait until ublk disk is added, when our daemon is started\n\t * successfully\n\t */\n\tsnprintf(ublkb, sizeof(ublkb), \"%s%u\", \"ublkb\", dev->dev_info.dev_id);\n\tret = wait_ublk_dev(ublkb, IN_CREATE, 3);\n\tif (ret < 0) {\n\t\tublk_err(\"%s: can't start daemon id %d, type %s\\n\",\n\t\t\t\t__func__, dev_id, tgt_type);\n\t\tublk_ctrl_del_dev(dev);\n\t} else {\n\t\t*exp_id = dev->dev_info.dev_id;\n\t}\nfail:\n\tublk_ctrl_deinit(dev);\n\treturn ret;\n}\n\nstatic int cmd_dev_del_by_kill(int number)\n{\n\tstruct ublk_dev *dev;\n\tint ret;\n\n\tdev = ublk_ctrl_init();\n\tdev->dev_info.dev_id = number;\n\n\tret = ublk_ctrl_get_info(dev);\n\tif (ret < 0)\n\t\tgoto fail;\n\n\t/* simulate one ublk daemon panic */\n\tkill(dev->dev_info.ublksrv_pid, 9);\n\n\tret = ublk_stop_io_daemon(dev);\n\tif (ret < 0)\n\t\tublk_err(\"%s: can't stop daemon id %d\\n\", __func__, number);\n\tublk_ctrl_del_dev(dev);\nfail:\n\tif (ret >= 0)\n\t\tret = ublk_ctrl_get_info(dev);\n\tublk_ctrl_deinit(dev);\n\n\treturn (ret != 0) ? 0 : -EIO;\n}\n\n/****************** part 2: target implementation ********************/\n\nstatic int ublk_null_tgt_init(struct ublk_dev *dev)\n{\n\tconst struct ublksrv_ctrl_dev_info *info = &dev->dev_info;\n\tunsigned long dev_size = 250UL << 30;\n\n\tdev->tgt.dev_size = dev_size;\n\tdev->tgt.params = (struct ublk_params) {\n\t\t.types = UBLK_PARAM_TYPE_BASIC,\n\t\t.basic = {\n\t\t\t.logical_bs_shift\t= 9,\n\t\t\t.physical_bs_shift\t= 12,\n\t\t\t.io_opt_shift\t\t= 12,\n\t\t\t.io_min_shift\t\t= 9,\n\t\t\t.max_sectors\t\t= info->max_io_buf_bytes >> 9,\n\t\t\t.dev_sectors\t\t= dev_size >> 9,\n\t\t},\n\t};\n\n\treturn 0;\n}\n\nstatic int ublk_null_queue_io(struct ublk_queue *q, int tag)\n{\n\tconst struct ublksrv_io_desc *iod = ublk_get_iod(q, tag);\n\n\tublk_complete_io(q, tag, iod->nr_sectors << 9);\n\n\treturn 0;\n}\n\nstatic const struct ublk_tgt_ops tgt_ops_list[] = {\n\t{\n\t\t.name = \"null\",\n\t\t.init_tgt = ublk_null_tgt_init,\n\t\t.queue_io = ublk_null_queue_io,\n\t},\n};\n\nstatic const struct ublk_tgt_ops *ublk_find_tgt(const char *name)\n{\n\tconst struct ublk_tgt_ops *ops;\n\tint i;\n\n\tif (name == NULL)\n\t\treturn NULL;\n\n\tfor (i = 0; sizeof(tgt_ops_list) / sizeof(*ops); i++)\n\t\tif (strcmp(tgt_ops_list[i].name, name) == 0)\n\t\t\treturn &tgt_ops_list[i];\n\treturn NULL;\n}\n\n\n/****************** part 3: IO test over ublk disk ********************/\n\n#include \"helpers.h\"\n#include \"liburing.h\"\n#define BS\t\t4096\n#define BUFFERS\t\t128\n\nstruct io_ctx {\n\tint dev_id;\n\tint write;\n\tint seq;\n\n\t/* output */\n\tint res;\n\tpthread_t handle;\n};\n\nstatic int __test_io(struct io_uring *ring, int fd, int write,\n\t\tint seq, struct iovec *vecs, int exp_len, off_t start)\n{\n\tstruct io_uring_sqe *sqe;\n\tstruct io_uring_cqe *cqe;\n\tint i, ret;\n\toff_t offset;\n\n\toffset = start;\n\tfor (i = 0; i < BUFFERS; i++) {\n\t\tsqe = io_uring_get_sqe(ring);\n\t\tif (!sqe) {\n\t\t\tfprintf(stderr, \"sqe get failed\\n\");\n\t\t\tgoto err;\n\t\t}\n\t\tif (!seq)\n\t\t\toffset = start + BS * (rand() % BUFFERS);\n\t\tif (write) {\n\t\t\tio_uring_prep_write_fixed(sqe, fd, vecs[i].iov_base,\n\t\t\t\t\t\t  vecs[i].iov_len,\n\t\t\t\t\t\t  offset, i);\n\t\t} else {\n\t\t\tio_uring_prep_read_fixed(sqe, fd, vecs[i].iov_base,\n\t\t\t\t\t\t vecs[i].iov_len,\n\t\t\t\t\t\t offset, i);\n\t\t}\n\t\tsqe->user_data = i;\n\t\tif (seq)\n\t\t\toffset += BS;\n\t}\n\n\tret = io_uring_submit(ring);\n\tif (ret != BUFFERS) {\n\t\tfprintf(stderr, \"submit got %d, wanted %d\\n\", ret, BUFFERS);\n\t\tgoto err;\n\t}\n\n\tfor (i = 0; i < BUFFERS; i++) {\n\t\tret = io_uring_wait_cqe(ring, &cqe);\n\t\tif (ret) {\n\t\t\tfprintf(stderr, \"wait_cqe=%d\\n\", ret);\n\t\t\tgoto err;\n\t\t}\n\t\tif (exp_len == -1) {\n\t\t\tint iov_len = vecs[cqe->user_data].iov_len;\n\n\t\t\tif (cqe->res != iov_len) {\n\t\t\t\tfprintf(stderr, \"cqe res %d, wanted %d\\n\",\n\t\t\t\t\tcqe->res, iov_len);\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t} else if (cqe->res != exp_len) {\n\t\t\tfprintf(stderr, \"cqe res %d, wanted %d\\n\", cqe->res, exp_len);\n\t\t\tgoto err;\n\t\t}\n\t\tio_uring_cqe_seen(ring, cqe);\n\t}\n\n\treturn 0;\nerr:\n\treturn 1;\n}\n\n/* Run IO over ublk block device  */\nstatic int test_io(struct io_ctx *ctx)\n{\n\tstruct io_uring ring;\n\tint ret, ring_flags = 0;\n\tchar buf[256];\n\tint fd = -1;\n\toff_t offset = 0;\n\tunsigned long long bytes;\n\tint open_flags = O_DIRECT;\n\tstruct iovec *vecs = t_create_buffers(BUFFERS, BS);\n\n\tret = t_create_ring(BUFFERS, &ring, ring_flags);\n\tif (ret == T_SETUP_SKIP)\n\t\treturn 0;\n\tif (ret != T_SETUP_OK) {\n\t\tfprintf(stderr, \"ring create failed: %d\\n\", ret);\n\t\treturn 1;\n\t}\n\n\tsnprintf(buf, sizeof(buf), \"%s%d\", UBLKB_DEV, ctx->dev_id);\n\n\tif (ctx->write)\n\t\topen_flags |= O_WRONLY;\n\telse\n\t\topen_flags |= O_RDONLY;\n\tfd = open(buf, open_flags);\n\tif (fd < 0) {\n\t\tif (errno == EINVAL)\n\t\t\treturn 0;\n\t\treturn 1;\n\t}\n\n\tif (ioctl(fd, BLKGETSIZE64, &bytes) != 0)\n\t\treturn 1;\n\n\tret = t_register_buffers(&ring, vecs, BUFFERS);\n\tif (ret == T_SETUP_SKIP)\n\t\treturn 0;\n\tif (ret != T_SETUP_OK) {\n\t\tfprintf(stderr, \"buffer reg failed: %d\\n\", ret);\n\t\treturn 1;\n\t}\n\n\tfor (offset = 0; offset < bytes; offset += BS * BUFFERS) {\n\t\tret = __test_io(&ring, fd, ctx->write, ctx->seq, vecs, BS,\n\t\t\t\toffset);\n\t\tif (ret != T_SETUP_OK) {\n\t\t\tfprintf(stderr, \"/dev/ublkb%d read failed: offset %lu ret %d\\n\",\n\t\t\t\t\tctx->dev_id, (unsigned long) offset, ret);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tclose(fd);\n\tio_uring_unregister_buffers(&ring);\n\tio_uring_queue_exit(&ring);\n\n\treturn ret;\n}\n\nstatic void *test_io_fn(void *data)\n{\n\tstruct io_ctx *ctx = data;\n\n\tctx->res = test_io(ctx);\n\n\treturn data;\n}\n\nstatic void ignore_stderr(void)\n{\n\tint devnull = open(\"/dev/null\", O_WRONLY);\n\n\tif (devnull >= 0) {\n\t\tdup2(devnull, fileno(stderr));\n\t\tclose(devnull);\n\t}\n}\n\nstatic int test_io_worker(int dev_id)\n{\n\tconst int nr_jobs = 4;\n\tstruct io_ctx ctx[nr_jobs];\n\tint i, ret = 0;\n\n\tfor (i = 0; i < nr_jobs; i++) {\n\t\tctx[i].dev_id = dev_id;\n\t\tctx[i].write = (i & 0x1) ? 0 : 1;\n\t\tctx[i].seq = 1;\n\n\t\tpthread_create(&ctx[i].handle, NULL, test_io_fn, &ctx[i]);\n\t}\n\n\tfor (i = 0; i < nr_jobs; i++) {\n\t\tpthread_join(ctx[i].handle, NULL);\n\n\t\tif (!ret && ctx[i].res)\n\t\t\tret = ctx[i].res;\n\t}\n\n\treturn ret;\n}\n\n/*\n * Run IO over created ublk device, meantime delete this ublk device\n *\n * Cover cancellable uring_cmd\n * */\nstatic int test_del_ublk_with_io(void)\n{\n\tconst unsigned wait_ms = 200;\n\tchar *tgt_type = \"null\";\n\tint dev_id = -1;\n\tint ret, pid;\n\n\tret = cmd_dev_add(tgt_type, &dev_id, 2, BUFFERS);\n\tif (ret != T_SETUP_OK) {\n\t\tfprintf(stderr, \"buffer reg failed: %d\\n\", ret);\n\t\treturn T_EXIT_FAIL;\n\t}\n\n\tswitch ((pid = fork())) {\n\tcase -1:\n\t\tfprintf(stderr, \"fork failed\\n\");\n\t\treturn T_EXIT_FAIL;\n\tcase 0:\n\t\t/* io error is expected since the parent is killing ublk */\n\t\tignore_stderr();\n\t\ttest_io_worker(dev_id);\n\t\treturn 0;\n\tdefault:\n\t\t/*\n\t\t * Wait a little while until ublk IO pipeline is warm up,\n\t\t * then try to shutdown ublk device by `kill -9 $ublk_daemon_pid`.\n\t\t *\n\t\t * cancellable uring_cmd code path can be covered in this way.\n\t\t */\n\t\tusleep(wait_ms * 1000);\n\t\tret = cmd_dev_del_by_kill(dev_id);\n\t\twaitpid(pid, NULL, 0);\n\t\treturn ret;\n\t}\n}\n\nint main(int argc, char *argv[])\n{\n\tconst int nr_loop = 4;\n\tstruct ublk_dev *dev;\n\t__u64 features;\n\tint ret, i;\n\n\tif (argc > 1)\n\t\treturn T_EXIT_SKIP;\n\n\tdev = ublk_ctrl_init();\n\t/* ublk isn't supported or the module isn't loaded */\n\tif (!dev)\n\t\treturn T_EXIT_SKIP;\n\n\t/* kernel doesn't support get_features */\n\tret = ublk_ctrl_get_features(dev, &features);\n\tif (ret < 0)\n\t\treturn T_EXIT_SKIP;\n\n\tif (!(features & UBLK_F_CMD_IOCTL_ENCODE))\n\t\treturn T_EXIT_SKIP;\n\n\tfor (i = 0; i < nr_loop; i++) {\n\t\tif (test_del_ublk_with_io())\n\t\t\treturn T_EXIT_FAIL;\n\t}\n\tublk_ctrl_deinit(dev);\n\treturn T_EXIT_PASS;\n}\n#else\nint main(int argc, char *argv[])\n{\n\treturn T_EXIT_SKIP;\n}\n#endif\n"},
                          "roles": ["analysisTarget",
                                    "tracedFile"]}],
           "results": [{"ruleId": "-Wanalyzer-va-list-leak",
                        "properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                       "gcc/analyzer/saved_diagnostic/ploc": {"enode": 116},
                                       "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(710)",
                                       "gcc/analyzer/saved_diagnostic/state": "started",
                                       "gcc/analyzer/saved_diagnostic/idx": 1,
                                       "gcc/analyzer/saved_diagnostic/duplicates": [{"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 116},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(710)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 2,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 211},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(863)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 3,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 211},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(863)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 4,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 270},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(933)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 7,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 270},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(933)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 8,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 551},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1128)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 9,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 551},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1128)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 10,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 795},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1301)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 12,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 795},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1301)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 13,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 820},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1321)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 14,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 820},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1321)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 15,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 829},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1329)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 16,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 829},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1329)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 17,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 921},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1420)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 18,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 921},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1420)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 19,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 930},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1425)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 20,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 930},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1425)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 21,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 980},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1451)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 22,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 980},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1451)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 23,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 1261},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1604)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 24,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 1261},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1604)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 25,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 1416},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1647)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 26,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 1416},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1647)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 27,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 1425},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1653)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 28,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 1425},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1653)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 29,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 1434},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1656)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 30,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 1434},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1656)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 31,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 1443},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1659)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 32,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 1443},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1659)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 33,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 1452},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1662)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 34,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}},
                                                                                    {"properties": {"gcc/analyzer/saved_diagnostic/sm": "va_list",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 1452},
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&ALLOCA_REGION(1662)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "started",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 35,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"}}],
                                       "gcc/analyzer/pending_diagnostic/kind": "va_list_leak"},
                        "level": "warning",
                        "message": {"text": "missing call to ‘va_end’"},
                        "locations": [{"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                 "uriBaseId": "PWD"},
                                                            "region": {"startLine": 163,
                                                                       "startColumn": 1,
                                                                       "endColumn": 2},
                                                            "contextRegion": {"startLine": 163,
                                                                              "snippet": {"text": "}\n"}}},
                                       "logicalLocations": [{"index": 0,
                                                             "fullyQualifiedName": "ublk_err"}]}],
                        "codeFlows": [{"threadFlows": [{"id": "main",
                                                        "locations": [{"properties": {"gcc/analyzer/checker_event/emission_id": "(1)",
                                                                                      "gcc/analyzer/checker_event/kind": "function_entry"},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 1217,
                                                                                                                    "startColumn": 5,
                                                                                                                    "endColumn": 9},
                                                                                                         "contextRegion": {"startLine": 1217,
                                                                                                                           "snippet": {"text": "int main(int argc, char *argv[])\n"}}},
                                                                                    "logicalLocations": [{"index": 1,
                                                                                                          "fullyQualifiedName": "main"}],
                                                                                    "message": {"text": "entry to ‘main’"}},
                                                                       "kinds": ["enter",
                                                                                 "function"],
                                                                       "nestingLevel": 1,
                                                                       "executionOrder": 1},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(2)",
                                                                                      "gcc/analyzer/checker_event/kind": "start_cfg_edge",
                                                                                      "gcc/analyzer/superedge_event/superedge": {"src_id": 27,
                                                                                                                                 "dst_id": 29}},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 1224,
                                                                                                                    "startColumn": 12,
                                                                                                                    "endColumn": 13},
                                                                                                         "contextRegion": {"startLine": 1224,
                                                                                                                           "snippet": {"text": "\tif (argc > 1)\n"}}},
                                                                                    "logicalLocations": [{"index": 1,
                                                                                                          "fullyQualifiedName": "main"}],
                                                                                    "message": {"text": "following ‘false’ branch (when ‘argc <= 1’)..."}},
                                                                       "kinds": ["branch",
                                                                                 "false"],
                                                                       "nestingLevel": 1,
                                                                       "executionOrder": 2},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(3)",
                                                                                      "gcc/analyzer/checker_event/kind": "end_cfg_edge",
                                                                                      "gcc/analyzer/superedge_event/superedge": {"src_id": 27,
                                                                                                                                 "dst_id": 29}},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 1227,
                                                                                                                    "startColumn": 15,
                                                                                                                    "endColumn": 31},
                                                                                                         "contextRegion": {"startLine": 1227,
                                                                                                                           "snippet": {"text": "\tdev = ublk_ctrl_init();\n"}}},
                                                                                    "logicalLocations": [{"index": 1,
                                                                                                          "fullyQualifiedName": "main"}],
                                                                                    "message": {"text": "...to here"}},
                                                                       "kinds": ["branch",
                                                                                 "false"],
                                                                       "nestingLevel": 1,
                                                                       "executionOrder": 3},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(4)",
                                                                                      "gcc/analyzer/checker_event/kind": "call",
                                                                                      "gcc/analyzer/superedge_event/superedge": {"src_id": 29,
                                                                                                                                 "dst_id": 30}},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 1227,
                                                                                                                    "startColumn": 15,
                                                                                                                    "endColumn": 31},
                                                                                                         "contextRegion": {"startLine": 1227,
                                                                                                                           "snippet": {"text": "\tdev = ublk_ctrl_init();\n"}}},
                                                                                    "logicalLocations": [{"index": 1,
                                                                                                          "fullyQualifiedName": "main"}],
                                                                                    "message": {"text": "calling ‘ublk_ctrl_init’ from ‘main’"}},
                                                                       "kinds": ["call",
                                                                                 "function"],
                                                                       "nestingLevel": 1,
                                                                       "executionOrder": 4},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(5)",
                                                                                      "gcc/analyzer/checker_event/kind": "function_entry"},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 350,
                                                                                                                    "startColumn": 25,
                                                                                                                    "endColumn": 39},
                                                                                                         "contextRegion": {"startLine": 350,
                                                                                                                           "snippet": {"text": "static struct ublk_dev *ublk_ctrl_init(void)\n"}}},
                                                                                    "logicalLocations": [{"index": 2,
                                                                                                          "fullyQualifiedName": "ublk_ctrl_init"}],
                                                                                    "message": {"text": "entry to ‘ublk_ctrl_init’"}},
                                                                       "kinds": ["enter",
                                                                                 "function"],
                                                                       "nestingLevel": 2,
                                                                       "executionOrder": 5},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(6)",
                                                                                      "gcc/analyzer/checker_event/kind": "start_cfg_edge",
                                                                                      "gcc/analyzer/superedge_event/superedge": {"src_id": 1083,
                                                                                                                                 "dst_id": 1086}},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 357,
                                                                                                                    "startColumn": 12,
                                                                                                                    "endColumn": 13},
                                                                                                         "contextRegion": {"startLine": 357,
                                                                                                                           "snippet": {"text": "\tif (dev->ctrl_fd < 0) {\n"}}},
                                                                                    "logicalLocations": [{"index": 2,
                                                                                                          "fullyQualifiedName": "ublk_ctrl_init"}],
                                                                                    "message": {"text": "following ‘false’ branch..."}},
                                                                       "kinds": ["branch",
                                                                                 "false"],
                                                                       "nestingLevel": 2,
                                                                       "executionOrder": 6},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(7)",
                                                                                      "gcc/analyzer/checker_event/kind": "end_cfg_edge",
                                                                                      "gcc/analyzer/superedge_event/superedge": {"src_id": 1083,
                                                                                                                                 "dst_id": 1086}},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 362,
                                                                                                                    "startColumn": 9,
                                                                                                                    "endColumn": 35},
                                                                                                         "contextRegion": {"startLine": 362,
                                                                                                                           "snippet": {"text": "\tinfo->max_io_buf_bytes = UBLK_IO_MAX_BYTES;\n"}}},
                                                                                    "logicalLocations": [{"index": 2,
                                                                                                          "fullyQualifiedName": "ublk_ctrl_init"}],
                                                                                    "message": {"text": "...to here"}},
                                                                       "kinds": ["branch",
                                                                                 "false"],
                                                                       "nestingLevel": 2,
                                                                       "executionOrder": 7},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(8)",
                                                                                      "gcc/analyzer/checker_event/kind": "start_cfg_edge",
                                                                                      "gcc/analyzer/superedge_event/superedge": {"src_id": 1089,
                                                                                                                                 "dst_id": 1090}},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 366,
                                                                                                                    "startColumn": 12,
                                                                                                                    "endColumn": 13},
                                                                                                         "contextRegion": {"startLine": 366,
                                                                                                                           "snippet": {"text": "\tif (ret < 0) {\n"}}},
                                                                                    "logicalLocations": [{"index": 2,
                                                                                                          "fullyQualifiedName": "ublk_ctrl_init"}],
                                                                                    "message": {"text": "following ‘true’ branch..."}},
                                                                       "kinds": ["branch",
                                                                                 "true"],
                                                                       "nestingLevel": 2,
                                                                       "executionOrder": 8},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(9)",
                                                                                      "gcc/analyzer/checker_event/kind": "end_cfg_edge",
                                                                                      "gcc/analyzer/superedge_event/superedge": {"src_id": 1089,
                                                                                                                                 "dst_id": 1090}},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 367,
                                                                                                                    "startColumn": 17,
                                                                                                                    "endColumn": 61},
                                                                                                         "contextRegion": {"startLine": 367,
                                                                                                                           "snippet": {"text": "\t\tublk_err(\"queue_init: %s\\n\", strerror(-ret));\n"}}},
                                                                                    "logicalLocations": [{"index": 2,
                                                                                                          "fullyQualifiedName": "ublk_ctrl_init"}],
                                                                                    "message": {"text": "...to here"}},
                                                                       "kinds": ["branch",
                                                                                 "true"],
                                                                       "nestingLevel": 2,
                                                                       "executionOrder": 9},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(10)",
                                                                                      "gcc/analyzer/checker_event/kind": "call",
                                                                                      "gcc/analyzer/superedge_event/superedge": {"src_id": 1092,
                                                                                                                                 "dst_id": 1093}},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 367,
                                                                                                                    "startColumn": 17,
                                                                                                                    "endColumn": 61},
                                                                                                         "contextRegion": {"startLine": 367,
                                                                                                                           "snippet": {"text": "\t\tublk_err(\"queue_init: %s\\n\", strerror(-ret));\n"}}},
                                                                                    "logicalLocations": [{"index": 2,
                                                                                                          "fullyQualifiedName": "ublk_ctrl_init"}],
                                                                                    "message": {"text": "calling ‘ublk_err’ from ‘ublk_ctrl_init’"}},
                                                                       "kinds": ["call",
                                                                                 "function"],
                                                                       "nestingLevel": 2,
                                                                       "executionOrder": 10},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(11)",
                                                                                      "gcc/analyzer/checker_event/kind": "function_entry"},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 157,
                                                                                                                    "startColumn": 13,
                                                                                                                    "endColumn": 21},
                                                                                                         "contextRegion": {"startLine": 157,
                                                                                                                           "snippet": {"text": "static void ublk_err(const char *fmt, ...)\n"}}},
                                                                                    "logicalLocations": [{"index": 0,
                                                                                                          "fullyQualifiedName": "ublk_err"}],
                                                                                    "message": {"text": "entry to ‘ublk_err’"}},
                                                                       "kinds": ["enter",
                                                                                 "function"],
                                                                       "nestingLevel": 3,
                                                                       "executionOrder": 11},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(12)",
                                                                                      "gcc/analyzer/checker_event/kind": "state_change"},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 161,
                                                                                                                    "startColumn": 9,
                                                                                                                    "endColumn": 17},
                                                                                                         "contextRegion": {"startLine": 161,
                                                                                                                           "snippet": {"text": "\tva_start(ap, fmt);\n"}}},
                                                                                    "logicalLocations": [{"index": 0,
                                                                                                          "fullyQualifiedName": "ublk_err"}],
                                                                                    "message": {"text": "‘va_start’ called here"}},
                                                                       "kinds": ["acquire",
                                                                                 "resource"],
                                                                       "nestingLevel": 3,
                                                                       "executionOrder": 12},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(13)",
                                                                                      "gcc/analyzer/checker_event/kind": "warning"},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 163,
                                                                                                                    "startColumn": 1,
                                                                                                                    "endColumn": 2},
                                                                                                         "contextRegion": {"startLine": 163,
                                                                                                                           "snippet": {"text": "}\n"}}},
                                                                                    "logicalLocations": [{"index": 0,
                                                                                                          "fullyQualifiedName": "ublk_err"}],
                                                                                    "message": {"text": "missing call to ‘va_end’ to match ‘va_start’ at [(12)](sarif:/runs/0/results/0/codeFlows/0/threadFlows/0/locations/11)"}},
                                                                       "kinds": ["danger"],
                                                                       "nestingLevel": 3,
                                                                       "executionOrder": 13}]}]}]},
                       {"ruleId": "-Wanalyzer-possible-null-dereference",
                        "taxa": [{"id": "690",
                                  "toolComponent": {"name": "cwe"}}],
                        "properties": {"gcc/analyzer/saved_diagnostic/sm": "malloc",
                                       "gcc/analyzer/saved_diagnostic/ploc": {"enode": 87},
                                       "gcc/analyzer/saved_diagnostic/var": "dev_8",
                                       "gcc/analyzer/saved_diagnostic/sval": "&HEAP_ALLOCATED_REGION(617)",
                                       "gcc/analyzer/saved_diagnostic/state": "unchecked ({free})",
                                       "gcc/analyzer/saved_diagnostic/idx": 0,
                                       "gcc/analyzer/saved_diagnostic/duplicates": [{"properties": {"gcc/analyzer/saved_diagnostic/sm": "malloc",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 766},
                                                                                                    "gcc/analyzer/saved_diagnostic/var": "dev_8",
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&HEAP_ALLOCATED_REGION(1258)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "unchecked ({free})",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 11,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "possible_null_deref"}}],
                                       "gcc/analyzer/pending_diagnostic/kind": "possible_null_deref"},
                        "level": "warning",
                        "message": {"text": "dereference of possibly-NULL ‘dev’"},
                        "locations": [{"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                 "uriBaseId": "PWD"},
                                                            "region": {"startLine": 356,
                                                                       "startColumn": 9,
                                                                       "endColumn": 46},
                                                            "contextRegion": {"startLine": 356,
                                                                              "snippet": {"text": "\tdev->ctrl_fd = open(CTRL_DEV, O_RDWR);\n"}}},
                                       "logicalLocations": [{"index": 2,
                                                             "fullyQualifiedName": "ublk_ctrl_init"}]}],
                        "codeFlows": [{"threadFlows": [{"id": "main",
                                                        "locations": [{"properties": {"gcc/analyzer/checker_event/emission_id": "(1)",
                                                                                      "gcc/analyzer/checker_event/kind": "function_entry"},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 1217,
                                                                                                                    "startColumn": 5,
                                                                                                                    "endColumn": 9},
                                                                                                         "contextRegion": {"startLine": 1217,
                                                                                                                           "snippet": {"text": "int main(int argc, char *argv[])\n"}}},
                                                                                    "logicalLocations": [{"index": 1,
                                                                                                          "fullyQualifiedName": "main"}],
                                                                                    "message": {"text": "entry to ‘main’"}},
                                                                       "kinds": ["enter",
                                                                                 "function"],
                                                                       "nestingLevel": 1,
                                                                       "executionOrder": 1},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(2)",
                                                                                      "gcc/analyzer/checker_event/kind": "start_cfg_edge",
                                                                                      "gcc/analyzer/superedge_event/superedge": {"src_id": 27,
                                                                                                                                 "dst_id": 29}},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 1224,
                                                                                                                    "startColumn": 12,
                                                                                                                    "endColumn": 13},
                                                                                                         "contextRegion": {"startLine": 1224,
                                                                                                                           "snippet": {"text": "\tif (argc > 1)\n"}}},
                                                                                    "logicalLocations": [{"index": 1,
                                                                                                          "fullyQualifiedName": "main"}],
                                                                                    "message": {"text": "following ‘false’ branch (when ‘argc <= 1’)..."}},
                                                                       "kinds": ["branch",
                                                                                 "false"],
                                                                       "nestingLevel": 1,
                                                                       "executionOrder": 2},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(3)",
                                                                                      "gcc/analyzer/checker_event/kind": "end_cfg_edge",
                                                                                      "gcc/analyzer/superedge_event/superedge": {"src_id": 27,
                                                                                                                                 "dst_id": 29}},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 1227,
                                                                                                                    "startColumn": 15,
                                                                                                                    "endColumn": 31},
                                                                                                         "contextRegion": {"startLine": 1227,
                                                                                                                           "snippet": {"text": "\tdev = ublk_ctrl_init();\n"}}},
                                                                                    "logicalLocations": [{"index": 1,
                                                                                                          "fullyQualifiedName": "main"}],
                                                                                    "message": {"text": "...to here"}},
                                                                       "kinds": ["branch",
                                                                                 "false"],
                                                                       "nestingLevel": 1,
                                                                       "executionOrder": 3},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(4)",
                                                                                      "gcc/analyzer/checker_event/kind": "call",
                                                                                      "gcc/analyzer/superedge_event/superedge": {"src_id": 29,
                                                                                                                                 "dst_id": 30}},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 1227,
                                                                                                                    "startColumn": 15,
                                                                                                                    "endColumn": 31},
                                                                                                         "contextRegion": {"startLine": 1227,
                                                                                                                           "snippet": {"text": "\tdev = ublk_ctrl_init();\n"}}},
                                                                                    "logicalLocations": [{"index": 1,
                                                                                                          "fullyQualifiedName": "main"}],
                                                                                    "message": {"text": "calling ‘ublk_ctrl_init’ from ‘main’"}},
                                                                       "kinds": ["call",
                                                                                 "function"],
                                                                       "nestingLevel": 1,
                                                                       "executionOrder": 4},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(5)",
                                                                                      "gcc/analyzer/checker_event/kind": "function_entry"},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 350,
                                                                                                                    "startColumn": 25,
                                                                                                                    "endColumn": 39},
                                                                                                         "contextRegion": {"startLine": 350,
                                                                                                                           "snippet": {"text": "static struct ublk_dev *ublk_ctrl_init(void)\n"}}},
                                                                                    "logicalLocations": [{"index": 2,
                                                                                                          "fullyQualifiedName": "ublk_ctrl_init"}],
                                                                                    "message": {"text": "entry to ‘ublk_ctrl_init’"}},
                                                                       "kinds": ["enter",
                                                                                 "function"],
                                                                       "nestingLevel": 2,
                                                                       "executionOrder": 5},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(6)",
                                                                                      "gcc/analyzer/checker_event/kind": "state_change"},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 352,
                                                                                                                    "startColumn": 51,
                                                                                                                    "endColumn": 74},
                                                                                                         "contextRegion": {"startLine": 352,
                                                                                                                           "snippet": {"text": "\tstruct ublk_dev *dev = (struct ublk_dev *)calloc(1, sizeof(*dev));\n"}}},
                                                                                    "logicalLocations": [{"index": 2,
                                                                                                          "fullyQualifiedName": "ublk_ctrl_init"}],
                                                                                    "message": {"text": "this call could return NULL"}},
                                                                       "kinds": ["acquire",
                                                                                 "memory"],
                                                                       "nestingLevel": 2,
                                                                       "executionOrder": 6},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(7)",
                                                                                      "gcc/analyzer/checker_event/kind": "warning"},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "uring_cmd_ublk.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 356,
                                                                                                                    "startColumn": 9,
                                                                                                                    "endColumn": 46},
                                                                                                         "contextRegion": {"startLine": 356,
                                                                                                                           "snippet": {"text": "\tdev->ctrl_fd = open(CTRL_DEV, O_RDWR);\n"}}},
                                                                                    "logicalLocations": [{"index": 2,
                                                                                                          "fullyQualifiedName": "ublk_ctrl_init"}],
                                                                                    "message": {"text": "‘dev’ could be NULL: unchecked value from [(6)](sarif:/runs/0/results/1/codeFlows/0/threadFlows/0/locations/5)"}},
                                                                       "kinds": ["danger"],
                                                                       "nestingLevel": 2,
                                                                       "executionOrder": 7}]}]}]}],
           "logicalLocations": [{"name": "ublk_err",
                                 "fullyQualifiedName": "ublk_err",
                                 "decoratedName": "ublk_err",
                                 "kind": "function",
                                 "index": 0},
                                {"name": "main",
                                 "fullyQualifiedName": "main",
                                 "decoratedName": "main",
                                 "kind": "function",
                                 "index": 1},
                                {"name": "ublk_ctrl_init",
                                 "fullyQualifiedName": "ublk_ctrl_init",
                                 "decoratedName": "ublk_ctrl_init",
                                 "kind": "function",
                                 "index": 2}]}]}
