From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7652DC433ED for ; Wed, 21 Apr 2021 00:39:53 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8D3F361409 for ; Wed, 21 Apr 2021 00:39:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8D3F361409 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZ0uF-0002xg-9M for qemu-devel@archiver.kernel.org; Tue, 20 Apr 2021 20:39:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57116) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZ0tf-0002Z6-JW for qemu-devel@nongnu.org; Tue, 20 Apr 2021 20:39:15 -0400 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]:35437) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lZ0td-0007GC-K8 for qemu-devel@nongnu.org; Tue, 20 Apr 2021 20:39:15 -0400 Received: by mail-io1-xd2d.google.com with SMTP id h141so32008623iof.2 for ; Tue, 20 Apr 2021 17:39:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uVJRj2tE2nezofmVlObTkKqRr47I4K5in3MT/Ka7fnc=; b=iaOpnI19VJF0A4hV9XkUBxXvwGsZMM9aqLBLZxo3OPLyksMVEjTOee29/yS89EPjQ7 Qs/R4MjT/afhZLGtMsFllg6E9Dmif5UfnkZUlrx3X+cyWqR1pzhSmU2TNzJ0LElIDdry i4R9KLoXwkO3i9nx7K2TkiZJVa3asLykur+kOpXaGuFRAdQLdTd4a2AYiZMjEOeEl2S0 8XuffOcI4jvm2pBFx+RanpS1HRRlVNJvXmQw5evo1VcRP2QnUqiS0qu+ap44Kg8KH2Bd XaR5njvmULhVRSeqWb98O4T+OoUjL46yYqSwM/J93/IuyDE46yNH/Q1RcuKfgho3YJy1 KF5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uVJRj2tE2nezofmVlObTkKqRr47I4K5in3MT/Ka7fnc=; b=eMBHngKyFt/eda30F5w2B6Y4X9GofPhUQ+Rq4pZ561edhhcALVVoE4mtt7tmTb+JUx nXekiUvk9IQPMbhtKNPrMonqi8vDV1V9FRDv6pwpnaaX87Bo5pO4boloWaEIjJYbK1Vy 64LGxv31HsRF5iIrxyQlXJCCQSzaixdyMhdp9HRVolevzKUfWJCN5CN1WJ2fSJE+0FBA pScFvqNSPLb2hxgKncM41SaH3r0/4UwMv4dUuuN/RI+sTwyRu+GPW94fKfqzq4oJvPaZ rV2XgpzZe0PTVOC5nVW5xobUebIGaS+ONYnp48nzorA6IugSgD+ncGlVnF0uplxA1VOe 2lJQ== X-Gm-Message-State: AOAM531v2O8ZiaPpxKWaLcfwXUJHBG4jDzYLyTUlFGXaTORmW9g+XDye VdhgdHT4tqkmegADHKYpf7sGJJQb0R0KLul8dYU= X-Google-Smtp-Source: ABdhPJzdw0vOFuoxAzeev7x5nQWYaOX9cQybl/Y9X1Ama5kW549zgek7x2WBK1S/nmVKYx+v3AgGwVRDrgZajIGsIVU= X-Received: by 2002:a05:6638:2591:: with SMTP id s17mr23051193jat.87.1618965551053; Tue, 20 Apr 2021 17:39:11 -0700 (PDT) MIME-Version: 1.0 References: <20210420154643.58439-1-ma.mandourr@gmail.com> <20210420154643.58439-2-ma.mandourr@gmail.com> <20210420190334.GE1529659@redhat.com> In-Reply-To: <20210420190334.GE1529659@redhat.com> From: Mahmoud Mandour Date: Wed, 21 Apr 2021 02:39:00 +0200 Message-ID: Subject: Re: [Virtio-fs] [PATCH v2 1/7] virtiofsd: Changed allocations of fuse_req to GLib functions To: Vivek Goyal Content-Type: multipart/alternative; boundary="00000000000092fc0905c070ca1a" Received-SPF: pass client-ip=2607:f8b0:4864:20::d2d; envelope-from=ma.mandourr@gmail.com; helo=mail-io1-xd2d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "open list:virtiofs" , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --00000000000092fc0905c070ca1a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Apr 20, 2021 at 9:03 PM Vivek Goyal wrote: > On Tue, Apr 20, 2021 at 05:46:36PM +0200, Mahmoud Mandour wrote: > > Replaced the allocation and deallocation of fuse_req structs > > using calloc()/free() call pairs to a GLib's g_try_new0() > > and g_free(). > > Hi, > > What's the context of these patches. I see all of them are switching > to glib functions. Why to do that? What's the advantage. > > Vivek > > > > > Signed-off-by: Mahmoud Mandour > > Reviewed-by: Stefan Hajnoczi > > --- > > tools/virtiofsd/fuse_lowlevel.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/tools/virtiofsd/fuse_lowlevel.c > b/tools/virtiofsd/fuse_lowlevel.c > > index 58e32fc963..812cef6ef6 100644 > > --- a/tools/virtiofsd/fuse_lowlevel.c > > +++ b/tools/virtiofsd/fuse_lowlevel.c > > @@ -106,7 +106,7 @@ static void list_add_req(struct fuse_req *req, > struct fuse_req *next) > > static void destroy_req(fuse_req_t req) > > { > > pthread_mutex_destroy(&req->lock); > > - free(req); > > + g_free(req); > > } > > > > void fuse_free_req(fuse_req_t req) > > @@ -130,7 +130,7 @@ static struct fuse_req *fuse_ll_alloc_req(struct > fuse_session *se) > > { > > struct fuse_req *req; > > > > - req =3D (struct fuse_req *)calloc(1, sizeof(struct fuse_req)); > > + req =3D g_try_new0(struct fuse_req, 1); > > if (req =3D=3D NULL) { > > fuse_log(FUSE_LOG_ERR, "fuse: failed to allocate request\n"); > > } else { > > @@ -1684,7 +1684,7 @@ static struct fuse_req *check_interrupt(struct > fuse_session *se, > > if (curr->u.i.unique =3D=3D req->unique) { > > req->interrupted =3D 1; > > list_del_req(curr); > > - free(curr); > > + g_free(curr); > > return NULL; > > } > > } > > -- > > 2.25.1 > > > > _______________________________________________ > > Virtio-fs mailing list > > Virtio-fs@redhat.com > > https://listman.redhat.com/mailman/listinfo/virtio-fs > > Hello Vivek, Taken from the Qemu Coding Style document in the documentation: "Use of the malloc/free/realloc/calloc/valloc/memalign/posix_memalign APIs is not allowed in the QEMU codebase. Instead of these routines, use the GLib memory allocation routines g_malloc/g_malloc0/g_new/g_new0/g_realloc/g_free or QEMU=E2=80=99s qemu_memalign/qemu_blockalign/qemu_vfree APIs." It's also in the bite-sized contributions page as a task. Thanks, Mahmoud --00000000000092fc0905c070ca1a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
<= /div>
O= n Tue, Apr 20, 2021 at 9:03 PM Vivek Goyal <vgoyal@redhat.com> wrote:
On Tue, Apr 20, 2021 at 05:46:36PM +0200, Mahmoud= Mandour wrote:
> Replaced the allocation and deallocation of fuse_req structs
> using calloc()/free() call pairs to a GLib's g_try_new0()
> and g_free().

