From patchwork Mon Apr 3 08:47:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13197808 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72068C76196 for ; Mon, 3 Apr 2023 08:48:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D4F56B0072; Mon, 3 Apr 2023 04:48:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 05CE76B0074; Mon, 3 Apr 2023 04:48:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E19636B0075; Mon, 3 Apr 2023 04:48:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CE0216B0072 for ; Mon, 3 Apr 2023 04:48:18 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 91526ABDE3 for ; Mon, 3 Apr 2023 08:48:18 +0000 (UTC) X-FDA: 80639453076.13.995C25B Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id D7895A000F for ; Mon, 3 Apr 2023 08:48:16 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=VOVUClk0; spf=pass (imf15.hostedemail.com: domain of cem@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cem@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680511696; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=C71pWMy4jbYBxZot5uSQLjx5KowzEZh2qlPuFcp0qkg=; b=S3q10AH0tQTDWJqnaT3E4vndb5pi6dtLT8SaM4Fu6a74am6VrHF/XlvXfeGyoL8BSz8IqB k/o3J+zYNHFj/+2iEwV1hIHTPpXDjAhEqqXJluK+pj/ArLRpj0sxLkO/X0BL6BRWegjidS qGsu+ie/1MXntOU7+kccLdBm/sNH/10= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=VOVUClk0; spf=pass (imf15.hostedemail.com: domain of cem@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cem@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680511696; a=rsa-sha256; cv=none; b=LCdSxxlH+hDM7Rs7cCAtvAxhT1ZuVxkj64yuh4+3warVo0yeAcnxBH+RLpsIeB1lmKOPim f+saE1TLZq6Jr51VeL/eoDah3o3cShqToVdSU8qwJLzL312orF2zmacDEO8o7BQIDsUftW yojk64SEG4qDLP4nID+sxLQWgTPn48w= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D51B860F5A; Mon, 3 Apr 2023 08:48:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6B30C4339C; Mon, 3 Apr 2023 08:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680511695; bh=+0zQcAzsOXQwjktjWL0vkvwn0ez4Qoz15/Uz4pSYjMA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VOVUClk0KIZTDvpV3mvscFtpPF2E9p2tSjwXXXd55omX9+Sfl9gFfAWAZmnCJ8kqJ FxLGZtvPAUrXSVeV7xmWw6dWcj/NjHCCyhwJrkB5ZGVgRZXF7cKRpcqbZqwv9HE/Yj r44b6K6TLCdBm2O5W/xRmSIuu847/MGlQJyDQbZIbalse40bineyZYJc02fS/00J2f rDYithEgtWpu8kQ/IRRVEL/cnARFe6+xobqFzCf1DZuE8siuUrspndsHw9PpshtPgv ZXmX35H4eoi77BDXgPX6dim4BEdyK5CK0aISXVTRslWBmKhDm/03ApltyBev1YNESx gXMRZcHXp811g== From: cem@kernel.org To: hughd@google.com Cc: jack@suse.cz, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, djwong@kernel.org Subject: [PATCH 1/6] shmem: make shmem_inode_acct_block() return error Date: Mon, 3 Apr 2023 10:47:54 +0200 Message-Id: <20230403084759.884681-2-cem@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230403084759.884681-1-cem@kernel.org> References: <20230403084759.884681-1-cem@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D7895A000F X-Stat-Signature: oxf7w93c3apfcecign44dc8ps7daqqiu X-Rspam-User: X-HE-Tag: 1680511696-250337 X-HE-Meta: U2FsdGVkX1/9sc8LxUXtFLgjTyj9B/eK3MTKtqMCD68xcHHXgXRVJuiFCs5FrOMyZuPoDuiNwhyNFjl9D7UuD091TbBlUp9h8wbUuy1SROikHjdoFvw0AUybMcSnBrTUd6+pG7W7ETKcNVnEl4kJ+On12Vzd3WoKbkcNg0tWan+05a5liB6jRXzY/tgjH1Yk3DQWGRhkS2SLLjzV7q3ZYtg+5To57VQ4oxrpmfFxmQsGcNpLNqMqrceWopQoUcwxSJXu8ZCDvK+mZRuRYPPB3xs0dpsfUW/yVQ4u8eyrljBze58gKEK/tT1RhjLWipLmA0/V/vw0Fxw6TqTgN+5l1n3VQWMv89kIki+M24BjHp7EEo1WWYZy5iCMQj0n8ld5Q4XfqPaZncDDQoaVP2wD2o4z00UEGXBppF3p7tFQVVZTF1qMuIhxE91wtb10knJ1OTu3tYVMhUcy23Yjq+p8CWTExuTotL2763qiudXJbKPbwj5ceVEi2q8cBAHWGtaCCBBKZa96gZFVmzKoAJkEElOgybEkCYTp5uhf6brCluKGcaIycekfqelDrynG7JNkhbSndQimRoY8Z9ECZDEAm6Gq5TxR72tWP9VUE0qva2VGHV3wHWFgeaux9LT8tHUGzcpQtmdYxOcb51Sn48T5ehDiBmCdTQrQ9vJeIL3fcBNA2NLdyKpo8lgSvZAkFKXC7A4oGnjLsKi2/PW37RFzDI2Wk79GtkpcNBoGHsuXYEg2SrVJevIVsD+E4ARgYhsRjLnuzYTURdtw4Z+5A2F0ggf/XiaVVwfaM9XrqWsqYAx0ziqvb8aBS0LfIgvPoAzSGsj/ItQAq32aP/5SseEaTWmxcFn4bbEDsNR0CukyNa3qcPgeAwNEo25YxPsx1ZeQJLzUxdMu7aP8e/KJsf4v0xDI7F3NKV/VlDLUVFeDfzfbmEZ9tFu8m6s8jUspy+LoNBJgvU/nauXIcJ0wzKx Z5GaArD6 0KMH5ZQ6NNEb0HFV9aWM5WgoekjsOXxtQuelaC85JAr9n6chfwqjE/U87B6QyQq8WxpP6sryG7Wnu+GgJVcS/ZZTL9SRNOsJmGnbafw5AbyJ4jxx1gt8h6uvoBcUlSDrFSlKzNjTv4HbjdKcdtBHhSZVSCGQtCwsNyf2PsemmPkiSlvXaemNgbF3bSZQ8UQLbsIvmgYA8IKNQn8egI3vsb0rF6i/5PzP2O0QbY7dyf1oD8VtThrXrH921LimrPUYb81PI8DBQspBXgs5ZinQ5F6fFiV0wvoGLBWC5dctzot8JGEh1ddxsBL3o/ir9/DRlc4E1PH9wiqCTzuqS2HHM/bIM19woQxtK8z5YfDyR41Rl3K0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Lukas Czerner Make shmem_inode_acct_block() return proper error code instead of bool. This will be useful later when we introduce quota support. There should be no functional change. Signed-off-by: Lukas Czerner Signed-off-by: Carlos Maiolino --- mm/shmem.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 448f393d8ab2b..0e63ea5f6ce69 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -198,13 +198,14 @@ static inline void shmem_unacct_blocks(unsigned long flags, long pages) vm_unacct_memory(pages * VM_ACCT(PAGE_SIZE)); } -static inline bool shmem_inode_acct_block(struct inode *inode, long pages) +static inline int shmem_inode_acct_block(struct inode *inode, long pages) { struct shmem_inode_info *info = SHMEM_I(inode); struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); + int err = -ENOSPC; if (shmem_acct_block(info->flags, pages)) - return false; + return err; if (sbinfo->max_blocks) { if (percpu_counter_compare(&sbinfo->used_blocks, @@ -213,11 +214,11 @@ static inline bool shmem_inode_acct_block(struct inode *inode, long pages) percpu_counter_add(&sbinfo->used_blocks, pages); } - return true; + return 0; unacct: shmem_unacct_blocks(info->flags, pages); - return false; + return err; } static inline void shmem_inode_unacct_blocks(struct inode *inode, long pages) @@ -369,7 +370,7 @@ bool shmem_charge(struct inode *inode, long pages) struct shmem_inode_info *info = SHMEM_I(inode); unsigned long flags; - if (!shmem_inode_acct_block(inode, pages)) + if (shmem_inode_acct_block(inode, pages)) return false; /* nrpages adjustment first, then shmem_recalc_inode() when balanced */ @@ -1589,7 +1590,8 @@ static struct folio *shmem_alloc_and_acct_folio(gfp_t gfp, struct inode *inode, huge = false; nr = huge ? HPAGE_PMD_NR : 1; - if (!shmem_inode_acct_block(inode, nr)) + err = shmem_inode_acct_block(inode, nr); + if (err) goto failed; if (huge) @@ -2433,7 +2435,7 @@ int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, int ret; pgoff_t max_off; - if (!shmem_inode_acct_block(inode, 1)) { + if (shmem_inode_acct_block(inode, 1)) { /* * We may have got a page, returned -ENOENT triggering a retry, * and now we find ourselves with -ENOMEM. Release the page, to From patchwork Mon Apr 3 08:47:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13197811 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C02D0C76196 for ; Mon, 3 Apr 2023 08:48:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B19DC6B007D; Mon, 3 Apr 2023 04:48:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A6FBD6B007B; Mon, 3 Apr 2023 04:48:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E90F6B007D; Mon, 3 Apr 2023 04:48:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7A6276B007B for ; Mon, 3 Apr 2023 04:48:23 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 42D9840A64 for ; Mon, 3 Apr 2023 08:48:23 +0000 (UTC) X-FDA: 80639453286.20.F3BB5AA Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf11.hostedemail.com (Postfix) with ESMTP id 6C3E440019 for ; Mon, 3 Apr 2023 08:48:20 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OFJAG6Fo; spf=pass (imf11.hostedemail.com: domain of cem@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cem@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680511700; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ATcjSUnSSLP3xPTdDDsq/zbx5D/qMgoL9Dtp6sqHink=; b=pN2E4DexHfNGE+81h/fHqBt2VVsLnIKhSO1ZluDor7SF5XYzHs4Egt2Q/G69nU9vmE6zAO nPRWx5VFq+KBXlL8+6o/c8a6hrpUPf68dWXIqCXZJyJlF5Ua3dSmlgxIAchC0Jebix+47M MjNyRRv0pVtR7ClcTyyMticFP8zATNk= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OFJAG6Fo; spf=pass (imf11.hostedemail.com: domain of cem@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cem@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680511700; a=rsa-sha256; cv=none; b=YAi4+3/hcsd9vNuKZzn5aKoGoYlEI8SCBXINwQeInoz01MuL7Pg+aZHXz1ykS20QwIP4wq HKGE1oP9+wYrQexlntpRVIhD13moSZ+TmhCdJoyiP+Bo6vdc0usvxo2n2tLPSEKUIRDgH+ y+8fxOZ/sqPDpJqlOj4Txcsnx0UnBIk= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 84323B815C3; Mon, 3 Apr 2023 08:48:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C96D3C433D2; Mon, 3 Apr 2023 08:48:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680511697; bh=alCHEsMOWI9FSAhiZoQby4G8FGoC7s8cIHuq02QwOlQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OFJAG6Fonx5PIwq1Ibx3C895kbftdRxkSMptSdn8S+FA2nLWdUci9v/hFV5TkT2Hz l65cIMH3E1mE/ytiw1gDFhA7Y0YQGSgU7UmgLjRfe9kgFOlJlhgMbWmdU/Q//U42G9 TpZ+A5GuuEPklskqk66Xf3eqcQoAiYqdoQMebegGd/0F/tbK+CxsUKvBStaiH4mJFz SOQdECKnOPO0IDDJuiyGYV7XFPinkxW574Jqj+U+2dRZPp6yXRl8O3FKhxYf0kaQ0O MhqKn5B0193uu5XZUlh208IW53QiWdE8jdwE3j8KSjRk8cSdy7ckKOln73kvmulT7O rC2mUK3cP2cyA== From: cem@kernel.org To: hughd@google.com Cc: jack@suse.cz, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, djwong@kernel.org Subject: [PATCH 2/6] shmem: make shmem_get_inode() return ERR_PTR instead of NULL Date: Mon, 3 Apr 2023 10:47:55 +0200 Message-Id: <20230403084759.884681-3-cem@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230403084759.884681-1-cem@kernel.org> References: <20230403084759.884681-1-cem@kernel.org> MIME-Version: 1.0 X-Stat-Signature: wgbs3exz6icrcjcexf7i3rgfcism7kr9 X-Rspam-User: X-Rspamd-Queue-Id: 6C3E440019 X-Rspamd-Server: rspam06 X-HE-Tag: 1680511700-497408 X-HE-Meta: U2FsdGVkX18EHJMCtVJKUIPosnM17c7o9x40T48lK+2Sl7RSlhjD2XQdHVSt4qKxyseXS4b9Z4q/Sxfti3S5lumSqhJPKXeWF5/MdAPSsUU5pTFeg/ImfP4lBWQjBvEHJX08PJGrd91zYUgM4bEitJFZRd+hyYhVVVwGU/InHe3M5OcW+XZb9hxjlFW5kEsk8i1Jl9EsgX/jbPcHthUGlMTMgeLVvmGY2hIsBORPddT21WXLX0VAfw9WUfo1rgnC6F0kPl9j3dJji0u5DaGzJOGk2CZF6m4P4rfHlhO3UKWF4ME76NBPV/ICtQ3TWEgHiqOJQFPot+Xvo3YzjFuiYDB9l8reW/TaGnpO8eExr0l0RWeppNGikqfWHistpWwo/M5K6JIuEMVhF6d73F1fMN1JQVX6cVxXkF45hnq/nPqx7P1XSccJO6DDWA8wxIbsZwmT83ezTp66gBSPmKES8NYn2QJR6FFEltFnmmhTOu80XQrATsHsnn0GVDFOeRZnFmPk9/KXWXSk/0y6gncrrTxQBYorByhi9xtYP0JPcR0mtqqeepaWa05RBoLe8J50psszoM0Mcm4KbLGAJrSDXHN74AnkyTQC3q3DUEWqTD7aEpsiLc+RYI2YGuVTjugqIpm7c5B9YUWkZMByrJZkqGq1qzAPwDZH0Rz2swjtPE/dwy/a1hOdKRO5J0RDNz4tq817aXXdoEMz7LXcJveBVqlFTFqeMkhExlJlj++Y9LMF3WEYaXF8/oDOpzzn0qVJ1mnaZFNX5dBB4xDLGolqD4HNBzfI8Lz2P0JDwelTgfG+XQLZPivqilY/Eoa9r3MAeQCOCWLyFo1HkGzZrvui/OBHAQfUgfX17Z7VT1TR4KzByC/33abW3NPlYpR3XhkRX5WNIC72yLASXY1HZFiFdDSpEAfEa98ewZ7pjZs1/hWkfmLJZ+8cQuLJMPTH1G/gLUVwSShULOQWLN5yYus ucg1j0cj +nM5eKcQapaJy0p8fbCeTI478JJY4os/ABL8O1Ob+wVG4lK1F/xy8f0SZ3nzzw3viKfQ7wunZ0cu2qr2zKs9mIAlbAv7qmsHyCidGfDlrPigSEKeEdyfpe4OowYS6A+ZnO9EFECMlPtFTVrn8Fz2yHJ+WnSB9zf9vglvce302oEKgvS8WiBwwmHWbWJvxqmhFCBBex5bdHSB4S+ZKcaS0KeIU0aJriPExdqpZJ/mJgVcX2nxaJTFv87MlCABss2m7NnzsxNu6TQJDQC5ALBE0m93ANw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Lukas Czerner Make shmem_get_inode() return ERR_PTR instead of NULL on error. This will be useful later when we introduce quota support. There should be no functional change. Signed-off-by: Lukas Czerner Signed-off-by: Carlos Maiolino --- mm/shmem.c | 205 +++++++++++++++++++++++++++++------------------------ 1 file changed, 114 insertions(+), 91 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 0e63ea5f6ce69..88e13930fc013 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2354,65 +2354,71 @@ static struct inode *shmem_get_inode(struct mnt_idmap *idmap, struct super_block struct shmem_inode_info *info; struct shmem_sb_info *sbinfo = SHMEM_SB(sb); ino_t ino; + int err; + + err = shmem_reserve_inode(sb, &ino); + if (err) + return ERR_PTR(err); - if (shmem_reserve_inode(sb, &ino)) - return NULL; inode = new_inode(sb); - if (inode) { - inode->i_ino = ino; - inode_init_owner(idmap, inode, dir, mode); - inode->i_blocks = 0; - inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); - inode->i_generation = get_random_u32(); - info = SHMEM_I(inode); - memset(info, 0, (char *)inode - (char *)info); - spin_lock_init(&info->lock); - atomic_set(&info->stop_eviction, 0); - info->seals = F_SEAL_SEAL; - info->flags = flags & VM_NORESERVE; - info->i_crtime = inode->i_mtime; - info->fsflags = (dir == NULL) ? 0 : - SHMEM_I(dir)->fsflags & SHMEM_FL_INHERITED; - if (info->fsflags) - shmem_set_inode_flags(inode, info->fsflags); - INIT_LIST_HEAD(&info->shrinklist); - INIT_LIST_HEAD(&info->swaplist); - simple_xattrs_init(&info->xattrs); - cache_no_acl(inode); - mapping_set_large_folios(inode->i_mapping); - - switch (mode & S_IFMT) { - default: - inode->i_op = &shmem_special_inode_operations; - init_special_inode(inode, mode, dev); - break; - case S_IFREG: - inode->i_mapping->a_ops = &shmem_aops; - inode->i_op = &shmem_inode_operations; - inode->i_fop = &shmem_file_operations; - mpol_shared_policy_init(&info->policy, - shmem_get_sbmpol(sbinfo)); - break; - case S_IFDIR: - inc_nlink(inode); - /* Some things misbehave if size == 0 on a directory */ - inode->i_size = 2 * BOGO_DIRENT_SIZE; - inode->i_op = &shmem_dir_inode_operations; - inode->i_fop = &simple_dir_operations; - break; - case S_IFLNK: - /* - * Must not load anything in the rbtree, - * mpol_free_shared_policy will not be called. - */ - mpol_shared_policy_init(&info->policy, NULL); - break; - } - lockdep_annotate_inode_mutex_key(inode); - } else + if (!inode) { shmem_free_inode(sb); + return ERR_PTR(-ENOSPC); + } + + inode->i_ino = ino; + inode_init_owner(idmap, inode, dir, mode); + inode->i_blocks = 0; + inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); + inode->i_generation = get_random_u32(); + info = SHMEM_I(inode); + memset(info, 0, (char *)inode - (char *)info); + spin_lock_init(&info->lock); + atomic_set(&info->stop_eviction, 0); + info->seals = F_SEAL_SEAL; + info->flags = flags & VM_NORESERVE; + info->i_crtime = inode->i_mtime; + info->fsflags = (dir == NULL) ? 0 : + SHMEM_I(dir)->fsflags & SHMEM_FL_INHERITED; + if (info->fsflags) + shmem_set_inode_flags(inode, info->fsflags); + INIT_LIST_HEAD(&info->shrinklist); + INIT_LIST_HEAD(&info->swaplist); + simple_xattrs_init(&info->xattrs); + cache_no_acl(inode); + mapping_set_large_folios(inode->i_mapping); + + switch (mode & S_IFMT) { + default: + inode->i_op = &shmem_special_inode_operations; + init_special_inode(inode, mode, dev); + break; + case S_IFREG: + inode->i_mapping->a_ops = &shmem_aops; + inode->i_op = &shmem_inode_operations; + inode->i_fop = &shmem_file_operations; + mpol_shared_policy_init(&info->policy, + shmem_get_sbmpol(sbinfo)); + break; + case S_IFDIR: + inc_nlink(inode); + /* Some things misbehave if size == 0 on a directory */ + inode->i_size = 2 * BOGO_DIRENT_SIZE; + inode->i_op = &shmem_dir_inode_operations; + inode->i_fop = &simple_dir_operations; + break; + case S_IFLNK: + /* + * Must not load anything in the rbtree, + * mpol_free_shared_policy will not be called. + */ + mpol_shared_policy_init(&info->policy, NULL); + break; + } + + lockdep_annotate_inode_mutex_key(inode); return inode; } @@ -2927,27 +2933,30 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev) { struct inode *inode; - int error = -ENOSPC; + int error; inode = shmem_get_inode(idmap, dir->i_sb, dir, mode, dev, VM_NORESERVE); - if (inode) { - error = simple_acl_create(dir, inode); - if (error) - goto out_iput; - error = security_inode_init_security(inode, dir, - &dentry->d_name, - shmem_initxattrs, NULL); - if (error && error != -EOPNOTSUPP) - goto out_iput; - error = 0; - dir->i_size += BOGO_DIRENT_SIZE; - dir->i_ctime = dir->i_mtime = current_time(dir); - inode_inc_iversion(dir); - d_instantiate(dentry, inode); - dget(dentry); /* Extra count - pin the dentry in core */ - } + if (IS_ERR(inode)) + return PTR_ERR(inode); + + error = simple_acl_create(dir, inode); + if (error) + goto out_iput; + error = security_inode_init_security(inode, dir, + &dentry->d_name, + shmem_initxattrs, NULL); + if (error && error != -EOPNOTSUPP) + goto out_iput; + + error = 0; + dir->i_size += BOGO_DIRENT_SIZE; + dir->i_ctime = dir->i_mtime = current_time(dir); + inode_inc_iversion(dir); + d_instantiate(dentry, inode); + dget(dentry); /* Extra count - pin the dentry in core */ return error; + out_iput: iput(inode); return error; @@ -2958,21 +2967,24 @@ shmem_tmpfile(struct mnt_idmap *idmap, struct inode *dir, struct file *file, umode_t mode) { struct inode *inode; - int error = -ENOSPC; + int error; inode = shmem_get_inode(idmap, dir->i_sb, dir, mode, 0, VM_NORESERVE); - if (inode) { - error = security_inode_init_security(inode, dir, - NULL, - shmem_initxattrs, NULL); - if (error && error != -EOPNOTSUPP) - goto out_iput; - error = simple_acl_create(dir, inode); - if (error) - goto out_iput; - d_tmpfile(file, inode); - } + + if (IS_ERR(inode)) + return PTR_ERR(inode); + + error = security_inode_init_security(inode, dir, + NULL, + shmem_initxattrs, NULL); + if (error && error != -EOPNOTSUPP) + goto out_iput; + error = simple_acl_create(dir, inode); + if (error) + goto out_iput; + d_tmpfile(file, inode); return finish_open_simple(file, error); + out_iput: iput(inode); return error; @@ -3146,8 +3158,9 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, inode = shmem_get_inode(idmap, dir->i_sb, dir, S_IFLNK | 0777, 0, VM_NORESERVE); - if (!inode) - return -ENOSPC; + + if (IS_ERR(inode)) + return PTR_ERR(inode); error = security_inode_init_security(inode, dir, &dentry->d_name, shmem_initxattrs, NULL); @@ -3762,12 +3775,13 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) struct shmem_options *ctx = fc->fs_private; struct inode *inode; struct shmem_sb_info *sbinfo; + int error = -ENOMEM; /* Round up to L1_CACHE_BYTES to resist false sharing */ sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL); if (!sbinfo) - return -ENOMEM; + return error; sb->s_fs_info = sbinfo; @@ -3829,8 +3843,10 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) inode = shmem_get_inode(&nop_mnt_idmap, sb, NULL, S_IFDIR | sbinfo->mode, 0, VM_NORESERVE); - if (!inode) + if (IS_ERR(inode)) { + error = PTR_ERR(inode); goto failed; + } inode->i_uid = sbinfo->uid; inode->i_gid = sbinfo->gid; sb->s_root = d_make_root(inode); @@ -3840,7 +3856,7 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) failed: shmem_put_super(sb); - return -ENOMEM; + return error; } static int shmem_get_tree(struct fs_context *fc) @@ -4209,10 +4225,16 @@ EXPORT_SYMBOL_GPL(shmem_truncate_range); #define shmem_vm_ops generic_file_vm_ops #define shmem_anon_vm_ops generic_file_vm_ops #define shmem_file_operations ramfs_file_operations -#define shmem_get_inode(idmap, sb, dir, mode, dev, flags) ramfs_get_inode(sb, dir, mode, dev) #define shmem_acct_size(flags, size) 0 #define shmem_unacct_size(flags, size) do {} while (0) +static inline struct inode *shmem_get_inode(struct super_block *sb, struct inode *dir, + umode_t mode, dev_t dev, unsigned long flags) +{ + struct inode *inode = ramfs_get_inode(sb, dir, mode, dev); + return inode ? inode : ERR_PTR(-ENOSPC); +} + #endif /* CONFIG_SHMEM */ /* common code */ @@ -4237,9 +4259,10 @@ static struct file *__shmem_file_setup(struct vfsmount *mnt, const char *name, l inode = shmem_get_inode(&nop_mnt_idmap, mnt->mnt_sb, NULL, S_IFREG | S_IRWXUGO, 0, flags); - if (unlikely(!inode)) { + + if (IS_ERR(inode)) { shmem_unacct_size(flags, size); - return ERR_PTR(-ENOSPC); + return ERR_CAST(inode); } inode->i_flags |= i_flags; inode->i_size = size; From patchwork Mon Apr 3 08:47:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13197810 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4B18C77B62 for ; Mon, 3 Apr 2023 08:48:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 653746B0075; Mon, 3 Apr 2023 04:48:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5DC8E6B0078; Mon, 3 Apr 2023 04:48:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 47C456B007B; Mon, 3 Apr 2023 04:48:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 39BD26B0075 for ; Mon, 3 Apr 2023 04:48:23 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 14863A0492 for ; Mon, 3 Apr 2023 08:48:23 +0000 (UTC) X-FDA: 80639453286.19.ABB94CB Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf24.hostedemail.com (Postfix) with ESMTP id 74EE218001A for ; Mon, 3 Apr 2023 08:48:20 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=g9nWUEEM; spf=pass (imf24.hostedemail.com: domain of cem@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cem@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680511700; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dYlc1jmimOpu++fgK4m6NvvZQ7dOhc28V6dQJ5ItySQ=; b=Ooaw9f2Nu3+UF9FwD01jxWGAvx91UHm2wURBXfC846cRgloK6i3e5hsuPlaX2ljv+BH0Jq bHA6DDqbH7Vn4YCs55BHR9WhELjIb8pwFz3nvCov1gS0jI4xHDshDAKeN/Yd1VU1WXXA5J VNFiYLoFgFCiHi65p9AnAN9EVKtp/+8= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=g9nWUEEM; spf=pass (imf24.hostedemail.com: domain of cem@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cem@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680511700; a=rsa-sha256; cv=none; b=BI9q5nr8B6U35X8OoyM/JQowHaqNFqBcHx6OcMlcgfEUHlHuSkix5XPNFYVMuLfGQqCiQk uFOMZRkqSsi11CEOkjD+QEsJYtXPS2XXA4rKgz86dDrWDfiOv2KjrbNv8gQWDJ1En+xt+f zah1PFcKBQO1NVkLsvLu9NnDUvBiipc= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A95F060F5A; Mon, 3 Apr 2023 08:48:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC20DC4339C; Mon, 3 Apr 2023 08:48:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680511699; bh=Su2DoSY6BWVBfCUfk9QccjNDv0XP3B1+MpHIwHBykn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g9nWUEEMRDid916NyRQuwKd2XaaGWV6PBImgZfSim19fxbwjlJ3bEV94rgC0h2+yG ZZVrsheSbTsqjsCaCDG98G2AEQGYjcvVZZVg/UD+UKI/0XSHNUvD+XHXxMgiwvgbe6 Ok/SsHK2nFBfSpOrN/M6T1FL2w94swHcw8AXKzBbiur1d5ivFpK5eOps8iHonayngv 37R96Q2TjCpqsRGJJGbjCSA6dTKDrm6yyHbmGrnU9u4ZvsbosQuiU9QVraHbACq3oa 5Hut+ESrPnQwO3Y0tUDvj7sVVlD29udS8iTCP1Zp/B539XMdpUaLddvAuX4wEClTFJ UfiZaMbADrhnA== From: cem@kernel.org To: hughd@google.com Cc: jack@suse.cz, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, djwong@kernel.org Subject: [PATCH 3/6] quota: Check presence of quota operation structures instead of ->quota_read and ->quota_write callbacks Date: Mon, 3 Apr 2023 10:47:56 +0200 Message-Id: <20230403084759.884681-4-cem@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230403084759.884681-1-cem@kernel.org> References: <20230403084759.884681-1-cem@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 74EE218001A X-Stat-Signature: irgzco7r8u6q8sfcxw9z6r85wduh6oaf X-HE-Tag: 1680511700-334447 X-HE-Meta: U2FsdGVkX1+jVOQd9LKRHFxfm2DuZnx/zDQyzla8G6qBZFEoHRwT9KrfqxESOMXqG0OIqo9d1IjcQausY7FS3CyAnfzRDFHdFEtu80u5K7Kiy7M/cDUWAhS/1yqW9eDuOwRgW1/GBwvnWijKD4CfTo9BICMp/3gvMp1Yfj4EHug6QLwlBvm/J3H5aC378rbrwRFqzbB0c8JLwmSWuNNdIwocMg8LcDZ7+CcsdB55WaMmonaX01v9Gm4M5d+NpPvaf+l8Z/NnwvFFxoKp47CI/Jbf8BR5abnvoUYP+IKwQYGRP4qYXCwrWoGJlBbLWVL0dTt1B+EeXa90lh8Yrnwrd+c1oStHmvkCYqaUzGWRrwfvK5Pz3H9GdIfTX55UYskwKHsm9O0H6HmOts+H6TkbIBj7Ru3ApmLV6gKA1JGfvaTYY+plwz+0udN7Vgtwo5ZCwwU56vIA4XhGiulH5NkyerikbDg4Umhwo1BH0P3NQdcfuekw3EStvRsQUzWrV+wtU+EAOzxdDNaO51izH0JPPREY/N43SaCS6xqL1a1vBR77Jq7GM0f6PhmfELcv+T33vKj/rvEC7x+vdNrc1GQH6L5uktyKKRfcEklxTuAhWDwm7RjzqdkvNEMMwxP+dXRsNWmLwmcsKoVU3PM8cxhXem6TwATAMoTlSLPNa21S0F0BEZ6uwbG9poozidipO9VlJZe0hUw6jiUG+BvCQDrsZq85gWQasJxD0W8zYleldibSLzKR9whxQpC9b6ufVDg211sDlMYpyzvF/hj8IpcO1W0KoseLSdtXa09knUZDG3HuhJDT0+DOpvzEPhpP6cT2HerkCGZKXMOhel+evaSv8qQCVlP3nMICRYoYczsZlLhjUmRDpmRCdiazooVDdb9GkMcZYmRJLxVLq05wffd7uyAgaf94mLyJiIBn5UA5SqkS6WOFrzAbVTwIlchQLRBaKXrVgHElBM+pvoU3B/s MejSf60v 0EuINV+r9Ujajfqg/mutQV5raw2yUW/5QWQjkZ+AQTsgfcF31VdoLgeQJJwxZHI1hjWHY1iMEDpP4MvWdnFOXIUdby46Gjz2t4dswR0G5qUnaTMjasTWUzw5YsbdCpYpR4Q6QyQHNekrzx/iRTIv1rszzuUwcxx5SHbLo5+xoBRBFkVMXv0n6js3iJoAWd0/u4TCHhuEpcygoyjpR5iYZ8RajE/exwBJWA6iySVXeoMualh3HMTT4cafP06Ui04j1I8gsf8tT/afsFsOWDbcKwdDPK5FXgQfuwNg5Fwrnb4NxB4kC21A4G8uXeK2soiBglVl1V4ftgTPIeq55mtZ4lfG9UA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Jan Kara Currently we check whether superblock has ->quota_read and ->quota_write operations to check whether filesystem supports quotas. However for example for shmfs we will not read or write dquots so check whether quota operations are set in the superblock instead. Signed-off-by: Jan Kara --- fs/quota/dquot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c index a6357f728034a..81563a83b609d 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c @@ -2367,7 +2367,7 @@ int dquot_load_quota_sb(struct super_block *sb, int type, int format_id, if (!fmt) return -ESRCH; - if (!sb->s_op->quota_write || !sb->s_op->quota_read || + if (!sb->dq_op || !sb->s_qcop || (type == PRJQUOTA && sb->dq_op->get_projid == NULL)) { error = -EINVAL; goto out_fmt; From patchwork Mon Apr 3 08:47:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13197812 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C06D0C761A6 for ; Mon, 3 Apr 2023 08:48:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 396316B0078; Mon, 3 Apr 2023 04:48:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2CEB16B007B; Mon, 3 Apr 2023 04:48:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12E03900002; Mon, 3 Apr 2023 04:48:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E80606B0078 for ; Mon, 3 Apr 2023 04:48:25 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BA46DAAE2A for ; Mon, 3 Apr 2023 08:48:25 +0000 (UTC) X-FDA: 80639453370.23.D509F67 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf26.hostedemail.com (Postfix) with ESMTP id C154214000E for ; Mon, 3 Apr 2023 08:48:23 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lEuktvIh; spf=pass (imf26.hostedemail.com: domain of cem@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cem@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680511704; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Il33x1vudDVPPHQS1x/tITH6lQR8IjF0wjcpviMTNso=; b=ZATZqARPREbom0ATXTTerrwThFpcVLaS6Ptfwrr1ZBMqzqv0PBy7VtMQztS9Dzh2UqU9/Q UF1Xb8w5/UPkUj59g/j9uvmTeQyv0VZAJwjgIuXqjJ9eJcoEb/qb571GFobf51P27o9RoV w2BsCMIQjpp21WSuquE0ASeLkUPrriE= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lEuktvIh; spf=pass (imf26.hostedemail.com: domain of cem@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cem@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680511704; a=rsa-sha256; cv=none; b=FNoHqeO3I526XOiyPwYUnHRwiJZUrpdhIaklKTYK/JAYGO2BW4dJp2QAujW+qtnwW/pyub 0QJkjiDw+O7lIUpOltZ2q4s6SYXaMMgU0+jLzfgJdIK+6Nysw+50T75J1wczHky1qCuyVW TS/iJj9wEK7RaTkX5Px1mERIKUx1Wuc= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 37C1FB815C5; Mon, 3 Apr 2023 08:48:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C5F5C433EF; Mon, 3 Apr 2023 08:48:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680511701; bh=jl+58MslqHzGzg+pEpQVo0SgRfpjiAsXoqz/xf0Hdmo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lEuktvIhz/yzfl9A8YR0mS0eUScn4E+ZHMtJ32E4BEbeHVrybU9am8K0adig4SSe1 UPYFFRTNrBAMlcvyYxZ4RNdv+Zkj/LAAmJhbolMWN1ooP6zc/jmGvJ0hoA/v6jXtY9 csYw9iC013tVZgu42YD2sjwCYLuZAmjn0U4xI67+VNpfxCl6v79HOa8RhPen8Nw7WP W4FPIDpRK153D3n4nAX5RORJuS61ugnxkcVCwhCoUFZDBd33NxJHr/XB7Igs4DdVJp j01xj6X7Gr6khEKXgOzUHkiuszrg4woyVe6OZZSF/19klf9pd9gUt5TBRN+mLrN5LN VQkhhTMtJuPlg== From: cem@kernel.org To: hughd@google.com Cc: jack@suse.cz, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, djwong@kernel.org Subject: [PATCH 4/6] shmem: prepare shmem quota infrastructure Date: Mon, 3 Apr 2023 10:47:57 +0200 Message-Id: <20230403084759.884681-5-cem@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230403084759.884681-1-cem@kernel.org> References: <20230403084759.884681-1-cem@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: C154214000E X-Stat-Signature: tcre3nkpxuudnpwzamujdqfggyt7sz76 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1680511703-672389 X-HE-Meta: U2FsdGVkX1+zexnx2nrqDwVedhOI6Z7GoTB5DoRyGbMaVrmaJrc2nRpDrbwhGAo100//GJbdiU+d7L6Z2RkQITFkXKiLGmSk8v2oOeuhYro00QcxHVeCwMlXQ5ug93U43rQXSRaGyUXQ4FIPuJdEOHDnNs8lnXh61e9HKQqoK/WEZ2+TN9MwH+Iqlcpdb1TLJS1CtPlVCdpOYH3GAxDI52wBbv2j2H/hMQ/qgF3uOU4TBh7xMSMeaJ/3qUgml9q/6P7m9TiCfPve49TCUBwyULMYD+MouZpEiViKBs3mAinrEGe6JdaRITTaPTTPpdtir2GK20SsXSm5xrnHaO0oRP7YxlYuG+VrF2PEEwQ084hqFpUIEjHMicUG2n9cziYQguW5wZGD1lBaTRYfS3NeaWTnwiS85o0cNITsHiLYGmjaqnVzKRQ2ySX0cn1etYlc6DWMeW2Xv/1u9qXPmvXxAPQ1ogAIsrhNLud5h2hzgHJJoe0l2+jE+Dnoh6EtB1M3to5NUiw9nm1J3G8djYP3CR01wITPbAEQXP/cEU11difl8CbAZLgNsr1HZnw7yegpUoQupo/IemKISLuXNo315SQxtZ4OZ7Qx3sRI/OWqFcGv0WCbYll5WGcVvY2lf+RQfqukIbqbv4KEH5VVOz+NmB5FMxhBdj0r3vXSQyXINLYwo1yGn+WVo3d+MvJ/vvpPLwGCqF3WMxhHAoaWFo4R94IptkmMJyz4FsLGmPkYg07bEcuBbPyWoP2OxogL18E6Jtv2hHSu1G/n9jawB9rGn/cFIqIkBBE9nVrdKPtboywYiJnnfxcvPdMYivm6ft+/4Yi1Ldc//pqFXrWIXH26iJG2P0l0Gnr8QeKPEfuNgsCiCFY2jqTQP6CKhDvsLq6/MYLQsDwU2BDtBG5QV4DQz0Y/rA29POaqDdShkpLAJ/+xEV55j9IeQhaa5mq/vXG+M62xQqR8KlMxw5FZOTI 5hytvf3M 82C/9nqmJv+u8+JArq0dbMlAOmCT1lOhr9877yxGBqwMhq3wMyvpgFcYXVRi16+WAl6hv1UNwzEjszIPiwsTDaWtrJyt/2rNO5YWdz8xs3LjTin91BMIgnS3ppfSWM8QujUdyG+KuQ4PWuWC6kpO5sYjpLoSGVK/vy4nu9iZpLcCKDmiP2whmQyvOa7VGAez2XeHKE8GsAKSdZCawOv+kDyJMVZtenjjKcF+2q8E9MdbFZIk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Lukas Czerner Add new shmem quota format, its quota_format_ops together with dquot_operations Signed-off-by: Lukas Czerner Signed-off-by: Carlos Maiolino --- fs/Kconfig | 12 ++ include/linux/shmem_fs.h | 8 + include/uapi/linux/quota.h | 1 + mm/Makefile | 2 +- mm/shmem_quota.c | 318 +++++++++++++++++++++++++++++++++++++ 5 files changed, 340 insertions(+), 1 deletion(-) create mode 100644 mm/shmem_quota.c diff --git a/fs/Kconfig b/fs/Kconfig index e99830c650336..ba809882f1961 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -233,6 +233,18 @@ config TMPFS_INODE64 If unsure, say N. +config TMPFS_QUOTA + bool "Tmpfs quota support" + depends on TMPFS + select QUOTA + help + Quota support allows to set per user and group limits for tmpfs + usage. Say Y to enable quota support. Once enabled you can control + user and group quota enforcement with quota, usrquota and grpquota + mount options. + + If unsure, say N. + config ARCH_SUPPORTS_HUGETLBFS def_bool n diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 103d1000a5a2e..cf38381bdb4c1 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -163,4 +163,12 @@ extern int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd, #endif /* CONFIG_SHMEM */ #endif /* CONFIG_USERFAULTFD */ +/* + * Used space is stored as unsigned 64-bit value in bytes but + * quota core supports only signed 64-bit values so use that + * as a limit + */ +#define SHMEM_QUOTA_MAX_SPC_LIMIT 0x7fffffffffffffffLL /* 2^63-1 */ +#define SHMEM_QUOTA_MAX_INO_LIMIT 0x7fffffffffffffffLL + #endif diff --git a/include/uapi/linux/quota.h b/include/uapi/linux/quota.h index f17c9636a8593..52090105b8282 100644 --- a/include/uapi/linux/quota.h +++ b/include/uapi/linux/quota.h @@ -77,6 +77,7 @@ #define QFMT_VFS_V0 2 #define QFMT_OCFS2 3 #define QFMT_VFS_V1 4 +#define QFMT_SHMEM 5 /* Size of block in which space limits are passed through the quota * interface */ diff --git a/mm/Makefile b/mm/Makefile index 8e105e5b3e293..977d2b66775a9 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -52,7 +52,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \ readahead.o swap.o truncate.o vmscan.o shmem.o \ util.o mmzone.o vmstat.o backing-dev.o \ mm_init.o percpu.o slab_common.o \ - compaction.o \ + compaction.o shmem_quota.o\ interval_tree.o list_lru.o workingset.o \ debug.o gup.o mmap_lock.o $(mmu-y) diff --git a/mm/shmem_quota.c b/mm/shmem_quota.c new file mode 100644 index 0000000000000..c415043a71e67 --- /dev/null +++ b/mm/shmem_quota.c @@ -0,0 +1,318 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * In memory quota format relies on quota infrastructure to store dquot + * information for us. While conventional quota formats for file systems + * with persistent storage can load quota information into dquot from the + * storage on-demand and hence quota dquot shrinker can free any dquot + * that is not currently being used, it must be avoided here. Otherwise we + * can lose valuable information, user provided limits, because there is + * no persistent storage to load the information from afterwards. + * + * One information that in-memory quota format needs to keep track of is + * a sorted list of ids for each quota type. This is done by utilizing + * an rb tree which root is stored in mem_dqinfo->dqi_priv for each quota + * type. + * + * This format can be used to support quota on file system without persistent + * storage such as tmpfs. + * + * Author: Lukas Czerner + * Carlos Maiolino + * + * Copyright (C) 2023 Red Hat, Inc. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#ifdef CONFIG_TMPFS_QUOTA + +#define SHMEM_MAXQUOTAS 2 + +/* + * The following constants define the amount of time given a user + * before the soft limits are treated as hard limits (usually resulting + * in an allocation failure). The timer is started when the user crosses + * their soft limit, it is reset when they go below their soft limit. + */ +#define SHMEM_MAX_IQ_TIME 604800 /* (7*24*60*60) 1 week */ +#define SHMEM_MAX_DQ_TIME 604800 /* (7*24*60*60) 1 week */ + +struct quota_id { + struct rb_node node; + qid_t id; + qsize_t bhardlimit; + qsize_t bsoftlimit; + qsize_t ihardlimit; + qsize_t isoftlimit; +}; + +static int shmem_check_quota_file(struct super_block *sb, int type) +{ + /* There is no real quota file, nothing to do */ + return 1; +} + +/* + * There is no real quota file. Just allocate rb_root for quota ids and + * set limits + */ +static int shmem_read_file_info(struct super_block *sb, int type) +{ + struct quota_info *dqopt = sb_dqopt(sb); + struct mem_dqinfo *info = &dqopt->info[type]; + + info->dqi_priv = kzalloc(sizeof(struct rb_root), GFP_NOFS); + if (!info->dqi_priv) + return -ENOMEM; + + info->dqi_max_spc_limit = SHMEM_QUOTA_MAX_SPC_LIMIT; + info->dqi_max_ino_limit = SHMEM_QUOTA_MAX_INO_LIMIT; + + info->dqi_bgrace = SHMEM_MAX_DQ_TIME; + info->dqi_igrace = SHMEM_MAX_IQ_TIME; + info->dqi_flags = 0; + + return 0; +} + +static int shmem_write_file_info(struct super_block *sb, int type) +{ + /* There is no real quota file, nothing to do */ + return 0; +} + +/* + * Free all the quota_id entries in the rb tree and rb_root. + */ +static int shmem_free_file_info(struct super_block *sb, int type) +{ + struct mem_dqinfo *info = &sb_dqopt(sb)->info[type]; + struct rb_root *root = info->dqi_priv; + struct quota_id *entry; + struct rb_node *node; + + info->dqi_priv = NULL; + node = rb_first(root); + while (node) { + entry = rb_entry(node, struct quota_id, node); + node = rb_next(&entry->node); + + rb_erase(&entry->node, root); + kfree(entry); + } + + kfree(root); + return 0; +} + +static int shmem_get_next_id(struct super_block *sb, struct kqid *qid) +{ + struct mem_dqinfo *info = sb_dqinfo(sb, qid->type); + struct rb_node *node = ((struct rb_root *)info->dqi_priv)->rb_node; + qid_t id = from_kqid(&init_user_ns, *qid); + struct quota_info *dqopt = sb_dqopt(sb); + struct quota_id *entry = NULL; + int ret = 0; + + if (!sb_has_quota_active(sb, qid->type)) + return -ESRCH; + + down_read(&dqopt->dqio_sem); + while (node) { + entry = rb_entry(node, struct quota_id, node); + + if (id < entry->id) + node = node->rb_left; + else if (id > entry->id) + node = node->rb_right; + else + goto got_next_id; + } + + if (!entry) { + ret = -ENOENT; + goto out_unlock; + } + + if (id > entry->id) { + node = rb_next(&entry->node); + if (!node) { + ret = -ENOENT; + goto out_unlock; + } + entry = rb_entry(node, struct quota_id, node); + } + +got_next_id: + *qid = make_kqid(&init_user_ns, qid->type, entry->id); +out_unlock: + up_read(&dqopt->dqio_sem); + return ret; +} + +/* + * Load dquot with limits from existing entry, or create the new entry if + * it does not exist. + */ +static int shmem_acquire_dquot(struct dquot *dquot) +{ + struct mem_dqinfo *info = sb_dqinfo(dquot->dq_sb, dquot->dq_id.type); + struct rb_node **n = &((struct rb_root *)info->dqi_priv)->rb_node; + struct rb_node *parent = NULL, *new_node = NULL; + struct quota_id *new_entry, *entry; + qid_t id = from_kqid(&init_user_ns, dquot->dq_id); + struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); + int ret = 0; + + mutex_lock(&dquot->dq_lock); + + down_write(&dqopt->dqio_sem); + while (*n) { + parent = *n; + entry = rb_entry(parent, struct quota_id, node); + + if (id < entry->id) + n = &(*n)->rb_left; + else if (id > entry->id) + n = &(*n)->rb_right; + else + goto found; + } + + /* We don't have entry for this id yet, create it */ + new_entry = kzalloc(sizeof(struct quota_id), GFP_NOFS); + if (!new_entry) { + ret = -ENOMEM; + goto out_unlock; + } + + new_entry->id = id; + new_node = &new_entry->node; + rb_link_node(new_node, parent, n); + rb_insert_color(new_node, (struct rb_root *)info->dqi_priv); + entry = new_entry; + +found: + /* Load the stored limits from the tree */ + spin_lock(&dquot->dq_dqb_lock); + dquot->dq_dqb.dqb_bhardlimit = entry->bhardlimit; + dquot->dq_dqb.dqb_bsoftlimit = entry->bsoftlimit; + dquot->dq_dqb.dqb_ihardlimit = entry->ihardlimit; + dquot->dq_dqb.dqb_isoftlimit = entry->isoftlimit; + + if (!dquot->dq_dqb.dqb_bhardlimit && + !dquot->dq_dqb.dqb_bsoftlimit && + !dquot->dq_dqb.dqb_ihardlimit && + !dquot->dq_dqb.dqb_isoftlimit) + set_bit(DQ_FAKE_B, &dquot->dq_flags); + spin_unlock(&dquot->dq_dqb_lock); + + /* Make sure flags update is visible after dquot has been filled */ + smp_mb__before_atomic(); + set_bit(DQ_ACTIVE_B, &dquot->dq_flags); +out_unlock: + up_write(&dqopt->dqio_sem); + mutex_unlock(&dquot->dq_lock); + return ret; +} + +/* + * Store limits from dquot in the tree unless it's fake. If it is fake + * remove the id from the tree since there is no useful information in + * there. + */ +static int shmem_release_dquot(struct dquot *dquot) +{ + struct mem_dqinfo *info = sb_dqinfo(dquot->dq_sb, dquot->dq_id.type); + struct rb_node *node = ((struct rb_root *)info->dqi_priv)->rb_node; + qid_t id = from_kqid(&init_user_ns, dquot->dq_id); + struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); + struct quota_id *entry = NULL; + + mutex_lock(&dquot->dq_lock); + /* Check whether we are not racing with some other dqget() */ + if (dquot_is_busy(dquot)) + goto out_dqlock; + + down_write(&dqopt->dqio_sem); + while (node) { + entry = rb_entry(node, struct quota_id, node); + + if (id < entry->id) + node = node->rb_left; + else if (id > entry->id) + node = node->rb_right; + else + goto found; + } + + up_write(&dqopt->dqio_sem); + mutex_unlock(&dquot->dq_lock); + return 0; + +found: + if (test_bit(DQ_FAKE_B, &dquot->dq_flags)) { + /* Remove entry from the tree */ + rb_erase(&entry->node, info->dqi_priv); + kfree(entry); + } else { + /* Store the limits in the tree */ + spin_lock(&dquot->dq_dqb_lock); + entry->bhardlimit = dquot->dq_dqb.dqb_bhardlimit; + entry->bsoftlimit = dquot->dq_dqb.dqb_bsoftlimit; + entry->ihardlimit = dquot->dq_dqb.dqb_ihardlimit; + entry->isoftlimit = dquot->dq_dqb.dqb_isoftlimit; + spin_unlock(&dquot->dq_dqb_lock); + } + + clear_bit(DQ_ACTIVE_B, &dquot->dq_flags); + up_write(&dqopt->dqio_sem); + +out_dqlock: + mutex_unlock(&dquot->dq_lock); + return 0; +} + +int shmem_mark_dquot_dirty(struct dquot *dquot) +{ + return 0; +} + +int shmem_dquot_write_info(struct super_block *sb, int type) +{ + return 0; +} + +static const struct quota_format_ops shmem_format_ops = { + .check_quota_file = shmem_check_quota_file, + .read_file_info = shmem_read_file_info, + .write_file_info = shmem_write_file_info, + .free_file_info = shmem_free_file_info, +}; + +struct quota_format_type shmem_quota_format = { + .qf_fmt_id = QFMT_SHMEM, + .qf_ops = &shmem_format_ops, + .qf_owner = THIS_MODULE +}; + +const struct dquot_operations shmem_quota_operations = { + .acquire_dquot = shmem_acquire_dquot, + .release_dquot = shmem_release_dquot, + .alloc_dquot = dquot_alloc, + .destroy_dquot = dquot_destroy, + .write_info = shmem_dquot_write_info, + .mark_dirty = shmem_mark_dquot_dirty, + .get_next_id = shmem_get_next_id, +}; +#endif /* CONFIG_TMPFS_QUOTA */ From patchwork Mon Apr 3 08:47:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13197814 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E6D0C761A6 for ; Mon, 3 Apr 2023 08:48:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6BF69900002; Mon, 3 Apr 2023 04:48:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 47DA6900004; Mon, 3 Apr 2023 04:48:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20F9A900002; Mon, 3 Apr 2023 04:48:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id F25E1900003 for ; Mon, 3 Apr 2023 04:48:27 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B620EC096C for ; Mon, 3 Apr 2023 08:48:27 +0000 (UTC) X-FDA: 80639453454.06.73C7620 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf06.hostedemail.com (Postfix) with ESMTP id D557518000B for ; Mon, 3 Apr 2023 08:48:25 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DnaszmaI; spf=pass (imf06.hostedemail.com: domain of cem@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cem@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680511706; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DTC1va7OMOfTVx7jd9sPVEyFL8VGGd1dTa2NdHk7t88=; b=fX2fVg9buYru8C6YkE5uyYTER3Jnx7XcivhI+kNylw7p/4MH4DrfKVA4IcPH4t0P0PJHc3 DkLqlKzoZ82LD8fFePEObZmnx6PrVXAc9ut7DaJAjmFFwMswcQGTE7AEqlsQxOg5x735Yk vxHW4ZM5ZSk7SQ2FYcqzVsknGZ+LOOM= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DnaszmaI; spf=pass (imf06.hostedemail.com: domain of cem@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cem@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680511706; a=rsa-sha256; cv=none; b=uABC5CBrRGwDOuwJf/7jwBEXduEc+9WcpF8qWXCruQstr5Hwt3RWy+rnR4QrLcIoH5GFU7 R+lZMjuewUIDP5WQZBpb+0LYeOOWtBlYoCDf53/LDQ8bl669s/Nhig059cmn7xrehQthxe JrMOIN4R35hSqvFvyR5g+pIfzE236qM= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4DAF7B815D4; Mon, 3 Apr 2023 08:48:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88739C4339B; Mon, 3 Apr 2023 08:48:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680511702; bh=wqi/g8+nYJW5dWKPT/jj73GeiD/W48gxOqllJwPVhkQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DnaszmaIclWp+5FSgpgJBPZ34XcEbh1rtT+kCsF1JUv/PTDGJ3iBXfnojBzgEvuLj VbuDAXUUhRxRCw1qNxx8SMzBcNqR7nnZn6/cQxTWJL3saq80IPENaJcrKZD8YIw0Q0 k7vrHxK+jjU9xKvfMEpgqzbj7IiZft+DIO8ElCd6szPOnjnzEzSsQyoH7atFWzA4vD 6raCQta9Gqw8CnW6IUw07j0d207JKUBZ3BtlcMEC3Oiql/HUSf92fRBF2Vu+SNHAo7 gu/youuXGCb0JgjpRXj1C9KZqfRGSgNgT6ZfP7vwr9GDlNSuPF5Pg/VHGHG/nKekJI wQQbRzBgGc0Lg== From: cem@kernel.org To: hughd@google.com Cc: jack@suse.cz, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, djwong@kernel.org Subject: [PATCH 5/6] shmem: quota support Date: Mon, 3 Apr 2023 10:47:58 +0200 Message-Id: <20230403084759.884681-6-cem@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230403084759.884681-1-cem@kernel.org> References: <20230403084759.884681-1-cem@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D557518000B X-Stat-Signature: 9y7x9akf8my18ecwjgnkfmydw5ukrkzh X-HE-Tag: 1680511705-488447 X-HE-Meta: U2FsdGVkX18pgRjlqNmOeCOc4zd5E+0Miqgud8g6KZ4JVYdoWeeXWSOyIqOT75cBG/pwGn4bxkRWXw8GdQMSOilstZvb9wRU8uL24w0ocgi3o5ur7DXzgZGJNp2zKBMPitq8czVJ2AfC7R3Ho7u/WVi6+ZzNfh0XNZgTcYnJv7MSmHhGiMhWQ6K+ZlrJ3iZ/dlLtbr4q7tneoYkX+llnxCDDBdpJlDqeerv+tsinQSXMKIgyxPcUTxtsovdohJgQCzXY2zDRGRpsVR7M9SFHsKrDfue/gGV9SPEU4x62TOkyo4g3V6rpJ1qV81e7GLwQhkZPYXUaNtjKq/K7NAIlk+k+1NxZYC1AJ78nwH9+YOrpTVa6Jk76U5MSg4Zn5IdWL5vcUNUADJjbludvQq9D9DciL/nnWCZKCCp7A1uVDTW40pFK0Od0oI+taxtWSOzrmLduywjYrSU9pkIx9/Z6CWk79btEWqUG7dstvPWiHEUUOEf78+oCJ+1TMwSGBX4CcLXgisoWdgwZK9uA5f1vixf37rBiVl51DrXtMIH9TTzE8fL7qbxilOu9t8rqAEJROG4g2cjTd4wthEyY8Scjau3gssug4TvDGI/cozGnu2/QMJihTVMN+3eA4jbGESvQqiwnJGIj3p4HeSmhlka6coysL+QhEMa4jAtcFhJWkKA4ivzzOyBfi9dy7UYokisawCSb60o4xKPJOtnbxaUb2hEY/FP02+34kcXvIcN2eIZWc0OwU+pdOk5Zbpp6B+ayDUw2VYunD5EpBAFynMcCZhjsyK+T6Eh+yU1G1VpTHmQRxRpO3tANN0kRyu5ZMmDHnrk+wB+TpDyaBBJt4pWxOS5V/9ybBk5nbYhDS+ktHCbuqeoyi2skGMIWnnFPyp+y0v60Y5bNPzWAWVG3rJPon8KL6DQMGW4PeUH0T9SWeg/D4WdfoedQAVz2HApg4FOtw/98voj6Sg/YMdEN5GD GlQ5lVIT Sm6p63GNDi88x9KAKi/zs/Oa/HSBqaK9+JjbU5tgQOmSNmXYjwmNnEFA6uT+cCz/wea0LHTX3OZi8eFxMp6QbuL+9cDZIA90SgSULGpzjeYcxvSn0xvRLPyU+XwMJIBwo+Aksji/f2jBSkHMjpvOvNvtc/fBcKHf2Q+Q+LgEgJqFLWErlxy8vkeKjmihKQO5KGa91KB13S/agfeyS9tMnkY51tZnFA1x/z+VB5J6HtA6KsII= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Lukas Czerner Now the basic infra-structure is in place, enable quota support for tmpfs. Signed-off-by: Lukas Czerner Signed-off-by: Carlos Maiolino --- Documentation/filesystems/tmpfs.rst | 12 +++ include/linux/shmem_fs.h | 9 ++ mm/shmem.c | 162 ++++++++++++++++++++++++++-- 3 files changed, 174 insertions(+), 9 deletions(-) diff --git a/Documentation/filesystems/tmpfs.rst b/Documentation/filesystems/tmpfs.rst index 0408c245785e3..3f8d89bb7e1a5 100644 --- a/Documentation/filesystems/tmpfs.rst +++ b/Documentation/filesystems/tmpfs.rst @@ -86,6 +86,18 @@ use up all the memory on the machine; but enhances the scalability of that instance in a system with many CPUs making intensive use of it. +tmpfs also supports quota with the following mount options + +======== ============================================================= +quota User and group quota accounting and enforcement is enabled on + the mount. Tmpfs is using hidden system quota files that are + initialized on mount. +usrquota User quota accounting and enforcement is enabled on the + mount. +grpquota Group quota accounting and enforcement is enabled on the + mount. +======== ============================================================= + tmpfs has a mount option to set the NUMA memory allocation policy for all files in that instance (if CONFIG_NUMA is enabled) - which can be adjusted on the fly via 'mount -o remount ...' diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index cf38381bdb4c1..3e7e18726feb5 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -26,6 +26,9 @@ struct shmem_inode_info { atomic_t stop_eviction; /* hold when working on inode */ struct timespec64 i_crtime; /* file creation time */ unsigned int fsflags; /* flags for FS_IOC_[SG]ETFLAGS */ +#ifdef CONFIG_TMPFS_QUOTA + struct dquot *i_dquot[MAXQUOTAS]; +#endif struct inode vfs_inode; }; @@ -171,4 +174,10 @@ extern int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd, #define SHMEM_QUOTA_MAX_SPC_LIMIT 0x7fffffffffffffffLL /* 2^63-1 */ #define SHMEM_QUOTA_MAX_INO_LIMIT 0x7fffffffffffffffLL +#ifdef CONFIG_TMPFS_QUOTA +#define SHMEM_MAXQUOTAS 2 +extern const struct dquot_operations shmem_quota_operations; +extern struct quota_format_type shmem_quota_format; +#endif /* CONFIG_TMPFS_QUOTA */ + #endif diff --git a/mm/shmem.c b/mm/shmem.c index 88e13930fc013..d7529c883eaf5 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -79,6 +79,7 @@ static struct vfsmount *shm_mnt; #include #include #include +#include #include @@ -116,10 +117,12 @@ struct shmem_options { bool full_inums; int huge; int seen; + unsigned short quota_types; #define SHMEM_SEEN_BLOCKS 1 #define SHMEM_SEEN_INODES 2 #define SHMEM_SEEN_HUGE 4 #define SHMEM_SEEN_INUMS 8 +#define SHMEM_SEEN_QUOTA 16 }; #ifdef CONFIG_TMPFS @@ -211,8 +214,11 @@ static inline int shmem_inode_acct_block(struct inode *inode, long pages) if (percpu_counter_compare(&sbinfo->used_blocks, sbinfo->max_blocks - pages) > 0) goto unacct; + if ((err = dquot_alloc_block_nodirty(inode, pages)) != 0) + goto unacct; percpu_counter_add(&sbinfo->used_blocks, pages); - } + } else if ((err = dquot_alloc_block_nodirty(inode, pages)) != 0) + goto unacct; return 0; @@ -226,6 +232,8 @@ static inline void shmem_inode_unacct_blocks(struct inode *inode, long pages) struct shmem_inode_info *info = SHMEM_I(inode); struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); + dquot_free_block_nodirty(inode, pages); + if (sbinfo->max_blocks) percpu_counter_sub(&sbinfo->used_blocks, pages); shmem_unacct_blocks(info->flags, pages); @@ -254,6 +262,47 @@ bool vma_is_shmem(struct vm_area_struct *vma) static LIST_HEAD(shmem_swaplist); static DEFINE_MUTEX(shmem_swaplist_mutex); +#ifdef CONFIG_TMPFS_QUOTA + +static int shmem_enable_quotas(struct super_block *sb, + unsigned short quota_types) +{ + int type, err = 0; + + sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NOLIST_DIRTY; + for (type = 0; type < SHMEM_MAXQUOTAS; type++) { + if (!(quota_types & (1 << type))) + continue; + err = dquot_load_quota_sb(sb, type, QFMT_SHMEM, + DQUOT_USAGE_ENABLED | + DQUOT_LIMITS_ENABLED); + if (err) + goto out_err; + } + return 0; + +out_err: + pr_warn("tmpfs: failed to enable quota tracking (type=%d, err=%d)\n", + type, err); + for (type--; type >= 0; type--) + dquot_quota_off(sb, type); + return err; +} + +static void shmem_disable_quotas(struct super_block *sb) +{ + int type; + + for (type = 0; type < SHMEM_MAXQUOTAS; type++) + dquot_quota_off(sb, type); +} + +static struct dquot **shmem_get_dquots(struct inode *inode) +{ + return SHMEM_I(inode)->i_dquot; +} +#endif /* CONFIG_TMPFS_QUOTA */ + /* * shmem_reserve_inode() performs bookkeeping to reserve a shmem inode, and * produces a novel ino for the newly allocated inode. @@ -360,7 +409,6 @@ static void shmem_recalc_inode(struct inode *inode) freed = info->alloced - info->swapped - inode->i_mapping->nrpages; if (freed > 0) { info->alloced -= freed; - inode->i_blocks -= freed * BLOCKS_PER_PAGE; shmem_inode_unacct_blocks(inode, freed); } } @@ -378,7 +426,6 @@ bool shmem_charge(struct inode *inode, long pages) spin_lock_irqsave(&info->lock, flags); info->alloced += pages; - inode->i_blocks += pages * BLOCKS_PER_PAGE; shmem_recalc_inode(inode); spin_unlock_irqrestore(&info->lock, flags); @@ -394,7 +441,6 @@ void shmem_uncharge(struct inode *inode, long pages) spin_lock_irqsave(&info->lock, flags); info->alloced -= pages; - inode->i_blocks -= pages * BLOCKS_PER_PAGE; shmem_recalc_inode(inode); spin_unlock_irqrestore(&info->lock, flags); @@ -1133,6 +1179,15 @@ static int shmem_setattr(struct mnt_idmap *idmap, } } + /* Transfer quota accounting */ + if (i_uid_needs_update(idmap, attr, inode) || + i_gid_needs_update(idmap, attr,inode)) { + error = dquot_transfer(idmap, inode, attr); + + if (error) + return error; + } + setattr_copy(idmap, inode, attr); if (attr->ia_valid & ATTR_MODE) error = posix_acl_chmod(idmap, dentry, inode->i_mode); @@ -1178,7 +1233,9 @@ static void shmem_evict_inode(struct inode *inode) simple_xattrs_free(&info->xattrs); WARN_ON(inode->i_blocks); shmem_free_inode(inode->i_sb); + dquot_free_inode(inode); clear_inode(inode); + dquot_drop(inode); } static int shmem_find_swap_entries(struct address_space *mapping, @@ -1975,7 +2032,6 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, spin_lock_irq(&info->lock); info->alloced += folio_nr_pages(folio); - inode->i_blocks += (blkcnt_t)BLOCKS_PER_PAGE << folio_order(folio); shmem_recalc_inode(inode); spin_unlock_irq(&info->lock); alloced = true; @@ -2346,9 +2402,10 @@ static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags) #define shmem_initxattrs NULL #endif -static struct inode *shmem_get_inode(struct mnt_idmap *idmap, struct super_block *sb, - struct inode *dir, umode_t mode, dev_t dev, - unsigned long flags) +static struct inode *shmem_get_inode_noquota(struct mnt_idmap *idmap, + struct super_block *sb, + struct inode *dir, umode_t mode, + dev_t dev, unsigned long flags) { struct inode *inode; struct shmem_inode_info *info; @@ -2422,6 +2479,37 @@ static struct inode *shmem_get_inode(struct mnt_idmap *idmap, struct super_block return inode; } +static struct inode *shmem_get_inode(struct mnt_idmap *idmap, + struct super_block *sb, struct inode *dir, + umode_t mode, dev_t dev, unsigned long flags) +{ + int err; + struct inode *inode; + + inode = shmem_get_inode_noquota(idmap, sb, dir, mode, dev, flags); + if (IS_ERR(inode)) + return inode; + + err = dquot_initialize(inode); + if (err) + goto errout; + + err = dquot_alloc_inode(inode); + if (err) { + dquot_drop(inode); + goto errout; + } + return inode; + +errout: + inode->i_flags |= S_NOQUOTA; + iput(inode); + shmem_free_inode(sb); + if (err) + return ERR_PTR(err); + return NULL; +} + #ifdef CONFIG_USERFAULTFD int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd, @@ -2525,7 +2613,6 @@ int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, spin_lock_irq(&info->lock); info->alloced++; - inode->i_blocks += BLOCKS_PER_PAGE; shmem_recalc_inode(inode); spin_unlock_irq(&info->lock); @@ -3372,6 +3459,7 @@ static ssize_t shmem_listxattr(struct dentry *dentry, char *buffer, size_t size) static const struct inode_operations shmem_short_symlink_operations = { .getattr = shmem_getattr, + .setattr = shmem_setattr, .get_link = simple_get_link, #ifdef CONFIG_TMPFS_XATTR .listxattr = shmem_listxattr, @@ -3380,6 +3468,7 @@ static const struct inode_operations shmem_short_symlink_operations = { static const struct inode_operations shmem_symlink_inode_operations = { .getattr = shmem_getattr, + .setattr = shmem_setattr, .get_link = shmem_get_link, #ifdef CONFIG_TMPFS_XATTR .listxattr = shmem_listxattr, @@ -3478,6 +3567,9 @@ enum shmem_param { Opt_uid, Opt_inode32, Opt_inode64, + Opt_quota, + Opt_usrquota, + Opt_grpquota, }; static const struct constant_table shmem_param_enums_huge[] = { @@ -3499,6 +3591,11 @@ const struct fs_parameter_spec shmem_fs_parameters[] = { fsparam_u32 ("uid", Opt_uid), fsparam_flag ("inode32", Opt_inode32), fsparam_flag ("inode64", Opt_inode64), +#ifdef CONFIG_TMPFS_QUOTA + fsparam_flag ("quota", Opt_quota), + fsparam_flag ("usrquota", Opt_usrquota), + fsparam_flag ("grpquota", Opt_grpquota), +#endif {} }; @@ -3582,6 +3679,18 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param) ctx->full_inums = true; ctx->seen |= SHMEM_SEEN_INUMS; break; + case Opt_quota: + ctx->seen |= SHMEM_SEEN_QUOTA; + ctx->quota_types |= (QTYPE_MASK_USR | QTYPE_MASK_GRP); + break; + case Opt_usrquota: + ctx->seen |= SHMEM_SEEN_QUOTA; + ctx->quota_types |= QTYPE_MASK_USR; + break; + case Opt_grpquota: + ctx->seen |= SHMEM_SEEN_QUOTA; + ctx->quota_types |= QTYPE_MASK_GRP; + break; } return 0; @@ -3681,6 +3790,12 @@ static int shmem_reconfigure(struct fs_context *fc) goto out; } + if (ctx->seen & SHMEM_SEEN_QUOTA && + !sb_any_quota_loaded(fc->root->d_sb)) { + err = "Cannot enable quota on remount"; + goto out; + } + if (ctx->seen & SHMEM_SEEN_HUGE) sbinfo->huge = ctx->huge; if (ctx->seen & SHMEM_SEEN_INUMS) @@ -3763,6 +3878,9 @@ static void shmem_put_super(struct super_block *sb) { struct shmem_sb_info *sbinfo = SHMEM_SB(sb); +#ifdef CONFIG_TMPFS_QUOTA + shmem_disable_quotas(sb); +#endif free_percpu(sbinfo->ino_batch); percpu_counter_destroy(&sbinfo->used_blocks); mpol_put(sbinfo->mpol); @@ -3841,6 +3959,17 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) #endif uuid_gen(&sb->s_uuid); +#ifdef CONFIG_TMPFS_QUOTA + if (ctx->seen & SHMEM_SEEN_QUOTA) { + sb->dq_op = &shmem_quota_operations; + sb->s_qcop = &dquot_quotactl_sysfile_ops; + sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP; + + if (shmem_enable_quotas(sb, ctx->quota_types)) + goto failed; + } +#endif /* CONFIG_TMPFS_QUOTA */ + inode = shmem_get_inode(&nop_mnt_idmap, sb, NULL, S_IFDIR | sbinfo->mode, 0, VM_NORESERVE); if (IS_ERR(inode)) { @@ -4016,6 +4145,9 @@ static const struct super_operations shmem_ops = { #ifdef CONFIG_TMPFS .statfs = shmem_statfs, .show_options = shmem_show_options, +#endif +#ifdef CONFIG_TMPFS_QUOTA + .get_dquots = shmem_get_dquots, #endif .evict_inode = shmem_evict_inode, .drop_inode = generic_delete_inode, @@ -4082,6 +4214,14 @@ void __init shmem_init(void) shmem_init_inodecache(); +#ifdef CONFIG_TMPFS_QUOTA + error = register_quota_format(&shmem_quota_format); + if (error < 0) { + pr_err("Could not register quota format\n"); + goto out3; + } +#endif + error = register_filesystem(&shmem_fs_type); if (error) { pr_err("Could not register tmpfs\n"); @@ -4106,6 +4246,10 @@ void __init shmem_init(void) out1: unregister_filesystem(&shmem_fs_type); out2: +#ifdef CONFIG_TMPFS_QUOTA + unregister_quota_format(&shmem_quota_format); +#endif +out3: shmem_destroy_inodecache(); shm_mnt = ERR_PTR(error); } From patchwork Mon Apr 3 08:47:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13197813 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B074FC77B60 for ; Mon, 3 Apr 2023 08:48:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4808A900005; Mon, 3 Apr 2023 04:48:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 343EB900003; Mon, 3 Apr 2023 04:48:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12434900004; Mon, 3 Apr 2023 04:48:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C9633900002 for ; Mon, 3 Apr 2023 04:48:27 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 93089AAD8D for ; Mon, 3 Apr 2023 08:48:27 +0000 (UTC) X-FDA: 80639453454.07.850382D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id E338F20004 for ; Mon, 3 Apr 2023 08:48:25 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=t2f+kQnX; spf=pass (imf13.hostedemail.com: domain of cem@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cem@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680511706; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rCN3sBejzmtOa6W6DCIlR2R1obTO4eESRNws2pNblqM=; b=yy5DzC5KCdD4l1cYCzzfkEDkk+Zsa9h75/iP+rlLZ42shmUuZiZTKp+/R7fjsYnIxHEEzC ZaOVU0r0fgo0MduJO/guWoSN3CqlSJ8CZ/HJgiQoBtT4avkvxf61kKrDlhzqRucQ/idDub oUtu7MG/yzQKQTXXOR7QaOGLMTYojTY= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=t2f+kQnX; spf=pass (imf13.hostedemail.com: domain of cem@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cem@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680511706; a=rsa-sha256; cv=none; b=xjkzGnUGor0Nr9mnUbjAW9EPgOXjlKJxFR291wEiXXsZeivE59qQgs38XYDsLro7QUGCDh jBEwTtDpRnTS2zpq8hvDxdwzd60ooPc/P0J69TaVyWOQUsi/tpqntZ/CADzx9DRdiJJiy1 4PWwuZqOyeA89lSnKJyxHqClZuycImw= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 151D0616CF; Mon, 3 Apr 2023 08:48:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B4FFC433A1; Mon, 3 Apr 2023 08:48:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680511704; bh=LdVL5qK221tpZqXs/tk4ISbpY6XmJKeHGjUE00rYUPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t2f+kQnXIc22dSP4i0ua9+2Dd4BSoYmUUWwBeL4wV9ob9hd0ByntT4GittPehhTKe O1vgdYX6jevHnHlWHtHX1mSqQFqlFZDR8r8DbCjJkuqiTf1E7ujuiUbutZffi1v4B0 xAJVwhnWRrsx46PyQrVoh2oUwMDdtd3p3P/6tOs43S6R0cC34mzJqemRzIF8+owQly ensE+2NN+zVfg2Pq5eKolZwiMKiWAydmbfV10VkfurrkwnDIqlG3HVGNkeS862oBHO zQl6mkH+9EKqYL/LHxYWgR5wx1+U7KbIaLD627zNNOq19jSnez9kg24lL1boN+vqZR 5vHPb/hIOVBrQ== From: cem@kernel.org To: hughd@google.com Cc: jack@suse.cz, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, djwong@kernel.org Subject: [PATCH 6/6] Add default quota limit mount options Date: Mon, 3 Apr 2023 10:47:59 +0200 Message-Id: <20230403084759.884681-7-cem@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230403084759.884681-1-cem@kernel.org> References: <20230403084759.884681-1-cem@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: E338F20004 X-Rspam-User: X-Stat-Signature: x439qhzmp4y5q1xa5ey84nd4na96hif1 X-HE-Tag: 1680511705-56424 X-HE-Meta: U2FsdGVkX19KrgxWcMG8rpujum91iVXFOLo8FhrFacWjuqJDg9jjSwXBYOpf+gWAf3brA+INllc0kGytCFAIj5veZ8YilaRYEds9uia0rv2J9OxUPX73FPnnPNEKtc9Hl6Ml0fFBDL5JOuwlXKHhkxZzw1fEviASiNppyFcOdWuYDI/X3btVjNCTwiKUXUe6VVabACJPRYlYb58c5vK8e7sbln7siSgCx8S9FliMkKLUVjIiecj9NAqO5cZ5sMpZ+606Nml054omCpQhROjHBrFUdAjBBqCzxu65egrXnlRi1eEtBMsOA2Kl/YtX6yZpInH8QcKMGcWNbH+2dZFzafJ53hSYB+XwG2ktVHZ2wlrwVKXbjzNnqemI4v08znTEQWILZ57n1NLIBZQHZ4F6AlV2p0YRCSMhzrKPZMxYEN7pujprbwR0TJ0UMdD7A0NYR6S9lI6GCbi1tGwd3Z/E1DrgVTGrs9UpC1DRq+vfCGlCPIo0udW+YYm65eojSMjDVTXOezBjP+EndeT8GlB19sfS4/uG0jNDHzFfAu75L0pJDiUl3nM15Bag9OASqy52Yo3wQyiT5L2RatQPUcES3w5izSmdih75ALPtNZiSFu2rBDL+OU2X60C2mQySe7XMoKGUmQpHIifO28QQbNxdJMelXIzQVuam7pCuC1Mz1Vdq3eqS2RG2Gm20WfWV/G1tELxm92/ZFO5qXVAQTtgTwtiWPLFTX5IvaaebeOjhdJ6rLrDVGghCbcHnYlrvymLeYjIgxPIhQi/JRhyy9Q1ClDZWzPMDrYDAtKQYYw//Y43fbimWy0FhXmzHMGoIemjMW0NVfTrrYGBwYSSyKayxDslc5Eq82b5/6A4ZZTK7N9PALi88i1u2v4oKftrPavaURXfTwP2WuyFy6GdkI2MNnAcug9K9x9ojQX4AqJNTEcDXO1yFY5SCv2DZrS8pZK+Jjgh/TSiyeVDJjPVeZ3v g0yvejG5 GJ5Uo6Yji7tzmu5l4XbjAOQoJ60N+jAchtKe76UGsdaWpN/HJF8Vyzb0E8YtZiW78QW6MT6szpMPGtqNZviFfkfGvOvsU5WIVxHxIbFPAFPP1zI3dZj0nnI4mlYz5ITM2vvLnEsl+sIhU8AObd4mSPl7ObXV+TPiYoSwwNvWgigUEpf8UDTss6Y57BMXAS6AEYN8t1aN0RcRuwNmCcl6odaHGhmaZQditDxWkKMNYlP4IWKOlkHM+1w64zD+Qtt17A7uma6k6TBzQjRxsYBcQOYnXJDVn0DCetJGUAlECQeB9qP+EqvF6vTz4oEJaq0waGtJ/ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Lukas Czerner Allow system administrator to set default global quota limits at tmpfs mount time. Signed-off-by: Lukas Czerner Signed-off-by: Carlos Maiolino --- Documentation/filesystems/tmpfs.rst | 34 ++++++++++---- include/linux/shmem_fs.h | 8 ++++ mm/shmem.c | 69 +++++++++++++++++++++++++++++ mm/shmem_quota.c | 9 ++++ 4 files changed, 111 insertions(+), 9 deletions(-) diff --git a/Documentation/filesystems/tmpfs.rst b/Documentation/filesystems/tmpfs.rst index 3f8d89bb7e1a5..ec442a3ef90a0 100644 --- a/Documentation/filesystems/tmpfs.rst +++ b/Documentation/filesystems/tmpfs.rst @@ -88,15 +88,31 @@ that instance in a system with many CPUs making intensive use of it. tmpfs also supports quota with the following mount options -======== ============================================================= -quota User and group quota accounting and enforcement is enabled on - the mount. Tmpfs is using hidden system quota files that are - initialized on mount. -usrquota User quota accounting and enforcement is enabled on the - mount. -grpquota Group quota accounting and enforcement is enabled on the - mount. -======== ============================================================= +======================== ================================================= +quota User and group quota accounting and enforcement + is enabled on the mount. Tmpfs is using hidden + system quota files that are initialized on mount. +usrquota User quota accounting and enforcement is enabled + on the mount. +grpquota Group quota accounting and enforcement is enabled + on the mount. +usrquota_block_hardlimit Set global user quota block hard limit. +usrquota_inode_hardlimit Set global user quota inode hard limit. +grpquota_block_hardlimit Set global group quota block hard limit. +grpquota_inode_hardlimit Set global group quota inode hard limit. +======================== ================================================= + +None of the quota related mount options can be set or changed on remount. + +Quota limit parameters accept a suffix k, m or g for kilo, mega and giga +and can't be changed on remount. Default global quota limits are taking +effect for any and all user/group/project except root the first time the +quota entry for user/group/project id is being accessed - typically the +first time an inode with a particular id ownership is being created after +the mount. In other words, instead of the limits being initialized to zero, +they are initialized with the particular value provided with these mount +options. The limits can be changed for any user/group id at any time as it +normally can. tmpfs has a mount option to set the NUMA memory allocation policy for all files in that instance (if CONFIG_NUMA is enabled) - which can be diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 3e7e18726feb5..5527bd27a429d 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -37,6 +37,13 @@ struct shmem_inode_info { (FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL) #define SHMEM_FL_INHERITED (FS_NODUMP_FL | FS_NOATIME_FL) +struct shmem_quota_limits { + qsize_t usrquota_bhardlimit; /* Default user quota block hard limit */ + qsize_t usrquota_ihardlimit; /* Default user quota inode hard limit */ + qsize_t grpquota_bhardlimit; /* Default group quota block hard limit */ + qsize_t grpquota_ihardlimit; /* Default group quota inode hard limit */ +}; + struct shmem_sb_info { unsigned long max_blocks; /* How many blocks are allowed */ struct percpu_counter used_blocks; /* How many are allocated */ @@ -54,6 +61,7 @@ struct shmem_sb_info { spinlock_t shrinklist_lock; /* Protects shrinklist */ struct list_head shrinklist; /* List of shinkable inodes */ unsigned long shrinklist_len; /* Length of shrinklist */ + struct shmem_quota_limits qlimits; /* Default quota limits */ }; static inline struct shmem_inode_info *SHMEM_I(struct inode *inode) diff --git a/mm/shmem.c b/mm/shmem.c index d7529c883eaf5..80270213fd012 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -118,6 +118,7 @@ struct shmem_options { int huge; int seen; unsigned short quota_types; + struct shmem_quota_limits qlimits; #define SHMEM_SEEN_BLOCKS 1 #define SHMEM_SEEN_INODES 2 #define SHMEM_SEEN_HUGE 4 @@ -3570,6 +3571,10 @@ enum shmem_param { Opt_quota, Opt_usrquota, Opt_grpquota, + Opt_usrquota_block_hardlimit, + Opt_usrquota_inode_hardlimit, + Opt_grpquota_block_hardlimit, + Opt_grpquota_inode_hardlimit, }; static const struct constant_table shmem_param_enums_huge[] = { @@ -3595,6 +3600,10 @@ const struct fs_parameter_spec shmem_fs_parameters[] = { fsparam_flag ("quota", Opt_quota), fsparam_flag ("usrquota", Opt_usrquota), fsparam_flag ("grpquota", Opt_grpquota), + fsparam_string("usrquota_block_hardlimit", Opt_usrquota_block_hardlimit), + fsparam_string("usrquota_inode_hardlimit", Opt_usrquota_inode_hardlimit), + fsparam_string("grpquota_block_hardlimit", Opt_grpquota_block_hardlimit), + fsparam_string("grpquota_inode_hardlimit", Opt_grpquota_inode_hardlimit), #endif {} }; @@ -3691,6 +3700,50 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param) ctx->seen |= SHMEM_SEEN_QUOTA; ctx->quota_types |= QTYPE_MASK_GRP; break; + case Opt_usrquota_block_hardlimit: + size = memparse(param->string, &rest); + if (*rest || !size) + goto bad_value; + if (size > SHMEM_QUOTA_MAX_SPC_LIMIT) + return invalfc(fc, + "User quota block hardlimit too large."); + ctx->qlimits.usrquota_bhardlimit = size; + ctx->seen |= SHMEM_SEEN_QUOTA; + ctx->quota_types |= QTYPE_MASK_USR; + break; + case Opt_grpquota_block_hardlimit: + size = memparse(param->string, &rest); + if (*rest || !size) + goto bad_value; + if (size > SHMEM_QUOTA_MAX_SPC_LIMIT) + return invalfc(fc, + "Group quota block hardlimit too large."); + ctx->qlimits.grpquota_bhardlimit = size; + ctx->seen |= SHMEM_SEEN_QUOTA; + ctx->quota_types |= QTYPE_MASK_GRP; + break; + case Opt_usrquota_inode_hardlimit: + size = memparse(param->string, &rest); + if (*rest || !size) + goto bad_value; + if (size > SHMEM_QUOTA_MAX_INO_LIMIT) + return invalfc(fc, + "User quota inode hardlimit too large."); + ctx->qlimits.usrquota_ihardlimit = size; + ctx->seen |= SHMEM_SEEN_QUOTA; + ctx->quota_types |= QTYPE_MASK_USR; + break; + case Opt_grpquota_inode_hardlimit: + size = memparse(param->string, &rest); + if (*rest || !size) + goto bad_value; + if (size > SHMEM_QUOTA_MAX_INO_LIMIT) + return invalfc(fc, + "Group quota inode hardlimit too large."); + ctx->qlimits.grpquota_ihardlimit = size; + ctx->seen |= SHMEM_SEEN_QUOTA; + ctx->quota_types |= QTYPE_MASK_GRP; + break; } return 0; @@ -3796,6 +3849,18 @@ static int shmem_reconfigure(struct fs_context *fc) goto out; } +#ifdef CONFIG_TMPFS_QUOTA +#define CHANGED_LIMIT(name) \ + (ctx->qlimits.name## hardlimit && \ + (ctx->qlimits.name## hardlimit != sbinfo->qlimits.name## hardlimit)) + + if (CHANGED_LIMIT(usrquota_b) || CHANGED_LIMIT(usrquota_i) || + CHANGED_LIMIT(grpquota_b) || CHANGED_LIMIT(grpquota_i)) { + err = "Cannot change global quota limit on remount"; + goto out; + } +#endif /* CONFIG_TMPFS_QUOTA */ + if (ctx->seen & SHMEM_SEEN_HUGE) sbinfo->huge = ctx->huge; if (ctx->seen & SHMEM_SEEN_INUMS) @@ -3965,6 +4030,10 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_qcop = &dquot_quotactl_sysfile_ops; sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP; + /* Copy the default limits from ctx into sbinfo */ + memcpy(&sbinfo->qlimits, &ctx->qlimits, + sizeof(struct shmem_quota_limits)); + if (shmem_enable_quotas(sb, ctx->quota_types)) goto failed; } diff --git a/mm/shmem_quota.c b/mm/shmem_quota.c index c415043a71e67..77ba7c3494c70 100644 --- a/mm/shmem_quota.c +++ b/mm/shmem_quota.c @@ -168,6 +168,7 @@ static int shmem_acquire_dquot(struct dquot *dquot) { struct mem_dqinfo *info = sb_dqinfo(dquot->dq_sb, dquot->dq_id.type); struct rb_node **n = &((struct rb_root *)info->dqi_priv)->rb_node; + struct shmem_sb_info *sbinfo = dquot->dq_sb->s_fs_info; struct rb_node *parent = NULL, *new_node = NULL; struct quota_id *new_entry, *entry; qid_t id = from_kqid(&init_user_ns, dquot->dq_id); @@ -197,6 +198,14 @@ static int shmem_acquire_dquot(struct dquot *dquot) } new_entry->id = id; + if (dquot->dq_id.type == USRQUOTA) { + new_entry->bhardlimit = sbinfo->qlimits.usrquota_bhardlimit; + new_entry->ihardlimit = sbinfo->qlimits.usrquota_ihardlimit; + } else if (dquot->dq_id.type == GRPQUOTA) { + new_entry->bhardlimit = sbinfo->qlimits.grpquota_bhardlimit; + new_entry->ihardlimit = sbinfo->qlimits.grpquota_ihardlimit; + } + new_node = &new_entry->node; rb_link_node(new_node, parent, n); rb_insert_color(new_node, (struct rb_root *)info->dqi_priv);