Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
79d603a5
Commit
79d603a5
authored
Nov 30, 2011
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tdb2: provide tdb_layout_write() rather than implying it by new_tdb_layout arg.
Neater API.
parent
e01d795c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
32 deletions
+47
-32
ccan/tdb2/test/layout.c
ccan/tdb2/test/layout.c
+17
-19
ccan/tdb2/test/layout.h
ccan/tdb2/test/layout.h
+4
-2
ccan/tdb2/test/run-03-coalesce.c
ccan/tdb2/test/run-03-coalesce.c
+25
-10
ccan/tdb2/test/run-50-multiple-freelists.c
ccan/tdb2/test/run-50-multiple-freelists.c
+1
-1
No files found.
ccan/tdb2/test/layout.c
View file @
79d603a5
...
@@ -6,10 +6,9 @@
...
@@ -6,10 +6,9 @@
#include <err.h>
#include <err.h>
#include "logging.h"
#include "logging.h"
struct
tdb_layout
*
new_tdb_layout
(
const
char
*
filename
)
struct
tdb_layout
*
new_tdb_layout
(
void
)
{
{
struct
tdb_layout
*
layout
=
malloc
(
sizeof
(
*
layout
));
struct
tdb_layout
*
layout
=
malloc
(
sizeof
(
*
layout
));
layout
->
filename
=
filename
;
layout
->
num_elems
=
0
;
layout
->
num_elems
=
0
;
layout
->
elem
=
NULL
;
layout
->
elem
=
NULL
;
return
layout
;
return
layout
;
...
@@ -314,26 +313,25 @@ struct tdb_context *tdb_layout_get(struct tdb_layout *layout,
...
@@ -314,26 +313,25 @@ struct tdb_context *tdb_layout_get(struct tdb_layout *layout,
}
}
tdb
->
tdb2
.
ftable_off
=
find_ftable
(
layout
,
0
)
->
base
.
off
;
tdb
->
tdb2
.
ftable_off
=
find_ftable
(
layout
,
0
)
->
base
.
off
;
/* Get physical if they asked for it. */
if
(
layout
->
filename
)
{
int
fd
=
open
(
layout
->
filename
,
O_WRONLY
|
O_TRUNC
|
O_CREAT
,
0600
);
if
(
fd
<
0
)
err
(
1
,
"opening %s for writing"
,
layout
->
filename
);
if
(
write
(
fd
,
tdb
->
file
->
map_ptr
,
tdb
->
file
->
map_size
)
!=
tdb
->
file
->
map_size
)
err
(
1
,
"writing %s"
,
layout
->
filename
);
close
(
fd
);
tdb_close
(
tdb
);
/* NOMMAP is for lockcheck. */
tdb
=
tdb_open
(
layout
->
filename
,
TDB_NOMMAP
,
O_RDWR
,
0
,
&
tap_log_attr
);
}
return
tdb
;
return
tdb
;
}
}
void
tdb_layout_write
(
struct
tdb_layout
*
layout
,
union
tdb_attribute
*
attr
,
const
char
*
filename
)
{
struct
tdb_context
*
tdb
=
tdb_layout_get
(
layout
,
attr
);
int
fd
;
fd
=
open
(
filename
,
O_WRONLY
|
O_TRUNC
|
O_CREAT
,
0600
);
if
(
fd
<
0
)
err
(
1
,
"opening %s for writing"
,
filename
);
if
(
write
(
fd
,
tdb
->
file
->
map_ptr
,
tdb
->
file
->
map_size
)
!=
tdb
->
file
->
map_size
)
err
(
1
,
"writing %s"
,
filename
);
close
(
fd
);
tdb_close
(
tdb
);
}
void
tdb_layout_free
(
struct
tdb_layout
*
layout
)
void
tdb_layout_free
(
struct
tdb_layout
*
layout
)
{
{
unsigned
int
i
;
unsigned
int
i
;
...
...
ccan/tdb2/test/layout.h
View file @
79d603a5
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
#define TDB2_TEST_LAYOUT_H
#define TDB2_TEST_LAYOUT_H
#include <ccan/tdb2/private.h>
#include <ccan/tdb2/private.h>
struct
tdb_layout
*
new_tdb_layout
(
const
char
*
filename
);
struct
tdb_layout
*
new_tdb_layout
(
void
);
void
tdb_layout_add_freetable
(
struct
tdb_layout
*
layout
);
void
tdb_layout_add_freetable
(
struct
tdb_layout
*
layout
);
void
tdb_layout_add_free
(
struct
tdb_layout
*
layout
,
tdb_len_t
len
,
void
tdb_layout_add_free
(
struct
tdb_layout
*
layout
,
tdb_len_t
len
,
unsigned
ftable
);
unsigned
ftable
);
...
@@ -17,6 +17,9 @@ void tdb_layout_add_hashtable(struct tdb_layout *layout,
...
@@ -17,6 +17,9 @@ void tdb_layout_add_hashtable(struct tdb_layout *layout,
#endif
#endif
struct
tdb_context
*
tdb_layout_get
(
struct
tdb_layout
*
layout
,
struct
tdb_context
*
tdb_layout_get
(
struct
tdb_layout
*
layout
,
union
tdb_attribute
*
attr
);
union
tdb_attribute
*
attr
);
void
tdb_layout_write
(
struct
tdb_layout
*
layout
,
union
tdb_attribute
*
attr
,
const
char
*
filename
);
void
tdb_layout_free
(
struct
tdb_layout
*
layout
);
void
tdb_layout_free
(
struct
tdb_layout
*
layout
);
enum
layout_type
{
enum
layout_type
{
...
@@ -62,7 +65,6 @@ union tdb_layout_elem {
...
@@ -62,7 +65,6 @@ union tdb_layout_elem {
};
};
struct
tdb_layout
{
struct
tdb_layout
{
const
char
*
filename
;
unsigned
int
num_elems
;
unsigned
int
num_elems
;
union
tdb_layout_elem
*
elem
;
union
tdb_layout_elem
*
elem
;
};
};
...
...
ccan/tdb2/test/run-03-coalesce.c
View file @
79d603a5
...
@@ -32,11 +32,14 @@ int main(int argc, char *argv[])
...
@@ -32,11 +32,14 @@ int main(int argc, char *argv[])
key
=
tdb_mkdata
(
"hello"
,
5
);
key
=
tdb_mkdata
(
"hello"
,
5
);
/* No coalescing can be done due to EOF */
/* No coalescing can be done due to EOF */
layout
=
new_tdb_layout
(
"run-03-coalesce.tdb"
);
layout
=
new_tdb_layout
();
tdb_layout_add_freetable
(
layout
);
tdb_layout_add_freetable
(
layout
);
len
=
1024
;
len
=
1024
;
tdb_layout_add_free
(
layout
,
len
,
0
);
tdb_layout_add_free
(
layout
,
len
,
0
);
tdb
=
tdb_layout_get
(
layout
,
&
tap_log_attr
);
tdb_layout_write
(
layout
,
&
tap_log_attr
,
"run-03-coalesce.tdb"
);
/* NOMMAP is for lockcheck. */
tdb
=
tdb_open
(
"run-03-coalesce.tdb"
,
TDB_NOMMAP
,
O_RDWR
,
0
,
&
tap_log_attr
);
ok1
(
tdb_check
(
tdb
,
NULL
,
NULL
)
==
0
);
ok1
(
tdb_check
(
tdb
,
NULL
,
NULL
)
==
0
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
1
].
base
.
off
)
==
len
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
1
].
base
.
off
)
==
len
);
...
@@ -55,11 +58,14 @@ int main(int argc, char *argv[])
...
@@ -55,11 +58,14 @@ int main(int argc, char *argv[])
tdb_layout_free
(
layout
);
tdb_layout_free
(
layout
);
/* No coalescing can be done due to used record */
/* No coalescing can be done due to used record */
layout
=
new_tdb_layout
(
"run-03-coalesce.tdb"
);
layout
=
new_tdb_layout
();
tdb_layout_add_freetable
(
layout
);
tdb_layout_add_freetable
(
layout
);
tdb_layout_add_free
(
layout
,
1024
,
0
);
tdb_layout_add_free
(
layout
,
1024
,
0
);
tdb_layout_add_used
(
layout
,
key
,
data
,
6
);
tdb_layout_add_used
(
layout
,
key
,
data
,
6
);
tdb
=
tdb_layout_get
(
layout
,
&
tap_log_attr
);
tdb_layout_write
(
layout
,
&
tap_log_attr
,
"run-03-coalesce.tdb"
);
/* NOMMAP is for lockcheck. */
tdb
=
tdb_open
(
"run-03-coalesce.tdb"
,
TDB_NOMMAP
,
O_RDWR
,
0
,
&
tap_log_attr
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
1
].
base
.
off
)
==
1024
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
1
].
base
.
off
)
==
1024
);
ok1
(
tdb_check
(
tdb
,
NULL
,
NULL
)
==
0
);
ok1
(
tdb_check
(
tdb
,
NULL
,
NULL
)
==
0
);
...
@@ -78,11 +84,14 @@ int main(int argc, char *argv[])
...
@@ -78,11 +84,14 @@ int main(int argc, char *argv[])
tdb_layout_free
(
layout
);
tdb_layout_free
(
layout
);
/* Coalescing can be done due to two free records, then EOF */
/* Coalescing can be done due to two free records, then EOF */
layout
=
new_tdb_layout
(
"run-03-coalesce.tdb"
);
layout
=
new_tdb_layout
();
tdb_layout_add_freetable
(
layout
);
tdb_layout_add_freetable
(
layout
);
tdb_layout_add_free
(
layout
,
1024
,
0
);
tdb_layout_add_free
(
layout
,
1024
,
0
);
tdb_layout_add_free
(
layout
,
2048
,
0
);
tdb_layout_add_free
(
layout
,
2048
,
0
);
tdb
=
tdb_layout_get
(
layout
,
&
tap_log_attr
);
tdb_layout_write
(
layout
,
&
tap_log_attr
,
"run-03-coalesce.tdb"
);
/* NOMMAP is for lockcheck. */
tdb
=
tdb_open
(
"run-03-coalesce.tdb"
,
TDB_NOMMAP
,
O_RDWR
,
0
,
&
tap_log_attr
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
1
].
base
.
off
)
==
1024
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
1
].
base
.
off
)
==
1024
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
2
].
base
.
off
)
==
2048
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
2
].
base
.
off
)
==
2048
);
ok1
(
tdb_check
(
tdb
,
NULL
,
NULL
)
==
0
);
ok1
(
tdb_check
(
tdb
,
NULL
,
NULL
)
==
0
);
...
@@ -104,12 +113,15 @@ int main(int argc, char *argv[])
...
@@ -104,12 +113,15 @@ int main(int argc, char *argv[])
tdb_layout_free
(
layout
);
tdb_layout_free
(
layout
);
/* Coalescing can be done due to two free records, then data */
/* Coalescing can be done due to two free records, then data */
layout
=
new_tdb_layout
(
"run-03-coalesce.tdb"
);
layout
=
new_tdb_layout
();
tdb_layout_add_freetable
(
layout
);
tdb_layout_add_freetable
(
layout
);
tdb_layout_add_free
(
layout
,
1024
,
0
);
tdb_layout_add_free
(
layout
,
1024
,
0
);
tdb_layout_add_free
(
layout
,
512
,
0
);
tdb_layout_add_free
(
layout
,
512
,
0
);
tdb_layout_add_used
(
layout
,
key
,
data
,
6
);
tdb_layout_add_used
(
layout
,
key
,
data
,
6
);
tdb
=
tdb_layout_get
(
layout
,
&
tap_log_attr
);
tdb_layout_write
(
layout
,
&
tap_log_attr
,
"run-03-coalesce.tdb"
);
/* NOMMAP is for lockcheck. */
tdb
=
tdb_open
(
"run-03-coalesce.tdb"
,
TDB_NOMMAP
,
O_RDWR
,
0
,
&
tap_log_attr
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
1
].
base
.
off
)
==
1024
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
1
].
base
.
off
)
==
1024
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
2
].
base
.
off
)
==
512
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
2
].
base
.
off
)
==
512
);
ok1
(
tdb_check
(
tdb
,
NULL
,
NULL
)
==
0
);
ok1
(
tdb_check
(
tdb
,
NULL
,
NULL
)
==
0
);
...
@@ -130,12 +142,15 @@ int main(int argc, char *argv[])
...
@@ -130,12 +142,15 @@ int main(int argc, char *argv[])
tdb_layout_free
(
layout
);
tdb_layout_free
(
layout
);
/* Coalescing can be done due to three free records, then EOF */
/* Coalescing can be done due to three free records, then EOF */
layout
=
new_tdb_layout
(
"run-03-coalesce.tdb"
);
layout
=
new_tdb_layout
();
tdb_layout_add_freetable
(
layout
);
tdb_layout_add_freetable
(
layout
);
tdb_layout_add_free
(
layout
,
1024
,
0
);
tdb_layout_add_free
(
layout
,
1024
,
0
);
tdb_layout_add_free
(
layout
,
512
,
0
);
tdb_layout_add_free
(
layout
,
512
,
0
);
tdb_layout_add_free
(
layout
,
256
,
0
);
tdb_layout_add_free
(
layout
,
256
,
0
);
tdb
=
tdb_layout_get
(
layout
,
&
tap_log_attr
);
tdb_layout_write
(
layout
,
&
tap_log_attr
,
"run-03-coalesce.tdb"
);
/* NOMMAP is for lockcheck. */
tdb
=
tdb_open
(
"run-03-coalesce.tdb"
,
TDB_NOMMAP
,
O_RDWR
,
0
,
&
tap_log_attr
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
1
].
base
.
off
)
==
1024
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
1
].
base
.
off
)
==
1024
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
2
].
base
.
off
)
==
512
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
2
].
base
.
off
)
==
512
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
3
].
base
.
off
)
==
256
);
ok1
(
free_record_length
(
tdb
,
layout
->
elem
[
3
].
base
.
off
)
==
256
);
...
...
ccan/tdb2/test/run-50-multiple-freelists.c
View file @
79d603a5
...
@@ -21,7 +21,7 @@ int main(int argc, char *argv[])
...
@@ -21,7 +21,7 @@ int main(int argc, char *argv[])
data
=
tdb_mkdata
(
"world"
,
5
);
data
=
tdb_mkdata
(
"world"
,
5
);
/* Create a TDB with three free tables. */
/* Create a TDB with three free tables. */
layout
=
new_tdb_layout
(
NULL
);
layout
=
new_tdb_layout
();
tdb_layout_add_freetable
(
layout
);
tdb_layout_add_freetable
(
layout
);
tdb_layout_add_freetable
(
layout
);
tdb_layout_add_freetable
(
layout
);
tdb_layout_add_freetable
(
layout
);
tdb_layout_add_freetable
(
layout
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment