From patchwork Sun Mar 25 14:53:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10306661 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 061A9600CC for ; Sun, 25 Mar 2018 14:52:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA00E29263 for ; Sun, 25 Mar 2018 14:52:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE7C6293D5; Sun, 25 Mar 2018 14:52:02 +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 71A0B29263 for ; Sun, 25 Mar 2018 14:52:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753390AbeCYOwC (ORCPT ); Sun, 25 Mar 2018 10:52:02 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:37070 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753286AbeCYOwB (ORCPT ); Sun, 25 Mar 2018 10:52:01 -0400 Received: by mail-wm0-f65.google.com with SMTP id r131so4224615wmb.2; Sun, 25 Mar 2018 07:52: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=vk3GPBlj566SlXoKRcK4qxnygtAxSreVbAssD9E0jjk=; b=guuuYi6qdp+9sk1r70iV274j5mycgRE6BV9HoUWa2KFFdxnuLTxzrK6NA2mR0D1eIi Ca24nNdRfcswnvFPWyGzHVS8f4+i4ZZ3EbJSZ3C/1zY6wun88HZGEnHwpCC4ILARbtAg e/uoZC9XxTbqQySFWwnifPvV4/HReWfCMI1iFLpWr2auSHcX450L/ePSPyFiHhW14oFZ VbGigOvGC+2O5Iku08URWSXu7O+X4BtFGI3kOV5X0s/6M1I9mLv7AdEC1FV/gugFq8zy +zrP+BeLecbvxjCkUEhkD+8T3ftGYfROrqdF03Hngtkcw8hjT9wrrfLT8qnqXwIsJWSR 4u4w== 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=vk3GPBlj566SlXoKRcK4qxnygtAxSreVbAssD9E0jjk=; b=jDVM9q9LAndvn12BqQvqMB+jMzF+rWqcfsAoJyv3PSzI5IwJKWYcGCTxZhkSO1fBsb IrcSC1jDBM8jC5c0pNx0gTJ79EO5+o11BTfNL/JSYk06B4r9wwpubJgRt4A6rQOwAwzT 8FmjHcJ/aYbnqlLKnw3TZ8CLK1cyLNXyP2aauWSOX+SRJ/oS9VsONHjxsKndTyGbLUHa 1CySfSTlHJZ2WYzXEnqosrHzqRamI1jbK0iIRq6EJ29It98o0uQMiZbHrUlcnJCynQHu 7iGbD8UPBPBo+btga3wB8G+Tz6ZuH1Juq7HhKbwF/GyN7wx4CpU7ej+Usqd2uzBfa9Ze bBxQ== X-Gm-Message-State: AElRT7HyK0EJ6H7+KN+FBYo9WPvtUplP8WW30tR2sKSTQe5m2DKLptmZ GYWpoQeQah+EsI1yxK46/pGQng== X-Google-Smtp-Source: AG47ELsTMVNcYoDspb46SwBNpBqGKGkmEwJ6nau8+9O0FSAzoAAn6tfgcWqGDGx+v97sZLloZgkOog== X-Received: by 10.28.87.73 with SMTP id l70mr12834845wmb.123.1521989519515; Sun, 25 Mar 2018 07:51:59 -0700 (PDT) Received: from amir-VirtualBox.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id a63sm16537054wrc.22.2018.03.25.07.51.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 25 Mar 2018 07:51:58 -0700 (PDT) From: Amir Goldstein To: Eryu Guan Cc: Miklos Szeredi , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH 2/3] open_by_handle: add -s option to sleep and keep files open by handle Date: Sun, 25 Mar 2018 17:53:10 +0300 Message-Id: <1521989591-9496-3-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521989591-9496-1-git-send-email-amir73il@gmail.com> References: <1521989591-9496-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 This feature is needed for tests that need to open file by handle and then perform operations while that file is open. This will be used by an overlay test to keep disconnected dentries in dcache. Usage: open_by_handle -s On success, the program will run until it gets a terminating signal. Signed-off-by: Amir Goldstein --- src/open_by_handle.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/open_by_handle.c b/src/open_by_handle.c index d3beb78..e4bd29b 100644 --- a/src/open_by_handle.c +++ b/src/open_by_handle.c @@ -27,7 +27,7 @@ /* -usage: open_by_handle [-cludmrwapknh] [<-i|-o> ] [num_files] +usage: open_by_handle [-cludmrwapknhs] [<-i|-o> ] [num_files] Examples: @@ -48,9 +48,9 @@ Examples: open_by_handle -p -o [N] 4. Read file handles from file and open files by handle without - dropping caches beforehand: + dropping caches beforehand. Sleep afterhand to keep files open: - open_by_handle -np -i [N] + open_by_handle -nps -i [N] 5. Get file handles for existing test set, write data to files, drop caches, open all files by handle, read and verify written @@ -112,7 +112,7 @@ struct handle { void usage(void) { - fprintf(stderr, "usage: open_by_handle [-cludmrwapknh] [<-i|-o> ] [num_files]\n"); + fprintf(stderr, "usage: open_by_handle [-cludmrwapknhs] [<-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"); @@ -128,6 +128,7 @@ void usage(void) 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"); + fprintf(stderr, "open_by_handle -s [N] - wait in sleep loop after opening files by handle to keep them open\n"); exit(EXIT_FAILURE); } @@ -148,12 +149,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, drop_caches = 1; + int keepopen = 0, drop_caches = 1, sleep_loop = 0; if (argc < 2) usage(); - while ((c = getopt(argc, argv, "cludmrwapknhi:o:")) != -1) { + while ((c = getopt(argc, argv, "cludmrwapknhi:o:s")) != -1) { switch (c) { case 'c': create = 1; @@ -209,6 +210,9 @@ int main(int argc, char **argv) return EXIT_FAILURE; } break; + case 's': + sleep_loop = 1; + break; default: fprintf(stderr, "illegal option '%s'\n", argv[optind]); case 'h': @@ -308,6 +312,7 @@ int main(int argc, char **argv) fprintf(stderr, "failed reading file handle #%d from '%s'\n", i, infile); return EXIT_FAILURE; } + continue; } else { handle[i].fh.handle_bytes = MAX_HANDLE_SZ; ret = name_to_handle_at(AT_FDCWD, fname, &handle[i].fh, &mount_id, 0); @@ -478,7 +483,8 @@ int main(int argc, char **argv) perror(fname); return EXIT_FAILURE; } - close(fd); + if (!sleep_loop) + close(fd); continue; } else if (!nlink && !keepopen && fd < 0 && (errno == ENOENT || errno == ESTALE)) { continue; @@ -529,7 +535,8 @@ int main(int argc, char **argv) return EXIT_FAILURE; } } - close(fd); + if (!sleep_loop) + close(fd); } else if (nlink || !(errno == ENOENT || errno == ESTALE)) { printf("open_by_handle(%s) returned %d incorrectly on %s dir!\n", dname, errno, @@ -540,5 +547,10 @@ int main(int argc, char **argv) if (failed) return EXIT_FAILURE; + + /* Sleep keeping files open by handle */ + while (sleep_loop) + sleep(1); + return EXIT_SUCCESS; }