diff mbox series

[2/3] quota: Support using the page cache for quota files

Message ID 20220605143815.2330891-3-willy@infradead.org
State Rejected
Headers show
Series Cache quota files in the page cache | expand

Commit Message

Matthew Wilcox (Oracle) June 5, 2022, 2:38 p.m. UTC
Quota files are usually cached in the buffer cache of the block device.
These support functions allow a filesystem to cache quota files in their
page cache instead which is more efficient.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/quota/dquot.c         | 68 ++++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h       |  2 ++
 include/linux/quotaops.h |  1 +
 3 files changed, 71 insertions(+)

Comments

kernel test robot June 6, 2022, 2:53 a.m. UTC | #1
Hi "Matthew,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tytso-ext4/dev]
[also build test WARNING on jack-fs/for_next linus/master v5.19-rc1 next-20220603]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Matthew-Wilcox-Oracle/Cache-quota-files-in-the-page-cache/20220606-021629
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
config: mips-mtx1_defconfig (https://download.01.org/0day-ci/archive/20220606/202206061045.oKwjpuXb-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project b92436efcb7813fc481b30f2593a4907568d917a)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install mips cross compiling tool for clang build
        # apt-get install binutils-mipsel-linux-gnu
        # https://github.com/intel-lab-lkp/linux/commit/a7ff347e002ef476c8c116f30858f83529638a9b
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Matthew-Wilcox-Oracle/Cache-quota-files-in-the-page-cache/20220606-021629
        git checkout a7ff347e002ef476c8c116f30858f83529638a9b
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=mips SHELL=/bin/bash fs/quota/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> fs/quota/dquot.c:2184:19: warning: comparison of distinct pointer types ('typeof (toread) *' (aka 'unsigned int *') and 'typeof (((1UL) << 12) - ((unsigned long)(pos) & ~(~((1 << 12) - 1)))) *' (aka 'unsigned long *')) [-Wcompare-distinct-pointer-types]
                   size_t tocopy = min(toread, PAGE_SIZE - offset_in_page(pos));
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:45:19: note: expanded from macro 'min'
   #define min(x, y)       __careful_cmp(x, y, <)
                           ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:36:24: note: expanded from macro '__careful_cmp'
           __builtin_choose_expr(__safe_cmp(x, y), \
                                 ^~~~~~~~~~~~~~~~
   include/linux/minmax.h:26:4: note: expanded from macro '__safe_cmp'
                   (__typecheck(x, y) && __no_side_effects(x, y))
                    ^~~~~~~~~~~~~~~~~
   include/linux/minmax.h:20:28: note: expanded from macro '__typecheck'
           (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
                      ~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~
   1 warning generated.


vim +2184 fs/quota/dquot.c

  2165	
  2166	ssize_t generic_quota_read(struct super_block *sb, int type, char *data,
  2167				      size_t len, loff_t pos)
  2168	{
  2169		struct inode *inode = sb_dqopt(sb)->files[type];
  2170		struct address_space *mapping = inode->i_mapping;
  2171		size_t toread;
  2172		pgoff_t index;
  2173		loff_t i_size = i_size_read(inode);
  2174	
  2175		if (pos > i_size)
  2176			return 0;
  2177		if (pos + len > i_size)
  2178			len = i_size - pos;
  2179		toread = len;
  2180		index = pos / PAGE_SIZE;
  2181	
  2182		while (toread > 0) {
  2183			struct folio *folio = read_mapping_folio(mapping, index, NULL);
> 2184			size_t tocopy = min(toread, PAGE_SIZE - offset_in_page(pos));
  2185			void *src;
  2186	
  2187			if (folio == ERR_PTR(-ENOMEM)) {
  2188				memalloc_retry_wait(GFP_NOFS);
  2189				continue;
  2190			} else if (IS_ERR(folio))
  2191				return PTR_ERR(folio);
  2192	
  2193			src = kmap_local_folio(folio, offset_in_folio(folio, pos));
  2194			memcpy(data, src, tocopy);
  2195			kunmap_local(src);
  2196			folio_put(folio);
  2197	
  2198			toread -= tocopy;
  2199			data += tocopy;
  2200			pos += tocopy;
  2201			index++;
  2202		}
  2203		return len;
  2204	}
  2205	EXPORT_SYMBOL(generic_quota_read);
  2206
kernel test robot June 6, 2022, 4:05 a.m. UTC | #2
Hi "Matthew,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tytso-ext4/dev]
[also build test WARNING on jack-fs/for_next linus/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Matthew-Wilcox-Oracle/Cache-quota-files-in-the-page-cache/20220606-021629
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
config: riscv-randconfig-c006-20220605 (https://download.01.org/0day-ci/archive/20220606/202206061112.keHlFIBA-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project b92436efcb7813fc481b30f2593a4907568d917a)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install riscv cross compiling tool for clang build
        # apt-get install binutils-riscv-linux-gnu
        # https://github.com/intel-lab-lkp/linux/commit/a7ff347e002ef476c8c116f30858f83529638a9b
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Matthew-Wilcox-Oracle/Cache-quota-files-in-the-page-cache/20220606-021629
        git checkout a7ff347e002ef476c8c116f30858f83529638a9b
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash fs/quota/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> fs/quota/dquot.c:2184:19: warning: comparison of distinct pointer types ('typeof (toread) *' (aka 'unsigned int *') and 'typeof (((1UL) << (12)) - ((unsigned long)(pos) & ~(~(((1UL) << (12)) - 1)))) *' (aka 'unsigned long *')) [-Wcompare-distinct-pointer-types]
                   size_t tocopy = min(toread, PAGE_SIZE - offset_in_page(pos));
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:45:19: note: expanded from macro 'min'
   #define min(x, y)       __careful_cmp(x, y, <)
                           ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:36:24: note: expanded from macro '__careful_cmp'
           __builtin_choose_expr(__safe_cmp(x, y), \
                                 ^~~~~~~~~~~~~~~~
   include/linux/minmax.h:26:4: note: expanded from macro '__safe_cmp'
                   (__typecheck(x, y) && __no_side_effects(x, y))
                    ^~~~~~~~~~~~~~~~~
   include/linux/minmax.h:20:28: note: expanded from macro '__typecheck'
           (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
                      ~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   error: A dwo section may not contain relocations
   fatal error: too many errors emitted, stopping now [-ferror-limit=]
   1 warning and 20 errors generated.


vim +2184 fs/quota/dquot.c

  2165	
  2166	ssize_t generic_quota_read(struct super_block *sb, int type, char *data,
  2167				      size_t len, loff_t pos)
  2168	{
  2169		struct inode *inode = sb_dqopt(sb)->files[type];
  2170		struct address_space *mapping = inode->i_mapping;
  2171		size_t toread;
  2172		pgoff_t index;
  2173		loff_t i_size = i_size_read(inode);
  2174	
  2175		if (pos > i_size)
  2176			return 0;
  2177		if (pos + len > i_size)
  2178			len = i_size - pos;
  2179		toread = len;
  2180		index = pos / PAGE_SIZE;
  2181	
  2182		while (toread > 0) {
  2183			struct folio *folio = read_mapping_folio(mapping, index, NULL);
> 2184			size_t tocopy = min(toread, PAGE_SIZE - offset_in_page(pos));
  2185			void *src;
  2186	
  2187			if (folio == ERR_PTR(-ENOMEM)) {
  2188				memalloc_retry_wait(GFP_NOFS);
  2189				continue;
  2190			} else if (IS_ERR(folio))
  2191				return PTR_ERR(folio);
  2192	
  2193			src = kmap_local_folio(folio, offset_in_folio(folio, pos));
  2194			memcpy(data, src, tocopy);
  2195			kunmap_local(src);
  2196			folio_put(folio);
  2197	
  2198			toread -= tocopy;
  2199			data += tocopy;
  2200			pos += tocopy;
  2201			index++;
  2202		}
  2203		return len;
  2204	}
  2205	EXPORT_SYMBOL(generic_quota_read);
  2206
kernel test robot June 6, 2022, 4:36 a.m. UTC | #3
Hi "Matthew,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tytso-ext4/dev]
[also build test WARNING on jack-fs/for_next linus/master v5.19-rc1 next-20220603]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Matthew-Wilcox-Oracle/Cache-quota-files-in-the-page-cache/20220606-021629
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
config: i386-randconfig-s002 (https://download.01.org/0day-ci/archive/20220606/202206061211.HKxbKbgS-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-1) 11.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.4-18-g56afb504-dirty
        # https://github.com/intel-lab-lkp/linux/commit/a7ff347e002ef476c8c116f30858f83529638a9b
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Matthew-Wilcox-Oracle/Cache-quota-files-in-the-page-cache/20220606-021629
        git checkout a7ff347e002ef476c8c116f30858f83529638a9b
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 SHELL=/bin/bash fs/quota/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)
>> fs/quota/dquot.c:2184:33: sparse: sparse: incompatible types in comparison expression (different type sizes):
>> fs/quota/dquot.c:2184:33: sparse:    unsigned int *
>> fs/quota/dquot.c:2184:33: sparse:    unsigned long *

vim +2184 fs/quota/dquot.c

  2165	
  2166	ssize_t generic_quota_read(struct super_block *sb, int type, char *data,
  2167				      size_t len, loff_t pos)
  2168	{
  2169		struct inode *inode = sb_dqopt(sb)->files[type];
  2170		struct address_space *mapping = inode->i_mapping;
  2171		size_t toread;
  2172		pgoff_t index;
  2173		loff_t i_size = i_size_read(inode);
  2174	
  2175		if (pos > i_size)
  2176			return 0;
  2177		if (pos + len > i_size)
  2178			len = i_size - pos;
  2179		toread = len;
  2180		index = pos / PAGE_SIZE;
  2181	
  2182		while (toread > 0) {
  2183			struct folio *folio = read_mapping_folio(mapping, index, NULL);
> 2184			size_t tocopy = min(toread, PAGE_SIZE - offset_in_page(pos));
  2185			void *src;
  2186	
  2187			if (folio == ERR_PTR(-ENOMEM)) {
  2188				memalloc_retry_wait(GFP_NOFS);
  2189				continue;
  2190			} else if (IS_ERR(folio))
  2191				return PTR_ERR(folio);
  2192	
  2193			src = kmap_local_folio(folio, offset_in_folio(folio, pos));
  2194			memcpy(data, src, tocopy);
  2195			kunmap_local(src);
  2196			folio_put(folio);
  2197	
  2198			toread -= tocopy;
  2199			data += tocopy;
  2200			pos += tocopy;
  2201			index++;
  2202		}
  2203		return len;
  2204	}
  2205	EXPORT_SYMBOL(generic_quota_read);
  2206
diff mbox series

Patch

diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
index cdb22d6d7488..ef9aeae802c7 100644
--- a/fs/quota/dquot.c
+++ b/fs/quota/dquot.c
@@ -59,6 +59,7 @@ 
 #include <linux/fs.h>
 #include <linux/mount.h>
 #include <linux/mm.h>
+#include <linux/pagemap.h>
 #include <linux/time.h>
 #include <linux/types.h>
 #include <linux/string.h>
@@ -73,6 +74,7 @@ 
 #include <linux/proc_fs.h>
 #include <linux/security.h>
 #include <linux/sched.h>
+#include <linux/sched/mm.h>
 #include <linux/cred.h>
 #include <linux/kmod.h>
 #include <linux/namei.h>
@@ -2161,6 +2163,72 @@  const struct dquot_operations dquot_operations = {
 };
 EXPORT_SYMBOL(dquot_operations);
 
+ssize_t generic_quota_read(struct super_block *sb, int type, char *data,
+			      size_t len, loff_t pos)
+{
+	struct inode *inode = sb_dqopt(sb)->files[type];
+	struct address_space *mapping = inode->i_mapping;
+	size_t toread;
+	pgoff_t index;
+	loff_t i_size = i_size_read(inode);
+
+	if (pos > i_size)
+		return 0;
+	if (pos + len > i_size)
+		len = i_size - pos;
+	toread = len;
+	index = pos / PAGE_SIZE;
+
+	while (toread > 0) {
+		struct folio *folio = read_mapping_folio(mapping, index, NULL);
+		size_t tocopy = min(toread, PAGE_SIZE - offset_in_page(pos));
+		void *src;
+
+		if (folio == ERR_PTR(-ENOMEM)) {
+			memalloc_retry_wait(GFP_NOFS);
+			continue;
+		} else if (IS_ERR(folio))
+			return PTR_ERR(folio);
+
+		src = kmap_local_folio(folio, offset_in_folio(folio, pos));
+		memcpy(data, src, tocopy);
+		kunmap_local(src);
+		folio_put(folio);
+
+		toread -= tocopy;
+		data += tocopy;
+		pos += tocopy;
+		index++;
+	}
+	return len;
+}
+EXPORT_SYMBOL(generic_quota_read);
+
+int generic_quota_sync(struct super_block *sb, int type)
+{
+	struct quota_info *dqopt = sb_dqopt(sb);
+	int i, ret;
+
+	ret = dquot_writeback_dquots(sb, type);
+	if (ret)
+		return ret;
+	if (dqopt->flags & DQUOT_QUOTA_SYS_FILE)
+		return 0;
+
+	for (i = 0; i < MAXQUOTAS; i++) {
+		if (type != -1 && type != i)
+			continue;
+		if (!sb_has_quota_active(sb, i))
+			continue;
+		ret = write_inode_now(dqopt->files[i], true);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(generic_quota_sync);
+
 /*
  * Generic helper for ->open on filesystems supporting disk quotas.
  */
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 9ad5e3520fae..2e798fc4c118 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2449,6 +2449,8 @@  struct super_block *sget(struct file_system_type *type,
 			int (*test)(struct super_block *,void *),
 			int (*set)(struct super_block *,void *),
 			int flags, void *data);
+ssize_t generic_quota_read(struct super_block *sb, int type, char *data,
+		size_t len, loff_t pos);
 
 /* Alas, no aliases. Too much hassle with bringing module.h everywhere */
 #define fops_get(fops) \
diff --git a/include/linux/quotaops.h b/include/linux/quotaops.h
index a0f6668924d3..fe12b04948f6 100644
--- a/include/linux/quotaops.h
+++ b/include/linux/quotaops.h
@@ -105,6 +105,7 @@  int dquot_quota_on_mount(struct super_block *sb, char *qf_name,
 int dquot_quota_off(struct super_block *sb, int type);
 int dquot_writeback_dquots(struct super_block *sb, int type);
 int dquot_quota_sync(struct super_block *sb, int type);
+int generic_quota_sync(struct super_block *sb, int type);
 int dquot_get_state(struct super_block *sb, struct qc_state *state);
 int dquot_set_dqinfo(struct super_block *sb, int type, struct qc_info *ii);
 int dquot_get_dqblk(struct super_block *sb, struct kqid id,