From patchwork Mon Mar 23 17:34:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Van Braeckel X-Patchwork-Id: 6074641 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1B3F0BF90F for ; Mon, 23 Mar 2015 17:36:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4B74F202FE for ; Mon, 23 Mar 2015 17:36:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6BE21202F8 for ; Mon, 23 Mar 2015 17:36:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753122AbbCWRgO (ORCPT ); Mon, 23 Mar 2015 13:36:14 -0400 Received: from mail-wg0-f42.google.com ([74.125.82.42]:35178 "EHLO mail-wg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752423AbbCWRgM (ORCPT ); Mon, 23 Mar 2015 13:36:12 -0400 Received: by wgdm6 with SMTP id m6so151900450wgd.2; Mon, 23 Mar 2015 10:36:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=rCD3Ad4/CRDqXd9p0mGz9ALXF0G6gfvaQ49XFfxOc+E=; b=u932j6V2TLMivcEcbMjmj6vZeFtDI1VJrxHF8JcbDXyn4boQAyqDufH/9PYFdOUOPj 9NEh+ay2TMfsaQfg6JcJk8Ed0lN+zKjMyNIoVNfso5cd0TGld5drMnTXUOsGefDreUnP N3RP3Zs5lrPZi5XFrku0WyhMTjhznQpw+w+2bx/fMgCXaGdWV87lY5Qzet+hAsEBgVfy Qs60+/6yIKYVqrgjuWbwoLsNZqcyC61Rg6wigzHDgJi9JpkqPxQvr/bXrY4sg+U5cSIH pC5P/B27gkRajLwePf4qHT7OtBfHtqBNY7Pqwdvxfb0j6OkCgmRGOfO2vRKMCoPa+lso 05pw== X-Received: by 10.180.81.7 with SMTP id v7mr21455249wix.27.1427132171231; Mon, 23 Mar 2015 10:36:11 -0700 (PDT) Received: from localhost.localdomain ([188.188.28.255]) by mx.google.com with ESMTPSA id n6sm2369011wjy.8.2015.03.23.10.36.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Mar 2015 10:36:10 -0700 (PDT) From: Tom Van Braeckel To: clm@fb.com, jbacik@fb.com, dsterba@suse.cz, linux-btrfs@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Tom Van Braeckel , Martin Kepplinger Subject: [PATCH] btrfs: explicitly set control file's private_data Date: Mon, 23 Mar 2015 18:34:13 +0100 Message-Id: <1427132053-410-1-git-send-email-tomvanbraeckel@gmail.com> X-Mailer: git-send-email 2.1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_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 The private_data member of the Btrfs control device file (/dev/btrfs-control) is used to hold the current transaction and needs to be initialized to NULL to signify that no transaction is in progress. We explicitly set the control file's private_data to NULL to be independent of whatever value the misc subsystem initializes it to. Backstory: ---------- The misc subsystem (which is used by /dev/btrfs-control) initializes a file's private_data to point to the misc device when a driver has registered a custom open file operation and initializes it to NULL when a custom open file operation has *not* been provided. This subtle quirk is confusing, to the point where kernel code registers *empty* file open operations to have private_data point to the misc device structure. And it leads to bugs, where the addition or removal of a custom open file operation surprisingly changes the initial contents of a file's private_data structure. To simplify things in the misc subsystem, a patch [1] has been proposed to *always* set private_data to point to the misc device instead of only doing this when a custom open file operation has been registered. But before we can fix this in the misc subsystem itself, we need to modify the (few) drivers that rely on this very subtle behavior. [1] https://lkml.org/lkml/2014/12/4/939 Signed-off-by: Martin Kepplinger Signed-off-by: Tom Van Braeckel Acked-by: David Sterba --- fs/btrfs/super.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 05fef19..3cfb5ee 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1908,6 +1908,16 @@ static struct file_system_type btrfs_fs_type = { }; MODULE_ALIAS_FS("btrfs"); +static int btrfs_control_open(struct inode *inode, struct file *file) +{ + /* The control file's private_data is used to hold the + * transaction when it is started and is used to keep + * track of whether a transaction is already in progress. + */ + file->private_data = NULL; + return 0; +} + /* * used by btrfsctl to scan devices when no FS is mounted */ @@ -2009,6 +2019,7 @@ static const struct super_operations btrfs_super_ops = { }; static const struct file_operations btrfs_ctl_fops = { + .open = btrfs_control_open, .unlocked_ioctl = btrfs_control_ioctl, .compat_ioctl = btrfs_control_ioctl, .owner = THIS_MODULE,