@@ -1458,22 +1458,20 @@ _xfs_buf_ioapply(
1458
1458
* a call to this function unless the caller holds an additional reference
1459
1459
* itself.
1460
1460
*/
1461
- void
1462
- xfs_buf_submit (
1461
+ static int
1462
+ __xfs_buf_submit (
1463
1463
struct xfs_buf * bp )
1464
1464
{
1465
1465
trace_xfs_buf_submit (bp , _RET_IP_ );
1466
1466
1467
1467
ASSERT (!(bp -> b_flags & _XBF_DELWRI_Q ));
1468
- ASSERT (bp -> b_flags & XBF_ASYNC );
1469
1468
1470
1469
/* on shutdown we stale and complete the buffer immediately */
1471
1470
if (XFS_FORCED_SHUTDOWN (bp -> b_target -> bt_mount )) {
1472
1471
xfs_buf_ioerror (bp , - EIO );
1473
1472
bp -> b_flags &= ~XBF_DONE ;
1474
1473
xfs_buf_stale (bp );
1475
- xfs_buf_ioend (bp );
1476
- return ;
1474
+ return - EIO ;
1477
1475
}
1478
1476
1479
1477
if (bp -> b_flags & XBF_WRITE )
@@ -1482,23 +1480,14 @@ xfs_buf_submit(
1482
1480
/* clear the internal error state to avoid spurious errors */
1483
1481
bp -> b_io_error = 0 ;
1484
1482
1485
- /*
1486
- * The caller's reference is released during I/O completion.
1487
- * This occurs some time after the last b_io_remaining reference is
1488
- * released, so after we drop our Io reference we have to have some
1489
- * other reference to ensure the buffer doesn't go away from underneath
1490
- * us. Take a direct reference to ensure we have safe access to the
1491
- * buffer until we are finished with it.
1492
- */
1493
- xfs_buf_hold (bp );
1494
-
1495
1483
/*
1496
1484
* Set the count to 1 initially, this will stop an I/O completion
1497
1485
* callout which happens before we have started all the I/O from calling
1498
1486
* xfs_buf_ioend too early.
1499
1487
*/
1500
1488
atomic_set (& bp -> b_io_remaining , 1 );
1501
- xfs_buf_ioacct_inc (bp );
1489
+ if (bp -> b_flags & XBF_ASYNC )
1490
+ xfs_buf_ioacct_inc (bp );
1502
1491
_xfs_buf_ioapply (bp );
1503
1492
1504
1493
/*
@@ -1507,14 +1496,39 @@ xfs_buf_submit(
1507
1496
* that we don't return to the caller with completion still pending.
1508
1497
*/
1509
1498
if (atomic_dec_and_test (& bp -> b_io_remaining ) == 1 ) {
1510
- if (bp -> b_error )
1499
+ if (bp -> b_error || !( bp -> b_flags & XBF_ASYNC ) )
1511
1500
xfs_buf_ioend (bp );
1512
1501
else
1513
1502
xfs_buf_ioend_async (bp );
1514
1503
}
1515
1504
1516
- xfs_buf_rele (bp );
1505
+ return 0 ;
1506
+ }
1507
+
1508
+ void
1509
+ xfs_buf_submit (
1510
+ struct xfs_buf * bp )
1511
+ {
1512
+ int error ;
1513
+
1514
+ ASSERT (bp -> b_flags & XBF_ASYNC );
1515
+
1516
+ /*
1517
+ * The caller's reference is released during I/O completion.
1518
+ * This occurs some time after the last b_io_remaining reference is
1519
+ * released, so after we drop our Io reference we have to have some
1520
+ * other reference to ensure the buffer doesn't go away from underneath
1521
+ * us. Take a direct reference to ensure we have safe access to the
1522
+ * buffer until we are finished with it.
1523
+ */
1524
+ xfs_buf_hold (bp );
1525
+
1526
+ error = __xfs_buf_submit (bp );
1527
+ if (error )
1528
+ xfs_buf_ioend (bp );
1529
+
1517
1530
/* Note: it is not safe to reference bp now we've dropped our ref */
1531
+ xfs_buf_rele (bp );
1518
1532
}
1519
1533
1520
1534
/*
@@ -1526,22 +1540,7 @@ xfs_buf_submit_wait(
1526
1540
{
1527
1541
int error ;
1528
1542
1529
- trace_xfs_buf_submit_wait (bp , _RET_IP_ );
1530
-
1531
- ASSERT (!(bp -> b_flags & (_XBF_DELWRI_Q | XBF_ASYNC )));
1532
-
1533
- if (XFS_FORCED_SHUTDOWN (bp -> b_target -> bt_mount )) {
1534
- xfs_buf_ioerror (bp , - EIO );
1535
- xfs_buf_stale (bp );
1536
- bp -> b_flags &= ~XBF_DONE ;
1537
- return - EIO ;
1538
- }
1539
-
1540
- if (bp -> b_flags & XBF_WRITE )
1541
- xfs_buf_wait_unpin (bp );
1542
-
1543
- /* clear the internal error state to avoid spurious errors */
1544
- bp -> b_io_error = 0 ;
1543
+ ASSERT (!(bp -> b_flags & XBF_ASYNC ));
1545
1544
1546
1545
/*
1547
1546
* For synchronous IO, the IO does not inherit the submitters reference
@@ -1551,27 +1550,17 @@ xfs_buf_submit_wait(
1551
1550
*/
1552
1551
xfs_buf_hold (bp );
1553
1552
1554
- /*
1555
- * Set the count to 1 initially, this will stop an I/O completion
1556
- * callout which happens before we have started all the I/O from calling
1557
- * xfs_buf_ioend too early.
1558
- */
1559
- atomic_set (& bp -> b_io_remaining , 1 );
1560
- _xfs_buf_ioapply (bp );
1561
-
1562
- /*
1563
- * make sure we run completion synchronously if it raced with us and is
1564
- * already complete.
1565
- */
1566
- if (atomic_dec_and_test (& bp -> b_io_remaining ) == 1 )
1567
- xfs_buf_ioend (bp );
1553
+ error = __xfs_buf_submit (bp );
1554
+ if (error )
1555
+ goto out ;
1568
1556
1569
1557
/* wait for completion before gathering the error from the buffer */
1570
1558
trace_xfs_buf_iowait (bp , _RET_IP_ );
1571
1559
wait_for_completion (& bp -> b_iowait );
1572
1560
trace_xfs_buf_iowait_done (bp , _RET_IP_ );
1573
1561
error = bp -> b_error ;
1574
1562
1563
+ out :
1575
1564
/*
1576
1565
* all done now, we can release the hold that keeps the buffer
1577
1566
* referenced for the entire IO.
0 commit comments