Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp225653rwi; Tue, 18 Oct 2022 16:53:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5oz1/nABNVDCFE6fVB9AY3iSSunxUFjpnm+BTS18TOKHTEdp/EbyyXUvuRAq5wm2oZw5WN X-Received: by 2002:a17:907:9493:b0:78d:3415:bacd with SMTP id dm19-20020a170907949300b0078d3415bacdmr4468407ejc.184.1666137198949; Tue, 18 Oct 2022 16:53:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666137198; cv=none; d=google.com; s=arc-20160816; b=GXQq19YjfpCEnJf4qu4Lt4AUOJIZqj+Kbq9E1gIbkZWfz3QQnnPK7rfrm2P2TioGl7 BDWeZQd2wUcnuJhIT3Fx0vrT8/2znIa0UH8Y5/T7jyhWKjJgJZ1hs6Zx4ephIGbjSXxe 6z2mS8VODCZeKo+t69nD3+hoaJYMjlZUzc/x2PJQqxTU6WmUnN9ZIiAUgOA/qLXUjIih 6KT4H6XeyfcH5PJJFu2hk0qFqC8AqE1jSq2n1F7ibCv9SP1Rvs2yd13JuO0tT1vAY6pd vW6pXoBUPxv6sWK31UlDhNYaedLBNDu1TjTyKpk8U67+ev+fCxA5Z4OH3S8Gz2OJLk4x t4Zw== 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=AQVOe4oCvjwQHwbJW6UYXvIxrMA6sYEZ8A+uwI77HZM=; b=IpMtdMS7Idp06ujun5yioVOOfzytaFgrUpMKAbJjEIGqypCwVQ82cYqNctc7FB8R8I yyQ8Pw56L49eCp+k5hO2l5T07jL1LEAfrO+gjO1gPIftfFO5J3P7KiGhbybZJqyuIZhM /YcjGCKCVBUzlsIQZlMNpfoCsEdQHNCOgFT2bFOegL8H12CkLCSCud3vttBxFJxBh4An 1eM67WCvrfPBUAN2EQwb9ZY6I7luV/R82bxoPMB5tB1LicTK5umE4ecNhkspbSYZ6yDh hvXaXPnnlWiSZQF4fqdikOpNCQF7UIYjx9oVmaY9M8yfpjPdQD7t/2VC9UfAJEtDQ6Bz 0F/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TvFpGEdF; 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 g13-20020a056402090d00b00458cd6f8506si16344505edz.173.2022.10.18.16.52.37; Tue, 18 Oct 2022 16:53:18 -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=TvFpGEdF; 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 S229454AbiJRXqK (ORCPT + 99 others); Tue, 18 Oct 2022 19:46:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229606AbiJRXqJ (ORCPT ); Tue, 18 Oct 2022 19:46:09 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9B7ACD5F9 for ; Tue, 18 Oct 2022 16:46:08 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id c24so15314364pls.9 for ; Tue, 18 Oct 2022 16:46:08 -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=AQVOe4oCvjwQHwbJW6UYXvIxrMA6sYEZ8A+uwI77HZM=; b=TvFpGEdFJAlVlhaPNXyBr0D9D82AtjKQN76XX53pCBoYSRRcN0apLbT/2q46oi77iZ 5srZsTXwKGOV08didsyvvSFbE+BqnPI3dlC4btB1zc1ml1/1AdsvO/2+UEHFc6LaxqMX NZlDQRbt14ivmPQ7IqfkNdQA0029ngC1p36ep4/ZT6TzK4IBhOZWz0MjUBYvKYDNSJ9Z G/h3fULi3l7QpJqOoY34DokIDsMQa971mzBgQ4+rwzvXNwu2sKQZSMOv5uh6KozV3AKp ZS4km6ACltRAvHJx0YRMVEa3LB63hIF28ihUzab0WDFyIBa54//nW+kCEJjvcEqHtDQ0 NSrQ== 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=AQVOe4oCvjwQHwbJW6UYXvIxrMA6sYEZ8A+uwI77HZM=; b=I1uJX6Q4PRswIDtLfCqd48PPxD9Vo9tR+kXRgxOtOC4zNWa8LYetnJ7zj/RJMGMpFb wu94GpwMMPFWuQIbdRQOCeWCVgfrHFKEEKn98w709G0IVynregK8rtz0VtgOKWA16LCU hczEsNxU4sVdbk9/4GlKM8INdNPTxOIC047sJAZMtvss+1x5ST2t2/AA+cyzI37sawbw z9BFDSpOc3uw7j2h+dtDsIRou8qOYKIuF5v4eptDjL97PLKGikepwip/+ZWQnEWHy7EO aMmbHWo000piKbvB+wa0+Ymb6BEau5pthqPxlcdtLZqnX1Zrq/FhmRWTn09C4jC+8BTk UNIA== X-Gm-Message-State: ACrzQf28DHJrSRTUEyO6FFMe9Xl5vLIT44BBpS95qoKY6wsIGKM1mlS/ 0eZ+P2sh/IEJlsDCipru3sXiLLR8AB0= X-Received: by 2002:a17:90b:3588:b0:20b:590:46a2 with SMTP id mm8-20020a17090b358800b0020b059046a2mr6276441pjb.14.1666136767647; Tue, 18 Oct 2022 16:46:07 -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 ik3-20020a170902ab0300b00170d34cf7f3sm9137783plb.257.2022.10.18.16.46.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 16:46:05 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 2/3] monitor/att: Detect cache changes Date: Tue, 18 Oct 2022 16:45:59 -0700 Message-Id: <20221018234600.3990980-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221018234600.3990980-1-luiz.dentz@gmail.com> References: <20221018234600.3990980-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 | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/monitor/att.c b/monitor/att.c index 491f196bf38d..7a4125567498 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,28 @@ 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) +{ + struct stat st; + + if (lstat(filename, &st)) + return; + + if (!gatt_db_isempty(db)) { + /* 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; + /* Clear db before reloading */ + gatt_db_clear(db); + } + + *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 +2480,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