From patchwork Mon Sep 30 21:58:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach Brown X-Patchwork-Id: 2966991 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3EDD49F288 for ; Mon, 30 Sep 2013 21:58:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5605620268 for ; Mon, 30 Sep 2013 21:58:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5DE612024F for ; Mon, 30 Sep 2013 21:58:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756362Ab3I3V6G (ORCPT ); Mon, 30 Sep 2013 17:58:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11747 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755415Ab3I3V6F (ORCPT ); Mon, 30 Sep 2013 17:58:05 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8ULw363026829 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 30 Sep 2013 17:58:03 -0400 Received: from localhost (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r8ULw2aW024726 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Mon, 30 Sep 2013 17:58:03 -0400 Date: Mon, 30 Sep 2013 14:58:02 -0700 From: Zach Brown To: =?utf-8?Q?Ond=C5=99ej?= Kunc Cc: linux-btrfs@vger.kernel.org Subject: [PATCH] btrfs: init device stats for new devices Message-ID: <20130930215802.GB10831@lenny.home.zabbo.net> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP > I discovered one minor bug in BTRFS filesystem. You sure did. > ERROR: ioctl(BTRFS_IOC_GET_DEV_STATS) on /dev/sde failed: No such device > > But this is not true ... all specified devices exist and are members > of btrfs filesystem. In dmesg I see this: > ... > [973077.099118] btrfs: get dev_stats failed, not yet valid > .... > > What makes device statistics valid ? I tried doing full filesystem > scrub ... but it did not fix that issue. The stats are only initialized (considered valid) for devices that are known at mount. You could unmount and mount after adding (or replacing) new devices and they'd start returning stats. The following (bad) patch illustrates the problem, but the code should be restructured so stats are reliably read as devices are added. - z From: Zach Brown Date: Mon, 30 Sep 2013 17:48:05 -0400 Subject: [PATCH] btrfs: init device stats for new devices Device stats are only initialized (read from tree items) on mount. Trying to read device stats after adding or replacing new devices will return errors. This cheesy patch demonstrates the problem, but this should really be a natural side-effect of adding devices to the fs_devices list. We have evidence that trying to do it by hand doesn't work. Any preferences for how to restructure this? --- fs/btrfs/dev-replace.c | 4 +++- fs/btrfs/volumes.c | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index 5d84443..7309096 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -556,7 +556,9 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info, mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); - return 0; + ret = btrfs_init_dev_stats(root->fs_info); + + return ret; } static void btrfs_dev_replace_update_device_in_mapping_tree( diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 0431147..e4ccc9b 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2126,6 +2126,9 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) ret = btrfs_commit_transaction(trans, root); } + if (!ret) + ret = btrfs_init_dev_stats(root->fs_info); + return ret; error_trans: @@ -6060,6 +6063,9 @@ int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info) int item_size; struct btrfs_dev_stats_item *ptr; + if (device->dev_stats_valid) + continue; + key.objectid = 0; key.type = BTRFS_DEV_STATS_KEY; key.offset = device->devid;