1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00
Commit Graph

91 Commits

Author SHA1 Message Date
Rusty Russell
4c0f3dcffe libctdb: test infrastructure
This introduces 'ctdb-test', a program for testing libctdb.  It takes
commands on standard input (with reduced functionality) or an input file.

It still needs some cleaning up, but you can uncover a bug in libctdb
today simply by running a simple attachdb test:

	$ ctdb-test tests/attachdb1.txt

It will print out a crash, and the path of successful and failed
operations which lead to it:

	...
	Child signalled 11 on failure path: [malloc]:1:S[socket]:1:S[connect]:1:S[malloc]:1:S[malloc]:1:S[malloc]:1:S[malloc]:4:S[malloc]:4:F

Feed that failure path into ctdb-test using --failpath (under a debugger):

	gdb --args ctdb-test tests/attachdb1.txt --failpath=[malloc]:1:S[socket]:1:S[connect]:1:S[malloc]:1:S[malloc]:1:S[malloc]:1:S[malloc]:4:S[malloc]:4:F

And you hit the exact error.

It is based on the fork-to-fail model of nfsim.  The relevant parts are
from page 154 of the proceedings of 2005 Ottawa Linux Symposium Volume II:
	http://www.linuxsymposium.org/2005/linuxsymposium_procv2.pdf

Or our presentation of same (from slide 21):
	http://ozlabs.org/~jk/projects/nfsim/nfsim.sxi

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit b4aab4199a57898877b6545a54f212087ed4b35a)
2010-07-16 14:12:40 +09:30
Rusty Russell
cfe0edc0b9 libctdb: implement synchronous readrecordlock interface.
Because this doesn't use a generic callback, it's not quite as trivial
as the other sync wrappers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit 1f20b938d46d4fcd50d2b473c1ab8dc31d178d2d)
2010-06-21 14:47:34 +09:30
Rusty Russell
b93e65eaf7 libctdb: implement ctdb_disconnect and ctdb_detachdb
These are important for testing, since we can easily tell if we
leak memory if there are outstanding allocations after calling
these.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit 18a212aa40d0ff9ff59775c6fcf9dc973e991460)
2010-06-18 15:35:52 +09:30
Rusty Russell
3d126e8c14 libctdb: fix io_elem resource leak on realloc failure.
Found by nfsim.

I knew about this, but as we stop when it happens anyway I didn't fix
it.  But it bugs nfsim, so fix it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit 936b02443d36306407d6a26e8037cf31e3190b32)
2010-06-18 15:48:48 +09:30
Rusty Russell
9f6d34150d libctdb: fix writerecord() to actually write the record.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit 680ee6afaa89f21115a1bf33a8b9e7e92084a1a1)
2010-06-21 14:45:37 +09:30
Rusty Russell
f2a33c1b51 libctdb: ctdb_service() never returns < 0
Found by ctdb-test.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit 0e8210f19edf2ae14154afb85d9b96951881f31f)
2010-06-18 15:13:54 +09:30
Rusty Russell
841518d677 libctdb: check ctdb_request_free & ctdb_cancel used appropriately.
Since I made this mistake myself, we should check for it.

We could have one function that does both, but from a user's point of
view they are very different and it's quite possibly a bug if they
think the request is finished/unfinished when it's not.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit 70f6ed2634fb10749cdad3deffa96a1aa439c235)
2010-06-18 15:15:11 +09:30
Rusty Russell
8e82448a5a libctdb: synchronous should be using ctdb_cancel to kill unfinished requests.
Found by ctdb-test.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit cd6b2f46075bfb64561496960af7fc2e95500e52)
2010-06-18 15:15:27 +09:30
Rusty Russell
b72620814c libctdb: fix uninitialized field usage on ctdb_attach failure path
Found by ctdb-test.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit 54c1036090d930c19231038ca861297153c1d0cf)
2010-06-18 15:47:23 +09:30
Rusty Russell
af40302f7b libctdb: removed unused lock field from struct ctdb_db
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit 256653a223c48ed932ce85f89fc2c2dda14f8c27)
2010-06-18 15:47:14 +09:30
Rusty Russell
e169d689b9 libctdb: connect TDB logging to our logging
A simple connector function, made a bit more complex because TDB adds
a '\n' and we don't.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit ae5b89dca00ca080c70868430fa54ba07bd6f5f4)
2010-06-08 18:09:42 +09:30
Rusty Russell
662807b807 libctdb: always check header hasn't changed on local tdb
The code on which this is based could alter the header: a normal client
can't.  If we use this differently later we can change this.  For the
moment it's a nice extra check.

