From patchwork Sat Oct 30 17:56:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sage Weil X-Patchwork-Id: 292332 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9UIGK4f008543 for ; Sat, 30 Oct 2010 18:16:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755289Ab0J3SQR (ORCPT ); Sat, 30 Oct 2010 14:16:17 -0400 Received: from cobra.newdream.net ([66.33.216.30]:44718 "EHLO cobra.newdream.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755082Ab0J3SQO (ORCPT ); Sat, 30 Oct 2010 14:16:14 -0400 Received: from vapre.ww.newdream.net (dsl092-035-022.lax1.dsl.speakeasy.net [66.92.35.22]) by cobra.newdream.net (Postfix) with ESMTPA id 6D250BC82C; Sat, 30 Oct 2010 11:19:35 -0700 (PDT) From: Sage Weil To: linux-btrfs@vger.kernel.org Cc: Sage Weil Subject: [PATCH 3/3] btrfs: implement 'start-sync' and 'wait-sync' commands Date: Sat, 30 Oct 2010 10:56:06 -0700 Message-Id: <1288461366-26914-3-git-send-email-sage@newdream.net> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1288461366-26914-1-git-send-email-sage@newdream.net> References: <1288461366-26914-1-git-send-email-sage@newdream.net> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Sat, 30 Oct 2010 18:16:23 +0000 (UTC) diff --git a/btrfs.c b/btrfs.c index c4b9a31..d45ac1f 100644 --- a/btrfs.c +++ b/btrfs.c @@ -83,6 +83,15 @@ static struct Command commands[] = { "filesystem sync", "\n" "Force a sync on the filesystem ." }, + { do_start_sync, 1, + "filesystem start-sync", "\n" + "Start a sync on the filesystem , and print the resulting\n" + "transaction id." + }, + { do_wait_sync, 2, + "filesystem wait-sync", " \n" + "Wait for the transaction on the filesystem at to commit." + }, { do_resize, 2, "filesystem resize", "[+/-][gkm]|max \n" "Resize the file system. If 'max' is passed, the filesystem\n" diff --git a/btrfs_cmds.c b/btrfs_cmds.c index 6da5862..5b5bb15 100644 --- a/btrfs_cmds.c +++ b/btrfs_cmds.c @@ -548,6 +548,55 @@ int do_fssync(int argc, char **argv) return 0; } +int do_start_sync(int argc, char **argv) +{ + int fd, res; + char *path = argv[1]; + __u64 transid; + + fd = open_file_or_dir(path); + if (fd < 0) { + fprintf(stderr, "ERROR: can't access to '%s'\n", path); + return 12; + } + + printf("StartSync '%s'\n", path); + res = ioctl(fd, BTRFS_IOC_START_SYNC, &transid); + close(fd); + if( res < 0 ){ + fprintf(stderr, "ERROR: unable to fs-syncing '%s'\n", path); + return 16; + } else { + printf("transid %llu\n", (unsigned long long)transid); + } + + return 0; +} + +int do_wait_sync(int argc, char **argv) +{ + int fd, res; + char *path = argv[1]; + __u64 transid = atoll(argv[2]); + + fd = open_file_or_dir(path); + if (fd < 0) { + fprintf(stderr, "ERROR: can't access to '%s'\n", path); + return 12; + } + + printf("WaitSync '%s' transid %llu\n", path, (unsigned long long)transid); + res = ioctl(fd, BTRFS_IOC_WAIT_SYNC, &transid); + close(fd); + if( res < 0 ){ + fprintf(stderr, "ERROR: unable to wait-sync on '%s' transid %llu: %s\n", path, + (unsigned long long)transid, strerror(errno)); + return 16; + } + + return 0; +} + int do_scan(int argc, char **argv) { int i, fd; diff --git a/btrfs_cmds.h b/btrfs_cmds.h index c44dc79..e0e5ceb 100644 --- a/btrfs_cmds.h +++ b/btrfs_cmds.h @@ -20,6 +20,8 @@ int do_create_snap_async(int nargs, char **argv); int do_delete_subvolume(int nargs, char **argv); int do_create_subvol(int nargs, char **argv); int do_fssync(int nargs, char **argv); +int do_start_sync(int nargs, char **argv); +int do_wait_sync(int nargs, char **argv); int do_defrag(int argc, char **argv); int do_show_filesystem(int nargs, char **argv); int do_add_volume(int nargs, char **args);