[PATCH 1/8] nvmet: add debugfs support

Daniel Wagner dwagner at suse.de
Mon Mar 25 12:22:24 PDT 2024


On Mon, Mar 25, 2024 at 07:18:52PM +0100, Daniel Wagner wrote:
> On Fri, Mar 22, 2024 at 08:03:26AM +0100, Hannes Reinecke wrote:
> > +static ssize_t nvmet_ctrl_state_write(struct file *file, const char __user *buf,
> > +				      size_t count, loff_t *ppos)
> > +{
> > +	struct seq_file *m = file->private_data;
> > +	struct nvmet_ctrl *ctrl = m->private;
> > +	char reset[16];
> > +
> > +	if (count >= sizeof(reset))
> > +		return -EINVAL;
> > +	if (copy_from_user(reset, buf, count))
> > +		return -EFAULT;
> > +	if (!memcmp(reset, "fatal", 5))
> > +		nvmet_ctrl_fatal_error(ctrl);
> 
> I'd like to use this also to trigger a reset. This allows to test the
> auth code a bit better, e.g. after changing the ctrl key on the target
> nothing will happen until a reconnect happens. Currently, I have to
> set the max queue count which triggers a reset. Also it would make the
> 'support real hardware' series for blktests why more generic.
> 
> This here should does the trick in my local testing:
> 
> --- a/drivers/nvme/target/debugfs.c
> +++ b/drivers/nvme/target/debugfs.c
> @@ -157,6 +157,8 @@ static ssize_t nvmet_ctrl_state_write(struct file *file, const char __user *buf,
>                 return -EFAULT;
>         if (!memcmp(reset, "fatal", 5))
>                 nvmet_ctrl_fatal_error(ctrl);
> +       else if (!memcmp(reset, "reset", 5))
> +               ctrl->ops->delete_ctrl(ctrl);
>         else
>                 return -EINVAL;
>         return count;
> 

and here the corresponding test extension (nvme/045)

	echo "Renew host key on the controller and force reconnect"

	new_hostkey="$(nvme gen-dhchap-key -n ${def_subsysnqn} 2> /dev/null)"

	_set_nvmet_hostkey "${def_hostnqn}" "${new_hostkey}"

	# Force a reconnect
	nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
	cntlid="$(nvme id-ctrl -o json "/dev/${nvmedev}" | jq .cntlid)"
	echo "reset" > /sys/kernel/debug/nvmet/"${def_subsysnqn}/ctrl${cntlid}"/state
	nvmf_wait_for_ctrl_delete "${nvmedev}"



More information about the Linux-nvme mailing list