Commit c7e263ab authored by Lukas Czerner's avatar Lukas Czerner Committed by Christian Brauner

shmem: make shmem_inode_acct_block() return error

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: default avatarLukas Czerner <lczerner@redhat.com>
Signed-off-by: default avatarCarlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Message-Id: <20230725144510.253763-2-cem@kernel.org>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent 5d0c230f
...@@ -199,13 +199,14 @@ static inline void shmem_unacct_blocks(unsigned long flags, long pages) ...@@ -199,13 +199,14 @@ static inline void shmem_unacct_blocks(unsigned long flags, long pages)
vm_unacct_memory(pages * VM_ACCT(PAGE_SIZE)); 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_inode_info *info = SHMEM_I(inode);
struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
int err = -ENOSPC;
if (shmem_acct_block(info->flags, pages)) if (shmem_acct_block(info->flags, pages))
return false; return err;
if (sbinfo->max_blocks) { if (sbinfo->max_blocks) {
if (percpu_counter_compare(&sbinfo->used_blocks, if (percpu_counter_compare(&sbinfo->used_blocks,
...@@ -214,11 +215,11 @@ static inline bool shmem_inode_acct_block(struct inode *inode, long pages) ...@@ -214,11 +215,11 @@ static inline bool shmem_inode_acct_block(struct inode *inode, long pages)
percpu_counter_add(&sbinfo->used_blocks, pages); percpu_counter_add(&sbinfo->used_blocks, pages);
} }
return true; return 0;
unacct: unacct:
shmem_unacct_blocks(info->flags, pages); shmem_unacct_blocks(info->flags, pages);
return false; return err;
} }
static inline void shmem_inode_unacct_blocks(struct inode *inode, long pages) static inline void shmem_inode_unacct_blocks(struct inode *inode, long pages)
...@@ -370,7 +371,7 @@ bool shmem_charge(struct inode *inode, long pages) ...@@ -370,7 +371,7 @@ bool shmem_charge(struct inode *inode, long pages)
struct shmem_inode_info *info = SHMEM_I(inode); struct shmem_inode_info *info = SHMEM_I(inode);
unsigned long flags; unsigned long flags;
if (!shmem_inode_acct_block(inode, pages)) if (shmem_inode_acct_block(inode, pages))
return false; return false;
/* nrpages adjustment first, then shmem_recalc_inode() when balanced */ /* nrpages adjustment first, then shmem_recalc_inode() when balanced */
...@@ -1588,13 +1589,14 @@ static struct folio *shmem_alloc_and_acct_folio(gfp_t gfp, struct inode *inode, ...@@ -1588,13 +1589,14 @@ static struct folio *shmem_alloc_and_acct_folio(gfp_t gfp, struct inode *inode,
struct shmem_inode_info *info = SHMEM_I(inode); struct shmem_inode_info *info = SHMEM_I(inode);
struct folio *folio; struct folio *folio;
int nr; int nr;
int err = -ENOSPC; int err;
if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE))
huge = false; huge = false;
nr = huge ? HPAGE_PMD_NR : 1; nr = huge ? HPAGE_PMD_NR : 1;
if (!shmem_inode_acct_block(inode, nr)) err = shmem_inode_acct_block(inode, nr);
if (err)
goto failed; goto failed;
if (huge) if (huge)
...@@ -2445,7 +2447,7 @@ int shmem_mfill_atomic_pte(pmd_t *dst_pmd, ...@@ -2445,7 +2447,7 @@ int shmem_mfill_atomic_pte(pmd_t *dst_pmd,
int ret; int ret;
pgoff_t max_off; 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, * We may have got a page, returned -ENOENT triggering a retry,
* and now we find ourselves with -ENOMEM. Release the page, to * and now we find ourselves with -ENOMEM. Release the page, to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment