]> git.ozlabs.org Git - ccan/commitdiff
tdb2: rename ->read and ->write functions.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)
Since failtest uses macros to override read and write, we need to avoid
those names, even inside our ops structure.

ccan/tdb2/check.c
ccan/tdb2/io.c
ccan/tdb2/private.h
ccan/tdb2/tdb.c
ccan/tdb2/test/run-04-basichash.c
ccan/tdb2/transaction.c

index 5a238a1c48274c507511518bea9d060daaa2e8de..4da81dbbbb53fa68ab1031fabaaccbc95f3dca2a 100644 (file)
@@ -512,7 +512,7 @@ size_t dead_space(struct tdb_context *tdb, tdb_off_t off)
 
        for (len = 0; off + len < tdb->map_size; len++) {
                char c;
 
        for (len = 0; off + len < tdb->map_size; len++) {
                char c;
-               if (tdb->methods->read(tdb, off, &c, 1))
+               if (tdb->methods->tread(tdb, off, &c, 1))
                        return 0;
                if (c != 0 && c != 0x43)
                        break;
                        return 0;
                if (c != 0 && c != 0x43)
                        break;
index bdf86b676738d2fa1c067e23f4361a4a8d54650d..13af1aecc14336043ff8cc85856429152195a301 100644 (file)
@@ -182,7 +182,7 @@ int zero_out(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len)
        }
        while (len) {
                unsigned todo = len < sizeof(buf) ? len : sizeof(buf);
        }
        while (len) {
                unsigned todo = len < sizeof(buf) ? len : sizeof(buf);
-               if (tdb->methods->write(tdb, off, buf, todo) == -1)
+               if (tdb->methods->twrite(tdb, off, buf, todo) == -1)
                        return -1;
                len -= todo;
                off += todo;
                        return -1;
                len -= todo;
                off += todo;
@@ -282,11 +282,11 @@ int tdb_write_convert(struct tdb_context *tdb, tdb_off_t off,
                        return -1;
                }
                memcpy(conv, rec, len);
                        return -1;
                }
                memcpy(conv, rec, len);
-               ret = tdb->methods->write(tdb, off,
-                                         tdb_convert(tdb, conv, len), len);
+               ret = tdb->methods->twrite(tdb, off,
+                                          tdb_convert(tdb, conv, len), len);
                free(conv);
        } else
                free(conv);
        } else
-               ret = tdb->methods->write(tdb, off, rec, len);
+               ret = tdb->methods->twrite(tdb, off, rec, len);
 
        return ret;
 }
 
        return ret;
 }
@@ -294,7 +294,7 @@ int tdb_write_convert(struct tdb_context *tdb, tdb_off_t off,
 int tdb_read_convert(struct tdb_context *tdb, tdb_off_t off,
                      void *rec, size_t len)
 {
 int tdb_read_convert(struct tdb_context *tdb, tdb_off_t off,
                      void *rec, size_t len)
 {
-       int ret = tdb->methods->read(tdb, off, rec, len);
+       int ret = tdb->methods->tread(tdb, off, rec, len);
        tdb_convert(tdb, rec, len);
        return ret;
 }
        tdb_convert(tdb, rec, len);
        return ret;
 }
@@ -329,8 +329,8 @@ static void *_tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset,
                tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_ERROR,
                           "tdb_alloc_read malloc failed len=%zu",
                           (size_t)(prefix + len));
                tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_ERROR,
                           "tdb_alloc_read malloc failed len=%zu",
                           (size_t)(prefix + len));
-       } else if (unlikely(tdb->methods->read(tdb, offset, buf+prefix,
-                                              len) == -1)) {
+       } else if (unlikely(tdb->methods->tread(tdb, offset, buf+prefix, len)
+                           == -1)) {
                free(buf);
                buf = NULL;
        }
                free(buf);
                buf = NULL;
        }
