1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-26 10:04:02 +03:00

55 Commits

Author SHA1 Message Date
Ronnie Sahlberg
fcd98a7e59 LIBCTDB: add support for traverse
(This used to be ctdb commit 9463e04038ba36792583f83bd95c1af322dc283a)
2011-01-14 17:38:56 +11:00
Ronnie Sahlberg
1859cde18d LIBCTDB uninitialized inqueue element
From Michael Anderson,
initialize the inqueue element of the ctdb structure to NULL,
else it might be used uninitialized and cause a segv.

(This used to be ctdb commit 775d02180b825ae32d6536eaf2059884d5fed9f4)
2011-01-11 07:40:57 +11:00
Ronnie Sahlberg
f815237f8f libctdb
fix a compile problem after renaming a structure field

(This used to be ctdb commit f44c02f45dbc13e3cc2e89ee1c96bd0d57042fcc)
2010-12-10 14:19:53 +11:00
Ronnie Sahlberg
e42fc0d4f5 LibCTDB
Add an input queue where we keep received pdus we have not yet processed
This allows us to perform SYNC calls from an ASYNC callback

(This used to be ctdb commit c111e98d3ad7bd3d09f4081e9bb1443d3722672f)
2010-12-10 13:42:25 +11:00
Ronnie Sahlberg
22ea35f17d adda GETPUBLICIPS control to libctdb and use this in the test example
enhance the test example to show the new releaseip/takeip messages

(This used to be ctdb commit 21cc57883e6c02b0e037211b26d1d866d5d7f03d)
2010-09-15 14:58:11 +10:00
Ronnie Sahlberg
a2c874bd61 Implement a new function GETNODEMAP in libctdb.
This function returns a pointer to a nodemap structure.

The returned structure must later be freed by calling ctdb_free_nodemap().

Move the definition of ctdb_sock_addr from ctdb_client.h to ctdb_protocol.h

Move the definition of the node flags, ctdb_node_and_flags and ctdb_node_map from ctdb_private.h to ctdb_protocol.h

Add both sync and async example for ctdb_getnodemap to the test application libctdb/tst.c

(This used to be ctdb commit 31c10eb2b337fd7d8a97a1f9e69b0e7570fec71d)
2010-09-13 14:32:11 +10:00
Ronnie Sahlberg
0e5be63bca update the example for the new signature of
ctdb_set_message_handler_send()

(This used to be ctdb commit 6aabe52d5ba629291aa630bc96a2b74dcecc5209)
2010-08-18 10:18:35 +10:00
Rusty Russell
a65cb6a9ae libctdb: add synchronous message handling and unregister, with tests.
It turns out that we *do* want a separate private arg for the message
handler and the completion callback, so we change that.

We also fix the prototypes of the remove_message functions as we
implement them.

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


(This used to be ctdb commit 332375246eccd95da626f434f6d49dd9458a9787)
2010-08-09 15:41:32 +09:30
Rusty Russell
7525493264 libctdb: test: run.sh script
This is a script which starts up a fake ctdbd and runs the libctdb
test suite.

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


(This used to be ctdb commit 67ca040b07713d83385db63489c887f7156b7853)
2010-06-21 16:09:16 +09:30
Rusty Russell
505e481588 libctdb: test: add readrecordlock support
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


(This used to be ctdb commit 1a23581c70a0c8c3b9c8fd4651ce1b2bb4464f97)
2010-06-21 16:06:00 +09:30
Rusty Russell
0be60b6a7a libctdb: test: add database save and restore
Once we do operations which alter the TDBs, we need to restore them to
pristine state after a failed child dies.

The method used here is a terrible hack: it should at least do a
tdb_lockall() on the database before blatting it.

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


(This used to be ctdb commit d48ec16bd2b4932442d95fc43bea52baa0425501)
2010-06-21 15:00:46 +09:30
Rusty Russell
d2def0ee1f libctdb: test: --no-failtest
Sometimes you just want to test that the basic test case is sane,
without all the failure paths being tested.

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


(This used to be ctdb commit be7c0bffb0d924c3e72753045d5b85ce90407579)
2010-06-21 14:48:54 +09:30
Rusty Russell
b0a8fd19ff libctdb: test: improve logging of failure paths
We include the file and line which called the functions, so the printed
failure path now looks like:

	[malloc(ctdb.c:144)]:1:S[socket(ctdb.c:168)]:1:S...

The form is:
    [ <function> ( <caller> ) ] : <input line> : <result>

<function> is the function which is called (eg. malloc).
<caller> is the file and line number which called <function>.
<input line> is the 1-based line number in the input which we were up to.
<result> is 'S' (success) or 'F' (failure).

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


(This used to be ctdb commit 5fb6da30b5b5a8b761c8ab9a8124b87b759ef055)
2010-06-21 14:57:11 +09:30
Rusty Russell
fee11bf13b libctdb: test: logging enhancement
Make children log through a pipe to the parent, which then spits it out
only if the child has a problem.

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


(This used to be ctdb commit 8ac006cf6c6cbfd3fe1606178eb0f0127d33f632)
2010-06-21 15:02:05 +09:30
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