[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] help cman-using applications avoid casts: const-correctness



Hello,

In trying to avoid some warnings in lvm2, I made some internal interfaces
"const-correct" (adding "const" attributes where it makes sense).
That ended up conflicting with the declaration of the "void *buf"
cman_send_data parameter in /usr/include/libcman.h:

    int cman_send_data(cman_handle_t handle, void *buf, int len,
                       int flags, uint8_t port, int nodeid);

because the caller declared its corresponding argument to be a
"const void *" pointer.  I could have cast away the caller's "const",
but that's no good either, from a maintenance standpoint.

So here's my attempt to dtrt, and fix the underlying problem in libcman.h:

2007-04-27  Jim Meyering  <jim meyering net>

	* lib/libcman.c (cman_set_version, cman_send_data):
	(cman_barrier_register, cman_barrier_change, cman_barrier_wait):
	(cman_barrier_delete): Make pointer parameters "const", as appropriate.
	(send_message): Update declaration, to reflect now-"const" *inbuf
	pointer, and add an internal cast-away-const.
	(info_call): Likewise.
	* lib/libcman.h: Update prototypes.

Index: lib/libcman.c
===================================================================
RCS file: /cvs/cluster/cluster/cman/lib/libcman.c,v
retrieving revision 1.33
diff -u -p -r1.33 libcman.c
--- lib/libcman.c	5 Jan 2007 10:30:53 -0000	1.33
+++ lib/libcman.c	27 Apr 2007 13:23:52 -0000
@@ -1,7 +1,7 @@
 /******************************************************************************
 *******************************************************************************
 **
-**  Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
+**  Copyright (C) 2004-2007 Red Hat, Inc.  All rights reserved.
 **
 **  This library is free software; you can redistribute it and/or
 **  modify it under the terms of the GNU Lesser General Public
@@ -250,7 +250,7 @@ static int loopy_writev(int fd, struct i
 }


-static int send_message(struct cman_handle *h, int msgtype, void *inbuf, int inlen)
+static int send_message(struct cman_handle *h, int msgtype, const void *inbuf, int inlen)
 {
 	struct sock_header header;
 	size_t len;
@@ -268,7 +268,7 @@ static int send_message(struct cman_hand
 	if (inbuf)
 	{
 		iov[1].iov_len = inlen;
-		iov[1].iov_base = inbuf;
+		iov[1].iov_base = (void *) inbuf;
 		iovlen++;
 	}

@@ -279,7 +279,7 @@ static int send_message(struct cman_hand
 }

 /* Does something similar to the ioctl calls */
