From patchwork Wed Jun 7 11:09:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 772364 X-Patchwork-Delegate: nbd@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wjQpS2ZBdz9sNS for ; Wed, 7 Jun 2017 21:10:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gdfqmHWn"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Ap+gg2Rw"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9BbF75v6JPpILKD6dSp8xWyW3vuBIKNUc2FFHldBIHs=; b=gdfqmHWn6angsU Xs/OnZIkJud3LQKbGSA56+wgwHKDBR9UzwHwFplY9Yhw3hqwLW7fZO1DjC/JfRt+taJjO93UO9nnW JGbUm1X9LG5RgWZjVAKkvXe4EbZlnfnnWmUXfuudxGYP3V4bdYe3QJxpVgDVT50Kg0Fj/QZzBHm0F 0omMxkjpMbmMAnXzoyyRBiSJHIwSN3HDLBxjc8olW5bPHaWpfH6IWlXO5P31vDFjaufku8nBqV5eW ywtv2JqM6n3rruHbxwgvUa2Gn7YeHy9IWV4s11cvJc6PpgLUd0cKJ/zWpaOlXv4BTeNKGSCa0wK8h oQehM/29+KYDImmYrXYA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dIYrU-00042H-JO; Wed, 07 Jun 2017 11:10:52 +0000 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dIYrQ-0003zC-OD for lede-dev@lists.infradead.org; Wed, 07 Jun 2017 11:10:50 +0000 Received: by mail-wr0-x241.google.com with SMTP id u101so924021wrc.1 for ; Wed, 07 Jun 2017 04:10:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KvjlQRj+3U94i0vyMjbvzSizhNKstRgUoCUkcBNoxc4=; b=Ap+gg2Rw69lPFQ96PQTsnrXBAPBIQj6ZDjDqsf3Jm0Ed6ltWzM78TQVCnjjlQDVVvI 6NRbCNI8FE28oJGOYZCORK2pEl84tmW6K8gpwZO6MJa9a9sHlHshym5OrJQMBg7SIjdU kIeNSSLL8LUaiYirjDNByYlUaF7ddQ8DU5FEjf0zAf/bA7toN4breCg5VEsHQodThGsW MK41uBlLLvodt3MnxvmSG/wXz5Zt1DZVkQ5yGhtf49c5hm35lveXs06e4yKu7roRkzPz P6scKoit78ruhtvQHyw5OQ2UCA9nCzLcG5tepbSJS4iXKEVKpK+bA54sx2067j8iHK6G iuUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KvjlQRj+3U94i0vyMjbvzSizhNKstRgUoCUkcBNoxc4=; b=dOCucromDMf5vUltNtsUif2fI0sW/e7ngqpqovKqnQ0EMZLd2gem1x+rvy7IEwVdfS mmOwxN55Z+zOt2mYtmAlwl+3pmDRraQl2XXGlvxI8sm3qb2M7evP5jvWjlM84IJBSR5F gE1cdReSkZpDgrIy9hCnvXvNSXYzN5b7h0OS7KymQCKHa/D2YBtB25hRPvnhqjz3zQXU z+JOPpTZOLFkKbHrm57gYaMZhjWWB/f3/kYiWcXH7w6w6JY2TEb3kLoEgiaMdyq1eFTp CUddpeQQ53i5Ag85kwFrntyv5leXF5owwZy43cfncrQOi6dWPCEJjr2U9ZZRX+X0jqkF 1ZHQ== X-Gm-Message-State: AODbwcAP2deRXbTSw4WP/U1h2Kc84P55RQl0jzFgXnvmVfpsfBxAa+ZY b1h2kZq2i0cYAeGH X-Received: by 10.223.164.7 with SMTP id d7mr19401676wra.183.1496833827801; Wed, 07 Jun 2017 04:10:27 -0700 (PDT) Received: from localhost.localdomain ([5.2.198.78]) by smtp.googlemail.com with ESMTPSA id d4sm1232222wra.65.2017.06.07.04.10.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Jun 2017 04:10:27 -0700 (PDT) From: Alexandru Ardelean To: lede-dev@lists.infradead.org Date: Wed, 7 Jun 2017 14:09:31 +0300 Message-Id: <1496833771-32723-3-git-send-email-ardeleanalex@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496833771-32723-1-git-send-email-ardeleanalex@gmail.com> References: <1496833771-32723-1-git-send-email-ardeleanalex@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170607_041048_950410_613AEEEC X-CRM114-Status: GOOD ( 14.14 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c0c:0:0:0:241 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (ardeleanalex[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid Subject: [LEDE-DEV] [PATCH 3/3] ubusd: move global retmsg per client X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandru Ardelean , nbd@nbd.name MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Even with the tx_queue-ing issue resolved, what seems to happen afterwards, is that all the messages seems to get through, but the client still loops in the `ubus_complete_request()` waiting for `req->status_msg` or for a timeout. Though, the timeout does not seem to happen, because the data is processed in `ubus_poll_data()`, with a infinite poll() timeout (ubus_complete_request() is called with timeout 0). It's likely that either the `seq` or `peer` sent from ubusd are wrong, and the client cannot get the correct ubus request in `ubus_process_req_msg()`. I haven't digged too deep into this ; setting the `retmsg` object on the client struct seems to have resolved any hanging with the `ubus list` command. Signed-off-by: Alexandru Ardelean --- ubusd.h | 2 ++ ubusd_proto.c | 35 +++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/ubusd.h b/ubusd.h index 6748c65..a9dd04e 100644 --- a/ubusd.h +++ b/ubusd.h @@ -39,6 +39,7 @@ struct ubus_msg_buf { struct ubus_client { struct ubus_id id; struct uloop_fd sock; + struct blob_buf b; uid_t uid; gid_t gid; @@ -57,6 +58,7 @@ struct ubus_client { struct ubus_msghdr hdr; struct blob_attr data; } hdrbuf; + struct ubus_msg_buf *retmsg; }; struct ubus_path { diff --git a/ubusd_proto.c b/ubusd_proto.c index 631047b..d71f74e 100644 --- a/ubusd_proto.c +++ b/ubusd_proto.c @@ -17,8 +17,6 @@ #include "ubusd.h" struct blob_buf b; -static struct ubus_msg_buf *retmsg; -static int *retmsg_data; static struct avl_tree clients; static struct blob_attr *attrbuf[UBUS_ATTR_MAX]; @@ -444,6 +442,8 @@ void ubusd_proto_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub { ubus_cmd_cb cb = NULL; int ret; + struct ubus_msg_buf *retmsg = cl->retmsg; + int *retmsg_data = blob_data(blob_data(retmsg->data)); retmsg->hdr.seq = ub->hdr.seq; retmsg->hdr.peer = ub->hdr.peer; @@ -468,6 +468,22 @@ void ubusd_proto_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub ubus_msg_send(cl, retmsg, false); } +static int ubusd_proto_init_retmsg(struct ubus_client *cl) +{ + struct blob_buf *b = &cl->b; + + blob_buf_init(&cl->b, 0); + blob_put_int32(&cl->b, UBUS_ATTR_STATUS, 0); + + /* we make the 'retmsg' buffer shared with the blob_buf b, to reduce mem duplication */ + cl->retmsg = ubus_msg_new(b->head, blob_raw_len(b->head), true); + if (!cl->retmsg) + return -1; + + cl->retmsg->hdr.type = UBUS_MSG_STATUS; + return 0; +} + struct ubus_client *ubusd_proto_new_client(int fd, uloop_fd_handler cb) { struct ubus_client *cl; @@ -488,6 +504,9 @@ struct ubus_client *ubusd_proto_new_client(int fd, uloop_fd_handler cb) if (!ubus_alloc_id(&clients, &cl->id, 0)) goto free; + if (ubusd_proto_init_retmsg(cl)) + goto free; + if (!ubusd_send_hello(cl)) goto delete; @@ -508,6 +527,8 @@ void ubusd_proto_free_client(struct ubus_client *cl) obj = list_first_entry(&cl->objects, struct ubus_object, list); ubusd_free_object(obj); } + ubus_msg_free(cl->retmsg); + blob_buf_free(&cl->b); ubusd_acl_free_client(cl); ubus_free_id(&clients, &cl->id); @@ -550,14 +571,4 @@ void ubus_notify_unsubscribe(struct ubus_subscription *s) static void __constructor ubusd_proto_init(void) { ubus_init_id_tree(&clients); - - blob_buf_init(&b, 0); - blob_put_int32(&b, UBUS_ATTR_STATUS, 0); - - retmsg = ubus_msg_from_blob(false); - if (!retmsg) - exit(1); - - retmsg->hdr.type = UBUS_MSG_STATUS; - retmsg_data = blob_data(blob_data(retmsg->data)); }