2007-04-26 22:49:28 +00:00
|
|
|
/* AFS cell and server record management
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
|
|
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
2007-04-26 22:57:07 +00:00
|
|
|
#include <linux/key.h>
|
|
|
|
#include <linux/ctype.h>
|
2010-08-04 14:16:38 +00:00
|
|
|
#include <linux/dns_resolver.h>
|
Detach sched.h from mm.h
First thing mm.h does is including sched.h solely for can_do_mlock() inline
function which has "current" dereference inside. By dealing with can_do_mlock()
mm.h can be detached from sched.h which is good. See below, why.
This patch
a) removes unconditional inclusion of sched.h from mm.h
b) makes can_do_mlock() normal function in mm/mlock.c
c) exports can_do_mlock() to not break compilation
d) adds sched.h inclusions back to files that were getting it indirectly.
e) adds less bloated headers to some files (asm/signal.h, jiffies.h) that were
getting them indirectly
Net result is:
a) mm.h users would get less code to open, read, preprocess, parse, ... if
they don't need sched.h
b) sched.h stops being dependency for significant number of files:
on x86_64 allmodconfig touching sched.h results in recompile of 4083 files,
after patch it's only 3744 (-8.3%).
Cross-compile tested on
all arm defconfigs, all mips defconfigs, all powerpc defconfigs,
alpha alpha-up
arm
i386 i386-up i386-defconfig i386-allnoconfig
ia64 ia64-up
m68k
mips
parisc parisc-up
powerpc powerpc-up
s390 s390-up
sparc sparc-up
sparc64 sparc64-up
um-x86_64
x86_64 x86_64-up x86_64-defconfig x86_64-allnoconfig
as well as my two usual configs.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-20 21:22:52 +00:00
|
|
|
#include <linux/sched.h>
|
2017-11-02 15:27:47 +00:00
|
|
|
#include <linux/inet.h>
|
2007-04-26 22:57:07 +00:00
|
|
|
#include <keys/rxrpc-type.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
/*
|
2007-04-26 22:57:07 +00:00
|
|
|
* allocate a cell record and fill in its name, VL server address list and
|
|
|
|
* allocate an anonymous key
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2017-11-02 15:27:45 +00:00
|
|
|
static struct afs_cell *afs_cell_alloc(struct afs_net *net,
|
|
|
|
const char *name, unsigned namelen,
|
2010-08-11 08:38:04 +00:00
|
|
|
char *vllist)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct afs_cell *cell;
|
2007-10-17 06:29:46 +00:00
|
|
|
struct key *key;
|
2007-04-26 22:57:07 +00:00
|
|
|
char keyname[4 + AFS_MAXCELLNAME + 1], *cp, *dp, *next;
|
2010-08-04 14:16:38 +00:00
|
|
|
char *dvllist = NULL, *_vllist = NULL;
|
|
|
|
char delimiter = ':';
|
2017-11-02 15:27:47 +00:00
|
|
|
int ret, i;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-08-11 08:38:04 +00:00
|
|
|
_enter("%*.*s,%s", namelen, namelen, name ?: "", vllist);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
BUG_ON(!name); /* TODO: want to look up "this cell" in the cache */
|
|
|
|
|
2010-08-04 14:16:38 +00:00
|
|
|
if (namelen > AFS_MAXCELLNAME) {
|
|
|
|
_leave(" = -ENAMETOOLONG");
|
2007-04-26 22:57:07 +00:00
|
|
|
return ERR_PTR(-ENAMETOOLONG);
|
2010-08-04 14:16:38 +00:00
|
|
|
}
|
2007-04-26 22:57:07 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* allocate and initialise a cell record */
|
2007-04-26 22:57:07 +00:00
|
|
|
cell = kzalloc(sizeof(struct afs_cell) + namelen + 1, GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!cell) {
|
|
|
|
_leave(" = -ENOMEM");
|
2007-04-26 22:55:03 +00:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-04-26 22:57:07 +00:00
|
|
|
memcpy(cell->name, name, namelen);
|
|
|
|
cell->name[namelen] = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-04-26 22:55:03 +00:00
|
|
|
atomic_set(&cell->usage, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
INIT_LIST_HEAD(&cell->link);
|
2017-11-02 15:27:45 +00:00
|
|
|
cell->net = net;
|
2007-04-26 22:55:03 +00:00
|
|
|
rwlock_init(&cell->servers_lock);
|
|
|
|
INIT_LIST_HEAD(&cell->servers);
|
2005-04-16 22:20:36 +00:00
|
|
|
init_rwsem(&cell->vl_sem);
|
|
|
|
INIT_LIST_HEAD(&cell->vl_list);
|
2007-04-26 22:55:03 +00:00
|
|
|
spin_lock_init(&cell->vl_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-11-02 15:27:47 +00:00
|
|
|
for (i = 0; i < AFS_CELL_MAX_ADDRS; i++) {
|
|
|
|
struct sockaddr_rxrpc *srx = &cell->vl_addrs[i];
|
|
|
|
srx->srx_family = AF_RXRPC;
|
|
|
|
srx->srx_service = VL_SERVICE;
|
|
|
|
srx->transport_type = SOCK_DGRAM;
|
|
|
|
srx->transport.sin.sin_port = htons(AFS_VL_PORT);
|
|
|
|
}
|
|
|
|
|
2010-08-04 14:16:38 +00:00
|
|
|
/* if the ip address is invalid, try dns query */
|
|
|
|
if (!vllist || strlen(vllist) < 7) {
|
|
|
|
ret = dns_query("afsdb", name, namelen, "ipv4", &dvllist, NULL);
|
|
|
|
if (ret < 0) {
|
2010-08-11 08:37:58 +00:00
|
|
|
if (ret == -ENODATA || ret == -EAGAIN || ret == -ENOKEY)
|
|
|
|
/* translate these errors into something
|
|
|
|
* userspace might understand */
|
|
|
|
ret = -EDESTADDRREQ;
|
2010-08-04 14:16:38 +00:00
|
|
|
_leave(" = %d", ret);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
_vllist = dvllist;
|
|
|
|
|
|
|
|
/* change the delimiter for user-space reply */
|
|
|
|
delimiter = ',';
|
|
|
|
|
|
|
|
} else {
|
2017-11-02 15:27:47 +00:00
|
|
|
if (strchr(vllist, ',') || !strchr(vllist, '.'))
|
|
|
|
delimiter = ',';
|
2010-08-04 14:16:38 +00:00
|
|
|
_vllist = vllist;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* fill in the VL server list from the rest of the string */
|
|
|
|
do {
|
2017-11-02 15:27:47 +00:00
|
|
|
struct sockaddr_rxrpc *srx = &cell->vl_addrs[cell->vl_naddrs];
|
2017-11-02 15:27:47 +00:00
|
|
|
const char *end;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-08-04 14:16:38 +00:00
|
|
|
next = strchr(_vllist, delimiter);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (next)
|
|
|
|
*next++ = 0;
|
|
|
|
|
2017-11-02 15:27:47 +00:00
|
|
|
if (in4_pton(_vllist, -1, (u8 *)&srx->transport.sin6.sin6_addr.s6_addr32[3],
|
|
|
|
-1, &end)) {
|
|
|
|
srx->transport_len = sizeof(struct sockaddr_in6);
|
|
|
|
srx->transport.sin6.sin6_family = AF_INET6;
|
|
|
|
srx->transport.sin6.sin6_flowinfo = 0;
|
|
|
|
srx->transport.sin6.sin6_scope_id = 0;
|
|
|
|
srx->transport.sin6.sin6_addr.s6_addr32[0] = 0;
|
|
|
|
srx->transport.sin6.sin6_addr.s6_addr32[1] = 0;
|
|
|
|
srx->transport.sin6.sin6_addr.s6_addr32[2] = htonl(0xffff);
|
|
|
|
} else if (in6_pton(_vllist, -1, srx->transport.sin6.sin6_addr.s6_addr,
|
|
|
|
-1, &end)) {
|
|
|
|
srx->transport_len = sizeof(struct sockaddr_in6);
|
|
|
|
srx->transport.sin6.sin6_family = AF_INET6;
|
|
|
|
srx->transport.sin6.sin6_flowinfo = 0;
|
|
|
|
srx->transport.sin6.sin6_scope_id = 0;
|
|
|
|
} else {
|
2007-04-26 22:57:07 +00:00
|
|
|
goto bad_address;
|
2017-11-02 15:27:47 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-11-02 15:27:47 +00:00
|
|
|
} while (cell->vl_naddrs++,
|
|
|
|
cell->vl_naddrs < AFS_CELL_MAX_ADDRS && (_vllist = next));
|
2007-04-26 22:57:07 +00:00
|
|
|
|
|
|
|
/* create a key to represent an anonymous user */
|
|
|
|
memcpy(keyname, "afs@", 4);
|
|
|
|
dp = keyname + 4;
|
|
|
|
cp = cell->name;
|
|
|
|
do {
|
|
|
|
*dp++ = toupper(*cp);
|
|
|
|
} while (*cp++);
|
|
|
|
|
2007-10-17 06:29:46 +00:00
|
|
|
key = rxrpc_get_null_key(keyname);
|
|
|
|
if (IS_ERR(key)) {
|
|
|
|
_debug("no key");
|
|
|
|
ret = PTR_ERR(key);
|
2007-04-26 22:57:07 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2007-10-17 06:29:46 +00:00
|
|
|
cell->anonymous_key = key;
|
2007-04-26 22:57:07 +00:00
|
|
|
|
|
|
|
_debug("anon key %p{%x}",
|
|
|
|
cell->anonymous_key, key_serial(cell->anonymous_key));
|
|
|
|
|
|
|
|
_leave(" = %p", cell);
|
|
|
|
return cell;
|
|
|
|
|
|
|
|
bad_address:
|
|
|
|
printk(KERN_ERR "kAFS: bad VL server IP address\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
error:
|
|
|
|
key_put(cell->anonymous_key);
|
2010-08-04 14:16:38 +00:00
|
|
|
kfree(dvllist);
|
2007-04-26 22:57:07 +00:00
|
|
|
kfree(cell);
|
|
|
|
_leave(" = %d", ret);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-04-26 22:57:07 +00:00
|
|
|
/*
|
2010-08-11 08:38:04 +00:00
|
|
|
* afs_cell_crate() - create a cell record
|
2017-11-02 15:27:45 +00:00
|
|
|
* @net: The network namespace
|
2010-08-11 08:38:04 +00:00
|
|
|
* @name: is the name of the cell.
|
|
|
|
* @namsesz: is the strlen of the cell name.
|
|
|
|
* @vllist: is a colon separated list of IP addresses in "a.b.c.d" format.
|
|
|
|
* @retref: is T to return the cell reference when the cell exists.
|
2007-04-26 22:57:07 +00:00
|
|
|
*/
|
2017-11-02 15:27:45 +00:00
|
|
|
struct afs_cell *afs_cell_create(struct afs_net *net,
|
|
|
|
const char *name, unsigned namesz,
|
2010-08-11 08:38:04 +00:00
|
|
|
char *vllist, bool retref)
|
2007-04-26 22:57:07 +00:00
|
|
|
{
|
|
|
|
struct afs_cell *cell;
|
|
|
|
int ret;
|
|
|
|
|
2010-08-11 08:38:04 +00:00
|
|
|
_enter("%*.*s,%s", namesz, namesz, name ?: "", vllist);
|
2007-04-26 22:57:07 +00:00
|
|
|
|
2017-11-02 15:27:45 +00:00
|
|
|
down_write(&net->cells_sem);
|
|
|
|
read_lock(&net->cells_lock);
|
|
|
|
list_for_each_entry(cell, &net->cells, link) {
|
2010-08-11 08:38:04 +00:00
|
|
|
if (strncasecmp(cell->name, name, namesz) == 0)
|
2008-03-28 21:15:55 +00:00
|
|
|
goto duplicate_name;
|
|
|
|
}
|
2017-11-02 15:27:45 +00:00
|
|
|
read_unlock(&net->cells_lock);
|
2008-03-28 21:15:55 +00:00
|
|
|
|
2017-11-02 15:27:45 +00:00
|
|
|
cell = afs_cell_alloc(net, name, namesz, vllist);
|
2007-04-26 22:57:07 +00:00
|
|
|
if (IS_ERR(cell)) {
|
|
|
|
_leave(" = %ld", PTR_ERR(cell));
|
2017-11-02 15:27:45 +00:00
|
|
|
up_write(&net->cells_sem);
|
2007-04-26 22:57:07 +00:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2007-04-26 22:55:03 +00:00
|
|
|
/* add a proc directory for this cell */
|
2017-11-02 15:27:45 +00:00
|
|
|
ret = afs_proc_cell_setup(net, cell);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
#ifdef CONFIG_AFS_FSCACHE
|
|
|
|
/* put it up for caching (this never returns an error) */
|
|
|
|
cell->cache = fscache_acquire_cookie(afs_cache_netfs.primary_index,
|
|
|
|
&afs_cell_cache_index_def,
|
FS-Cache: Provide the ability to enable/disable cookies
Provide the ability to enable and disable fscache cookies. A disabled cookie
will reject or ignore further requests to:
Acquire a child cookie
Invalidate and update backing objects
Check the consistency of a backing object
Allocate storage for backing page
Read backing pages
Write to backing pages
but still allows:
Checks/waits on the completion of already in-progress objects
Uncaching of pages
Relinquishment of cookies
Two new operations are provided:
(1) Disable a cookie:
void fscache_disable_cookie(struct fscache_cookie *cookie,
bool invalidate);
If the cookie is not already disabled, this locks the cookie against other
dis/enablement ops, marks the cookie as being disabled, discards or
invalidates any backing objects and waits for cessation of activity on any
associated object.
This is a wrapper around a chunk split out of fscache_relinquish_cookie(),
but it reinitialises the cookie such that it can be reenabled.
All possible failures are handled internally. The caller should consider
calling fscache_uncache_all_inode_pages() afterwards to make sure all page
markings are cleared up.
(2) Enable a cookie:
void fscache_enable_cookie(struct fscache_cookie *cookie,
bool (*can_enable)(void *data),
void *data)
If the cookie is not already enabled, this locks the cookie against other
dis/enablement ops, invokes can_enable() and, if the cookie is not an
index cookie, will begin the procedure of acquiring backing objects.
The optional can_enable() function is passed the data argument and returns
a ruling as to whether or not enablement should actually be permitted to
begin.
All possible failures are handled internally. The cookie will only be
marked as enabled if provisional backing objects are allocated.
A later patch will introduce these to NFS. Cookie enablement during nfs_open()
is then contingent on i_writecount <= 0. can_enable() checks for a race
between open(O_RDONLY) and open(O_WRONLY/O_RDWR). This simplifies NFS's cookie
handling and allows us to get rid of open(O_RDONLY) accidentally introducing
caching to an inode that's open for writing already.
One operation has its API modified:
(3) Acquire a cookie.
struct fscache_cookie *fscache_acquire_cookie(
struct fscache_cookie *parent,
const struct fscache_cookie_def *def,
void *netfs_data,
bool enable);
This now has an additional argument that indicates whether the requested
cookie should be enabled by default. It doesn't need the can_enable()
function because the caller must prevent multiple calls for the same netfs
object and it doesn't need to take the enablement lock because no one else
can get at the cookie before this returns.
Signed-off-by: David Howells <dhowells@redhat.com
2013-09-20 23:09:31 +00:00
|
|
|
cell, true);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* add to the cell lists */
|
2017-11-02 15:27:45 +00:00
|
|
|
write_lock(&net->cells_lock);
|
|
|
|
list_add_tail(&cell->link, &net->cells);
|
|
|
|
write_unlock(&net->cells_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-11-02 15:27:45 +00:00
|
|
|
down_write(&net->proc_cells_sem);
|
|
|
|
list_add_tail(&cell->proc_link, &net->proc_cells);
|
|
|
|
up_write(&net->proc_cells_sem);
|
|
|
|
up_write(&net->cells_sem);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-04-26 22:55:03 +00:00
|
|
|
_leave(" = %p", cell);
|
|
|
|
return cell;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-04-26 22:49:28 +00:00
|
|
|
error:
|
2017-11-02 15:27:45 +00:00
|
|
|
up_write(&net->cells_sem);
|
2007-04-26 22:57:07 +00:00
|
|
|
key_put(cell->anonymous_key);
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(cell);
|
|
|
|
_leave(" = %d", ret);
|
2007-04-26 22:55:03 +00:00
|
|
|
return ERR_PTR(ret);
|
2008-03-28 21:15:55 +00:00
|
|
|
|
|
|
|
duplicate_name:
|
2010-08-11 08:38:04 +00:00
|
|
|
if (retref && !IS_ERR(cell))
|
|
|
|
afs_get_cell(cell);
|
|
|
|
|
2017-11-02 15:27:45 +00:00
|
|
|
read_unlock(&net->cells_lock);
|
|
|
|
up_write(&net->cells_sem);
|
2010-08-11 08:38:04 +00:00
|
|
|
|
|
|
|
if (retref) {
|
|
|
|
_leave(" = %p", cell);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
_leave(" = -EEXIST");
|
2008-03-28 21:15:55 +00:00
|
|
|
return ERR_PTR(-EEXIST);
|
2007-04-26 22:49:28 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
2007-04-26 22:55:03 +00:00
|
|
|
* set the root cell information
|
|
|
|
* - can be called with a module parameter string
|
|
|
|
* - can be called from a write to /proc/fs/afs/rootcell
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2017-11-02 15:27:45 +00:00
|
|
|
int afs_cell_init(struct afs_net *net, char *rootcell)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct afs_cell *old_root, *new_root;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
_enter("");
|
|
|
|
|
|
|
|
if (!rootcell) {
|
|
|
|
/* module is loaded with no parameters, or built statically.
|
|
|
|
* - in the future we might initialize cell DB here.
|
|
|
|
*/
|
2007-04-26 22:55:03 +00:00
|
|
|
_leave(" = 0 [no root]");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cp = strchr(rootcell, ':');
|
2010-08-04 14:16:38 +00:00
|
|
|
if (!cp)
|
|
|
|
_debug("kAFS: no VL server IP addresses specified");
|
|
|
|
else
|
|
|
|
*cp++ = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* allocate a cell record for the root cell */
|
2017-11-02 15:27:45 +00:00
|
|
|
new_root = afs_cell_create(net, rootcell, strlen(rootcell), cp, false);
|
2007-04-26 22:55:03 +00:00
|
|
|
if (IS_ERR(new_root)) {
|
|
|
|
_leave(" = %ld", PTR_ERR(new_root));
|
|
|
|
return PTR_ERR(new_root);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-04-26 22:55:03 +00:00
|
|
|
/* install the new cell */
|
2017-11-02 15:27:45 +00:00
|
|
|
write_lock(&net->cells_lock);
|
|
|
|
old_root = net->ws_cell;
|
|
|
|
net->ws_cell = new_root;
|
|
|
|
write_unlock(&net->cells_lock);
|
2017-11-02 15:27:46 +00:00
|
|
|
afs_put_cell(net, old_root);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-04-26 22:55:03 +00:00
|
|
|
_leave(" = 0");
|
|
|
|
return 0;
|
2007-04-26 22:49:28 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* lookup a cell record
|
|
|
|
*/
|
2017-11-02 15:27:45 +00:00
|
|
|
struct afs_cell *afs_cell_lookup(struct afs_net *net,
|
|
|
|
const char *name, unsigned namesz,
|
2010-08-11 08:38:04 +00:00
|
|
|
bool dns_cell)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct afs_cell *cell;
|
|
|
|
|
2010-08-11 08:38:04 +00:00
|
|
|
_enter("\"%*.*s\",", namesz, namesz, name ?: "");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-11-02 15:27:45 +00:00
|
|
|
down_read(&net->cells_sem);
|
|
|
|
read_lock(&net->cells_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (name) {
|
|
|
|
/* if the cell was named, look for it in the cell record list */
|
2017-11-02 15:27:45 +00:00
|
|
|
list_for_each_entry(cell, &net->cells, link) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (strncmp(cell->name, name, namesz) == 0) {
|
|
|
|
afs_get_cell(cell);
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
}
|
2007-04-26 22:55:03 +00:00
|
|
|
cell = ERR_PTR(-ENOENT);
|
2010-08-11 08:38:04 +00:00
|
|
|
if (dns_cell)
|
|
|
|
goto create_cell;
|
2005-04-16 22:20:36 +00:00
|
|
|
found:
|
2007-04-26 22:55:03 +00:00
|
|
|
;
|
2007-04-26 22:49:28 +00:00
|
|
|
} else {
|
2017-11-02 15:27:45 +00:00
|
|
|
cell = net->ws_cell;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!cell) {
|
|
|
|
/* this should not happen unless user tries to mount
|
|
|
|
* when root cell is not set. Return an impossibly
|
2011-03-31 01:57:33 +00:00
|
|
|
* bizarre errno to alert the user. Things like
|
2005-04-16 22:20:36 +00:00
|
|
|
* ENOENT might be "more appropriate" but they happen
|
|
|
|
* for other reasons.
|
|
|
|
*/
|
2007-04-26 22:55:03 +00:00
|
|
|
cell = ERR_PTR(-EDESTADDRREQ);
|
2007-04-26 22:49:28 +00:00
|
|
|
} else {
|
2005-04-16 22:20:36 +00:00
|
|
|
afs_get_cell(cell);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-02 15:27:45 +00:00
|
|
|
read_unlock(&net->cells_lock);
|
|
|
|
up_read(&net->cells_sem);
|
2007-04-26 22:55:03 +00:00
|
|
|
_leave(" = %p", cell);
|
|
|
|
return cell;
|
2010-08-11 08:38:04 +00:00
|
|
|
|
|
|
|
create_cell:
|
2017-11-02 15:27:45 +00:00
|
|
|
read_unlock(&net->cells_lock);
|
|
|
|
up_read(&net->cells_sem);
|
2010-08-11 08:38:04 +00:00
|
|
|
|
2017-11-02 15:27:45 +00:00
|
|
|
cell = afs_cell_create(net, name, namesz, NULL, true);
|
2010-08-11 08:38:04 +00:00
|
|
|
|
|
|
|
_leave(" = %p", cell);
|
|
|
|
return cell;
|
2007-04-26 22:49:28 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-10-17 06:26:41 +00:00
|
|
|
#if 0
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* try and get a cell record
|
|
|
|
*/
|
2007-04-26 22:55:03 +00:00
|
|
|
struct afs_cell *afs_get_cell_maybe(struct afs_cell *cell)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2017-11-02 15:27:45 +00:00
|
|
|
write_lock(&net->cells_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (cell && !list_empty(&cell->link))
|
|
|
|
afs_get_cell(cell);
|
|
|
|
else
|
|
|
|
cell = NULL;
|
|
|
|
|
2017-11-02 15:27:45 +00:00
|
|
|
write_unlock(&net->cells_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return cell;
|
2007-04-26 22:49:28 +00:00
|
|
|
}
|
2007-10-17 06:26:41 +00:00
|
|
|
#endif /* 0 */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* destroy a cell record
|
|
|
|
*/
|
2017-11-02 15:27:46 +00:00
|
|
|
void afs_put_cell(struct afs_net *net, struct afs_cell *cell)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
if (!cell)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_enter("%p{%d,%s}", cell, atomic_read(&cell->usage), cell->name);
|
|
|
|
|
2007-04-26 22:55:03 +00:00
|
|
|
ASSERTCMP(atomic_read(&cell->usage), >, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* to prevent a race, the decrement and the dequeue must be effectively
|
|
|
|
* atomic */
|
2017-11-02 15:27:46 +00:00
|
|
|
write_lock(&net->cells_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (likely(!atomic_dec_and_test(&cell->usage))) {
|
2017-11-02 15:27:46 +00:00
|
|
|
write_unlock(&net->cells_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
_leave("");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-04-26 22:55:03 +00:00
|
|
|
ASSERT(list_empty(&cell->servers));
|
|
|
|
ASSERT(list_empty(&cell->vl_list));
|
|
|
|
|
2017-11-02 15:27:46 +00:00
|
|
|
wake_up(&net->cells_freeable_wq);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-11-02 15:27:46 +00:00
|
|
|
write_unlock(&net->cells_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
_leave(" [unused]");
|
2007-04-26 22:49:28 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* destroy a cell record
|
2017-11-02 15:27:45 +00:00
|
|
|
* - must be called with the net->cells_sem write-locked
|
2007-04-26 22:55:03 +00:00
|
|
|
* - cell->link should have been broken by the caller
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2017-11-02 15:27:45 +00:00
|
|
|
static void afs_cell_destroy(struct afs_net *net, struct afs_cell *cell)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
_enter("%p{%d,%s}", cell, atomic_read(&cell->usage), cell->name);
|
|
|
|
|
2007-04-26 22:55:03 +00:00
|
|
|
ASSERTCMP(atomic_read(&cell->usage), >=, 0);
|
|
|
|
ASSERT(list_empty(&cell->link));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-04-26 22:55:03 +00:00
|
|
|
/* wait for everyone to stop using the cell */
|
|
|
|
if (atomic_read(&cell->usage) > 0) {
|
|
|
|
DECLARE_WAITQUEUE(myself, current);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-04-26 22:55:03 +00:00
|
|
|
_debug("wait for cell %s", cell->name);
|
|
|
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
2017-11-02 15:27:45 +00:00
|
|
|
add_wait_queue(&net->cells_freeable_wq, &myself);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-04-26 22:55:03 +00:00
|
|
|
while (atomic_read(&cell->usage) > 0) {
|
|
|
|
schedule();
|
|
|
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-11-02 15:27:45 +00:00
|
|
|
remove_wait_queue(&net->cells_freeable_wq, &myself);
|
2007-04-26 22:55:03 +00:00
|
|
|
set_current_state(TASK_RUNNING);
|
|
|
|
}
|
|
|
|
|
|
|
|
_debug("cell dead");
|
|
|
|
ASSERTCMP(atomic_read(&cell->usage), ==, 0);
|
|
|
|
ASSERT(list_empty(&cell->servers));
|
|
|
|
ASSERT(list_empty(&cell->vl_list));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-11-02 15:27:45 +00:00
|
|
|
afs_proc_cell_remove(net, cell);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-11-02 15:27:45 +00:00
|
|
|
down_write(&net->proc_cells_sem);
|
2005-04-16 22:20:36 +00:00
|
|
|
list_del_init(&cell->proc_link);
|
2017-11-02 15:27:45 +00:00
|
|
|
up_write(&net->proc_cells_sem);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-04-03 15:42:41 +00:00
|
|
|
#ifdef CONFIG_AFS_FSCACHE
|
|
|
|
fscache_relinquish_cookie(cell->cache, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
2007-04-26 22:57:07 +00:00
|
|
|
key_put(cell->anonymous_key);
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(cell);
|
|
|
|
|
|
|
|
_leave(" [destroyed]");
|
2007-04-26 22:49:28 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* purge in-memory cell database on module unload or afs_init() failure
|
|
|
|
* - the timeout daemon is stopped before calling this
|
|
|
|
*/
|
2017-11-02 15:27:45 +00:00
|
|
|
void afs_cell_purge(struct afs_net *net)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct afs_cell *cell;
|
|
|
|
|
|
|
|
_enter("");
|
|
|
|
|
2017-11-02 15:27:46 +00:00
|
|
|
afs_put_cell(net, net->ws_cell);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-11-02 15:27:45 +00:00
|
|
|
down_write(&net->cells_sem);
|
2007-04-26 22:55:03 +00:00
|
|
|
|
2017-11-02 15:27:45 +00:00
|
|
|
while (!list_empty(&net->cells)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
cell = NULL;
|
|
|
|
|
|
|
|
/* remove the next cell from the front of the list */
|
2017-11-02 15:27:45 +00:00
|
|
|
write_lock(&net->cells_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-11-02 15:27:45 +00:00
|
|
|
if (!list_empty(&net->cells)) {
|
|
|
|
cell = list_entry(net->cells.next,
|
2005-04-16 22:20:36 +00:00
|
|
|
struct afs_cell, link);
|
|
|
|
list_del_init(&cell->link);
|
|
|
|
}
|
|
|
|
|
2017-11-02 15:27:45 +00:00
|
|
|
write_unlock(&net->cells_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (cell) {
|
|
|
|
_debug("PURGING CELL %s (%d)",
|
|
|
|
cell->name, atomic_read(&cell->usage));
|
|
|
|
|
|
|
|
/* now the cell should be left with no references */
|
2017-11-02 15:27:45 +00:00
|
|
|
afs_cell_destroy(net, cell);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-02 15:27:45 +00:00
|
|
|
up_write(&net->cells_sem);
|
2005-04-16 22:20:36 +00:00
|
|
|
_leave("");
|
2007-04-26 22:49:28 +00:00
|
|
|
}
|