Skip to content

Commit 55ab552

Browse files
Luís Henriquesidryomov
authored andcommitted
ceph: fix statfs for subdir mounts
When doing a mount using as base a directory that has 'max_bytes' quotas statfs uses that value as the total; if a subdirectory is used instead, the same 'max_bytes' too in statfs, unless there is another quota set. Unfortunately, if this subdirectory only has the 'max_files' quota set, then statfs uses the filesystem total. Fix this by making sure we only lookup realms that contain the 'max_bytes' quota. Cc: Ryan Taylor <rptaylor@uvic.ca> URL: https://tracker.ceph.com/issues/55090 Signed-off-by: Luís Henriques <lhenriques@suse.de> Reviewed-by: Jeff Layton <jlayton@kernel.org> Reviewed-by: Xiubo Li <xiubli@redhat.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent 825978f commit 55ab552

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

fs/ceph/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ void ceph_evict_inode(struct inode *inode)
578578

579579
__ceph_remove_caps(ci);
580580

581-
if (__ceph_has_any_quota(ci))
581+
if (__ceph_has_quota(ci, QUOTA_GET_ANY))
582582
ceph_adjust_quota_realms_count(inode, false);
583583

584584
/*

fs/ceph/quota.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ void ceph_cleanup_quotarealms_inodes(struct ceph_mds_client *mdsc)
195195

196196
/*
197197
* This function walks through the snaprealm for an inode and returns the
198-
* ceph_snap_realm for the first snaprealm that has quotas set (either max_files
199-
* or max_bytes). If the root is reached, return the root ceph_snap_realm
200-
* instead.
198+
* ceph_snap_realm for the first snaprealm that has quotas set (max_files,
199+
* max_bytes, or any, depending on the 'which_quota' argument). If the root is
200+
* reached, return the root ceph_snap_realm instead.
201201
*
202202
* Note that the caller is responsible for calling ceph_put_snap_realm() on the
203203
* returned realm.
@@ -209,7 +209,9 @@ void ceph_cleanup_quotarealms_inodes(struct ceph_mds_client *mdsc)
209209
* will be restarted.
210210
*/
211211
static struct ceph_snap_realm *get_quota_realm(struct ceph_mds_client *mdsc,
212-
struct inode *inode, bool retry)
212+
struct inode *inode,
213+
enum quota_get_realm which_quota,
214+
bool retry)
213215
{
214216
struct ceph_inode_info *ci = NULL;
215217
struct ceph_snap_realm *realm, *next;
@@ -248,7 +250,7 @@ static struct ceph_snap_realm *get_quota_realm(struct ceph_mds_client *mdsc,
248250
}
249251

250252
ci = ceph_inode(in);
251-
has_quota = __ceph_has_any_quota(ci);
253+
has_quota = __ceph_has_quota(ci, which_quota);
252254
iput(in);
253255

254256
next = realm->parent;
@@ -279,8 +281,8 @@ bool ceph_quota_is_same_realm(struct inode *old, struct inode *new)
279281
* dropped and we can then restart the whole operation.
280282
*/
281283
down_read(&mdsc->snap_rwsem);
282-
old_realm = get_quota_realm(mdsc, old, true);
283-
new_realm = get_quota_realm(mdsc, new, false);
284+
old_realm = get_quota_realm(mdsc, old, QUOTA_GET_ANY, true);
285+
new_realm = get_quota_realm(mdsc, new, QUOTA_GET_ANY, false);
284286
if (PTR_ERR(new_realm) == -EAGAIN) {
285287
up_read(&mdsc->snap_rwsem);
286288
if (old_realm)
@@ -483,7 +485,8 @@ bool ceph_quota_update_statfs(struct ceph_fs_client *fsc, struct kstatfs *buf)
483485
bool is_updated = false;
484486

485487
down_read(&mdsc->snap_rwsem);
486-
realm = get_quota_realm(mdsc, d_inode(fsc->sb->s_root), true);
488+
realm = get_quota_realm(mdsc, d_inode(fsc->sb->s_root),
489+
QUOTA_GET_MAX_BYTES, true);
487490
up_read(&mdsc->snap_rwsem);
488491
if (!realm)
489492
return false;

fs/ceph/super.h

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,9 +1279,29 @@ extern void ceph_fs_debugfs_init(struct ceph_fs_client *client);
12791279
extern void ceph_fs_debugfs_cleanup(struct ceph_fs_client *client);
12801280

12811281
/* quota.c */
1282-
static inline bool __ceph_has_any_quota(struct ceph_inode_info *ci)
1282+
1283+
enum quota_get_realm {
1284+
QUOTA_GET_MAX_FILES,
1285+
QUOTA_GET_MAX_BYTES,
1286+
QUOTA_GET_ANY
1287+
};
1288+
1289+
static inline bool __ceph_has_quota(struct ceph_inode_info *ci,
1290+
enum quota_get_realm which)
12831291
{
1284-
return ci->i_max_files || ci->i_max_bytes;
1292+
bool has_quota = false;
1293+
1294+
switch (which) {
1295+
case QUOTA_GET_MAX_BYTES:
1296+
has_quota = !!ci->i_max_bytes;
1297+
break;
1298+
case QUOTA_GET_MAX_FILES:
1299+
has_quota = !!ci->i_max_files;
1300+
break;
1301+
default:
1302+
has_quota = !!(ci->i_max_files || ci->i_max_bytes);
1303+
}
1304+
return has_quota;
12851305
}
12861306

12871307
extern void ceph_adjust_quota_realms_count(struct inode *inode, bool inc);
@@ -1290,10 +1310,10 @@ static inline void __ceph_update_quota(struct ceph_inode_info *ci,
12901310
u64 max_bytes, u64 max_files)
12911311
{
12921312
bool had_quota, has_quota;
1293-
had_quota = __ceph_has_any_quota(ci);
1313+
had_quota = __ceph_has_quota(ci, QUOTA_GET_ANY);
12941314
ci->i_max_bytes = max_bytes;
12951315
ci->i_max_files = max_files;
1296-
has_quota = __ceph_has_any_quota(ci);
1316+
has_quota = __ceph_has_quota(ci, QUOTA_GET_ANY);
12971317

12981318
if (had_quota != has_quota)
12991319
ceph_adjust_quota_realms_count(&ci->vfs_inode, has_quota);

0 commit comments

Comments
 (0)