Mark Fasheh
2013-Jan-08 21:41 UTC
[PATCH 0/3] btrfs-progs: better support for external users of send
Hi, The following 3 patches make changes to btrfs-progs in order to provide support for external software that wants to make use of the excellent btrfs send ioctl. The first patch introduces support for the BTRFS_SEND_FLAG_NO_FILE_DATA flag which is introduced in my kernel patch titled: btrfs: add "no file data" flag to btrfs send ioctl which can be found on the btrfs list, and for convenience is also attached at the end of this e-mail. The 2nd patch creates a libbtrfs and links the rest of the build to it. The functionality I chose to export as of right now centers on send support. With this library, an external program has a much easier time processing the stream which a send ioctl provides. It''s worth nothing btw that this patch can stand alone if need be. The last patch introduces send-test, a small piece of software (not built by default) to allow for testing of the send ioctl (including our new flag). As send-test is a client of libbtrfs it might also serve as example code for developers looking to make use of send. Testing has been pretty straight-forward - I build the software, verify that things work by making a file system or using send-test. Please review. Thanks, --Mark From: Mark Fasheh <mfasheh@suse.de> [PATCH] btrfs: add "no file data" flag to btrfs send ioctl This patch adds the flag, BTRFS_SEND_FLAG_NO_FILE_DATA to the btrfs send ioctl code. When this flag is set, the btrfs send code will never write file data into the stream (thus also avoiding expensive reads of that data in the first place). BTRFS_SEND_C_UPDATE_EXTENT commands will be sent (instead of BTRFS_SEND_C_WRITE) with an offset, length pair indicating the extent in question. This patch does not affect the operation of BTRFS_SEND_C_CLONE commands - they will continue to be sent when a search finds an appropriate extent to clone from. Signed-off-by: Mark Fasheh <mfasheh@suse.de> --- fs/btrfs/ioctl.h | 7 +++++++ fs/btrfs/send.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- fs/btrfs/send.h | 1 + 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h index 731e287..1f6cfdd 100644 --- a/fs/btrfs/ioctl.h +++ b/fs/btrfs/ioctl.h @@ -363,6 +363,13 @@ struct btrfs_ioctl_received_subvol_args { __u64 reserved[16]; /* in */ }; +/* + * Caller doesn''t want file data in the send stream, even if the + * search of clone sources doesn''t find an extent. UPDATE_EXTENT + * commands will be sent instead of WRITE commands. + */ +#define BTRFS_SEND_FLAG_NO_FILE_DATA 0x1 + struct btrfs_ioctl_send_args { __s64 send_fd; /* in */ __u64 clone_sources_count; /* in */ diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index e78b297..8d0c6b4 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -85,6 +85,7 @@ struct send_ctx { u32 send_max_size; u64 total_send_size; u64 cmd_send_size[BTRFS_SEND_C_MAX + 1]; + u64 flags; /* ''flags'' member of btrfs_ioctl_send_args is u64 */ struct vfsmount *mnt; @@ -3707,6 +3708,39 @@ out: return ret; } +/* + * Send an update extent command to user space. + */ +static int send_update_extent(struct send_ctx *sctx, + u64 offset, u32 len) +{ + int ret = 0; + struct fs_path *p; + + p = fs_path_alloc(sctx); + if (!p) + return -ENOMEM; + + ret = begin_cmd(sctx, BTRFS_SEND_C_UPDATE_EXTENT); + if (ret < 0) + goto out; + + ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen, p); + if (ret < 0) + goto out; + + TLV_PUT_PATH(sctx, BTRFS_SEND_A_PATH, p); + TLV_PUT_U64(sctx, BTRFS_SEND_A_FILE_OFFSET, offset); + TLV_PUT_U64(sctx, BTRFS_SEND_A_SIZE, len); + + ret = send_cmd(sctx); + +tlv_put_failure: +out: + fs_path_free(sctx, p); + return ret; +} + static int send_write_or_clone(struct send_ctx *sctx, struct btrfs_path *path, struct btrfs_key *key, @@ -3742,7 +3776,11 @@ static int send_write_or_clone(struct send_ctx *sctx, goto out; } - if (!clone_root) { + if (clone_root) { + ret = send_clone(sctx, offset, len, clone_root); + } else if (sctx->flags & BTRFS_SEND_FLAG_NO_FILE_DATA) { + ret = send_update_extent(sctx, offset, len); + } else { while (pos < len) { l = len - pos; if (l > BTRFS_SEND_READ_SIZE) @@ -3755,10 +3793,7 @@ static int send_write_or_clone(struct send_ctx *sctx, pos += ret; } ret = 0; - } else { - ret = send_clone(sctx, offset, len, clone_root); } - out: return ret; } @@ -4570,6 +4605,11 @@ long btrfs_ioctl_send(struct file *mnt_file, void __user *arg_) INIT_RADIX_TREE(&sctx->name_cache, GFP_NOFS); INIT_LIST_HEAD(&sctx->name_cache_list); + if (arg->flags & ~BTRFS_SEND_FLAG_NO_FILE_DATA) + return -EINVAL; + + sctx->flags = arg->flags; + sctx->send_filp = fget(arg->send_fd); if (IS_ERR(sctx->send_filp)) { ret = PTR_ERR(sctx->send_filp); diff --git a/fs/btrfs/send.h b/fs/btrfs/send.h index 1bf4f32..8bb18f7 100644 --- a/fs/btrfs/send.h +++ b/fs/btrfs/send.h @@ -86,6 +86,7 @@ enum btrfs_send_cmd { BTRFS_SEND_C_UTIMES, BTRFS_SEND_C_END, + BTRFS_SEND_C_UPDATE_EXTENT, __BTRFS_SEND_C_MAX, }; #define BTRFS_SEND_C_MAX (__BTRFS_SEND_C_MAX - 1) -- 1.7.7 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Mark Fasheh
2013-Jan-08 21:41 UTC
[PATCH 1/3] btrfs-progs: Add support for BTRFS_SEND_FLAG_NO_FILE_DATA
The flag and command are synced from kernel to user. Also, this patch adds a callback for the BTRFS_SEND_C_UPDATE_EXTENT in struct btrfs_send_ops. read_and_process_cmd() is updated to decode BTRFS_SEND_C_UPDATE_EXTENT and send the values through the right callback. I did not add a callback definition to cmds-receive.c as that code never uses BTRFS_SEND_FLAG_NO_FILE_DATA. Signed-off-by: Mark Fasheh <mfasheh@suse.de> --- ioctl.h | 7 +++++++ send-stream.c | 6 ++++++ send-stream.h | 1 + send.h | 1 + 4 files changed, 15 insertions(+), 0 deletions(-) diff --git a/ioctl.h b/ioctl.h index 6fda3a1..b7f1ce3 100644 --- a/ioctl.h +++ b/ioctl.h @@ -321,6 +321,13 @@ struct btrfs_ioctl_received_subvol_args { __u64 reserved[16]; /* in */ }; +/* + * Caller doesn''t want file data in the send stream, even if the + * search of clone sources doesn''t find an extent. UPDATE_EXTENT + * commands will be sent instead of WRITE commands. + */ +#define BTRFS_SEND_FLAG_NO_FILE_DATA 0x1 + struct btrfs_ioctl_send_args { __s64 send_fd; /* in */ __u64 clone_sources_count; /* in */ diff --git a/send-stream.c b/send-stream.c index 55fa728..a3628e4 100644 --- a/send-stream.c +++ b/send-stream.c @@ -418,6 +418,12 @@ static int read_and_process_cmd(struct btrfs_send_stream *s) TLV_GET_TIMESPEC(s, BTRFS_SEND_A_CTIME, &ct); ret = s->ops->utimes(path, &at, &mt, &ct, s->user); break; + case BTRFS_SEND_C_UPDATE_EXTENT: + TLV_GET_STRING(s, BTRFS_SEND_A_PATH, &path); + TLV_GET_U64(s, BTRFS_SEND_A_FILE_OFFSET, &offset); + TLV_GET_U64(s, BTRFS_SEND_A_SIZE, &tmp); + ret = s->ops->update_extent(path, offset, tmp, s->user); + break; case BTRFS_SEND_C_END: ret = 1; break; diff --git a/send-stream.h b/send-stream.h index b69b7f1..9a17e32 100644 --- a/send-stream.h +++ b/send-stream.h @@ -49,6 +49,7 @@ struct btrfs_send_ops { int (*utimes)(const char *path, struct timespec *at, struct timespec *mt, struct timespec *ct, void *user); + int (*update_extent)(const char *path, u64 offset, u64 len, void *user); }; int btrfs_read_and_process_send_stream(int fd, diff --git a/send.h b/send.h index 9934e94..48d425a 100644 --- a/send.h +++ b/send.h @@ -86,6 +86,7 @@ enum btrfs_send_cmd { BTRFS_SEND_C_UTIMES, BTRFS_SEND_C_END, + BTRFS_SEND_C_UPDATE_EXTENT, __BTRFS_SEND_C_MAX, }; #define BTRFS_SEND_C_MAX (__BTRFS_SEND_C_MAX - 1) -- 1.7.7 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Mark Fasheh
2013-Jan-08 21:41 UTC
[PATCH 2/3] btrfs-progs: libify some parts of btrfs-progs
External software wanting to use the functionality provided by the btrfs send ioctl has a hard time doing so without replicating tons of work. Of particular interest are functions like btrfs_read_and_process_send_stream() and subvol_uuid_search(). As that functionality requires a bit more than just send-stream.c and send-utils.c we have to pull in some other parts of the progs package. This patch adds code to the Makefile and headers to create a library, libbtrfs which the btrfs command now links to. Signed-off-by: Mark Fasheh <mfasheh@suse.de> --- Makefile | 38 ++++++++++++++++++++++++++++---------- btrfs-list.h | 4 ++++ crc32c.h | 4 ++++ ctree.h | 9 +++++++++ extent-cache.h | 6 ++++++ extent_io.h | 7 +++++++ radix-tree.h | 4 ++++ rbtree.h | 4 ++++ send-utils.h | 5 +++++ 9 files changed, 71 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 4894903..29c63b1 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,17 @@ CC = gcc -AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -CFLAGS = -g -O1 +AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -DBTRFS_FLAT_INCLUDES +CFLAGS = -g -O1 -fPIC objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ - root-tree.o dir-item.o file-item.o inode-item.o \ - inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o \ - volumes.o utils.o btrfs-list.o btrfslabel.o repair.o \ - send-stream.o send-utils.o qgroup.o + root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \ + extent-cache.o extent_io.o volumes.o utils.o btrfslabel.o repair.o \ + qgroup.o cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \ cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \ cmds-quota.o cmds-qgroup.o +libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o +libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \ + crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \ + extent_io.h ioctl.h ctree.h CHECKFLAGS= -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ -Wuninitialized -Wshadow -Wundef @@ -17,13 +20,18 @@ DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@ INSTALL = install prefix ?= /usr/local bindir = $(prefix)/bin -LIBS=-luuid -lm +libdir = $(prefix)/lib +incdir = $(prefix)/include/btrfs +LIBS=-luuid -lm -L. -lbtrfs RESTORE_LIBS=-lz progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck \ btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert \ btrfs-find-root btrfs-restore btrfstune +libs = libbtrfs.so.1.0 libbtrfs.so.1 libbtrfs.so +headers = $(libbtrfs_headers) + # make C=1 to enable sparse ifdef C check = sparse $(CHECKFLAGS) @@ -36,11 +44,16 @@ endif $(CC) $(DEPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $< -all: version $(progs) manpages +all: version $(libs) $(progs) manpages version: bash version.sh +$(libs): $(libbtrfs_objects) send.h + $(CC) $(CFLAGS) $(libbtrfs_objects) -shared -Wl,-soname,libbtrfs.so.1 -o libbtrfs.so.1.0 + ln -sf libbtrfs.so.1.0 libbtrfs.so.1 + ln -sf libbtrfs.so.1.0 libbtrfs.so + btrfs: $(objects) btrfs.o help.o common.o $(cmds_objects) $(CC) $(CFLAGS) -o btrfs btrfs.o help.o common.o $(cmds_objects) \ $(objects) $(LDFLAGS) $(LIBS) -lpthread @@ -109,12 +122,17 @@ install-man: cd man; $(MAKE) install clean : - rm -f $(progs) cscope.out *.o .*.d btrfs-convert btrfs-image btrfs-select-super \ - btrfs-zero-log btrfstune dir-test ioctl-test quick-test version.h + rm -f $(progs) $(libs) cscope.out *.o .*.d btrfs-convert btrfs-image \ + btrfs-select-super btrfs-zero-log btrfstune dir-test ioctl-test \ + quick-test version.h cd man; $(MAKE) clean install: $(progs) install-man $(INSTALL) -m755 -d $(DESTDIR)$(bindir) $(INSTALL) $(progs) $(DESTDIR)$(bindir) + $(INSTALL) -m755 -d $(DESTDIR)$(libdir) + $(INSTALL) $(libs) $(DESTDIR)$(libdir) + $(INSTALL) -m755 -d $(DESTDIR)$(incdir) + $(INSTALL) $(headers) $(DESTDIR)$(incdir) -include .*.d diff --git a/btrfs-list.h b/btrfs-list.h index cde4b3c..da6bf1c 100644 --- a/btrfs-list.h +++ b/btrfs-list.h @@ -16,7 +16,11 @@ * Boston, MA 021110-1307, USA. */ +#if BTRFS_FLAT_INCLUDES #include "kerncompat.h" +#else +#include <btrfs/kerncompat.h> +#endif /* BTRFS_FLAT_INCLUDES */ struct root_info; diff --git a/crc32c.h b/crc32c.h index 7f12e77..c552ef6 100644 --- a/crc32c.h +++ b/crc32c.h @@ -19,7 +19,11 @@ #ifndef __CRC32C__ #define __CRC32C__ +#if BTRFS_FLAT_INCLUDES #include "kerncompat.h" +#else +#include <btrfs/kerncompat.h> +#endif /* BTRFS_FLAT_INCLUDES */ u32 crc32c_le(u32 seed, unsigned char const *data, size_t length); void crc32c_optimization_init(void); diff --git a/ctree.h b/ctree.h index 293b24f..7a1ffce 100644 --- a/ctree.h +++ b/ctree.h @@ -19,12 +19,21 @@ #ifndef __BTRFS__ #define __BTRFS__ +#if BTRFS_FLAT_INCLUDES #include "list.h" #include "kerncompat.h" #include "radix-tree.h" #include "extent-cache.h" #include "extent_io.h" #include "ioctl.h" +#else +#include <btrfs/list.h> +#include <btrfs/kerncompat.h> +#include <btrfs/radix-tree.h> +#include <btrfs/extent-cache.h> +#include <btrfs/extent_io.h> +#include <btrfs/ioctl.h> +#endif /* BTRFS_FLAT_INCLUDES */ struct btrfs_root; struct btrfs_trans_handle; diff --git a/extent-cache.h b/extent-cache.h index 7f2f2a6..4cd0f79 100644 --- a/extent-cache.h +++ b/extent-cache.h @@ -18,8 +18,14 @@ #ifndef __PENDING_EXTENT__ #define __PENDING_EXTENT__ + +#if BTRFS_FLAT_INCLUDES #include "kerncompat.h" #include "rbtree.h" +#else +#include <btrfs/kerncompat.h> +#include <btrfs/rbtree.h> +#endif /* BTRFS_FLAT_INCLUDES */ struct cache_tree { struct rb_root root; diff --git a/extent_io.h b/extent_io.h index a5d6bf0..4553859 100644 --- a/extent_io.h +++ b/extent_io.h @@ -18,9 +18,16 @@ #ifndef __EXTENTMAP__ #define __EXTENTMAP__ + +#if BTRFS_FLAT_INCLUDES #include "kerncompat.h" #include "extent-cache.h" #include "list.h" +#else +#include <btrfs/kerncompat.h> +#include <btrfs/extent-cache.h> +#include <btrfs/list.h> +#endif /* BTRFS_FLAT_INCLUDES */ #define EXTENT_DIRTY 1 #define EXTENT_WRITEBACK (1 << 1) diff --git a/radix-tree.h b/radix-tree.h index d99ea7e..bf96d83 100644 --- a/radix-tree.h +++ b/radix-tree.h @@ -37,7 +37,11 @@ #ifndef _LINUX_RADIX_TREE_H #define _LINUX_RADIX_TREE_H +#if BTRFS_FLAT_INCLUDES #include "kerncompat.h" +#else +#include <btrfs/kerncompat.h> +#endif /* BTRFS_FLAT_INCLUDES */ #define RADIX_TREE_MAX_TAGS 2 diff --git a/rbtree.h b/rbtree.h index bed054d..b636ddd 100644 --- a/rbtree.h +++ b/rbtree.h @@ -93,7 +93,11 @@ static inline struct page * rb_insert_page_cache(struct inode * inode, #ifndef _LINUX_RBTREE_H #define _LINUX_RBTREE_H +#if BTRFS_FLAT_INCLUDES #include "kerncompat.h" +#else +#include <btrfs/kerncompat.h> +#endif /* BTRFS_FLAT_INCLUDES */ struct rb_node { unsigned long rb_parent_color; diff --git a/send-utils.h b/send-utils.h index da407eb..8040c50 100644 --- a/send-utils.h +++ b/send-utils.h @@ -18,8 +18,13 @@ #ifndef SEND_UTILS_H_ #define SEND_UTILS_H_ +#if BTRFS_FLAT_INCLUDES #include "ctree.h" #include "rbtree.h" +#else +#include <btrfs/ctree.h> +#include <btrfs/rbtree.h> +#endif /* BTRFS_FLAT_INCLUDES */ enum subvol_search_type { subvol_search_by_root_id, -- 1.7.7 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
send-test.c links against libbtrfs and uses the send functionality provided to decode and print a send stream to the console. We use the BTRFS_SEND_FLAG_NO_FILE_DATA flag as actual file data is never needed for this. Signed-off-by: Mark Fasheh <mfasheh@suse.de> --- Makefile | 5 +- send-test.c | 458 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 462 insertions(+), 1 deletions(-) create mode 100644 send-test.c diff --git a/Makefile b/Makefile index 29c63b1..b3a994b 100644 --- a/Makefile +++ b/Makefile @@ -115,6 +115,9 @@ btrfs-convert: $(objects) convert.o ioctl-test: $(objects) ioctl-test.o $(CC) $(CFLAGS) -o ioctl-test $(objects) ioctl-test.o $(LDFLAGS) $(LIBS) +send-test: $(objects) send-test.o + $(CC) $(CFLAGS) -o send-test send-test.o $(LDFLAGS) $(LIBS) -lpthread + manpages: cd man; $(MAKE) @@ -124,7 +127,7 @@ install-man: clean : rm -f $(progs) $(libs) cscope.out *.o .*.d btrfs-convert btrfs-image \ btrfs-select-super btrfs-zero-log btrfstune dir-test ioctl-test \ - quick-test version.h + quick-test send-test version.h cd man; $(MAKE) clean install: $(progs) install-man diff --git a/send-test.c b/send-test.c new file mode 100644 index 0000000..2eeaf79 --- /dev/null +++ b/send-test.c @@ -0,0 +1,458 @@ +/* + * 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. + */ + +#define _GNU_SOURCE + +#include <unistd.h> +#include <stdint.h> +#include <dirent.h> +#include <pthread.h> +#include <math.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <libgen.h> +#include <mntent.h> +#include <limits.h> +#include <stdlib.h> +#include <asm/types.h> +#include <uuid/uuid.h> + +/* + * 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 <btrfs/send-utils.h> +#include <btrfs/send-stream.h> +#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 <btrfs root> <subvol>\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[128]; + + 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[128]; + char parent_uuid_str[128]; + + 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; +} + +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_); + 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; + pthread_attr_t t_attr; + 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 = pthread_attr_init(&t_attr); + if (ret < 0) { + fprintf(stderr, "ERROR: pthread init 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, &t_attr, 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) { + 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; + } + + pthread_attr_destroy(&t_attr); +out: + return ret; +} -- 1.7.7 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Thanks for libbtrfs. comments below. On 01/09/2013 05:41 AM, Mark Fasheh wrote:> send-test.c links against libbtrfs and uses the send functionality provided > to decode and print a send stream to the console. We use the > BTRFS_SEND_FLAG_NO_FILE_DATA flag as actual file data is never needed for > this. > > Signed-off-by: Mark Fasheh <mfasheh@suse.de> > --- > Makefile | 5 +- > send-test.c | 458 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 462 insertions(+), 1 deletions(-) > create mode 100644 send-test.c > > diff --git a/Makefile b/Makefile > index 29c63b1..b3a994b 100644 > --- a/Makefile > +++ b/Makefile > @@ -115,6 +115,9 @@ btrfs-convert: $(objects) convert.o > ioctl-test: $(objects) ioctl-test.o > $(CC) $(CFLAGS) -o ioctl-test $(objects) ioctl-test.o $(LDFLAGS) $(LIBS) > > +send-test: $(objects) send-test.o > + $(CC) $(CFLAGS) -o send-test send-test.o $(LDFLAGS) $(LIBS) -lpthread > + > manpages: > cd man; $(MAKE) > > @@ -124,7 +127,7 @@ install-man: > clean : > rm -f $(progs) $(libs) cscope.out *.o .*.d btrfs-convert btrfs-image \ > btrfs-select-super btrfs-zero-log btrfstune dir-test ioctl-test \ > - quick-test version.h > + quick-test send-test version.h > cd man; $(MAKE) clean > > install: $(progs) install-man > diff --git a/send-test.c b/send-test.c > new file mode 100644 > index 0000000..2eeaf79 > --- /dev/null > +++ b/send-test.c > @@ -0,0 +1,458 @@ > +/* > + * Copyright (C) 2013 SUSE. All rights reserved. > + * > + * This code is adapted from cmds-send.c and cmds-receive.c,minor: git am reports white space error at this line.> + * 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. > + */ > + > +#define _GNU_SOURCE > + > +#include <unistd.h> > +#include <stdint.h> > +#include <dirent.h> > +#include <pthread.h> > +#include <math.h> > +#include <sys/types.h> > +#include <sys/stat.h> > +#include <fcntl.h> > +#include <sys/ioctl.h> > +#include <libgen.h> > +#include <mntent.h> > +#include <limits.h> > +#include <stdlib.h> > +#include <asm/types.h> > +#include <uuid/uuid.h> > + > +/* > + * 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 <btrfs/send-utils.h> > +#include <btrfs/send-stream.h> > +#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 <btrfs root> <subvol>\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[128]; > + > + 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[128]; > + char parent_uuid_str[128]; > + > + 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; > +} > + > +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_); > + 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; > + pthread_attr_t t_attr; > + 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 = pthread_attr_init(&t_attr); > + if (ret < 0) { > + fprintf(stderr, "ERROR: pthread init 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, &t_attr, 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) { > + 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; > + } > + > + pthread_attr_destroy(&t_attr); > +out: > + return ret; > +} >-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Anand Jain
2013-Jan-11 09:31 UTC
Re: [PATCH 2/3] btrfs-progs: libify some parts of btrfs-progs
Mark, test case : make (Do not run make all) make install generates the following error.. install -m755 -d /usr/local/lib install libbtrfs.so.1.0 libbtrfs.so.1 libbtrfs.so /usr/local/lib install: cannot stat `libbtrfs.so.1.0'': No such file or directory install: cannot stat `libbtrfs.so.1'': No such file or directory install: cannot stat `libbtrfs.so'': No such file or directory make: *** [install] Error 1 Thanks, Anand On 01/09/2013 05:41 AM, Mark Fasheh wrote:> External software wanting to use the functionality provided by the btrfs > send ioctl has a hard time doing so without replicating tons of work. Of > particular interest are functions like btrfs_read_and_process_send_stream() > and subvol_uuid_search(). As that functionality requires a bit more than > just send-stream.c and send-utils.c we have to pull in some other parts of > the progs package. > > This patch adds code to the Makefile and headers to create a library, > libbtrfs which the btrfs command now links to. > > Signed-off-by: Mark Fasheh <mfasheh@suse.de> > --- > Makefile | 38 ++++++++++++++++++++++++++++---------- > btrfs-list.h | 4 ++++ > crc32c.h | 4 ++++ > ctree.h | 9 +++++++++ > extent-cache.h | 6 ++++++ > extent_io.h | 7 +++++++ > radix-tree.h | 4 ++++ > rbtree.h | 4 ++++ > send-utils.h | 5 +++++ > 9 files changed, 71 insertions(+), 10 deletions(-) > > diff --git a/Makefile b/Makefile > index 4894903..29c63b1 100644 > --- a/Makefile > +++ b/Makefile > @@ -1,14 +1,17 @@ > CC = gcc > -AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 > -CFLAGS = -g -O1 > +AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -DBTRFS_FLAT_INCLUDES > +CFLAGS = -g -O1 -fPIC > objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ > - root-tree.o dir-item.o file-item.o inode-item.o \ > - inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o \ > - volumes.o utils.o btrfs-list.o btrfslabel.o repair.o \ > - send-stream.o send-utils.o qgroup.o > + root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \ > + extent-cache.o extent_io.o volumes.o utils.o btrfslabel.o repair.o \ > + qgroup.o > cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \ > cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \ > cmds-quota.o cmds-qgroup.o > +libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o > +libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \ > + crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \ > + extent_io.h ioctl.h ctree.h > > CHECKFLAGS= -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ > -Wuninitialized -Wshadow -Wundef > @@ -17,13 +20,18 @@ DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@ > INSTALL = install > prefix ?= /usr/local > bindir = $(prefix)/bin > -LIBS=-luuid -lm > +libdir = $(prefix)/lib > +incdir = $(prefix)/include/btrfs > +LIBS=-luuid -lm -L. -lbtrfs > RESTORE_LIBS=-lz > > progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck \ > btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert \ > btrfs-find-root btrfs-restore btrfstune > > +libs = libbtrfs.so.1.0 libbtrfs.so.1 libbtrfs.so > +headers = $(libbtrfs_headers) > + > # make C=1 to enable sparse > ifdef C > check = sparse $(CHECKFLAGS) > @@ -36,11 +44,16 @@ endif > $(CC) $(DEPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $< > > > -all: version $(progs) manpages > +all: version $(libs) $(progs) manpages > > version: > bash version.sh > > +$(libs): $(libbtrfs_objects) send.h > + $(CC) $(CFLAGS) $(libbtrfs_objects) -shared -Wl,-soname,libbtrfs.so.1 -o libbtrfs.so.1.0 > + ln -sf libbtrfs.so.1.0 libbtrfs.so.1 > + ln -sf libbtrfs.so.1.0 libbtrfs.so > + > btrfs: $(objects) btrfs.o help.o common.o $(cmds_objects) > $(CC) $(CFLAGS) -o btrfs btrfs.o help.o common.o $(cmds_objects) \ > $(objects) $(LDFLAGS) $(LIBS) -lpthread > @@ -109,12 +122,17 @@ install-man: > cd man; $(MAKE) install > > clean : > - rm -f $(progs) cscope.out *.o .*.d btrfs-convert btrfs-image btrfs-select-super \ > - btrfs-zero-log btrfstune dir-test ioctl-test quick-test version.h > + rm -f $(progs) $(libs) cscope.out *.o .*.d btrfs-convert btrfs-image \ > + btrfs-select-super btrfs-zero-log btrfstune dir-test ioctl-test \ > + quick-test version.h > cd man; $(MAKE) clean > > install: $(progs) install-man > $(INSTALL) -m755 -d $(DESTDIR)$(bindir) > $(INSTALL) $(progs) $(DESTDIR)$(bindir) > + $(INSTALL) -m755 -d $(DESTDIR)$(libdir) > + $(INSTALL) $(libs) $(DESTDIR)$(libdir) > + $(INSTALL) -m755 -d $(DESTDIR)$(incdir) > + $(INSTALL) $(headers) $(DESTDIR)$(incdir) > > -include .*.d > diff --git a/btrfs-list.h b/btrfs-list.h > index cde4b3c..da6bf1c 100644 > --- a/btrfs-list.h > +++ b/btrfs-list.h > @@ -16,7 +16,11 @@ > * Boston, MA 021110-1307, USA. > */ > > +#if BTRFS_FLAT_INCLUDES > #include "kerncompat.h" > +#else > +#include <btrfs/kerncompat.h> > +#endif /* BTRFS_FLAT_INCLUDES */ > > struct root_info; > > diff --git a/crc32c.h b/crc32c.h > index 7f12e77..c552ef6 100644 > --- a/crc32c.h > +++ b/crc32c.h > @@ -19,7 +19,11 @@ > #ifndef __CRC32C__ > #define __CRC32C__ > > +#if BTRFS_FLAT_INCLUDES > #include "kerncompat.h" > +#else > +#include <btrfs/kerncompat.h> > +#endif /* BTRFS_FLAT_INCLUDES */ > > u32 crc32c_le(u32 seed, unsigned char const *data, size_t length); > void crc32c_optimization_init(void); > diff --git a/ctree.h b/ctree.h > index 293b24f..7a1ffce 100644 > --- a/ctree.h > +++ b/ctree.h > @@ -19,12 +19,21 @@ > #ifndef __BTRFS__ > #define __BTRFS__ > > +#if BTRFS_FLAT_INCLUDES > #include "list.h" > #include "kerncompat.h" > #include "radix-tree.h" > #include "extent-cache.h" > #include "extent_io.h" > #include "ioctl.h" > +#else > +#include <btrfs/list.h> > +#include <btrfs/kerncompat.h> > +#include <btrfs/radix-tree.h> > +#include <btrfs/extent-cache.h> > +#include <btrfs/extent_io.h> > +#include <btrfs/ioctl.h> > +#endif /* BTRFS_FLAT_INCLUDES */ > > struct btrfs_root; > struct btrfs_trans_handle; > diff --git a/extent-cache.h b/extent-cache.h > index 7f2f2a6..4cd0f79 100644 > --- a/extent-cache.h > +++ b/extent-cache.h > @@ -18,8 +18,14 @@ > > #ifndef __PENDING_EXTENT__ > #define __PENDING_EXTENT__ > + > +#if BTRFS_FLAT_INCLUDES > #include "kerncompat.h" > #include "rbtree.h" > +#else > +#include <btrfs/kerncompat.h> > +#include <btrfs/rbtree.h> > +#endif /* BTRFS_FLAT_INCLUDES */ > > struct cache_tree { > struct rb_root root; > diff --git a/extent_io.h b/extent_io.h > index a5d6bf0..4553859 100644 > --- a/extent_io.h > +++ b/extent_io.h > @@ -18,9 +18,16 @@ > > #ifndef __EXTENTMAP__ > #define __EXTENTMAP__ > + > +#if BTRFS_FLAT_INCLUDES > #include "kerncompat.h" > #include "extent-cache.h" > #include "list.h" > +#else > +#include <btrfs/kerncompat.h> > +#include <btrfs/extent-cache.h> > +#include <btrfs/list.h> > +#endif /* BTRFS_FLAT_INCLUDES */ > > #define EXTENT_DIRTY 1 > #define EXTENT_WRITEBACK (1 << 1) > diff --git a/radix-tree.h b/radix-tree.h > index d99ea7e..bf96d83 100644 > --- a/radix-tree.h > +++ b/radix-tree.h > @@ -37,7 +37,11 @@ > #ifndef _LINUX_RADIX_TREE_H > #define _LINUX_RADIX_TREE_H > > +#if BTRFS_FLAT_INCLUDES > #include "kerncompat.h" > +#else > +#include <btrfs/kerncompat.h> > +#endif /* BTRFS_FLAT_INCLUDES */ > > #define RADIX_TREE_MAX_TAGS 2 > > diff --git a/rbtree.h b/rbtree.h > index bed054d..b636ddd 100644 > --- a/rbtree.h > +++ b/rbtree.h > @@ -93,7 +93,11 @@ static inline struct page * rb_insert_page_cache(struct inode * inode, > > #ifndef _LINUX_RBTREE_H > #define _LINUX_RBTREE_H > +#if BTRFS_FLAT_INCLUDES > #include "kerncompat.h" > +#else > +#include <btrfs/kerncompat.h> > +#endif /* BTRFS_FLAT_INCLUDES */ > struct rb_node > { > unsigned long rb_parent_color; > diff --git a/send-utils.h b/send-utils.h > index da407eb..8040c50 100644 > --- a/send-utils.h > +++ b/send-utils.h > @@ -18,8 +18,13 @@ > #ifndef SEND_UTILS_H_ > #define SEND_UTILS_H_ > > +#if BTRFS_FLAT_INCLUDES > #include "ctree.h" > #include "rbtree.h" > +#else > +#include <btrfs/ctree.h> > +#include <btrfs/rbtree.h> > +#endif /* BTRFS_FLAT_INCLUDES */ > > enum subvol_search_type { > subvol_search_by_root_id, >-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Mark Fasheh
2013-Jan-11 23:00 UTC
Re: [PATCH 2/3] btrfs-progs: libify some parts of btrfs-progs
On Fri, Jan 11, 2013 at 05:31:09PM +0800, Anand Jain wrote:> > Mark, > > test case : > make (Do not run make all) > make installThanks for testing!> generates the following error.. > > install -m755 -d /usr/local/lib > install libbtrfs.so.1.0 libbtrfs.so.1 libbtrfs.so /usr/local/lib > install: cannot stat `libbtrfs.so.1.0'': No such file or directory > install: cannot stat `libbtrfs.so.1'': No such file or directory > install: cannot stat `libbtrfs.so'': No such file or directory > make: *** [install] Error 1Ok, that''s weird because this works fine for me. Just in case, I tried against a clean checkout of btrfs-progs and with the patches taken from the mailing list: mfasheh@eris:/build/mfasheh/tmp> git clone git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-progs.git Cloning into btrfs-progs... <snip> mfasheh@eris:/build/mfasheh/tmp> cd btrfs-progs/ mfasheh@eris:/build/mfasheh/tmp/btrfs-progs> git am ../to-apply Applying: btrfs-progs: Add support for BTRFS_SEND_FLAG_NO_FILE_DATA Applying: btrfs-progs: libify some parts of btrfs-progs Applying: btrfs-progs: add send-test /build/mfasheh/tmp/btrfs-progs/.git/rebase-apply/patch:39: trailing whitespace. * This code is adapted from cmds-send.c and cmds-receive.c, warning: 1 line adds whitespace errors. mfasheh@eris:/build/mfasheh/tmp/btrfs-progs> make <snip, but suffice to say it builds> mfasheh@eris:/build/mfasheh/tmp/btrfs-progs> mkdir tmpinst mfasheh@eris:/build/mfasheh/tmp/btrfs-progs> make prefix=tmpinst install cd man; make install make[1]: Entering directory `/build/mfasheh/tmp/btrfs-progs/man'' install -m755 -d tmpinst/man/man8 install -m 644 mkfs.btrfs.8.gz btrfsctl.8.gz btrfsck.8.gz btrfs-image.8.gz btrfs-show.8.gz btrfs.8.gz tmpinst/man/man8 make[1]: Leaving directory `/build/mfasheh/tmp/btrfs-progs/man'' install -m755 -d tmpinst/bin install btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert btrfs-find-root btrfs-restor install -m755 -d tmpinst/lib install libbtrfs.so.1.0 libbtrfs.so.1 libbtrfs.so tmpinst/lib install -m755 -d tmpinst/include/btrfs install send-stream.h send-utils.h send.h rbtree.h btrfs-list.h crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h extent_io.h ioctl.h ctree.h tmpinst/include/btrfs Can you take a log of the build process and send that to me. If libbtrfs isn''t building on your end for some reason than that would be why it won''t install. Thanks again for testing this Anand! --Mark -- Mark Fasheh -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Fri, Jan 11, 2013 at 05:28:22PM +0800, Anand Jain wrote:> Thanks for libbtrfs. comments below.No problem, thanks for looking over and testing this out. I''ll correct the whitespace error below for my next send of the patches. --Mark -- Mark Fasheh -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Anand Jain
2013-Jan-14 03:42 UTC
Re: [PATCH 2/3] btrfs-progs: libify some parts of btrfs-progs
Mark, Its bit strange, the steps given before can reproduce the problem still on my older workspace. However when I try with the fresh clone, it can reproduce the issue (4 times, consistently) only with the following (new) steps.. ----------------- # git clone git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-progs.git # cd btrfs-progs/ # make version; make install :: # git am ../../../patch/libbtrfs/* Applying: btrfs-progs: Add support for BTRFS_SEND_FLAG_NO_FILE_DATA Applying: btrfs-progs: libify some parts of btrfs-progs Applying: btrfs-progs: add send-test /usr/src/cli/tmp/tmp7/btrfs-progs/.git/rebase-apply/patch:39: trailing whitespace. * This code is adapted from cmds-send.c and cmds-receive.c, warning: 1 line adds whitespace errors. # make install (the problem does not happen for: ''make; make install'') :: install -m755 -d /usr/local/bin install btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert btrfs-find-root btrfs-restore btrfstune /usr/local/bin install -m755 -d /usr/local/lib install libbtrfs.so.1.0 libbtrfs.so.1 libbtrfs.so /usr/local/lib install: cannot stat `libbtrfs.so.1.0'': No such file or directory install: cannot stat `libbtrfs.so.1'': No such file or directory install: cannot stat `libbtrfs.so'': No such file or directory make: *** [install] Error 1 # ---------------- Thanks, Anand On 01/12/2013 07:00 AM, Mark Fasheh wrote:> On Fri, Jan 11, 2013 at 05:31:09PM +0800, Anand Jain wrote: >> >> Mark, >> >> test case : >> make (Do not run make all) >> make install > Thanks for testing! > >> generates the following error.. >> >> install -m755 -d /usr/local/lib >> install libbtrfs.so.1.0 libbtrfs.so.1 libbtrfs.so /usr/local/lib >> install: cannot stat `libbtrfs.so.1.0'': No such file or directory >> install: cannot stat `libbtrfs.so.1'': No such file or directory >> install: cannot stat `libbtrfs.so'': No such file or directory >> make: *** [install] Error 1 > > Ok, that''s weird because this works fine for me. Just in case, I tried > against a clean checkout of btrfs-progs and with the patches taken from the > mailing list: > > mfasheh@eris:/build/mfasheh/tmp> git clone git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-progs.git > Cloning into btrfs-progs... > <snip> > mfasheh@eris:/build/mfasheh/tmp> cd btrfs-progs/ > mfasheh@eris:/build/mfasheh/tmp/btrfs-progs> git am ../to-apply > Applying: btrfs-progs: Add support for BTRFS_SEND_FLAG_NO_FILE_DATA > Applying: btrfs-progs: libify some parts of btrfs-progs > Applying: btrfs-progs: add send-test > /build/mfasheh/tmp/btrfs-progs/.git/rebase-apply/patch:39: trailing > whitespace. > * This code is adapted from cmds-send.c and cmds-receive.c, > warning: 1 line adds whitespace errors. > mfasheh@eris:/build/mfasheh/tmp/btrfs-progs> make > <snip, but suffice to say it builds> > mfasheh@eris:/build/mfasheh/tmp/btrfs-progs> mkdir tmpinst > mfasheh@eris:/build/mfasheh/tmp/btrfs-progs> make prefix=tmpinst install > cd man; make install > make[1]: Entering directory `/build/mfasheh/tmp/btrfs-progs/man'' > install -m755 -d tmpinst/man/man8 > install -m 644 mkfs.btrfs.8.gz btrfsctl.8.gz btrfsck.8.gz btrfs-image.8.gz > btrfs-show.8.gz btrfs.8.gz tmpinst/man/man8 > make[1]: Leaving directory `/build/mfasheh/tmp/btrfs-progs/man'' > install -m755 -d tmpinst/bin > install btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck > btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert > btrfs-find-root btrfs-restor > install -m755 -d tmpinst/lib > install libbtrfs.so.1.0 libbtrfs.so.1 libbtrfs.so tmpinst/lib > install -m755 -d tmpinst/include/btrfs > install send-stream.h send-utils.h send.h rbtree.h btrfs-list.h crc32c.h > list.h kerncompat.h radix-tree.h extent-cache.h extent_io.h ioctl.h ctree.h > tmpinst/include/btrfs > > > Can you take a log of the build process and send that to me. If libbtrfs > isn''t building on your end for some reason than that would be why it won''t > install. > > Thanks again for testing this Anand! > --Mark > > -- > Mark Fasheh > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Anand Jain
2013-Jan-14 03:43 UTC
Re: [PATCH 2/3] btrfs-progs: libify some parts of btrfs-progs
Mark, Good to create man libbtrfs ? Thanks, Anand On 01/09/2013 05:41 AM, Mark Fasheh wrote:> External software wanting to use the functionality provided by the btrfs > send ioctl has a hard time doing so without replicating tons of work. Of > particular interest are functions like btrfs_read_and_process_send_stream() > and subvol_uuid_search(). As that functionality requires a bit more than > just send-stream.c and send-utils.c we have to pull in some other parts of > the progs package. > > This patch adds code to the Makefile and headers to create a library, > libbtrfs which the btrfs command now links to. > > Signed-off-by: Mark Fasheh <mfasheh@suse.de> > --- > Makefile | 38 ++++++++++++++++++++++++++++---------- > btrfs-list.h | 4 ++++ > crc32c.h | 4 ++++ > ctree.h | 9 +++++++++ > extent-cache.h | 6 ++++++ > extent_io.h | 7 +++++++ > radix-tree.h | 4 ++++ > rbtree.h | 4 ++++ > send-utils.h | 5 +++++ > 9 files changed, 71 insertions(+), 10 deletions(-) > > diff --git a/Makefile b/Makefile > index 4894903..29c63b1 100644 > --- a/Makefile > +++ b/Makefile > @@ -1,14 +1,17 @@ > CC = gcc > -AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 > -CFLAGS = -g -O1 > +AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -DBTRFS_FLAT_INCLUDES > +CFLAGS = -g -O1 -fPIC > objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ > - root-tree.o dir-item.o file-item.o inode-item.o \ > - inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o \ > - volumes.o utils.o btrfs-list.o btrfslabel.o repair.o \ > - send-stream.o send-utils.o qgroup.o > + root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \ > + extent-cache.o extent_io.o volumes.o utils.o btrfslabel.o repair.o \ > + qgroup.o > cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \ > cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \ > cmds-quota.o cmds-qgroup.o > +libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o > +libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \ > + crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \ > + extent_io.h ioctl.h ctree.h > > CHECKFLAGS= -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ > -Wuninitialized -Wshadow -Wundef > @@ -17,13 +20,18 @@ DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@ > INSTALL = install > prefix ?= /usr/local > bindir = $(prefix)/bin > -LIBS=-luuid -lm > +libdir = $(prefix)/lib > +incdir = $(prefix)/include/btrfs > +LIBS=-luuid -lm -L. -lbtrfs > RESTORE_LIBS=-lz > > progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck \ > btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert \ > btrfs-find-root btrfs-restore btrfstune > > +libs = libbtrfs.so.1.0 libbtrfs.so.1 libbtrfs.so > +headers = $(libbtrfs_headers) > + > # make C=1 to enable sparse > ifdef C > check = sparse $(CHECKFLAGS) > @@ -36,11 +44,16 @@ endif > $(CC) $(DEPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $< > > > -all: version $(progs) manpages > +all: version $(libs) $(progs) manpages > > version: > bash version.sh > > +$(libs): $(libbtrfs_objects) send.h > + $(CC) $(CFLAGS) $(libbtrfs_objects) -shared -Wl,-soname,libbtrfs.so.1 -o libbtrfs.so.1.0 > + ln -sf libbtrfs.so.1.0 libbtrfs.so.1 > + ln -sf libbtrfs.so.1.0 libbtrfs.so > + > btrfs: $(objects) btrfs.o help.o common.o $(cmds_objects) > $(CC) $(CFLAGS) -o btrfs btrfs.o help.o common.o $(cmds_objects) \ > $(objects) $(LDFLAGS) $(LIBS) -lpthread > @@ -109,12 +122,17 @@ install-man: > cd man; $(MAKE) install > > clean : > - rm -f $(progs) cscope.out *.o .*.d btrfs-convert btrfs-image btrfs-select-super \ > - btrfs-zero-log btrfstune dir-test ioctl-test quick-test version.h > + rm -f $(progs) $(libs) cscope.out *.o .*.d btrfs-convert btrfs-image \ > + btrfs-select-super btrfs-zero-log btrfstune dir-test ioctl-test \ > + quick-test version.h > cd man; $(MAKE) clean > > install: $(progs) install-man > $(INSTALL) -m755 -d $(DESTDIR)$(bindir) > $(INSTALL) $(progs) $(DESTDIR)$(bindir) > + $(INSTALL) -m755 -d $(DESTDIR)$(libdir) > + $(INSTALL) $(libs) $(DESTDIR)$(libdir) > + $(INSTALL) -m755 -d $(DESTDIR)$(incdir) > + $(INSTALL) $(headers) $(DESTDIR)$(incdir) > > -include .*.d > diff --git a/btrfs-list.h b/btrfs-list.h > index cde4b3c..da6bf1c 100644 > --- a/btrfs-list.h > +++ b/btrfs-list.h > @@ -16,7 +16,11 @@ > * Boston, MA 021110-1307, USA. > */ > > +#if BTRFS_FLAT_INCLUDES > #include "kerncompat.h" > +#else > +#include <btrfs/kerncompat.h> > +#endif /* BTRFS_FLAT_INCLUDES */ > > struct root_info; > > diff --git a/crc32c.h b/crc32c.h > index 7f12e77..c552ef6 100644 > --- a/crc32c.h > +++ b/crc32c.h > @@ -19,7 +19,11 @@ > #ifndef __CRC32C__ > #define __CRC32C__ > > +#if BTRFS_FLAT_INCLUDES > #include "kerncompat.h" > +#else > +#include <btrfs/kerncompat.h> > +#endif /* BTRFS_FLAT_INCLUDES */ > > u32 crc32c_le(u32 seed, unsigned char const *data, size_t length); > void crc32c_optimization_init(void); > diff --git a/ctree.h b/ctree.h > index 293b24f..7a1ffce 100644 > --- a/ctree.h > +++ b/ctree.h > @@ -19,12 +19,21 @@ > #ifndef __BTRFS__ > #define __BTRFS__ > > +#if BTRFS_FLAT_INCLUDES > #include "list.h" > #include "kerncompat.h" > #include "radix-tree.h" > #include "extent-cache.h" > #include "extent_io.h" > #include "ioctl.h" > +#else > +#include <btrfs/list.h> > +#include <btrfs/kerncompat.h> > +#include <btrfs/radix-tree.h> > +#include <btrfs/extent-cache.h> > +#include <btrfs/extent_io.h> > +#include <btrfs/ioctl.h> > +#endif /* BTRFS_FLAT_INCLUDES */ > > struct btrfs_root; > struct btrfs_trans_handle; > diff --git a/extent-cache.h b/extent-cache.h > index 7f2f2a6..4cd0f79 100644 > --- a/extent-cache.h > +++ b/extent-cache.h > @@ -18,8 +18,14 @@ > > #ifndef __PENDING_EXTENT__ > #define __PENDING_EXTENT__ > + > +#if BTRFS_FLAT_INCLUDES > #include "kerncompat.h" > #include "rbtree.h" > +#else > +#include <btrfs/kerncompat.h> > +#include <btrfs/rbtree.h> > +#endif /* BTRFS_FLAT_INCLUDES */ > > struct cache_tree { > struct rb_root root; > diff --git a/extent_io.h b/extent_io.h > index a5d6bf0..4553859 100644 > --- a/extent_io.h > +++ b/extent_io.h > @@ -18,9 +18,16 @@ > > #ifndef __EXTENTMAP__ > #define __EXTENTMAP__ > + > +#if BTRFS_FLAT_INCLUDES > #include "kerncompat.h" > #include "extent-cache.h" > #include "list.h" > +#else > +#include <btrfs/kerncompat.h> > +#include <btrfs/extent-cache.h> > +#include <btrfs/list.h> > +#endif /* BTRFS_FLAT_INCLUDES */ > > #define EXTENT_DIRTY 1 > #define EXTENT_WRITEBACK (1 << 1) > diff --git a/radix-tree.h b/radix-tree.h > index d99ea7e..bf96d83 100644 > --- a/radix-tree.h > +++ b/radix-tree.h > @@ -37,7 +37,11 @@ > #ifndef _LINUX_RADIX_TREE_H > #define _LINUX_RADIX_TREE_H > > +#if BTRFS_FLAT_INCLUDES > #include "kerncompat.h" > +#else > +#include <btrfs/kerncompat.h> > +#endif /* BTRFS_FLAT_INCLUDES */ > > #define RADIX_TREE_MAX_TAGS 2 > > diff --git a/rbtree.h b/rbtree.h > index bed054d..b636ddd 100644 > --- a/rbtree.h > +++ b/rbtree.h > @@ -93,7 +93,11 @@ static inline struct page * rb_insert_page_cache(struct inode * inode, > > #ifndef _LINUX_RBTREE_H > #define _LINUX_RBTREE_H > +#if BTRFS_FLAT_INCLUDES > #include "kerncompat.h" > +#else > +#include <btrfs/kerncompat.h> > +#endif /* BTRFS_FLAT_INCLUDES */ > struct rb_node > { > unsigned long rb_parent_color; > diff --git a/send-utils.h b/send-utils.h > index da407eb..8040c50 100644 > --- a/send-utils.h > +++ b/send-utils.h > @@ -18,8 +18,13 @@ > #ifndef SEND_UTILS_H_ > #define SEND_UTILS_H_ > > +#if BTRFS_FLAT_INCLUDES > #include "ctree.h" > #include "rbtree.h" > +#else > +#include <btrfs/ctree.h> > +#include <btrfs/rbtree.h> > +#endif /* BTRFS_FLAT_INCLUDES */ > > enum subvol_search_type { > subvol_search_by_root_id, >-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Arvin Schnell
2013-Jan-14 14:18 UTC
Re: [PATCH 2/3] btrfs-progs: libify some parts of btrfs-progs
Hi, please find attached a patch to make the new libbtrfs usable from C++ (at least for the parts snapper will likely need). Regards, Arvin -- Arvin Schnell, <aschnell@suse.de> Senior Software Engineer, Research & Development SUSE LINUX Products GmbH, GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer, HRB 16746 (AG Nürnberg) Maxfeldstraße 5 90409 Nürnberg Germany --FCuugMFkClbJLl1L Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="libbtrfs-c++.diff" diff --git a/cmds-send.c b/cmds-send.c index 9b47e70..c51310a 100644 --- a/cmds-send.c +++ b/cmds-send.c @@ -40,6 +40,10 @@ #include "send.h" #include "send-utils.h" +#ifdef __cplusplus +extern "C" { +#endif + static int g_verbose = 0; struct btrfs_send { @@ -654,3 +658,7 @@ int cmd_send(int argc, char **argv) { return cmd_send_start(argc, argv); } + +#ifdef __cplusplus +} +#endif diff --git a/extent_io.c b/extent_io.c index ebb35b2..70ecc48 100644 --- a/extent_io.c +++ b/extent_io.c @@ -48,7 +48,7 @@ static struct extent_state *alloc_extent_state(void) return NULL; state->refs = 1; state->state = 0; - state->private = 0; + state->xprivate = 0; return state; } @@ -509,7 +509,7 @@ int set_state_private(struct extent_io_tree *tree, u64 start, u64 private) ret = -ENOENT; goto out; } - state->private = private; + state->xprivate = private; out: return ret; } @@ -530,7 +530,7 @@ int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private) ret = -ENOENT; goto out; } - *private = state->private; + *private = state->xprivate; out: return ret; } diff --git a/extent_io.h b/extent_io.h index 4553859..6d8404d 100644 --- a/extent_io.h +++ b/extent_io.h @@ -54,7 +54,7 @@ struct extent_state { u64 end; int refs; unsigned long state; - u64 private; + u64 xprivate; }; struct extent_buffer { @@ -93,8 +93,8 @@ int extent_buffer_uptodate(struct extent_buffer *eb); int set_extent_buffer_uptodate(struct extent_buffer *eb); int clear_extent_buffer_uptodate(struct extent_io_tree *tree, struct extent_buffer *eb); -int set_state_private(struct extent_io_tree *tree, u64 start, u64 private); -int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private); +int set_state_private(struct extent_io_tree *tree, u64 start, u64 xprivate); +int get_state_private(struct extent_io_tree *tree, u64 start, u64 *xprivate); struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree, u64 bytenr, u32 blocksize); struct extent_buffer *find_first_extent_buffer(struct extent_io_tree *tree, diff --git a/ioctl.h b/ioctl.h index b7f1ce3..56de39f 100644 --- a/ioctl.h +++ b/ioctl.h @@ -22,6 +22,10 @@ #include <linux/ioctl.h> #include <time.h> +#ifdef __cplusplus +extern "C" { +#endif + #define BTRFS_IOCTL_MAGIC 0x94 #define BTRFS_VOL_NAME_MAX 255 @@ -439,4 +443,9 @@ struct btrfs_ioctl_clone_range_args { struct btrfs_ioctl_qgroup_create_args) #define BTRFS_IOC_QGROUP_LIMIT _IOR(BTRFS_IOCTL_MAGIC, 43, \ struct btrfs_ioctl_qgroup_limit_args) + +#ifdef __cplusplus +} +#endif + #endif diff --git a/list.h b/list.h index d31090c..50f4619 100644 --- a/list.h +++ b/list.h @@ -19,8 +19,8 @@ #ifndef _LINUX_LIST_H #define _LINUX_LIST_H -#define LIST_POISON1 ((void *) 0x00100100) -#define LIST_POISON2 ((void *) 0x00200200) +#define LIST_POISON1 ((struct list_head *) 0x00100100) +#define LIST_POISON2 ((struct list_head *) 0x00200200) /* * Simple doubly linked list implementation. @@ -54,17 +54,17 @@ static inline void INIT_LIST_HEAD(struct list_head *list) * the prev/next entries already! */ #ifndef CONFIG_DEBUG_LIST -static inline void __list_add(struct list_head *new, +static inline void __list_add(struct list_head *xnew, struct list_head *prev, struct list_head *next) { - next->prev = new; - new->next = next; - new->prev = prev; - prev->next = new; + next->prev = xnew; + xnew->next = next; + xnew->prev = prev; + prev->next = xnew; } #else -extern void __list_add(struct list_head *new, +extern void __list_add(struct list_head *xnew, struct list_head *prev, struct list_head *next); #endif @@ -78,12 +78,12 @@ extern void __list_add(struct list_head *new, * This is good for implementing stacks. */ #ifndef CONFIG_DEBUG_LIST -static inline void list_add(struct list_head *new, struct list_head *head) +static inline void list_add(struct list_head *xnew, struct list_head *head) { - __list_add(new, head, head->next); + __list_add(xnew, head, head->next); } #else -extern void list_add(struct list_head *new, struct list_head *head); +extern void list_add(struct list_head *xnew, struct list_head *head); #endif @@ -95,9 +95,9 @@ extern void list_add(struct list_head *new, struct list_head *head); * Insert a new entry before the specified head. * This is useful for implementing queues. */ -static inline void list_add_tail(struct list_head *new, struct list_head *head) +static inline void list_add_tail(struct list_head *xnew, struct list_head *head) { - __list_add(new, head->prev, head); + __list_add(xnew, head->prev, head); } /* @@ -137,18 +137,18 @@ extern void list_del(struct list_head *entry); * Note: if ''old'' was empty, it will be overwritten. */ static inline void list_replace(struct list_head *old, - struct list_head *new) + struct list_head *xnew) { - new->next = old->next; - new->next->prev = new; - new->prev = old->prev; - new->prev->next = new; + xnew->next = old->next; + xnew->next->prev = xnew; + xnew->prev = old->prev; + xnew->prev->next = xnew; } static inline void list_replace_init(struct list_head *old, - struct list_head *new) + struct list_head *xnew) { - list_replace(old, new); + list_replace(old, xnew); INIT_LIST_HEAD(old); } /** diff --git a/rbtree.h b/rbtree.h index b636ddd..8f717a9 100644 --- a/rbtree.h +++ b/rbtree.h @@ -149,7 +149,7 @@ extern struct rb_node *rb_first(struct rb_root *); extern struct rb_node *rb_last(struct rb_root *); /* Fast replacement of a single node without remove/rebalance/add/rebalance */ -extern void rb_replace_node(struct rb_node *victim, struct rb_node *new, +extern void rb_replace_node(struct rb_node *victim, struct rb_node *xnew, struct rb_root *root); static inline void rb_link_node(struct rb_node * node, struct rb_node * parent, diff --git a/send-stream.h b/send-stream.h index 9a17e32..9223018 100644 --- a/send-stream.h +++ b/send-stream.h @@ -18,6 +18,10 @@ #ifndef SEND_STREAM_H_ #define SEND_STREAM_H_ +#ifdef __cplusplus +extern "C" { +#endif + struct btrfs_send_ops { int (*subvol)(const char *path, const u8 *uuid, u64 ctransid, void *user); @@ -55,5 +59,8 @@ struct btrfs_send_ops { int btrfs_read_and_process_send_stream(int fd, struct btrfs_send_ops *ops, void *user); +#ifdef __cplusplus +} +#endif #endif /* SEND_STREAM_H_ */ diff --git a/send-utils.h b/send-utils.h index 8040c50..199dd03 100644 --- a/send-utils.h +++ b/send-utils.h @@ -26,6 +26,10 @@ #include <btrfs/rbtree.h> #endif /* BTRFS_FLAT_INCLUDES */ +#ifdef __cplusplus +extern "C" { +#endif + enum subvol_search_type { subvol_search_by_root_id, subvol_search_by_uuid, @@ -70,5 +74,8 @@ void subvol_uuid_search_add(struct subvol_uuid_search *s, char *path_cat(const char *p1, const char *p2); char *path_cat3(const char *p1, const char *p2, const char *p3); +#ifdef __cplusplus +} +#endif #endif /* SEND_UTILS_H_ */ diff --git a/send.h b/send.h index 48d425a..e8da785 100644 --- a/send.h +++ b/send.h @@ -19,6 +19,10 @@ #include "ctree.h" +#ifdef __cplusplus +extern "C" { +#endif + #define BTRFS_SEND_STREAM_MAGIC "btrfs-stream" #define BTRFS_SEND_STREAM_VERSION 1 @@ -132,3 +136,7 @@ enum { #ifdef __KERNEL__ long btrfs_ioctl_send(struct file *mnt_file, void __user *arg); #endif + +#ifdef __cplusplus +} +#endif --FCuugMFkClbJLl1L-- -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Mark Fasheh
2013-Jan-14 18:10 UTC
Re: [PATCH 2/3] btrfs-progs: libify some parts of btrfs-progs
On Mon, Jan 14, 2013 at 11:43:44AM +0800, Anand Jain wrote:> > Mark, > > Good to create man libbtrfs ?Are you asking if you should do this? If so yeah for sure, I won''t complain about sharing the work! If you''re asking whether I should, I''m not sure. I suppose it''s probably a good idea :) I''ll have to look at other libfs manpages first to get an idea of what goes in there. At any rate, thanks :) --Mark -- Mark Fasheh -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Mark Fasheh
2013-Jan-14 18:14 UTC
Re: [PATCH 2/3] btrfs-progs: libify some parts of btrfs-progs
Hi Arvin! On Mon, Jan 14, 2013 at 03:18:14PM +0100, Arvin Schnell wrote:> please find attached a patch to make the new libbtrfs usable from > C++ (at least for the parts snapper will likely need).Thanks, that looks great. I''ll integrate it into my stack of patches and send it out with the next set. Can I put: Signed-off-by: Arvin Schnell <aschnell@suse.de> at the bottom of the patch to indicate that started with you? Thanks, --Mark -- Mark Fasheh -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Mark Fasheh
2013-Jan-14 18:16 UTC
Re: [PATCH 2/3] btrfs-progs: libify some parts of btrfs-progs
On Mon, Jan 14, 2013 at 11:42:05AM +0800, Anand Jain wrote:> > > Mark, > > Its bit strange, the steps given before can reproduce > the problem still on my older workspace. However when > I try with the fresh clone, it can reproduce the issue > (4 times, consistently) only with the following (new) > steps..Ok.> # git clone > git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-progs.git > > # cd btrfs-progs/ > # make version; make installAhh, this *does* reproduce for me. I think we just need to add libbtrfs as a target somewhere. I''ll fix it up. Thanks so much for drilling down to a test case! --Mark -- Mark Fasheh -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Arvin Schnell
2013-Jan-14 22:26 UTC
Re: [PATCH 2/3] btrfs-progs: libify some parts of btrfs-progs
On Mon, Jan 14, 2013 at 10:14:03AM -0800, Mark Fasheh wrote:> Hi Arvin! > > On Mon, Jan 14, 2013 at 03:18:14PM +0100, Arvin Schnell wrote: > > please find attached a patch to make the new libbtrfs usable from > > C++ (at least for the parts snapper will likely need). > > Thanks, that looks great. I''ll integrate it into my stack of patches and > send it out with the next set. > > Can I put: > > Signed-off-by: Arvin Schnell <aschnell@suse.de> > > at the bottom of the patch to indicate that started with you?Sure. Regards, Arvin -- Arvin Schnell, <aschnell@suse.de> Senior Software Engineer, Research & Development SUSE LINUX Products GmbH, GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer, HRB 16746 (AG Nürnberg) Maxfeldstraße 5 90409 Nürnberg Germany -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Mark Fasheh
2013-Jan-14 22:27 UTC
Re: [PATCH 2/3] btrfs-progs: libify some parts of btrfs-progs
On Mon, Jan 14, 2013 at 11:42:05AM +0800, Anand Jain wrote:> Its bit strange, the steps given before can reproduce > the problem still on my older workspace. However when > I try with the fresh clone, it can reproduce the issue > (4 times, consistently) only with the following (new) > steps.. > > ----------------- > # git clone > git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-progs.git > > # cd btrfs-progs/ > # make version; make installOk, I was able to fix this by adding the libs target to the various other targets. A series of patches with all the fixes (build and whitespace) and Arvin''s patch can be found at: https://github.com/markfasheh/btrfs-progs-patches/tree/no-data-and-libify If nothing else comes up, I will send them out tommorrow. Thanks again to you all for looking at this. --Mark -- Mark Fasheh -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Anand Jain
2013-Jan-15 08:06 UTC
Re: [PATCH 2/3] btrfs-progs: libify some parts of btrfs-progs
better if its there (man libbtrfs). pls create if you could. Thanks, Anand On 01/15/2013 02:10 AM, Mark Fasheh wrote:> On Mon, Jan 14, 2013 at 11:43:44AM +0800, Anand Jain wrote: >> >> Mark, >> >> Good to create man libbtrfs ? > > Are you asking if you should do this? If so yeah for sure, I won''t complain > about sharing the work! > > If you''re asking whether I should, I''m not sure. I suppose it''s probably a > good idea :) I''ll have to look at other libfs manpages first to get an idea > of what goes in there. > > At any rate, thanks :) > --Mark > > -- > Mark Fasheh >-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Ilya Dryomov
2013-Jan-15 12:46 UTC
Re: [PATCH 2/3] btrfs-progs: libify some parts of btrfs-progs
On Mon, Jan 14, 2013 at 03:18:14PM +0100, Arvin Schnell wrote:> > Hi, > > please find attached a patch to make the new libbtrfs usable from > C++ (at least for the parts snapper will likely need). > > Regards, > Arvin > > -- > Arvin Schnell, <aschnell@suse.de> > Senior Software Engineer, Research & Development > SUSE LINUX Products GmbH, GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer, HRB 16746 (AG Nürnberg) > Maxfeldstraße 5 > 90409 Nürnberg > Germany> diff --git a/cmds-send.c b/cmds-send.c > index 9b47e70..c51310a 100644 > --- a/cmds-send.c > +++ b/cmds-send.c > @@ -40,6 +40,10 @@ > #include "send.h" > #include "send-utils.h" > > +#ifdef __cplusplus > +extern "C" { > +#endif > + > static int g_verbose = 0; > > struct btrfs_send { > @@ -654,3 +658,7 @@ int cmd_send(int argc, char **argv) > { > return cmd_send_start(argc, argv); > } > + > +#ifdef __cplusplus > +} > +#endifHi Arvin, Why exactly do we need this in a non-header file? Thanks, Ilya -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Arvin Schnell
2013-Jan-15 13:26 UTC
Re: [PATCH 2/3] btrfs-progs: libify some parts of btrfs-progs
On Tue, Jan 15, 2013 at 02:46:50PM +0200, Ilya Dryomov wrote:> On Mon, Jan 14, 2013 at 03:18:14PM +0100, Arvin Schnell wrote: > > > > Hi, > > > > please find attached a patch to make the new libbtrfs usable from > > C++ (at least for the parts snapper will likely need).> Why exactly do we need this in a non-header file?Oh, that''s clearly a mistake. Thanks for noticing. Regards, Arvin -- Arvin Schnell, <aschnell@suse.de> Senior Software Engineer, Research & Development SUSE LINUX Products GmbH, GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer, HRB 16746 (AG Nürnberg) Maxfeldstraße 5 90409 Nürnberg Germany -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Mark Fasheh
2013-Jan-16 22:11 UTC
Re: [PATCH 2/3] btrfs-progs: libify some parts of btrfs-progs
On Tue, Jan 15, 2013 at 04:06:42PM +0800, Anand Jain wrote:> better if its there (man libbtrfs). pls create if you could.Hmm, I''m confused though - what exactly goes into a file system library man page? Could you point me to an example one? --Mark -- Mark Fasheh -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html