~ubuntu-branches/ubuntu/utopic/xfsprogs/utopic-proposed

« back to all changes in this revision

Viewing changes to libxfs/init.c

  • Committer: Bazaar Package Importer
  • Author(s): Nathan Scott
  • Date: 2009-05-06 11:29:18 UTC
  • mfrom: (8.1.1 jaunty)
  • Revision ID: james.westby@ubuntu.com-20090506112918-uzoyzcp90rtr8td7
Tags: 3.0.2
New bugfix release

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
17
 */
18
18
 
19
 
#include <xfs/libxfs.h>
 
19
#include <xfs.h>
20
20
#include <sys/stat.h>
21
21
#include "init.h"
22
22
 
28
28
struct cache *libxfs_bcache;    /* global buffer cache */
29
29
int libxfs_bhash_size;          /* #buckets in bcache */
30
30
 
 
31
int     use_xfs_buf_lock;       /* global flag: use xfs_buf_t locks for MT */
 
32
 
31
33
static void manage_zones(int);  /* setup global zones */
32
34
 
33
35
/*
335
337
        if (!libxfs_bhash_size)
336
338
                libxfs_bhash_size = LIBXFS_BHASHSIZE(sbp);
337
339
        libxfs_bcache = cache_init(libxfs_bhash_size, &libxfs_bcache_operations);
 
340
        use_xfs_buf_lock = a->usebuflock;
338
341
        manage_zones(0);
339
342
        rval = 1;
340
343
done:
362
365
static void
363
366
manage_zones(int release)
364
367
{
365
 
        extern xfs_zone_t       *xfs_buf_zone;
366
 
        extern xfs_zone_t       *xfs_ili_zone;
367
 
        extern xfs_zone_t       *xfs_inode_zone;
368
 
        extern xfs_zone_t       *xfs_ifork_zone;
369
 
        extern xfs_zone_t       *xfs_dabuf_zone;
370
 
        extern xfs_zone_t       *xfs_buf_item_zone;
371
 
        extern xfs_zone_t       *xfs_da_state_zone;
372
 
        extern xfs_zone_t       *xfs_btree_cur_zone;
373
 
        extern xfs_zone_t       *xfs_bmap_free_item_zone;
 
368
        extern kmem_zone_t      *xfs_buf_zone;
 
369
        extern kmem_zone_t      *xfs_ili_zone;
 
370
        extern kmem_zone_t      *xfs_inode_zone;
 
371
        extern kmem_zone_t      *xfs_ifork_zone;
 
372
        extern kmem_zone_t      *xfs_dabuf_zone;
 
373
        extern kmem_zone_t      *xfs_buf_item_zone;
 
374
        extern kmem_zone_t      *xfs_da_state_zone;
 
375
        extern kmem_zone_t      *xfs_btree_cur_zone;
 
376
        extern kmem_zone_t      *xfs_bmap_free_item_zone;
374
377
        extern void             xfs_dir_startup();
375
378
 
376
379
        if (release) {  /* free zone allocation */
377
 
                libxfs_free(xfs_buf_zone);
378
 
                libxfs_free(xfs_inode_zone);
379
 
                libxfs_free(xfs_ifork_zone);
380
 
                libxfs_free(xfs_dabuf_zone);
381
 
                libxfs_free(xfs_buf_item_zone);
382
 
                libxfs_free(xfs_da_state_zone);
383
 
                libxfs_free(xfs_btree_cur_zone);
384
 
                libxfs_free(xfs_bmap_free_item_zone);
 
380
                kmem_free(xfs_buf_zone);
 
381
                kmem_free(xfs_inode_zone);
 
382
                kmem_free(xfs_ifork_zone);
 
383
                kmem_free(xfs_dabuf_zone);
 
384
                kmem_free(xfs_buf_item_zone);
 
385
                kmem_free(xfs_da_state_zone);
 
386
                kmem_free(xfs_btree_cur_zone);
 
387
                kmem_free(xfs_bmap_free_item_zone);
385
388
                return;
386
389
        }
387
390
        /* otherwise initialise zone allocation */
