From patchwork Thu Mar 29 12:06:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10315305 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 C4F0F60383 for ; Thu, 29 Mar 2018 12:05:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4E882A1F2 for ; Thu, 29 Mar 2018 12:05:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 997752A222; Thu, 29 Mar 2018 12:05:46 +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 2AD882A1F2 for ; Thu, 29 Mar 2018 12:05:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752679AbeC2MFn (ORCPT ); Thu, 29 Mar 2018 08:05:43 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:54964 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750858AbeC2MFl (ORCPT ); Thu, 29 Mar 2018 08:05:41 -0400 Received: by mail-wm0-f66.google.com with SMTP id h76so10396576wme.4; Thu, 29 Mar 2018 05:05:41 -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=ZawovpOp3MRMbSTCwINjs0w5tbJm7ALbymDcAET1yqo=; b=Do/9iDpwP41LHCQZMMeyDKPjwO56OieBRj8hp9e5ZdFaJUeX2ErRpF2wVwIlaaRSof jhLdNsGjG7n596pbGRbsbFhikPhhyHgtLuxkG/IYE7AgshNckcV9M7rfpzwveDn96ynp dU6VFiu91bbF9nw60hZlRcPjJ1WryaWue91MjA0oUdTs1S+RywW3JtQGON2DYyoIfEhL Rk3WATe8+AjPR9fgUnWzdjc/tcWeRdlkPgmCDe09cDRRx96zvQ8iy65aWuYoYFJgcts0 YgaTWN5Xpsz0SPB4oWHG1YR9CdMh8KC8iJ8fGmHTyNAfxTF8SKx5+21vifD3RA3QgG3P VS6Q== 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=ZawovpOp3MRMbSTCwINjs0w5tbJm7ALbymDcAET1yqo=; b=eug1aoC/oCqsySetB6wuQligRh7mELKutIBZXyKxz0K72V7zYJYx6wQli79Jqg9p5W 25sYlHz5vzu5dAW0tpscPOyUM1xSpihoh0lYcnMW1jAjZD1V3U5xRYqZ7OAsbKnw/m1X inMgC3c/ld2y0g6q6KobF7rVFeqX60bLvAnm2xMhkrAHhM7d/XnX3ShF/bk9eHas0nrj s/S78Vqv/ATgIAxhWt+4DV31MJJxgQHxl48DHrfqz+6a3WZAsXhqx9xjlRAvfeBQALXB tbytVXR32RtgiVaak440Meri5eZ8HWen2UrelobF6Vbg08M8exTl686YXiszuDk/nogQ tg+Q== X-Gm-Message-State: AElRT7H0GbQtl0D63bqjQeTUqrTj+Q8Fvqd8WgIiakrhZUeIsCHDS+nh cJ8VydQn7+j3awfbFqTnmxvz8g== X-Google-Smtp-Source: AIpwx4+garmhMKkukwnP9a2cyddAGsF1fWgt8+q5nyFne0UHHp5BmhuHTORNBsKeA4igxxMEcJ+crw== X-Received: by 10.28.163.5 with SMTP id m5mr6008400wme.33.1522325140505; Thu, 29 Mar 2018 05:05:40 -0700 (PDT) Received: from localhost.localdomain ([141.226.13.13]) by smtp.gmail.com with ESMTPSA id s15sm6699694wrg.28.2018.03.29.05.05.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Mar 2018 05:05:39 -0700 (PDT) From: Amir Goldstein To: Eryu Guan Cc: Miklos Szeredi , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v2 4/5] open_by_handle: add -s option to sleep and keep files open by handle Date: Thu, 29 Mar 2018 15:06:49 +0300 Message-Id: <1522325210-17900-5-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522325210-17900-1-git-send-email-amir73il@gmail.com> References: <1522325210-17900-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 | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/open_by_handle.c b/src/open_by_handle.c index d3beb78..f5be235 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': @@ -478,7 +482,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 +534,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 +546,13 @@ int main(int argc, char **argv) if (failed) return EXIT_FAILURE; + + /* + * Sleep keeping files open by handle - the program need to be killed + * to release the open files. + */ + while (sleep_loop) + sleep(1); + return EXIT_SUCCESS; }