pnfsblock: Bug fixes for 3.1
Subsystems (2)
cover pnfsblock: Bug fixes for 3.1
These bug fixes for the pnfs block layout driver should apply to linux 3.1.
Jim Rees (2):
pnfsblock: fix size of upcall message
pnfsblock: fix return code confusion
Peng Tao (3):
pnfsblock: fix NULL pointer dereference
pnfsblock: fix writeback deadlock
pnfsblock: add missing rpc_put_mount and path_put
fs/nfs/blocklayout/blocklayout.c | 39 ++++++++++++++++++++++++---------- fs/nfs/blocklayout/blocklayout.h | 2 +- fs/nfs/blocklayout/blocklayoutdev.c | 13 +++++++---- 3 files changed, 36 insertions(+), 18 deletions(-)
Signature · 1 line
1.7.6
PATCH 1/5 pnfsblock: fix size of upcall message
Make the status field explicitly 32 bits. "...it's unlikely that the kernel and userspace would differ on the size of an int here, but it might be a good idea to go ahead and make that explicitly 32 bits in case we end up dealing with more exotic arches at some point in the future."
--- fs/nfs/blocklayout/blocklayout.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/nfs/blocklayout/blocklayout.h +1 -1
@@ -150,7 +150,7 @@ BLK_LSEG2EXT(struct pnfs_layout_segment *lseg) }struct bl_dev_msg { -int status; +int32_t status;uint32_t major, minor; };
Signature · 1 line
1.7.6
PATCH 2/5 pnfsblock: fix return code confusion
In reply to Jim ReesAlways return PTR_ERR, not NULL, from nfs4_blk_get_deviceinfo and nfs4_blk_decode_device.
Check for IS_ERR, not NULL, in bl_set_layoutdriver when calling nfs4_blk_get_deviceinfo.
--- fs/nfs/blocklayout/blocklayout.c | 20 ++++++++++++-------- fs/nfs/blocklayout/blocklayoutdev.c | 13 ++++++++----- 2 files changed, 20 insertions(+), 13 deletions(-)
fs/nfs/blocklayout/blocklayout.c +12 -8
@@ -805,7 +805,7 @@ nfs4_blk_get_deviceinfo(struct nfs_server *server, const struct nfs_fh *fh, struct nfs4_deviceid *d_id) {struct pnfs_device *dev; -struct pnfs_block_dev *rv =NULL ; +struct pnfs_block_dev *rv;u32 max_resp_sz;int max_pages;struct page **pages =NULL ;
@@ -823,18 +823,20 @@ nfs4_blk_get_deviceinfo(struct nfs_server *server, const struct nfs_fh *fh, dev =kmalloc (sizeof (*dev),GFP_NOFS );if (!dev) {dprintk ("%s kmalloc failed\n" , __func__); -return NULL ; +return ERR_PTR (-ENOMEM ); } pages =kzalloc (max_pages *sizeof (struct page *),GFP_NOFS );if (pages ==NULL ) {kfree (dev); -return NULL ; +return ERR_PTR (-ENOMEM ); }for (i =0 ; i < max_pages; i++) { pages[i] =alloc_page (GFP_NOFS ); -if (!pages[i]) +if (!pages[i]) { + rv =ERR_PTR (-ENOMEM ); goto out_free; + } }memcpy (&dev->dev_id, d_id,sizeof (*d_id));
@@ -847,8 +849,10 @@ nfs4_blk_get_deviceinfo(struct nfs_server *server, const struct nfs_fh *fh,dprintk ("%s: dev_id: %s\n" , __func__, dev->dev_id.data); rc =nfs4_proc_getdeviceinfo (server, dev);dprintk ("%s getdevice info returns %d\n" , __func__, rc); -if (rc) +if (rc) { + rv =ERR_PTR (rc); goto out_free; + } rv =nfs4_blk_decode_device (server, dev); out_free:
@@ -866,7 +870,7 @@ bl_set_layoutdriver(struct nfs_server *server, const struct nfs_fh *fh)struct pnfs_devicelist *dlist =NULL ;struct pnfs_block_dev *bdev;LIST_HEAD (block_disklist); -int status =0 , i; +int status, i;dprintk ("%s enter\n" , __func__);
@@ -898,8 +902,8 @@ bl_set_layoutdriver(struct nfs_server *server, const struct nfs_fh *fh)for (i =0 ; i < dlist->num_devs; i++) { bdev =nfs4_blk_get_deviceinfo (server, fh, &dlist->dev_id[i]); -if (!bdev) { - status = -ENODEV ; +if (IS_ERR (bdev)) { + status =PTR_ERR (bdev); goto out_error; }spin_lock (&b_mt_id->bm_lock);
fs/nfs/blocklayout/blocklayoutdev.c +8 -5
@@ -131,7 +131,7 @@ struct pnfs_block_dev * nfs4_blk_decode_device(struct nfs_server *server, struct pnfs_device *dev) { - struct pnfs_block_dev *rv = NULL; + struct pnfs_block_dev *rv;struct block_device *bd =NULL ;struct rpc_pipe_msg msg; struct bl_msg_hdr bl_msg = {
@@ -141,7 +141,7 @@ nfs4_blk_decode_device(struct nfs_server *server,uint8_t *dataptr;DECLARE_WAITQUEUE (wq, current);struct bl_dev_msg *reply = &bl_mount_reply; -int offset, len, i; +int offset, len, i, rc;dprintk ("%s CREATING PIPEFS MESSAGE\n" , __func__); dprintk("%s: deviceid: %s, mincount: %d\n", __func__, dev->dev_id.data,
@@ -168,8 +168,10 @@ nfs4_blk_decode_device(struct nfs_server *server,dprintk ("%s CALLING USERSPACE DAEMON\n" , __func__);add_wait_queue (&bl_wq, &wq); -if (rpc_queue_upcall (bl_device_pipe->d_inode, &msg) <0 ) { + rc =rpc_queue_upcall (bl_device_pipe->d_inode, &msg); +if (rc <0 ) {remove_wait_queue (&bl_wq, &wq); + rv =ERR_PTR (rc); goto out; }
@@ -187,8 +189,9 @@ nfs4_blk_decode_device(struct nfs_server *server, bd =nfs4_blkdev_get (MKDEV (reply->major, reply->minor));if (IS_ERR (bd)) { -dprintk ("%s failed to open device : %ld\n" , - __func__,PTR_ERR (bd)); + rc =PTR_ERR (bd); +dprintk ("%s failed to open device : %d\n" , __func__, rc); + rv =ERR_PTR (rc); goto out; }
Signature · 1 line
1.7.6
PATCH 3/5 pnfsblock: fix NULL pointer dereference
In reply to Jim ReesFrom: Peng Tao <[email protected]>
bl_add_page_to_bio returns error pointer. bio should be reset to NULL in failure cases as the out path always calls bl_submit_bio.
--- fs/nfs/blocklayout/blocklayout.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
fs/nfs/blocklayout/blocklayout.c +3 -0
@@ -303,6 +303,7 @@ bl_read_pagelist(struct nfs_read_data *rdata) bl_end_io_read, par);if (IS_ERR (bio)) { rdata->pnfs_error =PTR_ERR (bio); + bio =NULL ; goto out; } }
@@ -592,6 +593,7 @@ fill_invalid_ext: bl_end_io_write_zero, par);if (IS_ERR (bio)) { wdata->pnfs_error =PTR_ERR (bio); + bio =NULL ; goto out; }/* FIXME: This should be done in bi_end_io */
@@ -640,6 +642,7 @@ next_page: bl_end_io_write, par);if (IS_ERR (bio)) { wdata->pnfs_error =PTR_ERR (bio); + bio =NULL ; goto out; } isect +=PAGE_CACHE_SECTORS ;
Signature · 1 line
1.7.6
PATCH 4/5 pnfsblock: fix writeback deadlock
In reply to Jim ReesFrom: Peng Tao <[email protected]>
We should check if the sector is already initialized before trying to grab the page from page cache. Otherwise when two pages of the same block are written back by two threads each calling from writepage_locked, it can cause deadlock like bellow.
[ 1080.972099] INFO: task kswapd0:25 blocked for more than 120 seconds. [ 1080.972377] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 1080.972812] kswapd0 D ffff88000c4926c0 0 25 2 0x00000000 [ 1080.972816] ffff88000df276b0 0000000000000046 ffff88000df27640 ffffffff81013ba7 [ 1080.972821] ffff88000c492310 ffff88000df27fd8 ffff88000df27fd8 00000000001d3440 [ 1080.972824] ffff88000c378000 ffff88000c492310 ffff8800175d3d40 ffff880017fc75a8 [ 1080.972828] Call Trace: [ 1080.972860] [<ffffffff81013ba7>] ? read_tsc+0x9/0x19 [ 1080.972877] [<ffffffff810e0b23>] ? lock_page+0x2b/0x2b [ 1080.972899] [<ffffffff81475a1d>] io_schedule+0x63/0x7e [ 1080.972902] [<ffffffff810e0b31>] sleep_on_page+0xe/0x12 [ 1080.972905] [<ffffffff81475fe8>] __wait_on_bit_lock+0x46/0x8f [ 1080.972916] [<ffffffff810822d7>] ? lock_release_holdtime.part.7+0x6b/0x72 [ 1080.972919] [<ffffffff810e0af6>] __lock_page+0x66/0x68 [ 1080.972928] [<ffffffff81072705>] ? autoremove_wake_function+0x3d/0x3d [ 1080.972932] [<ffffffff810e0b1f>] lock_page+0x27/0x2b [ 1080.972934] [<ffffffff810e0bcf>] find_lock_page+0x34/0x57 [ 1080.972937] [<ffffffff810e1738>] find_or_create_page+0x34/0x8a [ 1080.972947] [<ffffffffa034245b>] bl_write_pagelist+0x205/0x6da [blocklayoutdriver] [ 1080.972951] [<ffffffffa034145d>] ? bl_free_lseg+0x38/0x38 [blocklayoutdriver] [ 1080.972995] [<ffffffffa02e27b9>] ? nfs_write_rpcsetup+0x118/0x123 [nfs] [ 1080.973033] [<ffffffffa030246b>] pnfs_generic_pg_writepages+0x10b/0x1f4 [nfs] [ 1080.973089] [<ffffffffa02deaae>] nfs_pageio_doio+0x1a/0x43 [nfs] [ 1080.973098] [<ffffffffa02df035>] nfs_pageio_complete+0x16/0x2d [nfs] [ 1080.973108] [<ffffffffa02e2d8f>] nfs_writepage_locked+0xa0/0xbf [nfs] [ 1080.973119] [<ffffffffa02e36a1>] nfs_writepage+0x16/0x2b [nfs] [ 1080.973122] [<ffffffff810e8762>] ? clear_page_dirty_for_io+0x87/0x9a [ 1080.973133] [<ffffffff810efc5b>] shrink_page_list+0x39b/0x6c8 [ 1080.973139] [<ffffffff810f03bb>] shrink_inactive_list+0x22c/0x39e [ 1080.973144] [<ffffffff810822d7>] ? lock_release_holdtime.part.7+0x6b/0x72 [ 1080.973148] [<ffffffff810f0c33>] shrink_zone+0x445/0x588 [ 1080.973152] [<ffffffff810f1a11>] balance_pgdat+0x2c2/0x56b [ 1080.973170] [<ffffffff81254208>] ? __bitmap_weight+0x34/0x80 [ 1080.973175] [<ffffffff810f1f78>] kswapd+0x2be/0x2fa [ 1080.973179] [<ffffffff810726c8>] ? __init_waitqueue_head+0x4b/0x4b [ 1080.973183] [<ffffffff810f1cba>] ? balance_pgdat+0x56b/0x56b [ 1080.973187] [<ffffffff81071f69>] kthread+0xa8/0xb0 [ 1080.973200] [<ffffffff814806b4>] kernel_thread_helper+0x4/0x10 [ 1080.973205] [<ffffffff81071ec1>] ? __init_kthread_worker+0x5a/0x5a [ 1080.973210] [<ffffffff814806b0>] ? gs_change+0x13/0x13 [ 1080.973213] no locks held by kswapd0/25.
--- fs/nfs/blocklayout/blocklayout.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
fs/nfs/blocklayout/blocklayout.c +6 -2
@@ -544,6 +544,11 @@ bl_write_pagelist(struct nfs_write_data *wdata, int sync) fill_invalid_ext:dprintk ("%s need to zero %d pages\n" , __func__, npg_zero);for (;npg_zero >0 ; npg_zero--) { +if (bl_is_sector_init (be->be_inval, isect)) { +dprintk ("isect %llu already init\n" , + (unsigned long long )isect); + goto next_page; + }/* page ref released in bl_end_io_write_zero */ index = isect >>PAGE_CACHE_SECTOR_SHIFT ; dprintk("%s zero %dth page: index %lu isect %llu\n",
@@ -563,8 +568,7 @@ fill_invalid_ext:* PageUptodate: It was read before * sector_initialized: already written out */ -if (PageDirty (page) ||PageWriteback (page) || -bl_is_sector_init (be->be_inval, isect)) { +if (PageDirty (page) ||PageWriteback (page)) {print_page (page);unlock_page (page);page_cache_release (page);
Signature · 1 line
1.7.6
PATCH 5/5 pnfsblock: add missing rpc_put_mount and path_put
In reply to Jim ReesFrom: Peng Tao <[email protected]>
--- fs/nfs/blocklayout/blocklayout.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
fs/nfs/blocklayout/blocklayout.c +6 -2
@@ -1000,17 +1000,20 @@ static int __init nfs4blocklayout_init(void) mnt, NFS_PIPE_DIRNAME, 0, &path);if (ret) - goto out_remove; + goto out_putrpc; bl_device_pipe =rpc_mkpipe (path.dentry,"blocklayout" ,NULL , &bl_upcall_ops,0 ); +path_put (&path);if (IS_ERR (bl_device_pipe)) { ret =PTR_ERR (bl_device_pipe); - goto out_remove; + goto out_putrpc; } out:return ret; +out_putrpc: +rpc_put_mount (); out_remove:pnfs_unregister_layoutdriver (&blocklayout_type);return ret;
@@ -1023,6 +1026,7 @@ static void __exit nfs4blocklayout_exit(void)pnfs_unregister_layoutdriver (&blocklayout_type);rpc_unlink (bl_device_pipe); +rpc_put_mount (); }MODULE_ALIAS ("nfs-layouttype4-3" );
Signature · 1 line
1.7.6
Re: [PATCH 5/5] pnfsblock: add missing rpc_put_mount and path_put
Quoted 3 lines · Jim Rees
From: Peng Tao <[email protected]>
Reported-by Jeff Layton <[email protected]>
This should really be
as Jeff has provided it in his previous mail.
Thanks,
Tao
Quoted 49 lines
Signed-off-by Peng Tao <[email protected]>Signed-off-by Jim Rees <[email protected]>---
fs/nfs/blocklayout/blocklayout.c | 8 ++++++--1 files changed, 6 insertions(+), 2 deletions(-)fs/nfs/blocklayout/blocklayout.c +3
-2@@ -1000,17 +1000,20 @@ static int __init nfs4blocklayout_init(void) mnt, NFS_PIPE_DIRNAME, 0, &path); if (ret) - goto out_remove; + goto out_putrpc; bl_device_pipe = rpc_mkpipe(path.dentry, "blocklayout", NULL, &bl_upcall_ops, 0); + path_put(&path); if (IS_ERR(bl_device_pipe)) { ret = PTR_ERR(bl_device_pipe); - goto out_remove; + goto out_putrpc; }out:
return ret;+out_putrpc:
+rpc_put_mount();
out_remove:
pnfs_unregister_layoutdriver(&blocklayout_type); return ret;fs/nfs/blocklayout/blocklayout.c +1
-1@@ -1023,6 +1026,7 @@ static void __exit nfs4blocklayout_exit(void) pnfs_unregister_layoutdriver(&blocklayout_type); rpc_unlink(bl_device_pipe); + rpc_put_mount(); } MODULE_ALIAS("nfs-layouttype4-3"); --1.7.6
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Thanks, -Bergwolf