Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp893330iob; Fri, 13 May 2022 15:47:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiXYbB4MZe2MX2RrBLZQwB05CUvlhzhqHkUO2G7XF5AxhFuqFHWSSrfu+5WgMWsNRh+8lN X-Received: by 2002:adf:e812:0:b0:20c:dd44:b06c with SMTP id o18-20020adfe812000000b0020cdd44b06cmr5601192wrm.714.1652482034170; Fri, 13 May 2022 15:47:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652482034; cv=none; d=google.com; s=arc-20160816; b=PIE5BQGCQ4sCeBRS8wIqPwrZCVCJioHq0tpBnKftxJ4H3XW0Q5IBFIuvbl5UziPMrS /WsD8qH5bC9KtqqPmmfEkzIg+pFR1hdIxUiiWFE8E1p+aUXO2X2JJi/D6sQvViEnRWmI +A397sjMEQNb+CM64gnaD5fvMLwRUjQFAYRR+0jAbB1D9C1+fyzPyWHdT+W/euEZX4Ww Rw7a8LVXtdJ0Fs7bPsXV4CaQ7QHM2raaZAUx9aSLYiOzQoIqSahcfvUg1VwWp/GB2Q9s h5iZfmhCvpe/beK8spyJhV4dXqm2lxORKm3ZOtN3mH4otlpn5E99uZLmywFM/DerVKp/ 1eBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=/x54ivsu0L8dQHsfXj5X8iP56Kte1TfUkHVw0Dl1VHM=; b=FMWWsdql1wcJ+RWrqYpScNVNdhMr4CMCa/U3rtQOY6DD2MHIPZOrbilu+KPA+o8Hb9 FlbSSoZD+ARRjI5/UhaxLXI4pUjtfcXB57Ksm3edEqt0eD811JWtG/Pd/gQKYs0sD2zw Evd1IKE35R7t76wf8PoKmBnKH9GNy3LfTQlR8gYwSi2shhUJ105cyMMRlX4rcTZjt0XS VHa4vJMSnI8wjWWt355+AepSwai/B1rqwqhzyW2iSd1P7gMJoDJYs3ojKxYLJPa0hpAh a2hmGShpj2AeEc6TyogBeKhyXfc4yf6Q257f5gwRdOT8TpLuDbSVdDTzZ7YDZtZevzyi pUDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="qKV2F/o+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v25-20020adfa1d9000000b0020c4c1b3a9dsi3126055wrv.588.2022.05.13.15.46.38; Fri, 13 May 2022 15:47:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@google.com header.s=20210112 header.b="qKV2F/o+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383113AbiEMRkp (ORCPT + 99 others); Fri, 13 May 2022 13:40:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383152AbiEMRkm (ORCPT ); Fri, 13 May 2022 13:40:42 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A53EC37A13 for ; Fri, 13 May 2022 10:40:34 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id g129-20020a25db87000000b0064b0d671050so7825430ybf.6 for ; Fri, 13 May 2022 10:40:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=/x54ivsu0L8dQHsfXj5X8iP56Kte1TfUkHVw0Dl1VHM=; b=qKV2F/o+1EleqLXGs3rBHm8b6aBfYoNPf/knsl2Sb1SacsaCDUg95ck9Gx6JtESbuB bWOP/I/kWCUgv6TttHk+/rePIlVtKrycnPaVy0m0p8e5HUVdlb/N+J+ZYQPgSLRhcVA7 palQF7MXJL9T433RCaLIjovMH6OYlC1Zf8EWRKAuy6QWAKJmpLrihJkQlgVDTFVvgcpF +rvUr1e6PjJHC3AjQBRda2cLpTN8KcZ8+tRav42P62w74xQUOuBPHSRZaacW3Q9GuCim STL68JEuK71bfcDTHpyKs+/hjsN3E1JNNCXlgr82AAc1Vi5PV5yIDED0zKWD3VgrW87o I+9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=/x54ivsu0L8dQHsfXj5X8iP56Kte1TfUkHVw0Dl1VHM=; b=sxgBANHxZpWqVC3+/pi1r3JAl/jje+OkXXYbcrMMZ7zF3GYKtKDkkPEp/2dL5d1g1c I0CgmLGzaYDMVYTHFK8EEeFGtFKtPsTepUMX9Yor0fs/5+OVS05TLwczR5LKgP2Jp/ru GTot7jUp9f4pgHRJ12oSk7fhKOHzqDNCgc79F42lnX/eudHp4Mm7FRzm3LroytsuCUSW pAtk1YVDrGoPbo9Flfco4iW2/VdbLxVRMmcYlbIu1Lt+Lo0fNHvi71lyYzUg0e7YQ9nZ vQKKLUxGz6KBQNJlOJK6zpwoP666V01zW0df0cYdfw7PVl6gTxNiAPYG5nE9iJDrdoQe NYVQ== X-Gm-Message-State: AOAM530vRdzcO0OL4bcbXRuxVVWcudjyfPX/EJXM/HS1tJOxl47cO/jY 8kO9Nl+MHzkMqoNXZhQ87rx2WIOCKFE= X-Received: from khazhy-linux.svl.corp.google.com ([2620:15c:2cd:202:43f7:a68a:3d8e:73b4]) (user=khazhy job=sendgmr) by 2002:a81:32c1:0:b0:2f7:cda8:50e1 with SMTP id y184-20020a8132c1000000b002f7cda850e1mr7020634ywy.519.1652463633776; Fri, 13 May 2022 10:40:33 -0700 (PDT) Date: Fri, 13 May 2022 10:40:30 -0700 In-Reply-To: Message-Id: <20220513174030.1307720-1-khazhy@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.36.0.550.gb090851708-goog Subject: [RESEND][RFC PATCH] blkcg: rewind seq_file if no stats From: Khazhismel Kumykov To: Tejun Heo , Jens Axboe , Alexander Viro , Christoph Hellwig Cc: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Khazhismel Kumykov Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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-kernel@vger.kernel.org Restores the previous behavior of only displaying devices for which we have statistics (and removes the current, broken, behavior of printing devname with no newline if no statistics) In lieu of get_seq_buf + seq_commit, provide a way to "undo" writes if we use seq_printf Fixes: 252c651a4c85 ("blk-cgroup: stop using seq_get_buf") Signed-off-by: Khazhismel Kumykov --- block/blk-cgroup.c | 5 +++++ fs/seq_file.c | 14 ++++++++++++++ include/linux/seq_file.h | 2 ++ 3 files changed, 21 insertions(+) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index 8dfe62786cd5..50043a742c48 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -909,6 +909,7 @@ static void blkcg_print_one_stat(struct blkcg_gq *blkg, struct seq_file *s) const char *dname; unsigned seq; int i; + int scookie; if (!blkg->online) return; @@ -917,6 +918,8 @@ static void blkcg_print_one_stat(struct blkcg_gq *blkg, struct seq_file *s) if (!dname) return; + scookie = seq_checkpoint(s); + seq_printf(s, "%s ", dname); do { @@ -956,6 +959,8 @@ static void blkcg_print_one_stat(struct blkcg_gq *blkg, struct seq_file *s) if (has_stats) seq_printf(s, "\n"); + else + seq_restore(s, scookie); } static int blkcg_print_stat(struct seq_file *sf, void *v) diff --git a/fs/seq_file.c b/fs/seq_file.c index 7ab8a58c29b6..c3ec6b57334e 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -408,6 +408,20 @@ void seq_printf(struct seq_file *m, const char *f, ...) } EXPORT_SYMBOL(seq_printf); +int seq_checkpoint(struct seq_file *m) +{ + return m->count; +} +EXPORT_SYMBOL(seq_checkpoint); + +void seq_restore(struct seq_file *m, int count) +{ + if (WARN_ON_ONCE(count > m->count || count > m->size)) + return; + m->count = count; +} +EXPORT_SYMBOL(seq_restore); + #ifdef CONFIG_BINARY_PRINTF void seq_bprintf(struct seq_file *m, const char *f, const u32 *binary) { diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h index 60820ab511d2..d3a05f7c2750 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h @@ -117,6 +117,8 @@ __printf(2, 0) void seq_vprintf(struct seq_file *m, const char *fmt, va_list args); __printf(2, 3) void seq_printf(struct seq_file *m, const char *fmt, ...); +int seq_checkpoint(struct seq_file *m); +void seq_restore(struct seq_file *m, int count); void seq_putc(struct seq_file *m, char c); void seq_puts(struct seq_file *m, const char *s); void seq_put_decimal_ull_width(struct seq_file *m, const char *delimiter, -- 2.36.0.550.gb090851708-goog