diff options
Diffstat (limited to 'fs/aio.c')
-rw-r--r-- | fs/aio.c | 123 |
1 files changed, 46 insertions, 77 deletions
@@ -398,7 +398,7 @@ static struct kiocb fastcall *__aio_get_req(struct kioctx *ctx) | |||
398 | if (unlikely(!req)) | 398 | if (unlikely(!req)) |
399 | return NULL; | 399 | return NULL; |
400 | 400 | ||
401 | req->ki_flags = 1 << KIF_LOCKED; | 401 | req->ki_flags = 0; |
402 | req->ki_users = 2; | 402 | req->ki_users = 2; |
403 | req->ki_key = 0; | 403 | req->ki_key = 0; |
404 | req->ki_ctx = ctx; | 404 | req->ki_ctx = ctx; |
@@ -547,24 +547,6 @@ struct kioctx *lookup_ioctx(unsigned long ctx_id) | |||
547 | return ioctx; | 547 | return ioctx; |
548 | } | 548 | } |
549 | 549 | ||
550 | static int lock_kiocb_action(void *param) | ||
551 | { | ||
552 | schedule(); | ||
553 | return 0; | ||
554 | } | ||
555 | |||
556 | static inline void lock_kiocb(struct kiocb *iocb) | ||
557 | { | ||
558 | wait_on_bit_lock(&iocb->ki_flags, KIF_LOCKED, lock_kiocb_action, | ||
559 | TASK_UNINTERRUPTIBLE); | ||
560 | } | ||
561 | |||
562 | static inline void unlock_kiocb(struct kiocb *iocb) | ||
563 | { | ||
564 | kiocbClearLocked(iocb); | ||
565 | wake_up_bit(&iocb->ki_flags, KIF_LOCKED); | ||
566 | } | ||
567 | |||
568 | /* | 550 | /* |
569 | * use_mm | 551 | * use_mm |
570 | * Makes the calling kernel thread take on the specified | 552 | * Makes the calling kernel thread take on the specified |
@@ -740,19 +722,9 @@ static ssize_t aio_run_iocb(struct kiocb *iocb) | |||
740 | ret = retry(iocb); | 722 | ret = retry(iocb); |
741 | current->io_wait = NULL; | 723 | current->io_wait = NULL; |
742 | 724 | ||
743 | if (-EIOCBRETRY != ret) { | 725 | if (ret != -EIOCBRETRY && ret != -EIOCBQUEUED) { |
744 | if (-EIOCBQUEUED != ret) { | 726 | BUG_ON(!list_empty(&iocb->ki_wait.task_list)); |
745 | BUG_ON(!list_empty(&iocb->ki_wait.task_list)); | 727 | aio_complete(iocb, ret, 0); |
746 | aio_complete(iocb, ret, 0); | ||
747 | /* must not access the iocb after this */ | ||
748 | } | ||
749 | } else { | ||
750 | /* | ||
751 | * Issue an additional retry to avoid waiting forever if | ||
752 | * no waits were queued (e.g. in case of a short read). | ||
753 | */ | ||
754 | if (list_empty(&iocb->ki_wait.task_list)) | ||
755 | kiocbSetKicked(iocb); | ||
756 | } | 728 | } |
757 | out: | 729 | out: |
758 | spin_lock_irq(&ctx->ctx_lock); | 730 | spin_lock_irq(&ctx->ctx_lock); |
@@ -805,9 +777,7 @@ static int __aio_run_iocbs(struct kioctx *ctx) | |||
805 | * Hold an extra reference while retrying i/o. | 777 | * Hold an extra reference while retrying i/o. |
806 | */ | 778 | */ |
807 | iocb->ki_users++; /* grab extra reference */ | 779 | iocb->ki_users++; /* grab extra reference */ |
808 | lock_kiocb(iocb); | ||
809 | aio_run_iocb(iocb); | 780 | aio_run_iocb(iocb); |
810 | unlock_kiocb(iocb); | ||
811 | if (__aio_put_req(ctx, iocb)) /* drop extra ref */ | 781 | if (__aio_put_req(ctx, iocb)) /* drop extra ref */ |
812 | put_ioctx(ctx); | 782 | put_ioctx(ctx); |
813 | } | 783 | } |
@@ -898,16 +868,24 @@ static void aio_kick_handler(void *data) | |||
898 | * and if required activate the aio work queue to process | 868 | * and if required activate the aio work queue to process |
899 | * it | 869 | * it |
900 | */ | 870 | */ |
901 | static void queue_kicked_iocb(struct kiocb *iocb) | 871 | static void try_queue_kicked_iocb(struct kiocb *iocb) |
902 | { | 872 | { |
903 | struct kioctx *ctx = iocb->ki_ctx; | 873 | struct kioctx *ctx = iocb->ki_ctx; |
904 | unsigned long flags; | 874 | unsigned long flags; |
905 | int run = 0; | 875 | int run = 0; |
906 | 876 | ||
907 | WARN_ON((!list_empty(&iocb->ki_wait.task_list))); | 877 | /* We're supposed to be the only path putting the iocb back on the run |
878 | * list. If we find that the iocb is *back* on a wait queue already | ||
879 | * than retry has happened before we could queue the iocb. This also | ||
880 | * means that the retry could have completed and freed our iocb, no | ||
881 | * good. */ | ||
882 | BUG_ON((!list_empty(&iocb->ki_wait.task_list))); | ||
908 | 883 | ||
909 | spin_lock_irqsave(&ctx->ctx_lock, flags); | 884 | spin_lock_irqsave(&ctx->ctx_lock, flags); |
910 | run = __queue_kicked_iocb(iocb); | 885 | /* set this inside the lock so that we can't race with aio_run_iocb() |
886 | * testing it and putting the iocb on the run list under the lock */ | ||
887 | if (!kiocbTryKick(iocb)) | ||
888 | run = __queue_kicked_iocb(iocb); | ||
911 | spin_unlock_irqrestore(&ctx->ctx_lock, flags); | 889 | spin_unlock_irqrestore(&ctx->ctx_lock, flags); |
912 | if (run) | 890 | if (run) |
913 | aio_queue_work(ctx); | 891 | aio_queue_work(ctx); |
@@ -930,10 +908,7 @@ void fastcall kick_iocb(struct kiocb *iocb) | |||
930 | return; | 908 | return; |
931 | } | 909 | } |
932 | 910 | ||
933 | /* If its already kicked we shouldn't queue it again */ | 911 | try_queue_kicked_iocb(iocb); |
934 | if (!kiocbTryKick(iocb)) { | ||
935 | queue_kicked_iocb(iocb); | ||
936 | } | ||
937 | } | 912 | } |
938 | EXPORT_SYMBOL(kick_iocb); | 913 | EXPORT_SYMBOL(kick_iocb); |
939 | 914 | ||
@@ -1321,8 +1296,11 @@ asmlinkage long sys_io_destroy(aio_context_t ctx) | |||
1321 | } | 1296 | } |
1322 | 1297 | ||
1323 | /* | 1298 | /* |
1324 | * Default retry method for aio_read (also used for first time submit) | 1299 | * aio_p{read,write} are the default ki_retry methods for |
1325 | * Responsible for updating iocb state as retries progress | 1300 | * IO_CMD_P{READ,WRITE}. They maintains kiocb retry state around potentially |
1301 | * multiple calls to f_op->aio_read(). They loop around partial progress | ||
1302 | * instead of returning -EIOCBRETRY because they don't have the means to call | ||
1303 | * kick_iocb(). | ||
1326 | */ | 1304 | */ |
1327 | static ssize_t aio_pread(struct kiocb *iocb) | 1305 | static ssize_t aio_pread(struct kiocb *iocb) |
1328 | { | 1306 | { |
@@ -1331,25 +1309,25 @@ static ssize_t aio_pread(struct kiocb *iocb) | |||
1331 | struct inode *inode = mapping->host; | 1309 | struct inode *inode = mapping->host; |
1332 | ssize_t ret = 0; | 1310 | ssize_t ret = 0; |
1333 | 1311 | ||
1334 | ret = file->f_op->aio_read(iocb, iocb->ki_buf, | 1312 | do { |
1335 | iocb->ki_left, iocb->ki_pos); | 1313 | ret = file->f_op->aio_read(iocb, iocb->ki_buf, |
1314 | iocb->ki_left, iocb->ki_pos); | ||
1315 | /* | ||
1316 | * Can't just depend on iocb->ki_left to determine | ||
1317 | * whether we are done. This may have been a short read. | ||
1318 | */ | ||
1319 | if (ret > 0) { | ||
1320 | iocb->ki_buf += ret; | ||
1321 | iocb->ki_left -= ret; | ||
1322 | } | ||
1336 | 1323 | ||
1337 | /* | ||
1338 | * Can't just depend on iocb->ki_left to determine | ||
1339 | * whether we are done. This may have been a short read. | ||
1340 | */ | ||
1341 | if (ret > 0) { | ||
1342 | iocb->ki_buf += ret; | ||
1343 | iocb->ki_left -= ret; | ||
1344 | /* | 1324 | /* |
1345 | * For pipes and sockets we return once we have | 1325 | * For pipes and sockets we return once we have some data; for |
1346 | * some data; for regular files we retry till we | 1326 | * regular files we retry till we complete the entire read or |
1347 | * complete the entire read or find that we can't | 1327 | * find that we can't read any more data (e.g short reads). |
1348 | * read any more data (e.g short reads). | ||
1349 | */ | 1328 | */ |
1350 | if (!S_ISFIFO(inode->i_mode) && !S_ISSOCK(inode->i_mode)) | 1329 | } while (ret > 0 && iocb->ki_left > 0 && |
1351 | ret = -EIOCBRETRY; | 1330 | !S_ISFIFO(inode->i_mode) && !S_ISSOCK(inode->i_mode)); |
1352 | } | ||
1353 | 1331 | ||
1354 | /* This means we must have transferred all that we could */ | 1332 | /* This means we must have transferred all that we could */ |
1355 | /* No need to retry anymore */ | 1333 | /* No need to retry anymore */ |
@@ -1359,27 +1337,21 @@ static ssize_t aio_pread(struct kiocb *iocb) | |||
1359 | return ret; | 1337 | return ret; |
1360 | } | 1338 | } |
1361 | 1339 | ||
1362 | /* | 1340 | /* see aio_pread() */ |
1363 | * Default retry method for aio_write (also used for first time submit) | ||
1364 | * Responsible for updating iocb state as retries progress | ||
1365 | */ | ||
1366 | static ssize_t aio_pwrite(struct kiocb *iocb) | 1341 | static ssize_t aio_pwrite(struct kiocb *iocb) |
1367 | { | 1342 | { |
1368 | struct file *file = iocb->ki_filp; | 1343 | struct file *file = iocb->ki_filp; |
1369 | ssize_t ret = 0; | 1344 | ssize_t ret = 0; |
1370 | 1345 | ||
1371 | ret = file->f_op->aio_write(iocb, iocb->ki_buf, | 1346 | do { |
1372 | iocb->ki_left, iocb->ki_pos); | 1347 | ret = file->f_op->aio_write(iocb, iocb->ki_buf, |
1373 | 1348 | iocb->ki_left, iocb->ki_pos); | |
1374 | if (ret > 0) { | 1349 | if (ret > 0) { |
1375 | iocb->ki_buf += ret; | 1350 | iocb->ki_buf += ret; |
1376 | iocb->ki_left -= ret; | 1351 | iocb->ki_left -= ret; |
1377 | 1352 | } | |
1378 | ret = -EIOCBRETRY; | 1353 | } while (ret > 0 && iocb->ki_left > 0); |
1379 | } | ||
1380 | 1354 | ||
1381 | /* This means we must have transferred all that we could */ | ||
1382 | /* No need to retry anymore */ | ||
1383 | if ((ret == 0) || (iocb->ki_left == 0)) | 1355 | if ((ret == 0) || (iocb->ki_left == 0)) |
1384 | ret = iocb->ki_nbytes - iocb->ki_left; | 1356 | ret = iocb->ki_nbytes - iocb->ki_left; |
1385 | 1357 | ||
@@ -1549,7 +1521,6 @@ int fastcall io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb, | |||
1549 | 1521 | ||
1550 | spin_lock_irq(&ctx->ctx_lock); | 1522 | spin_lock_irq(&ctx->ctx_lock); |
1551 | aio_run_iocb(req); | 1523 | aio_run_iocb(req); |
1552 | unlock_kiocb(req); | ||
1553 | if (!list_empty(&ctx->run_list)) { | 1524 | if (!list_empty(&ctx->run_list)) { |
1554 | /* drain the run list */ | 1525 | /* drain the run list */ |
1555 | while (__aio_run_iocbs(ctx)) | 1526 | while (__aio_run_iocbs(ctx)) |
@@ -1681,7 +1652,6 @@ asmlinkage long sys_io_cancel(aio_context_t ctx_id, struct iocb __user *iocb, | |||
1681 | if (NULL != cancel) { | 1652 | if (NULL != cancel) { |
1682 | struct io_event tmp; | 1653 | struct io_event tmp; |
1683 | pr_debug("calling cancel\n"); | 1654 | pr_debug("calling cancel\n"); |
1684 | lock_kiocb(kiocb); | ||
1685 | memset(&tmp, 0, sizeof(tmp)); | 1655 | memset(&tmp, 0, sizeof(tmp)); |
1686 | tmp.obj = (u64)(unsigned long)kiocb->ki_obj.user; | 1656 | tmp.obj = (u64)(unsigned long)kiocb->ki_obj.user; |
1687 | tmp.data = kiocb->ki_user_data; | 1657 | tmp.data = kiocb->ki_user_data; |
@@ -1693,7 +1663,6 @@ asmlinkage long sys_io_cancel(aio_context_t ctx_id, struct iocb __user *iocb, | |||
1693 | if (copy_to_user(result, &tmp, sizeof(tmp))) | 1663 | if (copy_to_user(result, &tmp, sizeof(tmp))) |
1694 | ret = -EFAULT; | 1664 | ret = -EFAULT; |
1695 | } | 1665 | } |
1696 | unlock_kiocb(kiocb); | ||
1697 | } else | 1666 | } else |
1698 | ret = -EINVAL; | 1667 | ret = -EINVAL; |
1699 | 1668 | ||