From patchwork Mon Apr 16 11:04:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhu Lingshan X-Patchwork-Id: 10342721 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 8691F601C2 for ; Mon, 16 Apr 2018 11:05:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 753CB285DC for ; Mon, 16 Apr 2018 11:05:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6651B28662; Mon, 16 Apr 2018 11:05:10 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 ECFD5285DC for ; Mon, 16 Apr 2018 11:05:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754713AbeDPLFI (ORCPT ); Mon, 16 Apr 2018 07:05:08 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:53950 "EHLO smtp2.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754780AbeDPLFH (ORCPT ); Mon, 16 Apr 2018 07:05:07 -0400 Received: from localhost.localdomain (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 16 Apr 2018 05:05:02 -0600 From: Zhu Lingshan To: target-devel@vger.kernel.org, nab@linux-iscsi.org, mchristi@redhat.com Cc: hare@suse.de, lduncan@suse.com, Zhu Lingshan Subject: [PATCH 6/6] tcmu: refactor nl wr_cache attr with new helpers Date: Mon, 16 Apr 2018 19:04:28 +0800 Message-Id: <20180416110428.5273-6-lszhu@suse.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180416110428.5273-1-lszhu@suse.com> References: <20180416110428.5273-1-lszhu@suse.com> 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 use new netlink events helpers tcmu_netlink_init() and tcmu_netlink_send() to refactor netlink event attribute TCMU_ATTR_WRITECACHE(belongs to TCMU_CMD_RECONFIG_DEVICE) which is also emulate_write_cache in configFS. Removed tcmu_netlink_event() since we have new netlink events helpers now. Signed-off-by: Zhu Lingshan --- drivers/target/target_core_user.c | 90 +++++++++------------------------------ 1 file changed, 21 insertions(+), 69 deletions(-) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index d913fb15f1b4..f0d667b67e0c 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -1586,73 +1586,6 @@ static int tcmu_wait_genl_cmd_reply(struct tcmu_dev *udev) return ret; } -static int tcmu_netlink_event(struct tcmu_dev *udev, enum tcmu_genl_cmd cmd, - int reconfig_attr, const void *reconfig_data) -{ - struct sk_buff *skb; - void *msg_header; - int ret = -ENOMEM; - - skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); - if (!skb) - return ret; - - msg_header = genlmsg_put(skb, 0, 0, &tcmu_genl_family, 0, cmd); - if (!msg_header) - goto free_skb; - - ret = nla_put_string(skb, TCMU_ATTR_DEVICE, udev->uio_info.name); - if (ret < 0) - goto free_skb; - - ret = nla_put_u32(skb, TCMU_ATTR_MINOR, udev->uio_info.uio_dev->minor); - if (ret < 0) - goto free_skb; - - ret = nla_put_u32(skb, TCMU_ATTR_DEVICE_ID, udev->se_dev.dev_index); - if (ret < 0) - goto free_skb; - - if (cmd == TCMU_CMD_RECONFIG_DEVICE) { - switch (reconfig_attr) { - case TCMU_ATTR_DEV_CFG: - ret = nla_put_string(skb, reconfig_attr, reconfig_data); - break; - case TCMU_ATTR_DEV_SIZE: - ret = nla_put_u64_64bit(skb, reconfig_attr, - *((u64 *)reconfig_data), - TCMU_ATTR_PAD); - break; - case TCMU_ATTR_WRITECACHE: - ret = nla_put_u8(skb, reconfig_attr, - *((u8 *)reconfig_data)); - break; - default: - BUG(); - } - - if (ret < 0) - goto free_skb; - } - - genlmsg_end(skb, msg_header); - - tcmu_init_genl_cmd_reply(udev, cmd); - - ret = genlmsg_multicast_allns(&tcmu_genl_family, skb, 0, - TCMU_MCGRP_CONFIG, GFP_KERNEL); - /* We don't care if no one is listening */ - if (ret == -ESRCH) - ret = 0; - if (!ret) - ret = tcmu_wait_genl_cmd_reply(udev); - - return ret; -free_skb: - nlmsg_free(skb); - return ret; -} - static int tcmu_netlink_event_init(struct tcmu_dev *udev, enum tcmu_genl_cmd cmd, struct sk_buff **buf, void **hdr) @@ -2384,6 +2317,26 @@ static ssize_t tcmu_emulate_write_cache_show(struct config_item *item, return snprintf(page, PAGE_SIZE, "%i\n", da->emulate_write_cache); } +static int tcmu_send_emulate_write_cache(struct tcmu_dev *udev, u8 val) +{ + struct sk_buff *skb = NULL; + void *msg_header = NULL; + int ret = 0; + + ret = tcmu_netlink_event_init(udev, TCMU_CMD_RECONFIG_DEVICE, + &skb, &msg_header); + if (ret < 0) + return ret; + ret = nla_put_u8(skb, TCMU_ATTR_WRITECACHE, val); + if (ret < 0) { + nlmsg_free(skb); + return ret; + } + ret = tcmu_netlink_event_send(udev, TCMU_CMD_RECONFIG_DEVICE, + &skb, &msg_header); + return ret; +} + static ssize_t tcmu_emulate_write_cache_store(struct config_item *item, const char *page, size_t count) { @@ -2399,8 +2352,7 @@ static ssize_t tcmu_emulate_write_cache_store(struct config_item *item, /* Check if device has been configured before */ if (tcmu_dev_configured(udev)) { - ret = tcmu_netlink_event(udev, TCMU_CMD_RECONFIG_DEVICE, - TCMU_ATTR_WRITECACHE, &val); + ret = tcmu_send_emulate_write_cache(udev, val); if (ret) { pr_err("Unable to reconfigure device\n"); return ret;