-
Notifications
You must be signed in to change notification settings - Fork 2
/
dm-lsmt.c
162 lines (136 loc) · 3.58 KB
/
dm-lsmt.c
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// SPDX-License-Identifier: GPL-2.0
#include "dm-ovbd.h"
struct lsmt_dm_target {
struct dm_dev *dev[256];
struct vfile *lsmt;
struct vfile *bf[256];
unsigned int nr;
};
static int lsmt_target_map(struct dm_target *ti, struct bio *bio)
{
struct lsmt_dm_target *mdt = (struct lsmt_dm_target *)ti->private;
if (!mdt) {
pr_err("LSMT DM Target not ready!!\n");
return DM_MAPIO_REQUEUE;
}
switch (bio_op(bio)) {
case REQ_OP_READ:
return mdt->lsmt->ops->bio_remap((struct vfile *)mdt->lsmt, bio,
mdt->dev, mdt->nr);
default:
pr_err("DM_MAPIO_KILL %s:%d op=%d sts=%d\n", __FILE__, __LINE__,
bio_op(bio), bio->bi_status);
return DM_MAPIO_KILL;
}
}
static int lsmt_target_end_io(struct dm_target *ti, struct bio *bio,
blk_status_t *error)
{
if (bio->bi_status != BLK_STS_OK) {
pr_err("DONE NOT OK %s:%d op=%d sts=%d\n", __FILE__, __LINE__,
bio_op(bio), bio->bi_status);
return DM_ENDIO_REQUEUE;
}
return DM_ENDIO_DONE;
}
static int lsmt_target_ctr(struct dm_target *ti, unsigned int argc, char **argv)
{
struct lsmt_dm_target *mdt;
const char *devname;
const char *tail;
struct dm_arg_set args = { .argc = argc, .argv = argv };
size_t len;
int ret;
int i;
pr_debug("\n >>in function %s\n", __func__);
if (argc < 2) {
pr_warn("\n Invalid no.of arguments.\n");
ti->error = "Invalid argument count";
return -EINVAL;
}
mdt = kmalloc(sizeof(*mdt), GFP_KERNEL);
if (!mdt) {
ti->error = "dm-lsmt_target: Cannot allocate context";
return -ENOMEM;
}
for (i = 0; args.argc >= 2; i++) {
devname = dm_shift_arg(&args);
tail = dm_shift_arg(&args);
ret = kstrtoul(tail, 10, &len);
if (ret < 0) {
pr_warn("Invalid parameter");
goto error_out;
}
pr_info("\nlsmt-md: load dev %s\n", devname);
if (dm_get_device(ti, devname, dm_table_get_mode(ti->table),
&mdt->dev[i])) {
ti->error = "dm-lsmt_target: Device lookup failed";
goto bad;
}
if (!mdt->dev[i] || !mdt->dev[i]->bdev) {
pr_warn("failed to get mdt dev or bdev\n");
goto error_out;
}
mdt->bf[i] = open_blkdev_as_vfile(mdt->dev[i]->bdev, len);
pr_info("lsmt: file %d size %lu", i,
mdt->bf[i]->ops->len(mdt->bf[i]));
}
mdt->nr = i;
mdt->lsmt = lsmt_open_files(mdt->bf, 1);
if (!mdt->lsmt) {
pr_crit("Failed to open lsmt file");
goto error_out;
}
pr_info("dm-lsmt: blk size is %lu\n",
mdt->lsmt->ops->len((struct vfile *)mdt->lsmt));
ti->private = mdt;
pr_debug("\n>>out function %s\n", __func__);
return 0;
error_out:
for (i = 0; i < mdt->nr; i++) {
if (mdt->bf[i])
mdt->bf[i]->ops->close((struct vfile *)mdt->bf[i]);
}
for (i = 0; i < mdt->nr; i++) {
if (mdt->dev[i])
dm_put_device(ti, mdt->dev[i]);
}
bad:
kfree(mdt);
pr_debug("\n>>out function %s with error\n", __func__);
return -EINVAL;
}
static void lsmt_target_dtr(struct dm_target *ti)
{
struct lsmt_dm_target *mdt = (struct lsmt_dm_target *)ti->private;
unsigned int i = 0;
pr_debug("\n<<in function %s\n", __func__);
if (mdt->lsmt)
mdt->lsmt->ops->close((struct vfile *)mdt->lsmt);
for (i = 0; i < mdt->nr; i++)
dm_put_device(ti, mdt->dev[i]);
kfree(mdt);
pr_debug("\n>>out function %s\n", __func__);
}
static struct target_type lsmt_target = {
.features = 0,
.name = "lsmt_target",
.version = { 1, 0, 0 },
.module = THIS_MODULE,
.ctr = lsmt_target_ctr,
.dtr = lsmt_target_dtr,
.map = lsmt_target_map,
.end_io = lsmt_target_end_io,
};
int init_lsmt_target(void)
{
int result;
result = dm_register_target(&lsmt_target);
if (result < 0)
pr_warn("\n Error in registering target\n");
return 0;
}
void cleanup_lsmt_target(void)
{
dm_unregister_target(&lsmt_target);
}