static int blockdev_malloc_unmap(struct malloc_disk *mdisk, struct spdk_io_channel *ch, struct copy_task *copy_req, struct spdk_scsi_unmap_bdesc *unmap_d, uint16_t bdesc_count) { uint64_t lba, offset, byte_count; uint32_t block_count; assert(bdesc_count <= MALLOC_MAX_UNMAP_BDESC); /* * For now, only support a single unmap descriptor per command. The copy engine API does not * support batch submission of operations. */ assert(bdesc_count == 1); lba = from_be64(&unmap_d[0].lba); offset = lba * mdisk->disk.blocklen; block_count = from_be32(&unmap_d[0].block_count); byte_count = (uint64_t)block_count * mdisk->disk.blocklen; if (lba >= mdisk->disk.blockcnt || block_count > mdisk->disk.blockcnt - lba) { return -1; } return spdk_copy_submit_fill(copy_req, ch, mdisk->malloc_buf + offset, 0, byte_count, malloc_done); }
void _prepare_stats(struct skipnode *x, size_t count, struct stats *stats) { size_t i; int real_count = 0; int max_len = 0; uint64_t min = 0UL; uint64_t max = 0UL; struct skipnode *node = x; memset(stats, 0, sizeof(struct stats)); for (i = 0; i < count; i++) { if (node->opt == ADD) { int klen = strlen(node->key); uint64_t off = from_be64(node->val); real_count++; max_len = klen > max_len ? klen : max_len; min = off < min ? off : min; max = off > max ? off : max; } node = node->forward[0]; } stats->max_len = max_len + 1; stats->mmap_size = (stats->max_len + sizeof(uint64_t)) * real_count ; }
uint64_t _read_offset(struct sst *sst, struct slice *sk) { int fd; int fcount; int blk_sizes; int result; uint64_t off = 0UL; char file[FILE_PATH_SIZE]; struct sst_block *blks; struct footer footer; int fsize = sizeof(struct footer); memset(file, 0, FILE_PATH_SIZE); snprintf(file, FILE_PATH_SIZE, "%s/%s", sst->basedir, sst->name); fd = open(file, O_RDWR, 0644); result = lseek(fd, -fsize, SEEK_END); if(result == -1) { abort(); } result = read(fd, &footer, fsize); if(result == -1) { abort(); } fcount = from_be32(footer.count); blk_sizes = fcount*sizeof(struct sst_block); blks = mmap(0, blk_sizes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if(blks == MAP_FAILED) { __DEBUG(LEVEL_ERROR, "%s", "Error:read_offset, mmapping the file"); goto out; } size_t left = 0, right = fcount, i = 0; while(left < right) { i = (right - left) / 2 + left; int cmp = strcmp(sk->data, blks[i].key); if(cmp == 0) { off = from_be64(blks[i].offset); break; } if(cmp < 0) right = i; else left = i + 1; } if(munmap(blks, blk_sizes) == -1) __DEBUG(LEVEL_ERROR, "%s", "read_offset:un-mmapping the file"); out : close(fd); return off; }
struct skiplist *_read_mmap(struct sst *sst, size_t count) { int i; int fd; int result; int fcount; int blk_sizes; char file[FILE_PATH_SIZE]; struct sst_block *blks; struct skiplist *merge = NULL; struct footer footer; int fsize = sizeof(struct footer); memset(file, 0, FILE_PATH_SIZE); snprintf(file, FILE_PATH_SIZE, "%s/%s", sst->basedir, sst->name); fd = open(file, O_RDWR, 0644); result = lseek(fd, -fsize, SEEK_END); if(result == -1) abort(); result = read(fd, &footer, fsize); if(result == -1) abort(); fcount = from_be32(footer.count); blk_sizes = fcount * sizeof(struct sst_block); blks = mmap(0, blk_sizes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if(blks == MAP_FAILED) { __DEBUG(LEVEL_ERROR, "%s", "Error: sst_bloom un-mmapping the file"); goto out; } merge = skiplist_new(fcount + count + 1); for(i = 0; i < fcount; i++) { skiplist_insert(merge, blks[i].key, from_be64(blks[i].offset), ADD); } if(munmap(blks, blk_sizes) == -1) { __DEBUG(LEVEL_ERROR, "%s", "read_map:un-mmapping the file"); } out: close(fd); return merge; }