index 75e49c8313fcee17d40f8fe01ecd7953c7305fb3..e2982bc5aac6cb49ac5c0118736f5c7b536e94c7 100644 (file)
@@ -366,8 +366,8 @@ struct tdb_context {
 };
 
 struct tdb_methods {
 };
 
 struct tdb_methods {
-       int (*read)(struct tdb_context *, tdb_off_t, void *, tdb_len_t);
-       int (*write)(struct tdb_context *, tdb_off_t, const void *, tdb_len_t);
+       int (*tread)(struct tdb_context *, tdb_off_t, void *, tdb_len_t);
+       int (*twrite)(struct tdb_context *, tdb_off_t, const void *, tdb_len_t);
        int (*oob)(struct tdb_context *, tdb_off_t, bool);
        int (*expand_file)(struct tdb_context *, tdb_len_t);
        void *(*direct)(struct tdb_context *, tdb_off_t, size_t, bool);
        int (*oob)(struct tdb_context *, tdb_off_t, bool);
        int (*expand_file)(struct tdb_context *, tdb_len_t);
        void *(*direct)(struct tdb_context *, tdb_off_t, size_t, bool);
index 1aa3baa46c24471033af359dba192ab82e3747a3..03d51c2192313a7ce6f9c6e270b92405619fed3c 100644 (file)
@@ -453,11 +453,11 @@ static int replace_data(struct tdb_context *tdb,
        }
 
        new_off += sizeof(struct tdb_used_record);
        }
 
        new_off += sizeof(struct tdb_used_record);
-       if (tdb->methods->write(tdb, new_off, key.dptr, key.dsize) == -1)
+       if (tdb->methods->twrite(tdb, new_off, key.dptr, key.dsize) == -1)
                return -1;
 
        new_off += key.dsize;
                return -1;
 
        new_off += key.dsize;
-       if (tdb->methods->write(tdb, new_off, dbuf.dptr, dbuf.dsize) == -1)
+       if (tdb->methods->twrite(tdb, new_off, dbuf.dptr, dbuf.dsize) == -1)
                return -1;
 
        /* FIXME: tdb_increment_seqnum(tdb); */
                return -1;
 
        /* FIXME: tdb_increment_seqnum(tdb); */
@@ -493,9 +493,9 @@ int tdb_store(struct tdb_context *tdb,
                                                   key.dsize, dbuf.dsize,
                                                   &rec, h.h))
                                        goto fail;
                                                   key.dsize, dbuf.dsize,
                                                   &rec, h.h))
                                        goto fail;
-                               if (tdb->methods->write(tdb, off + sizeof(rec)
-                                                       + key.dsize,
-                                                       dbuf.dptr, dbuf.dsize))
+                               if (tdb->methods->twrite(tdb, off + sizeof(rec)
+                                                        + key.dsize,
+                                                        dbuf.dptr, dbuf.dsize))
                                        goto fail;
                                tdb_unlock_hashes(tdb, h.hlock_start,
                                                  h.hlock_range, F_WRLCK);
                                        goto fail;
                                tdb_unlock_hashes(tdb, h.hlock_start,
                                                  h.hlock_range, F_WRLCK);
@@ -548,8 +548,8 @@ int tdb_append(struct tdb_context *tdb,
                                goto fail;
 
                        off += sizeof(rec) + key.dsize + old_dlen;
                                goto fail;
 
                        off += sizeof(rec) + key.dsize + old_dlen;
-                       if (tdb->methods->write(tdb, off, dbuf.dptr,
-                                               dbuf.dsize) == -1)
+                       if (tdb->methods->twrite(tdb, off, dbuf.dptr,
+                                                dbuf.dsize) == -1)
                                goto fail;
 
                        /* FIXME: tdb_increment_seqnum(tdb); */
                                goto fail;
 
                        /* FIXME: tdb_increment_seqnum(tdb); */
@@ -566,8 +566,8 @@ int tdb_append(struct tdb_context *tdb,
                                   (size_t)(key.dsize+old_dlen+dbuf.dsize));
                        goto fail;
                }
                                   (size_t)(key.dsize+old_dlen+dbuf.dsize));
                        goto fail;
                }
-               if (tdb->methods->read(tdb, off + sizeof(rec) + key.dsize,
-                                      newdata, old_dlen) != 0) {
+               if (tdb->methods->tread(tdb, off + sizeof(rec) + key.dsize,
+                                       newdata, old_dlen) != 0) {
                        free(newdata);
                        goto fail;
                }
                        free(newdata);
                        goto fail;
                }
index ceee06835132fb54d1ab73d996e2377f0b2eaa33..d1e41c29e494d6c35f5ef36beb9ddd294cd26454 100644 (file)
@@ -74,9 +74,9 @@ int main(int argc, char *argv[])
 
                /* Make sure we fill it in for later finding. */
                off = new_off + sizeof(struct tdb_used_record);
 
                /* Make sure we fill it in for later finding. */
                off = new_off + sizeof(struct tdb_used_record);
-               ok1(!tdb->methods->write(tdb, off, key.dptr, key.dsize));
+               ok1(!tdb->methods->twrite(tdb, off, key.dptr, key.dsize));
                off += key.dsize;
                off += key.dsize;
