From 7aebf4106b4263667696485303af498aa1eea9ef Mon Sep 17 00:00:00 2001 From: Boaz Harrosh Date: Wed, 13 Oct 2010 12:55:43 -0400 Subject: [PATCH 1/4] exofs: Cleaup read path in regard with read_for_write Last BUG fix added a flag to the the page_collect structure to communicate with readpage_strip. This calls for a clean up removing that flag's reincarnations in the read functions parameters. Signed-off-by: Boaz Harrosh --- fs/exofs/inode.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/fs/exofs/inode.c b/fs/exofs/inode.c index 3eadd97324b..24ab327a20c 100644 --- a/fs/exofs/inode.c +++ b/fs/exofs/inode.c @@ -185,7 +185,7 @@ static void update_write_page(struct page *page, int ret) /* Called at the end of reads, to optionally unlock pages and update their * status. */ -static int __readpages_done(struct page_collect *pcol, bool do_unlock) +static int __readpages_done(struct page_collect *pcol) { int i; u64 resid; @@ -221,7 +221,7 @@ static int __readpages_done(struct page_collect *pcol, bool do_unlock) page_stat ? "bad_bytes" : "good_bytes"); ret = update_read_page(page, page_stat); - if (do_unlock) + if (!pcol->read_4_write) unlock_page(page); length += PAGE_SIZE; } @@ -236,7 +236,7 @@ static void readpages_done(struct exofs_io_state *ios, void *p) { struct page_collect *pcol = p; - __readpages_done(pcol, true); + __readpages_done(pcol); atomic_dec(&pcol->sbi->s_curr_pending); kfree(pcol); } @@ -257,7 +257,7 @@ static void _unlock_pcol_pages(struct page_collect *pcol, int ret, int rw) } } -static int read_exec(struct page_collect *pcol, bool is_sync) +static int read_exec(struct page_collect *pcol) { struct exofs_i_info *oi = exofs_i(pcol->inode); struct exofs_io_state *ios = pcol->ios; @@ -267,17 +267,14 @@ static int read_exec(struct page_collect *pcol, bool is_sync) if (!pcol->pages) return 0; - /* see comment in _readpage() about sync reads */ - WARN_ON(is_sync && (pcol->nr_pages != 1)); - ios->pages = pcol->pages; ios->nr_pages = pcol->nr_pages; ios->length = pcol->length; ios->offset = pcol->pg_first << PAGE_CACHE_SHIFT; - if (is_sync) { + if (pcol->read_4_write) { exofs_oi_read(oi, pcol->ios); - return __readpages_done(pcol, false); + return __readpages_done(pcol); } pcol_copy = kmalloc(sizeof(*pcol_copy), GFP_KERNEL); @@ -303,7 +300,7 @@ static int read_exec(struct page_collect *pcol, bool is_sync) return 0; err: - if (!is_sync) + if (!pcol->read_4_write) _unlock_pcol_pages(pcol, ret, READ); pcol_free(pcol); @@ -356,7 +353,7 @@ static int readpage_strip(void *data, struct page *page) EXOFS_DBGMSG("readpage_strip(0x%lx, 0x%lx) empty page," " splitting\n", inode->i_ino, page->index); - return read_exec(pcol, false); + return read_exec(pcol); } try_again: @@ -366,7 +363,7 @@ try_again: } else if (unlikely((pcol->pg_first + pcol->nr_pages) != page->index)) { /* Discontinuity detected, split the request */ - ret = read_exec(pcol, false); + ret = read_exec(pcol); if (unlikely(ret)) goto fail; goto try_again; @@ -391,7 +388,7 @@ try_again: page, len, pcol->nr_pages, pcol->length); /* split the request, and start again with current page */ - ret = read_exec(pcol, false); + ret = read_exec(pcol); if (unlikely(ret)) goto fail; @@ -420,27 +417,24 @@ static int exofs_readpages(struct file *file, struct address_space *mapping, return ret; } - return read_exec(&pcol, false); + return read_exec(&pcol); } -static int _readpage(struct page *page, bool is_sync) +static int _readpage(struct page *page, bool read_4_write) { struct page_collect pcol; int ret; _pcol_init(&pcol, 1, page->mapping->host); - /* readpage_strip might call read_exec(,is_sync==false) at several - * places but not if we have a single page. - */ - pcol.read_4_write = is_sync; + pcol.read_4_write = read_4_write; ret = readpage_strip(&pcol, page); if (ret) { EXOFS_ERR("_readpage => %d\n", ret); return ret; } - return read_exec(&pcol, is_sync); + return read_exec(&pcol); } /* From 115e19c53501edc11f730191f7f047736815ae3d Mon Sep 17 00:00:00 2001 From: Boaz Harrosh Date: Thu, 7 Oct 2010 14:28:18 -0400 Subject: [PATCH 2/4] exofs: Set i_mapping->backing_dev_info anyway Though it has been promised that inode->i_mapping->backing_dev_info is not used and the supporting code is fine. Until the pointer will default to NULL, I'd rather it points to the correct thing regardless. At least for future infrastructure coder it is a clear indication of where are the key points that inodes are initialized. I know because it took me time to find this out. Signed-off-by: Boaz Harrosh --- fs/exofs/inode.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/exofs/inode.c b/fs/exofs/inode.c index 24ab327a20c..0ba9886da2e 100644 --- a/fs/exofs/inode.c +++ b/fs/exofs/inode.c @@ -1030,6 +1030,7 @@ struct inode *exofs_iget(struct super_block *sb, unsigned long ino) memcpy(oi->i_data, fcb.i_data, sizeof(fcb.i_data)); } + inode->i_mapping->backing_dev_info = sb->s_bdi; if (S_ISREG(inode->i_mode)) { inode->i_op = &exofs_file_inode_operations; inode->i_fop = &exofs_file_operations; @@ -1129,6 +1130,7 @@ struct inode *exofs_new_inode(struct inode *dir, int mode) sbi = sb->s_fs_info; + inode->i_mapping->backing_dev_info = sb->s_bdi; sb->s_dirt = 1; inode_init_owner(inode, dir, mode); inode->i_ino = sbi->s_nextid++; From 571f7f46bf367b29f574ca51a9ca1db5035602bb Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Thu, 21 Oct 2010 22:17:17 -0700 Subject: [PATCH 3/4] fs/exofs: typo fix of faild to failed Signed-off-by: Joe Perches Signed-off-by: Boaz Harrosh --- fs/exofs/dir.c | 4 ++-- fs/exofs/inode.c | 14 +++++++------- fs/exofs/ios.c | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/fs/exofs/dir.c b/fs/exofs/dir.c index d91e9d829bc..dcc941d82d6 100644 --- a/fs/exofs/dir.c +++ b/fs/exofs/dir.c @@ -420,7 +420,7 @@ int exofs_set_link(struct inode *dir, struct exofs_dir_entry *de, err = exofs_write_begin(NULL, page->mapping, pos, len, AOP_FLAG_UNINTERRUPTIBLE, &page, NULL); if (err) - EXOFS_ERR("exofs_set_link: exofs_write_begin FAILD => %d\n", + EXOFS_ERR("exofs_set_link: exofs_write_begin FAILED => %d\n", err); de->inode_no = cpu_to_le64(inode->i_ino); @@ -556,7 +556,7 @@ int exofs_delete_entry(struct exofs_dir_entry *dir, struct page *page) err = exofs_write_begin(NULL, page->mapping, pos, to - from, 0, &page, NULL); if (err) - EXOFS_ERR("exofs_delete_entry: exofs_write_begin FAILD => %d\n", + EXOFS_ERR("exofs_delete_entry: exofs_write_begin FAILED => %d\n", err); if (pde) pde->rec_len = cpu_to_le16(to - from); diff --git a/fs/exofs/inode.c b/fs/exofs/inode.c index 0ba9886da2e..f5f8ce03c2f 100644 --- a/fs/exofs/inode.c +++ b/fs/exofs/inode.c @@ -505,7 +505,7 @@ static int write_exec(struct page_collect *pcol) pcol_copy = kmalloc(sizeof(*pcol_copy), GFP_KERNEL); if (!pcol_copy) { - EXOFS_ERR("write_exec: Faild to kmalloc(pcol)\n"); + EXOFS_ERR("write_exec: Failed to kmalloc(pcol)\n"); ret = -ENOMEM; goto err; } @@ -521,7 +521,7 @@ static int write_exec(struct page_collect *pcol) ret = exofs_oi_write(oi, ios); if (unlikely(ret)) { - EXOFS_ERR("write_exec: exofs_oi_write() Faild\n"); + EXOFS_ERR("write_exec: exofs_oi_write() Failed\n"); goto err; } @@ -622,7 +622,7 @@ try_again: /* split the request, next loop will start again */ ret = write_exec(pcol); if (unlikely(ret)) { - EXOFS_DBGMSG("write_exec faild => %d", ret); + EXOFS_DBGMSG("write_exec failed => %d", ret); goto fail; } @@ -713,7 +713,7 @@ int exofs_write_begin(struct file *file, struct address_space *mapping, ret = simple_write_begin(file, mapping, pos, len, flags, pagep, fsdata); if (ret) { - EXOFS_DBGMSG("simple_write_begin faild\n"); + EXOFS_DBGMSG("simple_write_begin failed\n"); goto out; } @@ -726,7 +726,7 @@ int exofs_write_begin(struct file *file, struct address_space *mapping, if (ret) { /*SetPageError was done by _readpage. Is it ok?*/ unlock_page(page); - EXOFS_DBGMSG("__readpage_filler faild\n"); + EXOFS_DBGMSG("__readpage_filler failed\n"); } } out: @@ -1090,7 +1090,7 @@ static void create_done(struct exofs_io_state *ios, void *p) atomic_dec(&sbi->s_curr_pending); if (unlikely(ret)) { - EXOFS_ERR("object=0x%llx creation faild in pid=0x%llx", + EXOFS_ERR("object=0x%llx creation failed in pid=0x%llx", _LLU(exofs_oi_objno(oi)), _LLU(sbi->layout.s_pid)); /*TODO: When FS is corrupted creation can fail, object already * exist. Get rid of this asynchronous creation, if exist @@ -1211,7 +1211,7 @@ static int exofs_update_inode(struct inode *inode, int do_sync) args = kzalloc(sizeof(*args), GFP_KERNEL); if (!args) { - EXOFS_DBGMSG("Faild kzalloc of args\n"); + EXOFS_DBGMSG("Failed kzalloc of args\n"); return -ENOMEM; } diff --git a/fs/exofs/ios.c b/fs/exofs/ios.c index 6550bf70e41..f74a2ec027a 100644 --- a/fs/exofs/ios.c +++ b/fs/exofs/ios.c @@ -55,7 +55,7 @@ int exofs_read_kern(struct osd_dev *od, u8 *cred, struct osd_obj_id *obj, ret = osd_finalize_request(or, 0, cred, NULL); if (unlikely(ret)) { - EXOFS_DBGMSG("Faild to osd_finalize_request() => %d\n", ret); + EXOFS_DBGMSG("Failed to osd_finalize_request() => %d\n", ret); goto out; } @@ -79,7 +79,7 @@ int exofs_get_io_state(struct exofs_layout *layout, */ ios = kzalloc(exofs_io_state_size(layout->s_numdevs), GFP_KERNEL); if (unlikely(!ios)) { - EXOFS_DBGMSG("Faild kzalloc bytes=%d\n", + EXOFS_DBGMSG("Failed kzalloc bytes=%d\n", exofs_io_state_size(layout->s_numdevs)); *pios = NULL; return -ENOMEM; @@ -172,7 +172,7 @@ static int exofs_io_execute(struct exofs_io_state *ios) ret = osd_finalize_request(or, 0, ios->cred, NULL); if (unlikely(ret)) { - EXOFS_DBGMSG("Faild to osd_finalize_request() => %d\n", + EXOFS_DBGMSG("Failed to osd_finalize_request() => %d\n", ret); return ret; } @@ -361,7 +361,7 @@ static int _add_stripe_unit(struct exofs_io_state *ios, unsigned *cur_pg, per_dev->bio = bio_kmalloc(GFP_KERNEL, bio_size); if (unlikely(!per_dev->bio)) { - EXOFS_DBGMSG("Faild to allocate BIO size=%u\n", + EXOFS_DBGMSG("Failed to allocate BIO size=%u\n", bio_size); return -ENOMEM; } @@ -564,7 +564,7 @@ static int _sbi_write_mirror(struct exofs_io_state *ios, int cur_comp) master_dev->bio->bi_max_vecs); if (unlikely(!bio)) { EXOFS_DBGMSG( - "Faild to allocate BIO size=%u\n", + "Failed to allocate BIO size=%u\n", master_dev->bio->bi_max_vecs); ret = -ENOMEM; goto out; From fe2fd9ed5bf184f797412be8b86f4589d1b77bb8 Mon Sep 17 00:00:00 2001 From: Boaz Harrosh Date: Sat, 16 Oct 2010 19:14:01 +1100 Subject: [PATCH 4/4] exofs: Remove inode->i_count manipulation in exofs_new_inode exofs_new_inode() was incrementing the inode->i_count and decrementing it in create_done(), in a bad attempt to make sure the inode will still be there when the asynchronous create_done() finally arrives. This was very stupid because iput() was not called, and if it was actually needed, it would leak the inode. However all this is not needed, because at exofs_evict_inode() we already wait for create_done() by waiting for the object_created event. Therefore remove the superfluous ref counting and just Thicken the comment at exofs_evict_inode() a bit. While at it change places that open coded wait_obj_created() to call the already available wrapper. CC: Dave Chinner CC: Christoph Hellwig CC: Nick Piggin Signed-off-by: Boaz Harrosh --- fs/exofs/inode.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/fs/exofs/inode.c b/fs/exofs/inode.c index f5f8ce03c2f..42685424817 100644 --- a/fs/exofs/inode.c +++ b/fs/exofs/inode.c @@ -1067,8 +1067,10 @@ bad_inode: int __exofs_wait_obj_created(struct exofs_i_info *oi) { if (!obj_created(oi)) { + EXOFS_DBGMSG("!obj_created\n"); BUG_ON(!obj_2bcreated(oi)); wait_event(oi->i_wq, obj_created(oi)); + EXOFS_DBGMSG("wait_event done\n"); } return unlikely(is_bad_inode(&oi->vfs_inode)) ? -EIO : 0; } @@ -1102,7 +1104,6 @@ static void create_done(struct exofs_io_state *ios, void *p) set_obj_created(oi); - atomic_dec(&inode->i_count); wake_up(&oi->i_wq); } @@ -1153,17 +1154,11 @@ struct inode *exofs_new_inode(struct inode *dir, int mode) ios->obj.id = exofs_oi_objno(oi); exofs_make_credential(oi->i_cred, &ios->obj); - /* increment the refcount so that the inode will still be around when we - * reach the callback - */ - atomic_inc(&inode->i_count); - ios->done = create_done; ios->private = inode; ios->cred = oi->i_cred; ret = exofs_sbi_create(ios); if (ret) { - atomic_dec(&inode->i_count); exofs_put_io_state(ios); return ERR_PTR(ret); } @@ -1253,12 +1248,7 @@ static int exofs_update_inode(struct inode *inode, int do_sync) ios->out_attr_len = 1; ios->out_attr = &attr; - if (!obj_created(oi)) { - EXOFS_DBGMSG("!obj_created\n"); - BUG_ON(!obj_2bcreated(oi)); - wait_event(oi->i_wq, obj_created(oi)); - EXOFS_DBGMSG("wait_event done\n"); - } + wait_obj_created(oi); if (!do_sync) { args->sbi = sbi; @@ -1321,12 +1311,12 @@ void exofs_evict_inode(struct inode *inode) inode->i_size = 0; end_writeback(inode); - /* if we are deleting an obj that hasn't been created yet, wait */ - if (!obj_created(oi)) { - BUG_ON(!obj_2bcreated(oi)); - wait_event(oi->i_wq, obj_created(oi)); - /* ignore the error attempt a remove anyway */ - } + /* if we are deleting an obj that hasn't been created yet, wait. + * This also makes sure that create_done cannot be called with an + * already evicted inode. + */ + wait_obj_created(oi); + /* ignore the error, attempt a remove anyway */ /* Now Remove the OSD objects */ ret = exofs_get_io_state(&sbi->layout, &ios);