From patchwork Wed Jun 13 22:50:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10462993 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 E9D4360329 for ; Wed, 13 Jun 2018 22:51:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB19B28CEE for ; Wed, 13 Jun 2018 22:51:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFAF328CF5; Wed, 13 Jun 2018 22:51:07 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY 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 5712728CEE for ; Wed, 13 Jun 2018 22:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935724AbeFMWvD (ORCPT ); Wed, 13 Jun 2018 18:51:03 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:56516 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935719AbeFMWvC (ORCPT ); Wed, 13 Jun 2018 18:51:02 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w5DMiYsq136442; Wed, 13 Jun 2018 22:51:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2017-10-26; bh=g12uuFknfXlHLRs5ij/S72DXnI4KXu2DUMAkxzSVrSA=; b=VCN090MQ4GbhHYvvb5mC5yfgFNKUKmFQLm4OXRsvzwTrW70b1OFi/XEVKELIz8dE8/sI 0iJMgWmpl0rQfFCsyRZRIbPNBcs6tWLE6p7q2NJ90gPG9ImBiThbzAv282rhTGKB36Xy dpqJCsCY0Nrxv3bnX6qchNopu7ooqEfyOVDNHCFmliQyWVh9cqsxnMF4BZcQPaEg1RCn 9IczvQBQKZsLCOv9akf6rBr4gE7cL6gYU51xbX3L95w/D/yA/Ixdd739OakOSwepVA2i xP/TLB7GD78w8R0YPFy6glo7v0DloGqAvXDUnfuF8U69dgFhJhXqRvv8Tm6udd09Sr6e 6A== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2jk0xrjn1m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Jun 2018 22:51:00 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w5DMoxmk018019 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Jun 2018 22:50:59 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w5DMowpX013058; Wed, 13 Jun 2018 22:50:58 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 13 Jun 2018 15:50:58 -0700 Date: Wed, 13 Jun 2018 15:50:57 -0700 From: "Darrick J. Wong" To: Eryu Guan Cc: fstests , xfs , Ross Zwisler Subject: [PATCH] generic/223: port t_stripealign to FIEMAP Message-ID: <20180613225057.GB9432@magnolia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8923 signatures=668702 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806130243 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Since XFS has deprecated FIBMAP on FSDAX filesystems, we can't use FIBMAP to verify stripe alignment anymore. FIEMAP has existed for quite some time now, so port it to use that instead, and only fall back to FIBMAP if FIEMAP doesn't exist. Tested-by: ross.zwisler@linux.intel.com Signed-off-by: Darrick J. Wong --- src/t_stripealign.c | 72 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 11 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe fstests" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/src/t_stripealign.c b/src/t_stripealign.c index 05ed36b5..690f743a 100644 --- a/src/t_stripealign.c +++ b/src/t_stripealign.c @@ -17,8 +17,13 @@ #include #include #include +#include +#include -#define FIBMAP _IO(0x00, 1) /* bmap access */ +#define FIEMAP_EXTENT_ACCEPTABLE (FIEMAP_EXTENT_LAST | \ + FIEMAP_EXTENT_DATA_ENCRYPTED | FIEMAP_EXTENT_ENCODED | \ + FIEMAP_EXTENT_UNWRITTEN | FIEMAP_EXTENT_MERGED | \ + FIEMAP_EXTENT_SHARED) /* * If only filename given, print first block. @@ -28,11 +33,14 @@ int main(int argc, char ** argv) { - int fd; - int ret; - int sunit = 0; /* in blocks */ - char *filename; - unsigned int block = 0; + struct stat sb; + struct fiemap *fie; + struct fiemap_extent *fe; + int fd; + int ret; + int sunit = 0; /* in blocks */ + char *filename; + unsigned long long block; if (argc < 3) { printf("Usage: %s \n", argv[0]); @@ -48,21 +56,63 @@ int main(int argc, char ** argv) return 1; } - ret = ioctl(fd, FIBMAP, &block); - if (ret < 0) { + ret = fstat(fd, &sb); + if (ret) { + perror(filename); close(fd); - perror("fibmap"); return 1; } - close(fd); + fie = calloc(1, sizeof(struct fiemap) + sizeof(struct fiemap_extent)); + if (!fie) { + close(fd); + perror("malloc"); + return 1; + } + fie->fm_length = 1; + fie->fm_flags = FIEMAP_FLAG_SYNC; + fie->fm_extent_count = 1; + + ret = ioctl(fd, FS_IOC_FIEMAP, fie); + if (ret < 0) { + unsigned int bmap = 0; + + ret = ioctl(fd, FIBMAP, &bmap); + if (ret < 0) { + perror("fibmap"); + free(fie); + close(fd); + return 1; + } + block = bmap; + goto check; + } + + if (fie->fm_mapped_extents != 1) { + printf("%s: no extents?\n", filename); + free(fie); + close(fd); + return 1; + } + fe = &fie->fm_extents[0]; + if (fe->fe_flags & ~FIEMAP_EXTENT_ACCEPTABLE) { + printf("%s: bad flags 0x%x\n", filename, fe->fe_flags); + free(fie); + close(fd); + return 1; + } + + block = fie->fm_extents[0].fe_physical / sb.st_blksize; +check: if (block % sunit) { - printf("%s: Start block %u not multiple of sunit %u\n", + printf("%s: Start block %llu not multiple of sunit %u\n", filename, block, sunit); return 1; } else printf("%s: well-aligned\n", filename); + free(fie); + close(fd); return 0; }