From patchwork Wed Nov 17 10:41:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Eckert X-Patchwork-Id: 1556136 X-Patchwork-Delegate: daniel@makrotopia.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=e95xs/LU; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HvKLR5nQnz9s1l for ; Wed, 17 Nov 2021 21:44:31 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Q7XwKSFIUUDdntj8es3qoMAY2woU2rI/Zw4agH187xs=; b=e95xs/LU1iaaQg Z1mffE+2tBy2hS80ySdwv3ZYrPxvXMzjSz0tZqL0K6O1BA2lskiqUYjt4wV44EC3y+LyAylbNJbxa LL3DzSrcfiGvFMsztlTX6JhVRKeo9DHNwsB4NF7ChGSmVVzyAbp4MM+WYDrsxPioCeJgpl788/2ZP kRFZl2VfN5zPhcgewxKK8Ayl7NcRk0kJHvje+NzHjzY7QCCUkdeKteqlMWiECzVRT9u0UcCVhcyGN jvNbtA40kCp85WupRhTtyqC1qy5Cjuy/Zjq1vKoV3fOFWfk5RTLfYy+7nqcAoYXJXzOSuZMdxcnQs 27jLttfSvcRMTttbqcVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnINi-004Syy-N2; Wed, 17 Nov 2021 10:41:34 +0000 Received: from mxout70.expurgate.net ([194.37.255.70]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnINf-004Sxl-Kr for openwrt-devel@lists.openwrt.org; Wed, 17 Nov 2021 10:41:33 +0000 Received: from [127.0.0.1] (helo=localhost) by relay.expurgate.net with smtp (Exim 4.92) (envelope-from ) id 1mnINZ-00086c-3o; Wed, 17 Nov 2021 11:41:25 +0100 Received: from [195.243.126.94] (helo=securemail.tdt.de) by relay.expurgate.net with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mnINY-0004KR-CL; Wed, 17 Nov 2021 11:41:24 +0100 Received: from securemail.tdt.de (localhost [127.0.0.1]) by securemail.tdt.de (Postfix) with ESMTP id E2709240042; Wed, 17 Nov 2021 11:41:23 +0100 (CET) Received: from mail.dev.tdt.de (unknown [10.2.4.42]) by securemail.tdt.de (Postfix) with ESMTP id 91A55240041; Wed, 17 Nov 2021 11:41:23 +0100 (CET) Received: from localhost.localdomain (unknown [10.2.3.40]) by mail.dev.tdt.de (Postfix) with ESMTPSA id EA15C2006E; Wed, 17 Nov 2021 11:41:22 +0100 (CET) From: Florian Eckert To: daniel@makrotopia.org Cc: Eckert.Florian@googlemail.com, openwrt-devel@lists.openwrt.org Subject: [PATCH procd 1/1] system: add diskfree infos to ubus Date: Wed, 17 Nov 2021 11:41:17 +0100 Message-ID: <20211117104117.16802-1-fe@dev.tdt.de> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,URIBL_BLOCKED, URIBL_ZEN_BLOCKED_OPENDNS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.dev.tdt.de X-purgate: clean X-purgate-type: clean X-purgate-ID: 151534::1637145684-00002D2E-184EEA12/0/0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211117_024131_884592_AE535B7A X-CRM114-Status: GOOD ( 13.70 ) X-Spam-Score: -0.7 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This change adds the missing information about how much space is available on the root directory and in the temp directory. I took this implementation from the luci2 repository and adapted it for the [...] Content analysis details: (-0.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [194.37.255.70 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org This change adds the missing information about how much space is available on the root directory and in the temp directory. I took this implementation from the luci2 repository and adapted it for the procd service. Signed-off-by: Florian Eckert --- system.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/system.c b/system.c index 83aea42..a671f5d 100644 --- a/system.c +++ b/system.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -239,6 +240,12 @@ static int system_board(struct ubus_context *ctx, struct ubus_object *obj, return UBUS_STATUS_OK; } +static unsigned long +kscale(unsigned long b, unsigned long bs) +{ + return (b * (unsigned long long) bs + 1024/2) / 1024; +} + static int system_info(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) @@ -252,6 +259,12 @@ static int system_info(struct ubus_context *ctx, struct ubus_object *obj, char *key, *val; unsigned long long available, cached; FILE *f; + int i; + struct statvfs s; + const char *fslist[] = { + "/", "root", + "/tmp", "tmp", + }; if (sysinfo(&info)) return UBUS_STATUS_UNKNOWN_ERROR; @@ -311,6 +324,23 @@ static int system_info(struct ubus_context *ctx, struct ubus_object *obj, blobmsg_add_u64(&b, "cached", cached); blobmsg_close_table(&b, c); + for (i = 0; i < sizeof(fslist) / sizeof(fslist[0]); i += 2) { + if (statvfs(fslist[i], &s)) + continue; + + c = blobmsg_open_table(&b, fslist[i+1]); + + if (!s.f_frsize) + s.f_frsize = s.f_bsize; + + blobmsg_add_u64(&b, "total", kscale(s.f_blocks, s.f_frsize)); + blobmsg_add_u64(&b, "free", kscale(s.f_bfree, s.f_frsize)); + blobmsg_add_u64(&b, "used", kscale(s.f_blocks - s.f_bfree, s.f_frsize)); + blobmsg_add_u64(&b, "avail", kscale(s.f_bavail, s.f_frsize)); + + blobmsg_close_table(&b, c); + } + c = blobmsg_open_table(&b, "swap"); blobmsg_add_u64(&b, "total", (uint64_t)info.mem_unit * (uint64_t)info.totalswap);