pnfs: change lo refcounting to atomic_t
This will be required to allow us to grab reference outside of i_lock. While we are at it, make put_layout_hdr take the same argument as all the related functions. Signed-off-by: Fred Isaman <iisaman@netapp.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
This commit is contained in:
committed by
Trond Myklebust
parent
fc1794c5b0
commit
cc6e5340b0
@@ -177,34 +177,38 @@ EXPORT_SYMBOL_GPL(pnfs_unregister_layoutdriver);
|
|||||||
* pNFS client layout cache
|
* pNFS client layout cache
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Need to hold i_lock if caller does not already hold reference */
|
||||||
static void
|
static void
|
||||||
get_layout_hdr_locked(struct pnfs_layout_hdr *lo)
|
get_layout_hdr(struct pnfs_layout_hdr *lo)
|
||||||
{
|
{
|
||||||
assert_spin_locked(&lo->plh_inode->i_lock);
|
atomic_inc(&lo->plh_refcount);
|
||||||
lo->plh_refcount++;
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
destroy_layout_hdr(struct pnfs_layout_hdr *lo)
|
||||||
|
{
|
||||||
|
dprintk("%s: freeing layout cache %p\n", __func__, lo);
|
||||||
|
BUG_ON(!list_empty(&lo->plh_layouts));
|
||||||
|
NFS_I(lo->plh_inode)->layout = NULL;
|
||||||
|
kfree(lo);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
put_layout_hdr_locked(struct pnfs_layout_hdr *lo)
|
put_layout_hdr_locked(struct pnfs_layout_hdr *lo)
|
||||||
{
|
{
|
||||||
assert_spin_locked(&lo->plh_inode->i_lock);
|
if (atomic_dec_and_test(&lo->plh_refcount))
|
||||||
BUG_ON(lo->plh_refcount == 0);
|
destroy_layout_hdr(lo);
|
||||||
|
|
||||||
lo->plh_refcount--;
|
|
||||||
if (!lo->plh_refcount) {
|
|
||||||
dprintk("%s: freeing layout cache %p\n", __func__, lo);
|
|
||||||
BUG_ON(!list_empty(&lo->plh_layouts));
|
|
||||||
NFS_I(lo->plh_inode)->layout = NULL;
|
|
||||||
kfree(lo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
put_layout_hdr(struct inode *inode)
|
put_layout_hdr(struct pnfs_layout_hdr *lo)
|
||||||
{
|
{
|
||||||
spin_lock(&inode->i_lock);
|
struct inode *inode = lo->plh_inode;
|
||||||
put_layout_hdr_locked(NFS_I(inode)->layout);
|
|
||||||
spin_unlock(&inode->i_lock);
|
if (atomic_dec_and_lock(&lo->plh_refcount, &inode->i_lock)) {
|
||||||
|
destroy_layout_hdr(lo);
|
||||||
|
spin_unlock(&inode->i_lock);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -223,7 +227,7 @@ static void free_lseg(struct pnfs_layout_segment *lseg)
|
|||||||
|
|
||||||
NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg);
|
NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg);
|
||||||
/* Matched by get_layout_hdr in pnfs_insert_layout */
|
/* Matched by get_layout_hdr in pnfs_insert_layout */
|
||||||
put_layout_hdr(ino);
|
put_layout_hdr(NFS_I(ino)->layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The use of tmp_list is necessary because pnfs_curr_ld->free_lseg
|
/* The use of tmp_list is necessary because pnfs_curr_ld->free_lseg
|
||||||
@@ -490,7 +494,7 @@ pnfs_insert_layout(struct pnfs_layout_hdr *lo,
|
|||||||
__func__, lseg, lseg->pls_range.iomode,
|
__func__, lseg, lseg->pls_range.iomode,
|
||||||
lseg->pls_range.offset, lseg->pls_range.length);
|
lseg->pls_range.offset, lseg->pls_range.length);
|
||||||
}
|
}
|
||||||
get_layout_hdr_locked(lo);
|
get_layout_hdr(lo);
|
||||||
|
|
||||||
dprintk("%s:Return\n", __func__);
|
dprintk("%s:Return\n", __func__);
|
||||||
}
|
}
|
||||||
@@ -503,7 +507,7 @@ alloc_init_layout_hdr(struct inode *ino)
|
|||||||
lo = kzalloc(sizeof(struct pnfs_layout_hdr), GFP_KERNEL);
|
lo = kzalloc(sizeof(struct pnfs_layout_hdr), GFP_KERNEL);
|
||||||
if (!lo)
|
if (!lo)
|
||||||
return NULL;
|
return NULL;
|
||||||
lo->plh_refcount = 1;
|
atomic_set(&lo->plh_refcount, 1);
|
||||||
INIT_LIST_HEAD(&lo->plh_layouts);
|
INIT_LIST_HEAD(&lo->plh_layouts);
|
||||||
INIT_LIST_HEAD(&lo->plh_segs);
|
INIT_LIST_HEAD(&lo->plh_segs);
|
||||||
lo->plh_inode = ino;
|
lo->plh_inode = ino;
|
||||||
@@ -618,7 +622,7 @@ pnfs_update_layout(struct inode *ino,
|
|||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
atomic_inc(&lo->plh_outstanding);
|
atomic_inc(&lo->plh_outstanding);
|
||||||
|
|
||||||
get_layout_hdr_locked(lo);
|
get_layout_hdr(lo);
|
||||||
if (list_empty(&lo->plh_segs)) {
|
if (list_empty(&lo->plh_segs)) {
|
||||||
/* The lo must be on the clp list if there is any
|
/* The lo must be on the clp list if there is any
|
||||||
* chance of a CB_LAYOUTRECALL(FILE) coming in.
|
* chance of a CB_LAYOUTRECALL(FILE) coming in.
|
||||||
@@ -641,7 +645,7 @@ pnfs_update_layout(struct inode *ino,
|
|||||||
spin_unlock(&ino->i_lock);
|
spin_unlock(&ino->i_lock);
|
||||||
}
|
}
|
||||||
atomic_dec(&lo->plh_outstanding);
|
atomic_dec(&lo->plh_outstanding);
|
||||||
put_layout_hdr(ino);
|
put_layout_hdr(lo);
|
||||||
out:
|
out:
|
||||||
dprintk("%s end, state 0x%lx lseg %p\n", __func__,
|
dprintk("%s end, state 0x%lx lseg %p\n", __func__,
|
||||||
nfsi->layout->plh_flags, lseg);
|
nfsi->layout->plh_flags, lseg);
|
||||||
|
@@ -65,7 +65,7 @@ struct pnfs_layoutdriver_type {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct pnfs_layout_hdr {
|
struct pnfs_layout_hdr {
|
||||||
unsigned long plh_refcount;
|
atomic_t plh_refcount;
|
||||||
struct list_head plh_layouts; /* other client layouts */
|
struct list_head plh_layouts; /* other client layouts */
|
||||||
struct list_head plh_segs; /* layout segments list */
|
struct list_head plh_segs; /* layout segments list */
|
||||||
nfs4_stateid plh_stateid;
|
nfs4_stateid plh_stateid;
|
||||||
@@ -147,7 +147,7 @@ void unset_pnfs_layoutdriver(struct nfs_server *);
|
|||||||
int pnfs_layout_process(struct nfs4_layoutget *lgp);
|
int pnfs_layout_process(struct nfs4_layoutget *lgp);
|
||||||
void pnfs_destroy_layout(struct nfs_inode *);
|
void pnfs_destroy_layout(struct nfs_inode *);
|
||||||
void pnfs_destroy_all_layouts(struct nfs_client *);
|
void pnfs_destroy_all_layouts(struct nfs_client *);
|
||||||
void put_layout_hdr(struct inode *inode);
|
void put_layout_hdr(struct pnfs_layout_hdr *lo);
|
||||||
int pnfs_choose_layoutget_stateid(nfs4_stateid *dst,
|
int pnfs_choose_layoutget_stateid(nfs4_stateid *dst,
|
||||||
struct pnfs_layout_hdr *lo,
|
struct pnfs_layout_hdr *lo,
|
||||||
struct nfs4_state *open_state);
|
struct nfs4_state *open_state);
|
||||||
|
Reference in New Issue
Block a user