From patchwork Thu Jul 12 08:56:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 942857 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41R8rq69ZPz9rxs for ; Thu, 12 Jul 2018 18:54:49 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 3D4183E69EB for ; Thu, 12 Jul 2018 10:54:45 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) by picard.linux.it (Postfix) with ESMTP id 5317B3E675C for ; Thu, 12 Jul 2018 10:54:42 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-7.smtp.seeweb.it (Postfix) with ESMTP id 3DFA42011C8 for ; Thu, 12 Jul 2018 10:54:40 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="42164007" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 Jul 2018 16:54:38 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 23A224B473EC for ; Thu, 12 Jul 2018 16:54:34 +0800 (CST) Received: from RHEL7U5Alpha_SERVER.g08.fujitsu.local (10.167.220.156) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.399.0; Thu, 12 Jul 2018 16:54:33 +0800 From: Xiao Yang To: Date: Thu, 12 Jul 2018 16:56:50 +0800 Message-ID: <1531385810-22036-1-git-send-email-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.167.220.156] X-yoursite-MailScanner-ID: 23A224B473EC.A7F74 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com X-Spam-Status: No, score=0.0 required=7.0 tests=none autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH] zram/zram03.c: Fix obsolete zram status files X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Since kernel commit c87d1655c295, separate zram status files("compr_data_size", "num_reads" etc.) which can be accessed via one of zram/stat or zram/io_stat or zram/mm_stat were removed. This commit broke zram03, as below: ---------------------------------------------------------------------- safe_file_ops.c:144: Failed to open FILE '/sys/block/zram0/compr_data_size' for reading at zram03.c:181: errno=ENOENT(2): No such file or directory ---------------------------------------------------------------------- Also, zero pages in zram/mm_stat was extended to same element pages since kernel commit 8e19d540d107. We try to get requested zram status by zram/stat and zram/mm_stat if separate zram status files don't exist. URL for detailed zram status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/blockdev/zram.txt https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/block/stat.txt Signed-off-by: Xiao Yang --- testcases/kernel/device-drivers/zram/zram03.c | 50 +++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/testcases/kernel/device-drivers/zram/zram03.c b/testcases/kernel/device-drivers/zram/zram03.c index 3f7ab4e..06995fd 100644 --- a/testcases/kernel/device-drivers/zram/zram03.c +++ b/testcases/kernel/device-drivers/zram/zram03.c @@ -40,6 +40,9 @@ char *TCID = "zram03"; int TST_TOTAL = 1; #define PATH_ZRAM "/sys/block/zram0" +#define OBSOLETE_ZRAM_FILE "/sys/block/zram0/num_reads" +#define PATH_ZRAM_STAT "/sys/block/zram0/stat" +#define PATH_ZRAM_MM_STAT "/sys/block/zram0/mm_stat" #define SIZE (512 * 1024 * 1024L) #define DEVICE "/dev/zram0" @@ -182,14 +185,49 @@ static void print(char *string) tst_resm(TINFO, "%s is %s", filename, value); } +static void print_stat(char *nread, char *nwrite) +{ + char nread_val[BUFSIZ], nwrite_val[BUFSIZ]; + + SAFE_FILE_SCANF(cleanup, PATH_ZRAM_STAT, "%s %*s %*s %*s %s", + nread_val, nwrite_val); + tst_resm(TINFO, "%s from %s is %s", nread, PATH_ZRAM_STAT, + nread_val); + tst_resm(TINFO, "%s from %s is %s", nwrite, PATH_ZRAM_STAT, + nwrite_val); +} + +static void print_mm_stat(char *orig, char *compr, char *mem, char *zero) +{ + char orig_val[BUFSIZ], compr_val[BUFSIZ]; + char mem_val[BUFSIZ], zero_val[BUFSIZ]; + + SAFE_FILE_SCANF(cleanup, PATH_ZRAM_MM_STAT, "%s %s %s %*s %*s %s", + orig_val, compr_val, mem_val, zero_val); + tst_resm(TINFO, "%s from %s is %s", orig, PATH_ZRAM_MM_STAT, + orig_val); + tst_resm(TINFO, "%s from %s is %s", compr, PATH_ZRAM_MM_STAT, + compr_val); + tst_resm(TINFO, "%s from %s is %s", mem, PATH_ZRAM_MM_STAT, + mem_val); + tst_resm(TINFO, "%s from %s is %s", zero, PATH_ZRAM_MM_STAT, + zero_val); +} + static void dump_info(void) { print("initstate"); - print("compr_data_size"); - print("orig_data_size"); print("disksize"); - print("mem_used_total"); - print("num_reads"); - print("num_writes"); - print("zero_pages"); + if (!access(OBSOLETE_ZRAM_FILE, F_OK)) { + print("orig_data_size"); + print("compr_data_size"); + print("mem_used_total"); + print("zero_pages"); + print("num_reads"); + print("num_writes"); + } else { + print_mm_stat("orig_data_size", "compr_data_size", + "mem_used_total", "zero/same_pages"); + print_stat("num_reads", "num_writes"); + } }