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