From patchwork Wed Sep 13 05:01:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kenjiro Nakayama X-Patchwork-Id: 9950429 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 9C84E60245 for ; Wed, 13 Sep 2017 05:01:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F93529038 for ; Wed, 13 Sep 2017 05:01:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 840D629030; Wed, 13 Sep 2017 05:01:39 +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 EDE2B29030 for ; Wed, 13 Sep 2017 05:01:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751247AbdIMFBi (ORCPT ); Wed, 13 Sep 2017 01:01:38 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:35439 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751153AbdIMFBh (ORCPT ); Wed, 13 Sep 2017 01:01:37 -0400 Received: by mail-pf0-f194.google.com with SMTP id i23so2292610pfi.2 for ; Tue, 12 Sep 2017 22:01:37 -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=U+Da6N36ubf8ZfSv6WO+lFv+vNPQzokBNebE2/dAHSU=; b=hknDZymOx6u9Okbc5UWRS/BIaD5aQCn2LMvb9r3//KwseyQ6Uvz7G7BKUzgnJl+5Yv 0BpzP9fc8A/u4vbTP7gBybHZJwr2RI6hMcENNhzMj1aRx+SJeveySSSJEwqbKFQX8sPU KHlLVSxLGxvaMxX2cKgiGqrMFdEM/bl1nrVykO647vBNVXV7He+5pl4xkGjx+Oy9lc1k a1A2nIJn8ervvSvqyfMVaD4TOspYWHefVe1zi3T02dqQY/t1/Hk7dPxjYMUnWS3iExxq pvRJS8Im1kzysMBmhwT7zuYDp25qFSlGrRKHRv+8SFM7rNFP6WNuYDMcrG0OsuyA0lpq gokQ== 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=U+Da6N36ubf8ZfSv6WO+lFv+vNPQzokBNebE2/dAHSU=; b=Uoecg+cKjHRBoI8QnFzlDIY9ypB0GZF9GBmORGL5c+i5++LhnIP3vp69VDQlni2sFL nvF0tisqW2BccvA51zWL7QnW1uqq0ExIkeFDURBrLLTJDAJQxlqJkNbxbpSNqYWZNsLa LYagelXD0+7ED6h6Hl2OMZyYhFAWoOxTN9Ww//OZ3aeHNpnUlGU/5DWHMf+m33+S/cAR a1jX8DL4yQTvVyHCXK2wYRI2sl7G60ODzIRtQEs+fWUn8aemKpmuDS0tElYU8/cb4oEM 5mLv50OmorBQAg0lEuD3FfZ25pUc5FR6gtlewukWDjxUq5xMMm5+9ZupbOnLAa0o5kUy ip0Q== X-Gm-Message-State: AHPjjUjQC1LsWoYFn7+dw7AoSK20B2r+vLg0Gv8w9Bc1x6UzREtGTwGB 6oDmDoeuxkqOwLtg X-Google-Smtp-Source: ADKCNb5OxygQa4fZPQxhc+zODqHX1J51pR6CZkH9wEoASwUamuKpKDLveH69fOYhgAk1ZCCp86QgMA== X-Received: by 10.101.88.203 with SMTP id e11mr10591335pgu.95.1505278896701; Tue, 12 Sep 2017 22:01:36 -0700 (PDT) Received: from localhost.localdomain ([2400:4030:ac55:d000:18f3:45f2:6d16:16e9]) by smtp.gmail.com with ESMTPSA id r66sm16252225pfl.15.2017.09.12.22.01.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Sep 2017 22:01:35 -0700 (PDT) From: Kenjiro Nakayama To: target-devel@vger.kernel.org Cc: nab@linux-iscsi.org, mchristi@redhat.com, Kenjiro Nakayama Subject: [PATCH] target: Add netlink command reply supported option for each device Date: Wed, 13 Sep 2017 14:01:22 +0900 Message-Id: <20170913050122.13731-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 Currently netlink command reply support option (TCMU_ATTR_SUPP_KERN_CMD_REPLY) can be enabled only on module scope. Because of that, once an application enables the netlink command reply support, all applications using target_core_user.ko would be expected to support the netlink reply. To make matters worse, users will not be able to add a device via configfs manually. To fix these issues, this patch adds an option to make netlink command reply disabled on each device through configfs. Original TCMU_ATTR_SUPP_KERN_CMD_REPLY is still enabled on module scope to keep backward-compatibility and used by default, however once users set nl_reply_supported= via configfs for a particular device, the device disables the netlink command reply support. Signed-off-by: Kenjiro Nakayama Reviewed-by: Mike Christie --- drivers/target/target_core_user.c | 59 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index 942d094269fb..709c27ed4206 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -150,6 +150,8 @@ struct tcmu_dev { wait_queue_head_t nl_cmd_wq; char dev_config[TCMU_CONFIG_LEN]; + + int nl_reply_supported; }; #define TCMU_DEV(_se_dev) container_of(_se_dev, struct tcmu_dev, se_dev) @@ -1306,6 +1308,10 @@ static void tcmu_init_genl_cmd_reply(struct tcmu_dev *udev, int cmd) if (!tcmu_kern_cmd_reply_supported) return; + + if (udev->nl_reply_supported <= 0) + return; + relock: spin_lock(&udev->nl_cmd_lock); @@ -1332,6 +1338,9 @@ static int tcmu_wait_genl_cmd_reply(struct tcmu_dev *udev) if (!tcmu_kern_cmd_reply_supported) return 0; + if (udev->nl_reply_supported <= 0) + return 0; + pr_debug("sleeping for nl reply\n"); wait_for_completion(&nl_cmd->complete); @@ -1506,6 +1515,12 @@ static int tcmu_configure_device(struct se_device *dev) dev->dev_attrib.emulate_write_cache = 0; dev->dev_attrib.hw_queue_depth = 128; + /* If user didn't explicitly disable netlink reply support, use + * module scope setting. + */ + if (udev->nl_reply_supported >= 0) + udev->nl_reply_supported = tcmu_kern_cmd_reply_supported; + /* * Get a ref incase userspace does a close on the uio device before * LIO has initiated tcmu_free_device. @@ -1610,7 +1625,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_reply_supported, Opt_err, }; static match_table_t tokens = { @@ -1618,6 +1633,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_reply_supported, "nl_reply_supported=%d"}, {Opt_err, NULL} }; @@ -1692,6 +1708,18 @@ 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_reply_supported: + arg_p = match_strdup(&args[0]); + if (!arg_p) { + ret = -ENOMEM; + break; + } + ret = kstrtol(arg_p, 0, + (long int *) &udev->nl_reply_supported); + kfree(arg_p); + if (ret < 0) + pr_err("kstrtoul() failed for nl_reply_supported=\n"); + break; default: break; } @@ -1842,6 +1870,34 @@ static ssize_t tcmu_dev_size_store(struct config_item *item, const char *page, } CONFIGFS_ATTR(tcmu_, dev_size); +static ssize_t tcmu_nl_reply_supported_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, "%d\n", udev->nl_reply_supported); +} + +static ssize_t tcmu_nl_reply_supported_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); + s8 val; + int ret; + + ret = kstrtos8(page, 0, &val); + if (ret < 0) + return ret; + + udev->nl_reply_supported = val; + return count; +} +CONFIGFS_ATTR(tcmu_, nl_reply_supported); + static ssize_t tcmu_emulate_write_cache_show(struct config_item *item, char *page) { @@ -1884,6 +1940,7 @@ static struct configfs_attribute *tcmu_attrib_attrs[] = { &tcmu_attr_dev_config, &tcmu_attr_dev_size, &tcmu_attr_emulate_write_cache, + &tcmu_attr_nl_reply_supported, NULL, };