From patchwork Sun Apr 25 07:14:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12223021 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.7 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 DC007C43462 for ; Sun, 25 Apr 2021 07:14:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B8C2B613C2 for ; Sun, 25 Apr 2021 07:14:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230179AbhDYHPb (ORCPT ); Sun, 25 Apr 2021 03:15:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230194AbhDYHPa (ORCPT ); Sun, 25 Apr 2021 03:15:30 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08E20C061756; Sun, 25 Apr 2021 00:14:50 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id s7so52476039wru.6; Sun, 25 Apr 2021 00:14:49 -0700 (PDT) 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=55sVTQrFfGEhu0JHBA9CDTtF22kDefd1VZe71y3fPL8=; b=RXISvwUQR2zyFwKuwi/M6vAZW83b/J8XAdwmPRQt9up9tJB3n93unot/SnGphs3aup qr8N/PhpP5TaOKuXcNLfNrYM+tjghP28+mbmVrchckCXWoaq4qr61SZfdUhdRpRn7KLx Ae62Q20vfvMvKSMjqsNbdUJlmooS4vOTjquRF7kwKIdknUafa3Y6lgcRsV5aRBoXeQ03 V7EWj7w1CrqNfXoX4EpBdZcnBh9FVdIc+Mo12PzUdcphNEAdp03u/mNstmYXxWoTioOx yKNJabeHG88ltqJWmynZR9KXmm7l5aySMUSC50/PVdJIt7An3NeEa5Q9DcSS7+lt2leD GwPg== 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=55sVTQrFfGEhu0JHBA9CDTtF22kDefd1VZe71y3fPL8=; b=fQ7UbIGOGCjD4o3YiNTZRp8G7KoVuMqWyaAz09UoPuhFoSsTILNMoJdz7490dZdH8t d63Wtta52ThLQOsYiowgXrUmVPzm5KnQUDiovTHi+LX6hfQQuma5INE3ssNwZggMYzpB SoSqcp6ZfgMO3WxDgi0ES51fN727SSshRz6JCwsJeH91qbCEu1ZNGQdpOKnMKUf9Qz1u 0Thh/TJHm/tzVsoKP5IS7ohOezwoGp8DdR05f+3QeBtL08QcJe8rzc26RySIMrVJct+X KHGMSiEOfEHzEWp8W0zqNQcrHIgU38l83OpBQcTBvfglNVtxOYurop+RUEJkYXe/WhIh bmNg== X-Gm-Message-State: AOAM531lZ432ZOvIWP9BwAFda2kSM1DWwX+180UaPAxIzaWzZmx3Rk7E tlYBWKj018G1npyTahbS0FNwzohmiYc= X-Google-Smtp-Source: ABdhPJyqp61GnK0ZFDazcr/BYfBkasMS/UJOKDNbHfL2h4i2QCQRJBeU+Yo5wfJp4zy0zNI67Qep9Q== X-Received: by 2002:a5d:4acf:: with SMTP id y15mr15213796wrs.245.1619334888770; Sun, 25 Apr 2021 00:14:48 -0700 (PDT) Received: from localhost.localdomain ([82.114.44.37]) by smtp.gmail.com with ESMTPSA id x189sm15885626wmg.17.2021.04.25.00.14.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Apr 2021 00:14:48 -0700 (PDT) From: Amir Goldstein To: Eryu Guan Cc: Miklos Szeredi , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v2 1/5] src/t_dir_offset2: Add an option to limit of buffer size Date: Sun, 25 Apr 2021 10:14:41 +0300 Message-Id: <20210425071445.29547-2-amir73il@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210425071445.29547-1-amir73il@gmail.com> References: <20210425071445.29547-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org Will be used to force readdir in several getdents calls. Signed-off-by: Amir Goldstein --- src/t_dir_offset2.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/t_dir_offset2.c b/src/t_dir_offset2.c index 5a6d7193..7aeb990e 100644 --- a/src/t_dir_offset2.c +++ b/src/t_dir_offset2.c @@ -30,16 +30,32 @@ struct linux_dirent64 { static uint64_t d_off_history[HISTORY_LEN]; static uint64_t d_ino_history[HISTORY_LEN]; -int -main(int argc, char *argv[]) +void usage() { - int fd, nread; + fprintf(stderr, "usage: t_dir_offset2: [bufsize]\n"); + exit(EXIT_FAILURE); +} + +int main(int argc, char *argv[]) +{ + int fd; char buf[BUF_SIZE]; + int nread, bufsize = BUF_SIZE; struct linux_dirent64 *d; int bpos, total, i; off_t lret; int retval = EXIT_SUCCESS; + if (argc > 2) { + bufsize = atoi(argv[2]); + if (!bufsize) + usage(); + if (bufsize > BUF_SIZE) + bufsize = BUF_SIZE; + } else if (argc < 2) { + usage(); + } + fd = open(argv[1], O_RDONLY | O_DIRECTORY); if (fd < 0) { perror("open"); @@ -48,7 +64,7 @@ main(int argc, char *argv[]) total = 0; for ( ; ; ) { - nread = syscall(SYS_getdents64, fd, buf, BUF_SIZE); + nread = syscall(SYS_getdents64, fd, buf, bufsize); if (nread == -1) { perror("getdents"); exit(EXIT_FAILURE); @@ -89,7 +105,7 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } - nread = syscall(SYS_getdents64, fd, buf, BUF_SIZE); + nread = syscall(SYS_getdents64, fd, buf, bufsize); if (nread == -1) { perror("getdents"); exit(EXIT_FAILURE); From patchwork Sun Apr 25 07:14:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12223019 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.7 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 4AFEEC43461 for ; Sun, 25 Apr 2021 07:14:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3039961492 for ; Sun, 25 Apr 2021 07:14:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230197AbhDYHPa (ORCPT ); Sun, 25 Apr 2021 03:15:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230179AbhDYHPa (ORCPT ); Sun, 25 Apr 2021 03:15:30 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26B0AC061574; Sun, 25 Apr 2021 00:14:51 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id y204so26842987wmg.2; Sun, 25 Apr 2021 00:14:51 -0700 (PDT) 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=wwvJ0SUYHs2mHq+f1YwLTGzVZoArfQUCHwJFLhi7+IA=; b=jfSbPtrYWhQmEMRiu5CHowhSGE2vwnv0EAafpYdJ+s4Jvc+/zhgfRpUwebqQl1vlvI LbP2Ykl6ZwpAzXgqdigyBE7EzxvWflY9p035lwk9HEOH5QBF01DEFMhArC3wvqVBg3Tp dy9EpODOSZrDIpewl2FII9JPsdDl0pVpm7bYa2TAVglJ1R2syqIU/LoEiRg4gApW/AB1 lo361a6JF47EuC/Hz5h4jZdS7Y72a4AgWjCCwOvDO/KpxEeRup9SKwWP6BsG2GVlIQIM kL4Vb98FloguB9a4RW8c2+DKdhXJBRS372BB053V2Qxj3u9L/bRijjp5E2cLys48hYWU lyDw== 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=wwvJ0SUYHs2mHq+f1YwLTGzVZoArfQUCHwJFLhi7+IA=; b=lQJGnTY+On/5+alclF0vEAw0g4iy1f0F6jYiKgtUWJnIHJJCTOPNBVtiF5LndJWE10 be3GgdOFGt5fkSTkeVQFHkB4YGnCgEN2Ou4JPGpuk79a4aq+MI84ppmBaAyuOTcUCU3v XDm1kz+7mrZ5QQAbcavVsGlAwFXsMj4asKn+ErYCSo+egfmcoxsdPpmar7huWcCUYPNC wAbFYAxB9uvl7Y1hFqhFzC//apgdzTivLrVT1tRBZOwq3jneH6M81OWvoyvNFrsA+i71 JF5uY30pD6W++SfkUt8crWl/p6zUEBZOI8R9I6KbnaEal/px0ksyv69IcB7N2DqeGqZ2 rz9w== X-Gm-Message-State: AOAM531Rt155yuLFBz6tjwQSZxcoP5lEb2dIp1AZtpYmAPVD3MOzBHEm OgxjV3a5TvoFZnvnPE8NHRzEFZp2jlQ= X-Google-Smtp-Source: ABdhPJxxAQb4nATQOnofXWHfmEoMTfNjZhxmT/Y8kU5v6dxRbP99joNpd+VGmC9kY3w8zb/RgS1oQQ== X-Received: by 2002:a7b:c206:: with SMTP id x6mr2463386wmi.72.1619334889939; Sun, 25 Apr 2021 00:14:49 -0700 (PDT) Received: from localhost.localdomain ([82.114.44.37]) by smtp.gmail.com with ESMTPSA id x189sm15885626wmg.17.2021.04.25.00.14.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Apr 2021 00:14:49 -0700 (PDT) From: Amir Goldstein To: Eryu Guan Cc: Miklos Szeredi , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v2 2/5] src/t_dir_offset2: Add an option to find file by name Date: Sun, 25 Apr 2021 10:14:42 +0300 Message-Id: <20210425071445.29547-3-amir73il@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210425071445.29547-1-amir73il@gmail.com> References: <20210425071445.29547-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org Will be used to check for missing/stale entries. Signed-off-by: Amir Goldstein --- src/t_dir_offset2.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/t_dir_offset2.c b/src/t_dir_offset2.c index 7aeb990e..7af24519 100644 --- a/src/t_dir_offset2.c +++ b/src/t_dir_offset2.c @@ -8,11 +8,13 @@ * that these offsets are seekable to entry with the right inode. */ +#include #include #include #include #include #include +#include #include #include @@ -32,7 +34,7 @@ static uint64_t d_ino_history[HISTORY_LEN]; void usage() { - fprintf(stderr, "usage: t_dir_offset2: [bufsize]\n"); + fprintf(stderr, "usage: t_dir_offset2: [[bufsize] [-v]]\n"); exit(EXIT_FAILURE); } @@ -45,6 +47,9 @@ int main(int argc, char *argv[]) int bpos, total, i; off_t lret; int retval = EXIT_SUCCESS; + const char *filename = NULL; + int exists = 0, found = 0; + int verbose = 0; if (argc > 2) { bufsize = atoi(argv[2]); @@ -52,6 +57,12 @@ int main(int argc, char *argv[]) usage(); if (bufsize > BUF_SIZE) bufsize = BUF_SIZE; + + if (argc > 3) { + filename = argv[3]; + if (argc > 4 && !strcmp(argv[4], "-v")) + verbose = 1; + } } else if (argc < 2) { usage(); } @@ -62,6 +73,14 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } + if (filename) { + exists = !faccessat(fd, filename, F_OK, AT_SYMLINK_NOFOLLOW); + if (!exists && errno != ENOENT) { + perror("faccessat"); + exit(EXIT_FAILURE); + } + } + total = 0; for ( ; ; ) { nread = syscall(SYS_getdents64, fd, buf, bufsize); @@ -91,10 +110,28 @@ int main(int argc, char *argv[]) } d_off_history[total] = d->d_off; d_ino_history[total] = d->d_ino; + if (filename) { + if (verbose) + printf("entry #%d: %s (d_ino=%lld, d_off=%lld)\n", + i, d->d_name, (long long int)d->d_ino, + (long long int)d->d_off); + if (!strcmp(filename, d->d_name)) + found = 1; + } bpos += d->d_reclen; } } + if (filename) { + if (exists == found) { + printf("entry %s %sfound as expected\n", filename, found ? "" : "not "); + } else { + fprintf(stderr, "%s entry %s\n", + exists ? "missing" : "stale", filename); + exit(EXIT_FAILURE); + } + } + /* check if seek works correctly */ d = (struct linux_dirent64 *)buf; for (i = total - 1; i >= 0; i--) From patchwork Sun Apr 25 07:14:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12223023 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.7 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 DF4CBC433ED for ; Sun, 25 Apr 2021 07:14:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4492610A1 for ; Sun, 25 Apr 2021 07:14:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230200AbhDYHPd (ORCPT ); Sun, 25 Apr 2021 03:15:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229825AbhDYHPd (ORCPT ); Sun, 25 Apr 2021 03:15:33 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58E23C061574; Sun, 25 Apr 2021 00:14:52 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id f195-20020a1c1fcc0000b029012eb88126d7so3374927wmf.3; Sun, 25 Apr 2021 00:14:52 -0700 (PDT) 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=FIlIiRJSjRiunFMuHCtAG6p9TvlZTNyPYb6XoxHnjlA=; b=R+plW7xFxDzBBuf8BB7sPlx17x6/EKFMCoc5EtmZHwTIqLl7t4cx3tm9IC8keTMFI1 Tf1znqfnVwmS14Ta6UkeI1fc8ZaCIdzAIxXM/uAQIWleCJp9ZArGS9UmOrzMmrppxpvm gEdaVmMvlEMzlNzZqhqkP4PHQtQEy6rH9fBoQEel+6BEn+lHSVdVjsrWSdE8hJZWu+Qf rutm4lUW7Mg0tPp/yccJCYR2C3Pp2z28NHCaj8J6IwvRFEZ4TAeJnVlNLJMETpJYkpUg rUKhQ9oVgVUAaIM/9VICzR8E5Vxy55ZQLdrMaz8CWOHK4GtjLg45J6DynJ5V9bse/Bgv j/tA== 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=FIlIiRJSjRiunFMuHCtAG6p9TvlZTNyPYb6XoxHnjlA=; b=DMoeqh+5c/mbxj+84XHX7S/q4ijErCjLi/Hb9IPm6tfyqt5A6cTnQM3ny2xRkM6qiN FVi6u+3HLMZtAlPrE0Z/x0CdFpYwPsFNveRSAABoz0EHF+7qN/LV6CLpAmKtE8aHjQTw qhJtzRdYFxN3JXewBNXOn1is9ws2fsnCainNfgl0m/lTOrBhXTgwzy2w4/A7tbmi0Zhk ZbcynxlKlB8x3bgdgF6kGHiFNnSCniQkb3K3arwnXafrPFoixLkzJqWfmFiHFtwqJk1i rFjaY/YE8M20L5m+xU/RKgbFwSUa0gVD7u2YY6ExXL+zVayeJyHVxjHHBVY/wUUFwObl z2+w== X-Gm-Message-State: AOAM533RrzVoormp6yIB/kSw3LYm3Pgc/Ges0PXSYTZPfotpkP07wJB0 EW/9HyJmbNowZfFS3P6pd8Q= X-Google-Smtp-Source: ABdhPJzgeu0uyEZ4/Gv8piZpW/A9Sn7zHDyGIGGXcDVXUCkQYLP8Tzw9vtEUJ2/K1EyxcLhcm1vkxw== X-Received: by 2002:a1c:64c4:: with SMTP id y187mr14203210wmb.162.1619334891092; Sun, 25 Apr 2021 00:14:51 -0700 (PDT) Received: from localhost.localdomain ([82.114.44.37]) by smtp.gmail.com with ESMTPSA id x189sm15885626wmg.17.2021.04.25.00.14.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Apr 2021 00:14:50 -0700 (PDT) From: Amir Goldstein To: Eryu Guan Cc: Miklos Szeredi , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v2 3/5] src/t_dir_offset2: Add option to create or unlink file Date: Sun, 25 Apr 2021 10:14:43 +0300 Message-Id: <20210425071445.29547-4-amir73il@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210425071445.29547-1-amir73il@gmail.com> References: <20210425071445.29547-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org Will be used to test missing/stale entries after modifications to an open dirfd. Signed-off-by: Amir Goldstein --- src/t_dir_offset2.c | 56 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/src/t_dir_offset2.c b/src/t_dir_offset2.c index 7af24519..75b41c1a 100644 --- a/src/t_dir_offset2.c +++ b/src/t_dir_offset2.c @@ -34,13 +34,13 @@ static uint64_t d_ino_history[HISTORY_LEN]; void usage() { - fprintf(stderr, "usage: t_dir_offset2: [[bufsize] [-v]]\n"); + fprintf(stderr, "usage: t_dir_offset2: [[bufsize] [-|+] [-v]]\n"); exit(EXIT_FAILURE); } int main(int argc, char *argv[]) { - int fd; + int fd, fd2 = -1; char buf[BUF_SIZE]; int nread, bufsize = BUF_SIZE; struct linux_dirent64 *d; @@ -49,7 +49,7 @@ int main(int argc, char *argv[]) int retval = EXIT_SUCCESS; const char *filename = NULL; int exists = 0, found = 0; - int verbose = 0; + int modify = 0, verbose = 0; if (argc > 2) { bufsize = atoi(argv[2]); @@ -60,6 +60,13 @@ int main(int argc, char *argv[]) if (argc > 3) { filename = argv[3]; + /* + creates, - removes */ + if (filename[0] == '+') + modify = 1; + else if (filename[0] == '-') + modify = -1; + if (modify) + filename++; if (argc > 4 && !strcmp(argv[4], "-v")) verbose = 1; } @@ -89,6 +96,49 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } + if (modify && fd2 < 0 && total == 0) { + printf("getdents at offset 0 returned %d bytes\n", nread); + + /* create/unlink entry after first getdents */ + if (modify > 0) { + if (openat(fd, filename, O_CREAT, 0600) < 0) { + perror("openat"); + exit(EXIT_FAILURE); + } + exists = 1; + printf("created entry %s\n", filename); + } else if (modify < 0) { + if (unlinkat(fd, filename, 0) < 0) { + perror("unlinkat"); + exit(EXIT_FAILURE); + } + exists = 0; + printf("unlinked entry %s\n", filename); + } + + /* + * Old fd may not return new entry and may return stale + * entries which is allowed. Keep old fd open and open + * a new fd to check for stale or missing entries later. + */ + fd2 = open(argv[1], O_RDONLY | O_DIRECTORY); + if (fd2 < 0) { + perror("open fd2"); + exit(EXIT_FAILURE); + } + } + + if (nread == 0) { + if (fd2 < 0 || fd == fd2) + break; + + /* Re-iterate with new fd leaving old fd open */ + fd = fd2; + total = 0; + found = 0; + continue; + } + if (nread == 0) break; From patchwork Sun Apr 25 07:14:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12223025 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.7 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 2C562C43462 for ; Sun, 25 Apr 2021 07:14:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D7D961494 for ; Sun, 25 Apr 2021 07:14:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230208AbhDYHPe (ORCPT ); Sun, 25 Apr 2021 03:15:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229825AbhDYHPe (ORCPT ); Sun, 25 Apr 2021 03:15:34 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CABE4C061756; Sun, 25 Apr 2021 00:14:53 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id e5so23903334wrg.7; Sun, 25 Apr 2021 00:14:53 -0700 (PDT) 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=S2iJdrFUBFYZMKDHDAlnw9LDDh8hRAveUSxMiqeVjXQ=; b=WORP8m33oIiU7UYyKj7+iwGS9TMNqqkbN45xyef1LNyt+dR6A65Y5zXufdlQea6VQ3 jCrMpnmNVgzfT4m8Tl0my3/+ahMm1H1X5KRT7z2o5ZCF30JhCAB+ouDq2jqpuMMHqqpN dHok1HkWtQkRkVd7TnUEfwt8aCQkYWTlxdOnul7bvH/8kGNaJsPTh8UYv7guZbrv47Mp TKUPrL/suHQQMwPqFBb5IuPrtNK+qJNj1nDqCLzZ8XdaUQ72DGVnWYQaC1W1CwXtanVG OmmftHCluroMJiQ+Jc9Ojc724MN47/hwgO/w6+EYhXtAAP/6ZNywYldpL9jCQt1XiVTk kSdg== 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=S2iJdrFUBFYZMKDHDAlnw9LDDh8hRAveUSxMiqeVjXQ=; b=ZqtK4ar1aDZlmXXj6vaVL3vCDPUzh3HXA2FNIGc+mxZUjIfear1BQqGkjONO8/Lca6 tHeXWvdxQsBok5hu/copn6xnmAy69HiEUQKyPQqdIdnQyxEQl+qimyMkBQVgR4R0t4KF H+hpZGbA1pEgsvvqwVBU/TCOUqfpo9QmvdmTmBfk/qG/JaZ356wtTlctsRr+EwjoFOSq 7dOGWyyTQNi/QPviHOlct8yRddJF+Hk8HSm+PKe/JxMuK9xOJOqmCrQH5bOsnTXV9HFU twWoTZEdp2dtXAdzZ51/5ZXuWlpH/ippwuCsaVJjMe11DOTUr3UebSTZSPqg9HUgv6hL 7Zqw== X-Gm-Message-State: AOAM5320TLSkBbG8Xic2/47tL3UYtVlgUoD2nCvli1hHT5orLCyYt02F 5oQB9b0STdG5p+Nj0hC/7vo= X-Google-Smtp-Source: ABdhPJxzvZPSkbFmULhqQ50YcWT/9AqHz15M9XpKK5ROhd5TpZwja+rSQfraJFfIy5FSwypfpQAFhQ== X-Received: by 2002:adf:a119:: with SMTP id o25mr15104991wro.36.1619334892544; Sun, 25 Apr 2021 00:14:52 -0700 (PDT) Received: from localhost.localdomain ([82.114.44.37]) by smtp.gmail.com with ESMTPSA id x189sm15885626wmg.17.2021.04.25.00.14.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Apr 2021 00:14:51 -0700 (PDT) From: Amir Goldstein To: Eryu Guan Cc: Miklos Szeredi , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v2 4/5] generic: Test readdir of modified directrory Date: Sun, 25 Apr 2021 10:14:44 +0300 Message-Id: <20210425071445.29547-5-amir73il@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210425071445.29547-1-amir73il@gmail.com> References: <20210425071445.29547-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org Check that directory modifications to an open dir fd are observed by a new open fd. Signed-off-by: Amir Goldstein --- tests/generic/700 | 62 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/700.out | 2 ++ tests/generic/group | 1 + 3 files changed, 65 insertions(+) create mode 100755 tests/generic/700 create mode 100644 tests/generic/700.out diff --git a/tests/generic/700 b/tests/generic/700 new file mode 100755 index 00000000..3ece88d4 --- /dev/null +++ b/tests/generic/700 @@ -0,0 +1,62 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2021 CTERA Networks. All Rights Reserved. +# +# Check that directory modifications to an open dir are observed +# by a new open fd +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{ + cd / + rm -f $tmp.* +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# real QA test starts here +_supported_fs generic +_require_test + +rm -f $seqres.full + +testdir=$TEST_DIR/test-$seq +rm -rf $testdir +mkdir $testdir + +# Use small getdents bufsize to fit less than 10 entries +# stuct linux_dirent64 is 20 bytes not including d_name +bufsize=200 + +# Check readdir content of an empty dir changes when adding a new file +echo -e "\nCreate file 0 in an open dir:" >> $seqres.full +$here/src/t_dir_offset2 $testdir $bufsize "+0" 2>&1 >> $seqres.full || \ + echo "Missing created file in open dir (see $seqres.full for details)" + +# Create enough files to be returned in multiple gendents() calls. +# At least one of the files that we delete will not be listed in the +# first call, so we may encounter stale entries in following calls. +for n in {1..100}; do + touch $testdir/$n +done + +# Check readdir content changes after removing files +for n in {1..10}; do + echo -e "\nRemove file ${n}0 in an open dir:" >> $seqres.full + $here/src/t_dir_offset2 $testdir $bufsize "-${n}0" 2>&1 >> $seqres.full || \ + echo "Found unlinked files in open dir (see $seqres.full for details)" +done + +# success, all done +echo "Silence is golden" +status=0 diff --git a/tests/generic/700.out b/tests/generic/700.out new file mode 100644 index 00000000..f9acaa71 --- /dev/null +++ b/tests/generic/700.out @@ -0,0 +1,2 @@ +QA output created by 700 +Silence is golden diff --git a/tests/generic/group b/tests/generic/group index ab00cc04..bac5aa48 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -634,3 +634,4 @@ 629 auto quick rw copy_range 630 auto quick rw dedupe clone 631 auto rw overlay rename +700 auto quick dir From patchwork Sun Apr 25 07:14:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12223027 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.7 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 1FB4BC433ED for ; Sun, 25 Apr 2021 07:14:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06BFF610A1 for ; Sun, 25 Apr 2021 07:14:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230217AbhDYHPg (ORCPT ); Sun, 25 Apr 2021 03:15:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229825AbhDYHPf (ORCPT ); Sun, 25 Apr 2021 03:15:35 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ED1CC061574; Sun, 25 Apr 2021 00:14:55 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id e5so23903348wrg.7; Sun, 25 Apr 2021 00:14:54 -0700 (PDT) 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=vY9pa33hAaQweAU2f1GgzuYkEAL50qzPDAnuDVOks2k=; b=lzAgTVcYw0/kYHhA8bfSI1fg+6a8NNraagklwbCrZtf/Uh76TaHbx0BSAJijI4TvkQ iBChb+d4D5mBtnLWWSdl5XwvdNmwQeJF9zQaNuJTu6LYgHhoxOAbSytiB7yQKjALAmLe 51Rc7rssXJ5YtyiyD0DWrJUXvmdbIPUzoTrsGcuHyNX1+QW26a8YUPqy8RyOpchiVheg C3P0g9NRFCghlS1FfxMppwSnCaaR55sJUxRN+ewWQ7b3i5Zo9bm12ADx/Vy4EUrhvW5A 9R8JukhCdwqmUDTVUUI69FY49Iz90BVISRuKgpXWCTBQ8rHSVGXXxbFuk9E7rOKR/VNE 8n4w== 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=vY9pa33hAaQweAU2f1GgzuYkEAL50qzPDAnuDVOks2k=; b=ki6wSXywQQ2GP+2kDN2Tnp9pimK/ShAXKvp07CLyQVj1UYxPSDJ41WEa9PHpr7czIz gH3zVOFKFD40WvsvGZ7IXrKyc5PkqcPUUOmzlMK9DBCBW1vLksfncW6i0LT9PPFl2kIp oEGX14W9NmZ6m4/uyMpLWTr/pZtlkVZ8badMxZJFI4MSIiC50qUMNsBDbiiGrBe87vIh hjRnSMCeUuswehOO7tJb0ms53mcvPG0J3hiayzgC/7W/9olHdi+sEVJSGy8bcLzPRPxS LzGqi1zSJ18cB4ZQGKIXzwe/L/JrwW+z4eEFfNBHPaZrforMyUcQ4DIws7NgUhiE3EMD pb5Q== X-Gm-Message-State: AOAM531gU2lLS8VEyx/73LQFyxRaJtKgiqnfVEGXwMQgpnJ+mcANHPKR 6yhenG5n9ct+TN0/aQeT/t0= X-Google-Smtp-Source: ABdhPJxNys0eQFuCgpM13ZoxtfVVriem1NNgKwxBtOGQfBtnK/SajBdprNA6wB3P5KqDjUiei5Kqzw== X-Received: by 2002:a5d:5745:: with SMTP id q5mr2110842wrw.250.1619334893804; Sun, 25 Apr 2021 00:14:53 -0700 (PDT) Received: from localhost.localdomain ([82.114.44.37]) by smtp.gmail.com with ESMTPSA id x189sm15885626wmg.17.2021.04.25.00.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Apr 2021 00:14:53 -0700 (PDT) From: Amir Goldstein To: Eryu Guan Cc: Miklos Szeredi , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v2 5/5] overlay: Test invalidate of readdir cache Date: Sun, 25 Apr 2021 10:14:45 +0300 Message-Id: <20210425071445.29547-6-amir73il@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210425071445.29547-1-amir73il@gmail.com> References: <20210425071445.29547-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org This is a regression test for kernel commit 65cd913ec9d9 ("ovl: invalidate readdir cache on changes to dir with origin") Signed-off-by: Amir Goldstein --- tests/overlay/077 | 117 ++++++++++++++++++++++++++++++++++++++++++ tests/overlay/077.out | 2 + tests/overlay/group | 1 + 3 files changed, 120 insertions(+) create mode 100755 tests/overlay/077 create mode 100644 tests/overlay/077.out diff --git a/tests/overlay/077 b/tests/overlay/077 new file mode 100755 index 00000000..58c0f3b5 --- /dev/null +++ b/tests/overlay/077 @@ -0,0 +1,117 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2021 CTERA Networks. All Rights Reserved. +# +# FS QA Test 077 +# +# Test invalidate of readdir cache +# +# This is a regression test for kernel commit 65cd913ec9d9 +# ("ovl: invalidate readdir cache on changes to dir with origin") +# +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 / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +rm -f $seqres.full + +# real QA test starts here +_supported_fs overlay +_require_scratch_nocheck + +# Use small getdents bufsize to fit less than 10 entries +# stuct linux_dirent64 is 20 bytes not including d_name +bufsize=200 + +# Create enough files to be returned in multiple gendents() calls. +# At least one of the files that we delete will not be listed in the +# first call, so we may encounter stale entries in following calls. +create_files() { + for n in {1..100}; do + touch ${1}/${2}${n} + done +} + +# remove all files from previous runs +_scratch_mkfs + +# Create test area with a merge dir, a "former" merge dir, +# a pure upper dir and impure upper dir. For each case, overlayfs +# readdir cache is used a bit differently. +lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER +upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER + +mkdir -p $lowerdir/merge $lowerdir/former $upperdir/pure $upperdir/impure +# Lower files in merge dir are listed first +create_files $lowerdir/merge m +# Files to be moved into impure upper dir +create_files $lowerdir o +# File to be copied up to make former merge dir impure +touch $lowerdir/former/f100 + +_scratch_mount + +create_files $SCRATCH_MNT/pure p +create_files $SCRATCH_MNT/former f +# Copy up file so readdir will need to lookup its origin d_ino +touch $SCRATCH_MNT/merge/m100 +# Move copied up files so readdir will need to lookup origin d_ino +mv $SCRATCH_MNT/o* $SCRATCH_MNT/impure/ + +# Remove the lower directory and mount overlay again to create +# a "former merge dir" +$UMOUNT_PROG $SCRATCH_MNT +rm -rf $lowerdir/former +_scratch_mount + +# Check readdir cache invalidate on pure upper dir +echo -e "\nCreate file in pure upper dir:" >> $seqres.full +$here/src/t_dir_offset2 $SCRATCH_MNT/pure $bufsize "+p0" 2>&1 >> $seqres.full || \ + echo "Missing created file in pure upper dir (see $seqres.full for details)" +echo -e "\nRemove file in pure upper dir:" >> $seqres.full +$here/src/t_dir_offset2 $SCRATCH_MNT/pure $bufsize "-p100" 2>&1 >> $seqres.full || \ + echo "Found unlinked file in pure upper dir (see $seqres.full for details)" + +# Check readdir cache invalidate on impure upper dir +echo -e "\nCreate file in impure upper dir:" >> $seqres.full +$here/src/t_dir_offset2 $SCRATCH_MNT/impure $bufsize "+o0" 2>&1 >> $seqres.full || \ + echo "Missing created file in impure upper dir (see $seqres.full for details)" +echo -e "\nRemove file in impure upper dir:" >> $seqres.full +$here/src/t_dir_offset2 $SCRATCH_MNT/impure $bufsize "-o100" 2>&1 >> $seqres.full || \ + echo "Found unlinked file in impure upper dir (see $seqres.full for details)" + +# Check readdir cache invalidate on merge dir +echo -e "\nCreate file in merge dir:" >> $seqres.full +$here/src/t_dir_offset2 $SCRATCH_MNT/merge $bufsize "+m0" 2>&1 >> $seqres.full || \ + echo "Missing created file in merge dir (see $seqres.full for details)" +echo -e "\nRemove file in merge dir:" >> $seqres.full +$here/src/t_dir_offset2 $SCRATCH_MNT/merge $bufsize "-m100" 2>&1 >> $seqres.full || \ + echo "Found unlinked file in merge dir (see $seqres.full for details)" + +# Check readdir cache invalidate on former merge dir +echo -e "\nCreate file in former merge dir:" >> $seqres.full +$here/src/t_dir_offset2 $SCRATCH_MNT/former $bufsize "+f0" 2>&1 >> $seqres.full || \ + echo "Missing created file in former merge dir (see $seqres.full for details)" +echo -e "\nRemove file in former merge dir:" >> $seqres.full +$here/src/t_dir_offset2 $SCRATCH_MNT/former $bufsize "-f100" 2>&1 >> $seqres.full || \ + echo "Found unlinked file in former merge dir (see $seqres.full for details)" + +# success, all done +echo "Silence is golden" +status=0 +exit diff --git a/tests/overlay/077.out b/tests/overlay/077.out new file mode 100644 index 00000000..11538276 --- /dev/null +++ b/tests/overlay/077.out @@ -0,0 +1,2 @@ +QA output created by 077 +Silence is golden diff --git a/tests/overlay/group b/tests/overlay/group index ddc355e5..bd014f20 100644 --- a/tests/overlay/group +++ b/tests/overlay/group @@ -79,6 +79,7 @@ 074 auto quick exportfs dangerous 075 auto quick perms 076 auto quick perms dangerous +077 auto quick dir 100 auto quick union samefs 101 auto quick union nonsamefs 102 auto quick union nonsamefs xino