summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Rockai <prockai@redhat.com>2012-09-26 14:44:03 +0200
committerPetr Rockai <prockai@redhat.com>2012-09-26 17:26:23 +0200
commit662a2122f6224b5404d9f1276868bc3069766c49 (patch)
treeab23d37501e416629a1c8063e8a67f86bef87a0a
parent4ece923a4b8a38fd794ac1cc83d887747db6edda (diff)
downloadlvm2-662a2122f6224b5404d9f1276868bc3069766c49.tar.gz
lvm2-662a2122f6224b5404d9f1276868bc3069766c49.tar.xz
lvm2-662a2122f6224b5404d9f1276868bc3069766c49.zip
libdaemon: Split daemon-shared.[hc] into daemon-io.[hc] and config-util.[hc].
-rw-r--r--daemons/lvmetad/lvmetad-core.c3
-rw-r--r--include/.symlinks.in3
-rw-r--r--lib/cache/lvmetad.h2
-rw-r--r--libdaemon/client/Makefile.in2
-rw-r--r--libdaemon/client/config-util.c (renamed from libdaemon/client/daemon-shared.c)79
-rw-r--r--libdaemon/client/config-util.h (renamed from libdaemon/client/daemon-shared.h)12
-rw-r--r--libdaemon/client/daemon-client.c4
-rw-r--r--libdaemon/client/daemon-io.c99
-rw-r--r--libdaemon/client/daemon-io.h30
-rw-r--r--libdaemon/server/daemon-server.c3
10 files changed, 143 insertions, 94 deletions
diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c
index 6c2303df..0c39a778 100644
--- a/daemons/lvmetad/lvmetad-core.c
+++ b/daemons/lvmetad/lvmetad-core.c
@@ -15,7 +15,8 @@
#define _XOPEN_SOURCE 500 /* pthread */
#include "configure.h"
-#include "daemon-shared.h"
+#include "daemon-io.h"
+#include "config-util.h"
#include "daemon-server.h"
#include "daemon-log.h"
diff --git a/include/.symlinks.in b/include/.symlinks.in
index bd0eba7d..e94ff849 100644
--- a/include/.symlinks.in
+++ b/include/.symlinks.in
@@ -61,7 +61,8 @@
@top_srcdir@/lib/report/report.h
@top_srcdir@/lib/uuid/uuid.h
@top_srcdir@/libdaemon/client/daemon-client.h
-@top_srcdir@/libdaemon/client/daemon-shared.h
+@top_srcdir@/libdaemon/client/daemon-io.h
+@top_srcdir@/libdaemon/client/config-util.h
@top_srcdir@/libdm/libdevmapper.h
@top_srcdir@/libdm/misc/dm-ioctl.h
@top_srcdir@/libdm/misc/dm-logging.h
diff --git a/lib/cache/lvmetad.h b/lib/cache/lvmetad.h
index 60110a00..10c4b139 100644
--- a/lib/cache/lvmetad.h
+++ b/lib/cache/lvmetad.h
@@ -15,7 +15,7 @@
#ifndef _LVM_METAD_H
#define _LVM_METAD_H
-#include "daemon-shared.h" // XXX
+#include "config-util.h"
struct volume_group;
struct cmd_context;
diff --git a/libdaemon/client/Makefile.in b/libdaemon/client/Makefile.in
index 4d8c436f..d608816a 100644
--- a/libdaemon/client/Makefile.in
+++ b/libdaemon/client/Makefile.in
@@ -15,6 +15,6 @@ top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
LIB_STATIC = libdaemonclient.a
-SOURCES = daemon-shared.c daemon-client.c
+SOURCES = daemon-io.c config-util.c daemon-client.c
include $(top_builddir)/make.tmpl
diff --git a/libdaemon/client/daemon-shared.c b/libdaemon/client/config-util.c
index e6f17a03..25731398 100644
--- a/libdaemon/client/daemon-shared.c
+++ b/libdaemon/client/config-util.c
@@ -18,86 +18,9 @@
#include <unistd.h>
#include "dm-logging.h"
-#include "daemon-shared.h"
+#include "config-util.h"
#include "libdevmapper.h"
-/*
- * Read a single message from a (socket) filedescriptor. Messages are delimited
- * by blank lines. This call will block until all of a message is received. The
- * memory will be allocated from heap. Upon error, all memory is freed and the
- * buffer pointer is set to NULL.
- *
- * See also write_buffer about blocking (read_buffer has identical behaviour).
- */
-int read_buffer(int fd, char **buffer) {
- int bytes = 0;
- int buffersize = 32;
- char *new;
- *buffer = dm_malloc(buffersize + 1);
-
- while (1) {
- int result = read(fd, (*buffer) + bytes, buffersize - bytes);
- if (result > 0) {
- bytes += result;
- if (!strncmp((*buffer) + bytes - 4, "\n##\n", 4)) {
- *(*buffer + bytes - 4) = 0;
- break; /* success, we have the full message now */
- }
- if (bytes == buffersize) {
- buffersize += 1024;
- if (!(new = realloc(*buffer, buffersize + 1)))
- goto fail;
- *buffer = new;
- }
- continue;
- }
- if (result == 0) {
- errno = ECONNRESET;
- goto fail; /* we should never encounter EOF here */
- }
- if (result < 0 && errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
- goto fail;
- /* TODO call select here if we encountered EAGAIN/EWOULDBLOCK/EINTR */
- }
- return 1;
-fail:
- dm_free(*buffer);
- *buffer = NULL;
- return 0;
-}
-
-/*
- * Write a buffer to a filedescriptor. Keep trying. Blocks (even on
- * SOCK_NONBLOCK) until all of the write went through.
- *
- * TODO use select on EWOULDBLOCK/EAGAIN/EINTR to avoid useless spinning
- */
-int write_buffer(int fd, const char *buffer, int length) {
- static const char terminate[] = "\n##\n";
- int done = 0;
- int written = 0;
-write:
- while (1) {
- int result = write(fd, buffer + written, length - written);
- if (result > 0)
- written += result;
- if (result < 0 && errno != EWOULDBLOCK && errno != EAGAIN && errno != EINTR)
- return 0; /* too bad */
- if (written == length) {
- if (done)
- return 1;
- else
- break; /* done */
- }
- }
-
- buffer = terminate;
- length = 4;
- written = 0;
- done = 1;
- goto write;
-}
-
char *format_buffer_v(const char *head, va_list ap)
{
char *buffer, *old;
diff --git a/libdaemon/client/daemon-shared.h b/libdaemon/client/config-util.h
index acb71c6b..ae5e5569 100644
--- a/libdaemon/client/daemon-shared.h
+++ b/libdaemon/client/config-util.h
@@ -12,22 +12,14 @@
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _LVM_DAEMON_SHARED_H
-#define _LVM_DAEMON_SHARED_H
+#ifndef _LVM_DAEMON_CONFIG_UTIL_H
+#define _LVM_DAEMON_CONFIG_UTIL_H
#include "configure.h"
#include "libdevmapper.h"
-#define _REENTRANT
-#define _GNU_SOURCE
-#define _FILE_OFFSET_BITS 64
-
-/* TODO function names */
-
#include <stdarg.h>
-int read_buffer(int fd, char **buffer);
-int write_buffer(int fd, const char *buffer, int length);
char *format_buffer_v(const char *head, va_list ap);
char *format_buffer(const char *head, ...);
diff --git a/libdaemon/client/daemon-client.c b/libdaemon/client/daemon-client.c
index 2de970ac..e34a2a00 100644
--- a/libdaemon/client/daemon-client.c
+++ b/libdaemon/client/daemon-client.c
@@ -12,8 +12,10 @@
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "daemon-shared.h"
+#include "daemon-io.h"
+#include "config-util.h"
#include "daemon-client.h"
+#include "dm-logging.h"
#include <sys/un.h>
#include <sys/socket.h>
diff --git a/libdaemon/client/daemon-io.c b/libdaemon/client/daemon-io.c
new file mode 100644
index 00000000..4af9343f
--- /dev/null
+++ b/libdaemon/client/daemon-io.c
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2011-2012 Red Hat, Inc.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "daemon-io.h"
+#include "dm-logging.h"
+#include "libdevmapper.h"
+
+/*
+ * Read a single message from a (socket) filedescriptor. Messages are delimited
+ * by blank lines. This call will block until all of a message is received. The
+ * memory will be allocated from heap. Upon error, all memory is freed and the
+ * buffer pointer is set to NULL.
+ *
+ * See also write_buffer about blocking (read_buffer has identical behaviour).
+ */
+int read_buffer(int fd, char **buffer) {
+ int bytes = 0;
+ int buffersize = 32;
+ char *new;
+ *buffer = dm_malloc(buffersize + 1);
+
+ while (1) {
+ int result = read(fd, (*buffer) + bytes, buffersize - bytes);
+ if (result > 0) {
+ bytes += result;
+ if (!strncmp((*buffer) + bytes - 4, "\n##\n", 4)) {
+ *(*buffer + bytes - 4) = 0;
+ break; /* success, we have the full message now */
+ }
+ if (bytes == buffersize) {
+ buffersize += 1024;
+ if (!(new = realloc(*buffer, buffersize + 1)))
+ goto fail;
+ *buffer = new;
+ }
+ continue;
+ }
+ if (result == 0) {
+ errno = ECONNRESET;
+ goto fail; /* we should never encounter EOF here */
+ }
+ if (result < 0 && errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
+ goto fail;
+ /* TODO call select here if we encountered EAGAIN/EWOULDBLOCK/EINTR */
+ }
+ return 1;
+fail:
+ dm_free(*buffer);
+ *buffer = NULL;
+ return 0;
+}
+
+/*
+ * Write a buffer to a filedescriptor. Keep trying. Blocks (even on
+ * SOCK_NONBLOCK) until all of the write went through.
+ *
+ * TODO use select on EWOULDBLOCK/EAGAIN/EINTR to avoid useless spinning
+ */
+int write_buffer(int fd, const char *buffer, int length) {
+ static const char terminate[] = "\n##\n";
+ int done = 0;
+ int written = 0;
+write:
+ while (1) {
+ int result = write(fd, buffer + written, length - written);
+ if (result > 0)
+ written += result;
+ if (result < 0 && errno != EWOULDBLOCK && errno != EAGAIN && errno != EINTR)
+ return 0; /* too bad */
+ if (written == length) {
+ if (done)
+ return 1;
+ else
+ break; /* done */
+ }
+ }
+
+ buffer = terminate;
+ length = 4;
+ written = 0;
+ done = 1;
+ goto write;
+}
diff --git a/libdaemon/client/daemon-io.h b/libdaemon/client/daemon-io.h
new file mode 100644
index 00000000..e6e5f062
--- /dev/null
+++ b/libdaemon/client/daemon-io.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2011-2012 Red Hat, Inc.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _LVM_DAEMON_IO_H
+#define _LVM_DAEMON_IO_H
+
+#include "configure.h"
+#include "libdevmapper.h"
+
+#define _REENTRANT
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+
+/* TODO function names */
+
+int read_buffer(int fd, char **buffer);
+int write_buffer(int fd, const char *buffer, int length);
+
+#endif /* _LVM_DAEMON_SHARED_H */
diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c
index 50bf0656..b15a7cc9 100644
--- a/libdaemon/server/daemon-server.c
+++ b/libdaemon/server/daemon-server.c
@@ -10,7 +10,8 @@
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "daemon-shared.h"
+#include "daemon-io.h"
+#include "config-util.h"
#include "daemon-server.h"
#include "daemon-log.h"