Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 2 | /* AFS Cache Manager Service |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. |
| 5 | * Written by David Howells (dhowells@redhat.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/sched.h> |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 12 | #include <linux/ip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include "internal.h" |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 14 | #include "afs_cm.h" |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 15 | #include "protocol_yfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 17 | static int afs_deliver_cb_init_call_back_state(struct afs_call *); |
| 18 | static int afs_deliver_cb_init_call_back_state3(struct afs_call *); |
| 19 | static int afs_deliver_cb_probe(struct afs_call *); |
| 20 | static int afs_deliver_cb_callback(struct afs_call *); |
| 21 | static int afs_deliver_cb_probe_uuid(struct afs_call *); |
| 22 | static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 23 | static void afs_cm_destructor(struct afs_call *); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 24 | static void SRXAFSCB_CallBack(struct work_struct *); |
| 25 | static void SRXAFSCB_InitCallBackState(struct work_struct *); |
| 26 | static void SRXAFSCB_Probe(struct work_struct *); |
| 27 | static void SRXAFSCB_ProbeUuid(struct work_struct *); |
| 28 | static void SRXAFSCB_TellMeAboutYourself(struct work_struct *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 30 | static int afs_deliver_yfs_cb_callback(struct afs_call *); |
| 31 | |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 32 | #define CM_NAME(name) \ |
Andi Kleen | d2abfa86 | 2019-04-13 08:37:36 +0100 | [diff] [blame] | 33 | char afs_SRXCB##name##_name[] __tracepoint_string = \ |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 34 | "CB." #name |
| 35 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 36 | /* |
| 37 | * CB.CallBack operation type |
| 38 | */ |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 39 | static CM_NAME(CallBack); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 40 | static const struct afs_call_type afs_SRXCBCallBack = { |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 41 | .name = afs_SRXCBCallBack_name, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 42 | .deliver = afs_deliver_cb_callback, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 43 | .destructor = afs_cm_destructor, |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 44 | .work = SRXAFSCB_CallBack, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 47 | /* |
| 48 | * CB.InitCallBackState operation type |
| 49 | */ |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 50 | static CM_NAME(InitCallBackState); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 51 | static const struct afs_call_type afs_SRXCBInitCallBackState = { |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 52 | .name = afs_SRXCBInitCallBackState_name, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 53 | .deliver = afs_deliver_cb_init_call_back_state, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 54 | .destructor = afs_cm_destructor, |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 55 | .work = SRXAFSCB_InitCallBackState, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 58 | /* |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 59 | * CB.InitCallBackState3 operation type |
| 60 | */ |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 61 | static CM_NAME(InitCallBackState3); |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 62 | static const struct afs_call_type afs_SRXCBInitCallBackState3 = { |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 63 | .name = afs_SRXCBInitCallBackState3_name, |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 64 | .deliver = afs_deliver_cb_init_call_back_state3, |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 65 | .destructor = afs_cm_destructor, |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 66 | .work = SRXAFSCB_InitCallBackState, |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 70 | * CB.Probe operation type |
| 71 | */ |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 72 | static CM_NAME(Probe); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 73 | static const struct afs_call_type afs_SRXCBProbe = { |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 74 | .name = afs_SRXCBProbe_name, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 75 | .deliver = afs_deliver_cb_probe, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 76 | .destructor = afs_cm_destructor, |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 77 | .work = SRXAFSCB_Probe, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 78 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | /* |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 81 | * CB.ProbeUuid operation type |
| 82 | */ |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 83 | static CM_NAME(ProbeUuid); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 84 | static const struct afs_call_type afs_SRXCBProbeUuid = { |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 85 | .name = afs_SRXCBProbeUuid_name, |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 86 | .deliver = afs_deliver_cb_probe_uuid, |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 87 | .destructor = afs_cm_destructor, |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 88 | .work = SRXAFSCB_ProbeUuid, |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | /* |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 92 | * CB.TellMeAboutYourself operation type |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 93 | */ |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 94 | static CM_NAME(TellMeAboutYourself); |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 95 | static const struct afs_call_type afs_SRXCBTellMeAboutYourself = { |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 96 | .name = afs_SRXCBTellMeAboutYourself_name, |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 97 | .deliver = afs_deliver_cb_tell_me_about_yourself, |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 98 | .destructor = afs_cm_destructor, |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 99 | .work = SRXAFSCB_TellMeAboutYourself, |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | /* |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 103 | * YFS CB.CallBack operation type |
| 104 | */ |
| 105 | static CM_NAME(YFS_CallBack); |
| 106 | static const struct afs_call_type afs_SRXYFSCB_CallBack = { |
| 107 | .name = afs_SRXCBYFS_CallBack_name, |
| 108 | .deliver = afs_deliver_yfs_cb_callback, |
| 109 | .destructor = afs_cm_destructor, |
| 110 | .work = SRXAFSCB_CallBack, |
| 111 | }; |
| 112 | |
| 113 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 114 | * route an incoming cache manager call |
| 115 | * - return T if supported, F if not |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 117 | bool afs_cm_incoming_call(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 119 | _enter("{%u, CB.OP %u}", call->service_id, call->operation_ID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 121 | call->epoch = rxrpc_kernel_get_epoch(call->net->socket, call->rxcall); |
| 122 | |
David Howells | 50a2c95 | 2016-10-13 08:27:10 +0100 | [diff] [blame] | 123 | switch (call->operation_ID) { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 124 | case CBCallBack: |
| 125 | call->type = &afs_SRXCBCallBack; |
| 126 | return true; |
| 127 | case CBInitCallBackState: |
| 128 | call->type = &afs_SRXCBInitCallBackState; |
| 129 | return true; |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 130 | case CBInitCallBackState3: |
| 131 | call->type = &afs_SRXCBInitCallBackState3; |
| 132 | return true; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 133 | case CBProbe: |
| 134 | call->type = &afs_SRXCBProbe; |
| 135 | return true; |
David Howells | f4b3526 | 2017-11-02 15:27:48 +0000 | [diff] [blame] | 136 | case CBProbeUuid: |
| 137 | call->type = &afs_SRXCBProbeUuid; |
| 138 | return true; |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 139 | case CBTellMeAboutYourself: |
| 140 | call->type = &afs_SRXCBTellMeAboutYourself; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 141 | return true; |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 142 | case YFSCBCallBack: |
| 143 | if (call->service_id != YFS_CM_SERVICE) |
| 144 | return false; |
| 145 | call->type = &afs_SRXYFSCB_CallBack; |
| 146 | return true; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 147 | default: |
| 148 | return false; |
| 149 | } |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 150 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | /* |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 153 | * Record a probe to the cache manager from a server. |
| 154 | */ |
| 155 | static int afs_record_cm_probe(struct afs_call *call, struct afs_server *server) |
| 156 | { |
| 157 | _enter(""); |
| 158 | |
| 159 | if (test_bit(AFS_SERVER_FL_HAVE_EPOCH, &server->flags) && |
| 160 | !test_bit(AFS_SERVER_FL_PROBING, &server->flags)) { |
| 161 | if (server->cm_epoch == call->epoch) |
| 162 | return 0; |
| 163 | |
| 164 | if (!server->probe.said_rebooted) { |
| 165 | pr_notice("kAFS: FS rebooted %pU\n", &server->uuid); |
| 166 | server->probe.said_rebooted = true; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | spin_lock(&server->probe_lock); |
| 171 | |
| 172 | if (!test_bit(AFS_SERVER_FL_HAVE_EPOCH, &server->flags)) { |
| 173 | server->cm_epoch = call->epoch; |
| 174 | server->probe.cm_epoch = call->epoch; |
| 175 | goto out; |
| 176 | } |
| 177 | |
| 178 | if (server->probe.cm_probed && |
| 179 | call->epoch != server->probe.cm_epoch && |
| 180 | !server->probe.said_inconsistent) { |
| 181 | pr_notice("kAFS: FS endpoints inconsistent %pU\n", |
| 182 | &server->uuid); |
| 183 | server->probe.said_inconsistent = true; |
| 184 | } |
| 185 | |
| 186 | if (!server->probe.cm_probed || call->epoch == server->cm_epoch) |
| 187 | server->probe.cm_epoch = server->cm_epoch; |
| 188 | |
| 189 | out: |
| 190 | server->probe.cm_probed = true; |
| 191 | spin_unlock(&server->probe_lock); |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | /* |
| 196 | * Find the server record by peer address and record a probe to the cache |
| 197 | * manager from a server. |
| 198 | */ |
| 199 | static int afs_find_cm_server_by_peer(struct afs_call *call) |
| 200 | { |
| 201 | struct sockaddr_rxrpc srx; |
| 202 | struct afs_server *server; |
| 203 | |
| 204 | rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx); |
| 205 | |
| 206 | server = afs_find_server(call->net, &srx); |
| 207 | if (!server) { |
| 208 | trace_afs_cm_no_server(call, &srx); |
| 209 | return 0; |
| 210 | } |
| 211 | |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 212 | call->server = server; |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 213 | return afs_record_cm_probe(call, server); |
| 214 | } |
| 215 | |
| 216 | /* |
| 217 | * Find the server record by server UUID and record a probe to the cache |
| 218 | * manager from a server. |
| 219 | */ |
| 220 | static int afs_find_cm_server_by_uuid(struct afs_call *call, |
| 221 | struct afs_uuid *uuid) |
| 222 | { |
| 223 | struct afs_server *server; |
| 224 | |
| 225 | rcu_read_lock(); |
| 226 | server = afs_find_server_by_uuid(call->net, call->request); |
| 227 | rcu_read_unlock(); |
| 228 | if (!server) { |
| 229 | trace_afs_cm_no_server_u(call, call->request); |
| 230 | return 0; |
| 231 | } |
| 232 | |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 233 | call->server = server; |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 234 | return afs_record_cm_probe(call, server); |
| 235 | } |
| 236 | |
| 237 | /* |
David Howells | 428edad | 2018-05-12 00:28:58 +0100 | [diff] [blame] | 238 | * Clean up a cache manager call. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 240 | static void afs_cm_destructor(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 242 | kfree(call->buffer); |
| 243 | call->buffer = NULL; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 244 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | /* |
David Howells | c435ee3 | 2017-11-02 15:27:49 +0000 | [diff] [blame] | 247 | * The server supplied a list of callbacks that it wanted to break. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 249 | static void SRXAFSCB_CallBack(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 251 | struct afs_call *call = container_of(work, struct afs_call, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 253 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
David Howells | 428edad | 2018-05-12 00:28:58 +0100 | [diff] [blame] | 255 | /* We need to break the callbacks before sending the reply as the |
| 256 | * server holds up change visibility till it receives our reply so as |
| 257 | * to maintain cache coherency. |
| 258 | */ |
David Howells | 4521819 | 2019-06-20 18:12:17 +0100 | [diff] [blame] | 259 | if (call->server) { |
| 260 | trace_afs_server(call->server, atomic_read(&call->server->usage), |
| 261 | afs_server_trace_callback); |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 262 | afs_break_callbacks(call->server, call->count, call->request); |
David Howells | 4521819 | 2019-06-20 18:12:17 +0100 | [diff] [blame] | 263 | } |
David Howells | 428edad | 2018-05-12 00:28:58 +0100 | [diff] [blame] | 264 | |
| 265 | afs_send_empty_reply(call); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 266 | afs_put_call(call); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 268 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 271 | * deliver request data to a CB.CallBack call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 273 | static int afs_deliver_cb_callback(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | { |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 275 | struct afs_callback_break *cb; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 276 | __be32 *bp; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 277 | int ret, loop; |
| 278 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 279 | _enter("{%u}", call->unmarshall); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 280 | |
| 281 | switch (call->unmarshall) { |
| 282 | case 0: |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 283 | afs_extract_to_tmp(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 284 | call->unmarshall++; |
| 285 | |
| 286 | /* extract the FID array and its count in two steps */ |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 287 | /* fall through */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 288 | case 1: |
| 289 | _debug("extract FID count"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 290 | ret = afs_extract_data(call, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 291 | if (ret < 0) |
| 292 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 293 | |
| 294 | call->count = ntohl(call->tmp); |
| 295 | _debug("FID count: %u", call->count); |
| 296 | if (call->count > AFSCBMAX) |
David Howells | 160cb95 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 297 | return afs_protocol_error(call, -EBADMSG, |
| 298 | afs_eproto_cb_fid_count); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 299 | |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 300 | call->buffer = kmalloc(array3_size(call->count, 3, 4), |
| 301 | GFP_KERNEL); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 302 | if (!call->buffer) |
| 303 | return -ENOMEM; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 304 | afs_extract_to_buf(call, call->count * 3 * 4); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 305 | call->unmarshall++; |
| 306 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 307 | /* Fall through */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 308 | case 2: |
| 309 | _debug("extract FID array"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 310 | ret = afs_extract_data(call, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 311 | if (ret < 0) |
| 312 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 313 | |
| 314 | _debug("unmarshall FID array"); |
| 315 | call->request = kcalloc(call->count, |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 316 | sizeof(struct afs_callback_break), |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 317 | GFP_KERNEL); |
| 318 | if (!call->request) |
| 319 | return -ENOMEM; |
| 320 | |
| 321 | cb = call->request; |
| 322 | bp = call->buffer; |
| 323 | for (loop = call->count; loop > 0; loop--, cb++) { |
| 324 | cb->fid.vid = ntohl(*bp++); |
| 325 | cb->fid.vnode = ntohl(*bp++); |
| 326 | cb->fid.unique = ntohl(*bp++); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 327 | } |
| 328 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 329 | afs_extract_to_tmp(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 330 | call->unmarshall++; |
| 331 | |
| 332 | /* extract the callback array and its count in two steps */ |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 333 | /* fall through */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 334 | case 3: |
| 335 | _debug("extract CB count"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 336 | ret = afs_extract_data(call, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 337 | if (ret < 0) |
| 338 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 339 | |
Marc Dionne | bcd8927 | 2017-03-16 16:27:44 +0000 | [diff] [blame] | 340 | call->count2 = ntohl(call->tmp); |
| 341 | _debug("CB count: %u", call->count2); |
| 342 | if (call->count2 != call->count && call->count2 != 0) |
David Howells | 160cb95 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 343 | return afs_protocol_error(call, -EBADMSG, |
| 344 | afs_eproto_cb_count); |
David Howells | 06aeb29 | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 345 | call->_iter = &call->iter; |
| 346 | iov_iter_discard(&call->iter, READ, call->count2 * 3 * 4); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 347 | call->unmarshall++; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 348 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 349 | /* Fall through */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 350 | case 4: |
David Howells | 06aeb29 | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 351 | _debug("extract discard %zu/%u", |
| 352 | iov_iter_count(&call->iter), call->count2 * 3 * 4); |
| 353 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 354 | ret = afs_extract_data(call, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 355 | if (ret < 0) |
| 356 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 357 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 358 | call->unmarshall++; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 359 | case 5: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | break; |
| 361 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 363 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 364 | return afs_io_error(call, afs_io_error_cm_reply); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 366 | /* we'll need the file server record as that tells us which set of |
| 367 | * vnodes to operate upon */ |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 368 | return afs_find_cm_server_by_peer(call); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 369 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 372 | * allow the fileserver to request callback state (re-)initialisation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 374 | static void SRXAFSCB_InitCallBackState(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 376 | struct afs_call *call = container_of(work, struct afs_call, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 378 | _enter("{%p}", call->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 380 | if (call->server) |
| 381 | afs_init_callback_state(call->server); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 382 | afs_send_empty_reply(call); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 383 | afs_put_call(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 384 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 385 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 388 | * deliver request data to a CB.InitCallBackState call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 390 | static int afs_deliver_cb_init_call_back_state(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 392 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 394 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 396 | afs_extract_discard(call, 0); |
| 397 | ret = afs_extract_data(call, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 398 | if (ret < 0) |
| 399 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 401 | /* we'll need the file server record as that tells us which set of |
| 402 | * vnodes to operate upon */ |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 403 | return afs_find_cm_server_by_peer(call); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 404 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | /* |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 407 | * deliver request data to a CB.InitCallBackState3 call |
| 408 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 409 | static int afs_deliver_cb_init_call_back_state3(struct afs_call *call) |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 410 | { |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 411 | struct afs_uuid *r; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 412 | unsigned loop; |
| 413 | __be32 *b; |
| 414 | int ret; |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 415 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 416 | _enter(""); |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 417 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 418 | _enter("{%u}", call->unmarshall); |
| 419 | |
| 420 | switch (call->unmarshall) { |
| 421 | case 0: |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 422 | call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 423 | if (!call->buffer) |
| 424 | return -ENOMEM; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 425 | afs_extract_to_buf(call, 11 * sizeof(__be32)); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 426 | call->unmarshall++; |
| 427 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 428 | /* Fall through */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 429 | case 1: |
| 430 | _debug("extract UUID"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 431 | ret = afs_extract_data(call, false); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 432 | switch (ret) { |
| 433 | case 0: break; |
| 434 | case -EAGAIN: return 0; |
| 435 | default: return ret; |
| 436 | } |
| 437 | |
| 438 | _debug("unmarshall UUID"); |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 439 | call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 440 | if (!call->request) |
| 441 | return -ENOMEM; |
| 442 | |
| 443 | b = call->buffer; |
| 444 | r = call->request; |
David Howells | ff54877 | 2017-02-10 16:34:07 +0000 | [diff] [blame] | 445 | r->time_low = b[0]; |
| 446 | r->time_mid = htons(ntohl(b[1])); |
| 447 | r->time_hi_and_version = htons(ntohl(b[2])); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 448 | r->clock_seq_hi_and_reserved = ntohl(b[3]); |
| 449 | r->clock_seq_low = ntohl(b[4]); |
| 450 | |
| 451 | for (loop = 0; loop < 6; loop++) |
| 452 | r->node[loop] = ntohl(b[loop + 5]); |
| 453 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 454 | call->unmarshall++; |
| 455 | |
| 456 | case 2: |
| 457 | break; |
| 458 | } |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 459 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 460 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 461 | return afs_io_error(call, afs_io_error_cm_reply); |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 462 | |
| 463 | /* we'll need the file server record as that tells us which set of |
| 464 | * vnodes to operate upon */ |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 465 | return afs_find_cm_server_by_uuid(call, call->request); |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 469 | * allow the fileserver to see if the cache manager is still alive |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 471 | static void SRXAFSCB_Probe(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 473 | struct afs_call *call = container_of(work, struct afs_call, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 475 | _enter(""); |
| 476 | afs_send_empty_reply(call); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 477 | afs_put_call(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 478 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 479 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 482 | * deliver request data to a CB.Probe call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 484 | static int afs_deliver_cb_probe(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | { |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 486 | int ret; |
| 487 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 488 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 490 | afs_extract_discard(call, 0); |
| 491 | ret = afs_extract_data(call, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 492 | if (ret < 0) |
| 493 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 495 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 496 | return afs_io_error(call, afs_io_error_cm_reply); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 497 | return afs_find_cm_server_by_peer(call); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 498 | } |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 499 | |
| 500 | /* |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 501 | * allow the fileserver to quickly find out if the fileserver has been rebooted |
| 502 | */ |
| 503 | static void SRXAFSCB_ProbeUuid(struct work_struct *work) |
| 504 | { |
| 505 | struct afs_call *call = container_of(work, struct afs_call, work); |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 506 | struct afs_uuid *r = call->request; |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 507 | |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 508 | _enter(""); |
| 509 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 510 | if (memcmp(r, &call->net->uuid, sizeof(call->net->uuid)) == 0) |
David Howells | 2067b2b | 2019-07-30 14:38:51 +0100 | [diff] [blame] | 511 | afs_send_empty_reply(call); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 512 | else |
David Howells | 2067b2b | 2019-07-30 14:38:51 +0100 | [diff] [blame] | 513 | rxrpc_kernel_abort_call(call->net->socket, call->rxcall, |
| 514 | 1, 1, "K-1"); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 515 | |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 516 | afs_put_call(call); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 517 | _leave(""); |
| 518 | } |
| 519 | |
| 520 | /* |
| 521 | * deliver request data to a CB.ProbeUuid call |
| 522 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 523 | static int afs_deliver_cb_probe_uuid(struct afs_call *call) |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 524 | { |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 525 | struct afs_uuid *r; |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 526 | unsigned loop; |
| 527 | __be32 *b; |
| 528 | int ret; |
| 529 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 530 | _enter("{%u}", call->unmarshall); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 531 | |
| 532 | switch (call->unmarshall) { |
| 533 | case 0: |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 534 | call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 535 | if (!call->buffer) |
| 536 | return -ENOMEM; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 537 | afs_extract_to_buf(call, 11 * sizeof(__be32)); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 538 | call->unmarshall++; |
| 539 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 540 | /* Fall through */ |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 541 | case 1: |
| 542 | _debug("extract UUID"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 543 | ret = afs_extract_data(call, false); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 544 | switch (ret) { |
| 545 | case 0: break; |
| 546 | case -EAGAIN: return 0; |
| 547 | default: return ret; |
| 548 | } |
| 549 | |
| 550 | _debug("unmarshall UUID"); |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 551 | call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 552 | if (!call->request) |
| 553 | return -ENOMEM; |
| 554 | |
| 555 | b = call->buffer; |
| 556 | r = call->request; |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 557 | r->time_low = b[0]; |
| 558 | r->time_mid = htons(ntohl(b[1])); |
| 559 | r->time_hi_and_version = htons(ntohl(b[2])); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 560 | r->clock_seq_hi_and_reserved = ntohl(b[3]); |
| 561 | r->clock_seq_low = ntohl(b[4]); |
| 562 | |
| 563 | for (loop = 0; loop < 6; loop++) |
| 564 | r->node[loop] = ntohl(b[loop + 5]); |
| 565 | |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 566 | call->unmarshall++; |
| 567 | |
| 568 | case 2: |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 569 | break; |
| 570 | } |
| 571 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 572 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 573 | return afs_io_error(call, afs_io_error_cm_reply); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 574 | return afs_find_cm_server_by_uuid(call, call->request); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | /* |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 578 | * allow the fileserver to ask about the cache manager's capabilities |
| 579 | */ |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 580 | static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work) |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 581 | { |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 582 | struct afs_call *call = container_of(work, struct afs_call, work); |
Florian Westphal | 35ebfc2 | 2019-05-31 18:27:03 +0200 | [diff] [blame] | 583 | int loop; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 584 | |
| 585 | struct { |
| 586 | struct /* InterfaceAddr */ { |
| 587 | __be32 nifs; |
| 588 | __be32 uuid[11]; |
| 589 | __be32 ifaddr[32]; |
| 590 | __be32 netmask[32]; |
| 591 | __be32 mtu[32]; |
| 592 | } ia; |
| 593 | struct /* Capabilities */ { |
| 594 | __be32 capcount; |
| 595 | __be32 caps[1]; |
| 596 | } cap; |
| 597 | } reply; |
| 598 | |
| 599 | _enter(""); |
| 600 | |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 601 | memset(&reply, 0, sizeof(reply)); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 602 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 603 | reply.ia.uuid[0] = call->net->uuid.time_low; |
| 604 | reply.ia.uuid[1] = htonl(ntohs(call->net->uuid.time_mid)); |
| 605 | reply.ia.uuid[2] = htonl(ntohs(call->net->uuid.time_hi_and_version)); |
| 606 | reply.ia.uuid[3] = htonl((s8) call->net->uuid.clock_seq_hi_and_reserved); |
| 607 | reply.ia.uuid[4] = htonl((s8) call->net->uuid.clock_seq_low); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 608 | for (loop = 0; loop < 6; loop++) |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 609 | reply.ia.uuid[loop + 5] = htonl((s8) call->net->uuid.node[loop]); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 610 | |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 611 | reply.cap.capcount = htonl(1); |
| 612 | reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION); |
| 613 | afs_send_simple_reply(call, &reply, sizeof(reply)); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 614 | afs_put_call(call); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 615 | _leave(""); |
| 616 | } |
| 617 | |
| 618 | /* |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 619 | * deliver request data to a CB.TellMeAboutYourself call |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 620 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 621 | static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call) |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 622 | { |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 623 | int ret; |
| 624 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 625 | _enter(""); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 626 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 627 | afs_extract_discard(call, 0); |
| 628 | ret = afs_extract_data(call, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 629 | if (ret < 0) |
| 630 | return ret; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 631 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 632 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 633 | return afs_io_error(call, afs_io_error_cm_reply); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 634 | return afs_find_cm_server_by_peer(call); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 635 | } |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 636 | |
| 637 | /* |
| 638 | * deliver request data to a YFS CB.CallBack call |
| 639 | */ |
| 640 | static int afs_deliver_yfs_cb_callback(struct afs_call *call) |
| 641 | { |
| 642 | struct afs_callback_break *cb; |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 643 | struct yfs_xdr_YFSFid *bp; |
| 644 | size_t size; |
| 645 | int ret, loop; |
| 646 | |
| 647 | _enter("{%u}", call->unmarshall); |
| 648 | |
| 649 | switch (call->unmarshall) { |
| 650 | case 0: |
| 651 | afs_extract_to_tmp(call); |
| 652 | call->unmarshall++; |
| 653 | |
| 654 | /* extract the FID array and its count in two steps */ |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 655 | /* Fall through */ |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 656 | case 1: |
| 657 | _debug("extract FID count"); |
| 658 | ret = afs_extract_data(call, true); |
| 659 | if (ret < 0) |
| 660 | return ret; |
| 661 | |
| 662 | call->count = ntohl(call->tmp); |
| 663 | _debug("FID count: %u", call->count); |
| 664 | if (call->count > YFSCBMAX) |
| 665 | return afs_protocol_error(call, -EBADMSG, |
| 666 | afs_eproto_cb_fid_count); |
| 667 | |
| 668 | size = array_size(call->count, sizeof(struct yfs_xdr_YFSFid)); |
| 669 | call->buffer = kmalloc(size, GFP_KERNEL); |
| 670 | if (!call->buffer) |
| 671 | return -ENOMEM; |
| 672 | afs_extract_to_buf(call, size); |
| 673 | call->unmarshall++; |
| 674 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 675 | /* Fall through */ |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 676 | case 2: |
| 677 | _debug("extract FID array"); |
| 678 | ret = afs_extract_data(call, false); |
| 679 | if (ret < 0) |
| 680 | return ret; |
| 681 | |
| 682 | _debug("unmarshall FID array"); |
| 683 | call->request = kcalloc(call->count, |
| 684 | sizeof(struct afs_callback_break), |
| 685 | GFP_KERNEL); |
| 686 | if (!call->request) |
| 687 | return -ENOMEM; |
| 688 | |
| 689 | cb = call->request; |
| 690 | bp = call->buffer; |
| 691 | for (loop = call->count; loop > 0; loop--, cb++) { |
| 692 | cb->fid.vid = xdr_to_u64(bp->volume); |
| 693 | cb->fid.vnode = xdr_to_u64(bp->vnode.lo); |
| 694 | cb->fid.vnode_hi = ntohl(bp->vnode.hi); |
| 695 | cb->fid.unique = ntohl(bp->vnode.unique); |
| 696 | bp++; |
| 697 | } |
| 698 | |
| 699 | afs_extract_to_tmp(call); |
| 700 | call->unmarshall++; |
| 701 | |
| 702 | case 3: |
| 703 | break; |
| 704 | } |
| 705 | |
| 706 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
| 707 | return afs_io_error(call, afs_io_error_cm_reply); |
| 708 | |
| 709 | /* We'll need the file server record as that tells us which set of |
| 710 | * vnodes to operate upon. |
| 711 | */ |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 712 | return afs_find_cm_server_by_peer(call); |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 713 | } |