From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:39244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T8mqW-0007At-DS for qemu-devel@nongnu.org; Tue, 04 Sep 2012 02:42:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T8mqU-0004OF-SR for qemu-devel@nongnu.org; Tue, 04 Sep 2012 02:42:48 -0400 Received: from e28smtp07.in.ibm.com ([122.248.162.7]:38377) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T8mqT-0004O2-Vp for qemu-devel@nongnu.org; Tue, 04 Sep 2012 02:42:46 -0400 Received: from /spool/local by e28smtp07.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 4 Sep 2012 12:12:42 +0530 Received: from d28av03.in.ibm.com (d28av03.in.ibm.com [9.184.220.65]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q846gcaf23986190 for ; Tue, 4 Sep 2012 12:12:38 +0530 Received: from d28av03.in.ibm.com (loopback [127.0.0.1]) by d28av03.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q846gctV008755 for ; Tue, 4 Sep 2012 16:42:38 +1000 Message-ID: <5045A2BB.3060007@linux.vnet.ibm.com> Date: Tue, 04 Sep 2012 14:42:03 +0800 From: Wenchao Xia MIME-Version: 1.0 References: <1346663926-20188-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1346663926-20188-2-git-send-email-xiawenc@linux.vnet.ibm.com> <5044B720.5080205@redhat.com> In-Reply-To: <5044B720.5080205@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/6] libqblock APIs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: kwolf@redhat.com, pbonzini@redhat.com, aliguori@us.ibm.com, qemu-devel@nongnu.org, stefanha@gmail.com Thank u for the careful reviewing of my codes, I will write down the typo errors you mentioned on a note. > On 09/03/2012 03:18 AM, Wenchao Xia wrote: >> This patch contains the major APIs in the library. >> Important APIs: >> 1 QBroker. These structure was used to retrieve errors, every thread must >> create one first, Later maybe thread related staff could be added into it. >> 2 QBlockState. It stands for an block image object. >> 3 QBlockInfoImageStatic. Now it is not folded with location and format. >> 4 ABI was kept with reserved members. >> >> structure, because it would cause caller more codes to find one member. > > Commit message snafu? > a wrong paste, sorry. >> +/** >> + * libqblock_init: Initialize the library >> + */ >> +void libqblock_init(void); > > Is this function safe to call more than once? Even tighter, is it safe > to call this function simultaneously from multiple threads? > No, it should be only called once, any other thread should not call it again, will document it. About the multiple thread user case, qemu block layer can't support that now, will fix that later. >> + >> +/** >> + * qb_broker_new: allocate a new broker >> + * >> + * Broker is used to pass operation to libqblock, and got feed back from it. > > s/got feed back/get feedback/ > >> + * >> + * Returns 0 on success, negative value on fail. > > Is there any particular interpretation to this negative value, such as > negative errno constant, or always -1? > Yes, negative values are defined with macros in the header file. >> + >> +/** >> + * qb_state_new: allocate a new QBloctState struct > > s/Bloct/Block/ > >> + * >> + * Following qblock action were based on this struct > > Didn't read well. Did you mean: > > Subsequent qblock actions will use this struct > Yes. >> + * >> + * Returns 0 if succeed, negative value on fail. > > Again, is there any particular meaning to which negative value is returned? > >> + >> +/** >> + * qb_open: open a block object. >> + * >> + * return 0 on success, negative on fail. >> + * >> + * @broker: operation broker. >> + * @qbs: pointer to struct QBlockState. >> + * @loc: location options for open, how to find the image. >> + * @fmt: format options, how to extract the data, only valid member now is >> + fmt->fmt_type, set NULL if you want auto discovery the format. > > set to NULL if you want to auto-discover the format > > Maybe also add a warning about the inherent security risks of attempting > format auto-discovery (any raw image must NOT be probed, as the raw > image can emulate any other format and cause qemu to chase down chains > where it should not). > it seems qemu-img could find out that an image is raw correctly by probing, do you mean give a warning saying that this image is probably some formats that qemu do not supported, such as virtual box's image? >> + * @flag: behavior control flags. > > What flags are currently defined? > It is the flags defined in the header file, such as LIBQBLOCK_O_RDWR, will document it. >> + */ >> +int qb_open(struct QBroker *broker, >> + struct QBlockState *qbs, >> + struct QBlockOptionLoc *loc, >> + struct QBlockOptionFormat *fmt, >> + int flag); >> + >> +/** >> + * qb_close: close a block object. >> + * >> + * qb_flush is automaticlly done inside. > > s/automaticlly/automatically/ > >> +/** >> + * qb_create: create a block image or object. >> + * >> + * Note: Create operation would not open the image automatically. >> + * >> + * return negative on fail, 0 on success. >> + * >> + * @broker: operation broker. >> + * @qbs: pointer to struct QBlockState. >> + * @loc: location options for open, how to find the image. >> + * @fmt: format options, how to extract the data. >> + * @flag: behavior control flags. > > Again, what flags are defined? > >> + >> +/* sync access */ >> +/** >> + * qb_read: block sync read. >> + * >> + * return negative on fail, 0 on success. > > Shouldn't this instead return the number of successfully read bytes, to > allow for short reads if offset exceeds end-of-file? If so, should it > return ssize_t instead of int? > I had this idea before too, let'me check if qemu block layer can provide this functionality, >> + * >> + * @broker: operation broker. >> + * @qbs: pointer to struct QBlockState. >> + * @buf: buffer that receive the content. > > s/receive/receives/ > >> + * @len: length to read. > > Is there a magic length for reading the entire file in one go? > no, if so where should I put with the result. >> + * @offset: offset in the block data. >> + */ >> +int qb_read(struct QBroker *broker, >> + struct QBlockState *qbs, >> + const void *buf, >> + size_t len, >> + off_t offset); > > You do realize that size_t and off_t are not necessarily the same width; > but I'm okay with limiting to size_t reads. > >> +/** >> + * qb_write: block sync write. >> + * >> + * return negative on fail, 0 on success. > > Again, this should probably return number of successfully written bytes, > as an ssize_t. > >> + * >> + * @broker: operation broker. >> + * @qbs: pointer to struct QBlockState. >> + * @buf: buffer that receive the content. > > s/receive/supplies/ > >> +/* advance image APIs */ >> +/** >> + * qb_is_allocated: check if following sectors was allocated on the image. >> + * >> + * return negative on fail, 0 or 1 on success. 0 means unallocated, 1 means >> + *allocated. > > Formatting is off. > coming later. >> + * >> + * @broker: operation broker. >> + * @qbs: pointer to struct QBlockState. >> + * @sector_num: start sector number. If 'sector_num' is beyond the end of the >> + *disk image the return value is 0 and 'pnum' is set to 0. >> + * @nb_sectors: how many sector would be checked, it is the max value 'pnum' >> + *should be set to. If nb_sectors goes beyond the end of the disk image it >> + *will be clamped. >> + * @pnum: pointer to receive how many sectors are allocated or unallocated. > > This interface requires the user to know how big a sector is. Would it > be any more convenient to the user to pass offsets, rather than sector > numbers; and/or have a function for converting between offsets and > sector numbers? > OK, I need a function returning how big a sector is in an image. >> + */ >> +int qb_is_allocated(struct QBroker *broker, >> + struct QBlockState *qbs, >> + int64_t sector_num, >> + int nb_sectors, > > Shouldn't nb_sectors be size_t? > >> + int *pnum); > > Exactly how does the *pnum argument work? This interface looks like it > isn't fully thought out yet. Either I want to know if a chunk of > sectors is allocated (I supply start and length of sectors to check), > regardless of how many sectors beyond that point are also allocated > (pnum makes no sense); or I want to know how many sectors are allocated > from a given point (I supply start, and the function returns length, so > nb_sectors makes no sense). Either way, I think you are supplying too > many parameters for how I envision checking for allocated sectors. > -- Best Regards Wenchao Xia