Rev 712: added tdb_wipe_all() function in
http://samba.org/~tridge/ctdb
tridge at samba.org
tridge at samba.org
Sat Jan 5 01:08:41 GMT 2008
------------------------------------------------------------
revno: 712
revision-id:tridge at samba.org-20080105010841-n49gmcacwn2x1fdc
parent: tridge at samba.org-20080104225518-kv0c3jrl6yd1hyr3
committer: Andrew Tridgell <tridge at samba.org>
branch nick: tridge.stable
timestamp: Sat 2008-01-05 12:08:41 +1100
message:
added tdb_wipe_all() function
modified:
lib/tdb/common/tdb.c tdb.c-20070220022425-m1wibgjq7n5hahs6-9
=== modified file 'lib/tdb/common/tdb.c'
--- a/lib/tdb/common/tdb.c 2008-01-04 22:33:39 +0000
+++ b/lib/tdb/common/tdb.c 2008-01-05 01:08:41 +0000
@@ -236,7 +236,7 @@
}
/* actually delete an entry in the database given the offset */
-int tdb_do_delete(struct tdb_context *tdb, tdb_off_t rec_ptr, struct list_struct*rec)
+int tdb_do_delete(struct tdb_context *tdb, tdb_off_t rec_ptr, struct list_struct *rec)
{
tdb_off_t last_ptr, i;
struct list_struct lastrec;
@@ -670,3 +670,57 @@
{
tdb->flags |= TDB_SEQNUM;
}
+
+
+/*
+ wipe the entire database, deleting all records. This can be done
+ very fast by using a global lock. The entire data portion of the
+ file becomes a single entry in the freelist.
+ */
+int tdb_wipe_all(struct tdb_context *tdb)
+{
+ int i;
+ tdb_off_t offset = 0;
+ ssize_t data_len;
+
+ if (tdb_lockall(tdb) != 0) {
+ return -1;
+ }
+
+ /* wipe the hashes */
+ for (i=0;i<tdb->header.hash_size;i++) {
+ if (tdb_ofs_write(tdb, TDB_HASH_TOP(i), &offset) == -1) {
+ TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_wipe_all: failed to write hash %d\n", i));
+ goto failed;
+ }
+ }
+
+ /* wipe the freelist */
+ if (tdb_ofs_write(tdb, FREELIST_TOP, &offset) == -1) {
+ TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_wipe_all: failed to write freelist\n"));
+ goto failed;
+ }
+
+ /* add all the rest of the file to the freelist */
+ data_len = (tdb->map_size - TDB_DATA_START(tdb->header.hash_size)) - sizeof(struct list_struct);
+ if (data_len > 0) {
+ struct list_struct rec;
+ memset(&rec,'\0',sizeof(rec));
+ rec.rec_len = data_len;
+ if (tdb_free(tdb, TDB_DATA_START(tdb->header.hash_size), &rec) == -1) {
+ TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_wipe_all: failed to add free record\n"));
+ goto failed;
+ }
+ }
+
+ if (tdb_unlockall(tdb) != 0) {
+ TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_wipe_all: failed to unlock\n"));
+ goto failed;
+ }
+
+ return 0;
+
+failed:
+ tdb_unlockall(tdb);
+ return -1;
+}
More information about the samba-cvs
mailing list