From patchwork Wed Nov 25 10:58:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 7697401 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 662199F1D3 for ; Wed, 25 Nov 2015 10:58:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 73543208DA for ; Wed, 25 Nov 2015 10:58:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 50D62207A2 for ; Wed, 25 Nov 2015 10:58:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752411AbbKYK6g (ORCPT ); Wed, 25 Nov 2015 05:58:36 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:37556 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752387AbbKYK6e (ORCPT ); Wed, 25 Nov 2015 05:58:34 -0500 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id tAPAwVsD029370 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 25 Nov 2015 10:58:31 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.13.8/8.13.8) with ESMTP id tAPAwVfW016227 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Wed, 25 Nov 2015 10:58:31 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id tAPAwUsO029231; Wed, 25 Nov 2015 10:58:30 GMT Received: from arch2.sg.oracle.com (/10.186.101.159) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 25 Nov 2015 02:58:30 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, mike.fleetwood@googlemail.com Subject: [PATCH v3 1/5] btrfs-progs: introduce framework to check kernel supported features Date: Wed, 25 Nov 2015 18:58:15 +0800 Message-Id: <1448449095-8319-1-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1448283378-10579-2-git-send-email-anand.jain@oracle.com> References: <1448283378-10579-2-git-send-email-anand.jain@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In the newer kernel, supported kernel features can be known from /sys/fs/btrfs/features however this interface was introduced only after 3.14, and most the incompatible FS features were introduce before 3.14. This patch proposes to maintain kernel version against the feature list, and so that will be the minimum kernel version needed to use the feature. Further, for features supported later than 3.14 this list can still be updated, so it serves as a repository which can be displayed for easy reference. Signed-off-by: Anand Jain --- v3: Mike pointed out that mixed-bg was from version 2.6.37, update it v2: Check for condition that what happens when we fail to read kernel version. Now the code will fail back to use the default as set by the progs. utils.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- utils.h | 1 + 2 files changed, 76 insertions(+), 5 deletions(-) diff --git a/utils.c b/utils.c index b754686..cc0bdfb 100644 --- a/utils.c +++ b/utils.c @@ -32,10 +32,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include "kerncompat.h" @@ -567,21 +569,28 @@ out: return ret; } +/* + * min_ker_ver: update with minimum kernel version at which the feature + * was integrated into the mainline. For the transit period, that is + * feature not yet in mainline but in mailing list and for testing, + * please use "0.0" to indicate the same. + */ static const struct btrfs_fs_feature { const char *name; u64 flag; const char *desc; + const char *min_ker_ver; } mkfs_features[] = { { "mixed-bg", BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS, - "mixed data and metadata block groups" }, + "mixed data and metadata block groups", "2.7.37"}, { "extref", BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF, - "increased hardlink limit per file to 65536" }, + "increased hardlink limit per file to 65536", "3.7"}, { "raid56", BTRFS_FEATURE_INCOMPAT_RAID56, - "raid56 extended format" }, + "raid56 extended format", "3.9"}, { "skinny-metadata", BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA, - "reduced-size metadata extent refs" }, + "reduced-size metadata extent refs", "3.10"}, { "no-holes", BTRFS_FEATURE_INCOMPAT_NO_HOLES, - "no explicit hole extents for files" }, + "no explicit hole extents for files", "3.14"}, /* Keep this one last */ { "list-all", BTRFS_FEATURE_LIST_ALL, NULL } }; @@ -3077,3 +3086,64 @@ unsigned int get_unit_mode_from_arg(int *argc, char *argv[], int df_mode) return unit_mode; } + +static int version_to_code(char *v) +{ + int i = 0; + char *b[3] = {NULL}; + char *save_b = NULL; + + for (b[i] = strtok_r(v, ".", &save_b); + b[i] != NULL; + b[i] = strtok_r(NULL, ".", &save_b)) + i++; + + if (b[2] == NULL) + return KERNEL_VERSION(atoi(b[0]), atoi(b[1]), 0); + else + return KERNEL_VERSION(atoi(b[0]), atoi(b[1]), atoi(b[2])); + +} + +static int get_kernel_code() +{ + int ret; + struct utsname utsbuf; + char *version; + + ret = uname(&utsbuf); + if (ret) + return -ret; + + if (!strlen(utsbuf.release)) + return -EINVAL; + + version = strtok(utsbuf.release, "-"); + + return version_to_code(version); +} + +u64 btrfs_features_allowed_by_kernel(void) +{ + int i; + int local_kernel_code = get_kernel_code(); + u64 features = 0; + + /* + * When system did not provide the kernel version then just + * return 0, the caller has to depend on the intelligence as + * per btrfs-progs version + */ + if (local_kernel_code <= 0) + return 0; + + for (i = 0; i < ARRAY_SIZE(mkfs_features) - 1; i++) { + char *ver = strdup(mkfs_features[i].min_ker_ver); + + if (local_kernel_code >= version_to_code(ver)) + features |= mkfs_features[i].flag; + + free(ver); + } + return (features); +} diff --git a/utils.h b/utils.h index 192f3d1..9044643 100644 --- a/utils.h +++ b/utils.h @@ -104,6 +104,7 @@ void btrfs_list_all_fs_features(u64 mask_disallowed); char* btrfs_parse_fs_features(char *namelist, u64 *flags); void btrfs_process_fs_features(u64 flags); void btrfs_parse_features_to_string(char *buf, u64 flags); +u64 btrfs_features_allowed_by_kernel(void); struct btrfs_mkfs_config { char *label;