@@ -435,6 +435,7 @@ int cmd_send(int argc, char **argv)
u64 parent_root_id = 0;
int full_send = 1;
int new_end_cmd_semantic = 0;
+ int k_sstream;
memset(&send, 0, sizeof(send));
send.dump_fd = fileno(stdout);
@@ -544,6 +545,18 @@ int cmd_send(int argc, char **argv)
ret = 1;
goto out;
}
+
+ /* check if btrfs kernel supports send stream ver 2 */
+ if (g_stream_version > BTRFS_SEND_STREAM_VERSION_1) {
+ k_sstream = btrfs_read_sysfs(BTRFS_SEND_STREAM_VER_PATH);
+ if (k_sstream < g_stream_version) {
+ fprintf(stderr,
+ "ERROR: Need btrfs kernel send stream version %d or above, %d\n",
+ BTRFS_SEND_STREAM_VERSION_2, k_sstream);
+ ret = 1;
+ goto out;
+ }
+ }
break;
case 's':
g_total_data_size = 1;
@@ -24,6 +24,8 @@ extern "C" {
#endif
#define BTRFS_SEND_STREAM_MAGIC "btrfs-stream"
+#define BTRFS_SEND_STREAM_VER_PATH "/sys/fs/btrfs/send/stream_version"
+
#define BTRFS_SEND_STREAM_VERSION_1 1
#define BTRFS_SEND_STREAM_VERSION_2 2
/* Max supported stream version. */
@@ -2681,3 +2681,20 @@ int fsid_to_mntpt(__u8 *fsid, char *mntpt, int *mnt_cnt)
return ret;
}
+
+int btrfs_read_sysfs(char path[PATH_MAX])
+{
+ int fd;
+ char val;
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0)
+ return -errno;
+
+ if (read(fd, &val, sizeof(char)) < sizeof(char)) {
+ close(fd);
+ return -EINVAL;
+ }
+ close(fd);
+ return atoi((const char *)&val);
+}
@@ -153,5 +153,6 @@ static inline u64 btrfs_min_dev_size(u32 leafsize)
return 2 * (BTRFS_MKFS_SYSTEM_GROUP_SIZE +
btrfs_min_global_blk_rsv_size(leafsize));
}
+int btrfs_read_sysfs(char path[PATH_MAX]);
#endif
When kernel does not have the send stream version 2 patches, the btrfs send with --stream-version 2 would fail with out giving the details what is wrong. This patch will help to identify correctly that required kernel patches are missing. Signed-off-by: Anand Jain <anand.jain@oracle.com> --- cmds-send.c | 13 +++++++++++++ send.h | 2 ++ utils.c | 17 +++++++++++++++++ utils.h | 1 + 4 files changed, 33 insertions(+)