master - clvmd: update add_reply_to_list
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=37396e2fe5c451c466f93f852a3559da023fc98c Commit: 37396e2fe5c451c466f93f852a3559da023fc98c Parent: 28479946249611f7f103c1caa33033a92ea0ce49 Author: Zdenek Kabelac <[email protected]> AuthorDate: Thu Mar 20 14:29:42 2014 +0100 Committer: Zdenek Kabelac <[email protected]> CommitterDate: Fri Mar 21 22:29:24 2014 +0100
clvmd: update add_reply_to_list
Take mutex lock after the allocation just before
the structure is merged into reply list.
--- daemons/clvmd/clvmd.c | 39 ++++++++++++++++++--------------------- 1 files changed, 18 insertions(+), 21 deletions(-)
daemons/clvmd/clvmd.c +18 -21
@@ -1675,32 +1675,29 @@ static void add_reply_to_list(struct local_client *client, int status, {struct node_reply *reply; -pthread_mutex_lock (&client->bits.localsock.reply_mutex); -/* Add it to the list of replies */ -if ((reply =dm_malloc (sizeof (*reply)))) { - reply->status = status; - clops->name_from_csid (csid, reply->node); -DEBUGLOG ("Reply from node %s: %d bytes\n" , reply->node, len); - -if (len >0 ) { -if (!(reply->replymsg =dm_malloc (len))) - reply->status =ENOMEM ; -else { -memcpy (reply->replymsg, buf, len); - } - }else { - reply->replymsg =NULL ; - } -/* Hook it onto the reply chain */ - reply->next = client->bits.localsock.replies; - client->bits.localsock.replies = reply; - }else { +if (!(reply =dm_zalloc (sizeof (*reply)))) {/* It's all gone horribly wrong... */ -pthread_mutex_unlock (&client->bits.localsock.reply_mutex);send_local_reply (client,ENOMEM , client->fd);return ; } + + reply->status = status; + clops->name_from_csid (csid, reply->node); +DEBUGLOG ("Reply from node %s: %d bytes\n" , reply->node, len); + +if (len >0 ) { +if (!(reply->replymsg =dm_malloc (len))) + reply->status =ENOMEM ; +else +memcpy (reply->replymsg, buf, len); + }else + reply->replymsg =NULL ; + +pthread_mutex_lock (&client->bits.localsock.reply_mutex); +/* Hook it onto the reply chain */ + reply->next = client->bits.localsock.replies; + client->bits.localsock.replies = reply;DEBUGLOG ("Got %d replies, expecting: %d\n" , client->bits.localsock.num_replies +1 , client->bits.localsock.expected_replies);