diff options
Diffstat (limited to 'fs/exofs/inode.c')
| -rw-r--r-- | fs/exofs/inode.c | 409 |
1 files changed, 202 insertions, 207 deletions
diff --git a/fs/exofs/inode.c b/fs/exofs/inode.c index 6c10f7476699..698a8636d39c 100644 --- a/fs/exofs/inode.c +++ b/fs/exofs/inode.c | |||
| @@ -37,15 +37,18 @@ | |||
| 37 | 37 | ||
| 38 | #include "exofs.h" | 38 | #include "exofs.h" |
| 39 | 39 | ||
| 40 | #ifdef CONFIG_EXOFS_DEBUG | 40 | #define EXOFS_DBGMSG2(M...) do {} while (0) |
| 41 | # define EXOFS_DEBUG_OBJ_ISIZE 1 | 41 | |
| 42 | #endif | 42 | enum { BIO_MAX_PAGES_KMALLOC = |
| 43 | (PAGE_SIZE - sizeof(struct bio)) / sizeof(struct bio_vec), | ||
| 44 | }; | ||
| 43 | 45 | ||
| 44 | struct page_collect { | 46 | struct page_collect { |
| 45 | struct exofs_sb_info *sbi; | 47 | struct exofs_sb_info *sbi; |
| 46 | struct request_queue *req_q; | 48 | struct request_queue *req_q; |
| 47 | struct inode *inode; | 49 | struct inode *inode; |
| 48 | unsigned expected_pages; | 50 | unsigned expected_pages; |
| 51 | struct exofs_io_state *ios; | ||
| 49 | 52 | ||
| 50 | struct bio *bio; | 53 | struct bio *bio; |
| 51 | unsigned nr_pages; | 54 | unsigned nr_pages; |
| @@ -54,22 +57,23 @@ struct page_collect { | |||
| 54 | }; | 57 | }; |
| 55 | 58 | ||
| 56 | static void _pcol_init(struct page_collect *pcol, unsigned expected_pages, | 59 | static void _pcol_init(struct page_collect *pcol, unsigned expected_pages, |
| 57 | struct inode *inode) | 60 | struct inode *inode) |
| 58 | { | 61 | { |
| 59 | struct exofs_sb_info *sbi = inode->i_sb->s_fs_info; | 62 | struct exofs_sb_info *sbi = inode->i_sb->s_fs_info; |
| 60 | 63 | ||
| 61 | pcol->sbi = sbi; | 64 | pcol->sbi = sbi; |
| 62 | pcol->req_q = osd_request_queue(sbi->s_dev); | 65 | /* Create master bios on first Q, later on cloning, each clone will be |
| 66 | * allocated on it's destination Q | ||
| 67 | */ | ||
| 68 | pcol->req_q = osd_request_queue(sbi->s_ods[0]); | ||
| 63 | pcol->inode = inode; | 69 | pcol->inode = inode; |
| 64 | pcol->expected_pages = expected_pages; | 70 | pcol->expected_pages = expected_pages; |
| 65 | 71 | ||
| 72 | pcol->ios = NULL; | ||
| 66 | pcol->bio = NULL; | 73 | pcol->bio = NULL; |
| 67 | pcol->nr_pages = 0; | 74 | pcol->nr_pages = 0; |
| 68 | pcol->length = 0; | 75 | pcol->length = 0; |
| 69 | pcol->pg_first = -1; | 76 | pcol->pg_first = -1; |
| 70 | |||
| 71 | EXOFS_DBGMSG("_pcol_init ino=0x%lx expected_pages=%u\n", inode->i_ino, | ||
| 72 | expected_pages); | ||
| 73 | } | 77 | } |
| 74 | 78 | ||
| 75 | static void _pcol_reset(struct page_collect *pcol) | 79 | static void _pcol_reset(struct page_collect *pcol) |
| @@ -80,35 +84,49 @@ static void _pcol_reset(struct page_collect *pcol) | |||
| 80 | pcol->nr_pages = 0; | 84 | pcol->nr_pages = 0; |
| 81 | pcol->length = 0; | 85 | pcol->length = 0; |
| 82 | pcol->pg_first = -1; | 86 | pcol->pg_first = -1; |
| 83 | EXOFS_DBGMSG("_pcol_reset ino=0x%lx expected_pages=%u\n", | 87 | pcol->ios = NULL; |
| 84 | pcol->inode->i_ino, pcol->expected_pages); | ||
| 85 | 88 | ||
| 86 | /* this is probably the end of the loop but in writes | 89 | /* this is probably the end of the loop but in writes |
| 87 | * it might not end here. don't be left with nothing | 90 | * it might not end here. don't be left with nothing |
| 88 | */ | 91 | */ |
| 89 | if (!pcol->expected_pages) | 92 | if (!pcol->expected_pages) |
| 90 | pcol->expected_pages = 128; | 93 | pcol->expected_pages = BIO_MAX_PAGES_KMALLOC; |
| 91 | } | 94 | } |
| 92 | 95 | ||
| 93 | static int pcol_try_alloc(struct page_collect *pcol) | 96 | static int pcol_try_alloc(struct page_collect *pcol) |
| 94 | { | 97 | { |
| 95 | int pages = min_t(unsigned, pcol->expected_pages, BIO_MAX_PAGES); | 98 | int pages = min_t(unsigned, pcol->expected_pages, |
| 99 | BIO_MAX_PAGES_KMALLOC); | ||
| 100 | |||
| 101 | if (!pcol->ios) { /* First time allocate io_state */ | ||
| 102 | int ret = exofs_get_io_state(pcol->sbi, &pcol->ios); | ||
| 103 | |||
| 104 | if (ret) | ||
| 105 | return ret; | ||
| 106 | } | ||
| 96 | 107 | ||
| 97 | for (; pages; pages >>= 1) { | 108 | for (; pages; pages >>= 1) { |
| 98 | pcol->bio = bio_alloc(GFP_KERNEL, pages); | 109 | pcol->bio = bio_kmalloc(GFP_KERNEL, pages); |
| 99 | if (likely(pcol->bio)) | 110 | if (likely(pcol->bio)) |
| 100 | return 0; | 111 | return 0; |
| 101 | } | 112 | } |
| 102 | 113 | ||
| 103 | EXOFS_ERR("Failed to kcalloc expected_pages=%u\n", | 114 | EXOFS_ERR("Failed to bio_kmalloc expected_pages=%u\n", |
| 104 | pcol->expected_pages); | 115 | pcol->expected_pages); |
| 105 | return -ENOMEM; | 116 | return -ENOMEM; |
| 106 | } | 117 | } |
| 107 | 118 | ||
| 108 | static void pcol_free(struct page_collect *pcol) | 119 | static void pcol_free(struct page_collect *pcol) |
| 109 | { | 120 | { |
| 110 | bio_put(pcol->bio); | 121 | if (pcol->bio) { |
| 111 | pcol->bio = NULL; | 122 | bio_put(pcol->bio); |
| 123 | pcol->bio = NULL; | ||
| 124 | } | ||
| 125 | |||
| 126 | if (pcol->ios) { | ||
| 127 | exofs_put_io_state(pcol->ios); | ||
| 128 | pcol->ios = NULL; | ||
| 129 | } | ||
| 112 | } | 130 | } |
| 113 | 131 | ||
| 114 | static int pcol_add_page(struct page_collect *pcol, struct page *page, | 132 | static int pcol_add_page(struct page_collect *pcol, struct page *page, |
| @@ -161,22 +179,17 @@ static void update_write_page(struct page *page, int ret) | |||
| 161 | /* Called at the end of reads, to optionally unlock pages and update their | 179 | /* Called at the end of reads, to optionally unlock pages and update their |
| 162 | * status. | 180 | * status. |
| 163 | */ | 181 | */ |
| 164 | static int __readpages_done(struct osd_request *or, struct page_collect *pcol, | 182 | static int __readpages_done(struct page_collect *pcol, bool do_unlock) |
| 165 | bool do_unlock) | ||
| 166 | { | 183 | { |
| 167 | struct bio_vec *bvec; | 184 | struct bio_vec *bvec; |
| 168 | int i; | 185 | int i; |
| 169 | u64 resid; | 186 | u64 resid; |
| 170 | u64 good_bytes; | 187 | u64 good_bytes; |
| 171 | u64 length = 0; | 188 | u64 length = 0; |
| 172 | int ret = exofs_check_ok_resid(or, &resid, NULL); | 189 | int ret = exofs_check_io(pcol->ios, &resid); |
| 173 | |||
| 174 | osd_end_request(or); | ||
| 175 | 190 | ||
| 176 | if (likely(!ret)) | 191 | if (likely(!ret)) |
| 177 | good_bytes = pcol->length; | 192 | good_bytes = pcol->length; |
| 178 | else if (!resid) | ||
| 179 | good_bytes = 0; | ||
| 180 | else | 193 | else |
| 181 | good_bytes = pcol->length - resid; | 194 | good_bytes = pcol->length - resid; |
| 182 | 195 | ||
| @@ -198,7 +211,7 @@ static int __readpages_done(struct osd_request *or, struct page_collect *pcol, | |||
| 198 | else | 211 | else |
| 199 | page_stat = ret; | 212 | page_stat = ret; |
| 200 | 213 | ||
| 201 | EXOFS_DBGMSG(" readpages_done(0x%lx, 0x%lx) %s\n", | 214 | EXOFS_DBGMSG2(" readpages_done(0x%lx, 0x%lx) %s\n", |
| 202 | inode->i_ino, page->index, | 215 | inode->i_ino, page->index, |
| 203 | page_stat ? "bad_bytes" : "good_bytes"); | 216 | page_stat ? "bad_bytes" : "good_bytes"); |
| 204 | 217 | ||
| @@ -214,13 +227,13 @@ static int __readpages_done(struct osd_request *or, struct page_collect *pcol, | |||
| 214 | } | 227 | } |
| 215 | 228 | ||
| 216 | /* callback of async reads */ | 229 | /* callback of async reads */ |
| 217 | static void readpages_done(struct osd_request *or, void *p) | 230 | static void readpages_done(struct exofs_io_state *ios, void *p) |
| 218 | { | 231 | { |
| 219 | struct page_collect *pcol = p; | 232 | struct page_collect *pcol = p; |
| 220 | 233 | ||
| 221 | __readpages_done(or, pcol, true); | 234 | __readpages_done(pcol, true); |
| 222 | atomic_dec(&pcol->sbi->s_curr_pending); | 235 | atomic_dec(&pcol->sbi->s_curr_pending); |
| 223 | kfree(p); | 236 | kfree(pcol); |
| 224 | } | 237 | } |
| 225 | 238 | ||
| 226 | static void _unlock_pcol_pages(struct page_collect *pcol, int ret, int rw) | 239 | static void _unlock_pcol_pages(struct page_collect *pcol, int ret, int rw) |
| @@ -238,17 +251,13 @@ static void _unlock_pcol_pages(struct page_collect *pcol, int ret, int rw) | |||
| 238 | 251 | ||
| 239 | unlock_page(page); | 252 | unlock_page(page); |
| 240 | } | 253 | } |
| 241 | pcol_free(pcol); | ||
| 242 | } | 254 | } |
| 243 | 255 | ||
| 244 | static int read_exec(struct page_collect *pcol, bool is_sync) | 256 | static int read_exec(struct page_collect *pcol, bool is_sync) |
| 245 | { | 257 | { |
| 246 | struct exofs_i_info *oi = exofs_i(pcol->inode); | 258 | struct exofs_i_info *oi = exofs_i(pcol->inode); |
| 247 | struct osd_obj_id obj = {pcol->sbi->s_pid, | 259 | struct exofs_io_state *ios = pcol->ios; |
| 248 | pcol->inode->i_ino + EXOFS_OBJ_OFF}; | ||
| 249 | struct osd_request *or = NULL; | ||
| 250 | struct page_collect *pcol_copy = NULL; | 260 | struct page_collect *pcol_copy = NULL; |
| 251 | loff_t i_start = pcol->pg_first << PAGE_CACHE_SHIFT; | ||
| 252 | int ret; | 261 | int ret; |
| 253 | 262 | ||
| 254 | if (!pcol->bio) | 263 | if (!pcol->bio) |
| @@ -257,17 +266,13 @@ static int read_exec(struct page_collect *pcol, bool is_sync) | |||
| 257 | /* see comment in _readpage() about sync reads */ | 266 | /* see comment in _readpage() about sync reads */ |
| 258 | WARN_ON(is_sync && (pcol->nr_pages != 1)); | 267 | WARN_ON(is_sync && (pcol->nr_pages != 1)); |
| 259 | 268 | ||
| 260 | or = osd_start_request(pcol->sbi->s_dev, GFP_KERNEL); | 269 | ios->bio = pcol->bio; |
| 261 | if (unlikely(!or)) { | 270 | ios->length = pcol->length; |
| 262 | ret = -ENOMEM; | 271 | ios->offset = pcol->pg_first << PAGE_CACHE_SHIFT; |
| 263 | goto err; | ||
| 264 | } | ||
| 265 | |||
| 266 | osd_req_read(or, &obj, i_start, pcol->bio, pcol->length); | ||
| 267 | 272 | ||
| 268 | if (is_sync) { | 273 | if (is_sync) { |
| 269 | exofs_sync_op(or, pcol->sbi->s_timeout, oi->i_cred); | 274 | exofs_oi_read(oi, pcol->ios); |
| 270 | return __readpages_done(or, pcol, false); | 275 | return __readpages_done(pcol, false); |
| 271 | } | 276 | } |
| 272 | 277 | ||
| 273 | pcol_copy = kmalloc(sizeof(*pcol_copy), GFP_KERNEL); | 278 | pcol_copy = kmalloc(sizeof(*pcol_copy), GFP_KERNEL); |
| @@ -277,14 +282,16 @@ static int read_exec(struct page_collect *pcol, bool is_sync) | |||
| 277 | } | 282 | } |
| 278 | 283 | ||
| 279 | *pcol_copy = *pcol; | 284 | *pcol_copy = *pcol; |
| 280 | ret = exofs_async_op(or, readpages_done, pcol_copy, oi->i_cred); | 285 | ios->done = readpages_done; |
| 286 | ios->private = pcol_copy; | ||
| 287 | ret = exofs_oi_read(oi, ios); | ||
| 281 | if (unlikely(ret)) | 288 | if (unlikely(ret)) |
| 282 | goto err; | 289 | goto err; |
| 283 | 290 | ||
| 284 | atomic_inc(&pcol->sbi->s_curr_pending); | 291 | atomic_inc(&pcol->sbi->s_curr_pending); |
| 285 | 292 | ||
| 286 | EXOFS_DBGMSG("read_exec obj=0x%llx start=0x%llx length=0x%lx\n", | 293 | EXOFS_DBGMSG("read_exec obj=0x%llx start=0x%llx length=0x%lx\n", |
| 287 | obj.id, _LLU(i_start), pcol->length); | 294 | ios->obj.id, _LLU(ios->offset), pcol->length); |
| 288 | 295 | ||
| 289 | /* pages ownership was passed to pcol_copy */ | 296 | /* pages ownership was passed to pcol_copy */ |
| 290 | _pcol_reset(pcol); | 297 | _pcol_reset(pcol); |
| @@ -293,12 +300,10 @@ static int read_exec(struct page_collect *pcol, bool is_sync) | |||
| 293 | err: | 300 | err: |
| 294 | if (!is_sync) | 301 | if (!is_sync) |
| 295 | _unlock_pcol_pages(pcol, ret, READ); | 302 | _unlock_pcol_pages(pcol, ret, READ); |
| 296 | else /* Pages unlocked by caller in sync mode only free bio */ | 303 | |
| 297 | pcol_free(pcol); | 304 | pcol_free(pcol); |
| 298 | 305 | ||
| 299 | kfree(pcol_copy); | 306 | kfree(pcol_copy); |
| 300 | if (or) | ||
| 301 | osd_end_request(or); | ||
| 302 | return ret; | 307 | return ret; |
| 303 | } | 308 | } |
| 304 | 309 | ||
| @@ -370,12 +375,12 @@ try_again: | |||
| 370 | if (len != PAGE_CACHE_SIZE) | 375 | if (len != PAGE_CACHE_SIZE) |
| 371 | zero_user(page, len, PAGE_CACHE_SIZE - len); | 376 | zero_user(page, len, PAGE_CACHE_SIZE - len); |
| 372 | 377 | ||
| 373 | EXOFS_DBGMSG(" readpage_strip(0x%lx, 0x%lx) len=0x%zx\n", | 378 | EXOFS_DBGMSG2(" readpage_strip(0x%lx, 0x%lx) len=0x%zx\n", |
| 374 | inode->i_ino, page->index, len); | 379 | inode->i_ino, page->index, len); |
| 375 | 380 | ||
| 376 | ret = pcol_add_page(pcol, page, len); | 381 | ret = pcol_add_page(pcol, page, len); |
| 377 | if (ret) { | 382 | if (ret) { |
| 378 | EXOFS_DBGMSG("Failed pcol_add_page pages[i]=%p " | 383 | EXOFS_DBGMSG2("Failed pcol_add_page pages[i]=%p " |
| 379 | "this_len=0x%zx nr_pages=%u length=0x%lx\n", | 384 | "this_len=0x%zx nr_pages=%u length=0x%lx\n", |
| 380 | page, len, pcol->nr_pages, pcol->length); | 385 | page, len, pcol->nr_pages, pcol->length); |
| 381 | 386 | ||
| @@ -419,9 +424,8 @@ static int _readpage(struct page *page, bool is_sync) | |||
| 419 | 424 | ||
| 420 | _pcol_init(&pcol, 1, page->mapping->host); | 425 | _pcol_init(&pcol, 1, page->mapping->host); |
| 421 | 426 | ||
| 422 | /* readpage_strip might call read_exec(,async) inside at several places | 427 | /* readpage_strip might call read_exec(,is_sync==false) at several |
| 423 | * but this is safe for is_async=0 since read_exec will not do anything | 428 | * places but not if we have a single page. |
| 424 | * when we have a single page. | ||
| 425 | */ | 429 | */ |
| 426 | ret = readpage_strip(&pcol, page); | 430 | ret = readpage_strip(&pcol, page); |
| 427 | if (ret) { | 431 | if (ret) { |
| @@ -440,8 +444,8 @@ static int exofs_readpage(struct file *file, struct page *page) | |||
| 440 | return _readpage(page, false); | 444 | return _readpage(page, false); |
| 441 | } | 445 | } |
| 442 | 446 | ||
| 443 | /* Callback for osd_write. All writes are asynchronouse */ | 447 | /* Callback for osd_write. All writes are asynchronous */ |
| 444 | static void writepages_done(struct osd_request *or, void *p) | 448 | static void writepages_done(struct exofs_io_state *ios, void *p) |
| 445 | { | 449 | { |
| 446 | struct page_collect *pcol = p; | 450 | struct page_collect *pcol = p; |
| 447 | struct bio_vec *bvec; | 451 | struct bio_vec *bvec; |
| @@ -449,16 +453,12 @@ static void writepages_done(struct osd_request *or, void *p) | |||
| 449 | u64 resid; | 453 | u64 resid; |
| 450 | u64 good_bytes; | 454 | u64 good_bytes; |
| 451 | u64 length = 0; | 455 | u64 length = 0; |
| 456 | int ret = exofs_check_io(ios, &resid); | ||
| 452 | 457 | ||
| 453 | int ret = exofs_check_ok_resid(or, NULL, &resid); | ||
| 454 | |||
| 455 | osd_end_request(or); | ||
| 456 | atomic_dec(&pcol->sbi->s_curr_pending); | 458 | atomic_dec(&pcol->sbi->s_curr_pending); |
| 457 | 459 | ||
| 458 | if (likely(!ret)) | 460 | if (likely(!ret)) |
| 459 | good_bytes = pcol->length; | 461 | good_bytes = pcol->length; |
| 460 | else if (!resid) | ||
| 461 | good_bytes = 0; | ||
| 462 | else | 462 | else |
| 463 | good_bytes = pcol->length - resid; | 463 | good_bytes = pcol->length - resid; |
| 464 | 464 | ||
| @@ -482,7 +482,7 @@ static void writepages_done(struct osd_request *or, void *p) | |||
| 482 | 482 | ||
| 483 | update_write_page(page, page_stat); | 483 | update_write_page(page, page_stat); |
| 484 | unlock_page(page); | 484 | unlock_page(page); |
| 485 | EXOFS_DBGMSG(" writepages_done(0x%lx, 0x%lx) status=%d\n", | 485 | EXOFS_DBGMSG2(" writepages_done(0x%lx, 0x%lx) status=%d\n", |
| 486 | inode->i_ino, page->index, page_stat); | 486 | inode->i_ino, page->index, page_stat); |
| 487 | 487 | ||
| 488 | length += bvec->bv_len; | 488 | length += bvec->bv_len; |
| @@ -496,23 +496,13 @@ static void writepages_done(struct osd_request *or, void *p) | |||
| 496 | static int write_exec(struct page_collect *pcol) | 496 | static int write_exec(struct page_collect *pcol) |
| 497 | { | 497 | { |
| 498 | struct exofs_i_info *oi = exofs_i(pcol->inode); | 498 | struct exofs_i_info *oi = exofs_i(pcol->inode); |
| 499 | struct osd_obj_id obj = {pcol->sbi->s_pid, | 499 | struct exofs_io_state *ios = pcol->ios; |
| 500 | pcol->inode->i_ino + EXOFS_OBJ_OFF}; | ||
| 501 | struct osd_request *or = NULL; | ||
| 502 | struct page_collect *pcol_copy = NULL; | 500 | struct page_collect *pcol_copy = NULL; |
| 503 | loff_t i_start = pcol->pg_first << PAGE_CACHE_SHIFT; | ||
| 504 | int ret; | 501 | int ret; |
| 505 | 502 | ||
| 506 | if (!pcol->bio) | 503 | if (!pcol->bio) |
| 507 | return 0; | 504 | return 0; |
| 508 | 505 | ||
| 509 | or = osd_start_request(pcol->sbi->s_dev, GFP_KERNEL); | ||
| 510 | if (unlikely(!or)) { | ||
| 511 | EXOFS_ERR("write_exec: Faild to osd_start_request()\n"); | ||
| 512 | ret = -ENOMEM; | ||
| 513 | goto err; | ||
| 514 | } | ||
| 515 | |||
| 516 | pcol_copy = kmalloc(sizeof(*pcol_copy), GFP_KERNEL); | 506 | pcol_copy = kmalloc(sizeof(*pcol_copy), GFP_KERNEL); |
| 517 | if (!pcol_copy) { | 507 | if (!pcol_copy) { |
| 518 | EXOFS_ERR("write_exec: Faild to kmalloc(pcol)\n"); | 508 | EXOFS_ERR("write_exec: Faild to kmalloc(pcol)\n"); |
| @@ -523,16 +513,22 @@ static int write_exec(struct page_collect *pcol) | |||
| 523 | *pcol_copy = *pcol; | 513 | *pcol_copy = *pcol; |
| 524 | 514 | ||
| 525 | pcol_copy->bio->bi_rw |= (1 << BIO_RW); /* FIXME: bio_set_dir() */ | 515 | pcol_copy->bio->bi_rw |= (1 << BIO_RW); /* FIXME: bio_set_dir() */ |
| 526 | osd_req_write(or, &obj, i_start, pcol_copy->bio, pcol_copy->length); | 516 | |
| 527 | ret = exofs_async_op(or, writepages_done, pcol_copy, oi->i_cred); | 517 | ios->bio = pcol_copy->bio; |
| 518 | ios->offset = pcol_copy->pg_first << PAGE_CACHE_SHIFT; | ||
| 519 | ios->length = pcol_copy->length; | ||
| 520 | ios->done = writepages_done; | ||
| 521 | ios->private = pcol_copy; | ||
| 522 | |||
| 523 | ret = exofs_oi_write(oi, ios); | ||
| 528 | if (unlikely(ret)) { | 524 | if (unlikely(ret)) { |
| 529 | EXOFS_ERR("write_exec: exofs_async_op() Faild\n"); | 525 | EXOFS_ERR("write_exec: exofs_oi_write() Faild\n"); |
| 530 | goto err; | 526 | goto err; |
| 531 | } | 527 | } |
| 532 | 528 | ||
| 533 | atomic_inc(&pcol->sbi->s_curr_pending); | 529 | atomic_inc(&pcol->sbi->s_curr_pending); |
| 534 | EXOFS_DBGMSG("write_exec(0x%lx, 0x%llx) start=0x%llx length=0x%lx\n", | 530 | EXOFS_DBGMSG("write_exec(0x%lx, 0x%llx) start=0x%llx length=0x%lx\n", |
| 535 | pcol->inode->i_ino, pcol->pg_first, _LLU(i_start), | 531 | pcol->inode->i_ino, pcol->pg_first, _LLU(ios->offset), |
| 536 | pcol->length); | 532 | pcol->length); |
| 537 | /* pages ownership was passed to pcol_copy */ | 533 | /* pages ownership was passed to pcol_copy */ |
| 538 | _pcol_reset(pcol); | 534 | _pcol_reset(pcol); |
| @@ -540,9 +536,9 @@ static int write_exec(struct page_collect *pcol) | |||
| 540 | 536 | ||
| 541 | err: | 537 | err: |
| 542 | _unlock_pcol_pages(pcol, ret, WRITE); | 538 | _unlock_pcol_pages(pcol, ret, WRITE); |
| 539 | pcol_free(pcol); | ||
| 543 | kfree(pcol_copy); | 540 | kfree(pcol_copy); |
| 544 | if (or) | 541 | |
| 545 | osd_end_request(or); | ||
| 546 | return ret; | 542 | return ret; |
| 547 | } | 543 | } |
| 548 | 544 | ||
| @@ -586,6 +582,9 @@ static int writepage_strip(struct page *page, | |||
| 586 | if (PageError(page)) | 582 | if (PageError(page)) |
| 587 | ClearPageError(page); | 583 | ClearPageError(page); |
| 588 | unlock_page(page); | 584 | unlock_page(page); |
| 585 | EXOFS_DBGMSG("writepage_strip(0x%lx, 0x%lx) " | ||
| 586 | "outside the limits\n", | ||
| 587 | inode->i_ino, page->index); | ||
| 589 | return 0; | 588 | return 0; |
| 590 | } | 589 | } |
| 591 | } | 590 | } |
| @@ -600,6 +599,9 @@ try_again: | |||
| 600 | ret = write_exec(pcol); | 599 | ret = write_exec(pcol); |
| 601 | if (unlikely(ret)) | 600 | if (unlikely(ret)) |
| 602 | goto fail; | 601 | goto fail; |
| 602 | |||
| 603 | EXOFS_DBGMSG("writepage_strip(0x%lx, 0x%lx) Discontinuity\n", | ||
| 604 | inode->i_ino, page->index); | ||
| 603 | goto try_again; | 605 | goto try_again; |
| 604 | } | 606 | } |
| 605 | 607 | ||
| @@ -609,7 +611,7 @@ try_again: | |||
| 609 | goto fail; | 611 | goto fail; |
| 610 | } | 612 | } |
| 611 | 613 | ||
| 612 | EXOFS_DBGMSG(" writepage_strip(0x%lx, 0x%lx) len=0x%zx\n", | 614 | EXOFS_DBGMSG2(" writepage_strip(0x%lx, 0x%lx) len=0x%zx\n", |
| 613 | inode->i_ino, page->index, len); | 615 | inode->i_ino, page->index, len); |
| 614 | 616 | ||
| 615 | ret = pcol_add_page(pcol, page, len); | 617 | ret = pcol_add_page(pcol, page, len); |
| @@ -634,6 +636,8 @@ try_again: | |||
| 634 | return 0; | 636 | return 0; |
| 635 | 637 | ||
| 636 | fail: | 638 | fail: |
| 639 | EXOFS_DBGMSG("Error: writepage_strip(0x%lx, 0x%lx)=>%d\n", | ||
| 640 | inode->i_ino, page->index, ret); | ||
| 637 | set_bit(AS_EIO, &page->mapping->flags); | 641 | set_bit(AS_EIO, &page->mapping->flags); |
| 638 | unlock_page(page); | 642 | unlock_page(page); |
| 639 | return ret; | 643 | return ret; |
| @@ -652,14 +656,17 @@ static int exofs_writepages(struct address_space *mapping, | |||
| 652 | wbc->range_end >> PAGE_CACHE_SHIFT; | 656 | wbc->range_end >> PAGE_CACHE_SHIFT; |
| 653 | 657 | ||
| 654 | if (start || end) | 658 | if (start || end) |
| 655 | expected_pages = min(end - start + 1, 32L); | 659 | expected_pages = end - start + 1; |
| 656 | else | 660 | else |
| 657 | expected_pages = mapping->nrpages; | 661 | expected_pages = mapping->nrpages; |
| 658 | 662 | ||
| 659 | EXOFS_DBGMSG("inode(0x%lx) wbc->start=0x%llx wbc->end=0x%llx" | 663 | if (expected_pages < 32L) |
| 660 | " m->nrpages=%lu start=0x%lx end=0x%lx\n", | 664 | expected_pages = 32L; |
| 665 | |||
| 666 | EXOFS_DBGMSG("inode(0x%lx) wbc->start=0x%llx wbc->end=0x%llx " | ||
| 667 | "nrpages=%lu start=0x%lx end=0x%lx expected_pages=%ld\n", | ||
| 661 | mapping->host->i_ino, wbc->range_start, wbc->range_end, | 668 | mapping->host->i_ino, wbc->range_start, wbc->range_end, |
| 662 | mapping->nrpages, start, end); | 669 | mapping->nrpages, start, end, expected_pages); |
| 663 | 670 | ||
| 664 | _pcol_init(&pcol, expected_pages, mapping->host); | 671 | _pcol_init(&pcol, expected_pages, mapping->host); |
| 665 | 672 | ||
| @@ -771,19 +778,28 @@ static int exofs_get_block(struct inode *inode, sector_t iblock, | |||
| 771 | const struct osd_attr g_attr_logical_length = ATTR_DEF( | 778 | const struct osd_attr g_attr_logical_length = ATTR_DEF( |
| 772 | OSD_APAGE_OBJECT_INFORMATION, OSD_ATTR_OI_LOGICAL_LENGTH, 8); | 779 | OSD_APAGE_OBJECT_INFORMATION, OSD_ATTR_OI_LOGICAL_LENGTH, 8); |
| 773 | 780 | ||
| 781 | static int _do_truncate(struct inode *inode) | ||
| 782 | { | ||
| 783 | struct exofs_i_info *oi = exofs_i(inode); | ||
| 784 | loff_t isize = i_size_read(inode); | ||
| 785 | int ret; | ||
| 786 | |||
| 787 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; | ||
| 788 | |||
| 789 | nobh_truncate_page(inode->i_mapping, isize, exofs_get_block); | ||
| 790 | |||
| 791 | ret = exofs_oi_truncate(oi, (u64)isize); | ||
| 792 | EXOFS_DBGMSG("(0x%lx) size=0x%llx\n", inode->i_ino, isize); | ||
| 793 | return ret; | ||
| 794 | } | ||
| 795 | |||
| 774 | /* | 796 | /* |
| 775 | * Truncate a file to the specified size - all we have to do is set the size | 797 | * Truncate a file to the specified size - all we have to do is set the size |
| 776 | * attribute. We make sure the object exists first. | 798 | * attribute. We make sure the object exists first. |
| 777 | */ | 799 | */ |
| 778 | void exofs_truncate(struct inode *inode) | 800 | void exofs_truncate(struct inode *inode) |
| 779 | { | 801 | { |
| 780 | struct exofs_sb_info *sbi = inode->i_sb->s_fs_info; | ||
| 781 | struct exofs_i_info *oi = exofs_i(inode); | 802 | struct exofs_i_info *oi = exofs_i(inode); |
| 782 | struct osd_obj_id obj = {sbi->s_pid, inode->i_ino + EXOFS_OBJ_OFF}; | ||
| 783 | struct osd_request *or; | ||
| 784 | struct osd_attr attr; | ||
| 785 | loff_t isize = i_size_read(inode); | ||
| 786 | __be64 newsize; | ||
| 787 | int ret; | 803 | int ret; |
| 788 | 804 | ||
| 789 | if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) | 805 | if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) |
| @@ -793,22 +809,6 @@ void exofs_truncate(struct inode *inode) | |||
| 793 | return; | 809 | return; |
| 794 | if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) | 810 | if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) |
| 795 | return; | 811 | return; |
| 796 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; | ||
| 797 | |||
| 798 | nobh_truncate_page(inode->i_mapping, isize, exofs_get_block); | ||
| 799 | |||
| 800 | or = osd_start_request(sbi->s_dev, GFP_KERNEL); | ||
| 801 | if (unlikely(!or)) { | ||
| 802 | EXOFS_ERR("ERROR: exofs_truncate: osd_start_request failed\n"); | ||
| 803 | goto fail; | ||
| 804 | } | ||
| 805 | |||
| 806 | osd_req_set_attributes(or, &obj); | ||
| 807 | |||
| 808 | newsize = cpu_to_be64((u64)isize); | ||
| 809 | attr = g_attr_logical_length; | ||
| 810 | attr.val_ptr = &newsize; | ||
| 811 | osd_req_add_set_attr_list(or, &attr, 1); | ||
| 812 | 812 | ||
| 813 | /* if we are about to truncate an object, and it hasn't been | 813 | /* if we are about to truncate an object, and it hasn't been |
| 814 | * created yet, wait | 814 | * created yet, wait |
| @@ -816,8 +816,7 @@ void exofs_truncate(struct inode *inode) | |||
| 816 | if (unlikely(wait_obj_created(oi))) | 816 | if (unlikely(wait_obj_created(oi))) |
| 817 | goto fail; | 817 | goto fail; |
| 818 | 818 | ||
| 819 | ret = exofs_sync_op(or, sbi->s_timeout, oi->i_cred); | 819 | ret = _do_truncate(inode); |
| 820 | osd_end_request(or); | ||
| 821 | if (ret) | 820 | if (ret) |
| 822 | goto fail; | 821 | goto fail; |
| 823 | 822 | ||
| @@ -847,65 +846,62 @@ int exofs_setattr(struct dentry *dentry, struct iattr *iattr) | |||
| 847 | 846 | ||
| 848 | /* | 847 | /* |
| 849 | * Read an inode from the OSD, and return it as is. We also return the size | 848 | * Read an inode from the OSD, and return it as is. We also return the size |
| 850 | * attribute in the 'sanity' argument if we got compiled with debugging turned | 849 | * attribute in the 'obj_size' argument. |
| 851 | * on. | ||
| 852 | */ | 850 | */ |
| 853 | static int exofs_get_inode(struct super_block *sb, struct exofs_i_info *oi, | 851 | static int exofs_get_inode(struct super_block *sb, struct exofs_i_info *oi, |
| 854 | struct exofs_fcb *inode, uint64_t *sanity) | 852 | struct exofs_fcb *inode, uint64_t *obj_size) |
| 855 | { | 853 | { |
| 856 | struct exofs_sb_info *sbi = sb->s_fs_info; | 854 | struct exofs_sb_info *sbi = sb->s_fs_info; |
| 857 | struct osd_request *or; | 855 | struct osd_attr attrs[2]; |
| 858 | struct osd_attr attr; | 856 | struct exofs_io_state *ios; |
| 859 | struct osd_obj_id obj = {sbi->s_pid, | ||
| 860 | oi->vfs_inode.i_ino + EXOFS_OBJ_OFF}; | ||
| 861 | int ret; | 857 | int ret; |
| 862 | 858 | ||
| 863 | exofs_make_credential(oi->i_cred, &obj); | 859 | *obj_size = ~0; |
| 864 | 860 | ret = exofs_get_io_state(sbi, &ios); | |
| 865 | or = osd_start_request(sbi->s_dev, GFP_KERNEL); | 861 | if (unlikely(ret)) { |
| 866 | if (unlikely(!or)) { | 862 | EXOFS_ERR("%s: exofs_get_io_state failed.\n", __func__); |
| 867 | EXOFS_ERR("exofs_get_inode: osd_start_request failed.\n"); | 863 | return ret; |
| 868 | return -ENOMEM; | ||
| 869 | } | 864 | } |
| 870 | osd_req_get_attributes(or, &obj); | ||
| 871 | 865 | ||
| 872 | /* we need the inode attribute */ | 866 | ios->obj.id = exofs_oi_objno(oi); |
| 873 | osd_req_add_get_attr_list(or, &g_attr_inode_data, 1); | 867 | exofs_make_credential(oi->i_cred, &ios->obj); |
| 868 | ios->cred = oi->i_cred; | ||
| 874 | 869 | ||
| 875 | #ifdef EXOFS_DEBUG_OBJ_ISIZE | 870 | attrs[0] = g_attr_inode_data; |
| 876 | /* we get the size attributes to do a sanity check */ | 871 | attrs[1] = g_attr_logical_length; |
| 877 | osd_req_add_get_attr_list(or, &g_attr_logical_length, 1); | 872 | ios->in_attr = attrs; |
| 878 | #endif | 873 | ios->in_attr_len = ARRAY_SIZE(attrs); |
| 879 | 874 | ||
| 880 | ret = exofs_sync_op(or, sbi->s_timeout, oi->i_cred); | 875 | ret = exofs_sbi_read(ios); |
| 881 | if (ret) | 876 | if (ret) |
| 882 | goto out; | 877 | goto out; |
| 883 | 878 | ||
| 884 | attr = g_attr_inode_data; | 879 | ret = extract_attr_from_ios(ios, &attrs[0]); |
| 885 | ret = extract_attr_from_req(or, &attr); | ||
| 886 | if (ret) { | 880 | if (ret) { |
| 887 | EXOFS_ERR("exofs_get_inode: extract_attr_from_req failed\n"); | 881 | EXOFS_ERR("%s: extract_attr of inode_data failed\n", __func__); |
| 888 | goto out; | 882 | goto out; |
| 889 | } | 883 | } |
| 884 | WARN_ON(attrs[0].len != EXOFS_INO_ATTR_SIZE); | ||
| 885 | memcpy(inode, attrs[0].val_ptr, EXOFS_INO_ATTR_SIZE); | ||
| 890 | 886 | ||
| 891 | WARN_ON(attr.len != EXOFS_INO_ATTR_SIZE); | 887 | ret = extract_attr_from_ios(ios, &attrs[1]); |
| 892 | memcpy(inode, attr.val_ptr, EXOFS_INO_ATTR_SIZE); | ||
| 893 | |||
| 894 | #ifdef EXOFS_DEBUG_OBJ_ISIZE | ||
| 895 | attr = g_attr_logical_length; | ||
| 896 | ret = extract_attr_from_req(or, &attr); | ||
| 897 | if (ret) { | 888 | if (ret) { |
| 898 | EXOFS_ERR("ERROR: extract attr from or failed\n"); | 889 | EXOFS_ERR("%s: extract_attr of logical_length failed\n", |
| 890 | __func__); | ||
| 899 | goto out; | 891 | goto out; |
| 900 | } | 892 | } |
| 901 | *sanity = get_unaligned_be64(attr.val_ptr); | 893 | *obj_size = get_unaligned_be64(attrs[1].val_ptr); |
| 902 | #endif | ||
| 903 | 894 | ||
| 904 | out: | 895 | out: |
| 905 | osd_end_request(or); | 896 | exofs_put_io_state(ios); |
| 906 | return ret; | 897 | return ret; |
| 907 | } | 898 | } |
| 908 | 899 | ||
| 900 | static void __oi_init(struct exofs_i_info *oi) | ||
| 901 | { | ||
| 902 | init_waitqueue_head(&oi->i_wq); | ||
| 903 | oi->i_flags = 0; | ||
| 904 | } | ||
| 909 | /* | 905 | /* |
| 910 | * Fill in an inode read from the OSD and set it up for use | 906 | * Fill in an inode read from the OSD and set it up for use |
| 911 | */ | 907 | */ |
| @@ -914,7 +910,7 @@ struct inode *exofs_iget(struct super_block *sb, unsigned long ino) | |||
| 914 | struct exofs_i_info *oi; | 910 | struct exofs_i_info *oi; |
| 915 | struct exofs_fcb fcb; | 911 | struct exofs_fcb fcb; |
| 916 | struct inode *inode; | 912 | struct inode *inode; |
| 917 | uint64_t uninitialized_var(sanity); | 913 | uint64_t obj_size; |
| 918 | int ret; | 914 | int ret; |
| 919 | 915 | ||
| 920 | inode = iget_locked(sb, ino); | 916 | inode = iget_locked(sb, ino); |
| @@ -923,13 +919,13 @@ struct inode *exofs_iget(struct super_block *sb, unsigned long ino) | |||
| 923 | if (!(inode->i_state & I_NEW)) | 919 | if (!(inode->i_state & I_NEW)) |
| 924 | return inode; | 920 | return inode; |
| 925 | oi = exofs_i(inode); | 921 | oi = exofs_i(inode); |
| 922 | __oi_init(oi); | ||
| 926 | 923 | ||
| 927 | /* read the inode from the osd */ | 924 | /* read the inode from the osd */ |
| 928 | ret = exofs_get_inode(sb, oi, &fcb, &sanity); | 925 | ret = exofs_get_inode(sb, oi, &fcb, &obj_size); |
| 929 | if (ret) | 926 | if (ret) |
| 930 | goto bad_inode; | 927 | goto bad_inode; |
| 931 | 928 | ||
| 932 | init_waitqueue_head(&oi->i_wq); | ||
| 933 | set_obj_created(oi); | 929 | set_obj_created(oi); |
| 934 | 930 | ||
| 935 | /* copy stuff from on-disk struct to in-memory struct */ | 931 | /* copy stuff from on-disk struct to in-memory struct */ |
| @@ -947,14 +943,12 @@ struct inode *exofs_iget(struct super_block *sb, unsigned long ino) | |||
| 947 | inode->i_blkbits = EXOFS_BLKSHIFT; | 943 | inode->i_blkbits = EXOFS_BLKSHIFT; |
| 948 | inode->i_generation = le32_to_cpu(fcb.i_generation); | 944 | inode->i_generation = le32_to_cpu(fcb.i_generation); |
| 949 | 945 | ||
| 950 | #ifdef EXOFS_DEBUG_OBJ_ISIZE | 946 | if ((inode->i_size != obj_size) && |
| 951 | if ((inode->i_size != sanity) && | ||
| 952 | (!exofs_inode_is_fast_symlink(inode))) { | 947 | (!exofs_inode_is_fast_symlink(inode))) { |
| 953 | EXOFS_ERR("WARNING: Size of object from inode and " | 948 | EXOFS_ERR("WARNING: Size of inode=%llu != object=%llu\n", |
| 954 | "attributes differ (%lld != %llu)\n", | 949 | inode->i_size, _LLU(obj_size)); |
| 955 | inode->i_size, _LLU(sanity)); | 950 | /* FIXME: call exofs_inode_recovery() */ |
| 956 | } | 951 | } |
| 957 | #endif | ||
| 958 | 952 | ||
| 959 | oi->i_dir_start_lookup = 0; | 953 | oi->i_dir_start_lookup = 0; |
| 960 | 954 | ||
| @@ -1020,23 +1014,30 @@ int __exofs_wait_obj_created(struct exofs_i_info *oi) | |||
| 1020 | * set the obj_created flag so that other methods know that the object exists on | 1014 | * set the obj_created flag so that other methods know that the object exists on |
| 1021 | * the OSD. | 1015 | * the OSD. |
| 1022 | */ | 1016 | */ |
| 1023 | static void create_done(struct osd_request *or, void *p) | 1017 | static void create_done(struct exofs_io_state *ios, void *p) |
| 1024 | { | 1018 | { |
| 1025 | struct inode *inode = p; | 1019 | struct inode *inode = p; |
| 1026 | struct exofs_i_info *oi = exofs_i(inode); | 1020 | struct exofs_i_info *oi = exofs_i(inode); |
| 1027 | struct exofs_sb_info *sbi = inode->i_sb->s_fs_info; | 1021 | struct exofs_sb_info *sbi = inode->i_sb->s_fs_info; |
| 1028 | int ret; | 1022 | int ret; |
| 1029 | 1023 | ||
| 1030 | ret = exofs_check_ok(or); | 1024 | ret = exofs_check_io(ios, NULL); |
| 1031 | osd_end_request(or); | 1025 | exofs_put_io_state(ios); |
| 1026 | |||
| 1032 | atomic_dec(&sbi->s_curr_pending); | 1027 | atomic_dec(&sbi->s_curr_pending); |
| 1033 | 1028 | ||
| 1034 | if (unlikely(ret)) { | 1029 | if (unlikely(ret)) { |
| 1035 | EXOFS_ERR("object=0x%llx creation faild in pid=0x%llx", | 1030 | EXOFS_ERR("object=0x%llx creation faild in pid=0x%llx", |
| 1036 | _LLU(sbi->s_pid), _LLU(inode->i_ino + EXOFS_OBJ_OFF)); | 1031 | _LLU(exofs_oi_objno(oi)), _LLU(sbi->s_pid)); |
| 1037 | make_bad_inode(inode); | 1032 | /*TODO: When FS is corrupted creation can fail, object already |
| 1038 | } else | 1033 | * exist. Get rid of this asynchronous creation, if exist |
| 1039 | set_obj_created(oi); | 1034 | * increment the obj counter and try the next object. Until we |
| 1035 | * succeed. All these dangling objects will be made into lost | ||
| 1036 | * files by chkfs.exofs | ||
| 1037 | */ | ||
| 1038 | } | ||
| 1039 | |||
| 1040 | set_obj_created(oi); | ||
| 1040 | 1041 | ||
| 1041 | atomic_dec(&inode->i_count); | 1042 | atomic_dec(&inode->i_count); |
| 1042 | wake_up(&oi->i_wq); | 1043 | wake_up(&oi->i_wq); |
| @@ -1051,8 +1052,7 @@ struct inode *exofs_new_inode(struct inode *dir, int mode) | |||
| 1051 | struct inode *inode; | 1052 | struct inode *inode; |
| 1052 | struct exofs_i_info *oi; | 1053 | struct exofs_i_info *oi; |
| 1053 | struct exofs_sb_info *sbi; | 1054 | struct exofs_sb_info *sbi; |
| 1054 | struct osd_request *or; | 1055 | struct exofs_io_state *ios; |
| 1055 | struct osd_obj_id obj; | ||
| 1056 | int ret; | 1056 | int ret; |
| 1057 | 1057 | ||
| 1058 | sb = dir->i_sb; | 1058 | sb = dir->i_sb; |
| @@ -1061,8 +1061,8 @@ struct inode *exofs_new_inode(struct inode *dir, int mode) | |||
| 1061 | return ERR_PTR(-ENOMEM); | 1061 | return ERR_PTR(-ENOMEM); |
| 1062 | 1062 | ||
| 1063 | oi = exofs_i(inode); | 1063 | oi = exofs_i(inode); |
| 1064 | __oi_init(oi); | ||
| 1064 | 1065 | ||
| 1065 | init_waitqueue_head(&oi->i_wq); | ||
| 1066 | set_obj_2bcreated(oi); | 1066 | set_obj_2bcreated(oi); |
| 1067 | 1067 | ||
| 1068 | sbi = sb->s_fs_info; | 1068 | sbi = sb->s_fs_info; |
| @@ -1089,28 +1089,28 @@ struct inode *exofs_new_inode(struct inode *dir, int mode) | |||
| 1089 | 1089 | ||
| 1090 | mark_inode_dirty(inode); | 1090 | mark_inode_dirty(inode); |
| 1091 | 1091 | ||
| 1092 | obj.partition = sbi->s_pid; | 1092 | ret = exofs_get_io_state(sbi, &ios); |
| 1093 | obj.id = inode->i_ino + EXOFS_OBJ_OFF; | 1093 | if (unlikely(ret)) { |
| 1094 | exofs_make_credential(oi->i_cred, &obj); | 1094 | EXOFS_ERR("exofs_new_inode: exofs_get_io_state failed\n"); |
| 1095 | 1095 | return ERR_PTR(ret); | |
| 1096 | or = osd_start_request(sbi->s_dev, GFP_KERNEL); | ||
| 1097 | if (unlikely(!or)) { | ||
| 1098 | EXOFS_ERR("exofs_new_inode: osd_start_request failed\n"); | ||
| 1099 | return ERR_PTR(-ENOMEM); | ||
| 1100 | } | 1096 | } |
| 1101 | 1097 | ||
| 1102 | osd_req_create_object(or, &obj); | 1098 | ios->obj.id = exofs_oi_objno(oi); |
| 1099 | exofs_make_credential(oi->i_cred, &ios->obj); | ||
| 1103 | 1100 | ||
| 1104 | /* increment the refcount so that the inode will still be around when we | 1101 | /* increment the refcount so that the inode will still be around when we |
| 1105 | * reach the callback | 1102 | * reach the callback |
| 1106 | */ | 1103 | */ |
| 1107 | atomic_inc(&inode->i_count); | 1104 | atomic_inc(&inode->i_count); |
| 1108 | 1105 | ||
| 1109 | ret = exofs_async_op(or, create_done, inode, oi->i_cred); | 1106 | ios->done = create_done; |
| 1107 | ios->private = inode; | ||
| 1108 | ios->cred = oi->i_cred; | ||
| 1109 | ret = exofs_sbi_create(ios); | ||
| 1110 | if (ret) { | 1110 | if (ret) { |
| 1111 | atomic_dec(&inode->i_count); | 1111 | atomic_dec(&inode->i_count); |
| 1112 | osd_end_request(or); | 1112 | exofs_put_io_state(ios); |
| 1113 | return ERR_PTR(-EIO); | 1113 | return ERR_PTR(ret); |
| 1114 | } | 1114 | } |
| 1115 | atomic_inc(&sbi->s_curr_pending); | 1115 | atomic_inc(&sbi->s_curr_pending); |
| 1116 | 1116 | ||
| @@ -1128,11 +1128,11 @@ struct updatei_args { | |||
| 1128 | /* | 1128 | /* |
| 1129 | * Callback function from exofs_update_inode(). | 1129 | * Callback function from exofs_update_inode(). |
| 1130 | */ | 1130 | */ |
| 1131 | static void updatei_done(struct osd_request *or, void *p) | 1131 | static void updatei_done(struct exofs_io_state *ios, void *p) |
| 1132 | { | 1132 | { |
| 1133 | struct updatei_args *args = p; | 1133 | struct updatei_args *args = p; |
| 1134 | 1134 | ||
| 1135 | osd_end_request(or); | 1135 | exofs_put_io_state(ios); |
| 1136 | 1136 | ||
| 1137 | atomic_dec(&args->sbi->s_curr_pending); | 1137 | atomic_dec(&args->sbi->s_curr_pending); |
| 1138 | 1138 | ||
| @@ -1148,8 +1148,7 @@ static int exofs_update_inode(struct inode *inode, int do_sync) | |||
| 1148 | struct exofs_i_info *oi = exofs_i(inode); | 1148 | struct exofs_i_info *oi = exofs_i(inode); |
| 1149 | struct super_block *sb = inode->i_sb; | 1149 | struct super_block *sb = inode->i_sb; |
| 1150 | struct exofs_sb_info *sbi = sb->s_fs_info; | 1150 | struct exofs_sb_info *sbi = sb->s_fs_info; |
| 1151 | struct osd_obj_id obj = {sbi->s_pid, inode->i_ino + EXOFS_OBJ_OFF}; | 1151 | struct exofs_io_state *ios; |
| 1152 | struct osd_request *or; | ||
| 1153 | struct osd_attr attr; | 1152 | struct osd_attr attr; |
| 1154 | struct exofs_fcb *fcb; | 1153 | struct exofs_fcb *fcb; |
| 1155 | struct updatei_args *args; | 1154 | struct updatei_args *args; |
| @@ -1186,18 +1185,16 @@ static int exofs_update_inode(struct inode *inode, int do_sync) | |||
| 1186 | } else | 1185 | } else |
| 1187 | memcpy(fcb->i_data, oi->i_data, sizeof(fcb->i_data)); | 1186 | memcpy(fcb->i_data, oi->i_data, sizeof(fcb->i_data)); |
| 1188 | 1187 | ||
| 1189 | or = osd_start_request(sbi->s_dev, GFP_KERNEL); | 1188 | ret = exofs_get_io_state(sbi, &ios); |
| 1190 | if (unlikely(!or)) { | 1189 | if (unlikely(ret)) { |
| 1191 | EXOFS_ERR("exofs_update_inode: osd_start_request failed.\n"); | 1190 | EXOFS_ERR("%s: exofs_get_io_state failed.\n", __func__); |
| 1192 | ret = -ENOMEM; | ||
| 1193 | goto free_args; | 1191 | goto free_args; |
| 1194 | } | 1192 | } |
| 1195 | 1193 | ||
| 1196 | osd_req_set_attributes(or, &obj); | ||
| 1197 | |||
| 1198 | attr = g_attr_inode_data; | 1194 | attr = g_attr_inode_data; |
| 1199 | attr.val_ptr = fcb; | 1195 | attr.val_ptr = fcb; |
| 1200 | osd_req_add_set_attr_list(or, &attr, 1); | 1196 | ios->out_attr_len = 1; |
| 1197 | ios->out_attr = &attr; | ||
| 1201 | 1198 | ||
| 1202 | if (!obj_created(oi)) { | 1199 | if (!obj_created(oi)) { |
| 1203 | EXOFS_DBGMSG("!obj_created\n"); | 1200 | EXOFS_DBGMSG("!obj_created\n"); |
| @@ -1206,22 +1203,19 @@ static int exofs_update_inode(struct inode *inode, int do_sync) | |||
| 1206 | EXOFS_DBGMSG("wait_event done\n"); | 1203 | EXOFS_DBGMSG("wait_event done\n"); |
| 1207 | } | 1204 | } |
| 1208 | 1205 | ||
| 1209 | if (do_sync) { | 1206 | if (!do_sync) { |
| 1210 | ret = exofs_sync_op(or, sbi->s_timeout, oi->i_cred); | ||
| 1211 | osd_end_request(or); | ||
| 1212 | goto free_args; | ||
| 1213 | } else { | ||
| 1214 | args->sbi = sbi; | 1207 | args->sbi = sbi; |
| 1208 | ios->done = updatei_done; | ||
| 1209 | ios->private = args; | ||
| 1210 | } | ||
| 1215 | 1211 | ||
| 1216 | ret = exofs_async_op(or, updatei_done, args, oi->i_cred); | 1212 | ret = exofs_oi_write(oi, ios); |
| 1217 | if (ret) { | 1213 | if (!do_sync && !ret) { |
| 1218 | osd_end_request(or); | ||
| 1219 | goto free_args; | ||
| 1220 | } | ||
| 1221 | atomic_inc(&sbi->s_curr_pending); | 1214 | atomic_inc(&sbi->s_curr_pending); |
| 1222 | goto out; /* deallocation in updatei_done */ | 1215 | goto out; /* deallocation in updatei_done */ |
| 1223 | } | 1216 | } |
| 1224 | 1217 | ||
| 1218 | exofs_put_io_state(ios); | ||
| 1225 | free_args: | 1219 | free_args: |
| 1226 | kfree(args); | 1220 | kfree(args); |
| 1227 | out: | 1221 | out: |
| @@ -1238,11 +1232,12 @@ int exofs_write_inode(struct inode *inode, int wait) | |||
| 1238 | * Callback function from exofs_delete_inode() - don't have much cleaning up to | 1232 | * Callback function from exofs_delete_inode() - don't have much cleaning up to |
| 1239 | * do. | 1233 | * do. |
| 1240 | */ | 1234 | */ |
| 1241 | static void delete_done(struct osd_request *or, void *p) | 1235 | static void delete_done(struct exofs_io_state *ios, void *p) |
| 1242 | { | 1236 | { |
| 1243 | struct exofs_sb_info *sbi; | 1237 | struct exofs_sb_info *sbi = p; |
| 1244 | osd_end_request(or); | 1238 | |
| 1245 | sbi = p; | 1239 | exofs_put_io_state(ios); |
| 1240 | |||
| 1246 | atomic_dec(&sbi->s_curr_pending); | 1241 | atomic_dec(&sbi->s_curr_pending); |
| 1247 | } | 1242 | } |
| 1248 | 1243 | ||
| @@ -1256,8 +1251,7 @@ void exofs_delete_inode(struct inode *inode) | |||
| 1256 | struct exofs_i_info *oi = exofs_i(inode); | 1251 | struct exofs_i_info *oi = exofs_i(inode); |
| 1257 | struct super_block *sb = inode->i_sb; | 1252 | struct super_block *sb = inode->i_sb; |
| 1258 | struct exofs_sb_info *sbi = sb->s_fs_info; | 1253 | struct exofs_sb_info *sbi = sb->s_fs_info; |
| 1259 | struct osd_obj_id obj = {sbi->s_pid, inode->i_ino + EXOFS_OBJ_OFF}; | 1254 | struct exofs_io_state *ios; |
| 1260 | struct osd_request *or; | ||
| 1261 | int ret; | 1255 | int ret; |
| 1262 | 1256 | ||
| 1263 | truncate_inode_pages(&inode->i_data, 0); | 1257 | truncate_inode_pages(&inode->i_data, 0); |
| @@ -1274,25 +1268,26 @@ void exofs_delete_inode(struct inode *inode) | |||
| 1274 | 1268 | ||
| 1275 | clear_inode(inode); | 1269 | clear_inode(inode); |
| 1276 | 1270 | ||
| 1277 | or = osd_start_request(sbi->s_dev, GFP_KERNEL); | 1271 | ret = exofs_get_io_state(sbi, &ios); |
| 1278 | if (unlikely(!or)) { | 1272 | if (unlikely(ret)) { |
| 1279 | EXOFS_ERR("exofs_delete_inode: osd_start_request failed\n"); | 1273 | EXOFS_ERR("%s: exofs_get_io_state failed\n", __func__); |
| 1280 | return; | 1274 | return; |
| 1281 | } | 1275 | } |
| 1282 | 1276 | ||
| 1283 | osd_req_remove_object(or, &obj); | ||
| 1284 | |||
| 1285 | /* if we are deleting an obj that hasn't been created yet, wait */ | 1277 | /* if we are deleting an obj that hasn't been created yet, wait */ |
| 1286 | if (!obj_created(oi)) { | 1278 | if (!obj_created(oi)) { |
| 1287 | BUG_ON(!obj_2bcreated(oi)); | 1279 | BUG_ON(!obj_2bcreated(oi)); |
| 1288 | wait_event(oi->i_wq, obj_created(oi)); | 1280 | wait_event(oi->i_wq, obj_created(oi)); |
| 1289 | } | 1281 | } |
| 1290 | 1282 | ||
| 1291 | ret = exofs_async_op(or, delete_done, sbi, oi->i_cred); | 1283 | ios->obj.id = exofs_oi_objno(oi); |
| 1284 | ios->done = delete_done; | ||
| 1285 | ios->private = sbi; | ||
| 1286 | ios->cred = oi->i_cred; | ||
| 1287 | ret = exofs_sbi_remove(ios); | ||
| 1292 | if (ret) { | 1288 | if (ret) { |
| 1293 | EXOFS_ERR( | 1289 | EXOFS_ERR("%s: exofs_sbi_remove failed\n", __func__); |
| 1294 | "ERROR: @exofs_delete_inode exofs_async_op failed\n"); | 1290 | exofs_put_io_state(ios); |
| 1295 | osd_end_request(or); | ||
| 1296 | return; | 1291 | return; |
| 1297 | } | 1292 | } |
| 1298 | atomic_inc(&sbi->s_curr_pending); | 1293 | atomic_inc(&sbi->s_curr_pending); |
