From patchwork Thu Nov 2 10:15:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10038333 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 CB85A603B5 for ; Thu, 2 Nov 2017 10:15:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA58628EDE for ; Thu, 2 Nov 2017 10:15:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF66128EE1; Thu, 2 Nov 2017 10:15:33 +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 BE98528EDE for ; Thu, 2 Nov 2017 10:15:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755295AbdKBKPZ (ORCPT ); Thu, 2 Nov 2017 06:15:25 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:49041 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755385AbdKBKPB (ORCPT ); Thu, 2 Nov 2017 06:15:01 -0400 Received: by mail-wm0-f66.google.com with SMTP id p75so9868871wmg.3; Thu, 02 Nov 2017 03:15:00 -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=eu3bky6I/GZYMX5zDC1jRxZgAD8fUCbj1ik+n85o9XI=; b=NYQIISxqPO6kCsi484N0anC81vlyGWXWLiBuZ71K1mD9WZIbE+6ETrdTIn51ffgJsb x0XN1dBDXL13KyrvhY3psHZtCiN2RDzALIde6CrLUUsO2FAssyyeVNfWTIeVZY7/qszq v1VpBJ7ksNGuSgePNSHJmjGxwto4OWn2fed4vL0ei/X3LOWq/xK0NjG5htfzXFk0k0OW AuOKPr9wnkuSjPCxcSNdWRtrQAvveKIR8a/1/Bhk8ktVH109EBMAI3OyA0B0sgxP5xOm kXOoJfeEtBBDtmIQQPMk/A+rPgjBlZ3y065I9gQrVKWVwjfIt+fxegyfVpyazV2L92QU yliw== 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=eu3bky6I/GZYMX5zDC1jRxZgAD8fUCbj1ik+n85o9XI=; b=sokRwv76VhTx/5tEAHV3r2vCAkZXdxklfTrtHWnYApBf2g++cPbwjrvzr76MNHWOGz /0XVksquJevCDC1OpbfHORWl1a0NeDTABgyNXxr7Y7rzTxvnv9xA4o+A0HRtdMNDQkHd NIYtbMwTN6FyAZTmwwWawH4d2Oq9VJgDlU3GSEwkrWDGcFqddVdE/HwwKd8AttKkkrkh d3rMmxtVaDYjyihTLMSNv29ey3Kh2WzpVwcDR+37iIO6doJnqXP+sR1DXbkmdgxYWpoE 2A0WQ0X5EwjKfy8tTFGqyQCtbzxetHEGvPUyQZGxzHz7V4KamY0nojjcZBoPTdzD1zMX j0ow== X-Gm-Message-State: AMCzsaX3m6rQfi/i82sCkbEsngXQT+En++1eK2txV7TEdaLbG3CLrh63 yYPXLHI2JyWej8byyT+ETlw= X-Google-Smtp-Source: ABhQp+Q1KN3k24sDTzQPRl2pQ6zbqpRCr+hPyTGLcBLe6RUV44rsoqVS28r+45UDYc3OybxsHgzmFA== X-Received: by 10.28.20.141 with SMTP id 135mr1145116wmu.74.1509617699947; Thu, 02 Nov 2017 03:14:59 -0700 (PDT) Received: from localhost.localdomain ([31.210.182.123]) by smtp.gmail.com with ESMTPSA id e6sm7190026wrg.53.2017.11.02.03.14.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Nov 2017 03:14:59 -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 3/7] open_by_handle: test content of open file handle Date: Thu, 2 Nov 2017 12:15:35 +0200 Message-Id: <1509617739-15744-4-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 -rwa [N] Get file handles for existing test set, write data to files, drop caches, open all files by handle, read data and verify old data, write new data to files. This is needed for testing that overlay decoded file handles are not pointing the lower inodes after new data is already written to upper inodes after copy up. open_by_handle -a is needed for testing copy up of disconnected overlay decoded file handles (to index dir). Signed-off-by: Amir Goldstein --- src/open_by_handle.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 7 deletions(-) diff --git a/src/open_by_handle.c b/src/open_by_handle.c index 8b12df3..581dc05 100644 --- a/src/open_by_handle.c +++ b/src/open_by_handle.c @@ -27,7 +27,7 @@ /* -usage: open_by_handle [-cludm] [num_files] +usage: open_by_handle [-cludmrwa] [num_files] Examples: @@ -43,17 +43,23 @@ Examples: open_by_handle [N] -3. Get file handles for existing test set, unlink all test files, +3. 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, drop caches, try to open all files by handle and expect ESTALE: open_by_handle -d [N] -4. Get file handles for existing test set, rename all test files, +5. 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] -5. Get file handles for existing test set, hardlink all test files, +6. 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): @@ -89,10 +95,13 @@ struct handle { void usage(void) { - fprintf(stderr, "usage: open_by_handle [-cludm] [num_files]\n"); + fprintf(stderr, "usage: open_by_handle [-cludmrwa] [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"); + fprintf(stderr, "open_by_handle -w [N] - write data to test files before open by handle\n"); + fprintf(stderr, "open_by_handle -r [N] - read data from test files after open by handle and verify written data\n"); + fprintf(stderr, "open_by_handle -a [N] - write data to test files after open by handle\n"); fprintf(stderr, "open_by_handle -l [N] - create hardlinks to test files, drop caches and try to open by handle\n"); 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"); @@ -112,15 +121,28 @@ int main(int argc, char **argv) int mount_fd, mount_id; int numfiles = 1; int create = 0, delete = 0, nlink = 1, move = 0; + int rd = 0, wr = 0, wrafter = 0; if (argc < 2 || argc > 4) usage(); - while ((c = getopt(argc, argv, "cludm")) != -1) { + while ((c = getopt(argc, argv, "cludmrwa")) != -1) { switch (c) { case 'c': create = 1; break; + case 'w': + /* Write data before open_by_handle_at() */ + wr = 1; + break; + case 'r': + /* Read data after open_by_handle_at() */ + rd = 1; + break; + case 'a': + /* Write data after open_by_handle_at() */ + wrafter = 1; + break; case 'l': nlink = 2; break; @@ -194,6 +216,23 @@ int main(int argc, char **argv) } } + /* write data to files */ + for (i=0; wr && i < numfiles; i++) { + sprintf(fname, "%s/file%06d", test_dir, i); + fd = open(fname, O_WRONLY, 0644); + if (fd < 0) { + strcat(fname, ": open"); + perror(fname); + return EXIT_FAILURE; + } + if (write(fd, "aaaa", 4) != 4) { + strcat(fname, ": write before"); + perror(fname); + return EXIT_FAILURE; + } + close(fd); + } + /* after creating test set only check that fs supports exportfs */ if (create) return EXIT_SUCCESS; @@ -265,8 +304,25 @@ int main(int argc, char **argv) */ for (i=0; i < numfiles; i++) { errno = 0; - fd = open_by_handle_at(mount_fd, &handle[i].fh, O_RDWR); + fd = open_by_handle_at(mount_fd, &handle[i].fh, wrafter ? O_RDWR : O_RDONLY); if (nlink && fd >= 0) { + if (rd) { + char buf[4] = {0}; + int size = read(fd, buf, 4); + if (size < 0) { + strcat(fname, ": read"); + perror(fname); + return EXIT_FAILURE; + } + if (size < 4 || memcmp(buf, "aaaa", 4)) { + printf("open_by_handle(%s) returned stale data '%.*s'!\n", fname, size, buf); + } + } + if (wrafter && write(fd, "aaaa", 4) != 4) { + strcat(fname, ": write after"); + perror(fname); + return EXIT_FAILURE; + } close(fd); continue; } else if (!nlink && fd < 0 && (errno == ENOENT || errno == ESTALE)) {