summaryrefslogtreecommitdiff
path: root/lib/tdb2/io.c
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-06-18 22:30:26 +0930
committerRusty Russell <rusty@rustcorp.com.au>2012-06-19 05:38:05 +0200
commitc3dcdf08f3472748c9e7984488398064abcd454a (patch)
tree3c7ea8afbb00cfae914bd7011d0a4b1321764133 /lib/tdb2/io.c
parentcab6e116786641e28747de3f70c8cd89ba17673f (diff)
downloadsamba-c3dcdf08f3472748c9e7984488398064abcd454a.tar.gz
samba-c3dcdf08f3472748c9e7984488398064abcd454a.tar.bz2
samba-c3dcdf08f3472748c9e7984488398064abcd454a.zip
TDB2: more internal cleanups after TDB1 compatibility removal.
This eliminates the separate tdb2 substructure, and makes some tdb1-required functions static. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/tdb2/io.c')
-rw-r--r--lib/tdb2/io.c57
1 files changed, 27 insertions, 30 deletions
diff --git a/lib/tdb2/io.c b/lib/tdb2/io.c
index 7308d2bf44..ca044ae361 100644
--- a/lib/tdb2/io.c
+++ b/lib/tdb2/io.c
@@ -99,7 +99,7 @@ static enum TDB_ERROR tdb_oob(struct tdb_context *tdb,
enum TDB_ERROR ecode;
/* We can't hold pointers during this: we could unmap! */
- assert(!tdb->tdb2.direct_access
+ assert(!tdb->direct_access
|| (tdb->flags & TDB_NOLOCK)
|| tdb_has_expansion_lock(tdb));
@@ -216,7 +216,7 @@ uint64_t tdb_find_zero_off(struct tdb_context *tdb, tdb_off_t off,
enum TDB_ERROR zero_out(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len)
{
char buf[8192] = { 0 };
- void *p = tdb->tdb2.io->direct(tdb, off, len, true);
+ void *p = tdb->io->direct(tdb, off, len, true);
enum TDB_ERROR ecode = TDB_SUCCESS;
assert(!(tdb->flags & TDB_RDONLY));
@@ -229,7 +229,7 @@ enum TDB_ERROR zero_out(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len)
}
while (len) {
unsigned todo = len < sizeof(buf) ? len : sizeof(buf);
- ecode = tdb->tdb2.io->twrite(tdb, off, buf, todo);
+ ecode = tdb->io->twrite(tdb, off, buf, todo);
if (ecode != TDB_SUCCESS) {
break;
}
@@ -245,8 +245,7 @@ tdb_off_t tdb_read_off(struct tdb_context *tdb, tdb_off_t off)
enum TDB_ERROR ecode;
if (likely(!(tdb->flags & TDB_CONVERT))) {
- tdb_off_t *p = tdb->tdb2.io->direct(tdb, off, sizeof(*p),
- false);
+ tdb_off_t *p = tdb->io->direct(tdb, off, sizeof(*p), false);
if (TDB_PTR_IS_ERR(p)) {
return TDB_ERR_TO_OFF(TDB_PTR_ERR(p));
}
@@ -272,7 +271,7 @@ static enum TDB_ERROR tdb_write(struct tdb_context *tdb, tdb_off_t off,
"Write to read-only database");
}
- ecode = tdb->tdb2.io->oob(tdb, off, len, false);
+ ecode = tdb->io->oob(tdb, off, len, false);
if (ecode != TDB_SUCCESS) {
return ecode;
}
@@ -306,7 +305,7 @@ static enum TDB_ERROR tdb_read(struct tdb_context *tdb, tdb_off_t off,
{
enum TDB_ERROR ecode;
- ecode = tdb->tdb2.io->oob(tdb, off, len, false);
+ ecode = tdb->io->oob(tdb, off, len, false);
if (ecode != TDB_SUCCESS) {
return ecode;
}
@@ -344,11 +343,11 @@ enum TDB_ERROR tdb_write_convert(struct tdb_context *tdb, tdb_off_t off,
" %zu bytes", len);
}
memcpy(conv, rec, len);
- ecode = tdb->tdb2.io->twrite(tdb, off,
- tdb_convert(tdb, conv, len), len);
+ ecode = tdb->io->twrite(tdb, off,
+ tdb_convert(tdb, conv, len), len);
free(conv);
} else {
- ecode = tdb->tdb2.io->twrite(tdb, off, rec, len);
+ ecode = tdb->io->twrite(tdb, off, rec, len);
}
return ecode;
}
@@ -356,7 +355,7 @@ enum TDB_ERROR tdb_write_convert(struct tdb_context *tdb, tdb_off_t off,
enum TDB_ERROR tdb_read_convert(struct tdb_context *tdb, tdb_off_t off,
void *rec, size_t len)
{
- enum TDB_ERROR ecode = tdb->tdb2.io->tread(tdb, off, rec, len);
+ enum TDB_ERROR ecode = tdb->io->tread(tdb, off, rec, len);
tdb_convert(tdb, rec, len);
return ecode;
}
@@ -370,8 +369,7 @@ enum TDB_ERROR tdb_write_off(struct tdb_context *tdb,
}
if (likely(!(tdb->flags & TDB_CONVERT))) {
- tdb_off_t *p = tdb->tdb2.io->direct(tdb, off, sizeof(*p),
- true);
+ tdb_off_t *p = tdb->io->direct(tdb, off, sizeof(*p), true);
if (TDB_PTR_IS_ERR(p)) {
return TDB_PTR_ERR(p);
}
@@ -397,7 +395,7 @@ static void *_tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset,
(size_t)(prefix + len));
return TDB_ERR_PTR(TDB_ERR_OOM);
} else {
- ecode = tdb->tdb2.io->tread(tdb, offset, buf+prefix, len);
+ ecode = tdb->io->tread(tdb, offset, buf+prefix, len);
if (unlikely(ecode != TDB_SUCCESS)) {
free(buf);
return TDB_ERR_PTR(ecode);
@@ -486,7 +484,7 @@ const void *tdb_access_read(struct tdb_context *tdb,
void *ret = NULL;
if (likely(!(tdb->flags & TDB_CONVERT))) {
- ret = tdb->tdb2.io->direct(tdb, off, len, false);
+ ret = tdb->io->direct(tdb, off, len, false);
if (TDB_PTR_IS_ERR(ret)) {
return ret;
@@ -498,14 +496,14 @@ const void *tdb_access_read(struct tdb_context *tdb,
if (TDB_PTR_IS_ERR(hdr)) {
return hdr;
}
- hdr->next = tdb->tdb2.access;
- tdb->tdb2.access = hdr;
+ hdr->next = tdb->access;
+ tdb->access = hdr;
ret = hdr + 1;
if (convert) {
tdb_convert(tdb, (void *)ret, len);
}
} else
- tdb->tdb2.direct_access++;
+ tdb->direct_access++;
return ret;
}
@@ -522,7 +520,7 @@ void *tdb_access_write(struct tdb_context *tdb,
}
if (likely(!(tdb->flags & TDB_CONVERT))) {
- ret = tdb->tdb2.io->direct(tdb, off, len, true);
+ ret = tdb->io->direct(tdb, off, len, true);
if (TDB_PTR_IS_ERR(ret)) {
return ret;
@@ -535,8 +533,8 @@ void *tdb_access_write(struct tdb_context *tdb,
if (TDB_PTR_IS_ERR(hdr)) {
return hdr;
}
- hdr->next = tdb->tdb2.access;
- tdb->tdb2.access = hdr;
+ hdr->next = tdb->access;
+ tdb->access = hdr;
hdr->off = off;
hdr->len = len;
hdr->convert = convert;
@@ -544,7 +542,7 @@ void *tdb_access_write(struct tdb_context *tdb,
if (convert)
tdb_convert(tdb, (void *)ret, len);
} else
- tdb->tdb2.direct_access++;
+ tdb->direct_access++;
return ret;
}
@@ -553,7 +551,7 @@ static struct tdb_access_hdr **find_hdr(struct tdb_context *tdb, const void *p)
{
struct tdb_access_hdr **hp;
- for (hp = &tdb->tdb2.access; *hp; hp = &(*hp)->next) {
+ for (hp = &tdb->access; *hp; hp = &(*hp)->next) {
if (*hp + 1 == p)
return hp;
}
@@ -569,7 +567,7 @@ void tdb_access_release(struct tdb_context *tdb, const void *p)
*hp = hdr->next;
free(hdr);
} else
- tdb->tdb2.direct_access--;
+ tdb->direct_access--;
}
enum TDB_ERROR tdb_access_commit(struct tdb_context *tdb, void *p)
@@ -586,7 +584,7 @@ enum TDB_ERROR tdb_access_commit(struct tdb_context *tdb, void *p)
*hp = hdr->next;
free(hdr);
} else {
- tdb->tdb2.direct_access--;
+ tdb->direct_access--;
ecode = TDB_SUCCESS;
}
@@ -614,10 +612,9 @@ void tdb_inc_seqnum(struct tdb_context *tdb)
if (likely(!(tdb->flags & TDB_CONVERT))) {
int64_t *direct;
- direct = tdb->tdb2.io->direct(tdb,
- offsetof(struct tdb_header,
- seqnum),
- sizeof(*direct), true);
+ direct = tdb->io->direct(tdb,
+ offsetof(struct tdb_header, seqnum),
+ sizeof(*direct), true);
if (likely(direct)) {
/* Don't let it go negative, even briefly */
if (unlikely((*direct) + 1) < 0)
@@ -649,5 +646,5 @@ static const struct tdb_methods io_methods = {
*/
void tdb_io_init(struct tdb_context *tdb)
{
- tdb->tdb2.io = &io_methods;
+ tdb->io = &io_methods;
}