Linux Audio

Check our new training course

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