ceph: kernel client cephfs quota support
Subsystems (2)
cover ceph: kernel client cephfs quota support
A cephfs-specific quota implementation has been available in the user-space fuse client for a while. This quota implementation allows an administrator to restrict the number of bytes and/or the number of files in a filesystem subtree. This quota implementation, however, is supported at the client-level only, which means that cooperation is required between different clients accessing the system.
This obviously assumes that all clients are trusted entities and will respect the quotas, preventing users from exceeding the quota limits. Since the kernel client doesn't support quotas, it has not been possible to use it in a cluster where quotas are a requirement.
This patchset is an RFC that adds kernel client support for cephfs quotas as it is currently implemented in the ceph fuse client. Note however that this patchset is not yet feature complete, as it only implements the max_files quota (max_bytes is still missing). I just wanted to have some early review before continuing, specially in the reverse path walk code, as this seems to be the perfect place to fail ;-)
I've obviously done some basic testing on this patchset but nothing really complex -- single client on small (VMs) cluster. Jan (thanks a lot!) has pushed a branch that should enable testing using teuthology, but unfortunately we haven't tried it:
https://github.com/jan--f/ceph/tree/wip-quota-kernel-testing
[ Note that the goal is to simply use the existing workunit quota.sh once
the kernel client has support for both max_files and max_bytes. ]
Luis Henriques (3):
ceph: quota: add initial infrastructure to support cephfs quotas
ceph: quotas: support for ceph.quota.max_files
ceph: quota: don't allow cross-quota renames
fs/ceph/Makefile | 2 +- fs/ceph/dir.c | 15 ++++ fs/ceph/file.c | 4 +- fs/ceph/inode.c | 6 ++ fs/ceph/mds_client.c | 21 ++++++ fs/ceph/mds_client.h | 2 + fs/ceph/quota.c | 136 +++++++++++++++++++++++++++++++++++++ fs/ceph/super.h | 10 +++ fs/ceph/xattr.c | 45 ++++++++++++ include/linux/ceph/ceph_features.h | 3 +- include/linux/ceph/ceph_fs.h | 17 +++++ 11 files changed, 258 insertions(+), 3 deletions(-) create mode 100644 fs/ceph/quota.c
RFC PATCH 1/3 ceph: quota: add initial infrastructure to support cephfs quotas
This patch adds the infrastructure required to support cephfs quotas as it is currently implemented in the ceph fuse client. Cephfs quotas can be set on any directory, and can restrict the number of bytes or the number of files stored beneath that point in the directory hierarchy.
Quotas are set using the extended attributes 'ceph.quota.max_files' and 'ceph.quota.max_bytes', and can be removed by setting these attributes to '0'.
--- fs/ceph/Makefile | 2 +- fs/ceph/inode.c | 6 ++++ fs/ceph/mds_client.c | 21 ++++++++++++++ fs/ceph/mds_client.h | 2 ++ fs/ceph/quota.c | 59 ++++++++++++++++++++++++++++++++++++++ fs/ceph/super.h | 8 ++++++ fs/ceph/xattr.c | 45 +++++++++++++++++++++++++++++ include/linux/ceph/ceph_features.h | 3 +- include/linux/ceph/ceph_fs.h | 17 +++++++++++ 9 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 fs/ceph/quota.c
fs/ceph/Makefile +1 -1
@@ -5,7 +5,7 @@ obj-$(CONFIG_CEPH_FS) += ceph.o ceph-y := super.o inode.o dir.o file.o locks.o addr.o ioctl.o \ - export.o caps.o snap.o xattr.o \ + export.o caps.o snap.o xattr.o quota.o \ mds_client.o mdsmap.o strings.o ceph_frag.o \ debugfs.o
fs/ceph/inode.c +6 -0
@@ -443,6 +443,9 @@ struct inode *ceph_alloc_inode(struct super_block *sb)atomic64_set (&ci->i_complete_seq[1 ],0 ); ci->i_symlink =NULL ; + ci->i_max_bytes =0 ; + ci->i_max_files =0 ; +memset (&ci->i_dir_layout,0 ,sizeof (ci->i_dir_layout));RCU_INIT_POINTER (ci->i_layout.pool_ns,NULL );
@@ -792,6 +795,9 @@ static int fill_inode(struct inode *inode, struct page *locked_page, inode->i_rdev =le32_to_cpu (info->rdev); inode->i_blkbits =fls (le32_to_cpu (info->layout.fl_stripe_unit)) -1 ; + ci->i_max_bytes = iinfo->max_bytes; + ci->i_max_files = iinfo->max_files; +if ((new_version || (new_issued &CEPH_CAP_AUTH_SHARED )) && (issued &CEPH_CAP_AUTH_EXCL ) ==0 ) { inode->i_mode =le32_to_cpu (info->mode);
fs/ceph/mds_client.c +21 -0
@@ -100,6 +100,24 @@ static int parse_reply_info_in(void **p, void *end, }else info->inline_version =CEPH_INLINE_NONE ; +if (features &CEPH_FEATURE_MDS_QUOTA ) { +u8 struct_v, struct_compat; +u32 struct_len; + +/* both struct_v and struct_compat are expected to be >= 1 */ +ceph_decode_8_safe (p, end, struct_v, bad); +ceph_decode_8_safe (p, end, struct_compat, bad); +if (!struct_v || !struct_compat) + goto bad; +ceph_decode_32_safe (p, end, struct_len, bad); +ceph_decode_need (p, end, struct_len, bad); +ceph_decode_64_safe (p, end, info->max_bytes, bad); +ceph_decode_64_safe (p, end, info->max_files, bad); + }else { + info->max_bytes =0 ; + info->max_files =0 ; + } + info->pool_ns_len =0 ; info->pool_ns_data =NULL ;if (features &CEPH_FEATURE_FS_FILE_LAYOUT_V2 ) {
@@ -3990,6 +4008,9 @@ static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)case CEPH_MSG_CLIENT_LEASE :handle_lease (mdsc, s, msg);break ; +case CEPH_MSG_CLIENT_QUOTA : +ceph_handle_quota (mdsc, s, msg); +break ;default : pr_err("received unknown message type %d %s\n", type,
fs/ceph/mds_client.h +2 -0
@@ -47,6 +47,8 @@ struct ceph_mds_reply_info_in {char *inline_data;u32 pool_ns_len;char *pool_ns_data; +u64 max_bytes; +u64 max_files; };struct ceph_mds_reply_dir_entry {
fs/ceph/quota.c new file +59 -0
59 lines not on this page · raw message
fs/ceph/super.h +8 -0
@@ -296,6 +296,9 @@ struct ceph_inode_info {u64 i_rbytes, i_rfiles, i_rsubdirs;u64 i_files, i_subdirs; +/* quotas */ +u64 i_max_bytes, i_max_files; +struct rb_root i_fragtree;int i_fragtree_nsplits;struct mutex i_fragtree_mutex;
@@ -1004,4 +1007,9 @@ extern int lock_to_ceph_filelock(struct file_lock *fl, struct ceph_filelock *c);extern int ceph_fs_debugfs_init (struct ceph_fs_client *client);extern void ceph_fs_debugfs_cleanup (struct ceph_fs_client *client); +/* quota.c */ +extern void ceph_handle_quota (struct ceph_mds_client *mdsc, +struct ceph_mds_session *session, +struct ceph_msg *msg); +#endif /* _FS_CEPH_SUPER_H */
fs/ceph/xattr.c +45 -0
63 lines not on this page · raw message
include/linux/ceph/ceph_features.h +2 -1
@@ -208,7 +208,8 @@ DEFINE_CEPH_FEATURE_DEPRECATED(63, 1, RESERVED_BROKEN, LUMINOUS) // client-facin CEPH_FEATURE_SERVER_JEWEL | \ CEPH_FEATURE_MON_STATEFUL_SUB | \ CEPH_FEATURE_CRUSH_TUNABLES5 | \ - CEPH_FEATURE_NEW_OSDOPREPLY_ENCODING) + CEPH_FEATURE_NEW_OSDOPREPLY_ENCODING | \ + CEPH_FEATURE_MDS_QUOTA)#define CEPH_FEATURES_REQUIRED_DEFAULT \ (CEPH_FEATURE_NOSRCADDR | \
include/linux/ceph/ceph_fs.h +17 -0
@@ -133,6 +133,7 @@ struct ceph_dir_layout {#define CEPH_MSG_CLIENT_LEASE 0x311#define CEPH_MSG_CLIENT_SNAP 0x312#define CEPH_MSG_CLIENT_CAPRELEASE 0x313 +#define CEPH_MSG_CLIENT_QUOTA 0x314/* pool ops */ #define CEPH_MSG_POOLOP_REPLY 48
@@ -802,4 +803,20 @@ struct ceph_mds_snap_realm { } __attribute__ ((packed));/* followed by my snap list, then prior parent snap list */ +/* +* quotas +*/ +struct ceph_mds_quota { +__le64 ino;/* ino */ +struct ceph_timespec rctime; +__le64 rbytes;/* dir stats */ +__le64 rfiles; +__le64 rsubdirs; +__u8 struct_v;/* compat */ +__u8 struct_compat; +__le32 struct_len; +__le64 max_bytes;/* quota max. bytes */ +__le64 max_files;/* quota max. files */ +} __attribute__ ((packed)); +#endif
RFC PATCH 2/3 ceph: quotas: support for ceph.quota.max_files
In reply to Luis HenriquesThis patch adds support for the max_files quota. It hooks into all the ceph functions that add new filesystem objects that need to be checked against the quota limit. -EDQUOT is returned when this limit is hit.
Note that we're not checking quotas on ceph_link(). ceph_link doesn't really create a new inode, and since the MDS doesn't update the directory statistics when a new (hard) link is created (only with symlinks), they are not accounted as a new file.
--- fs/ceph/dir.c | 11 +++++++++++ fs/ceph/file.c | 4 +++- fs/ceph/quota.c | 42 ++++++++++++++++++++++++++++++++++++++++++ fs/ceph/super.h | 1 + 4 files changed, 57 insertions(+), 1 deletion(-)
fs/ceph/dir.c +11 -0
@@ -815,6 +815,9 @@ static int ceph_mknod(struct inode *dir, struct dentry *dentry,if (ceph_snap (dir) !=CEPH_NOSNAP )return -EROFS ; +if (ceph_quota_is_quota_files_exceeded (dir)) +return -EDQUOT ; + err =ceph_pre_init_acls (dir, &mode, &acls);if (err <0 )return err;
@@ -868,6 +871,9 @@ static int ceph_symlink(struct inode *dir, struct dentry *dentry,if (ceph_snap (dir) !=CEPH_NOSNAP )return -EROFS ; +if (ceph_quota_is_quota_files_exceeded (dir)) +return -EDQUOT ; +dout ("symlink in dir %p dentry %p to '%s'\n" , dir, dentry, dest); req =ceph_mdsc_create_request (mdsc,CEPH_MDS_OP_SYMLINK ,USE_AUTH_MDS );if (IS_ERR (req)) {
@@ -917,6 +923,11 @@ static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) goto out; } +if (ceph_quota_is_quota_files_exceeded (dir)) { + err = -EDQUOT ; + goto out; + } + mode |=S_IFDIR ; err =ceph_pre_init_acls (dir, &mode, &acls);if (err <0 )
fs/ceph/file.c +3 -1
@@ -370,7 +370,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,struct ceph_mds_request *req;struct dentry *dn;struct ceph_acls_info acls = {}; -int mask; +int mask;int err; dout("atomic_open %p dentry %p '%pd' %s flags %d mode 0%o\n",
@@ -381,6 +381,8 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,return -ENAMETOOLONG ;if (flags &O_CREAT ) { +if (ceph_quota_is_quota_files_exceeded (dir)) +return -EDQUOT ; err =ceph_pre_init_acls (dir, &mode, &acls);if (err <0 )return err;
fs/ceph/quota.c +42 -0
45 lines not on this page · raw message
fs/ceph/super.h +1 -0
@@ -1011,5 +1011,6 @@ extern void ceph_fs_debugfs_cleanup(struct ceph_fs_client *client);extern void ceph_handle_quota (struct ceph_mds_client *mdsc,struct ceph_mds_session *session,struct ceph_msg *msg); +extern bool ceph_quota_is_quota_files_exceeded (struct inode *inode);#endif /* _FS_CEPH_SUPER_H */
Re: [RFC PATCH 2/3] ceph: quotas: support for ceph.quota.max_files
Quoted 115 lines · Luis Henriques
This patch adds support for the
max_filesquota. It hooks into all the ceph functions that add new filesystem objects that need to be checked against the quota limit.-EDQUOTis returned when this limit is hit.Note that we're not checking quotas on
ceph_link().ceph_linkdoesn't really create a new inode, and since the MDS doesn't update the directory statistics when a new (hard) link is created (only with symlinks), they are not accounted as a new file.Signed-off-by Luis Henriques <[email protected]>---
fs/ceph/dir.c | 11 +++++++++++ fs/ceph/file.c | 4 +++- fs/ceph/quota.c | 42 ++++++++++++++++++++++++++++++++++++++++++ fs/ceph/super.h | 1 + 4 files changed, 57 insertions(+), 1 deletion(-)fs/ceph/dir.c +11
-0@@ -815,6 +815,9 @@ static int ceph_mknod(struct inode *dir, struct dentry *dentry,if (ceph_snap (dir) !=CEPH_NOSNAP )return -EROFS ; +if (ceph_quota_is_quota_files_exceeded (dir)) +return -EDQUOT ; + err =ceph_pre_init_acls (dir, &mode, &acls);if (err <0 )return err;@@ -868,6 +871,9 @@ static int ceph_symlink(struct inode *dir, struct dentry *dentry,if (ceph_snap (dir) !=CEPH_NOSNAP )return -EROFS ; +if (ceph_quota_is_quota_files_exceeded (dir)) +return -EDQUOT ; +dout ("symlink in dir %p dentry %p to '%s'\n" , dir, dentry, dest); req =ceph_mdsc_create_request (mdsc,CEPH_MDS_OP_SYMLINK ,USE_AUTH_MDS );if (IS_ERR (req)) {@@ -917,6 +923,11 @@ static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) goto out; } +if (ceph_quota_is_quota_files_exceeded (dir)) { + err = -EDQUOT ; + goto out; + } + mode |=S_IFDIR ; err =ceph_pre_init_acls (dir, &mode, &acls);if (err <0 )fs/ceph/file.c +3
-1@@ -370,7 +370,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,struct ceph_mds_request *req;struct dentry *dn;struct ceph_acls_info acls = {}; -int mask; +int mask;int err; dout("atomic_open %p dentry %p '%pd' %s flags %d mode 0%o\n",@@ -381,6 +381,8 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,return -ENAMETOOLONG ;if (flags &O_CREAT ) { +if (ceph_quota_is_quota_files_exceeded (dir)) +return -EDQUOT ; err =ceph_pre_init_acls (dir, &mode, &acls);if (err <0 )return err;fs/ceph/quota.c +29
-0@@ -57,3 +57,45 @@ void ceph_handle_quota(struct ceph_mds_client *mdsc,iput (inode); } + +bool ceph_quota_is_quota_files_exceeded (struct inode *inode) +{ +struct ceph_inode_info *ci; +struct dentry *next, *parent; +u64 max_files; +u64 rentries =0 ; +unsigned seq; +bool result = false; + +WARN_ON (!S_ISDIR (inode->i_mode)); + +retry: + seq =read_seqbegin (&rename_lock); + ci =ceph_inode (inode); + next =d_find_any_alias (inode); + +while (true) { +spin_lock (&ci->i_ceph_lock); + max_files = ci->i_max_files; + rentries = ci->i_rfiles + ci->i_rsubdirs; +spin_unlock (&ci->i_ceph_lock); + +if ((max_files && (rentries >= max_files)) ||IS_ROOT (next)) +break ; + + parent =dget_parent (next); + ci =ceph_inode (d_inode (parent)); +dput (next);
fs/ceph/quota.c void ceph_handle_quota(struct ceph_mds_client *mdsc, · line 98
Quoted 10 lines
fs/ceph/quota.c +10
-0+ next = parent; + } + +dput (next); + +if (read_seqretry (&rename_lock, seq)) + goto retry; + +if (max_files && (rentries >= max_files)) + result = true;
This bottom-up dentry traversal code worries me. I vaguely remember that bottom-up dentry traversal in kernel is discouraged. Then there are multiples clients modifying the filesystem at the same time, the rename_lock does not help. That's why user space code Client::get_quota_root() checks dentry lease and does lookup parent. I’m not sure if we can do the same operations in kernel, because locking is much more complex in kernel.
For the long term, I prefer unifying quota and snapshot implementation. The inode trace in MClientReply contains information about which quota realm the inode belongs to. So client can find quota information easily. (This requires bigger change for both mds and client)
Regards
Yan, Zheng
Quoted 14 lines
fs/ceph/quota.c +3
-0+ +return result; +}fs/ceph/super.h +1
-0@@ -1011,5 +1011,6 @@ extern void ceph_fs_debugfs_cleanup(struct ceph_fs_client *client);extern void ceph_handle_quota (struct ceph_mds_client *mdsc,struct ceph_mds_session *session,struct ceph_msg *msg); +extern bool ceph_quota_is_quota_files_exceeded (struct inode *inode);#endif /* _FS_CEPH_SUPER_H */
Re: [RFC PATCH 2/3] ceph: quotas: support for ceph.quota.max_files
Quoted 1 line · Zheng
Quoted 1 line · Luis Henriques
<snip>
Quoted 6 lines
This bottom-up dentry traversal code worries me. I vaguely remember that bottom-up dentry traversal in kernel is discouraged. Then there are multiples clients modifying the filesystem at the same time, the
rename_lockdoes not help. That's why user space codeClient::get_quota_root()checks dentry lease and does lookup parent. I’m not sure if we can do the same operations in kernel, because locking is much more complex in kernel.
So, you're saying that in addition to using the rename_lock (for local renames), that loop will also need to do something similar to what's being done already in function ceph_d_revalidate. I.e., it needs to validate the lease (as in function dentry_lease_is_valid) and send a CEPH_MDS_OP_LOOKUP if a dentry is invalid. Or am I missing something?
Quoted 4 lines
For the long term, I prefer unifying quota and snapshot implementation. The inode trace in MClientReply contains information about which quota realm the inode belongs to. So client can find quota information easily. (This requires bigger change for both mds and client)
My motivation for trying to bring the kernel client a bit closer to the fuse client was that there are currently valid use-cases for this quota implementation, with all its limitations.
Now, I completely agree that ideally the core quota implementation should be moved to the MDS. This would simplify the clients side, and, above all, would remove the limitation of requiring clients cooperation.
Obviously, I would be more than happy to help on the kernel client side of this solution. But I'm afraid that the real hard work would be on the MDS code, where things such as multi-MDS and dir fragmentation would make this solution quite complex.
Cheers,
Signature · 1 line
Luís
Re: [RFC PATCH 2/3] ceph: quotas: support for ceph.quota.max_files
Quoted 14 lines · Luis Henriques
Quoted 1 line · Zheng
Quoted 1 line · Luis Henriques
<snip>
Quoted 6 lines
This bottom-up dentry traversal code worries me. I vaguely remember that bottom-up dentry traversal in kernel is discouraged. Then there are multiples clients modifying the filesystem at the same time, the
rename_lockdoes not help. That's why user space codeClient::get_quota_root()checks dentry lease and does lookup parent. I’m not sure if we can do the same operations in kernel, because locking is much more complex in kernel.
Quoted 5 lines
So, you're saying that in addition to using the
rename_lock(for local renames), that loop will also need to do something similar to what's being done already in functionceph_d_revalidate. I.e., it needs to validate the lease (as in functiondentry_lease_is_valid) and send aCEPH_MDS_OP_LOOKUPif a dentry is invalid. Or am I missing something?
yes
Quoted 15 lines
Quoted 5 lines
For the long term, I prefer unifying quota and snapshot implementation. The inode trace in MClientReply contains information about which quota realm the inode belongs to. So client can find quota information easily. (This requires bigger change for both mds and client)
My motivation for trying to bring the kernel client a bit closer to the fuse client was that there are currently valid use-cases for this quota implementation, with all its limitations.
Now, I completely agree that ideally the core quota implementation should be moved to the MDS. This would simplify the clients side, and, above all, would remove the limitation of requiring clients cooperation.
Quoted 4 lines
Obviously, I would be more than happy to help on the kernel client side of this solution. But I'm afraid that the real hard work would be on the MDS code, where things such as multi-MDS and dir fragmentation would make this solution quite complex.
I will start to hammer this code soon, please wait a few days.
Regards
Yan, Zheng
Quoted 4 lines
Cheers,
Signature · 1 line
Luís
RFC PATCH 3/3 ceph: quota: don't allow cross-quota renames
In reply to Luis HenriquesThis patch changes ceph_rename so that -EXDEV is returned if an attempt is made to mv a file between two different dir trees with different quotas setup.
--- fs/ceph/dir.c | 4 ++++ fs/ceph/quota.c | 35 +++++++++++++++++++++++++++++++++++ fs/ceph/super.h | 1 + 3 files changed, 40 insertions(+)
fs/ceph/dir.c +4 -0
@@ -1087,6 +1087,10 @@ static int ceph_rename(struct inode *old_dir, struct dentry *old_dentry,else return -EROFS ; } +/* don't allow cross-quota renames */ +if ((old_dir != new_dir) && (!ceph_quota_is_same_root (old_dir, new_dir))) +return -EXDEV ; +dout ("rename dir %p dentry %p to dir %p dentry %p\n" , old_dir, old_dentry, new_dir, new_dentry); req =ceph_mdsc_create_request (mdsc, op,USE_AUTH_MDS );
fs/ceph/quota.c +35 -0
@@ -20,6 +20,11 @@#include "super.h" #include "mds_client.h" +static inline bool ceph_has_quota (struct ceph_inode_info *ci) +{ +return (ci->i_max_files || ci->i_max_bytes); +} +void ceph_handle_quota (struct ceph_mds_client *mdsc,struct ceph_mds_session *session,struct ceph_msg *msg)
@@ -58,6 +63,36 @@ void ceph_handle_quota(struct ceph_mds_client *mdsc,iput (inode); } +static struct ceph_inode_info *get_quota_root (struct inode *inode) +{ +struct ceph_inode_info *ci; +struct dentry *next, *parent; + + next =d_find_any_alias (inode); + ci =ceph_inode (d_inode (next)); +while (!ceph_has_quota (ci) && !IS_ROOT (next)) { + parent =dget_parent (next); +dput (next); + next = parent; + ci =ceph_inode (d_inode (next)); + } + +dput (next); +if (ceph_has_quota (ci)) +return ci; +return NULL ; +} + +bool ceph_quota_is_same_root (struct inode *old,struct inode *new) +{ +struct ceph_inode_info *ci_old, *ci_new; + + ci_old =get_quota_root (old); + ci_new =get_quota_root (new); + +return (ci_old == ci_new); +} +bool ceph_quota_is_quota_files_exceeded (struct inode *inode) {struct ceph_inode_info *ci;
fs/ceph/super.h +1 -0
@@ -1012,5 +1012,6 @@ extern void ceph_handle_quota(struct ceph_mds_client *mdsc,struct ceph_mds_session *session, struct ceph_msg *msg);extern bool ceph_quota_is_quota_files_exceeded (struct inode *inode); +extern bool ceph_quota_is_same_root (struct inode *old,struct inode *new);#endif /* _FS_CEPH_SUPER_H */