]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - fs/ceph/quota.c
1 // SPDX-License-Identifier: GPL-2.0
3 * quota.c - CephFS quota
5 * Copyright (C) 2017-2018 SUSE
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include "mds_client.h"
24 void ceph_handle_quota(struct ceph_mds_client
*mdsc
,
25 struct ceph_mds_session
*session
,
28 struct super_block
*sb
= mdsc
->fsc
->sb
;
29 struct ceph_mds_quota
*h
= msg
->front
.iov_base
;
30 struct ceph_vino vino
;
32 struct ceph_inode_info
*ci
;
34 if (msg
->front
.iov_len
!= sizeof(*h
)) {
35 pr_err("%s corrupt message mds%d len %d\n", __func__
,
36 session
->s_mds
, (int)msg
->front
.iov_len
);
41 /* increment msg sequence number */
42 mutex_lock(&session
->s_mutex
);
44 mutex_unlock(&session
->s_mutex
);
47 vino
.ino
= le64_to_cpu(h
->ino
);
48 vino
.snap
= CEPH_NOSNAP
;
49 inode
= ceph_find_inode(sb
, vino
);
51 pr_warn("Failed to find inode %llu\n", vino
.ino
);
54 ci
= ceph_inode(inode
);
56 spin_lock(&ci
->i_ceph_lock
);
57 ci
->i_rbytes
= le64_to_cpu(h
->rbytes
);
58 ci
->i_rfiles
= le64_to_cpu(h
->rfiles
);
59 ci
->i_rsubdirs
= le64_to_cpu(h
->rsubdirs
);
60 ci
->i_max_bytes
= le64_to_cpu(h
->max_bytes
);
61 ci
->i_max_files
= le64_to_cpu(h
->max_files
);
62 spin_unlock(&ci
->i_ceph_lock
);
68 QUOTA_CHECK_MAX_FILES_OP
/* check quota max_files limit */
72 * check_quota_exceeded() will walk up the snaprealm hierarchy and, for each
73 * realm, it will execute quota check operation defined by the 'op' parameter.
74 * The snaprealm walk is interrupted if the quota check detects that the quota
75 * is exceeded or if the root inode is reached.
77 static bool check_quota_exceeded(struct inode
*inode
, enum quota_check_op op
,
80 struct ceph_mds_client
*mdsc
= ceph_inode_to_client(inode
)->mdsc
;
81 struct ceph_inode_info
*ci
;
82 struct ceph_snap_realm
*realm
, *next
;
83 struct ceph_vino vino
;
87 bool exceeded
= false;
89 down_read(&mdsc
->snap_rwsem
);
90 realm
= ceph_inode(inode
)->i_snap_realm
;
91 ceph_get_snap_realm(mdsc
, realm
);
93 vino
.ino
= realm
->ino
;
94 vino
.snap
= CEPH_NOSNAP
;
95 in
= ceph_find_inode(inode
->i_sb
, vino
);
97 pr_warn("Failed to find inode for %llu\n", vino
.ino
);
101 spin_lock(&ci
->i_ceph_lock
);
102 if (op
== QUOTA_CHECK_MAX_FILES_OP
) {
103 max
= ci
->i_max_files
;
104 rvalue
= ci
->i_rfiles
+ ci
->i_rsubdirs
;
106 is_root
= (ci
->i_vino
.ino
== CEPH_INO_ROOT
);
107 spin_unlock(&ci
->i_ceph_lock
);
109 case QUOTA_CHECK_MAX_FILES_OP
:
110 exceeded
= (max
&& (rvalue
>= max
));
113 /* Shouldn't happen */
114 pr_warn("Invalid quota check op (%d)\n", op
);
115 exceeded
= true; /* Just break the loop */
119 if (is_root
|| exceeded
)
121 next
= realm
->parent
;
122 ceph_get_snap_realm(mdsc
, next
);
123 ceph_put_snap_realm(mdsc
, realm
);
126 ceph_put_snap_realm(mdsc
, realm
);
127 up_read(&mdsc
->snap_rwsem
);
133 * ceph_quota_is_max_files_exceeded - check if we can create a new file
134 * @inode: directory where a new file is being created
136 * This functions returns true is max_files quota allows a new file to be
137 * created. It is necessary to walk through the snaprealm hierarchy (until the
138 * FS root) to check all realms with quotas set.
140 bool ceph_quota_is_max_files_exceeded(struct inode
*inode
)
142 WARN_ON(!S_ISDIR(inode
->i_mode
));
144 return check_quota_exceeded(inode
, QUOTA_CHECK_MAX_FILES_OP
, 0);