From patchwork Tue Feb 23 22:27:10 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leszek Ciesielski X-Patchwork-Id: 81547 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o1NMRFO2008569 for ; Tue, 23 Feb 2010 22:27:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754477Ab0BWW1O (ORCPT ); Tue, 23 Feb 2010 17:27:14 -0500 Received: from mail-fx0-f219.google.com ([209.85.220.219]:33337 "EHLO mail-fx0-f219.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754434Ab0BWW1N convert rfc822-to-8bit (ORCPT ); Tue, 23 Feb 2010 17:27:13 -0500 Received: by fxm19 with SMTP id 19so4379594fxm.21 for ; Tue, 23 Feb 2010 14:27:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=uQj68wzbtco/phCIoA0x81/mau86vgtjOjc7A5FdWO0=; b=mtr0O00CGR2RtQWh/2o1FmhLI7lNQc8PilJ2DlVqcgxUmF8wCQqCDfAAbmjMAqNdpJ OKFZg1NUtavFExF75iz3xwDdr1DuIhPZqzhCLPK3gKZ5ZKz75U0gzG6b3o1hMjeN6IxJ lsyOGJMjEiCthXLnsgr3uctKA2zaFN2oRk+lg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=OFDUhWciERb1nntzJeULPrIwmC8BNdlOx2qDBa11ZquwDts3Vw+75+ARFCr1hz2Rlm bo2A+xARAjaznFv+NAs3TWgfgip0DXVajesSYX8uNw8dW6PPcliDI3h9r6DaFauxiI// z+C1hcN1t7GbmF7zCzpK2xW63gFJyLtHubyug= MIME-Version: 1.0 Received: by 10.103.87.39 with SMTP id p39mr4451079mul.95.1266964030920; Tue, 23 Feb 2010 14:27:10 -0800 (PST) In-Reply-To: <4AEAE84A.5080003@hp.com> References: <23a15590910300458y677692bbua62d2b41e9141bc7@mail.gmail.com> <4AEAE84A.5080003@hp.com> Date: Tue, 23 Feb 2010 23:27:10 +0100 Message-ID: <23a15591002231427i4cacb74ahb09fe9c98d74bd16@mail.gmail.com> Subject: Re: Reporting free space to userspace programs From: Leszek Ciesielski To: linux-btrfs Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 23 Feb 2010 22:27:15 +0000 (UTC) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 8a1ea6e..893c154 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -623,13 +623,18 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) { struct btrfs_root *root = btrfs_sb(dentry->d_sb); struct btrfs_super_block *disk_super = &root->fs_info->super_copy; + struct btrfs_device *device; int bits = dentry->d_sb->s_blocksize_bits; __be32 *fsid = (__be32 *)root->fs_info->fsid; buf->f_namelen = BTRFS_NAME_LEN; buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits; - buf->f_bfree = buf->f_blocks - - (btrfs_super_bytes_used(disk_super) >> bits); + buf->f_bfree = buf->f_blocks; + mutex_lock(&root->fs_info->fs_devices->device_list_mutex); + list_for_each_entry(device, &root->fs_info->fs_devices->devices, dev_list) { + buf->f_bfree -= (device->bytes_used >> bits); + } + mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); buf->f_bavail = buf->f_bfree; buf->f_bsize = dentry->d_sb->s_blocksize;