From patchwork Thu Dec 7 14:36:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 10099335 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 05B2B602BF for ; Thu, 7 Dec 2017 14:39:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC25E29E7C for ; Thu, 7 Dec 2017 14:39:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D48E92A473; Thu, 7 Dec 2017 14:39:48 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22C7829E7C for ; Thu, 7 Dec 2017 14:39:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753849AbdLGOjp (ORCPT ); Thu, 7 Dec 2017 09:39:45 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:50854 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753627AbdLGOjo (ORCPT ); Thu, 7 Dec 2017 09:39:44 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.21/8.16.0.21) with SMTP id vB7EdfmP175460 for ; Thu, 7 Dec 2017 14:39:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=1KC7b3sfVOm65yfMTqrZycy6i46DO5W830grFnfjP7E=; b=LvWta1S5NWGWi+8yZ6vo1GxEVD12r4kuSDDGazFfzOgbES3J+ct/OhEBvSxDWC+WJNju 36nwf+PyyjaGnMgYvdJ/bYEDpd8wbSfqVBb2CsNKkp+Y/f2Y2XVngEfqWEFShisryMXm Eh8LBWqiMdzeV/qSW3GBDGVKr1uWsxmYqg9hgoXuGMV6HRyubrm8m9p8nvsSMwk4eGfX gF7qt+Bmk3K1o1Pxhlea5fTGJxbqT/4JBKYQvNrfyxV0H488+moUHD6yfoybtzfMGPhN C34k+bKhkfXxNB6llFqW9cwLwpxUlVx2+nu66oKs32JS83plIgQPE7RJ/VZvQNyAKM6t Cw== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2epd12qk6a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 07 Dec 2017 14:39:41 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id vB7Ea2xd021398 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 7 Dec 2017 14:36:02 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id vB7Ea2tN006562 for ; Thu, 7 Dec 2017 14:36:02 GMT Received: from localhost.localdomain (/42.60.24.64) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Dec 2017 06:36:01 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH v5 3/3] btrfs: add feature to deregister all unmounted devices Date: Thu, 7 Dec 2017 22:36:23 +0800 Message-Id: <20171207143623.26710-4-anand.jain@oracle.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171207143623.26710-1-anand.jain@oracle.com> References: <20171207143623.26710-1-anand.jain@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8737 signatures=668643 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712070216 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This adds a feature to remove all registered/scanned devices, which are not mounted or it got staled by some means. Signed-off-by: Anand Jain Suggested-by: David Sterba --- v2-4: Does not exist. fs/btrfs/super.c | 7 ++++++- fs/btrfs/volumes.c | 23 +++++++++++++++++++++++ fs/btrfs/volumes.h | 1 + include/uapi/linux/btrfs.h | 6 +++++- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index ea6fe4742834..409804843b74 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2213,7 +2213,12 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd, &btrfs_fs_type, &fs_devices); break; case BTRFS_IOC_PURGE_DEV: - ret = btrfs_purge_one_device(vol->name, FMODE_READ, + if (vol->ioctl_flag & ~BTRFS_IOCTL_PURGE_ALL_DEVS) + return -EOPNOTSUPP; + if (vol->ioctl_flag & BTRFS_IOCTL_PURGE_ALL_DEVS) + ret = btrfs_purge_devices(); + else + ret = btrfs_purge_one_device(vol->name, FMODE_READ, &btrfs_fs_type, &fs_devices); break; case BTRFS_IOC_DEVICES_READY: diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 5adab70c7658..9fa2539a8493 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1336,6 +1336,29 @@ int btrfs_purge_one_device(const char *path, fmode_t flags, void *holder, return ret; } +int btrfs_purge_devices(void) +{ + struct btrfs_fs_devices *fs_devices, *tmp; + + mutex_lock(&uuid_mutex); + list_for_each_entry_safe(fs_devices, tmp, &fs_uuids, list) { + /* + * For now ignore stale device within a mounted FS. + */ + if (fs_devices->opened) + continue; + + pr_info("BTRFS: %pU num_devices %llu deregistered", + fs_devices->fsid, fs_devices->num_devices); + btrfs_sysfs_remove_fsid(fs_devices); + list_del(&fs_devices->list); + free_fs_devices(fs_devices); + } + mutex_unlock(&uuid_mutex); + + return 0; +} + /* * Look for a btrfs signature on a device. This may be called out of the mount path * and we are not allowed to call set_blocksize during the scan. The superblock diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 8389d2815750..dec27ee4f67d 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -424,6 +424,7 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, struct btrfs_fs_devices **fs_devices_ret); int btrfs_purge_one_device(const char *path, fmode_t flags, void *holder, struct btrfs_fs_devices **fs_devices_ret); +int btrfs_purge_devices(void); int btrfs_close_devices(struct btrfs_fs_devices *fs_devices); void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step); void btrfs_assign_next_active_device(struct btrfs_fs_info *fs_info, diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index de0f1144d945..eaf6ef04b300 100644 --- a/include/uapi/linux/btrfs.h +++ b/include/uapi/linux/btrfs.h @@ -28,8 +28,12 @@ /* this should be 4k */ #define BTRFS_PATH_NAME_MAX 4087 +#define BTRFS_IOCTL_PURGE_ALL_DEVS (1ULL << 0) struct btrfs_ioctl_vol_args { - __s64 fd; + union { + __s64 fd; + __u64 ioctl_flag; + }; char name[BTRFS_PATH_NAME_MAX + 1]; };