From patchwork Thu Jan 10 09:37:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shin'ichiro Kawasaki X-Patchwork-Id: 10755453 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 B9AF31515 for ; Thu, 10 Jan 2019 09:38:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB4C5292A2 for ; Thu, 10 Jan 2019 09:38:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DF6F292BD; Thu, 10 Jan 2019 09:38:08 +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 41437292DA for ; Thu, 10 Jan 2019 09:38:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727956AbfAJJiH (ORCPT ); Thu, 10 Jan 2019 04:38:07 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:25565 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727934AbfAJJiH (ORCPT ); Thu, 10 Jan 2019 04:38:07 -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=1547113091; x=1578649091; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=z8Pb2zTInRMN1PR/pXA6dcbSKZE+cS0z7wrOF+mM2Po=; b=ZuAy79YyDEtfvrawvpEvNhYwscJylNL8Iqqfac90Uf6t4aFiNG8IY2Vx lZVOD/XDnP8zohRwFs0r9RTTKIUtj9n+htyfyDGh+3EGwjucN0umuPyxm WgwcyAyofdmYaJ0v2HD/AD9ZrXN64UTNlIK346qhs2hJmYF8IHUkg3veZ 1cc2TIIBc6Qybppy4ke0TcHYnLoMkKvLHZJCec7J2UNyWpzm5Rbl8m+Vg nVF8fwHVhv29qa+gIcsKUr8zZkvpCNdJaOtx6tOxTkqawS39O1bfJhC8d QsyDW4BvK/aETiHzqVPqes+w7aNIX4bV/3sVAhojWe3xjzt7yYxXULAuW w==; X-IronPort-AV: E=Sophos;i="5.56,460,1539619200"; d="scan'208";a="196468997" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Jan 2019 17:38:10 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP; 10 Jan 2019 01:19:38 -0800 Received: from shin_dev.dhcp.fujisawa.hgst.com (HELO shin_dev.fujisawa.hgst.com) ([10.149.52.166]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Jan 2019 01:38:04 -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 v2 09/16] src: Introduce zbdioctl program Date: Thu, 10 Jan 2019 18:37:18 +0900 Message-Id: <20190110093725.32675-10-shinichiro.kawasaki@wdc.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190110093725.32675-1-shinichiro.kawasaki@wdc.com> References: <20190110093725.32675-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. 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 +