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++; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 325 | case 5: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | break; |
| 327 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 329 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 330 | return afs_io_error(call, afs_io_error_cm_reply); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 332 | /* we'll need the file server record as that tells us which set of |
| 333 | * vnodes to operate upon */ |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 334 | return afs_find_cm_server_by_peer(call); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 335 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 338 | * allow the fileserver to request callback state (re-)initialisation |
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 | static void SRXAFSCB_InitCallBackState(struct work_struct *work) |
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 | struct afs_call *call = container_of(work, struct afs_call, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 344 | _enter("{%p}", call->server); |
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 | if (call->server) |
| 347 | afs_init_callback_state(call->server); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 348 | afs_send_empty_reply(call); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 349 | afs_put_call(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 350 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 351 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 354 | * deliver request data to a CB.InitCallBackState call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 356 | 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] | 357 | { |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 358 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 360 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 362 | afs_extract_discard(call, 0); |
| 363 | ret = afs_extract_data(call, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 364 | if (ret < 0) |
| 365 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 367 | /* we'll need the file server record as that tells us which set of |
| 368 | * vnodes to operate upon */ |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 369 | return afs_find_cm_server_by_peer(call); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 370 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | /* |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 373 | * deliver request data to a CB.InitCallBackState3 call |
| 374 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 375 | 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] | 376 | { |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 377 | struct afs_uuid *r; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 378 | unsigned loop; |
| 379 | __be32 *b; |
| 380 | int ret; |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 381 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 382 | _enter(""); |
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("{%u}", call->unmarshall); |
| 385 | |
| 386 | switch (call->unmarshall) { |
| 387 | case 0: |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 388 | call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 389 | if (!call->buffer) |
| 390 | return -ENOMEM; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 391 | afs_extract_to_buf(call, 11 * sizeof(__be32)); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 392 | call->unmarshall++; |
| 393 | |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame^] | 394 | fallthrough; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 395 | case 1: |
| 396 | _debug("extract UUID"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 397 | ret = afs_extract_data(call, false); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 398 | switch (ret) { |
| 399 | case 0: break; |
| 400 | case -EAGAIN: return 0; |
| 401 | default: return ret; |
| 402 | } |
| 403 | |
| 404 | _debug("unmarshall UUID"); |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 405 | call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 406 | if (!call->request) |
| 407 | return -ENOMEM; |
| 408 | |
| 409 | b = call->buffer; |
| 410 | r = call->request; |
David Howells | ff54877 | 2017-02-10 16:34:07 +0000 | [diff] [blame] | 411 | r->time_low = b[0]; |
| 412 | r->time_mid = htons(ntohl(b[1])); |
| 413 | r->time_hi_and_version = htons(ntohl(b[2])); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 414 | r->clock_seq_hi_and_reserved = ntohl(b[3]); |
| 415 | r->clock_seq_low = ntohl(b[4]); |
| 416 | |
| 417 | for (loop = 0; loop < 6; loop++) |
| 418 | r->node[loop] = ntohl(b[loop + 5]); |
| 419 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 420 | call->unmarshall++; |
| 421 | |
| 422 | case 2: |
| 423 | break; |
| 424 | } |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 425 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 426 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 427 | return afs_io_error(call, afs_io_error_cm_reply); |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 428 | |
| 429 | /* we'll need the file server record as that tells us which set of |
| 430 | * vnodes to operate upon */ |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 431 | return afs_find_cm_server_by_uuid(call, call->request); |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 435 | * allow the fileserver to see if the cache manager is still alive |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 437 | static void SRXAFSCB_Probe(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 439 | struct afs_call *call = container_of(work, struct afs_call, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 441 | _enter(""); |
| 442 | afs_send_empty_reply(call); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 443 | afs_put_call(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 444 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 445 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 448 | * deliver request data to a CB.Probe call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 450 | static int afs_deliver_cb_probe(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | { |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 452 | int ret; |
| 453 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 454 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 456 | afs_extract_discard(call, 0); |
| 457 | ret = afs_extract_data(call, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 458 | if (ret < 0) |
| 459 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 461 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 462 | return afs_io_error(call, afs_io_error_cm_reply); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 463 | return afs_find_cm_server_by_peer(call); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 464 | } |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 465 | |
| 466 | /* |
David Howells | 3120c17 | 2020-05-27 16:44:02 +0100 | [diff] [blame] | 467 | * Allow the fileserver to quickly find out if the cache manager has been |
| 468 | * rebooted. |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 469 | */ |
| 470 | static void SRXAFSCB_ProbeUuid(struct work_struct *work) |
| 471 | { |
| 472 | struct afs_call *call = container_of(work, struct afs_call, work); |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 473 | struct afs_uuid *r = call->request; |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 474 | |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 475 | _enter(""); |
| 476 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 477 | if (memcmp(r, &call->net->uuid, sizeof(call->net->uuid)) == 0) |
David Howells | 2067b2b | 2019-07-30 14:38:51 +0100 | [diff] [blame] | 478 | afs_send_empty_reply(call); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 479 | else |
David Howells | dde9f09 | 2020-03-13 13:46:08 +0000 | [diff] [blame] | 480 | afs_abort_service_call(call, 1, 1, "K-1"); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 481 | |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 482 | afs_put_call(call); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 483 | _leave(""); |
| 484 | } |
| 485 | |
| 486 | /* |
| 487 | * deliver request data to a CB.ProbeUuid call |
| 488 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 489 | static int afs_deliver_cb_probe_uuid(struct afs_call *call) |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 490 | { |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 491 | struct afs_uuid *r; |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 492 | unsigned loop; |
| 493 | __be32 *b; |
| 494 | int ret; |
| 495 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 496 | _enter("{%u}", call->unmarshall); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 497 | |
| 498 | switch (call->unmarshall) { |
| 499 | case 0: |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 500 | call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 501 | if (!call->buffer) |
| 502 | return -ENOMEM; |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 503 | afs_extract_to_buf(call, 11 * sizeof(__be32)); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 504 | call->unmarshall++; |
| 505 | |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame^] | 506 | fallthrough; |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 507 | case 1: |
| 508 | _debug("extract UUID"); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 509 | ret = afs_extract_data(call, false); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 510 | switch (ret) { |
| 511 | case 0: break; |
| 512 | case -EAGAIN: return 0; |
| 513 | default: return ret; |
| 514 | } |
| 515 | |
| 516 | _debug("unmarshall UUID"); |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 517 | call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 518 | if (!call->request) |
| 519 | return -ENOMEM; |
| 520 | |
| 521 | b = call->buffer; |
| 522 | r = call->request; |
David Howells | fe342cf | 2018-04-09 21:12:31 +0100 | [diff] [blame] | 523 | r->time_low = b[0]; |
| 524 | r->time_mid = htons(ntohl(b[1])); |
| 525 | r->time_hi_and_version = htons(ntohl(b[2])); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 526 | r->clock_seq_hi_and_reserved = ntohl(b[3]); |
| 527 | r->clock_seq_low = ntohl(b[4]); |
| 528 | |
| 529 | for (loop = 0; loop < 6; loop++) |
| 530 | r->node[loop] = ntohl(b[loop + 5]); |
| 531 | |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 532 | call->unmarshall++; |
| 533 | |
| 534 | case 2: |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 535 | break; |
| 536 | } |
| 537 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 538 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 539 | return afs_io_error(call, afs_io_error_cm_reply); |
David Howells | 3120c17 | 2020-05-27 16:44:02 +0100 | [diff] [blame] | 540 | return afs_find_cm_server_by_peer(call); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | /* |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 544 | * allow the fileserver to ask about the cache manager's capabilities |
| 545 | */ |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 546 | static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work) |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 547 | { |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 548 | struct afs_call *call = container_of(work, struct afs_call, work); |
Florian Westphal | 35ebfc2 | 2019-05-31 18:27:03 +0200 | [diff] [blame] | 549 | int loop; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 550 | |
| 551 | struct { |
| 552 | struct /* InterfaceAddr */ { |
| 553 | __be32 nifs; |
| 554 | __be32 uuid[11]; |
| 555 | __be32 ifaddr[32]; |
| 556 | __be32 netmask[32]; |
| 557 | __be32 mtu[32]; |
| 558 | } ia; |
| 559 | struct /* Capabilities */ { |
| 560 | __be32 capcount; |
| 561 | __be32 caps[1]; |
| 562 | } cap; |
| 563 | } reply; |
| 564 | |
| 565 | _enter(""); |
| 566 | |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 567 | memset(&reply, 0, sizeof(reply)); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 568 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 569 | reply.ia.uuid[0] = call->net->uuid.time_low; |
| 570 | reply.ia.uuid[1] = htonl(ntohs(call->net->uuid.time_mid)); |
| 571 | reply.ia.uuid[2] = htonl(ntohs(call->net->uuid.time_hi_and_version)); |
| 572 | reply.ia.uuid[3] = htonl((s8) call->net->uuid.clock_seq_hi_and_reserved); |
| 573 | reply.ia.uuid[4] = htonl((s8) call->net->uuid.clock_seq_low); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 574 | for (loop = 0; loop < 6; loop++) |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 575 | reply.ia.uuid[loop + 5] = htonl((s8) call->net->uuid.node[loop]); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 576 | |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 577 | reply.cap.capcount = htonl(1); |
| 578 | reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION); |
| 579 | afs_send_simple_reply(call, &reply, sizeof(reply)); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 580 | afs_put_call(call); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 581 | _leave(""); |
| 582 | } |
| 583 | |
| 584 | /* |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 585 | * deliver request data to a CB.TellMeAboutYourself call |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 586 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 587 | 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] | 588 | { |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 589 | int ret; |
| 590 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 591 | _enter(""); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 592 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 593 | afs_extract_discard(call, 0); |
| 594 | ret = afs_extract_data(call, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 595 | if (ret < 0) |
| 596 | return ret; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 597 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 598 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 599 | return afs_io_error(call, afs_io_error_cm_reply); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 600 | return afs_find_cm_server_by_peer(call); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 601 | } |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 602 | |
| 603 | /* |
| 604 | * deliver request data to a YFS CB.CallBack call |
| 605 | */ |
| 606 | static int afs_deliver_yfs_cb_callback(struct afs_call *call) |
| 607 | { |
| 608 | struct afs_callback_break *cb; |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 609 | struct yfs_xdr_YFSFid *bp; |
| 610 | size_t size; |
| 611 | int ret, loop; |
| 612 | |
| 613 | _enter("{%u}", call->unmarshall); |
| 614 | |
| 615 | switch (call->unmarshall) { |
| 616 | case 0: |
| 617 | afs_extract_to_tmp(call); |
| 618 | call->unmarshall++; |
| 619 | |
| 620 | /* extract the FID array and its count in two steps */ |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame^] | 621 | fallthrough; |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 622 | case 1: |
| 623 | _debug("extract FID count"); |
| 624 | ret = afs_extract_data(call, true); |
| 625 | if (ret < 0) |
| 626 | return ret; |
| 627 | |
| 628 | call->count = ntohl(call->tmp); |
| 629 | _debug("FID count: %u", call->count); |
| 630 | if (call->count > YFSCBMAX) |
David Howells | 7126ead | 2020-04-08 16:49:08 +0100 | [diff] [blame] | 631 | return afs_protocol_error(call, afs_eproto_cb_fid_count); |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 632 | |
| 633 | size = array_size(call->count, sizeof(struct yfs_xdr_YFSFid)); |
| 634 | call->buffer = kmalloc(size, GFP_KERNEL); |
| 635 | if (!call->buffer) |
| 636 | return -ENOMEM; |
| 637 | afs_extract_to_buf(call, size); |
| 638 | call->unmarshall++; |
| 639 | |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame^] | 640 | fallthrough; |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 641 | case 2: |
| 642 | _debug("extract FID array"); |
| 643 | ret = afs_extract_data(call, false); |
| 644 | if (ret < 0) |
| 645 | return ret; |
| 646 | |
| 647 | _debug("unmarshall FID array"); |
| 648 | call->request = kcalloc(call->count, |
| 649 | sizeof(struct afs_callback_break), |
| 650 | GFP_KERNEL); |
| 651 | if (!call->request) |
| 652 | return -ENOMEM; |
| 653 | |
| 654 | cb = call->request; |
| 655 | bp = call->buffer; |
| 656 | for (loop = call->count; loop > 0; loop--, cb++) { |
| 657 | cb->fid.vid = xdr_to_u64(bp->volume); |
| 658 | cb->fid.vnode = xdr_to_u64(bp->vnode.lo); |
| 659 | cb->fid.vnode_hi = ntohl(bp->vnode.hi); |
| 660 | cb->fid.unique = ntohl(bp->vnode.unique); |
| 661 | bp++; |
| 662 | } |
| 663 | |
| 664 | afs_extract_to_tmp(call); |
| 665 | call->unmarshall++; |
| 666 | |
| 667 | case 3: |
| 668 | break; |
| 669 | } |
| 670 | |
| 671 | if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING)) |
| 672 | return afs_io_error(call, afs_io_error_cm_reply); |
| 673 | |
| 674 | /* We'll need the file server record as that tells us which set of |
| 675 | * vnodes to operate upon. |
| 676 | */ |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 677 | return afs_find_cm_server_by_peer(call); |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 678 | } |