From patchwork Wed Aug 30 14:51:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9929861 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 A13A260383 for ; Wed, 30 Aug 2017 14:51:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92D0F283FF for ; Wed, 30 Aug 2017 14:51:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87E1D286AB; Wed, 30 Aug 2017 14:51:44 +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=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 11167283FF for ; Wed, 30 Aug 2017 14:51:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751805AbdH3Ovn (ORCPT ); Wed, 30 Aug 2017 10:51:43 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:37964 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751572AbdH3Ovi (ORCPT ); Wed, 30 Aug 2017 10:51:38 -0400 Received: by mail-wm0-f67.google.com with SMTP id u26so2036201wma.5; Wed, 30 Aug 2017 07:51:37 -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=2T5MgYH0upBIYJGKrhAZ/G2T+0J14z4HDYxcLoA0exY=; b=uHkTQ4aj3kerBz4av7ZAD/IUVMUzn4Au11vt5fCkLvG6f5iJaB7fu73yT82yoTYzxO arvf20M6AO2gjd6gQ8JZULEPO6ZWQaZOPkBauyX6s1xKbZKeIrhh7nbafo4vGpA0yCBt 9v+vuOV2DAyv2unT9jp8st32gemDeAnkl8lZcAoyOjKmOZa24ZnVAx8PQtuRFey2m1A4 MhwQfF3arx3FkrlZU+TqJvEtVOranXXNNi8K4BG9oCw/gwbAcMnHIN52W+YZNd+LVGsU Kip/AeByuQPsXVsf4ZAI4qu5ogH72yQBaZl+4SWJTN61LswOCjlGDqHB8Z+KQpoSc8Te q65A== 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=2T5MgYH0upBIYJGKrhAZ/G2T+0J14z4HDYxcLoA0exY=; b=oNw3936qpYNhsP97I6au+MR/Pjarw6nOrtMRCn9MHIsDaIZasVVvC9pFTAZqmw24Kt xgtoPmFgShWeDVIaUUXXxJyopeAkwAz+DxFkZybT2TpRpF0HrYKd480pvXyUur4ag5mV zj9wGVRQXY2gBMxU2B4faWfq2rUUIvMQNyp7C5SxznMT1BsgiYteZws5jvxex7RQaD9D UoeN8CYpSMHdvBUx9CU4NLaxMulD3QRNywEISXVIAXxPbYEYZdf09nzcQWyrJRX4i2Fd 9ZZELpKM1yZlu/+NYwTBIk8aPnMXvV7gukSJjCzy8ZReO4aX91F4R9wjjBZkG+KS4fgo UsxA== X-Gm-Message-State: AHYfb5jwdXlVbdy/E4barCXJ/awOCM313cvEvCI1h2JIhkCZzMvF4XaQ hHn7uMlbMRl+eA== X-Received: by 10.28.203.205 with SMTP id b196mr1361487wmg.105.1504104696668; Wed, 30 Aug 2017 07:51:36 -0700 (PDT) Received: from localhost.localdomain (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id f42sm2606306wrf.27.2017.08.30.07.51.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Aug 2017 07:51:35 -0700 (PDT) From: Amir Goldstein To: Eryu Guan Cc: Josef Bacik , "Darrick J . Wong" , Christoph Hellwig , fstests@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH v2 12/14] replay-log: add support for replaying ops in target device sector range Date: Wed, 30 Aug 2017 17:51:44 +0300 Message-Id: <1504104706-11965-13-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504104706-11965-1-git-send-email-amir73il@gmail.com> References: <1504104706-11965-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 Using command line options --start-sector and --end-sector, only operations acting on the specified target device range will be replayed. Single vebbose mode (-v) prints out only replayed operations. Double verbose mode (-vv) prints out also skipped operations. Signed-off-by: Amir Goldstein --- src/log-writes/log-writes.c | 33 +++++++++++++++++++++++++++++++-- src/log-writes/log-writes.h | 2 ++ src/log-writes/replay-log.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/log-writes/log-writes.c b/src/log-writes/log-writes.c index ba66a5c..d832c2a 100644 --- a/src/log-writes/log-writes.c +++ b/src/log-writes/log-writes.c @@ -119,6 +119,24 @@ int log_discard(struct log *log, struct log_write_entry *entry) /* * @log: the log we are replaying. + * @entry: entry to be replayed. + * + * @return: 0 if we should replay the entry, > 0 if we should skip it. + * + * Should we skip the entry in our log or replay onto the replay device. + */ +int log_should_skip(struct log *log, struct log_write_entry *entry) +{ + if (!entry->nr_sectors) + return 0; + if (entry->sector + entry->nr_sectors < log->start_sector || + entry->sector > log->end_sector) + return 1; + return 0; +} + +/* + * @log: the log we are replaying. * @entry: where we put the entry. * @read_data: read the entry data as well, entry must be log->sectorsize sized * if this is set. @@ -137,6 +155,7 @@ int log_replay_next_entry(struct log *log, struct log_write_entry *entry, char *buf; ssize_t ret; off_t offset; + u64 skip = 0; if (log->cur_entry >= log->nr_entries) return 1; @@ -158,9 +177,11 @@ int log_replay_next_entry(struct log *log, struct log_write_entry *entry, } } - if (log_writes_verbose) { + skip = log_should_skip(log, entry); + if (log_writes_verbose > 1 || (log_writes_verbose && !skip)) { offset = lseek(log->logfd, 0, SEEK_CUR); - printf("replaying %d@%llu: sector %llu, size %llu, flags %llu\n", + printf("%s %d@%llu: sector %llu, size %llu, flags %llu\n", + skip ? "skipping" : "replaying", (int)log->cur_entry - 1, offset / log->sectorsize, (unsigned long long)le64_to_cpu(entry->sector), (unsigned long long)size, @@ -173,6 +194,14 @@ int log_replay_next_entry(struct log *log, struct log_write_entry *entry, if (flags & LOG_DISCARD_FLAG) return log_discard(log, entry); + if (skip) { + if (lseek(log->logfd, size, SEEK_CUR) == (off_t)-1) { + fprintf(stderr, "Error seeking in log: %d\n", errno); + return -1; + } + return 0; + } + buf = malloc(size); if (!buf) { fprintf(stderr, "Error allocating buffer %llu entry %llu\n", (unsigned long long)size, (unsigned long long)log->cur_entry - 1); diff --git a/src/log-writes/log-writes.h b/src/log-writes/log-writes.h index 13f98ff..fc84acf 100644 --- a/src/log-writes/log-writes.h +++ b/src/log-writes/log-writes.h @@ -53,6 +53,8 @@ struct log { int replayfd; unsigned long flags; u64 sectorsize; + u64 start_sector; + u64 end_sector; u64 nr_entries; u64 cur_entry; u64 max_zero_size; diff --git a/src/log-writes/replay-log.c b/src/log-writes/replay-log.c index 87c03a2..971974b 100644 --- a/src/log-writes/replay-log.c +++ b/src/log-writes/replay-log.c @@ -20,6 +20,8 @@ enum option_indexes { FSCK, CHECK, START_MARK, + START_SECTOR, + END_SECTOR, }; static struct option long_options[] = { @@ -37,6 +39,8 @@ static struct option long_options[] = { {"fsck", required_argument, NULL, 0}, {"check", required_argument, NULL, 0}, {"start-mark", required_argument, NULL, 0}, + {"start-sector", required_argument, NULL, 0}, + {"end-sector", required_argument, NULL, 0}, { NULL, 0, NULL, 0 }, }; @@ -61,6 +65,12 @@ static void usage(void) "--check\n"); fprintf(stderr, "\t--check [|flush|fua] when to check the " "file system, mush specify --fsck\n"); + fprintf(stderr, "\t--start-sector - replay ops on region " + "from onto \n"); + fprintf(stderr, "\t--end-sector - replay ops on region " + "to onto \n"); + fprintf(stderr, "\t-v or --verbose - print replayed ops\n"); + fprintf(stderr, "\t-vv - print also skipped ops\n"); exit(1); } @@ -120,6 +130,8 @@ int main(int argc, char **argv) struct log_write_entry *entry; u64 stop_flags = 0; u64 start_entry = 0; + u64 start_sector = 0; + u64 end_sector = -1ULL; u64 run_limit = 0; u64 num_entries = 0; u64 check_number = 0; @@ -240,6 +252,22 @@ int main(int argc, char **argv) tmp = NULL; } break; + case START_SECTOR: + start_sector = strtoull(optarg, &tmp, 0); + if (tmp && *tmp != '\0') { + fprintf(stderr, "Invalid sector number\n"); + exit(1); + } + tmp = NULL; + break; + case END_SECTOR: + end_sector = strtoull(optarg, &tmp, 0); + if (tmp && *tmp != '\0') { + fprintf(stderr, "Invalid sector number\n"); + exit(1); + } + tmp = NULL; + break; default: usage(); } @@ -257,6 +285,9 @@ int main(int argc, char **argv) if (!discard) log->flags |= LOG_IGNORE_DISCARD; + log->start_sector = start_sector; + log->end_sector = end_sector; + entry = malloc(log->sectorsize); if (!entry) { fprintf(stderr, "Couldn't allocate buffer\n");