// File: yangwanyuan[P]HLKVDS/src/Tier.cc
// Function: hlkvds::MediumTier::CreateVolume(std::vector<hlkvds::BlockDevice*, std::allocator<hlkvds::BlockDevice*>>&)
bool MediumTier::CreateVolume(std::vector<BlockDevice*> &bd_vec) {

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

    int fast_tier_device_num = hlkvds::FastTierVolNum;
    volNum_ = bd_vec.size() - fast_tier_device_num;

    for (uint32_t i = 0; i < volNum_; i++ ) {
        BlockDevice *bdev = bd_vec[i + fast_tier_device_num];
        uint64_t device_capacity = bdev->GetDeviceCapacity();
        uint32_t seg_num = DS_MultiTier_Impl::CalcSegNumForMediumTierVolume(device_capacity, segSize_);
        Volume *vol = new Volume(bdev, idxMgr_, options_, i, 0, segSize_, seg_num, 0);
        volMap_.insert( pair<int, Volume*>(i, vol) );
        segTotalNum_ += seg_num;
    }

    initSBReservedContentForCreate();
    return true;
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xa8(%rsp)
movq %rsi, 0xa0(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x38(%rsp)
movq (%rax), %rcx
movl 0x48(%rcx), %ecx
movl %ecx, 0x38(%rax)
movl $0x1000, %edi           # imm = 0x1000
callq 0x16680
movq 0x38(%rsp), %rcx
cvttsd2si %xmm0, %rax
movl %eax, 0x9c(%rsp)
movl 0x38(%rcx), %eax
movl 0x38(%rcx), %edx
movl 0x9c(%rsp), %ecx
shrl %cl, %edx
movl 0x9c(%rsp), %ecx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
je 0x4d703
jmp 0x4d688
movq 0x23949(%rip), %rax     # 0x70fd8
movq (%rax), %rax
movq %rax, 0x30(%rsp)
callq 0x8480
movq 0x30(%rsp), %rdi
movq %rax, %rdx
leaq 0x4e06(%rip), %rsi      # 0x524b1
leaq 0x6ee1(%rip), %rcx      # 0x54593
leaq 0x6e29(%rip), %r8       # 0x544e2
movl $0x2eb, %r9d            # imm = 0x2EB
movb $0x0, %al
callq 0x86f0
movq 0x2390b(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x701e(%rip), %rsi      # 0x546f5
movb $0x0, %al
callq 0x86f0
movq 0x238f3(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x56d6(%rip), %rsi      # 0x52dc5
movb $0x0, %al
callq 0x86f0
movb $0x0, 0xb7(%rsp)
jmp 0x4d8a2
movl $0x1, 0x98(%rsp)
movq 0xa0(%rsp), %rdi
callq 0x166c0
movq %rax, %rcx
movq 0x38(%rsp), %rax
movslq 0x98(%rsp), %rdx
subq %rdx, %rcx
movl %ecx, 0x40(%rax)
movl $0x0, 0x94(%rsp)
movq 0x38(%rsp), %rcx
movl 0x94(%rsp), %eax
cmpl 0x40(%rcx), %eax
jae 0x4d890
movq 0xa0(%rsp), %rdi
movl 0x94(%rsp), %eax
movl 0x98(%rsp), %ecx
addl %ecx, %eax
movl %eax, %esi
callq 0x166e0
movq (%rax), %rax
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rdi
movq (%rdi), %rax
movq 0x30(%rax), %rax
callq *%rax
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x80(%rsp)
movq 0x80(%rsp), %rdi
movl 0x38(%rax), %esi
callq 0x11600
movl %eax, 0x7c(%rsp)
movl $0x58, %edi
callq 0x84f0
movq %rax, %rdi
movq 0x38(%rsp), %rax
movq %rdi, %rcx
movq %rcx, 0x28(%rsp)
movq 0x88(%rsp), %rsi
movq (%rax), %rcx
movq 0x10(%rax), %rdx
movl 0x94(%rsp), %r8d
movl 0x38(%rax), %r9d
movl 0x7c(%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 0x4d807
movq 0x38(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, 0x70(%rsp)
addq $0x48, %rax
movq %rax, 0x20(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x94(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0x16750
movq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x16700
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x40(%rsp)
movb %dl, 0x48(%rsp)
movl 0x7c(%rsp), %ecx
addl 0x3c(%rax), %ecx
movl %ecx, 0x3c(%rax)
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x4d73c
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
callq 0x84b0
jmp 0x4d8b3
movq 0x38(%rsp), %rdi
callq 0x4d8c0
movb $0x1, 0xb7(%rsp)
movb 0xb7(%rsp), %al
andb $0x1, %al
addq $0xb8, %rsp
retq
movq 0x68(%rsp), %rdi
callq 0x8820
nopl (%rax)