<br><br>
<div class="gmail_quote">On Wed, Mar 14, 2012 at 11:20 PM, Liu Yuan <span dir="ltr"><<a href="mailto:namei.unix@gmail.com">namei.unix@gmail.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT:#ccc 1px solid;MARGIN:0px 0px 0px 0.8ex;PADDING-LEFT:1ex" class="gmail_quote">
<div class="HOEnZb">
<div class="h5">On 03/14/2012 01:50 PM, <a href="mailto:yaohaiting.wujue@gmail.com">yaohaiting.wujue@gmail.com</a> wrote:<br>> From: HaiTing Yao <<a href="mailto:wujue.yht@taobao.com">wujue.yht@taobao.com</a>><br>
><br>> 1, make it more readable<br>><br>> 2, malloc size is not right, not multiply size of uint32_t<br>><br>> Signed-off-by: HaiTing Yao <<a href="mailto:wujue.yht@taobao.com">wujue.yht@taobao.com</a>><br>
> ---<br>> sheep/vdi.c | 15 ++++++++-------<br>> 1 files changed, 8 insertions(+), 7 deletions(-)<br>><br>> diff --git a/sheep/vdi.c b/sheep/vdi.c<br>> index 3791127..d0b8b2a 100644<br>> --- a/sheep/vdi.c<br>
> +++ b/sheep/vdi.c<br>> @@ -425,7 +425,7 @@ struct deletion_work {<br>> uint32_t vid;<br>><br>> int count;<br>> - char *buf;<br>> + uint32_t *buf;<br>> };<br>><br>> static LIST_HEAD(deletion_work_list);<br>
> @@ -433,7 +433,7 @@ static LIST_HEAD(deletion_work_list);<br>> static void delete_one(struct work *work)<br>> {<br>> struct deletion_work *dw = container_of(work, struct deletion_work, work);<br>> - uint32_t vdi_id = *(((uint32_t *)dw->buf) + dw->count - dw->done - 1);<br>
> + uint32_t vdi_id = *(dw->buf + dw->count - dw->done - 1);<br>> struct sd_vnode *entries = NULL;<br>> int nr_vnodes, nr_zones;<br>> int ret, i;<br>> @@ -516,9 +516,9 @@ static int fill_vdi_list(struct deletion_work *dw,<br>
> goto err;<br>> }<br>><br>> - ((uint32_t *)dw->buf)[dw->count++] = root_vid;<br>> + dw->buf[dw->count++] = root_vid;<br>> again:<br>> - vid = ((uint32_t *)dw->buf)[done++];<br>
> + vid = dw->buf[done++];<br>> ret = read_object(entries, nr_vnodes, nr_zones, dw->epoch,<br>> vid_to_vdi_oid(vid), (char *)inode,<br>> SD_INODE_HEADER_SIZE, 0, sys->nr_sobjs);<br>
> @@ -535,10 +535,10 @@ again:<br>> if (!inode->child_vdi_id[i])<br>> continue;<br>><br>> - ((uint32_t *)dw->buf)[dw->count++] = inode->child_vdi_id[i];<br>
> + dw->buf[dw->count++] = inode->child_vdi_id[i];<br>> }<br>><br>> - if (((uint32_t *)dw->buf)[done])<br>> + if (dw->buf[done])<br>> goto again;<br>
> err:<br>> free(inode);<br>> @@ -597,7 +597,8 @@ int start_deletion(uint32_t vid, uint32_t epoch)<br>> goto err;<br>> }<br>><br>> - dw->buf = zalloc(1 << 20); /* FIXME: handle larger buffer */<br>
> + /* buf is to store vdi id of every object */<br>> + dw->buf = zalloc(sizeof(vid) * MAX_DATA_OBJS); /* FIXME: handle larger buffer */<br><br></div></div>how about use macro for buf size = (SD_INODE_SIZE - SD_INODE_HEADER_SIZE) ?<br>
I guess /* FIXME: handle larger buffer */ could be removed. This comment doesn't make sense.<br><br>Thanks,<br>Yuan<br></blockquote>
<div> </div>
<div>OK, they are equal. I will send new patch soon</div>
<div> </div>
<div>Thanks</div>
<div>Wujue</div>
<blockquote style="BORDER-LEFT:#ccc 1px solid;MARGIN:0px 0px 0px 0.8ex;PADDING-LEFT:1ex" class="gmail_quote">
<div class="im"><br><br>> if (!dw->buf) {<br>> ret = SD_RES_NO_MEM;<br>> goto err;<br><br><br>--<br></div>thanks,<br>Yuan<br></blockquote></div><br>