nvme: don't bother to look up a namespace for controller ioctls
Don't bother to look up a namespace just to drop if after retreiving the controller for the multipath case. Just look up a live controller for the subsystem directly. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Keith Busch <kbusch@kernel.org> Reviewed-by: Javier González <javier.gonz@samsung.com>
This commit is contained in:
parent
2f907f7f96
commit
3557a44097
@ -2336,42 +2336,60 @@ static void nvme_ns_head_release(struct gendisk *disk, fmode_t mode)
|
|||||||
nvme_put_ns_head(disk->private_data);
|
nvme_put_ns_head(disk->private_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nvme_ns_head_ctrl_ioctl(struct nvme_ns *ns, unsigned int cmd,
|
static struct nvme_ctrl *nvme_find_get_live_ctrl(struct nvme_subsystem *subsys)
|
||||||
void __user *argp, struct nvme_ns_head *head, int srcu_idx)
|
|
||||||
{
|
{
|
||||||
struct nvme_ctrl *ctrl = ns->ctrl;
|
struct nvme_ctrl *ctrl;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
nvme_get_ctrl(ns->ctrl);
|
ret = mutex_lock_killable(&nvme_subsystems_lock);
|
||||||
nvme_put_ns_from_disk(head, srcu_idx);
|
if (ret)
|
||||||
ret = nvme_ctrl_ioctl(ns->ctrl, cmd, argp);
|
return ERR_PTR(ret);
|
||||||
|
list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) {
|
||||||
|
if (ctrl->state == NVME_CTRL_LIVE)
|
||||||
|
goto found;
|
||||||
|
}
|
||||||
|
mutex_unlock(&nvme_subsystems_lock);
|
||||||
|
return ERR_PTR(-EWOULDBLOCK);
|
||||||
|
found:
|
||||||
|
nvme_get_ctrl(ctrl);
|
||||||
|
mutex_unlock(&nvme_subsystems_lock);
|
||||||
|
return ctrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nvme_ns_head_ctrl_ioctl(struct nvme_ns_head *head,
|
||||||
|
unsigned int cmd, void __user *argp)
|
||||||
|
{
|
||||||
|
struct nvme_ctrl *ctrl = nvme_find_get_live_ctrl(head->subsys);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (IS_ERR(ctrl))
|
||||||
|
return PTR_ERR(ctrl);
|
||||||
|
ret = nvme_ctrl_ioctl(ctrl, cmd, argp);
|
||||||
nvme_put_ctrl(ctrl);
|
nvme_put_ctrl(ctrl);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int nvme_ns_head_ns_ioctl(struct nvme_ns_head *head,
|
||||||
|
unsigned int cmd, void __user *argp)
|
||||||
|
{
|
||||||
|
int srcu_idx = srcu_read_lock(&head->srcu);
|
||||||
|
struct nvme_ns *ns = nvme_find_path(head);
|
||||||
|
int ret = -EWOULDBLOCK;
|
||||||
|
|
||||||
|
if (ns)
|
||||||
|
ret = nvme_ns_ioctl(ns, cmd, argp);
|
||||||
|
srcu_read_unlock(&head->srcu, srcu_idx);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int nvme_ns_head_ioctl(struct block_device *bdev, fmode_t mode,
|
static int nvme_ns_head_ioctl(struct block_device *bdev, fmode_t mode,
|
||||||
unsigned int cmd, unsigned long arg)
|
unsigned int cmd, unsigned long arg)
|
||||||
{
|
{
|
||||||
struct nvme_ns_head *head = NULL;
|
struct nvme_ns_head *head = bdev->bd_disk->private_data;
|
||||||
void __user *argp = (void __user *)arg;
|
|
||||||
struct nvme_ns *ns;
|
|
||||||
int srcu_idx, ret;
|
|
||||||
|
|
||||||
ns = nvme_get_ns_from_disk(bdev->bd_disk, &head, &srcu_idx);
|
|
||||||
if (unlikely(!ns))
|
|
||||||
return -EWOULDBLOCK;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Handle ioctls that apply to the controller instead of the namespace
|
|
||||||
* seperately and drop the ns SRCU reference early. This avoids a
|
|
||||||
* deadlock when deleting namespaces using the passthrough interface.
|
|
||||||
*/
|
|
||||||
if (is_ctrl_ioctl(cmd))
|
if (is_ctrl_ioctl(cmd))
|
||||||
return nvme_ns_head_ctrl_ioctl(ns, cmd, argp, head, srcu_idx);
|
return nvme_ns_head_ctrl_ioctl(head, cmd, (void __user *)arg);
|
||||||
|
return nvme_ns_head_ns_ioctl(head, cmd, (void __user *)arg);
|
||||||
ret = nvme_ns_ioctl(ns, cmd, argp);
|
|
||||||
nvme_put_ns_from_disk(head, srcu_idx);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct block_device_operations nvme_ns_head_ops = {
|
const struct block_device_operations nvme_ns_head_ops = {
|
||||||
|
Loading…
Reference in New Issue
Block a user