Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3890306imu; Mon, 10 Dec 2018 09:23:08 -0800 (PST) X-Google-Smtp-Source: AFSGD/V3YLWmzswG4jbM1B4gxWYD/jiArBT8Yxw30Vl7pEdfPBOT4m+j6qjPvzDjfYpmO1DzF6wi X-Received: by 2002:a63:981:: with SMTP id 123mr11625120pgj.444.1544462588095; Mon, 10 Dec 2018 09:23:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544462588; cv=none; d=google.com; s=arc-20160816; b=dZzeZjASx3ypO36gFYyRHv6wz4ZuNy5fAIz2yG/F6FSGqX2SWxmAMtGYHtMUSRY6Pt Elq4qOKFUglViuy8eyKKLysfo8BAMay7+USmc/swMC1KOhc+7pMErUd2MN1uN6NxHXmN y5NvOs2Nr2FwMhHGLPZviuI4Aj6TUC0ax9YRPHasij2yHc492q60/L5P+SMC4348z3fx ldQyxOJNUucBzLyeRtY0MQ37zd4/Aih9+LNCKAHPfuuViVbCreh2gAbOKyIPL05ai9Nf YQpmrdKuRlqVN+6oiVOfK22h3CBW7A8GMhwZVQ2lB23f40uTfIuBn+rWrSHPzGa1zMN1 y5Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=FlXTxdtDJLVBSu4WQ+tkPcnifmaVol0aqyFcP8HOjP8=; b=gaNdjeEVYjjZs/VHNRK54BTAo+YaSy/TiQkceiAK0eZhTQathg9gs9D2NgbWh/fTiG tcqgV3sL8Rt6dntxZ/GmoYmcUm4I5piT103d2eo1lU4UOU7roPK0zVybUpvCtzlEelyO CN7nNmkHDplFU0oqGGdPoYyPzMAsnl/CBDOTMei+eSHlunRfXsGiPmrx57KpP5e8B5HJ kfIpQh6a4KqTunB2Jt+XKyzPYlsAt9WDbGDAQanSQnOA59/ZosqTryis633S5dlIodmW QcE8CfQAEORtAyxSc1RV6Fg7andsYQsYDdqbxq7NXwEOPU6zQMbaX1DhX+I+/ayRZYhE 7S0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d125si11062401pfc.114.2018.12.10.09.22.52; Mon, 10 Dec 2018 09:23:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729165AbeLJRT5 (ORCPT + 99 others); Mon, 10 Dec 2018 12:19:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36966 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728361AbeLJRNe (ORCPT ); Mon, 10 Dec 2018 12:13:34 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 268763154861; Mon, 10 Dec 2018 17:13:34 +0000 (UTC) Received: from horse.redhat.com (unknown [10.18.25.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id E178F600D7; Mon, 10 Dec 2018 17:13:33 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id 2FEB8223C0D; Mon, 10 Dec 2018 12:13:30 -0500 (EST) From: Vivek Goyal To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: vgoyal@redhat.com, miklos@szeredi.hu, stefanha@redhat.com, dgilbert@redhat.com, sweil@redhat.com, swhiteho@redhat.com Subject: [PATCH 11/52] fuse: implement FUSE_FORGET for virtio-fs Date: Mon, 10 Dec 2018 12:12:37 -0500 Message-Id: <20181210171318.16998-12-vgoyal@redhat.com> In-Reply-To: <20181210171318.16998-1-vgoyal@redhat.com> References: <20181210171318.16998-1-vgoyal@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Mon, 10 Dec 2018 17:13:34 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stefan Hajnoczi Sent single FUSE_FORGET requests on the hiprio queue. In the future it may be possible to do FUSE_BATCH_FORGET but that is tricky since virtio-fs gets called synchronously when forgets are queued. Signed-off-by: Stefan Hajnoczi --- fs/fuse/virtio_fs.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 4 deletions(-) diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c index fa99a31ee930..225eb729656f 100644 --- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -140,10 +140,26 @@ static void virtio_fs_notifications_done_work(struct work_struct *work) return; } -static void virtio_fs_hiprio_done(struct virtqueue *vq) +/* Work function for hiprio completion */ +static void virtio_fs_hiprio_done_work(struct work_struct *work) { - /* TODO */ - dev_dbg(&vq->vdev->dev, "%s\n", __func__); + struct virtio_fs_vq *fsvq = container_of(work, struct virtio_fs_vq, + done_work); + struct fuse_pqueue *fpq = &fsvq->fud->pq; + struct virtqueue *vq = fsvq->vq; + + /* Free completed FUSE_FORGET requests */ + spin_lock(&fpq->lock); + do { + unsigned len; + void *req; + + virtqueue_disable_cb(vq); + + while ((req = virtqueue_get_buf(vq, &len)) != NULL) + kfree(req); + } while (!virtqueue_enable_cb(vq) && likely(!virtqueue_is_broken(vq))); + spin_unlock(&fpq->lock); } /* Allocate and copy args into req->argbuf */ @@ -302,6 +318,7 @@ static int virtio_fs_setup_vqs(struct virtio_device *vdev, callbacks[1] = virtio_fs_vq_done; snprintf(fs->vqs[1].name, sizeof(fs->vqs[1].name), "hiprio"); names[1] = fs->vqs[1].name; + INIT_WORK(&fs->vqs[1].done_work, virtio_fs_hiprio_done_work); /* Initialize the requests virtqueues */ for (i = 2; i < fs->nvqs; i++) { @@ -424,11 +441,79 @@ static struct virtio_driver virtio_fs_driver = { #endif }; +struct virtio_fs_forget { + struct fuse_in_header ih; + struct fuse_forget_in arg; +}; + static void virtio_fs_wake_forget_and_unlock(struct fuse_iqueue *fiq) __releases(fiq->waitq.lock) { - /* TODO */ + struct fuse_forget_link *link; + struct virtio_fs_forget *forget; + struct fuse_pqueue *fpq; + struct scatterlist sg; + struct scatterlist *sgs[] = {&sg}; + struct virtio_fs *fs; + struct virtqueue *vq; + bool notify; + u64 unique; + int ret; + + BUG_ON(!fiq->forget_list_head.next); + link = fiq->forget_list_head.next; + BUG_ON(link->next); + fiq->forget_list_head.next = NULL; + fiq->forget_list_tail = &fiq->forget_list_head; + + unique = fuse_get_unique(fiq); + + fs = fiq->priv; + spin_unlock(&fiq->waitq.lock); + + /* Allocate a buffer for the request */ + forget = kmalloc(sizeof(*forget), GFP_ATOMIC); + if (!forget) { + pr_err("virtio-fs: dropped FORGET: kmalloc failed\n"); + goto out; /* TODO avoid dropping it? */ + } + + forget->ih = (struct fuse_in_header){ + .opcode = FUSE_FORGET, + .nodeid = link->forget_one.nodeid, + .unique = unique, + .len = sizeof(*forget), + }; + forget->arg = (struct fuse_forget_in){ + .nlookup = link->forget_one.nlookup, + }; + + sg_init_one(&sg, forget, sizeof(*forget)); + + /* Enqueue the request */ + vq = fs->vqs[1].vq; + dev_dbg(&vq->vdev->dev, "%s\n", __func__); + fpq = vq_to_fpq(vq); + spin_lock(&fpq->lock); + + ret = virtqueue_add_sgs(vq, sgs, 1, 0, forget, GFP_ATOMIC); + if (ret < 0) { + pr_err("virtio-fs: dropped FORGET: queue full\n"); + /* TODO handle full virtqueue */ + spin_unlock(&fpq->lock); + goto out; + } + + notify = virtqueue_kick_prepare(vq); + + spin_unlock(&fpq->lock); + + if (notify) + virtqueue_notify(vq); + +out: + kfree(link); } static void virtio_fs_wake_interrupt_and_unlock(struct fuse_iqueue *fiq) -- 2.13.6