blob: c332c95a6940f50fe3a9e220ebbb6928b0f5d27c [file] [log] [blame]
David Howellsec268152007-04-26 15:49:28 -07001/* AFS Cache Manager Service
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
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 Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/sched.h>
David Howells08e0e7c2007-04-26 15:55:03 -070016#include <linux/ip.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include "internal.h"
David Howells08e0e7c2007-04-26 15:55:03 -070018#include "afs_cm.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
David Howellsd0016482016-08-30 20:42:14 +010020static int afs_deliver_cb_init_call_back_state(struct afs_call *);
21static int afs_deliver_cb_init_call_back_state3(struct afs_call *);
22static int afs_deliver_cb_probe(struct afs_call *);
23static int afs_deliver_cb_callback(struct afs_call *);
24static int afs_deliver_cb_probe_uuid(struct afs_call *);
25static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *);
David Howells08e0e7c2007-04-26 15:55:03 -070026static void afs_cm_destructor(struct afs_call *);
David Howells341f7412017-01-05 10:38:36 +000027static void SRXAFSCB_CallBack(struct work_struct *);
28static void SRXAFSCB_InitCallBackState(struct work_struct *);
29static void SRXAFSCB_Probe(struct work_struct *);
30static void SRXAFSCB_ProbeUuid(struct work_struct *);
31static void SRXAFSCB_TellMeAboutYourself(struct work_struct *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
David Howells8e8d7f12017-01-05 10:38:34 +000033#define CM_NAME(name) \
34 const char afs_SRXCB##name##_name[] __tracepoint_string = \
35 "CB." #name
36
David Howells08e0e7c2007-04-26 15:55:03 -070037/*
38 * CB.CallBack operation type
39 */
David Howells8e8d7f12017-01-05 10:38:34 +000040static CM_NAME(CallBack);
David Howells08e0e7c2007-04-26 15:55:03 -070041static const struct afs_call_type afs_SRXCBCallBack = {
David Howells8e8d7f12017-01-05 10:38:34 +000042 .name = afs_SRXCBCallBack_name,
David Howells08e0e7c2007-04-26 15:55:03 -070043 .deliver = afs_deliver_cb_callback,
David Howells08e0e7c2007-04-26 15:55:03 -070044 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000045 .work = SRXAFSCB_CallBack,
Linus Torvalds1da177e2005-04-16 15:20:36 -070046};
47
David Howells08e0e7c2007-04-26 15:55:03 -070048/*
49 * CB.InitCallBackState operation type
50 */
David Howells8e8d7f12017-01-05 10:38:34 +000051static CM_NAME(InitCallBackState);
David Howells08e0e7c2007-04-26 15:55:03 -070052static const struct afs_call_type afs_SRXCBInitCallBackState = {
David Howells8e8d7f12017-01-05 10:38:34 +000053 .name = afs_SRXCBInitCallBackState_name,
David Howells08e0e7c2007-04-26 15:55:03 -070054 .deliver = afs_deliver_cb_init_call_back_state,
David Howells08e0e7c2007-04-26 15:55:03 -070055 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000056 .work = SRXAFSCB_InitCallBackState,
Linus Torvalds1da177e2005-04-16 15:20:36 -070057};
58
David Howells08e0e7c2007-04-26 15:55:03 -070059/*
David Howellsc35eccb2007-04-26 15:58:49 -070060 * CB.InitCallBackState3 operation type
61 */
David Howells8e8d7f12017-01-05 10:38:34 +000062static CM_NAME(InitCallBackState3);
David Howellsc35eccb2007-04-26 15:58:49 -070063static const struct afs_call_type afs_SRXCBInitCallBackState3 = {
David Howells8e8d7f12017-01-05 10:38:34 +000064 .name = afs_SRXCBInitCallBackState3_name,
David Howellsc35eccb2007-04-26 15:58:49 -070065 .deliver = afs_deliver_cb_init_call_back_state3,
David Howellsc35eccb2007-04-26 15:58:49 -070066 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000067 .work = SRXAFSCB_InitCallBackState,
David Howellsc35eccb2007-04-26 15:58:49 -070068};
69
70/*
David Howells08e0e7c2007-04-26 15:55:03 -070071 * CB.Probe operation type
72 */
David Howells8e8d7f12017-01-05 10:38:34 +000073static CM_NAME(Probe);
David Howells08e0e7c2007-04-26 15:55:03 -070074static const struct afs_call_type afs_SRXCBProbe = {
David Howells8e8d7f12017-01-05 10:38:34 +000075 .name = afs_SRXCBProbe_name,
David Howells08e0e7c2007-04-26 15:55:03 -070076 .deliver = afs_deliver_cb_probe,
David Howells08e0e7c2007-04-26 15:55:03 -070077 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000078 .work = SRXAFSCB_Probe,
David Howells08e0e7c2007-04-26 15:55:03 -070079};
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Linus Torvalds1da177e2005-04-16 15:20:36 -070081/*
David Howells9396d492008-04-29 01:03:22 -070082 * CB.ProbeUuid operation type
83 */
David Howells8e8d7f12017-01-05 10:38:34 +000084static CM_NAME(ProbeUuid);
David Howells9396d492008-04-29 01:03:22 -070085static const struct afs_call_type afs_SRXCBProbeUuid = {
David Howells8e8d7f12017-01-05 10:38:34 +000086 .name = afs_SRXCBProbeUuid_name,
David Howells9396d492008-04-29 01:03:22 -070087 .deliver = afs_deliver_cb_probe_uuid,
David Howells9396d492008-04-29 01:03:22 -070088 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +000089 .work = SRXAFSCB_ProbeUuid,
David Howells9396d492008-04-29 01:03:22 -070090};
91
92/*
David Howells7c80bcc2008-04-29 01:03:21 -070093 * CB.TellMeAboutYourself operation type
David Howellsb908fe62007-04-26 15:58:17 -070094 */
David Howells8e8d7f12017-01-05 10:38:34 +000095static CM_NAME(TellMeAboutYourself);
David Howells7c80bcc2008-04-29 01:03:21 -070096static const struct afs_call_type afs_SRXCBTellMeAboutYourself = {
David Howells8e8d7f12017-01-05 10:38:34 +000097 .name = afs_SRXCBTellMeAboutYourself_name,
David Howells7c80bcc2008-04-29 01:03:21 -070098 .deliver = afs_deliver_cb_tell_me_about_yourself,
David Howellsb908fe62007-04-26 15:58:17 -070099 .destructor = afs_cm_destructor,
David Howells341f7412017-01-05 10:38:36 +0000100 .work = SRXAFSCB_TellMeAboutYourself,
David Howellsb908fe62007-04-26 15:58:17 -0700101};
102
103/*
David Howells08e0e7c2007-04-26 15:55:03 -0700104 * route an incoming cache manager call
105 * - return T if supported, F if not
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 */
David Howells08e0e7c2007-04-26 15:55:03 -0700107bool afs_cm_incoming_call(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
David Howells50a2c952016-10-13 08:27:10 +0100109 _enter("{CB.OP %u}", call->operation_ID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
David Howells50a2c952016-10-13 08:27:10 +0100111 switch (call->operation_ID) {
David Howells08e0e7c2007-04-26 15:55:03 -0700112 case CBCallBack:
113 call->type = &afs_SRXCBCallBack;
114 return true;
115 case CBInitCallBackState:
116 call->type = &afs_SRXCBInitCallBackState;
117 return true;
David Howellsc35eccb2007-04-26 15:58:49 -0700118 case CBInitCallBackState3:
119 call->type = &afs_SRXCBInitCallBackState3;
120 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700121 case CBProbe:
122 call->type = &afs_SRXCBProbe;
123 return true;
David Howellsf4b35262017-11-02 15:27:48 +0000124 case CBProbeUuid:
125 call->type = &afs_SRXCBProbeUuid;
126 return true;
David Howells7c80bcc2008-04-29 01:03:21 -0700127 case CBTellMeAboutYourself:
128 call->type = &afs_SRXCBTellMeAboutYourself;
David Howellsb908fe62007-04-26 15:58:17 -0700129 return true;
David Howells08e0e7c2007-04-26 15:55:03 -0700130 default:
131 return false;
132 }
David Howellsec268152007-04-26 15:49:28 -0700133}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135/*
David Howells428edad2018-05-12 00:28:58 +0100136 * Clean up a cache manager call.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 */
David Howells08e0e7c2007-04-26 15:55:03 -0700138static void afs_cm_destructor(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
David Howells08e0e7c2007-04-26 15:55:03 -0700140 kfree(call->buffer);
141 call->buffer = NULL;
David Howellsec268152007-04-26 15:49:28 -0700142}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144/*
David Howellsc435ee32017-11-02 15:27:49 +0000145 * The server supplied a list of callbacks that it wanted to break.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 */
David Howells08e0e7c2007-04-26 15:55:03 -0700147static void SRXAFSCB_CallBack(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
David Howells08e0e7c2007-04-26 15:55:03 -0700149 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
David Howells08e0e7c2007-04-26 15:55:03 -0700151 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
David Howells428edad2018-05-12 00:28:58 +0100153 /* We need to break the callbacks before sending the reply as the
154 * server holds up change visibility till it receives our reply so as
155 * to maintain cache coherency.
156 */
David Howellsa86b06d2018-05-11 23:45:40 +0100157 if (call->cm_server)
158 afs_break_callbacks(call->cm_server, call->count, call->request);
David Howells428edad2018-05-12 00:28:58 +0100159
160 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000161 afs_put_call(call);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700163}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165/*
David Howells08e0e7c2007-04-26 15:55:03 -0700166 * deliver request data to a CB.CallBack call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 */
David Howellsd0016482016-08-30 20:42:14 +0100168static int afs_deliver_cb_callback(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169{
David Howells5cf9dd52018-04-09 21:12:31 +0100170 struct afs_callback_break *cb;
David Howells8324f0b2016-08-30 09:49:29 +0100171 struct sockaddr_rxrpc srx;
David Howells08e0e7c2007-04-26 15:55:03 -0700172 __be32 *bp;
David Howells08e0e7c2007-04-26 15:55:03 -0700173 int ret, loop;
174
David Howellsd0016482016-08-30 20:42:14 +0100175 _enter("{%u}", call->unmarshall);
David Howells08e0e7c2007-04-26 15:55:03 -0700176
177 switch (call->unmarshall) {
178 case 0:
179 call->offset = 0;
180 call->unmarshall++;
181
182 /* extract the FID array and its count in two steps */
183 case 1:
184 _debug("extract FID count");
David Howellsd0016482016-08-30 20:42:14 +0100185 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howells372ee162016-08-03 14:11:40 +0100186 if (ret < 0)
187 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700188
189 call->count = ntohl(call->tmp);
190 _debug("FID count: %u", call->count);
191 if (call->count > AFSCBMAX)
David Howells5f702c82018-04-06 14:17:25 +0100192 return afs_protocol_error(call, -EBADMSG);
David Howells08e0e7c2007-04-26 15:55:03 -0700193
194 call->buffer = kmalloc(call->count * 3 * 4, GFP_KERNEL);
195 if (!call->buffer)
196 return -ENOMEM;
197 call->offset = 0;
198 call->unmarshall++;
199
200 case 2:
201 _debug("extract FID array");
David Howellsd0016482016-08-30 20:42:14 +0100202 ret = afs_extract_data(call, call->buffer,
203 call->count * 3 * 4, true);
David Howells372ee162016-08-03 14:11:40 +0100204 if (ret < 0)
205 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700206
207 _debug("unmarshall FID array");
208 call->request = kcalloc(call->count,
David Howells5cf9dd52018-04-09 21:12:31 +0100209 sizeof(struct afs_callback_break),
David Howells08e0e7c2007-04-26 15:55:03 -0700210 GFP_KERNEL);
211 if (!call->request)
212 return -ENOMEM;
213
214 cb = call->request;
215 bp = call->buffer;
216 for (loop = call->count; loop > 0; loop--, cb++) {
217 cb->fid.vid = ntohl(*bp++);
218 cb->fid.vnode = ntohl(*bp++);
219 cb->fid.unique = ntohl(*bp++);
David Howells5cf9dd52018-04-09 21:12:31 +0100220 cb->cb.type = AFSCM_CB_UNTYPED;
David Howells08e0e7c2007-04-26 15:55:03 -0700221 }
222
223 call->offset = 0;
224 call->unmarshall++;
225
226 /* extract the callback array and its count in two steps */
227 case 3:
228 _debug("extract CB count");
David Howellsd0016482016-08-30 20:42:14 +0100229 ret = afs_extract_data(call, &call->tmp, 4, true);
David Howells372ee162016-08-03 14:11:40 +0100230 if (ret < 0)
231 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700232
Marc Dionnebcd89272017-03-16 16:27:44 +0000233 call->count2 = ntohl(call->tmp);
234 _debug("CB count: %u", call->count2);
235 if (call->count2 != call->count && call->count2 != 0)
David Howells5f702c82018-04-06 14:17:25 +0100236 return afs_protocol_error(call, -EBADMSG);
David Howells08e0e7c2007-04-26 15:55:03 -0700237 call->offset = 0;
238 call->unmarshall++;
David Howells08e0e7c2007-04-26 15:55:03 -0700239
240 case 4:
241 _debug("extract CB array");
David Howellsd0016482016-08-30 20:42:14 +0100242 ret = afs_extract_data(call, call->buffer,
Marc Dionnebcd89272017-03-16 16:27:44 +0000243 call->count2 * 3 * 4, false);
David Howells372ee162016-08-03 14:11:40 +0100244 if (ret < 0)
245 return ret;
David Howells08e0e7c2007-04-26 15:55:03 -0700246
247 _debug("unmarshall CB array");
248 cb = call->request;
249 bp = call->buffer;
Marc Dionnebcd89272017-03-16 16:27:44 +0000250 for (loop = call->count2; loop > 0; loop--, cb++) {
David Howells5cf9dd52018-04-09 21:12:31 +0100251 cb->cb.version = ntohl(*bp++);
252 cb->cb.expiry = ntohl(*bp++);
253 cb->cb.type = ntohl(*bp++);
David Howells08e0e7c2007-04-26 15:55:03 -0700254 }
255
David Howells08e0e7c2007-04-26 15:55:03 -0700256 call->offset = 0;
257 call->unmarshall++;
David Howellsd0016482016-08-30 20:42:14 +0100258 case 5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 break;
260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
David Howells98bf40c2017-11-02 15:27:53 +0000262 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
263 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
David Howells08e0e7c2007-04-26 15:55:03 -0700265 /* we'll need the file server record as that tells us which set of
266 * vnodes to operate upon */
David Howells98bf40c2017-11-02 15:27:53 +0000267 rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
David Howellsa86b06d2018-05-11 23:45:40 +0100268 call->cm_server = afs_find_server(call->net, &srx);
269 if (!call->cm_server)
David Howells3709a392018-05-11 22:59:42 +0100270 trace_afs_cm_no_server(call, &srx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
David Howells341f7412017-01-05 10:38:36 +0000272 return afs_queue_call_work(call);
David Howellsec268152007-04-26 15:49:28 -0700273}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275/*
David Howells08e0e7c2007-04-26 15:55:03 -0700276 * allow the fileserver to request callback state (re-)initialisation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 */
David Howells08e0e7c2007-04-26 15:55:03 -0700278static void SRXAFSCB_InitCallBackState(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
David Howells08e0e7c2007-04-26 15:55:03 -0700280 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
David Howellsd0676a12017-11-02 15:27:49 +0000282 _enter("{%p}", call->cm_server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
David Howellsa86b06d2018-05-11 23:45:40 +0100284 if (call->cm_server)
285 afs_init_callback_state(call->cm_server);
David Howells08e0e7c2007-04-26 15:55:03 -0700286 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000287 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700288 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700289}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291/*
David Howells08e0e7c2007-04-26 15:55:03 -0700292 * deliver request data to a CB.InitCallBackState call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 */
David Howellsd0016482016-08-30 20:42:14 +0100294static int afs_deliver_cb_init_call_back_state(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
David Howells8324f0b2016-08-30 09:49:29 +0100296 struct sockaddr_rxrpc srx;
David Howells372ee162016-08-03 14:11:40 +0100297 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
David Howellsd0016482016-08-30 20:42:14 +0100299 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
David Howellsf044c882017-11-02 15:27:45 +0000301 rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
David Howells8324f0b2016-08-30 09:49:29 +0100302
David Howellsd0016482016-08-30 20:42:14 +0100303 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100304 if (ret < 0)
305 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
David Howells08e0e7c2007-04-26 15:55:03 -0700307 /* we'll need the file server record as that tells us which set of
308 * vnodes to operate upon */
David Howellsa86b06d2018-05-11 23:45:40 +0100309 call->cm_server = afs_find_server(call->net, &srx);
310 if (!call->cm_server)
David Howells3709a392018-05-11 22:59:42 +0100311 trace_afs_cm_no_server(call, &srx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
David Howells341f7412017-01-05 10:38:36 +0000313 return afs_queue_call_work(call);
David Howellsec268152007-04-26 15:49:28 -0700314}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316/*
David Howellsc35eccb2007-04-26 15:58:49 -0700317 * deliver request data to a CB.InitCallBackState3 call
318 */
David Howellsd0016482016-08-30 20:42:14 +0100319static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
David Howellsc35eccb2007-04-26 15:58:49 -0700320{
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300321 struct afs_uuid *r;
David Howellsd0016482016-08-30 20:42:14 +0100322 unsigned loop;
323 __be32 *b;
324 int ret;
David Howellsc35eccb2007-04-26 15:58:49 -0700325
David Howellsd0016482016-08-30 20:42:14 +0100326 _enter("");
David Howellsc35eccb2007-04-26 15:58:49 -0700327
David Howellsd0016482016-08-30 20:42:14 +0100328 _enter("{%u}", call->unmarshall);
329
330 switch (call->unmarshall) {
331 case 0:
332 call->offset = 0;
333 call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
334 if (!call->buffer)
335 return -ENOMEM;
336 call->unmarshall++;
337
338 case 1:
339 _debug("extract UUID");
340 ret = afs_extract_data(call, call->buffer,
341 11 * sizeof(__be32), false);
342 switch (ret) {
343 case 0: break;
344 case -EAGAIN: return 0;
345 default: return ret;
346 }
347
348 _debug("unmarshall UUID");
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300349 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
David Howellsd0016482016-08-30 20:42:14 +0100350 if (!call->request)
351 return -ENOMEM;
352
353 b = call->buffer;
354 r = call->request;
David Howellsff548772017-02-10 16:34:07 +0000355 r->time_low = b[0];
356 r->time_mid = htons(ntohl(b[1]));
357 r->time_hi_and_version = htons(ntohl(b[2]));
David Howellsd0016482016-08-30 20:42:14 +0100358 r->clock_seq_hi_and_reserved = ntohl(b[3]);
359 r->clock_seq_low = ntohl(b[4]);
360
361 for (loop = 0; loop < 6; loop++)
362 r->node[loop] = ntohl(b[loop + 5]);
363
364 call->offset = 0;
365 call->unmarshall++;
366
367 case 2:
368 break;
369 }
David Howellsc35eccb2007-04-26 15:58:49 -0700370
David Howells98bf40c2017-11-02 15:27:53 +0000371 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
372 return -EIO;
David Howellsc35eccb2007-04-26 15:58:49 -0700373
374 /* we'll need the file server record as that tells us which set of
375 * vnodes to operate upon */
David Howells001ab5a672018-05-11 23:21:35 +0100376 rcu_read_lock();
David Howellsa86b06d2018-05-11 23:45:40 +0100377 call->cm_server = afs_find_server_by_uuid(call->net, call->request);
David Howells001ab5a672018-05-11 23:21:35 +0100378 rcu_read_unlock();
David Howellsa86b06d2018-05-11 23:45:40 +0100379 if (!call->cm_server)
David Howells3709a392018-05-11 22:59:42 +0100380 trace_afs_cm_no_server_u(call, call->request);
David Howellsc35eccb2007-04-26 15:58:49 -0700381
David Howells341f7412017-01-05 10:38:36 +0000382 return afs_queue_call_work(call);
David Howellsc35eccb2007-04-26 15:58:49 -0700383}
384
385/*
David Howells08e0e7c2007-04-26 15:55:03 -0700386 * allow the fileserver to see if the cache manager is still alive
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 */
David Howells08e0e7c2007-04-26 15:55:03 -0700388static void SRXAFSCB_Probe(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
David Howells08e0e7c2007-04-26 15:55:03 -0700390 struct afs_call *call = container_of(work, struct afs_call, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
David Howells08e0e7c2007-04-26 15:55:03 -0700392 _enter("");
393 afs_send_empty_reply(call);
David Howells341f7412017-01-05 10:38:36 +0000394 afs_put_call(call);
David Howells08e0e7c2007-04-26 15:55:03 -0700395 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700396}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398/*
David Howells08e0e7c2007-04-26 15:55:03 -0700399 * deliver request data to a CB.Probe call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 */
David Howellsd0016482016-08-30 20:42:14 +0100401static int afs_deliver_cb_probe(struct afs_call *call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
David Howells372ee162016-08-03 14:11:40 +0100403 int ret;
404
David Howellsd0016482016-08-30 20:42:14 +0100405 _enter("");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
David Howellsd0016482016-08-30 20:42:14 +0100407 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100408 if (ret < 0)
409 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
David Howells98bf40c2017-11-02 15:27:53 +0000411 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
412 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
David Howells341f7412017-01-05 10:38:36 +0000414 return afs_queue_call_work(call);
David Howellsec268152007-04-26 15:49:28 -0700415}
David Howellsb908fe62007-04-26 15:58:17 -0700416
417/*
David Howells9396d492008-04-29 01:03:22 -0700418 * allow the fileserver to quickly find out if the fileserver has been rebooted
419 */
420static void SRXAFSCB_ProbeUuid(struct work_struct *work)
421{
422 struct afs_call *call = container_of(work, struct afs_call, work);
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300423 struct afs_uuid *r = call->request;
David Howells9396d492008-04-29 01:03:22 -0700424
425 struct {
426 __be32 match;
427 } reply;
428
429 _enter("");
430
David Howellsf044c882017-11-02 15:27:45 +0000431 if (memcmp(r, &call->net->uuid, sizeof(call->net->uuid)) == 0)
David Howells9396d492008-04-29 01:03:22 -0700432 reply.match = htonl(0);
433 else
434 reply.match = htonl(1);
435
436 afs_send_simple_reply(call, &reply, sizeof(reply));
David Howells341f7412017-01-05 10:38:36 +0000437 afs_put_call(call);
David Howells9396d492008-04-29 01:03:22 -0700438 _leave("");
439}
440
441/*
442 * deliver request data to a CB.ProbeUuid call
443 */
David Howellsd0016482016-08-30 20:42:14 +0100444static int afs_deliver_cb_probe_uuid(struct afs_call *call)
David Howells9396d492008-04-29 01:03:22 -0700445{
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300446 struct afs_uuid *r;
David Howells9396d492008-04-29 01:03:22 -0700447 unsigned loop;
448 __be32 *b;
449 int ret;
450
David Howellsd0016482016-08-30 20:42:14 +0100451 _enter("{%u}", call->unmarshall);
David Howells9396d492008-04-29 01:03:22 -0700452
453 switch (call->unmarshall) {
454 case 0:
455 call->offset = 0;
456 call->buffer = kmalloc(11 * sizeof(__be32), GFP_KERNEL);
457 if (!call->buffer)
458 return -ENOMEM;
459 call->unmarshall++;
460
461 case 1:
462 _debug("extract UUID");
David Howellsd0016482016-08-30 20:42:14 +0100463 ret = afs_extract_data(call, call->buffer,
464 11 * sizeof(__be32), false);
David Howells9396d492008-04-29 01:03:22 -0700465 switch (ret) {
466 case 0: break;
467 case -EAGAIN: return 0;
468 default: return ret;
469 }
470
471 _debug("unmarshall UUID");
Christoph Hellwig41bb26f2017-05-28 08:56:46 +0300472 call->request = kmalloc(sizeof(struct afs_uuid), GFP_KERNEL);
David Howells9396d492008-04-29 01:03:22 -0700473 if (!call->request)
474 return -ENOMEM;
475
476 b = call->buffer;
477 r = call->request;
David Howellsfe342cf2018-04-09 21:12:31 +0100478 r->time_low = b[0];
479 r->time_mid = htons(ntohl(b[1]));
480 r->time_hi_and_version = htons(ntohl(b[2]));
David Howells9396d492008-04-29 01:03:22 -0700481 r->clock_seq_hi_and_reserved = ntohl(b[3]);
482 r->clock_seq_low = ntohl(b[4]);
483
484 for (loop = 0; loop < 6; loop++)
485 r->node[loop] = ntohl(b[loop + 5]);
486
487 call->offset = 0;
488 call->unmarshall++;
489
490 case 2:
David Howells9396d492008-04-29 01:03:22 -0700491 break;
492 }
493
David Howells98bf40c2017-11-02 15:27:53 +0000494 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
495 return -EIO;
David Howells9396d492008-04-29 01:03:22 -0700496
David Howells341f7412017-01-05 10:38:36 +0000497 return afs_queue_call_work(call);
David Howells9396d492008-04-29 01:03:22 -0700498}
499
500/*
David Howellsb908fe62007-04-26 15:58:17 -0700501 * allow the fileserver to ask about the cache manager's capabilities
502 */
David Howells7c80bcc2008-04-29 01:03:21 -0700503static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work)
David Howellsb908fe62007-04-26 15:58:17 -0700504{
505 struct afs_interface *ifs;
506 struct afs_call *call = container_of(work, struct afs_call, work);
507 int loop, nifs;
508
509 struct {
510 struct /* InterfaceAddr */ {
511 __be32 nifs;
512 __be32 uuid[11];
513 __be32 ifaddr[32];
514 __be32 netmask[32];
515 __be32 mtu[32];
516 } ia;
517 struct /* Capabilities */ {
518 __be32 capcount;
519 __be32 caps[1];
520 } cap;
521 } reply;
522
523 _enter("");
524
525 nifs = 0;
526 ifs = kcalloc(32, sizeof(*ifs), GFP_KERNEL);
527 if (ifs) {
528 nifs = afs_get_ipv4_interfaces(ifs, 32, false);
529 if (nifs < 0) {
530 kfree(ifs);
531 ifs = NULL;
532 nifs = 0;
533 }
534 }
535
536 memset(&reply, 0, sizeof(reply));
537 reply.ia.nifs = htonl(nifs);
538
David Howellsf044c882017-11-02 15:27:45 +0000539 reply.ia.uuid[0] = call->net->uuid.time_low;
540 reply.ia.uuid[1] = htonl(ntohs(call->net->uuid.time_mid));
541 reply.ia.uuid[2] = htonl(ntohs(call->net->uuid.time_hi_and_version));
542 reply.ia.uuid[3] = htonl((s8) call->net->uuid.clock_seq_hi_and_reserved);
543 reply.ia.uuid[4] = htonl((s8) call->net->uuid.clock_seq_low);
David Howellsb908fe62007-04-26 15:58:17 -0700544 for (loop = 0; loop < 6; loop++)
David Howellsf044c882017-11-02 15:27:45 +0000545 reply.ia.uuid[loop + 5] = htonl((s8) call->net->uuid.node[loop]);
David Howellsb908fe62007-04-26 15:58:17 -0700546
547 if (ifs) {
548 for (loop = 0; loop < nifs; loop++) {
549 reply.ia.ifaddr[loop] = ifs[loop].address.s_addr;
550 reply.ia.netmask[loop] = ifs[loop].netmask.s_addr;
551 reply.ia.mtu[loop] = htonl(ifs[loop].mtu);
552 }
Patrick McHardy5b35fad2007-05-03 03:27:39 -0700553 kfree(ifs);
David Howellsb908fe62007-04-26 15:58:17 -0700554 }
555
556 reply.cap.capcount = htonl(1);
557 reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION);
558 afs_send_simple_reply(call, &reply, sizeof(reply));
David Howells341f7412017-01-05 10:38:36 +0000559 afs_put_call(call);
David Howellsb908fe62007-04-26 15:58:17 -0700560 _leave("");
561}
562
563/*
David Howells7c80bcc2008-04-29 01:03:21 -0700564 * deliver request data to a CB.TellMeAboutYourself call
David Howellsb908fe62007-04-26 15:58:17 -0700565 */
David Howellsd0016482016-08-30 20:42:14 +0100566static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call)
David Howellsb908fe62007-04-26 15:58:17 -0700567{
David Howells372ee162016-08-03 14:11:40 +0100568 int ret;
569
David Howellsd0016482016-08-30 20:42:14 +0100570 _enter("");
David Howellsb908fe62007-04-26 15:58:17 -0700571
David Howellsd0016482016-08-30 20:42:14 +0100572 ret = afs_extract_data(call, NULL, 0, false);
David Howells372ee162016-08-03 14:11:40 +0100573 if (ret < 0)
574 return ret;
David Howellsb908fe62007-04-26 15:58:17 -0700575
David Howells98bf40c2017-11-02 15:27:53 +0000576 if (!afs_check_call_state(call, AFS_CALL_SV_REPLYING))
577 return -EIO;
David Howellsb908fe62007-04-26 15:58:17 -0700578
David Howells341f7412017-01-05 10:38:36 +0000579 return afs_queue_call_work(call);
David Howellsb908fe62007-04-26 15:58:17 -0700580}