forked from open-iscsi/tcmu-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtcmu-runner.h
167 lines (145 loc) · 4.61 KB
/
tcmu-runner.h
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
163
164
165
166
167
/*
* Copyright 2014, Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
/*
* This header defines the interface between tcmu-runner and its loadable
* subtype handlers.
*/
#ifndef __TCMU_RUNNER_H
#define __TCMU_RUNNER_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
#include <sys/uio.h>
#include "scsi_defs.h"
#include "libtcmu_log.h"
#include "libtcmu_common.h"
#include "alua.h"
typedef int (*rw_fn_t)(struct tcmu_device *, struct tcmulib_cmd *,
struct iovec *, size_t, size_t, off_t);
typedef int (*flush_fn_t)(struct tcmu_device *, struct tcmulib_cmd *);
typedef int (*handle_cmd_fn_t)(struct tcmu_device *, struct tcmulib_cmd *);
typedef int (*unmap_fn_t)(struct tcmu_device *dev, struct tcmulib_cmd *cmd,
uint64_t off, uint64_t len);
struct tcmulib_cfg_info;
enum {
TCMUR_LOCK_SUCCESS,
TCMUR_LOCK_FAILED,
TCMUR_LOCK_NOTCONN,
TCMUR_LOCK_BLACKLISTED,
};
struct tcmur_handler {
const char *name; /* Human-friendly name */
const char *subtype; /* Name for cfgstring matching */
const char *cfg_desc; /* Description of this backstore's config string */
void *opaque; /* Handler private data. */
/*
* As much as possible, check that the cfgstring will result
* in a working device when given to us as dev->cfgstring in
* the ->open() call.
*
* This function is optional but gives configuration tools a
* chance to warn users in advance if the device they're
* trying to create is invalid.
*
* Returns true if string is valid. Only if false, set *reason
* to a string that says why. The string will be free()ed.
* Suggest using asprintf().
*/
bool (*check_config)(const char *cfgstring, char **reason);
int (*reconfig)(struct tcmu_device *dev, struct tcmulib_cfg_info *cfg);
/* Per-device added/removed callbacks */
int (*open)(struct tcmu_device *dev);
void (*close)(struct tcmu_device *dev);
/*
* If > 0, runner will execute up to nr_threads IO callouts from
* threads.
* if 0, runner will call IO callouts from the cmd proc thread or
* completion context for compound commands.
*/
int nr_threads;
/*
* Async handle_cmd only handlers return:
*
* - SCSI status if handled (either good/bad)
* - TCMU_NOT_HANDLED if opcode is not handled
* - TCMU_ASYNC_HANDLED if opcode is handled asynchronously
*
* Handlers that set nr_threads > 0 and async handlers
* that implement handle_cmd and the IO callouts below return:
*
* 0 if the handler has queued the command.
* - TCMU_NOT_HANDLED if the command is not supported.
* - SAM_STAT_TASK_SET_FULL if the handler was not able to allocate
* resources for the command.
*
* If 0 is returned the handler must call the tcmulib_cmd->done
* function with SAM_STAT_GOOD or a SAM status code and set the
* the sense asc/ascq if needed.
*/
handle_cmd_fn_t handle_cmd;
/*
* Below callbacks are only exected called by generic_handle_cmd.
* Returns:
* - 0 if the handler has queued the command.
* - SAM_STAT_TASK_SET_FULL if the handler was not able to allocate
* resources for the command.
*
* If 0 is returned the handler must call the tcmulib_cmd->done
* function with SAM_STAT_GOOD or a SAM status code and set the
* the sense asc/ascq if needed.
*/
rw_fn_t write;
rw_fn_t read;
flush_fn_t flush;
unmap_fn_t unmap;
/*
* Must return a TCMUR_LOCK return value.
*/
int (*lock)(struct tcmu_device *dev);
/*
* Must return TCMUR_DEV_LOCK state value.
*/
int (*get_lock_state)(struct tcmu_device *dev);
/*
* internal field, don't touch this
*
* indicates to tcmu-runner whether this is an internal handler loaded
* via dlopen or an external handler registered via dbus. In the
* latter case opaque will point to a struct dbus_info.
*/
bool _is_dbus_handler;
};
/*
* Each tcmu-runner (tcmur) handler plugin must export the
* following. It usually just calls tcmur_register_handler.
*
* int handler_init(void);
*/
/*
* APIs for tcmur only
*/
int tcmur_register_handler(struct tcmur_handler *handler);
bool tcmur_unregister_handler(struct tcmur_handler *handler);
/*
* Misc
*/
void tcmu_cancel_thread(pthread_t thread);
#ifdef __cplusplus
}
#endif
#endif