Commit 55696154 authored by Matias Bjørling's avatar Matias Bjørling Committed by Jens Axboe

lightnvm: introduce ioctl to initialize device

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: default avatarMatias Bjørling <m@bjorling.me>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent e3eb3799
...@@ -1019,6 +1019,54 @@ static long nvm_ioctl_dev_remove(struct file *file, void __user *arg) ...@@ -1019,6 +1019,54 @@ static long nvm_ioctl_dev_remove(struct file *file, void __user *arg)
return __nvm_configure_remove(&remove); 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) static long nvm_ctl_ioctl(struct file *file, uint cmd, unsigned long arg)
{ {
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
...@@ -1032,6 +1080,8 @@ static long nvm_ctl_ioctl(struct file *file, uint cmd, unsigned long 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); return nvm_ioctl_dev_create(file, argp);
case NVM_DEV_REMOVE: case NVM_DEV_REMOVE:
return nvm_ioctl_dev_remove(file, argp); return nvm_ioctl_dev_remove(file, argp);
case NVM_DEV_INIT:
return nvm_ioctl_dev_init(file, argp);
} }
return 0; return 0;
} }
......
...@@ -101,6 +101,12 @@ struct nvm_ioctl_remove { ...@@ -101,6 +101,12 @@ struct nvm_ioctl_remove {
__u32 flags; __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 */ /* The ioctl type, 'L', 0x20 - 0x2F documented in ioctl-number.txt */
enum { enum {
...@@ -111,6 +117,9 @@ enum { ...@@ -111,6 +117,9 @@ enum {
/* device level cmds */ /* device level cmds */
NVM_DEV_CREATE_CMD, NVM_DEV_CREATE_CMD,
NVM_DEV_REMOVE_CMD, NVM_DEV_REMOVE_CMD,
/* Init a device to support LightNVM media managers */
NVM_DEV_INIT_CMD,
}; };
#define NVM_IOCTL 'L' /* 0x4c */ #define NVM_IOCTL 'L' /* 0x4c */
...@@ -123,6 +132,8 @@ enum { ...@@ -123,6 +132,8 @@ enum {
struct nvm_ioctl_create) struct nvm_ioctl_create)
#define NVM_DEV_REMOVE _IOW(NVM_IOCTL, NVM_DEV_REMOVE_CMD, \ #define NVM_DEV_REMOVE _IOW(NVM_IOCTL, NVM_DEV_REMOVE_CMD, \
struct nvm_ioctl_remove) 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_MAJOR 1
#define NVM_VERSION_MINOR 0 #define NVM_VERSION_MINOR 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment