X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Ftransaction.c;h=55b7fd60dc9c38af5298dc0e87817ca1fa3bf952;hp=d9a1bc050ef6a4415bd69647d3dc9e6ce59573ac;hb=18fe5ef012a96014b9e61e48616e682b4a5708a2;hpb=0753972a623c7bf24f13578a5ceb3995ea307876 diff --git a/ccan/tdb2/transaction.c b/ccan/tdb2/transaction.c index d9a1bc05..55b7fd60 100644 --- a/ccan/tdb2/transaction.c +++ b/ccan/tdb2/transaction.c @@ -438,7 +438,7 @@ static enum TDB_ERROR transaction_sync(struct tdb_context *tdb, } #ifdef MS_SYNC if (tdb->file->map_ptr) { - tdb_off_t moffset = offset & ~(PAGESIZE-1); + tdb_off_t moffset = offset & ~(getpagesize()-1); if (msync(moffset + (char *)tdb->file->map_ptr, length + (offset - moffset), MS_SYNC) != 0) { return tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR, @@ -711,7 +711,7 @@ static struct tdb_recovery_record *alloc_recovery(struct tdb_context *tdb, size_t i; enum TDB_ERROR ecode; unsigned char *p; - const struct tdb_methods *methods = tdb->transaction->io_methods; + const struct tdb_methods *old_methods = tdb->methods; rec = malloc(sizeof(*rec) + tdb_recovery_size(tdb)); if (!rec) { @@ -721,6 +721,10 @@ static struct tdb_recovery_record *alloc_recovery(struct tdb_context *tdb, return TDB_ERR_PTR(TDB_ERR_OOM); } + /* We temporarily revert to the old I/O methods, so we can use + * tdb_access_read */ + tdb->methods = tdb->transaction->io_methods; + /* build the recovery data into a single blob to allow us to do a single large write, which should be more efficient */ p = (unsigned char *)(rec + 1); @@ -728,7 +732,7 @@ static struct tdb_recovery_record *alloc_recovery(struct tdb_context *tdb, tdb_off_t offset; tdb_len_t length; unsigned int off; - unsigned char buffer[PAGESIZE]; + const unsigned char *buffer; if (tdb->transaction->blocks[i] == NULL) { continue; @@ -745,21 +749,20 @@ static struct tdb_recovery_record *alloc_recovery(struct tdb_context *tdb, } if (offset + length > tdb->file->map_size) { - free(rec); - tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR, - "tdb_transaction_setup_recovery:" - " transaction data over new region" - " boundary"); - return TDB_ERR_PTR(TDB_ERR_CORRUPT); + ecode = tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR, + "tdb_transaction_setup_recovery:" + " transaction data over new region" + " boundary"); + goto fail; } if (offset + length > tdb->transaction->old_map_size) { /* Short read at EOF. */ length = tdb->transaction->old_map_size - offset; } - ecode = methods->tread(tdb, offset, buffer, length); - if (ecode != TDB_SUCCESS) { - free(rec); - return TDB_ERR_PTR(ecode); + buffer = tdb_access_read(tdb, offset, length, false); + if (TDB_PTR_IS_ERR(buffer)) { + ecode = TDB_PTR_ERR(buffer); + goto fail; } /* Skip over anything the same at the start. */ @@ -784,10 +787,17 @@ static struct tdb_recovery_record *alloc_recovery(struct tdb_context *tdb, off += len + samelen; offset += len + samelen; } + tdb_access_release(tdb, buffer); } *len = p - (unsigned char *)(rec + 1); + tdb->methods = old_methods; return rec; + +fail: + free(rec); + tdb->methods = old_methods; + return TDB_ERR_PTR(ecode); } static tdb_off_t create_recovery_area(struct tdb_context *tdb,