diff options
author | Dave Chinner <david@fromorbit.com> | 2010-01-11 06:47:48 -0500 |
---|---|---|
committer | Alex Elder <aelder@sgi.com> | 2010-01-15 16:34:30 -0500 |
commit | 8b26c5825e023b1bccac7afd174ebe55b8905cb1 (patch) | |
tree | a8d27401fc943101af7eda72f2ed040664eead68 /fs | |
parent | b657fc82a3ca6d7ad16a59e81765f0fb0e86cdbb (diff) |
xfs: handle ENOMEM correctly during initialisation of perag structures
Add proper error handling in case an error occurs while initializing
new perag structures for a mount point. The mount structure is
restored to its previous state by deleting and freeing any perag
structures added during the call.
Signed-off-by: Dave Chinner <david@fromorbit.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Alex Elder <aelder@sgi.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/xfs/xfs_mount.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index 049dbc71c28e..be643e588067 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c | |||
@@ -432,11 +432,13 @@ xfs_initialize_perag( | |||
432 | xfs_agnumber_t *maxagi) | 432 | xfs_agnumber_t *maxagi) |
433 | { | 433 | { |
434 | xfs_agnumber_t index, max_metadata; | 434 | xfs_agnumber_t index, max_metadata; |
435 | xfs_agnumber_t first_initialised = 0; | ||
435 | xfs_perag_t *pag; | 436 | xfs_perag_t *pag; |
436 | xfs_agino_t agino; | 437 | xfs_agino_t agino; |
437 | xfs_ino_t ino; | 438 | xfs_ino_t ino; |
438 | xfs_sb_t *sbp = &mp->m_sb; | 439 | xfs_sb_t *sbp = &mp->m_sb; |
439 | xfs_ino_t max_inum = XFS_MAXINUMBER_32; | 440 | xfs_ino_t max_inum = XFS_MAXINUMBER_32; |
441 | int error = -ENOMEM; | ||
440 | 442 | ||
441 | /* Check to see if the filesystem can overflow 32 bit inodes */ | 443 | /* Check to see if the filesystem can overflow 32 bit inodes */ |
442 | agino = XFS_OFFBNO_TO_AGINO(mp, sbp->sb_agblocks - 1, 0); | 444 | agino = XFS_OFFBNO_TO_AGINO(mp, sbp->sb_agblocks - 1, 0); |
@@ -453,17 +455,20 @@ xfs_initialize_perag( | |||
453 | xfs_perag_put(pag); | 455 | xfs_perag_put(pag); |
454 | continue; | 456 | continue; |
455 | } | 457 | } |
458 | if (!first_initialised) | ||
459 | first_initialised = index; | ||
456 | pag = kmem_zalloc(sizeof(*pag), KM_MAYFAIL); | 460 | pag = kmem_zalloc(sizeof(*pag), KM_MAYFAIL); |
457 | if (!pag) | 461 | if (!pag) |
458 | return -ENOMEM; | 462 | goto out_unwind; |
459 | if (radix_tree_preload(GFP_NOFS)) | 463 | if (radix_tree_preload(GFP_NOFS)) |
460 | return -ENOMEM; | 464 | goto out_unwind; |
461 | spin_lock(&mp->m_perag_lock); | 465 | spin_lock(&mp->m_perag_lock); |
462 | if (radix_tree_insert(&mp->m_perag_tree, index, pag)) { | 466 | if (radix_tree_insert(&mp->m_perag_tree, index, pag)) { |
463 | BUG(); | 467 | BUG(); |
464 | spin_unlock(&mp->m_perag_lock); | 468 | spin_unlock(&mp->m_perag_lock); |
465 | kmem_free(pag); | 469 | radix_tree_preload_end(); |
466 | return -EEXIST; | 470 | error = -EEXIST; |
471 | goto out_unwind; | ||
467 | } | 472 | } |
468 | pag->pag_agno = index; | 473 | pag->pag_agno = index; |
469 | pag->pag_mount = mp; | 474 | pag->pag_mount = mp; |
@@ -523,6 +528,14 @@ xfs_initialize_perag( | |||
523 | if (maxagi) | 528 | if (maxagi) |
524 | *maxagi = index; | 529 | *maxagi = index; |
525 | return 0; | 530 | return 0; |
531 | |||
532 | out_unwind: | ||
533 | kmem_free(pag); | ||
534 | for (; index > first_initialised; index--) { | ||
535 | pag = radix_tree_delete(&mp->m_perag_tree, index); | ||
536 | kmem_free(pag); | ||
537 | } | ||
538 | return error; | ||
526 | } | 539 | } |
527 | 540 | ||
528 | void | 541 | void |