diff options
Diffstat (limited to 'fs/aio.c')
-rw-r--r-- | fs/aio.c | 98 |
1 files changed, 45 insertions, 53 deletions
@@ -741,19 +741,9 @@ static ssize_t aio_run_iocb(struct kiocb *iocb) | |||
741 | ret = retry(iocb); | 741 | ret = retry(iocb); |
742 | current->io_wait = NULL; | 742 | current->io_wait = NULL; |
743 | 743 | ||
744 | if (-EIOCBRETRY != ret) { | 744 | if (ret != -EIOCBRETRY && ret != -EIOCBQUEUED) { |
745 | if (-EIOCBQUEUED != ret) { | 745 | BUG_ON(!list_empty(&iocb->ki_wait.task_list)); |
746 | BUG_ON(!list_empty(&iocb->ki_wait.task_list)); | 746 | 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 | } | 747 | } |
758 | out: | 748 | out: |
759 | spin_lock_irq(&ctx->ctx_lock); | 749 | spin_lock_irq(&ctx->ctx_lock); |
@@ -899,16 +889,24 @@ static void aio_kick_handler(void *data) | |||
899 | * and if required activate the aio work queue to process | 889 | * and if required activate the aio work queue to process |
900 | * it | 890 | * it |
901 | */ | 891 | */ |
902 | static void queue_kicked_iocb(struct kiocb *iocb) | 892 | static void try_queue_kicked_iocb(struct kiocb *iocb) |
903 | { | 893 | { |
904 | struct kioctx *ctx = iocb->ki_ctx; | 894 | struct kioctx *ctx = iocb->ki_ctx; |
905 | unsigned long flags; | 895 | unsigned long flags; |
906 | int run = 0; | 896 | int run = 0; |
907 | 897 | ||
908 | WARN_ON((!list_empty(&iocb->ki_wait.task_list))); | 898 | /* We're supposed to be the only path putting the iocb back on the run |
899 | * list. If we find that the iocb is *back* on a wait queue already | ||
900 | * than retry has happened before we could queue the iocb. This also | ||
901 | * means that the retry could have completed and freed our iocb, no | ||
902 | * good. */ | ||
903 | BUG_ON((!list_empty(&iocb->ki_wait.task_list))); | ||
909 | 904 | ||
910 | spin_lock_irqsave(&ctx->ctx_lock, flags); | 905 | spin_lock_irqsave(&ctx->ctx_lock, flags); |
911 | run = __queue_kicked_iocb(iocb); | 906 | /* set this inside the lock so that we can't race with aio_run_iocb() |
907 | * testing it and putting the iocb on the run list under the lock */ | ||
908 | if (!kiocbTryKick(iocb)) | ||
909 | run = __queue_kicked_iocb(iocb); | ||
912 | spin_unlock_irqrestore(&ctx->ctx_lock, flags); | 910 | spin_unlock_irqrestore(&ctx->ctx_lock, flags); |
913 | if (run) | 911 | if (run) |
914 | aio_queue_work(ctx); | 912 | aio_queue_work(ctx); |
@@ -931,10 +929,7 @@ void fastcall kick_iocb(struct kiocb *iocb) | |||
931 | return; | 929 | return; |
932 | } | 930 | } |
933 | 931 | ||
934 | /* If its already kicked we shouldn't queue it again */ | 932 | try_queue_kicked_iocb(iocb); |
935 | if (!kiocbTryKick(iocb)) { | ||
936 | queue_kicked_iocb(iocb); | ||
937 | } | ||
938 | } | 933 | } |
939 | EXPORT_SYMBOL(kick_iocb); | 934 | EXPORT_SYMBOL(kick_iocb); |
940 | 935 | ||
@@ -1322,8 +1317,11 @@ asmlinkage long sys_io_destroy(aio_context_t ctx) | |||
1322 | } | 1317 | } |
1323 | 1318 | ||
1324 | /* | 1319 | /* |
1325 | * Default retry method for aio_read (also used for first time submit) | 1320 | * aio_p{read,write} are the default ki_retry methods for |
1326 | * Responsible for updating iocb state as retries progress | 1321 | * IO_CMD_P{READ,WRITE}. They maintains kiocb retry state around potentially |
1322 | * multiple calls to f_op->aio_read(). They loop around partial progress | ||
1323 | * instead of returning -EIOCBRETRY because they don't have the means to call | ||
1324 | * kick_iocb(). | ||
1327 | */ | 1325 | */ |
1328 | static ssize_t aio_pread(struct kiocb *iocb) | 1326 | static ssize_t aio_pread(struct kiocb *iocb) |
1329 | { | 1327 | { |
@@ -1332,25 +1330,25 @@ static ssize_t aio_pread(struct kiocb *iocb) | |||
1332 | struct inode *inode = mapping->host; | 1330 | struct inode *inode = mapping->host; |
1333 | ssize_t ret = 0; | 1331 | ssize_t ret = 0; |
1334 | 1332 | ||
1335 | ret = file->f_op->aio_read(iocb, iocb->ki_buf, | 1333 | do { |
1336 | iocb->ki_left, iocb->ki_pos); | 1334 | ret = file->f_op->aio_read(iocb, iocb->ki_buf, |
1335 | iocb->ki_left, iocb->ki_pos); | ||
1336 | /* | ||
1337 | * Can't just depend on iocb->ki_left to determine | ||
1338 | * whether we are done. This may have been a short read. | ||
1339 | */ | ||
1340 | if (ret > 0) { | ||
1341 | iocb->ki_buf += ret; | ||
1342 | iocb->ki_left -= ret; | ||
1343 | } | ||
1337 | 1344 | ||
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 | /* | 1345 | /* |
1346 | * For pipes and sockets we return once we have | 1346 | * For pipes and sockets we return once we have some data; for |
1347 | * some data; for regular files we retry till we | 1347 | * regular files we retry till we complete the entire read or |
1348 | * complete the entire read or find that we can't | 1348 | * find that we can't read any more data (e.g short reads). |
1349 | * read any more data (e.g short reads). | ||
1350 | */ | 1349 | */ |
1351 | if (!S_ISFIFO(inode->i_mode) && !S_ISSOCK(inode->i_mode)) | 1350 | } while (ret > 0 && iocb->ki_left > 0 && |
1352 | ret = -EIOCBRETRY; | 1351 | !S_ISFIFO(inode->i_mode) && !S_ISSOCK(inode->i_mode)); |
1353 | } | ||
1354 | 1352 | ||
1355 | /* This means we must have transferred all that we could */ | 1353 | /* This means we must have transferred all that we could */ |
1356 | /* No need to retry anymore */ | 1354 | /* No need to retry anymore */ |
@@ -1360,27 +1358,21 @@ static ssize_t aio_pread(struct kiocb *iocb) | |||
1360 | return ret; | 1358 | return ret; |
1361 | } | 1359 | } |
1362 | 1360 | ||
1363 | /* | 1361 | /* 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) | 1362 | static ssize_t aio_pwrite(struct kiocb *iocb) |
1368 | { | 1363 | { |
1369 | struct file *file = iocb->ki_filp; | 1364 | struct file *file = iocb->ki_filp; |
1370 | ssize_t ret = 0; | 1365 | ssize_t ret = 0; |
1371 | 1366 | ||
1372 | ret = file->f_op->aio_write(iocb, iocb->ki_buf, | 1367 | do { |
1373 | iocb->ki_left, iocb->ki_pos); | 1368 | ret = file->f_op->aio_write(iocb, iocb->ki_buf, |
1374 | 1369 | iocb->ki_left, iocb->ki_pos); | |
1375 | if (ret > 0) { | 1370 | if (ret > 0) { |
1376 | iocb->ki_buf += ret; | 1371 | iocb->ki_buf += ret; |
1377 | iocb->ki_left -= ret; | 1372 | iocb->ki_left -= ret; |
1378 | 1373 | } | |
1379 | ret = -EIOCBRETRY; | 1374 | } while (ret > 0 && iocb->ki_left > 0); |
1380 | } | ||
1381 | 1375 | ||
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)) | 1376 | if ((ret == 0) || (iocb->ki_left == 0)) |
1385 | ret = iocb->ki_nbytes - iocb->ki_left; | 1377 | ret = iocb->ki_nbytes - iocb->ki_left; |
1386 | 1378 | ||