Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1656663rwb; Mon, 7 Nov 2022 04:24:16 -0800 (PST) X-Google-Smtp-Source: AMsMyM6393ScXTaK0exO4JuJtxcaa/b81yPSvthMIPYAjq0Q8BoL31rmeANMDQGBJFQcS7oVJ74x X-Received: by 2002:a05:6402:1292:b0:463:27a0:72b4 with SMTP id w18-20020a056402129200b0046327a072b4mr45872696edv.419.1667823856599; Mon, 07 Nov 2022 04:24:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667823856; cv=none; d=google.com; s=arc-20160816; b=M/dORYwlS0wQmEv1dxEq3E5X96ZAL0gQDCrC76H/Ou2MRHNsunDednNszcyPdaX6Zg 7QEFvYvLq1NvIEpvlxu3HZOWQbNqCdxu8dLv90UCpt78oOpLUVdiSwkbjSXl3JOoInqE kvCcoJ0q0oVZwBzVSzmuHEtaR7OWBhKU9DtNagkTF90widVvN+aMaI4DbUpfbQqhWgEU cEVMGgU/21T5TLHe+G8aTY4WBOWkk/LsV/0i3y+ObfPdp4lTqF2HpRkwaxjgi7vMGvoT GHt1a13Cw5Wzuq0vj12h/bkqeaUg4QyTJS/iCoRqAm3gkvF6IWsqOAm2+m/T5fKX7+Vj hm3w== 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:cc:to:from :dkim-signature; bh=yNH/JRMMbNBjJGEyAIMaU9Rbue7IVZktvVu0mJ7rLNc=; b=GYcCTzpNu2woPG+7GYv+h2npFHHwP1KOGwC471K1aYY9F4JN3ie5Q2tdYNpqv4YxyS 2KKRrXcCo7HfsVGCThgEpmkCqHNGsVAuDRYNLhAqINt2Ay9efAzBe+4fgSKVigZVHCaI Gv9Pw3L2982sGFn6dz3rbPM+Hfbp1bxTXnXUE6O2u5XpmO9BWLMPP2xhjNh+yEkXo7ql I+6YMBsHwEGd53JgU1Y6hAXQfrcyozj2yebb+SgTB4juyMQvZSNzkqXfDFThCnP8CAa5 /w0j6/FvtyD21JfrNJU2rxqyR56jDrFK8+wUqCD5p6YV3ker6mfvgepx6P/wKp6fR+Jg VYDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dzaEh4ra; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-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 hb32-20020a170907162000b007ade82b938asi10428591ejc.784.2022.11.07.04.23.49; Mon, 07 Nov 2022 04:24:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-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=dzaEh4ra; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-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 S231421AbiKGMXe (ORCPT + 99 others); Mon, 7 Nov 2022 07:23:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232151AbiKGMXc (ORCPT ); Mon, 7 Nov 2022 07:23:32 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 493966247 for ; Mon, 7 Nov 2022 04:23:30 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id b62so10338460pgc.0 for ; Mon, 07 Nov 2022 04:23:30 -0800 (PST) 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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yNH/JRMMbNBjJGEyAIMaU9Rbue7IVZktvVu0mJ7rLNc=; b=dzaEh4raQcQr2hBzOZqZPhKf4hDCUSrlW+7rTUcXfd1iMwnBUa/LOpM2hzOMNLJfFs 6GXZAalYTp6sX+9rykYWWj0q+GssuY6Bdaopue+YlCq9uYQEhPZ7xw3+/Xqf3le786/S 0hB7sPXaP4SdoVj8cduB9XbQwD1/vQrDL7erf5G4PWfW0dRBjxXaVVcLn6Jca/sueYhP TlelrCxhfh/eZ+mYj/+JQSgYAd2/LahF040N+51Av7fN3QW/oLq55gJTenN8XuXu+dW8 v4hNV1sK/7yfk3yyySZShEdWd9sfrMqcxqGMAsIsMBt8zurZSgnkicYbloAHJCaegQg2 vFlg== 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:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yNH/JRMMbNBjJGEyAIMaU9Rbue7IVZktvVu0mJ7rLNc=; b=UostMGbveqRjXmzKVK2DB9L7aA3yuyf3N42GJJ8te5JuGotsS/aZxqPeP6eHSLrhJF myKUwD/j1YGgZ4JkZy0GbBDKVJubmn+agQAq/GJQ31BZnkqV+cWntFijOr2DJu9TK/NE g3wxQ2NupVhvoGvSmRAA/7pWZLl8yMwGNpjEPJNaMoy4X0lwmmJRjrf0VKJFfQaxGBtQ A4eUp9VlwYygwZNUaTIWSW1gS5Pl+Uf247qJUJ3vMHsev9iCa6uLpn0UHrwHJFQwILhZ z3uPb1QRW2deYYVz+FBBntQmQoQ5l4ZSP4Z2YtWQjOpoOGoMfKVPl+IS/IzWepRaaY5m PyMg== X-Gm-Message-State: ACrzQf118dt5Z7jrDxkEJSJNvZWBbRjaXEFhdr+xdxxvxITPWmVtmn0S Suva02MG5cHAcWQPCknKy7M= X-Received: by 2002:a63:5123:0:b0:46f:f329:c013 with SMTP id f35-20020a635123000000b0046ff329c013mr27173500pgb.428.1667823809762; Mon, 07 Nov 2022 04:23:29 -0800 (PST) Received: from localhost ([2406:7400:63:f20b:312d:45b2:85c1:c486]) by smtp.gmail.com with ESMTPSA id b12-20020a1709027e0c00b00186f608c543sm4834064plm.304.2022.11.07.04.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 04:23:29 -0800 (PST) From: "Ritesh Harjani (IBM)" To: Theodore Ts'o Cc: linux-ext4@vger.kernel.org, Harshad Shirwadkar , Wang Shilong , Andreas Dilger , Li Xi , Ritesh Harjani Subject: [RFCv1 11/72] libext2fs: merge quota context after threads finish Date: Mon, 7 Nov 2022 17:50:59 +0530 Message-Id: X-Mailer: git-send-email 2.37.3 In-Reply-To: References: 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-ext4@vger.kernel.org From: Wang Shilong Every threads calculate its own quota accounting, merge them after threads finish. Signed-off-by: Wang Shilong [Note: splitted the patch to seperate libext2fs changes from e2fsck] Signed-off-by: Ritesh Harjani (IBM) --- lib/support/mkquota.c | 39 +++++++++++++++++++++++++++++++++++++++ lib/support/quotaio.h | 3 +++ 2 files changed, 42 insertions(+) diff --git a/lib/support/mkquota.c b/lib/support/mkquota.c index 9339c994..ce1ab4cd 100644 --- a/lib/support/mkquota.c +++ b/lib/support/mkquota.c @@ -618,6 +618,45 @@ out: return err; } +static errcode_t merge_usage(dict_t *dest, dict_t *src) +{ + dnode_t *n; + struct dquot *src_dq, *dest_dq; + + for (n = dict_first(src); n; n = dict_next(src, n)) { + src_dq = dnode_get(n); + if (!src_dq) + continue; + dest_dq = get_dq(dest, src_dq->dq_id); + if (dest_dq == NULL) + return -ENOMEM; + dest_dq->dq_dqb.dqb_curspace += src_dq->dq_dqb.dqb_curspace; + dest_dq->dq_dqb.dqb_curinodes += src_dq->dq_dqb.dqb_curinodes; + } + + return 0; +} + + +errcode_t quota_merge_and_update_usage(quota_ctx_t dest_qctx, + quota_ctx_t src_qctx) +{ + dict_t *dict; + enum quota_type qtype; + errcode_t retval = 0; + + for (qtype = 0; qtype < MAXQUOTAS; qtype++) { + dict = src_qctx->quota_dict[qtype]; + if (!dict) + continue; + retval = merge_usage(dest_qctx->quota_dict[qtype], dict); + if (retval) + break; + } + + return retval; +} + /* * Compares the measured quota in qctx->quota_dict with that in the quota inode * on disk and updates the limits in qctx->quota_dict. 'usage_inconsistent' is diff --git a/lib/support/quotaio.h b/lib/support/quotaio.h index 84fac35d..240a0762 100644 --- a/lib/support/quotaio.h +++ b/lib/support/quotaio.h @@ -40,6 +40,7 @@ #include "ext2fs/ext2_fs.h" #include "ext2fs/ext2fs.h" #include "dqblk_v2.h" +#include "support/dict.h" typedef int64_t qsize_t; /* Type in which we store size limitations */ @@ -236,6 +237,8 @@ int quota_file_exists(ext2_filsys fs, enum quota_type qtype); void quota_set_sb_inum(ext2_filsys fs, ext2_ino_t ino, enum quota_type qtype); errcode_t quota_compare_and_update(quota_ctx_t qctx, enum quota_type qtype, int *usage_inconsistent); +errcode_t quota_merge_and_update_usage(quota_ctx_t dest_qctx, + quota_ctx_t src_qctx); int parse_quota_opts(const char *opts, int (*func)(char *)); /* parse_qtype.c */ -- 2.37.3