[Pacemaker] Remote Access not Working

Andrew Beekhof andrew at beekhof.net
Fri Nov 20 06:36:38 EST 2009


On Fri, Nov 20, 2009 at 11:17 AM, Colin <colin.hch at gmail.com> wrote:
> Hi,
>
> this is looking better again: A remote "cibadmin -Q" is now doing the
> right thing, however a remote "crm_mon" is still _not_ working
> correctly.
>
> Let's see, now that I should know where to look ... the function
> cib_recv_plaintext() in lib/common/remote.c looks a bit suspicious to
> me:
>
> - The "if (len == 0)" check will never be true because len is
> initialised to 512 and then only grows.
> - The assumption that a partial read (wrt. the buffer) signals no more
> data is IMO not valid.

It is if you didn't get a signal.
But I agree the code needs a cleanup.

I went with: http://hg.clusterlabs.org/pacemaker/stable-1.0/rev/5acf9f2e9c9e

> With the following patch I can at least get a "crm_mon -1rf" to do the
> right thing:
>
> diff -ur Pacemaker-1-0-f7a8250d23fc/lib/common/remote.c
> Pacemaker-my/lib/common/remote.c
> --- Pacemaker-1-0-f7a8250d23fc/lib/common/remote.c      2009-11-19
> 21:12:53.000000000 +0100
> +++ Pacemaker-my/lib/common/remote.c    2009-11-20 10:52:36.000000000 +0100
> @@ -220,33 +220,29 @@
>  char*
>  cib_recv_plaintext(int sock)
>  {
> -       int last = 0;
>        char* buf = NULL;
> -       int chunk_size = 512;
> -       int len = chunk_size;
> +       ssize_t buf_size = 512;
> +       ssize_t len = 0;
>
> -       crm_malloc0(buf, chunk_size);
> +       crm_malloc0(buf, buf_size);
>
>        while(1) {
> -               int rc = recv(sock, buf+last, chunk_size, 0);
> +               ssize_t rc = recv(sock, buf+len, buf_size-len, 0);
>                if (rc == 0) {
>                        if(len == 0) {
>                                goto bail;
>                        }
>                        return buf;
>
> -               } else if(rc > 0 && rc < chunk_size) {
> -                       return buf;
> -
> -               } else if(rc == chunk_size) {
> -                       last = len;
> -                       len += chunk_size;
> -                       crm_realloc(buf, len);
> -                       CRM_ASSERT(buf != NULL);
> +               } else if(rc > 0) {
> +                 len += rc;
> +                 if (len == buf_size) {
> +                   crm_realloc(buf, buf_size += 512);  /* Should do
> exponential growth for amortized constant time? */
> +                   CRM_ASSERT(buf != NULL);
> +                 }
>                }
> -
>                if(rc < 0 && errno != EINTR) {
> -                       crm_perror(LOG_ERR,"Error receiving message: %d", rc);
> +                 crm_perror(LOG_ERR,"Error receiving message: %d", (int)rc);
>                        goto bail;
>                }
>        }
>
> And that is as far as I can get with crm_mon, as it doesn't supports
> continuous update via remote access?
>
> static int cib_remote_set_connection_dnotify(
>    cib_t *cib, void (*dnotify)(gpointer user_data))
> {
>    return cib_NOTSUPPORTED;
> }

No, thats something else.
Remote notifications should work, I'll test that today.




More information about the Pacemaker mailing list