From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2B9FC433F5 for ; Tue, 8 Feb 2022 19:34:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386135AbiBHTeZ (ORCPT ); Tue, 8 Feb 2022 14:34:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236908AbiBHTeX (ORCPT ); Tue, 8 Feb 2022 14:34:23 -0500 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29BDFC0612C0 for ; Tue, 8 Feb 2022 11:34:21 -0800 (PST) Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 218E6xtZ013398 for ; Tue, 8 Feb 2022 11:34:21 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=ym0eYPc+/3BSXFxHlf6MCDJYer0+6GkZA5M0cn96aec=; b=FRLXCZoYTQDP8I1w4P6a7N1ciEXBZsZzrTrnm+slOf1Uo33zoh8LKuhehqexZjEZehdV A6/CaX806ypDRfvjUIWyqJov4cYu1ZGbqP/aXybv/5kcM5hfG3kJxaxDZc+t9MXc9+G6 tXsB5j2E9LAwFkNo2hhVZwWhuDnIFUm31WM= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3e3puw3pvy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 08 Feb 2022 11:34:20 -0800 Received: from twshared18912.14.frc2.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:11d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 8 Feb 2022 11:34:19 -0800 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 44ADDA7B542A; Tue, 8 Feb 2022 11:31:25 -0800 (PST) From: Stefan Roesch To: , CC: Subject: [PATCH v1 3/3] btrfs: add force_chunk_alloc sysfs entry to force allocation Date: Tue, 8 Feb 2022 11:31:22 -0800 Message-ID: <20220208193122.492533-4-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220208193122.492533-1-shr@fb.com> References: <20220208193122.492533-1-shr@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: aklaHB2uV1JuURkg8CcuAllc8JFLkd0r X-Proofpoint-ORIG-GUID: aklaHB2uV1JuURkg8CcuAllc8JFLkd0r X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_06,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=fb_outbound_notspam policy=fb_outbound score=0 malwarescore=0 mlxlogscore=999 phishscore=0 mlxscore=0 suspectscore=0 lowpriorityscore=0 bulkscore=0 spamscore=0 priorityscore=1501 impostorscore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080114 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This adds the force_chunk_alloc sysfs entry to be able to force a storage allocation. This is a debugging and test feature and is enabled with the CONFIG_BTRFS_DEBUG configuration option. It is stored at /sys/fs/btrfs//allocation//force_chunk_alloc. Signed-off-by: Stefan Roesch --- fs/btrfs/sysfs.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index ca337117f15b..4f4f038bc261 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -62,6 +62,10 @@ struct raid_kobject { .store =3D _store, \ } =20 +#define BTRFS_ATTR_W(_prefix, _name, _store) \ + static struct kobj_attribute btrfs_attr_##_prefix##_##_name =3D \ + __INIT_KOBJ_ATTR(_name, 0200, NULL, _store) + #define BTRFS_ATTR_RW(_prefix, _name, _show, _store) \ static struct kobj_attribute btrfs_attr_##_prefix##_##_name =3D \ __INIT_KOBJ_ATTR(_name, 0644, _show, _store) @@ -785,6 +789,54 @@ static ssize_t btrfs_chunk_size_store(struct kobject= *kobj, return val; } =20 +#ifdef CONFIG_BTRFS_DEBUG +/* + * Request chunk allocation with current chunk size. + */ +static ssize_t btrfs_force_chunk_alloc_store(struct kobject *kobj, + struct kobj_attribute *a, + const char *buf, size_t len) +{ + struct btrfs_space_info *space_info =3D to_space_info(kobj); + struct btrfs_fs_info *fs_info =3D to_fs_info(get_btrfs_kobj(kobj)); + struct btrfs_trans_handle *trans; + unsigned long val; + int ret; + + if (!fs_info) { + pr_err("couldn't get fs_info\n"); + return -EPERM; + } + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + if (sb_rdonly(fs_info->sb)) + return -EROFS; + + ret =3D kstrtoul(buf, 10, &val); + if (ret) + return ret; + + if (val =3D=3D 0) + return -EINVAL; + + /* + * Allocate new chunk. + */ + trans =3D btrfs_start_transaction(fs_info->tree_root, 0); + if (!trans) + return PTR_ERR(trans); + ret =3D btrfs_force_chunk_alloc(trans, space_info->flags); + btrfs_end_transaction(trans); + + if (ret =3D=3D 1) + return len; + + return -ENOSPC; +} +#endif + SPACE_INFO_ATTR(flags); SPACE_INFO_ATTR(total_bytes); SPACE_INFO_ATTR(bytes_used); @@ -797,6 +849,9 @@ SPACE_INFO_ATTR(disk_used); SPACE_INFO_ATTR(disk_total); BTRFS_ATTR_RW(space_info, chunk_size, btrfs_chunk_size_show, btrfs_chunk_size_store); +#ifdef CONFIG_BTRFS_DEBUG +BTRFS_ATTR_W(space_info, force_chunk_alloc, btrfs_force_chunk_alloc_stor= e); +#endif =20 /* * Allocation information about block group types. @@ -815,6 +870,9 @@ static struct attribute *space_info_attrs[] =3D { BTRFS_ATTR_PTR(space_info, disk_used), BTRFS_ATTR_PTR(space_info, disk_total), BTRFS_ATTR_PTR(space_info, chunk_size), +#ifdef CONFIG_BTRFS_DEBUG + BTRFS_ATTR_PTR(space_info, force_chunk_alloc), +#endif NULL, }; ATTRIBUTE_GROUPS(space_info); --=20 2.30.2