Lines Matching +full:total +full:- +full:timeout
1 // SPDX-License-Identifier: GPL-2.0
3 * quota.c - CephFS quota
5 * Copyright (C) 2017-2018 SUSE
15 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(inode->i_sb); in ceph_adjust_quota_realms_count()
17 atomic64_inc(&mdsc->quotarealms_count); in ceph_adjust_quota_realms_count()
19 atomic64_dec(&mdsc->quotarealms_count); in ceph_adjust_quota_realms_count()
24 struct super_block *sb = inode->i_sb; in ceph_has_realms_with_quotas()
26 struct inode *root = d_inode(sb->s_root); in ceph_has_realms_with_quotas()
28 if (atomic64_read(&mdsc->quotarealms_count) > 0) in ceph_has_realms_with_quotas()
34 if (ceph_vino_is_reserved(ceph_inode(inode)->i_vino)) in ceph_has_realms_with_quotas()
44 struct super_block *sb = mdsc->fsc->sb; in ceph_handle_quota()
45 struct ceph_mds_quota *h = msg->front.iov_base; in ceph_handle_quota()
50 if (msg->front.iov_len < sizeof(*h)) { in ceph_handle_quota()
52 session->s_mds, (int)msg->front.iov_len); in ceph_handle_quota()
58 mutex_lock(&session->s_mutex); in ceph_handle_quota()
60 mutex_unlock(&session->s_mutex); in ceph_handle_quota()
63 vino.ino = le64_to_cpu(h->ino); in ceph_handle_quota()
72 spin_lock(&ci->i_ceph_lock); in ceph_handle_quota()
73 ci->i_rbytes = le64_to_cpu(h->rbytes); in ceph_handle_quota()
74 ci->i_rfiles = le64_to_cpu(h->rfiles); in ceph_handle_quota()
75 ci->i_rsubdirs = le64_to_cpu(h->rsubdirs); in ceph_handle_quota()
76 __ceph_update_quota(ci, le64_to_cpu(h->max_bytes), in ceph_handle_quota()
77 le64_to_cpu(h->max_files)); in ceph_handle_quota()
78 spin_unlock(&ci->i_ceph_lock); in ceph_handle_quota()
89 mutex_lock(&mdsc->quotarealms_inodes_mutex); in find_quotarealm_inode()
90 node = &(mdsc->quotarealms_inodes.rb_node); in find_quotarealm_inode()
95 if (ino < qri->ino) in find_quotarealm_inode()
96 node = &((*node)->rb_left); in find_quotarealm_inode()
97 else if (ino > qri->ino) in find_quotarealm_inode()
98 node = &((*node)->rb_right); in find_quotarealm_inode()
102 if (!qri || (qri->ino != ino)) { in find_quotarealm_inode()
106 qri->ino = ino; in find_quotarealm_inode()
107 qri->inode = NULL; in find_quotarealm_inode()
108 qri->timeout = 0; in find_quotarealm_inode()
109 mutex_init(&qri->mutex); in find_quotarealm_inode()
110 rb_link_node(&qri->node, parent, node); in find_quotarealm_inode()
111 rb_insert_color(&qri->node, &mdsc->quotarealms_inodes); in find_quotarealm_inode()
115 mutex_unlock(&mdsc->quotarealms_inodes_mutex); in find_quotarealm_inode()
135 qri = find_quotarealm_inode(mdsc, realm->ino); in lookup_quotarealm_inode()
139 mutex_lock(&qri->mutex); in lookup_quotarealm_inode()
140 if (qri->inode && ceph_is_any_caps(qri->inode)) { in lookup_quotarealm_inode()
142 mutex_unlock(&qri->mutex); in lookup_quotarealm_inode()
143 return qri->inode; in lookup_quotarealm_inode()
146 if (qri->timeout && in lookup_quotarealm_inode()
147 time_before_eq(jiffies, qri->timeout)) { in lookup_quotarealm_inode()
148 mutex_unlock(&qri->mutex); in lookup_quotarealm_inode()
151 if (qri->inode) { in lookup_quotarealm_inode()
153 int ret = __ceph_do_getattr(qri->inode, NULL, in lookup_quotarealm_inode()
156 in = qri->inode; in lookup_quotarealm_inode()
160 in = ceph_lookup_inode(sb, realm->ino); in lookup_quotarealm_inode()
165 realm->ino, PTR_ERR(in)); in lookup_quotarealm_inode()
166 qri->timeout = jiffies + msecs_to_jiffies(60 * 1000); /* XXX */ in lookup_quotarealm_inode()
168 qri->timeout = 0; in lookup_quotarealm_inode()
169 qri->inode = in; in lookup_quotarealm_inode()
171 mutex_unlock(&qri->mutex); in lookup_quotarealm_inode()
183 * mdsc->quotarealms_inodes_mutex... in ceph_cleanup_quotarealms_inodes()
185 mutex_lock(&mdsc->quotarealms_inodes_mutex); in ceph_cleanup_quotarealms_inodes()
186 while (!RB_EMPTY_ROOT(&mdsc->quotarealms_inodes)) { in ceph_cleanup_quotarealms_inodes()
187 node = rb_first(&mdsc->quotarealms_inodes); in ceph_cleanup_quotarealms_inodes()
189 rb_erase(node, &mdsc->quotarealms_inodes); in ceph_cleanup_quotarealms_inodes()
190 iput(qri->inode); in ceph_cleanup_quotarealms_inodes()
193 mutex_unlock(&mdsc->quotarealms_inodes_mutex); in ceph_cleanup_quotarealms_inodes()
205 * Callers of this function need to hold mdsc->snap_rwsem. However, if there's
208 * this function will return -EAGAIN; otherwise, the snaprealms walk-through
225 realm = ceph_inode(inode)->i_snap_realm; in get_quota_realm()
234 spin_lock(&realm->inodes_with_caps_lock); in get_quota_realm()
235 has_inode = realm->inode; in get_quota_realm()
236 in = has_inode ? igrab(realm->inode) : NULL; in get_quota_realm()
237 spin_unlock(&realm->inodes_with_caps_lock); in get_quota_realm()
241 up_read(&mdsc->snap_rwsem); in get_quota_realm()
242 in = lookup_quotarealm_inode(mdsc, inode->i_sb, realm); in get_quota_realm()
243 down_read(&mdsc->snap_rwsem); in get_quota_realm()
248 return ERR_PTR(-EAGAIN); in get_quota_realm()
256 next = realm->parent; in get_quota_realm()
272 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(old->i_sb); in ceph_quota_is_same_realm()
280 * 'retry' parameter to 'false', we'll get -EAGAIN if the rwsem was in ceph_quota_is_same_realm()
283 down_read(&mdsc->snap_rwsem); in ceph_quota_is_same_realm()
286 if (PTR_ERR(new_realm) == -EAGAIN) { in ceph_quota_is_same_realm()
287 up_read(&mdsc->snap_rwsem); in ceph_quota_is_same_realm()
293 up_read(&mdsc->snap_rwsem); in ceph_quota_is_same_realm()
319 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(inode->i_sb); in check_quota_exceeded()
329 down_read(&mdsc->snap_rwsem); in check_quota_exceeded()
331 realm = ceph_inode(inode)->i_snap_realm; in check_quota_exceeded()
340 spin_lock(&realm->inodes_with_caps_lock); in check_quota_exceeded()
341 has_inode = realm->inode; in check_quota_exceeded()
342 in = has_inode ? igrab(realm->inode) : NULL; in check_quota_exceeded()
343 spin_unlock(&realm->inodes_with_caps_lock); in check_quota_exceeded()
347 up_read(&mdsc->snap_rwsem); in check_quota_exceeded()
348 in = lookup_quotarealm_inode(mdsc, inode->i_sb, realm); in check_quota_exceeded()
349 down_read(&mdsc->snap_rwsem); in check_quota_exceeded()
356 spin_lock(&ci->i_ceph_lock); in check_quota_exceeded()
358 max = ci->i_max_files; in check_quota_exceeded()
359 rvalue = ci->i_rfiles + ci->i_rsubdirs; in check_quota_exceeded()
361 max = ci->i_max_bytes; in check_quota_exceeded()
362 rvalue = ci->i_rbytes; in check_quota_exceeded()
364 spin_unlock(&ci->i_ceph_lock); in check_quota_exceeded()
380 (((max - rvalue) >> 4) < delta); in check_quota_exceeded()
391 next = realm->parent; in check_quota_exceeded()
400 up_read(&mdsc->snap_rwsem); in check_quota_exceeded()
406 * ceph_quota_is_max_files_exceeded - check if we can create a new file
418 WARN_ON(!S_ISDIR(inode->i_mode)); in ceph_quota_is_max_files_exceeded()
424 * ceph_quota_is_max_bytes_exceeded - check if we can write to a file
442 return check_quota_exceeded(inode, QUOTA_CHECK_MAX_BYTES_OP, (newsize - size)); in ceph_quota_is_max_bytes_exceeded()
446 * ceph_quota_is_max_bytes_approaching - check if we're reaching max_bytes
455 loff_t size = ceph_inode(inode)->i_reported_size; in ceph_quota_is_max_bytes_approaching()
465 (newsize - size)); in ceph_quota_is_max_bytes_approaching()
469 * ceph_quota_update_statfs - if root has quota update statfs with quota status
480 struct ceph_mds_client *mdsc = fsc->mdsc; in ceph_quota_update_statfs()
484 u64 total = 0, used, free; in ceph_quota_update_statfs() local
487 down_read(&mdsc->snap_rwsem); in ceph_quota_update_statfs()
488 realm = get_quota_realm(mdsc, d_inode(fsc->sb->s_root), in ceph_quota_update_statfs()
490 up_read(&mdsc->snap_rwsem); in ceph_quota_update_statfs()
494 spin_lock(&realm->inodes_with_caps_lock); in ceph_quota_update_statfs()
495 in = realm->inode ? igrab(realm->inode) : NULL; in ceph_quota_update_statfs()
496 spin_unlock(&realm->inodes_with_caps_lock); in ceph_quota_update_statfs()
499 spin_lock(&ci->i_ceph_lock); in ceph_quota_update_statfs()
500 if (ci->i_max_bytes) { in ceph_quota_update_statfs()
501 total = ci->i_max_bytes >> CEPH_BLOCK_SHIFT; in ceph_quota_update_statfs()
502 used = ci->i_rbytes >> CEPH_BLOCK_SHIFT; in ceph_quota_update_statfs()
504 if (!total) { in ceph_quota_update_statfs()
505 total = ci->i_max_bytes >> CEPH_4K_BLOCK_SHIFT; in ceph_quota_update_statfs()
506 used = ci->i_rbytes >> CEPH_4K_BLOCK_SHIFT; in ceph_quota_update_statfs()
507 buf->f_frsize = 1 << CEPH_4K_BLOCK_SHIFT; in ceph_quota_update_statfs()
512 free = total > used ? total - used : 0; in ceph_quota_update_statfs()
514 * total=used=4KB,free=0 when quota is full in ceph_quota_update_statfs()
515 * and total=free=4KB, used=0 otherwise */ in ceph_quota_update_statfs()
516 if (!total) { in ceph_quota_update_statfs()
517 total = 1; in ceph_quota_update_statfs()
518 free = ci->i_max_bytes > ci->i_rbytes ? 1 : 0; in ceph_quota_update_statfs()
519 buf->f_frsize = 1 << CEPH_4K_BLOCK_SHIFT; in ceph_quota_update_statfs()
522 spin_unlock(&ci->i_ceph_lock); in ceph_quota_update_statfs()
523 if (total) { in ceph_quota_update_statfs()
524 buf->f_blocks = total; in ceph_quota_update_statfs()
525 buf->f_bfree = free; in ceph_quota_update_statfs()
526 buf->f_bavail = free; in ceph_quota_update_statfs()