Lines Matching +full:max +full:- +full:msg +full:- +full:size

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);
17 atomic64_inc(&mdsc->quotarealms_count);
19 atomic64_dec(&mdsc->quotarealms_count);
24 struct super_block *sb = inode->i_sb;
26 struct inode *root = d_inode(sb->s_root);
28 if (atomic64_read(&mdsc->quotarealms_count) > 0)
34 if (ceph_vino_is_reserved(ceph_inode(inode)->i_vino))
42 struct ceph_msg *msg)
44 struct super_block *sb = mdsc->fsc->sb;
45 struct ceph_mds_quota *h = msg->front.iov_base;
46 struct ceph_client *cl = mdsc->fsc->client;
54 if (msg->front.iov_len < sizeof(*h)) {
56 session->s_mds, (int)msg->front.iov_len);
57 ceph_msg_dump(msg);
62 vino.ino = le64_to_cpu(h->ino);
71 spin_lock(&ci->i_ceph_lock);
72 ci->i_rbytes = le64_to_cpu(h->rbytes);
73 ci->i_rfiles = le64_to_cpu(h->rfiles);
74 ci->i_rsubdirs = le64_to_cpu(h->rsubdirs);
75 __ceph_update_quota(ci, le64_to_cpu(h->max_bytes),
76 le64_to_cpu(h->max_files));
77 spin_unlock(&ci->i_ceph_lock);
89 struct ceph_client *cl = mdsc->fsc->client;
91 mutex_lock(&mdsc->quotarealms_inodes_mutex);
92 node = &(mdsc->quotarealms_inodes.rb_node);
97 if (ino < qri->ino)
98 node = &((*node)->rb_left);
99 else if (ino > qri->ino)
100 node = &((*node)->rb_right);
104 if (!qri || (qri->ino != ino)) {
108 qri->ino = ino;
109 qri->inode = NULL;
110 qri->timeout = 0;
111 mutex_init(&qri->mutex);
112 rb_link_node(&qri->node, parent, node);
113 rb_insert_color(&qri->node, &mdsc->quotarealms_inodes);
117 mutex_unlock(&mdsc->quotarealms_inodes_mutex);
134 struct ceph_client *cl = mdsc->fsc->client;
138 qri = find_quotarealm_inode(mdsc, realm->ino);
142 mutex_lock(&qri->mutex);
143 if (qri->inode && ceph_is_any_caps(qri->inode)) {
145 mutex_unlock(&qri->mutex);
146 return qri->inode;
149 if (qri->timeout &&
150 time_before_eq(jiffies, qri->timeout)) {
151 mutex_unlock(&qri->mutex);
154 if (qri->inode) {
156 int ret = __ceph_do_getattr(qri->inode, NULL,
159 in = qri->inode;
163 in = ceph_lookup_inode(sb, realm->ino);
167 doutc(cl, "Can't lookup inode %llx (err: %ld)\n", realm->ino,
169 qri->timeout = jiffies + secs_to_jiffies(60); /* XXX */
171 qri->timeout = 0;
172 qri->inode = in;
174 mutex_unlock(&qri->mutex);
186 * mdsc->quotarealms_inodes_mutex...
188 mutex_lock(&mdsc->quotarealms_inodes_mutex);
189 while (!RB_EMPTY_ROOT(&mdsc->quotarealms_inodes)) {
190 node = rb_first(&mdsc->quotarealms_inodes);
192 rb_erase(node, &mdsc->quotarealms_inodes);
193 iput(qri->inode);
196 mutex_unlock(&mdsc->quotarealms_inodes_mutex);
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;
230 realm = ceph_inode(inode)->i_snap_realm;
240 spin_lock(&realm->inodes_with_caps_lock);
241 has_inode = realm->inode;
242 in = has_inode ? igrab(realm->inode) : NULL;
243 spin_unlock(&realm->inodes_with_caps_lock);
247 up_read(&mdsc->snap_rwsem);
248 in = lookup_quotarealm_inode(mdsc, inode->i_sb, realm);
249 down_read(&mdsc->snap_rwsem);
254 return -EAGAIN;
262 next = realm->parent;
281 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(old->i_sb);
290 * 'retry' parameter to 'false', we'll get -EAGAIN if the rwsem was
293 down_read(&mdsc->snap_rwsem);
296 if (ret == -EAGAIN) {
297 up_read(&mdsc->snap_rwsem);
303 up_read(&mdsc->snap_rwsem);
329 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(inode->i_sb);
330 struct ceph_client *cl = mdsc->fsc->client;
334 u64 max, rvalue;
340 down_read(&mdsc->snap_rwsem);
342 realm = ceph_inode(inode)->i_snap_realm;
352 spin_lock(&realm->inodes_with_caps_lock);
353 has_inode = realm->inode;
354 in = has_inode ? igrab(realm->inode) : NULL;
355 spin_unlock(&realm->inodes_with_caps_lock);
359 up_read(&mdsc->snap_rwsem);
360 in = lookup_quotarealm_inode(mdsc, inode->i_sb, realm);
361 down_read(&mdsc->snap_rwsem);
368 spin_lock(&ci->i_ceph_lock);
370 max = ci->i_max_files;
371 rvalue = ci->i_rfiles + ci->i_rsubdirs;
373 max = ci->i_max_bytes;
374 rvalue = ci->i_rbytes;
376 spin_unlock(&ci->i_ceph_lock);
380 exceeded = (max && (rvalue + delta > max));
383 if (max) {
384 if (rvalue >= max)
392 (((max - rvalue) >> 4) < delta);
403 next = realm->parent;
412 up_read(&mdsc->snap_rwsem);
418 * ceph_quota_is_max_files_exceeded - check if we can create a new file
430 WARN_ON(!S_ISDIR(inode->i_mode));
436 * ceph_quota_is_max_bytes_exceeded - check if we can write to a file
438 * @newsize: new size if write succeeds
440 * This functions returns true is max_bytes quota allows a file size to reach
445 loff_t size = i_size_read(inode);
450 /* return immediately if we're decreasing file size */
451 if (newsize <= size)
454 return check_quota_exceeded(inode, QUOTA_CHECK_MAX_BYTES_OP, (newsize - size));
458 * ceph_quota_is_max_bytes_approaching - check if we're reaching max_bytes
460 * @newsize: new size if write succeeds
462 * This function returns true if the new file size @newsize will be consuming
467 loff_t size = ceph_inode(inode)->i_reported_size;
472 /* return immediately if we're decreasing file size */
473 if (newsize <= size)
477 (newsize - size));
481 * ceph_quota_update_statfs - if root has quota update statfs with quota status
492 struct ceph_mds_client *mdsc = fsc->mdsc;
499 down_read(&mdsc->snap_rwsem);
500 get_quota_realm(mdsc, d_inode(fsc->sb->s_root), QUOTA_GET_MAX_BYTES,
502 up_read(&mdsc->snap_rwsem);
506 spin_lock(&realm->inodes_with_caps_lock);
507 in = realm->inode ? igrab(realm->inode) : NULL;
508 spin_unlock(&realm->inodes_with_caps_lock);
511 spin_lock(&ci->i_ceph_lock);
512 if (ci->i_max_bytes) {
513 total = ci->i_max_bytes >> CEPH_BLOCK_SHIFT;
514 used = ci->i_rbytes >> CEPH_BLOCK_SHIFT;
515 /* For quota size less than 4MB, use 4KB block size */
517 total = ci->i_max_bytes >> CEPH_4K_BLOCK_SHIFT;
518 used = ci->i_rbytes >> CEPH_4K_BLOCK_SHIFT;
519 buf->f_frsize = 1 << CEPH_4K_BLOCK_SHIFT;
524 free = total > used ? total - used : 0;
525 /* For quota size less than 4KB, report the
530 free = ci->i_max_bytes > ci->i_rbytes ? 1 : 0;
531 buf->f_frsize = 1 << CEPH_4K_BLOCK_SHIFT;
534 spin_unlock(&ci->i_ceph_lock);
536 buf->f_blocks = total;
537 buf->f_bfree = free;
538 buf->f_bavail = free;