We optimize out the record write altogether when the record hasn't
changed, rather than just suppressing the seqnum update.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit 2638dbae7bf1a35ed37802e35e179e435a5d622a)
2010-06-08 18:10:36 +09:30
Rusty Russell
7589b58138 libctdb: more bool conversion, and accompany lock by ctdb_db in API
I missed some int->bool conversions previously, particularly the
return of ctdb_writerecord().

By always handing functions ctdb_connection or ctdb_db, we keep it
consistent with the rest of the API and can do extra lock consistency
checks.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit 3f939956ddd693cba6ea5c655288f4f5ca95f768)
2010-06-08 17:11:40 +09:30
Rusty Russell
866cca9637 libctdb: clarify logging levels
Now we have more messages, it seems to make sense to document their usage
and make them consistent.

In particular, LOG_CRIT for internal libctdb problems, LOG_ALERT for
API misuse.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit a6fed3f577c7ec51df38ed15ecb9db6ea2ae7c8f)
2010-06-08 16:53:17 +09:30
Rusty Russell
7aa68b02b2 libctdb: use magic to detect free/invalid locks
Rather than using a binary, we use a magic value for locking.  We also
split out the "dont have the lock yet" from the "do have the lock"
paths for clarity and extra checking.

This should detect a superset of the previous case, even if they free
(and reuse) the lock memory.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit dc081d40051b9204bb38e4de7dfe8d78656593d0)
2010-06-08 16:52:23 +09:30
Ronnie Sahlberg
a530344b84 In ctdb_writerecord()
Verify that the lock is still held and refuse the write otherwise.

We have to guarantee that we dont write to an unlocked record.

If we write to a record after it has been released, the record may have
already migrated off the node, in which case we get a DMASTER split brain for this record. (These application bugs are incredibly hard to track down)

(This used to be ctdb commit f62c7e44dc303f274bbc1dd59fad2167e72a2af0)
2010-06-05 15:43:01 +10:00
Ronnie Sahlberg
b9e5c8a47b Split ctdb_release_lock() into a function to release the locvk and another function to free the data structures.
This allows us to keep the datastructure valid after the lock has been released by the application and we can trap and warn when the application is accessing the lock after it has been released. I.e. application bugs.

(This used to be ctdb commit 463a266205f145cd9c4c36b9c59d3747eeef0e2e)
2010-06-05 15:38:11 +10:00
Ronnie Sahlberg
2e2211575a Must initialize ctdb->locks or else bad things happen
(This used to be ctdb commit 9ec0b9bb148327a40e439d9c643c9d2ff93ce598)
2010-06-05 14:27:46 +10:00
Rusty Russell
3510980049 libctdb: documentation
Full documentation for all the functions.

This looks longer than it is, because it sorts them into async and
sync parts, and also renames some formal parameters.

Added TODO to libctdb directory to track our plans.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit 108e9c2450876a9f8821aa7efd5be971eee5afd3)
2010-06-04 20:30:08 +09:30
Rusty Russell
3a569c14bc libctdb: use bool in API
Return bool instead of -1/0; that's what the young kids are doing
these days!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit e285b5d5a9d4fbc4f75dbb237d2fcdbd84f2d605)
2010-06-04 20:19:25 +09:30
Rusty Russell
62df8f9a91 libctdb: track lock for each ctdb_db, complain if they hold too long.
In particular, this stops them grabbing two (with wrappers so we can
enhance this logic once we support threads), and warns them if they
re-enter ctdb_service() holding a lock (you are not supposed to block!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit c620cfbad3b5f0d6330ef47f572d4ade08e169e8)
2010-06-04 19:41:42 +09:30
Rusty Russell
d77a1e9399 patch libctdb-use-logging.patch
(This used to be ctdb commit fecb8a19e97f6e453066461b234acdb0946bbadd)
2010-06-04 20:27:06 +09:30
Rusty Russell
379fd4e606 libctdb: add logging infrastructure
This is based on Ronnie's work, merged with mine.  That means
errors are all my fault.

