From patchwork Wed Feb 10 19:03:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12081647 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 CC5F6C433E9 for ; Wed, 10 Feb 2021 19:05:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B09464EEC for ; Wed, 10 Feb 2021 19:05:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233738AbhBJTEs (ORCPT ); Wed, 10 Feb 2021 14:04:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233117AbhBJTEY (ORCPT ); Wed, 10 Feb 2021 14:04:24 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF287C06174A; Wed, 10 Feb 2021 11:03:39 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id p20so6087807ejb.6; Wed, 10 Feb 2021 11:03:39 -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=kx4B9Ki589BDEBvT/0Cd9YL+L1gc2ftBtjc/8QBxF0/4jUEiH9DXo9VbdP5naG/YVj hapoKIvgjXiv9NDuNiX6pygRdpmUBvkwrokRbmVZtt5l4/Obluq+FlEBK9E/3aQZ202d PEdH6sgmAkDbA1MBe6Ud9n1UsrZP3FaaDgQSLlS6dBZ1hVpq17V0XpRDx+ypOm2H4JYv SEhG559raRoF/c79xSarwiz7uUVFsRoEuOiBNiP7DbeginSH60CIn0uvmU5NR9sq2VkU Vqnp33sEhaiK447SXiqi4Pn+QoG1rv7rqOGFf6CGT+kdGpjkDIaiFLm5naBBFIYkLNld VosA== 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=UHypHS1x8H7H6OF1pfuiTW+3yotG9DALrlS4atHX1MyoAZf+8CksO0Xgrc3MhRVihX ZvkhABhlh7sbnpihC1uBzXwCYFRwpScT/RBcL41BRm9+Ec/tUSzwS0Sbp5FPa77vpoXM RaJ3o8cc1MbV4W9rhvdFNOeQFyjWgGK0DE7kiVfB939X6xZsxQefjCB2tyo7v6lABy6e BRyAAMHazMY22yg9bWwaH1gi8M3OiGOwZnqOsxgesfefQkbd7Mcu6NNf76EyKyYO9pd6 C2b9D0Q/7xHBKBn6qHlWFlhdGfGn/jluXv6US2nO25CW5ceRS/tE8hd1WEbv+W+5v4o0 yowg== X-Gm-Message-State: AOAM530sgEwSqA3fR7VxYcyI9f5rIbdQ4+JOxduxXuq+mEbd7IG64wka jU3EvWdvznNnGHxPZPRsVeg= X-Google-Smtp-Source: ABdhPJzdj4MSVefSqkjevM1EVbAUDfpGnSiYCvP7AE7vXXFRBsKLVrimPEeGhI9dccCaDmUPN9CLhw== X-Received: by 2002:a17:907:20f2:: with SMTP id rh18mr4478312ejb.350.1612983818758; Wed, 10 Feb 2021 11:03:38 -0800 (PST) Received: from localhost.localdomain ([141.226.162.179]) by smtp.gmail.com with ESMTPSA id m19sm1743617edq.81.2021.02.10.11.03.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Feb 2021 11:03:38 -0800 (PST) From: Amir Goldstein To: Eryu Guan Cc: Miklos Szeredi , Icenowy Zheng , Chengguang Xu , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v2 1/5] overlay/030: Update comment w.r.t upstream kernel Date: Wed, 10 Feb 2021 21:03:30 +0200 Message-Id: <20210210190334.1212210-2-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210210190334.1212210-1-amir73il@gmail.com> References: <20210210190334.1212210-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 Wed Feb 10 19:03:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12081651 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=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 457C7C43331 for ; Wed, 10 Feb 2021 19:05:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1FE0764E3B for ; Wed, 10 Feb 2021 19:05:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234117AbhBJTEu (ORCPT ); Wed, 10 Feb 2021 14:04:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233955AbhBJTE0 (ORCPT ); Wed, 10 Feb 2021 14:04:26 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6ADA9C061756; Wed, 10 Feb 2021 11:03:41 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id hs11so6126782ejc.1; Wed, 10 Feb 2021 11:03:41 -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=VS579JX6uwPGrlRUjBif6vX6YNZ7KhH/hJO4KN155Jc=; b=JJl4vYE8oUKjEOV11FGzoO/L3Drvvdh6CDJwi2LcFkxE8mgSlCCxJfCm44djdyZlFY PWq1BaZT0uKzysVrjbEHcx5IYyJQX+M8CAY8uf0H3riKZFjxmwhH52Q/Oa+ymQN1Gqyk X2qkXyee9NfCU5s4lVLbKHHRV0rt+suHfzdk2gb+TtFJEvxuNSiNnJ0S+m7as6f8YqZf B8AU8K2Y9WGD2Ih2xkq5+mIlpwCBFpTZnHG96Ex+KrNt4KgpnmTmItlqflrVefq/J2Fn vUpOVmUMFaW+Ke3eQyJqhBH6CdcHqtK5/Q7nkX7Nx/8JzV12Le/b8tuYVe3VhfyBeJ0d uypQ== 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=VS579JX6uwPGrlRUjBif6vX6YNZ7KhH/hJO4KN155Jc=; b=gvrALDSwFsU4tu8n01F7V33aJtWVOCoM1zu24g38a1BfLWbSMX5ZMnHhemsprreCxx 5ZIBQlWrzT5Mrd41AZQtpguoAZ+yevLfhV+/BpCbeZKcWYqPVXLFqw3AEXYtvsBJuHDC j2qpGWPdyMPZriszSAPAk7DHBedKb8olb/NdiP7YincHt2TiwDVOTUogwQpv0LoT744y /Ta/Tc1A0jJm96C+r6LSV40AXts+2KCAzOZOMWLM46Rzm5MOGWO72ViVjeQuQ2YOqlCg fuUs247W4fuBatuPIMMJ6zSdZLQ6sYsm1/TXI6Ss2C+Il5CDjasrsuIYV+ERRrl512oa rEQA== X-Gm-Message-State: AOAM5303Bh63suxNTA5MKy4tS4V+o/q7ZCXcmz9Dnr6U4/Zo1CfkU4vR A0B4gZVS4wuAxzuvtBDViVNEKAJiOjE= X-Google-Smtp-Source: ABdhPJxmXmTrx/FoPuCntGkElbgpcIvGVea9eKpepHEsF/pdsAufw69tcc16fBteyspHrIFOez9eiQ== X-Received: by 2002:a17:906:15ca:: with SMTP id l10mr4271971ejd.402.1612983820152; Wed, 10 Feb 2021 11:03:40 -0800 (PST) Received: from localhost.localdomain ([141.226.162.179]) by smtp.gmail.com with ESMTPSA id m19sm1743617edq.81.2021.02.10.11.03.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Feb 2021 11:03:39 -0800 (PST) From: Amir Goldstein To: Eryu Guan Cc: Miklos Szeredi , Icenowy Zheng , Chengguang Xu , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v2 2/5] src/t_immutable: factor out some helpers Date: Wed, 10 Feb 2021 21:03:31 +0200 Message-Id: <20210210190334.1212210-3-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210210190334.1212210-1-amir73il@gmail.com> References: <20210210190334.1212210-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..7431e75d 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; - } 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)) { + 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)); - return 1; + if (create_dir(&path, "%s/append-only.d/dir", dir)) { + return 1; } 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)); + if ((fd = create_file(&path, "%s/append-only.d/file", dir)) == -1) { return 1; } + close(fd); 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)) { + 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)); - return 1; + if (create_dir(&path, "%s/immutable.d/dir", dir)) { + 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)); + if ((fd = create_file(&path, "%s/immutable.d/file", dir)) == -1) { 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 Wed Feb 10 19:03:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12081649 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=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 87627C43332 for ; Wed, 10 Feb 2021 19:05:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DBA064E70 for ; Wed, 10 Feb 2021 19:05:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233940AbhBJTEt (ORCPT ); Wed, 10 Feb 2021 14:04:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234117AbhBJTEY (ORCPT ); Wed, 10 Feb 2021 14:04:24 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9A59C0613D6; Wed, 10 Feb 2021 11:03:42 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id bl23so6090890ejb.5; Wed, 10 Feb 2021 11:03:42 -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=e81CvUg/4FfNqpB+xmLqCh+M5NuNd+9zjlBJatgTsgU=; b=JJZSWl5aecXBhZZg2ZAZW21dhAW6274UxHjkx1q//J/VNrnKwmyCNDSr4mcQISH5Nx BPBl7WC2EvovjsMS1adKIV2q6QU7ZTvQpZJ36iHd4NT2vKL/iX8MxPBkLwV3EBRHTPlP 7xPug+rQaRM3Ir5gh8hk2ATE4atqZpixWxphP0ivTTVraaVuem5QhjzJNi2ZKwqQwDiI U4cqZcEsiM5Gf5u61OQuO6OhDqwFI3MixVhwp/lS2htA+1OUCE50A9fk+lgldhjUfUEy zuPHRy0Kv4IIxJ0Rjzuzg7KpRt93bSJkLeksrTl4cDhnFmbgzVU0fFd75q/oQDjg3/+U +DdQ== 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=e81CvUg/4FfNqpB+xmLqCh+M5NuNd+9zjlBJatgTsgU=; b=hHr7f06wwTIYr+jXPdv6EwTcJcI4aicTOYlbRQP1EhnN8HZQKkx1l8WFebrPW7TAIM vX7mHIzxs/d+OrOb5Tqzy0T+FpK39RT8CF1YWuJpHpDg8gFw96TtEYqY6yfy+DiyudaO bxJQ1bmowAo08IOlNWScMXa0MycDehcJJbJa8jDu+P2z8SodwBiHO0kbKZYsKQvtWbeY uRDNnLjwG1+nz6JDh2ZjUt57Uim2gI8NzFgIAKwKu+xgmSzPPKkZSTFObgoGP+wdrB37 k2FkcDRR86/OsHziPSFhXgm9RcT9NqQsR2OaavJCPS8paYw3zGWZ1E4lR7hA0akNpk4+ SUDA== X-Gm-Message-State: AOAM533jJpbiMx0mX0cxrEvyJverM5t/BiS8kObDRKI2OxMdPXVSBbCT YZrT6DPbjEeGiuyGciVT9J8= X-Google-Smtp-Source: ABdhPJw4uep2Czs9EWd+OZKQIymdZK7oxSYyeOkEtFro8b5GpK7kE/unfScCJx9QdMOwM918FxjcZA== X-Received: by 2002:a17:906:798:: with SMTP id l24mr4491252ejc.92.1612983821605; Wed, 10 Feb 2021 11:03:41 -0800 (PST) Received: from localhost.localdomain ([141.226.162.179]) by smtp.gmail.com with ESMTPSA id m19sm1743617edq.81.2021.02.10.11.03.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Feb 2021 11:03:41 -0800 (PST) From: Amir Goldstein To: Eryu Guan Cc: Miklos Szeredi , Icenowy Zheng , Chengguang Xu , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v2 3/5] src/t_immutable: Allow setting flags on existing files Date: Wed, 10 Feb 2021 21:03:32 +0200 Message-Id: <20210210190334.1212210-4-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210210190334.1212210-1-amir73il@gmail.com> References: <20210210190334.1212210-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 7431e75d..0611e193 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 || !runtest) { return ret; } } else if (remove) { From patchwork Wed Feb 10 19:03:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12081653 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=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 5CEE6C43331 for ; Wed, 10 Feb 2021 19:05:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DB3B64E77 for ; Wed, 10 Feb 2021 19:05:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233955AbhBJTEx (ORCPT ); Wed, 10 Feb 2021 14:04:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234224AbhBJTE0 (ORCPT ); Wed, 10 Feb 2021 14:04:26 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FEEAC061786; Wed, 10 Feb 2021 11:03:44 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id p20so6088117ejb.6; Wed, 10 Feb 2021 11:03: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=7vQQseBKx2a8Kjbt1q8bbcNuAJE164apTHT1g73Artw=; b=R/uNuGafcduNgOb9+Oh4kSgFbpgfK9fAft8BBDzAOcHsXlmU44MYgowl1Drtp1EsKs TmSRKM0nrEv2yot1+2FrsZVV3WIyG6VwG5vCnJ0nubk8Cgx5r60ZBv3WuS6EVUtlDsI1 YD58TC90WfMAOwyh2VBssUormvXSo80IMZA/qVREkjGMhwh4ofBpTQwc816NSfagiOD8 eGbrw7zlKxtbNI/G36dVu5d4qNguH4P1B7Qacr2nLTeVyKWQD9rqYa/ONnDZ0LVoNEI/ GmpcXSj91AkeFvOr+s4HCy8ChLSc6La2xPfL6JAdWiHyo5YfZ4FZcDQM+5V/qofQEH9y QucA== 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=7vQQseBKx2a8Kjbt1q8bbcNuAJE164apTHT1g73Artw=; b=ZQQQKlDiSTsyLA4mHWVDVaySSkAaq8PK08w+iTs2EWD80NEBo1wQFKF14fmD4law4v B0OdFugAXdsb9fhuboWaEHeuRbUqtVP1r1qdROplGpL7nlHKZHaItmcisIKdPbWCEGI8 W/WfHkE65sXlIK3npj166WdpMxUpiViWB158smB3Zy13fI7yDtNRZHOVI4W8Y6Tcfc98 940wdrcaJI0EKYW6ESOV4ZdRlMKvKkBun04neRYI0tCFIio8poXOlegjLMnNEtybF9bu u0Zv0QsA5pfGi4SS7Ct6PbpEohAxBoGsVhNiO3Jff4ogewk5x2KBk5A239k5ldsGinHX VM6w== X-Gm-Message-State: AOAM531A+0g8EUMMMcwntvZc3Y2C/uw6wj/bDRNDGfEQ4NJkzHv11Lrz O79w4QS6+YN2EN6Vajh/HUo= X-Google-Smtp-Source: ABdhPJzfbgOj7am4rmgfKXPs52pILq5vN5c133TTZK9WcxcM2Fq352aIbdjgjCj6DeinTp3yjG1Fbw== X-Received: by 2002:a17:907:9626:: with SMTP id gb38mr4369492ejc.301.1612983823087; Wed, 10 Feb 2021 11:03:43 -0800 (PST) Received: from localhost.localdomain ([141.226.162.179]) by smtp.gmail.com with ESMTPSA id m19sm1743617edq.81.2021.02.10.11.03.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Feb 2021 11:03:42 -0800 (PST) From: Amir Goldstein To: Eryu Guan Cc: Miklos Szeredi , Icenowy Zheng , Chengguang Xu , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v2 4/5] overlay: Test lost immutable/append-only flags on copy-up Date: Wed, 10 Feb 2021 21:03:33 +0200 Message-Id: <20210210190334.1212210-5-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210210190334.1212210-1-amir73il@gmail.com> References: <20210210190334.1212210-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. [1] https://lore.kernel.org/linux-unionfs/20201226104618.239739-1-cgxu519@mykernel.net/ Signed-off-by: Amir Goldstein --- tests/overlay/075 | 92 +++++++++++++++++++++++++++++++++++++++++++ tests/overlay/075.out | 11 ++++++ tests/overlay/group | 1 + 3 files changed, 104 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..5a6c3be0 --- /dev/null +++ b/tests/overlay/075 @@ -0,0 +1,92 @@ +#! /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 ia +_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 + 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 From patchwork Wed Feb 10 19:03:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12081655 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 1131BC433E0 for ; Wed, 10 Feb 2021 19:05:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E087764E3B for ; Wed, 10 Feb 2021 19:05:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234414AbhBJTFW (ORCPT ); Wed, 10 Feb 2021 14:05:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234345AbhBJTFQ (ORCPT ); Wed, 10 Feb 2021 14:05:16 -0500 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFCE2C061788; Wed, 10 Feb 2021 11:03:45 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id s5so4266490edw.8; Wed, 10 Feb 2021 11:03:45 -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=Zhs8E2as/K5hxOttBuP4bqtfk2cYGV03BLwkm3GAQwA=; b=XtWQoTXW85A7Q5ogJDKkBpsOx+0RR+6rWkKc7PiNktx69vqCc4bZl7MnOkTcahoVae XfyCDiIWhQnjFZWeJIs63RKVGdJ59arvucBhU+YBX2Hz5dzteYwoXzK/jTYUvV4BfrAa tS/UQnHBYeRw1WIj1Bpy+eU24woALKJPeWM4EuQob1JzZYW19PvsxYP0qCQ/t7iqVLKb e8ZG8AF5RRn0WnmkFH2jtVln4G+h6V88nKYeUfZOWfBkLRy+cehlJrSTgE6u4ODh5KnA jEIIbxy3lUfWQ/QGI/ZZ8jckJdOV0RfPrQrVvD7azodnBqUBjaQUiFCYiZkdi8N3ns7r vvgg== 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=Zhs8E2as/K5hxOttBuP4bqtfk2cYGV03BLwkm3GAQwA=; b=Ew0Hnu46YULWW/Gk8/+D3Ra10aPSY49zdMBbNYq7C8WUxZiwmYSxX58usDERvwnn1A GkQpoio19LyAdzh28+vFR3HF4xrK48sUQMixlqb4MKipDxZ59t+y1cbgNLCyAGV8eHQx wNi5UWfkLCsQAKFjOd4b3MJAb4rY+riWehpwiEH+kHSL2W9MH1pM9y5/GAojLZRicm5N gJwu8kJYgltFZlKd6JNbfalgODE4tmvtHTJ5fpSb0w9TslIbs7YRgHRHIm5QIvEpDRqN mFHi2Bxfvz4PspQ0Nr6xnBGmF+BC5wGBxUuRKuGznxlw9w9PEGtGhdBiNl+kK2HYXiTU cSHw== X-Gm-Message-State: AOAM531ccbiZOGOEubbW4rrke7Lyqzv8+iXOQLBColtOSnBuqOKzbSNp PhryiG3YPRl8ZlJSUowA+rWoYZRbNbo= X-Google-Smtp-Source: ABdhPJy2XiNkQrehg5Yd0tTXI4Af2FdHz4yA5d0vA1izNv7B7o6jGwEmu209zyJ4epbtfqA7w/SxSw== X-Received: by 2002:aa7:c94c:: with SMTP id h12mr4696939edt.40.1612983824634; Wed, 10 Feb 2021 11:03:44 -0800 (PST) Received: from localhost.localdomain ([141.226.162.179]) by smtp.gmail.com with ESMTPSA id m19sm1743617edq.81.2021.02.10.11.03.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Feb 2021 11:03:44 -0800 (PST) From: Amir Goldstein To: Eryu Guan Cc: Miklos Szeredi , Icenowy Zheng , Chengguang Xu , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v2 5/5] overlay: Regression test for deadlock on directory ioctl Date: Wed, 10 Feb 2021 21:03:34 +0200 Message-Id: <20210210190334.1212210-6-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210210190334.1212210-1-amir73il@gmail.com> References: <20210210190334.1212210-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org 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 [1] a regression in that commit that causes a deadlock when setting inode flags on lower dir. The regression was fixed by commit b854cc659dcb ("ovl: avoid deadlock on directory ioctl") and applied to kernel 5.10.15. [1] https://lore.kernel.org/linux-unionfs/20210101201230.768653-1-icenowy@aosc.io/ Signed-off-by: Amir Goldstein --- tests/overlay/076 | 66 +++++++++++++++++++++++++++++++++++++++++++ tests/overlay/076.out | 2 ++ tests/overlay/group | 1 + 3 files changed, 69 insertions(+) create mode 100644 tests/overlay/076 create mode 100644 tests/overlay/076.out diff --git a/tests/overlay/076 b/tests/overlay/076 new file mode 100644 index 00000000..07827c0b --- /dev/null +++ b/tests/overlay/076 @@ -0,0 +1,66 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2021 CTERA Networks. All Rights Reserved. +# +# FS QA Test 076 +# +# Support for chattr on overlayfs directories was added in kernel v5.10 +# by commit 61536bed2149 ("ovl: support [S|G]ETFLAGS and FS[S|G]ETXATTR +# ioctls for directories"). That commit introduced a deadlock. +# +# This is a regression test for the fix commit b854cc659dcb ("ovl: avoid +# deadlock on directory ioctl") +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + $CHATTR_PROG -i $lowerdir/foo > /dev/null 2>&1 + $CHATTR_PROG -i $upperdir/foo > /dev/null 2>&1 + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs overlay +_require_scratch +_require_chattr i + +# remove all files from previous runs +_scratch_mkfs + +# prepare lower test file +lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER +upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER +workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK +mkdir -p $lowerdir +mkdir $lowerdir/foo + +# mounting overlay +_scratch_mount + +# Try to add the immutable attributes, it will invoke ioctl() on the directory +# The ioctl will fail on kernel < 5.10, succeed on kernel >= 5.10.15 and hang +# on kernel v5.10..v5.10.14. Anything but hang is considered a test success. +$CHATTR_PROG +i $SCRATCH_MNT/foo > /dev/null 2>&1 + +$UMOUNT_PROG $SCRATCH_MNT + +# success, all done +echo "Silence is golden" +status=0 +exit diff --git a/tests/overlay/076.out b/tests/overlay/076.out new file mode 100644 index 00000000..248e095d --- /dev/null +++ b/tests/overlay/076.out @@ -0,0 +1,2 @@ +QA output created by 076 +Silence is golden diff --git a/tests/overlay/group b/tests/overlay/group index cfc75bb1..ddc355e5 100644 --- a/tests/overlay/group +++ b/tests/overlay/group @@ -78,6 +78,7 @@ 073 auto quick whiteout 074 auto quick exportfs dangerous 075 auto quick perms +076 auto quick perms dangerous 100 auto quick union samefs 101 auto quick union nonsamefs 102 auto quick union nonsamefs xino