From patchwork Sun Jan 7 18:07:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10148419 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 7DEA9601BE for ; Sun, 7 Jan 2018 18:06:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7294E28628 for ; Sun, 7 Jan 2018 18:06:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6780F28633; Sun, 7 Jan 2018 18:06:43 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham 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 C08DC28628 for ; Sun, 7 Jan 2018 18:06:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754338AbeAGSGl (ORCPT ); Sun, 7 Jan 2018 13:06:41 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:40009 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754273AbeAGSGi (ORCPT ); Sun, 7 Jan 2018 13:06:38 -0500 Received: by mail-wm0-f68.google.com with SMTP id f206so10460786wmf.5; Sun, 07 Jan 2018 10:06:37 -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; bh=OnfRl26Lx+yugmJu992UPzpp1i+SV4wQDDBk7UBeHUw=; b=Af/JCyi+HZTRz/IYCwoSNv0tfoXUTwhbr+fRK+FQjA0jQn0LKmsVq/KMGhKtsAcjfZ Wf7Z9hdOobGYWr+P37WtTdlP5cCYVRHiL8t+lKRbMIQCWS17Y/W7VMICVDuWP+YXPUzA SwUBjp66KX9GHmcD36IlSJcDPSUgUwfUsFQQKDSoFZ1PXh/Rocvrcu5MAoa4de+HXGF6 knYJBv409b/Ny17NEpXMR1N2NnNT10wM7e29kUW+OVmJDBXgbYpL1nD4pXtJkmPOf02S Xlt9JBZyFAlbf7YYKOm+O5ML3y/k2UshOBgMAAmPslMV0XpwTpHN76prKuoGU6W6Cn5I FmOA== 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=OnfRl26Lx+yugmJu992UPzpp1i+SV4wQDDBk7UBeHUw=; b=MSNsa3tnZ/VYQsUAzq2rggFXFkaF85VoRvUe9q2iat5+9+Os/RaWI07DPNaWwNoGIg j53JhQXWfyV6tEfnHfwvwXSagc31pk4tTqY8yPczJBdUI7QWNg2cKbygrZ2zB5yOaq0D c/rU42OiLgdVrzd9/kK/1LkPFBjJlPFpELAJfVURPG+nz4sq8Z+5EnMojMjBkwG/PNip nBAXCIKYYNKZQKmCJp2j668RP7BCtUVqp4xj7YGzVZfR9BDkjN6O4gV6NlN+tJrBakuE uYbMQfIQZ/oiF++3ZV3CKe9LiMGCahOwfaEssuNM97mggNektfL2t5XZ0421fHaJqIyc WwoQ== X-Gm-Message-State: AKGB3mL455SlIp8qFWoRow++rGtpkTQ1pqqFZrz2ZMLldK/MCRle51sJ 81X5G/rl+3G3d4gTEOnIls0= X-Google-Smtp-Source: ACJfBos1YNUqX3nSVR60gNKzzw01TU+BmEkS0FuNB+0ZxPS7opG0x681U5VbChvFI5j7C/ib5/Ks6g== X-Received: by 10.28.175.66 with SMTP id y63mr6457773wme.7.1515348396764; Sun, 07 Jan 2018 10:06:36 -0800 (PST) Received: from localhost.localdomain (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id k42sm11433750wrf.37.2018.01.07.10.06.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 07 Jan 2018 10:06:36 -0800 (PST) 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 1/7] open_by_handle: store and load file handles from file Date: Sun, 7 Jan 2018 20:07:19 +0200 Message-Id: <1515348445-1403-2-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515348445-1403-1-git-send-email-amir73il@gmail.com> References: <1515348445-1403-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 -p -o [N] open_by_handle -p -i [N] This will be used to test decoding of file handles after various file systems operations including mount cycle. Signed-off-by: Amir Goldstein --- src/open_by_handle.c | 110 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 85 insertions(+), 25 deletions(-) diff --git a/src/open_by_handle.c b/src/open_by_handle.c index dbc5b0f..f9dfefc 100644 --- a/src/open_by_handle.c +++ b/src/open_by_handle.c @@ -43,30 +43,36 @@ Examples: open_by_handle -p [N] -3. Get file handles for existing test set, write data to files, +3. Get file handles for existing test set and write them to a file. + Read file handles from file and open files by handle: + + open_by_handle -p -o [N] + open_by_handle -p -i [N] + +4. Get file handles for existing test set, write data to files, drop caches, open all files by handle, read and verify written data, write new data to file: open_by_handle -rwa [N] -4. Get file handles for existing test set, unlink all test files, +5. Get file handles for existing test set, unlink all test files, remove test_dir, drop caches, try to open all files by handle and expect ESTALE: open_by_handle -dp [N] -5. Get file handles for existing test set, keep open file handles for all +6. Get file handles for existing test set, keep open file handles for all test files, unlink all test files, drop caches and try to open all files by handle (should work): open_by_handle -dk [N] -6. Get file handles for existing test set, rename all test files, +7. Get file handles for existing test set, rename all test files, drop caches, try to open all files by handle (should work): open_by_handle -m [N] -7. Get file handles for existing test set, hardlink all test files, +8. Get file handles for existing test set, hardlink all test files, then unlink the original files, drop caches and try to open all files by handle (should work): @@ -103,7 +109,7 @@ struct handle { void usage(void) { - fprintf(stderr, "usage: open_by_handle [-cludmrwapk] [num_files]\n"); + fprintf(stderr, "usage: open_by_handle [-cludmrwapk] [<-i|-o> ] [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"); @@ -116,6 +122,8 @@ void usage(void) 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"); + fprintf(stderr, "open_by_handle -i [N] - read test files handles from file and try to open by handle\n"); + fprintf(stderr, "open_by_handle -o [N] - get file handles of test files and write handles to file\n"); exit(EXIT_FAILURE); } @@ -131,15 +139,16 @@ int main(int argc, char **argv) char *test_dir; char *mount_dir; int mount_fd, mount_id; + int in_fd = 0, out_fd = 0; int numfiles = 1; int create = 0, delete = 0, nlink = 1, move = 0; int rd = 0, wr = 0, wrafter = 0, parent = 0; int keepopen = 0; - if (argc < 2 || argc > 4) + if (argc < 2) usage(); - while ((c = getopt(argc, argv, "cludmrwapk")) != -1) { + while ((c = getopt(argc, argv, "cludmrwapki:o:")) != -1) { switch (c) { case 'c': create = 1; @@ -176,13 +185,27 @@ int main(int argc, char **argv) case 'k': keepopen = 1; break; + case 'i': + in_fd = open(optarg, O_RDONLY); + if (in_fd < 0) { + perror(optarg); + return EXIT_FAILURE; + } + break; + case 'o': + out_fd = creat(optarg, 0644); + if (out_fd < 0) { + perror(optarg); + return EXIT_FAILURE; + } + break; default: fprintf(stderr, "illegal option '%s'\n", argv[optind]); case 'h': usage(); } } - if (optind == argc || optind > 2) + if (optind == argc) usage(); test_dir = argv[optind++]; if (optind < argc) @@ -192,11 +215,14 @@ int main(int argc, char **argv) usage(); } - if (parent) { + if (parent && !in_fd) { 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. + * -i flag implies that test_dir IS a mount point, because we + * are testing open by handle of dir, which may have been + * deleted or renamed. */ mount_dir = dirname(dname); if (create) @@ -241,15 +267,24 @@ int main(int argc, char **argv) /* sync to get the new inodes to hit the disk */ sync(); - /* create the handles */ + /* create/read the handles */ for (i=0; i < numfiles; i++) { sprintf(fname, "%s/file%06d", test_dir, i); - handle[i].fh.handle_bytes = MAX_HANDLE_SZ; - ret = name_to_handle_at(AT_FDCWD, fname, &handle[i].fh, &mount_id, 0); - if (ret < 0) { - strcat(fname, ": name_to_handle"); - perror(fname); - return EXIT_FAILURE; + if (in_fd) { + ret = read(in_fd, (char *)&handle[i], sizeof(*handle)); + if (ret < sizeof(*handle)) { + strcat(fname, ": read handle"); + perror(fname); + return EXIT_FAILURE; + } + } else { + handle[i].fh.handle_bytes = MAX_HANDLE_SZ; + ret = name_to_handle_at(AT_FDCWD, fname, &handle[i].fh, &mount_id, 0); + if (ret < 0) { + strcat(fname, ": name_to_handle"); + perror(fname); + return EXIT_FAILURE; + } } if (keepopen) { /* Open without close to keep unlinked files around */ @@ -260,15 +295,40 @@ int main(int argc, char **argv) return EXIT_FAILURE; } } + if (out_fd) { + ret = write(out_fd, (char *)&handle[i], sizeof(*handle)); + if (ret < sizeof(*handle)) { + strcat(fname, ": write handle"); + perror(fname); + return EXIT_FAILURE; + } + } } 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; + if (in_fd) { + ret = read(in_fd, (char *)&dir_handle, sizeof(*handle)); + if (ret < sizeof(*handle)) { + strcat(dname, ": read handle"); + perror(dname); + return EXIT_FAILURE; + } + } else { + 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; + } + } + if (out_fd) { + ret = write(out_fd, (char *)&dir_handle, sizeof(*handle)); + if (ret < sizeof(*handle)) { + strcat(dname, ": write handle"); + perror(dname); + return EXIT_FAILURE; + } } } @@ -289,8 +349,8 @@ int main(int argc, char **argv) close(fd); } - /* after creating test set only check that fs supports exportfs */ - if (create) + /* If creating test set or saving files handles, we are done */ + if (create || out_fd) return EXIT_SUCCESS; /* hardlink the files */