Differences from Ronnie's:
1) use syslog's LOG_ levels directly.
2) typesafe arg to log function, and use it (eg stderr) in helper function.
3) store fn in ctdb context, and expose ctdb_log_level directly thru API.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

(This used to be ctdb commit 86259aa395555aaf7b2fae7326caa2ea62961092)
2010-06-04 20:27:03 +09:30
Rusty Russell
cc8435852c libctdb: add ctdb arg to more functions.
This is going to help for logging, since we want it there.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

(This used to be ctdb commit 0786152472bc43efae4c896f7c6c07c6e080b9b2)
2010-06-04 16:54:08 +09:30
Ronnie Sahlberg
e8fb04de01 Readrecordlock changes:
Make the use of ctdb_release_lock() mandatory from the callback.

Split ctdb_release_lock() in two, release the tdb lock in the
ctdb_release_lock() function and move the freeing of the lock structure to ctdb_free_lock() which is private to libctdb.

When the callback returns, verify that the callback has actually released the lock and warn (FIXME) if not.

Update ctdb_writerecord to warn and fail (FIXME) if writing while the lock is not held.

(This used to be ctdb commit 87dc18a3a051da04685f14529c53c428d37c2912)
2010-06-04 14:47:06 +10:00
Ronnie Sahlberg
29c43d556c remove the global rrl_cb_called from the libctdb example
and psss it through the callback via private_data.

add a comment that the callback may sometimes have already been invoked
when the ctdb_readrecordlock_async() call returns
and that the application can use *private_data IF the application
needs to know if the callback has already triggered or not.

(This used to be ctdb commit 0ba458a91ba510215a9c8770286a68e19911515f)
2010-06-04 14:20:17 +10:00
Rusty Russell
94df6f322d libctdb: change callback for ctdb_readrecordlock.
After discussion with Ronnie, we decided to revisit this interface.  We use
the name ctdb_readrecordlock_async, as it is *not* always a send, and we
use a specific callback to avoid the "fake request" creation on the fast
path.

The request itself is never exposed: this means it can't be cancelled,
but we can revisit that later if need be.

This makes both use and implementation simpler.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

(This used to be ctdb commit 03b5546ae45a60ab41eb4f7159a45bfdbf959888)
2010-06-04 13:33:08 +09:30
Rusty Russell
5d0d51e77b libctdb: fix wrong argument being handed to callback on attachdb fail
When attachdb failed, we were handing the db, not the user-supplied
arg to the callback.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

(This used to be ctdb commit 8626b6d7d4e5c747b6bac9d5e5b2cd302b6e144c)
2010-06-04 13:34:06 +09:30
Ronnie Sahlberg
2d4b98381f ctdb_req_control contains 4 padding bytes. Create an explicit pad variable here and set it to 0 when creating a control to keep valgrind happy.
PDUs are padded to 8 byte boundary. If padding is used, memset it to 0
to keep valgrind happy.

(This used to be ctdb commit 8818d5c483558c0faa6a3923ed5e675fdcfc13af)
2010-06-02 16:49:05 +10:00
Ronnie Sahlberg
0844759964 Add the offsetof macro to libctdb
change all calls to new_ctdb_request() to use the offset macro to calculate the correct size (instead of allocating one byte too many and hoping the alignment padding saves us.)

(This used to be ctdb commit 07b395258ab08218e8eed3b4a52654925b85275c)
2010-06-02 15:13:32 +10:00
Ronnie Sahlberg
f94291c37d Make the call to free the request explicit in the callback
instead of implicit

