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) && |
David Howells | f6cbb36 | 2020-04-24 15:10:00 +0100 | [diff] [blame] | 160 | !afs_is_probing_server(server)) { |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 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 | |
David Howells | 69cf397 | 2020-04-24 11:21:14 +0100 | [diff] [blame] | 172 | if (!test_and_set_bit(AFS_SERVER_FL_HAVE_EPOCH, &server->flags)) { |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 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 | dde9f09 | 2020-03-13 13:46:08 +0000 | [diff] [blame] | 247 | * Abort a service call from within an action function. |
| 248 | */ |
| 249 | static void afs_abort_service_call(struct afs_call *call, u32 abort_code, int error, |
| 250 | const char *why) |
| 251 | { |
| 252 | rxrpc_kernel_abort_call(call->net->socket, call->rxcall, |
| 253 | abort_code, error, why); |
| 254 | afs_set_call_complete(call, error, 0); |
| 255 | } |
| 256 | |
| 257 | /* |
David Howells | c435ee3 | 2017-11-02 15:27:49 +0000 | [diff] [blame] | 258 | * The server supplied a list of callbacks that it wanted to break. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 260 | static void SRXAFSCB_CallBack(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 262 | struct afs_call *call = container_of(work, struct afs_call, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 264 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
David Howells | 428edad | 2018-05-12 00:28:58 +0100 | [diff] [blame] | 266 | /* We need to break the callbacks before sending the reply as the |
| 267 | * server holds up change visibility till it receives our reply so as |
| 268 | * to maintain cache coherency. |
| 269 | */ |
David Howells | 4521819 | 2019-06-20 18:12:17 +0100 | [diff] [blame] | 270 | if (call->server) { |
David Howells | 977e5f8 | 2020-04-17 17:31:26 +0100 | [diff] [blame] | 271 | trace_afs_server(call->server, |
| 272 | atomic_read(&call->server->ref), |
| 273 | atomic_read(&call->server->active), |
David Howells | 4521819 | 2019-06-20 18:12:17 +0100 | [diff] [blame] | 274 | afs_server_trace_callback); |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 275 | afs_break_callbacks(call->server, call->count, call->request); |
David Howells | 4521819 | 2019-06-20 18:12:17 +0100 | [diff] [blame] | 276 | } |
David Howells | 428edad | 2018-05-12 00:28:58 +0100 | [diff] [blame] | 277 | |
| 278 | afs_send_empty_reply(call); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 279 | afs_put_call(call); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 281 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 284 | * deliver request data to a CB.CallBack call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 286 | static int afs_deliver_cb_callback(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 288 | struct afs_callback_break *cb; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 289 | __be32 *bp; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 290 | int ret, loop; |
| 291 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 292 | _enter("{%u}", call->unmarshall); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 293 | |
| 294 | switch (call->unmarshall) { |
| 295 | case 0: |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 296 | afs_extract_to_tmp(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 297 | call->unmarshall++; |
| 298 | |
| 299 | /* extract the FID array and its count in two steps */ |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 300 | /* fall through */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 301 | case 1: |
| 302 | _debug("extract FID count"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 303 | ret = afs_extract_data(call, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 304 | if (ret < 0) |
| 305 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 306 | |
| 307 | call->count = ntohl(call->tmp); |
| 308 | _debug("FID count: %u", call->count); |
| 309 | if (call->count > AFSCBMAX) |
David Howells | 7126ead | 2020-04-08 16:49:08 +0100 | [diff] [blame^] | 310 | return afs_protocol_error(call, afs_eproto_cb_fid_count); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 311 | |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 312 | call->buffer = kmalloc(array3_size(call->count, 3, 4), |
| 313 | GFP_KERNEL); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 314 | if (!call->buffer) |
| 315 | return -ENOMEM; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 316 | afs_extract_to_buf(call, call->count * 3 * 4); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 317 | call->unmarshall++; |
| 318 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 319 | /* Fall through */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 320 | case 2: |
| 321 | _debug("extract FID array"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 322 | ret = afs_extract_data(call, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 323 | if (ret < 0) |
| 324 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 325 | |
| 326 | _debug("unmarshall FID array"); |
| 327 | call->request = kcalloc(call->count, |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 328 | sizeof(struct afs_callback_break), |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 329 | GFP_KERNEL); |
| 330 | if (!call->request) |
| 331 | return -ENOMEM; |
| 332 | |
| 333 | cb = call->request; |
| 334 | bp = call->buffer; |
| 335 | for (loop = call->count; loop > 0; loop--, cb++) { |
| 336 | cb->fid.vid = ntohl(*bp++); |
| 337 | cb->fid.vnode = ntohl(*bp++); |
| 338 | cb->fid.unique = ntohl(*bp++); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 339 | } |
| 340 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 341 | afs_extract_to_tmp(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 342 | call->unmarshall++; |
| 343 | |
| 344 | /* extract the callback array and its count in two steps */ |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 345 | /* fall through */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 346 | case 3: |
| 347 | _debug("extract CB count"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 348 | ret = afs_extract_data(call, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 349 | if (ret < 0) |
| 350 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 351 | |
Marc Dionne | bcd8927 | 2017-03-16 16:27:44 +0000 | [diff] [blame] | 352 | call->count2 = ntohl(call->tmp); |
| 353 | _debug("CB count: %u", call->count2); |
| 354 | if (call->count2 != call->count && call->count2 != 0) |
David Howells | 7126ead | 2020-04-08 16:49:08 +0100 | [diff] [blame^] | 355 | return afs_protocol_error(call, afs_eproto_cb_count); |
David Howells | fc27612 | 2019-11-21 09:12:17 +0000 | [diff] [blame] | 356 | call->iter = &call->def_iter; |
| 357 | iov_iter_discard(&call->def_iter, READ, call->count2 * 3 * 4); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 358 | call->unmarshall++; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 359 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 360 | /* Fall through */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 361 | case 4: |
David Howells | 06aeb29 | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 362 | _debug("extract discard %zu/%u", |
David Howells | fc27612 | 2019-11-21 09:12:17 +0000 | [diff] [blame] | 363 | iov_iter_count(call->iter), call->count2 * 3 * 4); |
David Howells | 06aeb29 | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 364 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 365 | ret = afs_extract_data(call, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 366 | if (ret < 0) |
| 367 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 368 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 369 | call->unmarshall++; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 370 | case 5: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | break; |
| 372 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 374 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 375 | return afs_io_error(call, afs_io_error_cm_reply); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 377 | /* we'll need the file server record as that tells us which set of |
| 378 | * vnodes to operate upon */ |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 379 | return afs_find_cm_server_by_peer(call); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 380 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 383 | * allow the fileserver to request callback state (re-)initialisation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 385 | static void SRXAFSCB_InitCallBackState(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 387 | struct afs_call *call = container_of(work, struct afs_call, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 389 | _enter("{%p}", call->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 391 | if (call->server) |
| 392 | afs_init_callback_state(call->server); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 393 | afs_send_empty_reply(call); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 394 | afs_put_call(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 395 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 396 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 399 | * deliver request data to a CB.InitCallBackState call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 401 | 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] | 402 | { |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 403 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 405 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 407 | afs_extract_discard(call, 0); |
| 408 | ret = afs_extract_data(call, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 409 | if (ret < 0) |
| 410 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 412 | /* we'll need the file server record as that tells us which set of |
| 413 | * vnodes to operate upon */ |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 414 | return afs_find_cm_server_by_peer(call); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 415 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | /* |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 418 | * deliver request data to a CB.InitCallBackState3 call |
| 419 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 420 | 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] | 421 | { |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 422 | struct afs_uuid *r; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 423 | unsigned loop; |
| 424 | __be32 *b; |
| 425 | int ret; |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 426 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 427 | _enter(""); |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 428 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 429 | _enter("{%u}", call->unmarshall); |
| 430 | |
| 431 | switch (call->unmarshall) { |
| 432 | case 0: |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 433 | call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 434 | if (!call->buffer) |
| 435 | return -ENOMEM; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 436 | afs_extract_to_buf(call, 11 * sizeof(__be32)); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 437 | call->unmarshall++; |
| 438 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 439 | /* Fall through */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 440 | case 1: |
| 441 | _debug("extract UUID"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 442 | ret = afs_extract_data(call, false); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 443 | switch (ret) { |
| 444 | case 0: break; |
| 445 | case -EAGAIN: return 0; |
| 446 | default: return ret; |
| 447 | } |
| 448 | |
| 449 | _debug("unmarshall UUID"); |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 450 | call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 451 | if (!call->request) |
| 452 | return -ENOMEM; |
| 453 | |
| 454 | b = call->buffer; |
| 455 | r = call->request; |
David Howells | ff54877 | 2017-02-10 16:34:07 +0000 | [diff] [blame] | 456 | r->time_low = b[0]; |
| 457 | r->time_mid = htons(ntohl(b[1])); |
| 458 | r->time_hi_and_version = htons(ntohl(b[2])); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 459 | r->clock_seq_hi_and_reserved = ntohl(b[3]); |
| 460 | r->clock_seq_low = ntohl(b[4]); |
| 461 | |
| 462 | for (loop = 0; loop < 6; loop++) |
| 463 | r->node[loop] = ntohl(b[loop + 5]); |
| 464 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 465 | call->unmarshall++; |
| 466 | |
| 467 | case 2: |
| 468 | break; |
| 469 | } |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 470 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 471 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 472 | return afs_io_error(call, afs_io_error_cm_reply); |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 473 | |
| 474 | /* we'll need the file server record as that tells us which set of |
| 475 | * vnodes to operate upon */ |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 476 | return afs_find_cm_server_by_uuid(call, call->request); |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 480 | * allow the fileserver to see if the cache manager is still alive |
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 | static void SRXAFSCB_Probe(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 484 | struct afs_call *call = container_of(work, struct afs_call, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 486 | _enter(""); |
| 487 | afs_send_empty_reply(call); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 488 | afs_put_call(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 489 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 490 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 493 | * deliver request data to a CB.Probe call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 495 | static int afs_deliver_cb_probe(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | { |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 497 | int ret; |
| 498 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 499 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 501 | afs_extract_discard(call, 0); |
| 502 | ret = afs_extract_data(call, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 503 | if (ret < 0) |
| 504 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 506 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 507 | return afs_io_error(call, afs_io_error_cm_reply); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 508 | return afs_find_cm_server_by_peer(call); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 509 | } |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 510 | |
| 511 | /* |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 512 | * allow the fileserver to quickly find out if the fileserver has been rebooted |
| 513 | */ |
| 514 | static void SRXAFSCB_ProbeUuid(struct work_struct *work) |
| 515 | { |
| 516 | struct afs_call *call = container_of(work, struct afs_call, work); |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 517 | struct afs_uuid *r = call->request; |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 518 | |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 519 | _enter(""); |
| 520 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 521 | if (memcmp(r, &call->net->uuid, sizeof(call->net->uuid)) == 0) |
David Howells | 2067b2b | 2019-07-30 14:38:51 +0100 | [diff] [blame] | 522 | afs_send_empty_reply(call); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 523 | else |
David Howells | dde9f09 | 2020-03-13 13:46:08 +0000 | [diff] [blame] | 524 | afs_abort_service_call(call, 1, 1, "K-1"); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 525 | |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 526 | afs_put_call(call); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 527 | _leave(""); |
| 528 | } |
| 529 | |
| 530 | /* |
| 531 | * deliver request data to a CB.ProbeUuid call |
| 532 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 533 | static int afs_deliver_cb_probe_uuid(struct afs_call *call) |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 534 | { |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 535 | struct afs_uuid *r; |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 536 | unsigned loop; |
| 537 | __be32 *b; |
| 538 | int ret; |
| 539 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 540 | _enter("{%u}", call->unmarshall); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 541 | |
| 542 | switch (call->unmarshall) { |
| 543 | case 0: |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 544 | call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 545 | if (!call->buffer) |
| 546 | return -ENOMEM; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 547 | afs_extract_to_buf(call, 11 * sizeof(__be32)); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 548 | call->unmarshall++; |
| 549 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 550 | /* Fall through */ |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 551 | case 1: |
| 552 | _debug("extract UUID"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 553 | ret = afs_extract_data(call, false); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 554 | switch (ret) { |
| 555 | case 0: break; |
| 556 | case -EAGAIN: return 0; |
| 557 | default: return ret; |
| 558 | } |
| 559 | |
| 560 | _debug("unmarshall UUID"); |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 561 | call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 562 | if (!call->request) |
| 563 | return -ENOMEM; |
| 564 | |
| 565 | b = call->buffer; |
| 566 | r = call->request; |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 567 | r->time_low = b[0]; |
| 568 | r->time_mid = htons(ntohl(b[1])); |
| 569 | r->time_hi_and_version = htons(ntohl(b[2])); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 570 | r->clock_seq_hi_and_reserved = ntohl(b[3]); |
| 571 | r->clock_seq_low = ntohl(b[4]); |
| 572 | |
| 573 | for (loop = 0; loop < 6; loop++) |
| 574 | r->node[loop] = ntohl(b[loop + 5]); |
| 575 | |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 576 | call->unmarshall++; |
| 577 | |
| 578 | case 2: |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 579 | break; |
| 580 | } |
| 581 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 582 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 583 | return afs_io_error(call, afs_io_error_cm_reply); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 584 | return afs_find_cm_server_by_uuid(call, call->request); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /* |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 588 | * allow the fileserver to ask about the cache manager's capabilities |
| 589 | */ |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 590 | static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work) |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 591 | { |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 592 | struct afs_call *call = container_of(work, struct afs_call, work); |
Florian Westphal | 35ebfc2 | 2019-05-31 18:27:03 +0200 | [diff] [blame] | 593 | int loop; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 594 | |
| 595 | struct { |
| 596 | struct /* InterfaceAddr */ { |
| 597 | __be32 nifs; |
| 598 | __be32 uuid[11]; |
| 599 | __be32 ifaddr[32]; |
| 600 | __be32 netmask[32]; |
| 601 | __be32 mtu[32]; |
| 602 | } ia; |
| 603 | struct /* Capabilities */ { |
| 604 | __be32 capcount; |
| 605 | __be32 caps[1]; |
| 606 | } cap; |
| 607 | } reply; |
| 608 | |
| 609 | _enter(""); |
| 610 | |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 611 | memset(&reply, 0, sizeof(reply)); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 612 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 613 | reply.ia.uuid[0] = call->net->uuid.time_low; |
| 614 | reply.ia.uuid[1] = htonl(ntohs(call->net->uuid.time_mid)); |
| 615 | reply.ia.uuid[2] = htonl(ntohs(call->net->uuid.time_hi_and_version)); |
| 616 | reply.ia.uuid[3] = htonl((s8) call->net->uuid.clock_seq_hi_and_reserved); |
| 617 | reply.ia.uuid[4] = htonl((s8) call->net->uuid.clock_seq_low); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 618 | for (loop = 0; loop < 6; loop++) |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 619 | reply.ia.uuid[loop + 5] = htonl((s8) call->net->uuid.node[loop]); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 620 | |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 621 | reply.cap.capcount = htonl(1); |
| 622 | reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION); |
| 623 | afs_send_simple_reply(call, &reply, sizeof(reply)); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 624 | afs_put_call(call); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 625 | _leave(""); |
| 626 | } |
| 627 | |
| 628 | /* |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 629 | * deliver request data to a CB.TellMeAboutYourself call |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 630 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 631 | 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] | 632 | { |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 633 | int ret; |
| 634 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 635 | _enter(""); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 636 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 637 | afs_extract_discard(call, 0); |
| 638 | ret = afs_extract_data(call, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 639 | if (ret < 0) |
| 640 | return ret; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 641 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 642 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 643 | return afs_io_error(call, afs_io_error_cm_reply); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 644 | return afs_find_cm_server_by_peer(call); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 645 | } |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 646 | |
| 647 | /* |
| 648 | * deliver request data to a YFS CB.CallBack call |
| 649 | */ |
| 650 | static int afs_deliver_yfs_cb_callback(struct afs_call *call) |
| 651 | { |
| 652 | struct afs_callback_break *cb; |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 653 | struct yfs_xdr_YFSFid *bp; |
| 654 | size_t size; |
| 655 | int ret, loop; |
| 656 | |
| 657 | _enter("{%u}", call->unmarshall); |
| 658 | |
| 659 | switch (call->unmarshall) { |
| 660 | case 0: |
| 661 | afs_extract_to_tmp(call); |
| 662 | call->unmarshall++; |
| 663 | |
| 664 | /* extract the FID array and its count in two steps */ |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 665 | /* Fall through */ |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 666 | case 1: |
| 667 | _debug("extract FID count"); |
| 668 | ret = afs_extract_data(call, true); |
| 669 | if (ret < 0) |
| 670 | return ret; |
| 671 | |
| 672 | call->count = ntohl(call->tmp); |
| 673 | _debug("FID count: %u", call->count); |
| 674 | if (call->count > YFSCBMAX) |
David Howells | 7126ead | 2020-04-08 16:49:08 +0100 | [diff] [blame^] | 675 | return afs_protocol_error(call, afs_eproto_cb_fid_count); |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 676 | |
| 677 | size = array_size(call->count, sizeof(struct yfs_xdr_YFSFid)); |
| 678 | call->buffer = kmalloc(size, GFP_KERNEL); |
| 679 | if (!call->buffer) |
| 680 | return -ENOMEM; |
| 681 | afs_extract_to_buf(call, size); |
| 682 | call->unmarshall++; |
| 683 | |
Gustavo A. R. Silva | e690c9e | 2019-01-10 15:52:25 -0600 | [diff] [blame] | 684 | /* Fall through */ |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 685 | case 2: |
| 686 | _debug("extract FID array"); |
| 687 | ret = afs_extract_data(call, false); |
| 688 | if (ret < 0) |
| 689 | return ret; |
| 690 | |
| 691 | _debug("unmarshall FID array"); |
| 692 | call->request = kcalloc(call->count, |
| 693 | sizeof(struct afs_callback_break), |
| 694 | GFP_KERNEL); |
| 695 | if (!call->request) |
| 696 | return -ENOMEM; |
| 697 | |
| 698 | cb = call->request; |
| 699 | bp = call->buffer; |
| 700 | for (loop = call->count; loop > 0; loop--, cb++) { |
| 701 | cb->fid.vid = xdr_to_u64(bp->volume); |
| 702 | cb->fid.vnode = xdr_to_u64(bp->vnode.lo); |
| 703 | cb->fid.vnode_hi = ntohl(bp->vnode.hi); |
| 704 | cb->fid.unique = ntohl(bp->vnode.unique); |
| 705 | bp++; |
| 706 | } |
| 707 | |
| 708 | afs_extract_to_tmp(call); |
| 709 | call->unmarshall++; |
| 710 | |
| 711 | case 3: |
| 712 | break; |
| 713 | } |
| 714 | |
| 715 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
| 716 | return afs_io_error(call, afs_io_error_cm_reply); |
| 717 | |
| 718 | /* We'll need the file server record as that tells us which set of |
| 719 | * vnodes to operate upon. |
| 720 | */ |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 721 | return afs_find_cm_server_by_peer(call); |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 722 | } |