Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5973572ybe; Tue, 10 Sep 2019 11:33:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwawNPUoVMa7+394WTHdBVbeJEOLm4Atu0gYKviobuws61WXbc2xadqQfqQZgoKK60dWKX4 X-Received: by 2002:a05:6402:286:: with SMTP id l6mr32348962edv.111.1568140439421; Tue, 10 Sep 2019 11:33:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568140439; cv=none; d=google.com; s=arc-20160816; b=KnBehfcRtylIhSzmFSHFhEFIKuj1luWIXNblJi4WiDQW9kdE/1F/nN5bNrjUGPZoD2 wnVpXKnsYfQuV1/44nt4+kwPpQwFsyX0CKTDG9SQK47D+twqCkvB8Hx9uyshjcMZx6Nl 3JuSd3PtKdelEXpqCIolzcKzUM8twcNnEF7qKV6rqhhKDI+aKK5iSB5GFy1VmCt30iQR lv8O+Zbe8t3A5teqqmWzHa48k2Z/T3rVAZPWx2MJJqBzMko8Z25ctf7DGg/jNi028jIT DfUkSvbuoj0twt1phPCrjiF6ZLdtMn40lUzuKw7TjjXEO/HFO60c+QgGrUj8Mj+vfmri KdLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=X4iBE5XpQvJ/yR8G4Qm3E0fH6IidYpJBeUQ3Kjwh2Vs=; b=fkADehlGksc9iEgXYc/tTbLLzep6KTaBpZKesz1l62rzRWUqKASCWenFNI32BOVv3D MVFoHkaFKzngWQjJSx2bp3FR5KbCD1iath0EnrTrT1OO4EgAjmdhWdnL7+886ty+U/nX wV/IHmRZObybb5RqyYg/8rA/kzoPN+Mh/OwDybKJ2tsRCyC4JS3j2N6h992k+dQOPDT/ 630M0EZv5m9S6qGNZjFZzROh0x94XSnPptYLfIDP2us+BFcGGTRm/lMopfm7Rd9AyaVm gTX+DGatbyeITxCU6fXd6dZiRaHs5P9JvEdeu+QnC9m1dTCYlfNGHvSrDnSA3EQJYbgd MRQw== 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 y17si10620680edo.354.2019.09.10.11.33.27; Tue, 10 Sep 2019 11:33:59 -0700 (PDT) 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 S2388411AbfIIPfr (ORCPT + 99 others); Mon, 9 Sep 2019 11:35:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31638 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728698AbfIIPfr (ORCPT ); Mon, 9 Sep 2019 11:35:47 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 066883090FEE; Mon, 9 Sep 2019 15:35:47 +0000 (UTC) Received: from horse.redhat.com (unknown [10.18.25.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FC6A5D6B2; Mon, 9 Sep 2019 15:35:38 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id CA111220292; Mon, 9 Sep 2019 11:35:37 -0400 (EDT) Date: Mon, 9 Sep 2019 11:35:37 -0400 From: Vivek Goyal To: piaojun Cc: linux-fsdevel@vger.kernel.org, virtualization@lists.linux-foundation.org, miklos@szeredi.hu, mst@redhat.com, linux-kernel@vger.kernel.org, virtio-fs@redhat.com Subject: Re: [Virtio-fs] [PATCH 15/18] virtiofs: Make virtio_fs object refcounted Message-ID: <20190909153537.GA25501@redhat.com> References: <20190905194859.16219-1-vgoyal@redhat.com> <20190905194859.16219-16-vgoyal@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.0 (2019-05-25) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 09 Sep 2019 15:35:47 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Sep 08, 2019 at 07:10:03PM +0800, piaojun wrote: > > > On 2019/9/6 3:48, Vivek Goyal wrote: > > This object is used both by fuse_connection as well virt device. So make > > this object reference counted and that makes it easy to define life cycle > > of the object. > > > > Now deivce can be removed while filesystem is still mounted. This will > > cleanup all the virtqueues but virtio_fs object will still be around and > > will be cleaned when filesystem is unmounted and sb/fc drops its reference. > > > > Removing a device also stops all virt queues and any new reuqest gets > > error -ENOTCONN. All existing in flight requests are drained before > > ->remove returns. > > > > Signed-off-by: Vivek Goyal > > --- > > fs/fuse/virtio_fs.c | 52 +++++++++++++++++++++++++++++++++++++-------- > > 1 file changed, 43 insertions(+), 9 deletions(-) > > > > diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c > > index 01bbf2c0e144..29ec2f5bbbe2 100644 > > --- a/fs/fuse/virtio_fs.c > > +++ b/fs/fuse/virtio_fs.c > > @@ -37,6 +37,7 @@ struct virtio_fs_vq { > > > > /* A virtio-fs device instance */ > > struct virtio_fs { > > + struct kref refcount; > > struct list_head list; /* on virtio_fs_instances */ > > char *tag; > > struct virtio_fs_vq *vqs; > > @@ -63,6 +64,27 @@ static inline struct fuse_pqueue *vq_to_fpq(struct virtqueue *vq) > > return &vq_to_fsvq(vq)->fud->pq; > > } > > > > +static void release_virtiofs_obj(struct kref *ref) > > +{ > > + struct virtio_fs *vfs = container_of(ref, struct virtio_fs, refcount); > > + > > + kfree(vfs->vqs); > > + kfree(vfs); > > +} > > + > > +static void virtio_fs_put(struct virtio_fs *fs) > > +{ > > + mutex_lock(&virtio_fs_mutex); > > + kref_put(&fs->refcount, release_virtiofs_obj); > > + mutex_unlock(&virtio_fs_mutex); > > +} > > + > > +static void virtio_fs_put(struct fuse_iqueue *fiq) > > +{ > > + struct virtio_fs *vfs = fiq->priv; > > + virtiofs_put(vfs); > > +} > > It's a little confusing that virtiofs_put() looks like virtiofs_put(), > and could we use __virtio_fs_put to replace virtio_fs_put? Fixed this in follow up patch I posted. https://www.redhat.com/archives/virtio-fs/2019-September/msg00091.html Vivek