-static int info_call(struct cman_handle *h, int msgtype, void *inbuf, int inlen, void *outbuf, int outlen)
+static int info_call(struct cman_handle *h, int msgtype, const void *inbuf, int inlen, void *outbuf, int outlen)
 {
 	if (send_message(h, msgtype, inbuf, inlen))
 		return -1;
@@ -752,7 +752,7 @@ int cman_get_version(cman_handle_t handl
 	return info_call(h, CMAN_CMD_GET_VERSION, NULL, 0, version, sizeof(cman_version_t));
 }

-int cman_set_version(cman_handle_t handle, cman_version_t *version)
+int cman_set_version(cman_handle_t handle, const cman_version_t *version)
 {
 	struct cman_handle *h = (struct cman_handle *)handle;
 	VALIDATE_HANDLE(h);
@@ -841,7 +841,7 @@ int cman_get_extra_info(cman_handle_t ha
 	return info_call(h, CMAN_CMD_GETEXTRAINFO, NULL, 0, info, maxlen);
 }

-int cman_send_data(cman_handle_t handle, void *buf, int len, int flags, uint8_t port, int nodeid)
+int cman_send_data(cman_handle_t handle, const void *buf, int len, int flags, uint8_t port, int nodeid)
 {
 	struct cman_handle *h = (struct cman_handle *)handle;
 	struct iovec iov[2];
@@ -859,7 +859,7 @@ int cman_send_data(cman_handle_t handle,
 	iov[0].iov_len = sizeof(header);
 	iov[0].iov_base = &header;
 	iov[1].iov_len = len;
-	iov[1].iov_base = buf;
+	iov[1].iov_base = (void *) buf;

 	return loopy_writev(h->fd, iov, 2);
 }
@@ -892,7 +892,7 @@ int cman_end_recv_data(cman_handle_t han
 }


-int cman_barrier_register(cman_handle_t handle, char *name, int flags, int nodes)
+int cman_barrier_register(cman_handle_t handle, const char *name, int flags, int nodes)
 {
 	struct cman_handle *h = (struct cman_handle *)handle;
 	struct cl_barrier_info binfo;
@@ -913,7 +913,7 @@ int cman_barrier_register(cman_handle_t 
 }


-int cman_barrier_change(cman_handle_t handle, char *name, int flags, int arg)
+int cman_barrier_change(cman_handle_t handle, const char *name, int flags, int arg)
 {
 	struct cman_handle *h = (struct cman_handle *)handle;
 	struct cl_barrier_info binfo;
@@ -934,7 +934,7 @@ int cman_barrier_change(cman_handle_t ha

 }

-int cman_barrier_wait(cman_handle_t handle, char *name)
+int cman_barrier_wait(cman_handle_t handle, const char *name)
 {
 	struct cman_handle *h = (struct cman_handle *)handle;
 	struct cl_barrier_info binfo;
@@ -952,7 +952,7 @@ int cman_barrier_wait(cman_handle_t hand
 	return info_call(h, CMAN_CMD_BARRIER, &binfo, sizeof(binfo), NULL, 0);
 }

-int cman_barrier_delete(cman_handle_t handle, char *name)
+int cman_barrier_delete(cman_handle_t handle, const char *name)
 {
 	struct cman_handle *h = (struct cman_handle *)handle;
 	struct cl_barrier_info binfo;
Index: lib/libcman.h
===================================================================
RCS file: /cvs/cluster/cluster/cman/lib/libcman.h,v
retrieving revision 1.29
diff -u -p -r1.29 libcman.h
--- lib/libcman.h	5 Oct 2006 07:48:33 -0000	1.29
+++ lib/libcman.h	27 Apr 2007 13:23:52 -0000
@@ -1,7 +1,7 @@
 /******************************************************************************
 *******************************************************************************
 **
-**  Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
+**  Copyright (C) 2004-2007 Red Hat, Inc.  All rights reserved.
 **
 **  This library is free software; you can redistribute it and/or
 **  modify it under the terms of the GNU Lesser General Public
@@ -321,7 +321,7 @@ int cman_get_extra_info(cman_handle_t ha

 /* Change the config file version. This should be needed much less now, as cman will
    re-read the config file if a new node joins with a new config versoin */
-int cman_set_version(cman_handle_t handle, cman_version_t *version);
+int cman_set_version(cman_handle_t handle, const cman_version_t *version);

 /* Deprecated in favour of cman_shutdown(). Use cman_tool anyway please. */
 int cman_leave_cluster(cman_handle_t handle, int reason);
@@ -363,7 +363,7 @@ int cman_shutdown(cman_handle_t, int fla
  * cman_start_recv_data() is like a bind(), and marks the port
  * as "listening". See cman_is_listening() above.
  */
-int cman_send_data(cman_handle_t handle, void *buf, int len, int flags, uint8_t port, int nodeid);
+int cman_send_data(cman_handle_t handle, const void *buf, int len, int flags, uint8_t port, int nodeid);
 int cman_start_recv_data(cman_handle_t handle, cman_datacallback_t, uint8_t port);
 int cman_end_recv_data(cman_handle_t handle);

@@ -372,10 +372,10 @@ int cman_end_recv_data(cman_handle_t han
  * Here for backwards compatibility. Most of the things you would achieve
  * with this can now be better done using openAIS services or just messaging.
  */
-int cman_barrier_register(cman_handle_t handle, char *name, int flags, int nodes);
-int cman_barrier_change(cman_handle_t handle, char *name, int flags, int arg);
-int cman_barrier_wait(cman_handle_t handle, char *name);
-int cman_barrier_delete(cman_handle_t handle, char *name);
+int cman_barrier_register(cman_handle_t handle, const char *name, int flags, int nodes);
+int cman_barrier_change(cman_handle_t handle, const char *name, int flags, int arg);
+int cman_barrier_wait(cman_handle_t handle, const char *name);
+int cman_barrier_delete(cman_handle_t handle, const char *name);

 /*
  * Add your own quorum device here, needs an admin socket


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]