From patchwork Tue Feb 16 11:28:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenwei Tao X-Patchwork-Id: 8324261 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 17043C02AA for ; Tue, 16 Feb 2016 11:28:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 160EE2028D for ; Tue, 16 Feb 2016 11:28:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC3902027D for ; Tue, 16 Feb 2016 11:28:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754830AbcBPL1r (ORCPT ); Tue, 16 Feb 2016 06:27:47 -0500 Received: from mail-pa0-f46.google.com ([209.85.220.46]:34159 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750953AbcBPL1p (ORCPT ); Tue, 16 Feb 2016 06:27:45 -0500 Received: by mail-pa0-f46.google.com with SMTP id fy10so62535232pac.1; Tue, 16 Feb 2016 03:27:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IqdhHTdApx2ly/L8UBrZjYTB+Thr6uhlu2N/Rx6W9nM=; b=m1xDnpo6BJBNJJ4lRsmhgroF7044gVmb441h4fROm6FT6gpHCX4fjOQ8CzbkPyDuwb DXPahFt/AJEVPGhVUdjpyl9yIpL9Wxk58rFfAFV/vrVe6i/+XR6uEjzzwP/zeGoUgEgP t9NC/XpbG1oKLQQSdJM/B2IusMIJp0WJ0SbJdz248GWSW+EfNXnq/6pz5GLJEUg1vot2 qhyJF9ARthV4P5EGN1Eyj03+uXkjExK63zMSPamre1eBzRWmk2RUkxqTMKhEw5CJI5xy WObSG9zIYQjlPoI3Zvi841GXPdY+VdqWsIPPqykMROe4Yb/CSl6UhybbI9Nacxh06L7j a2BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IqdhHTdApx2ly/L8UBrZjYTB+Thr6uhlu2N/Rx6W9nM=; b=XLK29Jxs8XySua8HD6frWC1BvohyGmx0UHcrycgHkfQYsy3+b+DQEh5s740NYackjf gdwLuy9HeFB7CyRjLyk8NgusYq+YHphs8udmoDeGfPHaR6Eb8SuycN24C+Lcg1Rr1W4O KhL82DY8e2zg5JgfKm0vfGdcYNKSnKgLlgxyuFXyOFpOGr6IL6kMFPzJOJcCGddZZPh6 pWBSo5L3DunsQ0ZQfDxodgaR+YUT5pP0NKqAfc2nogx4xmdLeMKQG0H/rfIK7Na3Rf50 VrHEgstXBwNZZJGXVXpBIfoDltQLh7jpeh7GBgcMIa/8THx3ry35x3o6pFj6RRUyIaj+ UN6g== X-Gm-Message-State: AG10YOSqqHjFpx6V7MKPJUeNUIqo6+b4oW/Tbw85WU+oWIAk9n0wUWqu2XOLsDaxiq24Zw== X-Received: by 10.66.235.129 with SMTP id um1mr30009172pac.17.1455622064907; Tue, 16 Feb 2016 03:27:44 -0800 (PST) Received: from taowenwei.bj-memblaze.com ([111.204.49.2]) by smtp.gmail.com with ESMTPSA id z67sm45097744pfa.71.2016.02.16.03.27.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Feb 2016 03:27:44 -0800 (PST) From: Wenwei Tao To: mb@lightnvm.io Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH 2/2] lightnvm: export per lun information to user Date: Tue, 16 Feb 2016 19:28:09 +0800 Message-Id: <1455622089-1300-2-git-send-email-ww.tao0320@gmail.com> X-Mailer: git-send-email 2.7.1.windows.2 In-Reply-To: <1455622089-1300-1-git-send-email-ww.tao0320@gmail.com> References: <1455622089-1300-1-git-send-email-ww.tao0320@gmail.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 95c5445..7da3b6b 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); @@ -1042,6 +1041,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; @@ -1151,6 +1206,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 b97801c..222c7e8 100644 --- a/drivers/lightnvm/gennvm.c +++ b/drivers/lightnvm/gennvm.c @@ -505,6 +505,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; @@ -545,6 +578,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 = gennvm_get_area, diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index e90a761..0c815ae 100644 --- a/include/linux/lightnvm.h +++ b/include/linux/lightnvm.h @@ -472,6 +472,8 @@ typedef int (nvmm_erase_blk_fn)(struct nvm_dev *, struct nvm_block *, 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_get_luns_status)(struct nvm_dev *, + struct nvm_ioctl_luns_status *); typedef void (nvmm_lun_info_print_fn)(struct nvm_dev *); typedef int (nvmm_get_area_fn)(struct nvm_dev *, sector_t *, sector_t); @@ -502,6 +504,7 @@ struct nvmm_type { nvmm_release_lun *release_lun; /* Statistics */ + nvmm_get_luns_status *get_luns_status; nvmm_lun_info_print_fn *lun_info_print; nvmm_get_area_fn *get_area; diff --git a/include/uapi/linux/lightnvm.h b/include/uapi/linux/lightnvm.h index 6dbf6a0..2d52d6d 100644 --- a/include/uapi/linux/lightnvm.h +++ b/include/uapi/linux/lightnvm.h @@ -36,6 +36,7 @@ #define NVM_MMTYPE_LEN 8 #define NVM_LUNS_MAX 768 +#define NVM_LUNS_STATUS 64 #define NVM_CTRL_FILE "/dev/lightnvm/control" @@ -110,6 +111,25 @@ struct nvm_ioctl_remove { __u32 flags; }; +struct nvm_lun_status { + bool reserved; + __u32 id; + __u32 lun_id; + __u32 chnl_id; + __u32 nr_open_blocks; + __u32 nr_closed_blocks; + __u32 nr_free_blocks; + __u32 nr_bad_blocks; +}; + +struct nvm_ioctl_luns_status { + char dev[DISK_NAME_LEN]; + __u32 nr_luns; + __u32 lun_begin; + __u32 lun_end; + struct nvm_lun_status status[NVM_LUNS_STATUS]; +}; + struct nvm_ioctl_dev_init { char dev[DISK_NAME_LEN]; /* open-channel SSD device */ char mmtype[NVM_MMTYPE_LEN]; /* register to media manager */ @@ -140,6 +160,7 @@ enum { /* device level cmds */ NVM_DEV_CREATE_CMD, NVM_DEV_REMOVE_CMD, + NVM_DEV_LUNS_STATUS_CMD, /* Init a device to support LightNVM media managers */ NVM_DEV_INIT_CMD, @@ -158,6 +179,8 @@ enum { struct nvm_ioctl_create) #define NVM_DEV_REMOVE _IOW(NVM_IOCTL, NVM_DEV_REMOVE_CMD, \ struct nvm_ioctl_remove) +#define NVM_DEV_LUNS_STATUS _IOW(NVM_IOCTL, NVM_DEV_LUNS_STATUS_CMD, \ + struct nvm_ioctl_luns_status) #define NVM_DEV_INIT _IOW(NVM_IOCTL, NVM_DEV_INIT_CMD, \ struct nvm_ioctl_dev_init) #define NVM_DEV_FACTORY _IOW(NVM_IOCTL, NVM_DEV_FACTORY_CMD, \