From patchwork Wed Nov 18 19:18:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 11915745 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4F36C5519F for ; Wed, 18 Nov 2020 19:20:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 73EBE22227 for ; Wed, 18 Nov 2020 19:20:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=osandov-com.20150623.gappssmtp.com header.i=@osandov-com.20150623.gappssmtp.com header.b="ctJn0jyR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727384AbgKRTTq (ORCPT ); Wed, 18 Nov 2020 14:19:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727363AbgKRTTq (ORCPT ); Wed, 18 Nov 2020 14:19:46 -0500 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BD77C0613D4 for ; Wed, 18 Nov 2020 11:19:44 -0800 (PST) Received: by mail-pl1-x644.google.com with SMTP id b3so1521711pls.11 for ; Wed, 18 Nov 2020 11:19:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YMykUAF1jBHiR3hoO57Gb2atrtMf3A6zHbbf8nZiQAw=; b=ctJn0jyRQWnOpDMJwzJ+5wGIlsnQ3VJ3TXetiT77zEVZfeZInXDICwBHskcwPaagfw hVFzGIgVWpn/RmBRX3h+aVFw4RBIaLTXiMBWXUP0Pbb9VJttVxZuBwkUofvTQBbzVOgz Kct6Hqn5DOOCDvLZw1BEHq3M9yE8NW0PIpiunBFr4tWy31Zz/S5wczAJcdR2eHrNtyaB V3rR9mK5JV/NaVSjDhsX4Qki6XSsWcY3lY1WCPTrVuSxwqaEMbIxnBqRUAZCzUkWlIGs sDCcta50NGCyweNXAWog7CT4ioEj8vmkYsz98Y5K4Xn8bOj5F2rgUWIjojE5CAtLtt0o Mxog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YMykUAF1jBHiR3hoO57Gb2atrtMf3A6zHbbf8nZiQAw=; b=oYtGPe1sumAD6+J1EJc+fK/i9BSmI/rvEK5XAQccqiqshnjJ+jR9T7q/2fGPJASH/u HnD5qxpjl8wvp3qENNPgfXRtxrFidabwyZf/187xoAxWSnjUtWhl6+KeBHqoxFdJDo7m Nmj0d9egkywW2qVABd+6ZrjX52hyzwQU3iI8GxSm74rf61usFTgDkei9QQ3vA1lsGQFA XPZcXzK4d/sL2S3BWK00Sauss6LqutbJ5WUszHjoHiUnpn0hQREUty8zdXXBLdAseAha GR8BEWm/SWfFRjVtS4sttmpTSEpPOrEd2dp5yn+jrPH/jjQ5WxfpPqipTwJXZA5iCAn8 rHew== X-Gm-Message-State: AOAM531uxA4zl1X8Cqcww094UH37U4BlQ/etwmhui9syt+sWMgRmM0wC /Nj+YGECnsc88Gpb1IAYyvOeGYK6WeEQvg== X-Google-Smtp-Source: ABdhPJyjyV39XZbRXV15OJ4+YJbkxyshR9NPZsrXzqNxm89Fj2aeHfQnMcTtwS6DMunK8J7vfAGITQ== X-Received: by 2002:a17:902:9b93:b029:d6:d0e3:10c6 with SMTP id y19-20020a1709029b93b02900d6d0e310c6mr5855545plp.41.1605727183352; Wed, 18 Nov 2020 11:19:43 -0800 (PST) Received: from relinquished.tfbnw.net ([2620:10d:c090:400::5:8b43]) by smtp.gmail.com with ESMTPSA id l9sm3197221pjy.10.2020.11.18.11.19.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 11:19:42 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v2 11/13] btrfs-progs: receive: process setflags ioctl commands Date: Wed, 18 Nov 2020 11:18:58 -0800 Message-Id: <40b7cf2fb2602cc6029eb36c15eab361ac4e5340.1605723745.git.osandov@osandov.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Boris Burkov 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. Signed-off-by: Boris Burkov --- cmds/receive-dump.c | 6 ++++++ cmds/receive.c | 24 ++++++++++++++++++++++++ common/send-stream.c | 7 +++++++ common/send-stream.h | 1 + 4 files changed, 38 insertions(+) diff --git a/cmds/receive-dump.c b/cmds/receive-dump.c index acc0ba32..40f07ad4 100644 --- a/cmds/receive-dump.c +++ b/cmds/receive-dump.c @@ -337,6 +337,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, @@ -361,4 +366,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 ca9c3f5a..1863f881 100644 --- a/cmds/receive.c +++ b/cmds/receive.c @@ -1381,6 +1381,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, false); + 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, @@ -1405,6 +1428,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 d455cdfb..da0c0e5d 100644 --- a/common/send-stream.c +++ b/common/send-stream.c @@ -370,6 +370,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) @@ -523,8 +524,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 a58739bb..5373bf69 100644 --- a/common/send-stream.h +++ b/common/send-stream.h @@ -72,6 +72,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,