]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - fs/ceph/xattr.c
ceph: quota: add initial infrastructure to support cephfs quotas
[mirror_ubuntu-bionic-kernel.git] / fs / ceph / xattr.c
index e1c4e0b12b4cd1309af51bad916120c7f2273fc4..7e72348639e4bcbf523ec4bec3a589fbcd643c7c 100644 (file)
@@ -224,6 +224,31 @@ static size_t ceph_vxattrcb_dir_rctime(struct ceph_inode_info *ci, char *val,
                        (long)ci->i_rctime.tv_nsec);
 }
 
+/* quotas */
+
+static bool ceph_vxattrcb_quota_exists(struct ceph_inode_info *ci)
+{
+       return (ci->i_max_files || ci->i_max_bytes);
+}
+
+static size_t ceph_vxattrcb_quota(struct ceph_inode_info *ci, char *val,
+                                 size_t size)
+{
+       return snprintf(val, size, "max_bytes=%llu max_files=%llu",
+                       ci->i_max_bytes, ci->i_max_files);
+}
+
+static size_t ceph_vxattrcb_quota_max_bytes(struct ceph_inode_info *ci,
+                                           char *val, size_t size)
+{
+       return snprintf(val, size, "%llu", ci->i_max_bytes);
+}
+
+static size_t ceph_vxattrcb_quota_max_files(struct ceph_inode_info *ci,
+                                           char *val, size_t size)
+{
+       return snprintf(val, size, "%llu", ci->i_max_files);
+}
 
 #define CEPH_XATTR_NAME(_type, _name)  XATTR_CEPH_PREFIX #_type "." #_name
 #define CEPH_XATTR_NAME2(_type, _name, _name2) \
@@ -247,6 +272,15 @@ static size_t ceph_vxattrcb_dir_rctime(struct ceph_inode_info *ci, char *val,
                .hidden = true,                 \
                .exists_cb = ceph_vxattrcb_layout_exists,       \
        }
+#define XATTR_QUOTA_FIELD(_type, _name)                                        \
+       {                                                               \
+               .name = CEPH_XATTR_NAME(_type, _name),                  \
+               .name_size = sizeof(CEPH_XATTR_NAME(_type, _name)),     \
+               .getxattr_cb = ceph_vxattrcb_ ## _type ## _ ## _name,   \
+               .readonly = false,                                      \
+               .hidden = true,                                         \
+               .exists_cb = ceph_vxattrcb_quota_exists,                \
+       }
 
 static struct ceph_vxattr ceph_dir_vxattrs[] = {
        {
@@ -270,6 +304,16 @@ static struct ceph_vxattr ceph_dir_vxattrs[] = {
        XATTR_NAME_CEPH(dir, rsubdirs),
        XATTR_NAME_CEPH(dir, rbytes),
        XATTR_NAME_CEPH(dir, rctime),
+       {
+               .name = "ceph.quota",
+               .name_size = sizeof("ceph.quota"),
+               .getxattr_cb = ceph_vxattrcb_quota,
+               .readonly = false,
+               .hidden = true,
+               .exists_cb = ceph_vxattrcb_quota_exists,
+       },
+       XATTR_QUOTA_FIELD(quota, max_bytes),
+       XATTR_QUOTA_FIELD(quota, max_files),
        { .name = NULL, 0 }     /* Required table terminator */
 };
 static size_t ceph_dir_vxattrs_name_size;      /* total size of all names */