From patchwork Thu Nov 3 16:53:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13030661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 425A6C4332F for ; Thu, 3 Nov 2022 16:53:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231700AbiKCQxh (ORCPT ); Thu, 3 Nov 2022 12:53:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231646AbiKCQxf (ORCPT ); Thu, 3 Nov 2022 12:53:35 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84657B7EE for ; Thu, 3 Nov 2022 09:53:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 23B45B8295E for ; Thu, 3 Nov 2022 16:53:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51B2AC433D7 for ; Thu, 3 Nov 2022 16:53:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667494411; bh=yatMWFl39r/OE7UTTbcPbvyoAW1RGdrPnOb1sMiIcZA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GA+PH8WKNcaLu9HkF/SZQ1AWOgFI58pYCrBtt19V40+8COzY8SRUaxCUmuc7qJX7h 1NmD6PJzMNUuKAJh/fS2V5ul4Gcm8zJ7cRzVWT/FcPxzn0V7V/4dn5h4CEIpEXhJku XIrhLD7cbKl+iQidBBV4tr0fh670u0VnQ1vFgjWYuUMHMEWJ1oz5E1EnQD9ZxQT1es 2lyHfxTZczfuxWApHYi1O5pTGWxFG+FXHkA98xvd6OhJROMe5Yma1cwV4qL/Hu5h9n G637qrGHgi9WhOL3Bsdtb4aBzHzl5N+seP+AjIweQYlW593PHRqteiqBkVEbIgcxkD OFT29OvfHLwKg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/2] btrfs-progs: receive: fix parsing of attributes field from the fileattr command Date: Thu, 3 Nov 2022 16:53:26 +0000 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana We're trying to get a U32 for the attributes, but the kernel sends a U64 (which is correct as we store attributes in a u64 flags field of the inode). This makes anyone trying to receive a v2 send stream to fail with: ERROR: invalid size for attribute, expected = 4, got = 8 We actually recently got such a report of someone using send stream v2 and getting such failure. See the Link tag below. Link: https://lore.kernel.org/linux-btrfs/6cb11fa5-c60d-e65b-0295-301a694e66ad@inbox.ru/ Fixes: 7a6fb356dc65 ("btrfs-progs: receive: process setflags ioctl commands") Signed-off-by: Filipe Manana --- common/send-stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/send-stream.c b/common/send-stream.c index 72a25729..e9f565e6 100644 --- a/common/send-stream.c +++ b/common/send-stream.c @@ -570,7 +570,7 @@ static int read_and_process_cmd(struct btrfs_send_stream *sctx) break; case BTRFS_SEND_C_FILEATTR: TLV_GET_STRING(sctx, BTRFS_SEND_A_PATH, &path); - TLV_GET_U32(sctx, BTRFS_SEND_A_FILEATTR, &fileattr); + TLV_GET_U64(sctx, BTRFS_SEND_A_FILEATTR, &fileattr); ret = sctx->ops->fileattr(path, fileattr, sctx->user); break; } From patchwork Thu Nov 3 16:53:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13030662 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD2D0C433FE for ; Thu, 3 Nov 2022 16:53:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231646AbiKCQxj (ORCPT ); Thu, 3 Nov 2022 12:53:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230258AbiKCQxg (ORCPT ); Thu, 3 Nov 2022 12:53:36 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EE48E17 for ; Thu, 3 Nov 2022 09:53:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0890BB8295F for ; Thu, 3 Nov 2022 16:53:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38D34C433B5 for ; Thu, 3 Nov 2022 16:53:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667494412; bh=aB9w2S5YnHVBiSUa/kg+ZcWhY1ioiAPkMZlPOOb6Dqs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DRu1jKmgUAqOva3oRD9sRlFJo+YNSqYLyB+BWO7SE9WrLEcRyye0XOMWVwAdC3Xog ruoVybhafTVWCqVWwujC5KKvhNH396Rt9f11iqruu0lR/BFXloVAA6Na5ldAh0u4St XSaFRvMIA/nmLEO1/mhMBNkUwY5pTvSLmkBd7R82T6fSo5ya+C+zoDDCXpUbFJOYNG XlXzpOv8Lt3wb4WNK8cPuN0c0ifKhZppp8SKOTB5j9guhRVBDIUxCGEXXVQyelUlqk tpLy96SSVOh0lAJi4YDYi4dxX/MfrmtF14fHuhnePV9mDPgRUW7D2wGfavFx9M+47k OGa3SE7WS8Tvw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/2] btrfs-progs: receive: work around failure of fileattr commands Date: Thu, 3 Nov 2022 16:53:27 +0000 Message-Id: <73d07400c0fbf7d52fbcee00f73390d0749e5e76.1667494221.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana Currently fileattr commands, introduced in the send stream v2, always fail, since we have commented the FS_IOC_SETFLAGS ioctl() call and set 'ret' to -EOPNOTSUPP, which is then overwritten to -errno, which may have a random value since it was not initialized before. This results in a failure like this: ERROR: fileattr: set file attributes on p0/f1 failed: Invalid argument The error reason may be something else, since errno is undefined at this point. Unfortunatelly we don't have a way yet to apply attributes, since the attributes value we get from the kernel is what we store in flags field of the inode item. This means that for example we can not just call FS_IOC_SETFLAGS with the values we got, since they need to be converted from BTRFS_INODE_* flags to FS_* flags Besides that we'll have to reorder how we apply certain attributes like FS_NOCOW_FL for example, which must happen always on an empty file and right now we run write commands before attempting to change attributes, as that's the order the kernel sends the operations. So for now comment all the code, so that anyone using the v2 stream will not have a receive failure but will get a behaviour like the v1 stream: file attributes are ignored. This will have to be fixed later, but right now people can't use a send stream v2 for the purpose of getting better performance by avoid decompressing extents at the source and compression of the data at the destination. Link: https://lore.kernel.org/linux-btrfs/6cb11fa5-c60d-e65b-0295-301a694e66ad@inbox.ru/ Fixes: 8356c423e619 ("btrfs-progs: receive: implement FILEATTR command") Signed-off-by: Filipe Manana --- cmds/receive.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/cmds/receive.c b/cmds/receive.c index af3138d5..6f475544 100644 --- a/cmds/receive.c +++ b/cmds/receive.c @@ -1304,25 +1304,33 @@ static int process_fallocate(const char *path, int mode, u64 offset, u64 len, static int process_fileattr(const char *path, u64 attr, void *user) { - int ret; - struct btrfs_receive *rctx = user; - char full_path[PATH_MAX]; + /* + * Not yet supported, ignored for now, just like in send stream v1. + * The content of 'attr' matches the flags in the btrfs inode item, + * we can't apply them directly with FS_IOC_SETFLAGS, as we need to + * convert them from BTRFS_INODE_* flags to FS_* flags. Plus some + * flags are special and must be applied in a special way. + * The commented code below therefore does not work. + */ - ret = path_cat_out(full_path, rctx->full_subvol_path, path); - if (ret < 0) { - error("fileattr: path invalid: %s", path); - return ret; - } - ret = open_inode_for_write(rctx, full_path); - if (ret < 0) - return ret; - ret = -EOPNOTSUPP; - /* ret = ioctl(rctx->write_fd, FS_IOC_SETFLAGS, &flags); */ - if (ret < 0) { - ret = -errno; - error("fileattr: set file attributes on %s failed: %m", path); - return ret; - } + /* 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("fileattr: 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, &attr); */ + /* if (ret < 0) { */ + /* ret = -errno; */ + /* error("fileattr: set file attributes on %s failed: %m", path); */ + /* return ret; */ + /* } */ return 0; }