34 #include <linux/slab.h>
38 #define EXOFS_DBGMSG2(M...) do {} while (0)
41 unsigned expected_pages)
43 unsigned pages =
min_t(
unsigned, expected_pages,
66 static void _pcol_init(
struct page_collect *pcol,
unsigned expected_pages,
112 for (;
pages; pages >>= 1) {
121 EXOFS_ERR(
"Failed to kmalloc expected_pages=%u\n",
149 static int update_read_page(
struct page *page,
int ret)
154 SetPageUptodate(page);
156 ClearPageError(page);
164 clear_highpage(page);
166 SetPageUptodate(page);
168 ClearPageError(page);
180 static void update_write_page(
struct page *page,
int ret)
186 mapping_set_error(page->
mapping, ret);
203 good_bytes = pcol->
length;
210 " length=0x%lx nr_pages=%u\n",
214 for (i = 0; i < pcol->
nr_pages; i++) {
215 struct page *page = pcol->
pages[
i];
219 if (inode != pcol->
inode)
222 if (
likely(length < good_bytes))
229 page_stat ?
"bad_bytes" :
"good_bytes");
231 ret = update_read_page(page, page_stat);
243 static void readpages_done(
struct ore_io_state *ios,
void *
p)
247 __readpages_done(pcol);
252 static void _unlock_pcol_pages(
struct page_collect *pcol,
int ret,
int rw)
256 for (i = 0; i < pcol->
nr_pages; i++) {
257 struct page *page = pcol->
pages[
i];
260 update_read_page(page, ret);
262 update_write_page(page, ret);
268 static int _maybe_not_all_in_one_io(
struct ore_io_state *ios,
275 struct page **src_page;
277 unsigned long len_less = pcol_src->
length - ios->
length;
290 pcol->
pg_first = (*src_page)->index;
292 ret = pcol_try_alloc(pcol);
296 for (i = 0; i < pages_less; ++
i)
297 pcol->
pages[i] = *src_page++;
300 "pages_less=0x%x expected_pages=0x%x "
301 "next_offset=0x%llx next_len=0x%lx\n",
332 return __readpages_done(pcol);
342 ios->
done = readpages_done;
348 ret = _maybe_not_all_in_one_io(ios, pcol_copy, pcol);
352 EXOFS_DBGMSG2(
"read_exec(0x%lx) offset=0x%llx length=0x%llx\n",
365 _unlock_pcol_pages(pcol, ret,
READ);
380 static int readpage_strip(
void *
data,
struct page *page)
383 struct inode *inode = pcol->
inode;
385 loff_t i_size = i_size_read(inode);
390 BUG_ON(!PageLocked(page));
393 if (PageUptodate(page))
399 if (page->
index < end_index)
401 else if (page->
index == end_index)
406 if (!len || !obj_created(oi)) {
410 clear_highpage(page);
412 SetPageUptodate(page);
414 ClearPageError(page);
418 EXOFS_DBGMSG(
"readpage_strip(0x%lx) empty page len=%zx "
419 "read_4_write=%d index=0x%lx end_index=0x%lx "
420 "splitting\n", inode->
i_ino, len,
423 return read_exec(pcol);
433 ret = read_exec(pcol);
440 ret = pcol_try_alloc(pcol);
451 ret = pcol_add_page(pcol, page, len);
454 "this_len=0x%zx nr_pages=%u length=0x%lx\n",
458 ret = read_exec(pcol);
474 struct list_head *pages,
unsigned nr_pages)
479 _pcol_init(&pcol, nr_pages, mapping->
host);
483 EXOFS_ERR(
"read_cache_pages => %d\n", ret);
487 ret = read_exec(&pcol);
491 return read_exec(&pcol);
494 static int _readpage(
struct page *page,
bool read_4_write)
499 _pcol_init(&pcol, 1, page->
mapping->host);
502 ret = readpage_strip(&pcol, page);
508 return read_exec(&pcol);
514 static int exofs_readpage(
struct file *file,
struct page *page)
516 return _readpage(page,
false);
520 static void writepages_done(
struct ore_io_state *ios,
void *
p)
531 good_bytes = pcol->
length;
538 " length=0x%lx nr_pages=%u\n",
542 for (i = 0; i < pcol->
nr_pages; i++) {
543 struct page *page = pcol->
pages[
i];
544 struct inode *inode = page->
mapping->host;
547 if (inode != pcol->
inode)
550 if (
likely(length < good_bytes))
555 update_write_page(page, page_stat);
568 static struct page *__r4w_get_page(
void *
priv,
u64 offset,
bool *uptodate)
576 loff_t i_size = i_size_read(pcol->
inode);
578 if (offset >= i_size) {
590 "index=0x%llx\n",
_LLU(index));
595 if (PageDirty(page) || PageWriteback(page))
598 *uptodate = PageUptodate(page);
599 EXOFS_DBGMSG(
"index=0x%lx uptodate=%d\n", index, *uptodate);
609 static void __r4w_put_page(
void *priv,
struct page *page)
623 .get_page = &__r4w_get_page,
624 .put_page = &__r4w_put_page,
646 EXOFS_ERR(
"write_exec: Failed to kmalloc(pcol)\n");
655 ios->
done = writepages_done;
662 ret = _maybe_not_all_in_one_io(ios, pcol_copy, pcol);
666 EXOFS_DBGMSG2(
"write_exec(0x%lx) offset=0x%llx length=0x%llx\n",
671 EXOFS_ERR(
"write_exec: ore_write() Failed\n");
679 _unlock_pcol_pages(pcol, ret,
WRITE);
693 static int writepage_strip(
struct page *page,
697 struct inode *inode = pcol->
inode;
699 loff_t i_size = i_size_read(inode);
704 BUG_ON(!PageLocked(page));
706 ret = wait_obj_created(oi);
710 if (page->
index < end_index)
716 if (page->
index > end_index || !len) {
720 ret = write_exec(pcol);
724 ClearPageError(page);
727 "outside the limits\n",
740 ret = write_exec(pcol);
744 EXOFS_DBGMSG(
"writepage_strip(0x%lx, 0x%lx) Discontinuity\n",
750 ret = pcol_try_alloc(pcol);
758 ret = pcol_add_page(pcol, page, len);
761 "nr_pages=%u total_length=0x%lx\n",
765 ret = write_exec(pcol);
774 BUG_ON(PageWriteback(page));
775 set_page_writeback(page);
780 EXOFS_DBGMSG(
"Error: writepage_strip(0x%lx, 0x%lx)=>%d\n",
800 expected_pages = end - start + 1;
802 expected_pages = mapping->
nrpages;
804 if (expected_pages < 32L)
805 expected_pages = 32
L;
807 EXOFS_DBGMSG2(
"inode(0x%lx) wbc->start=0x%llx wbc->end=0x%llx "
808 "nrpages=%lu start=0x%lx end=0x%lx expected_pages=%ld\n",
810 mapping->
nrpages, start, end, expected_pages);
812 _pcol_init(&pcol, expected_pages, mapping->
host);
816 EXOFS_ERR(
"write_cache_pages => %d\n", ret);
820 ret = write_exec(&pcol);
825 return write_exec(&pcol);
830 for (i = 0; i < pcol.
nr_pages; i++) {
831 struct page *page = pcol.
pages[
i];
859 static void _write_failed(
struct inode *inode, loff_t to)
866 loff_t
pos,
unsigned len,
unsigned flags,
867 struct page **pagep,
void **fsdata)
886 loff_t i_size = i_size_read(mapping->
host);
890 if (page->
index < end_index)
892 else if (page->
index == end_index)
898 clear_highpage(page);
899 SetPageUptodate(page);
903 ret = _readpage(page,
true);
912 _write_failed(mapping->
host, pos + len);
917 static int exofs_write_begin_export(
struct file *file,
919 loff_t
pos,
unsigned len,
unsigned flags,
920 struct page **pagep,
void **fsdata)
928 static int exofs_write_end(
struct file *file,
struct address_space *mapping,
929 loff_t
pos,
unsigned len,
unsigned copied,
930 struct page *page,
void *fsdata)
932 struct inode *inode = mapping->
host;
934 loff_t i_size = inode->
i_size;
939 _write_failed(inode, pos + len);
942 if (i_size != inode->
i_size)
943 mark_inode_dirty(inode);
947 static int exofs_releasepage(
struct page *page,
gfp_t gfp)
954 static void exofs_invalidatepage(
struct page *page,
unsigned long offset)
961 .readpage = exofs_readpage,
962 .readpages = exofs_readpages,
964 .writepages = exofs_writepages,
965 .write_begin = exofs_write_begin_export,
966 .write_end = exofs_write_end,
967 .releasepage = exofs_releasepage,
969 .invalidatepage = exofs_invalidatepage,
978 .launder_page =
NULL,
979 .is_partially_uptodate =
NULL,
980 .error_remove_page =
NULL,
990 static inline int exofs_inode_is_fast_symlink(
struct inode *inode)
997 static int _do_truncate(
struct inode *inode, loff_t newsize)
1010 inode->
i_ino, newsize, ret);
1020 struct inode *inode = dentry->
d_inode;
1026 error = wait_obj_created(exofs_i(inode));
1035 iattr->
ia_size != i_size_read(inode)) {
1036 error = _do_truncate(inode, iattr->
ia_size);
1042 mark_inode_dirty(inode);
1064 [0] = g_attr_inode_data,
1065 [1] = g_attr_inode_file_layout,
1066 [2] = g_attr_inode_dir_layout,
1074 EXOFS_ERR(
"%s: ore_get_io_state failed.\n", __func__);
1078 attrs[1].
len = exofs_on_disk_inode_layout_size(sbi->
oc.numdevs);
1079 attrs[2].
len = exofs_on_disk_inode_layout_size(sbi->
oc.numdevs);
1086 EXOFS_ERR(
"object(0x%llx) corrupted, return empty file=>%d\n",
1088 memset(inode, 0,
sizeof(*inode));
1089 inode->
i_mode = 0040000 | (0777 & ~022);
1100 EXOFS_ERR(
"%s: extract_attr of inode_data failed\n", __func__);
1108 EXOFS_ERR(
"%s: extract_attr of inode_data failed\n", __func__);
1114 EXOFS_ERR(
"%s: unsupported files layout %d\n",
1123 EXOFS_ERR(
"%s: extract_attr of inode_data failed\n", __func__);
1129 EXOFS_ERR(
"%s: unsupported meta-data layout %d\n",
1153 struct inode *
inode;
1161 oi = exofs_i(inode);
1164 exofs_oi_objno(oi));
1167 ret = exofs_get_inode(sb, oi, &fcb);
1171 set_obj_created(oi);
1216 if (exofs_inode_is_fast_symlink(inode))
1237 return ERR_PTR(ret);
1242 if (!obj_created(oi)) {
1244 BUG_ON(!obj_2bcreated(oi));
1256 static void create_done(
struct ore_io_state *ios,
void *p)
1258 struct inode *inode =
p;
1269 EXOFS_ERR(
"object=0x%llx creation failed in pid=0x%llx",
1270 _LLU(exofs_oi_objno(oi)),
1280 set_obj_created(oi);
1292 struct inode *
inode;
1301 oi = exofs_i(inode);
1304 set_obj_2bcreated(oi);
1315 insert_inode_hash(inode);
1318 exofs_oi_objno(oi));
1321 mark_inode_dirty(inode);
1325 EXOFS_ERR(
"exofs_new_inode: ore_get_io_state failed\n");
1326 return ERR_PTR(ret);
1329 ios->
done = create_done;
1335 return ERR_PTR(ret);
1353 static void updatei_done(
struct ore_io_state *ios,
void *p)
1368 static int exofs_update_inode(
struct inode *inode,
int do_sync)
1399 if (old_valid_dev(inode->
i_rdev)) {
1414 EXOFS_ERR(
"%s: ore_get_io_state failed.\n", __func__);
1418 attr = g_attr_inode_data;
1423 wait_obj_created(oi);
1427 ios->
done = updatei_done;
1432 if (!do_sync && !ret) {
1442 inode->
i_ino, do_sync, ret);
1449 return exofs_update_inode(inode, 1);
1456 static void delete_done(
struct ore_io_state *ios,
void *p)
1491 wait_obj_created(oi);
1497 EXOFS_ERR(
"%s: ore_get_io_state failed\n", __func__);
1501 ios->
done = delete_done;
1506 EXOFS_ERR(
"%s: ore_remove failed\n", __func__);