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