History

afs: Lay the groundwork for supporting network namespaces

Lay the groundwork for supporting network namespaces (netns) to the AFS filesystem by moving various global features to a network-namespace struct (afs_net) and providing an instance of this as a temporary global variable that everything uses via accessor functions for the moment. The following changes have been made: (1) Store the netns in the superblock info. This will be obtained from the mounter's nsproxy on a manual mount and inherited from the parent superblock on an automount. (2) The cell list is made per-netns. It can be viewed through /proc/net/afs/cells and also be modified by writing commands to that file. (3) The local workstation cell is set per-ns in /proc/net/afs/rootcell. This is unset by default. (4) The 'rootcell' module parameter, which sets a cell and VL server list modifies the init net namespace, thereby allowing an AFS root fs to be theoretically used. (5) The volume location lists and the file lock manager are made per-netns. (6) The AF_RXRPC socket and associated I/O bits are made per-ns. The various workqueues remain global for the moment. Changes still to be made: (1) /proc/fs/afs/ should be moved to /proc/net/afs/ and a symlink emplaced from the old name. (2) A per-netns subsys needs to be registered for AFS into which it can store its per-netns data. (3) Rather than the AF_RXRPC socket being opened on module init, it needs to be opened on the creation of a superblock in that netns. (4) The socket needs to be closed when the last superblock using it is destroyed and all outstanding client calls on it have been completed. This prevents a reference loop on the namespace. (5) It is possible that several namespaces will want to use AFS, in which case each one will need its own UDP port. These can either be set through /proc/net/afs/cm_port or the kernel can pick one at random. The init_ns gets 7001 by default. Other issues that need resolving: (1) The DNS keyring needs net-namespacing. (2) Where do upcalls go (eg. DNS request-key upcall)? (3) Need something like open_socket_in_file_ns() syscall so that AFS command line tools attempting to operate on an AFS file/volume have their RPC calls go to the right place.

David Howells committed 9 years ago

Commit f044c881 parent 5e4def216 files · +603 −492Browse files

Unified · Split

16 files
  1. fs/afs/afs.h +9 −0
  2. fs/afs/callback.c +2 −22
  3. fs/afs/cell.c +63 −67
  4. fs/afs/cmservice.c +13 −13
  5. fs/afs/flock.c +2 −37
  6. fs/afs/fsclient.c +37 −19
  7. fs/afs/internal.h +122 −41
  8. fs/afs/main.c +105 −48
  9. fs/afs/proc.c +40 −24
  10. fs/afs/rxrpc.c +65 −67
  11. fs/afs/server.c +39 −43
  12. fs/afs/super.c +26 −19
  13. fs/afs/vlclient.c +6 −4
  14. fs/afs/vlocation.c +68 −83
  15. fs/afs/volume.c +5 −5
  16. include/uapi/linux/magic.h +1 −0
