1 /*- 2 * BSD LICENSE 3 * 4 * Copyright (c) Intel Corporation. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name of Intel Corporation nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #ifndef SPDK_BLOBSTORE_H 35 #define SPDK_BLOBSTORE_H 36 37 #include "spdk/assert.h" 38 #include "spdk/blob.h" 39 #include "spdk/queue.h" 40 #include "spdk/util.h" 41 42 #include "request.h" 43 44 /* In Memory Data Structures 45 * 46 * The following data structures exist only in memory. 47 */ 48 49 #define SPDK_BLOB_OPTS_CLUSTER_SZ (1024 * 1024) 50 #define SPDK_BLOB_OPTS_NUM_MD_PAGES UINT32_MAX 51 #define SPDK_BLOB_OPTS_MAX_MD_OPS 32 52 #define SPDK_BLOB_OPTS_DEFAULT_CHANNEL_OPS 512 53 #define SPDK_BLOB_BLOBID_HIGH_BIT (1ULL << 32) 54 55 struct spdk_xattr { 56 uint32_t index; 57 uint16_t value_len; 58 char *name; 59 void *value; 60 TAILQ_ENTRY(spdk_xattr) link; 61 }; 62 63 /* The mutable part of the blob data that is sync'd to 64 * disk. The data in here is both mutable and persistent. 65 */ 66 struct spdk_blob_mut_data { 67 /* Number of data clusters in the blob */ 68 uint64_t num_clusters; 69 70 /* Array LBAs that are the beginning of a cluster, in 71 * the order they appear in the blob. 72 */ 73 uint64_t *clusters; 74 75 /* The size of the clusters array. This is greater than or 76 * equal to 'num_clusters'. 77 */ 78 size_t cluster_array_size; 79 80 /* Number of extent pages */ 81 uint64_t num_extent_pages; 82 83 /* Array of page offsets into the metadata region, 84 * containing extents. Can contain entries for not yet 85 * allocated pages. */ 86 uint32_t *extent_pages; 87 88 /* The size of the extent page array. This is greater than or 89 * equal to 'num_extent_pages'. */ 90 size_t extent_pages_array_size; 91 92 /* Number of metadata pages */ 93 uint32_t num_pages; 94 95 /* Array of page offsets into the metadata region, in 96 * the order of the metadata page sequence. 97 */ 98 uint32_t *pages; 99 }; 100 101 enum spdk_blob_state { 102 /* The blob in-memory version does not match the on-disk 103 * version. 104 */ 105 SPDK_BLOB_STATE_DIRTY, 106 107 /* The blob in memory version of the blob matches the on disk 108 * version. 109 */ 110 SPDK_BLOB_STATE_CLEAN, 111 112 /* The in-memory state being synchronized with the on-disk 113 * blob state. */ 114 SPDK_BLOB_STATE_LOADING, 115 }; 116 117 TAILQ_HEAD(spdk_xattr_tailq, spdk_xattr); 118 119 struct spdk_blob_list { 120 spdk_blob_id id; 121 size_t clone_count; 122 TAILQ_HEAD(, spdk_blob_list) clones; 123 TAILQ_ENTRY(spdk_blob_list) link; 124 }; 125 126 struct spdk_blob { 127 struct spdk_blob_store *bs; 128 129 uint32_t open_ref; 130 131 spdk_blob_id id; 132 spdk_blob_id parent_id; 133 134 enum spdk_blob_state state; 135 136 /* Two copies of the mutable data. One is a version 137 * that matches the last known data on disk (clean). 138 * The other (active) is the current data. Syncing 139 * a blob makes the clean match the active. 140 */ 141 struct spdk_blob_mut_data clean; 142 struct spdk_blob_mut_data active; 143 144 bool invalid; 145 bool data_ro; 146 bool md_ro; 147 148 uint64_t invalid_flags; 149 uint64_t data_ro_flags; 150 uint64_t md_ro_flags; 151 152 struct spdk_bs_dev *back_bs_dev; 153 154 /* TODO: The xattrs are mutable, but we don't want to be 155 * copying them unnecessarily. Figure this out. 156 */ 157 struct spdk_xattr_tailq xattrs; 158 struct spdk_xattr_tailq xattrs_internal; 159 160 TAILQ_ENTRY(spdk_blob) link; 161 162 uint32_t frozen_refcnt; 163 bool locked_operation_in_progress; 164 enum blob_clear_method clear_method; 165 bool extent_rle_found; 166 bool extent_table_found; 167 bool use_extent_table; 168 169 /* A list of pending metadata pending_persists */ 170 TAILQ_HEAD(, spdk_blob_persist_ctx) pending_persists; 171 172 /* Number of data clusters retrived from extent table, 173 * that many have to be read from extent pages. */ 174 uint64_t remaining_clusters_in_et; 175 }; 176 177 struct spdk_blob_store { 178 uint64_t md_start; /* Offset from beginning of disk, in pages */ 179 uint32_t md_len; /* Count, in pages */ 180 181 struct spdk_io_channel *md_channel; 182 uint32_t max_channel_ops; 183 184 struct spdk_thread *md_thread; 185 186 struct spdk_bs_dev *dev; 187 188 struct spdk_bit_array *used_md_pages; 189 struct spdk_bit_array *used_clusters; 190 struct spdk_bit_array *used_blobids; 191 192 pthread_mutex_t used_clusters_mutex; 193 194 uint32_t cluster_sz; 195 uint64_t total_clusters; 196 uint64_t total_data_clusters; 197 uint64_t num_free_clusters; 198 uint64_t pages_per_cluster; 199 uint32_t io_unit_size; 200 201 spdk_blob_id super_blob; 202 struct spdk_bs_type bstype; 203 204 struct spdk_bs_cpl unload_cpl; 205 int unload_err; 206 207 TAILQ_HEAD(, spdk_blob) blobs; 208 TAILQ_HEAD(, spdk_blob_list) snapshots; 209 210 bool clean; 211 }; 212 213 struct spdk_bs_channel { 214 struct spdk_bs_request_set *req_mem; 215 TAILQ_HEAD(, spdk_bs_request_set) reqs; 216 217 struct spdk_blob_store *bs; 218 219 struct spdk_bs_dev *dev; 220 struct spdk_io_channel *dev_channel; 221 222 TAILQ_HEAD(, spdk_bs_request_set) need_cluster_alloc; 223 TAILQ_HEAD(, spdk_bs_request_set) queued_io; 224 }; 225 226 /** operation type */ 227 enum spdk_blob_op_type { 228 SPDK_BLOB_WRITE, 229 SPDK_BLOB_READ, 230 SPDK_BLOB_UNMAP, 231 SPDK_BLOB_WRITE_ZEROES, 232 SPDK_BLOB_WRITEV, 233 SPDK_BLOB_READV, 234 }; 235 236 /* back bs_dev */ 237 238 #define BLOB_SNAPSHOT "SNAP" 239 #define SNAPSHOT_IN_PROGRESS "SNAPTMP" 240 #define SNAPSHOT_PENDING_REMOVAL "SNAPRM" 241 242 struct spdk_blob_bs_dev { 243 struct spdk_bs_dev bs_dev; 244 struct spdk_blob *blob; 245 }; 246 247 /* On-Disk Data Structures 248 * 249 * The following data structures exist on disk. 250 */ 251 #define SPDK_BS_INITIAL_VERSION 1 252 #define SPDK_BS_VERSION 3 /* current version */ 253 254 #pragma pack(push, 1) 255 256 #define SPDK_MD_MASK_TYPE_USED_PAGES 0 257 #define SPDK_MD_MASK_TYPE_USED_CLUSTERS 1 258 #define SPDK_MD_MASK_TYPE_USED_BLOBIDS 2 259 260 struct spdk_bs_md_mask { 261 uint8_t type; 262 uint32_t length; /* In bits */ 263 uint8_t mask[0]; 264 }; 265 266 #define SPDK_MD_DESCRIPTOR_TYPE_PADDING 0 267 #define SPDK_MD_DESCRIPTOR_TYPE_XATTR 2 268 #define SPDK_MD_DESCRIPTOR_TYPE_FLAGS 3 269 #define SPDK_MD_DESCRIPTOR_TYPE_XATTR_INTERNAL 4 270 271 /* Following descriptors define cluster layout in a blob. 272 * EXTENT_RLE cannot be present in blobs metadata, 273 * at the same time as EXTENT_TABLE and EXTENT_PAGE descriptors. */ 274 275 /* EXTENT_RLE descriptor holds an array of LBA that points to 276 * beginning of allocated clusters. The array is run-length encoded, 277 * with 0's being unallocated clusters. It is part of serialized 278 * metadata chain for a blob. */ 279 #define SPDK_MD_DESCRIPTOR_TYPE_EXTENT_RLE 1 280 /* EXTENT_TABLE descriptor holds array of md page offsets that 281 * point to pages with EXTENT_PAGE descriptor. The 0's in the array 282 * are run-length encoded, non-zero values are unallocated pages. 283 * It is part of serialized metadata chain for a blob. */ 284 #define SPDK_MD_DESCRIPTOR_TYPE_EXTENT_TABLE 5 285 /* EXTENT_PAGE descriptor holds an array of LBAs that point to 286 * beginning of allocated clusters. The array is run-length encoded, 287 * with 0's being unallocated clusters. It is NOT part of 288 * serialized metadata chain for a blob. */ 289 #define SPDK_MD_DESCRIPTOR_TYPE_EXTENT_PAGE 6 290 291 struct spdk_blob_md_descriptor_xattr { 292 uint8_t type; 293 uint32_t length; 294 295 uint16_t name_length; 296 uint16_t value_length; 297 298 char name[0]; 299 /* String name immediately followed by string value. */ 300 }; 301 302 struct spdk_blob_md_descriptor_extent_rle { 303 uint8_t type; 304 uint32_t length; 305 306 struct { 307 uint32_t cluster_idx; 308 uint32_t length; /* In units of clusters */ 309 } extents[0]; 310 }; 311 312 struct spdk_blob_md_descriptor_extent_table { 313 uint8_t type; 314 uint32_t length; 315 316 /* Number of data clusters in the blob */ 317 uint64_t num_clusters; 318 319 struct { 320 uint32_t page_idx; 321 uint32_t num_pages; /* In units of pages */ 322 } extent_page[0]; 323 }; 324 325 struct spdk_blob_md_descriptor_extent_page { 326 uint8_t type; 327 uint32_t length; 328 329 /* First cluster index in this extent page */ 330 uint32_t start_cluster_idx; 331 332 uint32_t cluster_idx[0]; 333 }; 334 335 #define SPDK_BLOB_THIN_PROV (1ULL << 0) 336 #define SPDK_BLOB_INTERNAL_XATTR (1ULL << 1) 337 #define SPDK_BLOB_EXTENT_TABLE (1ULL << 2) 338 #define SPDK_BLOB_INVALID_FLAGS_MASK (SPDK_BLOB_THIN_PROV | SPDK_BLOB_INTERNAL_XATTR | SPDK_BLOB_EXTENT_TABLE) 339 340 #define SPDK_BLOB_READ_ONLY (1ULL << 0) 341 #define SPDK_BLOB_DATA_RO_FLAGS_MASK SPDK_BLOB_READ_ONLY 342 343 #define SPDK_BLOB_CLEAR_METHOD_SHIFT 0 344 #define SPDK_BLOB_CLEAR_METHOD (3ULL << SPDK_BLOB_CLEAR_METHOD_SHIFT) 345 #define SPDK_BLOB_MD_RO_FLAGS_MASK SPDK_BLOB_CLEAR_METHOD 346 347 struct spdk_blob_md_descriptor_flags { 348 uint8_t type; 349 uint32_t length; 350 351 /* 352 * If a flag in invalid_flags is set that the application is not aware of, 353 * it will not allow the blob to be opened. 354 */ 355 uint64_t invalid_flags; 356 357 /* 358 * If a flag in data_ro_flags is set that the application is not aware of, 359 * allow the blob to be opened in data_read_only and md_read_only mode. 360 */ 361 uint64_t data_ro_flags; 362 363 /* 364 * If a flag in md_ro_flags is set the the application is not aware of, 365 * allow the blob to be opened in md_read_only mode. 366 */ 367 uint64_t md_ro_flags; 368 }; 369 370 struct spdk_blob_md_descriptor { 371 uint8_t type; 372 uint32_t length; 373 }; 374 375 #define SPDK_INVALID_MD_PAGE UINT32_MAX 376 377 struct spdk_blob_md_page { 378 spdk_blob_id id; 379 380 uint32_t sequence_num; 381 uint32_t reserved0; 382 383 /* Descriptors here */ 384 uint8_t descriptors[4072]; 385 386 uint32_t next; 387 uint32_t crc; 388 }; 389 #define SPDK_BS_PAGE_SIZE 0x1000 390 SPDK_STATIC_ASSERT(SPDK_BS_PAGE_SIZE == sizeof(struct spdk_blob_md_page), "Invalid md page size"); 391 392 #define SPDK_BS_MAX_DESC_SIZE sizeof(((struct spdk_blob_md_page*)0)->descriptors) 393 394 /* Maximum number of extents a single Extent Page can fit. 395 * For an SPDK_BS_PAGE_SIZE of 4K SPDK_EXTENTS_PER_EP would be 512. */ 396 #define SPDK_EXTENTS_PER_EP_MAX ((SPDK_BS_MAX_DESC_SIZE - sizeof(struct spdk_blob_md_descriptor_extent_page)) / sizeof(uint32_t)) 397 #define SPDK_EXTENTS_PER_EP (spdk_align64pow2(SPDK_EXTENTS_PER_EP_MAX + 1) >> 1u) 398 399 #define SPDK_BS_SUPER_BLOCK_SIG "SPDKBLOB" 400 401 struct spdk_bs_super_block { 402 uint8_t signature[8]; 403 uint32_t version; 404 uint32_t length; 405 uint32_t clean; /* If there was a clean shutdown, this is 1. */ 406 spdk_blob_id super_blob; 407 408 uint32_t cluster_size; /* In bytes */ 409 410 uint32_t used_page_mask_start; /* Offset from beginning of disk, in pages */ 411 uint32_t used_page_mask_len; /* Count, in pages */ 412 413 uint32_t used_cluster_mask_start; /* Offset from beginning of disk, in pages */ 414 uint32_t used_cluster_mask_len; /* Count, in pages */ 415 416 uint32_t md_start; /* Offset from beginning of disk, in pages */ 417 uint32_t md_len; /* Count, in pages */ 418 419 struct spdk_bs_type bstype; /* blobstore type */ 420 421 uint32_t used_blobid_mask_start; /* Offset from beginning of disk, in pages */ 422 uint32_t used_blobid_mask_len; /* Count, in pages */ 423 424 uint64_t size; /* size of blobstore in bytes */ 425 uint32_t io_unit_size; /* Size of io unit in bytes */ 426 427 uint8_t reserved[4000]; 428 uint32_t crc; 429 }; 430 SPDK_STATIC_ASSERT(sizeof(struct spdk_bs_super_block) == 0x1000, "Invalid super block size"); 431 432 #pragma pack(pop) 433 434 struct spdk_bs_dev *spdk_bs_create_zeroes_dev(void); 435 struct spdk_bs_dev *spdk_bs_create_blob_bs_dev(struct spdk_blob *blob); 436 437 /* Unit Conversions 438 * 439 * The blobstore works with several different units: 440 * - Byte: Self explanatory 441 * - LBA: The logical blocks on the backing storage device. 442 * - Page: The read/write units of blobs and metadata. This is 443 * an offset into a blob in units of 4KiB. 444 * - Cluster Index: The disk is broken into a sequential list of 445 * clusters. This is the offset from the beginning. 446 * 447 * NOTE: These conversions all act on simple magnitudes, not with any sort 448 * of knowledge about the blobs themselves. For instance, converting 449 * a page to an lba with the conversion function below simply converts 450 * a number of pages to an equivalent number of lbas, but that 451 * lba certainly isn't the right lba that corresponds to a page offset 452 * for a particular blob. 453 */ 454 static inline uint64_t 455 _spdk_bs_byte_to_lba(struct spdk_blob_store *bs, uint64_t length) 456 { 457 assert(length % bs->dev->blocklen == 0); 458 459 return length / bs->dev->blocklen; 460 } 461 462 static inline uint64_t 463 _spdk_bs_dev_byte_to_lba(struct spdk_bs_dev *bs_dev, uint64_t length) 464 { 465 assert(length % bs_dev->blocklen == 0); 466 467 return length / bs_dev->blocklen; 468 } 469 470 static inline uint64_t 471 _spdk_bs_page_to_lba(struct spdk_blob_store *bs, uint64_t page) 472 { 473 return page * SPDK_BS_PAGE_SIZE / bs->dev->blocklen; 474 } 475 476 static inline uint64_t 477 _spdk_bs_md_page_to_lba(struct spdk_blob_store *bs, uint32_t page) 478 { 479 assert(page < bs->md_len); 480 return _spdk_bs_page_to_lba(bs, page + bs->md_start); 481 } 482 483 static inline uint64_t 484 _spdk_bs_dev_page_to_lba(struct spdk_bs_dev *bs_dev, uint64_t page) 485 { 486 return page * SPDK_BS_PAGE_SIZE / bs_dev->blocklen; 487 } 488 489 static inline uint64_t 490 _spdk_bs_io_unit_per_page(struct spdk_blob_store *bs) 491 { 492 return SPDK_BS_PAGE_SIZE / bs->io_unit_size; 493 } 494 495 static inline uint64_t 496 _spdk_bs_io_unit_to_page(struct spdk_blob_store *bs, uint64_t io_unit) 497 { 498 return io_unit / _spdk_bs_io_unit_per_page(bs); 499 } 500 501 static inline uint64_t 502 _spdk_bs_cluster_to_page(struct spdk_blob_store *bs, uint32_t cluster) 503 { 504 return (uint64_t)cluster * bs->pages_per_cluster; 505 } 506 507 static inline uint32_t 508 _spdk_bs_page_to_cluster(struct spdk_blob_store *bs, uint64_t page) 509 { 510 assert(page % bs->pages_per_cluster == 0); 511 512 return page / bs->pages_per_cluster; 513 } 514 515 static inline uint64_t 516 _spdk_bs_cluster_to_lba(struct spdk_blob_store *bs, uint32_t cluster) 517 { 518 return (uint64_t)cluster * (bs->cluster_sz / bs->dev->blocklen); 519 } 520 521 static inline uint32_t 522 _spdk_bs_lba_to_cluster(struct spdk_blob_store *bs, uint64_t lba) 523 { 524 assert(lba % (bs->cluster_sz / bs->dev->blocklen) == 0); 525 526 return lba / (bs->cluster_sz / bs->dev->blocklen); 527 } 528 529 static inline uint64_t 530 _spdk_bs_io_unit_to_back_dev_lba(struct spdk_blob *blob, uint64_t io_unit) 531 { 532 return io_unit * (blob->bs->io_unit_size / blob->back_bs_dev->blocklen); 533 } 534 535 static inline uint64_t 536 _spdk_bs_back_dev_lba_to_io_unit(struct spdk_blob *blob, uint64_t lba) 537 { 538 return lba * (blob->back_bs_dev->blocklen / blob->bs->io_unit_size); 539 } 540 541 static inline uint64_t 542 _spdk_bs_cluster_to_extent_table_id(uint64_t cluster_num) 543 { 544 return cluster_num / SPDK_EXTENTS_PER_EP; 545 } 546 547 static inline uint32_t * 548 _spdk_bs_cluster_to_extent_page(struct spdk_blob *blob, uint64_t cluster_num) 549 { 550 uint64_t extent_table_id = _spdk_bs_cluster_to_extent_table_id(cluster_num); 551 552 assert(blob->use_extent_table); 553 assert(extent_table_id < blob->active.extent_pages_array_size); 554 555 return &blob->active.extent_pages[extent_table_id]; 556 } 557 558 /* End basic conversions */ 559 560 static inline uint64_t 561 _spdk_bs_blobid_to_page(spdk_blob_id id) 562 { 563 return id & 0xFFFFFFFF; 564 } 565 566 /* The blob id is a 64 bit number. The lower 32 bits are the page_idx. The upper 567 * 32 bits are not currently used. Stick a 1 there just to catch bugs where the 568 * code assumes blob id == page_idx. 569 */ 570 static inline spdk_blob_id 571 _spdk_bs_page_to_blobid(uint64_t page_idx) 572 { 573 if (page_idx > UINT32_MAX) { 574 return SPDK_BLOBID_INVALID; 575 } 576 return SPDK_BLOB_BLOBID_HIGH_BIT | page_idx; 577 } 578 579 /* Given an io unit offset into a blob, look up the LBA for the 580 * start of that io unit. 581 */ 582 static inline uint64_t 583 _spdk_bs_blob_io_unit_to_lba(struct spdk_blob *blob, uint64_t io_unit) 584 { 585 uint64_t lba; 586 uint64_t pages_per_cluster; 587 uint64_t io_units_per_cluster; 588 uint64_t io_units_per_page; 589 uint64_t page; 590 591 page = _spdk_bs_io_unit_to_page(blob->bs, io_unit); 592 593 pages_per_cluster = blob->bs->pages_per_cluster; 594 io_units_per_page = _spdk_bs_io_unit_per_page(blob->bs); 595 io_units_per_cluster = io_units_per_page * pages_per_cluster; 596 597 assert(page < blob->active.num_clusters * pages_per_cluster); 598 599 lba = blob->active.clusters[page / pages_per_cluster]; 600 lba += io_unit % io_units_per_cluster; 601 return lba; 602 } 603 604 /* Given an io_unit offset into a blob, look up the number of io_units until the 605 * next cluster boundary. 606 */ 607 static inline uint32_t 608 _spdk_bs_num_io_units_to_cluster_boundary(struct spdk_blob *blob, uint64_t io_unit) 609 { 610 uint64_t io_units_per_cluster; 611 612 io_units_per_cluster = _spdk_bs_io_unit_per_page(blob->bs) * blob->bs->pages_per_cluster; 613 614 return io_units_per_cluster - (io_unit % io_units_per_cluster); 615 } 616 617 /* Given a page offset into a blob, look up the number of pages until the 618 * next cluster boundary. 619 */ 620 static inline uint32_t 621 _spdk_bs_num_pages_to_cluster_boundary(struct spdk_blob *blob, uint64_t page) 622 { 623 uint64_t pages_per_cluster; 624 625 pages_per_cluster = blob->bs->pages_per_cluster; 626 627 return pages_per_cluster - (page % pages_per_cluster); 628 } 629 630 /* Given an io_unit offset into a blob, look up the number of pages into blob to beginning of current cluster */ 631 static inline uint32_t 632 _spdk_bs_io_unit_to_cluster_start(struct spdk_blob *blob, uint64_t io_unit) 633 { 634 uint64_t pages_per_cluster; 635 uint64_t page; 636 637 pages_per_cluster = blob->bs->pages_per_cluster; 638 page = _spdk_bs_io_unit_to_page(blob->bs, io_unit); 639 640 return page - (page % pages_per_cluster); 641 } 642 643 /* Given an io_unit offset into a blob, look up the number of pages into blob to beginning of current cluster */ 644 static inline uint32_t 645 _spdk_bs_io_unit_to_cluster_number(struct spdk_blob *blob, uint64_t io_unit) 646 { 647 return (io_unit / _spdk_bs_io_unit_per_page(blob->bs)) / blob->bs->pages_per_cluster; 648 } 649 650 /* Given an io unit offset into a blob, look up if it is from allocated cluster. */ 651 static inline bool 652 _spdk_bs_io_unit_is_allocated(struct spdk_blob *blob, uint64_t io_unit) 653 { 654 uint64_t lba; 655 uint64_t page; 656 uint64_t pages_per_cluster; 657 658 pages_per_cluster = blob->bs->pages_per_cluster; 659 page = _spdk_bs_io_unit_to_page(blob->bs, io_unit); 660 661 assert(page < blob->active.num_clusters * pages_per_cluster); 662 663 lba = blob->active.clusters[page / pages_per_cluster]; 664 665 if (lba == 0) { 666 assert(spdk_blob_is_thin_provisioned(blob)); 667 return false; 668 } else { 669 return true; 670 } 671 } 672 673 #endif 674