From patchwork Tue Nov 1 08:01:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9407041 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 6231A60722 for ; Tue, 1 Nov 2016 08:02:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 545DB295E5 for ; Tue, 1 Nov 2016 08:02:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 493F0295F3; Tue, 1 Nov 2016 08:02:20 +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 662C5295E5 for ; Tue, 1 Nov 2016 08:02:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1167774AbcKAICM (ORCPT ); Tue, 1 Nov 2016 04:02:12 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:20095 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S965821AbcKAICK (ORCPT ); Tue, 1 Nov 2016 04:02:10 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="938907" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 01 Nov 2016 16:01:56 +0800 Received: from localhost.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 4201041B4BC8; Tue, 1 Nov 2016 16:01:52 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org, dsterba@suse.cz Cc: David Sterba Subject: [PATCH v3 4/4] btrfs-progs: remove send-test tool Date: Tue, 1 Nov 2016 16:01:46 +0800 Message-Id: <20161101080147.13163-5-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161101080147.13163-1-quwenruo@cn.fujitsu.com> References: <20161101080147.13163-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: 4201041B4BC8.AD3CF X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com 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 Since new "receive --dump" has better output and structure, it's time to remove old and function-weak send-test tool. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- Makefile.in | 6 +- send-test.c | 447 ------------------------------------------------------------ 2 files changed, 1 insertion(+), 452 deletions(-) delete mode 100644 send-test.c diff --git a/Makefile.in b/Makefile.in index c535c19..9295d32 100644 --- a/Makefile.in +++ b/Makefile.in @@ -428,10 +428,6 @@ test-ioctl: ioctl-test ioctl-test-32 ioctl-test-64 $(Q)./ioctl-test-32 > ioctl-test-32.log $(Q)./ioctl-test-64 > ioctl-test-64.log -send-test: $(objects) $(libs) send-test.o - @echo " [LD] $@" - $(Q)$(CC) $(CFLAGS) -o send-test $(objects) $(libs) send-test.o $(LDFLAGS) $(LIBS) - library-test: $(libs_shared) library-test.o @echo " [LD] $@" $(Q)$(CC) $(CFLAGS) -o library-test library-test.o $(LDFLAGS) -lbtrfs @@ -464,7 +460,7 @@ clean: $(CLEANDIRS) @echo "Cleaning" $(Q)$(RM) -f -- $(progs) cscope.out *.o *.o.d \ kernel-lib/*.o kernel-lib/*.o.d \ - dir-test ioctl-test quick-test send-test library-test library-test-static \ + dir-test ioctl-test quick-test library-test library-test-static \ btrfs.static mkfs.btrfs.static \ $(check_defs) \ $(libs) $(lib_links) \ diff --git a/send-test.c b/send-test.c deleted file mode 100644 index 4645b89..0000000 --- a/send-test.c +++ /dev/null @@ -1,447 +0,0 @@ -/* - * Copyright (C) 2013 SUSE. All rights reserved. - * - * This code is adapted from cmds-send.c and cmds-receive.c, - * Both of which are: - * - * Copyright (C) 2012 Alexander Block. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License v2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * This should be compilable without the rest of the btrfs-progs - * source distribution. - */ -#if BTRFS_FLAT_INCLUDES -#include "send-utils.h" -#include "send-stream.h" -#else -#include -#include -#endif /* BTRFS_FLAT_INCLUDES */ - -static int pipefd[2]; -struct btrfs_ioctl_send_args io_send = {0, }; -static char *subvol_path; -static char *root_path; - -struct recv_args { - char *full_subvol_path; - char *root_path; -}; - -void usage(int error) -{ - printf("send-test \n"); - if (error) - exit(error); -} - -static int print_subvol(const char *path, const u8 *uuid, u64 ctransid, - void *user) -{ - struct recv_args *r = user; - char uuid_str[BTRFS_UUID_UNPARSED_SIZE]; - - r->full_subvol_path = path_cat(r->root_path, path); - uuid_unparse(uuid, uuid_str); - - printf("subvol\t%s\t%llu\t%s\n", uuid_str, - (unsigned long long)ctransid, r->full_subvol_path); - - return 0; -} - -static int print_snapshot(const char *path, const u8 *uuid, u64 ctransid, - const u8 *parent_uuid, u64 parent_ctransid, - void *user) -{ - struct recv_args *r = user; - char uuid_str[BTRFS_UUID_UNPARSED_SIZE]; - char parent_uuid_str[BTRFS_UUID_UNPARSED_SIZE]; - - r->full_subvol_path = path_cat(r->root_path, path); - uuid_unparse(uuid, uuid_str); - uuid_unparse(parent_uuid, parent_uuid_str); - - printf("snapshot\t%s\t%llu\t%s\t%llu\t%s\n", uuid_str, - (unsigned long long)ctransid, parent_uuid_str, - (unsigned long long)parent_ctransid, r->full_subvol_path); - - return 0; -} - -static int print_mkfile(const char *path, void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("mkfile\t%s\n", full_path); - - free(full_path); - return 0; -} - -static int print_mkdir(const char *path, void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("mkdir\t%s\n", full_path); - - free(full_path); - return 0; -} - -static int print_mknod(const char *path, u64 mode, u64 dev, void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("mknod\t%llo\t0x%llx\t%s\n", (unsigned long long)mode, - (unsigned long long)dev, full_path); - - free(full_path); - return 0; -} - -static int print_mkfifo(const char *path, void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("mkfifo\t%s\n", full_path); - - free(full_path); - return 0; -} - -static int print_mksock(const char *path, void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("mksock\t%s\n", full_path); - - free(full_path); - return 0; -} - -static int print_symlink(const char *path, const char *lnk, void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("symlink\t%s\t%s\n", lnk, full_path); - - free(full_path); - return 0; -} - -static int print_rename(const char *from, const char *to, void *user) -{ - struct recv_args *r = user; - char *full_from = path_cat(r->full_subvol_path, from); - char *full_to = path_cat(r->full_subvol_path, to); - - printf("rename\t%s\t%s\n", from, to); - - free(full_from); - free(full_to); - return 0; -} - -static int print_link(const char *path, const char *lnk, void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("link\t%s\t%s\n", lnk, full_path); - - free(full_path); - return 0; -} - -static int print_unlink(const char *path, void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("unlink\t%s\n", full_path); - - free(full_path); - return 0; -} - -static int print_rmdir(const char *path, void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("rmdir\t%s\n", full_path); - - free(full_path); - return 0; -} - -static int print_write(const char *path, const void *data, u64 offset, - u64 len, void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("write\t%llu\t%llu\t%s\n", (unsigned long long)offset, - (unsigned long long)len, full_path); - - free(full_path); - return 0; -} - -static int print_clone(const char *path, u64 offset, u64 len, - const u8 *clone_uuid, u64 clone_ctransid, - const char *clone_path, u64 clone_offset, - void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("clone\t%s\t%s\n", full_path, clone_path); - - free(full_path); - return 0; -} - -static int print_set_xattr(const char *path, const char *name, - const void *data, int len, void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("set_xattr\t%s\t%s\t%d\n", full_path, - name, len); - - free(full_path); - return 0; -} - -static int print_remove_xattr(const char *path, const char *name, void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("remove_xattr\t%s\t%s\n", full_path, name); - - free(full_path); - return 0; -} - -static int print_truncate(const char *path, u64 size, void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("truncate\t%llu\t%s\n", (unsigned long long)size, full_path); - - free(full_path); - return 0; -} - -static int print_chmod(const char *path, u64 mode, void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("chmod\t%llo\t%s\n", (unsigned long long)mode, full_path); - - free(full_path); - return 0; -} - -static int print_chown(const char *path, u64 uid, u64 gid, void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("chown\t%llu\t%llu\t%s\n", (unsigned long long)uid, - (unsigned long long)gid, full_path); - - free(full_path); - return 0; -} - -static int print_utimes(const char *path, struct timespec *at, - struct timespec *mt, struct timespec *ct, - void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("utimes\t%s\n", full_path); - - free(full_path); - return 0; -} - -static int print_update_extent(const char *path, u64 offset, u64 len, - void *user) -{ - struct recv_args *r = user; - char *full_path = path_cat(r->full_subvol_path, path); - - printf("update_extent\t%s\t%llu\t%llu\n", full_path, offset, len); - - free(full_path); - return 0; -} - -static struct btrfs_send_ops send_ops_print = { - .subvol = print_subvol, - .snapshot = print_snapshot, - .mkfile = print_mkfile, - .mkdir = print_mkdir, - .mknod = print_mknod, - .mkfifo = print_mkfifo, - .mksock = print_mksock, - .symlink = print_symlink, - .rename = print_rename, - .link = print_link, - .unlink = print_unlink, - .rmdir = print_rmdir, - .write = print_write, - .clone = print_clone, - .set_xattr = print_set_xattr, - .remove_xattr = print_remove_xattr, - .truncate = print_truncate, - .chmod = print_chmod, - .chown = print_chown, - .utimes = print_utimes, - .update_extent = print_update_extent, -}; - -static void *process_thread(void *arg_) -{ - int ret; - - while (1) { - ret = btrfs_read_and_process_send_stream(pipefd[0], - &send_ops_print, arg_, 0); - if (ret) - break; - } - - if (ret > 0) - ret = 0; - - return ERR_PTR(ret); -} - -int main(int argc, char **argv) -{ - int ret = 0; - int subvol_fd; - pthread_t t_read; - void *t_err = NULL; - struct recv_args r; - - if (argc != 3) - usage(EINVAL); - - root_path = realpath(argv[1], NULL); - if (!root_path) { - ret = errno; - usage(ret); - } - - subvol_path = realpath(argv[2], NULL); - if (!subvol_path) { - ret = errno; - usage(ret); - } - - r.full_subvol_path = subvol_path; - r.root_path = root_path; - - subvol_fd = open(subvol_path, O_RDONLY|O_NOATIME); - if (subvol_fd < 0) { - ret = errno; - fprintf(stderr, "ERROR: Subvolume open failed. %s\n", - strerror(ret)); - goto out; - } - - ret = pipe(pipefd); - if (ret < 0) { - ret = errno; - fprintf(stderr, "ERROR: pipe failed. %s\n", strerror(ret)); - goto out; - } - - ret = pthread_create(&t_read, NULL, process_thread, &r); - if (ret < 0) { - ret = errno; - fprintf(stderr, "ERROR: pthread create failed. %s\n", - strerror(ret)); - goto out; - } - - io_send.send_fd = pipefd[1]; - io_send.clone_sources_count = 0; - io_send.clone_sources = NULL; - io_send.parent_root = 0; - io_send.flags = BTRFS_SEND_FLAG_NO_FILE_DATA; - - ret = ioctl(subvol_fd, BTRFS_IOC_SEND, &io_send); - if (ret < 0) { - ret = errno; - fprintf(stderr, "ERROR: send ioctl failed with %d: %s\n", ret, - strerror(ret)); - goto out; - } - - close(pipefd[1]); - - ret = pthread_join(t_read, &t_err); - if (ret) { - fprintf(stderr, "ERROR: pthread_join failed: %s\n", - strerror(ret)); - goto out; - } - if (t_err) { - ret = (long int)t_err; - fprintf(stderr, "ERROR: failed to process send stream, ret=%ld " - "(%s)\n", (long int)t_err, strerror(ret)); - goto out; - } - -out: - return !!ret; -}