From patchwork Sat Mar 19 16:58:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenwei Tao X-Patchwork-Id: 8625541 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 DBAF9C0553 for ; Sat, 19 Mar 2016 17:00:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C6001203EB for ; Sat, 19 Mar 2016 17:00:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 185A1203FB for ; Sat, 19 Mar 2016 17:00:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932256AbcCSRAw (ORCPT ); Sat, 19 Mar 2016 13:00:52 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33799 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932254AbcCSRAv (ORCPT ); Sat, 19 Mar 2016 13:00:51 -0400 Received: by mail-pf0-f196.google.com with SMTP id n5so22230177pfn.1; Sat, 19 Mar 2016 10:00:50 -0700 (PDT) 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=R4PtVbof0g0HaNYrQa6rfiPh+7fbDBeqbte1S5EFRfE=; b=zpXaPt5NLXofOk0t2I+rsJUU/EKEylyJAhIyxbrhD/SV38xN/bhodPQdRUtrXpxcHS 9oCzR9pZpUEUC/YM9+0RPzx28tsrimkXBCFUbGeHWEfttICMGGjKPK+KZxDKUgJmoy2M FJluBDfqH8dkLdMMdlz2BWFAB7QHZGGbOLnx/TQcc3W7PJxxIbSrlSkY/COdDTp2lwys Fm4NCfpzpuC5LuHiBFN8wZXOJSizKD6qsJ7XR7N3uFxcPjy6nAfj+Wyf7oj878/JkRTn d7vTLWhrWlgRz24iPWhicDuE96LsLNqbi3DDMFaoBBh0VVeSYyisMw+ufLhScfFTC7uY RPdQ== 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=R4PtVbof0g0HaNYrQa6rfiPh+7fbDBeqbte1S5EFRfE=; b=nBKWUDpH+FGXtYaL4Q7XX4WDocadWy1zT/3a6tcrqskTEALjZZ9iP0JabVEjyFbl0L ECUKZcgZH4ZFOGgr7CW0/roEHaBfiyle3rB6GmNCZl6/ZlnsDY+CT8OfS+P0DhH2ioWQ 7Rp39KVFuj922Rabkr0oWOS5Zkzc5D64kUvZJUT4NNX1Oocmhhbt2xeMrxN6qRSrHMWd VgXO6epV0vrAsqTEGE3MZJtnO5Z2pC79HNTIWZk283IqbLJ0M8wi73S9dsxF+/7xwhr8 sJsHRvf0YPBL4ISAeKwDPZEn0E4m+RwW1JCt8mhQMzySfJjqS8bQN7tR5WdonXiaNIFB CM9w== X-Gm-Message-State: AD7BkJKIUJZipvBo7LqTFsdHiSJcAI2tvtS810DPjEGInGof7Fpz2KjEBs2s6mZNhiggGA== X-Received: by 10.98.10.156 with SMTP id 28mr32624419pfk.130.1458406850484; Sat, 19 Mar 2016 10:00:50 -0700 (PDT) Received: from localhost.localdomain ([2002:72f6:a61b::72f6:a61b]) by smtp.gmail.com with ESMTPSA id v14sm29268489pas.10.2016.03.19.10.00.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 19 Mar 2016 10:00:50 -0700 (PDT) From: Wenwei Tao To: mb@lightnvm.io, jg@lightnvm.io Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH 3/3] lightnvm: export per lun information to user Date: Sun, 20 Mar 2016 00:58:58 +0800 Message-Id: <1458406738-4828-3-git-send-email-ww.tao0320@gmail.com> X-Mailer: git-send-email 2.7.0.windows.2 In-Reply-To: <1458406738-4828-1-git-send-email-ww.tao0320@gmail.com> References: <1458406738-4828-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=ham 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 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 = gennvm_get_area, diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index b941a8c..88b95f9 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, \