changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/ffi/ublk/srv.lisp

changeset 686: 8e16efedfd76
child: c2f4e7ee921b
author: Richard Westhaver <ellis@rwest.io>
date: Sun, 29 Sep 2024 23:43:03 -0400
permissions: -rw-r--r--
description: prim work on ffi/ublk
1 ;;; ublk/srv.lisp --- ublksrv API
2 
3 ;;
4 
5 ;;; Code:
6 (in-package :ublk)
7 
8 (define-alien-type ublksrv-ctrl-dev (struct ublksrv-ctrl-dev))
9 
10 (define-alien-type ublksrv-queue
11  (struct ublksrv-queue
12  (q-id int)
13  (q-depth int)
14  (ring-ptr (* io-uring))
15  (dev (* ublksrv-dev))
16  (private-data (* t))))
17 
18 (define-alien-type ublk-io-data
19  (struct ublk-io-data
20  (tag int)
21  (pad unsigned-int)
22  (iod (* ublksrv-io-desc))
23  (private-data (* t))))
24 
25 ;; TODO 2024-09-29: add all of these as callbacks :C
26 ;; (define-alien-type ublksrv-tgt-type
27 ;; (struct ublksrv-tgt-type
28 ;; (handle-io-async (function int (* ublksrv-queue) (* ublk-io-data)))
29 ;; (tgt-io-done (function void (* ublksrv-queue) (* ublk-io-data) (* io-uring-cqe)))
30 ;; (handle-event (function void (* ublksrv-queue)))
31 ;; (handle-io-background (function void (* ublksrv-queue) int))
32 ;; (usage-for-add (function void))
33 ;; (init-tgt (function int (* ublksrv-dev) int int (array c-string)))
34 ;; (deinit-tgt (function void (* ublksrv-dev)))
35 ;; (alloc-io-buf (function (* t) (* ublksrv-queue) (* t) int))
36 ;; (idle-fn (function void (* ublksrv-queue) bool))
37 ;; (type int)
38 ;; (ublk-flags unsigned)
39 ;; (ublksrv-flags unsigned)
40 ;; (pad unsigned)
41 ;; (name c-string)
42 ;; (recovery-tgt (function int (* ublksrv-dev) int))
43 ;; (init-queue (function int (* ublksrv-queue) (* (* t))))
44 ;; (deinit-queue (function void (* ublksrv-queue)))
45 ;; (reserved (array unsigned-long 5))))
46 
47 (define-alien-type ublksrv-dev-data
48  (struct ublksrv-dev-data
49  (dev-id int)
50  (max-io-buf-bytes unsigned)
51  (nr-hw-queues unsigned-short)
52  (queue-depth unsigned-short)
53  (tgt-type c-string)
54  (tgt-ops (* ublksrv-tgt-type))
55  (tgt-argc int)
56  (tgt-argv (* (c-string)))
57  (run-dir c-string)
58  (flags unsigned-long)
59  (ublksrv-flags unsigned-long)
60  (reserved (array unsigned-long 7))))
61 
62 (define-alien-type ublksrv-tgt-info
63  (struct ublksrv-tgt-info
64  (dev-size unsigned-long-long)
65  (tgt-ring-depth unsigned-int)
66  (nr-fds unsigned-int)
67  (fds (array int #.+ublksrv-tgt-max-fds+))
68  (tgt-data (* t))
69  (extra-ios unsigned-int)
70  (io-data-size unsigned-int)
71  (ops (* ublksrv-tgt-type))
72  (iowq-max-workers (array unsigned-int 2))
73  (reserved (array unsigned-long 4))))
74 
75 (define-alien-type ublksrv-dev
76  (struct ublksrv-dev
77  (tgt ublksrv-tgt-info)))
78 
79 (define-alien-routine build-user-data (unsigned 64)
80  (tag unsigned)
81  (op unsigned)
82  (tgt-data unsigned)
83  (is-target-io unsigned))
84 
85 (define-alien-routine ublksrv-ctrl-deinit void
86  (dev (* ublksrv-ctrl-dev)))