aboutsummaryrefslogtreecommitdiffstats
path: root/fs/exofs/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/exofs/inode.c')
-rw-r--r--fs/exofs/inode.c136
1 files changed, 55 insertions, 81 deletions
diff --git a/fs/exofs/inode.c b/fs/exofs/inode.c
index 4bb6ef822e46..eb7368ebd8cd 100644
--- a/fs/exofs/inode.c
+++ b/fs/exofs/inode.c
@@ -32,9 +32,6 @@
32 */ 32 */
33 33
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/writeback.h>
36#include <linux/buffer_head.h>
37#include <scsi/scsi_device.h>
38 35
39#include "exofs.h" 36#include "exofs.h"
40 37
@@ -697,6 +694,13 @@ static int exofs_writepage(struct page *page, struct writeback_control *wbc)
697 return write_exec(&pcol); 694 return write_exec(&pcol);
698} 695}
699 696
697/* i_mutex held using inode->i_size directly */
698static void _write_failed(struct inode *inode, loff_t to)
699{
700 if (to > inode->i_size)
701 truncate_pagecache(inode, to, inode->i_size);
702}
703
700int exofs_write_begin(struct file *file, struct address_space *mapping, 704int exofs_write_begin(struct file *file, struct address_space *mapping,
701 loff_t pos, unsigned len, unsigned flags, 705 loff_t pos, unsigned len, unsigned flags,
702 struct page **pagep, void **fsdata) 706 struct page **pagep, void **fsdata)
@@ -710,7 +714,7 @@ int exofs_write_begin(struct file *file, struct address_space *mapping,
710 fsdata); 714 fsdata);
711 if (ret) { 715 if (ret) {
712 EXOFS_DBGMSG("simple_write_begin faild\n"); 716 EXOFS_DBGMSG("simple_write_begin faild\n");
713 return ret; 717 goto out;
714 } 718 }
715 719
716 page = *pagep; 720 page = *pagep;
@@ -725,6 +729,9 @@ int exofs_write_begin(struct file *file, struct address_space *mapping,
725 EXOFS_DBGMSG("__readpage_filler faild\n"); 729 EXOFS_DBGMSG("__readpage_filler faild\n");
726 } 730 }
727 } 731 }
732out:
733 if (unlikely(ret))
734 _write_failed(mapping->host, pos + len);
728 735
729 return ret; 736 return ret;
730} 737}
@@ -750,6 +757,10 @@ static int exofs_write_end(struct file *file, struct address_space *mapping,
750 int ret; 757 int ret;
751 758
752 ret = simple_write_end(file, mapping,pos, len, copied, page, fsdata); 759 ret = simple_write_end(file, mapping,pos, len, copied, page, fsdata);
760 if (unlikely(ret))
761 _write_failed(inode, pos + len);
762
763 /* TODO: once simple_write_end marks inode dirty remove */
753 if (i_size != inode->i_size) 764 if (i_size != inode->i_size)
754 mark_inode_dirty(inode); 765 mark_inode_dirty(inode);
755 return ret; 766 return ret;
@@ -759,15 +770,13 @@ static int exofs_releasepage(struct page *page, gfp_t gfp)
759{ 770{
760 EXOFS_DBGMSG("page 0x%lx\n", page->index); 771 EXOFS_DBGMSG("page 0x%lx\n", page->index);
761 WARN_ON(1); 772 WARN_ON(1);
762 return try_to_free_buffers(page); 773 return 0;
763} 774}
764 775
765static void exofs_invalidatepage(struct page *page, unsigned long offset) 776static void exofs_invalidatepage(struct page *page, unsigned long offset)
766{ 777{
767 EXOFS_DBGMSG("page_has_buffers=>%d\n", page_has_buffers(page)); 778 EXOFS_DBGMSG("page 0x%lx offset 0x%lx\n", page->index, offset);
768 WARN_ON(1); 779 WARN_ON(1);
769
770 block_invalidatepage(page, offset);
771} 780}
772 781
773const struct address_space_operations exofs_aops = { 782const struct address_space_operations exofs_aops = {
@@ -808,87 +817,55 @@ static inline int exofs_inode_is_fast_symlink(struct inode *inode)
808 return S_ISLNK(inode->i_mode) && (oi->i_data[0] != 0); 817 return S_ISLNK(inode->i_mode) && (oi->i_data[0] != 0);
809} 818}
810 819
811/*
812 * get_block_t - Fill in a buffer_head
813 * An OSD takes care of block allocation so we just fake an allocation by
814 * putting in the inode's sector_t in the buffer_head.
815 * TODO: What about the case of create==0 and @iblock does not exist in the
816 * object?
817 */
818static int exofs_get_block(struct inode *inode, sector_t iblock,
819 struct buffer_head *bh_result, int create)
820{
821 map_bh(bh_result, inode->i_sb, iblock);
822 return 0;
823}
824
825const struct osd_attr g_attr_logical_length = ATTR_DEF( 820const struct osd_attr g_attr_logical_length = ATTR_DEF(
826 OSD_APAGE_OBJECT_INFORMATION, OSD_ATTR_OI_LOGICAL_LENGTH, 8); 821 OSD_APAGE_OBJECT_INFORMATION, OSD_ATTR_OI_LOGICAL_LENGTH, 8);
827 822
828static int _do_truncate(struct inode *inode) 823static int _do_truncate(struct inode *inode, loff_t newsize)
829{ 824{
830 struct exofs_i_info *oi = exofs_i(inode); 825 struct exofs_i_info *oi = exofs_i(inode);
831 loff_t isize = i_size_read(inode);
832 int ret; 826 int ret;
833 827
834 inode->i_mtime = inode->i_ctime = CURRENT_TIME; 828 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
835 829
836 nobh_truncate_page(inode->i_mapping, isize, exofs_get_block); 830 ret = exofs_oi_truncate(oi, (u64)newsize);
831 if (likely(!ret))
832 truncate_setsize(inode, newsize);
837 833
838 ret = exofs_oi_truncate(oi, (u64)isize); 834 EXOFS_DBGMSG("(0x%lx) size=0x%llx ret=>%d\n",
839 EXOFS_DBGMSG("(0x%lx) size=0x%llx\n", inode->i_ino, isize); 835 inode->i_ino, newsize, ret);
840 return ret; 836 return ret;
841} 837}
842 838
843/* 839/*
844 * Truncate a file to the specified size - all we have to do is set the size 840 * Set inode attributes - update size attribute on OSD if needed,
845 * attribute. We make sure the object exists first. 841 * otherwise just call generic functions.
846 */
847void exofs_truncate(struct inode *inode)
848{
849 struct exofs_i_info *oi = exofs_i(inode);
850 int ret;
851
852 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)
853 || S_ISLNK(inode->i_mode)))
854 return;
855 if (exofs_inode_is_fast_symlink(inode))
856 return;
857 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
858 return;
859
860 /* if we are about to truncate an object, and it hasn't been
861 * created yet, wait
862 */
863 if (unlikely(wait_obj_created(oi)))
864 goto fail;
865
866 ret = _do_truncate(inode);
867 if (ret)
868 goto fail;
869
870out:
871 mark_inode_dirty(inode);
872 return;
873fail:
874 make_bad_inode(inode);
875 goto out;
876}
877
878/*
879 * Set inode attributes - just call generic functions.
880 */ 842 */
881int exofs_setattr(struct dentry *dentry, struct iattr *iattr) 843int exofs_setattr(struct dentry *dentry, struct iattr *iattr)
882{ 844{
883 struct inode *inode = dentry->d_inode; 845 struct inode *inode = dentry->d_inode;
884 int error; 846 int error;
885 847
848 /* if we are about to modify an object, and it hasn't been
849 * created yet, wait
850 */
851 error = wait_obj_created(exofs_i(inode));
852 if (unlikely(error))
853 return error;
854
886 error = inode_change_ok(inode, iattr); 855 error = inode_change_ok(inode, iattr);
887 if (error) 856 if (unlikely(error))
888 return error; 857 return error;
889 858
890 error = inode_setattr(inode, iattr); 859 if ((iattr->ia_valid & ATTR_SIZE) &&
891 return error; 860 iattr->ia_size != i_size_read(inode)) {
861 error = _do_truncate(inode, iattr->ia_size);
862 if (unlikely(error))
863 return error;
864 }
865
866 setattr_copy(inode, iattr);
867 mark_inode_dirty(inode);
868 return 0;
892} 869}
893 870
894static const struct osd_attr g_attr_inode_file_layout = ATTR_DEF( 871static const struct osd_attr g_attr_inode_file_layout = ATTR_DEF(
@@ -1325,7 +1302,7 @@ static void delete_done(struct exofs_io_state *ios, void *p)
1325 * from the OSD here. We make sure the object was created before we try and 1302 * from the OSD here. We make sure the object was created before we try and
1326 * delete it. 1303 * delete it.
1327 */ 1304 */
1328void exofs_delete_inode(struct inode *inode) 1305void exofs_evict_inode(struct inode *inode)
1329{ 1306{
1330 struct exofs_i_info *oi = exofs_i(inode); 1307 struct exofs_i_info *oi = exofs_i(inode);
1331 struct super_block *sb = inode->i_sb; 1308 struct super_block *sb = inode->i_sb;
@@ -1335,30 +1312,27 @@ void exofs_delete_inode(struct inode *inode)
1335 1312
1336 truncate_inode_pages(&inode->i_data, 0); 1313 truncate_inode_pages(&inode->i_data, 0);
1337 1314
1338 if (is_bad_inode(inode)) 1315 /* TODO: should do better here */
1316 if (inode->i_nlink || is_bad_inode(inode))
1339 goto no_delete; 1317 goto no_delete;
1340 1318
1341 mark_inode_dirty(inode);
1342 exofs_update_inode(inode, inode_needs_sync(inode));
1343
1344 inode->i_size = 0; 1319 inode->i_size = 0;
1345 if (inode->i_blocks) 1320 end_writeback(inode);
1346 exofs_truncate(inode);
1347 1321
1348 clear_inode(inode); 1322 /* if we are deleting an obj that hasn't been created yet, wait */
1323 if (!obj_created(oi)) {
1324 BUG_ON(!obj_2bcreated(oi));
1325 wait_event(oi->i_wq, obj_created(oi));
1326 /* ignore the error attempt a remove anyway */
1327 }
1349 1328
1329 /* Now Remove the OSD objects */
1350 ret = exofs_get_io_state(&sbi->layout, &ios); 1330 ret = exofs_get_io_state(&sbi->layout, &ios);
1351 if (unlikely(ret)) { 1331 if (unlikely(ret)) {
1352 EXOFS_ERR("%s: exofs_get_io_state failed\n", __func__); 1332 EXOFS_ERR("%s: exofs_get_io_state failed\n", __func__);
1353 return; 1333 return;
1354 } 1334 }
1355 1335
1356 /* if we are deleting an obj that hasn't been created yet, wait */
1357 if (!obj_created(oi)) {
1358 BUG_ON(!obj_2bcreated(oi));
1359 wait_event(oi->i_wq, obj_created(oi));
1360 }
1361
1362 ios->obj.id = exofs_oi_objno(oi); 1336 ios->obj.id = exofs_oi_objno(oi);
1363 ios->done = delete_done; 1337 ios->done = delete_done;
1364 ios->private = sbi; 1338 ios->private = sbi;
@@ -1374,5 +1348,5 @@ void exofs_delete_inode(struct inode *inode)
1374 return; 1348 return;
1375 1349
1376no_delete: 1350no_delete:
1377 clear_inode(inode); 1351 end_writeback(inode);
1378} 1352}