From patchwork Thu Nov 2 10:15:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10038325 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 58E07603B5 for ; Thu, 2 Nov 2017 10:15:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4754628EE0 for ; Thu, 2 Nov 2017 10:15:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C4F828EE2; Thu, 2 Nov 2017 10:15:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9FCC28EE0 for ; Thu, 2 Nov 2017 10:15:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933318AbdKBKPG (ORCPT ); Thu, 2 Nov 2017 06:15:06 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:46221 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933303AbdKBKPD (ORCPT ); Thu, 2 Nov 2017 06:15:03 -0400 Received: by mail-wm0-f68.google.com with SMTP id m72so9898437wmc.1; Thu, 02 Nov 2017 03:15:02 -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; bh=VSBO37NTRU0098upjIJ9+kYcsbgY0LJ9CVrTOBX1ljQ=; b=MrGs9uSyoZt1CruLf2nS+XHCn/wavVSbpR1xvOipRiMfGoWqGJ43k7ESc0zKIaZrx8 821KiyL0HwWW+W6GwWLz2BtClHPULSMcircFK6kp9+jBfMaZWxnTY3cOQtZgSzQhyre3 gPXVY77h6dL2UjTAG5ZboN4ILzwDT11F+w+UuIA45IPvUEiUHGCYe/twHx53RlESltZR +BMet4HD3hKmVGvGRuK/2W4uA4vIeP5SkuJV7DkeW1/aGB5w5hwYUWiZdErXWp0REZ1z RqH2Le8Bfza1EAj8YjVPXCeidrOQi6IFyqGqz6jhB2FDTm3o4HIDCGCxrp8lhqTWmnvh X1Ww== 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; bh=VSBO37NTRU0098upjIJ9+kYcsbgY0LJ9CVrTOBX1ljQ=; b=GfMdiFZ5nUvGKohCm1yfRIEEzzeNJBefB1Y4WZ1F1iQ/PSc0J7WtpNvFjA9ojQcgTu xtfFQITmNPXRxAHoKZeaIUPhjHg7rkbuqsdL4e01iglBBLQngRNRANTRuTc5uew0+BsG J9WcFVnsB+Sxgc0jlH6Z7vRge65T55qyQVZuFyTRXCywTQO2NXTb3JmX0xHR/wFbQCir IpZgYTzmivxyFp2sy7iHWcnBArWyKW0R047UUJxzw8Uy/nLUPr1lHASTsgSPUZuDRmvb 8muDNxxmJR02G6tMSXZ3d3D2sV+tgneV+emI8mJsl8xiku1Ci9zo0K2KL3phlFL09w2d iEvg== X-Gm-Message-State: AMCzsaUns8mPvXryxMdDuaSU8Hu1R93wggq6xSzt5gbty1K2/Z1/NvY3 AMbndwWe8eQLnBmcjVI9msY= X-Google-Smtp-Source: ABhQp+Ru0koc3M6rVTLXLb0E+yZhbOLtMv/7k82pu5GpAF1v0y7ebjKWZ/ZuNxZKnmTDYP5LZTuXmw== X-Received: by 10.28.111.19 with SMTP id k19mr1053654wmc.84.1509617701346; Thu, 02 Nov 2017 03:15:01 -0700 (PDT) Received: from localhost.localdomain ([31.210.182.123]) by smtp.gmail.com with ESMTPSA id e6sm7190026wrg.53.2017.11.02.03.15.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Nov 2017 03:15:00 -0700 (PDT) From: Amir Goldstein To: Eryu Guan Cc: Jeff Layton , "J . Bruce Fields" , Miklos Szeredi , fstests@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org Subject: [PATCH 4/7] open_by_handle: test directory file handle Date: Thu, 2 Nov 2017 12:15:36 +0200 Message-Id: <1509617739-15744-5-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509617739-15744-1-git-send-email-amir73il@gmail.com> References: <1509617739-15744-1-git-send-email-amir73il@gmail.com> Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP usage: open_by_handle -cp [N] usage: open_by_handle -p [N] usage: open_by_handle -dp [N] With -p flag, create/delete also the test_dir itself and try to open by handle also test_dir itself after droping caches and use dir fd to test faccessat() of a file inside dir. mount_fd argument to open_by_handle_at() is open fd of test_dir's parent. Signed-off-by: Amir Goldstein --- src/open_by_handle.c | 114 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 101 insertions(+), 13 deletions(-) diff --git a/src/open_by_handle.c b/src/open_by_handle.c index 581dc05..e8edcf5 100644 --- a/src/open_by_handle.c +++ b/src/open_by_handle.c @@ -27,13 +27,13 @@ /* -usage: open_by_handle [-cludmrwa] [num_files] +usage: open_by_handle [-cludmrwap] [num_files] Examples: -1. Create test set of N files and try to get their NFS handles: +1. Create test set of of test_dir with N files and try to get their NFS handles: - open_by_handle -c [N] + open_by_handle -cp [N] This is used by new helper _require_exportfs() to check if filesystem supports exportfs @@ -41,7 +41,7 @@ Examples: 2. Get file handles for existing test set, drop caches and try to open all files by handle: - open_by_handle [N] + open_by_handle -p [N] 3. Get file handles for existing test set, write data to files, drop caches, open all files by handle, read and verify written @@ -50,9 +50,10 @@ Examples: open_by_handle -rwa [N] 4. Get file handles for existing test set, unlink all test files, - drop caches, try to open all files by handle and expect ESTALE: + remove test_dir, drop caches, try to open all files by handle + and expect ESTALE: - open_by_handle -d [N] + open_by_handle -dp [N] 5. Get file handles for existing test set, rename all test files, drop caches, try to open all files by handle (should work): @@ -85,17 +86,18 @@ Examples: #include #include #include +#include #define MAXFILES 1024 struct handle { struct file_handle fh; unsigned char fid[MAX_HANDLE_SZ]; -} handle[MAXFILES]; +} handle[MAXFILES], dir_handle; void usage(void) { - fprintf(stderr, "usage: open_by_handle [-cludmrwa] [num_files]\n"); + fprintf(stderr, "usage: open_by_handle [-cludmrwap] [num_files]\n"); fprintf(stderr, "\n"); fprintf(stderr, "open_by_handle -c [N] - create N test files under test_dir, try to get file handles and exit\n"); fprintf(stderr, "open_by_handle [N] - get file handles of test files, drop caches and try to open by handle\n"); @@ -106,6 +108,7 @@ void usage(void) fprintf(stderr, "open_by_handle -u [N] - unlink (hardlinked) test files, drop caches and try to open by handle\n"); fprintf(stderr, "open_by_handle -d [N] - unlink test files and hardlinks, drop caches and try to open by handle\n"); fprintf(stderr, "open_by_handle -m [N] - rename test files, drop caches and try to open by handle\n"); + fprintf(stderr, "open_by_handle -p - create/delete and try to open by handle also test_dir itself\n"); exit(EXIT_FAILURE); } @@ -113,20 +116,22 @@ int main(int argc, char **argv) { int i, c; int fd; - int ret; + int ret = 0; int failed = 0; + char dname[PATH_MAX]; char fname[PATH_MAX]; char fname2[PATH_MAX]; char *test_dir; + char *mount_dir; int mount_fd, mount_id; int numfiles = 1; int create = 0, delete = 0, nlink = 1, move = 0; - int rd = 0, wr = 0, wrafter = 0; + int rd = 0, wr = 0, wrafter = 0, parent = 0; if (argc < 2 || argc > 4) usage(); - while ((c = getopt(argc, argv, "cludmrwa")) != -1) { + while ((c = getopt(argc, argv, "cludmrwap")) != -1) { switch (c) { case 'c': create = 1; @@ -157,6 +162,9 @@ int main(int argc, char **argv) case 'm': move = 1; break; + case 'p': + parent = 1; + break; default: fprintf(stderr, "illegal option '%s'\n", argv[optind]); case 'h': @@ -173,9 +181,27 @@ int main(int argc, char **argv) usage(); } - mount_fd = open(test_dir, O_RDONLY|O_DIRECTORY); + if (parent) { + strcpy(dname, test_dir); + /* + * -p flag implies that test_dir is NOT a mount point, + * so its parent can be used as mount_fd for open_by_handle_at. + */ + mount_dir = dirname(dname); + if (create) + ret = mkdir(test_dir, 0700); + if (ret < 0 && errno != EEXIST) { + strcat(dname, ": mkdir"); + perror(dname); + return EXIT_FAILURE; + } + } else { + mount_dir = test_dir; + } + + mount_fd = open(mount_dir, O_RDONLY|O_DIRECTORY); if (mount_fd < 0) { - perror(test_dir); + perror(mount_dir); return EXIT_FAILURE; } @@ -216,6 +242,16 @@ int main(int argc, char **argv) } } + if (parent) { + dir_handle.fh.handle_bytes = MAX_HANDLE_SZ; + ret = name_to_handle_at(AT_FDCWD, test_dir, &dir_handle.fh, &mount_id, 0); + if (ret < 0) { + strcat(dname, ": name_to_handle"); + perror(dname); + return EXIT_FAILURE; + } + } + /* write data to files */ for (i=0; wr && i < numfiles; i++) { sprintf(fname, "%s/file%06d", test_dir, i); @@ -281,6 +317,15 @@ int main(int argc, char **argv) } } + if (parent && delete && !nlink) { + ret = rmdir(test_dir); + if (ret < 0) { + strcat(dname, ": rmdir"); + perror(dname); + return EXIT_FAILURE; + } + } + /* sync to get log forced for unlink transactions to hit the disk */ sync(); @@ -339,6 +384,49 @@ int main(int argc, char **argv) } failed++; } + + if (parent) { + fd = open_by_handle_at(mount_fd, &dir_handle.fh, O_RDONLY|O_DIRECTORY); + if (fd >= 0) { + if (!nlink) { + printf("open_by_handle(%s) opened an unlinked dir!\n", dname); + return EXIT_FAILURE; + } else { + /* + * Sanity check dir fd - expect to access orig file IFF + * it was not unlinked nor renamed. + */ + strcpy(fname, "file000000"); + ret = faccessat(fd, fname, F_OK, 0); + if ((ret == 0) != (!delete && !move) || + ((ret < 0) && errno != ENOENT)) { + strcat(fname, ": unexpected result from faccessat"); + perror(fname); + return EXIT_FAILURE; + } + /* + * Expect to access link file if ran test with -l flag + * (nlink > 1), -m flag (orig moved to link name) or + * -u flag (which implied previous -l run). + */ + strcpy(fname2, "link000000"); + ret = faccessat(fd, fname2, F_OK, 0); + if (ret < 0 && (nlink > 1 || delete || move || + errno != ENOENT)) { + strcat(fname2, ": unexpected result from faccessat"); + perror(fname2); + return EXIT_FAILURE; + } + } + close(fd); + } else if (nlink || !(errno == ENOENT || errno == ESTALE)) { + printf("open_by_handle(%s) returned %d incorrectly on %s dir!\n", + dname, errno, + nlink ? "a linked" : "an unlinked"); + return EXIT_FAILURE; + } + } + if (failed) return EXIT_FAILURE; return EXIT_SUCCESS;