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