1# SPDX-License-Identifier: BSD-3-Clause 2# Copyright (C) 2017 Intel Corporation. 3# All rights reserved. 4# Copyright (c) 2022 Dell Inc, or its subsidiaries. 5# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 6 7 8def bdev_set_options(client, bdev_io_pool_size=None, bdev_io_cache_size=None, 9 bdev_auto_examine=None, iobuf_small_cache_size=None, 10 iobuf_large_cache_size=None): 11 """Set parameters for the bdev subsystem. 12 Args: 13 bdev_io_pool_size: number of bdev_io structures in shared buffer pool (optional) 14 bdev_io_cache_size: maximum number of bdev_io structures cached per thread (optional) 15 bdev_auto_examine: if set to false, the bdev layer will not examine every disks automatically (optional) 16 iobuf_small_cache_size: size of the small iobuf per thread cache 17 iobuf_large_cache_size: size of the large iobuf per thread cache 18 """ 19 params = dict() 20 if bdev_io_pool_size is not None: 21 params['bdev_io_pool_size'] = bdev_io_pool_size 22 if bdev_io_cache_size is not None: 23 params['bdev_io_cache_size'] = bdev_io_cache_size 24 if bdev_auto_examine is not None: 25 params['bdev_auto_examine'] = bdev_auto_examine 26 if iobuf_small_cache_size is not None: 27 params['iobuf_small_cache_size'] = iobuf_small_cache_size 28 if iobuf_large_cache_size is not None: 29 params['iobuf_large_cache_size'] = iobuf_large_cache_size 30 return client.call('bdev_set_options', params) 31 32 33def bdev_examine(client, name): 34 """Examine a bdev manually. If the bdev does not exist yet when this RPC is called, 35 it will be examined when it is created 36 Args: 37 name: name of the bdev 38 """ 39 params = dict() 40 params['name'] = name 41 return client.call('bdev_examine', params) 42 43 44def bdev_wait_for_examine(client): 45 """Report when all bdevs have been examined 46 """ 47 return client.call('bdev_wait_for_examine') 48 49 50def bdev_compress_create(client, base_bdev_name, pm_path, lb_size=None): 51 """Construct a compress virtual block device. 52 Args: 53 base_bdev_name: name of the underlying base bdev 54 pm_path: path to persistent memory 55 lb_size: logical block size for the compressed vol in bytes. Must be 4K or 512. 56 Returns: 57 Name of created virtual block device. 58 """ 59 params = dict() 60 params['base_bdev_name'] = base_bdev_name 61 params['pm_path'] = pm_path 62 if lb_size is not None: 63 params['lb_size'] = lb_size 64 return client.call('bdev_compress_create', params) 65 66 67def bdev_compress_delete(client, name): 68 """Delete compress virtual block device. 69 Args: 70 name: name of compress vbdev to delete 71 """ 72 params = dict() 73 params['name'] = name 74 return client.call('bdev_compress_delete', params) 75 76 77def bdev_compress_get_orphans(client, name=None): 78 """Get a list of comp bdevs that do not have a pmem file (aka orphaned). 79 Args: 80 name: comp bdev name to query (optional; if omitted, query all comp bdevs) 81 Returns: 82 List of comp bdev names. 83 """ 84 params = dict() 85 if name is not None: 86 params['name'] = name 87 return client.call('bdev_compress_get_orphans', params) 88 89 90def bdev_crypto_create(client, base_bdev_name, name, crypto_pmd=None, key=None, cipher=None, key2=None, key_name=None): 91 """Construct a crypto virtual block device. 92 Args: 93 base_bdev_name: name of the underlying base bdev 94 name: name for the crypto vbdev 95 crypto_pmd: name of the DPDK crypto driver to use 96 key: key 97 cipher: crypto algorithm to use 98 key2: Optional second part of the key 99 key_name: The key name to use in crypto operations 100 Returns: 101 Name of created virtual block device. 102 """ 103 params = dict() 104 params['base_bdev_name'] = base_bdev_name 105 params['name'] = name 106 if crypto_pmd is not None: 107 params['crypto_pmd'] = crypto_pmd 108 if key is not None: 109 params['key'] = key 110 if cipher is not None: 111 params['cipher'] = cipher 112 if key2 is not None: 113 params['key2'] = key2 114 if key_name is not None: 115 params['key_name'] = key_name 116 return client.call('bdev_crypto_create', params) 117 118 119def bdev_crypto_delete(client, name): 120 """Delete crypto virtual block device. 121 Args: 122 name: name of crypto vbdev to delete 123 """ 124 params = dict() 125 params['name'] = name 126 return client.call('bdev_crypto_delete', params) 127 128 129def bdev_ocf_create(client, name, mode, cache_bdev_name, core_bdev_name, cache_line_size=None): 130 """Add an OCF block device 131 Args: 132 name: name of constructed OCF bdev 133 mode: OCF cache mode: {'wb', 'wt', 'pt', 'wa', 'wi', 'wo'} 134 cache_bdev_name: name of underlying cache bdev 135 core_bdev_name: name of underlying core bdev 136 cache_line_size: OCF cache line size. The unit is KiB: {4, 8, 16, 32, 64} 137 Returns: 138 Name of created block device 139 """ 140 params = dict() 141 params['name'] = name 142 params['mode'] = mode 143 params['cache_bdev_name'] = cache_bdev_name 144 params['core_bdev_name'] = core_bdev_name 145 if cache_line_size is not None: 146 params['cache_line_size'] = cache_line_size 147 return client.call('bdev_ocf_create', params) 148 149 150def bdev_ocf_delete(client, name): 151 """Delete an OCF device 152 Args: 153 name: name of OCF bdev 154 """ 155 params = dict() 156 params['name'] = name 157 return client.call('bdev_ocf_delete', params) 158 159 160def bdev_ocf_get_stats(client, name): 161 """Get statistics of chosen OCF block device 162 Args: 163 name: name of OCF bdev 164 Returns: 165 Statistics as json object 166 """ 167 params = dict() 168 params['name'] = name 169 return client.call('bdev_ocf_get_stats', params) 170 171 172def bdev_ocf_reset_stats(client, name): 173 """Reset statistics of chosen OCF block device 174 Args: 175 name: name of OCF bdev 176 Returns: 177 None 178 """ 179 params = dict() 180 params['name'] = name 181 return client.call('bdev_ocf_reset_stats', params) 182 183 184def bdev_ocf_get_bdevs(client, name=None): 185 """Get list of OCF devices including unregistered ones 186 Args: 187 name: name of OCF vbdev or name of cache device or name of core device (optional) 188 Returns: 189 Array of OCF devices with their current status 190 """ 191 params = dict() 192 if name is not None: 193 params['name'] = name 194 return client.call('bdev_ocf_get_bdevs', params) 195 196 197def bdev_ocf_set_cache_mode(client, name, mode): 198 """Set cache mode of OCF block device 199 Args: 200 name: name of OCF bdev 201 mode: OCF cache mode: {'wb', 'wt', 'pt', 'wa', 'wi', 'wo'} 202 Returns: 203 New cache mode name 204 """ 205 params = dict() 206 params['name'] = name 207 params['mode'] = mode 208 return client.call('bdev_ocf_set_cache_mode', params) 209 210 211def bdev_ocf_set_seqcutoff(client, name, policy, threshold=None, promotion_count=None): 212 """Set sequential cutoff parameters on all cores for the given OCF cache device 213 Args: 214 name: Name of OCF cache bdev 215 policy: Sequential cutoff policy 216 threshold: Activation threshold [KiB] (optional) 217 promotion_count: Promotion request count (optional) 218 """ 219 params = dict() 220 params['name'] = name 221 params['policy'] = policy 222 if threshold is not None: 223 params['threshold'] = threshold 224 if promotion_count is not None: 225 params['promotion_count'] = promotion_count 226 return client.call('bdev_ocf_set_seqcutoff', params) 227 228 229def bdev_ocf_flush_start(client, name): 230 """Start flushing OCF cache device 231 Args: 232 name: name of OCF bdev 233 """ 234 params = dict() 235 params['name'] = name 236 return client.call('bdev_ocf_flush_start', params) 237 238 239def bdev_ocf_flush_status(client, name): 240 """Get flush status of OCF cache device 241 Args: 242 name: name of OCF bdev 243 Returns: 244 Flush status 245 """ 246 params = dict() 247 params['name'] = name 248 return client.call('bdev_ocf_flush_status', params) 249 250 251def bdev_malloc_create(client, num_blocks, block_size, physical_block_size=None, name=None, uuid=None, optimal_io_boundary=None, 252 md_size=None, md_interleave=None, dif_type=None, dif_is_head_of_md=None): 253 """Construct a malloc block device. 254 Args: 255 num_blocks: size of block device in blocks 256 block_size: Data block size of device; must be a power of 2 and at least 512 257 physical_block_size: Physical block size of device; must be a power of 2 and at least 512 (optional) 258 name: name of block device (optional) 259 uuid: UUID of block device (optional) 260 optimal_io_boundary: Split on optimal IO boundary, in number of blocks, default 0 (disabled, optional) 261 md_size: metadata size of device (0, 8, 16, 32, 64, or 128), default 0 (optional) 262 md_interleave: metadata location, interleaved if set, and separated if omitted (optional) 263 dif_type: protection information type (optional) 264 dif_is_head_of_md: protection information is in the first 8 bytes of metadata (optional) 265 Returns: 266 Name of created block device. 267 """ 268 params = dict() 269 params['num_blocks'] = num_blocks 270 params['block_size'] = block_size 271 if physical_block_size is not None: 272 params['physical_block_size'] = physical_block_size 273 if name is not None: 274 params['name'] = name 275 if uuid is not None: 276 params['uuid'] = uuid 277 if optimal_io_boundary is not None: 278 params['optimal_io_boundary'] = optimal_io_boundary 279 if md_size is not None: 280 params['md_size'] = md_size 281 if md_interleave is not None: 282 params['md_interleave'] = md_interleave 283 if dif_type is not None: 284 params['dif_type'] = dif_type 285 if dif_is_head_of_md is not None: 286 params['dif_is_head_of_md'] = dif_is_head_of_md 287 return client.call('bdev_malloc_create', params) 288 289 290def bdev_malloc_delete(client, name): 291 """Delete malloc block device. 292 Args: 293 bdev_name: name of malloc bdev to delete 294 """ 295 params = dict() 296 params['name'] = name 297 return client.call('bdev_malloc_delete', params) 298 299 300def bdev_null_create(client, num_blocks, block_size, name, physical_block_size=None, uuid=None, md_size=None, 301 dif_type=None, dif_is_head_of_md=None): 302 """Construct a null block device. 303 Args: 304 num_blocks: size of block device in blocks 305 block_size: block size of device; data part size must be a power of 2 and at least 512 306 name: name of block device 307 physical_block_size: physical block size of the device; data part size must be a power of 2 and at least 512 (optional) 308 uuid: UUID of block device (optional) 309 md_size: metadata size of device (optional) 310 dif_type: protection information type (optional) 311 dif_is_head_of_md: protection information is in the first 8 bytes of metadata (optional) 312 Returns: 313 Name of created block device. 314 """ 315 params = dict() 316 params['num_blocks'] = num_blocks 317 params['block_size'] = block_size 318 params['name'] = name 319 if physical_block_size is not None: 320 params['physical_block_size'] = physical_block_size 321 if uuid is not None: 322 params['uuid'] = uuid 323 if md_size is not None: 324 params['md_size'] = md_size 325 if dif_type is not None: 326 params['dif_type'] = dif_type 327 if dif_is_head_of_md is not None: 328 params['dif_is_head_of_md'] = dif_is_head_of_md 329 return client.call('bdev_null_create', params) 330 331 332def bdev_null_delete(client, name): 333 """Remove null bdev from the system. 334 Args: 335 name: name of null bdev to delete 336 """ 337 params = dict() 338 params['name'] = name 339 return client.call('bdev_null_delete', params) 340 341 342def bdev_null_resize(client, name, new_size): 343 """Resize null bdev in the system. 344 Args: 345 name: name of null bdev to resize 346 new_size: new bdev size of resize operation. The unit is MiB 347 """ 348 params = dict() 349 params['name'] = name 350 params['new_size'] = new_size 351 return client.call('bdev_null_resize', params) 352 353 354def bdev_raid_set_options(client, process_window_size_kb=None, process_max_bandwidth_mb_sec=None): 355 """Set options for bdev raid. 356 Args: 357 process_window_size_kb: Background process (e.g. rebuild) window size in KiB 358 process_max_bandwidth_mb_sec: Background process (e.g. rebuild) maximum bandwidth in MiB/Sec 359 """ 360 params = dict() 361 if process_window_size_kb is not None: 362 params['process_window_size_kb'] = process_window_size_kb 363 364 if process_max_bandwidth_mb_sec is not None: 365 params['process_max_bandwidth_mb_sec'] = process_max_bandwidth_mb_sec 366 367 return client.call('bdev_raid_set_options', params) 368 369 370def bdev_raid_get_bdevs(client, category): 371 """Get list of raid bdevs based on category 372 Args: 373 category: any one of all or online or configuring or offline 374 Returns: 375 List of raid bdev details 376 """ 377 params = dict() 378 params['category'] = category 379 return client.call('bdev_raid_get_bdevs', params) 380 381 382def bdev_raid_create(client, name, raid_level, base_bdevs, strip_size_kb=None, uuid=None, superblock=None): 383 """Create raid bdev. Either strip size arg will work but one is required. 384 Args: 385 name: user defined raid bdev name 386 raid_level: raid level of raid bdev, supported values 0 387 base_bdevs: Space separated names of Nvme bdevs in double quotes, like "Nvme0n1 Nvme1n1 Nvme2n1" 388 strip_size_kb: strip size of raid bdev in KB, supported values like 8, 16, 32, 64, 128, 256, etc 389 uuid: UUID for this raid bdev (optional) 390 superblock: information about raid bdev will be stored in superblock on each base bdev, 391 disabled by default due to backward compatibility 392 Returns: 393 None 394 """ 395 params = dict() 396 params['name'] = name 397 params['raid_level'] = raid_level 398 params['base_bdevs'] = base_bdevs 399 if strip_size_kb is not None: 400 params['strip_size_kb'] = strip_size_kb 401 if uuid is not None: 402 params['uuid'] = uuid 403 if superblock is not None: 404 params['superblock'] = superblock 405 return client.call('bdev_raid_create', params) 406 407 408def bdev_raid_delete(client, name): 409 """Delete raid bdev 410 Args: 411 name: raid bdev name 412 Returns: 413 None 414 """ 415 params = dict() 416 params['name'] = name 417 return client.call('bdev_raid_delete', params) 418 419 420def bdev_raid_add_base_bdev(client, base_bdev, raid_bdev): 421 """Add base bdev to existing raid bdev 422 Args: 423 base_bdev: base bdev name 424 raid_bdev: raid bdev name 425 Returns: 426 None 427 """ 428 params = dict() 429 params['base_bdev'] = base_bdev 430 params['raid_bdev'] = raid_bdev 431 return client.call('bdev_raid_add_base_bdev', params) 432 433 434def bdev_raid_remove_base_bdev(client, name): 435 """Remove base bdev from existing raid bdev 436 Args: 437 name: base bdev name 438 Returns: 439 None 440 """ 441 params = dict() 442 params['name'] = name 443 return client.call('bdev_raid_remove_base_bdev', params) 444 445 446def bdev_aio_create(client, filename, name, block_size=None, readonly=None, fallocate=None): 447 """Construct a Linux AIO block device. 448 Args: 449 filename: path to device or file (ex: /dev/sda) 450 name: name of block device 451 block_size: block size of device (optional; autodetected if omitted) 452 readonly: set aio bdev as read-only 453 fallocate: enable fallocate for UNMAP/WRITEZEROS support (note that fallocate syscall would block reactor) 454 Returns: 455 Name of created block device. 456 """ 457 params = dict() 458 params['filename'] = filename 459 params['name'] = name 460 if block_size is not None: 461 params['block_size'] = block_size 462 if readonly is not None: 463 params['readonly'] = readonly 464 if fallocate is not None: 465 params['fallocate'] = fallocate 466 return client.call('bdev_aio_create', params) 467 468 469def bdev_aio_rescan(client, name): 470 """Rescan a Linux AIO block device. 471 Args: 472 name: name of aio bdev to rescan 473 """ 474 params = dict() 475 params['name'] = name 476 return client.call('bdev_aio_rescan', params) 477 478 479def bdev_aio_delete(client, name): 480 """Remove aio bdev from the system. 481 Args: 482 name: name of aio bdev to delete 483 """ 484 params = dict() 485 params['name'] = name 486 return client.call('bdev_aio_delete', params) 487 488 489def bdev_uring_create(client, filename, name, block_size=None, uuid=None): 490 """Create a bdev with Linux io_uring backend. 491 Args: 492 filename: path to device or file (ex: /dev/nvme0n1) 493 name: name of bdev 494 block_size: block size of device (optional; autodetected if omitted) 495 uuid: UUID of block device (optional) 496 Returns: 497 Name of created bdev. 498 """ 499 params = dict() 500 params['filename'] = filename 501 params['name'] = name 502 if block_size is not None: 503 params['block_size'] = block_size 504 if uuid is not None: 505 params['uuid'] = uuid 506 return client.call('bdev_uring_create', params) 507 508 509def bdev_uring_rescan(client, name): 510 """Rescan a Linux URING block device. 511 Args: 512 name: name of uring bdev to rescan 513 """ 514 params = dict() 515 params['name'] = name 516 return client.call('bdev_uring_rescan', params) 517 518 519def bdev_uring_delete(client, name): 520 """Delete a uring bdev. 521 Args: 522 name: name of uring bdev to delete 523 """ 524 params = dict() 525 params['name'] = name 526 return client.call('bdev_uring_delete', params) 527 528 529def bdev_xnvme_create(client, filename, name, io_mechanism, conserve_cpu=None): 530 """Create a bdev with xNVMe backend. 531 Args: 532 filename: path to device or file (ex: /dev/nvme0n1) 533 name: name of xNVMe bdev to create 534 io_mechanism: I/O mechanism to use (ex: io_uring, io_uring_cmd, etc.) 535 conserve_cpu: Whether or not to conserve CPU when polling (default: False) 536 Returns: 537 Name of created bdev. 538 """ 539 params = dict() 540 params['filename'] = filename 541 params['name'] = name 542 params['io_mechanism'] = io_mechanism 543 if conserve_cpu is not None: 544 params['conserve_cpu'] = conserve_cpu 545 return client.call('bdev_xnvme_create', params) 546 547 548def bdev_xnvme_delete(client, name): 549 """Delete a xNVMe bdev. 550 Args: 551 name: name of xNVMe bdev to delete 552 """ 553 params = dict() 554 params['name'] = name 555 return client.call('bdev_xnvme_delete', params) 556 557 558def bdev_nvme_set_options(client, action_on_timeout=None, timeout_us=None, timeout_admin_us=None, 559 keep_alive_timeout_ms=None, arbitration_burst=None, 560 low_priority_weight=None, medium_priority_weight=None, high_priority_weight=None, 561 nvme_adminq_poll_period_us=None, nvme_ioq_poll_period_us=None, io_queue_requests=None, 562 delay_cmd_submit=None, transport_retry_count=None, bdev_retry_count=None, 563 transport_ack_timeout=None, ctrlr_loss_timeout_sec=None, reconnect_delay_sec=None, 564 fast_io_fail_timeout_sec=None, disable_auto_failback=None, generate_uuids=None, 565 transport_tos=None, nvme_error_stat=None, rdma_srq_size=None, io_path_stat=None, 566 allow_accel_sequence=None, rdma_max_cq_size=None, rdma_cm_event_timeout_ms=None, 567 dhchap_digests=None, dhchap_dhgroups=None): 568 """Set options for the bdev nvme. This is startup command. 569 Args: 570 action_on_timeout: action to take on command time out. Valid values are: none, reset, abort (optional) 571 timeout_us: Timeout for each command, in microseconds. If 0, don't track timeouts (optional) 572 timeout_admin_us: Timeout for each admin command, in microseconds. If 0, treat same as io timeouts (optional) 573 keep_alive_timeout_ms: Keep alive timeout period in millisecond, default is 10s (optional) 574 arbitration_burst: The value is expressed as a power of two (optional) 575 low_priority_weight: The number of commands that may be executed from the low priority queue at one time (optional) 576 medium_priority_weight: The number of commands that may be executed from the medium priority queue at one time (optional) 577 high_priority_weight: The number of commands that may be executed from the high priority queue at one time (optional) 578 nvme_adminq_poll_period_us: How often the admin queue is polled for asynchronous events in microseconds (optional) 579 nvme_ioq_poll_period_us: How often to poll I/O queues for completions in microseconds (optional) 580 io_queue_requests: The number of requests allocated for each NVMe I/O queue. Default: 512 (optional) 581 delay_cmd_submit: Enable delayed NVMe command submission to allow batching of multiple commands (optional) 582 transport_retry_count: The number of attempts per I/O in the transport layer when an I/O fails (optional) 583 bdev_retry_count: The number of attempts per I/O in the bdev layer when an I/O fails. -1 means infinite retries. (optional) 584 transport_ack_timeout: Time to wait ack until packet retransmission for RDMA or until closes connection for TCP. 585 Range 0-31 where 0 is driver-specific default value (optional) 586 ctrlr_loss_timeout_sec: Time to wait until ctrlr is reconnected before deleting ctrlr. 587 -1 means infinite reconnect retries. 0 means no reconnect retry. 588 If reconnect_delay_sec is zero, ctrlr_loss_timeout_sec has to be zero. 589 If reconnect_delay_sec is non-zero, ctrlr_loss_timeout_sec has to be -1 or not less than reconnect_delay_sec. 590 This can be overridden by bdev_nvme_attach_controller. (optional) 591 reconnect_delay_sec: Time to delay a reconnect retry. 592 If ctrlr_loss_timeout_sec is zero, reconnect_delay_sec has to be zero. 593 If ctrlr_loss_timeout_sec is -1, reconnect_delay_sec has to be non-zero. 594 If ctrlr_loss_timeout_sec is not -1 or zero, reconnect_sec has to be non-zero and less than ctrlr_loss_timeout_sec. 595 This can be overridden by bdev_nvme_attach_controller. (optional) 596 fast_io_fail_timeout_sec: Time to wait until ctrlr is reconnected before failing I/O to ctrlr. 597 0 means no such timeout. 598 If fast_io_fail_timeout_sec is not zero, it has to be not less than reconnect_delay_sec and less than 599 ctrlr_loss_timeout_sec if ctrlr_loss_timeout_sec is not -1. 600 This can be overridden by bdev_nvme_attach_controller. (optional) 601 disable_auto_failback: Disable automatic failback. bdev_nvme_set_preferred_path can be used to do manual failback. 602 By default, immediately failback to the preferred I/O path if it is restored. (optional) 603 generate_uuids: Enable generation of unique identifiers for NVMe bdevs only if they do not provide UUID themselves. 604 These strings are based on device serial number and namespace ID and will always be the same for that device. 605 transport_tos: IPv4 Type of Service value. Only applicable for RDMA transports. 606 The default is 0 which means no TOS is applied. (optional) 607 nvme_error_stat: Enable collecting NVMe error counts. (optional) 608 rdma_srq_size: Set the size of a shared rdma receive queue. Default: 0 (disabled) (optional) 609 io_path_stat: Enable collection I/O path stat of each io path. (optional) 610 allow_accel_sequence: Allow NVMe bdevs to advertise support for accel sequences if the 611 controller also supports them. (optional) 612 rdma_max_cq_size: The maximum size of a rdma completion queue. Default: 0 (unlimited) (optional) 613 rdma_cm_event_timeout_ms: Time to wait for RDMA CM event. Only applicable for RDMA transports. 614 dhchap_digests: List of allowed DH-HMAC-CHAP digests. (optional) 615 dhchap_dhgroups: List of allowed DH-HMAC-CHAP DH groups. (optional) 616 """ 617 params = dict() 618 if action_on_timeout is not None: 619 params['action_on_timeout'] = action_on_timeout 620 if timeout_us is not None: 621 params['timeout_us'] = timeout_us 622 if timeout_admin_us is not None: 623 params['timeout_admin_us'] = timeout_admin_us 624 if keep_alive_timeout_ms is not None: 625 params['keep_alive_timeout_ms'] = keep_alive_timeout_ms 626 if arbitration_burst is not None: 627 params['arbitration_burst'] = arbitration_burst 628 if low_priority_weight is not None: 629 params['low_priority_weight'] = low_priority_weight 630 if medium_priority_weight is not None: 631 params['medium_priority_weight'] = medium_priority_weight 632 if high_priority_weight is not None: 633 params['high_priority_weight'] = high_priority_weight 634 if nvme_adminq_poll_period_us is not None: 635 params['nvme_adminq_poll_period_us'] = nvme_adminq_poll_period_us 636 if nvme_ioq_poll_period_us is not None: 637 params['nvme_ioq_poll_period_us'] = nvme_ioq_poll_period_us 638 if io_queue_requests is not None: 639 params['io_queue_requests'] = io_queue_requests 640 if delay_cmd_submit is not None: 641 params['delay_cmd_submit'] = delay_cmd_submit 642 if transport_retry_count is not None: 643 params['transport_retry_count'] = transport_retry_count 644 if bdev_retry_count is not None: 645 params['bdev_retry_count'] = bdev_retry_count 646 if transport_ack_timeout is not None: 647 params['transport_ack_timeout'] = transport_ack_timeout 648 if ctrlr_loss_timeout_sec is not None: 649 params['ctrlr_loss_timeout_sec'] = ctrlr_loss_timeout_sec 650 if reconnect_delay_sec is not None: 651 params['reconnect_delay_sec'] = reconnect_delay_sec 652 if fast_io_fail_timeout_sec is not None: 653 params['fast_io_fail_timeout_sec'] = fast_io_fail_timeout_sec 654 if disable_auto_failback is not None: 655 params['disable_auto_failback'] = disable_auto_failback 656 if generate_uuids is not None: 657 params['generate_uuids'] = generate_uuids 658 if transport_tos is not None: 659 params['transport_tos'] = transport_tos 660 if nvme_error_stat is not None: 661 params['nvme_error_stat'] = nvme_error_stat 662 if rdma_srq_size is not None: 663 params['rdma_srq_size'] = rdma_srq_size 664 if io_path_stat is not None: 665 params['io_path_stat'] = io_path_stat 666 if allow_accel_sequence is not None: 667 params['allow_accel_sequence'] = allow_accel_sequence 668 if rdma_max_cq_size is not None: 669 params['rdma_max_cq_size'] = rdma_max_cq_size 670 if rdma_cm_event_timeout_ms is not None: 671 params['rdma_cm_event_timeout_ms'] = rdma_cm_event_timeout_ms 672 if dhchap_digests is not None: 673 params['dhchap_digests'] = dhchap_digests 674 if dhchap_dhgroups is not None: 675 params['dhchap_dhgroups'] = dhchap_dhgroups 676 return client.call('bdev_nvme_set_options', params) 677 678 679def bdev_nvme_set_hotplug(client, enable, period_us=None): 680 """Set options for the bdev nvme. This is startup command. 681 Args: 682 enable: True to enable hotplug, False to disable. 683 period_us: how often the hotplug is processed for insert and remove events. Set 0 to reset to default. (optional) 684 """ 685 params = dict() 686 params['enable'] = enable 687 if period_us is not None: 688 params['period_us'] = period_us 689 return client.call('bdev_nvme_set_hotplug', params) 690 691 692def bdev_nvme_attach_controller(client, name, trtype, traddr, adrfam=None, trsvcid=None, 693 priority=None, subnqn=None, hostnqn=None, hostaddr=None, 694 hostsvcid=None, prchk_reftag=None, prchk_guard=None, 695 hdgst=None, ddgst=None, fabrics_connect_timeout_us=None, 696 multipath=None, num_io_queues=None, ctrlr_loss_timeout_sec=None, 697 reconnect_delay_sec=None, fast_io_fail_timeout_sec=None, 698 psk=None, max_bdevs=None, dhchap_key=None, dhchap_ctrlr_key=None): 699 """Construct block device for each NVMe namespace in the attached controller. 700 Args: 701 name: bdev name prefix; "n" + namespace ID will be appended to create unique names 702 trtype: transport type ("PCIe", "RDMA", "FC", "TCP") 703 traddr: transport address (PCI BDF or IP address) 704 adrfam: address family ("IPv4", "IPv6", "IB", or "FC") 705 trsvcid: transport service ID (port number for IP-based addresses) 706 priority: transport connection priority (Sock priority for TCP-based transports; optional) 707 subnqn: subsystem NQN to connect to (optional) 708 hostnqn: NQN to connect from (optional) 709 hostaddr: host transport address (IP address for IP-based transports, NULL for PCIe or FC; optional) 710 hostsvcid: host transport service ID (port number for IP-based transports, NULL for PCIe or FC; optional) 711 prchk_reftag: Enable checking of PI reference tag for I/O processing (optional) 712 prchk_guard: Enable checking of PI guard for I/O processing (optional) 713 hdgst: Enable TCP header digest (optional) 714 ddgst: Enable TCP data digest (optional) 715 fabrics_connect_timeout_us: Fabrics connect timeout in us (optional) 716 multipath: The behavior when multiple paths are created ("disable", "failover", or "multipath"; failover if not specified) 717 num_io_queues: The number of IO queues to request during initialization. (optional) 718 ctrlr_loss_timeout_sec: Time to wait until ctrlr is reconnected before deleting ctrlr. 719 -1 means infinite reconnect retries. 0 means no reconnect retry. 720 If reconnect_delay_sec is zero, ctrlr_loss_timeout_sec has to be zero. 721 If reconnect_delay_sec is non-zero, ctrlr_loss_timeout_sec has to be -1 or not less than reconnect_delay_sec. 722 (optional) 723 reconnect_delay_sec: Time to delay a reconnect retry. 724 If ctrlr_loss_timeout_sec is zero, reconnect_delay_sec has to be zero. 725 If ctrlr_loss_timeout_sec is -1, reconnect_delay_sec has to be non-zero. 726 If ctrlr_loss_timeout_sec is not -1 or zero, reconnect_sec has to be non-zero and less than ctrlr_loss_timeout_sec. 727 (optional) 728 fast_io_fail_timeout_sec: Time to wait until ctrlr is reconnected before failing I/O to ctrlr. 729 0 means no such timeout. 730 If fast_io_fail_timeout_sec is not zero, it has to be not less than reconnect_delay_sec and less than 731 ctrlr_loss_timeout_sec if ctrlr_loss_timeout_sec is not -1. (optional) 732 psk: Set PSK file path and enable TCP SSL socket implementation (optional) 733 max_bdevs: Size of the name array for newly created bdevs. Default is 128. (optional) 734 dhchap_key: DH-HMAC-CHAP key name. 735 dhchap_ctrlr_key: DH-HMAC-CHAP controller key name. 736 Returns: 737 Names of created block devices. 738 """ 739 params = dict() 740 params['name'] = name 741 params['trtype'] = trtype 742 params['traddr'] = traddr 743 if adrfam is not None: 744 params['adrfam'] = adrfam 745 if trsvcid is not None: 746 params['trsvcid'] = trsvcid 747 if priority is not None: 748 params['priority'] = priority 749 if subnqn is not None: 750 params['subnqn'] = subnqn 751 if hostnqn is not None: 752 params['hostnqn'] = hostnqn 753 if hostaddr is not None: 754 params['hostaddr'] = hostaddr 755 if hostsvcid is not None: 756 params['hostsvcid'] = hostsvcid 757 if prchk_reftag is not None: 758 params['prchk_reftag'] = prchk_reftag 759 if prchk_guard is not None: 760 params['prchk_guard'] = prchk_guard 761 if hdgst is not None: 762 params['hdgst'] = hdgst 763 if ddgst is not None: 764 params['ddgst'] = ddgst 765 if fabrics_connect_timeout_us is not None: 766 params['fabrics_connect_timeout_us'] = fabrics_connect_timeout_us 767 if multipath is not None: 768 params['multipath'] = multipath 769 if num_io_queues is not None: 770 params['num_io_queues'] = num_io_queues 771 if ctrlr_loss_timeout_sec is not None: 772 params['ctrlr_loss_timeout_sec'] = ctrlr_loss_timeout_sec 773 if reconnect_delay_sec is not None: 774 params['reconnect_delay_sec'] = reconnect_delay_sec 775 if fast_io_fail_timeout_sec is not None: 776 params['fast_io_fail_timeout_sec'] = fast_io_fail_timeout_sec 777 if psk is not None: 778 params['psk'] = psk 779 if max_bdevs is not None: 780 params['max_bdevs'] = max_bdevs 781 if dhchap_key is not None: 782 params['dhchap_key'] = dhchap_key 783 if dhchap_ctrlr_key is not None: 784 params['dhchap_ctrlr_key'] = dhchap_ctrlr_key 785 return client.call('bdev_nvme_attach_controller', params) 786 787 788def bdev_nvme_detach_controller(client, name, trtype=None, traddr=None, 789 adrfam=None, trsvcid=None, subnqn=None, 790 hostaddr=None, hostsvcid=None): 791 """Detach NVMe controller and delete any associated bdevs. Optionally, 792 If all of the transport ID options are specified, only remove that 793 transport path from the specified controller. If that is the only 794 available path for the controller, this will also result in the 795 controller being detached and the associated bdevs being deleted. 796 Args: 797 name: controller name 798 trtype: transport type ("PCIe", "RDMA") 799 traddr: transport address (PCI BDF or IP address) 800 adrfam: address family ("IPv4", "IPv6", "IB", or "FC") 801 trsvcid: transport service ID (port number for IP-based addresses) 802 subnqn: subsystem NQN to connect to (optional) 803 hostaddr: Host address (IP address) 804 hostsvcid: transport service ID on host side (port number) 805 """ 806 params = dict() 807 params['name'] = name 808 if trtype is not None: 809 params['trtype'] = trtype 810 if traddr is not None: 811 params['traddr'] = traddr 812 if adrfam is not None: 813 params['adrfam'] = adrfam 814 if trsvcid is not None: 815 params['trsvcid'] = trsvcid 816 if subnqn is not None: 817 params['subnqn'] = subnqn 818 if hostaddr is not None: 819 params['hostaddr'] = hostaddr 820 if hostsvcid is not None: 821 params['hostsvcid'] = hostsvcid 822 return client.call('bdev_nvme_detach_controller', params) 823 824 825def bdev_nvme_reset_controller(client, name, cntlid=None): 826 """Reset an NVMe controller or all NVMe controllers in an NVMe bdev controller. 827 Args: 828 name: controller name 829 cntlid: NVMe controller ID (optional) 830 """ 831 params = dict() 832 params['name'] = name 833 if cntlid is not None: 834 params['cntlid'] = cntlid 835 return client.call('bdev_nvme_reset_controller', params) 836 837 838def bdev_nvme_enable_controller(client, name, cntlid=None): 839 """Enable an NVMe controller or all NVMe controllers in an NVMe bdev controller. 840 Args: 841 name: controller name 842 cntlid: NVMe controller ID (optional) 843 """ 844 params = dict() 845 params['name'] = name 846 if cntlid is not None: 847 params['cntlid'] = cntlid 848 return client.call('bdev_nvme_enable_controller', params) 849 850 851def bdev_nvme_disable_controller(client, name, cntlid=None): 852 """Disable an NVMe controller or all NVMe controllers in an NVMe bdev controller. 853 Args: 854 name: controller name 855 cntlid: NVMe controller ID (optional) 856 """ 857 params = dict() 858 params['name'] = name 859 if cntlid is not None: 860 params['cntlid'] = cntlid 861 return client.call('bdev_nvme_disable_controller', params) 862 863 864def bdev_nvme_start_discovery(client, name, trtype, traddr, adrfam=None, trsvcid=None, 865 hostnqn=None, wait_for_attach=None, ctrlr_loss_timeout_sec=None, 866 reconnect_delay_sec=None, fast_io_fail_timeout_sec=None, 867 attach_timeout_ms=None): 868 """Start discovery with the specified discovery subsystem 869 Args: 870 name: bdev name prefix; "n" + namespace ID will be appended to create unique names 871 trtype: transport type ("PCIe", "RDMA", "FC", "TCP") 872 traddr: transport address (PCI BDF or IP address) 873 adrfam: address family ("IPv4", "IPv6", "IB", or "FC") 874 trsvcid: transport service ID (port number for IP-based addresses) 875 hostnqn: NQN to connect from (optional) 876 wait_for_attach: Wait to complete RPC until all discovered NVM subsystems have attached (optional) 877 ctrlr_loss_timeout_sec: Time to wait until ctrlr is reconnected before deleting ctrlr. 878 -1 means infinite reconnect retries. 0 means no reconnect retry. 879 If reconnect_delay_sec is zero, ctrlr_loss_timeout_sec has to be zero. 880 If reconnect_delay_sec is non-zero, ctrlr_loss_timeout_sec has to be -1 or not less than reconnect_delay_sec. 881 (optional) 882 reconnect_delay_sec: Time to delay a reconnect retry. 883 If ctrlr_loss_timeout_sec is zero, reconnect_delay_sec has to be zero. 884 If ctrlr_loss_timeout_sec is -1, reconnect_delay_sec has to be non-zero. 885 If ctrlr_loss_timeout_sec is not -1 or zero, reconnect_sec has to be non-zero and less than ctrlr_loss_timeout_sec. 886 (optional) 887 fast_io_fail_timeout_sec: Time to wait until ctrlr is reconnected before failing I/O to ctrlr. 888 0 means no such timeout. 889 If fast_io_fail_timeout_sec is not zero, it has to be not less than reconnect_delay_sec and less than 890 ctrlr_loss_timeout_sec if ctrlr_loss_timeout_sec is not -1. (optional) 891 attach_timeout_ms: Time to wait until the discovery and all discovered NVM subsystems are attached (optional) 892 """ 893 params = dict() 894 params['name'] = name 895 params['trtype'] = trtype 896 params['traddr'] = traddr 897 if adrfam is not None: 898 params['adrfam'] = adrfam 899 if trsvcid is not None: 900 params['trsvcid'] = trsvcid 901 if hostnqn is not None: 902 params['hostnqn'] = hostnqn 903 if wait_for_attach is not None: 904 params['wait_for_attach'] = wait_for_attach 905 if ctrlr_loss_timeout_sec is not None: 906 params['ctrlr_loss_timeout_sec'] = ctrlr_loss_timeout_sec 907 if reconnect_delay_sec is not None: 908 params['reconnect_delay_sec'] = reconnect_delay_sec 909 if fast_io_fail_timeout_sec is not None: 910 params['fast_io_fail_timeout_sec'] = fast_io_fail_timeout_sec 911 if attach_timeout_ms is not None: 912 params['attach_timeout_ms'] = attach_timeout_ms 913 return client.call('bdev_nvme_start_discovery', params) 914 915 916def bdev_nvme_stop_discovery(client, name): 917 """Stop a previously started discovery service 918 Args: 919 name: name of discovery service to start 920 """ 921 params = dict() 922 params['name'] = name 923 return client.call('bdev_nvme_stop_discovery', params) 924 925 926def bdev_nvme_get_discovery_info(client): 927 """Get information about the automatic discovery 928 """ 929 return client.call('bdev_nvme_get_discovery_info') 930 931 932def bdev_nvme_get_io_paths(client, name=None): 933 """Display all or the specified NVMe bdev's active I/O paths 934 Args: 935 name: Name of the NVMe bdev (optional) 936 Returns: 937 List of active I/O paths 938 """ 939 params = dict() 940 if name is not None: 941 params['name'] = name 942 return client.call('bdev_nvme_get_io_paths', params) 943 944 945def bdev_nvme_set_preferred_path(client, name, cntlid): 946 """Set the preferred I/O path for an NVMe bdev when in multipath mode 947 Args: 948 name: NVMe bdev name 949 cntlid: NVMe-oF controller ID 950 """ 951 params = dict() 952 params['name'] = name 953 params['cntlid'] = cntlid 954 return client.call('bdev_nvme_set_preferred_path', params) 955 956 957def bdev_nvme_set_multipath_policy(client, name, policy, selector=None, rr_min_io=None): 958 """Set multipath policy of the NVMe bdev 959 Args: 960 name: NVMe bdev name 961 policy: Multipath policy (active_passive or active_active) 962 selector: Multipath selector (round_robin, queue_depth) 963 rr_min_io: Number of IO to route to a path before switching to another one (optional) 964 """ 965 params = dict() 966 params['name'] = name 967 params['policy'] = policy 968 if selector is not None: 969 params['selector'] = selector 970 if rr_min_io is not None: 971 params['rr_min_io'] = rr_min_io 972 return client.call('bdev_nvme_set_multipath_policy', params) 973 974 975def bdev_nvme_get_path_iostat(client, name): 976 """Get I/O statistics for IO paths of the block device. 977 Args: 978 name: bdev name to query 979 Returns: 980 I/O statistics for IO paths of the requested block device. 981 """ 982 params = dict() 983 params['name'] = name 984 return client.call('bdev_nvme_get_path_iostat', params) 985 986 987def bdev_nvme_cuse_register(client, name): 988 """Register CUSE devices on NVMe controller. 989 Args: 990 name: Name of the operating NVMe controller 991 """ 992 params = dict() 993 params['name'] = name 994 return client.call('bdev_nvme_cuse_register', params) 995 996 997def bdev_nvme_cuse_unregister(client, name): 998 """Unregister CUSE devices on NVMe controller. 999 Args: 1000 name: Name of the operating NVMe controller 1001 """ 1002 params = dict() 1003 params['name'] = name 1004 return client.call('bdev_nvme_cuse_unregister', params) 1005 1006 1007def bdev_zone_block_create(client, name, base_bdev, zone_capacity, optimal_open_zones): 1008 """Creates a virtual zone device on top of existing non-zoned bdev. 1009 Args: 1010 name: Zone device name 1011 base_bdev: Base Nvme bdev name 1012 zone_capacity: Surfaced zone capacity in blocks 1013 optimal_open_zones: Number of zones required to reach optimal write speed (optional, default: 1) 1014 Returns: 1015 Name of created block device. 1016 """ 1017 params = dict() 1018 params['name'] = name 1019 params['base_bdev'] = base_bdev 1020 params['zone_capacity'] = zone_capacity 1021 params['optimal_open_zones'] = optimal_open_zones 1022 return client.call('bdev_zone_block_create', params) 1023 1024 1025def bdev_zone_block_delete(client, name): 1026 """Remove block zone bdev from the system. 1027 Args: 1028 name: name of block zone bdev to delete 1029 """ 1030 params = dict() 1031 params['name'] = name 1032 return client.call('bdev_zone_block_delete', params) 1033 1034 1035def bdev_rbd_register_cluster(client, name=None, user_id=None, config_param=None, config_file=None, key_file=None, core_mask=None): 1036 """Create a Rados Cluster object of the Ceph RBD backend. 1037 Args: 1038 name: name of Rados Cluster 1039 user_id: Ceph user name (optional) 1040 config_param: map of config keys to values (optional) 1041 config_file: file path of Ceph configuration file (optional) 1042 key_file: file path of Ceph key file (optional) 1043 core_mask: core mask for librbd IO context threads (optional) 1044 Returns: 1045 Name of registered Rados Cluster object. 1046 """ 1047 params = dict() 1048 if name is not None: 1049 params['name'] = name 1050 if user_id is not None: 1051 params['user_id'] = user_id 1052 if config_param is not None: 1053 params['config_param'] = config_param 1054 if config_file is not None: 1055 params['config_file'] = config_file 1056 if key_file is not None: 1057 params['key_file'] = key_file 1058 if core_mask is not None: 1059 params['core_mask'] = core_mask 1060 return client.call('bdev_rbd_register_cluster', params) 1061 1062 1063def bdev_rbd_unregister_cluster(client, name): 1064 """Remove Rados cluster object from the system. 1065 Args: 1066 name: name of Rados cluster object to unregister 1067 """ 1068 params = dict() 1069 params['name'] = name 1070 return client.call('bdev_rbd_unregister_cluster', params) 1071 1072 1073def bdev_rbd_get_clusters_info(client, name=None): 1074 """Get the cluster(s) info 1075 Args: 1076 name: name of Rados cluster object to query (optional; if omitted, query all clusters) 1077 Returns: 1078 List of registered Rados cluster information objects. 1079 """ 1080 params = dict() 1081 if name is not None: 1082 params['name'] = name 1083 return client.call('bdev_rbd_get_clusters_info', params) 1084 1085 1086def bdev_rbd_create(client, pool_name, rbd_name, block_size, name=None, user_id=None, config=None, cluster_name=None, uuid=None): 1087 """Create a Ceph RBD block device. 1088 Args: 1089 pool_name: Ceph RBD pool name 1090 rbd_name: Ceph RBD image name 1091 block_size: block size of RBD volume 1092 name: name of block device (optional) 1093 user_id: Ceph user name (optional) 1094 config: map of config keys to values (optional) 1095 cluster_name: Name to identify Rados cluster (optional) 1096 uuid: UUID of block device (optional) 1097 Returns: 1098 Name of created block device. 1099 """ 1100 params = dict() 1101 params['pool_name'] = pool_name 1102 params['rbd_name'] = rbd_name 1103 params['block_size'] = block_size 1104 if name is not None: 1105 params['name'] = name 1106 if user_id is not None: 1107 params['user_id'] = user_id 1108 if config is not None: 1109 params['config'] = config 1110 if cluster_name is not None: 1111 params['cluster_name'] = cluster_name 1112 else: 1113 print("WARNING:bdev_rbd_create should be used with specifying -c to have a cluster name after bdev_rbd_register_cluster.") 1114 if uuid is not None: 1115 params['uuid'] = uuid 1116 return client.call('bdev_rbd_create', params) 1117 1118 1119def bdev_rbd_delete(client, name): 1120 """Remove rbd bdev from the system. 1121 Args: 1122 name: name of rbd bdev to delete 1123 """ 1124 params = dict() 1125 params['name'] = name 1126 return client.call('bdev_rbd_delete', params) 1127 1128 1129def bdev_rbd_resize(client, name, new_size): 1130 """Resize rbd bdev in the system. 1131 Args: 1132 name: name of rbd bdev to resize 1133 new_size: new bdev size of resize operation. The unit is MiB 1134 """ 1135 params = dict() 1136 params['name'] = name 1137 params['new_size'] = new_size 1138 return client.call('bdev_rbd_resize', params) 1139 1140 1141def bdev_error_create(client, base_name, uuid=None): 1142 """Construct an error injection block device. 1143 Args: 1144 base_name: base bdev name 1145 uuid: UUID for this bdev (optional) 1146 """ 1147 params = dict() 1148 params['base_name'] = base_name 1149 if uuid is not None: 1150 params['uuid'] = uuid 1151 return client.call('bdev_error_create', params) 1152 1153 1154def bdev_delay_create(client, base_bdev_name, name, avg_read_latency, p99_read_latency, avg_write_latency, p99_write_latency, uuid=None): 1155 """Construct a delay block device. 1156 Args: 1157 base_bdev_name: name of the existing bdev 1158 name: name of block device 1159 avg_read_latency: complete 99% of read ops with this delay 1160 p99_read_latency: complete 1% of read ops with this delay 1161 avg_write_latency: complete 99% of write ops with this delay 1162 p99_write_latency: complete 1% of write ops with this delay 1163 uuid: UUID of block device (optional) 1164 Returns: 1165 Name of created block device. 1166 """ 1167 params = dict() 1168 params['base_bdev_name'] = base_bdev_name 1169 params['name'] = name 1170 params['avg_read_latency'] = avg_read_latency 1171 params['p99_read_latency'] = p99_read_latency 1172 params['avg_write_latency'] = avg_write_latency 1173 params['p99_write_latency'] = p99_write_latency 1174 if uuid is not None: 1175 params['uuid'] = uuid 1176 return client.call('bdev_delay_create', params) 1177 1178 1179def bdev_delay_delete(client, name): 1180 """Remove delay bdev from the system. 1181 Args: 1182 name: name of delay bdev to delete 1183 """ 1184 params = dict() 1185 params['name'] = name 1186 return client.call('bdev_delay_delete', params) 1187 1188 1189def bdev_delay_update_latency(client, delay_bdev_name, latency_type, latency_us): 1190 """Update the latency value for a delay block device 1191 Args: 1192 delay_bdev_name: name of the delay bdev 1193 latency_type: 'one of: avg_read, avg_write, p99_read, p99_write. No other values accepted.' 1194 latency_us: 'new latency value.' 1195 Returns: 1196 True if successful, or a specific error otherwise. 1197 """ 1198 params = dict() 1199 params['delay_bdev_name'] = delay_bdev_name 1200 params['latency_type'] = latency_type 1201 params['latency_us'] = latency_us 1202 return client.call('bdev_delay_update_latency', params) 1203 1204 1205def bdev_error_delete(client, name): 1206 """Remove error bdev from the system. 1207 Args: 1208 bdev_name: name of error bdev to delete 1209 """ 1210 params = dict() 1211 params['name'] = name 1212 return client.call('bdev_error_delete', params) 1213 1214 1215def bdev_iscsi_set_options(client, timeout_sec=None): 1216 """Set options for the bdev iscsi. 1217 Args: 1218 timeout_sec: Timeout for command, in seconds, if 0, don't track timeout 1219 """ 1220 params = dict() 1221 if timeout_sec is not None: 1222 params['timeout_sec'] = timeout_sec 1223 return client.call('bdev_iscsi_set_options', params) 1224 1225 1226def bdev_iscsi_create(client, name, url, initiator_iqn): 1227 """Construct an iSCSI block device. 1228 Args: 1229 name: name of block device 1230 url: iSCSI URL 1231 initiator_iqn: IQN name to be used by initiator 1232 Returns: 1233 Name of created block device. 1234 """ 1235 params = dict() 1236 params['name'] = name 1237 params['url'] = url 1238 params['initiator_iqn'] = initiator_iqn 1239 return client.call('bdev_iscsi_create', params) 1240 1241 1242def bdev_iscsi_delete(client, name): 1243 """Remove iSCSI bdev from the system. 1244 Args: 1245 bdev_name: name of iSCSI bdev to delete 1246 """ 1247 params = dict() 1248 params['name'] = name 1249 return client.call('bdev_iscsi_delete', params) 1250 1251 1252def bdev_passthru_create(client, base_bdev_name, name, uuid=None): 1253 """Construct a pass-through block device. 1254 Args: 1255 base_bdev_name: name of the existing bdev 1256 name: name of block device 1257 uuid: UUID of block device (optional) 1258 Returns: 1259 Name of created block device. 1260 """ 1261 params = dict() 1262 params['base_bdev_name'] = base_bdev_name 1263 params['name'] = name 1264 if uuid is not None: 1265 params['uuid'] = uuid 1266 return client.call('bdev_passthru_create', params) 1267 1268 1269def bdev_passthru_delete(client, name): 1270 """Remove pass through bdev from the system. 1271 Args: 1272 name: name of pass through bdev to delete 1273 """ 1274 params = dict() 1275 params['name'] = name 1276 return client.call('bdev_passthru_delete', params) 1277 1278 1279def bdev_opal_create(client, nvme_ctrlr_name, nsid, locking_range_id, range_start, range_length, password): 1280 """Create opal virtual block devices from a base nvme bdev. 1281 Args: 1282 nvme_ctrlr_name: name of the nvme ctrlr 1283 nsid: namespace ID of nvme ctrlr 1284 locking_range_id: locking range ID corresponding to this virtual bdev 1285 range_start: start address of this locking range 1286 range_length: length of this locking range 1287 password: admin password of base nvme bdev 1288 Returns: 1289 Name of the new created block devices. 1290 """ 1291 params = dict() 1292 params['nvme_ctrlr_name'] = nvme_ctrlr_name 1293 params['nsid'] = nsid 1294 params['locking_range_id'] = locking_range_id 1295 params['range_start'] = range_start 1296 params['range_length'] = range_length 1297 params['password'] = password 1298 return client.call('bdev_opal_create', params) 1299 1300 1301def bdev_opal_get_info(client, bdev_name, password): 1302 """Get opal locking range info. 1303 Args: 1304 bdev_name: name of opal vbdev to get info 1305 password: admin password 1306 Returns: 1307 Locking range info. 1308 """ 1309 params = dict() 1310 params['bdev_name'] = bdev_name 1311 params['password'] = password 1312 return client.call('bdev_opal_get_info', params) 1313 1314 1315def bdev_opal_delete(client, bdev_name, password): 1316 """Delete opal virtual bdev from the system. 1317 Args: 1318 bdev_name: name of opal vbdev to delete 1319 password: admin password of base nvme bdev 1320 """ 1321 params = dict() 1322 params['bdev_name'] = bdev_name 1323 params['password'] = password 1324 return client.call('bdev_opal_delete', params) 1325 1326 1327def bdev_opal_new_user(client, bdev_name, admin_password, user_id, user_password): 1328 """Add a user to opal bdev who can set lock state for this bdev. 1329 Args: 1330 bdev_name: name of opal vbdev 1331 admin_password: admin password 1332 user_id: ID of the user who will be added to this opal bdev 1333 user_password: password set for this user 1334 """ 1335 params = dict() 1336 params['bdev_name'] = bdev_name 1337 params['admin_password'] = admin_password 1338 params['user_id'] = user_id 1339 params['user_password'] = user_password 1340 return client.call('bdev_opal_new_user', params) 1341 1342 1343def bdev_opal_set_lock_state(client, bdev_name, user_id, password, lock_state): 1344 """set lock state for an opal bdev. 1345 Args: 1346 bdev_name: name of opal vbdev 1347 user_id: ID of the user who will set lock state 1348 password: password of the user 1349 lock_state: lock state to set 1350 """ 1351 params = dict() 1352 params['bdev_name'] = bdev_name 1353 params['user_id'] = user_id 1354 params['password'] = password 1355 params['lock_state'] = lock_state 1356 return client.call('bdev_opal_set_lock_state', params) 1357 1358 1359def bdev_split_create(client, base_bdev, split_count, split_size_mb=None): 1360 """Create split block devices from a base bdev. 1361 Args: 1362 base_bdev: name of bdev to split 1363 split_count: number of split bdevs to create 1364 split_size_mb: size of each split volume in MiB (optional) 1365 Returns: 1366 List of created block devices. 1367 """ 1368 params = dict() 1369 params['base_bdev'] = base_bdev 1370 params['split_count'] = split_count 1371 if split_size_mb is not None: 1372 params['split_size_mb'] = split_size_mb 1373 return client.call('bdev_split_create', params) 1374 1375 1376def bdev_split_delete(client, base_bdev): 1377 """Delete split block devices. 1378 Args: 1379 base_bdev: name of previously split bdev 1380 """ 1381 params = dict() 1382 params['base_bdev'] = base_bdev 1383 return client.call('bdev_split_delete', params) 1384 1385 1386def bdev_ftl_create(client, name, base_bdev, cache, **kwargs): 1387 """Construct FTL bdev 1388 Args: 1389 name: name of the bdev 1390 base_bdev: name of the base bdev 1391 cache: name of the cache device 1392 kwargs: optional parameters 1393 """ 1394 params = dict() 1395 params['name'] = name 1396 params['base_bdev'] = base_bdev 1397 params['cache'] = cache 1398 for key, value in kwargs.items(): 1399 if value is not None: 1400 params[key] = value 1401 return client.call('bdev_ftl_create', params) 1402 1403 1404def bdev_ftl_load(client, name, base_bdev, cache, **kwargs): 1405 """Load FTL bdev 1406 Args: 1407 name: name of the bdev 1408 base_bdev: name of the base bdev 1409 cache: Name of the cache device 1410 kwargs: optional parameters 1411 """ 1412 params = dict() 1413 params['name'] = name 1414 params['base_bdev'] = base_bdev 1415 params['cache'] = cache 1416 for key, value in kwargs.items(): 1417 if value is not None: 1418 params[key] = value 1419 return client.call('bdev_ftl_load', params) 1420 1421 1422def bdev_ftl_unload(client, name, fast_shutdown=None): 1423 """Unload FTL bdev 1424 Args: 1425 name: name of the bdev 1426 fast_shutdown: When set FTL will minimize persisted data during deletion and rely on shared memory during next load 1427 """ 1428 params = dict() 1429 params['name'] = name 1430 if fast_shutdown is not None: 1431 params['fast_shutdown'] = fast_shutdown 1432 return client.call('bdev_ftl_unload', params) 1433 1434 1435def bdev_ftl_delete(client, name, fast_shutdown=None): 1436 """Delete FTL bdev 1437 Args: 1438 name: name of the bdev 1439 fast_shutdown: When set FTL will minimize persisted data during deletion and rely on shared memory during next load 1440 """ 1441 params = dict() 1442 params['name'] = name 1443 if fast_shutdown is not None: 1444 params['fast_shutdown'] = fast_shutdown 1445 return client.call('bdev_ftl_delete', params) 1446 1447 1448def bdev_ftl_unmap(client, name, lba, num_blocks): 1449 """FTL unmap 1450 Args: 1451 name: name of the bdev 1452 lba: starting lba to be unmapped 1453 num_blocks: number of blocks to unmap 1454 """ 1455 params = dict() 1456 params['name'] = name 1457 params['lba'] = lba 1458 params['num_blocks'] = num_blocks 1459 return client.call('bdev_ftl_unmap', params) 1460 1461 1462def bdev_ftl_get_stats(client, name): 1463 """get FTL stats 1464 Args: 1465 name: name of the bdev 1466 """ 1467 params = dict() 1468 params['name'] = name 1469 return client.call('bdev_ftl_get_stats', params) 1470 1471 1472def bdev_ftl_get_properties(client, name): 1473 """Get FTL properties 1474 Args: 1475 name: name of the bdev 1476 """ 1477 params = dict() 1478 params['name'] = name 1479 return client.call('bdev_ftl_get_properties', params) 1480 1481 1482def bdev_ftl_set_property(client, name, ftl_property, value): 1483 """Set FTL property 1484 Args: 1485 name: name of the bdev 1486 ftl_property: name of the property to be set 1487 value: The new value of the updated property 1488 """ 1489 params = dict() 1490 params['name'] = name 1491 params['ftl_property'] = ftl_property 1492 params['value'] = value 1493 return client.call('bdev_ftl_set_property', params) 1494 1495 1496def bdev_get_bdevs(client, name=None, timeout=None): 1497 """Get information about block devices. 1498 Args: 1499 name: bdev name to query (optional; if omitted, query all bdevs) 1500 timeout: time in ms to wait for the bdev with specified name to appear 1501 Returns: 1502 List of bdev information objects. 1503 """ 1504 params = dict() 1505 if name is not None: 1506 params['name'] = name 1507 if timeout is not None: 1508 params['timeout'] = timeout 1509 return client.call('bdev_get_bdevs', params) 1510 1511 1512def bdev_get_iostat(client, name=None, per_channel=None): 1513 """Get I/O statistics for block devices. 1514 Args: 1515 name: bdev name to query (optional; if omitted, query all bdevs) 1516 per_channel: display per channel IO stats for specified bdev 1517 Returns: 1518 I/O statistics for the requested block devices. 1519 """ 1520 params = dict() 1521 if name is not None: 1522 params['name'] = name 1523 if per_channel is not None: 1524 params['per_channel'] = per_channel 1525 return client.call('bdev_get_iostat', params) 1526 1527 1528def bdev_reset_iostat(client, name=None, mode=None): 1529 """Reset I/O statistics for block devices. 1530 Args: 1531 name: bdev name to reset (optional; if omitted, reset all bdevs) 1532 mode: mode to reset: all, maxmin (optional: if omitted, reset all fields) 1533 """ 1534 params = dict() 1535 if name is not None: 1536 params['name'] = name 1537 if mode is not None: 1538 params['mode'] = mode 1539 return client.call('bdev_reset_iostat', params) 1540 1541 1542def bdev_enable_histogram(client, name, enable, opc): 1543 """Control whether histogram is enabled for specified bdev. 1544 Args: 1545 name: name of bdev 1546 enable: Enable or disable histogram on specified device 1547 opc: name of io_type (optional) 1548 """ 1549 params = dict() 1550 params['name'] = name 1551 params['enable'] = enable 1552 if opc: 1553 params['opc'] = opc 1554 return client.call('bdev_enable_histogram', params) 1555 1556 1557def bdev_get_histogram(client, name): 1558 """Get histogram for specified bdev. 1559 Args: 1560 name: name of bdev 1561 """ 1562 params = dict() 1563 params['name'] = name 1564 return client.call('bdev_get_histogram', params) 1565 1566 1567def bdev_error_inject_error(client, name, io_type, error_type, num=None, 1568 queue_depth=None, corrupt_offset=None, corrupt_value=None): 1569 """Inject an error via an error bdev. 1570 Args: 1571 name: name of error bdev 1572 io_type: one of "clear", "read", "write", "unmap", "flush", or "all" 1573 error_type: one of "failure", "pending", "corrupt_data" or "nomem" 1574 num: number of commands to fail 1575 queue_depth: the queue depth at which to trigger the error 1576 corrupt_offset: offset in bytes to xor with corrupt_value 1577 corrupt_value: value for xor (1-255, 0 is invalid) 1578 """ 1579 params = dict() 1580 params['name'] = name 1581 params['io_type'] = io_type 1582 params['error_type'] = error_type 1583 if num is not None: 1584 params['num'] = num 1585 if queue_depth is not None: 1586 params['queue_depth'] = queue_depth 1587 if corrupt_offset is not None: 1588 params['corrupt_offset'] = corrupt_offset 1589 if corrupt_value is not None: 1590 params['corrupt_value'] = corrupt_value 1591 return client.call('bdev_error_inject_error', params) 1592 1593 1594def bdev_set_qd_sampling_period(client, name, period): 1595 """Enable queue depth tracking on a specified bdev. 1596 Args: 1597 name: name of a bdev on which to track queue depth. 1598 period: period (in microseconds) at which to update the queue depth reading. If set to 0, polling will be disabled. 1599 """ 1600 params = dict() 1601 params['name'] = name 1602 params['period'] = period 1603 return client.call('bdev_set_qd_sampling_period', params) 1604 1605 1606def bdev_set_qos_limit( 1607 client, 1608 name, 1609 rw_ios_per_sec=None, 1610 rw_mbytes_per_sec=None, 1611 r_mbytes_per_sec=None, 1612 w_mbytes_per_sec=None): 1613 """Set QoS rate limit on a block device. 1614 Args: 1615 name: name of block device 1616 rw_ios_per_sec: R/W IOs per second limit (>=1000, example: 20000). 0 means unlimited. 1617 rw_mbytes_per_sec: R/W megabytes per second limit (>=10, example: 100). 0 means unlimited. 1618 r_mbytes_per_sec: Read megabytes per second limit (>=10, example: 100). 0 means unlimited. 1619 w_mbytes_per_sec: Write megabytes per second limit (>=10, example: 100). 0 means unlimited. 1620 """ 1621 params = dict() 1622 params['name'] = name 1623 if rw_ios_per_sec is not None: 1624 params['rw_ios_per_sec'] = rw_ios_per_sec 1625 if rw_mbytes_per_sec is not None: 1626 params['rw_mbytes_per_sec'] = rw_mbytes_per_sec 1627 if r_mbytes_per_sec is not None: 1628 params['r_mbytes_per_sec'] = r_mbytes_per_sec 1629 if w_mbytes_per_sec is not None: 1630 params['w_mbytes_per_sec'] = w_mbytes_per_sec 1631 return client.call('bdev_set_qos_limit', params) 1632 1633 1634def bdev_nvme_apply_firmware(client, bdev_name, filename): 1635 """Download and commit firmware to NVMe device. 1636 Args: 1637 bdev_name: name of NVMe block device 1638 filename: filename of the firmware to download 1639 """ 1640 params = dict() 1641 params['bdev_name'] = bdev_name 1642 params['filename'] = filename 1643 return client.call('bdev_nvme_apply_firmware', params) 1644 1645 1646def bdev_nvme_get_transport_statistics(client): 1647 """Get bdev_nvme poll group transport statistics""" 1648 return client.call('bdev_nvme_get_transport_statistics') 1649 1650 1651def bdev_nvme_get_controller_health_info(client, name): 1652 """Display health log of the required NVMe bdev controller. 1653 Args: 1654 name: name of the required NVMe bdev controller 1655 Returns: 1656 Health log for the requested NVMe bdev controller. 1657 """ 1658 params = dict() 1659 params['name'] = name 1660 return client.call('bdev_nvme_get_controller_health_info', params) 1661 1662 1663def bdev_daos_create(client, num_blocks, block_size, pool, cont, name, oclass=None, uuid=None): 1664 """Construct DAOS block device. 1665 Args: 1666 num_blocks: size of block device in blocks 1667 block_size: block size of device; must be a power of 2 and at least 512 1668 pool: UUID of DAOS pool 1669 cont: UUID of DAOS container 1670 name: name of block device (also the name of the backend file on DAOS DFS) 1671 oclass: DAOS object class (optional) 1672 uuid: UUID of block device (optional) 1673 Returns: 1674 Name of created block device. 1675 """ 1676 params = dict() 1677 params['num_blocks'] = num_blocks 1678 params['block_size'] = block_size 1679 params['pool'] = pool 1680 params['cont'] = cont 1681 params['name'] = name 1682 if oclass is not None: 1683 params['oclass'] = oclass 1684 if uuid is not None: 1685 params['uuid'] = uuid 1686 return client.call('bdev_daos_create', params) 1687 1688 1689def bdev_daos_delete(client, name): 1690 """Delete DAOS block device. 1691 Args: 1692 bdev_name: name of DAOS bdev to delete 1693 """ 1694 params = dict() 1695 params['name'] = name 1696 return client.call('bdev_daos_delete', params) 1697 1698 1699def bdev_daos_resize(client, name, new_size): 1700 """Resize DAOS bdev in the system. 1701 Args: 1702 name: name of DAOS bdev to resize 1703 new_size: new bdev size of resize operation. The unit is MiB 1704 """ 1705 params = dict() 1706 params['name'] = name 1707 params['new_size'] = new_size 1708 return client.call('bdev_daos_resize', params) 1709 1710 1711def bdev_nvme_start_mdns_discovery(client, name, svcname, hostnqn=None): 1712 """Start discovery with mDNS 1713 Args: 1714 name: bdev name prefix; "n" + unique seqno + namespace ID will be appended to create unique names 1715 svcname: service to discover ("_nvme-disc._tcp") 1716 hostnqn: NQN to connect from (optional) 1717 """ 1718 params = dict() 1719 params['name'] = name 1720 params['svcname'] = svcname 1721 if hostnqn is not None: 1722 params['hostnqn'] = hostnqn 1723 return client.call('bdev_nvme_start_mdns_discovery', params) 1724 1725 1726def bdev_nvme_stop_mdns_discovery(client, name): 1727 """Stop a previously started mdns discovery service 1728 Args: 1729 name: name of the discovery service to stop 1730 """ 1731 params = dict() 1732 params['name'] = name 1733 return client.call('bdev_nvme_stop_mdns_discovery', params) 1734 1735 1736def bdev_nvme_get_mdns_discovery_info(client): 1737 """Get information about the automatic mdns discovery 1738 """ 1739 return client.call('bdev_nvme_get_mdns_discovery_info') 1740