.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
---|
3 | 4 | * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. |
---|
4 | | - * |
---|
5 | | - * This copyrighted material is made available to anyone wishing to use, |
---|
6 | | - * modify, copy, or redistribute it subject to the terms and conditions |
---|
7 | | - * of the GNU General Public License version 2. |
---|
8 | 5 | */ |
---|
9 | 6 | |
---|
10 | 7 | /* |
---|
.. | .. |
---|
118 | 115 | struct gfs2_sbd *sdp; |
---|
119 | 116 | |
---|
120 | 117 | while (!list_empty(list)) { |
---|
121 | | - qd = list_entry(list->next, struct gfs2_quota_data, qd_lru); |
---|
| 118 | + qd = list_first_entry(list, struct gfs2_quota_data, qd_lru); |
---|
122 | 119 | sdp = qd->qd_gl->gl_name.ln_sbd; |
---|
123 | 120 | |
---|
124 | 121 | list_del(&qd->qd_lru); |
---|
.. | .. |
---|
528 | 525 | } |
---|
529 | 526 | |
---|
530 | 527 | /** |
---|
531 | | - * gfs2_qa_alloc - make sure we have a quota allocations data structure, |
---|
532 | | - * if necessary |
---|
| 528 | + * gfs2_qa_get - make sure we have a quota allocations data structure, |
---|
| 529 | + * if necessary |
---|
533 | 530 | * @ip: the inode for this reservation |
---|
534 | 531 | */ |
---|
535 | | -int gfs2_qa_alloc(struct gfs2_inode *ip) |
---|
| 532 | +int gfs2_qa_get(struct gfs2_inode *ip) |
---|
536 | 533 | { |
---|
537 | | - int error = 0; |
---|
538 | 534 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
---|
| 535 | + struct inode *inode = &ip->i_inode; |
---|
539 | 536 | |
---|
540 | 537 | if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF) |
---|
541 | 538 | return 0; |
---|
542 | 539 | |
---|
543 | | - down_write(&ip->i_rw_mutex); |
---|
| 540 | + spin_lock(&inode->i_lock); |
---|
544 | 541 | if (ip->i_qadata == NULL) { |
---|
545 | | - ip->i_qadata = kmem_cache_zalloc(gfs2_qadata_cachep, GFP_NOFS); |
---|
546 | | - if (!ip->i_qadata) |
---|
547 | | - error = -ENOMEM; |
---|
| 542 | + struct gfs2_qadata *tmp; |
---|
| 543 | + |
---|
| 544 | + spin_unlock(&inode->i_lock); |
---|
| 545 | + tmp = kmem_cache_zalloc(gfs2_qadata_cachep, GFP_NOFS); |
---|
| 546 | + if (!tmp) |
---|
| 547 | + return -ENOMEM; |
---|
| 548 | + |
---|
| 549 | + spin_lock(&inode->i_lock); |
---|
| 550 | + if (ip->i_qadata == NULL) |
---|
| 551 | + ip->i_qadata = tmp; |
---|
| 552 | + else |
---|
| 553 | + kmem_cache_free(gfs2_qadata_cachep, tmp); |
---|
548 | 554 | } |
---|
549 | | - up_write(&ip->i_rw_mutex); |
---|
550 | | - return error; |
---|
| 555 | + ip->i_qadata->qa_ref++; |
---|
| 556 | + spin_unlock(&inode->i_lock); |
---|
| 557 | + return 0; |
---|
551 | 558 | } |
---|
552 | 559 | |
---|
553 | | -void gfs2_qa_delete(struct gfs2_inode *ip, atomic_t *wcount) |
---|
| 560 | +void gfs2_qa_put(struct gfs2_inode *ip) |
---|
554 | 561 | { |
---|
555 | | - down_write(&ip->i_rw_mutex); |
---|
556 | | - if (ip->i_qadata && ((wcount == NULL) || (atomic_read(wcount) <= 1))) { |
---|
| 562 | + struct inode *inode = &ip->i_inode; |
---|
| 563 | + |
---|
| 564 | + spin_lock(&inode->i_lock); |
---|
| 565 | + if (ip->i_qadata && --ip->i_qadata->qa_ref == 0) { |
---|
557 | 566 | kmem_cache_free(gfs2_qadata_cachep, ip->i_qadata); |
---|
558 | 567 | ip->i_qadata = NULL; |
---|
559 | 568 | } |
---|
560 | | - up_write(&ip->i_rw_mutex); |
---|
| 569 | + spin_unlock(&inode->i_lock); |
---|
561 | 570 | } |
---|
562 | 571 | |
---|
563 | 572 | int gfs2_quota_hold(struct gfs2_inode *ip, kuid_t uid, kgid_t gid) |
---|
.. | .. |
---|
569 | 578 | if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF) |
---|
570 | 579 | return 0; |
---|
571 | 580 | |
---|
572 | | - if (ip->i_qadata == NULL) { |
---|
573 | | - error = gfs2_rsqa_alloc(ip); |
---|
574 | | - if (error) |
---|
575 | | - return error; |
---|
576 | | - } |
---|
| 581 | + error = gfs2_qa_get(ip); |
---|
| 582 | + if (error) |
---|
| 583 | + return error; |
---|
577 | 584 | |
---|
578 | 585 | qd = ip->i_qadata->qa_qd; |
---|
579 | 586 | |
---|
580 | 587 | if (gfs2_assert_warn(sdp, !ip->i_qadata->qa_qd_num) || |
---|
581 | | - gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags))) |
---|
582 | | - return -EIO; |
---|
| 588 | + gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags))) { |
---|
| 589 | + error = -EIO; |
---|
| 590 | + goto out; |
---|
| 591 | + } |
---|
583 | 592 | |
---|
584 | 593 | error = qdsb_get(sdp, make_kqid_uid(ip->i_inode.i_uid), qd); |
---|
585 | 594 | if (error) |
---|
586 | | - goto out; |
---|
| 595 | + goto out_unhold; |
---|
587 | 596 | ip->i_qadata->qa_qd_num++; |
---|
588 | 597 | qd++; |
---|
589 | 598 | |
---|
590 | 599 | error = qdsb_get(sdp, make_kqid_gid(ip->i_inode.i_gid), qd); |
---|
591 | 600 | if (error) |
---|
592 | | - goto out; |
---|
| 601 | + goto out_unhold; |
---|
593 | 602 | ip->i_qadata->qa_qd_num++; |
---|
594 | 603 | qd++; |
---|
595 | 604 | |
---|
.. | .. |
---|
597 | 606 | !uid_eq(uid, ip->i_inode.i_uid)) { |
---|
598 | 607 | error = qdsb_get(sdp, make_kqid_uid(uid), qd); |
---|
599 | 608 | if (error) |
---|
600 | | - goto out; |
---|
| 609 | + goto out_unhold; |
---|
601 | 610 | ip->i_qadata->qa_qd_num++; |
---|
602 | 611 | qd++; |
---|
603 | 612 | } |
---|
.. | .. |
---|
606 | 615 | !gid_eq(gid, ip->i_inode.i_gid)) { |
---|
607 | 616 | error = qdsb_get(sdp, make_kqid_gid(gid), qd); |
---|
608 | 617 | if (error) |
---|
609 | | - goto out; |
---|
| 618 | + goto out_unhold; |
---|
610 | 619 | ip->i_qadata->qa_qd_num++; |
---|
611 | 620 | qd++; |
---|
612 | 621 | } |
---|
613 | 622 | |
---|
614 | | -out: |
---|
| 623 | +out_unhold: |
---|
615 | 624 | if (error) |
---|
616 | 625 | gfs2_quota_unhold(ip); |
---|
| 626 | +out: |
---|
617 | 627 | return error; |
---|
618 | 628 | } |
---|
619 | 629 | |
---|
.. | .. |
---|
624 | 634 | |
---|
625 | 635 | if (ip->i_qadata == NULL) |
---|
626 | 636 | return; |
---|
| 637 | + |
---|
627 | 638 | gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags)); |
---|
628 | 639 | |
---|
629 | 640 | for (x = 0; x < ip->i_qadata->qa_qd_num; x++) { |
---|
.. | .. |
---|
631 | 642 | ip->i_qadata->qa_qd[x] = NULL; |
---|
632 | 643 | } |
---|
633 | 644 | ip->i_qadata->qa_qd_num = 0; |
---|
| 645 | + gfs2_qa_put(ip); |
---|
634 | 646 | } |
---|
635 | 647 | |
---|
636 | 648 | static int sort_qd(const void *a, const void *b) |
---|
.. | .. |
---|
777 | 789 | nbytes = sizeof(struct gfs2_quota); |
---|
778 | 790 | |
---|
779 | 791 | pg_beg = loc >> PAGE_SHIFT; |
---|
780 | | - pg_off = loc % PAGE_SIZE; |
---|
| 792 | + pg_off = offset_in_page(loc); |
---|
781 | 793 | |
---|
782 | 794 | /* If the quota straddles a page boundary, split the write in two */ |
---|
783 | 795 | if ((pg_off + nbytes) > PAGE_SIZE) { |
---|
.. | .. |
---|
879 | 891 | unsigned int nalloc = 0, blocks; |
---|
880 | 892 | int error; |
---|
881 | 893 | |
---|
882 | | - error = gfs2_rsqa_alloc(ip); |
---|
| 894 | + error = gfs2_qa_get(ip); |
---|
883 | 895 | if (error) |
---|
884 | 896 | return error; |
---|
885 | 897 | |
---|
.. | .. |
---|
887 | 899 | &data_blocks, &ind_blocks); |
---|
888 | 900 | |
---|
889 | 901 | ghs = kmalloc_array(num_qd, sizeof(struct gfs2_holder), GFP_NOFS); |
---|
890 | | - if (!ghs) |
---|
891 | | - return -ENOMEM; |
---|
| 902 | + if (!ghs) { |
---|
| 903 | + error = -ENOMEM; |
---|
| 904 | + goto out; |
---|
| 905 | + } |
---|
892 | 906 | |
---|
893 | 907 | sort(qda, num_qd, sizeof(struct gfs2_quota_data *), sort_qd, NULL); |
---|
894 | 908 | inode_lock(&ip->i_inode); |
---|
.. | .. |
---|
896 | 910 | error = gfs2_glock_nq_init(qda[qx]->qd_gl, LM_ST_EXCLUSIVE, |
---|
897 | 911 | GL_NOCACHE, &ghs[qx]); |
---|
898 | 912 | if (error) |
---|
899 | | - goto out; |
---|
| 913 | + goto out_dq; |
---|
900 | 914 | } |
---|
901 | 915 | |
---|
902 | 916 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); |
---|
903 | 917 | if (error) |
---|
904 | | - goto out; |
---|
| 918 | + goto out_dq; |
---|
905 | 919 | |
---|
906 | 920 | for (x = 0; x < num_qd; x++) { |
---|
907 | 921 | offset = qd2offset(qda[x]); |
---|
.. | .. |
---|
953 | 967 | gfs2_inplace_release(ip); |
---|
954 | 968 | out_alloc: |
---|
955 | 969 | gfs2_glock_dq_uninit(&i_gh); |
---|
956 | | -out: |
---|
| 970 | +out_dq: |
---|
957 | 971 | while (qx--) |
---|
958 | 972 | gfs2_glock_dq_uninit(&ghs[qx]); |
---|
959 | 973 | inode_unlock(&ip->i_inode); |
---|
960 | 974 | kfree(ghs); |
---|
961 | 975 | gfs2_log_flush(ip->i_gl->gl_name.ln_sbd, ip->i_gl, |
---|
962 | 976 | GFS2_LOG_HEAD_FLUSH_NORMAL | GFS2_LFC_DO_SYNC); |
---|
| 977 | +out: |
---|
| 978 | + gfs2_qa_put(ip); |
---|
963 | 979 | return error; |
---|
964 | 980 | } |
---|
965 | 981 | |
---|
.. | .. |
---|
1116 | 1132 | int found; |
---|
1117 | 1133 | |
---|
1118 | 1134 | if (!test_and_clear_bit(GIF_QD_LOCKED, &ip->i_flags)) |
---|
1119 | | - goto out; |
---|
| 1135 | + return; |
---|
1120 | 1136 | |
---|
1121 | 1137 | for (x = 0; x < ip->i_qadata->qa_qd_num; x++) { |
---|
1122 | 1138 | struct gfs2_quota_data *qd; |
---|
.. | .. |
---|
1153 | 1169 | qd_unlock(qda[x]); |
---|
1154 | 1170 | } |
---|
1155 | 1171 | |
---|
1156 | | -out: |
---|
1157 | 1172 | gfs2_quota_unhold(ip); |
---|
1158 | 1173 | } |
---|
1159 | 1174 | |
---|
.. | .. |
---|
1182 | 1197 | * |
---|
1183 | 1198 | * Returns: 0 on success. |
---|
1184 | 1199 | * min_req = ap->min_target ? ap->min_target : ap->target; |
---|
1185 | | - * quota must allow atleast min_req blks for success and |
---|
| 1200 | + * quota must allow at least min_req blks for success and |
---|
1186 | 1201 | * ap->allowed is set to the number of blocks allowed |
---|
1187 | 1202 | * |
---|
1188 | 1203 | * -EDQUOT otherwise, quota violation. ap->allowed is set to number |
---|
.. | .. |
---|
1200 | 1215 | ap->allowed = UINT_MAX; /* Assume we are permitted a whole lot */ |
---|
1201 | 1216 | if (!test_bit(GIF_QD_LOCKED, &ip->i_flags)) |
---|
1202 | 1217 | return 0; |
---|
1203 | | - |
---|
1204 | | - if (sdp->sd_args.ar_quota != GFS2_QUOTA_ON) |
---|
1205 | | - return 0; |
---|
1206 | 1218 | |
---|
1207 | 1219 | for (x = 0; x < ip->i_qadata->qa_qd_num; x++) { |
---|
1208 | 1220 | qd = ip->i_qadata->qa_qd[x]; |
---|
.. | .. |
---|
1261 | 1273 | if (ip->i_diskflags & GFS2_DIF_SYSTEM) |
---|
1262 | 1274 | return; |
---|
1263 | 1275 | |
---|
| 1276 | + if (gfs2_assert_withdraw(sdp, ip->i_qadata && |
---|
| 1277 | + ip->i_qadata->qa_ref > 0)) |
---|
| 1278 | + return; |
---|
1264 | 1279 | for (x = 0; x < ip->i_qadata->qa_qd_num; x++) { |
---|
1265 | 1280 | qd = ip->i_qadata->qa_qd[x]; |
---|
1266 | 1281 | |
---|
.. | .. |
---|
1275 | 1290 | { |
---|
1276 | 1291 | struct gfs2_sbd *sdp = sb->s_fs_info; |
---|
1277 | 1292 | struct gfs2_quota_data **qda; |
---|
1278 | | - unsigned int max_qd = PAGE_SIZE/sizeof(struct gfs2_holder); |
---|
| 1293 | + unsigned int max_qd = PAGE_SIZE / sizeof(struct gfs2_holder); |
---|
1279 | 1294 | unsigned int num_qd; |
---|
1280 | 1295 | unsigned int x; |
---|
1281 | 1296 | int error = 0; |
---|
.. | .. |
---|
1358 | 1373 | sdp->sd_quota_bitmap = kzalloc(bm_size, GFP_NOFS | __GFP_NOWARN); |
---|
1359 | 1374 | if (sdp->sd_quota_bitmap == NULL) |
---|
1360 | 1375 | sdp->sd_quota_bitmap = __vmalloc(bm_size, GFP_NOFS | |
---|
1361 | | - __GFP_ZERO, PAGE_KERNEL); |
---|
| 1376 | + __GFP_ZERO); |
---|
1362 | 1377 | if (!sdp->sd_quota_bitmap) |
---|
1363 | 1378 | return error; |
---|
1364 | 1379 | |
---|
.. | .. |
---|
1443 | 1458 | |
---|
1444 | 1459 | spin_lock(&qd_lock); |
---|
1445 | 1460 | while (!list_empty(head)) { |
---|
1446 | | - qd = list_entry(head->prev, struct gfs2_quota_data, qd_list); |
---|
| 1461 | + qd = list_last_entry(head, struct gfs2_quota_data, qd_list); |
---|
1447 | 1462 | |
---|
1448 | 1463 | list_del(&qd->qd_list); |
---|
1449 | 1464 | |
---|
.. | .. |
---|
1477 | 1492 | { |
---|
1478 | 1493 | if (error == 0 || error == -EROFS) |
---|
1479 | 1494 | return; |
---|
1480 | | - if (!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) { |
---|
1481 | | - fs_err(sdp, "gfs2_quotad: %s error %d\n", msg, error); |
---|
1482 | | - sdp->sd_log_error = error; |
---|
| 1495 | + if (!gfs2_withdrawn(sdp)) { |
---|
| 1496 | + if (!cmpxchg(&sdp->sd_log_error, 0, error)) |
---|
| 1497 | + fs_err(sdp, "gfs2_quotad: %s error %d\n", msg, error); |
---|
1483 | 1498 | wake_up(&sdp->sd_logd_waitq); |
---|
1484 | 1499 | } |
---|
1485 | 1500 | } |
---|
.. | .. |
---|
1506 | 1521 | ip = NULL; |
---|
1507 | 1522 | spin_lock(&sdp->sd_trunc_lock); |
---|
1508 | 1523 | if (!list_empty(&sdp->sd_trunc_list)) { |
---|
1509 | | - ip = list_entry(sdp->sd_trunc_list.next, |
---|
| 1524 | + ip = list_first_entry(&sdp->sd_trunc_list, |
---|
1510 | 1525 | struct gfs2_inode, i_trunc_list); |
---|
1511 | 1526 | list_del_init(&ip->i_trunc_list); |
---|
1512 | 1527 | } |
---|
.. | .. |
---|
1543 | 1558 | |
---|
1544 | 1559 | while (!kthread_should_stop()) { |
---|
1545 | 1560 | |
---|
| 1561 | + if (gfs2_withdrawn(sdp)) |
---|
| 1562 | + goto bypass; |
---|
1546 | 1563 | /* Update the master statfs file */ |
---|
1547 | 1564 | if (sdp->sd_statfs_force_sync) { |
---|
1548 | 1565 | int error = gfs2_statfs_sync(sdp->sd_vfs, 0); |
---|
.. | .. |
---|
1563 | 1580 | |
---|
1564 | 1581 | try_to_freeze(); |
---|
1565 | 1582 | |
---|
| 1583 | +bypass: |
---|
1566 | 1584 | t = min(quotad_timeo, statfs_timeo); |
---|
1567 | 1585 | |
---|
1568 | 1586 | prepare_to_wait(&sdp->sd_quota_wait, &wait, TASK_INTERRUPTIBLE); |
---|
.. | .. |
---|
1589 | 1607 | case GFS2_QUOTA_ON: |
---|
1590 | 1608 | state->s_state[USRQUOTA].flags |= QCI_LIMITS_ENFORCED; |
---|
1591 | 1609 | state->s_state[GRPQUOTA].flags |= QCI_LIMITS_ENFORCED; |
---|
1592 | | - /*FALLTHRU*/ |
---|
| 1610 | + fallthrough; |
---|
1593 | 1611 | case GFS2_QUOTA_ACCOUNT: |
---|
1594 | 1612 | state->s_state[USRQUOTA].flags |= QCI_ACCT_ENABLED | |
---|
1595 | 1613 | QCI_SYSFILE; |
---|
.. | .. |
---|
1676 | 1694 | if (error) |
---|
1677 | 1695 | return error; |
---|
1678 | 1696 | |
---|
1679 | | - error = gfs2_rsqa_alloc(ip); |
---|
| 1697 | + error = gfs2_qa_get(ip); |
---|
1680 | 1698 | if (error) |
---|
1681 | 1699 | goto out_put; |
---|
1682 | 1700 | |
---|
.. | .. |
---|
1745 | 1763 | out_q: |
---|
1746 | 1764 | gfs2_glock_dq_uninit(&q_gh); |
---|
1747 | 1765 | out_unlockput: |
---|
| 1766 | + gfs2_qa_put(ip); |
---|
1748 | 1767 | inode_unlock(&ip->i_inode); |
---|
1749 | 1768 | out_put: |
---|
1750 | 1769 | qd_put(qd); |
---|