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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx>
---
 fs/quota/dquot.c         | 68 ++++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h       |  2 ++
 include/linux/quotaops.h |  1 +
 3 files changed, 71 insertions(+)

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,
-- 
2.35.1




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux