From patchwork Fri Jan 18 09:44:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shinichiro Kawasaki X-Patchwork-Id: 10769627 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33DD714E5 for ; Fri, 18 Jan 2019 09:45:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 227322A1B1 for ; Fri, 18 Jan 2019 09:45:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 168172A9CB; Fri, 18 Jan 2019 09:45:45 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 9DC1C2A2D0 for ; Fri, 18 Jan 2019 09:45:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726288AbfARJpo (ORCPT ); Fri, 18 Jan 2019 04:45:44 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:8856 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725898AbfARJpn (ORCPT ); Fri, 18 Jan 2019 04:45:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1547804744; x=1579340744; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=abHhg2wcbdF25eLMhxDmHJ2SklmyEaucqIIwjuf8MIk=; b=GqPdo8Weze7wYpem/2izQAcZEJ1ln+IkN/Z61ZF9ZUQyVbDfTZzIya6u s5Ux6vvD5gim+n2R9HYWpQMHA/T6+brfRTNRZhkqxDKQpw6zR5CTKwYGM 9FY2orTQSuI/uYPGQRStFpbDp7c0QnmuBG1kandtxggZBCD08f507ue8K dNlb0O655RB9Xyo6fj9OuGNAemm8MgP2BobFN+segtrwy2CCoQNKloPIc qNJWrbhy2bkWtUaFJEJJIfRxurlEMs9nB7ZXJqBzM86GLUmI+cMyKUgd9 bcvPszqXnWnt4U7dhHn3K7cl4CAN+3bIDObT/zJdnIU2Ugf1HbEUVXeJC g==; X-IronPort-AV: E=Sophos;i="5.56,489,1539619200"; d="scan'208";a="99182297" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 18 Jan 2019 17:45:29 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 18 Jan 2019 01:26:47 -0800 Received: from shin_dev.dhcp.fujisawa.hgst.com (HELO shin_dev.fujisawa.hgst.com) ([10.149.52.166]) by uls-op-cesaip02.wdc.com with ESMTP; 18 Jan 2019 01:45:26 -0800 From: Shin'ichiro Kawasaki To: linux-block@vger.kernel.org, Omar Sandoval , Masato Suzuki , Shinichiro Kawasaki Cc: Omar Sandoval , Jens Axboe , Matias Bjorling , Hannes Reinecke , Mike Snitzer , "Martin K . Petersen" , Chaitanya Kulkarni Subject: [PATCH blktests v3 07/13] src: Introduce zbdioctl program Date: Fri, 18 Jan 2019 18:44:47 +0900 Message-Id: <20190118094453.13773-8-shinichiro.kawasaki@wdc.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190118094453.13773-1-shinichiro.kawasaki@wdc.com> References: <20190118094453.13773-1-shinichiro.kawasaki@wdc.com> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP zbdioctl implements calls to zoned block devices ioctls that are not supported currently by sys-utils blkzone utility, namely BLKGETZONESZ and BLKGETNRZONES. Reviewed-by: Chaitanya Kulkarni Signed-off-by: Shin'ichiro Kawasaki --- src/.gitignore | 1 + src/Makefile | 3 +- src/zbdioctl.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/zbdioctl.c diff --git a/src/.gitignore b/src/.gitignore index 8c95785..2108f56 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -6,3 +6,4 @@ /nbdsetsize /sg/dxfer-from-dev /sg/syzkaller1 +/zbdioctl diff --git a/src/Makefile b/src/Makefile index c4094b4..5a0556f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,7 +5,8 @@ C_TARGETS := \ sg/dxfer-from-dev \ sg/syzkaller1 \ nbdsetsize \ - loop_change_fd + loop_change_fd \ + zbdioctl CXX_TARGETS := \ discontiguous-io diff --git a/src/zbdioctl.c b/src/zbdioctl.c new file mode 100644 index 0000000..1ea72e8 --- /dev/null +++ b/src/zbdioctl.c @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: GPL-3.0+ +// Copyright (C) 2018 Western Digital Corporation or its affiliates. +#include +#include +#include +#include +#include +#include +#include +#include + +#if !defined(BLKGETZONESZ) || !defined(BLKGETNRZONES) + +int main(int argc, char **argv) +{ + return EXIT_FAILURE; +} + +#else + +struct request { + const char *name; + unsigned long code; +} requests[] = { + { "-s", BLKGETZONESZ}, + { "-n", BLKGETNRZONES}, + { NULL, 0}, +}; + +void usage(const char *progname) +{ + int i = 0; + + fprintf(stderr, "usage: %s \n", progname); + fprintf(stderr, " can be:\n"); + while (requests[i].name) { + fprintf(stderr, "\t%s\n", requests[i].name); + i++; + } + exit(EXIT_FAILURE); +} + +int main(int argc, char **argv) +{ + int i = 0, fd, ret; + unsigned int val; + unsigned long code = 0; + + if (argc != 3) + usage(argv[0]); + + while (requests[i].name) { + if (strcmp(argv[1], requests[i].name) == 0) { + code = requests[i].code; + break; + } + i++; + } + if (code == 0) + usage(argv[0]); + + fd = open(argv[2], O_RDWR); + if (fd < 0) { + perror("open"); + return EXIT_FAILURE; + } + + ret = ioctl(fd, code, &val); + if (ret < 0) { + perror("ioctl"); + close(fd); + return EXIT_FAILURE; + } + + printf("%u\n", val); + + close(fd); + + return EXIT_SUCCESS; +} + +#endif +