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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
def set_vhost_controller_coalescing(client, ctrlr, delay_base_us, iops_threshold):
"""Set coalescing for vhost controller.
Args:
ctrlr: controller name
delay_base_us: base delay time
iops_threshold: IOPS threshold when coalescing is enabled
"""
params = {
'ctrlr': ctrlr,
'delay_base_us': delay_base_us,
'iops_threshold': iops_threshold,
}
return client.call('set_vhost_controller_coalescing', params)
def construct_vhost_scsi_controller(client, ctrlr, cpumask=None):
"""Construct a vhost scsi controller.
Args:
ctrlr: controller name
cpumask: cpu mask for this controller
"""
params = {'ctrlr': ctrlr}
if cpumask:
params['cpumask'] = cpumask
return client.call('construct_vhost_scsi_controller', params)
def add_vhost_scsi_lun(client, ctrlr, scsi_target_num, bdev_name):
"""Add LUN to vhost scsi controller target.
Args:
ctrlr: controller name
scsi_target_num: target number to use
bdev_name: name of bdev to add to target
"""
params = {
'ctrlr': ctrlr,
'scsi_target_num': scsi_target_num,
'bdev_name': bdev_name,
}
return client.call('add_vhost_scsi_lun', params)
def remove_vhost_scsi_target(client, ctrlr, scsi_target_num):
"""Remove target from vhost scsi controller.
Args:
ctrlr: controller name to remove target from
scsi_target_num: number of target to remove from controller
"""
params = {
'ctrlr': ctrlr,
'scsi_target_num': scsi_target_num
}
return client.call('remove_vhost_scsi_target', params)
def construct_vhost_nvme_controller(client, ctrlr, io_queues, cpumask=None):
"""Construct vhost NVMe controller.
Args:
ctrlr: controller name
io_queues: number of IO queues for the controller
cpumask: cpu mask for this controller
"""
params = {
'ctrlr': ctrlr,
'io_queues': io_queues
}
if cpumask:
params['cpumask'] = cpumask
return client.call('construct_vhost_nvme_controller', params)
def add_vhost_nvme_ns(client, ctrlr, bdev_name):
"""Add namespace to vhost nvme controller.
Args:
ctrlr: controller name where to add a namespace
bdev_name: block device name for a new namespace
"""
params = {
'ctrlr': ctrlr,
'bdev_name': bdev_name,
}
return client.call('add_vhost_nvme_ns', params)
def construct_vhost_blk_controller(client, ctrlr, dev_name, cpumask=None, readonly=None):
"""Construct vhost BLK controller.
Args:
ctrlr: controller name
dev_name: device name to add to controller
cpumask: cpu mask for this controller
readonly: set controller as read-only
"""
params = {
'ctrlr': ctrlr,
'dev_name': dev_name,
}
if cpumask:
params['cpumask'] = cpumask
if readonly:
params['readonly'] = readonly
return client.call('construct_vhost_blk_controller', params)
def get_vhost_controllers(client, name=None):
"""Get information about configured vhost controllers.
Args:
name: controller name to query (optional; if omitted, query all controllers)
Returns:
List of vhost controllers.
"""
params = {}
if name:
params['name'] = name
return client.call('get_vhost_controllers', params)
def remove_vhost_controller(client, ctrlr):
"""Remove vhost controller from configuration.
Args:
ctrlr: controller name to remove
"""
params = {'ctrlr': ctrlr}
return client.call('remove_vhost_controller', params)
def construct_virtio_dev(client, name, trtype, traddr, dev_type, vq_count=None, vq_size=None):
"""Construct new virtio device using provided
transport type and device type.
Args:
name: name base for new created bdevs
trtype: virtio target transport type: pci or user
traddr: transport type specific target address: e.g. UNIX
domain socket path or BDF
dev_type: device type: blk or scsi
vq_count: number of virtual queues to be used
vq_size: size of each queue
"""
params = {
'name': name,
'trtype': trtype,
'traddr': traddr,
'dev_type': dev_type
}
if vq_count:
params['vq_count'] = vq_count
if vq_size:
params['vq_size'] = vq_size
return client.call('construct_virtio_dev', params)
def construct_virtio_user_scsi_bdev(client, path, name, vq_count=None, vq_size=None):
"""Connect to virtio user scsi device.
Args:
path: path to Virtio SCSI socket
name: use this name as base instead of 'VirtioScsiN'
vq_count: number of virtual queues to be used
vq_size: size of each queue
"""
params = {
'path': path,
'name': name,
}
if vq_count:
params['vq_count'] = vq_count
if vq_size:
params['vq_size'] = vq_size
return client.call('construct_virtio_user_scsi_bdev', params)
def construct_virtio_pci_scsi_bdev(client, pci_address, name):
"""Create a Virtio SCSI device from a virtio-pci device.
Args:
pci_address: PCI address in domain:bus:device.function format or
domain.bus.device.function format
name: Name for the virtio device. It will be inhereted by all created
bdevs, which are named n the following format:
<name>t<target_id>
"""
params = {
'pci_address': pci_address,
'name': name,
}
return client.call('construct_virtio_pci_scsi_bdev', params)
def remove_virtio_scsi_bdev(client, name):
"""Remove a Virtio-SCSI device
This will delete all bdevs exposed by this device.
Args:
name: virtio device name
"""
params = {'name': name}
return client.call('remove_virtio_scsi_bdev', params)
def remove_virtio_bdev(client, name):
"""Remove a Virtio device
This will delete all bdevs exposed by this device.
Args:
name: virtio device name
"""
params = {'name': name}
return client.call('remove_virtio_bdev', params)
def get_virtio_scsi_devs(client):
"""Get list of virtio scsi devices."""
return client.call('get_virtio_scsi_devs')
def construct_virtio_user_blk_bdev(client, path, name, vq_count=None, vq_size=None):
"""Connect to virtio user BLK device.
Args:
path: path to Virtio BLK socket
name: use this name as base instead of 'VirtioScsiN'
vq_count: number of virtual queues to be used
vq_size: size of each queue
"""
params = {
'path': path,
'name': name,
}
if vq_count:
params['vq_count'] = vq_count
if vq_size:
params['vq_size'] = vq_size
return client.call('construct_virtio_user_blk_bdev', params)
def construct_virtio_pci_blk_bdev(client, pci_address, name):
"""Create a Virtio Blk device from a virtio-pci device.
Args:
pci_address: PCI address in domain:bus:device.function format or
domain.bus.device.function format
name: name for the blk device
"""
params = {
'pci_address': pci_address,
'name': name,
}
return client.call('construct_virtio_pci_blk_bdev', params)
|