Re: [PATCH 3/3] lightnvm: export per lun information to user
On 03/22/2016 12:28 PM, Wenwei Tao wrote: I notice that sysfs already have lun information exposed, we only need to add some more, You are right, but that is for the configure_debug interface. It is not compiled in on production kernels.
Re: [PATCH 3/3] lightnvm: export per lun information to user
I notice that sysfs already have lun information exposed, we only need to add some more, 2016-03-21 18:27 GMT+08:00 Matias Bjørling : > On 03/19/2016 05:58 PM, Wenwei Tao wrote: >> >> Export per lun information to user, let the user >> know more detail information about underlying device. >> >> Signed-off-by: Wenwei Tao >> --- >> drivers/lightnvm/core.c | 59 >> ++- >> drivers/lightnvm/gennvm.c | 34 + >> include/linux/lightnvm.h | 3 +++ >> include/uapi/linux/lightnvm.h | 23 + >> 4 files changed, 118 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c >> index 84bc72d..7701eab 100644 >> --- a/drivers/lightnvm/core.c >> +++ b/drivers/lightnvm/core.c >> @@ -28,7 +28,6 @@ >> #include >> #include >> #include >> -#include >> >> static LIST_HEAD(nvm_targets); >> static LIST_HEAD(nvm_mgrs); >> @@ -1041,6 +1040,62 @@ static long nvm_ioctl_dev_remove(struct file *file, >> void __user *arg) >> return __nvm_configure_remove(&remove); >> } >> >> +static long nvm_ioctl_dev_luns_status(struct file *file, void __user >> *arg) >> +{ >> + struct nvm_dev *dev; >> + struct nvm_ioctl_luns_status *status; >> + long ret = -EINVAL; >> + >> + if (!capable(CAP_SYS_ADMIN)) >> + return -EPERM; >> + >> + status = kzalloc(sizeof(struct nvm_ioctl_luns_status), >> GFP_KERNEL); >> + if (!status) >> + return -ENOMEM; >> + >> + if (copy_from_user(status, arg, >> + sizeof(struct nvm_ioctl_luns_status))) { >> + ret = -EFAULT; >> + goto out; >> + } >> + >> + status->dev[DISK_NAME_LEN - 1] = '\0'; >> + down_write(&nvm_lock); >> + dev = nvm_find_nvm_dev(status->dev); >> + up_write(&nvm_lock); >> + if (!dev) { >> + pr_err("nvm: device not found\n"); >> + goto out; >> + } >> + >> + if (!dev->mt) { >> + pr_info("nvm: device has no media manager registered.\n"); >> + ret = -ENODEV; >> + goto out; >> + } >> + >> + if (status->lun_begin > status->lun_end || >> + status->lun_end > dev->nr_luns) { >> + pr_err("nvm: lun out of bound (%u:%u > %u)\n", >> + status->lun_begin, status->lun_end, dev->nr_luns); >> + goto out; >> + } >> + >> + dev->mt->get_luns_status(dev, status); >> + >> + if (copy_to_user(arg, status, >> +sizeof(struct nvm_ioctl_luns_status))) { >> + ret = -EFAULT; >> + goto out; >> + } >> + >> + ret = 0; >> + >> +out: >> + kfree(status); >> + return ret; >> +} >> + >> static void nvm_setup_nvm_sb_info(struct nvm_sb_info *info) >> { >> info->seqnr = 1; >> @@ -1150,6 +1205,8 @@ static long nvm_ctl_ioctl(struct file *file, uint >> cmd, unsigned long arg) >> return nvm_ioctl_dev_create(file, argp); >> case NVM_DEV_REMOVE: >> return nvm_ioctl_dev_remove(file, argp); >> + case NVM_DEV_LUNS_STATUS: >> + return nvm_ioctl_dev_luns_status(file, argp); >> case NVM_DEV_INIT: >> return nvm_ioctl_dev_init(file, argp); >> case NVM_DEV_FACTORY: >> diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c >> index 72e124a..b2390f4 100644 >> --- a/drivers/lightnvm/gennvm.c >> +++ b/drivers/lightnvm/gennvm.c >> @@ -502,6 +502,39 @@ static struct nvm_lun *gennvm_get_lun(struct nvm_dev >> *dev, int lunid) >> return &gn->luns[lunid].vlun; >> } >> >> +static void gennvm_get_luns_status(struct nvm_dev *dev, >> + struct nvm_ioctl_luns_status *status) >> +{ >> + int i, lun_begin = status->lun_begin; >> + int nr_luns, lun_end = status->lun_end; >> + struct gen_nvm *gn = dev->mp; >> + struct nvm_lun_status *lun_stat; >> + struct gen_lun *lun; >> + >> + status->nr_luns = dev->nr_luns; >> + nr_luns = min(lun_end - lun_begin + 1, >> + NVM_LUNS_STATUS); >> + >> + for (i = 0; i < nr_luns; i++) { >> + lun = &gn->luns[i + lun_begin]; >> + lun_stat = &status->status[i]; >> + >> + lun_stat->reserved = >> + test_bit(i + lun_begin, dev->lun_map); >> + lun_stat->id = lun->vlun.id; >> + lun_stat->lun_id = lun->vlun.lun_id; >> + lun_stat->chnl_id = lun->vlun.chnl_id; >> + lun_stat->nr_free_blocks = >> + lun->vlun.nr_free_blocks; >> + lun_stat->nr_open_blocks = >> + lun->vlun.nr_open_blocks; >> + lun_stat->nr_closed_blocks = >> + lun->vlun.nr_closed_blocks; >> + lun_stat->nr
Re: [PATCH 3/3] lightnvm: export per lun information to user
On 03/19/2016 05:58 PM, Wenwei Tao wrote: Export per lun information to user, let the user know more detail information about underlying device. Signed-off-by: Wenwei Tao --- drivers/lightnvm/core.c | 59 ++- drivers/lightnvm/gennvm.c | 34 + include/linux/lightnvm.h | 3 +++ include/uapi/linux/lightnvm.h | 23 + 4 files changed, 118 insertions(+), 1 deletion(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 84bc72d..7701eab 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -28,7 +28,6 @@ #include #include #include -#include static LIST_HEAD(nvm_targets); static LIST_HEAD(nvm_mgrs); @@ -1041,6 +1040,62 @@ static long nvm_ioctl_dev_remove(struct file *file, void __user *arg) return __nvm_configure_remove(&remove); } +static long nvm_ioctl_dev_luns_status(struct file *file, void __user *arg) +{ + struct nvm_dev *dev; + struct nvm_ioctl_luns_status *status; + long ret = -EINVAL; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + status = kzalloc(sizeof(struct nvm_ioctl_luns_status), GFP_KERNEL); + if (!status) + return -ENOMEM; + + if (copy_from_user(status, arg, + sizeof(struct nvm_ioctl_luns_status))) { + ret = -EFAULT; + goto out; + } + + status->dev[DISK_NAME_LEN - 1] = '\0'; + down_write(&nvm_lock); + dev = nvm_find_nvm_dev(status->dev); + up_write(&nvm_lock); + if (!dev) { + pr_err("nvm: device not found\n"); + goto out; + } + + if (!dev->mt) { + pr_info("nvm: device has no media manager registered.\n"); + ret = -ENODEV; + goto out; + } + + if (status->lun_begin > status->lun_end || + status->lun_end > dev->nr_luns) { + pr_err("nvm: lun out of bound (%u:%u > %u)\n", + status->lun_begin, status->lun_end, dev->nr_luns); + goto out; + } + + dev->mt->get_luns_status(dev, status); + + if (copy_to_user(arg, status, +sizeof(struct nvm_ioctl_luns_status))) { + ret = -EFAULT; + goto out; + } + + ret = 0; + +out: + kfree(status); + return ret; +} + static void nvm_setup_nvm_sb_info(struct nvm_sb_info *info) { info->seqnr = 1; @@ -1150,6 +1205,8 @@ static long nvm_ctl_ioctl(struct file *file, uint cmd, unsigned long arg) return nvm_ioctl_dev_create(file, argp); case NVM_DEV_REMOVE: return nvm_ioctl_dev_remove(file, argp); + case NVM_DEV_LUNS_STATUS: + return nvm_ioctl_dev_luns_status(file, argp); case NVM_DEV_INIT: return nvm_ioctl_dev_init(file, argp); case NVM_DEV_FACTORY: diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c index 72e124a..b2390f4 100644 --- a/drivers/lightnvm/gennvm.c +++ b/drivers/lightnvm/gennvm.c @@ -502,6 +502,39 @@ static struct nvm_lun *gennvm_get_lun(struct nvm_dev *dev, int lunid) return &gn->luns[lunid].vlun; } +static void gennvm_get_luns_status(struct nvm_dev *dev, + struct nvm_ioctl_luns_status *status) +{ + int i, lun_begin = status->lun_begin; + int nr_luns, lun_end = status->lun_end; + struct gen_nvm *gn = dev->mp; + struct nvm_lun_status *lun_stat; + struct gen_lun *lun; + + status->nr_luns = dev->nr_luns; + nr_luns = min(lun_end - lun_begin + 1, + NVM_LUNS_STATUS); + + for (i = 0; i < nr_luns; i++) { + lun = &gn->luns[i + lun_begin]; + lun_stat = &status->status[i]; + + lun_stat->reserved = + test_bit(i + lun_begin, dev->lun_map); + lun_stat->id = lun->vlun.id; + lun_stat->lun_id = lun->vlun.lun_id; + lun_stat->chnl_id = lun->vlun.chnl_id; + lun_stat->nr_free_blocks = + lun->vlun.nr_free_blocks; + lun_stat->nr_open_blocks = + lun->vlun.nr_open_blocks; + lun_stat->nr_closed_blocks = + lun->vlun.nr_closed_blocks; + lun_stat->nr_bad_blocks = + lun->vlun.nr_bad_blocks; + } +} + static void gennvm_lun_info_print(struct nvm_dev *dev) { struct gen_nvm *gn = dev->mp; @@ -542,6 +575,7 @@ static struct nvmm_type gennvm = { .get_lun= gennvm_get_lun, .reserve_lun= gennvm_reserve_lun, .release_lun= gennvm_release_lun, + .get_luns_status= gennvm_get_luns_status, .lun_info_print = gennvm_lun_info_print, .get_area = genn