On Wed, Feb 27, 2019 at 07:30:34PM +0800, oulijun wrote: > 在 2019/2/27 14:41, Leon Romanovsky 写道: > > From: Leon Romanovsky <leonro@xxxxxxxxxxxx> > > > > There is a need to distinguish between driver vs. general exposed > > attributes. The most common use case is to expose some internal > > garbage under extremely common and sexy name, e.g. pi, ci e.t.c > > > > In order to achieve that, we will add "drv_" prefix to all strings > > which were received through RDMA_NLDEV_ATTR_DRIVER_* attributes. > > > > Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx>a > > --- > > rdma/utils.c | 34 ++++++++++++++++++++++------------ > > 1 file changed, 22 insertions(+), 12 deletions(-) > > > > diff --git a/rdma/utils.c b/rdma/utils.c > > index 6bc14cd5..1f6bf330 100644 > > --- a/rdma/utils.c > > +++ b/rdma/utils.c > > @@ -829,27 +829,37 @@ static int print_driver_entry(struct rd *rd, struct nlattr *key_attr, > > struct nlattr *val_attr, > > enum rdma_nldev_print_type print_type) > > { > > - const char *key_str = mnl_attr_get_str(key_attr); > > int attr_type = nla_type(val_attr); > > + int ret = -EINVAL; > > + char *key_str; > > + > > + if (asprintf(&key_str, "drv_%s", mnl_attr_get_str(key_attr)) == -1) > > + return -ENOMEM; > > > > switch (attr_type) { > > case RDMA_NLDEV_ATTR_DRIVER_STRING: > > - return print_driver_string(rd, key_str, > > - mnl_attr_get_str(val_attr)); > > + ret = print_driver_string(rd, key_str, > > + mnl_attr_get_str(val_attr)); > > + break; > > case RDMA_NLDEV_ATTR_DRIVER_S32: > > - return print_driver_s32(rd, key_str, > > - mnl_attr_get_u32(val_attr), print_type); > > + ret = print_driver_s32(rd, key_str, mnl_attr_get_u32(val_attr), > > + print_type); > > + break; > > case RDMA_NLDEV_ATTR_DRIVER_U32: > > - return print_driver_u32(rd, key_str, > > - mnl_attr_get_u32(val_attr), print_type); > > + ret = print_driver_u32(rd, key_str, mnl_attr_get_u32(val_attr), > > + print_type); > > + break; > > case RDMA_NLDEV_ATTR_DRIVER_S64: > > - return print_driver_s64(rd, key_str, > > - mnl_attr_get_u64(val_attr), print_type); > > + ret = print_driver_s64(rd, key_str, mnl_attr_get_u64(val_attr), > > + print_type); > > + break; > > case RDMA_NLDEV_ATTR_DRIVER_U64: > > - return print_driver_u64(rd, key_str, > > - mnl_attr_get_u64(val_attr), print_type); > > + ret = print_driver_u64(rd, key_str, mnl_attr_get_u64(val_attr), > > + print_type); > > + break; > > } > > - return -EINVAL; > > + free(key_str); > > + return ret; > > } > > > > void print_driver_table(struct rd *rd, struct nlattr *tb) > > -- > > 2.19.1 > > > > > > . > > > This is fine to me and the implementation is more simple. > > Tested-by: Lijun Ou <oulijun@xxxxxxxxxx> Thanks a lot. > > thanks. >
Attachment:
signature.asc
Description: PGP signature