tdb: factor read_record_on_left() out of tdb_free()

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
tdb: increase readability of read_record_on_left()

by using early returns and better variable names,
and reducing indentation.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
tdb: reduce indentation in tdb_free() for merging left

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
tdb: fix debug message in tdb_free()

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
tdb: factor merge_with_left_record() out of tdb_free()

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
tdb: improve comments for tdb_free().

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
tdb: add utility function check_merge_with_left_record()

Check whether the record left of a given freelist record is
also a freelist record, and if so, merge the two records.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
tdb: simplify tdb_free() using check_merge_with_left_record()

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
tdb: add utility function check_merge_ptr_with_left_record()

Variant of check_merge_with_left_record() that reads the record
itself if necessary.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
tdb: add tdb_freelist_merge_adjacent()

This is intended to be called to reduce the fragmentation in the
freelist. This is to make up the deficiency of the freelist
to be not doubly linked. If the freelist were doubly linked,
we could easily avoid the creation of adjacent freelist entries.
But with the current singly linked list, it is only possible
to cheaply merge a new free record into a freelist entry on the left,
not on the right...

This can be called periodically, e.g. in the vacuuming process
of a ctdb cluster.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
tdb: use tdb_freelist_merge_adjacent in tdb_freelist_size()

So that we automatically defragment the free list when freelist_size is called
(unless the database is read only).

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
tdb: add "freelist_size" sub-command to tdbtool

With the new code, this has the side effect of
merging adjacent records in the freelist if the
database is not read-only.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
tdb: defragment the freelist in tdb_allocate_from_freelist()

While we are traversing the freelist anyways, merge a record
with the left if it is also a free list record.

That partially makes up for the fragmentation introduced by
the lack of merging with right records in tdb_free().

Note there is a potential slight downside:
If the left record we merge the current record into was earlier
in the chain and has hence already been met in traverse,
then we can not use the enlarged record even if it might be
a new best fit.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>

Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Thu Jun 26 12:16:03 CEST 2014 on sn-devel-104
smb2: Fix smb2_lease_state

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>

Autobuild-User(master): Michael Adam <obnox@samba.org>
Autobuild-Date(master): Thu Jun 26 17:30:00 CEST 2014 on sn-devel-104
dbwrap: Print wait times with full precision

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
s3-shadow-copy2: Add extreme debug output to shadow_copy2_strip_snapshot

This is sooo hairy to debug when things go wrong :-(

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
s3-shadow-copy2: Fix dir/@GMT-2012.10.15-13.48.43 form of paths

The previous clause in shadow_copy2_strip_snapshot would only handle @GMT-
at the end of a pathname if it was the *only* pathname component. XP
seems to send @GMT- at the end under certain circumstances even with a
path prefix.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
s3-shadow-copy2: Remove TODO and fix comments

The patch "s3-shadow-copy2: Fix dir/@GMT-2012.10.15-13.48.43 form of
paths" takes care of a case marked as TODO, remove it and adjust the
comments accordingly.

Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
s3-shadow-copy2: Fix incorrect case submounts

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
s3-shadow-copy2: Add more debugs

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>