(This used to be ctdb commit 573e4e2d2bd09dd9579150cce926de774a0b609c)
2010-06-02 13:49:34 +10:00
Ronnie Sahlberg
e999119d40 Automatically free the request once the callback has returned.
(This used to be ctdb commit 2b3904d3113737d57ac0ec78f33ad163ed7f623c)
2010-06-02 13:42:03 +10:00
Ronnie Sahlberg
212ee831b8 add a sync wrapper for the getpnn control
(This used to be ctdb commit 01c2acdf3cb29bb44c74d9d792cf1d3706534ad2)
2010-06-02 10:36:19 +10:00
Ronnie Sahlberg
2f188c6422 Update the tst.c example application for libctdb to
use the headers from /usr/include
and add a comment about how to compile it

(This used to be ctdb commit c0f38e0936c487b63964fd9cef7a9370f227275f)
2010-06-02 09:24:17 +10:00
Ronnie Sahlberg
cb5210043d add a gplv3 boilerplate to the example application for libctdb
(This used to be ctdb commit 53df35aff1e10201a38931bbb82fb266a38892c0)
2010-05-26 13:55:19 +10:00
Rusty Russell
bd8d302589 libctdb: tweak interface for readrecordlock
Previously we could hang in poll with the callback pending (since we
fake it): explicitly call it immediately.

Note: I experienced corruption using DLIST_ADD_END (ctdb->pnn was blatted
when adding to the message_handler list).  I switched them all to DLIST_ADD,
but maybe I'm using it wrong?

(This used to be ctdb commit 3727165f0d206999d2cfc2800ff8868640868c7c)
2010-05-24 13:52:17 +09:30
Rusty Russell
30f4d01df1 libctdb: uniform callbacks, _recv functions to pull out data.
This is a bit tricky for those cases where we need to do multiple or
zero I/Os (eg. attachdb and readrecordlock), but works well for the
simple cases.

(This used to be ctdb commit ebe4dd724338c156423cfdcc10a75b68c2084cde)
2010-05-24 13:17:36 +09:30
Rusty Russell
f45cf4a711 tst.c: update to Ronnie's latest
This provides a slightly more comprehensive test of the library.

(This used to be ctdb commit f36e891c00c63d5b9dfbaddacff86d9da72d3bb7)
2010-05-20 16:16:04 +09:30
Rusty Russell
1dc7f2c4f8 libctdb: first cut, supports getrecmaster only
This is a completely standalone library using only ctdb_protocol.h.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

Header from folded patch 'libctdb-message-handling.patch':

libctdb: add message handling to libctdb.

Now clients can send and receive ctdb messages.


(This used to be ctdb commit 732cf6ead4aa2fbefc2b81328171f52c8d935341)
2010-05-21 12:07:41 +09:30
Rusty Russell
7046a1ad0a libctdb: API changes from Ronnie's version
These simplifications mostly came up due to the implementation.

o Rename ctdb_context to ctdb_connection.
   We already have a ctdb_context internally in ctdbd; don't confuse them!
o Rename ctdb_handle to struct ctdb_request.
   From the user POV it's a request, and it's also useful internally to
   avoid implicit cast to/from void *.
o Rename ctdb_db_context to ctdb_db.
o Introduce ctdb_lock.
   This provides an explicit "lock object" you get from readrecordlock
   and have to hand to those functions which need you to hold a lock.
o status args are "int" not int32_t.
   Should this be a bool?
o Remove last traces on generic callback.
   Without semi-sync API, this doesn't help anything and loses type safety.
o Remove the semi-async API.
   We can add this later, but I think a sync and async API is enough for
   our poor users for the moment :)
o Registering a message handler also takes a callback.
   This way you can tell if it failed.  Not sure if this is overkill, but it's
   consistent.
o ctdb_service() takes an revents arg
   Strictly not necessary for a nonblocking fd, but nice to know if a
   read or write is possible.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

(This used to be ctdb commit 86e1f93df856f9627182ed0e18bfcff6866c0954)
2010-05-20 16:07:30 +09:30
Rusty Russell
bbfb992f55 libctdb: ctdb.h and tst.c from Ronnie
This imports ctdb.h and tst.c from Ronnie's work: it's a separate commit
for now to make the changes obvious.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

(This used to be ctdb commit 09f05cbfc883e5aac33d3781b163cde178ece4cf)
2010-05-20 16:01:28 +09:30