Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * RDMA Transport Layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2014 - 2018 ProfitBricks GmbH. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (c) 2019 - 2020 1&1 IONOS SE. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #undef pr_fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #define pr_fmt(fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "rtrs-pri.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "rtrs-clt.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "rtrs-log.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define MIN_MAX_RECONN_ATT -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define MAX_MAX_RECONN_ATT 9999
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static void rtrs_clt_sess_release(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	struct rtrs_clt_sess *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	sess = container_of(kobj, struct rtrs_clt_sess, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	free_sess(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static struct kobj_type ktype_sess = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	.sysfs_ops = &kobj_sysfs_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	.release = rtrs_clt_sess_release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static void rtrs_clt_sess_stats_release(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct rtrs_clt_stats *stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	stats = container_of(kobj, struct rtrs_clt_stats, kobj_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	free_percpu(stats->pcpu_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	kfree(stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static struct kobj_type ktype_stats = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	.sysfs_ops = &kobj_sysfs_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	.release = rtrs_clt_sess_stats_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static ssize_t max_reconnect_attempts_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 					   struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 					   char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct rtrs_clt *clt = container_of(dev, struct rtrs_clt, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	return sprintf(page, "%d\n", rtrs_clt_get_max_reconnect_attempts(clt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static ssize_t max_reconnect_attempts_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 					    struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 					    const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 					    size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct rtrs_clt *clt  = container_of(dev, struct rtrs_clt, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	ret = kstrtoint(buf, 10, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		rtrs_err(clt, "%s: failed to convert string '%s' to int\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			  attr->attr.name, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (value > MAX_MAX_RECONN_ATT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		     value < MIN_MAX_RECONN_ATT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		rtrs_err(clt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			  "%s: invalid range (provided: '%s', accepted: min: %d, max: %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			  attr->attr.name, buf, MIN_MAX_RECONN_ATT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			  MAX_MAX_RECONN_ATT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	rtrs_clt_set_max_reconnect_attempts(clt, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static DEVICE_ATTR_RW(max_reconnect_attempts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static ssize_t mpath_policy_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 				 struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 				 char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct rtrs_clt *clt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	clt = container_of(dev, struct rtrs_clt, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	switch (clt->mp_policy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	case MP_POLICY_RR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		return sprintf(page, "round-robin (RR: %d)\n", clt->mp_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	case MP_POLICY_MIN_INFLIGHT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		return sprintf(page, "min-inflight (MI: %d)\n", clt->mp_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		return sprintf(page, "Unknown (%d)\n", clt->mp_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static ssize_t mpath_policy_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 				  struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 				  const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 				  size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct rtrs_clt *clt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	clt = container_of(dev, struct rtrs_clt, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	ret = kstrtoint(buf, 10, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (!ret && (value == MP_POLICY_RR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		     value == MP_POLICY_MIN_INFLIGHT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		clt->mp_policy = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (!strncasecmp(buf, "round-robin", 11) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	    !strncasecmp(buf, "rr", 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		clt->mp_policy = MP_POLICY_RR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	else if (!strncasecmp(buf, "min-inflight", 12) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		 !strncasecmp(buf, "mi", 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		clt->mp_policy = MP_POLICY_MIN_INFLIGHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static DEVICE_ATTR_RW(mpath_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static ssize_t add_path_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			     struct device_attribute *attr, char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return scnprintf(page, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			 "Usage: echo [<source addr>@]<destination addr> > %s\n\n*addr ::= [ ip:<ipv4|ipv6> | gid:<gid> ]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			 attr->attr.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static ssize_t add_path_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			      struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			      const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct sockaddr_storage srcaddr, dstaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct rtrs_addr addr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		.src = &srcaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		.dst = &dstaddr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct rtrs_clt *clt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	const char *nl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	clt = container_of(dev, struct rtrs_clt, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	nl = strchr(buf, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (nl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		len = nl - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		len = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	err = rtrs_addr_to_sockaddr(buf, len, clt->port, &addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	err = rtrs_clt_create_path_from_sysfs(clt, &addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static DEVICE_ATTR_RW(add_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static ssize_t rtrs_clt_state_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 				    struct kobj_attribute *attr, char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	struct rtrs_clt_sess *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	sess = container_of(kobj, struct rtrs_clt_sess, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (sess->state == RTRS_CLT_CONNECTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		return sprintf(page, "connected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	return sprintf(page, "disconnected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static struct kobj_attribute rtrs_clt_state_attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	__ATTR(state, 0444, rtrs_clt_state_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static ssize_t rtrs_clt_reconnect_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 					struct kobj_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 					char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	return scnprintf(page, PAGE_SIZE, "Usage: echo 1 > %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			 attr->attr.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static ssize_t rtrs_clt_reconnect_store(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 					 struct kobj_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 					 const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	struct rtrs_clt_sess *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	sess = container_of(kobj, struct rtrs_clt_sess, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (!sysfs_streq(buf, "1")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		rtrs_err(sess->clt, "%s: unknown value: '%s'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			  attr->attr.name, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	ret = rtrs_clt_reconnect_from_sysfs(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static struct kobj_attribute rtrs_clt_reconnect_attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	__ATTR(reconnect, 0644, rtrs_clt_reconnect_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	       rtrs_clt_reconnect_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static ssize_t rtrs_clt_disconnect_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 					 struct kobj_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 					 char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	return scnprintf(page, PAGE_SIZE, "Usage: echo 1 > %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			 attr->attr.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static ssize_t rtrs_clt_disconnect_store(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 					  struct kobj_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 					  const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	struct rtrs_clt_sess *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	sess = container_of(kobj, struct rtrs_clt_sess, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (!sysfs_streq(buf, "1")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		rtrs_err(sess->clt, "%s: unknown value: '%s'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			  attr->attr.name, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	ret = rtrs_clt_disconnect_from_sysfs(sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static struct kobj_attribute rtrs_clt_disconnect_attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	__ATTR(disconnect, 0644, rtrs_clt_disconnect_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	       rtrs_clt_disconnect_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static ssize_t rtrs_clt_remove_path_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 					  struct kobj_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 					  char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	return scnprintf(page, PAGE_SIZE, "Usage: echo 1 > %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			 attr->attr.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static ssize_t rtrs_clt_remove_path_store(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 					   struct kobj_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 					   const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	struct rtrs_clt_sess *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	sess = container_of(kobj, struct rtrs_clt_sess, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	if (!sysfs_streq(buf, "1")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		rtrs_err(sess->clt, "%s: unknown value: '%s'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			  attr->attr.name, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	ret = rtrs_clt_remove_path_from_sysfs(sess, &attr->attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static struct kobj_attribute rtrs_clt_remove_path_attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	__ATTR(remove_path, 0644, rtrs_clt_remove_path_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	       rtrs_clt_remove_path_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) STAT_ATTR(struct rtrs_clt_stats, cpu_migration,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	  rtrs_clt_stats_migration_cnt_to_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	  rtrs_clt_reset_cpu_migr_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) STAT_ATTR(struct rtrs_clt_stats, reconnects,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	  rtrs_clt_stats_reconnects_to_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	  rtrs_clt_reset_reconnects_stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) STAT_ATTR(struct rtrs_clt_stats, rdma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	  rtrs_clt_stats_rdma_to_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	  rtrs_clt_reset_rdma_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) STAT_ATTR(struct rtrs_clt_stats, reset_all,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	  rtrs_clt_reset_all_help,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	  rtrs_clt_reset_all_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static struct attribute *rtrs_clt_stats_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	&cpu_migration_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	&reconnects_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	&rdma_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	&reset_all_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) static const struct attribute_group rtrs_clt_stats_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	.attrs = rtrs_clt_stats_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static ssize_t rtrs_clt_hca_port_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 				       struct kobj_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 				       char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	struct rtrs_clt_sess *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	sess = container_of(kobj, typeof(*sess), kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	return scnprintf(page, PAGE_SIZE, "%u\n", sess->hca_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static struct kobj_attribute rtrs_clt_hca_port_attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	__ATTR(hca_port, 0444, rtrs_clt_hca_port_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static ssize_t rtrs_clt_hca_name_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 				       struct kobj_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 				       char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	struct rtrs_clt_sess *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	sess = container_of(kobj, struct rtrs_clt_sess, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	return scnprintf(page, PAGE_SIZE, "%s\n", sess->hca_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static struct kobj_attribute rtrs_clt_hca_name_attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	__ATTR(hca_name, 0444, rtrs_clt_hca_name_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) static ssize_t rtrs_clt_src_addr_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 				       struct kobj_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 				       char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	struct rtrs_clt_sess *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	int cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	sess = container_of(kobj, struct rtrs_clt_sess, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	cnt = sockaddr_to_str((struct sockaddr *)&sess->s.src_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 			      page, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	return cnt + scnprintf(page + cnt, PAGE_SIZE - cnt, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static struct kobj_attribute rtrs_clt_src_addr_attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	__ATTR(src_addr, 0444, rtrs_clt_src_addr_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) static ssize_t rtrs_clt_dst_addr_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 				       struct kobj_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 				       char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	struct rtrs_clt_sess *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	int cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	sess = container_of(kobj, struct rtrs_clt_sess, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	cnt = sockaddr_to_str((struct sockaddr *)&sess->s.dst_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 			      page, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	return cnt + scnprintf(page + cnt, PAGE_SIZE - cnt, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) static struct kobj_attribute rtrs_clt_dst_addr_attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	__ATTR(dst_addr, 0444, rtrs_clt_dst_addr_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static struct attribute *rtrs_clt_sess_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	&rtrs_clt_hca_name_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	&rtrs_clt_hca_port_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	&rtrs_clt_src_addr_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	&rtrs_clt_dst_addr_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	&rtrs_clt_state_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	&rtrs_clt_reconnect_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	&rtrs_clt_disconnect_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	&rtrs_clt_remove_path_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) static const struct attribute_group rtrs_clt_sess_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	.attrs = rtrs_clt_sess_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) int rtrs_clt_create_sess_files(struct rtrs_clt_sess *sess)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	struct rtrs_clt *clt = sess->clt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	char str[NAME_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	int err, cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	cnt = sockaddr_to_str((struct sockaddr *)&sess->s.src_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 			      str, sizeof(str));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	cnt += scnprintf(str + cnt, sizeof(str) - cnt, "@");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	sockaddr_to_str((struct sockaddr *)&sess->s.dst_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			str + cnt, sizeof(str) - cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	err = kobject_init_and_add(&sess->kobj, &ktype_sess, clt->kobj_paths,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 				   "%s", str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		pr_err("kobject_init_and_add: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		kobject_put(&sess->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	err = sysfs_create_group(&sess->kobj, &rtrs_clt_sess_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		pr_err("sysfs_create_group(): %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		goto put_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	err = kobject_init_and_add(&sess->stats->kobj_stats, &ktype_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 				   &sess->kobj, "stats");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		pr_err("kobject_init_and_add: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		kobject_put(&sess->stats->kobj_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		goto remove_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	err = sysfs_create_group(&sess->stats->kobj_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 				 &rtrs_clt_stats_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		pr_err("failed to create stats sysfs group, err: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		goto put_kobj_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) put_kobj_stats:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	kobject_del(&sess->stats->kobj_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	kobject_put(&sess->stats->kobj_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) remove_group:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	sysfs_remove_group(&sess->kobj, &rtrs_clt_sess_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) put_kobj:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	kobject_del(&sess->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	kobject_put(&sess->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) void rtrs_clt_destroy_sess_files(struct rtrs_clt_sess *sess,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 				  const struct attribute *sysfs_self)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	kobject_del(&sess->stats->kobj_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	kobject_put(&sess->stats->kobj_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	if (sysfs_self)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		sysfs_remove_file_self(&sess->kobj, sysfs_self);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	kobject_del(&sess->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static struct attribute *rtrs_clt_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	&dev_attr_max_reconnect_attempts.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	&dev_attr_mpath_policy.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	&dev_attr_add_path.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) static const struct attribute_group rtrs_clt_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	.attrs = rtrs_clt_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) int rtrs_clt_create_sysfs_root_files(struct rtrs_clt *clt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	return sysfs_create_group(&clt->dev.kobj, &rtrs_clt_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) void rtrs_clt_destroy_sysfs_root_folders(struct rtrs_clt *clt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	if (clt->kobj_paths) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		kobject_del(clt->kobj_paths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		kobject_put(clt->kobj_paths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) void rtrs_clt_destroy_sysfs_root_files(struct rtrs_clt *clt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	sysfs_remove_group(&clt->dev.kobj, &rtrs_clt_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }