summaryrefslogtreecommitdiffstats
path: root/daemons/clvmd/clvmd-singlenode.c
diff options
context:
space:
mode:
authorMike Snitzer <snitzer@redhat.com>2010-03-26 15:45:36 +0000
committerMike Snitzer <snitzer@redhat.com>2010-03-26 15:45:36 +0000
commit217cb1aa840cb2c717f9c0f1e422fe868e32f837 (patch)
tree451a95991eee4d24afb21e16418b3b6b0da06d19 /daemons/clvmd/clvmd-singlenode.c
parent7b0f529d3e125d568599c4eed004c23a22ca97af (diff)
downloadlvm2-217cb1aa840cb2c717f9c0f1e422fe868e32f837.tar.gz
lvm2-217cb1aa840cb2c717f9c0f1e422fe868e32f837.tar.xz
lvm2-217cb1aa840cb2c717f9c0f1e422fe868e32f837.zip
Use a real socket for singlenode clvmd to fix clvmd's high cpu load.
Diffstat (limited to 'daemons/clvmd/clvmd-singlenode.c')
-rw-r--r--daemons/clvmd/clvmd-singlenode.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/daemons/clvmd/clvmd-singlenode.c b/daemons/clvmd/clvmd-singlenode.c
index ead20312..c7114f26 100644
--- a/daemons/clvmd/clvmd-singlenode.c
+++ b/daemons/clvmd/clvmd-singlenode.c
@@ -17,6 +17,7 @@
#include <netinet/in.h>
#include <sys/un.h>
+#include <sys/socket.h>
#include <unistd.h>
#include <fcntl.h>
#include <configure.h>
@@ -31,18 +32,37 @@
#include "lvm-functions.h"
#include "clvmd.h"
+static const char SINGLENODE_CLVMD_SOCKNAME[] = "\0singlenode_clvmd";
static int listen_fd = -1;
static int init_comms()
{
- listen_fd = open("/dev/null", O_RDWR);
+ struct sockaddr_un addr;
- if (listen_fd < 0)
+ listen_fd = socket(PF_UNIX, SOCK_STREAM, 0);
+ if (listen_fd < 0) {
+ DEBUGLOG("Can't create local socket: %s\n", strerror(errno));
return -1;
-
+ }
/* Set Close-on-exec */
fcntl(listen_fd, F_SETFD, 1);
+ memset(&addr, 0, sizeof(addr));
+ memcpy(addr.sun_path, SINGLENODE_CLVMD_SOCKNAME,
+ sizeof(SINGLENODE_CLVMD_SOCKNAME));
+ addr.sun_family = AF_UNIX;
+
+ if (bind(listen_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+ DEBUGLOG("Can't bind local socket: %s\n", strerror(errno));
+ close(listen_fd);
+ return -1;
+ }
+ if (listen(listen_fd, 10) < 0) {
+ DEBUGLOG("Can't listen local socket: %s\n", strerror(errno));
+ close(listen_fd);
+ return -1;
+ }
+
return 0;
}