NFS: Fix up NFS I/O subrequest creation
We require all NFS I/O subrequests to duplicate the lock context as well as the open context. Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
parent
6fbda89b25
commit
c917cfaf9b
@ -295,6 +295,42 @@ nfs_page_group_destroy(struct kref *kref)
|
|||||||
nfs_release_request(head);
|
nfs_release_request(head);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct nfs_page *
|
||||||
|
__nfs_create_request(struct nfs_lock_context *l_ctx, struct page *page,
|
||||||
|
struct nfs_page *last, unsigned int pgbase,
|
||||||
|
unsigned int offset, unsigned int count)
|
||||||
|
{
|
||||||
|
struct nfs_page *req;
|
||||||
|
struct nfs_open_context *ctx = l_ctx->open_context;
|
||||||
|
|
||||||
|
if (test_bit(NFS_CONTEXT_BAD, &ctx->flags))
|
||||||
|
return ERR_PTR(-EBADF);
|
||||||
|
/* try to allocate the request struct */
|
||||||
|
req = nfs_page_alloc();
|
||||||
|
if (req == NULL)
|
||||||
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
|
req->wb_lock_context = l_ctx;
|
||||||
|
refcount_inc(&l_ctx->count);
|
||||||
|
atomic_inc(&l_ctx->io_count);
|
||||||
|
|
||||||
|
/* Initialize the request struct. Initially, we assume a
|
||||||
|
* long write-back delay. This will be adjusted in
|
||||||
|
* update_nfs_request below if the region is not locked. */
|
||||||
|
req->wb_page = page;
|
||||||
|
if (page) {
|
||||||
|
req->wb_index = page_index(page);
|
||||||
|
get_page(page);
|
||||||
|
}
|
||||||
|
req->wb_offset = offset;
|
||||||
|
req->wb_pgbase = pgbase;
|
||||||
|
req->wb_bytes = count;
|
||||||
|
req->wb_context = get_nfs_open_context(ctx);
|
||||||
|
kref_init(&req->wb_kref);
|
||||||
|
nfs_page_group_init(req, last);
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nfs_create_request - Create an NFS read/write request.
|
* nfs_create_request - Create an NFS read/write request.
|
||||||
* @ctx: open context to use
|
* @ctx: open context to use
|
||||||
@ -312,40 +348,30 @@ nfs_create_request(struct nfs_open_context *ctx, struct page *page,
|
|||||||
struct nfs_page *last, unsigned int offset,
|
struct nfs_page *last, unsigned int offset,
|
||||||
unsigned int count)
|
unsigned int count)
|
||||||
{
|
{
|
||||||
struct nfs_page *req;
|
struct nfs_lock_context *l_ctx = nfs_get_lock_context(ctx);
|
||||||
struct nfs_lock_context *l_ctx;
|
struct nfs_page *ret;
|
||||||
|
|
||||||
if (test_bit(NFS_CONTEXT_BAD, &ctx->flags))
|
if (IS_ERR(l_ctx))
|
||||||
return ERR_PTR(-EBADF);
|
|
||||||
/* try to allocate the request struct */
|
|
||||||
req = nfs_page_alloc();
|
|
||||||
if (req == NULL)
|
|
||||||
return ERR_PTR(-ENOMEM);
|
|
||||||
|
|
||||||
/* get lock context early so we can deal with alloc failures */
|
|
||||||
l_ctx = nfs_get_lock_context(ctx);
|
|
||||||
if (IS_ERR(l_ctx)) {
|
|
||||||
nfs_page_free(req);
|
|
||||||
return ERR_CAST(l_ctx);
|
return ERR_CAST(l_ctx);
|
||||||
}
|
ret = __nfs_create_request(l_ctx, page, last, offset, offset, count);
|
||||||
req->wb_lock_context = l_ctx;
|
nfs_put_lock_context(l_ctx);
|
||||||
atomic_inc(&l_ctx->io_count);
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialize the request struct. Initially, we assume a
|
static struct nfs_page *
|
||||||
* long write-back delay. This will be adjusted in
|
nfs_create_subreq(struct nfs_page *req, struct nfs_page *last,
|
||||||
* update_nfs_request below if the region is not locked. */
|
unsigned int pgbase, unsigned int offset,
|
||||||
req->wb_page = page;
|
unsigned int count)
|
||||||
if (page) {
|
{
|
||||||
req->wb_index = page_index(page);
|
struct nfs_page *ret;
|
||||||
get_page(page);
|
|
||||||
|
ret = __nfs_create_request(req->wb_lock_context, req->wb_page, last,
|
||||||
|
pgbase, offset, count);
|
||||||
|
if (!IS_ERR(ret)) {
|
||||||
|
nfs_lock_request(ret);
|
||||||
|
ret->wb_index = req->wb_index;
|
||||||
}
|
}
|
||||||
req->wb_offset = offset;
|
return ret;
|
||||||
req->wb_pgbase = offset;
|
|
||||||
req->wb_bytes = count;
|
|
||||||
req->wb_context = get_nfs_open_context(ctx);
|
|
||||||
kref_init(&req->wb_kref);
|
|
||||||
nfs_page_group_init(req, last);
|
|
||||||
return req;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1049,14 +1075,10 @@ static int __nfs_pageio_add_request(struct nfs_pageio_descriptor *desc,
|
|||||||
pgbase += subreq->wb_bytes;
|
pgbase += subreq->wb_bytes;
|
||||||
|
|
||||||
if (bytes_left) {
|
if (bytes_left) {
|
||||||
subreq = nfs_create_request(req->wb_context,
|
subreq = nfs_create_subreq(req, subreq, pgbase,
|
||||||
req->wb_page,
|
offset, bytes_left);
|
||||||
subreq, pgbase, bytes_left);
|
|
||||||
if (IS_ERR(subreq))
|
if (IS_ERR(subreq))
|
||||||
goto err_ptr;
|
goto err_ptr;
|
||||||
nfs_lock_request(subreq);
|
|
||||||
subreq->wb_offset = offset;
|
|
||||||
subreq->wb_index = req->wb_index;
|
|
||||||
}
|
}
|
||||||
} while (bytes_left > 0);
|
} while (bytes_left > 0);
|
||||||
|
|
||||||
@ -1158,19 +1180,14 @@ int nfs_pageio_add_request(struct nfs_pageio_descriptor *desc,
|
|||||||
lastreq = lastreq->wb_this_page)
|
lastreq = lastreq->wb_this_page)
|
||||||
;
|
;
|
||||||
|
|
||||||
dupreq = nfs_create_request(req->wb_context,
|
dupreq = nfs_create_subreq(req, lastreq,
|
||||||
req->wb_page, lastreq, pgbase, bytes);
|
pgbase, offset, bytes);
|
||||||
|
|
||||||
|
nfs_page_group_unlock(req);
|
||||||
if (IS_ERR(dupreq)) {
|
if (IS_ERR(dupreq)) {
|
||||||
nfs_page_group_unlock(req);
|
|
||||||
desc->pg_error = PTR_ERR(dupreq);
|
desc->pg_error = PTR_ERR(dupreq);
|
||||||
goto out_failed;
|
goto out_failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
nfs_lock_request(dupreq);
|
|
||||||
nfs_page_group_unlock(req);
|
|
||||||
dupreq->wb_offset = offset;
|
|
||||||
dupreq->wb_index = req->wb_index;
|
|
||||||
} else
|
} else
|
||||||
dupreq = req;
|
dupreq = req;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user