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()
53 if (msg->front.iov_len < sizeof(*h)) { in ceph_handle_quota()
55 session->s_mds, (int)msg->front.iov_len); in ceph_handle_quota()
61 vino.ino = le64_to_cpu(h->ino); in ceph_handle_quota()
70 spin_lock(&ci->i_ceph_lock); in ceph_handle_quota()
71 ci->i_rbytes = le64_to_cpu(h->rbytes); in ceph_handle_quota()
72 ci->i_rfiles = le64_to_cpu(h->rfiles); in ceph_handle_quota()
73 ci->i_rsubdirs = le64_to_cpu(h->rsubdirs); in ceph_handle_quota()
74 __ceph_update_quota(ci, le64_to_cpu(h->max_bytes), in ceph_handle_quota()
75 le64_to_cpu(h->max_files)); in ceph_handle_quota()
76 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
226 realm = ceph_inode(inode)->i_snap_realm; in get_quota_realm()
235 spin_lock(&realm->inodes_with_caps_lock); in get_quota_realm()
236 has_inode = realm->inode; in get_quota_realm()
237 in = has_inode ? igrab(realm->inode) : NULL; in get_quota_realm()
238 spin_unlock(&realm->inodes_with_caps_lock); in get_quota_realm()
242 up_read(&mdsc->snap_rwsem); in get_quota_realm()
243 in = lookup_quotarealm_inode(mdsc, inode->i_sb, realm); in get_quota_realm()
244 down_read(&mdsc->snap_rwsem); in get_quota_realm()
249 return -EAGAIN; in get_quota_realm()
257 next = realm->parent; in get_quota_realm()
276 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(old->i_sb); in ceph_quota_is_same_realm()
285 * 'retry' parameter to 'false', we'll get -EAGAIN if the rwsem was in ceph_quota_is_same_realm()
288 down_read(&mdsc->snap_rwsem); in ceph_quota_is_same_realm()
291 if (ret == -EAGAIN) { in ceph_quota_is_same_realm()
292 up_read(&mdsc->snap_rwsem); in ceph_quota_is_same_realm()
298 up_read(&mdsc->snap_rwsem); in ceph_quota_is_same_realm()
324 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(inode->i_sb); in check_quota_exceeded()
334 down_read(&mdsc->snap_rwsem); in check_quota_exceeded()
336 realm = ceph_inode(inode)->i_snap_realm; in check_quota_exceeded()
345 spin_lock(&realm->inodes_with_caps_lock); in check_quota_exceeded()
346 has_inode = realm->inode; in check_quota_exceeded()
347 in = has_inode ? igrab(realm->inode) : NULL; in check_quota_exceeded()
348 spin_unlock(&realm->inodes_with_caps_lock); in check_quota_exceeded()
352 up_read(&mdsc->snap_rwsem); in check_quota_exceeded()
353 in = lookup_quotarealm_inode(mdsc, inode->i_sb, realm); in check_quota_exceeded()
354 down_read(&mdsc->snap_rwsem); in check_quota_exceeded()
361 spin_lock(&ci->i_ceph_lock); in check_quota_exceeded()
363 max = ci->i_max_files; in check_quota_exceeded()
364 rvalue = ci->i_rfiles + ci->i_rsubdirs; in check_quota_exceeded()
366 max = ci->i_max_bytes; in check_quota_exceeded()
367 rvalue = ci->i_rbytes; in check_quota_exceeded()
369 spin_unlock(&ci->i_ceph_lock); in check_quota_exceeded()
385 (((max - rvalue) >> 4) < delta); in check_quota_exceeded()
396 next = realm->parent; in check_quota_exceeded()
405 up_read(&mdsc->snap_rwsem); in check_quota_exceeded()
411 * ceph_quota_is_max_files_exceeded - check if we can create a new file
423 WARN_ON(!S_ISDIR(inode->i_mode)); in ceph_quota_is_max_files_exceeded()
429 * ceph_quota_is_max_bytes_exceeded - check if we can write to a file
447 return check_quota_exceeded(inode, QUOTA_CHECK_MAX_BYTES_OP, (newsize - size)); in ceph_quota_is_max_bytes_exceeded()
451 * ceph_quota_is_max_bytes_approaching - check if we're reaching max_bytes
460 loff_t size = ceph_inode(inode)->i_reported_size; in ceph_quota_is_max_bytes_approaching()
470 (newsize - size)); in ceph_quota_is_max_bytes_approaching()
474 * ceph_quota_update_statfs - if root has quota update statfs with quota status
485 struct ceph_mds_client *mdsc = fsc->mdsc; in ceph_quota_update_statfs()
489 u64 total = 0, used, free; in ceph_quota_update_statfs() local
492 down_read(&mdsc->snap_rwsem); in ceph_quota_update_statfs()
493 get_quota_realm(mdsc, d_inode(fsc->sb->s_root), QUOTA_GET_MAX_BYTES, in ceph_quota_update_statfs()
495 up_read(&mdsc->snap_rwsem); in ceph_quota_update_statfs()
499 spin_lock(&realm->inodes_with_caps_lock); in ceph_quota_update_statfs()
500 in = realm->inode ? igrab(realm->inode) : NULL; in ceph_quota_update_statfs()
501 spin_unlock(&realm->inodes_with_caps_lock); in ceph_quota_update_statfs()
504 spin_lock(&ci->i_ceph_lock); in ceph_quota_update_statfs()
505 if (ci->i_max_bytes) { in ceph_quota_update_statfs()
506 total = ci->i_max_bytes >> CEPH_BLOCK_SHIFT; in ceph_quota_update_statfs()
507 used = ci->i_rbytes >> CEPH_BLOCK_SHIFT; in ceph_quota_update_statfs()
509 if (!total) { in ceph_quota_update_statfs()
510 total = ci->i_max_bytes >> CEPH_4K_BLOCK_SHIFT; in ceph_quota_update_statfs()
511 used = ci->i_rbytes >> CEPH_4K_BLOCK_SHIFT; in ceph_quota_update_statfs()
512 buf->f_frsize = 1 << CEPH_4K_BLOCK_SHIFT; in ceph_quota_update_statfs()
517 free = total > used ? total - used : 0; in ceph_quota_update_statfs()
519 * total=used=4KB,free=0 when quota is full in ceph_quota_update_statfs()
520 * and total=free=4KB, used=0 otherwise */ in ceph_quota_update_statfs()
521 if (!total) { in ceph_quota_update_statfs()
522 total = 1; in ceph_quota_update_statfs()
523 free = ci->i_max_bytes > ci->i_rbytes ? 1 : 0; in ceph_quota_update_statfs()
524 buf->f_frsize = 1 << CEPH_4K_BLOCK_SHIFT; in ceph_quota_update_statfs()
527 spin_unlock(&ci->i_ceph_lock); in ceph_quota_update_statfs()
528 if (total) { in ceph_quota_update_statfs()
529 buf->f_blocks = total; in ceph_quota_update_statfs()
530 buf->f_bfree = free; in ceph_quota_update_statfs()
531 buf->f_bavail = free; in ceph_quota_update_statfs()