From patchwork Fri Feb 2 14:08:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Pen X-Patchwork-Id: 10196803 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 809D96037D for ; Fri, 2 Feb 2018 14:11:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A9A628E6D for ; Fri, 2 Feb 2018 14:11:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C66F28E8F; Fri, 2 Feb 2018 14:11:03 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 9E32128E7F for ; Fri, 2 Feb 2018 14:11:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752125AbeBBOLA (ORCPT ); Fri, 2 Feb 2018 09:11:00 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:36827 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752016AbeBBOKw (ORCPT ); Fri, 2 Feb 2018 09:10:52 -0500 Received: by mail-wr0-f194.google.com with SMTP id y3so12850656wrh.3 for ; Fri, 02 Feb 2018 06:10:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profitbricks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=16sEWwQiHd67OCtvIFOMuC/bhyI21CRau5hFoETJ5h8=; b=Eym7qX2/4KQpGYKuHQ/rvZSyjuUarnhg3o1tnuj0zhlBHGCGmJnV7uI8NKOxOTXTFJ zfIjSG4yB3Ah68LF1z/HbQhLu9N6U7MxvF0C7tqx+5nI4zlLvCZ9qQndhneeyD+OojXc 9am8hfURk9OY+KiPntpJS5Wk5FeuM7HuAHvwNYGdxJ7c4JVEhHdd7UaQRB45YPyPr6In j493BCtjYVuudgDX18nm8nehRFB+kMaNV5PgpaXfipK0xAUMJ6hB7/KcFQqESlUvwGxH YL4Ldb9J7PHU28CRl8EB4IgVGiZW3u4dEk8+E2jvZ+E3CpS8wcO6Y2BdyjZdd1/U5Q1x pwVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=16sEWwQiHd67OCtvIFOMuC/bhyI21CRau5hFoETJ5h8=; b=cNJKPkCWIys4doQ3m+XLyZtC4mZeueRCul25Ned3uh8kuIEN0StxlHLJxyB7meYmRo SoukCLt2alRcyoNZS8ApIf1csul4vPfXep19biG0C8EP/Mdid6VSDxGgKkKLNVYz99zr js0ZyBbTDgJnr33e0u7aH8s5H3gxsxKAcguOTUji22fAyV7XfzB31E1fxYakK3+VeBE6 Hnor1Dx/eyThQMj3wGGcNn0vIJSoIdjfAMk/zPIRZbDxwEY3SSThiK7VEFiyIfXv8yfu gksItm7JAckjvCTnwYrgK1lD6UZ0oss8Cuklim+FzncqXSwM7u/He4yYqMBpdLYA9+MY npcw== X-Gm-Message-State: AKwxytc5HjJQiUdY+g1bL1zoAshoHkEg8LGo/WGfFjB+ipJT86cdqfQk UlYtHLz9DezyQwADHC2o5XqINuW9 X-Google-Smtp-Source: AH8x224YGU5y8uCmLUGqMBZFRv+1YRz/OcSqM/XAEhuOVJmP+gynNz4CATIPxP3w2Ck13twiTZejHA== X-Received: by 10.223.196.226 with SMTP id o31mr18580385wrf.188.1517580650303; Fri, 02 Feb 2018 06:10:50 -0800 (PST) Received: from pb.pb.local ([62.217.45.26]) by smtp.gmail.com with ESMTPSA id v186sm798819wmf.17.2018.02.02.06.10.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Feb 2018 06:10:49 -0800 (PST) From: Roman Pen To: linux-block@vger.kernel.org, linux-rdma@vger.kernel.org Cc: Jens Axboe , Christoph Hellwig , Sagi Grimberg , Bart Van Assche , Or Gerlitz , Roman Pen , Danil Kipnis , Jack Wang Subject: [PATCH 07/24] ibtrs: client: sysfs interface functions Date: Fri, 2 Feb 2018 15:08:47 +0100 Message-Id: <20180202140904.2017-8-roman.penyaev@profitbricks.com> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20180202140904.2017-1-roman.penyaev@profitbricks.com> References: <20180202140904.2017-1-roman.penyaev@profitbricks.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is the sysfs interface to IBTRS sessions on client side: /sys/kernel/ibtrs_client// *** IBTRS session created by ibtrs_clt_open() API call | |- max_reconnect_attempts | *** number of reconnect attempts for session | |- add_path | *** adds another connection path into IBTRS session | |- paths// *** established paths to server in a session | |- disconnect | *** disconnect path | |- reconnect | *** reconnect path | |- remove_path | *** remove current path | |- state | *** retrieve current path state | |- stats/ *** current path statistics | |- cpu_migration |- rdma |- rdma_lat |- reconnects |- reset_all |- sg_entries |- wc_completions Signed-off-by: Roman Pen Signed-off-by: Danil Kipnis Cc: Jack Wang --- drivers/infiniband/ulp/ibtrs/ibtrs-clt-sysfs.c | 519 +++++++++++++++++++++++++ 1 file changed, 519 insertions(+) diff --git a/drivers/infiniband/ulp/ibtrs/ibtrs-clt-sysfs.c b/drivers/infiniband/ulp/ibtrs/ibtrs-clt-sysfs.c new file mode 100644 index 000000000000..04949d6d796b --- /dev/null +++ b/drivers/infiniband/ulp/ibtrs/ibtrs-clt-sysfs.c @@ -0,0 +1,519 @@ +/* + * InfiniBand Transport Layer + * + * Copyright (c) 2014 - 2017 ProfitBricks GmbH. All rights reserved. + * Authors: Fabian Holler + * Jack Wang + * Kleber Souza + * Danil Kipnis + * Roman Penyaev + * Milind Dumbare + * + * Copyright (c) 2017 - 2018 ProfitBricks GmbH. All rights reserved. + * Authors: Danil Kipnis + * Roman Penyaev + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#undef pr_fmt +#define pr_fmt(fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt + +#include "ibtrs-pri.h" +#include "ibtrs-clt.h" +#include "ibtrs-log.h" + +static struct kobject *ibtrs_kobj; + +#define MIN_MAX_RECONN_ATT -1 +#define MAX_MAX_RECONN_ATT 9999 + +static struct kobj_type ktype = { + .sysfs_ops = &kobj_sysfs_ops, +}; + +static ssize_t ibtrs_clt_max_reconn_attempts_show(struct kobject *kobj, + struct kobj_attribute *attr, + char *page) +{ + struct ibtrs_clt *clt; + + clt = container_of(kobj, struct ibtrs_clt, kobj); + + return sprintf(page, "%d\n", ibtrs_clt_get_max_reconnect_attempts(clt)); +} + +static ssize_t ibtrs_clt_max_reconn_attempts_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, + size_t count) +{ + struct ibtrs_clt *clt; + int value; + int ret; + + clt = container_of(kobj, struct ibtrs_clt, kobj); + + ret = kstrtoint(buf, 10, &value); + if (unlikely(ret)) { + ibtrs_err(clt, "%s: failed to convert string '%s' to int\n", + attr->attr.name, buf); + return ret; + } + if (unlikely(value > MAX_MAX_RECONN_ATT || + value < MIN_MAX_RECONN_ATT)) { + ibtrs_err(clt, "%s: invalid range" + " (provided: '%s', accepted: min: %d, max: %d)\n", + attr->attr.name, buf, MIN_MAX_RECONN_ATT, + MAX_MAX_RECONN_ATT); + return -EINVAL; + } + ibtrs_clt_set_max_reconnect_attempts(clt, value); + + return count; +} + +static struct kobj_attribute ibtrs_clt_max_reconnect_attempts_attr = + __ATTR(max_reconnect_attempts, 0644, + ibtrs_clt_max_reconn_attempts_show, + ibtrs_clt_max_reconn_attempts_store); + +static ssize_t ibtrs_clt_mp_policy_show(struct kobject *kobj, + struct kobj_attribute *attr, + char *page) +{ + struct ibtrs_clt *clt; + + clt = container_of(kobj, struct ibtrs_clt, kobj); + + switch (clt->mp_policy) { + case MP_POLICY_RR: + return sprintf(page, "round-robin (RR: %d)\n", clt->mp_policy); + case MP_POLICY_MIN_INFLIGHT: + return sprintf(page, "min-inflight (MI: %d)\n", clt->mp_policy); + default: + return sprintf(page, "Unknown (%d)\n", clt->mp_policy); + } +} + +static ssize_t ibtrs_clt_mp_policy_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, + size_t count) +{ + struct ibtrs_clt *clt; + int value; + int ret; + + clt = container_of(kobj, struct ibtrs_clt, kobj); + + ret = kstrtoint(buf, 10, &value); + if (!ret && (value == MP_POLICY_RR || value == MP_POLICY_MIN_INFLIGHT)) { + clt->mp_policy = value; + return count; + } + + if (!strncasecmp(buf, "round-robin", 11) || + !strncasecmp(buf, "rr", 2)) + clt->mp_policy = MP_POLICY_RR; + else if (!strncasecmp(buf, "min-inflight", 12) || + !strncasecmp(buf, "mi", 2)) + clt->mp_policy = MP_POLICY_MIN_INFLIGHT; + else + return -EINVAL; + + return count; +} + +static struct kobj_attribute ibtrs_clt_mp_policy_attr = + __ATTR(mp_policy, 0644, + ibtrs_clt_mp_policy_show, + ibtrs_clt_mp_policy_store); + +static ssize_t ibtrs_clt_state_show(struct kobject *kobj, + struct kobj_attribute *attr, char *page) +{ + struct ibtrs_clt_sess *sess; + + sess = container_of(kobj, struct ibtrs_clt_sess, kobj); + if (ibtrs_clt_sess_is_connected(sess)) + return sprintf(page, "connected\n"); + + return sprintf(page, "disconnected\n"); +} + +static struct kobj_attribute ibtrs_clt_state_attr = + __ATTR(state, 0444, ibtrs_clt_state_show, NULL); + +static ssize_t ibtrs_clt_reconnect_show(struct kobject *kobj, + struct kobj_attribute *attr, + char *page) +{ + return scnprintf(page, PAGE_SIZE, "Usage: echo 1 > %s\n", + attr->attr.name); +} + +static ssize_t ibtrs_clt_reconnect_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + struct ibtrs_clt_sess *sess; + int ret; + + sess = container_of(kobj, struct ibtrs_clt_sess, kobj); + if (!sysfs_streq(buf, "1")) { + ibtrs_err(sess, "%s: unknown value: '%s'\n", + attr->attr.name, buf); + return -EINVAL; + } + ret = ibtrs_clt_reconnect_from_sysfs(sess); + if (unlikely(ret)) + return ret; + + return count; +} + +static struct kobj_attribute ibtrs_clt_reconnect_attr = + __ATTR(reconnect, 0644, ibtrs_clt_reconnect_show, + ibtrs_clt_reconnect_store); + +static ssize_t ibtrs_clt_disconnect_show(struct kobject *kobj, + struct kobj_attribute *attr, + char *page) +{ + return scnprintf(page, PAGE_SIZE, "Usage: echo 1 > %s\n", + attr->attr.name); +} + +static ssize_t ibtrs_clt_disconnect_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + struct ibtrs_clt_sess *sess; + int ret; + + sess = container_of(kobj, struct ibtrs_clt_sess, kobj); + if (!sysfs_streq(buf, "1")) { + ibtrs_err(sess, "%s: unknown value: '%s'\n", + attr->attr.name, buf); + return -EINVAL; + } + ret = ibtrs_clt_disconnect_from_sysfs(sess); + if (unlikely(ret)) + return ret; + + return count; +} + +static struct kobj_attribute ibtrs_clt_disconnect_attr = + __ATTR(disconnect, 0644, ibtrs_clt_disconnect_show, + ibtrs_clt_disconnect_store); + +static ssize_t ibtrs_clt_remove_path_show(struct kobject *kobj, + struct kobj_attribute *attr, + char *page) +{ + return scnprintf(page, PAGE_SIZE, "Usage: echo 1 > %s\n", + attr->attr.name); +} + +static ssize_t ibtrs_clt_remove_path_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + struct ibtrs_clt_sess *sess; + int ret; + + sess = container_of(kobj, struct ibtrs_clt_sess, kobj); + if (!sysfs_streq(buf, "1")) { + ibtrs_err(sess, "%s: unknown value: '%s'\n", + attr->attr.name, buf); + return -EINVAL; + } + ret = ibtrs_clt_remove_path_from_sysfs(sess, &attr->attr); + if (unlikely(ret)) + return ret; + + return count; +} + +static struct kobj_attribute ibtrs_clt_remove_path_attr = + __ATTR(remove_path, 0644, ibtrs_clt_remove_path_show, + ibtrs_clt_remove_path_store); + +static ssize_t ibtrs_clt_add_path_show(struct kobject *kobj, + struct kobj_attribute *attr, char *page) +{ + return scnprintf(page, PAGE_SIZE, "Usage: echo" + " [,] > %s\n\n" + "*addr ::= [ ip: | gid: ]\n", + attr->attr.name); +} + +static ssize_t ibtrs_clt_add_path_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + struct sockaddr_storage srcaddr, dstaddr; + struct ibtrs_addr addr = { + .src = (struct sockaddr *)&srcaddr, + .dst = (struct sockaddr *)&dstaddr + }; + struct ibtrs_clt *clt; + const char *nl; + size_t len; + int err; + + clt = container_of(kobj, struct ibtrs_clt, kobj); + + nl = strchr(buf, '\n'); + if (nl) + len = nl - buf; + else + len = count; + err = ibtrs_addr_to_sockaddr(buf, len, clt->port, &addr); + if (unlikely(err)) + return -EINVAL; + + err = ibtrs_clt_create_path_from_sysfs(clt, &addr); + if (unlikely(err)) + return err; + + return count; +} + +static struct kobj_attribute ibtrs_clt_add_path_attr = + __ATTR(add_path, 0644, ibtrs_clt_add_path_show, + ibtrs_clt_add_path_store); + +STAT_ATTR(struct ibtrs_clt_sess, cpu_migration, + ibtrs_clt_stats_migration_cnt_to_str, + ibtrs_clt_reset_cpu_migr_stats); + +STAT_ATTR(struct ibtrs_clt_sess, sg_entries, + ibtrs_clt_stats_sg_list_distr_to_str, + ibtrs_clt_reset_sg_list_distr_stats); + +STAT_ATTR(struct ibtrs_clt_sess, reconnects, + ibtrs_clt_stats_reconnects_to_str, + ibtrs_clt_reset_reconnects_stat); + +STAT_ATTR(struct ibtrs_clt_sess, rdma_lat, + ibtrs_clt_stats_rdma_lat_distr_to_str, + ibtrs_clt_reset_rdma_lat_distr_stats); + +STAT_ATTR(struct ibtrs_clt_sess, wc_completion, + ibtrs_clt_stats_wc_completion_to_str, + ibtrs_clt_reset_wc_comp_stats); + +STAT_ATTR(struct ibtrs_clt_sess, rdma, + ibtrs_clt_stats_rdma_to_str, + ibtrs_clt_reset_rdma_stats); + +STAT_ATTR(struct ibtrs_clt_sess, reset_all, + ibtrs_clt_reset_all_help, + ibtrs_clt_reset_all_stats); + +static struct attribute *ibtrs_clt_stats_attrs[] = { + &sg_entries_attr.attr, + &cpu_migration_attr.attr, + &reconnects_attr.attr, + &rdma_lat_attr.attr, + &wc_completion_attr.attr, + &rdma_attr.attr, + &reset_all_attr.attr, + NULL, +}; + +static struct attribute_group ibtrs_clt_stats_attr_group = { + .attrs = ibtrs_clt_stats_attrs, +}; + +static int ibtrs_clt_create_stats_files(struct kobject *kobj, + struct kobject *kobj_stats) +{ + int ret; + + ret = kobject_init_and_add(kobj_stats, &ktype, kobj, "stats"); + if (ret) { + pr_err("Failed to init and add stats kobject, err: %d\n", + ret); + return ret; + } + + ret = sysfs_create_group(kobj_stats, &ibtrs_clt_stats_attr_group); + if (ret) { + pr_err("failed to create stats sysfs group, err: %d\n", + ret); + goto err; + } + + return 0; + +err: + kobject_del(kobj_stats); + kobject_put(kobj_stats); + + return ret; +} + +static struct attribute *ibtrs_clt_sess_attrs[] = { + &ibtrs_clt_state_attr.attr, + &ibtrs_clt_reconnect_attr.attr, + &ibtrs_clt_disconnect_attr.attr, + &ibtrs_clt_remove_path_attr.attr, + NULL, +}; + +static struct attribute_group ibtrs_clt_sess_attr_group = { + .attrs = ibtrs_clt_sess_attrs, +}; + +int ibtrs_clt_create_sess_files(struct ibtrs_clt_sess *sess) +{ + struct ibtrs_clt *clt = sess->clt; + char str[MAXHOSTNAMELEN]; + int err; + + sockaddr_to_str((struct sockaddr *)&sess->s.dst_addr, str, sizeof(str)); + + err = kobject_init_and_add(&sess->kobj, &ktype, &clt->kobj_paths, + "%s", str); + if (unlikely(err)) { + pr_err("kobject_init_and_add: %d\n", err); + return err; + } + err = sysfs_create_group(&sess->kobj, &ibtrs_clt_sess_attr_group); + if (unlikely(err)) { + pr_err("sysfs_create_group(): %d\n", err); + goto put_kobj; + } + err = ibtrs_clt_create_stats_files(&sess->kobj, &sess->kobj_stats); + if (unlikely(err)) + goto put_kobj; + + return 0; + +put_kobj: + kobject_del(&sess->kobj); + kobject_put(&sess->kobj); + + return err; +} + +static void ibtrs_sysfs_remove_file_self(struct kobject *kobj, + const struct attribute *attr) +{ + struct device_attribute dattr = { + .attr.name = attr->name + }; + struct device *device; + + /* + * Unfortunately original sysfs_remove_file_self() is not exported, + * so consider this as a hack to call self removal of a sysfs entry + * just using another "door". + */ + + device = container_of(kobj, typeof(*device), kobj); + device_remove_file_self(device, &dattr); +} + +void ibtrs_clt_destroy_sess_files(struct ibtrs_clt_sess *sess, + const struct attribute *sysfs_self) +{ + if (sess->kobj.state_in_sysfs) { + kobject_del(&sess->kobj_stats); + kobject_put(&sess->kobj_stats); + if (sysfs_self) + /* To avoid deadlock firstly commit suicide */ + ibtrs_sysfs_remove_file_self(&sess->kobj, sysfs_self); + kobject_del(&sess->kobj); + kobject_put(&sess->kobj); + } +} + +static struct attribute *ibtrs_clt_attrs[] = { + &ibtrs_clt_max_reconnect_attempts_attr.attr, + &ibtrs_clt_mp_policy_attr.attr, + &ibtrs_clt_add_path_attr.attr, + NULL, +}; + +static struct attribute_group ibtrs_clt_attr_group = { + .attrs = ibtrs_clt_attrs, +}; + +int ibtrs_clt_create_sysfs_root_folders(struct ibtrs_clt *clt) +{ + int err; + + err = kobject_init_and_add(&clt->kobj, &ktype, ibtrs_kobj, + "%s", clt->sessname); + if (unlikely(err)) { + pr_err("kobject_init_and_add(): %d\n", err); + return err; + } + err = kobject_init_and_add(&clt->kobj_paths, &ktype, + &clt->kobj, "paths"); + if (unlikely(err)) { + pr_err("kobject_init_and_add(): %d\n", err); + goto put_kobj; + } + + return 0; + +put_kobj: + kobject_del(&clt->kobj); + kobject_put(&clt->kobj); + + return err; +} + +int ibtrs_clt_create_sysfs_root_files(struct ibtrs_clt *clt) +{ + return sysfs_create_group(&clt->kobj, &ibtrs_clt_attr_group); +} + +void ibtrs_clt_destroy_sysfs_root_folders(struct ibtrs_clt *clt) +{ + if (clt->kobj_paths.state_in_sysfs) { + kobject_del(&clt->kobj_paths); + kobject_put(&clt->kobj_paths); + } + if (clt->kobj.state_in_sysfs) { + kobject_del(&clt->kobj); + kobject_put(&clt->kobj); + } +} + +void ibtrs_clt_destroy_sysfs_root_files(struct ibtrs_clt *clt) +{ + sysfs_remove_group(&clt->kobj, &ibtrs_clt_attr_group); +} + +int ibtrs_clt_create_sysfs_module_files(void) +{ + ibtrs_kobj = kobject_create_and_add(KBUILD_MODNAME, kernel_kobj); + if (unlikely(!ibtrs_kobj)) + return -ENOMEM; + + return 0; +} + +void ibtrs_clt_destroy_sysfs_module_files(void) +{ + kobject_del(ibtrs_kobj); + kobject_put(ibtrs_kobj); +}