David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 1 | /* AFS cell and server record management |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include "internal.h" |
| 15 | |
| 16 | DECLARE_RWSEM(afs_proc_cells_sem); |
| 17 | LIST_HEAD(afs_proc_cells); |
| 18 | |
| 19 | static struct list_head afs_cells = LIST_HEAD_INIT(afs_cells); |
| 20 | static DEFINE_RWLOCK(afs_cells_lock); |
| 21 | static DECLARE_RWSEM(afs_cells_sem); /* add/remove serialisation */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 22 | static DECLARE_WAIT_QUEUE_HEAD(afs_cells_freeable_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | static struct afs_cell *afs_cell_root; |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | /* |
| 26 | * create a cell record |
| 27 | * - "name" is the name of the cell |
| 28 | * - "vllist" is a colon separated list of IP addresses in "a.b.c.d" format |
| 29 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 30 | struct afs_cell *afs_cell_create(const char *name, char *vllist) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | { |
| 32 | struct afs_cell *cell; |
| 33 | char *next; |
| 34 | int ret; |
| 35 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 36 | _enter("%s,%s", name, vllist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | BUG_ON(!name); /* TODO: want to look up "this cell" in the cache */ |
| 39 | |
| 40 | /* allocate and initialise a cell record */ |
| 41 | cell = kmalloc(sizeof(struct afs_cell) + strlen(name) + 1, GFP_KERNEL); |
| 42 | if (!cell) { |
| 43 | _leave(" = -ENOMEM"); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 44 | return ERR_PTR(-ENOMEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | down_write(&afs_cells_sem); |
| 48 | |
| 49 | memset(cell, 0, sizeof(struct afs_cell)); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 50 | atomic_set(&cell->usage, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | INIT_LIST_HEAD(&cell->link); |
| 53 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 54 | rwlock_init(&cell->servers_lock); |
| 55 | INIT_LIST_HEAD(&cell->servers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | init_rwsem(&cell->vl_sem); |
| 58 | INIT_LIST_HEAD(&cell->vl_list); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 59 | spin_lock_init(&cell->vl_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 61 | strcpy(cell->name, name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
| 63 | /* fill in the VL server list from the rest of the string */ |
| 64 | ret = -EINVAL; |
| 65 | do { |
| 66 | unsigned a, b, c, d; |
| 67 | |
| 68 | next = strchr(vllist, ':'); |
| 69 | if (next) |
| 70 | *next++ = 0; |
| 71 | |
| 72 | if (sscanf(vllist, "%u.%u.%u.%u", &a, &b, &c, &d) != 4) |
| 73 | goto badaddr; |
| 74 | |
| 75 | if (a > 255 || b > 255 || c > 255 || d > 255) |
| 76 | goto badaddr; |
| 77 | |
| 78 | cell->vl_addrs[cell->vl_naddrs++].s_addr = |
| 79 | htonl((a << 24) | (b << 16) | (c << 8) | d); |
| 80 | |
| 81 | if (cell->vl_naddrs >= AFS_CELL_MAX_ADDRS) |
| 82 | break; |
| 83 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 84 | } while ((vllist = next)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 86 | /* add a proc directory for this cell */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | ret = afs_proc_cell_setup(cell); |
| 88 | if (ret < 0) |
| 89 | goto error; |
| 90 | |
| 91 | #ifdef AFS_CACHING_SUPPORT |
| 92 | /* put it up for caching */ |
| 93 | cachefs_acquire_cookie(afs_cache_netfs.primary_index, |
| 94 | &afs_vlocation_cache_index_def, |
| 95 | cell, |
| 96 | &cell->cache); |
| 97 | #endif |
| 98 | |
| 99 | /* add to the cell lists */ |
| 100 | write_lock(&afs_cells_lock); |
| 101 | list_add_tail(&cell->link, &afs_cells); |
| 102 | write_unlock(&afs_cells_lock); |
| 103 | |
| 104 | down_write(&afs_proc_cells_sem); |
| 105 | list_add_tail(&cell->proc_link, &afs_proc_cells); |
| 106 | up_write(&afs_proc_cells_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | up_write(&afs_cells_sem); |
| 108 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 109 | _leave(" = %p", cell); |
| 110 | return cell; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 112 | badaddr: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 113 | printk(KERN_ERR "kAFS: bad VL server IP address\n"); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 114 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | up_write(&afs_cells_sem); |
| 116 | kfree(cell); |
| 117 | _leave(" = %d", ret); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 118 | return ERR_PTR(ret); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 119 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 122 | * set the root cell information |
| 123 | * - can be called with a module parameter string |
| 124 | * - can be called from a write to /proc/fs/afs/rootcell |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | */ |
| 126 | int afs_cell_init(char *rootcell) |
| 127 | { |
| 128 | struct afs_cell *old_root, *new_root; |
| 129 | char *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | _enter(""); |
| 132 | |
| 133 | if (!rootcell) { |
| 134 | /* module is loaded with no parameters, or built statically. |
| 135 | * - in the future we might initialize cell DB here. |
| 136 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 137 | _leave(" = 0 [no root]"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | cp = strchr(rootcell, ':'); |
| 142 | if (!cp) { |
| 143 | printk(KERN_ERR "kAFS: no VL server IP addresses specified\n"); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 144 | _leave(" = -EINVAL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | return -EINVAL; |
| 146 | } |
| 147 | |
| 148 | /* allocate a cell record for the root cell */ |
| 149 | *cp++ = 0; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 150 | new_root = afs_cell_create(rootcell, cp); |
| 151 | if (IS_ERR(new_root)) { |
| 152 | _leave(" = %ld", PTR_ERR(new_root)); |
| 153 | return PTR_ERR(new_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | } |
| 155 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 156 | /* install the new cell */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | write_lock(&afs_cells_lock); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 158 | old_root = afs_cell_root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | afs_cell_root = new_root; |
| 160 | write_unlock(&afs_cells_lock); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 161 | afs_put_cell(old_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 163 | _leave(" = 0"); |
| 164 | return 0; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 165 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | /* |
| 168 | * lookup a cell record |
| 169 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 170 | struct afs_cell *afs_cell_lookup(const char *name, unsigned namesz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
| 172 | struct afs_cell *cell; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
| 174 | _enter("\"%*.*s\",", namesz, namesz, name ? name : ""); |
| 175 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 176 | down_read(&afs_cells_sem); |
| 177 | read_lock(&afs_cells_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
| 179 | if (name) { |
| 180 | /* if the cell was named, look for it in the cell record list */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | list_for_each_entry(cell, &afs_cells, link) { |
| 182 | if (strncmp(cell->name, name, namesz) == 0) { |
| 183 | afs_get_cell(cell); |
| 184 | goto found; |
| 185 | } |
| 186 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 187 | cell = ERR_PTR(-ENOENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | found: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 189 | ; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 190 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | cell = afs_cell_root; |
| 192 | if (!cell) { |
| 193 | /* this should not happen unless user tries to mount |
| 194 | * when root cell is not set. Return an impossibly |
| 195 | * bizzare errno to alert the user. Things like |
| 196 | * ENOENT might be "more appropriate" but they happen |
| 197 | * for other reasons. |
| 198 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 199 | cell = ERR_PTR(-EDESTADDRREQ); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 200 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | afs_get_cell(cell); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 206 | read_unlock(&afs_cells_lock); |
| 207 | up_read(&afs_cells_sem); |
| 208 | _leave(" = %p", cell); |
| 209 | return cell; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 210 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | /* |
| 213 | * try and get a cell record |
| 214 | */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 215 | struct afs_cell *afs_get_cell_maybe(struct afs_cell *cell) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | write_lock(&afs_cells_lock); |
| 218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | if (cell && !list_empty(&cell->link)) |
| 220 | afs_get_cell(cell); |
| 221 | else |
| 222 | cell = NULL; |
| 223 | |
| 224 | write_unlock(&afs_cells_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | return cell; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 226 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | /* |
| 229 | * destroy a cell record |
| 230 | */ |
| 231 | void afs_put_cell(struct afs_cell *cell) |
| 232 | { |
| 233 | if (!cell) |
| 234 | return; |
| 235 | |
| 236 | _enter("%p{%d,%s}", cell, atomic_read(&cell->usage), cell->name); |
| 237 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 238 | ASSERTCMP(atomic_read(&cell->usage), >, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
| 240 | /* to prevent a race, the decrement and the dequeue must be effectively |
| 241 | * atomic */ |
| 242 | write_lock(&afs_cells_lock); |
| 243 | |
| 244 | if (likely(!atomic_dec_and_test(&cell->usage))) { |
| 245 | write_unlock(&afs_cells_lock); |
| 246 | _leave(""); |
| 247 | return; |
| 248 | } |
| 249 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 250 | ASSERT(list_empty(&cell->servers)); |
| 251 | ASSERT(list_empty(&cell->vl_list)); |
| 252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | write_unlock(&afs_cells_lock); |
| 254 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 255 | wake_up(&afs_cells_freeable_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
| 257 | _leave(" [unused]"); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 258 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | /* |
| 261 | * destroy a cell record |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 262 | * - must be called with the afs_cells_sem write-locked |
| 263 | * - cell->link should have been broken by the caller |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | */ |
| 265 | static void afs_cell_destroy(struct afs_cell *cell) |
| 266 | { |
| 267 | _enter("%p{%d,%s}", cell, atomic_read(&cell->usage), cell->name); |
| 268 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 269 | ASSERTCMP(atomic_read(&cell->usage), >=, 0); |
| 270 | ASSERT(list_empty(&cell->link)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 272 | /* wait for everyone to stop using the cell */ |
| 273 | if (atomic_read(&cell->usage) > 0) { |
| 274 | DECLARE_WAITQUEUE(myself, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 276 | _debug("wait for cell %s", cell->name); |
| 277 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 278 | add_wait_queue(&afs_cells_freeable_wq, &myself); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 280 | while (atomic_read(&cell->usage) > 0) { |
| 281 | schedule(); |
| 282 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 283 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 285 | remove_wait_queue(&afs_cells_freeable_wq, &myself); |
| 286 | set_current_state(TASK_RUNNING); |
| 287 | } |
| 288 | |
| 289 | _debug("cell dead"); |
| 290 | ASSERTCMP(atomic_read(&cell->usage), ==, 0); |
| 291 | ASSERT(list_empty(&cell->servers)); |
| 292 | ASSERT(list_empty(&cell->vl_list)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
| 294 | afs_proc_cell_remove(cell); |
| 295 | |
| 296 | down_write(&afs_proc_cells_sem); |
| 297 | list_del_init(&cell->proc_link); |
| 298 | up_write(&afs_proc_cells_sem); |
| 299 | |
| 300 | #ifdef AFS_CACHING_SUPPORT |
| 301 | cachefs_relinquish_cookie(cell->cache, 0); |
| 302 | #endif |
| 303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | kfree(cell); |
| 305 | |
| 306 | _leave(" [destroyed]"); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 307 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | * purge in-memory cell database on module unload or afs_init() failure |
| 311 | * - the timeout daemon is stopped before calling this |
| 312 | */ |
| 313 | void afs_cell_purge(void) |
| 314 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | struct afs_cell *cell; |
| 316 | |
| 317 | _enter(""); |
| 318 | |
| 319 | afs_put_cell(afs_cell_root); |
| 320 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 321 | down_write(&afs_cells_sem); |
| 322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | while (!list_empty(&afs_cells)) { |
| 324 | cell = NULL; |
| 325 | |
| 326 | /* remove the next cell from the front of the list */ |
| 327 | write_lock(&afs_cells_lock); |
| 328 | |
| 329 | if (!list_empty(&afs_cells)) { |
| 330 | cell = list_entry(afs_cells.next, |
| 331 | struct afs_cell, link); |
| 332 | list_del_init(&cell->link); |
| 333 | } |
| 334 | |
| 335 | write_unlock(&afs_cells_lock); |
| 336 | |
| 337 | if (cell) { |
| 338 | _debug("PURGING CELL %s (%d)", |
| 339 | cell->name, atomic_read(&cell->usage)); |
| 340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | /* now the cell should be left with no references */ |
| 342 | afs_cell_destroy(cell); |
| 343 | } |
| 344 | } |
| 345 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame^] | 346 | up_write(&afs_cells_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | _leave(""); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 348 | } |