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()
46 struct ceph_client *cl = mdsc->fsc->client; in ceph_handle_quota()
54 if (msg->front.iov_len < sizeof(*h)) { in ceph_handle_quota()
56 session->s_mds, (int)msg->front.iov_len); in ceph_handle_quota()
62 vino.ino = le64_to_cpu(h->ino); in ceph_handle_quota()
71 spin_lock(&ci->i_ceph_lock); in ceph_handle_quota()
72 ci->i_rbytes = le64_to_cpu(h->rbytes); in ceph_handle_quota()
73 ci->i_rfiles = le64_to_cpu(h->rfiles); in ceph_handle_quota()
74 ci->i_rsubdirs = le64_to_cpu(h->rsubdirs); in ceph_handle_quota()
75 __ceph_update_quota(ci, le64_to_cpu(h->max_bytes), in ceph_handle_quota()
76 le64_to_cpu(h->max_files)); in ceph_handle_quota()
77 spin_unlock(&ci->i_ceph_lock); in ceph_handle_quota()
89 struct ceph_client *cl = mdsc->fsc->client; in find_quotarealm_inode()
91 mutex_lock(&mdsc->quotarealms_inodes_mutex); in find_quotarealm_inode()
92 node = &(mdsc->quotarealms_inodes.rb_node); in find_quotarealm_inode()
97 if (ino < qri->ino) in find_quotarealm_inode()
98 node = &((*node)->rb_left); in find_quotarealm_inode()
99 else if (ino > qri->ino) in find_quotarealm_inode()
100 node = &((*node)->rb_right); in find_quotarealm_inode()
104 if (!qri || (qri->ino != ino)) { in find_quotarealm_inode()
108 qri->ino = ino; in find_quotarealm_inode()
109 qri->inode = NULL; in find_quotarealm_inode()
110 qri->timeout = 0; in find_quotarealm_inode()
111 mutex_init(&qri->mutex); in find_quotarealm_inode()
112 rb_link_node(&qri->node, parent, node); in find_quotarealm_inode()
113 rb_insert_color(&qri->node, &mdsc->quotarealms_inodes); in find_quotarealm_inode()
117 mutex_unlock(&mdsc->quotarealms_inodes_mutex); in find_quotarealm_inode()
134 struct ceph_client *cl = mdsc->fsc->client; in lookup_quotarealm_inode()
138 qri = find_quotarealm_inode(mdsc, realm->ino); in lookup_quotarealm_inode()
142 mutex_lock(&qri->mutex); in lookup_quotarealm_inode()
143 if (qri->inode && ceph_is_any_caps(qri->inode)) { in lookup_quotarealm_inode()
145 mutex_unlock(&qri->mutex); in lookup_quotarealm_inode()
146 return qri->inode; in lookup_quotarealm_inode()
149 if (qri->timeout && in lookup_quotarealm_inode()
150 time_before_eq(jiffies, qri->timeout)) { in lookup_quotarealm_inode()
151 mutex_unlock(&qri->mutex); in lookup_quotarealm_inode()
154 if (qri->inode) { in lookup_quotarealm_inode()
156 int ret = __ceph_do_getattr(qri->inode, NULL, in lookup_quotarealm_inode()
159 in = qri->inode; in lookup_quotarealm_inode()
163 in = ceph_lookup_inode(sb, realm->ino); in lookup_quotarealm_inode()
167 doutc(cl, "Can't lookup inode %llx (err: %ld)\n", realm->ino, in lookup_quotarealm_inode()
169 qri->timeout = jiffies + msecs_to_jiffies(60 * 1000); /* XXX */ in lookup_quotarealm_inode()
171 qri->timeout = 0; in lookup_quotarealm_inode()
172 qri->inode = in; in lookup_quotarealm_inode()
174 mutex_unlock(&qri->mutex); in lookup_quotarealm_inode()
186 * mdsc->quotarealms_inodes_mutex... in ceph_cleanup_quotarealms_inodes()
188 mutex_lock(&mdsc->quotarealms_inodes_mutex); in ceph_cleanup_quotarealms_inodes()
189 while (!RB_EMPTY_ROOT(&mdsc->quotarealms_inodes)) { in ceph_cleanup_quotarealms_inodes()
190 node = rb_first(&mdsc->quotarealms_inodes); in ceph_cleanup_quotarealms_inodes()
192 rb_erase(node, &mdsc->quotarealms_inodes); in ceph_cleanup_quotarealms_inodes()
193 iput(qri->inode); in ceph_cleanup_quotarealms_inodes()
196 mutex_unlock(&mdsc->quotarealms_inodes_mutex); in ceph_cleanup_quotarealms_inodes()
208 * Callers of this function need to hold mdsc->snap_rwsem. However, if there's
211 * this function will return -EAGAIN; otherwise, the snaprealms walk-through
218 struct ceph_client *cl = mdsc->fsc->client; in get_quota_realm()
230 realm = ceph_inode(inode)->i_snap_realm; in get_quota_realm()
240 spin_lock(&realm->inodes_with_caps_lock); in get_quota_realm()
241 has_inode = realm->inode; in get_quota_realm()
242 in = has_inode ? igrab(realm->inode) : NULL; in get_quota_realm()
243 spin_unlock(&realm->inodes_with_caps_lock); in get_quota_realm()
247 up_read(&mdsc->snap_rwsem); in get_quota_realm()
248 in = lookup_quotarealm_inode(mdsc, inode->i_sb, realm); in get_quota_realm()
249 down_read(&mdsc->snap_rwsem); in get_quota_realm()
254 return -EAGAIN; in get_quota_realm()
262 next = realm->parent; in get_quota_realm()
281 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(old->i_sb); in ceph_quota_is_same_realm()
290 * 'retry' parameter to 'false', we'll get -EAGAIN if the rwsem was in ceph_quota_is_same_realm()
293 down_read(&mdsc->snap_rwsem); in ceph_quota_is_same_realm()
296 if (ret == -EAGAIN) { in ceph_quota_is_same_realm()
297 up_read(&mdsc->snap_rwsem); in ceph_quota_is_same_realm()
303 up_read(&mdsc->snap_rwsem); in ceph_quota_is_same_realm()
329 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(inode->i_sb); in check_quota_exceeded()
330 struct ceph_client *cl = mdsc->fsc->client; in check_quota_exceeded()
340 down_read(&mdsc->snap_rwsem); in check_quota_exceeded()
342 realm = ceph_inode(inode)->i_snap_realm; in check_quota_exceeded()
352 spin_lock(&realm->inodes_with_caps_lock); in check_quota_exceeded()
353 has_inode = realm->inode; in check_quota_exceeded()
354 in = has_inode ? igrab(realm->inode) : NULL; in check_quota_exceeded()
355 spin_unlock(&realm->inodes_with_caps_lock); in check_quota_exceeded()
359 up_read(&mdsc->snap_rwsem); in check_quota_exceeded()
360 in = lookup_quotarealm_inode(mdsc, inode->i_sb, realm); in check_quota_exceeded()
361 down_read(&mdsc->snap_rwsem); in check_quota_exceeded()
368 spin_lock(&ci->i_ceph_lock); in check_quota_exceeded()
370 max = ci->i_max_files; in check_quota_exceeded()
371 rvalue = ci->i_rfiles + ci->i_rsubdirs; in check_quota_exceeded()
373 max = ci->i_max_bytes; in check_quota_exceeded()
374 rvalue = ci->i_rbytes; in check_quota_exceeded()
376 spin_unlock(&ci->i_ceph_lock); in check_quota_exceeded()
392 (((max - rvalue) >> 4) < delta); in check_quota_exceeded()
403 next = realm->parent; in check_quota_exceeded()
412 up_read(&mdsc->snap_rwsem); in check_quota_exceeded()
418 * ceph_quota_is_max_files_exceeded - check if we can create a new file
430 WARN_ON(!S_ISDIR(inode->i_mode)); in ceph_quota_is_max_files_exceeded()
436 * ceph_quota_is_max_bytes_exceeded - check if we can write to a file
454 return check_quota_exceeded(inode, QUOTA_CHECK_MAX_BYTES_OP, (newsize - size)); in ceph_quota_is_max_bytes_exceeded()
458 * ceph_quota_is_max_bytes_approaching - check if we're reaching max_bytes
467 loff_t size = ceph_inode(inode)->i_reported_size; in ceph_quota_is_max_bytes_approaching()
477 (newsize - size)); in ceph_quota_is_max_bytes_approaching()
481 * ceph_quota_update_statfs - if root has quota update statfs with quota status
492 struct ceph_mds_client *mdsc = fsc->mdsc; in ceph_quota_update_statfs()
496 u64 total = 0, used, free; in ceph_quota_update_statfs() local
499 down_read(&mdsc->snap_rwsem); in ceph_quota_update_statfs()
500 get_quota_realm(mdsc, d_inode(fsc->sb->s_root), QUOTA_GET_MAX_BYTES, in ceph_quota_update_statfs()
502 up_read(&mdsc->snap_rwsem); in ceph_quota_update_statfs()
506 spin_lock(&realm->inodes_with_caps_lock); in ceph_quota_update_statfs()
507 in = realm->inode ? igrab(realm->inode) : NULL; in ceph_quota_update_statfs()
508 spin_unlock(&realm->inodes_with_caps_lock); in ceph_quota_update_statfs()
511 spin_lock(&ci->i_ceph_lock); in ceph_quota_update_statfs()
512 if (ci->i_max_bytes) { in ceph_quota_update_statfs()
513 total = ci->i_max_bytes >> CEPH_BLOCK_SHIFT; in ceph_quota_update_statfs()
514 used = ci->i_rbytes >> CEPH_BLOCK_SHIFT; in ceph_quota_update_statfs()
516 if (!total) { in ceph_quota_update_statfs()
517 total = ci->i_max_bytes >> CEPH_4K_BLOCK_SHIFT; in ceph_quota_update_statfs()
518 used = ci->i_rbytes >> CEPH_4K_BLOCK_SHIFT; in ceph_quota_update_statfs()
519 buf->f_frsize = 1 << CEPH_4K_BLOCK_SHIFT; in ceph_quota_update_statfs()
524 free = total > used ? total - used : 0; in ceph_quota_update_statfs()
526 * total=used=4KB,free=0 when quota is full in ceph_quota_update_statfs()
527 * and total=free=4KB, used=0 otherwise */ in ceph_quota_update_statfs()
528 if (!total) { in ceph_quota_update_statfs()
529 total = 1; in ceph_quota_update_statfs()
530 free = ci->i_max_bytes > ci->i_rbytes ? 1 : 0; in ceph_quota_update_statfs()
531 buf->f_frsize = 1 << CEPH_4K_BLOCK_SHIFT; in ceph_quota_update_statfs()
534 spin_unlock(&ci->i_ceph_lock); in ceph_quota_update_statfs()
535 if (total) { in ceph_quota_update_statfs()
536 buf->f_blocks = total; in ceph_quota_update_statfs()
537 buf->f_bfree = free; in ceph_quota_update_statfs()
538 buf->f_bavail = free; in ceph_quota_update_statfs()