From patchwork Thu Feb 15 19:05:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10223415 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 4F281602CB for ; Thu, 15 Feb 2018 19:06:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F80F29485 for ; Thu, 15 Feb 2018 19:06:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 347B9294AF; Thu, 15 Feb 2018 19:06:28 +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 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 B096729485 for ; Thu, 15 Feb 2018 19:06:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161188AbeBOTG0 (ORCPT ); Thu, 15 Feb 2018 14:06:26 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:46630 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161045AbeBOTFq (ORCPT ); Thu, 15 Feb 2018 14:05:46 -0500 Received: by mail-pg0-f68.google.com with SMTP id a11so485563pgu.13 for ; Thu, 15 Feb 2018 11:05:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=9F+Y8bO7hRu+jE2i4yLtvcb/faSLnQphB9g/78VpEZw=; b=mCEdtdiqV35IvtYfgCUXEOE/BSmFmZMoP4niXPdRUGwpFSmEb4/cYr3V0VB9AglZJL SPJTDHOBPeUZTHZd2WruWydfhy2LXM/sCznWM5+KC/YscYc3ylajdkeQ41d8zhGRnYbL omKEsowb1h2ZnKvHj01bDq8KX7b9GpLn3drJZNDRoEmihjgIGJBUhgUGEDTE4MxGhwOl 9P9m8FV4y7yx06EmiWsEuDp7lrV4A2wGSsAmYzvygpmY7eLq+xIfPCBnrDTibCvC3rlp GzO6r8ioHQE9ESETzsX3klDydQ0vchzesd1UM3+D5cVuy3o4tLfX4buHhr3a2GUS1ycP NiVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=9F+Y8bO7hRu+jE2i4yLtvcb/faSLnQphB9g/78VpEZw=; b=ZXlp6ePJHQIItkSV+CCIvNUbWijzCZxMuujdIq4bjMbbhvcEbVR7gRoCBCEr9bvmPW AugA0le0JyvRTHRwsczFP2eTzP6ghV8NqwsIHFlwQTKFxvndq4P5J56pd7eroCjawV93 kHXkdOu+dBluZC9Wvvyt2ouXvO23QSs78iIJVdXh09/vaTWoxhcwVY6cApbUymN0WNLZ 5qnI2Tpi+wnWcg6Abauq2R+dNGZlW4YbIO4QSCS0m9Tw4hdZX3yaT9RnskKnEcD8WBVB XhWP8H1refWA97wnc3eG7jgReI0cqJtYHqeTVbL2RuRn5e//dLFdUdwxNxkaLNwRgKrV 4wCQ== X-Gm-Message-State: APf1xPDSxmpn5/cpRNQZH8piILWzWDTKFC/x7Q3LBneqJX05pYysfchZ dD8hoRORRhVOyHRvZgivtc3oa2RtJk0= X-Google-Smtp-Source: AH8x224OJrwQmCcO7e6KNR8X9Ul+sNW3dyPAnWMIkE/2hjJnsUmhNurO9DCu2tlD+LMPO6649Q31Ag== X-Received: by 10.99.146.68 with SMTP id s4mr2972501pgn.295.1518721545455; Thu, 15 Feb 2018 11:05:45 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:200::6:4a19]) by smtp.gmail.com with ESMTPSA id p1sm40467428pgr.44.2018.02.15.11.05.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Feb 2018 11:05:44 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH v2 17/27] btrfs-progs: use libbtrfsutil for sync ioctls Date: Thu, 15 Feb 2018 11:05:02 -0800 Message-Id: <04c8e9a17db4aff5b00509fb83420e3075f7aaf6.1518720598.git.osandov@fb.com> X-Mailer: git-send-email 2.16.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-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval Signed-off-by: Omar Sandoval --- cmds-filesystem.c | 19 ++++++------------- cmds-qgroup.c | 10 +++++++--- cmds-subvolume.c | 25 +++++++++++++++++-------- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 467aff11..225df421 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -28,6 +28,8 @@ #include #include +#include + #include "kerncompat.h" #include "ctree.h" #include "utils.h" @@ -813,25 +815,16 @@ static const char * const cmd_filesystem_sync_usage[] = { static int cmd_filesystem_sync(int argc, char **argv) { - int fd, res; - char *path; - DIR *dirstream = NULL; + enum btrfs_util_error err; clean_args_no_options(argc, argv, cmd_filesystem_sync_usage); if (check_argc_exact(argc - optind, 1)) usage(cmd_filesystem_sync_usage); - path = argv[optind]; - - fd = btrfs_open_dir(path, &dirstream, 1); - if (fd < 0) - return 1; - - res = ioctl(fd, BTRFS_IOC_SYNC); - close_file_or_dir(fd, dirstream); - if( res < 0 ){ - error("sync ioctl failed on '%s': %m", path); + err = btrfs_util_sync(argv[optind]); + if (err) { + error_btrfs_util(err); return 1; } diff --git a/cmds-qgroup.c b/cmds-qgroup.c index 4f99e419..f9a52fa8 100644 --- a/cmds-qgroup.c +++ b/cmds-qgroup.c @@ -20,6 +20,8 @@ #include #include +#include + #include "ctree.h" #include "ioctl.h" @@ -299,6 +301,7 @@ static int cmd_qgroup_show(int argc, char **argv) int filter_flag = 0; unsigned unit_mode; int sync = 0; + enum btrfs_util_error err; struct btrfs_qgroup_comparer_set *comparer_set; struct btrfs_qgroup_filter_set *filter_set; @@ -372,9 +375,10 @@ static int cmd_qgroup_show(int argc, char **argv) } if (sync) { - ret = ioctl(fd, BTRFS_IOC_SYNC); - if (ret < 0) - warning("sync ioctl failed on '%s': %m", path); + err = btrfs_util_sync_fd(fd); + if (err) + warning("sync ioctl failed on '%s': %s", path, + strerror(errno)); } if (filter_flag) { diff --git a/cmds-subvolume.c b/cmds-subvolume.c index edcb4f11..6006a278 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -28,6 +28,8 @@ #include #include +#include + #include "kerncompat.h" #include "ioctl.h" #include "qgroup.h" @@ -219,12 +221,18 @@ out: static int wait_for_commit(int fd) { - int ret; + enum btrfs_util_error err; + uint64_t transid; - ret = ioctl(fd, BTRFS_IOC_START_SYNC, NULL); - if (ret < 0) - return ret; - return ioctl(fd, BTRFS_IOC_WAIT_SYNC, NULL); + err = btrfs_util_start_sync_fd(fd, &transid); + if (err) + return -1; + + err = btrfs_util_wait_sync_fd(fd, transid); + if (err) + return -1; + + return 0; } static const char * const cmd_subvol_delete_usage[] = { @@ -911,6 +919,7 @@ static int cmd_subvol_find_new(int argc, char **argv) char *subvol; u64 last_gen; DIR *dirstream = NULL; + enum btrfs_util_error err; clean_args_no_options(argc, argv, cmd_subvol_find_new_usage); @@ -934,9 +943,9 @@ static int cmd_subvol_find_new(int argc, char **argv) if (fd < 0) return 1; - ret = ioctl(fd, BTRFS_IOC_SYNC); - if (ret < 0) { - error("sync ioctl failed on '%s': %m", subvol); + err = btrfs_util_sync_fd(fd); + if (err) { + error_btrfs_util(err); close_file_or_dir(fd, dirstream); return 1; }