From patchwork Thu Nov 2 10:15:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10038311 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 24769603B5 for ; Thu, 2 Nov 2017 10:15:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 138F428EDE for ; Thu, 2 Nov 2017 10:15:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0813328EE1; Thu, 2 Nov 2017 10:15:12 +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 99B0528EE3 for ; Thu, 2 Nov 2017 10:15:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933335AbdKBKPI (ORCPT ); Thu, 2 Nov 2017 06:15:08 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:54494 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932321AbdKBKPE (ORCPT ); Thu, 2 Nov 2017 06:15:04 -0400 Received: by mail-wr0-f195.google.com with SMTP id o44so4462194wrf.11; Thu, 02 Nov 2017 03:15:03 -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=ukCQXzv25Fb1WckYOsNfdu8DdFGUcMYcae60hnSyP/U=; b=uGLhiDkBwJCApLpSj6e9GfgIbTjBClCidtLtK2ekzrp6vaFsRMN12YTMJ2WZ8ppzeT wj08nnd7BEM86G+D7dVQea87sIDtd5VTtx2YaSFM4vnYhW0b40cvIkfKzys2f16BDivU h3fCsG8mf/3AItH8Z4bxsuYEbUei5RNWxPRGhA0zsPY8laXxzifj/fiNaMILHiZHBE+b pXAcXysdSOrViCvz82ZSzKk+dIC2CmLbZtsrM8fwvHGOeOZXYAhK5BItVMMqNHgAnN67 TU+UG1PYhkp1vKL3RJ4bTpbfb55iE0+p5x7AFQkfPNS0jv82afdYZGi4c9sGuivuQlTo /7lQ== 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=ukCQXzv25Fb1WckYOsNfdu8DdFGUcMYcae60hnSyP/U=; b=DIWe/1ZyVG9YVtXNxJqzx5lrpXC2pFmnPiuzC0yFbVDML/uJC5NN8ZJgUYSLW/Z+8k Qlxy5RIoPWKdRbHThS7Vo70lYkp2/K6FYNSx+F1EBLHcGGVPqeVjJJhFu+m0rCnCiGCS jS0xh22z0cnZb8TZf9LX++EQnamxv72dnWDpTrBzzj420f+6EL6nSfQIhdf7kMR3hqsq VcjbeUammjjefr0+Ucg4BEhKLePnVVo7Sh3Eq53DNOLp8m51YSjIWB9Sltnnb1j71gyZ 5QtwEYazUathI1tTsGF10oV3NqtsxoLOf0IptiLoE8zqKmEqu0ug1KfIoHPgICjZKJUu S/Fg== X-Gm-Message-State: AMCzsaVzVEKgjLqpEkwuNraD3mC4Vgk14LY4yVoVxlOmXdOicndk4lKJ XEQIyuuy1JHbbSI6QqyYh6s= X-Google-Smtp-Source: ABhQp+SQ0IqT/eT0WxG+HpwDRm8oOijijubj+P9cT8GNAVBnx+uvYKMH7fCl5Wcmk4uXlkiFDZw7JQ== X-Received: by 10.223.155.208 with SMTP id e16mr2478632wrc.161.1509617702867; Thu, 02 Nov 2017 03:15:02 -0700 (PDT) Received: from localhost.localdomain ([31.210.182.123]) by smtp.gmail.com with ESMTPSA id e6sm7190026wrg.53.2017.11.02.03.15.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Nov 2017 03:15:02 -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 5/7] open_by_handle: test file handles of open files Date: Thu, 2 Nov 2017 12:15:37 +0200 Message-Id: <1509617739-15744-6-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 -dk [N] 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. Signed-off-by: Amir Goldstein --- src/open_by_handle.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/open_by_handle.c b/src/open_by_handle.c index e8edcf5..dbc5b0f 100644 --- a/src/open_by_handle.c +++ b/src/open_by_handle.c @@ -27,7 +27,7 @@ /* -usage: open_by_handle [-cludmrwap] [num_files] +usage: open_by_handle [-cludmrwapk] [num_files] Examples: @@ -55,12 +55,18 @@ Examples: open_by_handle -dp [N] -5. Get file handles for existing test set, rename all test files, +5. 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, drop caches, try to open all files by handle (should work): open_by_handle -m [N] -6. Get file handles for existing test set, hardlink all test files, +7. 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): @@ -97,10 +103,11 @@ struct handle { void usage(void) { - fprintf(stderr, "usage: open_by_handle [-cludmrwap] [num_files]\n"); + fprintf(stderr, "usage: open_by_handle [-cludmrwapk] [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 -k [N] - get file handles of files that are kept open, 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"); @@ -127,11 +134,12 @@ int main(int argc, char **argv) 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) usage(); - while ((c = getopt(argc, argv, "cludmrwap")) != -1) { + while ((c = getopt(argc, argv, "cludmrwapk")) != -1) { switch (c) { case 'c': create = 1; @@ -165,6 +173,9 @@ int main(int argc, char **argv) case 'p': parent = 1; break; + case 'k': + keepopen = 1; + break; default: fprintf(stderr, "illegal option '%s'\n", argv[optind]); case 'h': @@ -213,7 +224,7 @@ int main(int argc, char **argv) sprintf(fname2, "%s/link%06d", test_dir, i); fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0644); if (fd < 0) { - strcat(fname, ": open"); + strcat(fname, ": open(O_CREAT)"); perror(fname); return EXIT_FAILURE; } @@ -240,6 +251,15 @@ int main(int argc, char **argv) perror(fname); return EXIT_FAILURE; } + if (keepopen) { + /* Open without close to keep unlinked files around */ + fd = open(fname, O_RDONLY); + if (fd < 0) { + strcat(fname, ": open(O_RDONLY)"); + perror(fname); + return EXIT_FAILURE; + } + } } if (parent) { @@ -350,7 +370,7 @@ int main(int argc, char **argv) for (i=0; i < numfiles; i++) { errno = 0; fd = open_by_handle_at(mount_fd, &handle[i].fh, wrafter ? O_RDWR : O_RDONLY); - if (nlink && fd >= 0) { + if ((nlink || keepopen) && fd >= 0) { if (rd) { char buf[4] = {0}; int size = read(fd, buf, 4); @@ -370,7 +390,7 @@ int main(int argc, char **argv) } close(fd); continue; - } else if (!nlink && fd < 0 && (errno == ENOENT || errno == ESTALE)) { + } else if (!nlink && !keepopen && fd < 0 && (errno == ENOENT || errno == ESTALE)) { continue; } sprintf(fname, "%s/file%06d", test_dir, i); @@ -378,9 +398,10 @@ int main(int argc, char **argv) printf("open_by_handle(%s) opened an unlinked file!\n", fname); close(fd); } else { - printf("open_by_handle(%s) returned %d incorrectly on %s file!\n", + printf("open_by_handle(%s) returned %d incorrectly on %s%s file!\n", fname, errno, - nlink ? "a linked" : "an unlinked"); + nlink ? "a linked" : "an unlinked", + keepopen ? " open" : ""); } failed++; }