2 // Copyright (C) 2019 Red Hat Inc.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
15 // * Neither the name of Red Hat nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without
17 // specific prior written permission.
19 // THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
20 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
23 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 use std::os::raw::{c_char, c_int, c_void};
35 // This struct describes the plugin ABI which your plugin_init()
36 // function must return.
43 pub name: *const c_char,
44 pub longname: *const c_char,
45 pub version: *const c_char,
46 pub description: *const c_char,
48 pub load: Option<extern fn ()>,
49 pub unload: Option<extern fn ()>,
51 pub config: Option<extern fn (*const c_char, *const c_char)>,
52 pub config_complete: Option<extern fn () -> c_int>,
53 pub config_help: *const c_char,
55 pub open: extern fn (c_int) -> *mut c_void,
56 pub close: Option<extern fn (*mut c_void)>,
58 pub get_size: extern fn (*mut c_void) -> i64,
60 pub can_write: Option<extern fn (*mut c_void) -> c_int>,
61 pub can_flush: Option<extern fn (*mut c_void) -> c_int>,
62 pub is_rotational: Option<extern fn (*mut c_void) -> c_int>,
63 pub can_trim: Option<extern fn (*mut c_void) -> c_int>,
65 // Slots for old v1 API functions.
66 _pread_old: Option<extern fn ()>,
67 _pwrite_old: Option<extern fn ()>,
68 _flush_old: Option<extern fn ()>,
69 _trim_old: Option<extern fn ()>,
70 _zero_old: Option<extern fn ()>,
72 errno_is_preserved: c_int,
74 pub dump_plugin: Option<extern fn ()>,
76 pub can_zero: Option<extern fn (*mut c_void) -> c_int>,
77 pub can_fua: Option<extern fn (*mut c_void) -> c_int>,
79 pub pread: extern fn (h: *mut c_void, buf: *mut c_char, count: u32,
82 pub pwrite: Option<extern fn (h: *mut c_void, buf: *const c_char,
83 count: u32, offset: u64,
84 flags: u32) -> c_int>,
85 pub flush: Option<extern fn (h: *mut c_void, flags: u32) -> c_int>,
86 pub trim: Option<extern fn (h: *mut c_void,
87 count: u32, offset: u64,
88 flags: u32) -> c_int>,
89 pub zero: Option<extern fn (h: *mut c_void,
90 count: u32, offset: u64,
91 flags: u32) -> c_int>,
93 pub magic_config_key: *const c_char,
95 pub can_multi_conn: Option<extern fn (h: *mut c_void) -> c_int>,
97 // Slots for extents functions, which needs more integration.
98 _can_extents: Option<extern fn ()>,
99 _extents: Option<extern fn ()>,
101 pub can_cache: Option<extern fn (h: *mut c_void) -> c_int>,
102 pub cache: Option<extern fn (h: *mut c_void,
103 count: u32, offset: u64,
104 flags: u32) -> c_int>,
107 pub enum ThreadModel {
108 SerializeConnections = 0,
109 SerializeAllRequests = 1,
110 SerializeRequests = 2,
115 pub fn new (thread_model: ThreadModel,
117 open: extern fn (c_int) -> *mut c_void,
118 get_size: extern fn (*mut c_void) -> i64,
119 pread: extern fn (h: *mut c_void, buf: *mut c_char,
120 count: u32, offset: u64,
121 flags: u32) -> c_int) -> Plugin {
123 _struct_size: mem::size_of::<Plugin>() as u64,
125 _thread_model: thread_model as c_int,
127 longname: std::ptr::null(),
128 version: std::ptr::null(),
129 description: std::ptr::null(),
133 config_complete: None,
134 config_help: std::ptr::null(),
147 errno_is_preserved: 0,
156 magic_config_key: std::ptr::null(),
157 can_multi_conn: None,