388
 
        xfs_buf_zone = libxfs_zone_init(sizeof(xfs_buf_t), "xfs_buffer");
389
 
        xfs_inode_zone = libxfs_zone_init(sizeof(xfs_inode_t), "xfs_inode");
390
 
        xfs_ifork_zone = libxfs_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
391
 
        xfs_dabuf_zone = libxfs_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
392
 
        xfs_ili_zone = libxfs_zone_init(
 
391
        xfs_buf_zone = kmem_zone_init(sizeof(xfs_buf_t), "xfs_buffer");
 
392
        xfs_inode_zone = kmem_zone_init(sizeof(xfs_inode_t), "xfs_inode");
 
393
        xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
 
394
        xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
 
395
        xfs_ili_zone = kmem_zone_init(
393
396
                        sizeof(xfs_inode_log_item_t), "xfs_inode_log_item");
394
 
        xfs_buf_item_zone = libxfs_zone_init(
 
397
        xfs_buf_item_zone = kmem_zone_init(
395
398
                        sizeof(xfs_buf_log_item_t), "xfs_buf_log_item");
396
 
        xfs_da_state_zone = libxfs_zone_init(
 
399
        xfs_da_state_zone = kmem_zone_init(
397
400
                        sizeof(xfs_da_state_t), "xfs_da_state");
398
 
        xfs_btree_cur_zone = libxfs_zone_init(
 
401
        xfs_btree_cur_zone = kmem_zone_init(
399
402
                        sizeof(xfs_btree_cur_t), "xfs_btree_cur");
400
 
        xfs_bmap_free_item_zone = libxfs_zone_init(
 
403
        xfs_bmap_free_item_zone = kmem_zone_init(
401
404
                        sizeof(xfs_bmap_free_item_t), "xfs_bmap_free_item");
402
405
        xfs_dir_startup();
403
406
}
490
493
        return 0;
491
494
}
492
495
 
 
496
 
 
497
/*
 
498
 * Core dir v1 mount code for allowing reading of these dirs.
 
499
 */
 
500
static void
 
501
libxfs_dirv1_mount(
 
502
        xfs_mount_t     *mp)
 
503
{
 
504
        mp->m_dir_node_ents = mp->m_attr_node_ents =
 
505
                (XFS_LBSIZE(mp) - (uint)sizeof(xfs_da_node_hdr_t)) /
 
506
                (uint)sizeof(xfs_da_node_entry_t);
 
507
        mp->m_dir_magicpct = (XFS_LBSIZE(mp) * 37) / 100;
 
508
        mp->m_dirblksize = mp->m_sb.sb_blocksize;
 
509
        mp->m_dirblkfsbs = 1;
 
510
}
 
511
 
493
512
/*
494
513
 * Mount structure initialization, provides a filled-in xfs_mount_t
495
514
 * such that the numerous XFS_* macros can be used.  If dev is zero,
517
536
        mp->m_sb = *sb;
518
537
        sbp = &(mp->m_sb);
519
538
 
520
 
        libxfs_mount_common(mp, sb);
 
539
        xfs_mount_common(mp, sb);
521
540
 
522
 
        libxfs_alloc_compute_maxlevels(mp);
523
 
        libxfs_bmap_compute_maxlevels(mp, XFS_DATA_FORK);
524
 
        libxfs_bmap_compute_maxlevels(mp, XFS_ATTR_FORK);
525
 
        libxfs_ialloc_compute_maxlevels(mp);
 
541
        xfs_alloc_compute_maxlevels(mp);
 
542
        xfs_bmap_compute_maxlevels(mp, XFS_DATA_FORK);
 
543
        xfs_bmap_compute_maxlevels(mp, XFS_ATTR_FORK);
 
544
        xfs_ialloc_compute_maxlevels(mp);
526
545
 
527
546
        if (sbp->sb_imax_pct) {
528
547
                /* Make sure the maximum inode count is a multiple of the
539
558
        /*
540
559
         * Set whether we're using stripe alignment.
541
560
         */
542
 
        if (XFS_SB_VERSION_HASDALIGN(&mp->m_sb)) {
 
561
        if (xfs_sb_version_hasdalign(&mp->m_sb)) {
543
562
                mp->m_dalign = sbp->sb_unit;
544
563
                mp->m_swidth = sbp->sb_width;
545
564
        }
547
566
        /*
548
567
         * Set whether we're using inode alignment.
549
568
         */
550
 
        if (XFS_SB_VERSION_HASALIGN(&mp->m_sb) &&
 
569
        if (xfs_sb_version_hasalign(&mp->m_sb) &&
551
570
            mp->m_sb.sb_inoalignmt >=
552
571
            XFS_B_TO_FSBT(mp, mp->m_inode_cluster_size))
553
572
                mp->m_inoalign_mask = mp->m_sb.sb_inoalignmt - 1;
557
576
         * If we are using stripe alignment, check whether
558
577
         * the stripe unit is a multiple of the inode alignment
559
578
         */
560
 
        if (   mp->m_dalign
561
 
            && mp->m_inoalign_mask && !(mp->m_dalign & mp->m_inoalign_mask))
 
579
        if (mp->m_dalign && mp->m_inoalign_mask &&
 
580
                                        !(mp->m_dalign & mp->m_inoalign_mask))
562
581
                mp->m_sinoalign = mp->m_dalign;
563
582
        else
564
583
                mp->m_sinoalign = 0;
574
593
        }
575
594
 
576
595
        /* Initialize the appropriate directory manager */
577
 
        if (XFS_SB_VERSION_HASDIRV2(sbp))
578
 
                libxfs_dir2_mount(mp);
579
 
        else
580
 
                libxfs_dir_mount(mp);
 
596
        if (xfs_sb_version_hasdirv2(sbp))
 
597
                xfs_dir_mount(mp);
 
598
        else {
 
599
                fprintf(stderr, _("%s: WARNING - filesystem uses v1 dirs,"
 
600
                                "limited functionality provided.\n"), progname);
 
601
                libxfs_dirv1_mount(mp);
 
602
        }
581
603
 
582
604
        /* Initialize cached values for the attribute manager */
583
605
        mp->m_attr_magicpct = (mp->m_sb.sb_blocksize * 37) / 100;
 
606
        if (xfs_sb_version_hasattr2(&mp->m_sb))
 
607
                mp->m_flags |= LIBXFS_MOUNT_ATTR2;
584
608
 
585
609
        /* Initialize the precomputed transaction reservations values */
586
 
        libxfs_trans_init(mp);
 
610
        xfs_trans_init(mp);
587
611
 
588
612
        if (dev == 0)   /* maxtrres, we have no device so leave now */
589
613
                return mp;
629
653
                exit(1);
630
654
        }
631
655
 
632
 
        mp->m_maxagi = libxfs_initialize_perag(mp, sbp->sb_agcount);
 
656
        mp->m_maxagi = xfs_initialize_perag(mp, sbp->sb_agcount);
633
657
 
634
658
        /*
635
659
         * mkfs calls mount before the root inode is allocated.
646
670
                ASSERT(mp->m_rootip != NULL);
647
671
        }
648
672
        if ((flags & LIBXFS_MOUNT_ROOTINOS) && rtmount_inodes(mp)) {
649
 
                libxfs_iput(mp->m_rootip, 0);
 
673
                if (mp->m_rootip)
 
674
                        libxfs_iput(mp->m_rootip, 0);
650
675
                return NULL;
651
676
        }
652
677
 
654
679
         * mkfs calls mount before the AGF/AGI structures are written.
655
680
         */
656
681
        if ((flags & LIBXFS_MOUNT_ROOTINOS) && sbp->sb_rootino != NULLFSINO &&
657
 
            XFS_SB_VERSION_LAZYSBCOUNT(&mp->m_sb)) {
658
 
                error = libxfs_initialize_perag_data(mp, sbp->sb_agcount);
 
682
            xfs_sb_version_haslazysbcount(&mp->m_sb)) {
 
683
                error = xfs_initialize_perag_data(mp, sbp->sb_agcount);
659
684
                if (error) {
660
685
                        fprintf(stderr, _("%s: cannot init perag data (%d)\n"),
661
686
                                progname, error);