Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tmpfs: restore functionality of nr_inodes=0

Commit e809d5f0b5c9 ("tmpfs: per-superblock i_ino support") made changes
to shmem_reserve_inode() in mm/shmem.c, however the original test for
(sbinfo->max_inodes) got dropped. This causes mounting tmpfs with option
nr_inodes=0 to fail:

# mount -ttmpfs -onr_inodes=0 none /ext0
mount: /ext0: mount(2) system call failed: Cannot allocate memory.

This patch restores the nr_inodes=0 functionality.

Fixes: e809d5f0b5c9 ("tmpfs: per-superblock i_ino support")
Signed-off-by: Byron Stanoszek <gandalf@winds.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Hugh Dickins <hughd@google.com>
Acked-by: Chris Down <chris@chrisdown.name>
Link: https://lkml.kernel.org/r/20200902035715.16414-1-gandalf@winds.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Byron Stanoszek and committed by
Linus Torvalds
bb3e96d6 0964730b

+6 -4
+6 -4
mm/shmem.c
··· 279 279 280 280 if (!(sb->s_flags & SB_KERNMOUNT)) { 281 281 spin_lock(&sbinfo->stat_lock); 282 - if (!sbinfo->free_inodes) { 283 - spin_unlock(&sbinfo->stat_lock); 284 - return -ENOSPC; 282 + if (sbinfo->max_inodes) { 283 + if (!sbinfo->free_inodes) { 284 + spin_unlock(&sbinfo->stat_lock); 285 + return -ENOSPC; 286 + } 287 + sbinfo->free_inodes--; 285 288 } 286 - sbinfo->free_inodes--; 287 289 if (inop) { 288 290 ino = sbinfo->next_ino++; 289 291 if (unlikely(is_zero_ino(ino)))