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