From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41289) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFszn-0006WP-KE for qemu-devel@nongnu.org; Wed, 22 Jun 2016 20:59:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFszi-0002B7-L7 for qemu-devel@nongnu.org; Wed, 22 Jun 2016 20:59:51 -0400 Received: from [59.151.112.132] (port=42750 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFszi-00025x-0n for qemu-devel@nongnu.org; Wed, 22 Jun 2016 20:59:46 -0400 Message-ID: <576B3588.1070806@cn.fujitsu.com> Date: Thu, 23 Jun 2016 09:04:08 +0800 From: Changlong Xie MIME-Version: 1.0 References: <1466587008-3933-1-git-send-email-xiecl.fnst@cn.fujitsu.com> <1466587008-3933-2-git-send-email-xiecl.fnst@cn.fujitsu.com> <2b17fa8d-d2bb-d20e-2445-e010aa7066b1@redhat.com> <576A6486.4070409@cn.fujitsu.com> <233d4f8a-8d64-ffa8-9470-8c51463ef69b@redhat.com> <576ACB8C.7050304@redhat.com> In-Reply-To: <576ACB8C.7050304@redhat.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/2] blockjob: assert(cb) in the entry functions of blockjob List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake , Paolo Bonzini , qemu devel , Jeff Cody Cc: Kevin Wolf , Fam Zheng , Stefan Hajnoczi , Max Reitz On 06/23/2016 01:31 AM, Eric Blake wrote: > On 06/22/2016 04:19 AM, Paolo Bonzini wrote: >> >> >> On 22/06/2016 12:12, Changlong Xie wrote: >>> >>> commit/mirror/stream/backup use block_job_create(..., cb,..) to create >>> relevant blockjob. When they finished, these jobs will invoke >>> block_job_completed, then invoke job->cb() unconditionally. So i think >>> we need this to avoid segment fault. Actually backup has implemented this. >> >> So this suggests that the right place to put the assertion would be >> block_job_create. But it's even better to add a >> >> #define QEMU_NONNULL __attribute__((__nonnull__)) >> >> to include/qemu/compiler.h and declare the arguments as non-null. > > Or alternatively fix things to only invoke job->cb() if it is non-NULL, > so that callers don't have to pass in a no-op callback just to appease a > non-NULL attribute. > Is there any reason, that we should invoke job->cb() unconditionally without nonnull check? There is no relevant clue in the historical commit messages. If yes, i prefer paolo's suggestion; otherwise eric's solution is better. Thanks -Xie