Lines Matching +full:ip +full:- +full:blocks

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
4 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
10 * per-node file) and then are periodically synced to the quota file. This
32 * GFS quotas also use per-ID Lock Value Blocks (LVBs) to cache the contents of
76 #define GFS2_QD_HASH_MASK (GFS2_QD_HASH_SIZE - 1)
78 /* Lock order: qd_lock -> bucket lock -> qd->lockref.lock -> lru lock */
79 /* -> sd_bitmap_lock */
109 struct gfs2_sbd *sdp = qd->qd_sbd; in gfs2_qd_dealloc()
112 if (atomic_dec_and_test(&sdp->sd_quota_count)) in gfs2_qd_dealloc()
113 wake_up(&sdp->sd_kill_wait); in gfs2_qd_dealloc()
118 struct gfs2_sbd *sdp = qd->qd_sbd; in gfs2_qd_dispose()
121 list_del(&qd->qd_list); in gfs2_qd_dispose()
124 spin_lock_bucket(qd->qd_hash); in gfs2_qd_dispose()
125 hlist_bl_del_rcu(&qd->qd_hlist); in gfs2_qd_dispose()
126 spin_unlock_bucket(qd->qd_hash); in gfs2_qd_dispose()
129 gfs2_assert_warn(sdp, !qd->qd_change); in gfs2_qd_dispose()
130 gfs2_assert_warn(sdp, !qd->qd_slot_ref); in gfs2_qd_dispose()
131 gfs2_assert_warn(sdp, !qd->qd_bh_count); in gfs2_qd_dispose()
134 gfs2_glock_put(qd->qd_gl); in gfs2_qd_dispose()
135 call_rcu(&qd->qd_rcu, gfs2_qd_dealloc); in gfs2_qd_dispose()
144 list_del(&qd->qd_lru); in gfs2_qd_list_dispose()
159 if (!spin_trylock(&qd->qd_lockref.lock)) in gfs2_qd_isolate()
163 if (qd->qd_lockref.count == 0) { in gfs2_qd_isolate()
164 lockref_mark_dead(&qd->qd_lockref); in gfs2_qd_isolate()
165 list_lru_isolate_move(lru, &qd->qd_lru, dispose); in gfs2_qd_isolate()
169 spin_unlock(&qd->qd_lockref.lock); in gfs2_qd_isolate()
179 if (!(sc->gfp_mask & __GFP_FS)) in gfs2_qd_shrink_scan()
200 gfs2_qd_shrinker = shrinker_alloc(SHRINKER_NUMA_AWARE, "gfs2-qd"); in gfs2_qd_shrinker_init()
202 return -ENOMEM; in gfs2_qd_shrinker_init()
204 gfs2_qd_shrinker->count_objects = gfs2_qd_shrink_count; in gfs2_qd_shrinker_init()
205 gfs2_qd_shrinker->scan_objects = gfs2_qd_shrink_scan; in gfs2_qd_shrinker_init()
219 struct kqid qid = qd->qd_id; in qd2index()
238 qd->qd_sbd = sdp; in qd_alloc()
239 qd->qd_lockref.count = 0; in qd_alloc()
240 spin_lock_init(&qd->qd_lockref.lock); in qd_alloc()
241 qd->qd_id = qid; in qd_alloc()
242 qd->qd_slot = -1; in qd_alloc()
243 INIT_LIST_HEAD(&qd->qd_lru); in qd_alloc()
244 qd->qd_hash = hash; in qd_alloc()
247 &gfs2_quota_glops, CREATE, &qd->qd_gl); in qd_alloc()
266 if (!qid_eq(qd->qd_id, qid)) in gfs2_qd_search_bucket()
268 if (qd->qd_sbd != sdp) in gfs2_qd_search_bucket()
270 if (lockref_get_not_dead(&qd->qd_lockref)) { in gfs2_qd_search_bucket()
271 list_lru_del_obj(&gfs2_qd_lru, &qd->qd_lru); in gfs2_qd_search_bucket()
295 return -ENOMEM; in qd_get()
301 new_qd->qd_lockref.count++; in qd_get()
303 list_add(&new_qd->qd_list, &sdp->sd_quota_list); in qd_get()
304 hlist_bl_add_head_rcu(&new_qd->qd_hlist, &qd_hash_table[hash]); in qd_get()
305 atomic_inc(&sdp->sd_quota_count); in qd_get()
311 gfs2_glock_put(new_qd->qd_gl); in qd_get()
321 struct gfs2_sbd *sdp = qd->qd_sbd; in __qd_hold()
322 gfs2_assert(sdp, qd->qd_lockref.count > 0); in __qd_hold()
323 qd->qd_lockref.count++; in __qd_hold()
330 if (lockref_put_or_lock(&qd->qd_lockref)) in qd_put()
333 BUG_ON(__lockref_is_dead(&qd->qd_lockref)); in qd_put()
334 sdp = qd->qd_sbd; in qd_put()
335 if (unlikely(!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags))) { in qd_put()
336 lockref_mark_dead(&qd->qd_lockref); in qd_put()
337 spin_unlock(&qd->qd_lockref.lock); in qd_put()
343 qd->qd_lockref.count = 0; in qd_put()
344 list_lru_add_obj(&gfs2_qd_lru, &qd->qd_lru); in qd_put()
345 spin_unlock(&qd->qd_lockref.lock); in qd_put()
350 struct gfs2_sbd *sdp = qd->qd_sbd; in slot_get()
354 spin_lock(&sdp->sd_bitmap_lock); in slot_get()
355 if (qd->qd_slot_ref == 0) { in slot_get()
356 bit = find_first_zero_bit(sdp->sd_quota_bitmap, in slot_get()
357 sdp->sd_quota_slots); in slot_get()
358 if (bit >= sdp->sd_quota_slots) { in slot_get()
359 error = -ENOSPC; in slot_get()
362 set_bit(bit, sdp->sd_quota_bitmap); in slot_get()
363 qd->qd_slot = bit; in slot_get()
365 qd->qd_slot_ref++; in slot_get()
367 spin_unlock(&sdp->sd_bitmap_lock); in slot_get()
373 struct gfs2_sbd *sdp = qd->qd_sbd; in slot_hold()
375 spin_lock(&sdp->sd_bitmap_lock); in slot_hold()
376 gfs2_assert(sdp, qd->qd_slot_ref); in slot_hold()
377 qd->qd_slot_ref++; in slot_hold()
378 spin_unlock(&sdp->sd_bitmap_lock); in slot_hold()
383 struct gfs2_sbd *sdp = qd->qd_sbd; in slot_put()
385 spin_lock(&sdp->sd_bitmap_lock); in slot_put()
386 gfs2_assert(sdp, qd->qd_slot_ref); in slot_put()
387 if (!--qd->qd_slot_ref) { in slot_put()
388 BUG_ON(!test_and_clear_bit(qd->qd_slot, sdp->sd_quota_bitmap)); in slot_put()
389 qd->qd_slot = -1; in slot_put()
391 spin_unlock(&sdp->sd_bitmap_lock); in slot_put()
396 struct gfs2_sbd *sdp = qd->qd_sbd; in bh_get()
397 struct inode *inode = sdp->sd_qc_inode; in bh_get()
398 struct gfs2_inode *ip = GFS2_I(inode); in bh_get() local
404 spin_lock(&qd->qd_lockref.lock); in bh_get()
405 if (qd->qd_bh_count) { in bh_get()
406 qd->qd_bh_count++; in bh_get()
407 spin_unlock(&qd->qd_lockref.lock); in bh_get()
410 spin_unlock(&qd->qd_lockref.lock); in bh_get()
412 block = qd->qd_slot / sdp->sd_qc_per_block; in bh_get()
413 offset = qd->qd_slot % sdp->sd_qc_per_block; in bh_get()
416 (loff_t)block << inode->i_blkbits, in bh_get()
420 error = -ENOENT; in bh_get()
424 error = gfs2_meta_read(ip->i_gl, iomap.addr >> inode->i_blkbits, in bh_get()
428 error = -EIO; in bh_get()
432 spin_lock(&qd->qd_lockref.lock); in bh_get()
433 if (qd->qd_bh == NULL) { in bh_get()
434 qd->qd_bh = bh; in bh_get()
435 qd->qd_bh_qc = (struct gfs2_quota_change *) in bh_get()
436 (bh->b_data + sizeof(struct gfs2_meta_header) + in bh_get()
440 qd->qd_bh_count++; in bh_get()
441 spin_unlock(&qd->qd_lockref.lock); in bh_get()
451 struct gfs2_sbd *sdp = qd->qd_sbd; in bh_put()
454 spin_lock(&qd->qd_lockref.lock); in bh_put()
455 gfs2_assert(sdp, qd->qd_bh_count); in bh_put()
456 if (!--qd->qd_bh_count) { in bh_put()
457 bh = qd->qd_bh; in bh_put()
458 qd->qd_bh = NULL; in bh_put()
459 qd->qd_bh_qc = NULL; in bh_put()
461 spin_unlock(&qd->qd_lockref.lock); in bh_put()
470 spin_lock(&qd->qd_lockref.lock); in qd_grab_sync()
471 if (test_bit(QDF_LOCKED, &qd->qd_flags) || in qd_grab_sync()
472 !test_bit(QDF_CHANGE, &qd->qd_flags) || in qd_grab_sync()
473 qd->qd_sync_gen >= sync_gen) in qd_grab_sync()
476 if (__lockref_is_dead(&qd->qd_lockref)) in qd_grab_sync()
478 qd->qd_lockref.count++; in qd_grab_sync()
480 list_move_tail(&qd->qd_list, &sdp->sd_quota_list); in qd_grab_sync()
481 set_bit(QDF_LOCKED, &qd->qd_flags); in qd_grab_sync()
482 qd->qd_change_sync = qd->qd_change; in qd_grab_sync()
487 spin_unlock(&qd->qd_lockref.lock); in qd_grab_sync()
493 clear_bit(QDF_LOCKED, &qd->qd_flags); in qd_ungrab_sync()
507 spin_lock(&qd->qd_lockref.lock); in qd_unlock()
508 gfs2_assert_warn(qd->qd_sbd, test_bit(QDF_LOCKED, &qd->qd_flags)); in qd_unlock()
509 clear_bit(QDF_LOCKED, &qd->qd_flags); in qd_unlock()
510 spin_unlock(&qd->qd_lockref.lock); in qd_unlock()
541 * gfs2_qa_get - make sure we have a quota allocations data structure,
543 * @ip: the inode for this reservation
545 int gfs2_qa_get(struct gfs2_inode *ip) in gfs2_qa_get() argument
547 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_qa_get()
548 struct inode *inode = &ip->i_inode; in gfs2_qa_get()
550 if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF) in gfs2_qa_get()
553 spin_lock(&inode->i_lock); in gfs2_qa_get()
554 if (ip->i_qadata == NULL) { in gfs2_qa_get()
557 spin_unlock(&inode->i_lock); in gfs2_qa_get()
560 return -ENOMEM; in gfs2_qa_get()
562 spin_lock(&inode->i_lock); in gfs2_qa_get()
563 if (ip->i_qadata == NULL) in gfs2_qa_get()
564 ip->i_qadata = tmp; in gfs2_qa_get()
568 ip->i_qadata->qa_ref++; in gfs2_qa_get()
569 spin_unlock(&inode->i_lock); in gfs2_qa_get()
573 void gfs2_qa_put(struct gfs2_inode *ip) in gfs2_qa_put() argument
575 struct inode *inode = &ip->i_inode; in gfs2_qa_put()
577 spin_lock(&inode->i_lock); in gfs2_qa_put()
578 if (ip->i_qadata && --ip->i_qadata->qa_ref == 0) { in gfs2_qa_put()
579 kmem_cache_free(gfs2_qadata_cachep, ip->i_qadata); in gfs2_qa_put()
580 ip->i_qadata = NULL; in gfs2_qa_put()
582 spin_unlock(&inode->i_lock); in gfs2_qa_put()
585 int gfs2_quota_hold(struct gfs2_inode *ip, kuid_t uid, kgid_t gid) in gfs2_quota_hold() argument
587 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_quota_hold()
591 if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF) in gfs2_quota_hold()
594 error = gfs2_qa_get(ip); in gfs2_quota_hold()
598 qd = ip->i_qadata->qa_qd; in gfs2_quota_hold()
600 if (gfs2_assert_warn(sdp, !ip->i_qadata->qa_qd_num) || in gfs2_quota_hold()
601 gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags))) { in gfs2_quota_hold()
602 error = -EIO; in gfs2_quota_hold()
603 gfs2_qa_put(ip); in gfs2_quota_hold()
607 error = qdsb_get(sdp, make_kqid_uid(ip->i_inode.i_uid), qd); in gfs2_quota_hold()
610 ip->i_qadata->qa_qd_num++; in gfs2_quota_hold()
613 error = qdsb_get(sdp, make_kqid_gid(ip->i_inode.i_gid), qd); in gfs2_quota_hold()
616 ip->i_qadata->qa_qd_num++; in gfs2_quota_hold()
620 !uid_eq(uid, ip->i_inode.i_uid)) { in gfs2_quota_hold()
624 ip->i_qadata->qa_qd_num++; in gfs2_quota_hold()
629 !gid_eq(gid, ip->i_inode.i_gid)) { in gfs2_quota_hold()
633 ip->i_qadata->qa_qd_num++; in gfs2_quota_hold()
639 gfs2_quota_unhold(ip); in gfs2_quota_hold()
644 void gfs2_quota_unhold(struct gfs2_inode *ip) in gfs2_quota_unhold() argument
646 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_quota_unhold()
649 if (ip->i_qadata == NULL) in gfs2_quota_unhold()
652 gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags)); in gfs2_quota_unhold()
654 for (x = 0; x < ip->i_qadata->qa_qd_num; x++) { in gfs2_quota_unhold()
655 qdsb_put(ip->i_qadata->qa_qd[x]); in gfs2_quota_unhold()
656 ip->i_qadata->qa_qd[x] = NULL; in gfs2_quota_unhold()
658 ip->i_qadata->qa_qd_num = 0; in gfs2_quota_unhold()
659 gfs2_qa_put(ip); in gfs2_quota_unhold()
667 if (qid_lt(qd_a->qd_id, qd_b->qd_id)) in sort_qd()
668 return -1; in sort_qd()
669 if (qid_lt(qd_b->qd_id, qd_a->qd_id)) in sort_qd()
676 struct gfs2_sbd *sdp = qd->qd_sbd; in do_qc()
677 struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode); in do_qc() local
678 struct gfs2_quota_change *qc = qd->qd_bh_qc; in do_qc()
682 gfs2_trans_add_meta(ip->i_gl, qd->qd_bh); in do_qc()
686 * is used. Here, we use the value of qc->qc_change when the slot is in do_qc()
690 spin_lock(&qd->qd_lockref.lock); in do_qc()
693 if (test_bit(QDF_CHANGE, &qd->qd_flags)) in do_qc()
694 x = be64_to_cpu(qc->qc_change); in do_qc()
696 qd->qd_change += change; in do_qc()
698 if (!x && test_bit(QDF_CHANGE, &qd->qd_flags)) { in do_qc()
700 clear_bit(QDF_CHANGE, &qd->qd_flags); in do_qc()
701 qc->qc_flags = 0; in do_qc()
702 qc->qc_id = 0; in do_qc()
704 } else if (x && !test_bit(QDF_CHANGE, &qd->qd_flags)) { in do_qc()
706 set_bit(QDF_CHANGE, &qd->qd_flags); in do_qc()
710 qc->qc_flags = 0; in do_qc()
711 if (qd->qd_id.type == USRQUOTA) in do_qc()
712 qc->qc_flags = cpu_to_be32(GFS2_QCF_USER); in do_qc()
713 qc->qc_id = cpu_to_be32(from_kqid(&init_user_ns, qd->qd_id)); in do_qc()
715 qc->qc_change = cpu_to_be64(x); in do_qc()
717 spin_unlock(&qd->qd_lockref.lock); in do_qc()
723 if (change < 0) /* Reset quiet flag if we freed some blocks */ in do_qc()
724 clear_bit(QDF_QMSG_QUIET, &qd->qd_flags); in do_qc()
730 struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode); in gfs2_write_buf_to_page() local
731 struct inode *inode = &ip->i_inode; in gfs2_write_buf_to_page()
732 struct address_space *mapping = inode->i_mapping; in gfs2_write_buf_to_page()
736 unsigned bsize = sdp->sd_sb.sb_bsize, bnum = 0, boff = 0; in gfs2_write_buf_to_page()
739 blk = index << (PAGE_SHIFT - sdp->sd_sb.sb_bsize_shift); in gfs2_write_buf_to_page()
752 bh = bh->b_this_page; in gfs2_write_buf_to_page()
764 bh->b_size); in gfs2_write_buf_to_page()
770 gfs2_trans_add_data(ip->i_gl, bh); in gfs2_write_buf_to_page()
773 if (to_write > (bsize - boff)) { in gfs2_write_buf_to_page()
774 pg_off += (bsize - boff); in gfs2_write_buf_to_page()
775 to_write -= (bsize - boff); in gfs2_write_buf_to_page()
793 return -EIO; in gfs2_write_buf_to_page()
811 overflow = (pg_off + nbytes) - PAGE_SIZE; in gfs2_write_disk_quota()
815 nbytes - overflow); in gfs2_write_disk_quota()
819 ptr + nbytes - overflow, in gfs2_write_disk_quota()
825 * gfs2_adjust_quota - adjust record of current block usage
835 * Returns: 0 or -ve on error
842 struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode); in gfs2_adjust_quota() local
843 struct inode *inode = &ip->i_inode; in gfs2_adjust_quota()
848 if (gfs2_is_stuffed(ip)) { in gfs2_adjust_quota()
849 err = gfs2_unstuff_dinode(ip); in gfs2_adjust_quota()
855 err = gfs2_internal_read(ip, (char *)&q, &loc, sizeof(q)); in gfs2_adjust_quota()
859 loc -= sizeof(q); /* gfs2_internal_read would've advanced the loc ptr */ in gfs2_adjust_quota()
863 spin_lock(&qd->qd_lockref.lock); in gfs2_adjust_quota()
864 qd->qd_qb.qb_value = q.qu_value; in gfs2_adjust_quota()
866 if (fdq->d_fieldmask & QC_SPC_SOFT) { in gfs2_adjust_quota()
867 q.qu_warn = cpu_to_be64(fdq->d_spc_softlimit >> sdp->sd_sb.sb_bsize_shift); in gfs2_adjust_quota()
868 qd->qd_qb.qb_warn = q.qu_warn; in gfs2_adjust_quota()
870 if (fdq->d_fieldmask & QC_SPC_HARD) { in gfs2_adjust_quota()
871 q.qu_limit = cpu_to_be64(fdq->d_spc_hardlimit >> sdp->sd_sb.sb_bsize_shift); in gfs2_adjust_quota()
872 qd->qd_qb.qb_limit = q.qu_limit; in gfs2_adjust_quota()
874 if (fdq->d_fieldmask & QC_SPACE) { in gfs2_adjust_quota()
875 q.qu_value = cpu_to_be64(fdq->d_space >> sdp->sd_sb.sb_bsize_shift); in gfs2_adjust_quota()
876 qd->qd_qb.qb_value = q.qu_value; in gfs2_adjust_quota()
879 spin_unlock(&qd->qd_lockref.lock); in gfs2_adjust_quota()
884 if (size > inode->i_size) in gfs2_adjust_quota()
888 set_bit(QDF_REFRESH, &qd->qd_flags); in gfs2_adjust_quota()
897 struct gfs2_sbd *sdp = (*qda)->qd_sbd; in do_sync()
898 struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode); in do_sync() local
906 unsigned int nalloc = 0, blocks; in do_sync() local
909 gfs2_write_calc_reserv(ip, sizeof(struct gfs2_quota), in do_sync()
914 return -ENOMEM; in do_sync()
917 inode_lock(&ip->i_inode); in do_sync()
919 error = gfs2_glock_nq_init(qda[qx]->qd_gl, LM_ST_EXCLUSIVE, in do_sync()
925 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); in do_sync()
931 if (gfs2_write_alloc_required(ip, offset, in do_sync()
944 * two blocks need to be updated instead of 1 */ in do_sync()
945 blocks = num_qd * data_blocks + RES_DINODE + num_qd + 3; in do_sync()
949 error = gfs2_inplace_reserve(ip, &ap); in do_sync()
954 blocks += gfs2_rg_blocks(ip, reserved) + nalloc * ind_blocks + RES_STATFS; in do_sync()
956 error = gfs2_trans_begin(sdp, blocks, 0); in do_sync()
963 error = gfs2_adjust_quota(sdp, offset, qd->qd_change_sync, qd, in do_sync()
968 do_qc(qd, -qd->qd_change_sync); in do_sync()
969 set_bit(QDF_REFRESH, &qd->qd_flags); in do_sync()
975 gfs2_inplace_release(ip); in do_sync()
979 while (qx--) in do_sync()
981 inode_unlock(&ip->i_inode); in do_sync()
983 gfs2_log_flush(ip->i_gl->gl_name.ln_sbd, ip->i_gl, in do_sync()
988 spin_lock(&qd->qd_lockref.lock); in do_sync()
989 if (qd->qd_sync_gen < sync_gen) in do_sync()
990 qd->qd_sync_gen = sync_gen; in do_sync()
991 spin_unlock(&qd->qd_lockref.lock); in do_sync()
999 struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode); in update_qd() local
1007 error = gfs2_internal_read(ip, (char *)&q, &pos, sizeof(q)); in update_qd()
1011 qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lksb.sb_lvbptr; in update_qd()
1012 qlvb->qb_magic = cpu_to_be32(GFS2_MAGIC); in update_qd()
1013 qlvb->__pad = 0; in update_qd()
1014 qlvb->qb_limit = q.qu_limit; in update_qd()
1015 qlvb->qb_warn = q.qu_warn; in update_qd()
1016 qlvb->qb_value = q.qu_value; in update_qd()
1017 spin_lock(&qd->qd_lockref.lock); in update_qd()
1018 qd->qd_qb = *qlvb; in update_qd()
1019 spin_unlock(&qd->qd_lockref.lock); in update_qd()
1027 struct gfs2_sbd *sdp = qd->qd_sbd; in do_glock()
1028 struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode); in do_glock() local
1032 gfs2_assert_warn(sdp, sdp == qd->qd_gl->gl_name.ln_sbd); in do_glock()
1034 error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_SHARED, 0, q_gh); in do_glock()
1038 if (test_and_clear_bit(QDF_REFRESH, &qd->qd_flags)) in do_glock()
1041 spin_lock(&qd->qd_lockref.lock); in do_glock()
1042 qd->qd_qb = *(struct gfs2_quota_lvb *)qd->qd_gl->gl_lksb.sb_lvbptr; in do_glock()
1043 spin_unlock(&qd->qd_lockref.lock); in do_glock()
1045 if (force_refresh || qd->qd_qb.qb_magic != cpu_to_be32(GFS2_MAGIC)) { in do_glock()
1047 error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_EXCLUSIVE, in do_glock()
1052 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh); in do_glock()
1075 int gfs2_quota_lock(struct gfs2_inode *ip, kuid_t uid, kgid_t gid) in gfs2_quota_lock() argument
1077 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_quota_lock()
1082 if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF) in gfs2_quota_lock()
1085 error = gfs2_quota_hold(ip, uid, gid); in gfs2_quota_lock()
1089 sort(ip->i_qadata->qa_qd, ip->i_qadata->qa_qd_num, in gfs2_quota_lock()
1092 for (x = 0; x < ip->i_qadata->qa_qd_num; x++) { in gfs2_quota_lock()
1093 qd = ip->i_qadata->qa_qd[x]; in gfs2_quota_lock()
1094 error = do_glock(qd, NO_FORCE, &ip->i_qadata->qa_qd_ghs[x]); in gfs2_quota_lock()
1100 set_bit(GIF_QD_LOCKED, &ip->i_flags); in gfs2_quota_lock()
1102 while (x--) in gfs2_quota_lock()
1103 gfs2_glock_dq_uninit(&ip->i_qadata->qa_qd_ghs[x]); in gfs2_quota_lock()
1104 gfs2_quota_unhold(ip); in gfs2_quota_lock()
1112 struct gfs2_sbd *sdp = qd->qd_sbd; in need_sync()
1113 struct gfs2_tune *gt = &sdp->sd_tune; in need_sync()
1118 spin_lock(&qd->qd_lockref.lock); in need_sync()
1119 if (!qd->qd_qb.qb_limit) in need_sync()
1122 change = qd->qd_change; in need_sync()
1125 value = (s64)be64_to_cpu(qd->qd_qb.qb_value); in need_sync()
1126 limit = (s64)be64_to_cpu(qd->qd_qb.qb_limit); in need_sync()
1130 spin_lock(&gt->gt_spin); in need_sync()
1131 num = gt->gt_quota_scale_num; in need_sync()
1132 den = gt->gt_quota_scale_den; in need_sync()
1133 spin_unlock(&gt->gt_spin); in need_sync()
1142 spin_unlock(&qd->qd_lockref.lock); in need_sync()
1146 void gfs2_quota_unlock(struct gfs2_inode *ip) in gfs2_quota_unlock() argument
1148 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_quota_unlock()
1153 if (!test_and_clear_bit(GIF_QD_LOCKED, &ip->i_flags)) in gfs2_quota_unlock()
1156 for (x = 0; x < ip->i_qadata->qa_qd_num; x++) { in gfs2_quota_unlock()
1161 qd = ip->i_qadata->qa_qd[x]; in gfs2_quota_unlock()
1164 gfs2_glock_dq_uninit(&ip->i_qadata->qa_qd_ghs[x]); in gfs2_quota_unlock()
1175 gfs2_assert_warn(sdp, qd->qd_change_sync); in gfs2_quota_unlock()
1186 u64 sync_gen = READ_ONCE(sdp->sd_quota_sync_gen); in gfs2_quota_unlock()
1193 gfs2_quota_unhold(ip); in gfs2_quota_unlock()
1200 struct gfs2_sbd *sdp = qd->qd_sbd; in print_message()
1202 if (sdp->sd_args.ar_quota != GFS2_QUOTA_QUIET) { in print_message()
1205 (qd->qd_id.type == USRQUOTA) ? "user" : "group", in print_message()
1206 from_kqid(&init_user_ns, qd->qd_id)); in print_message()
1211 * gfs2_quota_check - check if allocating new blocks will exceed quota
1212 * @ip: The inode for which this check is being performed
1215 * @ap: The allocation parameters. ap->target contains the requested
1216 * blocks. ap->min_target, if set, contains the minimum blks
1220 * min_req = ap->min_target ? ap->min_target : ap->target;
1222 * ap->allowed is set to the number of blocks allowed
1224 * -EDQUOT otherwise, quota violation. ap->allowed is set to number
1225 * of blocks available.
1227 int gfs2_quota_check(struct gfs2_inode *ip, kuid_t uid, kgid_t gid, in gfs2_quota_check() argument
1230 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_quota_check()
1236 ap->allowed = UINT_MAX; /* Assume we are permitted a whole lot */ in gfs2_quota_check()
1237 if (!test_bit(GIF_QD_LOCKED, &ip->i_flags)) in gfs2_quota_check()
1240 for (x = 0; x < ip->i_qadata->qa_qd_num; x++) { in gfs2_quota_check()
1241 qd = ip->i_qadata->qa_qd[x]; in gfs2_quota_check()
1243 if (!(qid_eq(qd->qd_id, make_kqid_uid(uid)) || in gfs2_quota_check()
1244 qid_eq(qd->qd_id, make_kqid_gid(gid)))) in gfs2_quota_check()
1247 spin_lock(&qd->qd_lockref.lock); in gfs2_quota_check()
1248 warn = (s64)be64_to_cpu(qd->qd_qb.qb_warn); in gfs2_quota_check()
1249 limit = (s64)be64_to_cpu(qd->qd_qb.qb_limit); in gfs2_quota_check()
1250 value = (s64)be64_to_cpu(qd->qd_qb.qb_value); in gfs2_quota_check()
1251 value += qd->qd_change; in gfs2_quota_check()
1252 spin_unlock(&qd->qd_lockref.lock); in gfs2_quota_check()
1254 if (limit > 0 && (limit - value) < ap->allowed) in gfs2_quota_check()
1255 ap->allowed = limit - value; in gfs2_quota_check()
1257 if (limit && limit < (value + (s64)ap->target)) { in gfs2_quota_check()
1259 * min_target, return -EDQUOT */ in gfs2_quota_check()
1260 if (!ap->min_target || ap->min_target > ap->allowed) { in gfs2_quota_check()
1262 &qd->qd_flags)) { in gfs2_quota_check()
1264 quota_send_warning(qd->qd_id, in gfs2_quota_check()
1265 sdp->sd_vfs->s_dev, in gfs2_quota_check()
1268 error = -EDQUOT; in gfs2_quota_check()
1272 time_after_eq(jiffies, qd->qd_last_warn + in gfs2_quota_check()
1275 quota_send_warning(qd->qd_id, in gfs2_quota_check()
1276 sdp->sd_vfs->s_dev, QUOTA_NL_BSOFTWARN); in gfs2_quota_check()
1279 qd->qd_last_warn = jiffies; in gfs2_quota_check()
1285 void gfs2_quota_change(struct gfs2_inode *ip, s64 change, in gfs2_quota_change() argument
1290 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_quota_change()
1292 if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF || in gfs2_quota_change()
1295 if (ip->i_diskflags & GFS2_DIF_SYSTEM) in gfs2_quota_change()
1298 if (gfs2_assert_withdraw(sdp, ip->i_qadata && in gfs2_quota_change()
1299 ip->i_qadata->qa_ref > 0)) in gfs2_quota_change()
1301 for (x = 0; x < ip->i_qadata->qa_qd_num; x++) { in gfs2_quota_change()
1302 qd = ip->i_qadata->qa_qd[x]; in gfs2_quota_change()
1304 if (qid_eq(qd->qd_id, make_kqid_uid(uid)) || in gfs2_quota_change()
1305 qid_eq(qd->qd_id, make_kqid_gid(gid))) { in gfs2_quota_change()
1313 struct gfs2_sbd *sdp = sb->s_fs_info; in gfs2_quota_sync()
1319 if (sb_rdonly(sdp->sd_vfs)) in gfs2_quota_sync()
1324 return -ENOMEM; in gfs2_quota_sync()
1326 mutex_lock(&sdp->sd_quota_sync_mutex); in gfs2_quota_sync()
1327 sync_gen = sdp->sd_quota_sync_gen + 1; in gfs2_quota_sync()
1335 list_for_each_entry(iter, &sdp->sd_quota_list, qd_list) { in gfs2_quota_sync()
1353 qd_ungrab_sync(qda[--num_qd]); in gfs2_quota_sync()
1358 WRITE_ONCE(sdp->sd_quota_sync_gen, sync_gen); in gfs2_quota_sync()
1366 mutex_unlock(&sdp->sd_quota_sync_mutex); in gfs2_quota_sync()
1392 struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode); in gfs2_quota_init() local
1393 u64 size = i_size_read(sdp->sd_qc_inode); in gfs2_quota_init()
1394 unsigned int blocks = size >> sdp->sd_sb.sb_bsize_shift; in gfs2_quota_init() local
1404 if (gfs2_check_internal_file_size(sdp->sd_qc_inode, 1, 64 << 20)) in gfs2_quota_init()
1405 return -EIO; in gfs2_quota_init()
1407 sdp->sd_quota_slots = blocks * sdp->sd_qc_per_block; in gfs2_quota_init()
1408 bm_size = DIV_ROUND_UP(sdp->sd_quota_slots, 8 * sizeof(unsigned long)); in gfs2_quota_init()
1410 error = -ENOMEM; in gfs2_quota_init()
1411 sdp->sd_quota_bitmap = kzalloc(bm_size, GFP_NOFS | __GFP_NOWARN); in gfs2_quota_init()
1412 if (sdp->sd_quota_bitmap == NULL) in gfs2_quota_init()
1413 sdp->sd_quota_bitmap = __vmalloc(bm_size, GFP_NOFS | in gfs2_quota_init()
1415 if (!sdp->sd_quota_bitmap) in gfs2_quota_init()
1418 for (x = 0; x < blocks; x++) { in gfs2_quota_init()
1424 error = gfs2_get_extent(&ip->i_inode, x, &dblock, &extlen); in gfs2_quota_init()
1428 error = -EIO; in gfs2_quota_init()
1429 bh = gfs2_meta_ra(ip->i_gl, dblock, extlen); in gfs2_quota_init()
1435 qc = (struct gfs2_quota_change *)(bh->b_data + sizeof(struct gfs2_meta_header)); in gfs2_quota_init()
1436 for (y = 0; y < sdp->sd_qc_per_block && slot < sdp->sd_quota_slots; in gfs2_quota_init()
1439 s64 qc_change = be64_to_cpu(qc->qc_change); in gfs2_quota_init()
1440 u32 qc_flags = be32_to_cpu(qc->qc_flags); in gfs2_quota_init()
1444 be32_to_cpu(qc->qc_id)); in gfs2_quota_init()
1454 set_bit(QDF_CHANGE, &qd->qd_flags); in gfs2_quota_init()
1455 qd->qd_change = qc_change; in gfs2_quota_init()
1456 qd->qd_slot = slot; in gfs2_quota_init()
1457 qd->qd_slot_ref = 1; in gfs2_quota_init()
1466 sdp->sd_jdesc->jd_jid, slot); in gfs2_quota_init()
1472 gfs2_glock_put(qd->qd_gl); in gfs2_quota_init()
1483 BUG_ON(test_and_set_bit(slot, sdp->sd_quota_bitmap)); in gfs2_quota_init()
1484 list_add(&qd->qd_list, &sdp->sd_quota_list); in gfs2_quota_init()
1485 atomic_inc(&sdp->sd_quota_count); in gfs2_quota_init()
1486 hlist_bl_add_head_rcu(&qd->qd_hlist, &qd_hash_table[hash]); in gfs2_quota_init()
1497 extlen--; in gfs2_quota_init()
1520 BUG_ON(!test_bit(SDF_NORECOVERY, &sdp->sd_flags) && in gfs2_quota_cleanup()
1521 test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)); in gfs2_quota_cleanup()
1524 list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) { in gfs2_quota_cleanup()
1525 spin_lock(&qd->qd_lockref.lock); in gfs2_quota_cleanup()
1526 if (qd->qd_lockref.count != 0) { in gfs2_quota_cleanup()
1527 spin_unlock(&qd->qd_lockref.lock); in gfs2_quota_cleanup()
1530 lockref_mark_dead(&qd->qd_lockref); in gfs2_quota_cleanup()
1531 spin_unlock(&qd->qd_lockref.lock); in gfs2_quota_cleanup()
1533 list_lru_del_obj(&gfs2_qd_lru, &qd->qd_lru); in gfs2_quota_cleanup()
1534 list_add(&qd->qd_lru, &dispose); in gfs2_quota_cleanup()
1540 wait_event_timeout(sdp->sd_kill_wait, in gfs2_quota_cleanup()
1541 (count = atomic_read(&sdp->sd_quota_count)) == 0, in gfs2_quota_cleanup()
1545 fs_err(sdp, "%d left-over quota data objects\n", count); in gfs2_quota_cleanup()
1547 kvfree(sdp->sd_quota_bitmap); in gfs2_quota_cleanup()
1548 sdp->sd_quota_bitmap = NULL; in gfs2_quota_cleanup()
1553 if (error == 0 || error == -EROFS) in quotad_error()
1556 if (!cmpxchg(&sdp->sd_log_error, 0, error)) in quotad_error()
1558 wake_up(&sdp->sd_logd_waitq); in quotad_error()
1568 int error = fxn(sdp->sd_vfs, 0); in quotad_check_timeo()
1570 *timeo = gfs2_tune_get_i(&sdp->sd_tune, new_timeo) * HZ; in quotad_check_timeo()
1572 *timeo -= t; in quotad_check_timeo()
1577 if (!sdp->sd_statfs_force_sync) { in gfs2_wake_up_statfs()
1578 sdp->sd_statfs_force_sync = 1; in gfs2_wake_up_statfs()
1579 wake_up(&sdp->sd_quota_wait); in gfs2_wake_up_statfs()
1585 * gfs2_quotad - Write cached quota changes into the quota file
1593 struct gfs2_tune *tune = &sdp->sd_tune; in gfs2_quotad()
1604 if (sdp->sd_statfs_force_sync) { in gfs2_quotad()
1605 int error = gfs2_statfs_sync(sdp->sd_vfs, 0); in gfs2_quotad()
1612 &tune->gt_statfs_quantum); in gfs2_quotad()
1616 &quotad_timeo, &tune->gt_quota_quantum); in gfs2_quotad()
1620 t = wait_event_freezable_timeout(sdp->sd_quota_wait, in gfs2_quotad()
1621 sdp->sd_statfs_force_sync || in gfs2_quotad()
1626 if (sdp->sd_statfs_force_sync) in gfs2_quotad()
1635 struct gfs2_sbd *sdp = sb->s_fs_info; in gfs2_quota_get_state()
1639 switch (sdp->sd_args.ar_quota) { in gfs2_quota_get_state()
1643 state->s_state[USRQUOTA].flags |= QCI_LIMITS_ENFORCED; in gfs2_quota_get_state()
1644 state->s_state[GRPQUOTA].flags |= QCI_LIMITS_ENFORCED; in gfs2_quota_get_state()
1647 state->s_state[USRQUOTA].flags |= QCI_ACCT_ENABLED | in gfs2_quota_get_state()
1649 state->s_state[GRPQUOTA].flags |= QCI_ACCT_ENABLED | in gfs2_quota_get_state()
1655 if (sdp->sd_quota_inode) { in gfs2_quota_get_state()
1656 state->s_state[USRQUOTA].ino = in gfs2_quota_get_state()
1657 GFS2_I(sdp->sd_quota_inode)->i_no_addr; in gfs2_quota_get_state()
1658 state->s_state[USRQUOTA].blocks = sdp->sd_quota_inode->i_blocks; in gfs2_quota_get_state()
1660 state->s_state[USRQUOTA].nextents = 1; /* unsupported */ in gfs2_quota_get_state()
1661 state->s_state[GRPQUOTA] = state->s_state[USRQUOTA]; in gfs2_quota_get_state()
1662 state->s_incoredqs = list_lru_count(&gfs2_qd_lru); in gfs2_quota_get_state()
1669 struct gfs2_sbd *sdp = sb->s_fs_info; in gfs2_get_dqblk()
1677 if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF) in gfs2_get_dqblk()
1678 return -ESRCH; /* Crazy XFS error code */ in gfs2_get_dqblk()
1682 return -EINVAL; in gfs2_get_dqblk()
1691 qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lksb.sb_lvbptr; in gfs2_get_dqblk()
1692 fdq->d_spc_hardlimit = be64_to_cpu(qlvb->qb_limit) << sdp->sd_sb.sb_bsize_shift; in gfs2_get_dqblk()
1693 fdq->d_spc_softlimit = be64_to_cpu(qlvb->qb_warn) << sdp->sd_sb.sb_bsize_shift; in gfs2_get_dqblk()
1694 fdq->d_space = be64_to_cpu(qlvb->qb_value) << sdp->sd_sb.sb_bsize_shift; in gfs2_get_dqblk()
1708 struct gfs2_sbd *sdp = sb->s_fs_info; in gfs2_set_dqblk()
1709 struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode); in gfs2_set_dqblk() local
1713 unsigned int blocks = 0; in gfs2_set_dqblk() local
1718 if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF) in gfs2_set_dqblk()
1719 return -ESRCH; /* Crazy XFS error code */ in gfs2_set_dqblk()
1723 return -EINVAL; in gfs2_set_dqblk()
1725 if (fdq->d_fieldmask & ~GFS2_FIELDMASK) in gfs2_set_dqblk()
1726 return -EINVAL; in gfs2_set_dqblk()
1732 error = gfs2_qa_get(ip); in gfs2_set_dqblk()
1736 inode_lock(&ip->i_inode); in gfs2_set_dqblk()
1737 error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_EXCLUSIVE, 0, &q_gh); in gfs2_set_dqblk()
1740 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); in gfs2_set_dqblk()
1744 /* Check for existing entry, if none then alloc new blocks */ in gfs2_set_dqblk()
1749 /* If nothing has changed, this is a no-op */ in gfs2_set_dqblk()
1750 if ((fdq->d_fieldmask & QC_SPC_SOFT) && in gfs2_set_dqblk()
1751 ((fdq->d_spc_softlimit >> sdp->sd_sb.sb_bsize_shift) == be64_to_cpu(qd->qd_qb.qb_warn))) in gfs2_set_dqblk()
1752 fdq->d_fieldmask ^= QC_SPC_SOFT; in gfs2_set_dqblk()
1754 if ((fdq->d_fieldmask & QC_SPC_HARD) && in gfs2_set_dqblk()
1755 ((fdq->d_spc_hardlimit >> sdp->sd_sb.sb_bsize_shift) == be64_to_cpu(qd->qd_qb.qb_limit))) in gfs2_set_dqblk()
1756 fdq->d_fieldmask ^= QC_SPC_HARD; in gfs2_set_dqblk()
1758 if ((fdq->d_fieldmask & QC_SPACE) && in gfs2_set_dqblk()
1759 ((fdq->d_space >> sdp->sd_sb.sb_bsize_shift) == be64_to_cpu(qd->qd_qb.qb_value))) in gfs2_set_dqblk()
1760 fdq->d_fieldmask ^= QC_SPACE; in gfs2_set_dqblk()
1762 if (fdq->d_fieldmask == 0) in gfs2_set_dqblk()
1766 alloc_required = gfs2_write_alloc_required(ip, offset, sizeof(struct gfs2_quota)); in gfs2_set_dqblk()
1767 if (gfs2_is_stuffed(ip)) in gfs2_set_dqblk()
1771 gfs2_write_calc_reserv(ip, sizeof(struct gfs2_quota), in gfs2_set_dqblk()
1773 blocks = 1 + data_blocks + ind_blocks; in gfs2_set_dqblk()
1774 ap.target = blocks; in gfs2_set_dqblk()
1775 error = gfs2_inplace_reserve(ip, &ap); in gfs2_set_dqblk()
1778 blocks += gfs2_rg_blocks(ip, blocks); in gfs2_set_dqblk()
1781 /* Some quotas span block boundaries and can update two blocks, in gfs2_set_dqblk()
1783 error = gfs2_trans_begin(sdp, blocks + RES_DINODE + 2, 0); in gfs2_set_dqblk()
1790 clear_bit(QDF_QMSG_QUIET, &qd->qd_flags); in gfs2_set_dqblk()
1795 gfs2_inplace_release(ip); in gfs2_set_dqblk()
1801 gfs2_qa_put(ip); in gfs2_set_dqblk()
1802 inode_unlock(&ip->i_inode); in gfs2_set_dqblk()