[PATCH V2 3/3] nvme: introduce pr_work to handle resv event

Guixin Liu kanie at linux.alibaba.com
Mon Jan 15 18:02:02 PST 2024


在 2024/1/15 16:59, Sagi Grimberg 写道:
>
>> When a reservation event is reported, the corresponding log page is
>> already on the target side, and the host side needs to send a get
>> log command to clear these log pages.
>
> AENs are already sent to userspace, I don't see why the kernel
> should read the log page unless it has something meaningful to
> do with it.
>
Is it tolerable if we dont clear the log page?

Maybe I should check the max count of resv_log_list in nvmet.

>>
>> Signed-off-by: Guixin Liu <kanie at linux.alibaba.com>
>> ---
>>   drivers/nvme/host/core.c | 47 +++++++++++++++++++++++++++++++++++++++-
>>   drivers/nvme/host/nvme.h |  1 +
>>   2 files changed, 47 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
>> index 60f14019f981..a906aea2f4a8 100644
>> --- a/drivers/nvme/host/core.c
>> +++ b/drivers/nvme/host/core.c
>> @@ -4220,6 +4220,47 @@ static void 
>> nvme_handle_aer_persistent_error(struct nvme_ctrl *ctrl)
>>       nvme_reset_ctrl(ctrl);
>>   }
>>   +static void nvme_queue_pr(struct nvme_ctrl *ctrl)
>> +{
>> +    if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE)
>> +        queue_work(nvme_wq, &ctrl->pr_work);
>> +}
>> +
>> +static void nvme_pr_work(struct work_struct *work)
>> +{
>> +    struct nvme_ctrl *ctrl = container_of(work, struct nvme_ctrl, 
>> pr_work);
>> +    struct nvme_pr_log log = { 0 };
>> +    int error;
>> +
>> +    if (nvme_ctrl_state(ctrl) != NVME_CTRL_LIVE)
>> +        return;
>> +
>> +    error = nvme_get_log(ctrl, NVME_NSID_ALL, NVME_LOG_RESERVATION, 0,
>> +            NVME_CSI_NVM, &log, sizeof(log), 0);
>> +    if (error) {
>> +        dev_warn(ctrl->device,
>> +             "reading reservation log failed: %d\n", error);
>> +        return;
>> +    }
>> +
>> +    if (log.nr_avl_pages)
>> +        nvme_queue_pr(ctrl);
>> +}
>> +
>> +static void nvme_handle_aen_css(struct nvme_ctrl *ctrl, u32 result)
>> +{
>> +    u32 aer_css_type = nvme_aer_subtype(result);
>> +
>> +    switch (aer_css_type) {
>> +    case NVME_AEN_RESV_LOG_PAGE_AVALIABLE:
>> +        nvme_queue_pr(ctrl);
>> +        break;
>> +    default:
>> +        ctrl->aen_result = result;
>> +        dev_warn(ctrl->device, "async event result %08x\n", result);
>> +    }
>> +}
>> +
>>   void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status,
>>           volatile union nvme_result *res)
>>   {
>> @@ -4236,6 +4277,9 @@ void nvme_complete_async_event(struct nvme_ctrl 
>> *ctrl, __le16 status,
>>       case NVME_AER_NOTICE:
>>           requeue = nvme_handle_aen_notice(ctrl, result);
>>           break;
>> +    case NVME_AER_CSS:
>> +        nvme_handle_aen_css(ctrl, result);
>> +        break;
>>       case NVME_AER_ERROR:
>>           /*
>>            * For a persistent internal error, don't run async_event_work
>> @@ -4247,7 +4291,6 @@ void nvme_complete_async_event(struct nvme_ctrl 
>> *ctrl, __le16 status,
>>           }
>>           fallthrough;
>>       case NVME_AER_SMART:
>> -    case NVME_AER_CSS:
>>       case NVME_AER_VS:
>>           ctrl->aen_result = result;
>>           break;
>> @@ -4389,6 +4432,7 @@ void nvme_stop_ctrl(struct nvme_ctrl *ctrl)
>>       nvme_stop_keep_alive(ctrl);
>>       nvme_stop_failfast_work(ctrl);
>>       flush_work(&ctrl->async_event_work);
>> +    flush_work(&ctrl->pr_work);
>>       cancel_work_sync(&ctrl->fw_act_work);
>>       if (ctrl->ops->stop_ctrl)
>>           ctrl->ops->stop_ctrl(ctrl);
>> @@ -4494,6 +4538,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, 
>> struct device *dev,
>>       ctrl->quirks = quirks;
>>       ctrl->numa_node = NUMA_NO_NODE;
>>       INIT_WORK(&ctrl->scan_work, nvme_scan_work);
>> +    INIT_WORK(&ctrl->pr_work, nvme_pr_work);
>>       INIT_WORK(&ctrl->async_event_work, nvme_async_event_work);
>>       INIT_WORK(&ctrl->fw_act_work, nvme_fw_act_work);
>>       INIT_WORK(&ctrl->delete_work, nvme_delete_ctrl_work);
>> diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
>> index e7411dac00f7..6ea4552c4de3 100644
>> --- a/drivers/nvme/host/nvme.h
>> +++ b/drivers/nvme/host/nvme.h
>> @@ -334,6 +334,7 @@ struct nvme_ctrl {
>>       struct nvme_effects_log *effects;
>>       struct xarray cels;
>>       struct work_struct scan_work;
>> +    struct work_struct pr_work;
>>       struct work_struct async_event_work;
>>       struct delayed_work ka_work;
>>       struct delayed_work failfast_work;



More information about the Linux-nvme mailing list