master - cleanup: dmeventd code simplified
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7b17dfed69e50e...
Commit: 7b17dfed69e50eabdc288f48a2fde16d4000709f
Parent: 341055ddb3bfaf3297aa068abf0d2412bc4cfd0b
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Mar 10 09:44:26 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 10 12:24:10 2014 +0100
cleanup: dmeventd code simplified
Improve readbility of code.
---
daemons/dmeventd/dmeventd.c | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 621ae36..343180d 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -466,7 +466,7 @@ static int _get_status(struct message_data *message_data)
int i, j;
int ret = -1;
int count = dm_list_size(&_thread_registry);
- int size = 0, current = 0;
+ int size = 0, current;
char *buffers[count];
char *message;
@@ -510,8 +510,8 @@ static int _get_status(struct message_data *message_data)
out:
for (j = 0; j < i; ++j)
dm_free(buffers[j]);
- return ret;
+ return ret;
}
static int _get_parameters(struct message_data *message_data) {
@@ -818,7 +818,7 @@ static struct dm_task *_get_device_status(struct thread_status *ts)
static void *_monitor_thread(void *arg)
{
struct thread_status *thread = arg;
- int wait_error = 0;
+ int wait_error;
struct dm_task *task;
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
@@ -1413,9 +1413,10 @@ static int _client_read(struct dm_event_fifos *fifos,
dm_free(msg->data);
msg->data = NULL;
msg->size = 0;
+ return 0;
}
- return bytes == size;
+ return 1;
}
/*
@@ -1528,7 +1529,7 @@ static int _do_process_request(struct dm_event_daemon_message *msg)
/* Only one caller at a time. */
static void _process_request(struct dm_event_fifos *fifos)
{
- int die = 0;
+ int die;
struct dm_event_daemon_message msg = { 0 };
/*
@@ -1538,8 +1539,7 @@ static void _process_request(struct dm_event_fifos *fifos)
if (!_client_read(fifos, &msg))
return;
- if (msg.cmd == DM_EVENT_CMD_DIE)
- die = 1;
+ die = (msg.cmd == DM_EVENT_CMD_DIE) ? 1 : 0;
/* _do_process_request fills in msg (if memory allows for
data, otherwise just cmd and size = 0) */
10 years, 1 month
master - cleanup: clvmd use struct initializers
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=341055ddb3bfaf...
Commit: 341055ddb3bfaf3297aa068abf0d2412bc4cfd0b
Parent: c44ede31a39598c30634ff7b20e45e4600df5d37
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Mar 8 22:58:37 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 10 12:24:10 2014 +0100
cleanup: clvmd use struct initializers
Simplify code, and use compiler capability to
initilize struct members on its own.
---
daemons/clvmd/clvmd.c | 24 ++++++++----------------
1 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c
index 43fecb6..1fc3694 100644
--- a/daemons/clvmd/clvmd.c
+++ b/daemons/clvmd/clvmd.c
@@ -1121,15 +1121,13 @@ static int verify_message(char *buf, int len)
static void dump_message(char *buf, int len)
{
- unsigned char row[8];
+ unsigned char row[8] = { 0 };
char str[9];
int i, j, pos = 0;
if (len > 128)
len = 128;
- memset(row, 0, sizeof(row));
-
for (i = 0; i < len; i++) {
row[pos++] = buf[i];
@@ -1247,9 +1245,7 @@ static int read_from_local_sock(struct local_client *thisfd)
int len;
int argslen;
int missing_len;
- char buffer[PIPE_BUF + 1];
-
- memset(buffer, 0, sizeof(buffer));
+ char buffer[PIPE_BUF + 1] = { 0 };
len = read(thisfd->fd, buffer, sizeof(buffer) - 1);
if (len == -1 && errno == EINTR)
@@ -1982,7 +1978,11 @@ static void send_version_message(void)
{
char message[sizeof(struct clvm_header) + sizeof(int) * 3];
struct clvm_header *msg = (struct clvm_header *) message;
- int version_nums[3];
+ int version_nums[3] = {
+ htonl(CLVMD_MAJOR_VERSION),
+ htonl(CLVMD_MINOR_VERSION),
+ htonl(CLVMD_PATCH_VERSION)
+ };
msg->cmd = CLVMD_CMD_VERSION;
msg->status = 0;
@@ -1990,10 +1990,6 @@ static void send_version_message(void)
msg->clientid = 0;
msg->arglen = sizeof(version_nums);
- version_nums[0] = htonl(CLVMD_MAJOR_VERSION);
- version_nums[1] = htonl(CLVMD_MINOR_VERSION);
- version_nums[2] = htonl(CLVMD_PATCH_VERSION);
-
memcpy(&msg->args, version_nums, sizeof(version_nums));
hton_clvm(msg);
@@ -2379,11 +2375,7 @@ static if_type_t get_cluster_type(void)
size_t namelen = sizeof(buf);
hdb_handle_t cluster_handle;
hdb_handle_t clvmd_handle;
- confdb_callbacks_t callbacks = {
- .confdb_key_change_notify_fn = NULL,
- .confdb_object_create_change_notify_fn = NULL,
- .confdb_object_delete_change_notify_fn = NULL
- };
+ confdb_callbacks_t callbacks = { 0 };
result = confdb_initialize (&handle, &callbacks);
if (result != CS_OK)
10 years, 1 month
master - cleanup: clvmd use else if
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c44ede31a39598...
Commit: c44ede31a39598c30634ff7b20e45e4600df5d37
Parent: 2cfe0840d2e33fd8aa1892aaf73498fac68040af
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Mar 8 22:57:31 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 10 12:24:09 2014 +0100
cleanup: clvmd use else if
When string already matches, skip rest of tests.
---
daemons/clvmd/clvmd.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c
index 0a8d591..43fecb6 100644
--- a/daemons/clvmd/clvmd.c
+++ b/daemons/clvmd/clvmd.c
@@ -2352,13 +2352,13 @@ static if_type_t parse_cluster_interface(char *ifname)
if (!strcmp(ifname, "auto"))
iface = IF_AUTO;
- if (!strcmp(ifname, "cman"))
+ else if (!strcmp(ifname, "cman"))
iface = IF_CMAN;
- if (!strcmp(ifname, "openais"))
+ else if (!strcmp(ifname, "openais"))
iface = IF_OPENAIS;
- if (!strcmp(ifname, "corosync"))
+ else if (!strcmp(ifname, "corosync"))
iface = IF_COROSYNC;
- if (!strcmp(ifname, "singlenode"))
+ else if (!strcmp(ifname, "singlenode"))
iface = IF_SINGLENODE;
return iface;
10 years, 1 month
master - cleanup: clvmd assign NULL to pointers
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=2cfe0840d2e33f...
Commit: 2cfe0840d2e33fd8aa1892aaf73498fac68040af
Parent: c824369fbdd93011a1daccbb7159d16f365dce50
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Mar 10 12:16:09 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 10 12:24:09 2014 +0100
cleanup: clvmd assign NULL to pointers
Use NULL when assigning to void*.
---
daemons/clvmd/clvmd-command.c | 7 +++----
daemons/clvmd/clvmd.c | 7 +++----
2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/daemons/clvmd/clvmd-command.c b/daemons/clvmd/clvmd-command.c
index 96eec92..611f6bf 100644
--- a/daemons/clvmd/clvmd-command.c
+++ b/daemons/clvmd/clvmd-command.c
@@ -307,9 +307,8 @@ int do_post_command(struct local_client *client)
init_test(0);
switch (header->cmd) {
case CLVMD_CMD_TEST:
- status =
- sync_unlock("CLVMD_TEST", (int) (long) client->bits.localsock.private);
- client->bits.localsock.private = 0;
+ status = sync_unlock("CLVMD_TEST", (int) (long) client->bits.localsock.private);
+ client->bits.localsock.private = NULL;
break;
case CLVMD_CMD_LOCK_LV:
@@ -350,7 +349,7 @@ void cmd_client_cleanup(struct local_client *client)
}
dm_hash_destroy(lock_hash);
- client->bits.localsock.private = 0;
+ client->bits.localsock.private = NULL;
}
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c
index c319013..0a8d591 100644
--- a/daemons/clvmd/clvmd.c
+++ b/daemons/clvmd/clvmd.c
@@ -724,9 +724,8 @@ static int local_pipe_callback(struct local_client *thisfd, char *buf,
log_sys_error("close", "local_pipe");
/* Clear out the cross-link */
- if (thisfd->bits.pipe.client != NULL)
- thisfd->bits.pipe.client->bits.localsock.pipe_client =
- NULL;
+ if (thisfd->bits.pipe.client)
+ thisfd->bits.pipe.client->bits.localsock.pipe_client = NULL;
/* Reap child thread */
if (thisfd->bits.pipe.threadid) {
@@ -1811,7 +1810,7 @@ next_pre:
}
pthread_mutex_unlock(&client->bits.localsock.mutex);
DEBUGLOG("Subthread finished\n");
- pthread_exit((void *) 0);
+ pthread_exit(NULL);
}
/* Process a command on the local node and store the result */
10 years, 1 month
master - cleanup: clvmd indent changes
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c824369fbdd930...
Commit: c824369fbdd93011a1daccbb7159d16f365dce50
Parent: 109564d6a50eaf3ece1bf38a6422dc2d2f642cf7
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Mar 10 12:15:26 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 10 12:24:09 2014 +0100
cleanup: clvmd indent changes
Improve readbility of clvmd code.
Remove some unneeded braces.
---
daemons/clvmd/clvmd-command.c | 1 -
daemons/clvmd/clvmd.c | 80 ++++++++++++++++++----------------------
2 files changed, 36 insertions(+), 45 deletions(-)
diff --git a/daemons/clvmd/clvmd-command.c b/daemons/clvmd/clvmd-command.c
index 1ed1513..96eec92 100644
--- a/daemons/clvmd/clvmd-command.c
+++ b/daemons/clvmd/clvmd-command.c
@@ -183,7 +183,6 @@ int do_command(struct local_client *client, struct clvm_header *msg, int msglen,
}
return status;
-
}
static int lock_vg(struct local_client *client)
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c
index 9ee5998..c319013 100644
--- a/daemons/clvmd/clvmd.c
+++ b/daemons/clvmd/clvmd.c
@@ -526,7 +526,8 @@ int main(int argc, char *argv[])
cluster_iface = get_cluster_type();
#ifdef USE_CMAN
- if ((cluster_iface == IF_AUTO || cluster_iface == IF_CMAN) && (clops = init_cman_cluster())) {
+ if ((cluster_iface == IF_AUTO || cluster_iface == IF_CMAN) &&
+ (clops = init_cman_cluster())) {
max_csid_len = CMAN_MAX_CSID_LEN;
max_cluster_message = CMAN_MAX_CLUSTER_MESSAGE;
max_cluster_member_name_len = CMAN_MAX_NODENAME_LEN;
@@ -535,7 +536,8 @@ int main(int argc, char *argv[])
#endif
#ifdef USE_COROSYNC
if (!clops)
- if (((cluster_iface == IF_AUTO || cluster_iface == IF_COROSYNC) && (clops = init_corosync_cluster()))) {
+ if (((cluster_iface == IF_AUTO || cluster_iface == IF_COROSYNC) &&
+ (clops = init_corosync_cluster()))) {
max_csid_len = COROSYNC_CSID_LEN;
max_cluster_message = COROSYNC_MAX_CLUSTER_MESSAGE;
max_cluster_member_name_len = COROSYNC_MAX_CLUSTER_MEMBER_NAME_LEN;
@@ -544,7 +546,8 @@ int main(int argc, char *argv[])
#endif
#ifdef USE_OPENAIS
if (!clops)
- if ((cluster_iface == IF_AUTO || cluster_iface == IF_OPENAIS) && (clops = init_openais_cluster())) {
+ if ((cluster_iface == IF_AUTO || cluster_iface == IF_OPENAIS) &&
+ (clops = init_openais_cluster())) {
max_csid_len = OPENAIS_CSID_LEN;
max_cluster_message = OPENAIS_MAX_CLUSTER_MESSAGE;
max_cluster_member_name_len = OPENAIS_MAX_CLUSTER_MEMBER_NAME_LEN;
@@ -708,9 +711,8 @@ static int local_pipe_callback(struct local_client *thisfd, char *buf,
if (len == -1 && errno == EINTR)
return 1;
- if (len == sizeof(int)) {
+ if (len == sizeof(int))
memcpy(&status, buffer, sizeof(int));
- }
DEBUGLOG("read on PIPE %d: %d bytes: status: %d\n",
thisfd->fd, len, status);
@@ -728,21 +730,19 @@ static int local_pipe_callback(struct local_client *thisfd, char *buf,
/* Reap child thread */
if (thisfd->bits.pipe.threadid) {
- if ((errno = pthread_join(thisfd->bits.pipe.threadid,
- &ret)))
+ if ((errno = pthread_join(thisfd->bits.pipe.threadid, &ret)))
log_sys_error("pthread_join", "");
thisfd->bits.pipe.threadid = 0;
- if (thisfd->bits.pipe.client != NULL)
- thisfd->bits.pipe.client->bits.localsock.
- threadid = 0;
+ if (thisfd->bits.pipe.client)
+ thisfd->bits.pipe.client->bits.localsock.threadid = 0;
}
return -1;
} else {
DEBUGLOG("background routine status was %d, sock_client=%p\n",
status, sock_client);
/* But has the client gone away ?? */
- if (sock_client == NULL) {
+ if (!sock_client) {
DEBUGLOG("Got PIPE response for dead client, ignoring it\n");
} else {
/* If error then just return that code */
@@ -785,9 +785,8 @@ static void timedout_callback(struct local_client *client, const char *csid,
pthread_mutex_lock(&client->bits.localsock.reply_mutex);
reply = client->bits.localsock.replies;
- while (reply && strcmp(reply->node, nodename) != 0) {
+ while (reply && strcmp(reply->node, nodename) != 0)
reply = reply->next;
- }
pthread_mutex_unlock(&client->bits.localsock.reply_mutex);
@@ -942,10 +941,8 @@ static void main_loop(int local_sock, int cmd_timeout)
expected_replies !=
thisfd->bits.localsock.num_replies) {
/* Send timed out message + replies we already have */
- DEBUGLOG
- ("Request timed-out (send: %ld, now: %ld)\n",
- thisfd->bits.localsock.sent_time,
- the_time);
+ DEBUGLOG("Request timed-out (send: %ld, now: %ld)\n",
+ thisfd->bits.localsock.sent_time, the_time);
thisfd->bits.localsock.all_success = 0;
@@ -1106,7 +1103,7 @@ static int verify_message(char *buf, int len)
default:
log_error("verify_message bad cmd %x", h->cmd);
return -1;
- };
+ }
/* TODO: we may be able to narrow len/flags/clientid/arglen checks based on cmd */
@@ -1127,12 +1124,11 @@ static void dump_message(char *buf, int len)
{
unsigned char row[8];
char str[9];
- int i, j, pos;
+ int i, j, pos = 0;
if (len > 128)
len = 128;
- pos = 0;
memset(row, 0, sizeof(row));
for (i = 0; i < len; i++) {
@@ -1476,6 +1472,7 @@ static int read_from_local_sock(struct local_client *thisfd)
&stack_attr, pre_and_post_thread, thisfd);
DEBUGLOG("Created pre&post thread, state = %d\n", status);
}
+
return len;
}
@@ -1560,6 +1557,7 @@ static int distribute_command(struct local_client *thisfd)
thisfd->bits.localsock.num_replies = 0;
add_to_lvmqueue(thisfd, inheader, len, NULL);
}
+
return 0;
}
@@ -1763,9 +1761,7 @@ static __attribute__ ((noreturn)) void *pre_and_post_thread(void *arg)
while (!client->bits.localsock.finished) {
/* Execute the code */
/* FIXME: usage of init_test() is unprotected as in do_command() */
- status = do_pre_command(client);
-
- if (status)
+ if ((status = do_pre_command(client)))
client->bits.localsock.all_success = 0;
DEBUGLOG("Writing status %d down pipe %d\n", status, pipe_fd);
@@ -1787,10 +1783,9 @@ static __attribute__ ((noreturn)) void *pre_and_post_thread(void *arg)
client->bits.localsock.state);
if (client->bits.localsock.state != POST_COMMAND &&
- !client->bits.localsock.finished) {
+ !client->bits.localsock.finished)
pthread_cond_wait(&client->bits.localsock.cond,
&client->bits.localsock.mutex);
- }
DEBUGLOG("Got post command condition...\n");
@@ -1832,7 +1827,7 @@ static int process_local_command(struct clvm_header *msg, int msglen,
DEBUGLOG("process_local_command: %s msg=%p, msglen =%d, client=%p\n",
decode_cmd(msg->cmd), msg, msglen, client);
- if (replybuf == NULL)
+ if (!replybuf)
return -1;
/* If remote flag is set, just set a successful status code. */
@@ -1846,24 +1841,22 @@ static int process_local_command(struct clvm_header *msg, int msglen,
client->bits.localsock.all_success = 0;
/* If we took too long then discard the reply */
- if (xid == client->xid) {
+ if (xid == client->xid)
add_reply_to_list(client, status, our_csid, replybuf, replylen);
- } else {
- DEBUGLOG
- ("Local command took too long, discarding xid %d, current is %d\n",
- xid, client->xid);
- }
+ else
+ DEBUGLOG("Local command took too long, discarding xid %d, current is %d\n",
+ xid, client->xid);
free(replybuf);
+
return status;
}
static int process_reply(const struct clvm_header *msg, int msglen, const char *csid)
{
- struct local_client *client = NULL;
+ struct local_client *client;
- client = find_client(msg->clientid);
- if (!client) {
+ if (!(client = find_client(msg->clientid))) {
DEBUGLOG("Got message for unknown client 0x%x\n",
msg->clientid);
log_error("Got message for unknown client 0x%x\n",
@@ -1875,13 +1868,13 @@ static int process_reply(const struct clvm_header *msg, int msglen, const char *
client->bits.localsock.all_success = 0;
/* Gather replies together for this client id */
- if (msg->xid == client->xid) {
+ if (msg->xid == client->xid)
add_reply_to_list(client, msg->status, csid, msg->args,
msg->arglen);
- } else {
+ else
DEBUGLOG("Discarding reply with old XID %d, current = %d\n",
msg->xid, client->xid);
- }
+
return 0;
}
@@ -2007,7 +2000,7 @@ static void send_version_message(void)
hton_clvm(msg);
clops->cluster_send_message(message, sizeof(message), NULL,
- "Error Sending version number");
+ "Error Sending version number");
}
/* Send a message to either a local client or another server */
@@ -2018,11 +2011,10 @@ static int send_message(void *buf, int msglen, const char *csid, int fd,
int ptr;
struct timespec delay;
struct timespec remtime;
-
int retry_cnt = 0;
/* Send remote messages down the cluster socket */
- if (csid == NULL || !ISLOCAL_CSID(csid)) {
+ if (!csid || !ISLOCAL_CSID(csid)) {
hton_clvm((struct clvm_header *) buf);
return clops->cluster_send_message(buf, msglen, csid, errtext);
}
@@ -2046,6 +2038,7 @@ static int send_message(void *buf, int msglen, const char *csid, int fd,
}
ptr += len;
}
+
return len;
}
@@ -2154,9 +2147,8 @@ static int add_to_lvmqueue(struct local_client *client, struct clvm_header *msg,
cmd->remote = 0;
}
- DEBUGLOG
- ("add_to_lvmqueue: cmd=%p. client=%p, msg=%p, len=%d, csid=%p, xid=%d\n",
- cmd, client, msg, msglen, csid, cmd->xid);
+ DEBUGLOG("add_to_lvmqueue: cmd=%p. client=%p, msg=%p, len=%d, csid=%p, xid=%d\n",
+ cmd, client, msg, msglen, csid, cmd->xid);
pthread_mutex_lock(&lvm_thread_mutex);
dm_list_add(&lvm_cmd_head, &cmd->list);
pthread_cond_signal(&lvm_thread_cond);
10 years, 1 month
master - cleanup: clvmd simplify loops
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=109564d6a50eaf...
Commit: 109564d6a50eaf3ece1bf38a6422dc2d2f642cf7
Parent: 3d23404081b264c7bfdd0668ee72fd3aa692c935
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Mar 10 12:15:41 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 10 12:24:09 2014 +0100
cleanup: clvmd simplify loops
Rewrite write loops to be more readable.
---
daemons/clvmd/clvmd.c | 26 ++++++++------------------
1 files changed, 8 insertions(+), 18 deletions(-)
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c
index c7ad2da..9ee5998 100644
--- a/daemons/clvmd/clvmd.c
+++ b/daemons/clvmd/clvmd.c
@@ -1771,16 +1771,11 @@ static __attribute__ ((noreturn)) void *pre_and_post_thread(void *arg)
DEBUGLOG("Writing status %d down pipe %d\n", status, pipe_fd);
/* Tell the parent process we have finished this bit */
- do {
- write_status = write(pipe_fd, &status, sizeof(int));
- if (write_status == sizeof(int))
+ while ((write_status = write(pipe_fd, &status, sizeof(int))) != sizeof(int))
+ if (write_status >=0 || (errno != EINTR && errno != EAGAIN)) {
+ log_error("Error sending to pipe: %m\n");
break;
- if (write_status < 0 &&
- (errno == EINTR || errno == EAGAIN))
- continue;
- log_error("Error sending to pipe: %m\n");
- break;
- } while(1);
+ }
if (status) {
client->bits.localsock.state = POST_COMMAND;
@@ -1803,16 +1798,11 @@ static __attribute__ ((noreturn)) void *pre_and_post_thread(void *arg)
status = 0;
do_post_command(client);
- do {
- write_status = write(pipe_fd, &status, sizeof(int));
- if (write_status == sizeof(int))
+ while ((write_status = write(pipe_fd, &status, sizeof(int))) != sizeof(int))
+ if (write_status >=0 || (errno != EINTR && errno != EAGAIN)) {
+ log_error("Error sending to pipe: %m\n");
break;
- if (write_status < 0 &&
- (errno == EINTR || errno == EAGAIN))
- continue;
- log_error("Error sending to pipe: %m\n");
- break;
- } while(1);
+ }
next_pre:
DEBUGLOG("Waiting for next pre command\n");
10 years, 1 month
master - cleanup: clvmd rewrite send_message
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3d23404081b264...
Commit: 3d23404081b264c7bfdd0668ee72fd3aa692c935
Parent: cbca815dc44e805d6e4cc138c28af73f1e47432a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Mar 8 23:14:46 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 10 12:24:09 2014 +0100
cleanup: clvmd rewrite send_message
Improve readability of code and make it clear what it tries
to achieve.
---
daemons/clvmd/clvmd.c | 57 +++++++++++++++++-------------------------------
1 files changed, 20 insertions(+), 37 deletions(-)
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c
index e8375a8..c7ad2da 100644
--- a/daemons/clvmd/clvmd.c
+++ b/daemons/clvmd/clvmd.c
@@ -2024,8 +2024,8 @@ static void send_version_message(void)
static int send_message(void *buf, int msglen, const char *csid, int fd,
const char *errtext)
{
- int len = 0;
- int saved_errno = 0;
+ int len;
+ int ptr;
struct timespec delay;
struct timespec remtime;
@@ -2035,43 +2035,26 @@ static int send_message(void *buf, int msglen, const char *csid, int fd,
if (csid == NULL || !ISLOCAL_CSID(csid)) {
hton_clvm((struct clvm_header *) buf);
return clops->cluster_send_message(buf, msglen, csid, errtext);
- } else {
- int ptr = 0;
-
- /* Make sure it all goes */
- do {
- if (retry_cnt > MAX_RETRIES)
- {
- errno = saved_errno;
- log_error("%s", errtext);
- errno = saved_errno;
- break;
- }
-
- len = write(fd, (char*)buf + ptr, msglen - ptr);
-
- if (len <= 0) {
- if (errno == EINTR)
- continue;
- if (errno == EAGAIN ||
- errno == EIO ||
- errno == ENOSPC) {
- saved_errno = errno;
- retry_cnt++;
-
- delay.tv_sec = 0;
- delay.tv_nsec = 100000;
- remtime.tv_sec = 0;
- remtime.tv_nsec = 0;
- (void) nanosleep (&delay, &remtime);
+ }
- continue;
- }
- log_error("%s", errtext);
- break;
+ /* Make sure it all goes */
+ for (ptr = 0; ptr < msglen;) {
+ if ((len = write(fd, (char*)buf + ptr, msglen - ptr)) <= 0) {
+ if (errno == EINTR)
+ continue;
+ if ((errno == EAGAIN || errno == EIO || errno == ENOSPC) &&
+ ++retry_cnt < MAX_RETRIES) {
+ delay.tv_sec = 0;
+ delay.tv_nsec = 100000;
+ remtime.tv_sec = 0;
+ remtime.tv_nsec = 0;
+ (void) nanosleep (&delay, &remtime);
+ continue;
}
- ptr += len;
- } while (ptr < msglen);
+ log_error("%s", errtext);
+ break;
+ }
+ ptr += len;
}
return len;
}
10 years, 1 month
master - cleanup: clvmd reindent lock_vg code
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=cbca815dc44e80...
Commit: cbca815dc44e805d6e4cc138c28af73f1e47432a
Parent: 7a6c0e2425432cf6aa690709a985f6208f930ef6
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Mar 7 20:24:46 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 10 12:24:09 2014 +0100
cleanup: clvmd reindent lock_vg code
Code had wrong indent level, improve readability.
---
daemons/clvmd/clvmd-command.c | 102 +++++++++++++++++++---------------------
1 files changed, 48 insertions(+), 54 deletions(-)
diff --git a/daemons/clvmd/clvmd-command.c b/daemons/clvmd/clvmd-command.c
index 5d93f38..1ed1513 100644
--- a/daemons/clvmd/clvmd-command.c
+++ b/daemons/clvmd/clvmd-command.c
@@ -188,60 +188,54 @@ int do_command(struct local_client *client, struct clvm_header *msg, int msglen,
static int lock_vg(struct local_client *client)
{
- struct dm_hash_table *lock_hash;
- struct clvm_header *header =
- (struct clvm_header *) client->bits.localsock.cmd;
- unsigned char lock_cmd;
- int lock_mode;
- char *args = header->node + strlen(header->node) + 1;
- int lkid;
- int status = 0;
- char *lockname;
-
- /* Keep a track of VG locks in our own hash table. In current
- practice there should only ever be more than two VGs locked
- if a user tries to merge lots of them at once */
- if (client->bits.localsock.private) {
- lock_hash = (struct dm_hash_table *)client->bits.localsock.private;
- }
- else {
- lock_hash = dm_hash_create(3);
- if (!lock_hash)
- return ENOMEM;
- client->bits.localsock.private = (void *)lock_hash;
- }
-
- lock_cmd = args[0] & (LCK_NONBLOCK | LCK_HOLD | LCK_SCOPE_MASK | LCK_TYPE_MASK);
- lock_mode = ((int)lock_cmd & LCK_TYPE_MASK);
- /* lock_flags = args[1]; */
- lockname = &args[2];
- DEBUGLOG("doing PRE command LOCK_VG '%s' at %x (client=%p)\n", lockname, lock_cmd, client);
-
- if (lock_mode == LCK_UNLOCK) {
-
- lkid = (int)(long)dm_hash_lookup(lock_hash, lockname);
- if (lkid == 0)
- return EINVAL;
-
- status = sync_unlock(lockname, lkid);
- if (status)
- status = errno;
- else
- dm_hash_remove(lock_hash, lockname);
- }
- else {
- /* Read locks need to be PR; other modes get passed through */
- if (lock_mode == LCK_READ)
- lock_mode = LCK_PREAD;
- status = sync_lock(lockname, lock_mode, (lock_cmd & LCK_NONBLOCK) ? LCKF_NOQUEUE : 0, &lkid);
- if (status)
- status = errno;
- else
- if (!dm_hash_insert(lock_hash, lockname, (void *)(long)lkid))
- return ENOMEM;
- }
-
- return status;
+ struct dm_hash_table *lock_hash;
+ struct clvm_header *header =
+ (struct clvm_header *) client->bits.localsock.cmd;
+ unsigned char lock_cmd;
+ int lock_mode;
+ char *args = header->node + strlen(header->node) + 1;
+ int lkid;
+ int status;
+ char *lockname;
+
+ /*
+ * Keep a track of VG locks in our own hash table. In current
+ * practice there should only ever be more than two VGs locked
+ * if a user tries to merge lots of them at once
+ */
+ if (!client->bits.localsock.private) {
+ if (!(lock_hash = dm_hash_create(3)))
+ return ENOMEM;
+ client->bits.localsock.private = (void *) lock_hash;
+ } else
+ lock_hash = (struct dm_hash_table *) client->bits.localsock.private;
+
+ lock_cmd = args[0] & (LCK_NONBLOCK | LCK_HOLD | LCK_SCOPE_MASK | LCK_TYPE_MASK);
+ lock_mode = ((int) lock_cmd & LCK_TYPE_MASK);
+ /* lock_flags = args[1]; */
+ lockname = &args[2];
+ DEBUGLOG("doing PRE command LOCK_VG '%s' at %x (client=%p)\n", lockname, lock_cmd, client);
+
+ if (lock_mode == LCK_UNLOCK) {
+ if (!(lkid = (int) (long) dm_hash_lookup(lock_hash, lockname)))
+ return EINVAL;
+
+ if ((status = sync_unlock(lockname, lkid)))
+ status = errno;
+ else
+ dm_hash_remove(lock_hash, lockname);
+ } else {
+ /* Read locks need to be PR; other modes get passed through */
+ if (lock_mode == LCK_READ)
+ lock_mode = LCK_PREAD;
+
+ if ((status = sync_lock(lockname, lock_mode, (lock_cmd & LCK_NONBLOCK) ? LCKF_NOQUEUE : 0, &lkid)))
+ status = errno;
+ else if (!dm_hash_insert(lock_hash, lockname, (void *) (long) lkid))
+ return ENOMEM;
+ }
+
+ return status;
}
10 years, 1 month
master - dmeventd: wakeup timeout thread earlier
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7a6c0e2425432c...
Commit: 7a6c0e2425432cf6aa690709a985f6208f930ef6
Parent: 2a9b62c7f9948238f4ba8f60546b2fb1ae44c2c6
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Mar 10 09:40:32 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 10 12:24:07 2014 +0100
dmeventd: wakeup timeout thread earlier
When the last entry in the timeout queue is unregistered,
wakeup sleeping condition, so the thread is deleted earlier.
So the thread resource is release earlier.
Also when monitored with tools like valgrind this eliminites reported
leak.
---
WHATS_NEW_DM | 1 +
daemons/dmeventd/dmeventd.c | 2 ++
2 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index e470cd2..4f67bc3 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.85 -
===================================
+ Stop timeout thread immediately when the last worker thread is finished.
Fix dmeventd logging with parallel wait event processing.
Reuse _node_send_messages() for validation of transaction_id in preload.
Transaction_id could be lower by one only when messages are prepared.
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index f27444c..621ae36 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -614,6 +614,8 @@ static void _unregister_for_timeout(struct thread_status *thread)
if (!dm_list_empty(&thread->timeout_list)) {
dm_list_del(&thread->timeout_list);
dm_list_init(&thread->timeout_list);
+ if (dm_list_empty(&_timeout_registry))
+ pthread_cond_signal(&_timeout_cond);
}
pthread_mutex_unlock(&_timeout_mutex);
}
10 years, 1 month
master - dmeventd: remember number of log disablings
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=2a9b62c7f99482...
Commit: 2a9b62c7f9948238f4ba8f60546b2fb1ae44c2c6
Parent: 460c19df621d35260caceec7f598da1566263cd4
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Mar 10 09:47:44 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Mar 10 12:22:47 2014 +0100
dmeventd: remember number of log disablings
Individual events are handled through separate threads,
so once we have more then a single thread in this eventwait
sleeping, we got race on the dm_log setting, since
if one event is timeout out on alarm, while another is still waiting,
then dm log has been restored to NULL and the next sigalarm
has been reported as error.
Fix it by introducing counter which is protected via mutex,
and only when the last event is released, logging is restored.
TODO: libdm seems to have some static vars which may audit
for this type of use.
---
WHATS_NEW_DM | 1 +
daemons/dmeventd/dmeventd.c | 16 ++++++++++++++--
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 32c2265..e470cd2 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.85 -
===================================
+ Fix dmeventd logging with parallel wait event processing.
Reuse _node_send_messages() for validation of transaction_id in preload.
Transaction_id could be lower by one only when messages are prepared.
Do not call callback when preload fails.
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 4a17fb2..f27444c 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -661,6 +661,7 @@ static sigset_t _unblock_sigalrm(void)
/* Wait on a device until an event occurs. */
static int _event_wait(struct thread_status *thread, struct dm_task **task)
{
+ static unsigned _in_event_counter = 0;
sigset_t set;
int ret = DM_WAIT_RETRY;
struct dm_task *dmt;
@@ -677,12 +678,20 @@ static int _event_wait(struct thread_status *thread, struct dm_task **task)
!dm_task_set_event_nr(dmt, thread->event_nr))
goto out;
+ _lock_mutex();
+ /*
+ * Check if there are already some waiting events,
+ * in this case the logging is unmodified.
+ * TODO: audit libdm thread usage
+ */
+ if (!_in_event_counter++)
+ dm_log_init(_no_intr_log);
+ _unlock_mutex();
/*
* This is so that you can break out of waiting on an event,
* either for a timeout event, or to cancel the thread.
*/
set = _unblock_sigalrm();
- dm_log_init(_no_intr_log);
errno = 0;
if (dm_task_run(dmt)) {
thread->current_events |= DM_EVENT_DEVICE_ERROR;
@@ -706,7 +715,10 @@ static int _event_wait(struct thread_status *thread, struct dm_task **task)
}
pthread_sigmask(SIG_SETMASK, &set, NULL);
- dm_log_init(NULL);
+ _lock_mutex();
+ if (--_in_event_counter == 0)
+ dm_log_init(NULL);
+ _unlock_mutex();
out:
if (ret == DM_WAIT_FATAL || ret == DM_WAIT_RETRY) {
10 years, 1 month