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