Commit 74918f93 authored by Trond Myklebust's avatar Trond Myklebust

Merge branch 'layoutfixes'

* layoutfixes:
  NFSv4.1/pnfs: Remove redundant wakeup in pnfs_send_layoutreturn()
  NFSv4.1/pnfs: Remove redundant check in pnfs_layoutgets_blocked()
  NFSv4.1/pnfs: Remove redundant lo->plh_block_lgets in layoutreturn
  NFSv4.1/pnfs: Don't prevent layoutgets when doing return-on-close
  NFSv4.1/pnfs: Fix serialisation of layout return and layoutget
  NFSv4.1/pnfs: Remove redundant checks in pnfs_layoutgets_blocked()
  pNFS: Tighten up locking around DS commit buckets
parents 37bfcc14 58830550
...@@ -368,7 +368,6 @@ pnfs_prepare_layoutreturn(struct pnfs_layout_hdr *lo) ...@@ -368,7 +368,6 @@ pnfs_prepare_layoutreturn(struct pnfs_layout_hdr *lo)
if (test_and_set_bit(NFS_LAYOUT_RETURN, &lo->plh_flags)) if (test_and_set_bit(NFS_LAYOUT_RETURN, &lo->plh_flags))
return false; return false;
lo->plh_return_iomode = 0; lo->plh_return_iomode = 0;
lo->plh_block_lgets++;
pnfs_get_layout_hdr(lo); pnfs_get_layout_hdr(lo);
clear_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE, &lo->plh_flags); clear_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE, &lo->plh_flags);
return true; return true;
...@@ -817,25 +816,12 @@ pnfs_layout_stateid_blocked(const struct pnfs_layout_hdr *lo, ...@@ -817,25 +816,12 @@ pnfs_layout_stateid_blocked(const struct pnfs_layout_hdr *lo,
return !pnfs_seqid_is_newer(seqid, lo->plh_barrier); return !pnfs_seqid_is_newer(seqid, lo->plh_barrier);
} }
static bool
pnfs_layout_returning(const struct pnfs_layout_hdr *lo,
struct pnfs_layout_range *range)
{
return test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags) &&
(lo->plh_return_iomode == IOMODE_ANY ||
lo->plh_return_iomode == range->iomode);
}
/* lget is set to 1 if called from inside send_layoutget call chain */ /* lget is set to 1 if called from inside send_layoutget call chain */
static bool static bool
pnfs_layoutgets_blocked(const struct pnfs_layout_hdr *lo, pnfs_layoutgets_blocked(const struct pnfs_layout_hdr *lo)
struct pnfs_layout_range *range, int lget)
{ {
return lo->plh_block_lgets || return lo->plh_block_lgets ||
test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) || test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags);
(list_empty(&lo->plh_segs) &&
(atomic_read(&lo->plh_outstanding) > lget)) ||
pnfs_layout_returning(lo, range);
} }
int int
...@@ -847,7 +833,7 @@ pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo, ...@@ -847,7 +833,7 @@ pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo,
dprintk("--> %s\n", __func__); dprintk("--> %s\n", __func__);
spin_lock(&lo->plh_inode->i_lock); spin_lock(&lo->plh_inode->i_lock);
if (pnfs_layoutgets_blocked(lo, range, 1)) { if (pnfs_layoutgets_blocked(lo)) {
status = -EAGAIN; status = -EAGAIN;
} else if (!nfs4_valid_open_stateid(open_state)) { } else if (!nfs4_valid_open_stateid(open_state)) {
status = -EBADF; status = -EBADF;
...@@ -956,9 +942,7 @@ pnfs_send_layoutreturn(struct pnfs_layout_hdr *lo, nfs4_stateid stateid, ...@@ -956,9 +942,7 @@ pnfs_send_layoutreturn(struct pnfs_layout_hdr *lo, nfs4_stateid stateid,
if (unlikely(lrp == NULL)) { if (unlikely(lrp == NULL)) {
status = -ENOMEM; status = -ENOMEM;
spin_lock(&ino->i_lock); spin_lock(&ino->i_lock);
lo->plh_block_lgets--;
pnfs_clear_layoutreturn_waitbit(lo); pnfs_clear_layoutreturn_waitbit(lo);
rpc_wake_up(&NFS_SERVER(ino)->roc_rpcwaitq);
spin_unlock(&ino->i_lock); spin_unlock(&ino->i_lock);
pnfs_put_layout_hdr(lo); pnfs_put_layout_hdr(lo);
goto out; goto out;
...@@ -1107,7 +1091,9 @@ bool pnfs_roc(struct inode *ino) ...@@ -1107,7 +1091,9 @@ bool pnfs_roc(struct inode *ino)
} }
if (!found) if (!found)
goto out_noroc; goto out_noroc;
lo->plh_block_lgets++; if (test_and_set_bit(NFS_LAYOUT_RETURN, &lo->plh_flags))
goto out_noroc;
lo->plh_return_iomode = IOMODE_ANY;
pnfs_get_layout_hdr(lo); /* matched in pnfs_roc_release */ pnfs_get_layout_hdr(lo); /* matched in pnfs_roc_release */
spin_unlock(&ino->i_lock); spin_unlock(&ino->i_lock);
pnfs_free_lseg_list(&tmp_list); pnfs_free_lseg_list(&tmp_list);
...@@ -1135,7 +1121,7 @@ void pnfs_roc_release(struct inode *ino) ...@@ -1135,7 +1121,7 @@ void pnfs_roc_release(struct inode *ino)
spin_lock(&ino->i_lock); spin_lock(&ino->i_lock);
lo = NFS_I(ino)->layout; lo = NFS_I(ino)->layout;
lo->plh_block_lgets--; pnfs_clear_layoutreturn_waitbit(lo);
if (atomic_dec_and_test(&lo->plh_refcount)) { if (atomic_dec_and_test(&lo->plh_refcount)) {
pnfs_detach_layout_hdr(lo); pnfs_detach_layout_hdr(lo);
spin_unlock(&ino->i_lock); spin_unlock(&ino->i_lock);
...@@ -1438,6 +1424,8 @@ static int pnfs_layoutget_retry_bit_wait(struct wait_bit_key *key) ...@@ -1438,6 +1424,8 @@ static int pnfs_layoutget_retry_bit_wait(struct wait_bit_key *key)
static bool pnfs_prepare_to_retry_layoutget(struct pnfs_layout_hdr *lo) static bool pnfs_prepare_to_retry_layoutget(struct pnfs_layout_hdr *lo)
{ {
if (!pnfs_should_retry_layoutget(lo))
return false;
/* /*
* send layoutcommit as it can hold up layoutreturn due to lseg * send layoutcommit as it can hold up layoutreturn due to lseg
* reference * reference
...@@ -1533,8 +1521,7 @@ pnfs_update_layout(struct inode *ino, ...@@ -1533,8 +1521,7 @@ pnfs_update_layout(struct inode *ino,
* Because we free lsegs before sending LAYOUTRETURN, we need to wait * Because we free lsegs before sending LAYOUTRETURN, we need to wait
* for LAYOUTRETURN even if first is true. * for LAYOUTRETURN even if first is true.
*/ */
if (!lseg && pnfs_should_retry_layoutget(lo) && if (test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags)) {
test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags)) {
spin_unlock(&ino->i_lock); spin_unlock(&ino->i_lock);
dprintk("%s wait for layoutreturn\n", __func__); dprintk("%s wait for layoutreturn\n", __func__);
if (pnfs_prepare_to_retry_layoutget(lo)) { if (pnfs_prepare_to_retry_layoutget(lo)) {
...@@ -1547,7 +1534,7 @@ pnfs_update_layout(struct inode *ino, ...@@ -1547,7 +1534,7 @@ pnfs_update_layout(struct inode *ino,
goto out_put_layout_hdr; goto out_put_layout_hdr;
} }
if (pnfs_layoutgets_blocked(lo, &arg, 0)) if (pnfs_layoutgets_blocked(lo))
goto out_unlock; goto out_unlock;
atomic_inc(&lo->plh_outstanding); atomic_inc(&lo->plh_outstanding);
spin_unlock(&ino->i_lock); spin_unlock(&ino->i_lock);
...@@ -1619,12 +1606,7 @@ pnfs_layout_process(struct nfs4_layoutget *lgp) ...@@ -1619,12 +1606,7 @@ pnfs_layout_process(struct nfs4_layoutget *lgp)
lseg->pls_range = res->range; lseg->pls_range = res->range;
spin_lock(&ino->i_lock); spin_lock(&ino->i_lock);
if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) { if (pnfs_layoutgets_blocked(lo)) {
dprintk("%s forget reply due to recall\n", __func__);
goto out_forget_reply;
}
if (pnfs_layoutgets_blocked(lo, &lgp->args.range, 1)) {
dprintk("%s forget reply due to state\n", __func__); dprintk("%s forget reply due to state\n", __func__);
goto out_forget_reply; goto out_forget_reply;
} }
......
...@@ -124,11 +124,12 @@ pnfs_generic_scan_ds_commit_list(struct pnfs_commit_bucket *bucket, ...@@ -124,11 +124,12 @@ pnfs_generic_scan_ds_commit_list(struct pnfs_commit_bucket *bucket,
if (ret) { if (ret) {
cinfo->ds->nwritten -= ret; cinfo->ds->nwritten -= ret;
cinfo->ds->ncommitting += ret; cinfo->ds->ncommitting += ret;
bucket->clseg = bucket->wlseg; if (bucket->clseg == NULL)
if (list_empty(src)) bucket->clseg = pnfs_get_lseg(bucket->wlseg);
if (list_empty(src)) {
pnfs_put_lseg_locked(bucket->wlseg);
bucket->wlseg = NULL; bucket->wlseg = NULL;
else }
pnfs_get_lseg(bucket->clseg);
} }
return ret; return ret;
} }
...@@ -182,19 +183,23 @@ static void pnfs_generic_retry_commit(struct nfs_commit_info *cinfo, int idx) ...@@ -182,19 +183,23 @@ static void pnfs_generic_retry_commit(struct nfs_commit_info *cinfo, int idx)
struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds; struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds;
struct pnfs_commit_bucket *bucket; struct pnfs_commit_bucket *bucket;
struct pnfs_layout_segment *freeme; struct pnfs_layout_segment *freeme;
LIST_HEAD(pages);
int i; int i;
spin_lock(cinfo->lock);
for (i = idx; i < fl_cinfo->nbuckets; i++) { for (i = idx; i < fl_cinfo->nbuckets; i++) {
bucket = &fl_cinfo->buckets[i]; bucket = &fl_cinfo->buckets[i];
if (list_empty(&bucket->committing)) if (list_empty(&bucket->committing))
continue; continue;
nfs_retry_commit(&bucket->committing, bucket->clseg, cinfo, i);
spin_lock(cinfo->lock);
freeme = bucket->clseg; freeme = bucket->clseg;
bucket->clseg = NULL; bucket->clseg = NULL;
list_splice_init(&bucket->committing, &pages);
spin_unlock(cinfo->lock); spin_unlock(cinfo->lock);
nfs_retry_commit(&pages, freeme, cinfo, i);
pnfs_put_lseg(freeme); pnfs_put_lseg(freeme);
spin_lock(cinfo->lock);
} }
spin_unlock(cinfo->lock);
} }
static unsigned int static unsigned int
...@@ -216,10 +221,6 @@ pnfs_generic_alloc_ds_commits(struct nfs_commit_info *cinfo, ...@@ -216,10 +221,6 @@ pnfs_generic_alloc_ds_commits(struct nfs_commit_info *cinfo,
if (!data) if (!data)
break; break;
data->ds_commit_index = i; data->ds_commit_index = i;
spin_lock(cinfo->lock);
data->lseg = bucket->clseg;
bucket->clseg = NULL;
spin_unlock(cinfo->lock);
list_add(&data->pages, list); list_add(&data->pages, list);
nreq++; nreq++;
} }
...@@ -229,6 +230,22 @@ pnfs_generic_alloc_ds_commits(struct nfs_commit_info *cinfo, ...@@ -229,6 +230,22 @@ pnfs_generic_alloc_ds_commits(struct nfs_commit_info *cinfo,
return nreq; return nreq;
} }
static inline
void pnfs_fetch_commit_bucket_list(struct list_head *pages,
struct nfs_commit_data *data,
struct nfs_commit_info *cinfo)
{
struct pnfs_commit_bucket *bucket;
bucket = &cinfo->ds->buckets[data->ds_commit_index];
spin_lock(cinfo->lock);
list_splice_init(pages, &bucket->committing);
data->lseg = bucket->clseg;
bucket->clseg = NULL;
spin_unlock(cinfo->lock);
}
/* This follows nfs_commit_list pretty closely */ /* This follows nfs_commit_list pretty closely */
int int
pnfs_generic_commit_pagelist(struct inode *inode, struct list_head *mds_pages, pnfs_generic_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
...@@ -243,7 +260,7 @@ pnfs_generic_commit_pagelist(struct inode *inode, struct list_head *mds_pages, ...@@ -243,7 +260,7 @@ pnfs_generic_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
if (!list_empty(mds_pages)) { if (!list_empty(mds_pages)) {
data = nfs_commitdata_alloc(); data = nfs_commitdata_alloc();
if (data != NULL) { if (data != NULL) {
data->lseg = NULL; data->ds_commit_index = -1;
list_add(&data->pages, &list); list_add(&data->pages, &list);
nreq++; nreq++;
} else { } else {
...@@ -265,19 +282,16 @@ pnfs_generic_commit_pagelist(struct inode *inode, struct list_head *mds_pages, ...@@ -265,19 +282,16 @@ pnfs_generic_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
list_for_each_entry_safe(data, tmp, &list, pages) { list_for_each_entry_safe(data, tmp, &list, pages) {
list_del_init(&data->pages); list_del_init(&data->pages);
if (!data->lseg) { if (data->ds_commit_index < 0) {
nfs_init_commit(data, mds_pages, NULL, cinfo); nfs_init_commit(data, mds_pages, NULL, cinfo);
nfs_initiate_commit(NFS_CLIENT(inode), data, nfs_initiate_commit(NFS_CLIENT(inode), data,
NFS_PROTO(data->inode), NFS_PROTO(data->inode),
data->mds_ops, how, 0); data->mds_ops, how, 0);
} else { } else {
struct pnfs_commit_bucket *buckets; LIST_HEAD(pages);
buckets = cinfo->ds->buckets; pnfs_fetch_commit_bucket_list(&pages, data, cinfo);
nfs_init_commit(data, nfs_init_commit(data, &pages, data->lseg, cinfo);
&buckets[data->ds_commit_index].committing,
data->lseg,
cinfo);
initiate_commit(data, how); initiate_commit(data, how);
} }
} }
......
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