duplicate code in source3/lib/ctdb_conn.c

Amitay Isaacs amitay at gmail.com
Wed Nov 19 16:33:38 MST 2014


Hi Richard,

On Thu, Nov 20, 2014 at 9:46 AM, Richard Sharpe <realrichardsharpe at gmail.com
> wrote:

> Hi folks,
>
> In reading through the above code I have found about six copies of the
> following code:
>
>         r.hdr.length = offsetof(struct ctdb_req_message, data) + buflen;
>         r.hdr.ctdb_magic = CTDB_MAGIC;
>         r.hdr.ctdb_version = CTDB_PROTOCOL;
>         r.hdr.generation = 1;
>         r.hdr.operation  = CTDB_REQ_MESSAGE;
>         r.hdr.destnode   = dst_vnn;
>         r.hdr.srcnode    = conn->our_vnn;
>         r.hdr.reqid      = 0;
>         r.srvid          = dst_srvid;
>         r.datalen        = buflen;
>
>         DEBUG(10, ("ctdbd_messaging_send: Sending ctdb packet\n"));
>         ctdb_packet_dump(&r.hdr);
>
>         iov[0].iov_base = &r;
>         iov[0].iov_len = offsetof(struct ctdb_req_message, data);
>         iov[1].iov_base = discard_const_p(uint8_t, buf);
>         iov[1].iov_len = buflen;
>
>         nwritten = write_data_iov(conn->fd, iov, ARRAY_SIZE(iov));
>         if (nwritten == -1) {
>                 DEBUG(3, ("write_data_iov failed: %s\n", strerror(errno)));
>                 cluster_fatal("cluster dispatch daemon msg write error\n");
>         }
>
>
> Sure, there are some minor differences, and in only one of them we set
> the generation number, but surely we could use a function or a macro
> to initialize the hdr and send the message rather than duplicating so
> much code?
>
>
I am currently working on libctdb to implement wrapper routines that will
do the job of filling in protocol structures.  That way the CTDB protocol
is one place and hopefully easier to replace with proper marshalling rather
than existing "structs on wire" approach.  You can see the work in progress
in my ctdb-libctdb branch.

Amitay.


More information about the samba-technical mailing list