fs/afs/afs.h+9−0
@@ -72,6 +72,15 @@ struct afs_callback { · 71 unmodified lines
7272
7373 #define AFSCBMAX 50 /* maximum callbacks transferred per bulk op */
7474
75+struct afs_uuid {
76+ __be32 time_low; /* low part of timestamp */
77+ __be16 time_mid; /* mid part of timestamp */
78+ __be16 time_hi_and_version; /* high part of timestamp and version */
79+ __u8 clock_seq_hi_and_reserved; /* clock seq hi and variant */
80+ __u8 clock_seq_low; /* clock seq low */
81+ __u8 node[6]; /* spatially unique node ID (MAC addr) */
82+};
83+
7584 /*
7685 * AFS volume information
7786 */
fs/afs/callback.c+2−22
@@ -28,9 +28,7 @@ unsigned afs_vnode_update_timeout = 10; · 27 unmodified lines
2828 CIRC_SPACE((server)->cb_break_head, (server)->cb_break_tail, \
2929 ARRAY_SIZE((server)->cb_break))
3030
31−//static void afs_callback_updater(struct work_struct *);
32−
33−static struct workqueue_struct *afs_callback_update_worker;
31+struct workqueue_struct *afs_callback_update_worker;
3432
3533 /*
3634 * allow the fileserver to request callback state (re-)initialisation
@@ -343,7 +341,7 @@ void afs_dispatch_give_up_callbacks(struct work_struct *work) · 306 unmodified lines
343341 * had callbacks entirely, and the server will call us later to break
344342 * them
345343 */
346− afs_fs_give_up_callbacks(server, true);
344+ afs_fs_give_up_callbacks(server->cell->net, server, true);
347345 }
348346
349347 /*
@@ -456,21 +454,3 @@ static void afs_callback_updater(struct work_struct *work) · 106 unmodified lines
456454 afs_put_vnode(vl);
457455 }
458456 #endif
459−
460−/*
461− * initialise the callback update process
462− */
463−int __init afs_callback_update_init(void)
464−{
465− afs_callback_update_worker = alloc_ordered_workqueue("kafs_callbackd",
466− WQ_MEM_RECLAIM);
467− return afs_callback_update_worker ? 0 : -ENOMEM;
468−}
469−
470−/*
471− * shut down the callback update process
472− */
473−void afs_callback_update_kill(void)
474−{
475− destroy_workqueue(afs_callback_update_worker);
476−}
fs/afs/cell.c+63−67
@@ -18,20 +18,12 @@ · 17 unmodified lines
1818 #include <keys/rxrpc-type.h>
1919 #include "internal.h"
2020
21−DECLARE_RWSEM(afs_proc_cells_sem);
22−LIST_HEAD(afs_proc_cells);
23−
24−static LIST_HEAD(afs_cells);
25−static DEFINE_RWLOCK(afs_cells_lock);
26−static DECLARE_RWSEM(afs_cells_sem); /* add/remove serialisation */
27−static DECLARE_WAIT_QUEUE_HEAD(afs_cells_freeable_wq);
28−static struct afs_cell *afs_cell_root;
29−
3021 /*
3122 * allocate a cell record and fill in its name, VL server address list and
3223 * allocate an anonymous key
3324 */
34−static struct afs_cell *afs_cell_alloc(const char *name, unsigned namelen,
25+static struct afs_cell *afs_cell_alloc(struct afs_net *net,
26+ const char *name, unsigned namelen,
3527 char *vllist)
3628 {
3729 struct afs_cell *cell;
@@ -62,6 +54,7 @@ static struct afs_cell *afs_cell_alloc(const char *name, unsigned namelen, · 24 unmodified lines
6254
6355 atomic_set(&cell->usage, 1);
6456 INIT_LIST_HEAD(&cell->link);
57+ cell->net = net;
6558 rwlock_init(&cell->servers_lock);
6659 INIT_LIST_HEAD(&cell->servers);
6760 init_rwsem(&cell->vl_sem);
@@ -142,12 +135,14 @@ error: · 74 unmodified lines
142135
143136 /*
144137 * afs_cell_crate() - create a cell record
138+ * @net: The network namespace
145139 * @name: is the name of the cell.
146140 * @namsesz: is the strlen of the cell name.
147141 * @vllist: is a colon separated list of IP addresses in "a.b.c.d" format.
148142 * @retref: is T to return the cell reference when the cell exists.
149143 */
150−struct afs_cell *afs_cell_create(const char *name, unsigned namesz,
144+struct afs_cell *afs_cell_create(struct afs_net *net,
145+ const char *name, unsigned namesz,
151146 char *vllist, bool retref)
152147 {
153148 struct afs_cell *cell;
@@ -155,23 +150,23 @@ struct afs_cell *afs_cell_create(const char *name, unsigned namesz, · 1 unmodified line
155150
156151 _enter("%*.*s,%s", namesz, namesz, name ?: "", vllist);
157152
158− down_write(&afs_cells_sem);
159− read_lock(&afs_cells_lock);
160− list_for_each_entry(cell, &afs_cells, link) {
153+ down_write(&net->cells_sem);
154+ read_lock(&net->cells_lock);
155+ list_for_each_entry(cell, &net->cells, link) {
161156 if (strncasecmp(cell->name, name, namesz) == 0)
162157 goto duplicate_name;
163158 }
164− read_unlock(&afs_cells_lock);
159+ read_unlock(&net->cells_lock);
165160
166− cell = afs_cell_alloc(name, namesz, vllist);
161+ cell = afs_cell_alloc(net, name, namesz, vllist);
167162 if (IS_ERR(cell)) {
168163 _leave(" = %ld", PTR_ERR(cell));
169− up_write(&afs_cells_sem);
164+ up_write(&net->cells_sem);
170165 return cell;
171166 }
172167
173168 /* add a proc directory for this cell */
174− ret = afs_proc_cell_setup(cell);
169+ ret = afs_proc_cell_setup(net, cell);
175170 if (ret < 0)
176171 goto error;
177172
@@ -183,20 +178,20 @@ struct afs_cell *afs_cell_create(const char *name, unsigned namesz, · 5 unmodified lines
183178 #endif
184179
185180 /* add to the cell lists */
186− write_lock(&afs_cells_lock);
187− list_add_tail(&cell->link, &afs_cells);
188− write_unlock(&afs_cells_lock);
181+ write_lock(&net->cells_lock);
182+ list_add_tail(&cell->link, &net->cells);
183+ write_unlock(&net->cells_lock);
189184
190− down_write(&afs_proc_cells_sem);
191− list_add_tail(&cell->proc_link, &afs_proc_cells);
192− up_write(&afs_proc_cells_sem);
193− up_write(&afs_cells_sem);
185+ down_write(&net->proc_cells_sem);
186+ list_add_tail(&cell->proc_link, &net->proc_cells);
187+ up_write(&net->proc_cells_sem);
188+ up_write(&net->cells_sem);
194189
195190 _leave(" = %p", cell);
196191 return cell;
197192
198193 error:
199− up_write(&afs_cells_sem);
194+ up_write(&net->cells_sem);
200195 key_put(cell->anonymous_key);
201196 kfree(cell);
202197 _leave(" = %d", ret);
@@ -206,8 +201,8 @@ duplicate_name: · 3 unmodified lines
206201 if (retref && !IS_ERR(cell))
207202 afs_get_cell(cell);
208203
209− read_unlock(&afs_cells_lock);
210− up_write(&afs_cells_sem);
204+ read_unlock(&net->cells_lock);
205+ up_write(&net->cells_sem);
211206
212207 if (retref) {
213208 _leave(" = %p", cell);
@@ -223,7 +218,7 @@ duplicate_name: · 9 unmodified lines
223218 * - can be called with a module parameter string
224219 * - can be called from a write to /proc/fs/afs/rootcell
225220 */
226−int afs_cell_init(char *rootcell)
221+int afs_cell_init(struct afs_net *net, char *rootcell)
227222 {
228223 struct afs_cell *old_root, *new_root;
229224 char *cp;
@@ -245,17 +240,17 @@ int afs_cell_init(char *rootcell) · 15 unmodified lines
245240 *cp++ = 0;
246241
247242 /* allocate a cell record for the root cell */
248− new_root = afs_cell_create(rootcell, strlen(rootcell), cp, false);
243+ new_root = afs_cell_create(net, rootcell, strlen(rootcell), cp, false);
249244 if (IS_ERR(new_root)) {
250245 _leave(" = %ld", PTR_ERR(new_root));
251246 return PTR_ERR(new_root);
252247 }
253248
254249 /* install the new cell */
255− write_lock(&afs_cells_lock);
256− old_root = afs_cell_root;
257− afs_cell_root = new_root;
258− write_unlock(&afs_cells_lock);
250+ write_lock(&net->cells_lock);
251+ old_root = net->ws_cell;
252+ net->ws_cell = new_root;
253+ write_unlock(&net->cells_lock);
259254 afs_put_cell(old_root);
260255
261256 _leave(" = 0");
@@ -265,19 +260,20 @@ int afs_cell_init(char *rootcell) · 3 unmodified lines
265260 /*
266261 * lookup a cell record
267262 */
268−struct afs_cell *afs_cell_lookup(const char *name, unsigned namesz,
263+struct afs_cell *afs_cell_lookup(struct afs_net *net,
264+ const char *name, unsigned namesz,
269265 bool dns_cell)
270266 {
271267 struct afs_cell *cell;
272268
273269 _enter("\"%*.*s\",", namesz, namesz, name ?: "");
274270
275− down_read(&afs_cells_sem);
276− read_lock(&afs_cells_lock);
271+ down_read(&net->cells_sem);
272+ read_lock(&net->cells_lock);
277273
278274 if (name) {
279275 /* if the cell was named, look for it in the cell record list */
280− list_for_each_entry(cell, &afs_cells, link) {
276+ list_for_each_entry(cell, &net->cells, link) {
281277 if (strncmp(cell->name, name, namesz) == 0) {
282278 afs_get_cell(cell);
283279 goto found;
@@ -289,7 +285,7 @@ struct afs_cell *afs_cell_lookup(const char *name, unsigned namesz, · 5 unmodified lines
289285 found:
290286 ;
291287 } else {
292− cell = afs_cell_root;
288+ cell = net->ws_cell;
293289 if (!cell) {
294290 /* this should not happen unless user tries to mount
295291 * when root cell is not set. Return an impossibly
@@ -304,16 +300,16 @@ struct afs_cell *afs_cell_lookup(const char *name, unsigned namesz, · 8 unmodified lines
304300
305301 }
306302
307− read_unlock(&afs_cells_lock);
308− up_read(&afs_cells_sem);
303+ read_unlock(&net->cells_lock);
304+ up_read(&net->cells_sem);
309305 _leave(" = %p", cell);
310306 return cell;
311307
312308 create_cell:
313− read_unlock(&afs_cells_lock);
314− up_read(&afs_cells_sem);
309+ read_unlock(&net->cells_lock);
310+ up_read(&net->cells_sem);
315311
316− cell = afs_cell_create(name, namesz, NULL, true);
312+ cell = afs_cell_create(net, name, namesz, NULL, true);
317313
318314 _leave(" = %p", cell);
319315 return cell;
@@ -325,14 +321,14 @@ create_cell: · 5 unmodified lines
325321 */
326322 struct afs_cell *afs_get_cell_maybe(struct afs_cell *cell)
327323 {
328− write_lock(&afs_cells_lock);
324+ write_lock(&net->cells_lock);
329325
330326 if (cell && !list_empty(&cell->link))
331327 afs_get_cell(cell);
332328 else
333329 cell = NULL;
334330
335− write_unlock(&afs_cells_lock);
331+ write_unlock(&net->cells_lock);
336332 return cell;
337333 }
338334 #endif /* 0 */
@@ -351,10 +347,10 @@ void afs_put_cell(struct afs_cell *cell) · 12 unmodified lines
351347
352348 /* to prevent a race, the decrement and the dequeue must be effectively
353349 * atomic */
354− write_lock(&afs_cells_lock);
350+ write_lock(&cell->net->cells_lock);
355351
356352 if (likely(!atomic_dec_and_test(&cell->usage))) {
357− write_unlock(&afs_cells_lock);
353+ write_unlock(&cell->net->cells_lock);
358354 _leave("");
359355 return;
360356 }
@@ -362,19 +358,19 @@ void afs_put_cell(struct afs_cell *cell) · 1 unmodified line
362358 ASSERT(list_empty(&cell->servers));
363359 ASSERT(list_empty(&cell->vl_list));
364360
365− write_unlock(&afs_cells_lock);
361+ wake_up(&cell->net->cells_freeable_wq);
366362
367− wake_up(&afs_cells_freeable_wq);
363+ write_unlock(&cell->net->cells_lock);
368364
369365 _leave(" [unused]");
370366 }
371367
372368 /*
373369 * destroy a cell record
374− * - must be called with the afs_cells_sem write-locked
370+ * - must be called with the net->cells_sem write-locked
375371 * - cell->link should have been broken by the caller
376372 */
377−static void afs_cell_destroy(struct afs_cell *cell)
373+static void afs_cell_destroy(struct afs_net *net, struct afs_cell *cell)
378374 {
379375 _enter("%p{%d,%s}", cell, atomic_read(&cell->usage), cell->name);
380376
@@ -387,14 +383,14 @@ static void afs_cell_destroy(struct afs_cell *cell) · 6 unmodified lines
387383
388384 _debug("wait for cell %s", cell->name);
389385 set_current_state(TASK_UNINTERRUPTIBLE);
390− add_wait_queue(&afs_cells_freeable_wq, &myself);
386+ add_wait_queue(&net->cells_freeable_wq, &myself);
391387
392388 while (atomic_read(&cell->usage) > 0) {
393389 schedule();
394390 set_current_state(TASK_UNINTERRUPTIBLE);
395391 }
396392
397− remove_wait_queue(&afs_cells_freeable_wq, &myself);
393+ remove_wait_queue(&net->cells_freeable_wq, &myself);
398394 set_current_state(TASK_RUNNING);
399395 }
400396
@@ -403,11 +399,11 @@ static void afs_cell_destroy(struct afs_cell *cell) · 2 unmodified lines
403399 ASSERT(list_empty(&cell->servers));
404400 ASSERT(list_empty(&cell->vl_list));
405401
406− afs_proc_cell_remove(cell);
402+ afs_proc_cell_remove(net, cell);
407403
408− down_write(&afs_proc_cells_sem);
404+ down_write(&net->proc_cells_sem);
409405 list_del_init(&cell->proc_link);
410− up_write(&afs_proc_cells_sem);
406+ up_write(&net->proc_cells_sem);
411407
412408 #ifdef CONFIG_AFS_FSCACHE
413409 fscache_relinquish_cookie(cell->cache, 0);
@@ -422,39 +418,39 @@ static void afs_cell_destroy(struct afs_cell *cell) · 8 unmodified lines
422418 * purge in-memory cell database on module unload or afs_init() failure
423419 * - the timeout daemon is stopped before calling this
424420 */
425−void afs_cell_purge(void)
421+void afs_cell_purge(struct afs_net *net)
426422 {
427423 struct afs_cell *cell;
428424
429425 _enter("");
430426
431− afs_put_cell(afs_cell_root);
427+ afs_put_cell(net->ws_cell);
432428
433− down_write(&afs_cells_sem);
429+ down_write(&net->cells_sem);
434430
435− while (!list_empty(&afs_cells)) {
431+ while (!list_empty(&net->cells)) {
436432 cell = NULL;
437433
438434 /* remove the next cell from the front of the list */
439− write_lock(&afs_cells_lock);
435+ write_lock(&net->cells_lock);
440436
441− if (!list_empty(&afs_cells)) {
442− cell = list_entry(afs_cells.next,
437+ if (!list_empty(&net->cells)) {
438+ cell = list_entry(net->cells.next,
443439 struct afs_cell, link);
444440 list_del_init(&cell->link);
445441 }
446442
447− write_unlock(&afs_cells_lock);
443+ write_unlock(&net->cells_lock);
448444
449445 if (cell) {
450446 _debug("PURGING CELL %s (%d)",
451447 cell->name, atomic_read(&cell->usage));
452448
453449 /* now the cell should be left with no references */
454− afs_cell_destroy(cell);
450+ afs_cell_destroy(net, cell);
455451 }
456452 }
457453
458− up_write(&afs_cells_sem);
454+ up_write(&net->cells_sem);
459455 _leave("");
460456 }
fs/afs/cmservice.c+13−13
@@ -193,7 +193,7 @@ static int afs_deliver_cb_callback(struct afs_call *call) · 192 unmodified lines
193193
194194 switch (call->unmarshall) {
195195 case 0:
196− rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx);
196+ rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
197197 call->offset = 0;
198198 call->unmarshall++;
199199
@@ -290,7 +290,7 @@ static int afs_deliver_cb_callback(struct afs_call *call) · 90 unmodified lines
290290
291291 /* we'll need the file server record as that tells us which set of
292292 * vnodes to operate upon */
293− server = afs_find_server(&srx);
293+ server = afs_find_server(call->net, &srx);
294294 if (!server)
295295 return -ENOTCONN;
296296 call->server = server;
@@ -324,7 +324,7 @@ static int afs_deliver_cb_init_call_back_state(struct afs_call *call) · 27 unmodified lines
324324
325325 _enter("");
326326
327− rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx);
327+ rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
328328
329329 ret = afs_extract_data(call, NULL, 0, false);
330330 if (ret < 0)
@@ -335,7 +335,7 @@ static int afs_deliver_cb_init_call_back_state(struct afs_call *call) · 4 unmodified lines
335335
336336 /* we'll need the file server record as that tells us which set of
337337 * vnodes to operate upon */
338− server = afs_find_server(&srx);
338+ server = afs_find_server(call->net, &srx);
339339 if (!server)
340340 return -ENOTCONN;
341341 call->server = server;
@@ -357,7 +357,7 @@ static int afs_deliver_cb_init_call_back_state3(struct afs_call *call) · 15 unmodified lines
357357
358358 _enter("");
359359
360− rxrpc_kernel_get_peer(afs_socket, call->rxcall, &srx);
360+ rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);
361361
362362 _enter("{%u}", call->unmarshall);
363363
@@ -407,7 +407,7 @@ static int afs_deliver_cb_init_call_back_state3(struct afs_call *call) · 43 unmodified lines
407407
408408 /* we'll need the file server record as that tells us which set of
409409 * vnodes to operate upon */
410− server = afs_find_server(&srx);
410+ server = afs_find_server(call->net, &srx);
411411 if (!server)
412412 return -ENOTCONN;
413413 call->server = server;
@@ -461,7 +461,7 @@ static void SRXAFSCB_ProbeUuid(struct work_struct *work) · 47 unmodified lines
461461
462462 _enter("");
463463
464− if (memcmp(r, &afs_uuid, sizeof(afs_uuid)) == 0)
464+ if (memcmp(r, &call->net->uuid, sizeof(call->net->uuid)) == 0)
465465 reply.match = htonl(0);
466466 else
467467 reply.match = htonl(1);
@@ -568,13 +568,13 @@ static void SRXAFSCB_TellMeAboutYourself(struct work_struct *work) · 100 unmodified lines
568568 memset(&reply, 0, sizeof(reply));
569569 reply.ia.nifs = htonl(nifs);
570570
571− reply.ia.uuid[0] = afs_uuid.time_low;
572− reply.ia.uuid[1] = htonl(ntohs(afs_uuid.time_mid));
573− reply.ia.uuid[2] = htonl(ntohs(afs_uuid.time_hi_and_version));
574− reply.ia.uuid[3] = htonl((s8) afs_uuid.clock_seq_hi_and_reserved);
575− reply.ia.uuid[4] = htonl((s8) afs_uuid.clock_seq_low);
571+ reply.ia.uuid[0] = call->net->uuid.time_low;
572+ reply.ia.uuid[1] = htonl(ntohs(call->net->uuid.time_mid));
573+ reply.ia.uuid[2] = htonl(ntohs(call->net->uuid.time_hi_and_version));
574+ reply.ia.uuid[3] = htonl((s8) call->net->uuid.clock_seq_hi_and_reserved);
575+ reply.ia.uuid[4] = htonl((s8) call->net->uuid.clock_seq_low);
576576 for (loop = 0; loop < 6; loop++)
577− reply.ia.uuid[loop + 5] = htonl((s8) afs_uuid.node[loop]);
577+ reply.ia.uuid[loop + 5] = htonl((s8) call->net->uuid.node[loop]);
578578
579579 if (ifs) {
580580 for (loop = 0; loop < nifs; loop++) {
fs/afs/flock.c+2−37
@@ -14,47 +14,16 @@ · 13 unmodified lines
1414 #define AFS_LOCK_GRANTED 0
1515 #define AFS_LOCK_PENDING 1
1616
17+struct workqueue_struct *afs_lock_manager;
18+
1719 static void afs_fl_copy_lock(struct file_lock *new, struct file_lock *fl);
1820 static void afs_fl_release_private(struct file_lock *fl);
1921
20−static struct workqueue_struct *afs_lock_manager;
21−static DEFINE_MUTEX(afs_lock_manager_mutex);
22−
2322 static const struct file_lock_operations afs_lock_ops = {
2423 .fl_copy_lock = afs_fl_copy_lock,
2524 .fl_release_private = afs_fl_release_private,
2625 };
2726
28−/*
29− * initialise the lock manager thread if it isn't already running
30− */
31−static int afs_init_lock_manager(void)
32−{
33− int ret;
34−
35− ret = 0;
36− if (!afs_lock_manager) {
37− mutex_lock(&afs_lock_manager_mutex);
38− if (!afs_lock_manager) {
39− afs_lock_manager = alloc_workqueue("kafs_lockd",
40− WQ_MEM_RECLAIM, 0);
41− if (!afs_lock_manager)
42− ret = -ENOMEM;
43− }
44− mutex_unlock(&afs_lock_manager_mutex);
45− }
46− return ret;
47−}
48−
49−/*
50− * destroy the lock manager thread if it's running
51− */
52−void __exit afs_kill_lock_manager(void)
53−{
54− if (afs_lock_manager)
55− destroy_workqueue(afs_lock_manager);
56−}
57−
5827 /*
5928 * if the callback is broken on this vnode, then the lock may now be available
6029 */
@@ -264,10 +233,6 @@ static int afs_do_setlk(struct file *file, struct file_lock *fl) · 203 unmodified lines
264233 if (fl->fl_start != 0 || fl->fl_end != OFFSET_MAX)
265234 return -EINVAL;
266235
267− ret = afs_init_lock_manager();
268− if (ret < 0)
269− return ret;
270−
271236 fl->fl_ops = &afs_lock_ops;
272237 INIT_LIST_HEAD(&fl->fl_u.afs.link);
273238 fl->fl_u.afs.state = AFS_LOCK_PENDING;
fs/afs/fsclient.c+37−19
@@ -284,12 +284,13 @@ int afs_fs_fetch_file_status(struct afs_server *server, · 283 unmodified lines
284284 bool async)
285285 {
286286 struct afs_call *call;
287+ struct afs_net *net = afs_v2net(vnode);
287288 __be32 *bp;
288289
289290 _enter(",%x,{%x:%u},,",
290291 key_serial(key), vnode->fid.vid, vnode->fid.vnode);
291292
292− call = afs_alloc_flat_call(&afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
293+ call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
293294 if (!call)
294295 return -ENOMEM;
295296
@@ -490,11 +491,12 @@ static int afs_fs_fetch_data64(struct afs_server *server, · 194 unmodified lines
490491 bool async)
491492 {
492493 struct afs_call *call;
494+ struct afs_net *net = afs_v2net(vnode);
493495 __be32 *bp;
494496
495497 _enter("");
496498
497− call = afs_alloc_flat_call(&afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
499+ call = afs_alloc_flat_call(net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
498500 if (!call)
499501 return -ENOMEM;
500502
@@ -531,6 +533,7 @@ int afs_fs_fetch_data(struct afs_server *server, · 30 unmodified lines
531533 bool async)
532534 {
533535 struct afs_call *call;
536+ struct afs_net *net = afs_v2net(vnode);
534537 __be32 *bp;
535538
536539 if (upper_32_bits(req->pos) ||
@@ -540,7 +543,7 @@ int afs_fs_fetch_data(struct afs_server *server, · 3 unmodified lines
540543
541544 _enter("");
542545
543− call = afs_alloc_flat_call(&afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
546+ call = afs_alloc_flat_call(net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
544547 if (!call)
545548 return -ENOMEM;
546549
@@ -590,7 +593,8 @@ static const struct afs_call_type afs_RXFSGiveUpCallBacks = { · 43 unmodified lines
590593 * give up a set of callbacks
591594 * - the callbacks are held in the server->cb_break ring
592595 */
593−int afs_fs_give_up_callbacks(struct afs_server *server,
596+int afs_fs_give_up_callbacks(struct afs_net *net,
597+ struct afs_server *server,
594598 bool async)
595599 {
596600 struct afs_call *call;
@@ -610,7 +614,7 @@ int afs_fs_give_up_callbacks(struct afs_server *server, · 13 unmodified lines
610614
611615 _debug("break %zu callbacks", ncallbacks);
612616
613− call = afs_alloc_flat_call(&afs_RXFSGiveUpCallBacks,
617+ call = afs_alloc_flat_call(net, &afs_RXFSGiveUpCallBacks,
614618 12 + ncallbacks * 6 * 4, 0);
615619 if (!call)
616620 return -ENOMEM;
@@ -699,6 +703,7 @@ int afs_fs_create(struct afs_server *server, · 82 unmodified lines
699703 bool async)
700704 {
701705 struct afs_call *call;
706+ struct afs_net *net = afs_v2net(vnode);
702707 size_t namesz, reqsz, padsz;
703708 __be32 *bp;
704709
@@ -708,7 +713,7 @@ int afs_fs_create(struct afs_server *server, · 3 unmodified lines
708713 padsz = (4 - (namesz & 3)) & 3;
709714 reqsz = (5 * 4) + namesz + padsz + (6 * 4);
710715
711− call = afs_alloc_flat_call(&afs_RXFSCreateXXXX, reqsz,
716+ call = afs_alloc_flat_call(net, &afs_RXFSCreateXXXX, reqsz,
712717 (3 + 21 + 21 + 3 + 6) * 4);
713718 if (!call)
714719 return -ENOMEM;
@@ -789,6 +794,7 @@ int afs_fs_remove(struct afs_server *server, · 74 unmodified lines
789794 bool async)
790795 {
791796 struct afs_call *call;
797+ struct afs_net *net = afs_v2net(vnode);
792798 size_t namesz, reqsz, padsz;
793799 __be32 *bp;
794800
@@ -798,7 +804,7 @@ int afs_fs_remove(struct afs_server *server, · 3 unmodified lines
798804 padsz = (4 - (namesz & 3)) & 3;
799805 reqsz = (5 * 4) + namesz + padsz;
800806
801− call = afs_alloc_flat_call(&afs_RXFSRemoveXXXX, reqsz, (21 + 6) * 4);
807+ call = afs_alloc_flat_call(net, &afs_RXFSRemoveXXXX, reqsz, (21 + 6) * 4);
802808 if (!call)
803809 return -ENOMEM;
804810
@@ -870,6 +876,7 @@ int afs_fs_link(struct afs_server *server, · 65 unmodified lines
870876 bool async)
871877 {
872878 struct afs_call *call;
879+ struct afs_net *net = afs_v2net(vnode);
873880 size_t namesz, reqsz, padsz;
874881 __be32 *bp;
875882
@@ -879,7 +886,7 @@ int afs_fs_link(struct afs_server *server, · 3 unmodified lines
879886 padsz = (4 - (namesz & 3)) & 3;
880887 reqsz = (5 * 4) + namesz + padsz + (3 * 4);
881888
882− call = afs_alloc_flat_call(&afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
889+ call = afs_alloc_flat_call(net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
883890 if (!call)
884891 return -ENOMEM;
885892
@@ -958,6 +965,7 @@ int afs_fs_symlink(struct afs_server *server, · 72 unmodified lines
958965 bool async)
959966 {
960967 struct afs_call *call;
968+ struct afs_net *net = afs_v2net(vnode);
961969 size_t namesz, reqsz, padsz, c_namesz, c_padsz;
962970 __be32 *bp;
963971
@@ -971,7 +979,7 @@ int afs_fs_symlink(struct afs_server *server, · 7 unmodified lines
971979
972980 reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
973981
974− call = afs_alloc_flat_call(&afs_RXFSSymlink, reqsz,
982+ call = afs_alloc_flat_call(net, &afs_RXFSSymlink, reqsz,
975983 (3 + 21 + 21 + 6) * 4);
976984 if (!call)
977985 return -ENOMEM;
@@ -1062,6 +1070,7 @@ int afs_fs_rename(struct afs_server *server, · 84 unmodified lines
10621070 bool async)
10631071 {
10641072 struct afs_call *call;
1073+ struct afs_net *net = afs_v2net(orig_dvnode);
10651074 size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
10661075 __be32 *bp;
10671076
@@ -1078,7 +1087,7 @@ int afs_fs_rename(struct afs_server *server, · 10 unmodified lines
10781087 (3 * 4) +
10791088 4 + n_namesz + n_padsz;
10801089
1081− call = afs_alloc_flat_call(&afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
1090+ call = afs_alloc_flat_call(net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
10821091 if (!call)
10831092 return -ENOMEM;
10841093
@@ -1172,12 +1181,13 @@ static int afs_fs_store_data64(struct afs_server *server, · 87 unmodified lines
11721181 {
11731182 struct afs_vnode *vnode = wb->vnode;
11741183 struct afs_call *call;
1184+ struct afs_net *net = afs_v2net(vnode);
11751185 __be32 *bp;
11761186
11771187 _enter(",%x,{%x:%u},,",
11781188 key_serial(wb->key), vnode->fid.vid, vnode->fid.vnode);
11791189
1180− call = afs_alloc_flat_call(&afs_RXFSStoreData64,
1190+ call = afs_alloc_flat_call(net, &afs_RXFSStoreData64,
11811191 (4 + 6 + 3 * 2) * 4,
11821192 (21 + 6) * 4);
11831193 if (!call)
@@ -1230,6 +1240,7 @@ int afs_fs_store_data(struct afs_server *server, struct afs_writeback *wb, · 46 unmodified lines
12301240 {
12311241 struct afs_vnode *vnode = wb->vnode;
12321242 struct afs_call *call;
1243+ struct afs_net *net = afs_v2net(vnode);
12331244 loff_t size, pos, i_size;
12341245 __be32 *bp;
12351246
@@ -1254,7 +1265,7 @@ int afs_fs_store_data(struct afs_server *server, struct afs_writeback *wb, · 18 unmodified lines
12541265 return afs_fs_store_data64(server, wb, first, last, offset, to,
12551266 size, pos, i_size, async);
12561267
1257− call = afs_alloc_flat_call(&afs_RXFSStoreData,
1268+ call = afs_alloc_flat_call(net, &afs_RXFSStoreData,
12581269 (4 + 6 + 3) * 4,
12591270 (21 + 6) * 4);
12601271 if (!call)
@@ -1356,6 +1367,7 @@ static int afs_fs_setattr_size64(struct afs_server *server, struct key *key, · 95 unmodified lines
13561367 bool async)
13571368 {
13581369 struct afs_call *call;
1370+ struct afs_net *net = afs_v2net(vnode);
13591371 __be32 *bp;
13601372
13611373 _enter(",%x,{%x:%u},,",
@@ -1363,7 +1375,7 @@ static int afs_fs_setattr_size64(struct afs_server *server, struct key *key, · 1 unmodified line
13631375
13641376 ASSERT(attr->ia_valid & ATTR_SIZE);
13651377
1366− call = afs_alloc_flat_call(&afs_RXFSStoreData64_as_Status,
1378+ call = afs_alloc_flat_call(net, &afs_RXFSStoreData64_as_Status,
13671379 (4 + 6 + 3 * 2) * 4,
13681380 (21 + 6) * 4);
13691381 if (!call)
@@ -1404,6 +1416,7 @@ static int afs_fs_setattr_size(struct afs_server *server, struct key *key, · 34 unmodified lines
14041416 bool async)
14051417 {
14061418 struct afs_call *call;
1419+ struct afs_net *net = afs_v2net(vnode);
14071420 __be32 *bp;
14081421
14091422 _enter(",%x,{%x:%u},,",
@@ -1414,7 +1427,7 @@ static int afs_fs_setattr_size(struct afs_server *server, struct key *key, · 4 unmodified lines
14141427 return afs_fs_setattr_size64(server, key, vnode, attr,
14151428 async);
14161429
1417− call = afs_alloc_flat_call(&afs_RXFSStoreData_as_Status,
1430+ call = afs_alloc_flat_call(net, &afs_RXFSStoreData_as_Status,
14181431 (4 + 6 + 3) * 4,
14191432 (21 + 6) * 4);
14201433 if (!call)
@@ -1452,6 +1465,7 @@ int afs_fs_setattr(struct afs_server *server, struct key *key, · 31 unmodified lines
14521465 bool async)
14531466 {
14541467 struct afs_call *call;
1468+ struct afs_net *net = afs_v2net(vnode);
14551469 __be32 *bp;
14561470
14571471 if (attr->ia_valid & ATTR_SIZE)
@@ -1461,7 +1475,7 @@ int afs_fs_setattr(struct afs_server *server, struct key *key, · 3 unmodified lines
14611475 _enter(",%x,{%x:%u},,",
14621476 key_serial(key), vnode->fid.vid, vnode->fid.vnode);
14631477
1464− call = afs_alloc_flat_call(&afs_RXFSStoreStatus,
1478+ call = afs_alloc_flat_call(net, &afs_RXFSStoreStatus,
14651479 (4 + 6) * 4,
14661480 (21 + 6) * 4);
14671481 if (!call)
@@ -1687,6 +1701,7 @@ int afs_fs_get_volume_status(struct afs_server *server, · 219 unmodified lines
16871701 bool async)
16881702 {
16891703 struct afs_call *call;
1704+ struct afs_net *net = afs_v2net(vnode);
16901705 __be32 *bp;
16911706 void *tmpbuf;
16921707
@@ -1696,7 +1711,7 @@ int afs_fs_get_volume_status(struct afs_server *server, · 3 unmodified lines
16961711 if (!tmpbuf)
16971712 return -ENOMEM;
16981713
1699− call = afs_alloc_flat_call(&afs_RXFSGetVolumeStatus, 2 * 4, 12 * 4);
1714+ call = afs_alloc_flat_call(net, &afs_RXFSGetVolumeStatus, 2 * 4, 12 * 4);
17001715 if (!call) {
17011716 kfree(tmpbuf);
17021717 return -ENOMEM;
@@ -1779,11 +1794,12 @@ int afs_fs_set_lock(struct afs_server *server, · 76 unmodified lines
17791794 bool async)
17801795 {
17811796 struct afs_call *call;
1797+ struct afs_net *net = afs_v2net(vnode);
17821798 __be32 *bp;
17831799
17841800 _enter("");
17851801
1786− call = afs_alloc_flat_call(&afs_RXFSSetLock, 5 * 4, 6 * 4);
1802+ call = afs_alloc_flat_call(net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
17871803 if (!call)
17881804 return -ENOMEM;
17891805
@@ -1812,11 +1828,12 @@ int afs_fs_extend_lock(struct afs_server *server, · 22 unmodified lines
18121828 bool async)
18131829 {
18141830 struct afs_call *call;
1831+ struct afs_net *net = afs_v2net(vnode);
18151832 __be32 *bp;
18161833
18171834 _enter("");
18181835
1819− call = afs_alloc_flat_call(&afs_RXFSExtendLock, 4 * 4, 6 * 4);
1836+ call = afs_alloc_flat_call(net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
18201837 if (!call)
18211838 return -ENOMEM;
18221839
@@ -1844,11 +1861,12 @@ int afs_fs_release_lock(struct afs_server *server, · 21 unmodified lines
18441861 bool async)
18451862 {
18461863 struct afs_call *call;
1864+ struct afs_net *net = afs_v2net(vnode);
18471865 __be32 *bp;
18481866
18491867 _enter("");
18501868
1851− call = afs_alloc_flat_call(&afs_RXFSReleaseLock, 4 * 4, 6 * 4);
1869+ call = afs_alloc_flat_call(net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
18521870 if (!call)
18531871 return -ENOMEM;
18541872
fs/afs/internal.h+122−41
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121 #include <linux/fscache.h>
2222 #include <linux/backing-dev.h>
2323 #include <linux/uuid.h>
24+#include <net/net_namespace.h>
2425 #include <net/af_rxrpc.h>
2526
2627 #include "afs.h"
@@ -48,6 +49,7 @@ struct afs_mount_params { · 21 unmodified lines
4849 afs_voltype_t type; /* type of volume requested */
4950 int volnamesz; /* size of volume name */
5051 const char *volname; /* name of volume to mount */
52+ struct afs_net *net; /* Network namespace in effect */
5153 struct afs_cell *cell; /* cell in which to find volume */
5254 struct afs_volume *volume; /* volume record */
5355 struct key *key; /* key to use for secure mounting */
@@ -62,6 +64,7 @@ enum afs_call_state { · 8 unmodified lines
6264 AFS_CALL_AWAIT_ACK, /* awaiting final ACK of incoming call */
6365 AFS_CALL_COMPLETE, /* Completed or failed */
6466 };
67+
6568 /*
6669 * a record of an in-progress RxRPC call
6770 */
@@ -72,6 +75,7 @@ struct afs_call { · 4 unmodified lines
7275 struct work_struct work; /* actual work processor */
7376 struct rxrpc_call *rxcall; /* RxRPC call handle */
7477 struct key *key; /* security for this call */
78+ struct afs_net *net; /* The network namespace */
7579 struct afs_server *server; /* server affected by incoming CM call */
7680 void *request; /* request data (first part) */
7781 struct address_space *mapping; /* page set */
@@ -173,6 +177,7 @@ struct afs_writeback { · 95 unmodified lines
173177 * - there's one superblock per volume
174178 */
175179 struct afs_super_info {
180+ struct afs_net *net; /* Network namespace */
176181 struct afs_volume *volume; /* volume record */
177182 char rwparent; /* T if parent is R/W AFS volume */
178183 };
@@ -192,12 +197,62 @@ struct afs_cache_cell { · 13 unmodified lines
192197 struct in_addr vl_servers[15]; /* cached cell VL servers */
193198 };
194199
200+/*
201+ * AFS network namespace record.
202+ */
203+struct afs_net {
204+ struct afs_uuid uuid;
205+ bool live; /* F if this namespace is being removed */
206+
207+ /* AF_RXRPC I/O stuff */
208+ struct socket *socket;
209+ struct afs_call *spare_incoming_call;
210+ struct work_struct charge_preallocation_work;
211+ struct mutex socket_mutex;
212+ atomic_t nr_outstanding_calls;
213+ atomic_t nr_superblocks;
214+
215+ /* Cell database */
216+ struct list_head cells;
217+ struct afs_cell *ws_cell;
218+ rwlock_t cells_lock;
219+ struct rw_semaphore cells_sem;
220+ wait_queue_head_t cells_freeable_wq;
221+
222+ struct rw_semaphore proc_cells_sem;
223+ struct list_head proc_cells;
224+
225+ /* Volume location database */
226+ struct list_head vl_updates; /* VL records in need-update order */
227+ struct list_head vl_graveyard; /* Inactive VL records */
228+ struct delayed_work vl_reaper;
229+ struct delayed_work vl_updater;
230+ spinlock_t vl_updates_lock;
231+ spinlock_t vl_graveyard_lock;
232+
233+ /* File locking renewal management */
234+ struct mutex lock_manager_mutex;
235+
236+ /* Server database */
237+ struct rb_root servers; /* Active servers */
238+ rwlock_t servers_lock;
239+ struct list_head server_graveyard; /* Inactive server LRU list */
240+ spinlock_t server_graveyard_lock;
241+ struct delayed_work server_reaper;
242+
243+ /* Misc */
244+ struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */
245+};
246+
247+extern struct afs_net __afs_net;// Dummy AFS network namespace; TODO: replace with real netns
248+
195249 /*
196250 * AFS cell record
197251 */
198252 struct afs_cell {
199253 atomic_t usage;
200254 struct list_head link; /* main cell list link */
255+ struct afs_net *net; /* The network namespace */
201256 struct key *anonymous_key; /* anonymous user key for this cell */
202257 struct list_head proc_link; /* /proc cell list link */
203258 #ifdef CONFIG_AFS_FSCACHE
@@ -411,15 +466,6 @@ struct afs_interface { · 207 unmodified lines
411466 unsigned mtu; /* MTU of interface */
412467 };
413468
414−struct afs_uuid {
415− __be32 time_low; /* low part of timestamp */
416− __be16 time_mid; /* mid part of timestamp */
417− __be16 time_hi_and_version; /* high part of timestamp and version */
418− __u8 clock_seq_hi_and_reserved; /* clock seq hi and variant */
419− __u8 clock_seq_low; /* clock seq low */
420− __u8 node[6]; /* spatially unique node ID (MAC addr) */
421−};
422−
423469 /*****************************************************************************/
424470 /*
425471 * cache.c
@@ -440,6 +486,8 @@ extern struct fscache_cookie_def afs_vnode_cache_index_def; · 14 unmodified lines
440486 /*
441487 * callback.c
442488 */
489+extern struct workqueue_struct *afs_callback_update_worker;
490+
443491 extern void afs_init_callback_state(struct afs_server *);
444492 extern void afs_broken_callback_work(struct work_struct *);
445493 extern void afs_break_callbacks(struct afs_server *, size_t,
@@ -448,22 +496,17 @@ extern void afs_discard_callback_on_delete(struct afs_vnode *); · 2 unmodified lines
448496 extern void afs_give_up_callback(struct afs_vnode *);
449497 extern void afs_dispatch_give_up_callbacks(struct work_struct *);
450498 extern void afs_flush_callback_breaks(struct afs_server *);
451−extern int __init afs_callback_update_init(void);
452−extern void afs_callback_update_kill(void);
453499
454500 /*
455501 * cell.c
456502 */
457−extern struct rw_semaphore afs_proc_cells_sem;
458−extern struct list_head afs_proc_cells;
459−
460503 #define afs_get_cell(C) do { atomic_inc(&(C)->usage); } while(0)
461−extern int afs_cell_init(char *);
462−extern struct afs_cell *afs_cell_create(const char *, unsigned, char *, bool);
463−extern struct afs_cell *afs_cell_lookup(const char *, unsigned, bool);
504+extern int afs_cell_init(struct afs_net *, char *);
505+extern struct afs_cell *afs_cell_create(struct afs_net *, const char *, unsigned, char *, bool);
506+extern struct afs_cell *afs_cell_lookup(struct afs_net *, const char *, unsigned, bool);
464507 extern struct afs_cell *afs_grab_cell(struct afs_cell *);
465508 extern void afs_put_cell(struct afs_cell *);
466−extern void afs_cell_purge(void);
509+extern void __net_exit afs_cell_purge(struct afs_net *);
467510
468511 /*
469512 * cmservice.c
@@ -492,7 +535,8 @@ extern void afs_put_read(struct afs_read *); · 22 unmodified lines
492535 /*
493536 * flock.c
494537 */
495−extern void __exit afs_kill_lock_manager(void);
538+extern struct workqueue_struct *afs_lock_manager;
539+
496540 extern void afs_lock_work(struct work_struct *);
497541 extern void afs_lock_may_be_available(struct afs_vnode *);
498542 extern int afs_lock(struct file *, int, struct file_lock *);
@@ -504,7 +548,7 @@ extern int afs_flock(struct file *, int, struct file_lock *); · 5 unmodified lines
504548 extern int afs_fs_fetch_file_status(struct afs_server *, struct key *,
505549 struct afs_vnode *, struct afs_volsync *,
506550 bool);
507−extern int afs_fs_give_up_callbacks(struct afs_server *, bool);
551+extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *, bool);
508552 extern int afs_fs_fetch_data(struct afs_server *, struct key *,
509553 struct afs_vnode *, struct afs_read *, bool);
510554 extern int afs_fs_create(struct afs_server *, struct key *,
@@ -554,7 +598,35 @@ extern int afs_drop_inode(struct inode *); · 43 unmodified lines
554598 * main.c
555599 */
556600 extern struct workqueue_struct *afs_wq;
557−extern struct afs_uuid afs_uuid;
601+
602+static inline struct afs_net *afs_d2net(struct dentry *dentry)
603+{
604+ return &__afs_net;
605+}
606+
607+static inline struct afs_net *afs_i2net(struct inode *inode)
608+{
609+ return &__afs_net;
610+}
611+
612+static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
613+{
614+ return &__afs_net;
615+}
616+
617+static inline struct afs_net *afs_sock2net(struct sock *sk)
618+{
619+ return &__afs_net;
620+}
621+
622+static inline struct afs_net *afs_get_net(struct afs_net *net)
623+{
624+ return net;
625+}
626+
627+static inline void afs_put_net(struct afs_net *net)
628+{
629+}
558630
559631 /*
560632 * misc.c
@@ -579,23 +651,24 @@ extern int afs_get_ipv4_interfaces(struct afs_interface *, size_t, bool); · 18 unmodified lines
579651 /*
580652 * proc.c
581653 */
582−extern int afs_proc_init(void);
583−extern void afs_proc_cleanup(void);
584−extern int afs_proc_cell_setup(struct afs_cell *);
585−extern void afs_proc_cell_remove(struct afs_cell *);
654+extern int __net_init afs_proc_init(struct afs_net *);
655+extern void __net_exit afs_proc_cleanup(struct afs_net *);
656+extern int afs_proc_cell_setup(struct afs_net *, struct afs_cell *);
657+extern void afs_proc_cell_remove(struct afs_net *, struct afs_cell *);
586658
587659 /*
588660 * rxrpc.c
589661 */
590−extern struct socket *afs_socket;
591−extern atomic_t afs_outstanding_calls;
662+extern struct workqueue_struct *afs_async_calls;
592663
593−extern int afs_open_socket(void);
594−extern void afs_close_socket(void);
664+extern int __net_init afs_open_socket(struct afs_net *);
665+extern void __net_exit afs_close_socket(struct afs_net *);
666+extern void afs_charge_preallocation(struct work_struct *);
595667 extern void afs_put_call(struct afs_call *);
596668 extern int afs_queue_call_work(struct afs_call *);
597669 extern int afs_make_call(struct in_addr *, struct afs_call *, gfp_t, bool);
598−extern struct afs_call *afs_alloc_flat_call(const struct afs_call_type *,
670+extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
671+ const struct afs_call_type *,
599672 size_t, size_t);
600673 extern void afs_flat_call_destructor(struct afs_call *);
601674 extern void afs_send_empty_reply(struct afs_call *);
@@ -629,37 +702,45 @@ do { \ · 27 unmodified lines
629702
630703 extern struct afs_server *afs_lookup_server(struct afs_cell *,
631704 const struct in_addr *);
632−extern struct afs_server *afs_find_server(const struct sockaddr_rxrpc *);
705+extern struct afs_server *afs_find_server(struct afs_net *,
706+ const struct sockaddr_rxrpc *);
633707 extern void afs_put_server(struct afs_server *);
634−extern void __exit afs_purge_servers(void);
708+extern void afs_reap_server(struct work_struct *);
709+extern void __net_exit afs_purge_servers(struct afs_net *);
635710
636711 /*
637712 * super.c
638713 */
639−extern int afs_fs_init(void);
640−extern void afs_fs_exit(void);
714+extern int __init afs_fs_init(void);
715+extern void __exit afs_fs_exit(void);
641716
642717 /*
643718 * vlclient.c
644719 */
645−extern int afs_vl_get_entry_by_name(struct in_addr *, struct key *,
720+extern int afs_vl_get_entry_by_name(struct afs_net *,
721+ struct in_addr *, struct key *,
646722 const char *, struct afs_cache_vlocation *,
647723 bool);
648−extern int afs_vl_get_entry_by_id(struct in_addr *, struct key *,
724+extern int afs_vl_get_entry_by_id(struct afs_net *,
725+ struct in_addr *, struct key *,
649726 afs_volid_t, afs_voltype_t,
650727 struct afs_cache_vlocation *, bool);
651728
652729 /*
653730 * vlocation.c
654731 */
732+extern struct workqueue_struct *afs_vlocation_update_worker;
733+
655734 #define afs_get_vlocation(V) do { atomic_inc(&(V)->usage); } while(0)
656735
657−extern int __init afs_vlocation_update_init(void);
658−extern struct afs_vlocation *afs_vlocation_lookup(struct afs_cell *,
736+extern struct afs_vlocation *afs_vlocation_lookup(struct afs_net *,
737+ struct afs_cell *,
659738 struct key *,
660739 const char *, size_t);
661−extern void afs_put_vlocation(struct afs_vlocation *);
662−extern void afs_vlocation_purge(void);
740+extern void afs_put_vlocation(struct afs_net *, struct afs_vlocation *);
741+extern void afs_vlocation_updater(struct work_struct *);
742+extern void afs_vlocation_reaper(struct work_struct *);
743+extern void __net_exit afs_vlocation_purge(struct afs_net *);
663744
664745 /*
665746 * vnode.c
@@ -707,7 +788,7 @@ extern int afs_vnode_release_lock(struct afs_vnode *, struct key *); · 41 unmodified lines
707788 */
708789 #define afs_get_volume(V) do { atomic_inc(&(V)->usage); } while(0)
709790
710−extern void afs_put_volume(struct afs_volume *);
791+extern void afs_put_volume(struct afs_net *, struct afs_volume *);
711792 extern struct afs_volume *afs_volume_lookup(struct afs_mount_params *);
712793 extern struct afs_server *afs_volume_pick_fileserver(struct afs_vnode *);
713794 extern int afs_volume_release_fileserver(struct afs_vnode *,
fs/afs/main.c+105−48
@@ -31,30 +31,104 @@ static char *rootcell; · 30 unmodified lines
3131 module_param(rootcell, charp, 0);
3232 MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
3333
34−struct afs_uuid afs_uuid;
3534 struct workqueue_struct *afs_wq;
35+struct afs_net __afs_net;
36+
37+/*
38+ * Initialise an AFS network namespace record.
39+ */
40+static int __net_init afs_net_init(struct afs_net *net)
41+{
42+ int ret;
43+
44+ net->live = true;
45+ generate_random_uuid((unsigned char *)&net->uuid);
46+
47+ INIT_WORK(&net->charge_preallocation_work, afs_charge_preallocation);
48+ mutex_init(&net->socket_mutex);
49+ INIT_LIST_HEAD(&net->cells);
50+ rwlock_init(&net->cells_lock);
51+ init_rwsem(&net->cells_sem);
52+ init_waitqueue_head(&net->cells_freeable_wq);
53+ init_rwsem(&net->proc_cells_sem);
54+ INIT_LIST_HEAD(&net->proc_cells);
55+ INIT_LIST_HEAD(&net->vl_updates);
56+ INIT_LIST_HEAD(&net->vl_graveyard);
57+ INIT_DELAYED_WORK(&net->vl_reaper, afs_vlocation_reaper);
58+ INIT_DELAYED_WORK(&net->vl_updater, afs_vlocation_updater);
59+ spin_lock_init(&net->vl_updates_lock);
60+ spin_lock_init(&net->vl_graveyard_lock);
61+ net->servers = RB_ROOT;
62+ rwlock_init(&net->servers_lock);
63+ INIT_LIST_HEAD(&net->server_graveyard);
64+ spin_lock_init(&net->server_graveyard_lock);
65+ INIT_DELAYED_WORK(&net->server_reaper, afs_reap_server);
66+
67+ /* Register the /proc stuff */
68+ ret = afs_proc_init(net);
69+ if (ret < 0)
70+ goto error_proc;
71+
72+ /* Initialise the cell DB */
73+ ret = afs_cell_init(net, rootcell);
74+ if (ret < 0)
75+ goto error_cell_init;
76+
77+ /* Create the RxRPC transport */
78+ ret = afs_open_socket(net);
79+ if (ret < 0)
80+ goto error_open_socket;
81+
82+ return 0;
83+
84+error_open_socket:
85+ afs_vlocation_purge(net);
86+ afs_cell_purge(net);
87+error_cell_init:
88+ afs_proc_cleanup(net);
89+error_proc:
90+ return ret;
91+}
92+
93+/*
94+ * Clean up and destroy an AFS network namespace record.
95+ */
96+static void __net_exit afs_net_exit(struct afs_net *net)
97+{
98+ net->live = false;
99+ afs_close_socket(net);
100+ afs_purge_servers(net);
101+ afs_vlocation_purge(net);
102+ afs_cell_purge(net);
103+ afs_proc_cleanup(net);
104+}
36105
37106 /*
38107 * initialise the AFS client FS module
39108 */
40109 static int __init afs_init(void)
41110 {
42− int ret;
111+ int ret = -ENOMEM;
43112
44113 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
45114
46− generate_random_uuid((unsigned char *)&afs_uuid);
47−
48− /* create workqueue */
49− ret = -ENOMEM;
50115 afs_wq = alloc_workqueue("afs", 0, 0);
51116 if (!afs_wq)
52− return ret;
53−
54− /* register the /proc stuff */
55− ret = afs_proc_init();
56− if (ret < 0)
57− goto error_proc;
117+ goto error_afs_wq;
118+ afs_async_calls = alloc_workqueue("kafsd", WQ_MEM_RECLAIM, 0);
119+ if (!afs_async_calls)
120+ goto error_async;
121+ afs_vlocation_update_worker =
122+ alloc_workqueue("kafs_vlupdated", WQ_MEM_RECLAIM, 0);
123+ if (!afs_vlocation_update_worker)
124+ goto error_vl_up;
125+ afs_callback_update_worker =
126+ alloc_ordered_workqueue("kafs_callbackd", WQ_MEM_RECLAIM);
127+ if (!afs_callback_update_worker)
128+ goto error_callback;
129+ afs_lock_manager = alloc_workqueue("kafs_lockd", WQ_MEM_RECLAIM, 0);
130+ if (!afs_lock_manager)
131+ goto error_lockmgr;
58132
59133 #ifdef CONFIG_AFS_FSCACHE
60134 /* we want to be able to cache */
@@ -63,25 +137,9 @@ static int __init afs_init(void) · 2 unmodified lines
63137 goto error_cache;
64138 #endif
65139
66− /* initialise the cell DB */
67− ret = afs_cell_init(rootcell);
68− if (ret < 0)
69− goto error_cell_init;
70−
71− /* initialise the VL update process */
72− ret = afs_vlocation_update_init();
73− if (ret < 0)
74− goto error_vl_update_init;
75−
76− /* initialise the callback update process */
77− ret = afs_callback_update_init();
140+ ret = afs_net_init(&__afs_net);
78141 if (ret < 0)
79− goto error_callback_update_init;
80−
81− /* create the RxRPC transport */
82− ret = afs_open_socket();
83− if (ret < 0)
84− goto error_open_socket;
142+ goto error_net;
85143
86144 /* register the filesystems */
87145 ret = afs_fs_init();
@@ -91,21 +149,22 @@ static int __init afs_init(void) · 3 unmodified lines
91149 return ret;
92150
93151 error_fs:
94− afs_close_socket();
95−error_open_socket:
96− afs_callback_update_kill();
97−error_callback_update_init:
98− afs_vlocation_purge();
99−error_vl_update_init:
100− afs_cell_purge();
101−error_cell_init:
152+ afs_net_exit(&__afs_net);
153+error_net:
102154 #ifdef CONFIG_AFS_FSCACHE
103155 fscache_unregister_netfs(&afs_cache_netfs);
104156 error_cache:
105157 #endif
106− afs_proc_cleanup();
107−error_proc:
158+ destroy_workqueue(afs_lock_manager);
159+error_lockmgr:
160+ destroy_workqueue(afs_callback_update_worker);
161+error_callback:
162+ destroy_workqueue(afs_vlocation_update_worker);
163+error_vl_up:
164+ destroy_workqueue(afs_async_calls);
165+error_async:
108166 destroy_workqueue(afs_wq);
167+error_afs_wq:
109168 rcu_barrier();
110169 printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
111170 return ret;
@@ -124,17 +183,15 @@ static void __exit afs_exit(void) · 12 unmodified lines
124183 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
125184
126185 afs_fs_exit();
127− afs_kill_lock_manager();
128− afs_close_socket();
129− afs_purge_servers();
130− afs_callback_update_kill();
131− afs_vlocation_purge();
132− destroy_workqueue(afs_wq);
133− afs_cell_purge();
186+ afs_net_exit(&__afs_net);
134187 #ifdef CONFIG_AFS_FSCACHE
135188 fscache_unregister_netfs(&afs_cache_netfs);
136189 #endif
137− afs_proc_cleanup();
190+ destroy_workqueue(afs_lock_manager);
191+ destroy_workqueue(afs_callback_update_worker);
192+ destroy_workqueue(afs_vlocation_update_worker);
193+ destroy_workqueue(afs_async_calls);
194+ destroy_workqueue(afs_wq);
138195 rcu_barrier();
139196 }
140197
fs/afs/proc.c+40−24
@@ -17,8 +17,15 @@ · 16 unmodified lines
1717 #include <linux/uaccess.h>
1818 #include "internal.h"
1919
20−static struct proc_dir_entry *proc_afs;
20+static inline struct afs_net *afs_proc2net(struct file *f)
21+{
22+ return &__afs_net;
23+}
2124
25+static inline struct afs_net *afs_seq2net(struct seq_file *m)
26+{
27+ return &__afs_net; // TODO: use seq_file_net(m)
28+}
2229
2330 static int afs_proc_cells_open(struct inode *inode, struct file *file);
2431 static void *afs_proc_cells_start(struct seq_file *p, loff_t *pos);
@@ -122,23 +129,23 @@ static const struct file_operations afs_proc_cell_servers_fops = { · 97 unmodified lines
122129 /*
123130 * initialise the /proc/fs/afs/ directory
124131 */
125−int afs_proc_init(void)
132+int afs_proc_init(struct afs_net *net)
126133 {
127134 _enter("");
128135
129− proc_afs = proc_mkdir("fs/afs", NULL);
130− if (!proc_afs)
136+ net->proc_afs = proc_mkdir("fs/afs", NULL);
137+ if (!net->proc_afs)
131138 goto error_dir;
132139
133− if (!proc_create("cells", 0644, proc_afs, &afs_proc_cells_fops) ||
134− !proc_create("rootcell", 0644, proc_afs, &afs_proc_rootcell_fops))
140+ if (!proc_create("cells", 0644, net->proc_afs, &afs_proc_cells_fops) ||
141+ !proc_create("rootcell", 0644, net->proc_afs, &afs_proc_rootcell_fops))
135142 goto error_tree;
136143
137144 _leave(" = 0");
138145 return 0;
139146
140147 error_tree:
141− remove_proc_subtree("fs/afs", NULL);
148+ proc_remove(net->proc_afs);
142149 error_dir:
143150 _leave(" = -ENOMEM");
144151 return -ENOMEM;
@@ -147,9 +154,10 @@ error_dir: · 2 unmodified lines
147154 /*
148155 * clean up the /proc/fs/afs/ directory
149156 */
150−void afs_proc_cleanup(void)
157+void afs_proc_cleanup(struct afs_net *net)
151158 {
152− remove_proc_subtree("fs/afs", NULL);
159+ proc_remove(net->proc_afs);
160+ net->proc_afs = NULL;
153161 }
154162
155163 /*
@@ -176,25 +184,30 @@ static int afs_proc_cells_open(struct inode *inode, struct file *file) · 20 unmodified lines
176184 */
177185 static void *afs_proc_cells_start(struct seq_file *m, loff_t *_pos)
178186 {
179− /* lock the list against modification */
180− down_read(&afs_proc_cells_sem);
181− return seq_list_start_head(&afs_proc_cells, *_pos);
187+ struct afs_net *net = afs_seq2net(m);
188+
189+ down_read(&net->proc_cells_sem);
190+ return seq_list_start_head(&net->proc_cells, *_pos);
182191 }
183192
184193 /*
185194 * move to next cell in cells list
186195 */
187−static void *afs_proc_cells_next(struct seq_file *p, void *v, loff_t *pos)
196+static void *afs_proc_cells_next(struct seq_file *m, void *v, loff_t *pos)
188197 {
189− return seq_list_next(v, &afs_proc_cells, pos);
198+ struct afs_net *net = afs_seq2net(m);
199+
200+ return seq_list_next(v, &net->proc_cells, pos);
190201 }
191202
192203 /*
193204 * clean up after reading from the cells list
194205 */
195−static void afs_proc_cells_stop(struct seq_file *p, void *v)
206+static void afs_proc_cells_stop(struct seq_file *m, void *v)
196207 {
197− up_read(&afs_proc_cells_sem);
208+ struct afs_net *net = afs_seq2net(m);
209+
210+ up_read(&net->proc_cells_sem);
198211 }
199212
200213 /*
@@ -203,8 +216,9 @@ static void afs_proc_cells_stop(struct seq_file *p, void *v) · 2 unmodified lines
203216 static int afs_proc_cells_show(struct seq_file *m, void *v)
204217 {
205218 struct afs_cell *cell = list_entry(v, struct afs_cell, proc_link);
219+ struct afs_net *net = afs_seq2net(m);
206220
207− if (v == &afs_proc_cells) {
221+ if (v == &net->proc_cells) {
208222 /* display header on line 1 */
209223 seq_puts(m, "USE NAME\n");
210224 return 0;
@@ -223,6 +237,7 @@ static int afs_proc_cells_show(struct seq_file *m, void *v) · 12 unmodified lines
223237 static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf,
224238 size_t size, loff_t *_pos)
225239 {
240+ struct afs_net *net = afs_proc2net(file);
226241 char *kbuf, *name, *args;
227242 int ret;
228243
@@ -264,7 +279,7 @@ static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf, · 35 unmodified lines
264279 if (strcmp(kbuf, "add") == 0) {
265280 struct afs_cell *cell;
266281
267− cell = afs_cell_create(name, strlen(name), args, false);
282+ cell = afs_cell_create(net, name, strlen(name), args, false);
268283 if (IS_ERR(cell)) {
269284 ret = PTR_ERR(cell);
270285 goto done;
@@ -303,6 +318,7 @@ static ssize_t afs_proc_rootcell_write(struct file *file, · 32 unmodified lines
303318 const char __user *buf,
304319 size_t size, loff_t *_pos)
305320 {
321+ struct afs_net *net = afs_proc2net(file);
306322 char *kbuf, *s;
307323 int ret;
308324
@@ -322,7 +338,7 @@ static ssize_t afs_proc_rootcell_write(struct file *file, · 13 unmodified lines
322338 /* determine command to perform */
323339 _debug("rootcell=%s", kbuf);
324340
325− ret = afs_cell_init(kbuf);
341+ ret = afs_cell_init(net, kbuf);
326342 if (ret >= 0)
327343 ret = size; /* consume everything, always */
328344
@@ -334,13 +350,13 @@ static ssize_t afs_proc_rootcell_write(struct file *file, · 5 unmodified lines
334350 /*
335351 * initialise /proc/fs/afs/<cell>/
336352 */
337−int afs_proc_cell_setup(struct afs_cell *cell)
353+int afs_proc_cell_setup(struct afs_net *net, struct afs_cell *cell)
338354 {
339355 struct proc_dir_entry *dir;
340356
341357 _enter("%p{%s}", cell, cell->name);
342358
343− dir = proc_mkdir(cell->name, proc_afs);
359+ dir = proc_mkdir(cell->name, net->proc_afs);
344360 if (!dir)
345361 goto error_dir;
346362
@@ -356,7 +372,7 @@ int afs_proc_cell_setup(struct afs_cell *cell) · 9 unmodified lines
356372 return 0;
357373
358374 error_tree:
359− remove_proc_subtree(cell->name, proc_afs);
375+ remove_proc_subtree(cell->name, net->proc_afs);
360376 error_dir:
361377 _leave(" = -ENOMEM");
362378 return -ENOMEM;
@@ -365,11 +381,11 @@ error_dir: · 2 unmodified lines
365381 /*
366382 * remove /proc/fs/afs/<cell>/
367383 */
368−void afs_proc_cell_remove(struct afs_cell *cell)
384+void afs_proc_cell_remove(struct afs_net *net, struct afs_cell *cell)
369385 {
370386 _enter("");
371387
372− remove_proc_subtree(cell->name, proc_afs);
388+ remove_proc_subtree(cell->name, net->proc_afs);
373389
374390 _leave("");
375391 }
fs/afs/rxrpc.c+65−67
@@ -17,10 +17,7 @@ · 16 unmodified lines
1717 #include "internal.h"
1818 #include "afs_cm.h"
1919
20−struct socket *afs_socket; /* my RxRPC socket */
21−static struct workqueue_struct *afs_async_calls;
22−static struct afs_call *afs_spare_incoming_call;
23−atomic_t afs_outstanding_calls;
20+struct workqueue_struct *afs_async_calls;
2421
2522 static void afs_wake_up_call_waiter(struct sock *, struct rxrpc_call *, unsigned long);
2623 static int afs_wait_for_call_to_complete(struct afs_call *);
@@ -37,15 +34,11 @@ static const struct afs_call_type afs_RXCMxxxx = { · 10 unmodified lines
3734 .abort_to_error = afs_abort_to_error,
3835 };
3936
40−static void afs_charge_preallocation(struct work_struct *);
41−
42−static DECLARE_WORK(afs_charge_preallocation_work, afs_charge_preallocation);
43−
4437 /*
4538 * open an RxRPC socket and bind it to be a server for callback notifications
4639 * - the socket is left in blocking mode and non-blocking ops use MSG_DONTWAIT
4740 */
48−int afs_open_socket(void)
41+int afs_open_socket(struct afs_net *net)
4942 {
5043 struct sockaddr_rxrpc srx;
5144 struct socket *socket;
@@ -53,11 +46,6 @@ int afs_open_socket(void) · 1 unmodified line
5346
5447 _enter("");
5548
56− ret = -ENOMEM;
57− afs_async_calls = alloc_workqueue("kafsd", WQ_MEM_RECLAIM, 0);
58− if (!afs_async_calls)
59− goto error_0;
60−
6149 ret = sock_create_kern(&init_net, AF_RXRPC, SOCK_DGRAM, PF_INET, &socket);
6250 if (ret < 0)
6351 goto error_1;
@@ -85,16 +73,14 @@ int afs_open_socket(void) · 21 unmodified lines
8573 if (ret < 0)
8674 goto error_2;
8775
88− afs_socket = socket;
89− afs_charge_preallocation(NULL);
76+ net->socket = socket;
77+ afs_charge_preallocation(&net->charge_preallocation_work);
9078 _leave(" = 0");
9179 return 0;
9280
9381 error_2:
9482 sock_release(socket);
9583 error_1:
96− destroy_workqueue(afs_async_calls);
97−error_0:
9884 _leave(" = %d", ret);
9985 return ret;
10086 }
@@ -102,36 +88,36 @@ error_0: · 1 unmodified line
10288 /*
10389 * close the RxRPC socket AFS was using
10490 */
105−void afs_close_socket(void)
91+void afs_close_socket(struct afs_net *net)
10692 {
10793 _enter("");
10894
109− kernel_listen(afs_socket, 0);
95+ kernel_listen(net->socket, 0);
11096 flush_workqueue(afs_async_calls);
11197
112− if (afs_spare_incoming_call) {
113− afs_put_call(afs_spare_incoming_call);
114− afs_spare_incoming_call = NULL;
98+ if (net->spare_incoming_call) {
99+ afs_put_call(net->spare_incoming_call);
100+ net->spare_incoming_call = NULL;
115101 }
116102
117− _debug("outstanding %u", atomic_read(&afs_outstanding_calls));
118− wait_on_atomic_t(&afs_outstanding_calls, atomic_t_wait,
103+ _debug("outstanding %u", atomic_read(&net->nr_outstanding_calls));
104+ wait_on_atomic_t(&net->nr_outstanding_calls, atomic_t_wait,
119105 TASK_UNINTERRUPTIBLE);
120106 _debug("no outstanding calls");
121107
122− kernel_sock_shutdown(afs_socket, SHUT_RDWR);
108+ kernel_sock_shutdown(net->socket, SHUT_RDWR);
123109 flush_workqueue(afs_async_calls);
124− sock_release(afs_socket);
110+ sock_release(net->socket);
125111
126112 _debug("dework");
127− destroy_workqueue(afs_async_calls);
128113 _leave("");
129114 }
130115
131116 /*
132117 * Allocate a call.
133118 */
134−static struct afs_call *afs_alloc_call(const struct afs_call_type *type,
119+static struct afs_call *afs_alloc_call(struct afs_net *net,
120+ const struct afs_call_type *type,
135121 gfp_t gfp)
136122 {
137123 struct afs_call *call;
@@ -142,11 +128,12 @@ static struct afs_call *afs_alloc_call(const struct afs_call_type *type, · 4 unmodified lines
142128 return NULL;
143129
144130 call->type = type;
131+ call->net = net;
145132 atomic_set(&call->usage, 1);
146133 INIT_WORK(&call->async_work, afs_process_async_call);
147134 init_waitqueue_head(&call->waitq);
148135
149− o = atomic_inc_return(&afs_outstanding_calls);
136+ o = atomic_inc_return(&net->nr_outstanding_calls);
150137 trace_afs_call(call, afs_call_trace_alloc, 1, o,
151138 __builtin_return_address(0));
152139 return call;
@@ -157,8 +144,9 @@ static struct afs_call *afs_alloc_call(const struct afs_call_type *type, · 4 unmodified lines
157144 */
158145 void afs_put_call(struct afs_call *call)
159146 {
147+ struct afs_net *net = call->net;
160148 int n = atomic_dec_return(&call->usage);
161− int o = atomic_read(&afs_outstanding_calls);
149+ int o = atomic_read(&net->nr_outstanding_calls);
162150
163151 trace_afs_call(call, afs_call_trace_put, n + 1, o,
164152 __builtin_return_address(0));
@@ -169,7 +157,7 @@ void afs_put_call(struct afs_call *call) · 4 unmodified lines
169157 ASSERT(call->type->name != NULL);
170158
171159 if (call->rxcall) {
172− rxrpc_kernel_end_call(afs_socket, call->rxcall);
160+ rxrpc_kernel_end_call(net->socket, call->rxcall);
173161 call->rxcall = NULL;
174162 }
175163 if (call->type->destructor)
@@ -178,11 +166,11 @@ void afs_put_call(struct afs_call *call) · 2 unmodified lines
178166 kfree(call->request);
179167 kfree(call);
180168
181− o = atomic_dec_return(&afs_outstanding_calls);
169+ o = atomic_dec_return(&net->nr_outstanding_calls);
182170 trace_afs_call(call, afs_call_trace_free, 0, o,
183171 __builtin_return_address(0));
184172 if (o == 0)
185− wake_up_atomic_t(&afs_outstanding_calls);
173+ wake_up_atomic_t(&net->nr_outstanding_calls);
186174 }
187175 }
188176
@@ -194,7 +182,7 @@ int afs_queue_call_work(struct afs_call *call) · 5 unmodified lines
194182 int u = atomic_inc_return(&call->usage);
195183
196184 trace_afs_call(call, afs_call_trace_work, u,
197− atomic_read(&afs_outstanding_calls),
185+ atomic_read(&call->net->nr_outstanding_calls),
198186 __builtin_return_address(0));
199187
200188 INIT_WORK(&call->work, call->type->work);
@@ -207,12 +195,13 @@ int afs_queue_call_work(struct afs_call *call) · 6 unmodified lines
207195 /*
208196 * allocate a call with flat request and reply buffers
209197 */
210−struct afs_call *afs_alloc_flat_call(const struct afs_call_type *type,
198+struct afs_call *afs_alloc_flat_call(struct afs_net *net,
199+ const struct afs_call_type *type,
211200 size_t request_size, size_t reply_max)
212201 {
213202 struct afs_call *call;
214203
215− call = afs_alloc_call(type, GFP_NOFS);
204+ call = afs_alloc_call(net, type, GFP_NOFS);
216205 if (!call)
217206 goto nomem_call;
218207
@@ -317,7 +306,7 @@ static int afs_send_pages(struct afs_call *call, struct msghdr *msg) · 98 unmodified lines
317306 bytes = msg->msg_iter.count;
318307 nr = msg->msg_iter.nr_segs;
319308
320− ret = rxrpc_kernel_send_data(afs_socket, call->rxcall, msg,
309+ ret = rxrpc_kernel_send_data(call->net->socket, call->rxcall, msg,
321310 bytes, afs_notify_end_request_tx);
322311 for (loop = 0; loop < nr; loop++)
323312 put_page(bv[loop].bv_page);
@@ -352,7 +341,7 @@ int afs_make_call(struct in_addr *addr, struct afs_call *call, gfp_t gfp, · 28 unmodified lines
352341
353342 _debug("____MAKE %p{%s,%x} [%d]____",
354343 call, call->type->name, key_serial(call->key),
355− atomic_read(&afs_outstanding_calls));
344+ atomic_read(&call->net->nr_outstanding_calls));
356345
357346 call->async = async;
358347
@@ -376,7 +365,7 @@ int afs_make_call(struct in_addr *addr, struct afs_call *call, gfp_t gfp, · 17 unmodified lines
376365 }
377366
378367 /* create a call */
379− rxcall = rxrpc_kernel_begin_call(afs_socket, &srx, call->key,
368+ rxcall = rxrpc_kernel_begin_call(call->net->socket, &srx, call->key,
380369 (unsigned long)call,
381370 tx_total_len, gfp,
382371 (async ?
@@ -410,7 +399,7 @@ int afs_make_call(struct in_addr *addr, struct afs_call *call, gfp_t gfp, · 27 unmodified lines
410399 */
411400 if (!call->send_pages)
412401 call->state = AFS_CALL_AWAIT_REPLY;
413− ret = rxrpc_kernel_send_data(afs_socket, rxcall,
402+ ret = rxrpc_kernel_send_data(call->net->socket, rxcall,
414403 &msg, call->request_size,
415404 afs_notify_end_request_tx);
416405 if (ret < 0)
@@ -432,13 +421,14 @@ int afs_make_call(struct in_addr *addr, struct afs_call *call, gfp_t gfp, · 15 unmodified lines
432421 error_do_abort:
433422 call->state = AFS_CALL_COMPLETE;
434423 if (ret != -ECONNABORTED) {
435− rxrpc_kernel_abort_call(afs_socket, rxcall, RX_USER_ABORT,
436− ret, "KSD");
424+ rxrpc_kernel_abort_call(call->net->socket, rxcall,
425+ RX_USER_ABORT, ret, "KSD");
437426 } else {
438427 abort_code = 0;
439428 offset = 0;
440− rxrpc_kernel_recv_data(afs_socket, rxcall, NULL, 0, &offset,
441− false, &abort_code, &call->service_id);
429+ rxrpc_kernel_recv_data(call->net->socket, rxcall, NULL,
430+ 0, &offset, false, &abort_code,
431+ &call->service_id);
442432 ret = call->type->abort_to_error(abort_code);
443433 }
444434 error_kill_call:
@@ -464,7 +454,8 @@ static void afs_deliver_to_call(struct afs_call *call) · 19 unmodified lines
464454 ) {
465455 if (call->state == AFS_CALL_AWAIT_ACK) {
466456 size_t offset = 0;
467− ret = rxrpc_kernel_recv_data(afs_socket, call->rxcall,
457+ ret = rxrpc_kernel_recv_data(call->net->socket,
458+ call->rxcall,
468459 NULL, 0, &offset, false,
469460 &call->abort_code,
470461 &call->service_id);
@@ -492,12 +483,12 @@ static void afs_deliver_to_call(struct afs_call *call) · 21 unmodified lines
492483 goto call_complete;
493484 case -ENOTCONN:
494485 abort_code = RX_CALL_DEAD;
495− rxrpc_kernel_abort_call(afs_socket, call->rxcall,
486+ rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
496487 abort_code, ret, "KNC");
497488 goto save_error;
498489 case -ENOTSUPP:
499490 abort_code = RXGEN_OPCODE;
500− rxrpc_kernel_abort_call(afs_socket, call->rxcall,
491+ rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
501492 abort_code, ret, "KIV");
502493 goto save_error;
503494 case -ENODATA:
@@ -507,7 +498,7 @@ static void afs_deliver_to_call(struct afs_call *call) · 3 unmodified lines
507498 abort_code = RXGEN_CC_UNMARSHAL;
508499 if (call->state != AFS_CALL_AWAIT_REPLY)
509500 abort_code = RXGEN_SS_UNMARSHAL;
510− rxrpc_kernel_abort_call(afs_socket, call->rxcall,
501+ rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
511502 abort_code, -EBADMSG, "KUM");
512503 goto save_error;
513504 }
@@ -541,13 +532,13 @@ static int afs_wait_for_call_to_complete(struct afs_call *call) · 27 unmodified lines
541532
542533 _enter("");
543534
544− rtt = rxrpc_kernel_get_rtt(afs_socket, call->rxcall);
535+ rtt = rxrpc_kernel_get_rtt(call->net->socket, call->rxcall);
545536 rtt2 = nsecs_to_jiffies64(rtt) * 2;
546537 if (rtt2 < 2)
547538 rtt2 = 2;
548539
549540 timeout = rtt2;
550− last_life = rxrpc_kernel_check_life(afs_socket, call->rxcall);
541+ last_life = rxrpc_kernel_check_life(call->net->socket, call->rxcall);
551542
552543 add_wait_queue(&call->waitq, &myself);
553544 for (;;) {
@@ -564,7 +555,7 @@ static int afs_wait_for_call_to_complete(struct afs_call *call) · 10 unmodified lines
564555 if (call->state == AFS_CALL_COMPLETE)
565556 break;
566557
567− life = rxrpc_kernel_check_life(afs_socket, call->rxcall);
558+ life = rxrpc_kernel_check_life(call->net->socket, call->rxcall);
568559 if (timeout == 0 &&
569560 life == last_life && signal_pending(current))
570561 break;
@@ -583,7 +574,7 @@ static int afs_wait_for_call_to_complete(struct afs_call *call) · 12 unmodified lines
583574 /* Kill off the call if it's still live. */
584575 if (call->state < AFS_CALL_COMPLETE) {
585576 _debug("call interrupted");
586− rxrpc_kernel_abort_call(afs_socket, call->rxcall,
577+ rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
587578 RX_USER_ABORT, -EINTR, "KWI");
588579 }
589580
@@ -621,7 +612,7 @@ static void afs_wake_up_async_call(struct sock *sk, struct rxrpc_call *rxcall, · 31 unmodified lines
621612 u = __atomic_add_unless(&call->usage, 1, 0);
622613 if (u != 0) {
623614 trace_afs_call(call, afs_call_trace_wake, u,
624− atomic_read(&afs_outstanding_calls),
615+ atomic_read(&call->net->nr_outstanding_calls),
625616 __builtin_return_address(0));
626617
627618 if (!queue_work(afs_async_calls, &call->async_work))
@@ -685,13 +676,15 @@ static void afs_rx_attach(struct rxrpc_call *rxcall, unsigned long user_call_ID) · 57 unmodified lines
685676 /*
686677 * Charge the incoming call preallocation.
687678 */
688−static void afs_charge_preallocation(struct work_struct *work)
679+void afs_charge_preallocation(struct work_struct *work)
689680 {
690− struct afs_call *call = afs_spare_incoming_call;
681+ struct afs_net *net =
682+ container_of(work, struct afs_net, charge_preallocation_work);
683+ struct afs_call *call = net->spare_incoming_call;
691684
692685 for (;;) {
693686 if (!call) {
694− call = afs_alloc_call(&afs_RXCMxxxx, GFP_KERNEL);
687+ call = afs_alloc_call(net, &afs_RXCMxxxx, GFP_KERNEL);
695688 if (!call)
696689 break;
697690
@@ -700,7 +693,7 @@ static void afs_charge_preallocation(struct work_struct *work) · 2 unmodified lines
700693 init_waitqueue_head(&call->waitq);
701694 }
702695
703− if (rxrpc_kernel_charge_accept(afs_socket,
696+ if (rxrpc_kernel_charge_accept(net->socket,
704697 afs_wake_up_async_call,
705698 afs_rx_attach,
706699 (unsigned long)call,
@@ -708,7 +701,7 @@ static void afs_charge_preallocation(struct work_struct *work) · 1 unmodified line
708701 break;
709702 call = NULL;
710703 }
711− afs_spare_incoming_call = call;
704+ net->spare_incoming_call = call;
712705 }
713706
714707 /*
@@ -729,7 +722,9 @@ static void afs_rx_discard_new_call(struct rxrpc_call *rxcall, · 14 unmodified lines
729722 static void afs_rx_new_call(struct sock *sk, struct rxrpc_call *rxcall,
730723 unsigned long user_call_ID)
731724 {
732− queue_work(afs_wq, &afs_charge_preallocation_work);
725+ struct afs_net *net = afs_sock2net(sk);
726+
727+ queue_work(afs_wq, &net->charge_preallocation_work);
733728 }
734729
735730 /*
@@ -784,11 +779,12 @@ static void afs_notify_end_reply_tx(struct sock *sock, · 48 unmodified lines
784779 */
785780 void afs_send_empty_reply(struct afs_call *call)
786781 {
782+ struct afs_net *net = call->net;
787783 struct msghdr msg;
788784
789785 _enter("");
790786
791− rxrpc_kernel_set_tx_length(afs_socket, call->rxcall, 0);
787+ rxrpc_kernel_set_tx_length(net->socket, call->rxcall, 0);
792788
793789 msg.msg_name = NULL;
794790 msg.msg_namelen = 0;
@@ -798,7 +794,7 @@ void afs_send_empty_reply(struct afs_call *call) · 3 unmodified lines
798794 msg.msg_flags = 0;
799795
800796 call->state = AFS_CALL_AWAIT_ACK;
801− switch (rxrpc_kernel_send_data(afs_socket, call->rxcall, &msg, 0,
797+ switch (rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, 0,
802798 afs_notify_end_reply_tx)) {
803799 case 0:
804800 _leave(" [replied]");
@@ -806,7 +802,7 @@ void afs_send_empty_reply(struct afs_call *call) · 1 unmodified line
806802
807803 case -ENOMEM:
808804 _debug("oom");
809− rxrpc_kernel_abort_call(afs_socket, call->rxcall,
805+ rxrpc_kernel_abort_call(net->socket, call->rxcall,
810806 RX_USER_ABORT, -ENOMEM, "KOO");
811807 default:
812808 _leave(" [error]");
@@ -819,13 +815,14 @@ void afs_send_empty_reply(struct afs_call *call) · 6 unmodified lines
819815 */
820816 void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len)
821817 {
818+ struct afs_net *net = call->net;
822819 struct msghdr msg;
823820 struct kvec iov[1];
824821 int n;
825822
826823 _enter("");
827824
828− rxrpc_kernel_set_tx_length(afs_socket, call->rxcall, len);
825+ rxrpc_kernel_set_tx_length(net->socket, call->rxcall, len);
829826
830827 iov[0].iov_base = (void *) buf;
831828 iov[0].iov_len = len;
@@ -837,7 +834,7 @@ void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len) · 5 unmodified lines
837834 msg.msg_flags = 0;
838835
839836 call->state = AFS_CALL_AWAIT_ACK;
840− n = rxrpc_kernel_send_data(afs_socket, call->rxcall, &msg, len,
837+ n = rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, len,
841838 afs_notify_end_reply_tx);
842839 if (n >= 0) {
843840 /* Success */
@@ -847,7 +844,7 @@ void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len) · 3 unmodified lines
847844
848845 if (n == -ENOMEM) {
849846 _debug("oom");
850− rxrpc_kernel_abort_call(afs_socket, call->rxcall,
847+ rxrpc_kernel_abort_call(net->socket, call->rxcall,
851848 RX_USER_ABORT, -ENOMEM, "KOO");
852849 }
853850 _leave(" [error]");
@@ -859,6 +856,7 @@ void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len) · 5 unmodified lines
859856 int afs_extract_data(struct afs_call *call, void *buf, size_t count,
860857 bool want_more)
861858 {
859+ struct afs_net *net = call->net;
862860 int ret;
863861
864862 _enter("{%s,%zu},,%zu,%d",
@@ -866,7 +864,7 @@ int afs_extract_data(struct afs_call *call, void *buf, size_t count, · 1 unmodified line
866864
867865 ASSERTCMP(call->offset, <=, count);
868866
869− ret = rxrpc_kernel_recv_data(afs_socket, call->rxcall,
867+ ret = rxrpc_kernel_recv_data(net->socket, call->rxcall,
870868 buf, count, &call->offset,
871869 want_more, &call->abort_code,
872870 &call->service_id);
fs/afs/server.c+39−43
@@ -15,32 +15,22 @@ · 14 unmodified lines
1515
1616 static unsigned afs_server_timeout = 10; /* server timeout in seconds */
1717
18−static void afs_reap_server(struct work_struct *);
19−
20−/* tree of all the servers, indexed by IP address */
21−static struct rb_root afs_servers = RB_ROOT;
22−static DEFINE_RWLOCK(afs_servers_lock);
23−
24−/* LRU list of all the servers not currently in use */
25−static LIST_HEAD(afs_server_graveyard);
26−static DEFINE_SPINLOCK(afs_server_graveyard_lock);
27−static DECLARE_DELAYED_WORK(afs_server_reaper, afs_reap_server);
28−
2918 /*
3019 * install a server record in the master tree
3120 */
3221 static int afs_install_server(struct afs_server *server)
3322 {
3423 struct afs_server *xserver;
24+ struct afs_net *net = server->cell->net;
3525 struct rb_node **pp, *p;
3626 int ret;
3727
3828 _enter("%p", server);
3929
40− write_lock(&afs_servers_lock);
30+ write_lock(&net->servers_lock);
4131
4232 ret = -EEXIST;
43− pp = &afs_servers.rb_node;
33+ pp = &net->servers.rb_node;
4434 p = NULL;
4535 while (*pp) {
4636 p = *pp;
@@ -55,11 +45,11 @@ static int afs_install_server(struct afs_server *server) · 8 unmodified lines
5545 }
5646
5747 rb_link_node(&server->master_rb, p, pp);
58− rb_insert_color(&server->master_rb, &afs_servers);
48+ rb_insert_color(&server->master_rb, &net->servers);
5949 ret = 0;
6050
6151 error:
62− write_unlock(&afs_servers_lock);
52+ write_unlock(&net->servers_lock);
6353 return ret;
6454 }
6555
@@ -150,9 +140,9 @@ found_server_quickly: · 84 unmodified lines
150140 read_unlock(&cell->servers_lock);
151141 no_longer_unused:
152142 if (!list_empty(&server->grave)) {
153− spin_lock(&afs_server_graveyard_lock);
143+ spin_lock(&cell->net->server_graveyard_lock);
154144 list_del_init(&server->grave);
155− spin_unlock(&afs_server_graveyard_lock);
145+ spin_unlock(&cell->net->server_graveyard_lock);
156146 }
157147 _leave(" = %p{%d}", server, atomic_read(&server->usage));
158148 return server;
@@ -178,7 +168,8 @@ server_in_two_cells: · 19 unmodified lines
178168 /*
179169 * look up a server by its IP address
180170 */
181−struct afs_server *afs_find_server(const struct sockaddr_rxrpc *srx)
171+struct afs_server *afs_find_server(struct afs_net *net,
172+ const struct sockaddr_rxrpc *srx)
182173 {
183174 struct afs_server *server = NULL;
184175 struct rb_node *p;
@@ -191,9 +182,9 @@ struct afs_server *afs_find_server(const struct sockaddr_rxrpc *srx) · 6 unmodified lines
191182 return NULL;
192183 }
193184
194− read_lock(&afs_servers_lock);
185+ read_lock(&net->servers_lock);
195186
196− p = afs_servers.rb_node;
187+ p = net->servers.rb_node;
197188 while (p) {
198189 server = rb_entry(p, struct afs_server, master_rb);
199190
@@ -211,7 +202,7 @@ struct afs_server *afs_find_server(const struct sockaddr_rxrpc *srx) · 11 unmodified lines
211202
212203 server = NULL;
213204 found:
214− read_unlock(&afs_servers_lock);
205+ read_unlock(&net->servers_lock);
215206 ASSERTIFCMP(server, server->addr.s_addr, ==, addr.s_addr);
216207 _leave(" = %p", server);
217208 return server;
@@ -223,6 +214,8 @@ found: · 5 unmodified lines
223214 */
224215 void afs_put_server(struct afs_server *server)
225216 {
217+ struct afs_net *net = server->cell->net;
218+
226219 if (!server)
227220 return;
228221
@@ -239,14 +232,14 @@ void afs_put_server(struct afs_server *server) · 10 unmodified lines
239232
240233 afs_flush_callback_breaks(server);
241234
242− spin_lock(&afs_server_graveyard_lock);
235+ spin_lock(&net->server_graveyard_lock);
243236 if (atomic_read(&server->usage) == 0) {
244− list_move_tail(&server->grave, &afs_server_graveyard);
237+ list_move_tail(&server->grave, &net->server_graveyard);
245238 server->time_of_death = ktime_get_real_seconds();
246− queue_delayed_work(afs_wq, &afs_server_reaper,
247− afs_server_timeout * HZ);
239+ queue_delayed_work(afs_wq, &net->server_reaper,
240+ net->live ? afs_server_timeout * HZ : 0);
248241 }
249− spin_unlock(&afs_server_graveyard_lock);
242+ spin_unlock(&net->server_graveyard_lock);
250243 _leave(" [dead]");
251244 }
252245
@@ -272,42 +265,45 @@ static void afs_destroy_server(struct afs_server *server) · 19 unmodified lines
272265 /*
273266 * reap dead server records
274267 */
275−static void afs_reap_server(struct work_struct *work)
268+void afs_reap_server(struct work_struct *work)
276269 {
277270 LIST_HEAD(corpses);
278271 struct afs_server *server;
272+ struct afs_net *net = container_of(work, struct afs_net, server_reaper.work);
279273 unsigned long delay, expiry;
280274 time64_t now;
281275
282276 now = ktime_get_real_seconds();
283− spin_lock(&afs_server_graveyard_lock);
277+ spin_lock(&net->server_graveyard_lock);
284278
285− while (!list_empty(&afs_server_graveyard)) {
286− server = list_entry(afs_server_graveyard.next,
279+ while (!list_empty(&net->server_graveyard)) {
280+ server = list_entry(net->server_graveyard.next,
287281 struct afs_server, grave);
288282
289283 /* the queue is ordered most dead first */
290− expiry = server->time_of_death + afs_server_timeout;
291− if (expiry > now) {
292− delay = (expiry - now) * HZ;
293− mod_delayed_work(afs_wq, &afs_server_reaper, delay);
294− break;
284+ if (net->live) {
285+ expiry = server->time_of_death + afs_server_timeout;
286+ if (expiry > now) {
287+ delay = (expiry - now) * HZ;
288+ mod_delayed_work(afs_wq, &net->server_reaper, delay);
289+ break;
290+ }
295291 }
296292
297293 write_lock(&server->cell->servers_lock);
298− write_lock(&afs_servers_lock);
294+ write_lock(&net->servers_lock);
299295 if (atomic_read(&server->usage) > 0) {
300296 list_del_init(&server->grave);
301297 } else {
302298 list_move_tail(&server->grave, &corpses);
303299 list_del_init(&server->link);
304− rb_erase(&server->master_rb, &afs_servers);
300+ rb_erase(&server->master_rb, &net->servers);
305301 }
306− write_unlock(&afs_servers_lock);
302+ write_unlock(&net->servers_lock);
307303 write_unlock(&server->cell->servers_lock);
308304 }
309305
310− spin_unlock(&afs_server_graveyard_lock);
306+ spin_unlock(&net->server_graveyard_lock);
311307
312308 /* now reap the corpses we've extracted */
313309 while (!list_empty(&corpses)) {
@@ -318,10 +314,10 @@ static void afs_reap_server(struct work_struct *work) · 4 unmodified lines
318314 }
319315
320316 /*
321− * discard all the server records for rmmod
317+ * Discard all the server records from a net namespace when it is destroyed or
318+ * the afs module is removed.
322319 */
323−void __exit afs_purge_servers(void)
320+void __net_exit afs_purge_servers(struct afs_net *net)
324321 {
325− afs_server_timeout = 0;
326− mod_delayed_work(afs_wq, &afs_server_reaper, 0);
322+ mod_delayed_work(afs_wq, &net->server_reaper, 0);
327323 }
fs/afs/super.c+26−19
@@ -25,11 +25,10 @@ · 24 unmodified lines
2525 #include <linux/statfs.h>
2626 #include <linux/sched.h>
2727 #include <linux/nsproxy.h>
28+#include <linux/magic.h>
2829 #include <net/net_namespace.h>
2930 #include "internal.h"
3031
31−#define AFS_FS_MAGIC 0x6B414653 /* 'kAFS' */
32−
3332 static void afs_i_init_once(void *foo);
3433 static struct dentry *afs_mount(struct file_system_type *fs_type,
3534 int flags, const char *dev_name, void *data);
@@ -201,7 +200,8 @@ static int afs_parse_options(struct afs_mount_params *params, · 165 unmodified lines
201200 token = match_token(p, afs_options_list, args);
202201 switch (token) {
203202 case afs_opt_cell:
204− cell = afs_cell_lookup(args[0].from,
203+ cell = afs_cell_lookup(params->net,
204+ args[0].from,
205205 args[0].to - args[0].from,
206206 false);
207207 if (IS_ERR(cell))
@@ -308,7 +308,7 @@ static int afs_parse_device_name(struct afs_mount_params *params, · 100 unmodified lines
308308
309309 /* lookup the cell record */
310310 if (cellname || !params->cell) {
311− cell = afs_cell_lookup(cellname, cellnamesz, true);
311+ cell = afs_cell_lookup(params->net, cellname, cellnamesz, true);
312312 if (IS_ERR(cell)) {
313313 printk(KERN_ERR "kAFS: unable to lookup cell '%*.*s'\n",
314314 cellnamesz, cellnamesz, cellname ?: "");
@@ -334,7 +334,7 @@ static int afs_test_super(struct super_block *sb, void *data) · 19 unmodified lines
334334 struct afs_super_info *as1 = data;
335335 struct afs_super_info *as = sb->s_fs_info;
336336
337− return as->volume == as1->volume;
337+ return as->net == as1->net && as->volume == as1->volume;
338338 }
339339
340340 static int afs_set_super(struct super_block *sb, void *data)
@@ -411,6 +411,7 @@ static struct dentry *afs_mount(struct file_system_type *fs_type, · 70 unmodified lines
411411 _enter(",,%s,%p", dev_name, options);
412412
413413 memset(&params, 0, sizeof(params));
414+ params.net = &__afs_net;
414415
415416 ret = -EINVAL;
416417 if (current->nsproxy->net_ns != &init_net)
@@ -444,36 +445,32 @@ static struct dentry *afs_mount(struct file_system_type *fs_type, · 27 unmodified lines
444445 }
445446
446447 /* allocate a superblock info record */
448+ ret = -ENOMEM;
447449 as = kzalloc(sizeof(struct afs_super_info), GFP_KERNEL);
448− if (!as) {
449− ret = -ENOMEM;
450− afs_put_volume(vol);
451− goto error;
452− }
450+ if (!as)
451+ goto error_vol;
452+
453+ as->net = afs_get_net(params.net);
453454 as->volume = vol;
454455
455456 /* allocate a deviceless superblock */
456457 sb = sget(fs_type, afs_test_super, afs_set_super, flags, as);
457458 if (IS_ERR(sb)) {
458459 ret = PTR_ERR(sb);
459− afs_put_volume(vol);
460− kfree(as);
461− goto error;
460+ goto error_as;
462461 }
463462
464463 if (!sb->s_root) {
465464 /* initial superblock/root creation */
466465 _debug("create");
467466 ret = afs_fill_super(sb, &params);
468− if (ret < 0) {
469− deactivate_locked_super(sb);
470− goto error;
471− }
467+ if (ret < 0)
468+ goto error_sb;
472469 sb->s_flags |= MS_ACTIVE;
473470 } else {
474471 _debug("reuse");
475472 ASSERTCMP(sb->s_flags, &, MS_ACTIVE);
476− afs_put_volume(vol);
473+ afs_put_volume(params.net, vol);
477474 kfree(as);
478475 }
479476
@@ -482,6 +479,14 @@ static struct dentry *afs_mount(struct file_system_type *fs_type, · 2 unmodified lines
482479 _leave(" = 0 [%p]", sb);
483480 return dget(sb->s_root);
484481
482+error_sb:
483+ deactivate_locked_super(sb);
484+ goto error;
485+error_as:
486+ afs_put_net(as->net);
487+ kfree(as);
488+error_vol:
489+ afs_put_volume(params.net, vol);
485490 error:
486491 afs_put_cell(params.cell);
487492 key_put(params.key);
@@ -493,8 +498,10 @@ error: · 5 unmodified lines
493498 static void afs_kill_super(struct super_block *sb)
494499 {
495500 struct afs_super_info *as = sb->s_fs_info;
501+ struct afs_net *net = as->net;
502+
496503 kill_anon_super(sb);
497− afs_put_volume(as->volume);
504+ afs_put_volume(net, as->volume);
498505 kfree(as);
499506 }
500507
fs/afs/vlclient.c+6−4
@@ -143,7 +143,8 @@ static const struct afs_call_type afs_RXVLGetEntryById = { · 142 unmodified lines
143143 /*
144144 * dispatch a get volume entry by name operation
145145 */
146−int afs_vl_get_entry_by_name(struct in_addr *addr,
146+int afs_vl_get_entry_by_name(struct afs_net *net,
147+ struct in_addr *addr,
147148 struct key *key,
148149 const char *volname,
149150 struct afs_cache_vlocation *entry,
@@ -159,7 +160,7 @@ int afs_vl_get_entry_by_name(struct in_addr *addr, · 9 unmodified lines
159160 padsz = (4 - (volnamesz & 3)) & 3;
160161 reqsz = 8 + volnamesz + padsz;
161162
162− call = afs_alloc_flat_call(&afs_RXVLGetEntryByName, reqsz, 384);
163+ call = afs_alloc_flat_call(net, &afs_RXVLGetEntryByName, reqsz, 384);
163164 if (!call)
164165 return -ENOMEM;
165166
@@ -183,7 +184,8 @@ int afs_vl_get_entry_by_name(struct in_addr *addr, · 17 unmodified lines
183184 /*
184185 * dispatch a get volume entry by ID operation
185186 */
186−int afs_vl_get_entry_by_id(struct in_addr *addr,
187+int afs_vl_get_entry_by_id(struct afs_net *net,
188+ struct in_addr *addr,
187189 struct key *key,
188190 afs_volid_t volid,
189191 afs_voltype_t voltype,
@@ -195,7 +197,7 @@ int afs_vl_get_entry_by_id(struct in_addr *addr, · 5 unmodified lines
195197
196198 _enter("");
197199
198− call = afs_alloc_flat_call(&afs_RXVLGetEntryById, 12, 384);
200+ call = afs_alloc_flat_call(net, &afs_RXVLGetEntryById, 12, 384);
199201 if (!call)
200202 return -ENOMEM;
201203
fs/afs/vlocation.c+68−83
@@ -16,20 +16,11 @@ · 15 unmodified lines
1616 #include <linux/sched.h>
1717 #include "internal.h"
1818
19+struct workqueue_struct *afs_vlocation_update_worker;
20+
1921 static unsigned afs_vlocation_timeout = 10; /* volume location timeout in seconds */
2022 static unsigned afs_vlocation_update_timeout = 10 * 60;
2123
22−static void afs_vlocation_reaper(struct work_struct *);
23−static void afs_vlocation_updater(struct work_struct *);
24−
25−static LIST_HEAD(afs_vlocation_updates);
26−static LIST_HEAD(afs_vlocation_graveyard);
27−static DEFINE_SPINLOCK(afs_vlocation_updates_lock);
28−static DEFINE_SPINLOCK(afs_vlocation_graveyard_lock);
29−static DECLARE_DELAYED_WORK(afs_vlocation_reap, afs_vlocation_reaper);
30−static DECLARE_DELAYED_WORK(afs_vlocation_update, afs_vlocation_updater);
31−static struct workqueue_struct *afs_vlocation_update_worker;
32−
3324 /*
3425 * iterate through the VL servers in a cell until one of them admits knowing
3526 * about the volume in question
@@ -52,8 +43,8 @@ static int afs_vlocation_access_vl_by_name(struct afs_vlocation *vl, · 16 unmodified lines
5243 _debug("CellServ[%hu]: %08x", cell->vl_curr_svix, addr.s_addr);
5344
5445 /* attempt to access the VL server */
55− ret = afs_vl_get_entry_by_name(&addr, key, vl->vldb.name, vldb,
56− false);
46+ ret = afs_vl_get_entry_by_name(cell->net, &addr, key,
47+ vl->vldb.name, vldb, false);
5748 switch (ret) {
5849 case 0:
5950 goto out;
@@ -110,8 +101,8 @@ static int afs_vlocation_access_vl_by_id(struct afs_vlocation *vl, · 50 unmodified lines
110101 _debug("CellServ[%hu]: %08x", cell->vl_curr_svix, addr.s_addr);
111102
112103 /* attempt to access the VL server */
113− ret = afs_vl_get_entry_by_id(&addr, key, volid, voltype, vldb,
114− false);
104+ ret = afs_vl_get_entry_by_id(cell->net, &addr, key, volid,
105+ voltype, vldb, false);
115106 switch (ret) {
116107 case 0:
117108 goto out;
@@ -335,7 +326,8 @@ static int afs_vlocation_fill_in_record(struct afs_vlocation *vl, · 217 unmodified lines
335326 /*
336327 * queue a vlocation record for updates
337328 */
338−static void afs_vlocation_queue_for_updates(struct afs_vlocation *vl)
329+static void afs_vlocation_queue_for_updates(struct afs_net *net,
330+ struct afs_vlocation *vl)
339331 {
340332 struct afs_vlocation *xvl;
341333
@@ -343,25 +335,25 @@ static void afs_vlocation_queue_for_updates(struct afs_vlocation *vl) · 1 unmodified line
343335 vl->update_at = ktime_get_real_seconds() +
344336 afs_vlocation_update_timeout;
345337
346− spin_lock(&afs_vlocation_updates_lock);
338+ spin_lock(&net->vl_updates_lock);
347339
348− if (!list_empty(&afs_vlocation_updates)) {
340+ if (!list_empty(&net->vl_updates)) {
349341 /* ... but wait at least 1 second more than the newest record
350342 * already queued so that we don't spam the VL server suddenly
351343 * with lots of requests
352344 */
353− xvl = list_entry(afs_vlocation_updates.prev,
345+ xvl = list_entry(net->vl_updates.prev,
354346 struct afs_vlocation, update);
355347 if (vl->update_at <= xvl->update_at)
356348 vl->update_at = xvl->update_at + 1;
357− } else {
349+ } else if (net->live) {
358350 queue_delayed_work(afs_vlocation_update_worker,
359− &afs_vlocation_update,
351+ &net->vl_updater,
360352 afs_vlocation_update_timeout * HZ);
361353 }
362354
363− list_add_tail(&vl->update, &afs_vlocation_updates);
364− spin_unlock(&afs_vlocation_updates_lock);
355+ list_add_tail(&vl->update, &net->vl_updates);
356+ spin_unlock(&net->vl_updates_lock);
365357 }
366358
367359 /*
@@ -371,7 +363,8 @@ static void afs_vlocation_queue_for_updates(struct afs_vlocation *vl) · 3 unmodified lines
371363 * - lookup in the local cache if not able to find on the VL server
372364 * - insert/update in the local cache if did get a VL response
373365 */
374−struct afs_vlocation *afs_vlocation_lookup(struct afs_cell *cell,
366+struct afs_vlocation *afs_vlocation_lookup(struct afs_net *net,
367+ struct afs_cell *cell,
375368 struct key *key,
376369 const char *name,
377370 size_t namesz)
@@ -427,7 +420,7 @@ fill_in_record: · 49 unmodified lines
427420 #endif
428421
429422 /* schedule for regular updates */
430− afs_vlocation_queue_for_updates(vl);
423+ afs_vlocation_queue_for_updates(net, vl);
431424 goto success;
432425
433426 found_in_memory:
@@ -436,9 +429,9 @@ found_in_memory: · 2 unmodified lines
436429 atomic_inc(&vl->usage);
437430 spin_unlock(&cell->vl_lock);
438431 if (!list_empty(&vl->grave)) {
439− spin_lock(&afs_vlocation_graveyard_lock);
432+ spin_lock(&net->vl_graveyard_lock);
440433 list_del_init(&vl->grave);
441− spin_unlock(&afs_vlocation_graveyard_lock);
434+ spin_unlock(&net->vl_graveyard_lock);
442435 }
443436 up_write(&cell->vl_sem);
444437
@@ -481,7 +474,7 @@ error_abandon: · 36 unmodified lines
481474 wake_up(&vl->waitq);
482475 error:
483476 ASSERT(vl != NULL);
484− afs_put_vlocation(vl);
477+ afs_put_vlocation(net, vl);
485478 _leave(" = %d", ret);
486479 return ERR_PTR(ret);
487480 }
@@ -489,7 +482,7 @@ error: · 1 unmodified line
489482 /*
490483 * finish using a volume location record
491484 */
492−void afs_put_vlocation(struct afs_vlocation *vl)
485+void afs_put_vlocation(struct afs_net *net, struct afs_vlocation *vl)
493486 {
494487 if (!vl)
495488 return;
@@ -503,22 +496,22 @@ void afs_put_vlocation(struct afs_vlocation *vl) · 7 unmodified lines
503496 return;
504497 }
505498
506− spin_lock(&afs_vlocation_graveyard_lock);
499+ spin_lock(&net->vl_graveyard_lock);
507500 if (atomic_read(&vl->usage) == 0) {
508501 _debug("buried");
509− list_move_tail(&vl->grave, &afs_vlocation_graveyard);
502+ list_move_tail(&vl->grave, &net->vl_graveyard);
510503 vl->time_of_death = ktime_get_real_seconds();
511− queue_delayed_work(afs_wq, &afs_vlocation_reap,
504+ queue_delayed_work(afs_wq, &net->vl_reaper,
512505 afs_vlocation_timeout * HZ);
513506
514507 /* suspend updates on this record */
515508 if (!list_empty(&vl->update)) {
516− spin_lock(&afs_vlocation_updates_lock);
509+ spin_lock(&net->vl_updates_lock);
517510 list_del_init(&vl->update);
518− spin_unlock(&afs_vlocation_updates_lock);
511+ spin_unlock(&net->vl_updates_lock);
519512 }
520513 }
521− spin_unlock(&afs_vlocation_graveyard_lock);
514+ spin_unlock(&net->vl_graveyard_lock);
522515 _leave(" [killed?]");
523516 }
524517
@@ -539,31 +532,34 @@ static void afs_vlocation_destroy(struct afs_vlocation *vl) · 14 unmodified lines
539532 /*
540533 * reap dead volume location records
541534 */
542−static void afs_vlocation_reaper(struct work_struct *work)
535+void afs_vlocation_reaper(struct work_struct *work)
543536 {
544537 LIST_HEAD(corpses);
545538 struct afs_vlocation *vl;
539+ struct afs_net *net = container_of(work, struct afs_net, vl_reaper.work);
546540 unsigned long delay, expiry;
547541 time64_t now;
548542
549543 _enter("");
550544
551545 now = ktime_get_real_seconds();
552− spin_lock(&afs_vlocation_graveyard_lock);
546+ spin_lock(&net->vl_graveyard_lock);
553547
554− while (!list_empty(&afs_vlocation_graveyard)) {
555− vl = list_entry(afs_vlocation_graveyard.next,
548+ while (!list_empty(&net->vl_graveyard)) {
549+ vl = list_entry(net->vl_graveyard.next,
556550 struct afs_vlocation, grave);
557551
558552 _debug("check %p", vl);
559553
560554 /* the queue is ordered most dead first */
561− expiry = vl->time_of_death + afs_vlocation_timeout;
562− if (expiry > now) {
563− delay = (expiry - now) * HZ;
564− _debug("delay %lu", delay);
565− mod_delayed_work(afs_wq, &afs_vlocation_reap, delay);
566− break;
555+ if (net->live) {
556+ expiry = vl->time_of_death + afs_vlocation_timeout;
557+ if (expiry > now) {
558+ delay = (expiry - now) * HZ;
559+ _debug("delay %lu", delay);
560+ mod_delayed_work(afs_wq, &net->vl_reaper, delay);
561+ break;
562+ }
567563 }
568564
569565 spin_lock(&vl->cell->vl_lock);
@@ -578,7 +574,7 @@ static void afs_vlocation_reaper(struct work_struct *work) · 8 unmodified lines
578574 spin_unlock(&vl->cell->vl_lock);
579575 }
580576
581− spin_unlock(&afs_vlocation_graveyard_lock);
577+ spin_unlock(&net->vl_graveyard_lock);
582578
583579 /* now reap the corpses we've extracted */
584580 while (!list_empty(&corpses)) {
@@ -590,57 +586,47 @@ static void afs_vlocation_reaper(struct work_struct *work) · 5 unmodified lines
590586 _leave("");
591587 }
592588
593−/*
594− * initialise the VL update process
595− */
596−int __init afs_vlocation_update_init(void)
597−{
598− afs_vlocation_update_worker = alloc_workqueue("kafs_vlupdated",
599− WQ_MEM_RECLAIM, 0);
600− return afs_vlocation_update_worker ? 0 : -ENOMEM;
601−}
602−
603589 /*
604590 * discard all the volume location records for rmmod
605591 */
606−void afs_vlocation_purge(void)
592+void __net_exit afs_vlocation_purge(struct afs_net *net)
607593 {
608− afs_vlocation_timeout = 0;
609−
610− spin_lock(&afs_vlocation_updates_lock);
611− list_del_init(&afs_vlocation_updates);
612− spin_unlock(&afs_vlocation_updates_lock);
613− mod_delayed_work(afs_vlocation_update_worker, &afs_vlocation_update, 0);
614− destroy_workqueue(afs_vlocation_update_worker);
615−
616− mod_delayed_work(afs_wq, &afs_vlocation_reap, 0);
594+ spin_lock(&net->vl_updates_lock);
595+ list_del_init(&net->vl_updates);
596+ spin_unlock(&net->vl_updates_lock);
597+ mod_delayed_work(afs_vlocation_update_worker, &net->vl_updater, 0);
598+ mod_delayed_work(afs_wq, &net->vl_reaper, 0);
617599 }
618600
619601 /*
620602 * update a volume location
621603 */
622−static void afs_vlocation_updater(struct work_struct *work)
604+void afs_vlocation_updater(struct work_struct *work)
623605 {
624606 struct afs_cache_vlocation vldb;
625607 struct afs_vlocation *vl, *xvl;
608+ struct afs_net *net = container_of(work, struct afs_net, vl_updater.work);
626609 time64_t now;
627610 long timeout;
628611 int ret;
629612
613+ if (!net->live)
614+ return;
615+
630616 _enter("");
631617
632618 now = ktime_get_real_seconds();
633619
634620 /* find a record to update */
635− spin_lock(&afs_vlocation_updates_lock);
621+ spin_lock(&net->vl_updates_lock);
636622 for (;;) {
637− if (list_empty(&afs_vlocation_updates)) {
638− spin_unlock(&afs_vlocation_updates_lock);
623+ if (list_empty(&net->vl_updates) || !net->live) {
624+ spin_unlock(&net->vl_updates_lock);
639625 _leave(" [nothing]");
640626 return;
641627 }
642628
643− vl = list_entry(afs_vlocation_updates.next,
629+ vl = list_entry(net->vl_updates.next,
644630 struct afs_vlocation, update);
645631 if (atomic_read(&vl->usage) > 0)
646632 break;
@@ -650,15 +636,15 @@ static void afs_vlocation_updater(struct work_struct *work) · 3 unmodified lines
650636 timeout = vl->update_at - now;
651637 if (timeout > 0) {
652638 queue_delayed_work(afs_vlocation_update_worker,
653− &afs_vlocation_update, timeout * HZ);
654− spin_unlock(&afs_vlocation_updates_lock);
639+ &net->vl_updater, timeout * HZ);
640+ spin_unlock(&net->vl_updates_lock);
655641 _leave(" [nothing]");
656642 return;
657643 }
658644
659645 list_del_init(&vl->update);
660646 atomic_inc(&vl->usage);
661− spin_unlock(&afs_vlocation_updates_lock);
647+ spin_unlock(&net->vl_updates_lock);
662648
663649 /* we can now perform the update */
664650 _debug("update %s", vl->vldb.name);
@@ -688,18 +674,18 @@ static void afs_vlocation_updater(struct work_struct *work) · 23 unmodified lines
688674 vl->update_at = ktime_get_real_seconds() +
689675 afs_vlocation_update_timeout;
690676
691− spin_lock(&afs_vlocation_updates_lock);
677+ spin_lock(&net->vl_updates_lock);
692678
693− if (!list_empty(&afs_vlocation_updates)) {
679+ if (!list_empty(&net->vl_updates)) {
694680 /* next update in 10 minutes, but wait at least 1 second more
695681 * than the newest record already queued so that we don't spam
696682 * the VL server suddenly with lots of requests
697683 */
698− xvl = list_entry(afs_vlocation_updates.prev,
684+ xvl = list_entry(net->vl_updates.prev,
699685 struct afs_vlocation, update);
700686 if (vl->update_at <= xvl->update_at)
701687 vl->update_at = xvl->update_at + 1;
702− xvl = list_entry(afs_vlocation_updates.next,
688+ xvl = list_entry(net->vl_updates.next,
703689 struct afs_vlocation, update);
704690 timeout = xvl->update_at - now;
705691 if (timeout < 0)
@@ -710,11 +696,10 @@ static void afs_vlocation_updater(struct work_struct *work) · 4 unmodified lines
710696
711697 ASSERT(list_empty(&vl->update));
712698
713− list_add_tail(&vl->update, &afs_vlocation_updates);
699+ list_add_tail(&vl->update, &net->vl_updates);
714700
715701 _debug("timeout %ld", timeout);
716− queue_delayed_work(afs_vlocation_update_worker,
717− &afs_vlocation_update, timeout * HZ);
718− spin_unlock(&afs_vlocation_updates_lock);
719− afs_put_vlocation(vl);
702+ queue_delayed_work(afs_vlocation_update_worker, &net->vl_updater, timeout * HZ);
703+ spin_unlock(&net->vl_updates_lock);
704+ afs_put_vlocation(net, vl);
720705 }
fs/afs/volume.c+5−5
@@ -54,7 +54,7 @@ struct afs_volume *afs_volume_lookup(struct afs_mount_params *params) · 53 unmodified lines
5454 params->volnamesz, params->volnamesz, params->volname, params->rwpath);
5555
5656 /* lookup the volume location record */
57− vlocation = afs_vlocation_lookup(params->cell, params->key,
57+ vlocation = afs_vlocation_lookup(params->net, params->cell, params->key,
5858 params->volname, params->volnamesz);
5959 if (IS_ERR(vlocation)) {
6060 ret = PTR_ERR(vlocation);
@@ -138,7 +138,7 @@ success: · 77 unmodified lines
138138 _debug("kAFS selected %s volume %08x",
139139 afs_voltypes[volume->type], volume->vid);
140140 up_write(&params->cell->vl_sem);
141− afs_put_vlocation(vlocation);
141+ afs_put_vlocation(params->net, vlocation);
142142 _leave(" = %p", volume);
143143 return volume;
144144
@@ -146,7 +146,7 @@ success: · 1 unmodified line
146146 error_up:
147147 up_write(&params->cell->vl_sem);
148148 error:
149− afs_put_vlocation(vlocation);
149+ afs_put_vlocation(params->net, vlocation);
150150 _leave(" = %d", ret);
151151 return ERR_PTR(ret);
152152
@@ -163,7 +163,7 @@ error_discard: · 10 unmodified lines
163163 /*
164164 * destroy a volume record
165165 */
166−void afs_put_volume(struct afs_volume *volume)
166+void afs_put_volume(struct afs_net *net, struct afs_volume *volume)
167167 {
168168 struct afs_vlocation *vlocation;
169169 int loop;
@@ -195,7 +195,7 @@ void afs_put_volume(struct afs_volume *volume) · 25 unmodified lines
195195 #ifdef CONFIG_AFS_FSCACHE
196196 fscache_relinquish_cookie(volume->cache, 0);
197197 #endif
198− afs_put_vlocation(vlocation);
198+ afs_put_vlocation(net, vlocation);
199199
200200 for (loop = volume->nservers - 1; loop >= 0; loop--)
201201 afs_put_server(volume->servers[loop]);
include/uapi/linux/magic.h+1−0
@@ -47,6 +47,7 @@ · 46 unmodified lines
4747 #define OPENPROM_SUPER_MAGIC 0x9fa1
4848 #define QNX4_SUPER_MAGIC 0x002f /* qnx4 fs detection */
4949 #define QNX6_SUPER_MAGIC 0x68191122 /* qnx6 fs detection */
50+#define AFS_FS_MAGIC 0x6B414653
5051
5152 #define REISERFS_SUPER_MAGIC 0x52654973 /* used by gcc */
5253 /* used by file system utilities that