hc
2024-09-20 cf4ce59b3b70238352c7f1729f0f7223214828ad
kernel/net/smc/smc_diag.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Shared Memory Communications over RDMA (SMC-R) and RoCE
34 *
....@@ -20,6 +21,15 @@
2021
2122 #include "smc.h"
2223 #include "smc_core.h"
24
+
25
+struct smc_diag_dump_ctx {
26
+ int pos[2];
27
+};
28
+
29
+static struct smc_diag_dump_ctx *smc_dump_context(struct netlink_callback *cb)
30
+{
31
+ return (struct smc_diag_dump_ctx *)cb->ctx;
32
+}
2333
2434 static void smc_gid_be16_convert(__u8 *buf, u8 *gid_raw)
2535 {
....@@ -192,13 +202,15 @@
192202 }
193203
194204 static int smc_diag_dump_proto(struct proto *prot, struct sk_buff *skb,
195
- struct netlink_callback *cb)
205
+ struct netlink_callback *cb, int p_type)
196206 {
207
+ struct smc_diag_dump_ctx *cb_ctx = smc_dump_context(cb);
197208 struct net *net = sock_net(skb->sk);
209
+ int snum = cb_ctx->pos[p_type];
198210 struct nlattr *bc = NULL;
199211 struct hlist_head *head;
212
+ int rc = 0, num = 0;
200213 struct sock *sk;
201
- int rc = 0;
202214
203215 read_lock(&prot->h.smc_hash->lock);
204216 head = &prot->h.smc_hash->ht;
....@@ -208,13 +220,18 @@
208220 sk_for_each(sk, head) {
209221 if (!net_eq(sock_net(sk), net))
210222 continue;
223
+ if (num < snum)
224
+ goto next;
211225 rc = __smc_diag_dump(sk, skb, cb, nlmsg_data(cb->nlh), bc);
212
- if (rc)
213
- break;
226
+ if (rc < 0)
227
+ goto out;
228
+next:
229
+ num++;
214230 }
215231
216232 out:
217233 read_unlock(&prot->h.smc_hash->lock);
234
+ cb_ctx->pos[p_type] = num;
218235 return rc;
219236 }
220237
....@@ -222,10 +239,10 @@
222239 {
223240 int rc = 0;
224241
225
- rc = smc_diag_dump_proto(&smc_proto, skb, cb);
242
+ rc = smc_diag_dump_proto(&smc_proto, skb, cb, SMCPROTO_SMC);
226243 if (!rc)
227
- rc = smc_diag_dump_proto(&smc_proto6, skb, cb);
228
- return rc;
244
+ smc_diag_dump_proto(&smc_proto6, skb, cb, SMCPROTO_SMC6);
245
+ return skb->len;
229246 }
230247
231248 static int smc_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)