[PATCH] ctdb-daemon: Handle out-of-memory when setting recovery lock file
Michael Adam
obnox at samba.org
Thu Jan 8 17:08:06 MST 2015
reviewed by me (although the "and" in the commit message
would argue for splitting the patch in two..)- pushing
On 2015-01-07 at 18:14 +1100, Martin Schwenke wrote:
> Review and push appreciated, thanks.
>
> peace & happiness,
> martin
> >From 9e9c387a87e36843acb5ad08c343ca7368190378 Mon Sep 17 00:00:00 2001
> From: Martin Schwenke <martin at meltin.net>
> Date: Tue, 9 Dec 2014 13:40:23 +1100
> Subject: [PATCH] ctdb-daemon: Handle out-of-memory when setting recovery lock
> file
>
> Log a message when the reclock file actually changes and avoid a
> memory allocation when it doesn't change.
>
> Signed-off-by: Martin Schwenke <martin at meltin.net>
> ---
> ctdb/server/ctdb_control.c | 34 ++++++++++++++++++++++++++--------
> 1 file changed, 26 insertions(+), 8 deletions(-)
>
> diff --git a/ctdb/server/ctdb_control.c b/ctdb/server/ctdb_control.c
> index 49bc986..9d835e8 100644
> --- a/ctdb/server/ctdb_control.c
> +++ b/ctdb/server/ctdb_control.c
> @@ -519,17 +519,35 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
> outdata->dsize = strlen(ctdb->recovery_lock_file) + 1;
> }
> return 0;
> - case CTDB_CONTROL_SET_RECLOCK_FILE:
> - ctdb->tunable.verify_recovery_lock = 0;
> - if (ctdb->recovery_lock_file != NULL) {
> - talloc_free(ctdb->recovery_lock_file);
> - ctdb->recovery_lock_file = NULL;
> + case CTDB_CONTROL_SET_RECLOCK_FILE: {
> + char *t;
> +
> + if (indata.dsize == 0) {
> + TALLOC_FREE(ctdb->recovery_lock_file);
> + return 0;
> + }
> +
> + /* Return silent success if unchanged. Recovery
> + * master updates all nodes on each recovery - we
> + * don't need the extra memory allocation or log
> + * message each time. */
> + if (strcmp(discard_const(indata.dptr),
> + ctdb->recovery_lock_file) == 0) {
> + return 0;
> }
> - if (indata.dsize > 0) {
> - ctdb->recovery_lock_file = talloc_strdup(ctdb, discard_const(indata.dptr));
> - ctdb->tunable.verify_recovery_lock = 1;
> +
> + t = talloc_strdup(ctdb, discard_const(indata.dptr));
> + if (t == NULL) {
> + DEBUG(DEBUG_ERR, ("Out of memory in SET_RECLOCK_FILE\n"));
> + return -1;
> }
> +
> + talloc_free(ctdb->recovery_lock_file);
> + ctdb->recovery_lock_file = t;
> + DEBUG(DEBUG_NOTICE, ("Updated recovery lock file to %s\n", t));
> +
> return 0;
> + }
>
> case CTDB_CONTROL_STOP_NODE:
> CHECK_CONTROL_DATA_SIZE(0);
> --
> 2.1.4
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20150109/81bf41bf/attachment.pgp>
More information about the samba-technical
mailing list