// File: yangwanyuan[P]HLKVDS/src/DS_MultiVolume_Impl.cc
// Function: hlkvds::DS_MultiVolume_Impl::CreateAllComponents(unsigned long)
bool DS_MultiVolume_Impl::CreateAllComponents(uint64_t sst_offset) {
    segSize_ = options_.segment_size;

    uint32_t align_bit = log2(ALIGNED_SIZE);
    if (segSize_ != (segSize_ >> align_bit) << align_bit) {
        __ERROR("Segment Size is not page aligned!");
        return false;
    }

    maxValueLen_ = segSize_ - SegBase::SizeOfSegOnDisk() - IndexManager::SizeOfHashEntryOnDisk();
    volNum_ = bdVec_.size();

    //Create Pure Volumes
    if (volNum_ > 1) {
        for (uint32_t i = 1; i < volNum_; i++ ) {
            BlockDevice * bdev = bdVec_[i];
            uint64_t device_capacity = bdev->GetDeviceCapacity();
            uint32_t seg_num = calcSegNumForPureVolume(device_capacity, segSize_);
            segTotalNum_ += seg_num;
            Volume *vol = new Volume(bdev, idxMgr_, options_, i, 0, segSize_, seg_num, 0);
            volMap_.insert( pair<int, Volume *>(i, vol) );
        }
    }

    //Create Meta Volumes
    BlockDevice * bdev = bdVec_[0];
    uint64_t device_capacity = bdev->GetDeviceCapacity();
    uint32_t seg_num = calcSegNumForMetaVolume(device_capacity, sst_offset, segTotalNum_, segSize_);
    segTotalNum_ += seg_num;
    sstLengthOnDisk_ = calcSSTsLengthOnDiskBySegNum(segTotalNum_);
    uint64_t start_off = sst_offset + sstLengthOnDisk_;
    Volume *vol = new Volume(bdev, idxMgr_, options_, 0, start_off, segSize_, seg_num, 0);
    volMap_.insert( make_pair(0, vol) );

    initSBReservedContentForCreate();

    return true;
}