-               ok1(!tdb->methods->write(tdb, off, dbuf.dptr, dbuf.dsize));
+               ok1(!tdb->methods->twrite(tdb, off, dbuf.dptr, dbuf.dsize));
 
                /* We should be able to unlock that OK. */
                ok1(tdb_unlock_hashes(tdb, h.hlock_start, h.hlock_range,
 
                /* We should be able to unlock that OK. */
                ok1(tdb_unlock_hashes(tdb, h.hlock_start, h.hlock_range,
@@ -233,9 +233,9 @@ int main(int argc, char *argv[])
 
                /* Make sure we fill it in for later finding. */
                off = new_off + sizeof(struct tdb_used_record);
 
                /* Make sure we fill it in for later finding. */
                off = new_off + sizeof(struct tdb_used_record);
-               ok1(!tdb->methods->write(tdb, off, key.dptr, key.dsize));
+               ok1(!tdb->methods->twrite(tdb, off, key.dptr, key.dsize));
                off += key.dsize;
                off += key.dsize;
-               ok1(!tdb->methods->write(tdb, off, dbuf.dptr, dbuf.dsize));
+               ok1(!tdb->methods->twrite(tdb, off, dbuf.dptr, dbuf.dsize));
 
                /* We should be able to unlock that OK. */
                ok1(tdb_unlock_hashes(tdb, h.hlock_start, h.hlock_range,
 
                /* We should be able to unlock that OK. */
                ok1(tdb_unlock_hashes(tdb, h.hlock_start, h.hlock_range,
index c29c46510cffea170ea9d6f8079433902fb5f29d..66be5bdc8e533cf67c49fddea59e2951ca10e863 100644 (file)
@@ -151,7 +151,8 @@ static int transaction_read(struct tdb_context *tdb, tdb_off_t off, void *buf,
        if (tdb->transaction->num_blocks <= blk ||
            tdb->transaction->blocks[blk] == NULL) {
                /* nope, do a real read */
        if (tdb->transaction->num_blocks <= blk ||
            tdb->transaction->blocks[blk] == NULL) {
                /* nope, do a real read */
-               if (tdb->transaction->io_methods->read(tdb, off, buf, len) != 0) {
+               if (tdb->transaction->io_methods->tread(tdb, off, buf, len)
+                   != 0) {
                        goto fail;
                }
                return 0;
                        goto fail;
                }
                return 0;
@@ -249,9 +250,9 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off,
                        if (len2 + (blk * getpagesize()) > tdb->transaction->old_map_size) {
                                len2 = tdb->transaction->old_map_size - (blk * getpagesize());
                        }
                        if (len2 + (blk * getpagesize()) > tdb->transaction->old_map_size) {
                                len2 = tdb->transaction->old_map_size - (blk * getpagesize());
                        }
-                       if (tdb->transaction->io_methods->read(tdb, blk * getpagesize(),
-                                                              tdb->transaction->blocks[blk],
-                                                              len2) != 0) {
+                       if (tdb->transaction->io_methods->tread(tdb, blk * getpagesize(),
+                                                               tdb->transaction->blocks[blk],
+                                                               len2) != 0) {
                                tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
                                           "transaction_write: failed to"
                                           " read old block: %s",
                                tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
                                           "transaction_write: failed to"
                                           " read old block: %s",
@@ -468,8 +469,8 @@ static void _tdb_transaction_cancel(struct tdb_context *tdb)
                uint64_t invalid = TDB_RECOVERY_INVALID_MAGIC;
 
                /* remove the recovery marker */
                uint64_t invalid = TDB_RECOVERY_INVALID_MAGIC;
 
                /* remove the recovery marker */
-               if (methods->write(tdb, tdb->transaction->magic_offset,
-                                  &invalid, sizeof(invalid)) == -1 ||
+               if (methods->twrite(tdb, tdb->transaction->magic_offset,
+                                   &invalid, sizeof(invalid)) == -1 ||
                    transaction_sync(tdb, tdb->transaction->magic_offset,
                                     sizeof(invalid)) == -1) {
                        tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                    transaction_sync(tdb, tdb->transaction->magic_offset,
                                     sizeof(invalid)) == -1) {
                        tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
@@ -624,7 +625,7 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
        }
 
        if (recovery_head != 0) {
        }
 
        if (recovery_head != 0) {
-               if (methods->read(tdb, recovery_head, &rec, sizeof(rec))) {
+               if (methods->tread(tdb, recovery_head, &rec, sizeof(rec))) {
                        tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                                 "tdb_recovery_allocate:"
                                 " failed to read recovery record");
                        tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                                 "tdb_recovery_allocate:"
                                 " failed to read recovery record");
@@ -696,8 +697,8 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
        /* write the recovery header offset and sync - we can sync without a race here
           as the magic ptr in the recovery record has not been set */
        tdb_convert(tdb, &recovery_head, sizeof(recovery_head));
        /* write the recovery header offset and sync - we can sync without a race here
           as the magic ptr in the recovery record has not been set */
        tdb_convert(tdb, &recovery_head, sizeof(recovery_head));
-       if (methods->write(tdb, offsetof(struct tdb_header, recovery),
-                          &recovery_head, sizeof(tdb_off_t)) == -1) {
+       if (methods->twrite(tdb, offsetof(struct tdb_header, recovery),
+                           &recovery_head, sizeof(tdb_off_t)) == -1) {
                tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                         "tdb_recovery_allocate:"
                         " failed to write recovery head");
                tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                         "tdb_recovery_allocate:"
                         " failed to write recovery head");
@@ -790,9 +791,9 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
                /* the recovery area contains the old data, not the
                   new data, so we have to call the original tdb_read
                   method to get it */
                /* the recovery area contains the old data, not the
                   new data, so we have to call the original tdb_read
                   method to get it */
-               if (methods->read(tdb, offset,
-                                 p + sizeof(offset) + sizeof(length),
-                                 length) != 0) {
+               if (methods->tread(tdb, offset,
+                                  p + sizeof(offset) + sizeof(length),
+                                  length) != 0) {
                        free(data);
                        return -1;
                }
                        free(data);
                        return -1;
                }
@@ -805,8 +806,8 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
        tdb_convert(tdb, p, sizeof(tailer));
 
        /* write the recovery data to the recovery area */
        tdb_convert(tdb, p, sizeof(tailer));
 
        /* write the recovery data to the recovery area */
-       if (methods->write(tdb, recovery_offset, data,
-                          sizeof(*rec) + recovery_size) == -1) {
+       if (methods->twrite(tdb, recovery_offset, data,
+                           sizeof(*rec) + recovery_size) == -1) {
                tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                         "tdb_transaction_setup_recovery:"
                         " failed to write recovery data");
                tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                         "tdb_transaction_setup_recovery:"
                         " failed to write recovery data");
@@ -833,7 +834,7 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
        *magic_offset = recovery_offset + offsetof(struct tdb_recovery_record,
                                                   magic);
 
        *magic_offset = recovery_offset + offsetof(struct tdb_recovery_record,
                                                   magic);
 
-       if (methods->write(tdb, *magic_offset, &magic, sizeof(magic)) == -1) {
+       if (methods->twrite(tdb, *magic_offset, &magic, sizeof(magic)) == -1) {
                tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                         "tdb_transaction_setup_recovery:"
                         " failed to write recovery magic");
                tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                         "tdb_transaction_setup_recovery:"
                         " failed to write recovery magic");
@@ -1007,8 +1008,8 @@ int tdb_transaction_commit(struct tdb_context *tdb)
                        length = tdb->transaction->last_block_size;
                }
 
                        length = tdb->transaction->last_block_size;
                }
 
-               if (methods->write(tdb, offset, tdb->transaction->blocks[i],
-                                  length) == -1) {
+               if (methods->twrite(tdb, offset, tdb->transaction->blocks[i],
+                                   length) == -1) {
                        tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                                   "tdb_transaction_commit:"
                                   " write failed during commit");
                        tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                                   "tdb_transaction_commit:"
                                   " write failed during commit");
@@ -1113,8 +1114,8 @@ int tdb_transaction_recover(struct tdb_context *tdb)
        }
 
        /* read the full recovery data */
        }
 
        /* read the full recovery data */
-       if (tdb->methods->read(tdb, recovery_head + sizeof(rec), data,
-                              rec.len) == -1) {
+       if (tdb->methods->tread(tdb, recovery_head + sizeof(rec), data,
+                               rec.len) == -1) {
                tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                           "tdb_transaction_recover:"
                           " failed to read recovery data");
                tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                           "tdb_transaction_recover:"
                           " failed to read recovery data");
@@ -1131,7 +1132,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
                memcpy(&len, p + sizeof(ofs), sizeof(len));
                p += sizeof(ofs) + sizeof(len);
 
                memcpy(&len, p + sizeof(ofs), sizeof(len));
                p += sizeof(ofs) + sizeof(len);
 
-               if (tdb->methods->write(tdb, ofs, p, len) == -1) {
+               if (tdb->methods->twrite(tdb, ofs, p, len) == -1) {
                        free(data);
                        tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                                 "tdb_transaction_recover:"
                        free(data);
                        tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                                 "tdb_transaction_recover:"