diff options
Diffstat (limited to 'fs/ocfs2/quota_global.c')
-rw-r--r-- | fs/ocfs2/quota_global.c | 144 |
1 files changed, 82 insertions, 62 deletions
diff --git a/fs/ocfs2/quota_global.c b/fs/ocfs2/quota_global.c index edfa60cd155c..44f2a5e1d042 100644 --- a/fs/ocfs2/quota_global.c +++ b/fs/ocfs2/quota_global.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include "sysfile.h" | 23 | #include "sysfile.h" |
24 | #include "dlmglue.h" | 24 | #include "dlmglue.h" |
25 | #include "uptodate.h" | 25 | #include "uptodate.h" |
26 | #include "super.h" | ||
26 | #include "quota.h" | 27 | #include "quota.h" |
27 | 28 | ||
28 | static struct workqueue_struct *ocfs2_quota_wq = NULL; | 29 | static struct workqueue_struct *ocfs2_quota_wq = NULL; |
@@ -69,6 +70,7 @@ static void ocfs2_global_mem2diskdqb(void *dp, struct dquot *dquot) | |||
69 | d->dqb_curspace = cpu_to_le64(m->dqb_curspace); | 70 | d->dqb_curspace = cpu_to_le64(m->dqb_curspace); |
70 | d->dqb_btime = cpu_to_le64(m->dqb_btime); | 71 | d->dqb_btime = cpu_to_le64(m->dqb_btime); |
71 | d->dqb_itime = cpu_to_le64(m->dqb_itime); | 72 | d->dqb_itime = cpu_to_le64(m->dqb_itime); |
73 | d->dqb_pad1 = d->dqb_pad2 = 0; | ||
72 | } | 74 | } |
73 | 75 | ||
74 | static int ocfs2_global_is_id(void *dp, struct dquot *dquot) | 76 | static int ocfs2_global_is_id(void *dp, struct dquot *dquot) |
@@ -113,6 +115,15 @@ int ocfs2_read_quota_block(struct inode *inode, u64 v_block, | |||
113 | int rc = 0; | 115 | int rc = 0; |
114 | struct buffer_head *tmp = *bh; | 116 | struct buffer_head *tmp = *bh; |
115 | 117 | ||
118 | if (i_size_read(inode) >> inode->i_sb->s_blocksize_bits <= v_block) { | ||
119 | ocfs2_error(inode->i_sb, | ||
120 | "Quota file %llu is probably corrupted! Requested " | ||
121 | "to read block %Lu but file has size only %Lu\n", | ||
122 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | ||
123 | (unsigned long long)v_block, | ||
124 | (unsigned long long)i_size_read(inode)); | ||
125 | return -EIO; | ||
126 | } | ||
116 | rc = ocfs2_read_virt_blocks(inode, v_block, 1, &tmp, 0, | 127 | rc = ocfs2_read_virt_blocks(inode, v_block, 1, &tmp, 0, |
117 | ocfs2_validate_quota_block); | 128 | ocfs2_validate_quota_block); |
118 | if (rc) | 129 | if (rc) |
@@ -211,14 +222,13 @@ ssize_t ocfs2_quota_write(struct super_block *sb, int type, | |||
211 | 222 | ||
212 | mutex_lock_nested(&gqinode->i_mutex, I_MUTEX_QUOTA); | 223 | mutex_lock_nested(&gqinode->i_mutex, I_MUTEX_QUOTA); |
213 | if (gqinode->i_size < off + len) { | 224 | if (gqinode->i_size < off + len) { |
214 | down_write(&OCFS2_I(gqinode)->ip_alloc_sem); | 225 | loff_t rounded_end = |
215 | err = ocfs2_extend_no_holes(gqinode, off + len, off); | 226 | ocfs2_align_bytes_to_blocks(sb, off + len); |
216 | up_write(&OCFS2_I(gqinode)->ip_alloc_sem); | 227 | |
217 | if (err < 0) | 228 | /* Space is already allocated in ocfs2_global_read_dquot() */ |
218 | goto out; | ||
219 | err = ocfs2_simple_size_update(gqinode, | 229 | err = ocfs2_simple_size_update(gqinode, |
220 | oinfo->dqi_gqi_bh, | 230 | oinfo->dqi_gqi_bh, |
221 | off + len); | 231 | rounded_end); |
222 | if (err < 0) | 232 | if (err < 0) |
223 | goto out; | 233 | goto out; |
224 | new = 1; | 234 | new = 1; |
@@ -234,7 +244,7 @@ ssize_t ocfs2_quota_write(struct super_block *sb, int type, | |||
234 | } | 244 | } |
235 | if (err) { | 245 | if (err) { |
236 | mlog_errno(err); | 246 | mlog_errno(err); |
237 | return err; | 247 | goto out; |
238 | } | 248 | } |
239 | lock_buffer(bh); | 249 | lock_buffer(bh); |
240 | if (new) | 250 | if (new) |
@@ -342,7 +352,6 @@ int ocfs2_global_read_info(struct super_block *sb, int type) | |||
342 | info->dqi_bgrace = le32_to_cpu(dinfo.dqi_bgrace); | 352 | info->dqi_bgrace = le32_to_cpu(dinfo.dqi_bgrace); |
343 | info->dqi_igrace = le32_to_cpu(dinfo.dqi_igrace); | 353 | info->dqi_igrace = le32_to_cpu(dinfo.dqi_igrace); |
344 | oinfo->dqi_syncms = le32_to_cpu(dinfo.dqi_syncms); | 354 | oinfo->dqi_syncms = le32_to_cpu(dinfo.dqi_syncms); |
345 | oinfo->dqi_syncjiff = msecs_to_jiffies(oinfo->dqi_syncms); | ||
346 | oinfo->dqi_gi.dqi_blocks = le32_to_cpu(dinfo.dqi_blocks); | 355 | oinfo->dqi_gi.dqi_blocks = le32_to_cpu(dinfo.dqi_blocks); |
347 | oinfo->dqi_gi.dqi_free_blk = le32_to_cpu(dinfo.dqi_free_blk); | 356 | oinfo->dqi_gi.dqi_free_blk = le32_to_cpu(dinfo.dqi_free_blk); |
348 | oinfo->dqi_gi.dqi_free_entry = le32_to_cpu(dinfo.dqi_free_entry); | 357 | oinfo->dqi_gi.dqi_free_entry = le32_to_cpu(dinfo.dqi_free_entry); |
@@ -352,7 +361,7 @@ int ocfs2_global_read_info(struct super_block *sb, int type) | |||
352 | oinfo->dqi_gi.dqi_qtree_depth = qtree_depth(&oinfo->dqi_gi); | 361 | oinfo->dqi_gi.dqi_qtree_depth = qtree_depth(&oinfo->dqi_gi); |
353 | INIT_DELAYED_WORK(&oinfo->dqi_sync_work, qsync_work_fn); | 362 | INIT_DELAYED_WORK(&oinfo->dqi_sync_work, qsync_work_fn); |
354 | queue_delayed_work(ocfs2_quota_wq, &oinfo->dqi_sync_work, | 363 | queue_delayed_work(ocfs2_quota_wq, &oinfo->dqi_sync_work, |
355 | oinfo->dqi_syncjiff); | 364 | msecs_to_jiffies(oinfo->dqi_syncms)); |
356 | 365 | ||
357 | out_err: | 366 | out_err: |
358 | mlog_exit(status); | 367 | mlog_exit(status); |
@@ -402,13 +411,36 @@ int ocfs2_global_write_info(struct super_block *sb, int type) | |||
402 | return err; | 411 | return err; |
403 | } | 412 | } |
404 | 413 | ||
414 | static int ocfs2_global_qinit_alloc(struct super_block *sb, int type) | ||
415 | { | ||
416 | struct ocfs2_mem_dqinfo *oinfo = sb_dqinfo(sb, type)->dqi_priv; | ||
417 | |||
418 | /* | ||
419 | * We may need to allocate tree blocks and a leaf block but not the | ||
420 | * root block | ||
421 | */ | ||
422 | return oinfo->dqi_gi.dqi_qtree_depth; | ||
423 | } | ||
424 | |||
425 | static int ocfs2_calc_global_qinit_credits(struct super_block *sb, int type) | ||
426 | { | ||
427 | /* We modify all the allocated blocks, tree root, and info block */ | ||
428 | return (ocfs2_global_qinit_alloc(sb, type) + 2) * | ||
429 | OCFS2_QUOTA_BLOCK_UPDATE_CREDITS; | ||
430 | } | ||
431 | |||
405 | /* Read in information from global quota file and acquire a reference to it. | 432 | /* Read in information from global quota file and acquire a reference to it. |
406 | * dquot_acquire() has already started the transaction and locked quota file */ | 433 | * dquot_acquire() has already started the transaction and locked quota file */ |
407 | int ocfs2_global_read_dquot(struct dquot *dquot) | 434 | int ocfs2_global_read_dquot(struct dquot *dquot) |
408 | { | 435 | { |
409 | int err, err2, ex = 0; | 436 | int err, err2, ex = 0; |
410 | struct ocfs2_mem_dqinfo *info = | 437 | struct super_block *sb = dquot->dq_sb; |
411 | sb_dqinfo(dquot->dq_sb, dquot->dq_type)->dqi_priv; | 438 | int type = dquot->dq_type; |
439 | struct ocfs2_mem_dqinfo *info = sb_dqinfo(sb, type)->dqi_priv; | ||
440 | struct ocfs2_super *osb = OCFS2_SB(sb); | ||
441 | struct inode *gqinode = info->dqi_gqinode; | ||
442 | int need_alloc = ocfs2_global_qinit_alloc(sb, type); | ||
443 | handle_t *handle = NULL; | ||
412 | 444 | ||
413 | err = ocfs2_qinfo_lock(info, 0); | 445 | err = ocfs2_qinfo_lock(info, 0); |
414 | if (err < 0) | 446 | if (err < 0) |
@@ -419,14 +451,33 @@ int ocfs2_global_read_dquot(struct dquot *dquot) | |||
419 | OCFS2_DQUOT(dquot)->dq_use_count++; | 451 | OCFS2_DQUOT(dquot)->dq_use_count++; |
420 | OCFS2_DQUOT(dquot)->dq_origspace = dquot->dq_dqb.dqb_curspace; | 452 | OCFS2_DQUOT(dquot)->dq_origspace = dquot->dq_dqb.dqb_curspace; |
421 | OCFS2_DQUOT(dquot)->dq_originodes = dquot->dq_dqb.dqb_curinodes; | 453 | OCFS2_DQUOT(dquot)->dq_originodes = dquot->dq_dqb.dqb_curinodes; |
454 | ocfs2_qinfo_unlock(info, 0); | ||
455 | |||
422 | if (!dquot->dq_off) { /* No real quota entry? */ | 456 | if (!dquot->dq_off) { /* No real quota entry? */ |
423 | /* Upgrade to exclusive lock for allocation */ | ||
424 | ocfs2_qinfo_unlock(info, 0); | ||
425 | err = ocfs2_qinfo_lock(info, 1); | ||
426 | if (err < 0) | ||
427 | goto out_qlock; | ||
428 | ex = 1; | 457 | ex = 1; |
458 | /* | ||
459 | * Add blocks to quota file before we start a transaction since | ||
460 | * locking allocators ranks above a transaction start | ||
461 | */ | ||
462 | WARN_ON(journal_current_handle()); | ||
463 | down_write(&OCFS2_I(gqinode)->ip_alloc_sem); | ||
464 | err = ocfs2_extend_no_holes(gqinode, | ||
465 | gqinode->i_size + (need_alloc << sb->s_blocksize_bits), | ||
466 | gqinode->i_size); | ||
467 | up_write(&OCFS2_I(gqinode)->ip_alloc_sem); | ||
468 | if (err < 0) | ||
469 | goto out; | ||
429 | } | 470 | } |
471 | |||
472 | handle = ocfs2_start_trans(osb, | ||
473 | ocfs2_calc_global_qinit_credits(sb, type)); | ||
474 | if (IS_ERR(handle)) { | ||
475 | err = PTR_ERR(handle); | ||
476 | goto out; | ||
477 | } | ||
478 | err = ocfs2_qinfo_lock(info, ex); | ||
479 | if (err < 0) | ||
480 | goto out_trans; | ||
430 | err = qtree_write_dquot(&info->dqi_gi, dquot); | 481 | err = qtree_write_dquot(&info->dqi_gi, dquot); |
431 | if (ex && info_dirty(sb_dqinfo(dquot->dq_sb, dquot->dq_type))) { | 482 | if (ex && info_dirty(sb_dqinfo(dquot->dq_sb, dquot->dq_type))) { |
432 | err2 = __ocfs2_global_write_info(dquot->dq_sb, dquot->dq_type); | 483 | err2 = __ocfs2_global_write_info(dquot->dq_sb, dquot->dq_type); |
@@ -438,6 +489,9 @@ out_qlock: | |||
438 | ocfs2_qinfo_unlock(info, 1); | 489 | ocfs2_qinfo_unlock(info, 1); |
439 | else | 490 | else |
440 | ocfs2_qinfo_unlock(info, 0); | 491 | ocfs2_qinfo_unlock(info, 0); |
492 | out_trans: | ||
493 | if (handle) | ||
494 | ocfs2_commit_trans(osb, handle); | ||
441 | out: | 495 | out: |
442 | if (err < 0) | 496 | if (err < 0) |
443 | mlog_errno(err); | 497 | mlog_errno(err); |
@@ -607,7 +661,7 @@ static void qsync_work_fn(struct work_struct *work) | |||
607 | 661 | ||
608 | dquot_scan_active(sb, ocfs2_sync_dquot_helper, oinfo->dqi_type); | 662 | dquot_scan_active(sb, ocfs2_sync_dquot_helper, oinfo->dqi_type); |
609 | queue_delayed_work(ocfs2_quota_wq, &oinfo->dqi_sync_work, | 663 | queue_delayed_work(ocfs2_quota_wq, &oinfo->dqi_sync_work, |
610 | oinfo->dqi_syncjiff); | 664 | msecs_to_jiffies(oinfo->dqi_syncms)); |
611 | } | 665 | } |
612 | 666 | ||
613 | /* | 667 | /* |
@@ -635,20 +689,18 @@ out: | |||
635 | return status; | 689 | return status; |
636 | } | 690 | } |
637 | 691 | ||
638 | int ocfs2_calc_qdel_credits(struct super_block *sb, int type) | 692 | static int ocfs2_calc_qdel_credits(struct super_block *sb, int type) |
639 | { | 693 | { |
640 | struct ocfs2_mem_dqinfo *oinfo; | 694 | struct ocfs2_mem_dqinfo *oinfo = sb_dqinfo(sb, type)->dqi_priv; |
641 | int features[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA, | 695 | /* |
642 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA }; | 696 | * We modify tree, leaf block, global info, local chunk header, |
643 | 697 | * global and local inode; OCFS2_QINFO_WRITE_CREDITS already | |
644 | if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, features[type])) | 698 | * accounts for inode update |
645 | return 0; | 699 | */ |
646 | 700 | return (oinfo->dqi_gi.dqi_qtree_depth + 2) * | |
647 | oinfo = sb_dqinfo(sb, type)->dqi_priv; | 701 | OCFS2_QUOTA_BLOCK_UPDATE_CREDITS + |
648 | /* We modify tree, leaf block, global info, local chunk header, | 702 | OCFS2_QINFO_WRITE_CREDITS + |
649 | * global and local inode */ | 703 | OCFS2_INODE_UPDATE_CREDITS; |
650 | return oinfo->dqi_gi.dqi_qtree_depth + 2 + 1 + | ||
651 | 2 * OCFS2_INODE_UPDATE_CREDITS; | ||
652 | } | 704 | } |
653 | 705 | ||
654 | static int ocfs2_release_dquot(struct dquot *dquot) | 706 | static int ocfs2_release_dquot(struct dquot *dquot) |
@@ -680,33 +732,10 @@ out: | |||
680 | return status; | 732 | return status; |
681 | } | 733 | } |
682 | 734 | ||
683 | int ocfs2_calc_qinit_credits(struct super_block *sb, int type) | ||
684 | { | ||
685 | struct ocfs2_mem_dqinfo *oinfo; | ||
686 | int features[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA, | ||
687 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA }; | ||
688 | struct ocfs2_dinode *lfe, *gfe; | ||
689 | |||
690 | if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, features[type])) | ||
691 | return 0; | ||
692 | |||
693 | oinfo = sb_dqinfo(sb, type)->dqi_priv; | ||
694 | gfe = (struct ocfs2_dinode *)oinfo->dqi_gqi_bh->b_data; | ||
695 | lfe = (struct ocfs2_dinode *)oinfo->dqi_lqi_bh->b_data; | ||
696 | /* We can extend local file + global file. In local file we | ||
697 | * can modify info, chunk header block and dquot block. In | ||
698 | * global file we can modify info, tree and leaf block */ | ||
699 | return ocfs2_calc_extend_credits(sb, &lfe->id2.i_list, 0) + | ||
700 | ocfs2_calc_extend_credits(sb, &gfe->id2.i_list, 0) + | ||
701 | 3 + oinfo->dqi_gi.dqi_qtree_depth + 2; | ||
702 | } | ||
703 | |||
704 | static int ocfs2_acquire_dquot(struct dquot *dquot) | 735 | static int ocfs2_acquire_dquot(struct dquot *dquot) |
705 | { | 736 | { |
706 | handle_t *handle; | ||
707 | struct ocfs2_mem_dqinfo *oinfo = | 737 | struct ocfs2_mem_dqinfo *oinfo = |
708 | sb_dqinfo(dquot->dq_sb, dquot->dq_type)->dqi_priv; | 738 | sb_dqinfo(dquot->dq_sb, dquot->dq_type)->dqi_priv; |
709 | struct ocfs2_super *osb = OCFS2_SB(dquot->dq_sb); | ||
710 | int status = 0; | 739 | int status = 0; |
711 | 740 | ||
712 | mlog_entry("id=%u, type=%d", dquot->dq_id, dquot->dq_type); | 741 | mlog_entry("id=%u, type=%d", dquot->dq_id, dquot->dq_type); |
@@ -715,16 +744,7 @@ static int ocfs2_acquire_dquot(struct dquot *dquot) | |||
715 | status = ocfs2_lock_global_qf(oinfo, 1); | 744 | status = ocfs2_lock_global_qf(oinfo, 1); |
716 | if (status < 0) | 745 | if (status < 0) |
717 | goto out; | 746 | goto out; |
718 | handle = ocfs2_start_trans(osb, | ||
719 | ocfs2_calc_qinit_credits(dquot->dq_sb, dquot->dq_type)); | ||
720 | if (IS_ERR(handle)) { | ||
721 | status = PTR_ERR(handle); | ||
722 | mlog_errno(status); | ||
723 | goto out_ilock; | ||
724 | } | ||
725 | status = dquot_acquire(dquot); | 747 | status = dquot_acquire(dquot); |
726 | ocfs2_commit_trans(osb, handle); | ||
727 | out_ilock: | ||
728 | ocfs2_unlock_global_qf(oinfo, 1); | 748 | ocfs2_unlock_global_qf(oinfo, 1); |
729 | out: | 749 | out: |
730 | mlog_exit(status); | 750 | mlog_exit(status); |