// Assembly:
subq $0x128, %rsp            # imm = 0x128
movq %rdi, 0x118(%rsp)
movq %rsi, 0x110(%rsp)
movq 0x118(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x8(%rax), %rcx
movl 0x44(%rcx), %ecx
movl %ecx, 0xd8(%rax)
movl $0x1000, %edi           # imm = 0x1000
callq 0x16680
movq 0x60(%rsp), %rcx
cvttsd2si %xmm0, %rax
movl %eax, 0x10c(%rsp)
movl 0xd8(%rcx), %eax
movl 0xd8(%rcx), %edx
movl 0x10c(%rsp), %ecx
shrl %cl, %edx
movl 0x10c(%rsp), %ecx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
je 0x13ccd
jmp 0x13c52
movq 0x5d37f(%rip), %rax     # 0x70fd8
movq (%rax), %rax
movq %rax, 0x58(%rsp)
callq 0x8480
movq 0x58(%rsp), %rdi
movq %rax, %rdx
leaq 0x3e83c(%rip), %rsi     # 0x524b1
leaq 0x3ebbb(%rip), %rcx     # 0x52837
leaq 0x3e8ce(%rip), %r8      # 0x52551
movl $0x134, %r9d            # imm = 0x134
movb $0x0, %al
callq 0x86f0
movq 0x5d341(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x40a60(%rip), %rsi     # 0x54701
movb $0x0, %al
callq 0x86f0
movq 0x5d329(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x3f10c(%rip), %rsi     # 0x52dc5
movb $0x0, %al
callq 0x86f0
movb $0x0, 0x127(%rsp)
jmp 0x14060
movq 0x60(%rsp), %rax
movl 0xd8(%rax), %eax
movq %rax, 0x48(%rsp)
callq 0x166a0
movq %rax, %rcx
movq 0x48(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x50(%rsp)
callq 0x166b0
movq 0x50(%rsp), %rcx
movq %rax, %rdx
movq 0x60(%rsp), %rax
subq %rdx, %rcx
movl %ecx, 0xdc(%rax)
movq 0x10(%rax), %rdi
callq 0x166c0
movq %rax, %rcx
movq 0x60(%rsp), %rax
movl %ecx, 0xe0(%rax)
cmpl $0x1, 0xe0(%rax)
jbe 0x13ebc
movl $0x1, 0x108(%rsp)
movq 0x60(%rsp), %rcx
movl 0x108(%rsp), %eax
cmpl 0xe0(%rcx), %eax
jae 0x13eba
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rdi
movl 0x108(%rsp), %eax
movl %eax, %esi
callq 0x166e0
movq (%rax), %rax
movq %rax, 0x100(%rsp)
movq 0x100(%rsp), %rdi
movq (%rdi), %rax
movq 0x30(%rax), %rax
callq *%rax
movq 0x60(%rsp), %rdi
movq %rax, 0xf8(%rsp)
movq 0xf8(%rsp), %rsi
movl 0xd8(%rdi), %edx
callq 0x14080
movl %eax, %ecx
movq 0x60(%rsp), %rax
movl %ecx, 0xf4(%rsp)
movl 0xf4(%rsp), %edx
movl 0xe4(%rax), %ecx
addl %edx, %ecx
movl %ecx, 0xe4(%rax)
movl $0x58, %edi
callq 0x84f0
movq %rax, %rdi
movq 0x60(%rsp), %rax
movq %rdi, %rcx
movq %rcx, 0x40(%rsp)
movq 0x100(%rsp), %rsi
movq 0x8(%rax), %rcx
movq 0x20(%rax), %rdx
movl 0x108(%rsp), %r8d
movl 0xd8(%rax), %r9d
movl 0xf4(%rsp), %r10d
movq %rsp, %rax
movl %r10d, 0x8(%rax)
movl %r9d, (%rax)
movl $0x0, 0x10(%rax)
xorl %eax, %eax
movl %eax, %r9d
callq 0x50b10
jmp 0x13e28
movq 0x60(%rsp), %rax
movq 0x40(%rsp), %rcx
movq %rcx, 0xe8(%rsp)
addq $0x28, %rax
movq %rax, 0x38(%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
leaq 0xe8(%rsp), %rdx
callq 0x16750
movq 0x38(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x16700
movq %rax, 0xb8(%rsp)
movb %dl, 0xc0(%rsp)
movl 0x108(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x108(%rsp)
jmp 0x13d3c
movq 0x40(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
callq 0x84b0
jmp 0x14071
jmp 0x13ebc
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, 0x2c(%rsp)
movl %eax, %esi
callq 0x166e0
movq (%rax), %rax
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rdi
movq (%rdi), %rax
movq 0x30(%rax), %rax
callq *%rax
movq 0x60(%rsp), %rdi
movq %rax, 0xa8(%rsp)
movq 0xa8(%rsp), %rsi
movq 0x110(%rsp), %rdx
movl 0xd8(%rdi), %r8d
movl 0xe4(%rdi), %ecx
callq 0x140a0
movq 0x60(%rsp), %rdi
movl %eax, 0xa4(%rsp)
movl 0xa4(%rsp), %ecx
movl 0xe4(%rdi), %eax
addl %ecx, %eax
movl %eax, 0xe4(%rdi)
movl 0xe4(%rdi), %esi
callq 0x14170
movq 0x60(%rsp), %rcx
movq %rax, 0xe8(%rcx)
movq 0x110(%rsp), %rax
movq 0xe8(%rcx), %rcx
addq %rcx, %rax
movq %rax, 0x98(%rsp)
movl $0x58, %edi
callq 0x84f0
movl 0x2c(%rsp), %r8d
movq %rax, %rdi
movq 0x60(%rsp), %rax
movq %rdi, %rcx
movq %rcx, 0x30(%rsp)
movq 0xb0(%rsp), %rsi
movq 0x8(%rax), %rcx
movq 0x20(%rax), %rdx
movq 0x98(%rsp), %r9
movl 0xd8(%rax), %r10d
movl 0xa4(%rsp), %r11d
movq %rsp, %rax
movl %r11d, 0x8(%rax)
movl %r10d, (%rax)
movl $0x0, 0x10(%rax)
callq 0x50b10
jmp 0x13fcd
movq 0x60(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, 0x90(%rsp)
addq $0x28, %rax
movq %rax, 0x20(%rsp)
movl $0x0, 0x7c(%rsp)
leaq 0x7c(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x16780
movq 0x20(%rsp), %rdi
movl %eax, 0x80(%rsp)
movq %rdx, 0x88(%rsp)
leaq 0x80(%rsp), %rsi
callq 0x16700
movq 0x60(%rsp), %rdi
movq %rax, 0x68(%rsp)
movb %dl, 0x70(%rsp)
callq 0x141f0
movb $0x1, 0x127(%rsp)
jmp 0x14060
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
callq 0x84b0
jmp 0x14071
movb 0x127(%rsp), %al
andb $0x1, %al
addq $0x128, %rsp            # imm = 0x128
retq
movq 0xe0(%rsp), %rdi
callq 0x8820
nop