From patchwork Wed Sep 27 02:01:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Misono Tomohiro X-Patchwork-Id: 9972961 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 CC81760375 for ; Wed, 27 Sep 2017 02:01:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE80629048 for ; Wed, 27 Sep 2017 02:01:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B24852904D; Wed, 27 Sep 2017 02:01:59 +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 3656629048 for ; Wed, 27 Sep 2017 02:01:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754458AbdI0CB5 (ORCPT ); Tue, 26 Sep 2017 22:01:57 -0400 Received: from mgwym01.jp.fujitsu.com ([211.128.242.40]:27280 "EHLO mgwym01.jp.fujitsu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754335AbdI0CB4 (ORCPT ); Tue, 26 Sep 2017 22:01:56 -0400 Received: from yt-mxoi1.gw.nic.fujitsu.com (unknown [192.168.229.67]) by mgwym01.jp.fujitsu.com with smtp id 6853_6fb3_9463eadd_0fc7_4dc1_8af3_34796e29c490; Wed, 27 Sep 2017 11:01:53 +0900 Received: from g01jpfmpwyt02.exch.g01.fujitsu.local (g01jpfmpwyt02.exch.g01.fujitsu.local [10.128.193.56]) by yt-mxoi1.gw.nic.fujitsu.com (Postfix) with ESMTP id 86308AC019D for ; Wed, 27 Sep 2017 11:01:47 +0900 (JST) Received: from g01jpexchyt35.g01.fujitsu.local (unknown [10.128.193.4]) by g01jpfmpwyt02.exch.g01.fujitsu.local (Postfix) with ESMTP id B0058584364 for ; Wed, 27 Sep 2017 11:01:46 +0900 (JST) X-SecurityPolicyCheck: OK by SHieldMailChecker v2.5.2 X-SHieldMailCheckerPolicyVersion: FJ-ISEC-20170217-enc X-SHieldMailCheckerMailID: 3e2a2eab5a9f40f7aa51ff15f22f89a0 Subject: [PATCH v2 2/5] btrfs-progs: move get_fsid() to util.c From: "Misono, Tomohiro" To: References: <7610069d-bd81-2239-0be8-6635478c2dda@jp.fujitsu.com> Message-ID: Date: Wed, 27 Sep 2017 11:01:43 +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 Make get_fsid() to a common function. This will be used for 'subvol delete --commit-after'. Signed-off-by: Tomohiro Misono Reviewed-by: Qu Wenruo --- cmds-property.c | 30 ------------------------------ utils.c | 31 +++++++++++++++++++++++++++++++ utils.h | 1 + 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/cmds-property.c b/cmds-property.c index 9ae1246..03bafa0 100644 --- a/cmds-property.c +++ b/cmds-property.c @@ -48,36 +48,6 @@ static int parse_prop(const char *arg, const struct prop_handler *props, return -1; } -static int get_fsid(const char *path, u8 *fsid, int silent) -{ - int ret; - int fd; - struct btrfs_ioctl_fs_info_args args; - - fd = open(path, O_RDONLY); - if (fd < 0) { - ret = -errno; - if (!silent) - error("failed to open %s: %s", path, - strerror(-ret)); - goto out; - } - - ret = ioctl(fd, BTRFS_IOC_FS_INFO, &args); - if (ret < 0) { - ret = -errno; - goto out; - } - - memcpy(fsid, args.fsid, BTRFS_FSID_SIZE); - ret = 0; - -out: - if (fd != -1) - close(fd); - return ret; -} - static int check_btrfs_object(const char *object) { int ret; diff --git a/utils.c b/utils.c index 7a2710f..4a5dc60 100644 --- a/utils.c +++ b/utils.c @@ -1758,6 +1758,37 @@ out: return ret; } +int get_fsid(const char *path, u8 *fsid, int silent) +{ + int ret; + int fd; + struct btrfs_ioctl_fs_info_args args; + + fd = open(path, O_RDONLY); + if (fd < 0) { + ret = -errno; + if (!silent) + error("failed to open %s: %s", path, + strerror(-ret)); + goto out; + } + + ret = ioctl(fd, BTRFS_IOC_FS_INFO, &args); + if (ret < 0) { + ret = -errno; + goto out; + } + + memcpy(fsid, args.fsid, BTRFS_FSID_SIZE); + ret = 0; + +out: + if (fd != -1) + close(fd); + return ret; +} + + static int group_profile_devs_min(u64 flag) { switch (flag & BTRFS_BLOCK_GROUP_PROFILE_MASK) { diff --git a/utils.h b/utils.h index d28a05a..b3aabe1 100644 --- a/utils.h +++ b/utils.h @@ -100,6 +100,7 @@ int open_file_or_dir3(const char *fname, DIR **dirstream, int open_flags); void close_file_or_dir(int fd, DIR *dirstream); int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args, struct btrfs_ioctl_dev_info_args **di_ret); +int get_fsid(const char *path, u8 *fsid, int silent); int get_label(const char *btrfs_dev, char *label); int set_label(const char *btrfs_dev, const char *label);