forked from ublk-org/ublksrv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tgt_null.cpp
84 lines (65 loc) · 1.97 KB
/
tgt_null.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// SPDX-License-Identifier: MIT or GPL-2.0-only
#include <config.h>
#include "ublksrv_tgt.h"
static int null_init_tgt(struct ublksrv_dev *dev, int type, int argc,
char *argv[])
{
struct ublksrv_tgt_info *tgt = &dev->tgt;
const struct ublksrv_ctrl_dev_info *info = &dev->ctrl_dev->dev_info;
int jbuf_size;
char *jbuf = ublksrv_tgt_return_json_buf(dev, &jbuf_size);
struct ublksrv_tgt_base_json tgt_json = {
.type = type,
};
unsigned long long dev_size = 250UL * 1024 * 1024 * 1024;
struct ublk_params p = {
.types = UBLK_PARAM_TYPE_BASIC,
.basic = {
.logical_bs_shift = 9,
.physical_bs_shift = 12,
.io_opt_shift = 12,
.io_min_shift = 9,
.max_sectors = info->max_io_buf_bytes >> 9,
.dev_sectors = dev_size >> 9,
},
};
int ret;
strcpy(tgt_json.name, "null");
if (type != UBLKSRV_TGT_TYPE_NULL)
return -1;
tgt_json.dev_size = tgt->dev_size = dev_size;
tgt->tgt_ring_depth = info->queue_depth;
tgt->nr_fds = 0;
ublksrv_json_write_dev_info(dev->ctrl_dev, jbuf, jbuf_size);
ublksrv_json_write_target_base_info(jbuf, jbuf_size, &tgt_json);
do {
ret = ublksrv_json_write_params(&p, jbuf, jbuf_size);
if (ret < 0)
jbuf = ublksrv_tgt_realloc_json_buf(dev, &jbuf_size);
} while (ret < 0);
return 0;
}
static co_io_job __null_handle_io_async(struct ublksrv_queue *q,
struct ublk_io *io, int tag)
{
const struct ublksrv_io_desc *iod = ublksrv_get_iod(q, tag);
ublksrv_complete_io(q, tag, iod->nr_sectors << 9);
co_io_job_return();
}
static int null_handle_io_async(struct ublksrv_queue *q, int tag)
{
struct ublk_io_tgt *io = (struct ublk_io_tgt *)&q->ios[tag];
io->co = __null_handle_io_async(q, (struct ublk_io *)io, tag);
return 0;
}
struct ublksrv_tgt_type null_tgt_type = {
.handle_io_async = null_handle_io_async,
.init_tgt = null_init_tgt,
.type = UBLKSRV_TGT_TYPE_NULL,
.name = "null",
};
static void tgt_null_init() __attribute__((constructor));
static void tgt_null_init(void)
{
ublksrv_register_tgt_type(&null_tgt_type);
}