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 | 50a2c95 | 2016-10-13 08:27:10 +0100 | [diff] [blame] | 121 | switch (call->operation_ID) { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 122 | case CBCallBack: |
| 123 | call->type = &afs_SRXCBCallBack; |
| 124 | return true; |
| 125 | case CBInitCallBackState: |
| 126 | call->type = &afs_SRXCBInitCallBackState; |
| 127 | return true; |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 128 | case CBInitCallBackState3: |
| 129 | call->type = &afs_SRXCBInitCallBackState3; |
| 130 | return true; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 131 | case CBProbe: |
| 132 | call->type = &afs_SRXCBProbe; |
| 133 | return true; |
David Howells | f4b3526 | 2017-11-02 15:27:48 +0000 | [diff] [blame] | 134 | case CBProbeUuid: |
| 135 | call->type = &afs_SRXCBProbeUuid; |
| 136 | return true; |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 137 | case CBTellMeAboutYourself: |
| 138 | call->type = &afs_SRXCBTellMeAboutYourself; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 139 | return true; |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 140 | case YFSCBCallBack: |
| 141 | if (call->service_id != YFS_CM_SERVICE) |
| 142 | return false; |
| 143 | call->type = &afs_SRXYFSCB_CallBack; |
| 144 | return true; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 145 | default: |
| 146 | return false; |
| 147 | } |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 148 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | /* |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 151 | * Find the server record by peer address and record a probe to the cache |
| 152 | * manager from a server. |
| 153 | */ |
| 154 | static int afs_find_cm_server_by_peer(struct afs_call *call) |
| 155 | { |
| 156 | struct sockaddr_rxrpc srx; |
| 157 | struct afs_server *server; |
| 158 | |
| 159 | rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx); |
| 160 | |
| 161 | server = afs_find_server(call->net, &srx); |
| 162 | if (!server) { |
| 163 | trace_afs_cm_no_server(call, &srx); |
| 164 | return 0; |
| 165 | } |
| 166 | |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 167 | call->server = server; |
David Howells | 4474635 | 2020-05-27 15:52:02 +0100 | [diff] [blame] | 168 | return 0; |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /* |
| 172 | * Find the server record by server UUID and record a probe to the cache |
| 173 | * manager from a server. |
| 174 | */ |
| 175 | static int afs_find_cm_server_by_uuid(struct afs_call *call, |
| 176 | struct afs_uuid *uuid) |
| 177 | { |
| 178 | struct afs_server *server; |
| 179 | |
| 180 | rcu_read_lock(); |
| 181 | server = afs_find_server_by_uuid(call->net, call->request); |
| 182 | rcu_read_unlock(); |
| 183 | if (!server) { |
| 184 | trace_afs_cm_no_server_u(call, call->request); |
| 185 | return 0; |
| 186 | } |
| 187 | |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 188 | call->server = server; |
David Howells | 4474635 | 2020-05-27 15:52:02 +0100 | [diff] [blame] | 189 | return 0; |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* |
David Howells | 428edad | 2018-05-12 00:28:58 +0100 | [diff] [blame] | 193 | * Clean up a cache manager call. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 195 | static void afs_cm_destructor(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 197 | kfree(call->buffer); |
| 198 | call->buffer = NULL; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | /* |
David Howells | dde9f09 | 2020-03-13 13:46:08 +0000 | [diff] [blame] | 202 | * Abort a service call from within an action function. |
| 203 | */ |
| 204 | static void afs_abort_service_call(struct afs_call *call, u32 abort_code, int error, |
| 205 | const char *why) |
| 206 | { |
| 207 | rxrpc_kernel_abort_call(call->net->socket, call->rxcall, |
| 208 | abort_code, error, why); |
| 209 | afs_set_call_complete(call, error, 0); |
| 210 | } |
| 211 | |
| 212 | /* |
David Howells | c435ee3 | 2017-11-02 15:27:49 +0000 | [diff] [blame] | 213 | * The server supplied a list of callbacks that it wanted to break. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 215 | static void SRXAFSCB_CallBack(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 217 | struct afs_call *call = container_of(work, struct afs_call, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 219 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
David Howells | 428edad | 2018-05-12 00:28:58 +0100 | [diff] [blame] | 221 | /* We need to break the callbacks before sending the reply as the |
| 222 | * server holds up change visibility till it receives our reply so as |
| 223 | * to maintain cache coherency. |
| 224 | */ |
David Howells | 4521819 | 2019-06-20 18:12:17 +0100 | [diff] [blame] | 225 | if (call->server) { |
David Howells | 977e5f8 | 2020-04-17 17:31:26 +0100 | [diff] [blame] | 226 | trace_afs_server(call->server, |
| 227 | atomic_read(&call->server->ref), |
| 228 | atomic_read(&call->server->active), |
David Howells | 4521819 | 2019-06-20 18:12:17 +0100 | [diff] [blame] | 229 | afs_server_trace_callback); |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 230 | afs_break_callbacks(call->server, call->count, call->request); |
David Howells | 4521819 | 2019-06-20 18:12:17 +0100 | [diff] [blame] | 231 | } |
David Howells | 428edad | 2018-05-12 00:28:58 +0100 | [diff] [blame] | 232 | |
| 233 | afs_send_empty_reply(call); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 234 | afs_put_call(call); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 236 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 239 | * deliver request data to a CB.CallBack call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 241 | static int afs_deliver_cb_callback(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 243 | struct afs_callback_break *cb; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 244 | __be32 *bp; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 245 | int ret, loop; |
| 246 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 247 | _enter("{%u}", call->unmarshall); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 248 | |
| 249 | switch (call->unmarshall) { |
| 250 | case 0: |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 251 | afs_extract_to_tmp(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 252 | call->unmarshall++; |
| 253 | |
| 254 | /* extract the FID array and its count in two steps */ |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 255 | fallthrough; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 256 | case 1: |
| 257 | _debug("extract FID count"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 258 | ret = afs_extract_data(call, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 259 | if (ret < 0) |
| 260 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 261 | |
| 262 | call->count = ntohl(call->tmp); |
| 263 | _debug("FID count: %u", call->count); |
| 264 | if (call->count > AFSCBMAX) |
David Howells | 7126ead | 2020-04-08 16:49:08 +0100 | [diff] [blame] | 265 | return afs_protocol_error(call, afs_eproto_cb_fid_count); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 266 | |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 267 | call->buffer = kmalloc(array3_size(call->count, 3, 4), |
| 268 | GFP_KERNEL); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 269 | if (!call->buffer) |
| 270 | return -ENOMEM; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 271 | afs_extract_to_buf(call, call->count * 3 * 4); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 272 | call->unmarshall++; |
| 273 | |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 274 | fallthrough; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 275 | case 2: |
| 276 | _debug("extract FID array"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 277 | ret = afs_extract_data(call, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 278 | if (ret < 0) |
| 279 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 280 | |
| 281 | _debug("unmarshall FID array"); |
| 282 | call->request = kcalloc(call->count, |
David Howells | 5cf9dd5 | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 283 | sizeof(struct afs_callback_break), |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 284 | GFP_KERNEL); |
| 285 | if (!call->request) |
| 286 | return -ENOMEM; |
| 287 | |
| 288 | cb = call->request; |
| 289 | bp = call->buffer; |
| 290 | for (loop = call->count; loop > 0; loop--, cb++) { |
| 291 | cb->fid.vid = ntohl(*bp++); |
| 292 | cb->fid.vnode = ntohl(*bp++); |
| 293 | cb->fid.unique = ntohl(*bp++); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 294 | } |
| 295 | |
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 callback array and its count in two steps */ |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 300 | fallthrough; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 301 | case 3: |
| 302 | _debug("extract CB 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 | |
Marc Dionne | bcd8927 | 2017-03-16 16:27:44 +0000 | [diff] [blame] | 307 | call->count2 = ntohl(call->tmp); |
| 308 | _debug("CB count: %u", call->count2); |
| 309 | if (call->count2 != call->count && call->count2 != 0) |
David Howells | 7126ead | 2020-04-08 16:49:08 +0100 | [diff] [blame] | 310 | return afs_protocol_error(call, afs_eproto_cb_count); |
David Howells | fc27612 | 2019-11-21 09:12:17 +0000 | [diff] [blame] | 311 | call->iter = &call->def_iter; |
| 312 | iov_iter_discard(&call->def_iter, READ, call->count2 * 3 * 4); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 313 | call->unmarshall++; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 314 | |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 315 | fallthrough; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 316 | case 4: |
David Howells | 06aeb29 | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 317 | _debug("extract discard %zu/%u", |
David Howells | fc27612 | 2019-11-21 09:12:17 +0000 | [diff] [blame] | 318 | iov_iter_count(call->iter), call->count2 * 3 * 4); |
David Howells | 06aeb29 | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 319 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 320 | ret = afs_extract_data(call, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 321 | if (ret < 0) |
| 322 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 323 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 324 | call->unmarshall++; |
Gustavo A. R. Silva | b2db6c3 | 2021-05-25 15:40:22 +0100 | [diff] [blame^] | 325 | fallthrough; |
| 326 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 327 | case 5: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | break; |
| 329 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 331 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 332 | return afs_io_error(call, afs_io_error_cm_reply); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 334 | /* we'll need the file server record as that tells us which set of |
| 335 | * vnodes to operate upon */ |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 336 | return afs_find_cm_server_by_peer(call); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 337 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 340 | * allow the fileserver to request callback state (re-)initialisation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 342 | static void SRXAFSCB_InitCallBackState(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 344 | struct afs_call *call = container_of(work, struct afs_call, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 346 | _enter("{%p}", call->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 348 | if (call->server) |
| 349 | afs_init_callback_state(call->server); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 350 | afs_send_empty_reply(call); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 351 | afs_put_call(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 352 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 353 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 356 | * deliver request data to a CB.InitCallBackState call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 358 | 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] | 359 | { |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 360 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 362 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 364 | afs_extract_discard(call, 0); |
| 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 369 | /* we'll need the file server record as that tells us which set of |
| 370 | * vnodes to operate upon */ |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 371 | return afs_find_cm_server_by_peer(call); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 372 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | /* |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 375 | * deliver request data to a CB.InitCallBackState3 call |
| 376 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 377 | 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] | 378 | { |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 379 | struct afs_uuid *r; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 380 | unsigned loop; |
| 381 | __be32 *b; |
| 382 | int ret; |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 383 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 384 | _enter(""); |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 385 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 386 | _enter("{%u}", call->unmarshall); |
| 387 | |
| 388 | switch (call->unmarshall) { |
| 389 | case 0: |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 390 | call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 391 | if (!call->buffer) |
| 392 | return -ENOMEM; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 393 | afs_extract_to_buf(call, 11 * sizeof(__be32)); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 394 | call->unmarshall++; |
| 395 | |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 396 | fallthrough; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 397 | case 1: |
| 398 | _debug("extract UUID"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 399 | ret = afs_extract_data(call, false); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 400 | switch (ret) { |
| 401 | case 0: break; |
| 402 | case -EAGAIN: return 0; |
| 403 | default: return ret; |
| 404 | } |
| 405 | |
| 406 | _debug("unmarshall UUID"); |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 407 | call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 408 | if (!call->request) |
| 409 | return -ENOMEM; |
| 410 | |
| 411 | b = call->buffer; |
| 412 | r = call->request; |
David Howells | ff54877 | 2017-02-10 16:34:07 +0000 | [diff] [blame] | 413 | r->time_low = b[0]; |
| 414 | r->time_mid = htons(ntohl(b[1])); |
| 415 | r->time_hi_and_version = htons(ntohl(b[2])); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 416 | r->clock_seq_hi_and_reserved = ntohl(b[3]); |
| 417 | r->clock_seq_low = ntohl(b[4]); |
| 418 | |
| 419 | for (loop = 0; loop < 6; loop++) |
| 420 | r->node[loop] = ntohl(b[loop + 5]); |
| 421 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 422 | call->unmarshall++; |
Gustavo A. R. Silva | b2db6c3 | 2021-05-25 15:40:22 +0100 | [diff] [blame^] | 423 | fallthrough; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 424 | |
| 425 | case 2: |
| 426 | break; |
| 427 | } |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 428 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 429 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 430 | return afs_io_error(call, afs_io_error_cm_reply); |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 431 | |
| 432 | /* we'll need the file server record as that tells us which set of |
| 433 | * vnodes to operate upon */ |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 434 | return afs_find_cm_server_by_uuid(call, call->request); |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 438 | * allow the fileserver to see if the cache manager is still alive |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 440 | static void SRXAFSCB_Probe(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 442 | struct afs_call *call = container_of(work, struct afs_call, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 444 | _enter(""); |
| 445 | afs_send_empty_reply(call); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 446 | afs_put_call(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 447 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 448 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 451 | * deliver request data to a CB.Probe call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 453 | static int afs_deliver_cb_probe(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | { |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 455 | int ret; |
| 456 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 457 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 459 | afs_extract_discard(call, 0); |
| 460 | ret = afs_extract_data(call, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 461 | if (ret < 0) |
| 462 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 464 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 465 | return afs_io_error(call, afs_io_error_cm_reply); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 466 | return afs_find_cm_server_by_peer(call); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 467 | } |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 468 | |
| 469 | /* |
David Howells | 3120c17 | 2020-05-27 16:44:02 +0100 | [diff] [blame] | 470 | * Allow the fileserver to quickly find out if the cache manager has been |
| 471 | * rebooted. |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 472 | */ |
| 473 | static void SRXAFSCB_ProbeUuid(struct work_struct *work) |
| 474 | { |
| 475 | struct afs_call *call = container_of(work, struct afs_call, work); |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 476 | struct afs_uuid *r = call->request; |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 477 | |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 478 | _enter(""); |
| 479 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 480 | if (memcmp(r, &call->net->uuid, sizeof(call->net->uuid)) == 0) |
David Howells | 2067b2b | 2019-07-30 14:38:51 +0100 | [diff] [blame] | 481 | afs_send_empty_reply(call); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 482 | else |
David Howells | dde9f09 | 2020-03-13 13:46:08 +0000 | [diff] [blame] | 483 | afs_abort_service_call(call, 1, 1, "K-1"); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 484 | |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 485 | afs_put_call(call); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 486 | _leave(""); |
| 487 | } |
| 488 | |
| 489 | /* |
| 490 | * deliver request data to a CB.ProbeUuid call |
| 491 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 492 | static int afs_deliver_cb_probe_uuid(struct afs_call *call) |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 493 | { |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 494 | struct afs_uuid *r; |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 495 | unsigned loop; |
| 496 | __be32 *b; |
| 497 | int ret; |
| 498 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 499 | _enter("{%u}", call->unmarshall); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 500 | |
| 501 | switch (call->unmarshall) { |
| 502 | case 0: |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 503 | call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 504 | if (!call->buffer) |
| 505 | return -ENOMEM; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 506 | afs_extract_to_buf(call, 11 * sizeof(__be32)); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 507 | call->unmarshall++; |
| 508 | |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 509 | fallthrough; |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 510 | case 1: |
| 511 | _debug("extract UUID"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 512 | ret = afs_extract_data(call, false); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 513 | switch (ret) { |
| 514 | case 0: break; |
| 515 | case -EAGAIN: return 0; |
| 516 | default: return ret; |
| 517 | } |
| 518 | |
| 519 | _debug("unmarshall UUID"); |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 520 | call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 521 | if (!call->request) |
| 522 | return -ENOMEM; |
| 523 | |
| 524 | b = call->buffer; |
| 525 | r = call->request; |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 526 | r->time_low = b[0]; |
| 527 | r->time_mid = htons(ntohl(b[1])); |
| 528 | r->time_hi_and_version = htons(ntohl(b[2])); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 529 | r->clock_seq_hi_and_reserved = ntohl(b[3]); |
| 530 | r->clock_seq_low = ntohl(b[4]); |
| 531 | |
| 532 | for (loop = 0; loop < 6; loop++) |
| 533 | r->node[loop] = ntohl(b[loop + 5]); |
| 534 | |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 535 | call->unmarshall++; |
Gustavo A. R. Silva | b2db6c3 | 2021-05-25 15:40:22 +0100 | [diff] [blame^] | 536 | fallthrough; |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 537 | |
| 538 | case 2: |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 539 | break; |
| 540 | } |
| 541 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 542 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 543 | return afs_io_error(call, afs_io_error_cm_reply); |
David Howells | 3120c17 | 2020-05-27 16:44:02 +0100 | [diff] [blame] | 544 | return afs_find_cm_server_by_peer(call); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | /* |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 548 | * allow the fileserver to ask about the cache manager's capabilities |
| 549 | */ |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 550 | static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work) |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 551 | { |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 552 | struct afs_call *call = container_of(work, struct afs_call, work); |
Florian Westphal | 35ebfc2 | 2019-05-31 18:27:03 +0200 | [diff] [blame] | 553 | int loop; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 554 | |
| 555 | struct { |
| 556 | struct /* InterfaceAddr */ { |
| 557 | __be32 nifs; |
| 558 | __be32 uuid[11]; |
| 559 | __be32 ifaddr[32]; |
| 560 | __be32 netmask[32]; |
| 561 | __be32 mtu[32]; |
| 562 | } ia; |
| 563 | struct /* Capabilities */ { |
| 564 | __be32 capcount; |
| 565 | __be32 caps[1]; |
| 566 | } cap; |
| 567 | } reply; |
| 568 | |
| 569 | _enter(""); |
| 570 | |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 571 | memset(&reply, 0, sizeof(reply)); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 572 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 573 | reply.ia.uuid[0] = call->net->uuid.time_low; |
| 574 | reply.ia.uuid[1] = htonl(ntohs(call->net->uuid.time_mid)); |
| 575 | reply.ia.uuid[2] = htonl(ntohs(call->net->uuid.time_hi_and_version)); |
| 576 | reply.ia.uuid[3] = htonl((s8) call->net->uuid.clock_seq_hi_and_reserved); |
| 577 | reply.ia.uuid[4] = htonl((s8) call->net->uuid.clock_seq_low); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 578 | for (loop = 0; loop < 6; loop++) |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 579 | reply.ia.uuid[loop + 5] = htonl((s8) call->net->uuid.node[loop]); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 580 | |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 581 | reply.cap.capcount = htonl(1); |
| 582 | reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION); |
| 583 | afs_send_simple_reply(call, &reply, sizeof(reply)); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 584 | afs_put_call(call); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 585 | _leave(""); |
| 586 | } |
| 587 | |
| 588 | /* |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 589 | * deliver request data to a CB.TellMeAboutYourself call |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 590 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 591 | 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] | 592 | { |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 593 | int ret; |
| 594 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 595 | _enter(""); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 596 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 597 | afs_extract_discard(call, 0); |
| 598 | ret = afs_extract_data(call, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 599 | if (ret < 0) |
| 600 | return ret; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 601 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 602 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 603 | return afs_io_error(call, afs_io_error_cm_reply); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 604 | return afs_find_cm_server_by_peer(call); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 605 | } |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 606 | |
| 607 | /* |
| 608 | * deliver request data to a YFS CB.CallBack call |
| 609 | */ |
| 610 | static int afs_deliver_yfs_cb_callback(struct afs_call *call) |
| 611 | { |
| 612 | struct afs_callback_break *cb; |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 613 | struct yfs_xdr_YFSFid *bp; |
| 614 | size_t size; |
| 615 | int ret, loop; |
| 616 | |
| 617 | _enter("{%u}", call->unmarshall); |
| 618 | |
| 619 | switch (call->unmarshall) { |
| 620 | case 0: |
| 621 | afs_extract_to_tmp(call); |
| 622 | call->unmarshall++; |
| 623 | |
| 624 | /* extract the FID array and its count in two steps */ |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 625 | fallthrough; |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 626 | case 1: |
| 627 | _debug("extract FID count"); |
| 628 | ret = afs_extract_data(call, true); |
| 629 | if (ret < 0) |
| 630 | return ret; |
| 631 | |
| 632 | call->count = ntohl(call->tmp); |
| 633 | _debug("FID count: %u", call->count); |
| 634 | if (call->count > YFSCBMAX) |
David Howells | 7126ead | 2020-04-08 16:49:08 +0100 | [diff] [blame] | 635 | return afs_protocol_error(call, afs_eproto_cb_fid_count); |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 636 | |
| 637 | size = array_size(call->count, sizeof(struct yfs_xdr_YFSFid)); |
| 638 | call->buffer = kmalloc(size, GFP_KERNEL); |
| 639 | if (!call->buffer) |
| 640 | return -ENOMEM; |
| 641 | afs_extract_to_buf(call, size); |
| 642 | call->unmarshall++; |
| 643 | |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 644 | fallthrough; |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 645 | case 2: |
| 646 | _debug("extract FID array"); |
| 647 | ret = afs_extract_data(call, false); |
| 648 | if (ret < 0) |
| 649 | return ret; |
| 650 | |
| 651 | _debug("unmarshall FID array"); |
| 652 | call->request = kcalloc(call->count, |
| 653 | sizeof(struct afs_callback_break), |
| 654 | GFP_KERNEL); |
| 655 | if (!call->request) |
| 656 | return -ENOMEM; |
| 657 | |
| 658 | cb = call->request; |
| 659 | bp = call->buffer; |
| 660 | for (loop = call->count; loop > 0; loop--, cb++) { |
| 661 | cb->fid.vid = xdr_to_u64(bp->volume); |
| 662 | cb->fid.vnode = xdr_to_u64(bp->vnode.lo); |
| 663 | cb->fid.vnode_hi = ntohl(bp->vnode.hi); |
| 664 | cb->fid.unique = ntohl(bp->vnode.unique); |
| 665 | bp++; |
| 666 | } |
| 667 | |
| 668 | afs_extract_to_tmp(call); |
| 669 | call->unmarshall++; |
Gustavo A. R. Silva | b2db6c3 | 2021-05-25 15:40:22 +0100 | [diff] [blame^] | 670 | fallthrough; |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 671 | |
| 672 | case 3: |
| 673 | break; |
| 674 | } |
| 675 | |
| 676 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
| 677 | return afs_io_error(call, afs_io_error_cm_reply); |
| 678 | |
| 679 | /* We'll need the file server record as that tells us which set of |
| 680 | * vnodes to operate upon. |
| 681 | */ |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 682 | return afs_find_cm_server_by_peer(call); |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 683 | } |