NFS: Convert nfs_get_lock_context to return an ERR_PTR on failure
We want to be able to distinguish between allocation failures, and the case where the lock context is not needed (because there are no locks). Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
This commit is contained in:
parent
a11a2bf4de
commit
b3c54de6f8
3 changed files with 18 additions and 8 deletions
|
@ -450,6 +450,7 @@ static ssize_t nfs_direct_read(struct kiocb *iocb, const struct iovec *iov,
|
||||||
ssize_t result = -ENOMEM;
|
ssize_t result = -ENOMEM;
|
||||||
struct inode *inode = iocb->ki_filp->f_mapping->host;
|
struct inode *inode = iocb->ki_filp->f_mapping->host;
|
||||||
struct nfs_direct_req *dreq;
|
struct nfs_direct_req *dreq;
|
||||||
|
struct nfs_lock_context *l_ctx;
|
||||||
|
|
||||||
dreq = nfs_direct_req_alloc();
|
dreq = nfs_direct_req_alloc();
|
||||||
if (dreq == NULL)
|
if (dreq == NULL)
|
||||||
|
@ -457,9 +458,12 @@ static ssize_t nfs_direct_read(struct kiocb *iocb, const struct iovec *iov,
|
||||||
|
|
||||||
dreq->inode = inode;
|
dreq->inode = inode;
|
||||||
dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp));
|
dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp));
|
||||||
dreq->l_ctx = nfs_get_lock_context(dreq->ctx);
|
l_ctx = nfs_get_lock_context(dreq->ctx);
|
||||||
if (dreq->l_ctx == NULL)
|
if (IS_ERR(l_ctx)) {
|
||||||
|
result = PTR_ERR(l_ctx);
|
||||||
goto out_release;
|
goto out_release;
|
||||||
|
}
|
||||||
|
dreq->l_ctx = l_ctx;
|
||||||
if (!is_sync_kiocb(iocb))
|
if (!is_sync_kiocb(iocb))
|
||||||
dreq->iocb = iocb;
|
dreq->iocb = iocb;
|
||||||
|
|
||||||
|
@ -849,6 +853,7 @@ static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov,
|
||||||
ssize_t result = -ENOMEM;
|
ssize_t result = -ENOMEM;
|
||||||
struct inode *inode = iocb->ki_filp->f_mapping->host;
|
struct inode *inode = iocb->ki_filp->f_mapping->host;
|
||||||
struct nfs_direct_req *dreq;
|
struct nfs_direct_req *dreq;
|
||||||
|
struct nfs_lock_context *l_ctx;
|
||||||
|
|
||||||
dreq = nfs_direct_req_alloc();
|
dreq = nfs_direct_req_alloc();
|
||||||
if (!dreq)
|
if (!dreq)
|
||||||
|
@ -856,9 +861,12 @@ static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov,
|
||||||
|
|
||||||
dreq->inode = inode;
|
dreq->inode = inode;
|
||||||
dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp));
|
dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp));
|
||||||
dreq->l_ctx = nfs_get_lock_context(dreq->ctx);
|
l_ctx = nfs_get_lock_context(dreq->ctx);
|
||||||
if (dreq->l_ctx == NULL)
|
if (IS_ERR(l_ctx)) {
|
||||||
|
result = PTR_ERR(l_ctx);
|
||||||
goto out_release;
|
goto out_release;
|
||||||
|
}
|
||||||
|
dreq->l_ctx = l_ctx;
|
||||||
if (!is_sync_kiocb(iocb))
|
if (!is_sync_kiocb(iocb))
|
||||||
dreq->iocb = iocb;
|
dreq->iocb = iocb;
|
||||||
|
|
||||||
|
|
|
@ -578,7 +578,7 @@ struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx)
|
||||||
spin_unlock(&inode->i_lock);
|
spin_unlock(&inode->i_lock);
|
||||||
new = kmalloc(sizeof(*new), GFP_KERNEL);
|
new = kmalloc(sizeof(*new), GFP_KERNEL);
|
||||||
if (new == NULL)
|
if (new == NULL)
|
||||||
return NULL;
|
return ERR_PTR(-ENOMEM);
|
||||||
nfs_init_lock_context(new);
|
nfs_init_lock_context(new);
|
||||||
spin_lock(&inode->i_lock);
|
spin_lock(&inode->i_lock);
|
||||||
res = __nfs_find_lock_context(ctx);
|
res = __nfs_find_lock_context(ctx);
|
||||||
|
|
|
@ -102,6 +102,7 @@ nfs_create_request(struct nfs_open_context *ctx, struct inode *inode,
|
||||||
unsigned int offset, unsigned int count)
|
unsigned int offset, unsigned int count)
|
||||||
{
|
{
|
||||||
struct nfs_page *req;
|
struct nfs_page *req;
|
||||||
|
struct nfs_lock_context *l_ctx;
|
||||||
|
|
||||||
/* try to allocate the request struct */
|
/* try to allocate the request struct */
|
||||||
req = nfs_page_alloc();
|
req = nfs_page_alloc();
|
||||||
|
@ -109,11 +110,12 @@ nfs_create_request(struct nfs_open_context *ctx, struct inode *inode,
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
/* get lock context early so we can deal with alloc failures */
|
/* get lock context early so we can deal with alloc failures */
|
||||||
req->wb_lock_context = nfs_get_lock_context(ctx);
|
l_ctx = nfs_get_lock_context(ctx);
|
||||||
if (req->wb_lock_context == NULL) {
|
if (IS_ERR(l_ctx)) {
|
||||||
nfs_page_free(req);
|
nfs_page_free(req);
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_CAST(l_ctx);
|
||||||
}
|
}
|
||||||
|
req->wb_lock_context = l_ctx;
|
||||||
|
|
||||||
/* Initialize the request struct. Initially, we assume a
|
/* Initialize the request struct. Initially, we assume a
|
||||||
* long write-back delay. This will be adjusted in
|
* long write-back delay. This will be adjusted in
|
||||||
|
|
Loading…
Add table
Reference in a new issue