Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2509456pxa; Fri, 7 Aug 2020 12:58:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQS22WI+lW+mBkuEFvHVRlZHrqgnTNTFU0JnZbBgciIkXPd+ANuHdqpSysog/hqzcVc6r4 X-Received: by 2002:aa7:c70b:: with SMTP id i11mr10196834edq.272.1596830298218; Fri, 07 Aug 2020 12:58:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596830298; cv=none; d=google.com; s=arc-20160816; b=zv6IR3X/fl7zOUVSRK09klVvxZVqp2xWlJ/T0pmnue/S6w23POliCP0ypPaahc/rUp Alh1IxP46h4koN4dgqJsoxT/SX8tCS8UQnWhCPo+2nS2dudVD43XoPi/eovKYy1AZs99 ASBQ75GxugGbfbb6tEl2oQaNPULD39gm/19h7CzN6H8o66zCu09300mYGpdObMSzoibF kXfewBW8q2XPWxteszQs588FF5F+m6O5kItz85lm7GAceX5raMcnuDYUtFRORETCNp+S IOBWhFWWOOs3NjNrrimTFuxl77ewRNDwFCvjefRR2/9adH9a6WHfjcAWM6PASa/JkDCZ L4zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BDe9SblDEhv0vLYedGkGVjAfd7sAv5XmgCgw2xWVnkQ=; b=YnSZYG+3nj63d8mZvnDOZ3T1nvJKAx7b/rEk7bOqgI1jWFoHV/iYyptb//dL43uqC6 ot2LnJoWGZhP0IJfyU5NwKb4YRmOAvudjDe8kWODqSLh7aW1iDjmP3UuMTl2ZvThCOJL TwIyFA9OohtE0C1QKvSNzoz/anXFVjTeic5qXaipBv7DZGCMkmmGK9YEs+ZpvssEOWJi b2XDvDTaGD7hIoJiVbqOxEDV2W2GeElm4bpsJ5oVSSt9PkxKmnzHQp8SLSI4HUTM3ufl 181ghLRnHwUntQM8MpDQXGazRopnH/ZBE0HvHy9CgHKq38R8WmcL2y+7LSYj0y2jAGal fh6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LYwLNsSJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q8si1133719ejm.507.2020.08.07.12.57.55; Fri, 07 Aug 2020 12:58:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LYwLNsSJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727876AbgHGT4p (ORCPT + 99 others); Fri, 7 Aug 2020 15:56:45 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:24700 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726932AbgHGTzz (ORCPT ); Fri, 7 Aug 2020 15:55:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596830154; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BDe9SblDEhv0vLYedGkGVjAfd7sAv5XmgCgw2xWVnkQ=; b=LYwLNsSJxAb4BlEna2haVqnaPUvb2Y+kj4v94gSi8+LUVnIdL94GKwW6kOMUkgLMlhJUxn jhrkoEmt61WXmki1xoLsR0BrurHsjUBy6IoZwJdA6xWtCJnH6FNvnkzfK6BXaFeFeIteWv YKB9RSM3/p44VIJ1eux3gAwkSzsIzeo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-440-3zX15gWgNwKG-A13e8PxxQ-1; Fri, 07 Aug 2020 15:55:52 -0400 X-MC-Unique: 3zX15gWgNwKG-A13e8PxxQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8BAB857; Fri, 7 Aug 2020 19:55:51 +0000 (UTC) Received: from horse.redhat.com (ovpn-113-142.rdu2.redhat.com [10.10.113.142]) by smtp.corp.redhat.com (Postfix) with ESMTP id 793DE5C1C3; Fri, 7 Aug 2020 19:55:45 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id BEEC8222E4A; Fri, 7 Aug 2020 15:55:38 -0400 (EDT) From: Vivek Goyal To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, virtio-fs@redhat.com Cc: vgoyal@redhat.com, miklos@szeredi.hu, stefanha@redhat.com, dgilbert@redhat.com Subject: [PATCH v2 06/20] virtiofs: Provide a helper function for virtqueue initialization Date: Fri, 7 Aug 2020 15:55:12 -0400 Message-Id: <20200807195526.426056-7-vgoyal@redhat.com> In-Reply-To: <20200807195526.426056-1-vgoyal@redhat.com> References: <20200807195526.426056-1-vgoyal@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This reduces code duplication and make it little easier to read code. Signed-off-by: Vivek Goyal --- fs/fuse/virtio_fs.c | 50 +++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c index 4c4ef5d69298..e615edfbd09c 100644 --- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -24,6 +24,8 @@ enum { VQ_REQUEST }; +#define VQ_NAME_LEN 24 + /* Per-virtqueue state */ struct virtio_fs_vq { spinlock_t lock; @@ -36,7 +38,7 @@ struct virtio_fs_vq { bool connected; long in_flight; struct completion in_flight_zero; /* No inflight requests */ - char name[24]; + char name[VQ_NAME_LEN]; } ____cacheline_aligned_in_smp; /* A virtio-fs device instance */ @@ -596,6 +598,26 @@ static void virtio_fs_vq_done(struct virtqueue *vq) schedule_work(&fsvq->done_work); } +static void virtio_fs_init_vq(struct virtio_fs_vq *fsvq, char *name, + int vq_type) +{ + strncpy(fsvq->name, name, VQ_NAME_LEN); + spin_lock_init(&fsvq->lock); + INIT_LIST_HEAD(&fsvq->queued_reqs); + INIT_LIST_HEAD(&fsvq->end_reqs); + init_completion(&fsvq->in_flight_zero); + + if (vq_type == VQ_REQUEST) { + INIT_WORK(&fsvq->done_work, virtio_fs_requests_done_work); + INIT_DELAYED_WORK(&fsvq->dispatch_work, + virtio_fs_request_dispatch_work); + } else { + INIT_WORK(&fsvq->done_work, virtio_fs_hiprio_done_work); + INIT_DELAYED_WORK(&fsvq->dispatch_work, + virtio_fs_hiprio_dispatch_work); + } +} + /* Initialize virtqueues */ static int virtio_fs_setup_vqs(struct virtio_device *vdev, struct virtio_fs *fs) @@ -611,7 +633,7 @@ static int virtio_fs_setup_vqs(struct virtio_device *vdev, if (fs->num_request_queues == 0) return -EINVAL; - fs->nvqs = 1 + fs->num_request_queues; + fs->nvqs = VQ_REQUEST + fs->num_request_queues; fs->vqs = kcalloc(fs->nvqs, sizeof(fs->vqs[VQ_HIPRIO]), GFP_KERNEL); if (!fs->vqs) return -ENOMEM; @@ -625,29 +647,17 @@ static int virtio_fs_setup_vqs(struct virtio_device *vdev, goto out; } + /* Initialize the hiprio/forget request virtqueue */ callbacks[VQ_HIPRIO] = virtio_fs_vq_done; - snprintf(fs->vqs[VQ_HIPRIO].name, sizeof(fs->vqs[VQ_HIPRIO].name), - "hiprio"); + virtio_fs_init_vq(&fs->vqs[VQ_HIPRIO], "hiprio", VQ_HIPRIO); names[VQ_HIPRIO] = fs->vqs[VQ_HIPRIO].name; - INIT_WORK(&fs->vqs[VQ_HIPRIO].done_work, virtio_fs_hiprio_done_work); - INIT_LIST_HEAD(&fs->vqs[VQ_HIPRIO].queued_reqs); - INIT_LIST_HEAD(&fs->vqs[VQ_HIPRIO].end_reqs); - INIT_DELAYED_WORK(&fs->vqs[VQ_HIPRIO].dispatch_work, - virtio_fs_hiprio_dispatch_work); - init_completion(&fs->vqs[VQ_HIPRIO].in_flight_zero); - spin_lock_init(&fs->vqs[VQ_HIPRIO].lock); /* Initialize the requests virtqueues */ for (i = VQ_REQUEST; i < fs->nvqs; i++) { - spin_lock_init(&fs->vqs[i].lock); - INIT_WORK(&fs->vqs[i].done_work, virtio_fs_requests_done_work); - INIT_DELAYED_WORK(&fs->vqs[i].dispatch_work, - virtio_fs_request_dispatch_work); - INIT_LIST_HEAD(&fs->vqs[i].queued_reqs); - INIT_LIST_HEAD(&fs->vqs[i].end_reqs); - init_completion(&fs->vqs[i].in_flight_zero); - snprintf(fs->vqs[i].name, sizeof(fs->vqs[i].name), - "requests.%u", i - VQ_REQUEST); + char vq_name[VQ_NAME_LEN]; + + snprintf(vq_name, VQ_NAME_LEN, "requests.%u", i - VQ_REQUEST); + virtio_fs_init_vq(&fs->vqs[i], vq_name, VQ_REQUEST); callbacks[i] = virtio_fs_vq_done; names[i] = fs->vqs[i].name; } -- 2.25.4