Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp84068rwi; Tue, 18 Oct 2022 14:29:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ULq5IItgTHD5kxH0c/UszKahOs2Y3XSiwkN1TIqqm0VZxdilOwJe8tSwkwi09xIwvaJ9j X-Received: by 2002:a17:903:240d:b0:183:9bab:9c3 with SMTP id e13-20020a170903240d00b001839bab09c3mr5093668plo.48.1666128574613; Tue, 18 Oct 2022 14:29:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666128574; cv=none; d=google.com; s=arc-20160816; b=bWnttQ/FPDMx1Sz44jlDobPQOFLb+xUbFZgLd0EThKhsAuV8A7J3gPmIwsuI+ny0m7 Z7x9XXp2garxR6YY22tfq9B8t34v3qYyPWUWVBhyxtot2u22txEOkfyu4nhTv2r2HWSP nYReqpr7imEI/orjI70vE+K8nMuYGkJyvCeyptFYRy9uoAzTo9N+J6b96Ko8A3Bl0Zth fHo2XOzCW4QgphicM/DkZLhgdRADz+px1jmIZM/0OocP6fPidI636q7f8l5xo3OmUcRc /i03UUTzTflLS/Xi0p7OAW1ELF6kkhKKam7uAMwWuIysdQZq7MScAnOLFVdUpAQ+3UxB +HEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=UbSj7fj+X30LLZftuEXUEleVFi2jSrK/Zu4j8/Qe0RU=; b=Vwj2b2nA+tAw0zf4uL+VY4eRLcJDbVMopqXQ74qf4n8lpjR9lVRmbsSglpQXc3LxwX jxMC/EqB1K14FuhUpmrl7P+h+AliPRfqxOy1Psnw+gWU4ZTYCcNENOP/eMXTDexFicRD IXA8wVjawldOpLqCVdneedThpqM6xrFTBsO7t7fwwvkx2+sWuzmNJKA2OZYEeAfq2CCc Kj7//q8FHzc7NqdvgSfCqI/WAyTWzxYEWQ95hcKnDeE01Vb6KHFOZu3uOP8pOi/mKWoW hmBk4VSspihk+q76e/cUrzdluv7q9og8MSFZT7SDP/Imj/QOoNibDU60X1Y2vZy0n81B mBrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="hD5nW/hc"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y67-20020a623246000000b005370942e40dsi14688572pfy.324.2022.10.18.14.29.03; Tue, 18 Oct 2022 14:29:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="hD5nW/hc"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229956AbiJRV2G (ORCPT + 99 others); Tue, 18 Oct 2022 17:28:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229957AbiJRV2G (ORCPT ); Tue, 18 Oct 2022 17:28:06 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB30EAA3FE for ; Tue, 18 Oct 2022 14:28:05 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id 128so14453477pga.1 for ; Tue, 18 Oct 2022 14:28:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=UbSj7fj+X30LLZftuEXUEleVFi2jSrK/Zu4j8/Qe0RU=; b=hD5nW/hc9gVohUZkwYxrru36jsdERdDbdXEnqft5GlfoNezeMJsEl0DTM+JgoeL+6i J3yAu3ZjzavJ/5DcyI3MOGZwfHkSCl1MSSkVAyE1yacsan4W1lP9ddjQNKYS3z4NWQCS 0liDD3TngL/wHb3IG8EO+QA99Xec4w6fOKCsMYsx20D51xBD37qW+98qd6wC7uuVi1hG y7CqyfPnZjtOdajROajs6s4E8NtTgRbeGKVYJ54OLlXPZ6+ITwx1vf35HnmFiHNRnZKO bjq1MDHwNhQuOx75lRRgeT0cHZOs4zDhL1EApNH1a2kwWoWHCH9j7tLDC5qhoLF6s13l Uw0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UbSj7fj+X30LLZftuEXUEleVFi2jSrK/Zu4j8/Qe0RU=; b=BslsE1zxiXxAMZk74/dYJXPZmZaliMkO/NHnea4XNjZwrcbRUMBw5h/Ncgc6qZ+ISR +VfsECKfxtW9vpj6RQvGPv5V5rEUTYQwI6oNfoyEsZVIKrcRQRS7cNIYJ2wN/TDSY8gR n0HCXoB/tT+aypTPYQifg1sPQkHrCC00zbkUQL4xir/KAbddxxzrYTy1cxxcRME1aIyD H1480fVC0l1MygyrnwsDz63Pxsa+M8KWx5gR9H5E6XtKGc5IEqjS2ZIgVhWyAgyj532R SKAgAQvO803v9S7GmPBvi1rq9ZOe5C2GbdYngFR98W+ZsxgnA/lb0HKBRAqY0FgPSbQ5 nBNA== X-Gm-Message-State: ACrzQf1iWOJEZs596LAWmA86Z74ClZjOEpLw6gXV9Ef4DktwqjjaAdvV NzBY5FLs4ph0g3ZvKuBFEJ0o47QXulM= X-Received: by 2002:a63:5466:0:b0:43c:bc41:73a with SMTP id e38-20020a635466000000b0043cbc41073amr4430370pgm.77.1666128484738; Tue, 18 Oct 2022 14:28:04 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id n9-20020a170903110900b0017f7c4e260fsm9230653plh.150.2022.10.18.14.28.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 14:28:03 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/2] monitor/att: Detect cache changes Date: Tue, 18 Oct 2022 14:28:00 -0700 Message-Id: <20221018212800.3967256-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221018212800.3967256-1-luiz.dentz@gmail.com> References: <20221018212800.3967256-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This attempts to detect if the were any changes on cache files since they were last loaded and then attempt to reload them. --- monitor/att.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/monitor/att.c b/monitor/att.c index 491f196bf38d..6143b79b58ae 100644 --- a/monitor/att.c +++ b/monitor/att.c @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -2426,7 +2427,9 @@ struct att_read { struct att_conn_data { struct gatt_db *ldb; + struct timespec ldb_mtim; struct gatt_db *rdb; + struct timespec rdb_mtim; struct queue *reads; }; @@ -2440,6 +2443,26 @@ static void att_conn_data_free(void *data) free(att_data); } +static void gatt_load_db(struct gatt_db *db, const char *filename, + struct timespec *mtim) +{ + if (!gatt_db_isempty(db)) { + struct stat st; + + if (lstat(filename, &st)) + return; + + /* Check if file has been modified since last time */ + if (st.st_mtim.tv_sec == mtim->tv_sec && + st.st_mtim.tv_nsec == mtim->tv_nsec) + return; + + *mtim = st.st_mtim; + } + + btd_settings_gatt_db_load(db, filename); +} + static void load_gatt_db(struct packet_conn_data *conn) { struct att_conn_data *data = conn->data; @@ -2455,22 +2478,14 @@ static void load_gatt_db(struct packet_conn_data *conn) conn->destroy = att_conn_data_free; } - if (!gatt_db_isempty(data->ldb) && !gatt_db_isempty(data->rdb)) - return; - ba2str((bdaddr_t *)conn->src, local); ba2str((bdaddr_t *)conn->dst, peer); - if (gatt_db_isempty(data->ldb)) { - create_filename(filename, PATH_MAX, "/%s/attributes", local); - btd_settings_gatt_db_load(data->ldb, filename); - } + create_filename(filename, PATH_MAX, "/%s/attributes", local); + gatt_load_db(data->ldb, filename, &data->ldb_mtim); - if (gatt_db_isempty(data->rdb)) { - create_filename(filename, PATH_MAX, "/%s/cache/%s", local, - peer); - btd_settings_gatt_db_load(data->rdb, filename); - } + create_filename(filename, PATH_MAX, "/%s/cache/%s", local, peer); + gatt_load_db(data->rdb, filename, &data->rdb_mtim); } static struct gatt_db_attribute *get_attribute(const struct l2cap_frame *frame, -- 2.37.3