diff options
Diffstat (limited to 'fs/aio.c')
-rw-r--r-- | fs/aio.c | 124 |
1 files changed, 46 insertions, 78 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,25 +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 | smp_mb__after_clear_bit(); | ||
566 | wake_up_bit(&iocb->ki_flags, KIF_LOCKED); | ||
567 | } | ||
568 | |||
569 | /* | 550 | /* |
570 | * use_mm | 551 | * use_mm |
571 | * Makes the calling kernel thread take on the specified | 552 | * Makes the calling kernel thread take on the specified |
@@ -741,19 +722,9 @@ static ssize_t aio_run_iocb(struct kiocb *iocb) | |||
741 | ret = retry(iocb); | 722 | ret = retry(iocb); |
742 | current->io_wait = NULL; | 723 | current->io_wait = NULL; |
743 | 724 | ||
744 | if (-EIOCBRETRY != ret) { | 725 | if (ret != -EIOCBRETRY && ret != -EIOCBQUEUED) { |
745 | if (-EIOCBQUEUED != ret) { | 726 | BUG_ON(!list_empty(&iocb->ki_wait.task_list)); |
746 | BUG_ON(!list_empty(&iocb->ki_wait.task_list)); | 727 | aio_complete(iocb, ret, 0); |
747 | aio_complete(iocb, ret, 0); | ||
748 | /* must not access the iocb after this */ | ||
749 | } | ||
750 | } else { | ||
751 | /* | ||
752 | * Issue an additional retry to avoid waiting forever if | ||
753 | * no waits were queued (e.g. in case of a short read). | ||
754 | */ | ||
755 | if (list_empty(&iocb->ki_wait.task_list)) | ||
756 | kiocbSetKicked(iocb); | ||
757 | } | 728 | } |
758 | out: | 729 | out: |
759 | spin_lock_irq(&ctx->ctx_lock); | 730 | spin_lock_irq(&ctx->ctx_lock); |
@@ -806,9 +777,7 @@ static int __aio_run_iocbs(struct kioctx *ctx) | |||
806 | * Hold an extra reference while retrying i/o. | 777 | * Hold an extra reference while retrying i/o. |
807 | */ | 778 | */ |
808 | iocb->ki_users++; /* grab extra reference */ | 779 | iocb->ki_users++; /* grab extra reference */ |
809 | lock_kiocb(iocb); | ||
810 | aio_run_iocb(iocb); | 780 | aio_run_iocb(iocb); |
811 | unlock_kiocb(iocb); | ||
812 | if (__aio_put_req(ctx, iocb)) /* drop extra ref */ | 781 | if (__aio_put_req(ctx, iocb)) /* drop extra ref */ |
813 | put_ioctx(ctx); | 782 | put_ioctx(ctx); |
814 | } | 783 | } |
@@ -899,16 +868,24 @@ static void aio_kick_handler(void *data) | |||
899 | * and if required activate the aio work queue to process | 868 | * and if required activate the aio work queue to process |
900 | * it | 869 | * it |
901 | */ | 870 | */ |
902 | static void queue_kicked_iocb(struct kiocb *iocb) | 871 | static void try_queue_kicked_iocb(struct kiocb *iocb) |
903 | { | 872 | { |
904 | struct kioctx *ctx = iocb->ki_ctx; | 873 | struct kioctx *ctx = iocb->ki_ctx; |
905 | unsigned long flags; | 874 | unsigned long flags; |
906 | int run = 0; | 875 | int run = 0; |
907 | 876 | ||
908 | 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))); | ||
909 | 883 | ||
910 | spin_lock_irqsave(&ctx->ctx_lock, flags); | 884 | spin_lock_irqsave(&ctx->ctx_lock, flags); |
911 | 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); | ||
912 | spin_unlock_irqrestore(&ctx->ctx_lock, flags); | 889 | spin_unlock_irqrestore(&ctx->ctx_lock, flags); |
913 | if (run) | 890 | if (run) |
914 | aio_queue_work(ctx); | 891 | aio_queue_work(ctx); |
@@ -931,10 +908,7 @@ void fastcall kick_iocb(struct kiocb *iocb) | |||
931 | return; | 908 | return; |
932 | } | 909 | } |
933 | 910 | ||
934 | /* If its already kicked we shouldn't queue it again */ | 911 | try_queue_kicked_iocb(iocb); |
935 | if (!kiocbTryKick(iocb)) { | ||
936 | queue_kicked_iocb(iocb); | ||
937 | } | ||
938 | } | 912 | } |
939 | EXPORT_SYMBOL(kick_iocb); | 913 | EXPORT_SYMBOL(kick_iocb); |
940 | 914 | ||
@@ -1322,8 +1296,11 @@ asmlinkage long sys_io_destroy(aio_context_t ctx) | |||
1322 | } | 1296 | } |
1323 | 1297 | ||
1324 | /* | 1298 | /* |
1325 | * Default retry method for aio_read (also used for first time submit) | 1299 | * aio_p{read,write} are the default ki_retry methods for |
1326 | * 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(). | ||
1327 | */ | 1304 | */ |
1328 | static ssize_t aio_pread(struct kiocb *iocb) | 1305 | static ssize_t aio_pread(struct kiocb *iocb) |
1329 | { | 1306 | { |
@@ -1332,25 +1309,25 @@ static ssize_t aio_pread(struct kiocb *iocb) | |||
1332 | struct inode *inode = mapping->host; | 1309 | struct inode *inode = mapping->host; |
1333 | ssize_t ret = 0; | 1310 | ssize_t ret = 0; |
1334 | 1311 | ||
1335 | ret = file->f_op->aio_read(iocb, iocb->ki_buf, | 1312 | do { |
1336 | 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 | } | ||
1337 | 1323 | ||
1338 | /* | ||
1339 | * Can't just depend on iocb->ki_left to determine | ||
1340 | * whether we are done. This may have been a short read. | ||
1341 | */ | ||
1342 | if (ret > 0) { | ||
1343 | iocb->ki_buf += ret; | ||
1344 | iocb->ki_left -= ret; | ||
1345 | /* | 1324 | /* |
1346 | * For pipes and sockets we return once we have | 1325 | * For pipes and sockets we return once we have some data; for |
1347 | * some data; for regular files we retry till we | 1326 | * regular files we retry till we complete the entire read or |
1348 | * complete the entire read or find that we can't | 1327 | * find that we can't read any more data (e.g short reads). |
1349 | * read any more data (e.g short reads). | ||
1350 | */ | 1328 | */ |
1351 | if (!S_ISFIFO(inode->i_mode) && !S_ISSOCK(inode->i_mode)) | 1329 | } while (ret > 0 && iocb->ki_left > 0 && |
1352 | ret = -EIOCBRETRY; | 1330 | !S_ISFIFO(inode->i_mode) && !S_ISSOCK(inode->i_mode)); |
1353 | } | ||
1354 | 1331 | ||
1355 | /* This means we must have transferred all that we could */ | 1332 | /* This means we must have transferred all that we could */ |
1356 | /* No need to retry anymore */ | 1333 | /* No need to retry anymore */ |
@@ -1360,27 +1337,21 @@ static ssize_t aio_pread(struct kiocb *iocb) | |||
1360 | return ret; | 1337 | return ret; |
1361 | } | 1338 | } |
1362 | 1339 | ||
1363 | /* | 1340 | /* see aio_pread() */ |
1364 | * Default retry method for aio_write (also used for first time submit) | ||
1365 | * Responsible for updating iocb state as retries progress | ||
1366 | */ | ||
1367 | static ssize_t aio_pwrite(struct kiocb *iocb) | 1341 | static ssize_t aio_pwrite(struct kiocb *iocb) |
1368 | { | 1342 | { |
1369 | struct file *file = iocb->ki_filp; | 1343 | struct file *file = iocb->ki_filp; |
1370 | ssize_t ret = 0; | 1344 | ssize_t ret = 0; |
1371 | 1345 | ||
1372 | ret = file->f_op->aio_write(iocb, iocb->ki_buf, | 1346 | do { |
1373 | iocb->ki_left, iocb->ki_pos); | 1347 | ret = file->f_op->aio_write(iocb, iocb->ki_buf, |
1374 | 1348 | iocb->ki_left, iocb->ki_pos); | |
1375 | if (ret > 0) { | 1349 | if (ret > 0) { |
1376 | iocb->ki_buf += ret; | 1350 | iocb->ki_buf += ret; |
1377 | iocb->ki_left -= ret; | 1351 | iocb->ki_left -= ret; |
1378 | 1352 | } | |
1379 | ret = -EIOCBRETRY; | 1353 | } while (ret > 0 && iocb->ki_left > 0); |
1380 | } | ||
1381 | 1354 | ||
1382 | /* This means we must have transferred all that we could */ | ||
1383 | /* No need to retry anymore */ | ||
1384 | if ((ret == 0) || (iocb->ki_left == 0)) | 1355 | if ((ret == 0) || (iocb->ki_left == 0)) |
1385 | ret = iocb->ki_nbytes - iocb->ki_left; | 1356 | ret = iocb->ki_nbytes - iocb->ki_left; |
1386 | 1357 | ||
@@ -1550,7 +1521,6 @@ int fastcall io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb, | |||
1550 | 1521 | ||
1551 | spin_lock_irq(&ctx->ctx_lock); | 1522 | spin_lock_irq(&ctx->ctx_lock); |
1552 | aio_run_iocb(req); | 1523 | aio_run_iocb(req); |
1553 | unlock_kiocb(req); | ||
1554 | if (!list_empty(&ctx->run_list)) { | 1524 | if (!list_empty(&ctx->run_list)) { |
1555 | /* drain the run list */ | 1525 | /* drain the run list */ |
1556 | while (__aio_run_iocbs(ctx)) | 1526 | while (__aio_run_iocbs(ctx)) |
@@ -1682,7 +1652,6 @@ asmlinkage long sys_io_cancel(aio_context_t ctx_id, struct iocb __user *iocb, | |||
1682 | if (NULL != cancel) { | 1652 | if (NULL != cancel) { |
1683 | struct io_event tmp; | 1653 | struct io_event tmp; |
1684 | pr_debug("calling cancel\n"); | 1654 | pr_debug("calling cancel\n"); |
1685 | lock_kiocb(kiocb); | ||
1686 | memset(&tmp, 0, sizeof(tmp)); | 1655 | memset(&tmp, 0, sizeof(tmp)); |
1687 | tmp.obj = (u64)(unsigned long)kiocb->ki_obj.user; | 1656 | tmp.obj = (u64)(unsigned long)kiocb->ki_obj.user; |
1688 | tmp.data = kiocb->ki_user_data; | 1657 | tmp.data = kiocb->ki_user_data; |
@@ -1694,7 +1663,6 @@ asmlinkage long sys_io_cancel(aio_context_t ctx_id, struct iocb __user *iocb, | |||
1694 | if (copy_to_user(result, &tmp, sizeof(tmp))) | 1663 | if (copy_to_user(result, &tmp, sizeof(tmp))) |
1695 | ret = -EFAULT; | 1664 | ret = -EFAULT; |
1696 | } | 1665 | } |
1697 | unlock_kiocb(kiocb); | ||
1698 | } else | 1666 | } else |
1699 | ret = -EINVAL; | 1667 | ret = -EINVAL; |
1700 | 1668 | ||