From patchwork Wed Jun 13 19:32:11 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: 10462855 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 8F80C60348 for ; Wed, 13 Jun 2018 19:32:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BA9128FA8 for ; Wed, 13 Jun 2018 19:32:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7053D28FCD; Wed, 13 Jun 2018 19:32:34 +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 E617928FA8 for ; Wed, 13 Jun 2018 19:32:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935202AbeFMTcd (ORCPT ); Wed, 13 Jun 2018 15:32:33 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:56896 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934978AbeFMTcc (ORCPT ); Wed, 13 Jun 2018 15:32:32 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w5DJSo1F160994; Wed, 13 Jun 2018 19:32:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=cxaOyfoxOb+Ob5N3ZC+Trsuhco74Iok1eFemmzpeXxU=; b=RLKM08qNi0O9cavVc1OBXWtcHwVBqUkdjGSMK3iUb8UWnmyWiQF1uAw/hI2g2VlTjfdj vl9AHyGyA9Z6aoNoo0r/OqVHiCo2d8Xf7+z4XqORcT6kHh+rZ44QW0cMEwbfedGGODqE Rfv1D+yzM7/XpHHRhpQ7pxz9/H0JIp1iS/T3U/oBA7jSr5fOyWSsx75wfAH93J3i2Msu 8fCqNEqTrbavXYJRaCx3h3Ia3yzsLfoxqd7RlmINLiXkcyncZJEaFUlHl+H8X+lUavOR AtVdkpKx0Kh1j+bBrw7fLX54pfEzKuVpmLaaiADF1h8hh42bDzDZf2fBH0as4Ztj9bYo aQ== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2jk0xra4p6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Jun 2018 19:32:20 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w5DJWJQl030220 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Jun 2018 19:32:19 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w5DJWHeR019813; Wed, 13 Jun 2018 19:32:17 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 13 Jun 2018 12:32:17 -0700 Subject: [PATCH 4/5] mkfs: emit config file from builtin defaults From: "Darrick J. Wong" To: sandeen@redhat.com, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Wed, 13 Jun 2018 12:32:11 -0700 Message-ID: <152891833127.3968.5527165230597489132.stgit@magnolia> In-Reply-To: <152891829964.3968.4760134019673731615.stgit@magnolia> References: <152891829964.3968.4760134019673731615.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8923 signatures=668702 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 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-1806130206 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Create a build-time helper program to generate a config file from the built-in defaults. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen --- mkfs/Makefile | 14 ++++- mkfs/mkconfig.c | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 mkfs/mkconfig.c -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" 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/mkfs/Makefile b/mkfs/Makefile index 102f5214..44ddbd30 100644 --- a/mkfs/Makefile +++ b/mkfs/Makefile @@ -12,13 +12,24 @@ CFILES = proto.c xfs_mkfs.c config.c defaults.c CFGFILE_CFLAGS = -DMKFS_XFS_CONF_DIR=\"$(PKG_MKFS_CFG_DIR)\" \ -DMKFS_XFS_DEFAULT_CONFIG=\"$(PKG_MKFS_DEFAULT_CFGFILE)\" +CFGFILE_TEMPLATE = $(PKG_MKFS_DEFAULT_CFGFILE).template + LCFLAGS += $(CFGFILE_CFLAGS) LLDLIBS += $(LIBXFS) $(LIBXCMD) $(LIBFROG) $(LIBRT) $(LIBPTHREAD) $(LIBBLKID) \ $(LIBUUID) LTDEPENDENCIES += $(LIBXFS) $(LIBXCMD) $(LIBFROG) LLDFLAGS = -static-libtool-libs +LDIRT = $(CFGFILE_TEMPLATE) + +default: depend $(CFGFILE_TEMPLATE) $(LTCOMMAND) + +mkconfig: mkconfig.c defaults.c + @echo " [CC] mkconfig" + $(Q) $(BUILD_CC) $(BUILD_CFLAGS) $(CFGFILE_CFLAGS) -o $@ $^ -default: depend $(LTCOMMAND) +$(CFGFILE_TEMPLATE): mkconfig + @echo " [GENERATE] $@" + $(Q) ./mkconfig > $@ include $(BUILDRULES) @@ -27,6 +38,7 @@ install: default $(LTINSTALL) -m 755 $(LTCOMMAND) $(PKG_ROOT_SBIN_DIR) $(INSTALL) -m 755 -d $(PKG_CFG_DIR) $(INSTALL) -m 755 -d $(PKG_MKFS_CFG_DIR) + $(INSTALL) -m 644 $(CFGFILE_TEMPLATE) $(PKG_MKFS_CFG_DIR) install-dev: -include .dep diff --git a/mkfs/mkconfig.c b/mkfs/mkconfig.c new file mode 100644 index 00000000..3826b0bf --- /dev/null +++ b/mkfs/mkconfig.c @@ -0,0 +1,163 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#include "libxfs.h" +#include "config.h" + +enum cfgfile_var_type { + FV_BOOL = 0 +}; + +struct subopt_map { + const char *suboptname; + const void *ptr; + enum cfgfile_var_type type; +}; + +/* Map all the config file options to their default_features equivalents. */ +struct confopts { + const char *name; + struct subopt_map subopts[CFG_MAX_SUBOPTS]; +} confopts_tab[] = { + { + .name = "data", + .subopts = { + [CFG_D_NOALIGN] = { + .suboptname = "noalign", + .ptr = &default_features.nodalign, + .type = FV_BOOL, + }, + {NULL} + }, + }, + { + .name = "inode", + .subopts = { + [CFG_I_ALIGN] = { + .suboptname = "align", + .ptr = &default_features.inode_align, + .type = FV_BOOL, + }, + [CFG_I_PROJID32BIT] = { + .suboptname = "projid32bit", + .ptr = &default_features.projid32bit, + .type = FV_BOOL, + }, + [CFG_I_SPINODES] = { + .suboptname = "sparse", + .ptr = &default_features.spinodes, + .type = FV_BOOL, + }, + {NULL} + }, + }, + { + .name = "log", + .subopts = { + [CFG_L_LAZYSBCNTR] = { + .suboptname = "lazy-count", + .ptr = &default_features.lazy_sb_counters, + .type = FV_BOOL, + }, + {NULL} + }, + }, + { + .name = "metadata", + .subopts = { + [CFG_M_CRC] = { + .suboptname = "crc", + .ptr = &default_features.crcs_enabled, + .type = FV_BOOL, + }, + [CFG_M_FINOBT] = { + .suboptname = "finobt", + .ptr = &default_features.finobt, + .type = FV_BOOL, + }, + [CFG_M_RMAPBT] = { + .suboptname = "rmapbt", + .ptr = &default_features.rmapbt, + .type = FV_BOOL, + }, + [CFG_M_REFLINK] = { + .suboptname = "reflink", + .ptr = &default_features.reflink, + .type = FV_BOOL, + }, + {NULL} + }, + }, + { + .name = "naming", + .subopts = { + [CFG_N_FTYPE] = { + .suboptname = "ftype", + .ptr = &default_features.dirftype, + .type = FV_BOOL, + }, + {NULL} + }, + }, + { + .name = "rtdev", + .subopts = { + [CFG_R_NOALIGN] = { + .suboptname = "noalign", + .ptr = &default_features.nortalign, + .type = FV_BOOL, + }, + {NULL} + }, + }, +}; + +/* Spit out a config file template. */ +int +main( + int argc, + char *argv[]) +{ + struct confopts *opts = confopts_tab; + struct subopt_map *submap; + int c; + unsigned int i, j; + + while ((c = getopt(argc, argv, "")) != EOF) { + switch (c) { + case '?': + fprintf(stderr, "Unknown option %c.\n", optopt); + return 1; + } + } + if (argc - optind != 0) { + fprintf(stderr, "extra arguments\n"); + return 1; + } + + printf("# mkfs.xfs configuration file to collect settings.\n"); + printf("# See the mkfs.xfs(8) manpage for details.\n"); + printf("# Copy this file to %s/%s to override the built-in defaults.\n", + MKFS_XFS_CONF_DIR, MKFS_XFS_DEFAULT_CONFIG); + + for (i = 0; i < ARRAY_SIZE(confopts_tab); i++, opts++) { + if (i > 0) + printf("\n"); + printf("[%s]\n", opts->name); + submap = opts->subopts; + for (j = 0; + j < ARRAY_SIZE(opts->subopts) && submap->suboptname; + j++, submap++) { + printf("%s = ", submap->suboptname); + switch (submap->type) { + case FV_BOOL: + printf("%d\n", *((bool *)submap->ptr)); + break; + } + } + } + + return 0; +}