From patchwork Sat Jan 16 16:56:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12024911 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 4D262C433E0 for ; Sat, 16 Jan 2021 17:09:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 14BC820700 for ; Sat, 16 Jan 2021 17:09:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726906AbhAPRJN (ORCPT ); Sat, 16 Jan 2021 12:09:13 -0500 Received: from mail-lj1-f179.google.com ([209.85.208.179]:45933 "EHLO mail-lj1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727995AbhAPRJA (ORCPT ); Sat, 16 Jan 2021 12:09:00 -0500 Received: by mail-lj1-f179.google.com with SMTP id f17so13751620ljg.12; Sat, 16 Jan 2021 09:08:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C2k4AmnHtUh0OVe9iECxCs78XogrR+lg0yB62QXs+9E=; b=Yk96M01xL3zhyHglIQQyCKEFzMXcr3c71sqsYNkB0ra0zcMUqq1L2TjJ3KBBvUY6tC EsRBsp9GM8crOmRYicRCiOxJZbtUtUFZo8yCKuiwxk7D+XRL5wR+1UM8iDbNshPSF+DY nzHxpq0FcLi9Egiib6K3u4GMKyercQEQoV8ENhZSS2XoPbfZjY6R53Dah/9JyMSeCAFC oUz2neveT5X10QVUyPOmeTAISD2dYB7PPmKtRa4dJKyZkVdkB4CSfKNk5IFhsNYfRzUl vmChCHqSm1IqQH59nLFT63McEMfr9ilGmIvgYVX5J1bmdeX+0Ve5vxyw2BxadwliLibI qW6Q== 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=C2k4AmnHtUh0OVe9iECxCs78XogrR+lg0yB62QXs+9E=; b=hfbpE4xUvdhzogbwfPUz/mzGMOBz3FYUYJoiGycX6wRdqUHpsmU8nmBH2jAZqjVDJJ DeeAPfrzctprfAIzV+a7iB5kRADx+YhBtsgQyRFzXNA4ZSkod2tqKRfIT+1zgBeNIclm alXBrnhBkCx/2f1bPQJ2HuwIqStURUyVr5xSZJiAROB45KcSrZX1uitiD3JIwqCG8CXv yKzHhqaor3ajtRW01Wnkia4dVsIMB8RYgeOLxuazNmdAyD/eBDziVfZFzZMF65WupsYS rO+Ml+BDNz8dGW40MiloqFOmMdLvPjFOf468q9CFGk3UfRiF9NOeSuvzr+GgF/UkUkWQ oO3A== X-Gm-Message-State: AOAM531Sai2ESZQP4NmT3BtqsySageJbxxGqvuURTyCUW6XUUrFebVnU SaFR+53sC6U+F6/ECg8jyJXLYC1yQ2U= X-Google-Smtp-Source: ABdhPJx9Zd0nrQANJgwoxf8Q+MLgyW8iVEd3FgSg3ftv1b6owDjISDZUT7DvTDWWkoHAgBRnj68gVw== X-Received: by 2002:a17:906:f1cc:: with SMTP id gx12mr11934663ejb.164.1610816185015; Sat, 16 Jan 2021 08:56:25 -0800 (PST) Received: from localhost.localdomain ([31.210.181.203]) by smtp.gmail.com with ESMTPSA id zn8sm7061063ejb.39.2021.01.16.08.56.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 08:56:24 -0800 (PST) From: Amir Goldstein To: Eryu Guan Cc: Icenowy Zheng , Chengguang Xu , Xiao Yang , Miklos Szeredi , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH 1/4] overlay/030: Update comment w.r.t upstream kernel Date: Sat, 16 Jan 2021 18:56:16 +0200 Message-Id: <20210116165619.494265-2-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116165619.494265-1-amir73il@gmail.com> References: <20210116165619.494265-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org commit 61536bed2149 ("ovl: support [S|G]ETFLAGS and FS[S|G]ETXATTR ioctls for directories") makes the comment in test header inaccurate. Fix the comment to include this information. Signed-off-by: Amir Goldstein --- tests/overlay/030 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/overlay/030 b/tests/overlay/030 index 3ef206b6..c461e502 100755 --- a/tests/overlay/030 +++ b/tests/overlay/030 @@ -8,8 +8,11 @@ # and directories in an overlayfs upper directory. # # This test is similar and was derived from generic/079, but -# the original test is _notrun on overlay mount because FS_IOC_GETFLAGS -# FS_IOC_SETFLAGS ioctls fail on overlay directory inodes. +# the original test is _notrun with FSTYP=overlay on kernel < v5.10 +# because prior to commit 61536bed2149 ("ovl: support [S|G]ETFLAGS +# and FS[S|G]ETXATTR ioctls for directories"), t_immutable -c would +# fail to prepare immutable/append-only directories on the overlay +# mount path. # seq=`basename $0` seqres=$RESULT_DIR/$seq From patchwork Sat Jan 16 16:56:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12024909 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 A7119C433E0 for ; Sat, 16 Jan 2021 17:08:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7095C22AAF for ; Sat, 16 Jan 2021 17:08:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726395AbhAPRHq (ORCPT ); Sat, 16 Jan 2021 12:07:46 -0500 Received: from mail-lf1-f45.google.com ([209.85.167.45]:37395 "EHLO mail-lf1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725964AbhAPRHe (ORCPT ); Sat, 16 Jan 2021 12:07:34 -0500 Received: by mail-lf1-f45.google.com with SMTP id o17so17909564lfg.4; Sat, 16 Jan 2021 09:07:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wa2CXXj6gWguxDo1AA/mB/lnLHXaE5PDB4GKaYCGK0Y=; b=tW5vX254OruXkfZ/pSraa6c04oiYgSfLbFzRaf69g6tKUsPs0Bx4ViPIehDTFWBXmZ 2CsDi5/gNmmebU0kSwZ56/JBoHfEzBUD8Dzy1iTUTl4aRcBWZ6992XFfGwGAv5sHR9Mo mGa6MOFkpqdOO+sC8c2VEXCrLByvg537vrw03OPQ4ouBF8Ub4F0xpBRMnBjfcjhcXobQ 5XkMYzT50TK4/99H0Q9CLC0Y3fLB0wNbjqhPMd0lG+/NaFXSIgYhrV0FcPBSamSyEKZi JeHddInik9iPwqGs8cqOkCpzG5SwDYfD7xhJ4YrFEgnbd8gA4sAcxdFAiVel6WINz2wd RbTw== 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=wa2CXXj6gWguxDo1AA/mB/lnLHXaE5PDB4GKaYCGK0Y=; b=ieROmw/D8eTRgLms78XsT8e7xaNou71xTdGa5NOA6u73rJ/DV/BYLJm6HQe/a5/pAf mBObJ3z1T5zES+BFd8soYuFKc/jVV/mXqJuKi5qWCDCMwrl4Z4JQAxPPPfthLw+dfVJD DYwcSqL+C5odizD17AifQk8vSWtL1K7ZZACsOtzzrf+KZik8ICraE67/DxNzbjsgUBbi ErDO0ZkzhTTdIqTc3GFqvpQ+7SW3nI1aie7Vsq7etFvAiOPOVHa02tY2Yo8JQSh7KP75 TQ8a0xugXHHv7b5Th40hpMOfwOmLgqhccCwIE1Jktm+RGYi3WrU/yaTrRX6jCvgOmQt6 dBew== X-Gm-Message-State: AOAM531LwynuWWEdV7NOj1C/N57GkZMhyGSkmPxqCwON+w1dIWtPm3uy mKFIzPikCTt22qYtQZGRHGUmA+Zn4mk= X-Google-Smtp-Source: ABdhPJxvvsYLlyc8CoVBJHJpBeR+QZVukpiGzksJwMXMrRvleAWgelFWcZszGNBXhTNrpdgkNNTOVg== X-Received: by 2002:a17:906:5907:: with SMTP id h7mr2624661ejq.252.1610816186517; Sat, 16 Jan 2021 08:56:26 -0800 (PST) Received: from localhost.localdomain ([31.210.181.203]) by smtp.gmail.com with ESMTPSA id zn8sm7061063ejb.39.2021.01.16.08.56.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 08:56:25 -0800 (PST) From: Amir Goldstein To: Eryu Guan Cc: Icenowy Zheng , Chengguang Xu , Xiao Yang , Miklos Szeredi , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH 2/4] src/t_immutable: factor out some helpers Date: Sat, 16 Jan 2021 18:56:17 +0200 Message-Id: <20210116165619.494265-3-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116165619.494265-1-amir73il@gmail.com> References: <20210116165619.494265-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org Reduce boilerplate code. define _GNU_SOURCE needed for asprintf. Signed-off-by: Amir Goldstein --- src/t_immutable.c | 221 ++++++++++++++++++++++------------------------ 1 file changed, 104 insertions(+), 117 deletions(-) diff --git a/src/t_immutable.c b/src/t_immutable.c index 86c567ed..b6a76af0 100644 --- a/src/t_immutable.c +++ b/src/t_immutable.c @@ -8,6 +8,9 @@ #define TEST_UTIME +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif #include #include #include @@ -1895,13 +1898,66 @@ static int check_test_area(const char *dir) return 0; } +static int create_dir(char **ppath, const char *fmt, const char *dir) +{ + const char *path; + struct stat st; + + if (asprintf(ppath, fmt, dir) == -1) { + return -1; + } + path = *ppath; + if (stat(path, &st) == 0) { + fprintf(stderr, "%s: Test area directory %s must not exist for test area creation.\n", + __progname, path); + return 1; + } + if (mkdir(path, 0777) != 0) { + fprintf(stderr, "%s: error creating directory %s: %s\n", __progname, path, strerror(errno)); + return -1; + } + return 0; +} + +static int create_file(char **ppath, const char *fmt, const char *dir) +{ + const char *path; + int fd; + + if (asprintf(ppath, fmt, dir) == -1) { + return -1; + } + path = *ppath; + if ((fd = open(path, O_WRONLY|O_CREAT|O_EXCL, 0666)) == -1) { + fprintf(stderr, "%s: error creating file %s: %s\n", __progname, path, strerror(errno)); + return -1; + } + return fd; +} + +static int create_xattrs(int fd) +{ + if (fsetxattr(fd, "trusted.test", "readonly", strlen("readonly"), XATTR_CREATE) != 0) { + if (errno != EOPNOTSUPP) { + perror("setxattr"); + return 1; + } + } + if (fsetxattr(fd, "user.test", "readonly", strlen("readonly"), XATTR_CREATE) != 0) { + if (errno != EOPNOTSUPP) { + perror("setxattr"); + return 1; + } + } + return 0; +} + static int create_test_area(const char *dir) { int fd; char *path; static const char *acl_u_text = "u::rw-,g::rw-,o::rw-,u:nobody:rw-,m::rw-"; static const char *acl_u_text_d = "u::rwx,g::rwx,o::rwx,u:nobody:rwx,m::rwx"; - struct stat st; static const char *immutable = "This is an immutable file.\nIts contents cannot be altered.\n"; static const char *append_only = "This is an append-only file.\nIts contents cannot be altered.\n" "Data can only be appended.\n---\n"; @@ -1911,79 +1967,45 @@ static int create_test_area(const char *dir) return 1; } - if (stat(dir, &st) == 0) { - fprintf(stderr, "%s: Test area directory %s must not exist for test area creation.\n", - __progname, dir); - return 1; - } - umask(0000); - if (mkdir(dir, 0777) != 0) { - fprintf(stderr, "%s: error creating directory %s: %s\n", __progname, dir, strerror(errno)); + if (create_dir(&path, "%s", dir)) { return 1; } - - asprintf(&path, "%s/immutable.d", dir); - if (mkdir(path, 0777) != 0) { - fprintf(stderr, "%s: error creating directory %s: %s\n", __progname, path, strerror(errno)); - return 1; - } free(path); - asprintf(&path, "%s/empty-immutable.d", dir); - if (mkdir(path, 0777) != 0) { - fprintf(stderr, "%s: error creating directory %s: %s\n", __progname, path, strerror(errno)); - return 1; + if (create_dir(&path, "%s/append-only.d", dir)) { + return 1; } free(path); - asprintf(&path, "%s/append-only.d", dir); - if (mkdir(path, 0777) != 0) { - fprintf(stderr, "%s: error creating directory %s: %s\n", __progname, path, strerror(errno)); - return 1; + if (create_dir(&path, "%s/append-only.d/dir", dir)) { + return 1; } free(path); - asprintf(&path, "%s/empty-append-only.d", dir); - if (mkdir(path, 0777) != 0) { - fprintf(stderr, "%s: error creating directory %s: %s\n", __progname, path, strerror(errno)); + if ((fd = create_file(&path, "%s/append-only.d/file", dir)) == -1) { return 1; } + close(fd); free(path); - asprintf(&path, "%s/immutable.d/dir", dir); - if (mkdir(path, 0777) != 0) { - fprintf(stderr, "%s: error creating directory %s: %s\n", __progname, path, strerror(errno)); - return 1; + if (create_dir(&path, "%s/immutable.d", dir)) { + return 1; } free(path); - asprintf(&path, "%s/append-only.d/dir", dir); - if (mkdir(path, 0777) != 0) { - fprintf(stderr, "%s: error creating directory %s: %s\n", __progname, path, strerror(errno)); - return 1; + if (create_dir(&path, "%s/immutable.d/dir", dir)) { + return 1; } free(path); - asprintf(&path, "%s/append-only.d/file", dir); - if ((fd = open(path, O_WRONLY|O_CREAT|O_EXCL, 0666)) == -1) { - fprintf(stderr, "%s: error creating file %s: %s\n", __progname, path, strerror(errno)); + if ((fd = create_file(&path, "%s/immutable.d/file", dir)) == -1) { return 1; } close(fd); free(path); - asprintf(&path, "%s/immutable.d/file", dir); - if ((fd = open(path, O_WRONLY|O_CREAT|O_EXCL, 0666)) == -1) { - fprintf(stderr, "%s: error creating file %s: %s\n", __progname, path, strerror(errno)); - return 1; - } - close(fd); - free(path); - - asprintf(&path, "%s/immutable.f", dir); - if ((fd = open(path, O_WRONLY|O_CREAT|O_EXCL, 0666)) == -1) { - fprintf(stderr, "%s: error creating file %s: %s\n", __progname, path, strerror(errno)); + if ((fd = create_file(&path, "%s/immutable.f", dir)) == -1) { return 1; } if (write(fd, immutable, strlen(immutable)) != strlen(immutable)) { @@ -1994,17 +2016,8 @@ static int create_test_area(const char *dir) perror("acl"); return 1; } - if (fsetxattr(fd, "trusted.test", "readonly", strlen("readonly"), XATTR_CREATE) != 0) { - if (errno != EOPNOTSUPP) { - perror("setxattr"); - return 1; - } - } - if (fsetxattr(fd, "user.test", "readonly", strlen("readonly"), XATTR_CREATE) != 0) { - if (errno != EOPNOTSUPP) { - perror("setxattr"); - return 1; - } + if (create_xattrs(fd)) { + return 1; } if (fsetflag(path, fd, 1, 1)) { perror("fsetflag"); @@ -2014,8 +2027,7 @@ static int create_test_area(const char *dir) close(fd); free(path); - asprintf(&path, "%s/append-only.f", dir); - if ((fd = open(path, O_WRONLY|O_CREAT|O_EXCL, 0666)) == -1) { + if ((fd = create_file(&path, "%s/append-only.f", dir)) == -1) { fprintf(stderr, "%s: error creating file %s: %s\n", __progname, path, strerror(errno)); return 1; } @@ -2027,17 +2039,8 @@ static int create_test_area(const char *dir) perror("acl"); return 1; } - if (fsetxattr(fd, "trusted.test", "readonly", strlen("readonly"), XATTR_CREATE) != 0) { - if (errno != EOPNOTSUPP) { - perror("setxattr"); - return 1; - } - } - if (fsetxattr(fd, "user.test", "readonly", strlen("readonly"), XATTR_CREATE) != 0) { - if (errno != EOPNOTSUPP) { - perror("setxattr"); - return 1; - } + if (create_xattrs(fd)) { + return 1; } if (fsetflag(path, fd, 1, 0)) { perror("fsetflag"); @@ -2056,17 +2059,8 @@ static int create_test_area(const char *dir) perror("acl"); return 1; } - if (fsetxattr(fd, "trusted.test", "readonly", strlen("readonly"), XATTR_CREATE) != 0) { - if (errno != EOPNOTSUPP) { - perror("setxattr"); - return 1; - } - } - if (fsetxattr(fd, "user.test", "readonly", strlen("readonly"), XATTR_CREATE) != 0) { - if (errno != EOPNOTSUPP) { - perror("setxattr"); - return 1; - } + if (create_xattrs(fd)) { + return 1; } if (fsetflag(path, fd, 1, 1)) { perror("fsetflag"); @@ -2076,7 +2070,9 @@ static int create_test_area(const char *dir) close(fd); free(path); - asprintf(&path, "%s/empty-immutable.d", dir); + if (create_dir(&path, "%s/empty-immutable.d", dir)) { + return 1; + } if ((fd = open(path, O_RDONLY)) == -1) { fprintf(stderr, "%s: error opening %s: %s\n", __progname, path, strerror(errno)); return 1; @@ -2098,17 +2094,8 @@ static int create_test_area(const char *dir) perror("acl"); return 1; } - if (fsetxattr(fd, "trusted.test", "readonly", strlen("readonly"), XATTR_CREATE) != 0) { - if (errno != EOPNOTSUPP) { - perror("setxattr"); - return 1; - } - } - if (fsetxattr(fd, "user.test", "readonly", strlen("readonly"), XATTR_CREATE) != 0) { - if (errno != EOPNOTSUPP) { - perror("setxattr"); - return 1; - } + if (create_xattrs(fd)) { + return 1; } if (fsetflag(path, fd, 1, 0)) { perror("fsetflag"); @@ -2118,7 +2105,9 @@ static int create_test_area(const char *dir) close(fd); free(path); - asprintf(&path, "%s/empty-append-only.d", dir); + if (create_dir(&path, "%s/empty-append-only.d", dir)) { + return 1; + } if ((fd = open(path, O_RDONLY)) == -1) { fprintf(stderr, "%s: error opening %s: %s\n", __progname, path, strerror(errno)); return 1; @@ -2242,6 +2231,7 @@ int main(int argc, char **argv) { int ret; int failed = 0; + int runtest = 1, create = 0, remove = 0; /* this arg parsing is gross, but who cares, its a test program */ @@ -2251,32 +2241,29 @@ int main(int argc, char **argv) } if (!strcmp(argv[1], "-c")) { - if (argc == 3) { - if ((ret = create_test_area(argv[argc-1]))) - return ret; - } else { - fprintf(stderr, "usage: t_immutable -c test_area_dir\n"); - return 1; - } + create = 1; } else if (!strcmp(argv[1], "-C")) { - if (argc == 3) { - return create_test_area(argv[argc-1]); - } else { - fprintf(stderr, "usage: t_immutable -C test_area_dir\n"); - return 1; - } + /* Prepare test area without running tests */ + create = 1; + runtest = 0; } else if (!strcmp(argv[1], "-r")) { - if (argc == 3) - return remove_test_area(argv[argc-1]); - else { - fprintf(stderr, "usage: t_immutable -r test_area_dir\n"); - return 1; - } - } else if (argc != 2) { - fprintf(stderr, "usage: t_immutable [-c|-r] test_area_dir\n"); + remove = 1; + } + + if (argc != 2 + (create | remove)) { + fprintf(stderr, "usage: t_immutable [-C|-c|-r] test_area_dir\n"); return 1; } + if (create) { + ret = create_test_area(argv[argc-1]); + if (ret || !runtest) { + return ret; + } + } else if (remove) { + return remove_test_area(argv[argc-1]); + } + umask(0000); if (check_test_area(argv[argc-1])) From patchwork Sat Jan 16 16:56:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12024907 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 D6FCCC433E9 for ; Sat, 16 Jan 2021 17:07:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A2D8D22A83 for ; Sat, 16 Jan 2021 17:07:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726917AbhAPRHH (ORCPT ); Sat, 16 Jan 2021 12:07:07 -0500 Received: from mail-ej1-f52.google.com ([209.85.218.52]:42968 "EHLO mail-ej1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727898AbhAPRGu (ORCPT ); Sat, 16 Jan 2021 12:06:50 -0500 Received: by mail-ej1-f52.google.com with SMTP id r12so6420815ejb.9; Sat, 16 Jan 2021 09:06:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f1/Piw45BGbvrGj/usOEnL03jLiIpZV3qUgR6D6ISU4=; b=PT7/sdoOVEcUwjMhV6ajiRNgPe/lCst2tYkK6pkUhea0W8aH+mITsxze3Zw3yzRvAF ONKnHmAf+3ykHqTzEUnlmsAGuivE10MsG2Q5FL5/ACwnZ6y9a8qZAMtxaYsuizxJcayF tGZr/2wCtp++aDxYEW9vRzjv+dTmpbTJvpGaYK4JKg0TeEKzxG9MyXU3UiD78EMUB/Ad msCnQx3rUJHG9XZEdVoDKOVad86WU1v0l11mfJzw/ElP8fN4yDHStIFxs0Jvf8UOjU+L LakOvIfXJISahQweLZLX9VOTCHg0bzpORsFOSw4JC9uxfEd0T8tE91iN0z5PliogG+WA foSQ== 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=f1/Piw45BGbvrGj/usOEnL03jLiIpZV3qUgR6D6ISU4=; b=YQDxRzG30HoQGqBuKNsVOO6zNJMZ1Tl/ZhPSsfaO5m+qs4Yg67UxzSE5TxIWbX8Ju4 c45oGnlhAeel9Ty0RVjgMGuU1WWYl9Mjss7qAAQ8rJdVTTmPEBktxxV8wx90rY16W6CS 3rL0fzKyU8giOcexT9ltnMh1V92IPqjw8HJjIJwfaiF3/1G7mHDpxrjixaTkAU/ew0gw jYxnb3DPCkZltlvStXByzIkpjJGUoLHC/NiaEeXZIg7gFjth4xZK5cfiAxGs/VntDCDY Fr4I+49RHzoh0MmItFue2IoKqhOREZdTfKRAqdXcG0PMyQu3T4ZP6DP3sWTQ3Iudxxa9 cVNg== X-Gm-Message-State: AOAM531bKTn53i++lFh2WLcYX2ITv9OaTNNNMviL8NDup+tY11NN7pUz 54LOCz7Ojcym+fVNA/wwXArOXfkHmVo= X-Google-Smtp-Source: ABdhPJx3cdhgtX9ufv3PK4FCWEFG4ia55xeGf1EThJ+Bgi+gZ1wqoe0OOMgI6CkKnGai3TpJ5rtHPg== X-Received: by 2002:a17:906:660b:: with SMTP id b11mr13584345ejp.458.1610816188073; Sat, 16 Jan 2021 08:56:28 -0800 (PST) Received: from localhost.localdomain ([31.210.181.203]) by smtp.gmail.com with ESMTPSA id zn8sm7061063ejb.39.2021.01.16.08.56.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 08:56:27 -0800 (PST) From: Amir Goldstein To: Eryu Guan Cc: Icenowy Zheng , Chengguang Xu , Xiao Yang , Miklos Szeredi , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH 3/4] src/t_immutable: Allow setting flags on existing files Date: Sat, 16 Jan 2021 18:56:18 +0200 Message-Id: <20210116165619.494265-4-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116165619.494265-1-amir73il@gmail.com> References: <20210116165619.494265-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org For overlayfs tests we need to be able to setflags on existing (lower) files. t_immutable -C test_dir Creates the test area and sets flags, but it also allows setting flags on an existing test area. t_immutable -R test_dir Removes the flags from existing test area, but does not remove the files in the test area. To setup a test area with file without flags, need to run the -C and -R commands. Signed-off-by: Amir Goldstein --- src/t_immutable.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/t_immutable.c b/src/t_immutable.c index b6a76af0..a2e6796d 100644 --- a/src/t_immutable.c +++ b/src/t_immutable.c @@ -1898,6 +1898,8 @@ static int check_test_area(const char *dir) return 0; } +static int allow_existing; + static int create_dir(char **ppath, const char *fmt, const char *dir) { const char *path; @@ -1908,6 +1910,9 @@ static int create_dir(char **ppath, const char *fmt, const char *dir) } path = *ppath; if (stat(path, &st) == 0) { + if (allow_existing && S_ISDIR(st.st_mode)) { + return 0; + } fprintf(stderr, "%s: Test area directory %s must not exist for test area creation.\n", __progname, path); return 1; @@ -1921,6 +1926,7 @@ static int create_dir(char **ppath, const char *fmt, const char *dir) static int create_file(char **ppath, const char *fmt, const char *dir) { + int flags = O_WRONLY|O_CREAT | (allow_existing ? 0 : O_EXCL); const char *path; int fd; @@ -1928,7 +1934,7 @@ static int create_file(char **ppath, const char *fmt, const char *dir) return -1; } path = *ppath; - if ((fd = open(path, O_WRONLY|O_CREAT|O_EXCL, 0666)) == -1) { + if ((fd = open(path, flags, 0666)) == -1) { fprintf(stderr, "%s: error creating file %s: %s\n", __progname, path, strerror(errno)); return -1; } @@ -1937,13 +1943,15 @@ static int create_file(char **ppath, const char *fmt, const char *dir) static int create_xattrs(int fd) { - if (fsetxattr(fd, "trusted.test", "readonly", strlen("readonly"), XATTR_CREATE) != 0) { + int flags = allow_existing ? 0 : XATTR_CREATE; + + if (fsetxattr(fd, "trusted.test", "readonly", strlen("readonly"), flags) != 0) { if (errno != EOPNOTSUPP) { perror("setxattr"); return 1; } } - if (fsetxattr(fd, "user.test", "readonly", strlen("readonly"), XATTR_CREATE) != 0) { + if (fsetxattr(fd, "user.test", "readonly", strlen("readonly"), flags) != 0) { if (errno != EOPNOTSUPP) { perror("setxattr"); return 1; @@ -2214,6 +2222,10 @@ static int remove_test_area(const char *dir) return 1; } + if (allow_existing) { + return 0; + } + pid = fork(); if (!pid) { execl("/bin/rm", "rm", "-rf", dir, NULL); @@ -2236,7 +2248,7 @@ int main(int argc, char **argv) /* this arg parsing is gross, but who cares, its a test program */ if (argc < 2) { - fprintf(stderr, "usage: t_immutable [-C|-c|-r] test_area_dir\n"); + fprintf(stderr, "usage: t_immutable [-C|-c|-R|-r] test_area_dir\n"); return 1; } @@ -2246,18 +2258,24 @@ int main(int argc, char **argv) /* Prepare test area without running tests */ create = 1; runtest = 0; + /* With existing test area, only setflags */ + allow_existing = 1; } else if (!strcmp(argv[1], "-r")) { remove = 1; + } else if (!strcmp(argv[1], "-R")) { + /* Cleanup flags on test area but leave the files */ + remove = 1; + allow_existing = 1; } if (argc != 2 + (create | remove)) { - fprintf(stderr, "usage: t_immutable [-C|-c|-r] test_area_dir\n"); + fprintf(stderr, "usage: t_immutable [-C|-c|-R|-r] test_area_dir\n"); return 1; } if (create) { ret = create_test_area(argv[argc-1]); - if (ret || !runtest) { + if (ret || allow_existing) { return ret; } } else if (remove) { From patchwork Sat Jan 16 16:56:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12024905 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 A27A5C433E6 for ; Sat, 16 Jan 2021 17:07:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7392322A85 for ; Sat, 16 Jan 2021 17:07:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727900AbhAPRGv (ORCPT ); Sat, 16 Jan 2021 12:06:51 -0500 Received: from mail-ed1-f48.google.com ([209.85.208.48]:35688 "EHLO mail-ed1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726751AbhAPRGt (ORCPT ); Sat, 16 Jan 2021 12:06:49 -0500 Received: by mail-ed1-f48.google.com with SMTP id u19so13045906edx.2; Sat, 16 Jan 2021 09:06:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QHFxbDhsnQzHQlBD/5Lv++BjjSF2/FwwLkaS9AAgVE0=; b=qMhGwpj6g5fSCmYrC3IQmlYsOqbFDcIg1nzlFSWEEguSP1+dh+5HQ+xuscifj0nHuY 7floZUe48heX3txjcwdcVyJWmP01tMwB0DDA7qnG5NAH7ZqkSxeIK2Mm1ZRB7gLqHqyE BpmTbxtM68y2+B6f9UK3w/lq2057x23pNr+DvmFqlRcAT9zn8qjMFCRyugfpoSYIqETc AUh0IQdxbmUH6wD9JiT9VHFbNPfSmsaDrrdHIqKbfWqj3BBQVKFppQGj0fXtO18zssyM Z/1RpiXetx0MC1fesNgFuPdyLkuGBfPekywKZ0HqVn8lBJq4VD1FvmMQzWT6Jix43noO /Erw== 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=QHFxbDhsnQzHQlBD/5Lv++BjjSF2/FwwLkaS9AAgVE0=; b=pAhZMkp5ZhRN2kQvBcniKZAr8wNQbeFTHtP8FWa0kMUu+mfvzT9Zhg2I4jZH7wEDuv r9PMOiF6T3Z2DnuvexERK1vbyr65Pfmo1z8PAK+cvx4OPudbC65hk+H/yRpVf0kANSLL rqQ/F+ChB/WoU3M1oZKTGvSSSzYywGtAev0Nn7bfPWQrzCBJpsdN5mPMlEH9XmWjw+PR 6pyylAvUJ5pJG6XzaK5wzMU//daLziicC1pUBPA05VYZbCFwd2d2k1CKTk71lAM2pnNs MW5xRYOVyKZpKVayEJde9ryrJQmns7HVOexG9qpyfGPgKW1zN+SdzGkaRo8Bbeokhy84 IuPg== X-Gm-Message-State: AOAM532AMIQxo963pY0950Byn1x7WcZ/9Bt5y2F3aTgKuqzIhbUFQ6mx 7GzKkh4cy85w9n3PnvD/sHU5V1v8gAg= X-Google-Smtp-Source: ABdhPJzUJ/5G/cNwUqRoAWysskvGblpL/ipitKchnbDmhvyj9vShih8KP6+2wrKjBr6Oaj5jxQtWCg== X-Received: by 2002:a50:fb97:: with SMTP id e23mr14116891edq.208.1610816189674; Sat, 16 Jan 2021 08:56:29 -0800 (PST) Received: from localhost.localdomain ([31.210.181.203]) by smtp.gmail.com with ESMTPSA id zn8sm7061063ejb.39.2021.01.16.08.56.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 08:56:29 -0800 (PST) From: Amir Goldstein To: Eryu Guan Cc: Icenowy Zheng , Chengguang Xu , Xiao Yang , Miklos Szeredi , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH 4/4] overlay: Test lost immutable/append-only flags on copy-up Date: Sat, 16 Jan 2021 18:56:19 +0200 Message-Id: <20210116165619.494265-5-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116165619.494265-1-amir73il@gmail.com> References: <20210116165619.494265-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org Chengguang Xu reported [1] that append-only flag is lost on copy-up. I had noticed that for directories, immutable flag can also be lost on copy up (when parent is copied up). That's an old overlayfs bug. Overlayfs added the ability to set inode flags (e.g. chattr +i) in kernel 5.10 by commit 61536bed2149 ("ovl: support [S|G]ETFLAGS and FS[S|G]ETXATTR ioctls for directories"). Icenowy Zheng reported [2] a regression in that commit that causes a deadlock when setting inode flags on lower dir. There is a commented line in the test that triggers this deadlock, but it has been left commented out until a fix is merged upstream. [1] https://lore.kernel.org/linux-unionfs/20201226104618.239739-1-cgxu519@mykernel.net/ [2] https://lore.kernel.org/linux-unionfs/20210101201230.768653-1-icenowy@aosc.io/ Signed-off-by: Amir Goldstein --- tests/overlay/075 | 97 +++++++++++++++++++++++++++++++++++++++++++ tests/overlay/075.out | 11 +++++ tests/overlay/group | 1 + 3 files changed, 109 insertions(+) create mode 100755 tests/overlay/075 create mode 100644 tests/overlay/075.out diff --git a/tests/overlay/075 b/tests/overlay/075 new file mode 100755 index 00000000..bcdc8d4e --- /dev/null +++ b/tests/overlay/075 @@ -0,0 +1,97 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2021 CTERA Networks. All Rights Reserved. +# +# FS QA Test No. 075 +# +# Run the t_immutable test program for immutable/append-only files +# and directories that exist in overlayfs lower layer. +# +# This test is similar and was derived from generic/079, but instead +# of creating new files which are created in upper layer, prepare +# the test area in lower layer before running the t_immutable test on +# the overlayfs mount. +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +timmutable=$here/src/t_immutable +lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER +upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + # -r will fail to remove test dirs, because we added subdirs + # we just need to remove the flags so use -R + $timmutable -R $upperdir/testdir &> /dev/null + $timmutable -R $lowerdir/testdir &> /dev/null + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +_supported_fs overlay + +_require_chattr iaA +_require_test_program "t_immutable" +_require_scratch + +_scratch_mkfs + +# Preparing test area files in lower dir and check chattr support of base fs +mkdir -p $lowerdir +mkdir -p $upperdir +$timmutable -C $lowerdir/testdir >$tmp.out 2>&1 +if grep -q -e 'Operation not supported' -e "Inappropriate ioctl" $tmp.out; then + _notrun "Setting immutable/append flag not supported" +fi +# Remove the immutable/append-only flags and create subdirs +$timmutable -R $lowerdir/testdir >$tmp.out 2>&1 +for dir in $lowerdir/testdir/*.d; do + mkdir $dir/subdir +done +# Restore the immutable/append-only flags +$timmutable -C $lowerdir/testdir >$tmp.out 2>&1 + +_scratch_mount + +# Test immutability of files in overlay +echo "Before directories copy up" +$timmutable $SCRATCH_MNT/testdir 2>&1 + +# Trigger copy-up of immutable/append-only dirs by touching their subdirs +# inode flags are not copied-up, so immutable/append-only flags are lost +for dir in $SCRATCH_MNT/testdir/*.d; do + # chattr on dir fails (not supported) on kernel < 5.10. + # chattr on lower dir will deadlock on kernel 5.10 with commit 61536bed2149 + # ("ovl: support [S|G]ETFLAGS and FS[S|G]ETXATTR ioctls for directories"), + # so this line is commented out until a fix is merged + # $CHATTR_PROG +A $dir/subdir > /dev/null 2>&1 + touch $dir/subdir +done + +# Trigger copy-up of append-only files by touching them +# inode flags are not copied-up, so append-only flags are lost +# touch on the immutable files is expected to fail, so immutable +# flags will not be lost +for file in $SCRATCH_MNT/testdir/*.f; do + touch $file > /dev/null 2>&1 +done + +# immutable/append-only flags still exist on the overlay in-core inode +# After mount cycle, flags are forever lost +_scratch_cycle_mount + +# Test immutability of files in overlay after directories copy-up +echo "After directories copy up" +$timmutable $SCRATCH_MNT/testdir 2>&1 + +status=$? +exit diff --git a/tests/overlay/075.out b/tests/overlay/075.out new file mode 100644 index 00000000..ab39c6b8 --- /dev/null +++ b/tests/overlay/075.out @@ -0,0 +1,11 @@ +QA output created by 075 +Before directories copy up +testing immutable...PASS. +testing append-only...PASS. +testing immutable as non-root...PASS. +testing append-only as non-root...PASS. +After directories copy up +testing immutable...PASS. +testing append-only...PASS. +testing immutable as non-root...PASS. +testing append-only as non-root...PASS. diff --git a/tests/overlay/group b/tests/overlay/group index 047ea046..cfc75bb1 100644 --- a/tests/overlay/group +++ b/tests/overlay/group @@ -77,6 +77,7 @@ 072 auto quick copyup hardlink 073 auto quick whiteout 074 auto quick exportfs dangerous +075 auto quick perms 100 auto quick union samefs 101 auto quick union nonsamefs 102 auto quick union nonsamefs xino