From patchwork Tue Feb 26 13:40:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lijun Ou X-Patchwork-Id: 10830141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E9C5D15AC for ; Tue, 26 Feb 2019 12:58:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D724629EB0 for ; Tue, 26 Feb 2019 12:58:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9BBA2BE2A; Tue, 26 Feb 2019 12:58:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BF5429EB0 for ; Tue, 26 Feb 2019 12:58:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726222AbfBZM6N (ORCPT ); Tue, 26 Feb 2019 07:58:13 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:4740 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725954AbfBZM6N (ORCPT ); Tue, 26 Feb 2019 07:58:13 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 1F5702430D8A363F277C; Tue, 26 Feb 2019 20:58:10 +0800 (CST) Received: from linux-ioko.site (10.71.200.31) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.408.0; Tue, 26 Feb 2019 20:57:59 +0800 From: Lijun Ou To: , , CC: , Subject: [RFC V2 iproute2-next] rdma: Add the prefix for driver attributes Date: Tue, 26 Feb 2019 21:40:12 +0800 Message-ID: <1551188412-30780-1-git-send-email-oulijun@huawei.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.71.200.31] X-CFilter-Loop: Reflected Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We need to increase the prefix named drv_ to distinguish whether the attribute is from IB/core or the driver attribute. From the sample output: root@(none)# ./rdma res show cq dev hns_0 dev hns_0 cqe 1023 users 2 poll-ctx WORKQUEUE pid 0 comm [ib_core] drv_state 2 drv_ceqn 0 drv_poll 0 drv_shift 10 drv_cmd_sn 1 drv_cqn 0 drv_hopnum 1 drv_pi 0 drv_ci 0 drv_rdb_en 1 drv_coalesce 0 drv_period 0 drv_cnt 0 drv_se_idx 0 root@(none)# ./rdma res show cq dev hns_0 -j [{["ifindex":1,"ifname":"hns_0","cqe":1023,"users":2,"poll-ctx":"WORKQUEUE","pid":0,"comm":"ib_core","drv_state":2,"drv_ceqn":0,"drv_poll":0,"drv_shift":10,"drv_cmd_sn":1,"drv_cqn":0,"drv_hopnum":1,"drv_pi":0,"drv_ci":0,"drv_rdb_en":1,"drv_coalesce":0,"drv_period":0,"drv_cnt":0,"drv_se_idx":0]}] Signed-off-by: Lijun Ou --- V1->V2: - Add the prefix print for driver by JSON format. --- include/json_writer.h | 3 +++ lib/json_writer.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++- rdma/utils.c | 18 +++++++++--------- 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/include/json_writer.h b/include/json_writer.h index b52dc2d..f8da48f 100644 --- a/include/json_writer.h +++ b/include/json_writer.h @@ -28,6 +28,9 @@ void jsonw_pretty(json_writer_t *self, bool on); /* Add property name */ void jsonw_name(json_writer_t *self, const char *name); +/* Add property name with driver specific */ +void jsonw_driver_name(json_writer_t *self, const char *name); + /* Add value */ __attribute__((format(printf, 2, 3))) void jsonw_printf(json_writer_t *self, const char *fmt, ...); diff --git a/lib/json_writer.c b/lib/json_writer.c index 5004c18..6d09eec 100644 --- a/lib/json_writer.c +++ b/lib/json_writer.c @@ -89,6 +89,44 @@ static void jsonw_puts(json_writer_t *self, const char *str) putc('"', self->out); } +/* Output JSON encoded string with the driver-specific */ +/* Handles C escapes, does not do Unicode */ +static void jsonw_driver_puts(json_writer_t *self, const char *str) +{ + putc('"', self->out); + fputs("drv_", self->out); + for (; *str; ++str) + switch (*str) { + case '\t': + fputs("\\t", self->out); + break; + case '\n': + fputs("\\n", self->out); + break; + case '\r': + fputs("\\r", self->out); + break; + case '\f': + fputs("\\f", self->out); + break; + case '\b': + fputs("\\b", self->out); + break; + case '\\': + fputs("\\n", self->out); + break; + case '"': + fputs("\\\"", self->out); + break; + case '\'': + fputs("\\\'", self->out); + break; + default: + putc(*str, self->out); + } + putc('"', self->out); +} + /* Create a new JSON stream */ json_writer_t *jsonw_new(FILE *f) { @@ -152,6 +190,18 @@ void jsonw_name(json_writer_t *self, const char *name) putc(' ', self->out); } +/* Add a JSON property name for driver */ +void jsonw_driver_name(json_writer_t *self, const char *name) +{ + jsonw_eor(self); + jsonw_eol(self); + self->sep = '\0'; + jsonw_driver_puts(self, name); + putc(':', self->out); + if (self->pretty) + putc(' ', self->out); +} + __attribute__((format(printf, 2, 3))) void jsonw_printf(json_writer_t *self, const char *fmt, ...) { @@ -323,7 +373,7 @@ void jsonw_lluint_field(json_writer_t *self, void jsonw_int_field(json_writer_t *self, const char *prop, int num) { - jsonw_name(self, prop); + jsonw_driver_name(self, prop); jsonw_int(self, num); } diff --git a/rdma/utils.c b/rdma/utils.c index 069d44f..8890981 100644 --- a/rdma/utils.c +++ b/rdma/utils.c @@ -720,7 +720,7 @@ static int print_driver_string(struct rd *rd, const char *key_str, jsonw_string_field(rd->jw, key_str, val_str); return 0; } else { - return pr_out("%s %s ", key_str, val_str); + return pr_out("drv_%s %s ", key_str, val_str); } } @@ -733,9 +733,9 @@ static int print_driver_s32(struct rd *rd, const char *key_str, int32_t val, } switch (print_type) { case RDMA_NLDEV_PRINT_TYPE_UNSPEC: - return pr_out("%s %d ", key_str, val); + return pr_out("drv_%s %d ", key_str, val); case RDMA_NLDEV_PRINT_TYPE_HEX: - return pr_out("%s 0x%x ", key_str, val); + return pr_out("drv_%s 0x%x ", key_str, val); default: return -EINVAL; } @@ -750,9 +750,9 @@ static int print_driver_u32(struct rd *rd, const char *key_str, uint32_t val, } switch (print_type) { case RDMA_NLDEV_PRINT_TYPE_UNSPEC: - return pr_out("%s %u ", key_str, val); + return pr_out("drv_%s %u ", key_str, val); case RDMA_NLDEV_PRINT_TYPE_HEX: - return pr_out("%s 0x%x ", key_str, val); + return pr_out("drv_%s 0x%x ", key_str, val); default: return -EINVAL; } @@ -767,9 +767,9 @@ static int print_driver_s64(struct rd *rd, const char *key_str, int64_t val, } switch (print_type) { case RDMA_NLDEV_PRINT_TYPE_UNSPEC: - return pr_out("%s %" PRId64 " ", key_str, val); + return pr_out("drv_%s %" PRId64 " ", key_str, val); case RDMA_NLDEV_PRINT_TYPE_HEX: - return pr_out("%s 0x%" PRIx64 " ", key_str, val); + return pr_out("drv_%s 0x%" PRIx64 " ", key_str, val); default: return -EINVAL; } @@ -784,9 +784,9 @@ static int print_driver_u64(struct rd *rd, const char *key_str, uint64_t val, } switch (print_type) { case RDMA_NLDEV_PRINT_TYPE_UNSPEC: - return pr_out("%s %" PRIu64 " ", key_str, val); + return pr_out("drv_%s %" PRIu64 " ", key_str, val); case RDMA_NLDEV_PRINT_TYPE_HEX: - return pr_out("%s 0x%" PRIx64 " ", key_str, val); + return pr_out("drv_%s 0x%" PRIx64 " ", key_str, val); default: return -EINVAL; }