Commit 49566f6f authored by David Howells's avatar David Howells

afs: Note the cell in the superblock info also

Keep a reference to the cell in the superblock info structure in addition
to the volume and net pointers.  This will make it easier to clean up in a
future patch in which afs_put_volume() will need the cell pointer.

Whilst we're at it, make the cell and volume getting functions return a
pointer to the object got to make the call sites look neater.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
parent 59fa1c4a
...@@ -178,6 +178,7 @@ struct afs_writeback { ...@@ -178,6 +178,7 @@ struct afs_writeback {
*/ */
struct afs_super_info { struct afs_super_info {
struct afs_net *net; /* Network namespace */ struct afs_net *net; /* Network namespace */
struct afs_cell *cell; /* The cell in which the volume resides */
struct afs_volume *volume; /* volume record */ struct afs_volume *volume; /* volume record */
char rwparent; /* T if parent is R/W AFS volume */ char rwparent; /* T if parent is R/W AFS volume */
}; };
...@@ -502,7 +503,12 @@ extern void afs_flush_callback_breaks(struct afs_server *); ...@@ -502,7 +503,12 @@ extern void afs_flush_callback_breaks(struct afs_server *);
/* /*
* cell.c * cell.c
*/ */
#define afs_get_cell(C) do { atomic_inc(&(C)->usage); } while(0) static inline struct afs_cell *afs_get_cell(struct afs_cell *cell)
{
if (cell)
atomic_inc(&cell->usage);
return cell;
}
extern int afs_cell_init(struct afs_net *, char *); extern int afs_cell_init(struct afs_net *, char *);
extern struct afs_cell *afs_cell_create(struct afs_net *, const char *, unsigned, char *, bool); extern struct afs_cell *afs_cell_create(struct afs_net *, const char *, unsigned, char *, bool);
extern struct afs_cell *afs_cell_lookup(struct afs_net *, const char *, unsigned, bool); extern struct afs_cell *afs_cell_lookup(struct afs_net *, const char *, unsigned, bool);
...@@ -789,7 +795,12 @@ extern int afs_vnode_release_lock(struct afs_vnode *, struct key *); ...@@ -789,7 +795,12 @@ extern int afs_vnode_release_lock(struct afs_vnode *, struct key *);
/* /*
* volume.c * volume.c
*/ */
#define afs_get_volume(V) do { atomic_inc(&(V)->usage); } while(0) static inline struct afs_volume *afs_get_volume(struct afs_volume *volume)
{
if (volume)
atomic_inc(&volume->usage);
return volume;
}
extern void afs_put_volume(struct afs_net *, struct afs_volume *); extern void afs_put_volume(struct afs_net *, struct afs_volume *);
extern struct afs_volume *afs_volume_lookup(struct afs_mount_params *); extern struct afs_volume *afs_volume_lookup(struct afs_mount_params *);
......
...@@ -394,6 +394,28 @@ static int afs_fill_super(struct super_block *sb, ...@@ -394,6 +394,28 @@ static int afs_fill_super(struct super_block *sb,
return ret; return ret;
} }
static struct afs_super_info *afs_alloc_sbi(struct afs_mount_params *params)
{
struct afs_super_info *as;
as = kzalloc(sizeof(struct afs_super_info), GFP_KERNEL);
if (as) {
as->net = afs_get_net(params->net);
as->cell = afs_get_cell(params->cell);
}
return as;
}
static void afs_destroy_sbi(struct afs_super_info *as)
{
if (as) {
afs_put_volume(as->net, as->volume);
afs_put_cell(as->cell);
afs_put_net(as->net);
kfree(as);
}
}
/* /*
* get an AFS superblock * get an AFS superblock
*/ */
...@@ -404,7 +426,6 @@ static struct dentry *afs_mount(struct file_system_type *fs_type, ...@@ -404,7 +426,6 @@ static struct dentry *afs_mount(struct file_system_type *fs_type,
struct super_block *sb; struct super_block *sb;
struct afs_volume *vol; struct afs_volume *vol;
struct key *key; struct key *key;
char *new_opts = kstrdup(options, GFP_KERNEL);
struct afs_super_info *as; struct afs_super_info *as;
int ret; int ret;
...@@ -437,20 +458,18 @@ static struct dentry *afs_mount(struct file_system_type *fs_type, ...@@ -437,20 +458,18 @@ static struct dentry *afs_mount(struct file_system_type *fs_type,
} }
params.key = key; params.key = key;
/* allocate a superblock info record */
ret = -ENOMEM;
as = afs_alloc_sbi(&params);
if (!as)
goto error;
/* parse the device name */ /* parse the device name */
vol = afs_volume_lookup(&params); vol = afs_volume_lookup(&params);
if (IS_ERR(vol)) { if (IS_ERR(vol)) {
ret = PTR_ERR(vol); ret = PTR_ERR(vol);
goto error; goto error;
} }
/* allocate a superblock info record */
ret = -ENOMEM;
as = kzalloc(sizeof(struct afs_super_info), GFP_KERNEL);
if (!as)
goto error_vol;
as->net = afs_get_net(params.net);
as->volume = vol; as->volume = vol;
/* allocate a deviceless superblock */ /* allocate a deviceless superblock */
...@@ -466,31 +485,27 @@ static struct dentry *afs_mount(struct file_system_type *fs_type, ...@@ -466,31 +485,27 @@ static struct dentry *afs_mount(struct file_system_type *fs_type,
ret = afs_fill_super(sb, &params); ret = afs_fill_super(sb, &params);
if (ret < 0) if (ret < 0)
goto error_sb; goto error_sb;
as = NULL;
sb->s_flags |= MS_ACTIVE; sb->s_flags |= MS_ACTIVE;
} else { } else {
_debug("reuse"); _debug("reuse");
ASSERTCMP(sb->s_flags, &, MS_ACTIVE); ASSERTCMP(sb->s_flags, &, MS_ACTIVE);
afs_put_volume(params.net, vol); afs_destroy_sbi(as);
kfree(as); as = NULL;
} }
afs_put_cell(params.cell); afs_put_cell(params.cell);
kfree(new_opts); key_put(params.key);
_leave(" = 0 [%p]", sb); _leave(" = 0 [%p]", sb);
return dget(sb->s_root); return dget(sb->s_root);
error_sb: error_sb:
deactivate_locked_super(sb); deactivate_locked_super(sb);
goto error;
error_as: error_as:
afs_put_net(as->net); afs_destroy_sbi(as);
kfree(as);
error_vol:
afs_put_volume(params.net, vol);
error: error:
afs_put_cell(params.cell); afs_put_cell(params.cell);
key_put(params.key); key_put(params.key);
kfree(new_opts);
_leave(" = %d", ret); _leave(" = %d", ret);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
...@@ -498,11 +513,9 @@ static struct dentry *afs_mount(struct file_system_type *fs_type, ...@@ -498,11 +513,9 @@ static struct dentry *afs_mount(struct file_system_type *fs_type,
static void afs_kill_super(struct super_block *sb) static void afs_kill_super(struct super_block *sb)
{ {
struct afs_super_info *as = sb->s_fs_info; struct afs_super_info *as = sb->s_fs_info;
struct afs_net *net = as->net;
kill_anon_super(sb); kill_anon_super(sb);
afs_put_volume(net, as->volume); afs_destroy_sbi(as);
kfree(as);
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment