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=-10.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham 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 14020C48BE5 for ; Mon, 21 Jun 2021 08:29:27 +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 9542C60FF4 for ; Mon, 21 Jun 2021 08:29:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9542C60FF4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lvFJ7-0001vy-Qf for qemu-devel@archiver.kernel.org; Mon, 21 Jun 2021 04:29:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44966) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lvFI7-0000Qt-90 for qemu-devel@nongnu.org; Mon, 21 Jun 2021 04:28:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25914) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lvFI4-0007ko-Oj for qemu-devel@nongnu.org; Mon, 21 Jun 2021 04:28:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624264100; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4+pjEI9oWBjggg1vOoxCpJSegklvGvNbPRhtl2fxxqg=; b=Tqzk4dZ+M6H0qUzPr+uAeZN9uRHzS8HVhnpTsSwGGSNZYz6XHoForUkp0bC/IoljODuTj4 lFai89OzcrI0cXlCowaWaWW73cGMt61UwGXvepq3E8XysA2mSgzqX9KH7AtCVh9pmAWzjg gzBB2fvY935YnWaAJ+SxWMQ2yEPBNEA= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-423-xM-sATkBNA69YeRoTZyiZA-1; Mon, 21 Jun 2021 04:28:19 -0400 X-MC-Unique: xM-sATkBNA69YeRoTZyiZA-1 Received: by mail-ed1-f72.google.com with SMTP id ee28-20020a056402291cb0290394a9a0bfaeso1932209edb.6 for ; Mon, 21 Jun 2021 01:28:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=4+pjEI9oWBjggg1vOoxCpJSegklvGvNbPRhtl2fxxqg=; b=iX1rDiK26ftlHYeJOVSPpxs0lupgEVouEy9Arqw/zDn4G9PkGOX5/wiQXBSdF2LRh5 PdurBwQThz5zvAaleuwD5uHHTmUCvYy0x7854CX2anVrcZpIdYU31Ii2P6Sh6yY0tPq+ RySeBsYUnsgcvuLfmzDZhS92fcbclsfpaZYQridKGjxf203iBUX/Can+753etpZs3nda KaUFCt2NZyb2auBrmsmtAcgskud2mfscwE7sse0H4OuGf1Nzhbx08FOXdYq+i5VgcJYq qpzHCbSQqCgKvl3kZ3I0kO+22ch4D5eMtH9Zn6FexcCHweF9tYt8RRPJsItB47kt1QIs fdhg== X-Gm-Message-State: AOAM533dtkZtMyLO4bYOCOcRyBCHIVPeuggicmk9CQ9cBPskn/YA1JLq l3h0fKgUDSTl1lMRPRzGVohl9dDwWcdg5WzhSj0ekUnMHrUXzXlD8N11ROIK2T8FEFviAsKdMeu lpTKJw5E6jYXSTWileYWIZMk8og1uQtf1rNRzoZWAYv9Io/aW7sOvQQa9tKOl2J6kKvA= X-Received: by 2002:a17:906:f256:: with SMTP id gy22mr9960816ejb.103.1624264097757; Mon, 21 Jun 2021 01:28:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrx09CQhw95r7ShIZvDpfOahu4Q2qIkRN3Bdg3srKaLXHXfpKxhIHMKGsEXlnehBhe1lP6aw== X-Received: by 2002:a17:906:f256:: with SMTP id gy22mr9960798ejb.103.1624264097522; Mon, 21 Jun 2021 01:28:17 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:4:31cb:e591:1e1e:abde:a8f1]) by smtp.gmail.com with ESMTPSA id b19sm1632505edd.10.2021.06.21.01.28.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Jun 2021 01:28:17 -0700 (PDT) Subject: Re: [PATCH v4 3/6] block-copy: improve comments of BlockCopyTask and BlockCopyState types and functions To: Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org References: <20210614073350.17048-1-eesposit@redhat.com> <20210614073350.17048-4-eesposit@redhat.com> <47ed70d3-dfac-089e-3da0-e50455c4d0bb@virtuozzo.com> From: Emanuele Giuseppe Esposito Message-ID: Date: Mon, 21 Jun 2021 10:28:16 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <47ed70d3-dfac-089e-3da0-e50455c4d0bb@virtuozzo.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=216.205.24.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.299, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 19/06/2021 20:53, Vladimir Sementsov-Ogievskiy wrote: > 14.06.2021 10:33, Emanuele Giuseppe Esposito wrote: >> --- a/block/block-copy.c >> +++ b/block/block-copy.c >> @@ -52,29 +52,35 @@ typedef struct BlockCopyCallState { >>       /* Coroutine where async block-copy is running */ >>       Coroutine *co; >> -    /* To reference all call states from BlockCopyState */ >> -    QLIST_ENTRY(BlockCopyCallState) list; >> - >>       /* State */ >> -    int ret; >>       bool finished; >> -    QemuCoSleep sleep; >> -    bool cancelled; >> +    QemuCoSleep sleep; /* TODO: protect API with a lock */ >> + >> +    /* To reference all call states from BlockCopyState */ >> +    QLIST_ENTRY(BlockCopyCallState) list; >>       /* OUT parameters */ >> +    bool cancelled; >>       bool error_is_read; >> +    int ret; > > Hmm, about that. Is @ret an "OUT parameter"? Yes it is. > > But someone may think, that out parameters doesn't need locking like > "State" parameters (otherwise, what is the difference for the person who > read these comments?). But that is wrong. And ret is modified under > mutex for reason. In patch 5 I added a comment above @ret and @error_is_read: /* Fields protected by lock in BlockCopyState */ I can add your explanation too. > > Actually, the full description of "ret" field usage may look as follows: > > Set concurrently by tasks under mutex. Only set once by first failed > task (and untouched if no task failed). > After finish (if call_state->finished is true) not modified anymore and > may be read safely without mutex. > > So, before finished, ret is a kind of "State" too: it is both read and > written by tasks. > > This shows to me that dividing fields into "IN", "State" and "OUT", > doesn't really help here. In this series we use different policies of > concurrent access to fields: some are accessed only under mutex, other > has more complex usage scenario (like this @ret), some needs atomic access. > Yes but I think especially the IN vs State division helps a lot to understand what needs a lock and what doesn't. Emanuele