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" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 20 | static int afs_deliver_cb_init_call_back_state(struct afs_call *); |
| 21 | static int afs_deliver_cb_init_call_back_state3(struct afs_call *); |
| 22 | static int afs_deliver_cb_probe(struct afs_call *); |
| 23 | static int afs_deliver_cb_callback(struct afs_call *); |
| 24 | static int afs_deliver_cb_probe_uuid(struct afs_call *); |
| 25 | static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 26 | static void afs_cm_destructor(struct afs_call *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 28 | /* |
| 29 | * CB.CallBack operation type |
| 30 | */ |
| 31 | static const struct afs_call_type afs_SRXCBCallBack = { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 32 | .name = "CB.CallBack", |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 33 | .deliver = afs_deliver_cb_callback, |
| 34 | .abort_to_error = afs_abort_to_error, |
| 35 | .destructor = afs_cm_destructor, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 38 | /* |
| 39 | * CB.InitCallBackState operation type |
| 40 | */ |
| 41 | static const struct afs_call_type afs_SRXCBInitCallBackState = { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 42 | .name = "CB.InitCallBackState", |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 43 | .deliver = afs_deliver_cb_init_call_back_state, |
| 44 | .abort_to_error = afs_abort_to_error, |
| 45 | .destructor = afs_cm_destructor, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 48 | /* |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 49 | * CB.InitCallBackState3 operation type |
| 50 | */ |
| 51 | static const struct afs_call_type afs_SRXCBInitCallBackState3 = { |
| 52 | .name = "CB.InitCallBackState3", |
| 53 | .deliver = afs_deliver_cb_init_call_back_state3, |
| 54 | .abort_to_error = afs_abort_to_error, |
| 55 | .destructor = afs_cm_destructor, |
| 56 | }; |
| 57 | |
| 58 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 59 | * CB.Probe operation type |
| 60 | */ |
| 61 | static const struct afs_call_type afs_SRXCBProbe = { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 62 | .name = "CB.Probe", |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 63 | .deliver = afs_deliver_cb_probe, |
| 64 | .abort_to_error = afs_abort_to_error, |
| 65 | .destructor = afs_cm_destructor, |
| 66 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | /* |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 69 | * CB.ProbeUuid operation type |
| 70 | */ |
| 71 | static const struct afs_call_type afs_SRXCBProbeUuid = { |
| 72 | .name = "CB.ProbeUuid", |
| 73 | .deliver = afs_deliver_cb_probe_uuid, |
| 74 | .abort_to_error = afs_abort_to_error, |
| 75 | .destructor = afs_cm_destructor, |
| 76 | }; |
| 77 | |
| 78 | /* |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 79 | * CB.TellMeAboutYourself operation type |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 80 | */ |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 81 | static const struct afs_call_type afs_SRXCBTellMeAboutYourself = { |
| 82 | .name = "CB.TellMeAboutYourself", |
| 83 | .deliver = afs_deliver_cb_tell_me_about_yourself, |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 84 | .abort_to_error = afs_abort_to_error, |
| 85 | .destructor = afs_cm_destructor, |
| 86 | }; |
| 87 | |
| 88 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 89 | * route an incoming cache manager call |
| 90 | * - return T if supported, F if not |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 92 | bool afs_cm_incoming_call(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
David Howells | 50a2c95 | 2016-10-13 08:27:10 +0100 | [diff] [blame] | 94 | _enter("{CB.OP %u}", call->operation_ID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
David Howells | 50a2c95 | 2016-10-13 08:27:10 +0100 | [diff] [blame] | 96 | switch (call->operation_ID) { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 97 | case CBCallBack: |
| 98 | call->type = &afs_SRXCBCallBack; |
| 99 | return true; |
| 100 | case CBInitCallBackState: |
| 101 | call->type = &afs_SRXCBInitCallBackState; |
| 102 | return true; |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 103 | case CBInitCallBackState3: |
| 104 | call->type = &afs_SRXCBInitCallBackState3; |
| 105 | return true; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 106 | case CBProbe: |
| 107 | call->type = &afs_SRXCBProbe; |
| 108 | return true; |
David Howells | 15b1752 | 2017-11-02 15:27:48 +0000 | [diff] [blame] | 109 | case CBProbeUuid: |
| 110 | call->type = &afs_SRXCBProbeUuid; |
| 111 | return true; |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 112 | case CBTellMeAboutYourself: |
| 113 | call->type = &afs_SRXCBTellMeAboutYourself; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 114 | return true; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 115 | default: |
| 116 | return false; |
| 117 | } |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
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 | * clean up a cache manager call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 123 | static void afs_cm_destructor(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 125 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
David Howells | 6c67c7c | 2014-05-21 14:48:05 +0100 | [diff] [blame] | 127 | /* Break the callbacks here so that we do it after the final ACK is |
| 128 | * received. The step number here must match the final number in |
| 129 | * afs_deliver_cb_callback(). |
| 130 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 131 | if (call->unmarshall == 5) { |
David Howells | 6c67c7c | 2014-05-21 14:48:05 +0100 | [diff] [blame] | 132 | ASSERT(call->server && call->count && call->request); |
| 133 | afs_break_callbacks(call->server, call->count, call->request); |
| 134 | } |
| 135 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 136 | afs_put_server(call->server); |
| 137 | call->server = NULL; |
| 138 | kfree(call->buffer); |
| 139 | call->buffer = NULL; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 140 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 143 | * allow the fileserver to see if the cache manager is still alive |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 145 | static void SRXAFSCB_CallBack(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 147 | struct afs_call *call = container_of(work, struct afs_call, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 149 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 151 | /* be sure to send the reply *before* attempting to spam the AFS server |
| 152 | * with FSFetchStatus requests on the vnodes with broken callbacks lest |
| 153 | * the AFS server get into a vicious cycle of trying to break further |
| 154 | * callbacks because it hadn't received completion of the CBCallBack op |
| 155 | * yet */ |
| 156 | afs_send_empty_reply(call); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 158 | afs_break_callbacks(call->server, call->count, call->request); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 160 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 163 | * deliver request data to a CB.CallBack call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 165 | static int afs_deliver_cb_callback(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { |
David Howells | 8324f0b | 2016-08-30 09:49:29 +0100 | [diff] [blame] | 167 | struct sockaddr_rxrpc srx; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 168 | struct afs_callback *cb; |
| 169 | struct afs_server *server; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 170 | __be32 *bp; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 171 | int ret, loop; |
| 172 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 173 | _enter("{%u}", call->unmarshall); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 174 | |
| 175 | switch (call->unmarshall) { |
| 176 | case 0: |
David Howells | 8324f0b | 2016-08-30 09:49:29 +0100 | [diff] [blame] | 177 | rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 178 | call->offset = 0; |
| 179 | call->unmarshall++; |
| 180 | |
| 181 | /* extract the FID array and its count in two steps */ |
| 182 | case 1: |
| 183 | _debug("extract FID count"); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 184 | ret = afs_extract_data(call, &call->tmp, 4, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 185 | if (ret < 0) |
| 186 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 187 | |
| 188 | call->count = ntohl(call->tmp); |
| 189 | _debug("FID count: %u", call->count); |
| 190 | if (call->count > AFSCBMAX) |
| 191 | return -EBADMSG; |
| 192 | |
| 193 | call->buffer = kmalloc(call->count * 3 * 4, GFP_KERNEL); |
| 194 | if (!call->buffer) |
| 195 | return -ENOMEM; |
| 196 | call->offset = 0; |
| 197 | call->unmarshall++; |
| 198 | |
| 199 | case 2: |
| 200 | _debug("extract FID array"); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 201 | ret = afs_extract_data(call, call->buffer, |
| 202 | call->count * 3 * 4, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 203 | if (ret < 0) |
| 204 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 205 | |
| 206 | _debug("unmarshall FID array"); |
| 207 | call->request = kcalloc(call->count, |
| 208 | sizeof(struct afs_callback), |
| 209 | GFP_KERNEL); |
| 210 | if (!call->request) |
| 211 | return -ENOMEM; |
| 212 | |
| 213 | cb = call->request; |
| 214 | bp = call->buffer; |
| 215 | for (loop = call->count; loop > 0; loop--, cb++) { |
| 216 | cb->fid.vid = ntohl(*bp++); |
| 217 | cb->fid.vnode = ntohl(*bp++); |
| 218 | cb->fid.unique = ntohl(*bp++); |
| 219 | cb->type = AFSCM_CB_UNTYPED; |
| 220 | } |
| 221 | |
| 222 | call->offset = 0; |
| 223 | call->unmarshall++; |
| 224 | |
| 225 | /* extract the callback array and its count in two steps */ |
| 226 | case 3: |
| 227 | _debug("extract CB count"); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 228 | ret = afs_extract_data(call, &call->tmp, 4, true); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 229 | if (ret < 0) |
| 230 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 231 | |
Marc Dionne | eaaad76 | 2017-03-16 16:27:44 +0000 | [diff] [blame] | 232 | call->count2 = ntohl(call->tmp); |
| 233 | _debug("CB count: %u", call->count2); |
| 234 | if (call->count2 != call->count && call->count2 != 0) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 235 | return -EBADMSG; |
| 236 | call->offset = 0; |
| 237 | call->unmarshall++; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 238 | |
| 239 | case 4: |
| 240 | _debug("extract CB array"); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 241 | ret = afs_extract_data(call, call->buffer, |
Marc Dionne | eaaad76 | 2017-03-16 16:27:44 +0000 | [diff] [blame] | 242 | call->count2 * 3 * 4, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 243 | if (ret < 0) |
| 244 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 245 | |
| 246 | _debug("unmarshall CB array"); |
| 247 | cb = call->request; |
| 248 | bp = call->buffer; |
Marc Dionne | eaaad76 | 2017-03-16 16:27:44 +0000 | [diff] [blame] | 249 | for (loop = call->count2; loop > 0; loop--, cb++) { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 250 | cb->version = ntohl(*bp++); |
| 251 | cb->expiry = ntohl(*bp++); |
| 252 | cb->type = ntohl(*bp++); |
| 253 | } |
| 254 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 255 | call->offset = 0; |
| 256 | call->unmarshall++; |
| 257 | |
David Howells | 6c67c7c | 2014-05-21 14:48:05 +0100 | [diff] [blame] | 258 | /* Record that the message was unmarshalled successfully so |
| 259 | * that the call destructor can know do the callback breaking |
| 260 | * work, even if the final ACK isn't received. |
| 261 | * |
| 262 | * If the step number changes, then afs_cm_destructor() must be |
| 263 | * updated also. |
| 264 | */ |
| 265 | call->unmarshall++; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 266 | case 5: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | break; |
| 268 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 270 | call->state = AFS_CALL_REPLYING; |
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 | /* we'll need the file server record as that tells us which set of |
| 273 | * vnodes to operate upon */ |
David Howells | 8324f0b | 2016-08-30 09:49:29 +0100 | [diff] [blame] | 274 | server = afs_find_server(&srx); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 275 | if (!server) |
| 276 | return -ENOTCONN; |
| 277 | call->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 279 | INIT_WORK(&call->work, SRXAFSCB_CallBack); |
Tejun Heo | 0ad53ee | 2011-01-14 15:56:37 +0000 | [diff] [blame] | 280 | queue_work(afs_wq, &call->work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 282 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 285 | * allow the fileserver to request callback state (re-)initialisation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 287 | static void SRXAFSCB_InitCallBackState(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 289 | struct afs_call *call = container_of(work, struct afs_call, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 291 | _enter("{%p}", call->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 293 | afs_init_callback_state(call->server); |
| 294 | afs_send_empty_reply(call); |
| 295 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 296 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 299 | * deliver request data to a CB.InitCallBackState call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 301 | 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] | 302 | { |
David Howells | 8324f0b | 2016-08-30 09:49:29 +0100 | [diff] [blame] | 303 | struct sockaddr_rxrpc srx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | struct afs_server *server; |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 305 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 307 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
David Howells | 8324f0b | 2016-08-30 09:49:29 +0100 | [diff] [blame] | 309 | rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx); |
| 310 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 311 | ret = afs_extract_data(call, NULL, 0, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 312 | if (ret < 0) |
| 313 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 315 | /* no unmarshalling required */ |
| 316 | call->state = AFS_CALL_REPLYING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 318 | /* we'll need the file server record as that tells us which set of |
| 319 | * vnodes to operate upon */ |
David Howells | 8324f0b | 2016-08-30 09:49:29 +0100 | [diff] [blame] | 320 | server = afs_find_server(&srx); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 321 | if (!server) |
| 322 | return -ENOTCONN; |
| 323 | call->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 325 | INIT_WORK(&call->work, SRXAFSCB_InitCallBackState); |
Tejun Heo | 0ad53ee | 2011-01-14 15:56:37 +0000 | [diff] [blame] | 326 | queue_work(afs_wq, &call->work); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 327 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 328 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | /* |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 331 | * deliver request data to a CB.InitCallBackState3 call |
| 332 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 333 | 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] | 334 | { |
David Howells | 8324f0b | 2016-08-30 09:49:29 +0100 | [diff] [blame] | 335 | struct sockaddr_rxrpc srx; |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 336 | struct afs_server *server; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 337 | struct afs_uuid *r; |
| 338 | unsigned loop; |
| 339 | __be32 *b; |
| 340 | int ret; |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 341 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 342 | _enter(""); |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 343 | |
David Howells | 8324f0b | 2016-08-30 09:49:29 +0100 | [diff] [blame] | 344 | rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx); |
| 345 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 346 | _enter("{%u}", call->unmarshall); |
| 347 | |
| 348 | switch (call->unmarshall) { |
| 349 | case 0: |
| 350 | call->offset = 0; |
| 351 | call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL); |
| 352 | if (!call->buffer) |
| 353 | return -ENOMEM; |
| 354 | call->unmarshall++; |
| 355 | |
| 356 | case 1: |
| 357 | _debug("extract UUID"); |
| 358 | ret = afs_extract_data(call, call->buffer, |
| 359 | 11 * sizeof(__be32), false); |
| 360 | switch (ret) { |
| 361 | case 0: break; |
| 362 | case -EAGAIN: return 0; |
| 363 | default: return ret; |
| 364 | } |
| 365 | |
| 366 | _debug("unmarshall UUID"); |
| 367 | call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL); |
| 368 | if (!call->request) |
| 369 | return -ENOMEM; |
| 370 | |
| 371 | b = call->buffer; |
| 372 | r = call->request; |
| 373 | r->time_low = ntohl(b[0]); |
| 374 | r->time_mid = ntohl(b[1]); |
| 375 | r->time_hi_and_version = ntohl(b[2]); |
| 376 | r->clock_seq_hi_and_reserved = ntohl(b[3]); |
| 377 | r->clock_seq_low = ntohl(b[4]); |
| 378 | |
| 379 | for (loop = 0; loop < 6; loop++) |
| 380 | r->node[loop] = ntohl(b[loop + 5]); |
| 381 | |
| 382 | call->offset = 0; |
| 383 | call->unmarshall++; |
| 384 | |
| 385 | case 2: |
| 386 | break; |
| 387 | } |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 388 | |
| 389 | /* no unmarshalling required */ |
| 390 | call->state = AFS_CALL_REPLYING; |
| 391 | |
| 392 | /* we'll need the file server record as that tells us which set of |
| 393 | * vnodes to operate upon */ |
David Howells | 8324f0b | 2016-08-30 09:49:29 +0100 | [diff] [blame] | 394 | server = afs_find_server(&srx); |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 395 | if (!server) |
| 396 | return -ENOTCONN; |
| 397 | call->server = server; |
| 398 | |
| 399 | INIT_WORK(&call->work, SRXAFSCB_InitCallBackState); |
Tejun Heo | 0ad53ee | 2011-01-14 15:56:37 +0000 | [diff] [blame] | 400 | queue_work(afs_wq, &call->work); |
David Howells | c35eccb | 2007-04-26 15:58:49 -0700 | [diff] [blame] | 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 405 | * allow the fileserver to see if the cache manager is still alive |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 407 | static void SRXAFSCB_Probe(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 409 | struct afs_call *call = container_of(work, struct afs_call, work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 411 | _enter(""); |
| 412 | afs_send_empty_reply(call); |
| 413 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 414 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 417 | * deliver request data to a CB.Probe call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 419 | static int afs_deliver_cb_probe(struct afs_call *call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | { |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 421 | int ret; |
| 422 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 423 | _enter(""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 425 | ret = afs_extract_data(call, NULL, 0, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 426 | if (ret < 0) |
| 427 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 429 | /* no unmarshalling required */ |
| 430 | call->state = AFS_CALL_REPLYING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 432 | INIT_WORK(&call->work, SRXAFSCB_Probe); |
Tejun Heo | 0ad53ee | 2011-01-14 15:56:37 +0000 | [diff] [blame] | 433 | queue_work(afs_wq, &call->work); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 434 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 435 | } |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 436 | |
| 437 | /* |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 438 | * allow the fileserver to quickly find out if the fileserver has been rebooted |
| 439 | */ |
| 440 | static void SRXAFSCB_ProbeUuid(struct work_struct *work) |
| 441 | { |
| 442 | struct afs_call *call = container_of(work, struct afs_call, work); |
| 443 | struct afs_uuid *r = call->request; |
| 444 | |
| 445 | struct { |
| 446 | __be32 match; |
| 447 | } reply; |
| 448 | |
| 449 | _enter(""); |
| 450 | |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 451 | if (memcmp(r, &afs_uuid, sizeof(afs_uuid)) == 0) |
| 452 | reply.match = htonl(0); |
| 453 | else |
| 454 | reply.match = htonl(1); |
| 455 | |
| 456 | afs_send_simple_reply(call, &reply, sizeof(reply)); |
| 457 | _leave(""); |
| 458 | } |
| 459 | |
| 460 | /* |
| 461 | * deliver request data to a CB.ProbeUuid call |
| 462 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 463 | static int afs_deliver_cb_probe_uuid(struct afs_call *call) |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 464 | { |
| 465 | struct afs_uuid *r; |
| 466 | unsigned loop; |
| 467 | __be32 *b; |
| 468 | int ret; |
| 469 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 470 | _enter("{%u}", call->unmarshall); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 471 | |
| 472 | switch (call->unmarshall) { |
| 473 | case 0: |
| 474 | call->offset = 0; |
| 475 | call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL); |
| 476 | if (!call->buffer) |
| 477 | return -ENOMEM; |
| 478 | call->unmarshall++; |
| 479 | |
| 480 | case 1: |
| 481 | _debug("extract UUID"); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 482 | ret = afs_extract_data(call, call->buffer, |
| 483 | 11 * sizeof(__be32), false); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 484 | switch (ret) { |
| 485 | case 0: break; |
| 486 | case -EAGAIN: return 0; |
| 487 | default: return ret; |
| 488 | } |
| 489 | |
| 490 | _debug("unmarshall UUID"); |
| 491 | call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL); |
| 492 | if (!call->request) |
| 493 | return -ENOMEM; |
| 494 | |
| 495 | b = call->buffer; |
| 496 | r = call->request; |
| 497 | r->time_low = ntohl(b[0]); |
| 498 | r->time_mid = ntohl(b[1]); |
| 499 | r->time_hi_and_version = ntohl(b[2]); |
| 500 | r->clock_seq_hi_and_reserved = ntohl(b[3]); |
| 501 | r->clock_seq_low = ntohl(b[4]); |
| 502 | |
| 503 | for (loop = 0; loop < 6; loop++) |
| 504 | r->node[loop] = ntohl(b[loop + 5]); |
| 505 | |
| 506 | call->offset = 0; |
| 507 | call->unmarshall++; |
| 508 | |
| 509 | case 2: |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 510 | break; |
| 511 | } |
| 512 | |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 513 | call->state = AFS_CALL_REPLYING; |
| 514 | |
| 515 | INIT_WORK(&call->work, SRXAFSCB_ProbeUuid); |
Tejun Heo | 0ad53ee | 2011-01-14 15:56:37 +0000 | [diff] [blame] | 516 | queue_work(afs_wq, &call->work); |
David Howells | 9396d49 | 2008-04-29 01:03:22 -0700 | [diff] [blame] | 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | /* |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 521 | * allow the fileserver to ask about the cache manager's capabilities |
| 522 | */ |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 523 | static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work) |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 524 | { |
| 525 | struct afs_interface *ifs; |
| 526 | struct afs_call *call = container_of(work, struct afs_call, work); |
| 527 | int loop, nifs; |
| 528 | |
| 529 | struct { |
| 530 | struct /* InterfaceAddr */ { |
| 531 | __be32 nifs; |
| 532 | __be32 uuid[11]; |
| 533 | __be32 ifaddr[32]; |
| 534 | __be32 netmask[32]; |
| 535 | __be32 mtu[32]; |
| 536 | } ia; |
| 537 | struct /* Capabilities */ { |
| 538 | __be32 capcount; |
| 539 | __be32 caps[1]; |
| 540 | } cap; |
| 541 | } reply; |
| 542 | |
| 543 | _enter(""); |
| 544 | |
| 545 | nifs = 0; |
| 546 | ifs = kcalloc(32, sizeof(*ifs), GFP_KERNEL); |
| 547 | if (ifs) { |
| 548 | nifs = afs_get_ipv4_interfaces(ifs, 32, false); |
| 549 | if (nifs < 0) { |
| 550 | kfree(ifs); |
| 551 | ifs = NULL; |
| 552 | nifs = 0; |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | memset(&reply, 0, sizeof(reply)); |
| 557 | reply.ia.nifs = htonl(nifs); |
| 558 | |
| 559 | reply.ia.uuid[0] = htonl(afs_uuid.time_low); |
| 560 | reply.ia.uuid[1] = htonl(afs_uuid.time_mid); |
| 561 | reply.ia.uuid[2] = htonl(afs_uuid.time_hi_and_version); |
| 562 | reply.ia.uuid[3] = htonl((s8) afs_uuid.clock_seq_hi_and_reserved); |
| 563 | reply.ia.uuid[4] = htonl((s8) afs_uuid.clock_seq_low); |
| 564 | for (loop = 0; loop < 6; loop++) |
| 565 | reply.ia.uuid[loop + 5] = htonl((s8) afs_uuid.node[loop]); |
| 566 | |
| 567 | if (ifs) { |
| 568 | for (loop = 0; loop < nifs; loop++) { |
| 569 | reply.ia.ifaddr[loop] = ifs[loop].address.s_addr; |
| 570 | reply.ia.netmask[loop] = ifs[loop].netmask.s_addr; |
| 571 | reply.ia.mtu[loop] = htonl(ifs[loop].mtu); |
| 572 | } |
Patrick McHardy | 5b35fad | 2007-05-03 03:27:39 -0700 | [diff] [blame] | 573 | kfree(ifs); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | reply.cap.capcount = htonl(1); |
| 577 | reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION); |
| 578 | afs_send_simple_reply(call, &reply, sizeof(reply)); |
| 579 | |
| 580 | _leave(""); |
| 581 | } |
| 582 | |
| 583 | /* |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 584 | * deliver request data to a CB.TellMeAboutYourself call |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 585 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 586 | 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] | 587 | { |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 588 | int ret; |
| 589 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 590 | _enter(""); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 591 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 592 | ret = afs_extract_data(call, NULL, 0, false); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 593 | if (ret < 0) |
| 594 | return ret; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 595 | |
| 596 | /* no unmarshalling required */ |
| 597 | call->state = AFS_CALL_REPLYING; |
| 598 | |
David Howells | 7c80bcc | 2008-04-29 01:03:21 -0700 | [diff] [blame] | 599 | INIT_WORK(&call->work, SRXAFSCB_TellMeAboutYourself); |
Tejun Heo | 0ad53ee | 2011-01-14 15:56:37 +0000 | [diff] [blame] | 600 | queue_work(afs_wq, &call->work); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 601 | return 0; |
| 602 | } |