.owner = THIS_MODULE,
};
+static int gen_reserve_luns(struct nvm_dev *dev, struct nvm_target *t,
+ int lun_begin, int lun_end)
+{
+ struct gen_dev *gn = dev->mp;
+ struct nvm_lun *lun;
+ int i;
+
+ for (i = lun_begin; i <= lun_end; i++) {
+ if (test_and_set_bit(i, dev->lun_map)) {
+ pr_err("nvm: lun %d already allocated\n", i);
+ goto err;
+ }
+
+ lun = &gn->luns[i];
+ list_add_tail(&lun->list, &t->lun_list);
+ }
+
+ return 0;
+
+err:
+ while (--i > lun_begin) {
+ lun = &gn->luns[i];
+ clear_bit(i, dev->lun_map);
+ list_del(&lun->list);
+ }
+
+ return -EBUSY;
+}
+
+static void gen_release_luns(struct nvm_dev *dev, struct nvm_target *t)
+{
+ struct nvm_lun *lun, *tmp;
+
+ list_for_each_entry_safe(lun, tmp, &t->lun_list, list) {
+ WARN_ON(!test_and_clear_bit(lun->id, dev->lun_map));
+ list_del(&lun->list);
+ }
+}
+
static int gen_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
{
struct gen_dev *gn = dev->mp;
if (!t)
return -ENOMEM;
+ INIT_LIST_HEAD(&t->lun_list);
+
+ if (gen_reserve_luns(dev, t, s->lun_begin, s->lun_end))
+ goto err_t;
+
tqueue = blk_alloc_queue_node(GFP_KERNEL, dev->q->node);
if (!tqueue)
- goto err_t;
+ goto err_reserve;
blk_queue_make_request(tqueue, tt->make_rq);
tdisk = alloc_disk(0);
put_disk(tdisk);
err_queue:
blk_cleanup_queue(tqueue);
+err_reserve:
+ gen_release_luns(dev, t);
err_t:
kfree(t);
return -ENOMEM;
if (tt->exit)
tt->exit(tdisk->private_data);
+ gen_release_luns(t->dev, t);
put_disk(tdisk);
list_del(&t->list);
INIT_LIST_HEAD(&lun->free_list);
INIT_LIST_HEAD(&lun->used_list);
INIT_LIST_HEAD(&lun->bb_list);
+ INIT_LIST_HEAD(&lun->list);
spin_lock_init(&lun->lock);
return nvm_erase_ppa(dev, &addr, 1, flags);
}
-static int gen_reserve_lun(struct nvm_dev *dev, int lunid)
-{
- return test_and_set_bit(lunid, dev->lun_map);
-}
-
-static void gen_release_lun(struct nvm_dev *dev, int lunid)
-{
- WARN_ON(!test_and_clear_bit(lunid, dev->lun_map));
-}
-
static struct nvm_lun *gen_get_lun(struct nvm_dev *dev, int lunid)
{
struct gen_dev *gn = dev->mp;
.mark_blk = gen_mark_blk,
.get_lun = gen_get_lun,
- .reserve_lun = gen_reserve_lun,
- .release_lun = gen_release_lun,
.lun_info_print = gen_lun_info_print,
.get_area = gen_get_area,
struct nvm_target {
struct list_head list;
+ struct list_head lun_list;
struct nvm_dev *dev;
struct nvm_tgt_type *type;
struct gendisk *disk;
int lun_id;
int chnl_id;
+ struct list_head list;
spinlock_t lock;
/* lun block lists */
typedef int (nvmm_erase_blk_fn)(struct nvm_dev *, struct nvm_block *, int);
typedef void (nvmm_mark_blk_fn)(struct nvm_dev *, struct ppa_addr, int);
typedef struct nvm_lun *(nvmm_get_lun_fn)(struct nvm_dev *, int);
-typedef int (nvmm_reserve_lun)(struct nvm_dev *, int);
-typedef void (nvmm_release_lun)(struct nvm_dev *, int);
typedef void (nvmm_lun_info_print_fn)(struct nvm_dev *);
typedef int (nvmm_get_area_fn)(struct nvm_dev *, sector_t *, sector_t);
/* Configuration management */
nvmm_get_lun_fn *get_lun;
- nvmm_reserve_lun *reserve_lun;
- nvmm_release_lun *release_lun;
/* Statistics */
nvmm_lun_info_print_fn *lun_info_print;