zircon/system/ulib/fs/journal/test/journal_test.cc
// Tests a pretty common operation from a client point-of-view: order data operations around
// completion of a metadata update.
Tests a pretty common operation from a client point-of-view: order data operations around
completion of a metadata update.
Tests a pretty common operation from a client point - of - view : order data operations around completion of a metadata update .
TEST_F(JournalTest, DataOperationsCanBeOrderedAroundMetadata) {
  storage::VmoBuffer buffer = registry()->InitializeBuffer(5);
  const std::vector<storage::UnbufferedOperation> operations = {
      {
          zx::unowned_vmo(buffer.vmo().get()),
          {
              storage::OperationType::kWrite,
              .vmo_offset = 0,
              .dev_offset = 20,
              .length = 1,
          },
      },
      {
          zx::unowned_vmo(buffer.vmo().get()),
          {
              storage::OperationType::kWrite,
              .vmo_offset = 1,
              .dev_offset = 200,
              .length = 1,
          },
      },
      {
          zx::unowned_vmo(buffer.vmo().get()),
          {
              storage::OperationType::kWrite,
              .vmo_offset = 2,
              .dev_offset = 2000,
              .length = 1,
          },
      },
  };
  JournalRequestVerifier verifier(registry()->info(), registry()->journal(),
                                  registry()->writeback(), 0);
  MockTransactionHandler::TransactionCallback callbacks[] = {
      [&](const std::vector<storage::BufferedOperation>& requests) {
        verifier.VerifyDataWrite(operations[0], requests);
        verifier.ExtendDataOffset(operations[0].op.length);
        return ZX_OK;
      },
      [&](const std::vector<storage::BufferedOperation>& requests) {
        verifier.VerifyJournalWrite(operations[1], requests);
        return ZX_OK;
      },
      [&](const std::vector<storage::BufferedOperation>& requests) {
        verifier.VerifyMetadataWrite(operations[1], requests);
        verifier.ExtendJournalOffset(operations[1].op.length + kEntryMetadataBlocks);
        return ZX_OK;
      },
      [&](const std::vector<storage::BufferedOperation>& requests) {
        verifier.VerifyDataWrite(operations[2], requests);
        verifier.ExtendDataOffset(operations[2].op.length);
        return ZX_OK;
      },
      [&](const std::vector<storage::BufferedOperation>& requests) {
        uint64_t sequence_number = 1;
        verifier.VerifyInfoBlockWrite(sequence_number, requests);
        registry()->VerifyReplay({}, sequence_number);
        return ZX_OK;
      }};
  MockTransactionHandler handler(registry(), callbacks, std::size(callbacks));
  {
    Journal journal(&handler, take_info(), take_journal_buffer(), take_data_buffer(), 0,
                    Journal::Options());
    auto promise = journal.WriteData({operations[0]})
                       .and_then(journal.WriteMetadata({operations[1]}))
                       .and_then(journal.WriteData({operations[2]}));
    journal.schedule_task(std::move(promise));
  }
}
TEST_F ( JournalTest , DataOperationsCanBeOrderedAroundMetadata ) { storage :: VmoBuffer buffer = registry ( ) -> InitializeBuffer ( 5 ) ; const std :: vector < storage :: UnbufferedOperation > operations = { { zx :: unowned_vmo ( buffer . vmo ( ) . get ( ) ) , { storage :: OperationType :: kWrite , . vmo_offset = 0 , . dev_offset = 20 , . length = 1 , } , } , { zx :: unowned_vmo ( buffer . vmo ( ) . get ( ) ) , { storage :: OperationType :: kWrite , . vmo_offset = 1 , . dev_offset = 200 , . length = 1 , } , } , { zx :: unowned_vmo ( buffer . vmo ( ) . get ( ) ) , { storage :: OperationType :: kWrite , . vmo_offset = 2 , . dev_offset = 2000 , . length = 1 , } , } , } ; JournalRequestVerifier verifier ( registry ( ) -> info ( ) , registry ( ) -> journal ( ) , registry ( ) -> writeback ( ) , 0 ) ; MockTransactionHandler :: TransactionCallback callbacks [ ] = { [ & ] ( const std :: vector < storage :: BufferedOperation > & requests ) { verifier . VerifyDataWrite ( operations [ 0 ] , requests ) ; verifier . ExtendDataOffset ( operations [ 0 ] . op . length ) ; return ZX_OK ; } , [ & ] ( const std :: vector < storage :: BufferedOperation > & requests ) { verifier . VerifyJournalWrite ( operations [ 1 ] , requests ) ; return ZX_OK ; } , [ & ] ( const std :: vector < storage :: BufferedOperation > & requests ) { verifier . VerifyMetadataWrite ( operations [ 1 ] , requests ) ; verifier . ExtendJournalOffset ( operations [ 1 ] . op . length + kEntryMetadataBlocks ) ; return ZX_OK ; } , [ & ] ( const std :: vector < storage :: BufferedOperation > & requests ) { verifier . VerifyDataWrite ( operations [ 2 ] , requests ) ; verifier . ExtendDataOffset ( operations [ 2 ] . op . length ) ; return ZX_OK ; } , [ & ] ( const std :: vector < storage :: BufferedOperation > & requests ) { uint64_t sequence_number = 1 ; verifier . VerifyInfoBlockWrite ( sequence_number , requests ) ; registry ( ) -> VerifyReplay ( { } , sequence_number ) ; return ZX_OK ; } } ; MockTransactionHandler handler ( registry ( ) , callbacks , std :: size ( callbacks ) ) ; { Journal journal ( & handler , take_info ( ) , take_journal_buffer ( ) , take_data_buffer ( ) , 0 , Journal :: Options ( ) ) ; auto promise = journal . WriteData ( { operations [ 0 ] } ) . and_then ( journal . WriteMetadata ( { operations [ 1 ] } ) ) . and_then ( journal . WriteData ( { operations [ 2 ] } ) ) ; journal . schedule_task ( std :: move ( promise ) ) ; } }
Tests a pretty common operation from a client point-of-view: order data operations around
completion of a metadata update.
Tests a pretty common operation from a client point - of - view : order data operations around completion of a metadata update .
// We're using the same source buffer, but use: // - operations[0] as data // - operations[1] as metadata // - operations[2] as data // Operation[0]: Data. // Operation[1]: Metadata (journal, then metadata). // Operation[2]: Data. // Final operation: Updating the info block on journal teardown.