From patchwork Fri Jan 8 18:14:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Matias_Bj=C3=B8rling?= X-Patchwork-Id: 7988591 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 2E429BEEE5 for ; Fri, 8 Jan 2016 18:16:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 466A0201EC for ; Fri, 8 Jan 2016 18:16:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 534B0201CE for ; Fri, 8 Jan 2016 18:16:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755657AbcAHSO6 (ORCPT ); Fri, 8 Jan 2016 13:14:58 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:32836 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932603AbcAHSOx (ORCPT ); Fri, 8 Jan 2016 13:14:53 -0500 Received: by mail-wm0-f67.google.com with SMTP id u188so17049961wmu.0 for ; Fri, 08 Jan 2016 10:14:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bjorling.me; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=ONjJYWKpTs5A6Htn2UvjwtjQAnDG6J32lTkoqatSnWw=; b=HIEINWLtRwxZl0fy/C4as+/b5bKJy7hFo2mTjZZqS0Y4jCjA+rzijGIcMuyQcgoXiX ojSti/kf9MUGsw5WyG0S7s65P3POkHX2zDcPL7ijBI+CqacgrpuyGzrcMHQ/pHIkyi0w C+X96UuHaiPhgN7HlmJaOXcBY3KneMH1/C1Cw= 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:mime-version:content-type:content-transfer-encoding; bh=ONjJYWKpTs5A6Htn2UvjwtjQAnDG6J32lTkoqatSnWw=; b=AperDBQDFP16bC2rZV4hsJom2ghkVkV8aX6ZxBNaGDl4Z/Ak8irh3EVPEThip3hSx7 njyU8HS80pWlNzqd+2cfIGRzPkeOvczHoJQ7/lhw5E+6oTS1ZGXE2WimUgZNMt1xpqKc pgbzUeV5ifIM7YltSTFXXcogSVwgH+fgSBZL/uamm6ZFMfARzbHLlD0yqNksmng2WXTo u84sjHr4a4j3M7QGw5ivP1ZoDJw7I28UWMOLUw+qoX9zI0a4P6otrOcouhy7Ujl6pGMK KGxshyavIvkzym3+WOvXVIoaa8HbqsIrSfNK1z+Qsh2y0SO8PN4INMk+jL+GuQN17xF0 uUhA== X-Gm-Message-State: ALoCoQlG82mloRKeGMAAtuKAM9u8bfWEwyghk2IxT7g8WvhVNy+/XGd/pEeTUZwDwR3nVA2cFVfWI0hTCRuQRw8GPhX4Vf7Psg== X-Received: by 10.194.209.129 with SMTP id mm1mr85267241wjc.47.1452276891585; Fri, 08 Jan 2016 10:14:51 -0800 (PST) Received: from localhost.localdomain (6164198-cl69.boa.fiberby.dk. [193.106.164.198]) by smtp.gmail.com with ESMTPSA id t9sm52713200wjf.33.2016.01.08.10.14.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Jan 2016 10:14:50 -0800 (PST) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 5/7] lightnvm: introduce ioctl to initialize device Date: Fri, 8 Jan 2016 19:14:35 +0100 Message-Id: <1452276877-390-5-git-send-email-m@bjorling.me> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1452276877-390-1-git-send-email-m@bjorling.me> References: <1452276877-390-1-git-send-email-m@bjorling.me> MIME-Version: 1.0 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_SIGNED, 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 Based on the previous patch, we now introduce an ioctl to initialize the device using nvm_init_sysblock and create the necessary system blocks. The user may specify the media manager that they wish to instantiate on top. Default from user-space will be "gennvm". Signed-off-by: Matias Bjørling --- drivers/lightnvm/core.c | 50 +++++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/lightnvm.h | 11 ++++++++++ 2 files changed, 61 insertions(+) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 73b8ae1..ee08fac 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -1019,6 +1019,54 @@ static long nvm_ioctl_dev_remove(struct file *file, void __user *arg) return __nvm_configure_remove(&remove); } +static void nvm_setup_nvm_sb_info(struct nvm_sb_info *info) +{ + info->seqnr = 1; + info->erase_cnt = 0; + info->version = 1; +} + +static long __nvm_ioctl_dev_init(struct nvm_ioctl_dev_init *init) +{ + struct nvm_dev *dev; + struct nvm_sb_info info; + + down_write(&nvm_lock); + dev = nvm_find_nvm_dev(init->dev); + up_write(&nvm_lock); + if (!dev) { + pr_err("nvm: device not found\n"); + return -EINVAL; + } + + nvm_setup_nvm_sb_info(&info); + + strncpy(info.mmtype, init->mmtype, NVM_MMTYPE_LEN); + info.fs_ppa.ppa = -1; + + return nvm_init_sysblock(dev, &info); +} + +static long nvm_ioctl_dev_init(struct file *file, void __user *arg) +{ + struct nvm_ioctl_dev_init init; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + if (copy_from_user(&init, arg, sizeof(struct nvm_ioctl_dev_init))) + return -EFAULT; + + if (init.flags != 0) { + pr_err("nvm: no flags supported\n"); + return -EINVAL; + } + + init.dev[DISK_NAME_LEN - 1] = '\0'; + + return __nvm_ioctl_dev_init(&init); +} + static long nvm_ctl_ioctl(struct file *file, uint cmd, unsigned long arg) { void __user *argp = (void __user *)arg; @@ -1032,6 +1080,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_INIT: + return nvm_ioctl_dev_init(file, argp); } return 0; } diff --git a/include/uapi/linux/lightnvm.h b/include/uapi/linux/lightnvm.h index 0171b85..56339e2 100644 --- a/include/uapi/linux/lightnvm.h +++ b/include/uapi/linux/lightnvm.h @@ -101,6 +101,12 @@ struct nvm_ioctl_remove { __u32 flags; }; +struct nvm_ioctl_dev_init { + char dev[DISK_NAME_LEN]; /* open-channel SSD device */ + char mmtype[NVM_MMTYPE_LEN]; /* register to media manager */ + + __u32 flags; +}; /* The ioctl type, 'L', 0x20 - 0x2F documented in ioctl-number.txt */ enum { @@ -111,6 +117,9 @@ enum { /* device level cmds */ NVM_DEV_CREATE_CMD, NVM_DEV_REMOVE_CMD, + + /* Init a device to support LightNVM media managers */ + NVM_DEV_INIT_CMD, }; #define NVM_IOCTL 'L' /* 0x4c */ @@ -123,6 +132,8 @@ enum { struct nvm_ioctl_create) #define NVM_DEV_REMOVE _IOW(NVM_IOCTL, NVM_DEV_REMOVE_CMD, \ struct nvm_ioctl_remove) +#define NVM_DEV_INIT _IOW(NVM_IOCTL, NVM_DEV_INIT_CMD, \ + struct nvm_ioctl_dev_init) #define NVM_VERSION_MAJOR 1 #define NVM_VERSION_MINOR 0