struct malloc_disk *create_malloc_disk(uint64_t num_blocks, uint32_t block_size) { struct malloc_disk *mdisk; if (block_size % 512 != 0) { SPDK_ERRLOG("Block size %u is not a multiple of 512.\n", block_size); return NULL; } if (num_blocks == 0) { SPDK_ERRLOG("Disk must be more than 0 blocks\n"); return NULL; } mdisk = rte_malloc(NULL, sizeof(*mdisk), 0); if (!mdisk) { perror("mdisk"); return NULL; } memset(mdisk, 0, sizeof(*mdisk)); /* * Allocate the large backend memory buffer using rte_malloc(), * so that we guarantee it is allocated from hugepage memory. * * TODO: need to pass a hint so we know which socket to allocate * from on multi-socket systems. */ mdisk->malloc_buf = rte_zmalloc(NULL, num_blocks * block_size, 2 * 1024 * 1024); if (!mdisk->malloc_buf) { SPDK_ERRLOG("rte_zmalloc failed\n"); rte_free(mdisk); return NULL; } snprintf(mdisk->disk.name, SPDK_BDEV_MAX_NAME_LENGTH, "Malloc%d", malloc_disk_count); snprintf(mdisk->disk.product_name, SPDK_BDEV_MAX_PRODUCT_NAME_LENGTH, "Malloc disk"); malloc_disk_count++; mdisk->disk.write_cache = 1; mdisk->disk.blocklen = block_size; mdisk->disk.blockcnt = num_blocks; mdisk->disk.thin_provisioning = 1; mdisk->disk.max_unmap_bdesc_count = MALLOC_MAX_UNMAP_BDESC; mdisk->disk.ctxt = mdisk; mdisk->disk.fn_table = &malloc_fn_table; spdk_bdev_register(&mdisk->disk); mdisk->next = g_malloc_disk_head; g_malloc_disk_head = mdisk; return mdisk; }
struct spdk_bdev * create_aio_disk(char *fname) { struct file_disk *fdisk; fdisk = calloc(sizeof(*fdisk), 1); if (!fdisk) { SPDK_ERRLOG("Unable to allocate enough memory for aio backend\n"); return NULL; } fdisk->file = fname; if (blockdev_aio_open(fdisk)) { SPDK_ERRLOG("Unable to open file %s. fd: %d errno: %d\n", fname, fdisk->fd, errno); goto error_return; } fdisk->size = spdk_fd_get_size(fdisk->fd); TAILQ_INIT(&fdisk->sync_completion_list); snprintf(fdisk->disk.name, SPDK_BDEV_MAX_NAME_LENGTH, "AIO%d", g_blockdev_count); snprintf(fdisk->disk.product_name, SPDK_BDEV_MAX_PRODUCT_NAME_LENGTH, "AIO disk"); fdisk->disk.need_aligned_buffer = 1; fdisk->disk.write_cache = 1; fdisk->disk.blocklen = spdk_fd_get_blocklen(fdisk->fd); fdisk->disk.blockcnt = fdisk->size / fdisk->disk.blocklen; fdisk->disk.ctxt = fdisk; fdisk->disk.fn_table = &aio_fn_table; g_blockdev_count++; spdk_io_device_register(&fdisk->disk, blockdev_aio_create_cb, blockdev_aio_destroy_cb, sizeof(struct blockdev_aio_io_channel)); spdk_bdev_register(&fdisk->disk); return &fdisk->disk; error_return: blockdev_aio_close(fdisk); aio_free_disk(fdisk); return NULL; }