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