From patchwork Wed Sep 27 02:02:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Misono Tomohiro X-Patchwork-Id: 9972965 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 4771460375 for ; Wed, 27 Sep 2017 02:03:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 397B32904E for ; Wed, 27 Sep 2017 02:03:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E16729050; Wed, 27 Sep 2017 02:03:00 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 D09DC2904E for ; Wed, 27 Sep 2017 02:02:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967819AbdI0CC5 (ORCPT ); Tue, 26 Sep 2017 22:02:57 -0400 Received: from mgwkm03.jp.fujitsu.com ([202.219.69.170]:29636 "EHLO mgwkm03.jp.fujitsu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966927AbdI0CC4 (ORCPT ); Tue, 26 Sep 2017 22:02:56 -0400 Received: from kw-mxq.gw.nic.fujitsu.com (unknown [192.168.231.130]) by mgwkm03.jp.fujitsu.com with smtp id 7a0e_7379_906bc499_a064_49b8_97d0_6055ed375649; Wed, 27 Sep 2017 11:02:52 +0900 Received: from g01jpfmpwyt02.exch.g01.fujitsu.local (g01jpfmpwyt02.exch.g01.fujitsu.local [10.128.193.56]) by kw-mxq.gw.nic.fujitsu.com (Postfix) with ESMTP id 46F23AC00B9 for ; Wed, 27 Sep 2017 11:02:51 +0900 (JST) Received: from g01jpexchyt38.g01.fujitsu.local (unknown [10.128.193.4]) by g01jpfmpwyt02.exch.g01.fujitsu.local (Postfix) with ESMTP id 7AB15584283 for ; Wed, 27 Sep 2017 11:02:50 +0900 (JST) X-SecurityPolicyCheck: OK by SHieldMailChecker v2.5.2 X-SHieldMailCheckerPolicyVersion: FJ-ISEC-20170217-enc X-SHieldMailCheckerMailID: 95bccec932474ba48bc8133988a9daa4 Subject: [PATCH v2 4/5] btrfs-progs: change seen_fsid to hold fd and DIR* From: "Misono, Tomohiro" To: References: <7610069d-bd81-2239-0be8-6635478c2dda@jp.fujitsu.com> Message-ID: <56bb58ff-e9d5-045b-7eb4-4e4583fa4866@jp.fujitsu.com> Date: Wed, 27 Sep 2017 11:02:47 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <7610069d-bd81-2239-0be8-6635478c2dda@jp.fujitsu.com> Content-Language: en-US X-SecurityPolicyCheck-GC: OK by FENCE-Mail X-TM-AS-MML: disable 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 Change seen_fsid to hold fd and DIR* in order to keep access to each fs. This will be used for 'subvol delete --commit-after'. Signed-off-by: Tomohiro Misono Reviewed-by: Qu Wenruo --- cmds-filesystem.c | 4 ++-- utils.c | 6 +++++- utils.h | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index c7dae40..4bbff43 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -277,7 +277,7 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices, u64 devs_found = 0; u64 total; - if (add_seen_fsid(fs_devices->fsid, seen_fsid_hash)) + if (add_seen_fsid(fs_devices->fsid, seen_fsid_hash, -1, NULL)) return; uuid_unparse(fs_devices->fsid, uuidbuf); @@ -324,7 +324,7 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info, struct btrfs_ioctl_dev_info_args *tmp_dev_info; int ret; - ret = add_seen_fsid(fs_info->fsid, seen_fsid_hash); + ret = add_seen_fsid(fs_info->fsid, seen_fsid_hash, -1, NULL); if (ret == -EEXIST) return 0; else if (ret) diff --git a/utils.c b/utils.c index f91d41e..bdfbfe0 100644 --- a/utils.c +++ b/utils.c @@ -1804,7 +1804,8 @@ int is_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[]) return 0; } -int add_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[]) +int add_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[], + int fd, DIR *dirstream) { u8 hash = fsid[0]; int slot = hash % SEEN_FSID_HASH_SIZE; @@ -1832,6 +1833,8 @@ insert: alloc->next = NULL; memcpy(alloc->fsid, fsid, BTRFS_FSID_SIZE); + alloc->fd = fd; + alloc->dirstream = dirstream; if (seen) seen->next = alloc; @@ -1851,6 +1854,7 @@ void free_seen_fsid(struct seen_fsid *seen_fsid_hash[]) seen = seen_fsid_hash[slot]; while (seen) { next = seen->next; + close_file_or_dir(seen->fd, seen->dirstream); free(seen); seen = next; } diff --git a/utils.h b/utils.h index da34e6c..bac7688 100644 --- a/utils.h +++ b/utils.h @@ -107,9 +107,12 @@ int get_fsid(const char *path, u8 *fsid, int silent); struct seen_fsid { u8 fsid[BTRFS_FSID_SIZE]; struct seen_fsid *next; + DIR *dirstream; + int fd; }; int is_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[]); -int add_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[]); +int add_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[], + int fd, DIR *dirstream); void free_seen_fsid(struct seen_fsid *seen_fsid_hash[]); int get_label(const char *btrfs_dev, char *label);