Hi,

What's the context of these patches. I see all of them are switching to glib functions. Why to do that? What's the advantage.

Vivek

>
> Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>=C2=A0 tools/virtiofsd/fuse_lowlevel.c | 6 +++---
>=C2=A0 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lo= wlevel.c
> index 58e32fc963..812cef6ef6 100644
> --- a/tools/virtiofsd/fuse_lowlevel.c
> +++ b/tools/virtiofsd/fuse_lowlevel.c
> @@ -106,7 +106,7 @@ static void list_add_req(struct fuse_req *req, str= uct fuse_req *next)
>=C2=A0 static void destroy_req(fuse_req_t req)
>=C2=A0 {
>=C2=A0 =C2=A0 =C2=A0 pthread_mutex_destroy(&req->lock);
> -=C2=A0 =C2=A0 free(req);
> +=C2=A0 =C2=A0 g_free(req);
>=C2=A0 }
>=C2=A0
>=C2=A0 void fuse_free_req(fuse_req_t req)
> @@ -130,7 +130,7 @@ static struct fuse_req *fuse_ll_alloc_req(struct f= use_session *se)
>=C2=A0 {
>=C2=A0 =C2=A0 =C2=A0 struct fuse_req *req;
>=C2=A0
> -=C2=A0 =C2=A0 req =3D (struct fuse_req *)calloc(1, sizeof(struct fuse= _req));
> +=C2=A0 =C2=A0 req =3D g_try_new0(struct fuse_req, 1);
>=C2=A0 =C2=A0 =C2=A0 if (req =3D=3D NULL) {
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fuse_log(FUSE_LOG_ERR, "fuse: f= ailed to allocate request\n");
>=C2=A0 =C2=A0 =C2=A0 } else {
> @@ -1684,7 +1684,7 @@ static struct fuse_req *check_interrupt(struct f= use_session *se,
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (curr->u.i.unique =3D=3D req-&= gt;unique) {
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 req->interrupted = =3D 1;
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 list_del_req(curr); > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 free(curr);
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 g_free(curr);
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return NULL;
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
>=C2=A0 =C2=A0 =C2=A0 }
> --
> 2.25.1
>
> _______________________________________________
> Virtio-fs mailing list
> Virtio-fs@re= dhat.com
> https://listman.redhat.com/mailman/listin= fo/virtio-fs


Hello=C2=A0Vivek,

Taken = from the Qemu Coding Style document in the documentation:
"U= se of the malloc/free/realloc/calloc/valloc/memalign/posix_memalign APIs is= not allowed in the QEMU codebase. Instead of these routines, use the GLib = memory allocation routines g_malloc/g_malloc0/g_new/g_new0/g_realloc/g_free= or QEMU=E2=80=99s qemu_memalign/qemu_blockalign/qemu_vfree APIs."
It's also in the bite-sized contributions page as a task.
<= div>
Thanks,
Mahmoud=C2=A0
--00000000000092fc0905c070ca1a--