From patchwork Tue Sep 26 05:45:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Misono Tomohiro X-Patchwork-Id: 9971031 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 05720602D8 for ; Tue, 26 Sep 2017 05:45:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBC7A28E9D for ; Tue, 26 Sep 2017 05:45:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF2B728EB1; Tue, 26 Sep 2017 05:45:14 +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 5A0A228E9D for ; Tue, 26 Sep 2017 05:45:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965170AbdIZFpM (ORCPT ); Tue, 26 Sep 2017 01:45:12 -0400 Received: from mgwym01.jp.fujitsu.com ([211.128.242.40]:18083 "EHLO mgwym01.jp.fujitsu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965051AbdIZFpM (ORCPT ); Tue, 26 Sep 2017 01:45:12 -0400 Received: from yt-mxoi1.gw.nic.fujitsu.com (unknown [192.168.229.67]) by mgwym01.jp.fujitsu.com with smtp id 6e56_4273_11891a61_7b83_4a45_877f_5d329c3fa52a; Tue, 26 Sep 2017 14:45:05 +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 A86B0AC0107 for ; Tue, 26 Sep 2017 14:45:04 +0900 (JST) Received: from G01JPEXCHYT15.g01.fujitsu.local (G01JPEXCHYT15.g01.fujitsu.local [10.128.194.54]) by g01jpfmpwyt02.exch.g01.fujitsu.local (Postfix) with ESMTP id C75DD584302 for ; Tue, 26 Sep 2017 14:45:03 +0900 (JST) X-SecurityPolicyCheck: OK by SHieldMailChecker v2.5.2 X-SHieldMailCheckerPolicyVersion: FJ-ISEC-20170217-enc X-SHieldMailCheckerMailID: c1b786f067ff47d1a3e87d4b31e0aaf1 Subject: [PATCH 1/4] btrfs-progs: move get_fsid() to util.c From: "Misono, Tomohiro" To: References: <8c494134-ce71-4ca7-dc91-06d36774cc84@jp.fujitsu.com> Message-ID: <7aa5d067-bd06-ee73-ee61-33ca1ea2223e@jp.fujitsu.com> Date: Tue, 26 Sep 2017 14:45:00 +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: <8c494134-ce71-4ca7-dc91-06d36774cc84@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 --- 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);