From: Omar Sandoval <osandov@osandov.com>
To: linux-btrfs@vger.kernel.org
Cc: kernel-team@fb.com
Subject: [PATCH v14 08/10] btrfs-progs: receive: process setflags ioctl commands
Date: Thu, 17 Mar 2022 10:25:51 -0700 [thread overview]
Message-ID: <7e92fa68eafefadb4f384b3b8cb2879b6edbcd89.1647537098.git.osandov@fb.com> (raw)
In-Reply-To: <cover.1647537027.git.osandov@fb.com>
From: Boris Burkov <boris@bur.io>
In send stream v2, send can emit a command for setting inode flags via
the setflags ioctl. Pass the flags attribute through to the ioctl call
in receive.
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Boris Burkov <boris@bur.io>
---
cmds/receive-dump.c | 6 ++++++
cmds/receive.c | 25 +++++++++++++++++++++++++
common/send-stream.c | 7 +++++++
common/send-stream.h | 1 +
4 files changed, 39 insertions(+)
diff --git a/cmds/receive-dump.c b/cmds/receive-dump.c
index fa397bcf..df5991e1 100644
--- a/cmds/receive-dump.c
+++ b/cmds/receive-dump.c
@@ -339,6 +339,11 @@ static int print_fallocate(const char *path, int mode, u64 offset, u64 len,
mode, offset, len);
}
+static int print_setflags(const char *path, int flags, void *user)
+{
+ return PRINT_DUMP(user, path, "setflags", "flags=%d", flags);
+}
+
struct btrfs_send_ops btrfs_print_send_ops = {
.subvol = print_subvol,
.snapshot = print_snapshot,
@@ -363,4 +368,5 @@ struct btrfs_send_ops btrfs_print_send_ops = {
.update_extent = print_update_extent,
.encoded_write = print_encoded_write,
.fallocate = print_fallocate,
+ .setflags = print_setflags,
};
diff --git a/cmds/receive.c b/cmds/receive.c
index 4893d693..7f76a04f 100644
--- a/cmds/receive.c
+++ b/cmds/receive.c
@@ -38,6 +38,7 @@
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/xattr.h>
+#include <linux/fs.h>
#include <uuid/uuid.h>
#include <lzo/lzo1x.h>
@@ -1284,6 +1285,29 @@ static int process_fallocate(const char *path, int mode, u64 offset, u64 len,
return 0;
}
+static int process_setflags(const char *path, int flags, void *user)
+{
+ int ret;
+ struct btrfs_receive *rctx = user;
+ char full_path[PATH_MAX];
+
+ ret = path_cat_out(full_path, rctx->full_subvol_path, path);
+ if (ret < 0) {
+ error("setflags: path invalid: %s", path);
+ return ret;
+ }
+ ret = open_inode_for_write(rctx, full_path);
+ if (ret < 0)
+ return ret;
+ ret = ioctl(rctx->write_fd, FS_IOC_SETFLAGS, &flags);
+ if (ret < 0) {
+ ret = -errno;
+ error("setflags: setflags ioctl on %s failed: %m", path);
+ return ret;
+ }
+ return 0;
+}
+
static struct btrfs_send_ops send_ops = {
.subvol = process_subvol,
.snapshot = process_snapshot,
@@ -1308,6 +1332,7 @@ static struct btrfs_send_ops send_ops = {
.update_extent = process_update_extent,
.encoded_write = process_encoded_write,
.fallocate = process_fallocate,
+ .setflags = process_setflags,
};
static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
diff --git a/common/send-stream.c b/common/send-stream.c
index 2d0aa624..21295cbb 100644
--- a/common/send-stream.c
+++ b/common/send-stream.c
@@ -374,6 +374,7 @@ static int read_and_process_cmd(struct btrfs_send_stream *sctx)
int len;
int xattr_len;
int fallocate_mode;
+ int setflags_flags;
ret = read_cmd(sctx);
if (ret)
@@ -546,8 +547,14 @@ static int read_and_process_cmd(struct btrfs_send_stream *sctx)
ret = sctx->ops->fallocate(path, fallocate_mode, offset, tmp,
sctx->user);
break;
+ case BTRFS_SEND_C_SETFLAGS:
+ TLV_GET_STRING(sctx, BTRFS_SEND_A_PATH, &path);
+ TLV_GET_U32(sctx, BTRFS_SEND_A_SETFLAGS_FLAGS, &setflags_flags);
+ ret = sctx->ops->setflags(path, setflags_flags, sctx->user);
+ break;
}
+
tlv_get_failed:
out:
free(path);
diff --git a/common/send-stream.h b/common/send-stream.h
index 61a88d3d..3189f889 100644
--- a/common/send-stream.h
+++ b/common/send-stream.h
@@ -59,6 +59,7 @@ struct btrfs_send_ops {
u32 encryption, void *user);
int (*fallocate)(const char *path, int mode, u64 offset, u64 len,
void *user);
+ int (*setflags)(const char *path, int flags, void *user);
};
int btrfs_read_and_process_send_stream(int fd,
--
2.35.1
next prev parent reply other threads:[~2022-03-17 17:26 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-17 17:25 [PATCH v14 0/7] btrfs: add send/receive support for reading/writing compressed data Omar Sandoval
2022-03-17 17:25 ` [PATCH v14 1/7] btrfs: send: remove unused send_ctx::{total,cmd}_send_size Omar Sandoval
2022-03-17 17:25 ` [PATCH v14 2/7] btrfs: send: explicitly number commands and attributes Omar Sandoval
2022-03-24 17:52 ` Sweet Tea Dorminy
2022-03-17 17:25 ` [PATCH v14 3/7] btrfs: add send stream v2 definitions Omar Sandoval
2022-03-17 17:25 ` [PATCH v14 4/7] btrfs: send: write larger chunks when using stream v2 Omar Sandoval
2022-03-24 17:52 ` Sweet Tea Dorminy
2022-03-30 17:05 ` Omar Sandoval
2022-03-17 17:25 ` [PATCH v14 5/7] btrfs: send: allocate send buffer with alloc_page() and vmap() for v2 Omar Sandoval
2022-03-24 17:53 ` Sweet Tea Dorminy
2022-03-30 16:03 ` Omar Sandoval
2022-03-30 16:33 ` Sweet Tea Dorminy
2022-03-30 17:13 ` Omar Sandoval
2022-03-30 18:48 ` Sweet Tea Dorminy
2022-03-30 20:42 ` Omar Sandoval
2022-03-30 21:04 ` Sweet Tea Dorminy
2022-03-17 17:25 ` [PATCH v14 6/7] btrfs: send: send compressed extents with encoded writes Omar Sandoval
2022-03-17 17:25 ` [PATCH v14 7/7] btrfs: send: enable support for stream v2 and compressed writes Omar Sandoval
2022-03-17 17:25 ` [PATCH v14 01/10] btrfs-progs: receive: support v2 send stream larger tlv_len Omar Sandoval
2022-03-17 17:25 ` [PATCH v14 02/10] btrfs-progs: receive: dynamically allocate sctx->read_buf Omar Sandoval
2022-03-17 17:25 ` [PATCH v14 03/10] btrfs-progs: receive: support v2 send stream DATA tlv format Omar Sandoval
2022-03-17 17:25 ` [PATCH v14 04/10] btrfs-progs: receive: add send stream v2 cmds and attrs to send.h Omar Sandoval
2022-03-17 17:25 ` [PATCH v14 05/10] btrfs-progs: receive: process encoded_write commands Omar Sandoval
2022-03-17 17:25 ` [PATCH v14 06/10] btrfs-progs: receive: encoded_write fallback to explicit decode and write Omar Sandoval
2022-03-17 17:25 ` [PATCH v14 07/10] btrfs-progs: receive: process fallocate commands Omar Sandoval
2022-03-17 17:25 ` Omar Sandoval [this message]
2022-03-17 17:25 ` [PATCH v14 09/10] btrfs-progs: send: stream v2 ioctl flags Omar Sandoval
2022-03-17 17:25 ` [PATCH v14 10/10] btrfs-progs: receive: add tests for basic encoded_write send/receive Omar Sandoval
2022-03-24 17:53 ` [PATCH v14 0/7] btrfs: add send/receive support for reading/writing compressed data Sweet Tea Dorminy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7e92fa68eafefadb4f384b3b8cb2879b6edbcd89.1647537098.git.osandov@fb.com \
--to=osandov@osandov.com \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox