From patchwork Thu May 18 16:18:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 9734737 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 6B70C601BC for ; Thu, 18 May 2017 16:18:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53CF128782 for ; Thu, 18 May 2017 16:18:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 488CF287CF; Thu, 18 May 2017 16:18:28 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 B6AA4287A3 for ; Thu, 18 May 2017 16:18:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932672AbdERQSY (ORCPT ); Thu, 18 May 2017 12:18:24 -0400 Received: from mail-pf0-f179.google.com ([209.85.192.179]:34240 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932610AbdERQSW (ORCPT ); Thu, 18 May 2017 12:18:22 -0400 Received: by mail-pf0-f179.google.com with SMTP id 9so26193904pfj.1 for ; Thu, 18 May 2017 09:18:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=D6JEnhuMbXD64tOAzEb+06G7Ibk0fl2oZgSp7uxw99A=; b=QCPqEy0uNkVobJol1nhVoFw6o8qk7pla3dPhhPSllfg3yr0jYz/bAVZggJTIQLM9hQ wm3gCIqV53f5huHyZHCHlSeT/gJbMawyc223dh4Gc0YgrWP91+P5sknAUMxxUJPidQWr OJwBkb5PSPmi1TgLFw5QrG9VjH7pE8IJG8V3Gd8Oz3iNeFbhxdr2ad5FA1AmOU67ce3M 8Te6aJUpbZEeHe3yjPLgUFalrCcJ6h89V0ASR7rwZKEd+5yqVQEPodMfokRq5qCkw4yF MtZHuNtXyfq5uV4irHXbWQi9rur/Ed+N29LFRk9yK5lrECF6OoEw9y4HAyRQgCQ7I+WW /fNw== 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:in-reply-to :references; bh=D6JEnhuMbXD64tOAzEb+06G7Ibk0fl2oZgSp7uxw99A=; b=eTfG21uOmdg5mwk7uNm7uoSnZC2hqjINVaUdM1CntBuOdua1upbZNbB7LxQjRRMlh3 0O6MvACpiMugSkzi4Ohzu90JSGriJ8Gz1x/Li5p7zMYRYf5Gyrrybt5v3qy6vuB9Ws2e u2hN0gvniAEAjDOvprXIzsJSgLhNKzYdgkGk4GhyQ7gqyzKmFQnTtpmBJyqBJmV5ND0S SY6ZJzGyr0wcpxqcNz1WFzy5iQOFbq/uof0/Jt/OKV1cIcDO/JRkL3Nm0x3BRml1FvJ9 HUEHctoKKk+KHJao+BJwOYYGLXklqPcsYKWxnGgLrXpckANFhtZdG1xiJ1XTg/I27F3A x84g== X-Gm-Message-State: AODbwcAgbTa6Si0N0xWArOmzjMD+2BJwkQ7AJDaF/iiFeDXcfy6MoWBK MlBbrrbrDw1W61Es X-Received: by 10.84.136.34 with SMTP id 31mr5951133plk.36.1495124301759; Thu, 18 May 2017 09:18:21 -0700 (PDT) Received: from xeon-e3.wavecable.com (76-14-207-240.or.wavecable.com. [76.14.207.240]) by smtp.gmail.com with ESMTPSA id d75sm896796pfj.75.2017.05.18.09.18.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2017 09:18:21 -0700 (PDT) From: Stephen Hemminger X-Google-Original-From: Stephen Hemminger To: jejb@linux.vnet.ibm.com, martin.petersen@oracle.com, kys@microsoft.com Cc: devel@linuxdriverproject.org, linux-scsi@vger.kernel.org, Stephen Hemminger Subject: [PATCH 1/2] storvsc: use in place iterator function Date: Thu, 18 May 2017 09:18:11 -0700 Message-Id: <20170518161812.14124-2-sthemmin@microsoft.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170518161812.14124-1-sthemmin@microsoft.com> References: <20170518161812.14124-1-sthemmin@microsoft.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In 4.12-rc1, new functions were added to support iterating over elements in the vmbus event ring. This patch uses them to simplify the ring buffer handling in virtual SCSI driver as well. Signed-off-by: Stephen Hemminger --- drivers/scsi/storvsc_drv.c | 44 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c index ae966dc3bbc5..f8a1649e4c63 100644 --- a/drivers/scsi/storvsc_drv.c +++ b/drivers/scsi/storvsc_drv.c @@ -1149,13 +1149,9 @@ static void storvsc_on_receive(struct storvsc_device *stor_device, static void storvsc_on_channel_callback(void *context) { struct vmbus_channel *channel = (struct vmbus_channel *)context; + const struct vmpacket_descriptor *desc; struct hv_device *device; struct storvsc_device *stor_device; - u32 bytes_recvd; - u64 request_id; - unsigned char packet[ALIGN(sizeof(struct vstor_packet), 8)]; - struct storvsc_cmd_request *request; - int ret; if (channel->primary_channel != NULL) device = channel->primary_channel->device_obj; @@ -1166,32 +1162,22 @@ static void storvsc_on_channel_callback(void *context) if (!stor_device) return; - do { - ret = vmbus_recvpacket(channel, packet, - ALIGN((sizeof(struct vstor_packet) - - vmscsi_size_delta), 8), - &bytes_recvd, &request_id); - if (ret == 0 && bytes_recvd > 0) { - - request = (struct storvsc_cmd_request *) - (unsigned long)request_id; - - if ((request == &stor_device->init_request) || - (request == &stor_device->reset_request)) { - - memcpy(&request->vstor_packet, packet, - (sizeof(struct vstor_packet) - - vmscsi_size_delta)); - complete(&request->wait_event); - } else { - storvsc_on_receive(stor_device, - (struct vstor_packet *)packet, - request); - } + foreach_vmbus_pkt(desc, channel) { + void *packet = hv_pkt_data(desc); + struct storvsc_cmd_request *request; + + request = (struct storvsc_cmd_request *) + ((unsigned long)desc->trans_id); + + if (request == &stor_device->init_request || + request == &stor_device->reset_request) { + memcpy(&request->vstor_packet, packet, + (sizeof(struct vstor_packet) - vmscsi_size_delta)); + complete(&request->wait_event); } else { - break; + storvsc_on_receive(stor_device, packet, request); } - } while (1); + } } static int storvsc_connect_to_vsp(struct hv_device *device, u32 ring_size,