On 04/13/2012 04:20 PM, Li Wenpeng wrote: > From: levin li <xingke.lwp at taobao.com> > > Currently, parse_objs traverse all the nodes to get the object, > and then call the callback function, it's OK for do_print_obj(), > but it's a waste for get_data_oid(), when the cluster gets larger > with more nodes, it makes collie slower the get the object id. > > I add a return value for the callback function obj_parse_func_t, > if the function returns 1, the loop breaks when the first time > it succeeds, if 0, it will traverse the whole node list. > > Signed-off-by: levin li <xingke.lwp at taobao.com> > --- > collie/vdi.c | 23 ++++++++++++++++------- > 1 files changed, 16 insertions(+), 7 deletions(-) > > diff --git a/collie/vdi.c b/collie/vdi.c > index 8260eba..9675774 100644 > --- a/collie/vdi.c > +++ b/collie/vdi.c > @@ -188,10 +188,10 @@ static void get_oid(uint32_t vid, char *name, char *tag, uint32_t snapid, > } > } > > -typedef void (*obj_parser_func_t)(char *sheep, uint64_t oid, > +typedef int (*obj_parser_func_t)(char *sheep, uint64_t oid, > struct sd_obj_rsp *rsp, char *buf, void *data); > > -static void do_print_obj(char *sheep, uint64_t oid, struct sd_obj_rsp *rsp, > +static int do_print_obj(char *sheep, uint64_t oid, struct sd_obj_rsp *rsp, > char *buf, void *data) > { > switch (rsp->result) { > @@ -211,6 +211,8 @@ static void do_print_obj(char *sheep, uint64_t oid, struct sd_obj_rsp *rsp, > sheep, rsp->result); > break; > } > + > + return 0; > } > > struct get_data_oid_info { > @@ -219,7 +221,7 @@ struct get_data_oid_info { > unsigned idx; > }; > > -static void get_data_oid(char *sheep, uint64_t oid, struct sd_obj_rsp *rsp, > +static int get_data_oid(char *sheep, uint64_t oid, struct sd_obj_rsp *rsp, > char *buf, void *data) > { > struct get_data_oid_info *info = data; > @@ -230,8 +232,10 @@ static void get_data_oid(char *sheep, uint64_t oid, struct sd_obj_rsp *rsp, > if (info->success) > break; > info->success = 1; > - if (inode->data_vdi_id[info->idx]) > + if (inode->data_vdi_id[info->idx]) { > info->data_oid = vid_to_data_oid(inode->data_vdi_id[info->idx], info->idx); > + return 1; > + } > break; > case SD_RES_NO_OBJ: > break; > @@ -244,12 +248,14 @@ static void get_data_oid(char *sheep, uint64_t oid, struct sd_obj_rsp *rsp, > sheep, rsp->result); > break; > } > + > + return 0; > } > > static void parse_objs(uint64_t oid, obj_parser_func_t func, void *data, unsigned size) > { > char name[128]; > - int i, fd, ret; > + int i, fd, ret, cb_ret; > char *buf; > > buf = zalloc(size); > @@ -284,8 +290,11 @@ static void parse_objs(uint64_t oid, obj_parser_func_t func, void *data, unsigne > > if (ret) > fprintf(stderr, "Failed to connect to %s\n", name); > - else > - func(name, oid, rsp, buf, data); > + else { > + cb_ret = func(name, oid, rsp, buf, data); > + if (cb_ret) > + break; > + } > } > > free(buf); Applied, thanks Yuan |