.. | .. |
---|
9 | 9 | * on the Melbourne quota system as used on BSD derived systems. The internal |
---|
10 | 10 | * implementation is based on one of the several variants of the LINUX |
---|
11 | 11 | * inode-subsystem with added complexity of the diskquota system. |
---|
12 | | - * |
---|
| 12 | + * |
---|
13 | 13 | * Author: Marco van Wieringen <mvw@planets.elm.net> |
---|
14 | 14 | * |
---|
15 | 15 | * Fixes: Dmitry Gorodchanin <pgmdsg@ibi.com>, 11 Feb 96 |
---|
.. | .. |
---|
51 | 51 | * Added journalled quota support, fix lock inversion problems |
---|
52 | 52 | * Jan Kara, <jack@suse.cz>, 2003,2004 |
---|
53 | 53 | * |
---|
54 | | - * (C) Copyright 1994 - 1997 Marco van Wieringen |
---|
| 54 | + * (C) Copyright 1994 - 1997 Marco van Wieringen |
---|
55 | 55 | */ |
---|
56 | 56 | |
---|
57 | 57 | #include <linux/errno.h> |
---|
.. | .. |
---|
78 | 78 | #include <linux/namei.h> |
---|
79 | 79 | #include <linux/capability.h> |
---|
80 | 80 | #include <linux/quotaops.h> |
---|
| 81 | +#include <linux/blkdev.h> |
---|
| 82 | +#include <linux/sched/mm.h> |
---|
81 | 83 | #include "../internal.h" /* ugh */ |
---|
82 | 84 | |
---|
83 | 85 | #include <linux/uaccess.h> |
---|
.. | .. |
---|
197 | 199 | int qm; |
---|
198 | 200 | |
---|
199 | 201 | spin_unlock(&dq_list_lock); |
---|
200 | | - |
---|
| 202 | + |
---|
201 | 203 | for (qm = 0; module_names[qm].qm_fmt_id && |
---|
202 | 204 | module_names[qm].qm_fmt_id != id; qm++) |
---|
203 | 205 | ; |
---|
.. | .. |
---|
223 | 225 | |
---|
224 | 226 | /* |
---|
225 | 227 | * Dquot List Management: |
---|
226 | | - * The quota code uses three lists for dquot management: the inuse_list, |
---|
227 | | - * free_dquots, and dquot_hash[] array. A single dquot structure may be |
---|
228 | | - * on all three lists, depending on its current state. |
---|
| 228 | + * The quota code uses four lists for dquot management: the inuse_list, |
---|
| 229 | + * free_dquots, dqi_dirty_list, and dquot_hash[] array. A single dquot |
---|
| 230 | + * structure may be on some of those lists, depending on its current state. |
---|
229 | 231 | * |
---|
230 | 232 | * All dquots are placed to the end of inuse_list when first created, and this |
---|
231 | 233 | * list is used for invalidate operation, which must look at every dquot. |
---|
.. | .. |
---|
235 | 237 | * removed from the list as soon as they are used again, and |
---|
236 | 238 | * dqstats.free_dquots gives the number of dquots on the list. When |
---|
237 | 239 | * dquot is invalidated it's completely released from memory. |
---|
| 240 | + * |
---|
| 241 | + * Dirty dquots are added to the dqi_dirty_list of quota_info when mark |
---|
| 242 | + * dirtied, and this list is searched when writing dirty dquots back to |
---|
| 243 | + * quota file. Note that some filesystems do dirty dquot tracking on their |
---|
| 244 | + * own (e.g. in a journal) and thus don't use dqi_dirty_list. |
---|
238 | 245 | * |
---|
239 | 246 | * Dquots with a specific identity (device, type and id) are placed on |
---|
240 | 247 | * one of the dquot_hash[] hash chains. The provides an efficient search |
---|
.. | .. |
---|
421 | 428 | int dquot_acquire(struct dquot *dquot) |
---|
422 | 429 | { |
---|
423 | 430 | int ret = 0, ret2 = 0; |
---|
| 431 | + unsigned int memalloc; |
---|
424 | 432 | struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); |
---|
425 | 433 | |
---|
426 | 434 | mutex_lock(&dquot->dq_lock); |
---|
427 | | - if (!test_bit(DQ_READ_B, &dquot->dq_flags)) |
---|
| 435 | + memalloc = memalloc_nofs_save(); |
---|
| 436 | + if (!test_bit(DQ_READ_B, &dquot->dq_flags)) { |
---|
428 | 437 | ret = dqopt->ops[dquot->dq_id.type]->read_dqblk(dquot); |
---|
429 | | - if (ret < 0) |
---|
430 | | - goto out_iolock; |
---|
| 438 | + if (ret < 0) |
---|
| 439 | + goto out_iolock; |
---|
| 440 | + } |
---|
431 | 441 | /* Make sure flags update is visible after dquot has been filled */ |
---|
432 | 442 | smp_mb__before_atomic(); |
---|
433 | 443 | set_bit(DQ_READ_B, &dquot->dq_flags); |
---|
.. | .. |
---|
453 | 463 | smp_mb__before_atomic(); |
---|
454 | 464 | set_bit(DQ_ACTIVE_B, &dquot->dq_flags); |
---|
455 | 465 | out_iolock: |
---|
| 466 | + memalloc_nofs_restore(memalloc); |
---|
456 | 467 | mutex_unlock(&dquot->dq_lock); |
---|
457 | 468 | return ret; |
---|
458 | 469 | } |
---|
.. | .. |
---|
464 | 475 | int dquot_commit(struct dquot *dquot) |
---|
465 | 476 | { |
---|
466 | 477 | int ret = 0; |
---|
| 478 | + unsigned int memalloc; |
---|
467 | 479 | struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); |
---|
468 | 480 | |
---|
469 | 481 | mutex_lock(&dquot->dq_lock); |
---|
| 482 | + memalloc = memalloc_nofs_save(); |
---|
470 | 483 | if (!clear_dquot_dirty(dquot)) |
---|
471 | 484 | goto out_lock; |
---|
472 | 485 | /* Inactive dquot can be only if there was error during read/init |
---|
.. | .. |
---|
476 | 489 | else |
---|
477 | 490 | ret = -EIO; |
---|
478 | 491 | out_lock: |
---|
| 492 | + memalloc_nofs_restore(memalloc); |
---|
479 | 493 | mutex_unlock(&dquot->dq_lock); |
---|
480 | 494 | return ret; |
---|
481 | 495 | } |
---|
.. | .. |
---|
487 | 501 | int dquot_release(struct dquot *dquot) |
---|
488 | 502 | { |
---|
489 | 503 | int ret = 0, ret2 = 0; |
---|
| 504 | + unsigned int memalloc; |
---|
490 | 505 | struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); |
---|
491 | 506 | |
---|
492 | 507 | mutex_lock(&dquot->dq_lock); |
---|
| 508 | + memalloc = memalloc_nofs_save(); |
---|
493 | 509 | /* Check whether we are not racing with some other dqget() */ |
---|
494 | 510 | if (dquot_is_busy(dquot)) |
---|
495 | 511 | goto out_dqlock; |
---|
.. | .. |
---|
505 | 521 | } |
---|
506 | 522 | clear_bit(DQ_ACTIVE_B, &dquot->dq_flags); |
---|
507 | 523 | out_dqlock: |
---|
| 524 | + memalloc_nofs_restore(memalloc); |
---|
508 | 525 | mutex_unlock(&dquot->dq_lock); |
---|
509 | 526 | return ret; |
---|
510 | 527 | } |
---|
.. | .. |
---|
589 | 606 | /* Now we have active dquot so we can just increase use count */ |
---|
590 | 607 | atomic_inc(&dquot->dq_count); |
---|
591 | 608 | spin_unlock(&dq_list_lock); |
---|
592 | | - dqstats_inc(DQST_LOOKUPS); |
---|
593 | 609 | dqput(old_dquot); |
---|
594 | 610 | old_dquot = dquot; |
---|
595 | 611 | /* |
---|
.. | .. |
---|
644 | 660 | * use count */ |
---|
645 | 661 | dqgrab(dquot); |
---|
646 | 662 | spin_unlock(&dq_list_lock); |
---|
647 | | - dqstats_inc(DQST_LOOKUPS); |
---|
648 | 663 | err = sb->dq_op->write_dquot(dquot); |
---|
649 | 664 | if (err) { |
---|
650 | 665 | /* |
---|
.. | .. |
---|
1056 | 1071 | struct list_head *tofree_head) |
---|
1057 | 1072 | { |
---|
1058 | 1073 | struct inode *inode; |
---|
| 1074 | +#ifdef CONFIG_QUOTA_DEBUG |
---|
1059 | 1075 | int reserved = 0; |
---|
| 1076 | +#endif |
---|
1060 | 1077 | |
---|
1061 | 1078 | spin_lock(&sb->s_inode_list_lock); |
---|
1062 | 1079 | list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { |
---|
.. | .. |
---|
1068 | 1085 | */ |
---|
1069 | 1086 | spin_lock(&dq_data_lock); |
---|
1070 | 1087 | if (!IS_NOQUOTA(inode)) { |
---|
| 1088 | +#ifdef CONFIG_QUOTA_DEBUG |
---|
1071 | 1089 | if (unlikely(inode_get_rsv_space(inode) > 0)) |
---|
1072 | 1090 | reserved = 1; |
---|
| 1091 | +#endif |
---|
1073 | 1092 | remove_inode_dquot_ref(inode, type, tofree_head); |
---|
1074 | 1093 | } |
---|
1075 | 1094 | spin_unlock(&dq_data_lock); |
---|
.. | .. |
---|
1670 | 1689 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
---|
1671 | 1690 | if (!dquots[cnt]) |
---|
1672 | 1691 | continue; |
---|
1673 | | - if (flags & DQUOT_SPACE_RESERVE) { |
---|
| 1692 | + if (reserve) { |
---|
1674 | 1693 | ret = dquot_add_space(dquots[cnt], 0, number, flags, |
---|
1675 | 1694 | &warn[cnt]); |
---|
1676 | 1695 | } else { |
---|
.. | .. |
---|
1683 | 1702 | if (!dquots[cnt]) |
---|
1684 | 1703 | continue; |
---|
1685 | 1704 | spin_lock(&dquots[cnt]->dq_dqb_lock); |
---|
1686 | | - if (flags & DQUOT_SPACE_RESERVE) { |
---|
1687 | | - dquots[cnt]->dq_dqb.dqb_rsvspace -= |
---|
1688 | | - number; |
---|
1689 | | - } else { |
---|
1690 | | - dquots[cnt]->dq_dqb.dqb_curspace -= |
---|
1691 | | - number; |
---|
1692 | | - } |
---|
| 1705 | + if (reserve) |
---|
| 1706 | + dquot_free_reserved_space(dquots[cnt], |
---|
| 1707 | + number); |
---|
| 1708 | + else |
---|
| 1709 | + dquot_decr_space(dquots[cnt], number); |
---|
1693 | 1710 | spin_unlock(&dquots[cnt]->dq_dqb_lock); |
---|
1694 | 1711 | } |
---|
1695 | 1712 | spin_unlock(&inode->i_lock); |
---|
.. | .. |
---|
1740 | 1757 | continue; |
---|
1741 | 1758 | /* Back out changes we already did */ |
---|
1742 | 1759 | spin_lock(&dquots[cnt]->dq_dqb_lock); |
---|
1743 | | - dquots[cnt]->dq_dqb.dqb_curinodes--; |
---|
| 1760 | + dquot_decr_inodes(dquots[cnt], 1); |
---|
1744 | 1761 | spin_unlock(&dquots[cnt]->dq_dqb_lock); |
---|
1745 | 1762 | } |
---|
1746 | 1763 | goto warn_put_all; |
---|
.. | .. |
---|
2161 | 2178 | } |
---|
2162 | 2179 | EXPORT_SYMBOL(dquot_file_open); |
---|
2163 | 2180 | |
---|
| 2181 | +static void vfs_cleanup_quota_inode(struct super_block *sb, int type) |
---|
| 2182 | +{ |
---|
| 2183 | + struct quota_info *dqopt = sb_dqopt(sb); |
---|
| 2184 | + struct inode *inode = dqopt->files[type]; |
---|
| 2185 | + |
---|
| 2186 | + if (!inode) |
---|
| 2187 | + return; |
---|
| 2188 | + if (!(dqopt->flags & DQUOT_QUOTA_SYS_FILE)) { |
---|
| 2189 | + inode_lock(inode); |
---|
| 2190 | + inode->i_flags &= ~S_NOQUOTA; |
---|
| 2191 | + inode_unlock(inode); |
---|
| 2192 | + } |
---|
| 2193 | + dqopt->files[type] = NULL; |
---|
| 2194 | + iput(inode); |
---|
| 2195 | +} |
---|
| 2196 | + |
---|
2164 | 2197 | /* |
---|
2165 | 2198 | * Turn quota off on a device. type == -1 ==> quotaoff for all types (umount) |
---|
2166 | 2199 | */ |
---|
2167 | 2200 | int dquot_disable(struct super_block *sb, int type, unsigned int flags) |
---|
2168 | 2201 | { |
---|
2169 | | - int cnt, ret = 0; |
---|
| 2202 | + int cnt; |
---|
2170 | 2203 | struct quota_info *dqopt = sb_dqopt(sb); |
---|
2171 | | - struct inode *toputinode[MAXQUOTAS]; |
---|
2172 | 2204 | |
---|
2173 | 2205 | /* s_umount should be held in exclusive mode */ |
---|
2174 | 2206 | if (WARN_ON_ONCE(down_read_trylock(&sb->s_umount))) |
---|
.. | .. |
---|
2190 | 2222 | return 0; |
---|
2191 | 2223 | |
---|
2192 | 2224 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
---|
2193 | | - toputinode[cnt] = NULL; |
---|
2194 | 2225 | if (type != -1 && cnt != type) |
---|
2195 | 2226 | continue; |
---|
2196 | 2227 | if (!sb_has_quota_loaded(sb, cnt)) |
---|
.. | .. |
---|
2210 | 2241 | dqopt->flags &= ~dquot_state_flag( |
---|
2211 | 2242 | DQUOT_SUSPENDED, cnt); |
---|
2212 | 2243 | spin_unlock(&dq_state_lock); |
---|
2213 | | - iput(dqopt->files[cnt]); |
---|
2214 | | - dqopt->files[cnt] = NULL; |
---|
| 2244 | + vfs_cleanup_quota_inode(sb, cnt); |
---|
2215 | 2245 | continue; |
---|
2216 | 2246 | } |
---|
2217 | 2247 | spin_unlock(&dq_state_lock); |
---|
.. | .. |
---|
2233 | 2263 | if (dqopt->ops[cnt]->free_file_info) |
---|
2234 | 2264 | dqopt->ops[cnt]->free_file_info(sb, cnt); |
---|
2235 | 2265 | put_quota_format(dqopt->info[cnt].dqi_format); |
---|
2236 | | - |
---|
2237 | | - toputinode[cnt] = dqopt->files[cnt]; |
---|
2238 | | - if (!sb_has_quota_loaded(sb, cnt)) |
---|
2239 | | - dqopt->files[cnt] = NULL; |
---|
2240 | 2266 | dqopt->info[cnt].dqi_flags = 0; |
---|
2241 | 2267 | dqopt->info[cnt].dqi_igrace = 0; |
---|
2242 | 2268 | dqopt->info[cnt].dqi_bgrace = 0; |
---|
.. | .. |
---|
2258 | 2284 | * must also discard the blockdev buffers so that we see the |
---|
2259 | 2285 | * changes done by userspace on the next quotaon() */ |
---|
2260 | 2286 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
---|
2261 | | - /* This can happen when suspending quotas on remount-ro... */ |
---|
2262 | | - if (toputinode[cnt] && !sb_has_quota_loaded(sb, cnt)) { |
---|
2263 | | - inode_lock(toputinode[cnt]); |
---|
2264 | | - toputinode[cnt]->i_flags &= ~S_NOQUOTA; |
---|
2265 | | - truncate_inode_pages(&toputinode[cnt]->i_data, 0); |
---|
2266 | | - inode_unlock(toputinode[cnt]); |
---|
2267 | | - mark_inode_dirty_sync(toputinode[cnt]); |
---|
| 2287 | + if (!sb_has_quota_loaded(sb, cnt) && dqopt->files[cnt]) { |
---|
| 2288 | + inode_lock(dqopt->files[cnt]); |
---|
| 2289 | + truncate_inode_pages(&dqopt->files[cnt]->i_data, 0); |
---|
| 2290 | + inode_unlock(dqopt->files[cnt]); |
---|
2268 | 2291 | } |
---|
2269 | 2292 | if (sb->s_bdev) |
---|
2270 | 2293 | invalidate_bdev(sb->s_bdev); |
---|
2271 | 2294 | put_inodes: |
---|
| 2295 | + /* We are done when suspending quotas */ |
---|
| 2296 | + if (flags & DQUOT_SUSPENDED) |
---|
| 2297 | + return 0; |
---|
| 2298 | + |
---|
2272 | 2299 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
---|
2273 | | - if (toputinode[cnt]) { |
---|
2274 | | - /* On remount RO, we keep the inode pointer so that we |
---|
2275 | | - * can reenable quota on the subsequent remount RW. We |
---|
2276 | | - * have to check 'flags' variable and not use sb_has_ |
---|
2277 | | - * function because another quotaon / quotaoff could |
---|
2278 | | - * change global state before we got here. We refuse |
---|
2279 | | - * to suspend quotas when there is pending delete on |
---|
2280 | | - * the quota file... */ |
---|
2281 | | - if (!(flags & DQUOT_SUSPENDED)) |
---|
2282 | | - iput(toputinode[cnt]); |
---|
2283 | | - else if (!toputinode[cnt]->i_nlink) |
---|
2284 | | - ret = -EBUSY; |
---|
2285 | | - } |
---|
2286 | | - return ret; |
---|
| 2300 | + if (!sb_has_quota_loaded(sb, cnt)) |
---|
| 2301 | + vfs_cleanup_quota_inode(sb, cnt); |
---|
| 2302 | + return 0; |
---|
2287 | 2303 | } |
---|
2288 | 2304 | EXPORT_SYMBOL(dquot_disable); |
---|
2289 | 2305 | |
---|
.. | .. |
---|
2298 | 2314 | * Turn quotas on on a device |
---|
2299 | 2315 | */ |
---|
2300 | 2316 | |
---|
2301 | | -/* |
---|
2302 | | - * Helper function to turn quotas on when we already have the inode of |
---|
2303 | | - * quota file and no quota information is loaded. |
---|
2304 | | - */ |
---|
2305 | | -static int vfs_load_quota_inode(struct inode *inode, int type, int format_id, |
---|
| 2317 | +static int vfs_setup_quota_inode(struct inode *inode, int type) |
---|
| 2318 | +{ |
---|
| 2319 | + struct super_block *sb = inode->i_sb; |
---|
| 2320 | + struct quota_info *dqopt = sb_dqopt(sb); |
---|
| 2321 | + |
---|
| 2322 | + if (!S_ISREG(inode->i_mode)) |
---|
| 2323 | + return -EACCES; |
---|
| 2324 | + if (IS_RDONLY(inode)) |
---|
| 2325 | + return -EROFS; |
---|
| 2326 | + if (sb_has_quota_loaded(sb, type)) |
---|
| 2327 | + return -EBUSY; |
---|
| 2328 | + |
---|
| 2329 | + dqopt->files[type] = igrab(inode); |
---|
| 2330 | + if (!dqopt->files[type]) |
---|
| 2331 | + return -EIO; |
---|
| 2332 | + if (!(dqopt->flags & DQUOT_QUOTA_SYS_FILE)) { |
---|
| 2333 | + /* We don't want quota and atime on quota files (deadlocks |
---|
| 2334 | + * possible) Also nobody should write to the file - we use |
---|
| 2335 | + * special IO operations which ignore the immutable bit. */ |
---|
| 2336 | + inode_lock(inode); |
---|
| 2337 | + inode->i_flags |= S_NOQUOTA; |
---|
| 2338 | + inode_unlock(inode); |
---|
| 2339 | + /* |
---|
| 2340 | + * When S_NOQUOTA is set, remove dquot references as no more |
---|
| 2341 | + * references can be added |
---|
| 2342 | + */ |
---|
| 2343 | + __dquot_drop(inode); |
---|
| 2344 | + } |
---|
| 2345 | + return 0; |
---|
| 2346 | +} |
---|
| 2347 | + |
---|
| 2348 | +int dquot_load_quota_sb(struct super_block *sb, int type, int format_id, |
---|
2306 | 2349 | unsigned int flags) |
---|
2307 | 2350 | { |
---|
2308 | 2351 | struct quota_format_type *fmt = find_quota_format(format_id); |
---|
2309 | | - struct super_block *sb = inode->i_sb; |
---|
2310 | 2352 | struct quota_info *dqopt = sb_dqopt(sb); |
---|
2311 | 2353 | int error; |
---|
2312 | 2354 | |
---|
| 2355 | + /* Just unsuspend quotas? */ |
---|
| 2356 | + BUG_ON(flags & DQUOT_SUSPENDED); |
---|
| 2357 | + /* s_umount should be held in exclusive mode */ |
---|
| 2358 | + if (WARN_ON_ONCE(down_read_trylock(&sb->s_umount))) |
---|
| 2359 | + up_read(&sb->s_umount); |
---|
| 2360 | + |
---|
2313 | 2361 | if (!fmt) |
---|
2314 | 2362 | return -ESRCH; |
---|
2315 | | - if (!S_ISREG(inode->i_mode)) { |
---|
2316 | | - error = -EACCES; |
---|
2317 | | - goto out_fmt; |
---|
2318 | | - } |
---|
2319 | | - if (IS_RDONLY(inode)) { |
---|
2320 | | - error = -EROFS; |
---|
2321 | | - goto out_fmt; |
---|
2322 | | - } |
---|
2323 | 2363 | if (!sb->s_op->quota_write || !sb->s_op->quota_read || |
---|
2324 | 2364 | (type == PRJQUOTA && sb->dq_op->get_projid == NULL)) { |
---|
2325 | 2365 | error = -EINVAL; |
---|
.. | .. |
---|
2351 | 2391 | invalidate_bdev(sb->s_bdev); |
---|
2352 | 2392 | } |
---|
2353 | 2393 | |
---|
2354 | | - if (!(dqopt->flags & DQUOT_QUOTA_SYS_FILE)) { |
---|
2355 | | - /* We don't want quota and atime on quota files (deadlocks |
---|
2356 | | - * possible) Also nobody should write to the file - we use |
---|
2357 | | - * special IO operations which ignore the immutable bit. */ |
---|
2358 | | - inode_lock(inode); |
---|
2359 | | - inode->i_flags |= S_NOQUOTA; |
---|
2360 | | - inode_unlock(inode); |
---|
2361 | | - /* |
---|
2362 | | - * When S_NOQUOTA is set, remove dquot references as no more |
---|
2363 | | - * references can be added |
---|
2364 | | - */ |
---|
2365 | | - __dquot_drop(inode); |
---|
2366 | | - } |
---|
2367 | | - |
---|
2368 | | - error = -EIO; |
---|
2369 | | - dqopt->files[type] = igrab(inode); |
---|
2370 | | - if (!dqopt->files[type]) |
---|
2371 | | - goto out_file_flags; |
---|
2372 | 2394 | error = -EINVAL; |
---|
2373 | 2395 | if (!fmt->qf_ops->check_quota_file(sb, type)) |
---|
2374 | | - goto out_file_init; |
---|
| 2396 | + goto out_fmt; |
---|
2375 | 2397 | |
---|
2376 | 2398 | dqopt->ops[type] = fmt->qf_ops; |
---|
2377 | 2399 | dqopt->info[type].dqi_format = fmt; |
---|
.. | .. |
---|
2379 | 2401 | INIT_LIST_HEAD(&dqopt->info[type].dqi_dirty_list); |
---|
2380 | 2402 | error = dqopt->ops[type]->read_file_info(sb, type); |
---|
2381 | 2403 | if (error < 0) |
---|
2382 | | - goto out_file_init; |
---|
| 2404 | + goto out_fmt; |
---|
2383 | 2405 | if (dqopt->flags & DQUOT_QUOTA_SYS_FILE) { |
---|
2384 | 2406 | spin_lock(&dq_data_lock); |
---|
2385 | 2407 | dqopt->info[type].dqi_flags |= DQF_SYS_FILE; |
---|
.. | .. |
---|
2394 | 2416 | dquot_disable(sb, type, flags); |
---|
2395 | 2417 | |
---|
2396 | 2418 | return error; |
---|
2397 | | -out_file_init: |
---|
2398 | | - dqopt->files[type] = NULL; |
---|
2399 | | - iput(inode); |
---|
2400 | | -out_file_flags: |
---|
2401 | | - inode_lock(inode); |
---|
2402 | | - inode->i_flags &= ~S_NOQUOTA; |
---|
2403 | | - inode_unlock(inode); |
---|
2404 | 2419 | out_fmt: |
---|
2405 | 2420 | put_quota_format(fmt); |
---|
2406 | 2421 | |
---|
2407 | | - return error; |
---|
| 2422 | + return error; |
---|
2408 | 2423 | } |
---|
| 2424 | +EXPORT_SYMBOL(dquot_load_quota_sb); |
---|
| 2425 | + |
---|
| 2426 | +/* |
---|
| 2427 | + * More powerful function for turning on quotas on given quota inode allowing |
---|
| 2428 | + * setting of individual quota flags |
---|
| 2429 | + */ |
---|
| 2430 | +int dquot_load_quota_inode(struct inode *inode, int type, int format_id, |
---|
| 2431 | + unsigned int flags) |
---|
| 2432 | +{ |
---|
| 2433 | + int err; |
---|
| 2434 | + |
---|
| 2435 | + err = vfs_setup_quota_inode(inode, type); |
---|
| 2436 | + if (err < 0) |
---|
| 2437 | + return err; |
---|
| 2438 | + err = dquot_load_quota_sb(inode->i_sb, type, format_id, flags); |
---|
| 2439 | + if (err < 0) |
---|
| 2440 | + vfs_cleanup_quota_inode(inode->i_sb, type); |
---|
| 2441 | + return err; |
---|
| 2442 | +} |
---|
| 2443 | +EXPORT_SYMBOL(dquot_load_quota_inode); |
---|
2409 | 2444 | |
---|
2410 | 2445 | /* Reenable quotas on remount RW */ |
---|
2411 | 2446 | int dquot_resume(struct super_block *sb, int type) |
---|
2412 | 2447 | { |
---|
2413 | 2448 | struct quota_info *dqopt = sb_dqopt(sb); |
---|
2414 | | - struct inode *inode; |
---|
2415 | 2449 | int ret = 0, cnt; |
---|
2416 | 2450 | unsigned int flags; |
---|
2417 | 2451 | |
---|
.. | .. |
---|
2425 | 2459 | if (!sb_has_quota_suspended(sb, cnt)) |
---|
2426 | 2460 | continue; |
---|
2427 | 2461 | |
---|
2428 | | - inode = dqopt->files[cnt]; |
---|
2429 | | - dqopt->files[cnt] = NULL; |
---|
2430 | 2462 | spin_lock(&dq_state_lock); |
---|
2431 | 2463 | flags = dqopt->flags & dquot_state_flag(DQUOT_USAGE_ENABLED | |
---|
2432 | 2464 | DQUOT_LIMITS_ENABLED, |
---|
.. | .. |
---|
2435 | 2467 | spin_unlock(&dq_state_lock); |
---|
2436 | 2468 | |
---|
2437 | 2469 | flags = dquot_generic_flag(flags, cnt); |
---|
2438 | | - ret = vfs_load_quota_inode(inode, cnt, |
---|
2439 | | - dqopt->info[cnt].dqi_fmt_id, flags); |
---|
2440 | | - iput(inode); |
---|
| 2470 | + ret = dquot_load_quota_sb(sb, cnt, dqopt->info[cnt].dqi_fmt_id, |
---|
| 2471 | + flags); |
---|
| 2472 | + if (ret < 0) |
---|
| 2473 | + vfs_cleanup_quota_inode(sb, cnt); |
---|
2441 | 2474 | } |
---|
2442 | 2475 | |
---|
2443 | 2476 | return ret; |
---|
.. | .. |
---|
2454 | 2487 | if (path->dentry->d_sb != sb) |
---|
2455 | 2488 | error = -EXDEV; |
---|
2456 | 2489 | else |
---|
2457 | | - error = vfs_load_quota_inode(d_inode(path->dentry), type, |
---|
| 2490 | + error = dquot_load_quota_inode(d_inode(path->dentry), type, |
---|
2458 | 2491 | format_id, DQUOT_USAGE_ENABLED | |
---|
2459 | 2492 | DQUOT_LIMITS_ENABLED); |
---|
2460 | 2493 | return error; |
---|
2461 | 2494 | } |
---|
2462 | 2495 | EXPORT_SYMBOL(dquot_quota_on); |
---|
2463 | | - |
---|
2464 | | -/* |
---|
2465 | | - * More powerful function for turning on quotas allowing setting |
---|
2466 | | - * of individual quota flags |
---|
2467 | | - */ |
---|
2468 | | -int dquot_enable(struct inode *inode, int type, int format_id, |
---|
2469 | | - unsigned int flags) |
---|
2470 | | -{ |
---|
2471 | | - struct super_block *sb = inode->i_sb; |
---|
2472 | | - |
---|
2473 | | - /* Just unsuspend quotas? */ |
---|
2474 | | - BUG_ON(flags & DQUOT_SUSPENDED); |
---|
2475 | | - /* s_umount should be held in exclusive mode */ |
---|
2476 | | - if (WARN_ON_ONCE(down_read_trylock(&sb->s_umount))) |
---|
2477 | | - up_read(&sb->s_umount); |
---|
2478 | | - |
---|
2479 | | - if (!flags) |
---|
2480 | | - return 0; |
---|
2481 | | - /* Just updating flags needed? */ |
---|
2482 | | - if (sb_has_quota_loaded(sb, type)) { |
---|
2483 | | - if (flags & DQUOT_USAGE_ENABLED && |
---|
2484 | | - sb_has_quota_usage_enabled(sb, type)) |
---|
2485 | | - return -EBUSY; |
---|
2486 | | - if (flags & DQUOT_LIMITS_ENABLED && |
---|
2487 | | - sb_has_quota_limits_enabled(sb, type)) |
---|
2488 | | - return -EBUSY; |
---|
2489 | | - spin_lock(&dq_state_lock); |
---|
2490 | | - sb_dqopt(sb)->flags |= dquot_state_flag(flags, type); |
---|
2491 | | - spin_unlock(&dq_state_lock); |
---|
2492 | | - return 0; |
---|
2493 | | - } |
---|
2494 | | - |
---|
2495 | | - return vfs_load_quota_inode(inode, type, format_id, flags); |
---|
2496 | | -} |
---|
2497 | | -EXPORT_SYMBOL(dquot_enable); |
---|
2498 | 2496 | |
---|
2499 | 2497 | /* |
---|
2500 | 2498 | * This function is used when filesystem needs to initialize quotas |
---|
.. | .. |
---|
2506 | 2504 | struct dentry *dentry; |
---|
2507 | 2505 | int error; |
---|
2508 | 2506 | |
---|
2509 | | - dentry = lookup_one_len_unlocked(qf_name, sb->s_root, strlen(qf_name)); |
---|
| 2507 | + dentry = lookup_positive_unlocked(qf_name, sb->s_root, strlen(qf_name)); |
---|
2510 | 2508 | if (IS_ERR(dentry)) |
---|
2511 | 2509 | return PTR_ERR(dentry); |
---|
2512 | 2510 | |
---|
2513 | | - if (d_really_is_negative(dentry)) { |
---|
2514 | | - error = -ENOENT; |
---|
2515 | | - goto out; |
---|
2516 | | - } |
---|
2517 | | - |
---|
2518 | 2511 | error = security_quota_on(dentry); |
---|
2519 | 2512 | if (!error) |
---|
2520 | | - error = vfs_load_quota_inode(d_inode(dentry), type, format_id, |
---|
| 2513 | + error = dquot_load_quota_inode(d_inode(dentry), type, format_id, |
---|
2521 | 2514 | DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED); |
---|
2522 | 2515 | |
---|
2523 | | -out: |
---|
2524 | 2516 | dput(dentry); |
---|
2525 | 2517 | return error; |
---|
2526 | 2518 | } |
---|
.. | .. |
---|
2542 | 2534 | if (!(flags & qtype_enforce_flag(type))) |
---|
2543 | 2535 | continue; |
---|
2544 | 2536 | /* Can't enforce without accounting */ |
---|
2545 | | - if (!sb_has_quota_usage_enabled(sb, type)) |
---|
2546 | | - return -EINVAL; |
---|
2547 | | - ret = dquot_enable(dqopt->files[type], type, |
---|
2548 | | - dqopt->info[type].dqi_fmt_id, |
---|
2549 | | - DQUOT_LIMITS_ENABLED); |
---|
2550 | | - if (ret < 0) |
---|
| 2537 | + if (!sb_has_quota_usage_enabled(sb, type)) { |
---|
| 2538 | + ret = -EINVAL; |
---|
2551 | 2539 | goto out_err; |
---|
| 2540 | + } |
---|
| 2541 | + if (sb_has_quota_limits_enabled(sb, type)) { |
---|
| 2542 | + ret = -EBUSY; |
---|
| 2543 | + goto out_err; |
---|
| 2544 | + } |
---|
| 2545 | + spin_lock(&dq_state_lock); |
---|
| 2546 | + dqopt->flags |= dquot_state_flag(DQUOT_LIMITS_ENABLED, type); |
---|
| 2547 | + spin_unlock(&dq_state_lock); |
---|
2552 | 2548 | } |
---|
2553 | 2549 | return 0; |
---|
2554 | 2550 | out_err: |
---|
.. | .. |
---|
2598 | 2594 | out_err: |
---|
2599 | 2595 | /* Backout enforcement disabling we already did */ |
---|
2600 | 2596 | for (type--; type >= 0; type--) { |
---|
2601 | | - if (flags & qtype_enforce_flag(type)) |
---|
2602 | | - dquot_enable(dqopt->files[type], type, |
---|
2603 | | - dqopt->info[type].dqi_fmt_id, |
---|
2604 | | - DQUOT_LIMITS_ENABLED); |
---|
| 2597 | + if (flags & qtype_enforce_flag(type)) { |
---|
| 2598 | + spin_lock(&dq_state_lock); |
---|
| 2599 | + dqopt->flags |= |
---|
| 2600 | + dquot_state_flag(DQUOT_LIMITS_ENABLED, type); |
---|
| 2601 | + spin_unlock(&dq_state_lock); |
---|
| 2602 | + } |
---|
2605 | 2603 | } |
---|
2606 | 2604 | return ret; |
---|
2607 | 2605 | } |
---|
.. | .. |
---|
2730 | 2728 | |
---|
2731 | 2729 | if (check_blim) { |
---|
2732 | 2730 | if (!dm->dqb_bsoftlimit || |
---|
2733 | | - dm->dqb_curspace + dm->dqb_rsvspace < dm->dqb_bsoftlimit) { |
---|
| 2731 | + dm->dqb_curspace + dm->dqb_rsvspace <= dm->dqb_bsoftlimit) { |
---|
2734 | 2732 | dm->dqb_btime = 0; |
---|
2735 | 2733 | clear_bit(DQ_BLKS_B, &dquot->dq_flags); |
---|
2736 | 2734 | } else if (!(di->d_fieldmask & QC_SPC_TIMER)) |
---|
.. | .. |
---|
2739 | 2737 | } |
---|
2740 | 2738 | if (check_ilim) { |
---|
2741 | 2739 | if (!dm->dqb_isoftlimit || |
---|
2742 | | - dm->dqb_curinodes < dm->dqb_isoftlimit) { |
---|
| 2740 | + dm->dqb_curinodes <= dm->dqb_isoftlimit) { |
---|
2743 | 2741 | dm->dqb_itime = 0; |
---|
2744 | 2742 | clear_bit(DQ_INODES_B, &dquot->dq_flags); |
---|
2745 | 2743 | } else if (!(di->d_fieldmask & QC_INO_TIMER)) |
---|
.. | .. |
---|
2782 | 2780 | struct qc_type_state *tstate; |
---|
2783 | 2781 | struct quota_info *dqopt = sb_dqopt(sb); |
---|
2784 | 2782 | int type; |
---|
2785 | | - |
---|
| 2783 | + |
---|
2786 | 2784 | memset(state, 0, sizeof(*state)); |
---|
2787 | 2785 | for (type = 0; type < MAXQUOTAS; type++) { |
---|
2788 | 2786 | if (!sb_has_quota_active(sb, type)) |
---|
.. | .. |
---|
2799 | 2797 | tstate->flags |= QCI_LIMITS_ENFORCED; |
---|
2800 | 2798 | tstate->spc_timelimit = mi->dqi_bgrace; |
---|
2801 | 2799 | tstate->ino_timelimit = mi->dqi_igrace; |
---|
2802 | | - tstate->ino = dqopt->files[type]->i_ino; |
---|
2803 | | - tstate->blocks = dqopt->files[type]->i_blocks; |
---|
| 2800 | + if (dqopt->files[type]) { |
---|
| 2801 | + tstate->ino = dqopt->files[type]->i_ino; |
---|
| 2802 | + tstate->blocks = dqopt->files[type]->i_blocks; |
---|
| 2803 | + } |
---|
2804 | 2804 | tstate->nextents = 1; /* We don't know... */ |
---|
2805 | 2805 | spin_unlock(&dq_data_lock); |
---|
2806 | 2806 | } |
---|
.. | .. |
---|
2857 | 2857 | EXPORT_SYMBOL(dquot_quotactl_sysfile_ops); |
---|
2858 | 2858 | |
---|
2859 | 2859 | static int do_proc_dqstats(struct ctl_table *table, int write, |
---|
2860 | | - void __user *buffer, size_t *lenp, loff_t *ppos) |
---|
| 2860 | + void *buffer, size_t *lenp, loff_t *ppos) |
---|
2861 | 2861 | { |
---|
2862 | 2862 | unsigned int type = (unsigned long *)table->data - dqstats.stat; |
---|
2863 | 2863 | s64 value = percpu_counter_sum(&dqstats.counter[type]); |
---|
.. | .. |
---|
2987 | 2987 | |
---|
2988 | 2988 | /* Find power-of-two hlist_heads which can fit into allocation */ |
---|
2989 | 2989 | nr_hash = (1UL << order) * PAGE_SIZE / sizeof(struct hlist_head); |
---|
2990 | | - dq_hash_bits = 0; |
---|
2991 | | - do { |
---|
2992 | | - dq_hash_bits++; |
---|
2993 | | - } while (nr_hash >> dq_hash_bits); |
---|
2994 | | - dq_hash_bits--; |
---|
| 2990 | + dq_hash_bits = ilog2(nr_hash); |
---|
2995 | 2991 | |
---|
2996 | 2992 | nr_hash = 1UL << dq_hash_bits; |
---|
2997 | 2993 | dq_hash_mask = nr_hash - 1; |
---|