From patchwork Mon May 18 09:16:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 6427041 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 860F4C0432 for ; Mon, 18 May 2015 09:16:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 95EB12060A for ; Mon, 18 May 2015 09:16:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A76162060C for ; Mon, 18 May 2015 09:16:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752889AbbERJQr (ORCPT ); Mon, 18 May 2015 05:16:47 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:34696 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752740AbbERJQq (ORCPT ); Mon, 18 May 2015 05:16:46 -0400 Received: by pabru16 with SMTP id ru16so144099031pab.1 for ; Mon, 18 May 2015 02:16:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=1DxUUl76wcsfAqBBX8kbAuTdMybzmHqLgBhMnFljSzQ=; b=P+mY4DzKfRASemUr2Oe2lUu1tXX/qbe0xUpPqitBVkX6MwmKvcg+1cFDaj5iijMy0d pnK5+sVOQc05EgW+/KBHw5eWKhSEYyOaC9CNCprbNMnRdN8I4howCoxDV17hAmknMtQp 9GVBgrOVhao8xxe//38XmBpgrhHpjxNtRdZ0JswBXNhdM60jGM0leLyeMGUZZEbZGnYM XUQzfU86DsdzN5xsVwF1K6ZCLYwl5I3wVDEtQ54/IVt1wZ+jjP2qd3Z57VKIZTpVhuIe ND4R+l6B1CKnFvPJBYuc+sXL6EccKUTvMaVdrV1KKzppSMPmFGrELexqYa0+YMwgMW+g gk0A== X-Gm-Message-State: ALoCoQnumektIktc6Gn30Ia/WlupTfCk8rF87XDT3vt8ToOWwY6oVaxsTko4cS7zb9DJRbdPJkvF X-Received: by 10.70.35.171 with SMTP id i11mr30526185pdj.103.1431940605589; Mon, 18 May 2015 02:16:45 -0700 (PDT) Received: from mew.localdomain (c-76-104-211-44.hsd1.wa.comcast.net. [76.104.211.44]) by mx.google.com with ESMTPSA id v2sm9377370pdn.90.2015.05.18.02.16.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 May 2015 02:16:44 -0700 (PDT) From: Omar Sandoval To: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org Cc: Qu Wenruo , Omar Sandoval Subject: [PATCH v3 3/6] Btrfs: clean up error handling in mount_subvol() Date: Mon, 18 May 2015 02:16:28 -0700 Message-Id: <27552c486222b6a99a4a1b6eafc1e598638df4b0.1431939732.git.osandov@osandov.com> X-Mailer: git-send-email 2.4.1 In-Reply-To: References: In-Reply-To: References: 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 In preparation for new functionality in mount_subvol(), give it ownership of subvol_name and tidy up the error paths. Reviewed-by: David Sterba Signed-off-by: Omar Sandoval --- fs/btrfs/super.c | 61 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index b5d04e4..460e0ea 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1176,55 +1176,61 @@ static struct dentry *mount_subvol(const char *subvol_name, int flags, const char *device_name, char *data) { struct dentry *root; - struct vfsmount *mnt; + struct vfsmount *mnt = NULL; char *newargs; + int ret; newargs = setup_root_args(data); - if (!newargs) - return ERR_PTR(-ENOMEM); - mnt = vfs_kern_mount(&btrfs_fs_type, flags, device_name, - newargs); + if (!newargs) { + root = ERR_PTR(-ENOMEM); + goto out; + } - if (PTR_RET(mnt) == -EBUSY) { + mnt = vfs_kern_mount(&btrfs_fs_type, flags, device_name, newargs); + if (PTR_ERR_OR_ZERO(mnt) == -EBUSY) { if (flags & MS_RDONLY) { - mnt = vfs_kern_mount(&btrfs_fs_type, flags & ~MS_RDONLY, device_name, - newargs); + mnt = vfs_kern_mount(&btrfs_fs_type, flags & ~MS_RDONLY, + device_name, newargs); } else { - int r; - mnt = vfs_kern_mount(&btrfs_fs_type, flags | MS_RDONLY, device_name, - newargs); + mnt = vfs_kern_mount(&btrfs_fs_type, flags | MS_RDONLY, + device_name, newargs); if (IS_ERR(mnt)) { - kfree(newargs); - return ERR_CAST(mnt); + root = ERR_CAST(mnt); + mnt = NULL; + goto out; } down_write(&mnt->mnt_sb->s_umount); - r = btrfs_remount(mnt->mnt_sb, &flags, NULL); + ret = btrfs_remount(mnt->mnt_sb, &flags, NULL); up_write(&mnt->mnt_sb->s_umount); - if (r < 0) { - /* FIXME: release vfsmount mnt ??*/ - kfree(newargs); - return ERR_PTR(r); + if (ret < 0) { + root = ERR_PTR(ret); + goto out; } } } - - kfree(newargs); - - if (IS_ERR(mnt)) - return ERR_CAST(mnt); + if (IS_ERR(mnt)) { + root = ERR_CAST(mnt); + mnt = NULL; + goto out; + } root = mount_subtree(mnt, subvol_name); + /* mount_subtree() drops our reference on the vfsmount. */ + mnt = NULL; if (!IS_ERR(root) && !is_subvolume_inode(d_inode(root))) { struct super_block *s = root->d_sb; dput(root); root = ERR_PTR(-EINVAL); deactivate_locked_super(s); - printk(KERN_ERR "BTRFS: '%s' is not a valid subvolume\n", - subvol_name); + pr_err("BTRFS: '%s' is not a valid subvolume\n", subvol_name); } +out: + mntput(mnt); + kfree(newargs); + kfree(subvol_name); return root; } @@ -1310,9 +1316,8 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, } if (subvol_name) { - root = mount_subvol(subvol_name, flags, device_name, data); - kfree(subvol_name); - return root; + /* mount_subvol() will free subvol_name. */ + return mount_subvol(subvol_name, flags, device_name, data); } security_init_mnt_opts(&new_sec_opts);