From patchwork Sat Mar 10 18:17:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10273841 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B27AA602BD for ; Sat, 10 Mar 2018 18:20:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A144228BAE for ; Sat, 10 Mar 2018 18:20:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95A3D296E5; Sat, 10 Mar 2018 18:20:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5A48428BAE for ; Sat, 10 Mar 2018 18:20:40 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5596121E082A6; Sat, 10 Mar 2018 10:14:20 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c05::243; helo=mail-pg0-x243.google.com; envelope-from=jix024@eng.ucsd.edu; receiver=linux-nvdimm@lists.01.org Received: from mail-pg0-x243.google.com (mail-pg0-x243.google.com [IPv6:2607:f8b0:400e:c05::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4B3FE2258AEF8 for ; Sat, 10 Mar 2018 10:14:18 -0800 (PST) Received: by mail-pg0-x243.google.com with SMTP id x2so695637pgo.9 for ; Sat, 10 Mar 2018 10:20:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eng.ucsd.edu; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Pt+InNFWgEguf5dQzSEmvZrYVuGOJVgpH+6xw/DhNJw=; b=WmpE7nKO+Vjl8OPRXIHyxTzjOPredAeGOU0gnyI0QHgP2uPQIYfPu2OrQ4f25sv0E/ kH89hbgcM86bV/I9icdf6aMsgWIH1teW+t8dWmxF7NoRDKig4KY99SdCV/oxAg9uzTi4 ILqtanHZ4CTBpul4cZPyhMEooGWMQMa5+1PZg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Pt+InNFWgEguf5dQzSEmvZrYVuGOJVgpH+6xw/DhNJw=; b=hXNW2aL7AKAF15zxRCuaNwpF9ROnZCtGhEtkBM9dSuaRT2I+3ipWsIW9Yb2s1d0iVy L5w1ob2dz/2sWjOM/g9AMnzNRKa5eoPbzt9+wbgZbogMhiOZy1dMv+G2qL+ld/b2MsVo nLEaYELnG+zPdRZ47OVVN/Rx72PCvMWXb2UYSU/QThwdm6b2+Vub/XP/2w0LbeE+wFah HKsDgjIoZ6TUfL2U9i3BP3uzwXT+x5OX7XjWuKXIw1gSyXAq6GNez26ALerZ0nO52NqD mzRM3J51erOtdTN6jAgpANfK9VJ3VK+QuBwgUJuMXyY7UcvmM7EQbceCxSrOr8qAo+VF g3HQ== X-Gm-Message-State: AElRT7Gn7mXljnRtaxFWS9Oy4tFrhktf6bHrzo/0gUDNMzxtdFxiVgoo TWzGsq8pkxtElORzLAGlwtV33w== X-Google-Smtp-Source: AG47ELuzQ9TQDIevIFiH2Si+vheU2Gttoh+C11W5X4xRBeVtYEJdOcaMMLwGnhz5tKYN9tl2Jd9CEQ== X-Received: by 10.99.126.84 with SMTP id o20mr2218516pgn.188.1520706036775; Sat, 10 Mar 2018 10:20:36 -0800 (PST) Received: from brienza-desktop.8.8.4.4 (andxu.ucsd.edu. [132.239.17.134]) by smtp.gmail.com with ESMTPSA id h80sm9210167pfj.181.2018.03.10.10.20.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:20:36 -0800 (PST) From: Andiry Xu To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org Subject: [RFC v2 17/83] Add statfs support. Date: Sat, 10 Mar 2018 10:17:58 -0800 Message-Id: <1520705944-6723-18-git-send-email-jix024@eng.ucsd.edu> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520705944-6723-1-git-send-email-jix024@eng.ucsd.edu> References: <1520705944-6723-1-git-send-email-jix024@eng.ucsd.edu> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: coughlan@redhat.com, miklos@szeredi.hu, Andiry Xu , david@fromorbit.com, jack@suse.com, swanson@cs.ucsd.edu, swhiteho@redhat.com, andiry.xu@gmail.com MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP From: Andiry Xu Signed-off-by: Andiry Xu --- fs/nova/balloc.c | 18 ++++++++++++++++++ fs/nova/balloc.h | 1 + fs/nova/super.c | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/fs/nova/balloc.c b/fs/nova/balloc.c index cb627db..0742fe0 100644 --- a/fs/nova/balloc.c +++ b/fs/nova/balloc.c @@ -217,3 +217,21 @@ inline int nova_insert_blocktree(struct nova_sb_info *sbi, return ret; } + +/* We do not take locks so it's inaccurate */ +unsigned long nova_count_free_blocks(struct super_block *sb) +{ + struct nova_sb_info *sbi = NOVA_SB(sb); + struct free_list *free_list; + unsigned long num_free_blocks = 0; + int i; + + for (i = 0; i < sbi->cpus; i++) { + free_list = nova_get_free_list(sb, i); + num_free_blocks += free_list->num_free_blocks; + } + + return num_free_blocks; +} + + diff --git a/fs/nova/balloc.h b/fs/nova/balloc.h index 57a93e4..537532e 100644 --- a/fs/nova/balloc.h +++ b/fs/nova/balloc.h @@ -66,6 +66,7 @@ inline struct nova_range_node *nova_alloc_blocknode(struct super_block *sb); inline void nova_free_blocknode(struct super_block *sb, struct nova_range_node *bnode); extern void nova_init_blockmap(struct super_block *sb, int recovery); +extern unsigned long nova_count_free_blocks(struct super_block *sb); inline int nova_insert_blocktree(struct nova_sb_info *sbi, struct rb_root *tree, struct nova_range_node *new_node); diff --git a/fs/nova/super.c b/fs/nova/super.c index 9762f26..3500d19 100644 --- a/fs/nova/super.c +++ b/fs/nova/super.c @@ -629,6 +629,24 @@ static int nova_fill_super(struct super_block *sb, void *data, int silent) return retval; } +static int nova_statfs(struct dentry *d, struct kstatfs *buf) +{ + struct super_block *sb = d->d_sb; + struct nova_sb_info *sbi = (struct nova_sb_info *)sb->s_fs_info; + + buf->f_type = NOVA_SUPER_MAGIC; + buf->f_bsize = sb->s_blocksize; + + buf->f_blocks = sbi->num_blocks; + buf->f_bfree = buf->f_bavail = nova_count_free_blocks(sb); + buf->f_files = LONG_MAX; + buf->f_ffree = LONG_MAX - sbi->s_inodes_used_count; + buf->f_namelen = NOVA_NAME_LEN; + nova_dbg_verbose("nova_stats: total 4k free blocks 0x%llx\n", + buf->f_bfree); + return 0; +} + static int nova_show_options(struct seq_file *seq, struct dentry *root) { struct nova_sb_info *sbi = NOVA_SB(root->d_sb); @@ -794,6 +812,7 @@ static struct super_operations nova_sops = { .alloc_inode = nova_alloc_inode, .destroy_inode = nova_destroy_inode, .put_super = nova_put_super, + .statfs = nova_statfs, .remount_fs = nova_remount, .show_options = nova_show_options, };