From patchwork Thu Sep 14 09:03:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kenjiro Nakayama X-Patchwork-Id: 9952623 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 80C6760317 for ; Thu, 14 Sep 2017 09:03:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7291628D74 for ; Thu, 14 Sep 2017 09:03:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6689D28DCB; Thu, 14 Sep 2017 09:03:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3F4A28D74 for ; Thu, 14 Sep 2017 09:03:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751258AbdINJDV (ORCPT ); Thu, 14 Sep 2017 05:03:21 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:34659 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751174AbdINJDU (ORCPT ); Thu, 14 Sep 2017 05:03:20 -0400 Received: by mail-pf0-f193.google.com with SMTP id g65so1242407pfe.1 for ; Thu, 14 Sep 2017 02:03:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=iBrE+vDmvP0rym/X28sr+nKMpkPMI4GXcwC1+3cto68=; b=KpL3tBEOsrKNaWTBEjTJWWFFGuordr6x4mMk1VXBpCgmUD7XOla016uPErGaZkpPrD dBPqUYhN8aWwkMzoWdKfL4IbiFF+5Kcozw3mXGCW9Ny4CTAmvMBQYF8cZ4M6oLpYZUdN QrmEwWvzfHhqZ2UhVJNPdNvbeWisTKB9bIKw5rERk2Ne6xQA2/1bRaAoe+3FePbAFaEm AARHHE7hYWUYf8IMi6Af6KEHUSq4kDO2aR3n93RIFy6ytXAvmEKDJqbFfMw4NPxpf8Nl E1bgDyoX44xgPy9z5xp+g3Zqo6PtfOhlhV6EeV/Vgg47KFgyMDJ+JPSF2m4McOgcs/k7 fNjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=iBrE+vDmvP0rym/X28sr+nKMpkPMI4GXcwC1+3cto68=; b=Fl+o5dr0wE10SsC/LJdd5oPx7OJ8vIX8rv/7RPLhk/7hQ+aFyZrRR5wsTfZfsk/qYa gW8NtjtKh/vt6OhqSccy3TW8/qnXG1R9bf8JqRZZqfWP2mrhDWMqLwnt+s/PKtnH6JhL 7apIKJdQW1tvT4yXrXnDZfdMV7SIHka2kwvbr+beZj3se3GlmOBHl/4f7uwa665Mg9X9 /FpxSQwJkDegdqhD2ifyo8uOTz9iBtTjpvVxfab3aGccy/JpfqJ0JSiVREVW/a5J157V ZkyhybKTBoaFH27Jv1nhtR+7jD4D8/hmVMnDKB+niQtTBxwroXt8qwdDF7WOAyHvhMTa u+VA== X-Gm-Message-State: AHPjjUj4ZicUrHareV4oqBItCIXCLPczPXGhux8+oitVLOtHR4f2NqRt cxgE652pgB/tuBy2 X-Google-Smtp-Source: ADKCNb7sXS+aX4GoJFqGPFqoR55UGfTwAzKg/k6jYsktj71VrGIuA1opyQibZP2uwbX5/YFQ2GXE6Q== X-Received: by 10.84.252.130 with SMTP id y2mr22667501pll.68.1505379799820; Thu, 14 Sep 2017 02:03:19 -0700 (PDT) Received: from p50.localdomain ([2400:4030:ac55:d000:18f3:45f2:6d16:16e9]) by smtp.gmail.com with ESMTPSA id z83sm27834687pfd.10.2017.09.14.02.03.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Sep 2017 02:03:19 -0700 (PDT) From: Kenjiro Nakayama To: target-devel@vger.kernel.org Cc: nab@linux-iscsi.org, mchristi@redhat.com, Kenjiro Nakayama Subject: [PATCH v2] target/tcmu: Add a timeout for the completion of netlink command reply Date: Thu, 14 Sep 2017 18:03:09 +0900 Message-Id: <20170914090309.22297-1-nakayamakenjiro@gmail.com> X-Mailer: git-send-email 2.13.5 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds a timeout for the completion of netlink command reply. Current code waits for the netlink reply from userspace and the status change, but it hangs forever when userspace failed to reply. To fix this issue, this patch replace wait_for_completion with wait_for_completion_timeout. Default timeout is 300 sec that gives enough time, and this is configurable via configfs. Changes in v2: Makes default timeout enough long as 300 sec. Makes timeout configurable via configfs. Suggested by Mike Christie. Signed-off-by: Kenjiro Nakayama --- drivers/target/target_core_user.c | 59 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index 942d094269fb..ef8570cb68a8 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -150,6 +150,9 @@ struct tcmu_dev { wait_queue_head_t nl_cmd_wq; char dev_config[TCMU_CONFIG_LEN]; + + /* timeout for netlink reply from userspace */ + unsigned int nl_timeout; }; #define TCMU_DEV(_se_dev) container_of(_se_dev, struct tcmu_dev, se_dev) @@ -1332,8 +1335,14 @@ static int tcmu_wait_genl_cmd_reply(struct tcmu_dev *udev) if (!tcmu_kern_cmd_reply_supported) return 0; - pr_debug("sleeping for nl reply\n"); - wait_for_completion(&nl_cmd->complete); + pr_debug("sleeping for nl reply with timeout %lu\n", + msecs_to_jiffies(udev->nl_timeout)); + ret = wait_for_completion_timeout(&nl_cmd->complete, + msecs_to_jiffies(udev->nl_timeout)); + if (!ret) { + printk(KERN_ERR "timeout waiting for nl reply from userspace\n"); + return -ETIME; + } spin_lock(&udev->nl_cmd_lock); nl_cmd->cmd = TCMU_CMD_UNSPEC; @@ -1506,6 +1515,10 @@ static int tcmu_configure_device(struct se_device *dev) dev->dev_attrib.emulate_write_cache = 0; dev->dev_attrib.hw_queue_depth = 128; + /* Set default timeout 300 sec */ + if (!udev->nl_timeout) + udev->nl_timeout = 300000; + /* * Get a ref incase userspace does a close on the uio device before * LIO has initiated tcmu_free_device. @@ -1610,7 +1623,7 @@ static void tcmu_destroy_device(struct se_device *dev) enum { Opt_dev_config, Opt_dev_size, Opt_hw_block_size, Opt_hw_max_sectors, - Opt_err, + Opt_nl_timeout, Opt_err, }; static match_table_t tokens = { @@ -1618,6 +1631,7 @@ static match_table_t tokens = { {Opt_dev_size, "dev_size=%u"}, {Opt_hw_block_size, "hw_block_size=%u"}, {Opt_hw_max_sectors, "hw_max_sectors=%u"}, + {Opt_nl_timeout, "nl_timeout=%u"}, {Opt_err, NULL} }; @@ -1692,6 +1706,17 @@ static ssize_t tcmu_set_configfs_dev_params(struct se_device *dev, ret = tcmu_set_dev_attrib(&args[0], &(dev->dev_attrib.hw_max_sectors)); break; + case Opt_nl_timeout: + arg_p = match_strdup(&args[0]); + if (!arg_p) { + ret = -ENOMEM; + break; + } + ret = kstrtou32(arg_p, 0, &udev->nl_timeout); + kfree(arg_p); + if (ret < 0) + pr_err("kstrtoul() failed for nl_timeout=\n"); + break; default: break; } @@ -1879,11 +1904,39 @@ static ssize_t tcmu_emulate_write_cache_store(struct config_item *item, } CONFIGFS_ATTR(tcmu_, emulate_write_cache); +static ssize_t tcmu_nl_timeout_show(struct config_item *item, char *page) +{ + struct se_dev_attrib *da = container_of(to_config_group(item), + struct se_dev_attrib, da_group); + struct tcmu_dev *udev = TCMU_DEV(da->da_dev); + + return snprintf(page, PAGE_SIZE, "%u\n", udev->nl_timeout); +} + +static ssize_t tcmu_nl_timeout_store(struct config_item *item, + const char *page, size_t count) +{ + struct se_dev_attrib *da = container_of(to_config_group(item), + struct se_dev_attrib, da_group); + struct tcmu_dev *udev = TCMU_DEV(da->da_dev); + u32 val; + int ret; + + ret = kstrtou32(page, 0, &val); + if (ret < 0) + return ret; + + udev->nl_timeout = val; + return count; +} +CONFIGFS_ATTR(tcmu_, nl_timeout); + static struct configfs_attribute *tcmu_attrib_attrs[] = { &tcmu_attr_cmd_time_out, &tcmu_attr_dev_config, &tcmu_attr_dev_size, &tcmu_attr_emulate_write_cache, + &tcmu_attr_nl_timeout, NULL, };