#include <linux/vmalloc.h>
#include <linux/uio_driver.h>
#include <linux/xarray.h>
-#include <linux/radix-tree.h>
#include <linux/stringify.h>
#include <linux/bitops.h>
#include <linux/highmem.h>
uint32_t dbi_max;
uint32_t dbi_thresh;
unsigned long *data_bitmap;
- struct radix_tree_root data_blocks;
+ struct xarray data_blocks;
struct xarray commands;
int prev_dbi, int *iov_cnt)
{
struct page *page;
- int ret, dbi;
+ int dbi;
dbi = find_first_zero_bit(udev->data_bitmap, udev->dbi_thresh);
if (dbi == udev->dbi_thresh)
return -1;
- page = radix_tree_lookup(&udev->data_blocks, dbi);
+ page = xa_load(&udev->data_blocks, dbi);
if (!page) {
if (atomic_add_return(1, &global_db_count) >
tcmu_global_max_blocks)
if (!page)
goto err_alloc;
- ret = radix_tree_insert(&udev->data_blocks, dbi, page);
- if (ret)
+ if (xa_store(&udev->data_blocks, dbi, page, GFP_KERNEL))
goto err_insert;
}
static inline struct page *
tcmu_get_block_page(struct tcmu_dev *udev, uint32_t dbi)
{
- return radix_tree_lookup(&udev->data_blocks, dbi);
+ return xa_load(&udev->data_blocks, dbi);
}
static inline void tcmu_free_cmd(struct tcmu_cmd *tcmu_cmd)
timer_setup(&udev->qfull_timer, tcmu_qfull_timedout, 0);
timer_setup(&udev->cmd_timer, tcmu_cmd_timedout, 0);
- INIT_RADIX_TREE(&udev->data_blocks, GFP_KERNEL);
+ xa_init(&udev->data_blocks);
return &udev->se_dev;
}
return -EINVAL;
}
-static void tcmu_blocks_release(struct radix_tree_root *blocks,
- int start, int end)
+static void tcmu_blocks_release(struct xarray *blocks, unsigned long first,
+ unsigned long last)
{
- int i;
+ XA_STATE(xas, blocks, first);
struct page *page;
- for (i = start; i < end; i++) {
- page = radix_tree_delete(blocks, i);
- if (page) {
- __free_page(page);
- atomic_dec(&global_db_count);
- }
+ xas_lock(&xas);
+ xas_for_each(&xas, page, last) {
+ xas_store(&xas, NULL);
+ __free_page(page);
+ atomic_dec(&global_db_count);
}
+ xas_unlock(&xas);
}
static void tcmu_remove_all_queued_tmr(struct tcmu_dev *udev)
unmap_mapping_range(udev->inode->i_mapping, off, 0, 1);
/* Release the block pages */
- tcmu_blocks_release(&udev->data_blocks, start, end);
+ tcmu_blocks_release(&udev->data_blocks, start, end - 1);
mutex_unlock(&udev->cmdr_lock);
total_freed += end - start;